Advertisement
Guest User

Untitled

a guest
Oct 29th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. program fpc_template;
  2.  
  3. uses CRT,fileutil,sysutils;
  4.  
  5. var outputfile:file; console:text; inputfile: file of char;
  6. filename,filename2:string;
  7. n,count:longword; result:longint; clength,n2:byte;
  8. buffer: array of byte; buffer2: shortstring; buffer3:byte;
  9. wait:boolean;
  10.  
  11. begin
  12. clrscr;
  13.  
  14. //sets filenames and delimiter
  15. wait:=false;
  16. filename:='output.txt';
  17. filename2:='output.vxl';
  18.  
  19. //checks command line parameters
  20. if (ParamCount >0) and (ParamStr(1)<>'0') then filename:=ParamStr(1);
  21. if (ParamCount >1) and (ParamStr(2)<>'0') then filename2:=ParamStr(2);
  22. if (ParamCount >2) and (ParamStr(3)='wait') then wait:=true;
  23.  
  24. assign(inputfile,filename);
  25. assign(outputfile,filename2);
  26. assigncrt(console);
  27. rewrite(console);
  28.  
  29. //outputs parameters to console
  30. writeln(console,paramstr(0));
  31. writeln('input - ',filename, ' (',fileutil.filesize(filename)/1000000:0:2,'MB) output - ',filename2);
  32. writeln;
  33.  
  34. //reads values to memory
  35. count:=0; result:=0;
  36. reset(inputfile,1);
  37. count:=system.filesize(inputfile); //gets the amount of characters
  38. writeln(console,count,' characters found, reading...');
  39. setlength(buffer,count); //sets array length to fit the characters
  40. blockread(inputfile,buffer[0],count,result); // fills the array
  41. writeln(console,result,' characters read, parsing...');
  42. close(inputfile);
  43.  
  44. //does stuff
  45. rewrite(outputfile,1);
  46. n:=0; clength:=0; result:=0;
  47.  
  48. for n:=0 to length(buffer) do
  49. begin
  50. 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
  51. begin //is a number
  52. clength:=clength+1;
  53. end
  54. else
  55. begin //is a delimiter
  56. if (n < length(buffer)) then
  57. begin
  58. for n2:=clength downto 1 do
  59. begin //for each character in current selection (if not the last number)
  60. buffer2:=buffer2+chr(buffer[n-n2]);
  61. end;
  62. // writes value to file
  63. clength:=0;
  64. end
  65. else begin
  66. for n2:=clength downto 1 do
  67. begin //for each character in current selection (if last number)
  68. buffer2:=buffer2+chr(buffer[n-n2]);
  69. end;
  70. end;
  71. end;
  72.  
  73. //WRITES VALUES
  74. if buffer2<>'' then buffer3:=byte(strtoint(buffer2));
  75. if buffer2<>'' then
  76. begin
  77. blockwrite(outputfile,buffer3,sizeof(buffer3));
  78. result:=result+1;
  79. end;
  80. buffer2:='';
  81.  
  82. //(optional) updates info text
  83. if (n mod (trunc(length(buffer)/20)+1) = 0) then
  84. begin
  85. gotoxy(1,wherey);
  86. write(console,trunc(n/length(buffer)*100),' %',' - ',n,' out of ',length(buffer)); //updates every 5 percent
  87. end;
  88. end;
  89.  
  90. gotoxy(1,wherey);
  91. write(console,trunc(trunc(n/length(buffer)*100)),' %',' - ',n,' out of ',length(buffer)); //last update when 100% done
  92. writeln(console);
  93. close(outputfile);
  94.  
  95. reset(outputfile);
  96. writeln(console,result,' values written to ',filename2,' (',fileutil.filesize(filename2)/1000000:0:2,'MB)');
  97. close(outputfile);
  98.  
  99. //optional info if wait is true
  100. if wait = true then
  101. begin
  102. writeln(console,'program finished, press any key to quit.');
  103. readkey;
  104. end;
  105.  
  106. close(console);
  107.  
  108. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement