home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ted99107.zip / TextEdit.CMD next >
OS/2 REXX Batch file  |  1999-04-17  |  43KB  |  1,670 lines

  1. /*
  2.  * Generator   : PPWIZARD version 99.106
  3.  *             : FREE tool for OS/2, Windows, DOS and UNIX by Dennis Bareis (db0@anz.com)
  4.  *             : http://www.labyrinth.net.au/~dbareis/ppwizard.htm
  5.  * Time        : Saturday, 17 Apr 1999 9:14:25am
  6.  * Input File  : E:\DB\PROJECTS\OS2\textedit\TEXTEDIT.x
  7.  * Output File : .\OUT\TextEdit.CMD
  8.  */
  9.  
  10. /*
  11. *$Header:E:/DB/PVCS.IT/OS2/TEXTEDIT/TEXTEDIT.X_V 1.5 17 Apr 1999 08:54:12 Dennis_Bareis $/PLATFORM/TEXTEDIT.X_V 1.5 11 Oct 1996 16:40:40 Dennis_Bareis $/PLATFORM/TEXTEDIT.X_V 1.4 11 Oct 1996 16:26:28 Dennis_Bareis $/PLATFORM/TEXTEDIT.X_V 1.3 17 Sep 1996 10:51:38 Dennis_Bareis $
  12. */
  13. PgmVersion="99.107"
  14. CopyRightDisplayed='N'
  15. LimitDefines=''
  16. TabChar=d2c(9)
  17. trace off
  18. call RemoveColorCodes
  19. /*
  20. *$Header:E:/DB/PVCS.IT/OS2/TEXTEDIT/SAYIT.XHV 1.1 25 Jul 1998 16:04:10 Dennis_Bareis $
  21. */
  22. if translate(strip(arg(1)))='DEBUG' then
  23. call DisplayCopyright
  24. /*
  25. *REXSYSTM.XH Version 99.092 By Dennis Bareis
  26. *http://www.labyrinth.net.au/~dbareis/index.htm(db0@anz.com)
  27. */
  28. parse version RexVersionInfo
  29. if pos('REGINA',translate(RexVersionInfo))<>0 then
  30. RexWhich='REGINA'
  31. else
  32. RexWhich='STANDARD_OS/2'
  33. parse source RexSystemOpSys .
  34. if RexSystemOpSys="WIN32" then
  35. do
  36. parse value uname()with RexSystemOpSys .
  37. if RexSystemOpSys<> "WIN95" & RexSystemOpSys <> "WIN98" & RexSystemOpSys <> "WINNT" then
  38. do
  39. call RexSystemFailure 'Regina uname() returned "' || uname() || '" (expected WIN95, WIN98 or WINNT)'
  40. end
  41. end
  42. RexSystmRexxPgmName='?';RexSystmRexxPgmName=RexGetFullSourceName()
  43. if arg(2)<> '' then
  44. call RexSystemFailure 'ARG(2) contains unexpected data of ' || arg(2) || '.'
  45. if translate(strip(arg(1)))='DEBUG' then
  46. do
  47. call RexDumpSystemInfo
  48. exit(0)
  49. end
  50. if RexWhich='STANDARD_OS/2' then
  51. do
  52. call SetLocal
  53. RexEnvVarPool='OS2ENVIRONMENT'
  54. RexStdoutStream='STDOUT'
  55. RexStderrStream='STDERR'
  56. end
  57. else
  58. do
  59. OPTIONS 'NOEXT_COMMANDS_AS_FUNCS'
  60. numeric digits 11
  61. RexEnvVarPool='SYSTEM'
  62. RexStdoutStream='<stdout>'
  63. RexStderrStream='<stderr>'
  64. end
  65. if RexSystemOpSys<> "UNIX" then
  66. do
  67. RexDirChar='\'
  68. RexOptionChar='/'
  69. end
  70. else
  71. do
  72. RexDirChar='/'
  73. RexOptionChar='-'
  74. end
  75. signal EndREXSYSTMXh
  76. RexDumpSystemInfo:
  77. say 'Program Name  : ' ||RexSystmRexxPgmName
  78. say 'Op System     : ' ||RexSystemOpSys
  79. say 'Rexx Ver      : ' ||RexVersionInfo
  80. say 'Which System  : ' ||RexWhich
  81. if RexWhich='REGINA' then
  82. say 'regina uname(): ' ||uname()
  83. return
  84. RexNeedReginaWorkAround:
  85. if RexWhich='STANDARD_OS/2' then
  86. return('N')
  87. else
  88. return('Y')
  89. RexGetFullSourceName:
  90. parse source . . TmpRexxSrc
  91. if RexWhich='REGINA' then
  92. TmpRexxSrc=stream(strip(TmpRexxSrc), 'c', 'query exists')
  93. if TmpRexxSrc='' then
  94. call RexSystemFailure 'Could not determine the name of the rexx program!'
  95. return(TmpRexxSrc)
  96. RexQueryExists:
  97. return(stream(arg(1), 'c', 'query exists'))
  98. RexGetNameOfTmpDir:
  99. TmpDir=GetEnv('TMP')
  100. if TmpDir='' then
  101. TmpDir=GetEnv('TEMP')
  102. if TmpDir='' then
  103. do
  104. if RexSystemOpSys="UNIX" then
  105. TmpDir='/tmp'
  106. end
  107. return(TmpDir)
  108. Stderr2:
  109. if RexSystemOpSys="DOS" | RexSystemOpSys = "WIN95" | RexSystemOpSys = "WIN98" then
  110. return('')
  111. else
  112. return(' 2>' ||arg(1))
  113. AddressCmd:
  114. SysCmd2Exec=arg(1)
  115. if RexWhich='STANDARD_OS/2' then
  116. SysCmd2Exec='@' ||SysCmd2Exec
  117. SysCmd2Exec
  118. SysCmdRc=Rc
  119. return(SysCmdRc)
  120. _SysFileDelete:
  121. if RexSystemOpSys="DOS" | RexSystemOpSys = "WIN95" | RexSystemOpSys = "WIN98" then
  122. return(AddressCmd('if exist ' || arg(1) || ' del ' || arg(1) || ' >nul'))
  123. else
  124. do
  125. if RexSystemOpSys="UNIX" then
  126. return(AddressCmd('rm -f '  || arg(1) || ' >& /dev/null'))
  127. else
  128. return(AddressCmd('del ' || arg(1) || ' >nul' || Stderr2('&1')))
  129. end
  130. GetEnv:
  131. return(value(arg(1),,RexEnvVarPool))
  132. EndREXSYSTMXh:
  133. PpWizardPgmName=RexSystmRexxPgmName
  134. PpWizardOpSys=RexSystemOpSys
  135. if RexSystemOpSys="OS/2" then
  136. call SetColorCodes
  137. else
  138. call RemoveColorCodes
  139. signal on NOVALUE name RexxTrapUninitializedVariable
  140. signal on SYNTAX name RexxTrapSyntaxError
  141. call DisplayCopyright
  142. Parameters=arg(1)
  143. parse var Parameters TextFile TextFileOut ChangeFile Parameters
  144. if ChangeFile="" then
  145. UserSyntaxError("Too few parameters")
  146. if stream(TextFile, 'c', 'query exists') == '' then
  147. do
  148. say LightRed|| 'ERROR: The text input file "' || TextFile || '" does not exist....' ||Reset
  149. exit(60)
  150. end
  151. if stream(ChangeFile, 'c', 'query exists') == '' then
  152. do
  153. say LightRed|| 'ERROR: The change file "' || ChangeFile || '" does not exist....' ||Reset
  154. exit(65)
  155. end
  156. LineBeingProcessed=''
  157. LineSourceBeingProcessed=''
  158. LongestSourceInfo=0
  159. LinesWithTabsFound=0
  160. CmtLine=';'
  161. CmtInline='//'
  162. CmtLineLng=length(CmtLine)
  163. /*
  164. *$Header:E:/DB/PVCS.IT/OS2/TEXTEDIT/LOADFILE.XHV 1.2 17 Apr 1999 08:54:06 Dennis_Bareis $
  165. */
  166. signal EndLoadFile
  167. IoError:
  168. FileState=stream(arg(1), 'State')
  169. if FileState='READY' then
  170. return('NO')
  171. return(stream(arg(1), 'Description'))
  172. LoadTextFile:
  173. TextFileName=arg(1)
  174. AbsoluteTextFileName=stream(TextFileName, 'c', 'query exists')
  175. say ' * Text File   : ' ||TextFileName
  176. if AbsoluteTextFileName='' then
  177. return(52)
  178. if translate(AbsoluteTextFileName)<>translate(TextFileName)then
  179. do
  180. TextFileName=AbsoluteTextFileName
  181. say ' * Its FullName: ' ||TextFileName
  182. end
  183. TextFile.0=0
  184. CloseRc=stream(TextFileName, 'c', 'close')
  185. LinesRead=0
  186. do while lines(TextFileName)<>0
  187. ThisLine=linein(TextFileName)
  188. LinesRead=LinesRead+1
  189. TextFile.LinesRead=ThisLine
  190. end
  191. TextFile.0=LinesRead
  192. if IoError(TextFileName)='NO' then
  193. LoadRc=0
  194. else
  195. LoadRc=83
  196. CloseRc=stream(TextFileName, 'c', 'close')
  197. return(LoadRc)
  198. LoadChangeFile:
  199. if IncludeLevel=0 then
  200. do
  201. TotalChangeLineNumber=0
  202. ChangeFile.0=0
  203. end
  204. ChangeFile.File.IncludeLevel=arg(1)
  205. say copies("    ", IncludeLevel) || ' * Change File : ' ||ChangeFile.File.IncludeLevel
  206. AbsoluteTextFileName=stream(ChangeFile.File.IncludeLevel, 'c', 'query exists')
  207. if AbsoluteTextFileName=="" then
  208. do
  209. say 'ERROR: File "' || ChangeFile.File.IncludeLevel || '" does not exist!'
  210. return(113)
  211. end
  212. if translate(AbsoluteTextFileName)<>translate(ChangeFile.File.IncludeLevel)then
  213. do
  214. ChangeFile.File.IncludeLevel=AbsoluteTextFileName
  215. say copies("    ", IncludeLevel) || ' * Its FullName: ' ||AbsoluteTextFileName
  216. end
  217. ChangeFile.LineNumber.IncludeLevel=0
  218. LinesProcessed.IncludeLevel=0
  219. do while lines(ChangeFile.File.IncludeLevel)>0
  220. StrippedFileLine=strip(linein(ChangeFile.File.IncludeLevel))
  221. ChangeFile.LineNumber.IncludeLevel=ChangeFile.LineNumber.IncludeLevel+1
  222. if StrippedFileLine="" then
  223. iterate
  224. if pos(TabChar,StrippedFileLine)<>0 then
  225. LinesWithTabsFound=LinesWithTabsFound+1
  226. parse var StrippedFileLine HashInclude IncludeFileName
  227. if translate(HashInclude)='#INCLUDE' then
  228. do
  229. IncludeFileName=ReplaceHashAndStandardDefines(strip(IncludeFileName))
  230. if IncludeFileName="" then
  231. do
  232. say 'ERROR: No filename specified on #include statement!'
  233. return(164)
  234. end
  235. MaybeQuote=left(IncludeFileName,1)
  236. if MaybeQuote='"' | MaybeQuote = "<" then
  237. do
  238. if MaybeQuote='"' then
  239. ExpectAtEnd='"'
  240. else
  241. ExpectAtEnd='>'
  242. if right(IncludeFileName,1)<>ExpectAtEnd then
  243. do
  244. say 'ERROR: Incorrectly quoted filename of "' || IncludeFileName || '" specified on #include line!'
  245. return(180)
  246. end
  247. IncludeFileName=substr(IncludeFileName,2,length(IncludeFileName)-2)
  248. end
  249. IncludeLevel=IncludeLevel+1
  250. IncludeRc=LoadChangeFile(IncludeFileName)
  251. IncludeLevel=IncludeLevel-1
  252. if IncludeRc=0 then
  253. iterate
  254. else
  255. do
  256. call Stream ChangeFile.File.IncludeLevel, 'c', 'Close'
  257. return(IncludeRc)
  258. end
  259. end
  260. TotalChangeLineNumber=TotalChangeLineNumber+1
  261. ChangeFile.TotalChangeLineNumber=StrippedFileLine
  262. ChangeFile.SourceInfo.TotalChangeLineNumber=ChangeFile.File.IncludeLevel|| '(' || ChangeFile.LineNumber.IncludeLevel || ')'
  263. if length(ChangeFile.SourceInfo.TotalChangeLineNumber)>LongestSourceInfo then
  264. LongestSourceInfo=length(ChangeFile.SourceInfo.TotalChangeLineNumber)
  265. end
  266. if IoError(ChangeFile.File.IncludeLevel)='NO' then
  267. LoadRc=0
  268. else
  269. LoadRc=211
  270. call Stream ChangeFile.File.IncludeLevel, 'c', 'Close'
  271. ChangeFile.0=TotalChangeLineNumber
  272. return(LoadRc)
  273. EndLoadFile:
  274. /*
  275. *$Header:E:/DB/PVCS.IT/OS2/TEXTEDIT/HASHIF.XHV 1.0 13 May 1998 21:50:34 Dennis_Bareis $
  276. */
  277. IfNesting=0
  278. IfState.WantLines.0='Y'
  279. IfState.IfTrue.0='Y'
  280. IfState.InTrue.0='Y'
  281. signal EndHashIf
  282. WantLine:
  283. if IfNesting=0 then
  284. return('Y')
  285. if IfState.WantLines.IfNesting='N' then
  286. return('N')
  287. else
  288. do
  289. if IfState.IfTrue.IfNesting=IfState.InTrue.IfNesting then
  290. return('Y')
  291. else
  292. return('N')
  293. end
  294. ProcessHashIf:
  295. TestCondition=arg(1)
  296. WantTheLines=WantLine()
  297. if WantTheLines='N' then
  298. IfResult='N'
  299. else
  300. do
  301. call SayIfDebugOn 'COMMAND: #if ' ||TestCondition
  302. interpret 'IfResult = (' || strip( TestCondition ) || ')'
  303. if IfResult then
  304. IfResult='Y'
  305. else
  306. IfResult='N'
  307. if IfResult='Y' then
  308. call SayIfDebugOn '    #if: True'
  309. else
  310. call SayIfDebugOn '    #if: False'
  311. end
  312. IfNesting=IfNesting+1
  313. IfState.WantLines.IfNesting=WantTheLines
  314. IfState.InTrue.IfNesting='Y'
  315. IfState.IfTrue.IfNesting=IfResult
  316. return('OK')
  317. ProcessHashElse:
  318. if IfNesting=0 then
  319. return("Found #elseif without matching #if")
  320. if IfState.InTrue.IfNesting='N' then
  321. return("Found unexpected #elseif (duplicated #elseif?)")
  322. IfState.InTrue.IfNesting='N'
  323. return('OK')
  324. ProcessHashEndif:
  325. if IfNesting=0 then
  326. return("Found #endif without matching #if")
  327. IfNesting=IfNesting-1
  328. return('OK')
  329. EndHashIf:
  330. /*
  331. *$Header:E:/DB/PVCS.IT/OS2/TEXTEDIT/DEFINE.XHV 1.2 09 Mar 1999 17:38:10 Dennis_Bareis $
  332. */
  333. HashDefineCount=0
  334. G.StdVar.CurrentPosn=0
  335. G.StdVar.LastRc=0
  336. G.StdVar.LastRcReason=""
  337. G.StdVar.SyntaxError=0
  338. G.StdVar.TextFileIn=TextFile
  339. G.StdVar.TextFileOut=TextFileOut
  340. G.StdVar.ChangeFile=ChangeFile
  341. G.StdVar.Parameters=strip(Parameters)
  342. G.StdVar.ReplaceCount=0
  343. signal EndDefine
  344. HashDefineExists:
  345. do DefineIndex=1 to HashDefineCount
  346. if arg(1)=DefineVariable.DefineIndex then
  347. return(DefineIndex)
  348. end
  349. return('N')
  350. AddHashDefine:
  351. DefineVariable='{' || arg(1) || '}'
  352. DefineContents=arg(2)
  353. if pos(DefineVariable,DefineContents)<>0 then
  354. do
  355. say 'ERROR: #define of "' || DefineVariable || '" would cause infinite loop!'
  356. return(76)
  357. end
  358. ItExists=HashDefineExists(DefineVariable)
  359. if ItExists<> 'N' then
  360. do
  361. SaveIndex=ItExists
  362. end
  363. else
  364. do
  365. HashDefineCount=HashDefineCount+1
  366. SaveIndex=HashDefineCount
  367. end
  368. DefineVariable.SaveIndex=DefineVariable
  369. DefineContents.SaveIndex=DefineContents
  370. return(0)
  371. ReplaceHashAndStandardDefines:
  372. HashDefineString=arg(1)
  373. TotalChanges=0
  374. if LimitDefines='' then
  375. SearchAndReplaceUserDefines='Y'
  376. else
  377. do
  378. if pos(LimitDefines,HashDefineString)=0 then
  379. SearchAndReplaceUserDefines='N'
  380. else
  381. SearchAndReplaceUserDefines='Y'
  382. end
  383. if SearchAndReplaceUserDefines='Y' then
  384. do
  385. do until ChangeCount=0
  386. ChangeCount=0
  387. do DefineIndex=1 to HashDefineCount
  388. HashDefineString=ReplaceString(HashDefineString,DefineVariable.DefineIndex,DefineContents.DefineIndex, "ChangeCount")
  389. end
  390. TotalChanges=TotalChanges+ChangeCount
  391. end
  392. end
  393. HashDefineString=ReplaceStandardDefinitions(HashDefineString, "TotalChanges")
  394. if arg(2)<> '' then
  395. call value arg(2),TotalChanges
  396. return(HashDefineString)
  397. ReplaceStandardDefinitions:
  398. DefineString=arg(1)
  399. if(pos("${",DefineString)<>0)then
  400. do
  401. DefineString=ReplaceString(DefineString, "${CurrentPosn}",G.StdVar.CurrentPosn,arg(2))
  402. DefineString=ReplaceString(DefineString, "${RcReason}",G.StdVar.LastRcReason,arg(2))
  403. DefineString=ReplaceString(DefineString, "${Rc}",G.StdVar.LastRc,arg(2))
  404. DefineString=ReplaceString(DefineString, "${ReplaceCount}",G.StdVar.ReplaceCount,arg(2))
  405. if(pos("${",DefineString)<>0)then
  406. do
  407. DefineString=ReplaceString(DefineString, "${TextFileIn}",G.StdVar.TextFileIn,arg(2))
  408. DefineString=ReplaceString(DefineString, "${TextFileOut}",G.StdVar.TextFileOut,arg(2))
  409. DefineString=ReplaceString(DefineString, "${ChangeFile}",G.StdVar.ChangeFile,arg(2))
  410. DefineString=ReplaceString(DefineString, "${Parameters}",G.StdVar.Parameters,arg(2))
  411. if(pos("${",DefineString)<>0)then
  412. do
  413. DefineString=ReplaceString(DefineString, "${SyntaxErrorCount}",G.StdVar.SyntaxError,arg(2))
  414. DefineString=ReplaceString(DefineString, "${Version}",PgmVersion,arg(2))
  415. ChangeTime=date('Weekday') || ', ' || date() || ' ' ||GetAmPmTime()
  416. DefineString=ReplaceString(DefineString, "${ChangeTime}",ChangeTime,arg(2))
  417. DefineString=ReplaceString(DefineString, "${CurrentLine}",GetCurrentLineContents(),arg(2))
  418. end
  419. end
  420. end
  421. return(DefineString)
  422. ReplaceString:
  423. TheString=arg(1)
  424. ChangeFrom=arg(2)
  425. ChangeTo=arg(3)
  426. ChangeCntVar=arg(4)
  427. LimitChange=arg(5)
  428. if LimitChange='' then
  429. LimitChange=99999
  430. ChangeFromLength=length(ChangeFrom)
  431. ChangeToLength=length(ChangeTo)
  432. FoundPosn=pos(ChangeFrom,TheString)
  433. ReplaceStringCounter=0
  434. do while FoundPosn<>0&LimitChange>0
  435. TheString=left(TheString,FoundPosn-1)||ChangeTo||substr(TheString,FoundPosn+ChangeFromLength)
  436. FoundPosn=pos(ChangeFrom,TheString,FoundPosn+ChangeToLength)
  437. ReplaceStringCounter=ReplaceStringCounter+1
  438. LimitChange=LimitChange-1
  439. end
  440. if ChangeCntVar<> '' then
  441. call value ChangeCntVar,value(ChangeCntVar)+ReplaceStringCounter
  442. return(TheString)
  443. GetCurrentLineContents:
  444. TheCurrentLine=G.StdVar.CurrentPosn
  445. if TextFile.0=0 then
  446. TheCurrentLine="<FileEmpty>"
  447. else
  448. do
  449. if TheCurrentLine=0 then
  450. TheCurrentLine=TextFile.1
  451. else
  452. TheCurrentLine=TextFile.TheCurrentLine
  453. end
  454. return(TheCurrentLine)
  455. SetReturnCodeDefine:
  456. G.StdVar.LastRc=arg(1)
  457. SayTheRc=arg(3)
  458. if G.StdVar.LastRc=0 then
  459. G.StdVar.LastRcReason="OK"
  460. else
  461. do
  462. G.StdVar.LastRcReason=arg(2)
  463. if SayTheRc<> 'NOSAY' then
  464. call SayIt 2, "WARNING: Rc=" || G.StdVar.LastRc || ', ' ||G.StdVar.LastRcReason
  465. end
  466. return
  467. SetCommandSyntaxReturnCodeDefine:
  468. TheRc=arg(1)
  469. TheReason='Syntax Error : ' ||arg(2)
  470. call SetReturnCodeDefine TheRc,TheReason, 'NOSAY'
  471. call SayIt 1,TheReason
  472. G.StdVar.SyntaxError=G.StdVar.SyntaxError+1
  473. return
  474. SetReplaceCountDefine:
  475. G.StdVar.ReplaceCount=arg(1)
  476. return
  477. EndDefine:
  478. /*
  479. *$Header:E:/DB/PVCS.IT/OS2/TEXTEDIT/PROCESSF.XHV 1.4 17 Apr 1999 08:54:08 Dennis_Bareis $
  480. */
  481. WantedSayLevel=9999
  482. WantedSayLevelDebug=WantedSayLevel
  483. DebugMode='N'
  484. signal EndProcessF
  485. SayIfDebugOn:
  486. if DebugMode='Y' then
  487. say arg(1)
  488. return
  489. ProcessChangeFile:
  490. say ''
  491. say 'PROCESSING'
  492. say '~~~~~~~~~~'
  493. NextChangeLine=1
  494. LastChangeLine=ChangeFile.0
  495. do while NextChangeLine<=LastChangeLine
  496. ChangeLine=ChangeFile.NextChangeLine
  497. LineBeingProcessed=ChangeLine
  498. LineSourceBeingProcessed=ChangeFile.SourceInfo.NextChangeLine
  499. NextChangeLine=NextChangeLine+1
  500. if left(ChangeLine,CmtLineLng)=CmtLine then
  501. iterate
  502. InLineComment=lastpos(CmtInline,ChangeLine)
  503. if InLineComment<>0 then
  504. do
  505. ChangeLine=strip(left(ChangeLine,InLineComment-1))
  506. if ChangeLine='' then
  507. iterate
  508. end
  509. if left(ChangeLine,1)='#' then
  510. do
  511. HashRc='?'
  512. parse var ChangeLine FirstWord SecondWordEtc
  513. FirstWord=translate(substr(FirstWord,2))
  514. if FirstWord='IF' then
  515. do
  516. LineAfterChanges=ReplaceHashAndStandardDefines(ChangeLine, "ChangesMade")
  517. if ChangesMade<>0 then
  518. parse var LineAfterChanges FirstWord SecondWordEtc
  519. HashRc=ProcessHashIf(SecondWordEtc)
  520. end
  521. else
  522. do
  523. if FirstWord='ELSEIF' then
  524. HashRc=ProcessHashElse()
  525. else
  526. do
  527. if FirstWord='ENDIF' then
  528. HashRc=ProcessHashEndif()
  529. end
  530. end
  531. if HashRc<> '?' then
  532. do
  533. if HashRc='OK' then
  534. iterate
  535. else
  536. do
  537. say 'ERROR: #if/elseif/endif failed, Reason = ' ||HashRc
  538. return(109)
  539. end
  540. end
  541. end
  542. if WantLine()='Y' then
  543. do
  544. ProcessLineRc=ProcessChangeLine(ChangeLine, 'NextChangeLine')
  545. if ProcessLineRc<>0 then
  546. do
  547. If ProcessLineRc='OK' then
  548. return(0)
  549. else
  550. return(ProcessLineRc)
  551. end
  552. end
  553. end
  554. return(0)
  555. ProcessChangeLine:
  556. TheLine=arg(1)
  557. NameOfLineVar=arg(2)
  558. if DebugMode='Y' then
  559. do
  560. ThisLineNumb=value(NameOfLineVar)
  561. if length(ThisLineNumb)>=4 then
  562. LineNumberStr=ThisLineNumb
  563. else
  564. LineNumberStr=right('    ' ||ThisLineNumb,4)
  565. end
  566. if left(TheLine,1)='#' then
  567. do
  568. if DebugMode='Y' then
  569. say LineNumberStr|| ' : COMMAND: ' ||TheLine
  570. parse var TheLine HashCmd ItsParameters
  571. HashCmd=translate(HashCmd)
  572. select
  573. when HashCmd="#DEFINE" | HashCmd = "#DEFINE+" then
  574. do
  575. if HashCmd="#DEFINE+" then
  576. ItsParameters=ReplaceHashAndStandardDefines(ItsParameters)
  577. parse var ItsParameters HashDefineV Rest
  578. HashDefineC=GetQuotedText(Rest, "Rest")
  579. if HashDefineC<> 'ERROR' then
  580. do
  581. if Rest<> '' then
  582. do
  583. call SetCommandSyntaxReturnCodeDefine 185, 'Extra unexpected parameters of "' || Rest || '" found on #define'
  584. return(186)
  585. end
  586. return(AddHashDefine(HashDefineV,strip(HashDefineC)))
  587. end
  588. end
  589. when HashCmd="#COMMENT" then
  590. do
  591. ItsParameters=ReplaceHashAndStandardDefines(ItsParameters)
  592. _CmtLine=GetQuotedText(ItsParameters, "Rest")
  593. if _CmtLine='ERROR' then
  594. return(203)
  595. _CmtInline=GetQuotedText(Rest, "Rest")
  596. if _CmtInline='ERROR' then
  597. return(206)
  598. if Rest<> '' then
  599. do
  600. call SetCommandSyntaxReturnCodeDefine 211, 'Extra unexpected parameters of "' || Rest || '" found on #define'
  601. return(212)
  602. end
  603. CmtLine=_CmtLine
  604. CmtInline=_CmtInline
  605. CmtLineLng=length(CmtLine)
  606. return(0)
  607. end
  608. otherwise
  609. do
  610. call SetCommandSyntaxReturnCodeDefine 225, 'Unknown #command of "' || TheLine || '" specified.'
  611. return(226)
  612. end
  613. end
  614. end
  615. else
  616. do
  617. if left(TheLine,1)<> '@' then
  618. DisplayThisLine='Y'
  619. else
  620. do
  621. TheLine=substr(TheLine,2)
  622. DisplayThisLine='N'
  623. end
  624. if DebugMode='Y' then
  625. say LineNumberStr|| ' : COMMAND BEFORE: ' ||TheLine
  626. TheLineVarsReplaced=ReplaceHashAndStandardDefines(TheLine)
  627. if DebugMode='Y' then
  628. do
  629. if TheLineVarsReplaced<>TheLine then
  630. say LineNumberStr|| ' : COMMAND AFTER : ' ||TheLineVarsReplaced
  631. end
  632. else
  633. do
  634. if DisplayThisLine='Y' then
  635. say 'COMMAND: ' ||TheLineVarsReplaced
  636. end
  637. parse var TheLineVarsReplaced Command ItsParameters
  638. Command=translate(Command)
  639. ItsParameters=strip(ItsParameters)
  640. select
  641. when Command="DEBUG" then
  642. do
  643. DebugRc=ProcessDebug(ItsParameters)
  644. end
  645. when Command="SAYLEVEL" then
  646. do
  647. WantedSayLevelDebug=GetPositiveInteger(ItsParameters)
  648. if WantedSayLevelDebug='ERROR' then
  649. WantedSayLevelDebug=9999
  650. if DebugMode='N' then
  651. WantedSayLevel=WantedSayLevelDebug
  652. end
  653. when Command="SAY" then
  654. do
  655. if ItsParameters='' then
  656. SayWhat=''
  657. else
  658. SayWhat=GetQuotedText(ItsParameters)
  659. if SayWhat<> 'ERROR' then
  660. call SayIt 0,SayWhat, ''
  661. end
  662. when Command="SETPATH" then
  663. do
  664. TheRc=HandlePathCommand(Command,ItsParameters)
  665. end
  666. when Command="LIBPATH" then
  667. do
  668. TheRc=HandlePathCommand(Command,ItsParameters)
  669. end
  670. when Command="TOP" then
  671. do
  672. G.StdVar.CurrentPosn=0
  673. call SetReturnCodeDefine 0
  674. call SayIt 3, 'Now at Location = ' ||G.StdVar.CurrentPosn
  675. end
  676. when Command="BOTTOM" then
  677. do
  678. G.StdVar.CurrentPosn=TextFile.0
  679. call SetReturnCodeDefine 0
  680. call SayIt 3, 'Now at Location = ' ||G.StdVar.CurrentPosn
  681. end
  682. when Command="MOVETO" then
  683. do
  684. MoveTo=GetPositiveInteger(ItsParameters)
  685. if MoveTo<> 'ERROR' then
  686. do
  687. if MoveTo<=TextFile.0 then
  688. do
  689. G.StdVar.CurrentPosn=MoveTo
  690. call SayIt 3, 'Now at Location = ' ||G.StdVar.CurrentPosn
  691. end
  692. else
  693. do
  694. G.StdVar.CurrentPosn=TextFile.0
  695. call SetReturnCodeDefine 350, "Can not MoveTo " || MoveTo || ' there are not enough lines, moved to end (' || G.StdVar.CurrentPosn || ')'
  696. end
  697. end
  698. end
  699. when Command="DOWN" then
  700. do
  701. if ItsParameters="" then
  702. MoveDown=1
  703. else
  704. MoveDown=GetPositiveInteger(ItsParameters)
  705. if MoveDown<> 'ERROR' then
  706. do
  707. MaxMove=TextFile.0-G.StdVar.CurrentPosn
  708. if MoveDown<=MaxMove then
  709. call SetReturnCodeDefine 0
  710. else
  711. do
  712. MoveDown=MaxMove
  713. call SetReturnCodeDefine 377, "Can not move down " || ItsParameters || ' lines, moved to end - ' || MoveDown || ' lines'
  714. end
  715. G.StdVar.CurrentPosn=G.StdVar.CurrentPosn+MoveDown
  716. call SayIt 3, 'Now at Location = ' ||G.StdVar.CurrentPosn
  717. end
  718. end
  719. when Command="UP" then
  720. do
  721. if ItsParameters="" then
  722. MoveUp=1
  723. else
  724. MoveUp=GetPositiveInteger(ItsParameters)
  725. if MoveUp<> 'ERROR' then
  726. do
  727. if MoveUp<=G.StdVar.CurrentPosn then
  728. call SetReturnCodeDefine 0
  729. else
  730. do
  731. MoveUp=MaxMove
  732. call SetReturnCodeDefine 405, "Can not move up" || ItsParameters || ' lines, moved to start - ' || MoveUp || ' lines'
  733. end
  734. G.StdVar.CurrentPosn=G.StdVar.CurrentPosn-MoveUp
  735. call SayIt 3, 'Now at Location = ' ||G.StdVar.CurrentPosn
  736. end
  737. end
  738. when Command="FIND" then
  739. do
  740. FindRc=PerformFind(ItsParameters)
  741. end
  742. when Command="DELETEBLOCK" then
  743. do
  744. DeleteRc=ProcessDeleteBlock(ItsParameters)
  745. end
  746. when Command="REPLACELINES" then
  747. do
  748. ReplaceRc=ProcessReplaceLines(ItsParameters)
  749. end
  750. when Command="CASESENSITIVE" then
  751. do
  752. ReplaceRc=ProcessCaseSensitive(ItsParameters)
  753. end
  754. when Command="EXIT" then
  755. do
  756. call SayIt 3, 'User requested exit...'
  757. ReturnCode=GetPositiveInteger(ItsParameters, "Rest")
  758. if ReturnCode='ERROR' then
  759. returnCode=445
  760. else
  761. do
  762. if Rest="" then
  763. Reason=""
  764. else
  765. do
  766. Reason=GetQuotedText(Rest)
  767. if Reason='ERROR' then
  768. Reason='Exiting, reason is unknown due to syntax error!'
  769. end
  770. if Reason<> '' then
  771. call SayIt 0,Reason
  772. end
  773. if ReturnCode=0 then
  774. ReturnCode='OK'
  775. return(ReturnCode)
  776. end
  777. when Command="DELETELINES" then
  778. do
  779. if ItsParameters="" then
  780. DeleteCount=1
  781. else
  782. DeleteCount=GetInteger(ItsParameters)
  783. if DeleteCount<> 'ERROR' then
  784. do
  785. OriginalCurrent=G.StdVar.CurrentPosn
  786. DeleteFrom=G.StdVar.CurrentPosn
  787. if DeleteFrom=0 then
  788. DeleteFrom=1
  789. if TextFile.0=0 then
  790. call SetCommandSyntaxReturnCodeDefine 487, 'Can not delete any lines (file is completely empty!)'
  791. else
  792. do
  793. CantDelete=""
  794. if DeleteCount<0 then
  795. do
  796. DeleteCount=abs(DeleteCount)
  797. DeleteEndIndex=DeleteFrom
  798. DeleteStartIndex=(DeleteEndIndex-DeleteCount)+1
  799. if DeleteStartIndex<1 then
  800. do
  801. call SetReturnCodeDefine 501, "Can not delete " || abs(DeleteCount) || ' lines (backwards), deleting to top'
  802. DeleteStartIndex=1
  803. end
  804. NewCurrent=DeleteFrom-DeleteCount
  805. if NewCurrent<0 then
  806. NewCurrent=0
  807. end
  808. else
  809. do
  810. DeleteStartIndex=DeleteFrom
  811. DeleteEndIndex=(DeleteStartIndex+DeleteCount)-1
  812. if DeleteEndIndex>TextFile.0 then
  813. do
  814. call SetReturnCodeDefine 516, "Can not delete " || DeleteCount || ' lines (forwards), deleting to end'
  815. DeleteEndIndex=TextFile.0
  816. end
  817. NewCurrent=OriginalCurrent
  818. end
  819. if DeleteEndIndex>TextFile.0 then
  820. call SetReturnCodeDefine 524, "Can not delete lines"
  821. else
  822. do
  823. call DeleteLinesByIndexes DeleteStartIndex,DeleteEndIndex
  824. if NewCurrent>TextFile.0 then
  825. NewCurrent=TextFile.0
  826. G.StdVar.CurrentPosn=NewCurrent
  827. call SetReturnCodeDefine 0
  828. end
  829. end
  830. end
  831. end
  832. when Command="EVALUATE" then
  833. do
  834. ProcessRc=ProcessEvaluate(ItsParameters)
  835. end
  836. when Command="EXECUTE" then
  837. do
  838. CmdToEval=GetQuotedText(ItsParameters)
  839. if CmdToEval<> 'ERROR' then
  840. do
  841. call SetReturnCodeDefine 0
  842. Rc=0
  843. interpret "call AddressCmd '@" || CmdToEval || "'"
  844. call SetReturnCodeDefine Rc, "Rc from EXECUTE"
  845. end
  846. end
  847. when Command="WILDCARD" then
  848. do
  849. WildChar=GetQuotedText(ItsParameters)
  850. if WildChar<> 'ERROR' then
  851. do
  852. if length(WildChar)<>1 then
  853. call SetCommandSyntaxReturnCodeDefine 568, 'Invalid Wildchar of of "' || WildChar || '" specified (should be 1 byte long!).'
  854. else
  855. do
  856. call SetReturnCodeDefine 0
  857. WildCardChar=WildChar
  858. end
  859. end
  860. end
  861. when Command="INSERTLINE" then
  862. do
  863. NewLine=GetQuotedText(ItsParameters)
  864. if NewLine<> 'ERROR' then
  865. do
  866. call MakeSpaceForLine G.StdVar.CurrentPosn
  867. NewLineIndex=G.StdVar.CurrentPosn+1
  868. TextFile.NewLineIndex=NewLine
  869. call SayIt 3, 'New line is being inserted as line #' ||NewLineIndex
  870. G.StdVar.CurrentPosn=G.StdVar.CurrentPosn+1
  871. call SetReturnCodeDefine 0
  872. end
  873. end
  874. when Command="REPLACETEXT" then
  875. do
  876. call SetReplaceCountDefine 0
  877. MaxReplace=GetInteger(ItsParameters, "Rest")
  878. if MaxReplace<> 'ERROR' then
  879. do
  880. BeforeString=GetQuotedText(Rest, "Rest")
  881. if BeforeString<> 'ERROR' then
  882. do
  883. AfterString=GetQuotedText(Rest)
  884. if AfterString<> 'ERROR' then
  885. do
  886. if MaxReplace<0 then
  887. do
  888. StepDirection=-1
  889. MaxReplace=abs(MaxReplace)
  890. StartAt=G.StdVar.CurrentPosn
  891. StopAt=0
  892. end
  893. else
  894. do
  895. StepDirection=1
  896. StartAt=G.StdVar.CurrentPosn+1
  897. StopAt=TextFile.0+1
  898. end
  899. if StartAt=StopAt then
  900. call SetReturnCodeDefine 635, "Can not perform REPLACETEXT command - No available lines to process"
  901. else
  902. do
  903. LineIndex=StartAt
  904. TotalChanges=0
  905. do while LineIndex<>StopAt
  906. OneLine=TextFile.LineIndex
  907. Changes=0
  908. OneLine=ReplaceString(OneLine,BeforeString,AfterString, "Changes",MaxReplace)
  909. if Changes<>0 then
  910. call SayIt 3,Changes|| ' changes made on line #' ||LineIndex
  911. TextFile.LineIndex=OneLine
  912. TotalChanges=TotalChanges+Changes
  913. MaxReplace=MaxReplace-Changes
  914. if MaxReplace<=0 then
  915. leave
  916. LineIndex=LineIndex+StepDirection
  917. end
  918. call SetReplaceCountDefine TotalChanges
  919. call SetReturnCodeDefine 0
  920. end
  921. end
  922. end
  923. end
  924. end
  925. when Command="CHECKPOINT" then
  926. do
  927. CheckpointFile=G.StdVar.TextFileOut
  928. if ItsParameters<> '' then
  929. CheckpointFile=GetQuotedText(ItsParameters)
  930. if CheckpointFile='ERROR' then
  931. call SetCommandSyntaxReturnCodeDefine 681, 'Invalid CHECKPOINT filename of "' || ItsParameters || '" specified.'
  932. else
  933. do
  934. call SayIt 3, 'Checkpointing to "' || CheckpointFile || '"'
  935. call _SysFileDelete CheckpointFile
  936. NumberFailingLines=0
  937. do LineIndex=1 to TextFile.0
  938. NumberFailingLines=NumberFailingLines+lineout(CheckpointFile,TextFile.LineIndex)
  939. end
  940. FileError=IoError(CheckpointFile)
  941. if FileError='NO' then
  942. call SetReturnCodeDefine 0
  943. else
  944. call SetReturnCodeDefine 700, 'Checkpoint I/O error - ' ||FileError
  945. CloseRc=stream(CheckpointFile, 'c', 'close')
  946. end
  947. end
  948. otherwise
  949. do
  950. call SetCommandSyntaxReturnCodeDefine 711, 'Unknown command of "' || TheLineVarsReplaced || '" specified.'
  951. end
  952. end
  953. end
  954. return(0)
  955. SayIt:
  956. SayLevel=arg(1)
  957. SayItText=arg(2)
  958. if arg(3, 'Exists')=1 then
  959. SayItChar=arg(3)
  960. else
  961. SayItChar='>'
  962. if WantedSayLevel<SayLevel then
  963. return('N')
  964. else
  965. do
  966. if arg(1)="" then
  967. say ''
  968. else
  969. say '         ' ||SayItChar||SayItText
  970. return('Y')
  971. end
  972. GetQuotedText:
  973. TheString=strip(arg(1))
  974. RestVarName=arg(2)
  975. if TheString='' then
  976. do
  977. call SetCommandSyntaxReturnCodeDefine 762, 'Expect a quoted string, no parameters available'
  978. return('ERROR')
  979. end
  980. QuoteChar=left(TheString,1)
  981. if datatype(QuoteChar, 'Alphanumeric')then
  982. do
  983. call SetCommandSyntaxReturnCodeDefine 770, 'Found an invalid quote character of "' || QuoteChar || '"'
  984. return('ERROR')
  985. end
  986. SecondQuotePosn=pos(QuoteChar,substr(TheString,2))
  987. if SecondQuotePosn<>0 then
  988. SecondQuotePosn=SecondQuotePosn+1
  989. else
  990. do
  991. call SetCommandSyntaxReturnCodeDefine 780, 'Could not find a matching end quote character of "' || QuoteChar || '"'
  992. return('ERROR')
  993. end
  994. QuotedString=substr(TheString,2,SecondQuotePosn-2)
  995. TheRest=substr(TheString,SecondQuotePosn+1)
  996. if TheRest<> '' then
  997. do
  998. if left(TheRest,1)<> ' ' then
  999. do
  1000. call SetCommandSyntaxReturnCodeDefine 792, 'There is no whitespace after the 2nd quote char of "' || QuoteChar || '" (did not expect to find "' || left(TheRest, 1) || '")'
  1001. return('ERROR')
  1002. end
  1003. end
  1004. TheRest=strip(TheRest)
  1005. if RestVarName<> '' then
  1006. call value RestVarName,TheRest
  1007. else
  1008. do
  1009. if TheRest<> '' then
  1010. do
  1011. call SetCommandSyntaxReturnCodeDefine 808, 'Extra unexpected parameters of "' || TheRest || '" found'
  1012. return('ERROR')
  1013. end
  1014. end
  1015. return(QuotedString)
  1016. GetInteger:
  1017. TheString=arg(1)
  1018. RestVarName=arg(2)
  1019. parse var TheString FirstWord TheRest
  1020. if FirstWord='' then
  1021. do
  1022. call SetCommandSyntaxReturnCodeDefine 828, 'Expect a number, no parameters available'
  1023. return('ERROR')
  1024. end
  1025. if translate(FirstWord)='ALL' | translate(FirstWord) = '+ALL' then
  1026. FirstWord=99999
  1027. if translate(FirstWord)='-ALL' then
  1028. FirstWord=-99999
  1029. if\datatype(FirstWord, 'Whole number')then
  1030. do
  1031. call SetCommandSyntaxReturnCodeDefine 837, 'Found a non-numeric parameter of ' ||FirstWord
  1032. return('ERROR')
  1033. end
  1034. if RestVarName<> '' then
  1035. call value RestVarName,TheRest
  1036. else
  1037. do
  1038. if TheRest<> '' then
  1039. do
  1040. call SetCommandSyntaxReturnCodeDefine 849, 'Extra unexpected parameters of "' || TheRest || '" found'
  1041. return('ERROR')
  1042. end
  1043. end
  1044. return(FirstWord)
  1045. GetPositiveInteger:
  1046. PositiveInteger=GetInteger(arg(1),arg(2))
  1047. if PositiveInteger='ERROR' then
  1048. return('ERROR')
  1049. if PositiveInteger<0 then
  1050. do
  1051. call SetCommandSyntaxReturnCodeDefine 869, 'Expected a positive integer, found negative one!'
  1052. return('ERROR')
  1053. end
  1054. return(PositiveInteger)
  1055. MakeSpaceForLine:
  1056. LastOne=arg(1)+1
  1057. StartAt=TextFile.0
  1058. do LineIndex=StartAt to LastOne by-1
  1059. UpOne=LineIndex+1
  1060. TextFile.UpOne=TextFile.LineIndex
  1061. end
  1062. TextFile.LastOne='*FreeSpace*'
  1063. TextFile.0=TextFile.0+1
  1064. return
  1065. DeleteLinesByIndexes:
  1066. HoleStart=arg(1)
  1067. HoleEnd=arg(2)
  1068. call SayIt 3, 'Deleting lines ' || HoleStart || ' to ' ||HoleEnd
  1069. do SayIndex=HoleStart to HoleEnd
  1070. call SayIt 50, '    Line #' || SayIndex ': "' || TextFile.SayIndex || '"'
  1071. end
  1072. if HoleEnd=TextFile.0 then
  1073. do
  1074. TextFile.0=HoleStart-1
  1075. end
  1076. else
  1077. do
  1078. MoveAmount=(HoleEnd-HoleStart)+1
  1079. do MoveFromIndex=HoleEnd+1 to TextFile.0
  1080. MoveToIndex=MoveFromIndex-MoveAmount
  1081. TextFile.MoveToIndex=TextFile.MoveFromIndex
  1082. end
  1083. TextFile.0=TextFile.0-MoveAmount
  1084. end
  1085. if G.StdVar.CurrentPosn>TextFile.0 then
  1086. G.StdVar.CurrentPosn=TextFile.0
  1087. return
  1088. ProcessDeleteBlock:
  1089. FromWildCard=GetQuotedText(arg(1), 'Rest')
  1090. if FromWildCard='ERROR' then
  1091. return(947)
  1092. if Rest='' then
  1093. ToWildCard=FromWildCard
  1094. else
  1095. do
  1096. ToWildCard=GetQuotedText(Rest)
  1097. if ToWildCard='ERROR' then
  1098. return(957)
  1099. end
  1100. StartPosn=SearchForwardsForWildcard(G.StdVar.CurrentPosn,FromWildCard)
  1101. if StartPosn=0 then
  1102. do
  1103. call SetReturnCodeDefine 964, 'Could not find a line matching the starting specification (StartingPosn=' || G.StdVar.CurrentPosn || ')!'
  1104. return(965)
  1105. end
  1106. EndPosn=SearchForwardsForWildcard(StartPosn,ToWildCard)
  1107. if EndPosn=0 then
  1108. do
  1109. call SetReturnCodeDefine 972, 'Could not find a line matching the ending specification!'
  1110. return(973)
  1111. end
  1112. if G.StdVar.CurrentPosn<=StartPosn then
  1113. NewPosn=G.StdVar.CurrentPosn
  1114. else
  1115. do
  1116. if G.StdVar.CurrentPosn>EndPosn then
  1117. NewPosn=G.StdVar.CurrentPosn-((EndPosn-StartPosn)+1)
  1118. else
  1119. NewPosn=StartPosn
  1120. end
  1121. call DeleteLinesByIndexes StartPosn,EndPosn
  1122. G.StdVar.CurrentPosn=NewPosn
  1123. call SetReturnCodeDefine 0
  1124. return(0)
  1125. SearchForwardsForWildcard:
  1126. StartIndex=arg(1)
  1127. if StartIndex=0 then
  1128. StartIndex=1
  1129. if StartIndex>TextFile.0 then
  1130. return(0)
  1131. do Index=StartIndex to TextFile.0
  1132. if StringsMatch(TextFile.Index,arg(2))='Y' then
  1133. return(Index)
  1134. end
  1135. return(0)
  1136. PerformFind:
  1137. FindCount=GetInteger(arg(1), "Rest")
  1138. if FindCount='ERROR' then
  1139. return(1046)
  1140. SearchFor=GetQuotedText(Rest)
  1141. if SearchFor='ERROR' then
  1142. return(1051)
  1143. if FindCount<0 then
  1144. do
  1145. FindCount=abs(FindCount)
  1146. StartAt=G.StdVar.CurrentPosn
  1147. LastOne=1
  1148. Step=-1
  1149. if StartAt=0 then
  1150. do
  1151. call SetReturnCodeDefine 1063, 'We are at top so we can not search backwards!'
  1152. return(1064)
  1153. end
  1154. end
  1155. else
  1156. do
  1157. StartAt=G.StdVar.CurrentPosn
  1158. LastOne=TextFile.0
  1159. Step=1
  1160. if StartAt=0 then
  1161. StartAt=1
  1162. end
  1163. FoundMatches=0
  1164. do Index=StartAt to LastOne by Step
  1165. if StringsMatch(TextFile.Index,SearchFor)='Y' then
  1166. do
  1167. FoundMatches=FoundMatches+1
  1168. call SayIt 3, 'Found match #' || FoundMatches || ' at Location = ' ||Index
  1169. if FoundMatches=FindCount then
  1170. do
  1171. G.StdVar.CurrentPosn=Index
  1172. call SetReturnCodeDefine 0
  1173. return(0)
  1174. end
  1175. end
  1176. end
  1177. call SetReturnCodeDefine 1097, 'We did not find what you wanted - found ' || FoundMatches || ' out of ' ||FindCount
  1178. return(1098)
  1179. ProcessReplaceLines:
  1180. call SetReplaceCountDefine 0
  1181. MaxReplaceCount=GetInteger(arg(1), "Rest")
  1182. if MaxReplaceCount='ERROR' then
  1183. return(1111)
  1184. SearchFor=GetQuotedText(Rest, "Rest")
  1185. if SearchFor='ERROR' then
  1186. return(1116)
  1187. ReplaceWith=GetQuotedText(Rest)
  1188. if ReplaceWith='ERROR' then
  1189. return(1121)
  1190. StartAt=G.StdVar.CurrentPosn
  1191. if MaxReplaceCount<0 then
  1192. do
  1193. MaxReplaceCount=abs(MaxReplaceCount)
  1194. LastOne=1
  1195. Step=-1
  1196. if StartAt=0 then
  1197. do
  1198. call SetReturnCodeDefine 1133, 'We are at top so we can not replace backwards!'
  1199. return(1134)
  1200. end
  1201. end
  1202. else
  1203. do
  1204. LastOne=TextFile.0
  1205. Step=1
  1206. if StartAt=0 then
  1207. StartAt=1
  1208. end
  1209. FoundMatches=0
  1210. do Index=StartAt to LastOne by Step
  1211. if StringsMatch(TextFile.Index,SearchFor)='Y' then
  1212. do
  1213. ReplacementLine=ReplaceString(ReplaceWith, "${ReplacedLine}",TextFile.Index)
  1214. TextFile.Index=ReplacementLine
  1215. FoundMatches=FoundMatches+1
  1216. call SetReplaceCountDefine FoundMatches
  1217. call SayIt 3, 'Found match #' || FoundMatches || ' at Location = ' ||Index
  1218. if FoundMatches=MaxReplaceCount then
  1219. do
  1220. call SetReturnCodeDefine 0
  1221. return(0)
  1222. end
  1223. end
  1224. end
  1225. call SetReturnCodeDefine 1174, 'We did not replace as many lines as you requested - replaced ' || FoundMatches || ' out of ' ||MaxReplaceCount
  1226. return(1175)
  1227. ProcessDebug:
  1228. NewMode=translate(strip(arg(1)))
  1229. select
  1230. when NewMode="OFF" then
  1231. do
  1232. if DebugMode='N' then
  1233. do
  1234. call SetReturnCodeDefine 1194, 'Tried to turn debugg off - it is already off'
  1235. return(1195)
  1236. end
  1237. WantedSayLevel=WantedSayLevelDebug
  1238. end
  1239. when NewMode="DUMPVAR" then
  1240. do
  1241. call Sayit 0, 'USER VARIABLES',    '■'
  1242. call Sayit 0, '~~~~~~~~~~~~~~~~~', '■'
  1243. do DefineIndex=1 to HashDefineCount
  1244. TheVar=DefineVariable.DefineIndex
  1245. ItsContents=DefineContents.DefineIndex
  1246. if length(DefineIndex)>=3 then
  1247. LineNumberStr=DefineIndex
  1248. else
  1249. LineNumberStr=right('   ' ||DefineIndex,3)
  1250. if length(TheVar)>=32 then
  1251. PaddedVar=TheVar
  1252. else
  1253. PaddedVar=right('   ' ||TheVar,32)
  1254. call Sayit 0,LineNumberStr|| ' : ' || PaddedVar || ' = ' || ItsContents, '■'
  1255. end
  1256. say ''
  1257. end
  1258. when NewMode="LISTPGM" then
  1259. do
  1260. call Sayit 0, 'PROGRAM BEING RUN', '*'
  1261. call Sayit 0, '~~~~~~~~~~~~~~~~~', '*'
  1262. do LineIndex=1 to ChangeFile.0
  1263. if length(LineIndex)>=4 then
  1264. LineNumberStr=LineIndex
  1265. else
  1266. LineNumberStr=right('    ' ||LineIndex,4)
  1267. LineSource=right(ChangeFile.SourceInfo.LineIndex,LongestSourceInfo)
  1268. call Sayit 0,LineSource|| ' : ' || ChangeFile.LineIndex, '*'
  1269. end
  1270. say ''
  1271. end
  1272. when NewMode="FILESTATE" then
  1273. do
  1274. call Sayit 0, 'CURRENT STATE OF TEXT FILE', '|'
  1275. call Sayit 0, '~~~~~~~~~~~~~~~~~~~~~~~~~~', '|'
  1276. do LineIndex=1 to TextFile.0
  1277. if length(LineIndex)>=4 then
  1278. LineNumberStr=LineIndex
  1279. else
  1280. LineNumberStr=right('    ' ||LineIndex,4)
  1281. call Sayit 0,LineNumberStr|| ' : ' || TextFile.LineIndex, '|'
  1282. end
  1283. call Sayit 0, '',                           '|'
  1284. call Sayit 0, 'OTHER INFO',   '|'
  1285. call Sayit 0, '~~~~~~~~~~',   '|'
  1286. call Sayit 0, 'Current Posn   : ' || G.StdVar.CurrentPosn,     '|'
  1287. call Sayit 0, 'Current Line   : ' || GetCurrentLineContents(), '|'
  1288. call Sayit 0, '# Syntax Errors: ' || G.StdVar.SyntaxError,     '|'
  1289. say ''
  1290. end
  1291. otherwise
  1292. do
  1293. DebugMode='Y'
  1294. WantedSayLevel=9999
  1295. end
  1296. end
  1297. return(0)
  1298. ProcessCaseSensitive:
  1299. NewMode=translate(strip(arg(1)))
  1300. select
  1301. when NewMode="ON" then
  1302. CaseSensitive='Y'
  1303. when NewMode="OFF" then
  1304. CaseSensitive='N'
  1305. otherwise
  1306. do
  1307. call SetCommandSyntaxReturnCodeDefine 1313, 'Invalid parameter (' || NewMode || ')'
  1308. return(1314)
  1309. end
  1310. end
  1311. return(0)
  1312. ProcessEvaluate:
  1313. HashDefineAnswerName=GetQuotedText(arg(1), "Rest")
  1314. if HashDefineAnswerName='ERROR' then
  1315. return(1327)
  1316. if Rest='' then
  1317. CmdToEvaluate=HashDefineAnswerName
  1318. else
  1319. do
  1320. CmdToEvaluate=GetQuotedText(Rest)
  1321. if CmdToEvaluate='ERROR' then
  1322. return(1337)
  1323. end
  1324. signal ON SYNTAX NAME SyntaxErrorInEvaluateCommand
  1325. signal ON NOVALUE NAME UnknownVariableInEvaluateCommand
  1326. HashDefineRc=0
  1327. if HashDefineAnswerName='' then
  1328. interpret CmdToEvaluate
  1329. else
  1330. do
  1331. interpret 'EvaluateAnswer = ' ||CmdToEvaluate
  1332. HashDefineRc=AddHashDefine(HashDefineAnswerName,EvaluateAnswer)
  1333. call SetReturnCodeDefine HashDefineRc, "Rc from EVALUATE"
  1334. end
  1335. signal on NOVALUE name RexxTrapUninitializedVariable
  1336. signal on SYNTAX name RexxTrapSyntaxError
  1337. return(HashDefineRc)
  1338. SyntaxErrorInEvaluateCommand:
  1339. FailReason=errortext(RC)
  1340. call SetCommandSyntaxReturnCodeDefine 1372, 'Evaluate at "' || LineSourceBeingProcessed || '" failed with syntax error (' || FailReason || ')'
  1341. signal on NOVALUE name RexxTrapUninitializedVariable
  1342. signal on SYNTAX name RexxTrapSyntaxError
  1343. return(1377)
  1344. UnknownVariableInEvaluateCommand:
  1345. FailReason="Variable=" || condition('D')
  1346. call SetCommandSyntaxReturnCodeDefine 1384, 'Evaluate at "' || LineSourceBeingProcessed || '" failed with unknown variable (' || FailReason || ')'
  1347. signal on NOVALUE name RexxTrapUninitializedVariable
  1348. signal on SYNTAX name RexxTrapSyntaxError
  1349. return(1389)
  1350. EndProcessF:
  1351. /*
  1352. *$Header:E:/DB/PVCS.IT/OS2/TEXTEDIT/PATH.XHV 1.2 09 Mar 1999 17:38:12 Dennis_Bareis $
  1353. */
  1354. signal EndPath
  1355. SearchForPathLine:
  1356. BeginsPathLine=arg(1)
  1357. PathVariable=arg(2)
  1358. BeginsPathLineLength=length(BeginsPathLine)
  1359. do LookIndex=1 to TextFile.0
  1360. LookLine=translate(strip(TextFile.LookIndex))
  1361. if BeginsPathLineLength<>0 then
  1362. do
  1363. if left(LookLine,BeginsPathLineLength)\==BeginsPathLine then
  1364. iterate
  1365. end
  1366. if pos(PathVariable,LookLine)<>0 then
  1367. return(LookIndex)
  1368. end
  1369. return(0)
  1370. LoadPathsIntoStem:
  1371. StemVarName=arg(1)
  1372. TheList=translate(arg(2))
  1373. Delimiter=';'
  1374. ComponentCount=0
  1375. do forever
  1376. DelimiterPos=pos(Delimiter,TheList)
  1377. if DelimiterPos=0 then
  1378. do
  1379. if TheList<> '' then
  1380. do
  1381. ComponentCount=ComponentCount+1
  1382. call value StemVarName|| '.' ||ComponentCount,strip(TheList)
  1383. end
  1384. leave
  1385. end
  1386. ThisComponent=left(TheList,DelimiterPos-1)
  1387. TheList=substr(TheList,DelimiterPos+1)
  1388. if ThisComponent<> '' then
  1389. do
  1390. ComponentCount=ComponentCount+1
  1391. call value StemVarName|| '.' ||ComponentCount,strip(ThisComponent)
  1392. end
  1393. end
  1394. call value StemVarName|| '.0',ComponentCount
  1395. return(ComponentCount)
  1396. FindPath:
  1397. do FindIndex=1 to Path.0
  1398. if Path.FindIndex=arg(1)then
  1399. return(FindIndex)
  1400. end
  1401. return(0)
  1402. DeletePath:
  1403. DeleteIndex=FindPath(arg(1))
  1404. if DeleteIndex<>0 then
  1405. do
  1406. do MoveFrom=DeleteIndex+1 to Path.0
  1407. MoveTo=MoveFrom-1
  1408. Path.MoveTo=Path.MoveFrom
  1409. end
  1410. Path.0=Path.0-1
  1411. end
  1412. return
  1413. HandlePathCommand:
  1414. PathCmd=arg(1)
  1415. PathCmdParms=translate(arg(2))
  1416. Rest=PathCmdParms
  1417. if PathCmd="SETPATH" then
  1418. do
  1419. Variable=GetQuotedText(Rest, "Rest")
  1420. if Variable='ERROR' then
  1421. return(146)
  1422. end
  1423. else
  1424. do
  1425. Variable='LIBPATH'
  1426. end
  1427. parse var Rest PathSubCmd Rest
  1428. if PathSubCmd<> 'ADDBEFORE' & PathSubCmd <> 'ADDAFTER' then
  1429. PositionPath=''
  1430. else
  1431. do
  1432. PositionPath=GetQuotedText(Rest, "Rest")
  1433. if PositionPath='ERROR' then
  1434. return(163)
  1435. end
  1436. OneOrMorePaths=GetQuotedText(Rest)
  1437. if OneOrMorePaths='ERROR' then
  1438. return(169)
  1439. if PathCmd="SETPATH" then
  1440. LineIndex=SearchForPathLine("SET ", " " || Variable || "=")
  1441. else
  1442. LineIndex=SearchForPathLine("",            Variable || "=")
  1443. if LineIndex=0 then
  1444. do
  1445. call SetReturnCodeDefine 180, 'Can not find the ' || Variable || ' variable'
  1446. return(181)
  1447. end
  1448. call SayIt 3, 'Variable=' || Variable || ' was found on line #' ||LineIndex
  1449. EqualSignPos=pos('=',TextFile.LineIndex)
  1450. ConstantPart=left(TextFile.LineIndex,EqualSignPos)
  1451. DataPart=substr(TextFile.LineIndex,EqualSignPos+1)
  1452. call SayIt 3, 'Path Before=<' || DataPart || '>'
  1453. Dummy=LoadPathsIntoStem("Path",translate(DataPart))
  1454. Dummy=LoadPathsIntoStem("UserPath",OneOrMorePaths)
  1455. do UserDeleteIndex=1 to UserPath.0
  1456. call DeletePath UserPath.UserDeleteIndex
  1457. end
  1458. if PathSubCmd<> 'DELETE' then
  1459. do
  1460. if PositionPath='' then
  1461. do
  1462. if PathSubCmd='ADDSTART' then
  1463. InsertAt=1
  1464. else
  1465. InsertAt=Path.0+1
  1466. end
  1467. else
  1468. do
  1469. InsertAt=FindPath(PositionPath)
  1470. if InsertAt=0 then
  1471. do
  1472. call SetReturnCodeDefine 221, 'Can not find the relative directory "' || PositionPath || '" - will add to start'
  1473. InsertAt=1
  1474. end
  1475. else
  1476. do
  1477. if PathSubCmd='ADDAFTER' then
  1478. do
  1479. InsertAt=InsertAt+1
  1480. end
  1481. end
  1482. end
  1483. do AddIndex=1 to UserPath.0
  1484. call InsertIntoPath InsertAt,UserPath.AddIndex
  1485. InsertAt=InsertAt+1
  1486. end
  1487. end
  1488. NewList=''
  1489. do AddIndex=1 to Path.0
  1490. if AddIndex=1 then
  1491. NewList=Path.1
  1492. else
  1493. NewList=NewList|| ';' ||Path.AddIndex
  1494. end
  1495. call SayIt 3, 'Path After =<' || NewList || '>'
  1496. TextFile.LineIndex=ConstantPart||NewList
  1497. return(0)
  1498. InsertIntoPath:
  1499. InsertIndex=arg(1)
  1500. InsertPath=arg(2)
  1501. if InsertIndex>Path.0 then
  1502. do
  1503. Path.0=InsertIndex
  1504. Path.InsertIndex=InsertPath
  1505. end
  1506. else
  1507. do
  1508. do Index=Path.0 to InsertIndex by-1
  1509. UpOne=Index+1
  1510. Path.UpOne=Path.Index
  1511. end
  1512. Path.InsertIndex=InsertPath
  1513. Path.0=Path.0+1
  1514. end
  1515. return
  1516. EndPath:
  1517. /*
  1518. *$Header:E:/DB/PVCS.IT/OS2/TEXTEDIT/COMPSTR.XHV 1.1 09 Mar 1999 17:38:10 Dennis_Bareis $
  1519. */
  1520. WildCardChar='*'
  1521. CaseSensitive='N'
  1522. signal EndCompStr
  1523. StringsMatch:procedure expose WildCardChar CaseSensitive
  1524. if CaseSensitive='Y' then
  1525. do
  1526. TestString=arg(1)
  1527. WildCardString=arg(2)
  1528. end
  1529. else
  1530. do
  1531. TestString=translate(arg(1))
  1532. WildCardString=translate(arg(2))
  1533. end
  1534. WildCardStringLng=length(WildCardString)
  1535. FirstWildPos=pos(WildCardChar,WildCardString)
  1536. if FirstWildPos=0 then
  1537. do
  1538. if TestString=WildCardString then
  1539. return('Y')
  1540. else
  1541. return('N')
  1542. end
  1543. if FirstWildPos=WildCardStringLng then
  1544. do
  1545. if left(TestString,WildCardStringLng-1)=left(WildCardString,WildCardStringLng-1)then
  1546. return('Y')
  1547. else
  1548. return('N')
  1549. end
  1550. if FirstWildPos<>1 then
  1551. do
  1552. StartWild=substr(WildCardString,1,FirstWildPos-1)
  1553. EndWild=substr(WildCardString,FirstWildPos+1)
  1554. if StringsMatch(TestString,StartWild||WildCardChar)='N' then
  1555. return('N')
  1556. return(StringsMatch(TestString,WildCardChar||EndWild))
  1557. end
  1558. SecondWildPos=lastpos(WildCardChar,WildCardString)
  1559. if FirstWildPos=SecondWildPos then
  1560. do
  1561. if right(TestString,WildCardStringLng-1)=substr(WildCardString,2)then
  1562. return('Y')
  1563. else
  1564. return('N')
  1565. end
  1566. else
  1567. do
  1568. if pos(substr(WildCardString,2,WildCardStringLng-2),TestString)<>0 then
  1569. return('Y')
  1570. else
  1571. return('N')
  1572. end
  1573. EndCompStr:
  1574. say ''
  1575. say 'LOADING FILES'
  1576. say '~~~~~~~~~~~~~'
  1577. LoadRc=LoadTextFile(TextFile)
  1578. if LoadRc<>0 then
  1579. do
  1580. say "ERROR: Can't load the text file " || TextFile || ' (Rc=' || LoadRc || ')'
  1581. exit(LoadRc)
  1582. end
  1583. IncludeLevel=0
  1584. LoadRc=LoadChangeFile(ChangeFile)
  1585. if LoadRc<>0 then
  1586. do
  1587. say "ERROR: Can't load the change file " || ChangeFile || ' (Rc=' || LoadRc || ')'
  1588. exit(LoadRc)
  1589. end
  1590. ProcessRc=ProcessChangeFile()
  1591. say ''
  1592. if ProcessRc=0 then
  1593. do
  1594. if G.StdVar.SyntaxError<>0 then
  1595. ProcessRc=G.StdVar.SyntaxError
  1596. end
  1597. say 'TEXTEDIT completed with RC = ' ||ProcessRc
  1598. exit(ProcessRc)
  1599. DisplayCopyright:
  1600. if CopyRightDisplayed='N' then
  1601. do
  1602. say '[]-------------------------------------------------------------[]'
  1603. say '| TEXTEDIT.CMD Version ' || PgmVersion || ' (C)opyright Dennis Bareis 1997    |'
  1604. say '| http://www.labyrinth.net.au/~dbareis/index.htm (db0@anz.com)  |'
  1605. say '[]-------------------------------------------------------------[]'
  1606. say ''
  1607. CopyRightDisplayed='Y'
  1608. end
  1609. return
  1610. RexSystemFailure:
  1611. FailedAt=SIGL
  1612. call DisplayCopyright
  1613. call RexDumpSystemInfo
  1614. say LightRed||arg(1)||Reset
  1615. exit(FailedAt)
  1616. SetColorCodes:
  1617. EscapeChar=d2c(27)
  1618. Reset=EscapeChar|| '[0m'
  1619. LightRed=EscapeChar|| '[1;31m'
  1620. Yellow=EscapeChar|| '[1;33m'
  1621. return
  1622. RemoveColorCodes:
  1623. Reset=''
  1624. LightRed=''
  1625. Yellow=''
  1626. return
  1627. GetAmPmTime:
  1628. CivilTime=time('C');  if length(CivilTime)  = 6 then CivilTime=' 'CivilTime
  1629. TheTime=time();NumSeconds=':'substr(TheTime,7,2)
  1630. return(insert(NumSeconds,CivilTime,5))
  1631. UserSyntaxError:
  1632. FailedAt=SIGL
  1633. say "SYNTAX ERROR"
  1634. say "~~~~~~~~~~~~"
  1635. say '    ' ||arg(1)
  1636. say ''
  1637. say 'CORRECT SYNTAX'
  1638. say '~~~~~~~~~~~~~~'
  1639. say '    TEXTEDIT[.CMD] TextFileBeingChanged OutputFile ChangeFile [OptionalParms]'
  1640. say ''
  1641. say 'The "OptionalParms" can be accessed from the change description file...'
  1642. exit(FailedAt)
  1643. CommonTrapHandler:
  1644. FailingLine=arg(1)
  1645. TrapHeading='BUG: ' ||arg(2)
  1646. TextDescription=arg(3)
  1647. Text=arg(4)
  1648. parse source . . SourceFileName
  1649. say Yellow||copies('=+',39)||LightRed
  1650. say TrapHeading
  1651. say copies('~',length(TrapHeading))
  1652. say substr(TextDescription,1,16)|| ': ' ||Text
  1653. if LineBeingProcessed<> '' then
  1654. do
  1655. say 'Processing Line : ' ||LineBeingProcessed
  1656. say 'Line Source     : ' ||LineSourceBeingProcessed
  1657. end
  1658. say 'Failing Module  : ' ||SourceFileName
  1659. say 'Failing Line #  : ' ||FailingLine
  1660. say 'Failing Command : ' ||strip(SourceLine(FailingLine))
  1661. say Yellow||copies('=+',39)||Reset
  1662. say ''
  1663. exit(FailingLine)
  1664. RexxTrapUninitializedVariable:
  1665. FailedAt=SIGL
  1666. call CommonTrapHandler FailedAt, 'NoValue Abort!', 'Unknown Variable', condition('D')
  1667. RexxTrapSyntaxError:
  1668. FailedAt=SIGL
  1669. call CommonTrapHandler FailedAt, 'Syntax Error!', 'Reason',errortext(Rc)
  1670.