Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program fpc_template;
- uses CRT,fileutil,sysutils;
- var outputfile:file; console:text; inputfile: file of char;
- filename,filename2:string;
- n,count:longword; result:longint; clength,n2:byte;
- buffer: array of byte; buffer2: shortstring; buffer3:byte;
- wait:boolean;
- begin
- clrscr;
- //sets filenames and delimiter
- wait:=false;
- filename:='output.txt';
- filename2:='output.vxl';
- //checks command line parameters
- if (ParamCount >0) and (ParamStr(1)<>'0') then filename:=ParamStr(1);
- if (ParamCount >1) and (ParamStr(2)<>'0') then filename2:=ParamStr(2);
- if (ParamCount >2) and (ParamStr(3)='wait') then wait:=true;
- assign(inputfile,filename);
- assign(outputfile,filename2);
- assigncrt(console);
- rewrite(console);
- //outputs parameters to console
- writeln(console,paramstr(0));
- writeln('input - ',filename, ' (',fileutil.filesize(filename)/1000000:0:2,'MB) output - ',filename2);
- writeln;
- //reads values to memory
- count:=0; result:=0;
- reset(inputfile,1);
- count:=system.filesize(inputfile); //gets the amount of characters
- writeln(console,count,' characters found, reading...');
- setlength(buffer,count); //sets array length to fit the characters
- blockread(inputfile,buffer[0],count,result); // fills the array
- writeln(console,result,' characters read, parsing...');
- close(inputfile);
- //does stuff
- rewrite(outputfile,1);
- n:=0; clength:=0; result:=0;
- for n:=0 to length(buffer) do
- begin
- if (ord(buffer[n])>47) and (ord(buffer[n])< 58) and (n<length(buffer)) then //checks if current number is a number, not the last
- begin //is a number
- clength:=clength+1;
- end
- else
- begin //is a delimiter
- if (n < length(buffer)) then
- begin
- for n2:=clength downto 1 do
- begin //for each character in current selection (if not the last number)
- buffer2:=buffer2+chr(buffer[n-n2]);
- end;
- // writes value to file
- clength:=0;
- end
- else begin
- for n2:=clength downto 1 do
- begin //for each character in current selection (if last number)
- buffer2:=buffer2+chr(buffer[n-n2]);
- end;
- end;
- end;
- //WRITES VALUES
- if buffer2<>'' then buffer3:=byte(strtoint(buffer2));
- if buffer2<>'' then
- begin
- blockwrite(outputfile,buffer3,sizeof(buffer3));
- result:=result+1;
- end;
- buffer2:='';
- //(optional) updates info text
- if (n mod (trunc(length(buffer)/20)+1) = 0) then
- begin
- gotoxy(1,wherey);
- write(console,trunc(n/length(buffer)*100),' %',' - ',n,' out of ',length(buffer)); //updates every 5 percent
- end;
- end;
- gotoxy(1,wherey);
- write(console,trunc(trunc(n/length(buffer)*100)),' %',' - ',n,' out of ',length(buffer)); //last update when 100% done
- writeln(console);
- close(outputfile);
- reset(outputfile);
- writeln(console,result,' values written to ',filename2,' (',fileutil.filesize(filename2)/1000000:0:2,'MB)');
- close(outputfile);
- //optional info if wait is true
- if wait = true then
- begin
- writeln(console,'program finished, press any key to quit.');
- readkey;
- end;
- close(console);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement