home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / stubs.zip / stubs.cmd next >
OS/2 REXX Batch file  |  1995-04-05  |  8KB  |  202 lines

  1. /*---------------------------------------------------------------------------*/
  2.   '@echo off'
  3.   programNameStr=   "Program Stub Creation"
  4.   copyrightStr=     "Copyright (c) Paul Gallagher 1995"
  5.  
  6. /*                                ***keywords*** "Version: %v  Date: %d %t"  */
  7.   versionStr=       "Version: 2:1  Date: 5-Apr-95 12:00:18"
  8. /*
  9. ;                                 ***keywords*** "%l"
  10. ; LOCK STATUS       "***_NOBODY_***"
  11. ;
  12. ;                                 ***keywords*** "%n"
  13. ; Filename          "STUBS.CMD"
  14. ; Platform          OS/2 (REXX)
  15. ;
  16. ; Authors           Paul Gallagher (paulpg@ibm.net)
  17. ;
  18. ; Description       
  19. ;
  20. ; Revision History
  21. ;                                 ***revision-history***
  22. ; 1 STUBS.CMD 26-Feb-95,18:40:08,`PAULG/EDMSUB1' Initial check-in
  23. ; 1:1 STUBS.CMD 9-Mar-95,0:23:52,`PAULG/EDMSUB1' Fix qchar replacement
  24. ; 2 STUBS.CMD 9-Mar-95,22:23:02,`PAULG/EDMSUB1' Final for EDM submission
  25. ; 2:1 STUBS.CMD 5-Apr-95,12:00:18,`PAULG/EDMSUB1' Add new email address
  26. ;                                 ***revision-history***
  27. ;----------------------------------------------------------------------------*/
  28.                                   /* */
  29. /*-----------------------------------------------------------------------------
  30. ; Set error traps
  31. ;----------------------------------------------------------------------------*/
  32. signal on failure name ExitProc
  33. signal on halt name ExitProc
  34. signal on syntax name ExitProc
  35.  
  36. /*-----------------------------------------------------------------------------
  37. ; Do initial parse of command line and call help message if required
  38. ;----------------------------------------------------------------------------*/
  39.                                   /* get the command line arguments */
  40. Parse Arg params
  41.                                   /* call help routine if required */
  42. If Pos(Translate(params),"-?"'00'x"/?"'00'x"-HELP"'00'x"/HELP") > 0 Then Do
  43.   Call HelpInfo
  44.   Signal ExitProc
  45. End
  46.  
  47. /*-----------------------------------------------------------------------------
  48. ; Start user procedure
  49. ;----------------------------------------------------------------------------*/
  50.  
  51.                                   /* sign-on */
  52. Say programNameStr versionStr
  53. Say copyrightStr
  54.  
  55.                                   /* set some global values that may be used
  56.                                      in stubs */
  57. Author = 'Paul Gallagher'
  58. FullAuthor = Author '(paulpg@ibm.net)'
  59. Parse Value DATE('N') With dd mm yy
  60. Parse Source . . SourceFile
  61.                                   /* command variable */
  62. Cmd = ''
  63.  
  64.                                   /* main loop */
  65. Do Forever
  66.                                   /* display menu */
  67.   Say 
  68.   Say "Select from the following commands:"
  69. /*FLAG1* DO NOT DELETE THIS LINE - New menu items inserted above*/
  70.   Say "   -----------------------------------------------------"
  71.   Say "   MODIFY: add a new template to this file"
  72.   Say "   EXIT: end processing"
  73.   Call CHAROUT ,'> '
  74.   Pull Cmd
  75.  
  76.                                   /* process menu option */
  77.   Select
  78.   When ABBREV("EXIT",Cmd) Then
  79.     Signal ExitProc
  80.   When ABBREV("MODIFY",Cmd) Then
  81.     Call AdminMODIFY
  82. /*FLAG2* DO NOT DELETE THIS LINE - New menu items inserted below*/
  83.   Otherwise
  84.     Nop
  85.   End
  86. End
  87.  
  88. /*-----------------------------------------------------------------------------
  89. ; General exit procedure
  90. ;----------------------------------------------------------------------------*/
  91. ExitProc:
  92.   Drop Cmd SourceFile
  93.   Drop params programNameStr copyrightStr versionStr Author FullAuthor
  94. Exit
  95. /*-----------------------------------------------------------------------------
  96. ; end of main routine
  97. ;----------------------------------------------------------------------------*/
  98.  
  99. /*-----------------------------------------------------------------------------
  100. ; routine to display help message
  101. ;----------------------------------------------------------------------------*/
  102. HelpInfo: Procedure Expose programNameStr copyrightStr versionStr
  103.   Say
  104.   Say "*======================================================================*"
  105.   Say "   "programNameStr
  106.   Say "   "versionStr
  107.   Say "   "copyrightStr
  108.   Say
  109.   Say "*======================================================================*"
  110. Return
  111.  
  112. /*-----------------------------------------------------------------------------
  113. ; routine to modify thjis file (add a new stub)
  114. ;----------------------------------------------------------------------------*/
  115. AdminMODIFY: Procedure Expose SourceFile
  116.                                   /* get parameters for new stub */
  117.   Say
  118.   Say "DEFINING NEW STUB..."
  119.   Call CHAROUT ,'Enter sample filename : '
  120.   Parse Pull sample
  121.   Call CHAROUT ,'Enter command key     : '
  122.   Pull key
  123.   Call CHAROUT ,'Description (for menu): '
  124.   Parse Pull description
  125.  
  126.                                   /* create a queue to store the file-in-process */
  127.   newq = RXQUEUE('Create')
  128.   oldq = RXQUEUE('Set',newq)
  129.  
  130.                                   /* read stubs.cmd to queue */
  131.   Do While LINES(SourceFile) > 0
  132.     line = LINEIN(SourceFile)
  133.     queue line
  134.   End
  135.  
  136.                                   /* begin re-writting stubs.cmd */
  137.   Call LINEOUT SourceFile,,1
  138.  
  139.   Do While QUEUED() > 0
  140.     Parse Pull line
  141.  
  142.                                   /* insert new menu item */
  143.     if (POS("/*FLAG1",line)=1) Then Do
  144.       Call LINEOUT SourceFile,'  Say "   'key': 'description'"'
  145.     End
  146.                                   /* write current line */
  147.     Call LINEOUT SourceFile,line
  148.  
  149.                                   /* insert new menu-processing commands */
  150.     if (POS("/*FLAG2",line)=1) Then Do
  151.       Call LINEOUT SourceFile,'  When ABBREV("'key'",Cmd) Then'
  152.       Call LINEOUT SourceFile,'    Call Create'key
  153.     End
  154.   End
  155.                                   /* append new procedure */
  156.   Call LINEOUT SourceFile,"/*-----------------------------------------------------------------------------"
  157.   Call LINEOUT SourceFile,"; routine to create a new stub file"
  158.   Call LINEOUT SourceFile,";----------------------------------------------------------------------------*/"
  159.   Call LINEOUT SourceFile,"Create"key": Procedure Expose Author FullAuthor dd mm yy"
  160.   Call LINEOUT SourceFile,"  Say '"key": "description"'"
  161.   Call LINEOUT SourceFile,"  Call CHAROUT ,'Enter new filename: '"
  162.   Call LINEOUT SourceFile,"  Parse Pull f"
  163.   Call LINEOUT SourceFile,"  If LENGTH(name)=0 Then Return"
  164.  
  165.                                   /* begin writing stub file */
  166.   Call LINEOUT SourceFile,""
  167.                                   /* insert sample script */
  168.   pre="Call LINEOUT f,'"
  169.   post="'"
  170.   Do While LINES(sample) > 0
  171.     line = LINEIN(sample)
  172.     new=""
  173.                                   /* replace conflicting quote chars in source */
  174.     Do While POS("'",line)>0
  175.       Parse Var line frag"'"line
  176.       new=new''frag"''"
  177.     End
  178.     new=new''line
  179.                                   /* write command to write 'clean' line */
  180.     Call LINEOUT SourceFile,'  'pre''new''post
  181.   End
  182.  
  183.                                   /* end writting stub */
  184.   Call LINEOUT SourceFile,"  Call LINEOUT f"
  185.  
  186.   Call LINEOUT SourceFile,"  Say f 'successfully create..'"
  187.   Call LINEOUT SourceFile,"  Drop f"
  188.   Call LINEOUT SourceFile,"Return"
  189.   Call LINEOUT SourceFile,""
  190.  
  191.   Call RXQUEUE 'Set',oldq
  192.   Call RXQUEUE 'Delete',newq
  193.  
  194.   Drop sample key description
  195.   Drop frag pre post qchar reqchar
  196.   Drop line newq oldq
  197.  
  198.   Say SourceFile "modified: re-run to use new options..."
  199.   Signal ExitProc
  200. Return
  201.  
  202.