home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / eptxfn30.zip / tfe.zip / tfconfig.cmd < prev    next >
OS/2 REXX Batch file  |  1999-11-07  |  4KB  |  152 lines

  1. /******************************************************
  2.  
  3.   File TFCONFIG.CMD - TFE configuration tool
  4.  
  5.   This procedure is part of the EPM TeX Front End v2.5a
  6.   (C) 1997-1999 Walter Schmidt.
  7.  
  8. *******************************************************/
  9.  
  10. VERSION = 'TFCONFIG 2.9c'
  11. APP = 'EPMTFE'
  12. DEFAULT_CFGFILE = 'tfe.cfg'
  13.  
  14. call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'SysLoadFuncs'
  15. call SysLoadFuncs
  16.  
  17. parse arg cfgfile option .
  18.  
  19. if cfgfile = '' then cfgfile = DEFAULT_CFGFILE
  20. else do
  21.    c = substr(cfgfile,1,1)
  22.    if c = '-' | c = '/' then do
  23.       option = cfgfile
  24.       cfgfile = DEFAULT_CFGFILE
  25.    end /* do */
  26. end /* do */
  27.  
  28. nowrite = (translate(option) = '-N') | (translate(option) = '/N')
  29. delete = (translate(option) = '-D') | (translate(option) = '/D')
  30. view = (translate(option) = '-V') | (translate(option) = '/V')
  31. write = (translate(option) = '-U') | (translate(option) = '/U') | (option = '')
  32.  
  33. if option <> '' & \ (nowrite | delete | view | write) then signal givehelp
  34.  
  35. if \ (view | nowrite) then say VERSION', 'date()' 'time()
  36.  
  37. inifile = SysIni('USER', 'EPM', 'EPMIniPath')
  38. if (inifile = 'ERROR:') & \ nowrite  then do
  39.    say 'Apparently the EPM is not installed.'
  40.    return 2
  41. end /* do */
  42.  
  43. inifile = strip(inifile, 'T', '0'x)
  44.  
  45. if filespec('D', inifile) = '' then do
  46.    bootdr = value('COMSPEC', , 'OS2ENVIRONMENT')
  47.    bootdr = filespec('D', bootdr)
  48.    inifile= bootdr||inifile
  49. end /* do */
  50.  
  51. if view then signal appview
  52.  
  53. if delete then signal appdelete
  54.  
  55. lineno = 0
  56. errflag = 0
  57.  
  58. if \ nowrite then say 'Updating' inifile '...'
  59.  
  60. do while lines(cfgfile) > 0
  61.    l = linein(cfgfile)
  62.    lineno = lineno + 1
  63.    parse var l rawcode '#' comment
  64.    code = translate(rawcode, " ", "09"x)
  65.    if code <> '' then do
  66.       parse var code  key '=' value
  67.       if key <> '' then do
  68.          key = strip(key)
  69.          if nowrite then 
  70.             say lineno': 'key' ='value
  71.          else do
  72.             value = strip(value)
  73.             if value <> '' then do
  74.               ret = SysIni(inifile, APP, translate(key), value||'0'x)
  75.               if ret <> '' then do
  76.                  say 'error: writing line 'lineno' failed'
  77.                  errflag = 1
  78.               end /* do */
  79.             end /* do */
  80.             else call SysIni inifile, APP, translate(key), 'DELETE:'
  81.          end /* do */
  82.       end /* do */
  83.    end /* do */
  84. end /* do */
  85.  
  86. if lineno = 0 then do
  87.     say 'File 'cfgfile' empty or not found.'
  88.     return 1
  89. end /* do */
  90.  
  91. if \ nowrite then do
  92.    ret = SysIni(inifile, APP, 'VERSION', VERSION||'0'x)
  93.    if ret <> '' then do
  94.       say 'error: cannot write version info to 'inifile
  95.       errflag = 1
  96.    end /* do */
  97. end /* do */
  98.    
  99. if errflag then do
  100.    say '... failed.'
  101.    return 2
  102. end /* do */
  103. else do
  104.    if \ nowrite then say '... done.'
  105.    return 0
  106. end /* do */
  107.  
  108. /* finis */
  109.  
  110. appdelete:
  111. say 'Deleting the application '||APP||' from 'inifile' ...'
  112. ret = SysIni(inifile, APP, 'DELETE:')
  113. if ret <> '' then do
  114.    say '... failed.'
  115.    return 2
  116. end /* do */
  117. else do
  118.    say '... done.'
  119.    return 0
  120. end /* do */
  121.  
  122. appview:
  123. ret = SysIni(inifile, APP, 'ALL:', keys)
  124. if ret \= 'ERROR:' then do
  125.    do i=1 to keys.0
  126.       value = SysIni(inifile, APP, keys.i)
  127.       say keys.i '=' strip(value, 'T', '0'x)
  128.    end /* do */
  129.    return 0
  130. end /* do */
  131. else return 2
  132.  
  133. givehelp:
  134. say
  135. say VERSION
  136. say
  137. say 'Usage: TFCONFIG [FILE] [OPTIONS]'
  138. say
  139. say 'Update, view or clear TeX Front End settings.'
  140. say
  141. say '  /U  update (default)'
  142. say '  /N  list contents of configuration file only'
  143. say '  /V  view current settings'
  144. say '  /D  delete all settings'
  145. say
  146. say 'Settings are read from .\tfe.cfg, unless FILE is specified.'
  147. say 'A given filename is ignored, if /V or /D is requested.'
  148. say
  149. return 1
  150. /* eof */
  151.  
  152.