home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / MAKEREXX.ZIP / makerexx.cmd < prev    next >
OS/2 REXX Batch file  |  1992-10-13  |  10KB  |  423 lines

  1. /* MAKEREXX */
  2.  
  3. trace off
  4. arg arguments
  5. call STANDARD_START arguments
  6. arg file '((' options
  7. file = strip(strip(file),'B','"')
  8. i = lastpos('\',file) + 1
  9. if i \= 0 then parse var file path =(i) file
  10. i = lastpos('.',file)
  11. j = i + 1
  12. parse var file fname =(i) . =(j) ftype
  13.  
  14. call SET_USER_GV_VALUES
  15. call SET_INI_VALUES
  16.  
  17. select
  18.   when ftype = 'XXX'
  19.     then do
  20.       call PROCESS_COPYBOOK ftype fname
  21.     end
  22.   when wordpos(ftype,gv.itype) \= 0
  23.     then do
  24.       call PROCESS_MAIN_ROUTINE ftype fname
  25.     end
  26.   when fname = 'MAKE'
  27.     then do
  28.       call PROCESS_MAKE_ROUTINE
  29.     end
  30.   when fname = 'INIT'
  31.     then do
  32.       call INIT_INI
  33.     end
  34.   when fname = 'HELP'
  35.     then do
  36.       call HELP_MESSAGE
  37.     end
  38.   Otherwise
  39.     call ERROR_MESSAGE '6 0001 Invalid paramaters.'
  40. end
  41.  
  42. call FINISHED_MESSAGE
  43. exit 0
  44.  
  45. PROCESS_MAKE_ROUTINE: procedure expose gv. ini.
  46.  
  47. call SysIni ini.file, 'REEXPAND', 'ALL:', 'expand.list'
  48. do m = 1 to expand.list.0
  49.   file = expand.list.m
  50.   i = lastpos('.',file)
  51.   j = i + 1
  52.   parse var file fname =(i) . =(j) ftype
  53.   call PROCESS_MAIN_ROUTINE ftype fname
  54. end
  55.  
  56. return 0
  57.  
  58. PROCESS_MAIN_ROUTINE: procedure expose gv. ini.
  59. arg ftype fname
  60.  
  61. call UPDATE_INI_COPYDATA ftype fname
  62. call BUILD_MEMBER ftype fname
  63.  
  64. return result
  65.  
  66. BUILD_MEMBER: procedure expose gv. ini.
  67.  
  68. arg ftype fname
  69. copy.level = 0
  70. suffix = word(gv.otype,wordpos(ftype,gv.itype))
  71. out.file = ini.rpathcmd || fname'.'suffix
  72.  
  73. filex = fname'.'ftype
  74. interpret 'filep = RPATH'ftype
  75. filex = syssearchpath(filep,filex)
  76. file.status = stream(filex,'C','OPERREAD')
  77.  
  78. if file.status \= 'READY:'
  79.   then do
  80.     call ERROR_MESSAGE '4 0001 Can not find input file',
  81.                 filex'. RC='file.status
  82.     return 4
  83.   end
  84. call SysFileDelete out.file
  85. if result > 2
  86.   then call ERROR_MESSAGE '16 0001 Problem deleting',
  87.                   file'. RC='result'.'
  88. call EXPAND_MEMBER ftype fname
  89.  
  90. file.status = stream(filex,'C','CLOSE')
  91.  
  92. tag.a = translate(strip(stream(filex,'C','QUERY EXISTS')))
  93. tag.b = strip(stream(filex,'C','QUERY DATETIME'))
  94. tag.c = strip(stream(filex,'C','QUERY SIZE'))
  95. tag.line = date() time() 'FILE DATA:' tag.b tag.c
  96. call INI_SET tag.a'|'LAST EXPANSION'|'tag.line
  97. call INI_SET 'REEXPAND|'fname'.'ftype"|DELETE:"
  98.  
  99. return result
  100.  
  101. EXPAND_MEMBER: procedure expose gv. ini. out.file copy.level
  102. arg ftype fname
  103.  
  104. filex = fname'.'ftype
  105. interpret 'filep = RPATH'ftype
  106. filex = syssearchpath(filep,filex)
  107. file.status = stream(filex,'C','OPERREAD')
  108. if file.status \= 'READY:'
  109.   then do
  110.     call ERROR_MESSAGE '4 0001 Can not find input file',
  111.                 file'. RC='file.status
  112.     return 4
  113.   end
  114. tag.a = strip(stream(filex,'C','QUERY DATETIME'))
  115. tag.b = strip(stream(filex,'C','QUERY SIZE'))
  116. tag.c = strip(stream(filex,'C','QUERY EXISTS'))
  117. tag.line = gv.tagpx'I'copy.level || gv.tagsx '/*' tag.a tag.b tag.c '*/'
  118. lo.rc = lineout(out.file,tag.line)
  119. if lo.rc > 0
  120.   then call ERROR_MESSAGE '16 0001 Problem writting',
  121.                   out.file'. RC='lo.rc'.'
  122. do forever
  123.   outline = LINEIN(filex)
  124.   if outline = '' then leave
  125.   if left(outline,7) = '++COPY '
  126.     then do
  127.       if lo.rc > 0
  128.     then call ERROR_MESSAGE '16 0001 Problem writting',
  129.                   out.file'. RC='lo.rc'.'
  130.       parse var outline . copy.file '((' copy.options
  131.       copy.file = strip(copy.file)
  132.       i = lastpos('.',copy.file)
  133.       j = i + 1
  134.       parse var copy.file copy.file.name =(i) . =(j) copy.file.type
  135.       outline = gv.tagpx'F'copy.level || gv.tagsx '/*' outline '*/'
  136.       lo.rc = lineout(out.file,outline)
  137.       copy.level = copy.level + 1
  138.       call EXPAND_MEMBER copy.file.type copy.file.name
  139.       copy.level = copy.level - 1
  140.     end
  141.     else do
  142.       if copy.level > 0 | gv.base.indent = 'YES'
  143.     then outline = gv.tagpx'C'copy.level || gv.tagsx outline
  144.       lo.rc = lineout(out.file,outline)
  145.       if lo.rc > 0
  146.     then call ERROR_MESSAGE '16 0001 Problem writting',
  147.                   out.file'. RC='lo.rc'.'
  148.     end
  149. end
  150. file.status = stream(filex,'C','CLOSE')
  151.  
  152. return 0
  153.  
  154. PROCESS_COPYBOOK: procedure expose gv. ini.
  155. arg ftype fname
  156.  
  157. call UPDATE_INI_COPYDATA ftype fname
  158. call SEARCH_UPDATES ftype fname
  159.  
  160. return 0
  161.  
  162. SEARCH_UPDATES: procedure expose gv. ini.
  163. arg ftype fname
  164.  
  165. call SysIni ini.file, 'COPIES', 'ALL:', 'copy.list'
  166. if result \= ''
  167.   then call ERROR_MESSAGE '12 0001 Error reading copy list from',
  168.                   file'. RC='result'.'
  169. if copy.list.0 = 0
  170.   then call ERROR_MESSAGE '4 0001 No copy info found in' ini.file'.'
  171. copy.data.table. = ''
  172. k = 0
  173. do i = 1 to copy.list.0
  174.   call SysIni ini.file, 'COPIES', copy.list.i
  175.   parse var result copy.data.index copy.data.work
  176.   do j = 1 to copy.data.index
  177.     parse var copy.data.work copy.data.member ':' copy.data.work
  178.     if copy.data.member = '' then iterate
  179.     k = k + 1
  180.     copy.data.table.main.k = copy.list.i
  181.     copy.data.table.copy.k = copy.data.member
  182.   end
  183. end
  184.  
  185. copy.data.table.0 = k
  186.  
  187. filex = fname'.'ftype
  188. names.found. = ''
  189. names.found.0 = 1
  190. this.file = translate(filex,'?',' ')
  191. names.found.1 = filex
  192. prefix = 'A???'
  193. interpret prefix||this.file '= 0'
  194. names.found.type.1 = ftype
  195. j = 1
  196.  
  197. do i = 1 to 100000
  198.   if i > j then leave
  199.   if wordpos(names.found.type.j,gv.itype) \= 0
  200.     then do
  201.       time.stamp = date() time()
  202.       call INI_SET 'REEXPAND|'names.found.i'|'time.stamp
  203.       leave
  204.     end
  205.   do k = 1 to copy.data.table.0
  206.     copy.file = copy.data.table.copy.k
  207.     if copy.file \= names.found.i then iterate
  208.     if copy.file = ' ' then iterate
  209.     this.file = copy.data.table.main.k
  210.     this.file = translate(this.file,'?',' ')
  211.     if symbol(prefix||this.file) = 'VAR'
  212.       then leave
  213.     interpret prefix||this.file '= 0'
  214.     j = j + 1
  215.     names.found.j = this.file
  216.     m = lastpos('.',this.file)
  217.     n = m + 1
  218.     parse var this.file fname =(m) . =(n) ftype
  219.     names.found.type.j = ftype
  220.   end
  221. end
  222. names.found.0 = j
  223.  
  224. return 0
  225.  
  226. UPDATE_INI_COPYDATA: procedure expose gv. ini.
  227. arg ftype fname
  228.  
  229. filex = fname'.'ftype
  230. interpret 'filep = RPATH'ftype
  231. filex = syssearchpath(filep,filex)
  232.  
  233. call SysFileSearch '++COPY ', filex, lines
  234. if result = 2
  235.   then call ERROR_MESSAGE '16 0001 Not enouth memory to process',
  236.                   file'. RC='result'.'
  237. copy.data = lines.0" "
  238. do i = 1 to lines.0
  239.   parse var lines.i . member '((' .
  240.   copy.data = copy.data||member':'
  241. end
  242. call INI_SET 'COPIES|'fname'.'ftype'|'copy.data
  243.  
  244. return 0
  245.  
  246. SET_INI_VALUES: procedure expose gv. ini.
  247.  
  248. ini. = ''
  249. ini.path = directory()
  250. ini.file = ini.path'\MAKEREXX.INI'
  251.  
  252. call SysIni ini.file, 'PATH', 'XXX'
  253. ini.rpathxxx = result
  254. call SysIni ini.file, 'PATH', 'REX'
  255. ini.rpathrex = result
  256. call SysIni ini.file, 'PATH', 'CMD'
  257. ini.rpathcmd = result
  258.  
  259. '@SET RPATHREX='ini.rpathrex
  260. '@SET RPATHERX='ini.rpatherx
  261. '@SET RPATHXXX='ini.rpathxxx
  262. '@SET RPATHCMD='ini.rpathcmd
  263. '@SET RPATHEPM='ini.rpathepm
  264.  
  265. return 0
  266.  
  267. SET_USER_GV_VALUES: procedure expose gv.
  268.  
  269. gv.itype = 'REX EPM'
  270. gv.otype = 'CMD ERX'
  271. gv.tagpx = '/*.'
  272. gv.tagsx = '.*/'
  273. gv.base.indent = 'YES'
  274.  
  275. return 0
  276.  
  277. INIT_INI: procedure expose gv. ini.
  278.  
  279. call SysFileDelete ini.file
  280. if result > 2
  281.   then call ERROR_MESSAGE '16 0001 Problem deleting',
  282.                   ini.file'. RC='result'.'
  283. call INI_SET 'INIT|DATE|'date()
  284. call INI_SET 'INIT|TIME|'time()
  285. call INI_SET 'PATH|XXX|.;C:\MAKEREXX;C:\MAKEREXX\XXX\'
  286. call INI_SET 'PATH|REX|.;C:\MAKEREXX;C:\MAKEREXX\REX\'
  287. call INI_SET 'PATH|EPM|.;C:\MAKEREXX;C:\MAKEREXX\REX\'
  288. call INI_SET 'PATH|CMD|C:\MAKEREXX\CMD\'
  289. call INI_SET 'PATH|ERX|C:\MAKEREXX\CMD\'
  290.  
  291. return 0
  292.  
  293.  
  294.  
  295.  
  296. /* standard ini routines */
  297.  
  298. INI_SET: procedure expose gv. ini.
  299. arg appl '|' name '|' value
  300.  
  301. call SysIni ini.file, appl, name, value
  302. if result \= '' then return result
  303.  
  304. return 0
  305.  
  306. /* standard routines */
  307.  
  308. STANDARD_START: procedure expose gv.
  309.  
  310. gv. = ''
  311. drop gv.v.initcode
  312. parse upper source gv.oper.system gv.call.type gv.cmd.file.source .
  313. if gv.oper.system <> 'OS/2'
  314.   then call ERROR_MESSAGE '16 001 This REXX routine can only run',
  315.                   'in OS/2, not' gv.oper.system'.'
  316. parse upper version gv.oper.system.version
  317. gv.cmd.file.drive = filespec('D',gv.cmd.file.source)
  318. gv.cmd.file.path = filespec('P',gv.cmd.file.source)
  319. gv.cmd.file.fullpath = gv.cmd.file.drive||gv.cmd.file.path
  320. gv.cmd.file.name = filespec('N',gv.cmd.file.source)
  321. parse var gv.cmd.file.name gv.cmd.name '.CMD'
  322. gv.start.dir = directory()
  323.  
  324. call RX_LOAD
  325.  
  326. gv.os2.ver = SysOS2Ver()
  327. arg . '((' gv.options
  328.  
  329. return 0
  330.  
  331. RX_LOAD: procedure expose gv.
  332.  
  333. if \ RxFuncQuery('SysLoadFuncs')
  334.   then return 0
  335. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  336. if result \= 0 then return result
  337. call SysLoadFuncs
  338.  
  339. return result
  340.  
  341. V_CLEANUP:
  342.  
  343. if symbol('gv.v.initcode') = 'VAR'
  344.   then call VExit
  345. if symbol('em.rc') = 'VAR' then return
  346.  
  347. exit 9999
  348.  
  349. ERROR_MESSAGE: procedure expose gv.
  350. arg em.rc msg
  351.  
  352. if symbol('gv.v.initcode') = 'VAR'
  353.   then call ERROR_MESSAGE_SCREEN
  354.   else say msg
  355.  
  356. if em.rc < 6 then return 0
  357.  
  358. call V_CLEANUP
  359.  
  360. exit em.rc
  361.  
  362. ERROR_MESSAGE_SCREEN:
  363.  
  364. if em.rc < 8
  365.   then type.error = 'non-critical'
  366.   else type.error = 'critical'
  367.  
  368. title = gv.cmd.name
  369. msg.line.0 = 3
  370. msg.line.1 = 'The following' type.error 'error has occured:'
  371. msg.line.2 = ''
  372. msg.line.3 = msg
  373. button = VMsgBox(title,msg.line,1)
  374.  
  375. return 0
  376.  
  377. FINISHED_MESSAGE: procedure expose gv.
  378.  
  379. title = gv.cmd.name
  380. msg.line.0 = 1
  381. msg.line.1 = title 'ENDING.'
  382. if symbol('gv.v.initcode') = 'VAR'
  383.   then button = VMsgBox(title,msg.line,1)
  384.   else say msg.line.1
  385.  
  386. return 0
  387.  
  388. HELP_MESSAGE: procedure expose gv.
  389.  
  390. title = gv.cmd.name
  391. msg.line.0 = 1
  392. msg.line.1 = 'No help found for' title
  393. if symbol('gv.v.initcode') = 'VAR'
  394.   then max.line = 10
  395.   else max.line = 20
  396. do j = 1 to 1000
  397.   if j \= 1 and help.line = ''
  398.     then return 0
  399.   do i = 1 to max.line
  400.     if help.line = ''
  401.       then return 0
  402.     help.line = linein(gv.cmd.name'.HLP')
  403.     if help.line = ''
  404.       then leave
  405.     msg.line.i = help.line
  406.     msg.line.0 = i
  407.   end
  408.   if symbol('gv.v.initcode') = 'VAR'
  409.     then do
  410.       button = VMsgBox(title,msg.line,1)
  411.       iterate j
  412.     end
  413.   do i = 1 to msg.line.0
  414.     say msg.line.1
  415.   end
  416.   if help.line = ''
  417.     then leave
  418.   say '<MORE>'
  419.   pull response
  420. end
  421.  
  422. return 0
  423.