home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / orx8.zip / rgf_util.cmd < prev    next >
OS/2 REXX Batch file  |  1997-07-21  |  13KB  |  312 lines

  1. /*
  2. program:   rgf_util.cmd
  3. type:      Object REXX, REXXSAA 6.0
  4. purpose:   collection of useful routines for Object REXX programs
  5. version:   1.00.1
  6. date:      1997-04-15
  7. changed:   1997-06-26, rgf, changed some minorities
  8.  
  9. author:    Rony G. Flatscher
  10.            Rony.Flatscher@wu-wien.ac.at
  11.            (Wirtschaftsuniversitaet Wien, University of Economics and Business
  12.            Administration, Vienna/Austria/Europe)
  13. needs:     ---
  14.  
  15. usage:     call or require
  16.  
  17. comments:  prepared for the "8th International Rexx Symposium 1997", April 1997, Heidelberg/Germany
  18.            Miscellaneous routines;
  19.  
  20.  
  21. All rights reserved and copyrighted 1995-1997 by the author, no guarantee that
  22. it works without errors, etc.  etc.
  23.  
  24. You are granted the right to use this module under the condition that you don't charge money for this module (as you didn't write
  25. it in the first place) or modules directly derived from this module, that you document the original author (to give appropriate
  26. credit) with the original name of the module and that you make the unaltered, original source-code of this module available on
  27. demand.  If that holds, you may even bundle this module (either in source or compiled form) with commercial software.
  28.  
  29. If you find an error, please send me the description (preferably a *very* short example);
  30. I'll try to fix it and re-release it to the net.
  31.  
  32. */
  33.  
  34.  
  35. /* add a directory for the purposes of the utilities defined herein           */
  36.  
  37. IF .rgf.util <> ".RGF.UTIL" THEN RETURN /* already defined, do not execute initialization
  38.                                            code another time                    */
  39.  
  40. .local[ "RGF.UTIL" ] = .directory~new    /* define a directory in .local       */
  41.  
  42. PARSE SOURCE op_sys call_type script_path
  43. .rgf.util ~ this_op_sys    = op_sys
  44. .rgf.util ~ this_full_path = script_path
  45. .rgf.util ~ this_call_type = call_type
  46. .rgf.util ~ this_name      = FILESPEC("Name", script_path)
  47.  
  48. .rgf.util~debugLevel = 0          /* define debug_level, if 0 not debug information
  49.                                   produced                                    */
  50.  
  51. .rgf.util~Log   = .monitor ~ new ~~INIT( .stdout )      /* define log-monitor */
  52. .rgf.util~Error = .monitor ~ new ~~INIT( .stderr )      /* define log-monitor */
  53. .rgf.util~Debug = .monitor ~ new ~~INIT( .stderr )      /* define Debug-monitor */
  54.  
  55. .rgf.util~indent = LEFT("", 3)          /* indent blanks                        */
  56.  
  57. .rgf.util ~ CR   = "0d"x
  58. .rgf.util ~ LF   = "0a"x
  59. .rgf.util ~ CRLF = "0d0a"x
  60.  
  61.  
  62.  
  63.  
  64. /* give feedback of intitialization step, if DebugLevel level is defined           */
  65. IF .rgf.util ~ DebugLevel > 0 THEN
  66. DO
  67.    PARSE VERSION version
  68.    PARSE SOURCE  op_sys call_type this_file
  69.    .rgf.util~log~lineout( pp(.rgf.util~this_name) "running on:" pp(op_sys),
  70.                           "DebugLevel level:" pp(.rgf.util~DebugLevel),
  71.                           "call type:" pp(call_type),
  72.                         )
  73.    .rgf.util~log~lineout( .rgf.util~indent "version:" pp(version) )
  74.    .rgf.util~log~lineout( .rgf.util~indent pp("initialization --- end") )
  75. END
  76.  
  77.  
  78. /*
  79. :: REQUIRES rgf_class.cmd               /* needs RGF-classes    */
  80. */
  81.  
  82.  
  83. :: REQUIRES sort_util.cmd               /* sorting support              */
  84. :: REQUIRES routine_find_file.cmd
  85. :: REQUIRES routine_ok.cmd
  86. :: REQUIRES routine_pp.cmd
  87. :: REQUIRES routine_pp_number.cmd
  88. :: REQUIRES routine_strip_quote.cmd
  89.  
  90.  
  91.  
  92.  
  93. /******************************************************************************/
  94. /*                                                                            */
  95. /* name:    dump(object, title, output-stream, indent-chars)                  */
  96. /*                                                                            */
  97. /* purpose: dumps a directory                                                 */
  98. /*                                                                            */
  99. /* returns: ---                                                               */
  100. /*                                                                            */
  101. /* remarks: defaults, if no object supplied:                                  */
  102. /*          title         ... "--- not given ---"                             */
  103. /*          output-stream ... .rgf.util ~ debug                               */
  104. /*          indent-chars  ... .rgf.util ~ indent                              */
  105. /*                                                                            */
  106. /* created: rgf, 95-09-30                                                     */
  107.  
  108. :: ROUTINE dump                  PUBLIC
  109.    USE ARG object, title, stream, indent
  110.  
  111.    /* supply defaults */
  112.    IF \VAR("TITLE")  THEN title  = "--- not given ---"
  113.  
  114.    IF \VAR("STREAM") THEN
  115.       stream = .rgf.util ~ debug                /* use .rgf.util-debug monitor */
  116.  
  117.    IF \VAR("INDENT") THEN
  118.       indent = .rgf.util ~ indent               /* use rgf.util-indention */
  119.  
  120.    max = 30                                     /* default */
  121.  
  122.    stream ~ LINEOUT( indent LEFT("begin of dump ...", 70, "-") )
  123.    tmp = indent "got" pp(object ~ class ) "title" pp(title)
  124.    IF object ~ hasmethod( "items" ) THEN
  125.       tmp = tmp "items" pp(object~items)
  126.    ELSE
  127.       tmp = tmp "--- method ITEMS not available ---"
  128.  
  129.    stream ~ LINEOUT( tmp )
  130.    stream ~ LINEOUT( "" )
  131.  
  132.    IF      IsA( object, .directory ) THEN CALL dumpDirectory  object, stream, indent
  133.    ELSE IF IsA( object, .stem )      THEN CALL dumpStem       object, stream, indent
  134.    ELSE IF IsA( object, .supplier )  THEN CALL dumpSupplier   object, stream, indent
  135.    ELSE                                   CALL dumpOver       object, stream, indent
  136.  
  137.    stream ~ LINEOUT( indent LEFT("end of dump ..", 70, "-") )
  138. /******************************************************************************/
  139.  
  140.  
  141.  
  142. /******************************************************************************/
  143. /*                                                                            */
  144. /* name:    dumpDirectory(directory, output-stream, indent-chars)             */
  145. /*                                                                            */
  146. /* purpose: dumps a directory                                                 */
  147. /*                                                                            */
  148. /* returns: ---                                                               */
  149. /*                                                                            */
  150. /* remarks: defaults, if no object supplied:                                  */
  151. /*          output-stream ... .rgf.util ~ debug                               */
  152. /*          indent-chars  ... .rgf.util ~ indent                              */
  153. /*                                                                            */
  154. /*          directory entries get always sorted !                             */
  155. /*                                                                            */
  156. /* created: rgf, 95-09-28                                                     */
  157.  
  158. :: ROUTINE dumpDirectory
  159.    USE ARG object, stream, indent
  160.  
  161.    IF \VAR("STREAM") THEN
  162.       stream = .rgf.util ~ debug                /* use .rgf.util-debug monitor */
  163.  
  164.    IF \VAR("INDENT") THEN
  165.       indent = .rgf.util ~ indent               /* use rgf.util-indention */
  166.  
  167.    items = object~items
  168.    width = LENGTH(items)                /* determine max length of index value*/
  169.  
  170.    aha = sort(object)                   /* returns a sorted .array object     */
  171.  
  172.    max = 0
  173.  
  174.    DO i over aha                        /* determine largest entry            */
  175.       max = MAX(max, i ~ length)
  176.       call trace off
  177.    END
  178.    max = max + 2                        /* account for brackets               */
  179.  
  180.    DO i over aha
  181.       stream ~ LINEOUT( indent LEFT(pp(i), max) "entry" pp(object[i])   )
  182.    END
  183.  
  184. /******************************************************************************/
  185.  
  186.  
  187.  
  188.  
  189.  
  190. /******************************************************************************/
  191. /*                                                                            */
  192. /* name:    dumpOver(object, output-stream, indent-chars)                     */
  193. /*                                                                            */
  194. /* purpose: dumps content of an object via "OVER"                             */
  195. /*                                                                            */
  196. /* returns: ---                                                               */
  197. /*                                                                            */
  198. /* remarks: defaults, if no object supplied:                                  */
  199. /*          output-stream ... .rgf.util ~ debug                               */
  200. /*          indent-chars  ... .rgf.util ~ indent                              */
  201. /*                                                                            */
  202. /* created: rgf, 95-09-30                                                     */
  203.  
  204. :: ROUTINE DumpOver
  205.    USE ARG object, stream, indent
  206.  
  207.    width = LENGTH(object ~ items)
  208.    a = 0
  209.    DO i OVER object
  210.       a = a + 1
  211.       stream ~ LINEOUT( indent "index" pp(RIGHT(a, width)) "item" pp(i) )
  212.    END
  213.  
  214.    RETURN
  215. /******************************************************************************/
  216.  
  217.  
  218.  
  219.  
  220. /******************************************************************************/
  221. /*                                                                            */
  222. /* name:    dumpStem(object, output-stream, indent-chars)                     */
  223. /*                                                                            */
  224. /* purpose: dumps content of a supplyable object                              */
  225. /*                                                                            */
  226. /* returns: ---                                                               */
  227. /*                                                                            */
  228. /* remarks: if object is not a supplier, a supplier will be produced of it by */
  229. /*          sending it a "SUPPLIER" message                                   */
  230. /*                                                                            */
  231. /*          defaults, if no object supplied:                                  */
  232. /*          output-stream ... .rgf.util ~ debug                               */
  233. /*          indent-chars  ... .rgf.util ~ indent                              */
  234. /*                                                                            */
  235. /* created: rgf, 95-09-30                                                     */
  236.  
  237. :: ROUTINE DumpStem
  238.    USE ARG object., stream, indent
  239.  
  240.    width = LENGTH(object.0)
  241.    DO i = 1 TO object.0
  242.       stream ~ LINEOUT( indent "index" pp(RIGHT(i, width)) "item" pp(object.i) )
  243.    END
  244.  
  245.    RETURN
  246. /******************************************************************************/
  247.  
  248.  
  249.  
  250.  
  251. /******************************************************************************/
  252. /*                                                                            */
  253. /* name:    dumpSupplier(object, output-stream, indent-chars)                 */
  254. /*                                                                            */
  255. /* purpose: dumps content of a supplyable object                              */
  256. /*                                                                            */
  257. /* returns: ---                                                               */
  258. /*                                                                            */
  259. /* remarks: if object is not a supplier, a supplier will be produced of it by */
  260. /*          sending it a "SUPPLIER" message                                   */
  261. /*                                                                            */
  262. /*          defaults, if no object supplied:                                  */
  263. /*          output-stream ... .rgf.util ~ debug                               */
  264. /*          indent-chars  ... .rgf.util ~ indent                              */
  265. /*                                                                            */
  266. /* created: rgf, 95-08-28                                                     */
  267.  
  268. :: ROUTINE DumpSupplier
  269.    USE ARG supplier, stream, indent
  270.  
  271.    DO WHILE supplier~AVAILABLE
  272.       stream ~ LINEOUT( indent "index" LEFT(pp(supplier~INDEX), 30) "item",
  273.                       pp(supplier~ITEM) )
  274.       supplier ~ NEXT
  275.    END
  276.  
  277.    RETURN
  278. /******************************************************************************/
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290. /******************************************************************************/
  291. /******************************************************************************/
  292.  
  293.  
  294.  
  295. :: ROUTINE sayLog                PUBLIC
  296.    PARSE ARG arg
  297.    .rgf.util~log~lineout( .rgf.util~indent arg )
  298.  
  299.  
  300. :: ROUTINE sayError              PUBLIC
  301.    PARSE ARG arg
  302.    .rgf.util ~ error ~ lineout( .rgf.util~indent "***" arg )
  303.  
  304.  
  305. :: ROUTINE sayDebug              PUBLIC
  306.    PARSE ARG arg
  307.    .rgf.util ~ debug ~ lineout( .rgf.util~indent arg )
  308.  
  309.  
  310.  
  311.  
  312.