home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / cedit2.zip / Global_Set.Cmd < prev    next >
OS/2 REXX Batch file  |  1993-11-05  |  10KB  |  281 lines

  1. /*
  2. program: Global_Set.cmd
  3. type:    REXXSAA-OS/2, version 2.x
  4. purpose: Setup Globals for all rexx procedures.
  5. version: 1.0
  6. date:    1993-03-17
  7. changed: 1.1    1993-07-21
  8.                 -Changed to allow UserID & UserName to be picked up.
  9.          1.2    1993-10-05
  10.                 -Changed to allow WHOAMI info retrieved by External Function.
  11.          1.3    1993-11-05
  12.                 -Fixed for better error handling.
  13.  
  14. author:  Byron Stephan
  15.  
  16. needs:   OS/2 2.0 GA & SP or higher,
  17.          YDBAUTIL.DLL from RXU11.ZIP,
  18.          RxNetInf.DLL written by David Brouse
  19.  
  20. Plans:    
  21.  
  22. Problems: none known
  23.  
  24. All rights reserved, copyrighted 1993, no guarantee that it works without
  25. errors, etc. etc.
  26.  
  27. donated to the public domain granted that you are not charging anything (money
  28. etc.) for it and derivates based upon it, as you did not write it,
  29. etc. if that holds you may bundle it with commercial programs too
  30.  
  31. you may freely distribute this program, granted that no changes are made
  32. to it.
  33.  
  34. Please, if you find an error, post me a message describing it, I will
  35. try to fix and rerelease it to the net.
  36.  
  37. procedures:
  38.  
  39. usage:   Use these statments in another REXX procedure. 
  40.    
  41. Initialize: Procedure Expose Global. LocalGlobal.
  42.    if Global_Set() <> 0 then do
  43.       Say 'Unable to Initialize!'
  44.       exit -1
  45.    end
  46.    numvar = rxVlist(, 'G', 'GlobalQueue')
  47.  
  48.    /* Suggested Addtional Local Global variables to add */
  49.    parse source LocalGlobal.OS LocalGlobal.CommandType LocalGlobal.RexxPathName
  50.    LocalGlobal.ProgramName = substr(LocalGlobal.RexxPathName,lastpos('\',LocalGlobal.RexxPathName)+1)
  51.  
  52.    LocalGlobal.Version = "1.0"
  53.    LocalGlobal.Program = global.ibrightyellow||LocalGlobal.ProgramName,
  54.                       ||" ("global.ibrightblue||LocalGlobal.Version||global.iBrightyellow,
  55.                       ||"):"global.iNormal
  56.    LocalGlobal.Author = global.ibrightgreen"Byron Stephan"global.iNormal
  57.  
  58.  
  59. syntax:
  60.  
  61. flags:
  62.  
  63. */
  64. SIGNAL ON FAILURE NAME Error
  65. SIGNAL ON HALT NAME Halt
  66. SIGNAL ON ERROR NAME Error
  67. SIGNAL ON SYNTAX NAME Error
  68.  
  69. Call SetColors
  70. Say global.iYellow"Initializing..."global.inormal
  71.  
  72. /* Suggested Addtional Local Global variables to add */
  73. parse source LocalGlobal.OS LocalGlobal.CommandType LocalGlobal.RexxPathName
  74. LocalGlobal.ProgramName = substr(LocalGlobal.RexxPathName,lastpos('\',LocalGlobal.RexxPathName)+1)
  75. LocalGlobal.Version = "1.3"
  76. LocalGlobal.Program = global.ibrightyellow||LocalGlobal.ProgramName,
  77.                    ||" ("global.ibrightblue||LocalGlobal.Version||global.iBrightyellow,
  78.                    ||"):"global.iNormal
  79. LocalGlobal.Author = global.ibrightgreen"Byron Stephan"global.iNormal
  80.  
  81. Call LoadFunctions
  82. Call SetGlobal
  83. Call StoreGlobal
  84. EXIT 0
  85. Return
  86.  
  87. SetColors:
  88.    /* define some ANSI.SYS-colors */
  89.    esc    = '1B'x          /* escape-char */
  90.  
  91.    /* define ANSI-colors */
  92.    global.iNormal        = esc||"[0;40m"  /* reset attributes to normal */
  93.    global.iRed           = esc||"[31;40m" /* red on black */
  94.    global.iGreen         = esc||"[32;40m" /* green on black */
  95.    global.iYellow        = esc||"[33;40m"    /* yellow on black */
  96.    global.iBlue          = esc||"[34;40m"    /* blue on black */
  97.    global.iMagenta       = esc||"[35;40m"    /* magenta on black */
  98.    global.iCyan          = esc||"[36;40m"    /* cyan on black */
  99.    global.iWhiteRed      = esc||"[1;41m"    /* white on red */
  100.    global.iWhiteBlue     = esc||"[1;44m"    /* white on blue */
  101.    global.iBlackWhite    = esc||"[30;47m"   /* black on white */
  102.    global.iRedWhite      = esc||"[31;47m"   /* red on white*/
  103.    global.iBrightRed     = esc||"[31;1;40m" /* red on black */
  104.    global.iBrightGreen   = esc||"[32;1;40m" /* Bright Green */
  105.    global.iBrightYellow  = esc||"[33;1;40m" /* Bright Yellow on black */
  106.    global.iBrightBlue    = esc||"[34;1;40m" /* Bright Blue on black */
  107.    global.iBrightCyan    = esc||"[36;1;40m" /* Bright Cyan on black */
  108.    global.iBrightWhite   = esc||"[37;1;40m" /* Bright White on black */
  109.    global.iBrightMagenta = esc||"[35;1;40m"    /* magenta on black */
  110.  
  111. return
  112.  
  113. LoadFunctions:
  114.    /* check whether RxFuncs are loaded, if not, load them */
  115.    IF RxFuncQuery('SysLoadFuncs') THEN
  116.    DO
  117.       /* load the load-function */
  118.       CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  119.       /* load the Sys* utilities */
  120.       CALL SysLoadFuncs
  121.    END
  122.  
  123.    /* check whether Additional Functions are loaded, if not, load them */
  124.    IF RxFuncQuery('rxydbautilinit')  THEN
  125.    DO
  126.       /* load the load-function */
  127.       CALL RxFuncAdd 'rxydbautilinit','ydbautil','rxydbautilinit'
  128.       /* load the YDB* utilities */
  129.       call rxydbautilinit
  130.    END
  131.  
  132.    /* check whether LAN Info Functions are loaded, if not, load them */
  133.    if RxFuncQuery( "RxNetLoadFuncs" ) then do
  134.       if RxFuncAdd("RxNetLoadFuncs", "RxNetInf", "RxNetLoadFuncs") then do
  135.          signal failure
  136.       end
  137.    end
  138.    Call RxNetLoadFuncs
  139.    Global.ComputerName = STRIP(RxNetGetWorkstation())
  140.    Global.UserId       = STRIP(RxNetGetUserId())
  141.    Global.Logon_Domain = STRIP(RxNetGetDomain())
  142.    Call RxNetDropFuncs
  143.  
  144. Return
  145.  
  146. SetGlobal:
  147.    Global.Username = Find_UserName(Global.Userid)
  148.  
  149. /*
  150.    if Words(global.UserName) > 2 then
  151.       Global.UserFirstName = word(Global.UserName,1)
  152.       Global.UserLastName = word(Global.UserName,3)
  153.    else do
  154. */
  155.       Global.UserFirstName = word(Global.UserName,1)
  156.       Global.UserLastName = word(Global.UserName,2)
  157. /*
  158.    end
  159. */
  160.  
  161.    /* get screen dimensions */
  162.    PARSE VALUE SysTextScreenSize() WITH global.ScreenRows global.ScreenColumns
  163.  
  164.    /* hint for default yes or no */
  165.    global.yesHint = global.iCyan || " (" || global.iYellow || "Y" || global.iCyan || "/n) " || global.iYellow
  166.    global.noHint  = global.iCyan || " (y/" || global.iYellow || "N" || global.iCyan || ") " || global.iYellow
  167.  
  168.    global.iBlankLine = global.iRedWhite || RIGHT("", global.ScreenColumns - 1) || global.iCyan
  169.    global.Seperator = global.iCyan ||copies("_", global.ScreenColumns - 1) || global.iNormal
  170.  
  171.    global.iNonPrintable = XRANGE("00"x, "1F"x) || D2C(255)
  172.    global.iFilter       = COPIES("FA"x, 256)
  173.    global.Bootdrive = substr(VALUE('PATH',,'OS2ENVIRONMENT'),POS('\OS2\SYSTEM',VALUE('PATH',,'OS2ENVIRONMENT')) - 2,2)
  174. Return
  175.  
  176. /**********************************************************************/
  177. StoreGlobal:
  178.    numvar = rxVlist(global., 'V', 'GlobalQueue')
  179.  
  180.    /* Next lines would load to REXX macrospace
  181.    qinfo = rxQueryMacro(Global_Set)
  182.    if substr(qinfo,1,1) = 0 then
  183.       NOP
  184.    else
  185.       addrc = rxaddmacro(Global_set, global_set.cmd)
  186.    */
  187. Return
  188.  
  189. Find_UserName: procedure
  190. /****************************************************************
  191. ** Get UserName for Userid Passed. This procedure is Encapsulated.
  192. *****************************************************************/
  193.    userid = ARG(1)
  194.  
  195.    Queue_Name = RxQueue("Create")
  196.    oq = RxQueue("Set",Queue_Name)
  197.  
  198.    /** Send Screen output to queue **/
  199.    "@Net Who "Userid"| PIPE "Queue_Name
  200.  
  201.    /** Do while Queue Still has lines **/
  202.    do Queued()
  203.       /** Read next line in queue **/
  204.       PARSE PULL line
  205.  
  206.       /** If line Has User's comment then line contains Name **/
  207.       If POS("User's Comment:",line) > 0 then do
  208.  
  209.          /** Strip off Label **/
  210.          Comment = STRIP(SUBSTR(line,POS(":",line)+1))
  211.  
  212.          /** Find last column poistion of name. Ignoring Case Number **/
  213.          NameEnd = LASTPOS("CASE",Comment) -1
  214.  
  215.          /** Needed in case there is no CASE number in USERID **/
  216.          if NameEnd = -1 then
  217.             NameEnd = LENGTH(Comment)
  218.  
  219.          /** Get User's Name **/
  220.          UserName = STRIP(SUBSTR(line,POS(":",line)+1,NameEnd))
  221.          leave
  222.       end
  223.    end
  224.  
  225.    /** Free up memory by deleting queue **/
  226.    oq = RxQueue("Delete",Queue_name)
  227.  
  228. Return UserName
  229.  
  230. HALT:
  231. /****************************************************************
  232. ** User stopped program! Shame on them!!
  233. *****************************************************************/
  234.    trace off
  235.    SAY LocalGlobal.Program||" User interrupted program."
  236.    Call Pause
  237.    EXIT -1
  238.  
  239. ERROR:
  240. /****************************************************************
  241. ** Error of some sort occured!
  242. *****************************************************************/
  243.    trace off
  244.    myrc = RC
  245.    SAY LocalGlobal.Program||' error occurred !'
  246.    SAY
  247.  
  248.    SAY 'REXX error' myrc 'in line' SIGL':' ||global.iRedWhite||ERRORTEXT(myrc)||global.iNormal
  249.    SAY global.iBrightRed||Substr('     ',1,6-Length(SIGL))(SIGL)' *-*   'Sourceline(sigl)||global.iNormal
  250.  
  251.    SAY
  252.  
  253. IF MYRC = 43 THEN do
  254.    SAY
  255.    SAY '    Chances are you are in not in the correct subdirectory.'
  256.    SAY '    This procedure MUST use some External Functions.'
  257.    SAY '    You MUST have the DLL''s or CMD files for these External Functions'
  258.    SAY '     in your LIBPATH or PATH.'
  259.    SAY '    (Since your are in OS/2 2.x then you should have "." in your LIBPATH'
  260.    SAY '    This would allow you to change to the directory with the DLL''s and run.)'
  261.    SAY
  262.    SAY global.iCyan||'Internally: YOU MUST BE IN K:\PUBLIC\REXX.'global.inormal
  263.    SAY
  264. end
  265. else do
  266.    SAY
  267.    SAY global.iCyan||'Please contact the author with a description of the error.'||global.iNormal
  268. end
  269.    CALL Pause
  270.    EXIT -99
  271.  
  272. Pause: procedure
  273. /****************************************************************
  274. ** Politely Pause
  275. *****************************************************************/
  276. Say "Press any key to continue."
  277. parse upper value SysGetKey('NOECHO') with key
  278.  
  279. Return
  280.  
  281.