home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / dev / c / cweb / arexx / start_web.ced < prev   
Encoding:
Text File  |  1994-12-03  |  12.6 KB  |  366 lines

  1. /*
  2.  * AREXX $VER: Start_Web.ced 3.12 (03.12.1994)
  3.  *
  4.  * DESCRIPTION: This AREXX script saves and weaves or tangles the current
  5.  *              CED Pro 3 view (it is very easy to use this script with
  6.  *              version 2 of CED, just look for the keyword `CED2' and
  7.  *              change by hand).  Then it loads the resulting `.tex' or
  8.  *              `.c' or `.cpp' file into a new view.  If a changefile is
  9.  *              present to the webfile in the current view, i.e., a file
  10.  *              with extension `.ch' instead of `.w' (or `.web' or `.wpp'),
  11.  *              it will be taken into account.  To use this script, install
  12.  *              two calls in the DOS/ARexx interface of CED of the form
  13.  *
  14.  *                 CWeb:ARexx/Start_Web CTangle
  15.  *                 CWeb:ARexx/Start_Web CWeave
  16.  *
  17.  *              If you are a COOL programmer and want to receive C++ source
  18.  *              files with an appropriate extension, you should add a third
  19.  *              call of the form
  20.  *
  21.  *                 CWeb:ARexx/Start_Web CTangle ++
  22.  *
  23.  *              with two arguments, so that CTANGLE will produce `.cpp'
  24.  *              file extensions.  You don't need a second entry for CWEAVE
  25.  *              when using C++, since CWEAVE always produces `.tex' files.
  26.  *
  27.  * CREATION DATE: 11.09.1992 (V0.1 and V0.2)
  28.  *
  29.  * AUTHOR: Andreas Scherer
  30.  *         Roland-Straße 16
  31.  *         52070 Aachen
  32.  *         Germany
  33.  *         <scherer@genesis.informatik.rwth-aachen.de>
  34.  *
  35.  * CHANGES: 25.10.1992: `change file' included (V0.3)
  36.  *          28.02.1993: `.web' extension is now permissible (V0.4)
  37.  *                      Options `+a +g' are default in my CWEAVE version.
  38.  *          19.03.1993: Absolute path name of the WEB file is taken into
  39.  *                      account due to CWEB 2.7 (V0.5)
  40.  *          31.08.1993: CWEB 2.7 [p6b] now returns RC=[0,5,10,20];
  41.  *                      give appropriate messages in CED (V0.6)
  42.  *          07.09.1993: Rely on system path to find CTANGLE/CWEAVE (V0.7)
  43.  *          03.10.1993: Refinement of program call for Cygnus Ed 3.5:
  44.  *                      ARexx<-->CED window isn't temporary anymore;
  45.  *                      output of CTANGLE/CWEAVE will be redirected
  46.  *                      to the log file `T:web.log'.  This file is loaded
  47.  *                      in case of an error (V0.8)
  48.  *          06.10.1993: Single script for both CTANGLE and CWEAVE (V1.0)
  49.  *          07.10.1993: Localization of all requester texts for German
  50.  *                      and English users.  Catalog with the English
  51.  *                      translation provided.  These features work for
  52.  *                      WorkBench 2.1 and higher; the script works with
  53.  *                      lower versions too (V1.1)
  54.  *          09.10.1993: Updated for CWEB 2.8 (V1.2)
  55.  *          20.10.1993: Allow special device name "RAM DISK:" (V1.3)
  56.  *          25.10.1993: Updated for CWEB 3.0 (V2.0)
  57.  *          04.11.1993: New patch level CWEB 3.0 [p8e] (V2.1)
  58.  *          10.11.1993: Saving bug fixed, a negative number of changes
  59.  *                      is possible for the current view (V2.2)
  60.  *          18.11.1993: Updated for CWEB 3.1 (V2.3)
  61.  *          19.11.1993: Naming simplification (V2.4)
  62.  *          21.11.1993: When called `CTangle ++', this script produces
  63.  *                      C++ output files with `.cpp' extensions.  Also
  64.  *                      the new extension `.wpp' is permissible (V3.0)
  65.  *          30.11.1993: New patch level CWEB 3.1 [p9a] (V3.1)
  66.  *          06.12.1993: Localization improved and new catalog name to
  67.  *                      avoid collisions with the localization of
  68.  *                      CWEB 3.1 [p9b] (V3.2)
  69.  *          01.01.1994: Pre-V38 users want to see the warning and
  70.  *                      error messages as well (V3.3)
  71.  *          31.01.1994: We are at patch level [p9c].
  72.  *                      RESULTFILE is not editable. (V3.4)
  73.  *          02.04.1994: Localization improved; only one set of
  74.  *                      default strings needed (V3.5)
  75.  *          13.04.1994: PROG_NAME tested in uppercase mode (V3.6)
  76.  *          13.05.1994: New patch level [p9d]. (V3.7)
  77.  *          24.06.1994: New option `m'.  (V3.8)
  78.  *          12.08.1994: Updated for CWEB 3.2 [p10] (V3.9)
  79.  *          24.08.1994: New option flag list.  (V3.10)
  80.  *          20.09.1994: German macros renamed.  (V3.11)
  81.  *          03.12.1994: Updated for CWEB 3.3 [p11] (V3.12)
  82.  *
  83.  * COPYRIGHT: (c) 1992-1994 Andreas Scherer
  84.  *
  85.  * Permission is granted to make and distribute verbatim copies of this
  86.  * document provided that the copyright notice and this permission notice
  87.  * are preserved on all copies.
  88.  *
  89.  * Permission is granted to copy and distribute modified versions of this
  90.  * document under the conditions for verbatim copying, provided that the
  91.  * entire resulting derived work is given a different name and distributed
  92.  * under the terms of a permission notice identical to this one.
  93.  */
  94.  
  95. Options FailAt 21
  96. Options Results
  97.  
  98. /*
  99.  * The pre-1.0 version of this script actually consisted of two
  100.  * separate scripts for CTANGLE and CWEAVE.  To facilitate further
  101.  * improvements, the name of the program we want to call is passed
  102.  * as a single argument on startup, possibly with a second `++' for
  103.  * C++ programmers.  It should be one of the strings `CTangle',
  104.  * `CTangle ++' (watch your space!) or `CWeave'.  (You don't need an
  105.  * extra `CWeave ++' command.)
  106.  */
  107. Parse Arg PROG_NAME CPP .
  108.  
  109. /*
  110.  * Since CTANGLE either has the same command line options as CWEAVE
  111.  * or ignores the others it is save to have a common specification
  112.  * of activated or deactivated switches.  According to the CWEB user
  113.  * manual options are activated by `+' and deactivated by `-'.
  114.  * The current implementation of the programs understand the following
  115.  * list of command line options:
  116.  *
  117.  *     b  - Print a banner line                    [+] (TW)
  118.  *     f  - Force line breaks                      [+] (W)
  119.  *     h  - Print a happy message                  [+] (TW)
  120.  *     i  - Indent parameter declarations          [+] (W)
  121.  *     lX - Use macros `Xcwebmac.tex'              [ ] (W)
  122.  *     m  - ARexx communication to SAS/C's browser [-] (TW)
  123.  *     o  - Separate declarations and statements   [+] (W)
  124.  *     p  - Give progress report                   [+] (TW)
  125.  *     s  - Show statistics                        [-] (TW)
  126.  *     x  - Include indexes and table of contents  [+] (W)
  127.  *
  128.  * The hard-wired defaults are in brackets.  A `T' or `W' in
  129.  * braces indicates that CTANGLE or CWEAVE acknowledges the option.
  130.  *
  131.  * For the purposes of this script I set the default language
  132.  * to German and request that the statistics are written to the
  133.  * log file as explained below.  Also I prefer that parameter
  134.  * declarations do not get indented in old-style function headers.
  135.  */
  136. WEB_OPTS = "-i +ld +s"
  137.  
  138. /*
  139.  * WorkBench 2.1/3.0 users are provided with localized messages in
  140.  * their system default language.  This may be either German or English.
  141.  * (Other languages are welcome!)  Default in this script, in case the
  142.  * catalogs can not be used, is the German version for all arguments
  143.  * to the `GetCatalogStr' function.  (You will have to edit these strings
  144.  * by hand if you don't have WorkBench 2.1/3.0, so go get the latest
  145.  * version of the best!)
  146.  */
  147. MSG_ERROR_EXTENSION = "Fehler, die Datei muß eine Endung `.w', `.web' oder `.wpp' haben."
  148. MSG_ERROR_FATAL     = "mit fatalem Fehler abgebrochen! Keine Ausgabe!"
  149. MSG_ERROR_ERROR     = "beendet mit Fehler! Ausgabe fehlerhaft!"
  150. MSG_ERROR_WARNING   = "beendet mit Warnung!" || '0A'X || "Ausgabe wahrscheinlich korrekt."
  151. MSG_ERROR_END       = "Fehler bei"
  152.  
  153. If 38 <= MyGetEnv("WORKBENCH") Then
  154.   If ~Show('Libraries','locale.library') Then
  155.     Call AddLib('locale.library',0,-30)
  156.  
  157. LOCALE_FOUND = Show('Libraries','locale.library')
  158.  
  159. If 1 = LOCALE_FOUND Then Do
  160.   catalog = OpenCatalog("cweb_arexx.catalog","deutsch",0);
  161.   MSG_ERROR_EXTENSION = GetCatalogStr(catalog,0,MSG_ERROR_EXTENSION)
  162.   MSG_ERROR_FATAL     = GetCatalogStr(catalog,1,MSG_ERROR_FATAL)
  163.   MSG_ERROR_ERROR     = GetCatalogStr(catalog,2,MSG_ERROR_ERROR)
  164.   MSG_ERROR_WARNING   = GetCatalogStr(catalog,3,MSG_ERROR_WARNING)
  165.   MSG_ERROR_END       = GetCatalogStr(catalog,4,MSG_ERROR_END)
  166. End
  167.  
  168. /*
  169.  * Give a little progress message to the Cygnus Ed 3.5 user.
  170.  * Comment this out if you use Cygnus Ed 2.12 (CED2).
  171.  */
  172. DM PROG_NAME "(Amiga Version 3.3) Copyright © 1993-1994 Andreas Scherer"
  173.  
  174. /*
  175.  * Get the full filename from CED.
  176.  * CED2 uses numbers instead of strings.
  177.  */
  178. Status FileName /* 19  */
  179. FULLNAME = RESULT
  180.  
  181. /*
  182.  * Make "RAM DISK:" a special case.
  183.  */
  184. If "RAM DISK:" = Upper(Left(FULLNAME,9)) Then
  185.   FULLNAME = "RAM:" ||  SubStr(FULLNAME,10)
  186.  
  187. /*
  188.  * Error messages and warnings of CTANGLE and CWEAVE will be written
  189.  * to a temporary log file, which can be loaded for debugging.  It will
  190.  * contain the complete screen output of CTANGLE/CWEAVE.
  191.  */
  192. LOGFILE = "T:cweb.log"
  193.  
  194. /*
  195.  * We need an absolute file name.
  196.  */
  197. IVOL     = Index(FULLNAME,":")
  198. IDIRS    = LastPos("/",SubStr(FULLNAME,1+IVOL))
  199. FILEONLY = SubStr(FULLNAME,IVOL+1+IDIRS)
  200. IBASE    = LastPos(".",FILEONLY)
  201.  
  202. If 0 = IBASE Then
  203.   IBASE = Length(FILEONLY)
  204. Else
  205.   IBASE = IBASE - 1
  206.  
  207. /*
  208.  * CWEB files normally have a `.w' extension.
  209.  */
  210. If "" = SubStr(FULLNAME,1+IVOL+IDIRS+IBASE) | "W" ~= Upper(Right(FULLNAME,1)) Then Do
  211.  
  212. /*
  213.  * But you may also use the `.web' form.
  214.  */
  215.   If "" = SubStr(FULLNAME,1+IVOL+IDIRS+IBASE) | "WEB" ~= Upper(Right(FULLNAME,3)) Then Do
  216.  
  217. /*
  218.  * And for C++ programmers there is even the `.wpp' form, so they can mix
  219.  * ANSI-C and COOL programs in the same directory.
  220.  */
  221.     If "" = SubStr(FULLNAME,1+IVOL+IDIRS+IBASE) | "WPP" ~= Upper(Right(FULLNAME,3)) Then Do
  222.  
  223. /*
  224.  * No other file extensions will be accepted.
  225.  */
  226.       Okay1 MSG_ERROR_EXTENSION
  227.       Call EndGame
  228.     End
  229.   End
  230. End
  231.  
  232. /*
  233.  * Fix the full name of the file including device or directory name.
  234.  */
  235. If 0 = IVOL Then Do
  236.   DIREC = Pragma('d')
  237.   If '/' ~= Right(DIREC,1) & ':' ~= Right(DIREC,1) Then
  238.     DIREC = DIREC||'/'
  239.   FULLNAME = DIREC||FULLNAME
  240.   Drop DIREC
  241. End
  242.  
  243. /*
  244.  * In case there is a `change file', it has a `.ch' extension.  If there
  245.  * is no change file in the current directory a dummy value is inserted.
  246.  */
  247. CHANGEFILE = Left(FULLNAME,IVOL+IDIRS+IBASE)||'.ch'
  248.  
  249. If ~Exists(CHANGEFILE) Then
  250.   CHANGEFILE = "-"
  251.  
  252. /*
  253.  * This file will hopefully be created by CTANGLE/CWEAVE.
  254.  */
  255. RESULTFILE = Left(FULLNAME,IVOL+IDIRS+IBASE)
  256.  
  257. If 'CTANGLE' = Upper(PROG_NAME) Then Do
  258.   If '++' = CPP Then
  259.     RESULTFILE = RESULTFILE||'.cpp'
  260.   Else
  261.     RESULTFILE = RESULTFILE||'.c'
  262. End
  263. If 'CWEAVE' = Upper(PROG_NAME) Then
  264.   RESULTFILE = RESULTFILE||'.tex'
  265.  
  266. /*
  267.  * Remember the path name of the WEB file.
  268.  */
  269. PATHNAME = Left(FULLNAME,IVOL+IDIRS)
  270.  
  271. Drop IVOL IDIRS IBASE
  272.  
  273. /*
  274.  * Save only if the file has been modified.  So get the number of changes
  275.  * to the file in the current view.  This number can be negative! so test
  276.  * for unequal to zero instead of greater than zero.  CED2 uses numbers
  277.  * instead of strings.
  278.  */
  279. Status NumChanges /* 18  */
  280. If 0 ~= RESULT Then
  281.   Save
  282.  
  283. /*
  284.  * Change the current directory first.
  285.  */
  286. Pragma('Directory',PATHNAME)
  287.  
  288. /*
  289.  * Now call the CTANGLE or the CWEAVE program.  We don't change the
  290.  * host address, because there may be more than one Cygnus Ed running,
  291.  * each having its own ARexx port name and we want to see the results
  292.  * in the right one.
  293.  */
  294. Address COMMAND PROG_NAME WEB_OPTS FULLNAME CHANGEFILE RESULTFILE ">" LOGFILE
  295.  
  296. /*
  297.  * Patch level [p6b] of `common.w' now returns error and warning codes
  298.  * as defined for the AMIGA system.  Take appropriate actions.
  299.  */
  300. If 20 = RC Then Do
  301.   Okay1 PROG_NAME MSG_ERROR_FATAL
  302.   OW LOGFILE /* Use 'jump to file' with CED2.  */
  303.   Call EndGame
  304. End; Else If 10 = RC Then Do
  305.   Okay1 PROG_NAME MSG_ERROR_ERROR
  306.   OW LOGFILE /* Use 'jump to file' with CED2.  */
  307.   Call EndGame
  308. End; Else If 5 = RC Then Do
  309.   Okay2 PROG_NAME MSG_ERROR_WARNING
  310.  
  311.   If 0 = RESULT Then Do
  312.     OW LOGFILE /* Use 'jump to file' with CED2.  */
  313.     Call EndGame
  314.   End
  315. End
  316.  
  317. /*
  318.  * Make sure the WEB-file is loaded.  This works with CED 3.5+ only.
  319.  */
  320. OW FULLNAME
  321.  
  322. /*
  323.  * Now load the resulting `.tex' or `.c' file into a new CED view.
  324.  */
  325. If Exists(RESULTFILE) Then Do
  326.   'jump to file "'RESULTFILE'"'
  327.  
  328. /*
  329.  * The `.tex'- or `.c'-file is already in a CED view.  Leave it, then
  330.  * load it again.  Is there a better way to do this?
  331.  */
  332.   If 0 ~= RESULT Then
  333.     Quit
  334.  
  335.   Open new
  336.   Open RESULTFILE
  337.  
  338. /*
  339.  * Make sure the resultfile can't be edited.
  340.  */
  341.   Status Editable
  342.   If 1 = RESULT Then
  343.     Editable File
  344. End; Else
  345.   Okay1 MSG_ERROR_END PROG_NAME
  346.  
  347. EndGame:
  348.   If 1 = LOCALE_FOUND Then
  349.     CloseCatalog(catalog);
  350.   DM /* Comment this out when using CED2.  */
  351.   Exit
  352. Return
  353.  
  354. /*
  355.  * When will ARexx supply GetEnv/SetEnv?
  356.  */
  357. MyGetEnv: Procedure
  358. Parse Arg NAME
  359.  
  360. If Open(TEMPFILE,"ENV:"||NAME,'r') Then Do
  361.   GIVES = Readln(TEMPFILE)
  362.   Call Close TEMPFILE
  363. End; Else GIVES = 37
  364.  
  365. Return GIVES
  366.