home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gawk213s.lzh / GAWK213S / VERSION.COM < prev    next >
Text File  |  1993-07-29  |  2KB  |  63 lines

  1. $! version.com -- very crude 'sh' for processing gawk's version.sh    [pr]
  2. $!
  3. $!    Use version.sh to create version.c, substituting the current
  4. $!    version identification.
  5. $!
  6. $  on error    then  goto unhandled_error
  7. $  on control_Y then  goto error_exit
  8. $  if p1.nes."" then  goto p1_ok
  9. $    write sys$error "you must specify a release number on the command line"
  10. $    goto error_exit
  11. $p1_ok:
  12. $  key = ""    !no substitution target yet
  13. $  open/read/error=cant_open_sh f_in version.sh
  14. $prolog_loop:
  15. $    read/end=eof_in_prolog f_in buf
  16. $      ! look for ``RELEASE="$1"''
  17. $    if f$locate("$1",buf).lt.f$length(buf) then  key = f$element(0,"=",buf)
  18. $      ! look for ``cat << EOF''
  19. $    if f$extract(0,3,buf).nes."cat" then  goto prolog_loop
  20. $      ! found ``cat''; look for "<" and assume that it's actually "<<"
  21. $    eof_token = f$edit(f$element(2,"<",buf),"TRIM")
  22. $    key = "${" + key + "}"    !"RELEASE" -> "${RELEASE}"
  23. $    open/write/error=cant_open_c f_out version.c
  24. $copy_loop:
  25. $    read/end=eof_too_soon f_in buf
  26. $      ! check for EOF sentinel
  27. $    if buf.eqs.eof_token then  goto copy_done
  28. $    pos = 0
  29. $subs: ! look for substitution target
  30. $    pos = pos + f$locate(key,f$extract(pos,999,buf))
  31. $    if pos.eq.f$length(buf) then goto substitute_done
  32. $      ! perform substitution
  33. $    buf = f$extract(0,pos,buf) + p1 + f$extract(pos+f$length(key),999,buf)
  34. $    pos = pos + f$length(p1) - f$length(key)
  35. $    goto subs    !look at the resulting line again
  36. $substitute_done:
  37. $    write f_out buf
  38. $    goto copy_loop
  39. $copy_done:
  40. $  close f_in
  41. $  close f_out
  42. $  exit        !success
  43. $!
  44. $! rudimentary error handling
  45. $cant_open_sh:
  46. $  write sys$error "Could not open ""version.sh"" for input"
  47. $  goto error_exit
  48. $cant_open_c:
  49. $  write sys$error "Could not create ""version.c"" for output"
  50. $  goto error_exit
  51. $eof_in_prolog:
  52. $  write sys$error "Never found ""cat"" command for controlling output"
  53. $  goto error_exit
  54. $eof_too_soon:
  55. $  write sys$error "Never found """,eof_token,""" line for terminating output"
  56. $  goto error_exit
  57. $unhandled_error:
  58. $  write sys$error "Unexpected error encountered" !this won't be much help :-(
  59. $error_exit:
  60. $  if f$trnlmn("f_in") .nes."" then  close/nolog f_in
  61. $  if f$trnlmn("f_out").nes."" then  close/nolog f_out
  62. $  exit %x1000002C    !SS$_ABORT | STS$M_INHIB_MSG
  63.