home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / dev / misc / cweb / arexx / start_web.ced < prev   
Encoding:
Text File  |  1993-12-21  |  9.4 KB  |  295 lines

  1. /*
  2. ** AREXX $VER: Start_Web.ced 2.0 (25.10.1993)
  3. **
  4. ** DESCRIPTION: This AREXX script saves and weaves or tangles the current
  5. **              CED Pro 3 view (it is very easy to use it with CED Pro 2).
  6. **              Then it loads the resulting `.tex' or `.c' file into a
  7. **              new view.  If a changefile is present to the webfile in
  8. **              the current view, i.e., a file with extension `.ch' instead
  9. **              of `.w' (or `.web'), it will be taken into account.  To use
  10. **              this script, install two calls in the DOS/ARexx interface
  11. **              of Cygnus Ed of the form
  12. **
  13. **                 CWeb:ARexx/Start_Web CTangle
  14. **                 CWeb:ARexx/Start_Web CWeave
  15. **
  16. ** DATE: 11.09.1992 (V0.1 and V0.2)
  17. ** AUTHOR: Andreas Scherer
  18. **         Abt-Wolf-Straße 17
  19. **         96215 Lichtenfels
  20. **         Germany
  21. **
  22. ** CHANGES: 25.10.1992: `change file' included (V0.3)
  23. **          28.02.1993: `.web' extension allowed (V0.4)
  24. **                      Options `+a +g' are default in my CWEAVE version.
  25. **          19.03.1993: Absolute path name from WEB file taken into
  26. **                      account due to CWEB 2.7 (V0.5)
  27. **          31.08.1993: CWeb 2.7 [p6b] now returns RC=[0,5,10,20];
  28. **                      give appropriate messages in CED (V0.6)
  29. **          07.09.1993: Rely on system path to find CTANGLE/CWEAVE (V0.7)
  30. **          03.10.1993: Refinement of program call for Cygnus Ed 3.5:
  31. **                      ARexx<-->CED window isn't temporary anymore;
  32. **                      output of CTANGLE/CWEAVE will be redirected
  33. **                      to the log file `T:web.log'.  This file is loaded
  34. **                      in case of an error (V0.8)
  35. **          06.10.1993: Single script for both CTANGLE and CWEAVE (V1.0)
  36. **          07.10.1993: Localization of all requester texts for German
  37. **                      and English users.  Catalog with the English
  38. **                      translation provided.  These features work for
  39. **                      WorkBench 2.1 and higher; the script works with
  40. **                      lower versions too (V1.1)
  41. **          09.10.1993: Updated for CWeb 2.8 (V1.2)
  42. **          20.10.1993: Allow special device name "RAM DISK:" (V1.3)
  43. **          25.10.1993: Updated for CWeb 3.0 (V2.0)
  44. **
  45. ** COPYRIGHT: (c) 1993 Andreas Scherer
  46. **
  47. ** Permission is granted to make and distribute verbatim copies of this
  48. ** document provided that the copyright notice and this permission notice
  49. ** are preserved on all copies.
  50. **
  51. ** Permission is granted to copy and distribute modified versions of this
  52. ** document under the conditions for verbatim copying, provided that the
  53. ** entire resulting derived work is distributed under the terms of a
  54. ** permission notice identical to this one.
  55. */
  56.  
  57. Options FailAt 21
  58. Options Results
  59.  
  60. /*
  61. ** The pre-1.0 version of this script actually consisted of two
  62. ** separate scripts for CTANGLE and CWEAVE.  To facilitate further
  63. ** improvements, the name of the program we want to call is passed
  64. ** as a single argument on startup.  It should be one of the
  65. ** strings `CTangle' or `CWeave'.
  66. */
  67. Parse Arg PROG_NAME
  68.  
  69. /*
  70. ** Since CTANGLE either has the same command line options as CWEAVE
  71. ** or ignores the others it is save to have a common specification
  72. ** of activated or deactivated switches.  According to the CWeb user
  73. ** manual options are activated by `+' and deactivated by `-'.
  74. ** The current implementation of the programs understand the following
  75. ** list of command line options:
  76. **
  77. **     a - Amiga-defined identifiers are keywords [+] (W)
  78. **     b - Print a banner line                    [+] (TW)
  79. **     f - Force line breaks                      [+] (W)
  80. **     g - Use German macros `gcwebmac.tex'       [+] (W)
  81. **     h - Print a happy message                  [+] (TW)
  82. **     i - Indent parameter declarations          [+] (W)
  83. **     p - Give progress report                   [+] (TW)
  84. **     s - Show statistics                        [-] (TW)
  85. **     x - Include indexes and table of contents  [+] (W)
  86. **
  87. ** The hard-wired defaults are in brackets.  A `T' or `W' in
  88. ** braces indicates that CTANGLE or CWEAVE acknowledges the option.
  89. **
  90. ** For the purposes of this script we set the default language
  91. ** to English and request that the statistics be written to the
  92. ** log file as explained below.  Also I prefer that parameter
  93. ** declarations be not indented.
  94. */
  95. WEB_OPTS = "-gi +s"
  96.  
  97. /*
  98. ** WorkBench 2.1/3.0 users are provided with localized messages in
  99. ** their system default language.  This may be either German or English.
  100. ** (Other languages are welcome!)  Default in this script, in case the
  101. ** catalogs can not be used, is the German version for all arguments
  102. ** to the `GetCatalogStr' function.  (You will have to edit these strings
  103. ** by hand if you don't have WorkBench 2.1/3.0, so go get the latest
  104. ** version of the best!)
  105. */
  106. If 38 <= MyGetEnv("WORKBENCH") Then
  107.   If ~Show('Libraries','locale.library') Then
  108.     Call AddLib('locale.library',0,-30)
  109.  
  110. LOCALE_FOUND = Show('Libraries','locale.library')
  111.  
  112. If 1 = LOCALE_FOUND Then Do
  113.   catalog = OpenCatalog("cweb.catalog","deutsch",0);
  114.  
  115. /*
  116. ** Give a little progress message to the Cygnus Ed 3.5 user.  Comment
  117. ** this out if you use Cygnus Ed 2.12.
  118. */
  119. If 'CTangle' = PROG_NAME Then
  120.   DM "CTangle V3.0 [p8d] Copyright © 1993 Andreas Scherer"
  121. Else
  122.   DM "CWeave V3.0 [p8d] Copyright © 1993 Andreas Scherer"
  123.  
  124. /*
  125. ** Get the full filename from CED.
  126. */
  127. Status FileName /* 19 */
  128. FULLNAME = RESULT
  129.  
  130. /*
  131. ** Make "RAM DISK:" a special case.
  132. */
  133. if "RAM DISK:" = Upper(Left(FULLNAME,9)) Then
  134.   FULLNAME = "RAM:" ||  SubStr(FULLNAME,10)
  135.  
  136. /*
  137. ** Error messages and warnings of CTANGLE and CWEAVE will be written
  138. ** to a temporary log file, which can be loaded for debugging.  It will
  139. ** contain the complete screen output of CTANGLE/CWEAVE.
  140. */
  141. LOGFILE = "T:web.log"
  142.  
  143. /*
  144. ** We need an absolute file name.
  145. */
  146. IVOL     = Index(FULLNAME,":")
  147. IDIRS    = LastPos("/",SubStr(FULLNAME,1+IVOL))
  148. FILEONLY = SubStr(FULLNAME,IVOL+1+IDIRS)
  149. IBASE    = LastPos(".",FILEONLY)
  150.  
  151. If 0 = IBASE Then
  152.   IBASE = Length(FILEONLY)
  153. Else
  154.   IBASE = IBASE - 1
  155.  
  156. /*
  157. ** CWeb files normally have a `.w' extension.
  158. */
  159. If "" = SubStr(FULLNAME,1+IVOL+IDIRS+IBASE) | "W" ~= Upper(Right(FULLNAME,1)) Then Do
  160.  
  161. /*
  162. ** But you may also use the `.web' form.
  163. */
  164.   If "" = SubStr(FULLNAME,1+IVOL+IDIRS+IBASE) | "WEB" ~= Upper(Right(FULLNAME,3)) Then Do
  165.     If 1 = LOCALE_FOUND Then
  166.       Okay1 GetCatalogStr(catalog,0,"Fehler, die Datei muß eine Endung `.w' oder `.web' haben.")
  167.     Else
  168.       Okay1 "Fehler, die Datei muß eine Endung `.w' oder `.web' haben."
  169.  
  170.     Call EndGame
  171.   End
  172. End
  173.  
  174. If 0 = IVOL Then Do
  175.   DIREC = Pragma('d')
  176.   If '/' ~= Right(DIREC,1) & ':' ~= Right(DIREC,1) Then
  177.     DIREC = DIREC||'/'
  178.   FULLNAME = DIREC||FULLNAME
  179.   Drop DIREC
  180. End
  181.  
  182. /*
  183. ** In case there is a `change file', it has a `.ch' extension.
  184. */
  185. CHANGEFILE = Left(FULLNAME,IVOL+IDIRS+IBASE)||'.ch'
  186.  
  187. /*
  188. ** This file will hopefully be created by CTANGLE/CWEAVE.
  189. */
  190. If 'CTangle' = PROG_NAME Then
  191.   RESULTFILE = Left(FULLNAME,IVOL+IDIRS+IBASE)||'.c'
  192. If 'CWeave' = PROG_NAME Then
  193.   RESULTFILE = Left(FULLNAME,IVOL+IDIRS+IBASE)||'.tex'
  194.  
  195. /*
  196. ** Remember the path name of the WEB file.
  197. */
  198. PATHNAME = Left(FULLNAME,IVOL+IDIRS)
  199.  
  200. Drop IVOL IDIRS IBASE
  201.  
  202. /*
  203. ** Save only if the file has been modified.
  204. ** So get the number of changes to the file.
  205. */
  206. Status NumChanges /* 18 */
  207. If 0 < RESULT Then
  208.   Save
  209.  
  210. /*
  211. ** Change the current directory first.
  212. */
  213. Pragma('Directory',PATHNAME)
  214.  
  215. /*
  216. ** Now call the CTANGLE or the CWEAVE program.  We don't change the
  217. ** host address, because there may be more than one Cygnus Ed running,
  218. ** each having its own ARexx port name.
  219. */
  220. If Exists(CHANGEFILE) Then
  221.   Address COMMAND PROG_NAME WEB_OPTS FULLNAME CHANGEFILE ">"LOGFILE
  222. Else
  223.   Address COMMAND PROG_NAME WEB_OPTS FULLNAME ">"LOGFILE
  224.  
  225. /*
  226. ** Patch level [p6b] of `common.w' now returns error and warning codes
  227. ** as defined for the AMIGA system.  Take appropriate actions.
  228. */
  229. If 20 = RC Then Do
  230.   If 1 = LOCALE_FOUND Then
  231.     Okay1 PROG_NAME || " " || GetCatalogStr(catalog,1,"mit fatalem Fehler abgebrochen! Keine Ausgabe!")
  232.   Else
  233.     Okay1 PROG_NAME || " " || "mit fatalem Fehler abgebrochen! Keine Ausgabe!"
  234.   OW LOGFILE
  235.   Call EndGame
  236. End; Else If 10 = RC Then Do
  237.   If 1 = LOCALE_FOUND Then
  238.     Okay1 PROG_NAME || " " || GetCatalogStr(catalog,2,"beendet mit Fehler! Ausgabe fehlerhaft!")
  239.   Else
  240.     Okay1 PROG_NAME || " " || "beendet mit Fehler! Ausgabe fehlerhaft!"
  241.   OW LOGFILE
  242.   Call EndGame
  243. End; Else If 5 = RC Then Do
  244.   If 1 = LOCALE_FOUND Then
  245.     Okay2 PROG_NAME || " " || GetCatalogStr(catalog,3,"beendet mit Warnung!" || '0A'X || "Ausgabe wahrscheinlich korrekt.")
  246.   Else
  247.     Okay2 PROG_NAME || " " || "beendet mit Warnung!" || '0A'X || "Ausgabe wahrscheinlich korrekt."
  248.  
  249.   If 0 = RESULT Then Do
  250.     OW LOGFILE
  251.     Call EndGame
  252.   End
  253. End
  254.  
  255. /*
  256. ** Now load the resulting `.tex' or `.c' file into a new CED view.
  257. */
  258. If Exists(RESULTFILE) Then Do
  259.   'jump to file "'RESULTFILE'"'
  260.  
  261. /*
  262. ** The `.tex'- or `.c'-file is already in a CED view.  Leave it, then
  263. ** load it again.  Is there a better way to do this?
  264. */
  265.   If 0 ~= RESULT Then
  266.     Quit
  267.  
  268.   Open new
  269.   Open RESULTFILE
  270. End; Else
  271.   If 1 = LOCALE_FOUND Then
  272.     Okay1 GetCatalogStr(catalog,4,"Fehler bei") || " " || PROG_NAME
  273.   Else
  274.     Okay1 "Fehler bei" || " " || PROG_NAME
  275.  
  276. EndGame:
  277.   If 1 = LOCALE_FOUND Then
  278.     CloseCatalog(catalog);
  279.   DM
  280.   Exit
  281. Return
  282.  
  283. /*
  284. ** When will ARexx supply GetEnv/SetEnv?
  285. */
  286. MyGetEnv: Procedure
  287. Parse Arg NAME
  288.  
  289. If Open(TEMPFILE,"ENV:"||NAME,'r') Then Do
  290.   GIVES = Readln(TEMPFILE)
  291.   Call Close TEMPFILE
  292. End; Else GIVES = 37
  293.  
  294. Return GIVES
  295.