Advertisement
Guest User

Untitled

a guest
Oct 28th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. program fpc_template;
  2.  
  3. uses CRT,fileutil,sysutils;
  4.  
  5. var inputfile:file; outputfile,console:text;
  6. filename,filename2,delimiter:string;
  7. n,count:longword; result:longint;
  8. buffer: array of byte;
  9. wait:boolean;
  10.  
  11. begin
  12. clrscr;
  13.  
  14. //sets filenames and delimiter
  15. delimiter:=',';
  16. wait:=false;
  17. filename:='input.vxl';
  18. filename2:='output.txt';
  19.  
  20. //checks command line parameters
  21. if (ParamCount >0) and (ParamStr(1)<>'0') then filename:=ParamStr(1);
  22. if (ParamCount >1) and (ParamStr(2)<>'0') then filename2:=ParamStr(2);
  23. if (ParamCount >2) and (ParamStr(3)<>'0') then delimiter:=ParamStr(3);
  24. if (ParamCount >3) and (ParamStr(4)='wait') then wait:=true;
  25.  
  26. assign(inputfile,filename);
  27. assign(outputfile,filename2);
  28. assigncrt(console);
  29. rewrite(console);
  30.  
  31. //outputs parameters to console
  32. writeln(console,paramstr(0));
  33. writeln('input - ',filename, ' (',fileutil.filesize(filename)/1000000:0:2,'MB) output - ',filename2);
  34. writeln;
  35.  
  36. //reads values to memory
  37. count:=0; result:=0;
  38. reset(inputfile,1);
  39. count:=system.filesize(inputfile); //gets the amount of values
  40. writeln(console,count,' bytes found, reading...');
  41. setlength(buffer,count); //sets array length to fit amount of values found
  42. blockread(inputfile, buffer[0], count, result); //fills the array
  43. writeln(console,result,' bytes read, outputting to file...');
  44. close(inputfile);
  45.  
  46.  
  47. //writes values to file
  48. rewrite(outputfile);
  49. n:=0;
  50. while n<count-1 do
  51. begin
  52. write(outputfile,inttostr(buffer[n])+delimiter); //writes count-1 values
  53. n:=n+1;
  54. end;
  55. write(outputfile,buffer[count-1]); //writes the last value, so there is no delimiter at end
  56. close(outputfile);
  57.  
  58. reset(outputfile);
  59. writeln(console,count,' values written to ',filename2,' (',fileutil.filesize(filename2)/1000000:0:2,'MB)');
  60. close(outputfile);
  61.  
  62. //optional info if wait is true
  63. if wait = true then
  64. begin
  65. writeln(console,'program finished, press any key to quit.');
  66. readkey;
  67. end;
  68.  
  69. close(console);
  70.  
  71. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement