home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / bldmgr.zip / bldmgr.cmd
OS/2 REXX Batch file  |  2002-04-26  |  5KB  |  202 lines

  1. /* $Id: bldmgr.cmd,v 1.2 2002/04/26 23:09:43 smilcke Exp $ */
  2.  
  3. /* Copyright (c) 2002 by Stefan Milcke
  4.                          Küferstraße 45
  5.            28779 Bremen
  6.  
  7.    This Rexx-Script is Freeware
  8. */
  9. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs';
  10. Call SysLoadFuncs;
  11.  
  12. /* Preinitialize some variables */
  13. file='BUILDLVL.CMD'
  14. text='BUILD_LEVEL'
  15. va=1
  16. verbose=1
  17. action=''
  18. YYYY=Left(Date('S'),4)
  19. MM=Left(Right(Date('S'),4),2)
  20. DD=Right(Date('S'),2)
  21.  
  22. ArgError=0
  23. ShowUsage=0
  24.  
  25. /* Get and parse arguments */
  26. Parse Arg Arguments
  27. Do i=1 To Words(Arguments)
  28.  A=Word(Arguments,i)
  29.  B=Translate(A)
  30.  If Left(B,6)='/FILE:' Then file=Right(A,Length(A)-6)
  31.  else If Left(B,6)='/TEXT:' Then text=Right(A,Length(A)-6)
  32.  else If Left(B,8)='/ACTION:' Then action=Translate(Right(A,Length(A)-8))
  33.  else If Left(B,4)='UIET' Then verbose=0
  34.  else
  35.  Do
  36.   ShowUsage='Unknown argument:'A
  37.   ArgError=1
  38.  End
  39. End
  40.  
  41. If Length(text)>0 Then
  42. Do
  43.  If Left(text,1)='"' Then text=Right(text,Length(text)-1)
  44.  If Right(text,1)='"' Then text=Left(text,Length(text)-1)
  45. End
  46. If ArgError=0 Then
  47. Do
  48.  actionvalid=1
  49.  If Left(action,4)='INCR' Then
  50.  Do
  51.   If Length(action)>4 Then va=Right(action,Length(action)-5)
  52.   action='INCR'
  53.  End
  54.  Else If Left(action,4)='DECR' Then
  55.  Do
  56.   If Length(action)>4 Then va=Right(action,Length(action)-5)
  57.   action='DECR'
  58.  End
  59.  Else If Left(action,5)='QUERY' Then
  60.  Do
  61.  End
  62.  Else If Left(action,7)='SETDATE' Then
  63.  Do
  64.   va=DD"."MM"."YYYY
  65.   If Length(action)>7 Then va=Right(action,Length(action)-8)
  66.  End
  67.  Else If Left(action,7)='SETYEAR' Then
  68.  Do
  69.   va=YYYY
  70.   If Length(action)>7 Then va=Right(action,Length(action)-8)
  71.   action='SET'
  72.  End
  73.  Else If Left(action,8)='SETMONTH' Then
  74.  Do
  75.   va=MM
  76.   If Length(action)>8 Then va=Right(action,Length(action)-9)
  77.   action='SET'
  78.  End
  79.  Else If Left(action,6)='SETDAY' Then
  80.  Do
  81.   va=DD
  82.   If Length(action)>6 Then va=Right(action,Length(action)-7)
  83.   action='SET'
  84.  End
  85.  Else If Left(action,3)='SET' Then
  86.  Do
  87.   If Length(action)>3 Then va=Right(action,Length(action)-4)
  88.   action='SET'
  89.  End
  90.  Else
  91.  Do
  92.   actionvalid=0
  93.  End
  94.  If actionvalid=1 Then Call PerformAction
  95.  Else
  96.  Do
  97.   ShowUsage='Unknown /ACTION: option:'action
  98.  End
  99. End
  100.  
  101. If ShowUsage<>0 Then
  102. Do
  103.  Say ''
  104.  Say ShowUsage
  105.  Say ''
  106.  Call Usage
  107. End
  108. Exit
  109.  
  110. PerformAction: Procedure Expose file text action va verbose
  111.  tmpfile=SysTempFileName('bldmgr.???')
  112.  found=0
  113.  If Length(Stream(tmpfile,"C","QUERY EXISTS"))> 0 Then '@del 'tmpfile
  114.  rc=Stream(file,"C","OPEN READ")
  115.  If rc='READY:' Then
  116.  Do
  117.   rc=Stream(tmpfile,"C","OPEN WRITE")
  118.   Do Forever
  119.    If Lines(file)=0 Then Leave
  120.    line=LineIn(file)
  121.    If found=0 Then
  122.    Do
  123.     If Pos(text,line)>0 Then
  124.     Do
  125.      found=1
  126.      OLine=line
  127.      L=Left(line,Pos(text,line)+Length(text)-1)
  128.      line=Right(line,Length(line)-Length(L))
  129.      Do Forever
  130.       If (Left(line,1)<>' ') Then Leave
  131.       L=L' '
  132.       line=Right(line,Length(line)-1)
  133.      End
  134.      V='0'
  135.      If action='SETDATE' Then
  136.      Do
  137.       V=Left(line,10)
  138.       line=Right(line,Length(line)-10)
  139.      End
  140.      Else
  141.      Do
  142.       Do Forever
  143.        If Length(line)=0 Then Leave
  144.        If DataType(Left(line,1),'N')=0 Then Leave
  145.        V=V''Left(line,1)
  146.        line=Right(line,Length(line)-1)
  147.       End
  148.       V=Value(V)
  149.      End
  150.      If action='QUERY' Then
  151.      Do
  152.       Say V
  153.       line=OLine
  154.      End
  155.      Else
  156.      Do
  157.       If action='SETDATE' Then OV=V
  158.       Else OV=V+0
  159.       If action='INCR' Then V=V+va
  160.       else if action='DECR' Then V=V-va
  161.       else if action='SET' Then V=va
  162.       else if action='SETDATE' Then V=va
  163.       line=L''V''line
  164.       If verbose=1 Then
  165.       Do
  166.        Say 'Old value:'OV' replaced by:'V
  167.       End
  168.      End
  169.     End
  170.    End
  171.    rc=LineOut(tmpfile,line)
  172.   End
  173.  End
  174.  rc=Stream(file,"C","CLOSE")
  175.  rc=Stream(tmpfile,"C","CLOSE")
  176.  If found=1 Then
  177.  Do
  178.   '@copy 'tmpfile' 'file' > nul'
  179.  End
  180.  '@del 'tmpfile
  181. Return
  182.  
  183. Usage: Procedure
  184.  Say 'Usage: BLDMGR.CMD [Arguments]'
  185.  Say 'Arguments can be one of this:'
  186.  Say '/QUIET'
  187.  Say '       Do not display messages'
  188.  Say '/FILE:<FileName>'
  189.  Say '      Input file name'
  190.  Say '/TEXT:<Text>'
  191.  Say '      Text to search for'
  192.  Say '/ACTION:<INCR[:n] | DECR[:n] | QUERY | SETYEAR | SETMONTH | SETDAY | SET[n]>'
  193.  Say '        Action to perform on file'
  194.  Say '        INCR[:n]       Increments value after <Text> by n (default=1)'
  195.  Say '        DECR[:n]       Decrements value after <Text> by n (default=1)'
  196.  Say '        QUERY          Displays value after <Text>'
  197.  Say '        SETYEAR[:YYYY] Sets year YYYY after <Text> (default=current)'
  198.  Say '        SETMONTH[:MM]  Sets month MM after <Text> (default=current)'
  199.  Say '        SETDAY[:DD]    Sets day DD after <Text> (default=current)'
  200.  Say '        SET[:n]        Sets value after <Text> to n (default=1)'
  201. Return
  202.