Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for txtcomp.rex

(view source code of txtcomp.rex as plain text)

  1. /* Initialize RexxUtil */
  2. Call RxFuncAdd "sysloadfuncs", "RexxUtil", "sysloadfuncs"
  3. Call sysloadfuncs
  4.  
  5. /* Default definitions                              */
  6. /* Names of files to contain differences            */
  7. f1min2 = "FILE1-2.RST"
  8. f2min1 = "FILE2-1.RST"
  9. /* Case sensitive compare, unless /I option is used */
  10. case = 1
  11. /* No header in files */
  12. header = 0
  13. /* Language US unless otherwise specified by /L:cc  */
  14. language = "US"
  15. /* No line numbers unless /N option is specified    */
  16. numline = 0
  17.  
  18. /* Command line parsing                             */
  19. Parse Upper Arg cmdline
  20. Do i = 1 By 1 Until cmdline = ""
  21. 	Parse Value cmdline With param.i cmdline
  22. End
  23. param.0 = i
  24.  
  25. cfile.0 = 0
  26. Do i = 1 To param.0
  27. 	param.i = Strip( param.i )
  28. 	If Left( param.i, 1 ) = "/" Then Do
  29. 		option = SubStr( param.i, 2, 1 )
  30. 		Select
  31. 			When option = "H" Then Do
  32. 				header = 1
  33. 			End
  34. 			When option = "I" Then Do
  35. 				case = 0
  36. 			End
  37. 			When option = "L" Then Do
  38. 				chck = SubStr( param.i, 3, 1 )
  39. 				If chck <> ":" Then Call Syntax
  40. 				lng  = SubStr( param.i, 4, 2 )
  41. 				If lng <> "NL" & lng <> "US" Then Do
  42. 					Call Syntax
  43. 				End
  44. 				Else Do
  45. 					language = lng
  46. 				End
  47. 			End
  48. 			When option = "N" Then Do
  49. 				numline = 1
  50. 			End
  51. 			Otherwise Do
  52. 				Call Syntax
  53. 			End
  54. 		End
  55. 	End
  56. 	Else Do
  57. 		files       = cfile.0 + 1
  58. 		cfile.0     = files
  59. 		cfile.files = param.i
  60. 		If cfile.0 > 2 Then Call Syntax
  61. 	End
  62. End
  63. If cfile.0 <> 2 Then Call Syntax
  64.  
  65. /* Select language specific message */
  66. Call SetLanguage
  67.  
  68. /* Check if input files do exist */
  69. If Exist( cfile.1 ) <> 1 | Exist( cfile.2 ) <> 1 Then Do
  70. 	Call SysCls
  71. 	Say
  72. 	Call Beep 220, 250
  73. 	Say infile_not_found
  74. 	Say
  75. 	Say any_key
  76. 	Call SysCurState "OFF"
  77. 	Call SysGetKey "NOECHO"
  78. 	Call SysCls
  79. 	Call Syntax
  80. End
  81.  
  82. /* Check if output files already exist */
  83. Call diffexist
  84.  
  85. /* Read first file */
  86. Say reading_cfile_1
  87. file.1.  = ""
  88. file.1.0 = 1
  89. file.1.1 = LineIn( cfile.1, 1, 1 )
  90. If Strip( file.1.1 ) = "" & Lines( cfile.1 ) = 0 Then Do
  91. 	file.1.0 = 0
  92. End
  93. Else Do
  94. 	i = 1
  95. 	Do Until Lines( cfile.1 ) = 0
  96. 		i = i + 1
  97. 		file.1.i = LineIn( cfile.1, , 1 )
  98. 	End
  99. 	file.1.0 = i
  100. End
  101. Say cfile_1_read
  102.  
  103. /* Read second file */
  104. Say reading_cfile_2
  105. file.2.  = ""
  106. file.2.0 = 1
  107. file.2.1 = LineIn( cfile.2, 1, 1 )
  108. If Strip( file.2.1 ) = "" & Lines( cfile.2 ) = 0 Then Do
  109. 	file.2.0 = 0
  110. End
  111. Else Do
  112. 	i = 1
  113. 	Do Until Lines( cfile.2 ) = 0
  114. 		i = i + 1
  115. 		file.2.i = LineIn( cfile.2, , 1 )
  116. 	End
  117. 	file.2.0 = i
  118. End
  119. Say cfile_2_read
  120.  
  121. /* Compare files one way */
  122. file1minus2.  = ""
  123. file1minus2.0 = file.1.0
  124. file2minus1.  = ""
  125. file2minus1.0 = file.2.0
  126. Call SysCls
  127. Say comparing_1_2
  128. Say "   0%"
  129. Do i = 1 To file.1.0
  130. 	add2file = 1
  131. 	Do j = 1 To file.2.0
  132. 		If case = 0 Then Do
  133. 			If Translate( file.1.i ) = Translate( file.2.j ) Then add2file = 0
  134. 		End
  135. 		Else Do
  136. 			If file.1.i = file.2.j Then add2file = 0
  137. 		End
  138. 	End
  139. 	If add2file = 1 Then Do
  140. 		If numline = 1 Then num1minus2.i = Right( i||";  ", 8 )
  141. 		file1minus2.i = file.1.i
  142. 	End
  143. 	percentage = ( i * 100 ) % file.1.0
  144. 	Call SysCls
  145. 	Say comparing_1_2
  146. 	Say Right( percentage||"%", 5 )
  147. End
  148. Say comp_1_2_ended
  149.  
  150. Call SysCls
  151. Say comparing_2_1
  152. Say "   0%"
  153. Do i = 1 To file.2.0
  154. 	add2file = 1
  155. 	Do j = 1 To file.1.0
  156. 		If case = 0 Then Do
  157. 			If Translate( file.2.i ) = Translate( file.1.j ) Then add2file = 0
  158. 		End
  159. 		Else Do
  160. 			If file.2.i = file.1.j Then add2file = 0
  161. 		End
  162. 	End
  163. 	If add2file = 1 Then Do
  164. 		If numline = 1 Then num2minus1.i = Right( i||";  ", 8 )
  165. 		file2minus1.i = file.2.i
  166. 	End
  167. 	percentage = ( i * 100 ) % file.2.0
  168. 	Call SysCls
  169. 	Say comparing_2_1
  170. 	Say Right( percentage||"%", 5 )
  171. End
  172. Call SysCls
  173. Say comp_2_1_ended
  174.  
  175. j = 0
  176. If file1minus2.0 > 0 Then Do
  177. 	Call SysCls
  178. 	Say writing_diff_1_2
  179. 	Say "   0%"
  180. 	If header = 1 Then Do
  181. 		Call LineOut f1min2, header_1_2
  182. 	End
  183. 	Do i = 1 To file1minus2.0
  184. 		If file1minus2.i <> "" Then Do
  185. 			If numline = 1 Then Do
  186. 				Call LineOut f1min2, num1minus2.i||file1minus2.i
  187. 			End
  188. 			Else Do
  189. 				Call LineOut f1min2, file1minus2.i
  190. 			End
  191. 			j = j + 1
  192. 		End
  193. 		percentage = ( i * 100 ) % file1minus2.0
  194. 		Call SysCls
  195. 		Say writing_diff_1_2
  196. 		Say Right( percentage||"%", 5 )
  197. 	End
  198. 	Call LineOut f1min2
  199. 	Call SysCls
  200. 	Say diff_1_2_written
  201. End
  202.  
  203. j = 0
  204. If file2minus1.0 > 0 Then Do
  205. 	Call SysCls
  206. 	Say writing_diff_2_1
  207. 	Say "   0%"
  208. 	If header = 1 Then Do
  209. 		Call LineOut f2min1, header_2_1
  210. 	End
  211. 	Do i = 1 To file2minus1.0
  212. 		If file2minus1.i <> "" Then Do
  213. 			If numline = 1 Then Do
  214. 				Call LineOut f2min1, num2minus1.i||file2minus1.i
  215. 			End
  216. 			Else Do
  217. 				Call LineOut f2min1, file2minus1.i
  218. 			End
  219. 			j = j + 1
  220. 		End
  221. 		percentage = ( i * 100 ) % file2minus1.0
  222. 		Call SysCls
  223. 		Say writing_diff_2_1
  224. 		Say Right( percentage||"%", 5 )
  225. 	End
  226. 	Call LineOut f2min1
  227. 	Call SysCls
  228. 	Say diff_2_1_written
  229. End
  230. Say
  231. exit
  232.  
  233.  
  234. exist: procedure
  235. 	Call SysFileTree arg( 1 ), "found.", "F"
  236. Return found.0
  237.  
  238.  
  239. Syntax:
  240. 	Select
  241. 		When language = "NL" Then Call SyntaxNL
  242. 		Otherwise Call SyntaxUS
  243. 	End
  244. Return
  245.  
  246.  
  247. SyntaxNL:
  248. 	Call SysCls
  249. 	Say
  250. 	Say " ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  251. 	Say " º  Programma      :  TxtComp                                                º"
  252. 	Say " º  Versie         :  2.10                                                   º"
  253. 	Say " º  Auteur         :  Rob van der Woude                                      º"
  254. 	Say " º  Rechten        :  Freeware, 'as is', (C) 1997-2003, Rob van der Woude    º"
  255. 	Say " º  Datum          :  31-08-1997                                             º"
  256. 	Say " º  Laatste rev.   :  02-03-2003                                             º"
  257. 	Say " º  Functie        :  Vergelijkt 2 bestanden en cre‰ert 2 nieuwe waarin      º"
  258. 	Say " º                    slechts die regels worden gezet die ofwel van elkaar   º"
  259. 	Say " º                    verschillen in de oorspronkelijke bestanden ofwel in   º"
  260. 	Say " º                    ‚‚n van de twee ontbreken.                             º"
  261. 	Say " º  Syntax         :  TXTCOMP file1 file2 [/I] [/H] [/N]                     º"
  262. 	Say " º  Parameters     :  /I     geen onderscheid hoofd- en kleine letters       º"
  263. 	Say " º                    /H     plaatst kopregel met bestandsinformatie         º"
  264. 	Say " º                    /L:cc  kies andere taal, cc kan NL of US zijn          º"
  265. 	Say " º                    /N     zet regelnummer-referenties voor elke regel     º"
  266. 	Say " º  Opmerkingen    :  TxtComp zal 2 nieuwe bestanden cre‰ren:                º"
  267. 	Say " º                    FILE1-2.RST bevat alleen die regels uit file1 die      º"
  268. 	Say " º                    ofwel verschillen van file2 of in file2 ontbreken;     º"
  269. 	Say " º                    FILE2-1.RST bevat alleen die regels uit file2 die      º"
  270. 	Say " º                    ofwel verschillen van file1 of in file1 ontbreken.     º"
  271. 	Say " ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  272. 	exit
  273. Return
  274.  
  275.  
  276. SyntaxUS:
  277. 	Call SysCls
  278. 	Say
  279. 	Say " ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»"
  280. 	Say " º  Program        :  TxtComp                                                º"
  281. 	Say " º  Version        :  2.10                                                   º"
  282. 	Say " º  Author         :  Rob van der Woude                                      º"
  283. 	Say " º  Legal status   :  Freeware, as is, (C) 1997-2003, Rob van der Woude      º"
  284. 	Say " º  Date           :  08/31/1997                                             º"
  285. 	Say " º  Last revision  :  02/03/2003                                             º"
  286. 	Say " º  Function       :  Compares 2 files and creates 2 new files containing    º"
  287. 	Say " º                    only those lines that were found to be either          º"
  288. 	Say " º                    different or not present at all in either of the       º"
  289. 	Say " º                    original files.                                        º"
  290. 	Say " º  Usage          :  TXTCOMP file1 file2 [/I] [/H] [/N]                     º"
  291. 	Say " º  Parameters     :  /I     ignores case during compare                     º"
  292. 	Say " º                    /H     places info in header of files to be created    º"
  293. 	Say " º                    /L:cc  choose different language, cc may be NL or US   º"
  294. 	Say " º                    /N     places line number references before each line  º"
  295. 	Say " º  Remarks        :  TxtComp will create 2 new files:                       º"
  296. 	Say " º                    FILE1-2.RST contains only those lines of file1         º"
  297. 	Say " º                    that are either different from or absent in file2;     º"
  298. 	Say " º                    FILE2-1.RST contains only those lines of file2         º"
  299. 	Say " º                    that are either different from or absent in file1.     º"
  300. 	Say " ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ"
  301. 	exit
  302. Return
  303.  
  304.  
  305. diffexist:
  306. 	Call SysFileTree f1min2, "exist1.", "F"
  307. 	Call SysFileTree f2min1, "exist2.", "F"
  308. 	If exist1.0 = 1 | exist2.0 = 1 Then Do
  309. 		Call SysCls
  310. 		Say
  311. 		Call Beep 220, 250
  312. 		Say diff_file_exist
  313. 		Say remove_or_rename
  314. 		Say
  315. 		Say any_key
  316. 		Call SysCurState "OFF"
  317. 		Call SysGetKey "NOECHO"
  318. 		exit
  319. 	End
  320. Return
  321.  
  322.  
  323. SetLanguage:
  324. 	Select
  325. 		When language = "NL" Then Do
  326. 			any_key           = "Druk op een willekeurige toets . . ."
  327. 			cfile_1_read      = cfile.1||" ingelezen"
  328. 			cfile_2_read      = cfile.2||" ingelezen"
  329. 			comparing_1_2     = "Inhoud "||cfile.1||" wordt vergeleken met "||cfile.2||" . . ."
  330. 			comparing_2_1     = "Inhoud "||cfile.2||" wordt vergeleken met "||cfile.1||" . . ."
  331. 			comp_1_2_ended    = "Inhoud "||cfile.1||" vergeleken met "||cfile.2
  332. 			comp_2_1_ended    = "Inhoud "||cfile.2||" vergeleken met "||cfile.1
  333. 			diff_1_2_written  = "Verschillen tussen "||cfile.1||" en "||cfile.2||" weggeschreven"
  334. 			diff_2_1_written  = "Verschillen tussen "||cfile.2||" en "||cfile.1||" weggeschreven"
  335. 			diff_file_exist   = "Bestand "||f1min2||" en/of "||f2min1||" bestaat reeds."
  336. 			header_1_2        = "; Regels die wel in "||cfile.1||" maar niet in "||cfile.2||" voorkomen."||"0D0A"X
  337. 			header_2_1        = "; Regels die wel in "||cfile.2||" maar niet in "||cfile.1||" voorkomen."||"0D0A"X
  338. 			If numline = 1 Then Do
  339. 				header_1_2 = header_1_2||";**** Regelnummers in "||cfile.1||"0D0A"X
  340. 				header_2_1 = header_2_1||";**** Regelnummers in "||cfile.2||"0D0A"X
  341. 			End
  342. 			infile_not_found  = "Opgegeven bestand(en) niet gevonden."
  343. 			reading_cfile_1   = cfile.1||" wordt ingelezen . . ."
  344. 			reading_cfile_2   = cfile.2||" wordt ingelezen . . ."
  345. 			remove_or_rename  = "Verwijder of hernoem de bestanden en probeer opnieuw."
  346. 			writing_diff_1_2  = "Verschillen tussen "||cfile.1||" en "||cfile.2||" worden weggeschreven . . ."
  347. 			writing_diff_2_1  = "Verschillen tussen "||cfile.2||" en "||cfile.1||" worden weggeschreven . . ."
  348. 		End
  349. 		Otherwise Do
  350. 			any_key           = "Press any key . . ."
  351. 			cfile_1_read      = cfile.1||" read"
  352. 			cfile_2_read      = cfile.2||" read"
  353. 			comparing_1_2     = "Comparing "||cfile.1||" with "||cfile.2||" . . ."
  354. 			comparing_2_1     = "Comparing "||cfile.2||" with "||cfile.1||" . . ."
  355. 			comp_1_2_ended    = "Compare of "||cfile.1||" and "||cfile.2||" ended"
  356. 			comp_2_1_ended    = "Compare of "||cfile.2||" and "||cfile.1||" ended"
  357. 			diff_1_2_written  = "Differences between "||cfile.1||" and "||cfile.2||" written"
  358. 			diff_2_1_written  = "Differences between "||cfile.2||" and "||cfile.1||" written"
  359. 			diff_file_exist   = "File "||f1min2||" and/or "||f2min1||" already exists."
  360. 			header_1_2        = "; Lines found in "||cfile.1||" but not in "||cfile.2||"0D0A"X
  361. 			header_2_1        = "; Lines found in "||cfile.2||" but not in "||cfile.1||"0D0A"X
  362. 			If numline = 1 Then Do
  363. 				header_1_2 = header_1_2||";**** Line numbers as in "||cfile.1||"0D0A"X
  364. 				header_2_1 = header_2_1||";**** Line numbers as in "||cfile.2||"0D0A"X
  365. 			End
  366. 			infile_not_found  = "Input file(s) not found."
  367. 			reading_cfile_1   = "Reading "||cfile.1||" . . ."
  368. 			reading_cfile_2   = "Reading "||cfile.2||" . . ."
  369. 			remove_or_rename  = "Remove or rename these files and try again."
  370. 			writing_diff_1_2  = "Writing differences between "||cfile.1||" and "||cfile.2||" to file . . ."
  371. 			writing_diff_2_1  = "Writing differences between "||cfile.2||" and "||cfile.1||" to file . . ."
  372. 		End
  373. 	End
  374. Return
  375.  

page last modified: 2024-04-16; loaded in 0.0084 seconds