home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd2.bin / bbs / dev / cweb-3.2.lha / CWeb / arexx / start_web.ced < prev   
Text File  |  1994-08-12  |  13KB  |  363 lines

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