home *** CD-ROM | disk | FTP | other *** search
- program exstr;
-
- uses
- dos,crt;
-
- const
- t : array [1..26] of byte =
- (2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9);
- var
- found : boolean;
- linecount : longint;
- line : string;
- wort : string;
- a : array[1..256] of byte absolute line;
- b : array[1..256] of byte absolute wort;
- func,p1,p2,i,j : integer;
- c : char;
- n,fields : word;
- fpos : array[1..30] of byte;
- flen : array[1..30] of byte;
- out : text;
-
-
- procedure std_inout;
-
- begin
- assign (input,''); Reset (input);
- assign (output,''); Rewrite (output);
- end;
-
-
- procedure crt_inout;
-
- begin
- close (input); assigncrt (input); Reset (input);
- close (output); assigncrt (output); Rewrite (output);
- end;
-
-
- procedure cypher;
-
- var
- i : integer;
- j : integer;
-
- begin
- j := 2;
- for i := 2 to length(line)+1 do
- begin
- a[i] := a[i] xor b[j];
- if (a[i] in [10,13,26]) then
- a[i] := a[i] xor b[j];
- j := j+1;
- if (j > length(wort)) then j := 2;
- end;
- end;
-
-
-
- function phone_number : boolean;
-
- begin
- p1 := pos('#',line);
- if (p1 > 0) then
- begin
- wort := copy(line,p1 + 1,200);
- for i := 1 to length(wort) do
- begin
- if (wort[i] in ['a'..'z']) then b[i+1] := b[i+1] - 32;
- if (wort[i] in ['A'..'Z']) then b[i+1] := t[b[i+1] - 64] + 48;
- end;
- phone_number := TRUE;
- end
- else phone_number := FALSE;
- end;
-
-
-
- procedure dialout;
-
- begin
- writeln(paramstr(5),wort);
- halt;
- end;
-
-
-
- function print : boolean;
-
- begin
- print := FALSE;
- case func of
- 0,
- 4 : begin
- if (func = 4) then writeln(out,line);
- print := TRUE;
- if (p1 > 0) then
- begin
- if (linecount >= p1) then
- begin
- c := readkey;
- if (c = #3) then halt;
- if (c = #13) then linecount := p1 - 1
- else linecount := 0;
- end;
- end;
- end;
- 1 : if (linecount <= p1) then print := TRUE;
- 2 : if (linecount > p1) then print := TRUE;
- 3 : if (length(line) <= 0) then
- begin
- if (i < p1) then
- begin
- print := TRUE;
- i := i + 1;
- end;
- end
- else
- begin
- print := TRUE;
- i := 0;
- end;
- 5 : if (i < (p1 - 1)) then
- begin
- write(line);
- if ((p2 > 0) and ((length(line) + 1) < (p2 - 1))) then
- for j := (length(line) + 1) to (p2 - 1) do
- write(' ');
- write(paramstr(4));
- i := i + 1;
- end
- else
- begin
- print := TRUE;
- i := 0;
- end;
- 6 : if (pos(paramstr(4),line) > 0) then print := TRUE;
- 7 : if (pos(paramstr(4),line) = 0) then print := TRUE;
- 8 : begin
- line := copy(line,p1,p2);
- print := TRUE;
- end;
- 9 : begin
- delete(line,p1,p2);
- print := TRUE;
- end;
- 10 : begin
- insert(paramstr(4),line,p1);
- print := TRUE;
- end;
- 11 : begin
- i := pos(paramstr(4),line);
- if (i > 0) then
- begin
- delete(line,i,length(paramstr(4)));
- insert(paramstr(5),line,i);
- end;
- print := TRUE;
- end;
- 12 : begin
- cypher;
- print := TRUE;
- end;
- 13,
- 14 : begin
- if (pos(paramstr(4),line) > 0) then found := TRUE;
- if (found = TRUE) then
- if (func = 13) then
- begin
- if (phone_number) then dialout;
- end
- else print := TRUE;
- if (length(line) <= 0) then found := FALSE;
- end;
- 15 : begin
- for n := 1 to fields do
- begin
- wort := copy(line,fpos[n],flen[n]);
- writeln(wort);
- end;
- print := false;
- end;
- end;
- end;
-
-
- begin
- if (paramcount < 4) then
- begin
- writeln(paramstr(0),' <function> <p1> <p2> <string> [<string2>]');
- writeln('function:');
- writeln(' 0 - Write every line to stdout; pause after <p1> lines.');
- writeln(' 1 - Write only first <p1> lines.');
- writeln(' 2 - Skip first <p1> lines.');
- writeln(' 3 - Write max.<p1> blank lines.');
- writeln(' 4 - Like function 0 - plus write also to file <string>.');
- writeln(' 5 - Concatenate <p1> lines;blank to col <p2>;write <string> in between.');
- writeln(' 6 - Write only lines that contain <string>.');
- writeln(' 7 - Write only lines that do not contain <string>.');
- writeln(' 8 - Extract substring at pos <p1> with length <p2> from every line.');
- writeln(' 9 - Delete substring at pos <p1> with length <p2> from every line.');
- writeln(' 10 - Insert <string> at pos <p1> in every line.');
- writeln(' 11 - Replace <string> with <string2> only once every line.');
- writeln(' 12 - Cypher/Uncypher every line with <string>.');
- writeln(' 13 - Find <string> in paragraph, then dial <string2>+#phone#.');
- writeln(' 14 - Write only paragraphs that contain <string>.');
- writeln(' 15 - Break lines in fields; Will ask for parameters.');
- exit;
- end;
- val(paramstr(1),func,i);
- val(paramstr(2),p1,i);
- val(paramstr(3),p2,i);
-
- if (func = 4) then
- begin
- assign(out,paramstr(4));
- rewrite(out);
- end;
- if (func = 15) then
- begin
- write ('# of fields: '); readln(fields);
- for n := 1 to fields do
- begin
- write ('#',n:2,' pos: ');readln(fpos[n]);
- write ('#',n:2,' len: ');readln(flen[n]);
- end;
- end;
- std_inout;
- i := 0;
- linecount := 0;
- while not eof(input) do
- begin
- readln(line);
- linecount := linecount + 1;
- if (print) then writeln(line);
- end;
- if (func = 4) then close(out);
- end.
-