home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Docs / cwebbin-p13.lha / cwebbin-p13 / arexx / start_web.ced < prev   
Encoding:
Text File  |  1995-06-17  |  12.2 KB  |  369 lines

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