home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / textfilt.zip / quote.cmd < prev    next >
OS/2 REXX Batch file  |  1995-04-05  |  6KB  |  160 lines

  1. /*---------------------------------------------------------------------------*/
  2.   '@echo off'
  3.   programNameStr=   "Quote input for use in C/REXX scripts"
  4.   copyrightStr=     "Copyright (c) Paul Gallagher 1995"
  5.  
  6. /*                                ***keywords*** "Version: %v  Date: %d %t"  */
  7.   versionStr=       "Version: 1:3  Date: 5-Apr-95 12:00:38"
  8. /*
  9. ;                                 ***keywords*** "%l"
  10. ; LOCK STATUS       "***_NOBODY_***"
  11. ;
  12. ;                                 ***keywords*** "%n"
  13. ; Filename          "QUOTE.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 QUOTE.CMD 26-Feb-95,18:33:14,`PAULG/EDMSUB1' Initial check-in
  23. ; 1:1 QUOTE.CMD 6-Mar-95,22:51:18,`PAULG/EDMSUB1' Added documentation; Fixed
  24. ;      bug in qchar replacement.
  25. ; 1:2 QUOTE.CMD 9-Mar-95,22:24:32,`PAULG/EDMSUB1' final for EDM submission
  26. ; 1:3 QUOTE.CMD 5-Apr-95,12:00:38,`PAULG/EDMSUB1' Add my new email address
  27. ;                                 ***revision-history***
  28. ;----------------------------------------------------------------------------*/
  29.                                   /* */
  30. /*-----------------------------------------------------------------------------
  31. ; Set error traps
  32. ;----------------------------------------------------------------------------*/
  33. signal on failure name ExitProc
  34. signal on halt name ExitProc
  35. signal on syntax name ExitProc
  36.  
  37. /*-----------------------------------------------------------------------------
  38. ; Do initial parse of command line and call help message if required
  39. ;----------------------------------------------------------------------------*/
  40.                                   /* get the command line arguments */
  41. Arg params
  42.                                   /* call help routine if required */
  43. If POS(params,"-?"'00'x"/?"'00'x"-HELP"'00'x"/HELP") > 0 Then Do
  44.   Call HelpInfo
  45.   Signal ExitProc
  46. End
  47.  
  48. /*-----------------------------------------------------------------------------
  49. ; Start user procedure
  50. ;----------------------------------------------------------------------------*/
  51.  
  52.                                   /* based on the formatting selected, define
  53.                                      appropriate quote paramters:
  54.                                         pre: prefix
  55.                                         post: suffix
  56.                                         qchar: quote character
  57.                                         qqchar: REXX-quoted quote char (!)
  58.                                         reqchar: replacement quote character
  59.                                           (for embedded quotes in body text) 
  60.                                      NB: pre and post should already contain
  61.                                          appropriate quotes to bound the text.
  62.                                   */
  63.   Select
  64.   When (params="C") Then Do
  65.       pre='printf("'
  66.       post='");'
  67.       qchar='"'
  68.       qqchar='''"'''
  69.       reqchar='\"'
  70.     End
  71.   When (params="C++") Then Do
  72.       pre='cout << "'
  73.       post='" << endl;'
  74.       qchar='"'
  75.       qqchar='''"'''
  76.       reqchar='\"'
  77.     End
  78.   When (params="REXX") Then Do
  79.       pre="Say '"
  80.       post="'"
  81.       qchar="'"
  82.       qqchar='"''"'
  83.       reqchar="''"
  84.     End
  85.   When (params="REXXF") Then Do
  86.       pre="Call LINEOUT f,'"
  87.       post="'"
  88.       qchar="'"
  89.       qqchar='"''"'
  90.       reqchar="''"
  91.     End
  92.   Otherwise
  93.     Signal ExitProc
  94.   End
  95.  
  96.   Call QuoteLines
  97.  
  98. /*-----------------------------------------------------------------------------
  99. ; General exit procedure
  100. ;----------------------------------------------------------------------------*/
  101. ExitProc:
  102.   Drop pre post qchar reqchar
  103.   Drop params programNameStr copyrightStr versionStr
  104. Exit
  105. /*-----------------------------------------------------------------------------
  106. ; end of main routine
  107. ;----------------------------------------------------------------------------*/
  108.  
  109. /*-----------------------------------------------------------------------------
  110. ; routine to display help message
  111. ;----------------------------------------------------------------------------*/
  112. HelpInfo: Procedure Expose programNameStr copyrightStr versionStr
  113.   Say
  114.   Say "*======================================================================*"
  115.   Say "   "programNameStr
  116.   Say "   "versionStr
  117.   Say "   "copyrightStr
  118.   Say
  119.   Say " QUOTE C"
  120.   Say "    formats lines with printf statements"
  121.   Say " QUOTE C++"
  122.   Say "    formats lines to print to cout iostream"
  123.   Say " QUOTE REXX"
  124.   Say "    formats lines to print with 'Say' keyword"
  125.   Say " QUOTE REXXF"
  126.   Say "    formats lines to print with 'LINEOUT' function"
  127.   Say
  128.   Say " This program is a filter - it processes the text redircted to its"
  129.   Say " standard input stream. Output is written to standard output stream."
  130.   Say " So, use it like this:"
  131.   Say "    type filename.txt | quote rexx > out.cmd"
  132.   Say " to process filename.txt for use in a REXX script"
  133.   Say "*======================================================================*"
  134. Return
  135.  
  136. /*-----------------------------------------------------------------------------
  137. ; routine to quote lines
  138. ; uses globals 'pre' 'post' 'qchar' and 'reqchar'
  139. ;----------------------------------------------------------------------------*/
  140. QuoteLines:
  141.   Do While LINES() > 0
  142.     line = LINEIN()
  143.     new=""
  144.  
  145.                                   /* replace qchar occurrences in source text
  146.                                      with reqchar */
  147.     Do While POS(qchar,line)>0
  148.       cmd = "Parse Var line frag"qqchar"line"
  149.       interpret cmd
  150.       new=new''frag''reqchar
  151.     End
  152.  
  153.                                   /* tack on any remaining line to new */
  154.     new=new''line
  155.                                   /* print the quoted line */
  156.     say pre''new''post
  157.   End
  158.   Drop cmd line frag new
  159. Return
  160.