Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simple text file reader-viewer line by line for Linux | in free pascal |
- program fr;
- // programmer: Aleksandar Josifoski josifoski@gmail.com
- // reading text file line by line
- // j for next k for previous g for first G for last line q for quit
- {$mode objfpc}{$H+}
- uses Unix, keyboard, sysutils;
- var
- f : Text;
- L, i, j : Longint;
- ar: array[1..100000] of String;
- si, sj : String;
- K : TKeyEvent;
- stcomm : String;
- begin
- InitKeyBoard;
- if (ParamStr(1)='') or (FileExists(ParamStr(1))=false) then begin
- writeln('Simple file reader-viewer line by line');
- writeln('Usage is fr YourFile');
- writeln('Shortcuts: j next, k previous, g first, G last line, q or ESC quit');
- DoneKeyBoard;
- Halt;
- end;
- stcomm:='tr -s ''\n'' <'+ParamStr(1)+' >frfile';
- L:= FpSystem(stcomm);
- L:= FpSystem('clear');
- AssignFile(f, 'frfile');
- reset(f);
- j:=0;
- while not(eof(f)) do begin
- j:=j+1;
- readln(f, ar[j]);
- end; // while
- CloseFile(f);
- if j=0 then begin
- writeln('empty file, exit');
- DoneKeyBoard;
- Halt;
- end;
- i:=1;
- str(j, sj);
- str(i, si);
- writeln(si+'/'+sj);
- writeln();
- writeln();
- write(ar[i]);
- repeat
- K:=GetKeyEvent;
- K:=TranslateKeyEvent(K);
- case GetKeyEventChar(K) of
- 'j' : if i < j then begin
- L:= FpSystem('clear');
- i:=i+1;
- str(i, si);
- writeln(si+'/'+sj);
- writeln();
- writeln();
- write(ar[i]);
- end;
- 'k' : if i > 1 then begin
- L:= FpSystem('clear');
- i:=i-1;
- str(i, si);
- writeln(si+'/'+sj);
- writeln();
- writeln();
- write(ar[i]);
- end;
- 'g' : begin
- L:= FpSystem('clear');
- i:=1;
- str(i, si);
- writeln(si+'/'+sj);
- writeln();
- writeln();
- write(ar[i]);
- end;
- 'G' : begin
- L:= FpSystem('clear');
- i:=j;
- str(i, si);
- writeln(si+'/'+sj);
- writeln();
- writeln();
- write(ar[i]);
- end;
- 'q' : L:= FpSystem('clear');
- #27 : L:= FpSystem('clear');
- end;
- until (GetKeyEventChar(K)='q') or (GetKeyEventChar(K)=#27);
- DoneKeyBoard;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement