MODULE InfoForEachEntry;

	(*
	Do for all entries in the list
	Helmut Zinn - 
	*)

	IMPORT
		Dialog, DosKeyboard, StdCmds, StdLog, Strings,
		TextCmds, TextControllers, TextMappers, TextModels;

	TYPE
		Function = PROCEDURE (IN path, file: ARRAY OF CHAR; t: TextModels.Model; VAR hit: INTEGER);

	PROCEDURE Log (IN path, file: ARRAY OF CHAR; t: TextModels.Model; VAR hit: INTEGER);
	BEGIN
		hit := 1;
		(*
		StdLog.String(TextCmds.find.find); StdLog.Tab;
		StdLog.String(TextCmds.find.replace); StdLog.Ln;
		*)
	END Log;

	PROCEDURE ReadField (VAR sc: TextMappers.Scanner; OUT s: ARRAY OF CHAR);
		VAR ch: CHAR; i: INTEGER;
	BEGIN
		i := 0;
		ch := sc.rider.char;
		WHILE (ch = TextModels.line) OR (ch = TextModels.tab) OR (ch = TextModels.para) DO
			sc.rider.ReadChar(ch)
		END;
		WHILE ~(sc.rider.eot
			OR (ch = TextModels.line) OR (ch = TextModels.tab) OR (ch = TextModels.para) OR (i > 254)) DO
			s[i] := ch; INC(i);
			sc.rider.ReadChar(ch);
		END;
		s[i] := 0X;
	END ReadField;

	PROCEDURE Do* (Task: Function; IN path, filename: ARRAY OF CHAR; t: TextModels.Model; VAR count: INTEGER);
		VAR
			cn: TextControllers.Controller;
			sc: TextMappers.Scanner;
			ch: CHAR;
			firstField, secondField: ARRAY 256 OF CHAR;
			hit: INTEGER;
	BEGIN
		count := 0;
		hit := 0;
		cn := TextControllers.Focus();
		IF cn # NIL THEN
			sc.ConnectTo(cn.text);
			sc.Scan; (* skip auto *)
			IF (sc.type = TextMappers.string) & (sc.string = "auto") THEN
				sc.rider.ReadChar(ch);
				WHILE ~DosKeyboard.Break() & ~sc.rider.eot DO
					ReadField(sc, firstField);
					ReadField(sc, secondField);
					TextCmds.find.find := firstField$;
					TextCmds.find.replace := secondField$;
					IF TextCmds.find.ignoreCase THEN
						Strings.ToLower(TextCmds.find.find, TextCmds.find.find);
					END;
					Dialog.Update(TextCmds.find);
					Task(path, filename, t, hit); (* do the task for each pair of fields *)
					count := count + hit;
					sc.rider.ReadChar(ch);
				END;
			END;
		END;
	END Do;

	PROCEDURE LogList*;
		VAR count: INTEGER;
	BEGIN
		(* StdCmds.OpenToolDialog('Info/Rsrc/ReplaceAll', 'Replace in all Docu'); *)
		Do(Log, "", "", NIL, count);
		StdLog.Int(count); StdLog.String(" entries."); StdLog.Ln;
	END LogList;

END InfoForEachEntry.
