Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program fpc_template;
- uses CRT,fileutil,sysutils;
- var inputfile:file; outputfile,console:text;
- filename,filename2,delimiter:string;
- n,count:longword; result:longint;
- buffer: array of byte;
- wait:boolean;
- begin
- clrscr;
- //sets filenames and delimiter
- delimiter:=',';
- wait:=false;
- filename:='input.vxl';
- filename2:='output.txt';
- //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)<>'0') then delimiter:=ParamStr(3);
- if (ParamCount >3) and (ParamStr(4)='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 values
- writeln(console,count,' bytes found, reading...');
- setlength(buffer,count); //sets array length to fit amount of values found
- blockread(inputfile, buffer[0], count, result); //fills the array
- writeln(console,result,' bytes read, outputting to file...');
- close(inputfile);
- //writes values to file
- rewrite(outputfile);
- n:=0;
- while n<count-1 do
- begin
- write(outputfile,inttostr(buffer[n])+delimiter); //writes count-1 values
- n:=n+1;
- end;
- write(outputfile,buffer[count-1]); //writes the last value, so there is no delimiter at end
- close(outputfile);
- reset(outputfile);
- writeln(console,count,' 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