home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / prog / arexx / makevers.lha / makeversion.rexx next >
Encoding:
OS/2 REXX Batch file  |  1991-07-30  |  3.2 KB  |  123 lines

  1. ==========================
  2. amiga.sw/programs #656, from langeveld, 3118 chars, Tue Jul 30 04:23:48 1991
  3. There is/are comment(s) on this message.
  4. --------------------------
  5. /* makevers.rexx
  6. **
  7. **   $VER: MakeVers version 1.0 (30.07.1991)
  8. **   =======================================
  9. **
  10. **   A quickie "bumprev" utility. Finds the first line with "$VER: " in it,
  11. **   parses it, and updates the version and/or revision number and the date,
  12. **   based on the significant number of digits specified on the command line.
  13. **   Since it leaves the rest of the line alone, this can be used with just
  14. **   about any file, even this one (since it only does the first line!)
  15. **
  16. **   Usage:   makevers <filename> <digits> [<force-version>]
  17. **
  18. **   Examples: MakeVers MyHeader.h 1
  19. **             Makevers MyApp.c 2 1.0
  20. **             Makevers MyProg.asm 3
  21. **
  22. **   Willy Langeveld, July 1991
  23. **
  24. */
  25.    parse arg filename ndigits forceversion .
  26.  
  27.    if filename = "" then do
  28.       say "Usage: bumprev <filename> <# digits>"
  29.       exit 20
  30.    end
  31.  
  32.    if ndigits = "" then ndigits = 1
  33. /*
  34. *   Read the file in
  35. */
  36.    if ~open(fh, filename, "R") then do
  37.       say "File " filename " does not exist"
  38.       exit 20
  39.    end
  40.  
  41.    do i = 1
  42.       str.i = readln(fh)
  43.       if eof(fh) then leave
  44.    end
  45.    call close(fh)
  46.    nlines = i - 1
  47. /*
  48. *   Now write the file back out
  49. */
  50.    if ~open(fh, filename, "W") then do
  51.       say "File " filename " can't be modified"
  52.       exit 20
  53.    end
  54. /*
  55. *   linefound will be set to 0 if the line is found
  56. */
  57.    linefound = 20
  58.    do i = 1 to nlines
  59.       string = str.i
  60.       if (index(string, "$VER: ") ~= 0) & (linefound ~= 0) then do
  61. /*
  62. *   This is a good candidate for the string.
  63. */
  64.          parse var string first "$VER: " name "(" date ")" last
  65.          n = words(name)
  66.          if forceversion = "" then do
  67.             fullversion = subword(name, n, 1)
  68.             if datatype(fullversion, numeric) then do
  69. /*
  70. *   This is it, update the revision number, truncate to right number of digits
  71. */
  72.                fullversion = fullversion + 10**(-ndigits)
  73.                parse var fullversion version "." revision
  74.                revision = substr(revision, 1, ndigits, "0")
  75.                fullversion = version || "." || revision
  76.             end
  77.             else do
  78. /*
  79. *   Datatype seems to not be numeric! Maybe better write this one out as
  80. *   is and continue looking.
  81. */
  82.                call writeln(fh, string)
  83.                iterate i
  84.             end
  85.          end
  86.          else fullversion = forceversion
  87. /*
  88. *   Get the date in standard format
  89. */
  90.          thedate = date(o)
  91.          parse var thedate year "/" month "/" day .
  92.          if year > 77 then year = year + 1900
  93.          else              year = year + 2000
  94. /*
  95. *   Assemble the string
  96. */
  97.          newstr = first  || "$VER: " || subword(name, 1, n - 1)
  98.          newstr = newstr || " " || fullversion || " "
  99.          newstr = newstr || "(" || day || "." || month || "." || year || ")"
  100.          newstr = newstr || last
  101.  
  102.          linefound = 0
  103. /*
  104. *   Confirm update
  105. */
  106.          say newstr
  107.       end
  108.       else do
  109.          newstr = string
  110.       end
  111.  
  112.       call writeln(fh, newstr)
  113.    end
  114. /*
  115. *   All done. If no line found, say so.
  116. */
  117.    call close(fh)
  118.  
  119.    if linefound ~= 0 then say "No version string found"
  120.  
  121.    exit linefound
  122.  
  123.