home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 375.lha / bump.rexx < prev    next >
OS/2 REXX Batch file  |  1990-05-02  |  3KB  |  90 lines

  1.  /*
  2.  Bump.rexx - by Larry Phillips, 1990
  3.  Bump a source file by 1 revision or specify version and revsion
  4.  
  5. Usage: Bump filename [version] [revision]
  6.        If only filename specified, bump revision and perhaps version
  7.        If filename and version specified, bump version, make revision 00
  8.        If all three specified, set to given values
  9.  
  10.  If the revision is greater than 99, the revision will be set to 00, and
  11. the version will be bumped by 1.
  12.  
  13.  Source file must contain a lines with the strings 'VERSION' and 'REVISION',
  14. each on a separate line, and each line having a numeric value in the range
  15. 0-99 somewhere after the string. Additionally, the numeric value must be
  16. followed by at least one space.  Use a comment if necessary.
  17.  
  18. The lines must be within the first 1024 bytes of the beginning of the file.
  19.  
  20. Examples of valid lines in source:
  21.  
  22. #define VERSION     0    /**/
  23. #define REVISION    01   /**/
  24.  
  25. VERSION  EQU 5  ;
  26. REVISION EQU 10 ;
  27.  
  28. */
  29.  
  30. parse arg filename version revision
  31.  
  32. if filename = '' | filename = '?' then call usage
  33.  
  34. if version >= 0 then doversion = 1
  35. if version >= 0 & revision = '' then revision = 0
  36.  
  37. if open(infile,filename,'a') >0 then do
  38.   call seek(infile,0,'b')
  39.   inline = readch(infile,1024)
  40.  
  41.   rev = pos('REVISION',inline)
  42.   if rev > 0 then do
  43.     revstring = substr(inline,rev,pos('0a'x,inline,rev)-rev)
  44.     do i=2 to 3
  45.       if word(revstring,i) < 100 & word(revstring,i) ~< 0 then do
  46.         revoffset = rev + wordindex(revstring,i) - 2
  47.         revstring = word(revstring,i)
  48.         if revision = '' then revision = revstring + 1
  49.         if revision > 99 then revision = 0
  50.         if length(revision) = 1 then revision = '0' || revision
  51.         call seek(infile,revoffset,'b')
  52.         call writech(infile,strip(revision) || ' ')
  53.       end
  54.     end
  55.   end
  56.  
  57.   if revision = 0 | doversion = 1 then do
  58.     ver = pos('VERSION',inline)
  59.     if ver > 0 then do
  60.       verstring = substr(inline,ver,pos('0a'x,inline,ver)-ver)
  61.       do i=2 to 3
  62.         if word(verstring,i) < 100 & word(verstring,i) ~< 0 then do
  63.           veroffset = ver + wordindex(verstring,i) - 2
  64.           verstring = word(verstring,i)
  65.           if version = '' then version = verstring + 1
  66.           if version > 99 then version = 0
  67.           call seek(infile,veroffset,'b')
  68.           call writech(infile,strip(version) || ' ')
  69.         end
  70.       end
  71.     end
  72.   end
  73. end
  74.  
  75. else
  76.   say 'Cannot open' filename
  77. exit 0
  78.  
  79. usage:
  80.   do i = 5 to 9
  81.     say sourceline(i)
  82.   end
  83.   call writech(stdout,'Want more help? (Y/N) ')
  84.   temp = readch(stdin,10)
  85.   if verify(temp,'yY','match') > 0 then
  86.   do i = 9 to 25
  87.     say sourceline(i)
  88.   end
  89. exit 0
  90.