home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / bin / iwfmmgen.cmd < prev    next >
Encoding:
Text File  |  1996-02-21  |  9.0 KB  |  238 lines

  1. /*---------------------------------------------------------------------------*/
  2. /*      Licensed Materials - Property of IBM                                 */
  3. /*                                                                           */
  4. /*      "Restricted Materials of IBM"                                        */
  5. /*                                                                           */
  6. /*      IBM WorkFrame                                                        */
  7. /*                                                                           */
  8. /*      (C) Copyright IBM Corp. 1991, 1995. All Rights Reserved.             */
  9. /*                                                                           */
  10. /*      US Government Users Restricted Rights - Use, duplication or          */
  11. /*      disclosure restricted by GSA ADP Schedule Contract with IBM Corp.    */
  12. /*---------------------------------------------------------------------------*/
  13. /*REXX*/
  14.  
  15. /**************************************************************************
  16. *  iwfmmgen.cmd  WorkFrame sample MAKEMAKE makefile generation script.    *
  17. *                                                                         *
  18. *  (c) Copyright International Business Machines Corporation 1994, 1995.  *
  19. *  All rights reserved.                                                   *
  20. *                                                                         *
  21. **************************************************************************/
  22.  
  23. /* Initialize. */
  24. RC.OK     = 0;
  25. RC.CANCEL = 8;
  26. RC.ERROR  = 8;
  27. RC.FATAL  = 16;
  28. NEWLINE   = '0d'x;
  29.  
  30. /* Load the REXX utility functions. */
  31. rc = RxFuncAdd('RxMessageBox', 'RexxUtil', 'RxMessageBox');
  32.  
  33. /* Extract the passed parameters. */
  34. /*if (Arg() <> 1) then*/
  35. /*   call Abort("Usage is: IWFMake IntermediateFile MakeFile DependencyFile");*/
  36. parse arg IntermediateFile,MakeFile,DependencyFile;
  37.  
  38. /* Parse the intermediate file to generate the make and dependency files. */
  39. rc = Parse(IntermediateFile);
  40. rc = Generate(Makefile, DependencyFile);
  41.  
  42. /* We are done. */
  43. call Done(RC_OK);
  44.  
  45. /**************************************************************************
  46. *  Parse(Stem, IntermediateFile);                                         *
  47. *  Parse the passed intermediate file into a REXX stem variable.          *
  48. *                                                                         *
  49. *  The intermediate file contains entries of the form:                    *
  50. *      :TAG.<VALUE1>...<VALUEn>                                           *
  51. *                                                                         *
  52. *  The stem variable represents the intermediate file as follows:         *
  53. *      STEM.TAG.0                                                         *
  54. *      STEM.TAG.NAME                                                      *
  55. ***************************************************************************/
  56.  
  57. Parse: procedure expose RC. NEWLINE  Stem.
  58. arg IntermediateFile;
  59. say "Parsing intermediate file.";
  60. Stem. = 0;
  61. LastTag = "";
  62. LastTarget = "";
  63. rc = RC_OK;
  64.  
  65. /* Process while not end of file. NOTE - this file has no blank lines,    */
  66. /* so we continue reading until an empty line if found, which is the end. */
  67. /* Get the first line. */
  68. Line = linein(IntermediateFile);
  69. do while (length(Line) > 0)
  70.    /* Parse the line into a (TAG,VALUE) pair. */
  71.    if (substr(Line,1,1) = ":") then do;
  72.       parse var Line ":" Tag "." Value
  73.    end;
  74.    else do;
  75.       Tag   = LastTag;
  76.       Value = Line;
  77.    end;
  78.    if (Tag = "") then call Abort("Error parsing intermediate file.");
  79.    LastTag = Tag;
  80.    if (Value <> "") then do;
  81.       /* Add the (TAG,VALUE) pair to the stem variable. */
  82.       /* All values are kept subordinate to the current RULE/TARGET tag. */
  83.       if ((Tag = "TARGET") | (Tag = "RULE")) then do;
  84.          Count = Stem.Tag.0;               /* Get the number of values for the tag. */
  85.          Count = Count + 1;                /* We now have one more value. */
  86.          Stem.Tag.0     = Count;           /* Set the new count. */
  87.          Stem.Tag.Count = Value;           /* Set the new value. */
  88.          LastTarget     = Tag"."Count;     /* Set the tag for the last target. */
  89.       end;
  90.       else do;
  91.          Count = Stem.LastTarget.Tag.0;    /* Get the number of values for the tag. */
  92.          Count = Count + 1;                /* We now have one more value. */
  93.          Stem.LastTarget.Tag.0     = Count;/* Set the new count. */
  94.          Stem.LastTarget.Tag.Count = Value;/* Set the new value. */
  95.       end;
  96.    end;
  97.  
  98.    /* Get the next line. */
  99.    Line = linein(IntermediateFile);
  100. end
  101. return(rc);
  102.  
  103. /**************************************************************************
  104. *  Generate(Stem, MakeFile, DependencyFile).                              *
  105. *  Generate a makefile and a separate dependency file (if requested)      *
  106. *  from the specified stem variable.                                      *
  107. ***************************************************************************/
  108.  
  109. Generate: procedure expose RC. NEWLINE  Stem.
  110. arg MakeFile, DependencyFile;
  111. say "Generating make file.";
  112. rc = RC_OK;
  113.  
  114. /* Determine if the make and dependency files are one and the same. */
  115. if (DependencyFile = "") then
  116.    DependencyFile = MakeFile;
  117.  
  118. /* Generate the make file. */
  119. call GenerateTargets;
  120. return(rc);
  121.  
  122. /**************************************************************************
  123. *  Generation utilities:                                                  *
  124. *  (a) GenerateTargets.                                                    *
  125. *  (a) GenerateTarget.                                                     *
  126. *  (a) GenerateTrailer.                                                   *
  127. **************************************************************************/
  128.  
  129. GenerateTargets:
  130. /*if (Stem.TARGET.0 < 2) then
  131. return(RC.ERROR);*/
  132.  
  133. rc = GeneratePreTargets("TARGET."1, "TARGET."2);
  134.  
  135. do ix=1 to Stem.RULE.0;
  136.    rc = GenerateTarget("RULE."ix);
  137. end
  138. if (Stem.TARGET.0 > 2) then
  139. do ix=3 to Stem.TARGET.0;
  140.    rc = GenerateTarget("TARGET."ix);
  141. end
  142. else
  143.    return(RC.OK);
  144. return(RC.OK);
  145.  
  146. GenerateTarget:
  147. arg ThisTarget;
  148. if (Stem.ThisTarget.COMMAND.0 <> 0) then
  149.    File = MakeFile;
  150. else
  151.    File = DependencyFile;
  152. rc = lineout(File, NEWLINE);
  153. if Stem.ThisTarget.DEPENDENCY.0 > 0 then
  154.    rc = lineout(File, Stem.ThisTarget": \");
  155.    else
  156.    rc = lineout(File, Stem.ThisTarget":");
  157. do xix=1 to Stem.ThisTarget.DEPENDENCY.0;
  158.    if xix < Stem.ThisTarget.DEPENDENCY.0 then
  159.    rc = lineout(File, "    "Stem.ThisTarget.DEPENDENCY.xix" \");
  160.    else
  161.    rc = lineout(File, "    "Stem.ThisTarget.DEPENDENCY.xix);
  162. end
  163. do xix=1 to Stem.ThisTarget.ACTION.0;
  164.    rc = lineout(File, "    @echo """ Stem.ThisTarget.ACTION.xix """");
  165. end
  166. do xix=1 to Stem.ThisTarget.COMMAND.0;
  167.    if Stem.ThisTarget.COMMAND.xix = "<<" then
  168.    rc = lineout(File, Stem.ThisTarget.COMMAND.xix);
  169.    else
  170.    rc = lineout(File, "    "Stem.ThisTarget.COMMAND.xix);
  171. end
  172. return(RC.OK);
  173.  
  174. GeneratePreTargets:
  175. arg SuffixTarget, AllTarget
  176. File = MakeFile;
  177. rc = lineout(File, NEWLINE);
  178. rc = charout(File, "."Stem.SuffixTarget":");
  179.  
  180. do xix=1 to Stem.SuffixTarget.DEPENDENCY.0;
  181.    rc = charout(File, " "Stem.SuffixTarget.DEPENDENCY.xix);
  182. end
  183. rc = lineout(File, NEWLINE);
  184. rc = lineout(File, NEWLINE);
  185.  
  186. File = MakeFile;
  187.  
  188. if Stem.AllTarget.DEPENDENCY.0 > 0 then
  189.    rc = lineout(File, "."Stem.AllTarget": \");
  190.    else
  191.    rc = lineout(File, "."Stem.AllTarget":");
  192. do xix=1 to Stem.AllTarget.DEPENDENCY.0;
  193.    if xix < Stem.AllTarget.DEPENDENCY.0 then
  194.    rc = lineout(File, "    "Stem.AllTarget.DEPENDENCY.xix" \");
  195.    else
  196.    rc = lineout(File, "    "Stem.AllTarget.DEPENDENCY.xix);
  197. end
  198. do xix=1 to Stem.AllTarget.ACTION.0;
  199.    rc = lineout(File, "    @echo """ Stem.AllTarget.ACTION.xix """");
  200. end
  201. do xix=1 to Stem.AllTarget.COMMAND.0;
  202.    if Stem.AllTarget.COMMAND.xix = "<<" then
  203.    rc = lineout(File, Stem.AllTarget.COMMAND.xix);
  204.    else
  205.    rc = lineout(File, "    "Stem.AllTarget.COMMAND.xix);
  206. end
  207. return(RC.OK);
  208.  
  209. /**************************************************************************
  210. *  General purpose utilities:                                             *
  211. *  (a) cancel():        ask the user if processing should be cancelled.   *
  212. *  (b) abort(message):  abort processing (with the given message).        *
  213. *  (c) done(rc):        terminate processing (with the given return code).*
  214. ***************************************************************************/
  215.  
  216. Cancel: procedure expose RC. NEWLINE
  217. rc = RxMessageBox("Do you really want to cancel?", , "YesNo", "Query");
  218. if (rc = 6) then
  219.    call Done(RC_CANCEL);
  220. return(RC_OK);
  221.  
  222. Abort: procedure expose RC. NEWLINE
  223. arg abortMessage;
  224. rc =  RxMessageBox(abortMessage, , "Ok", "Error");
  225. call Done(RC_FATAL);
  226.  
  227. Done: procedure expose RC. NEWLINE
  228. arg exitRc;
  229. if (exitRc = RC_OK) then
  230.    say "The make file was generated successfully.";
  231. else
  232.    say "The make file was not generated due to errors.";
  233.  
  234. /* unload rexx utilities */
  235. rc = RxFuncDrop('RxMessageBox');
  236.  
  237. exit(exitRc);
  238.