home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / wwwmrg.zip / WWWMERGE.CMD next >
OS/2 REXX Batch file  |  1994-12-05  |  17KB  |  515 lines

  1. /**
  2. *** ╔════════════════════════════════════════════════════════════════════╗
  3. *** ║                                                                    ║
  4. *** ║  WWWMerge - version 1.0                                            ║
  5. *** ║                                                                    ║
  6. *** ║ ────────────────────────────────────────────────────────────────── ║
  7. *** ║ This will merge two EXPLORE.INI files into the EXPLORE.INI file    ║
  8. *** ║ found in the %ETC% subdirectory.  If the URL appears in the file   ║
  9. *** ║ EXCLUDE.INI in the %ETC% subdirectory, then it will not be added.  ║
  10. *** ║ ────────────────────────────────────────────────────────────────── ║
  11. *** ║                                                                    ║
  12. *** ║ This code is provided on an as-is basis.  There is no warranty     ║
  13. *** ║ expressed or implied in the code.  There is no official support    ║
  14. *** ║ for this code.  However, you are welcome to contact Hilbert        ║
  15. *** ║ Computing for questions or comments on the code.  If you make your ║
  16. *** ║ own changes to the code and wish to upload the modified code to    ║
  17. *** ║ a public forum, please note your modifications to the code.        ║
  18. *** ║                                                                    ║
  19. *** ║ Many of the routines require the REXX suppliment DLLs found in     ║
  20. *** ║ OS/2 v2.0 and later.                                               ║
  21. *** ║                                                                    ║
  22. *** ║ I can be reached at:                                               ║
  23. *** ║                                                                    ║
  24. *** ║              Gary Murphy, Sr. Programmer                           ║
  25. *** ║              Hilbert Computing                                     ║
  26. *** ║              1022 N. Cooper                                        ║
  27. *** ║              Olathe, KS 66061                                      ║
  28. *** ║                                                                    ║
  29. *** ║              BBS/Fax.. (913) 829-2450 8N1 14.4Kbps                 ║
  30. *** ║              CIS...... [73457,365]                                 ║
  31. *** ║                                                                    ║
  32. *** ║ ────────────────────────────────────────────────────────────────── ║
  33. *** ║            Copyright (c) 1992-1994  Hilbert Computing              ║
  34. *** ╚════════════════════════════════════════════════════════════════════╝
  35. **/
  36.  
  37. parse arg commandline
  38.  
  39. call LoadFunctions
  40.  
  41. Opt. = ''
  42. call ParseOptions commandline
  43.  
  44. MergeFile = Opt.Parm.1
  45. if MergeFile = '' then
  46.    call Error 2004,1,MergeFile,"You must enter a file name to merge."
  47.  
  48. call SysFileTree MergeFile, "Found", "FO"
  49. if Found.0 = 0 then
  50.    call Error 2002,1,MergeFile
  51. else
  52.    MergeFile = Found.1
  53.  
  54. etc = value("ETC",,"OS2ENVIRONMENT")
  55. if etc = '' then
  56.    call Error 2008,1,"ETC"
  57.  
  58. call ReadExploreIni
  59. call ReadExploreIni MergeFile
  60. call ReadExploreIni etc"\EXCLUDE.INI"
  61.  
  62. call GetNewList
  63. call WriteNewIniFile
  64. exit
  65.  
  66.  
  67. WriteNewIniFile: procedure expose explore.
  68.    /**
  69.    *** This will write the old INI file plus the new entries in the merge list
  70.    **/
  71.  
  72.    etc = value("ETC",,"OS2ENVIRONMENT")
  73.    say "Backing up EXPLORE.INI..."
  74.    "@copy" etc"\EXPLORE.INI" etc"\EXPLORE.BAK > NUL 2> NUL"
  75.  
  76.    new = Open(etc"\EXPLORE.INI","Write")
  77.    do i = 1 to explore.!pre.1.0 ; call lineout new,explore.!pre.1.i  ; end
  78.  
  79.    call lineout new,"[quicklist]"
  80.    do i = 1 to explore.!ql.1.0
  81.       parse var explore.!ql.1.i "|" DescText "|" URL "|"
  82.       call lineout new,"quicklist= "DescText
  83.       call lineout new,URL
  84.    end
  85.  
  86.    say "Adding" explore.!ql.4.0 "entries..."
  87.  
  88.    do i = 1 to explore.!ql.4.0
  89.       parse var explore.!ql.4.i "|" DescText "|" URL "|"
  90.       call lineout new,"quicklist= "DescText
  91.       call lineout new,URL
  92.    end
  93.  
  94.    call lineout new," "
  95.    do i = 1 to explore.!post.1.0; call lineout new,explore.!post.1.i ; end
  96.    code = Close(new)
  97.    return
  98.  
  99.  
  100. IsInList: procedure expose explore.
  101.    /**
  102.    *** Return a boolean indicating whether the reference is in the list
  103.    *** indexed
  104.    **/
  105.  
  106.    parse arg ref,l
  107.  
  108.    do i = 1 to explore.!ql.l.0
  109.       if explore.!ql.l.i = ref then return 1
  110.    end
  111.    return 0
  112.  
  113.  
  114. GetNewList: procedure expose explore.
  115.    /**
  116.    ***  Determine which of the things in the merge list are new and not
  117.    ***  in the exclude list
  118.    **/
  119.  
  120.    l = 1
  121.    do i = 1 to explore.!ql.2.0
  122.       if IsInList(explore.!ql.2.i, 1) = 0 then      /* If not in original list */
  123.          if IsInList(explore.!ql.2.i, 3) = 0 then   /* If not in exclude list */
  124.             do
  125.             explore.!ql.4.l = explore.!ql.2.i       /* Add to the new list */
  126.             l = l + 1
  127.             end
  128.    end
  129.    explore.!ql.4.0 = l - 1
  130.    return
  131.  
  132.  
  133. ReadExploreIni: procedure expose explore.
  134.    /**
  135.    *** This will read an EXPLORE.INI formatted file.  If no file name is
  136.    *** passed, this will assume the live INI file in the ETC directory.
  137.    **/
  138.  
  139.    parse arg ExploreIni
  140.    if ExploreIni = '' then
  141.       do
  142.       etc = value("ETC",,"OS2ENVIRONMENT")
  143.       ExploreIni = etc"\EXPLORE.INI"
  144.       end
  145.  
  146.    if value(explore.0) = "EXPLORE.0" then
  147.       do
  148.       explore.  = ''
  149.       explore.0 = 0
  150.       end
  151.  
  152.    /* Increment the number of explore files */
  153.  
  154.    j = explore.0
  155.    j = j + 1
  156.    explore.0 = j
  157.  
  158.    if Exists(ExploreIni) = 0 then
  159.       do
  160.       explore.!pre.j.0 = 0
  161.       explore.!ql.j.0 = 0
  162.       explore.!post.j.0 = 0
  163.       end
  164.  
  165.    call charout ,"Reading" translate(ExploreIni)"..."
  166.  
  167.    ExploreIni = Open(ExploreIni,'Read')
  168.    l = 1
  169.    Found = 0
  170.  
  171.    /* Load all of the information up to the QuickList into the stem */
  172.  
  173.    do while(lines(ExploreIni) > 0) & (Found = 0)
  174.       explore.!pre.j.l = linein(ExploreIni)
  175.       if translate(explore.!pre.j.l) = '[QUICKLIST]' then
  176.          do
  177.          Found = 1
  178.          explore.!pre.j.0 = l - 1
  179.          end
  180.       l = l + 1
  181.    end /* while */
  182.    if Found = 0 then
  183.       call Error 3003,1,ExploreIni
  184.  
  185.    /* Load the quicklist into the stem */
  186.  
  187.    l = 1
  188.    Found = 0
  189.    do while(lines(ExploreIni) > 0) & (Found = 0)
  190.       Description = linein(ExploreIni)    /* Text description */
  191.       if Description = '' then
  192.          do
  193.          Found = 1
  194.          explore.!ql.j.0 = l - 1
  195.          end
  196.       else
  197.          do
  198.          parse var Description . '= ' DescText
  199.          URL = linein(ExploreIni)         /* URL              */
  200.          explore.!ql.j.l = '|'strip(DescText)'|'URL'|'
  201.          end
  202.       l = l + 1
  203.    end /* while */
  204.    say explore.!ql.j.0 "entries."
  205.  
  206.    l = 1
  207.    Found = 0
  208.  
  209.    do while(lines(ExploreIni) > 0) & (Found = 0)
  210.       explore.!post.j.l = linein(ExploreIni)
  211.       l = l + 1
  212.    end /* while */
  213.    explore.!post.j.0 = l - 1
  214.    code = Close(ExploreIni)
  215.    return
  216.  
  217.  
  218.  
  219. /* #include <io.rex> */
  220.  
  221.  
  222.  
  223. /* #include <error.rex> */
  224.  
  225. /**
  226. *** ╔═══════════════════════════════════════════════════════════════════════╗
  227. *** ║ Error Handler                                                         ║
  228. *** ╚═══════════════════════════════════════════════════════════════════════╝
  229. **/
  230.  
  231.  
  232. Error: procedure
  233.    /**
  234.    ***  This is a centralized processor for error messages and error handling
  235.    **/
  236.  
  237.    parse arg ErrNo,Fatal,String1,String2,String3
  238.  
  239.    if Fatal = 0 then
  240.       MsgId = 'HRX'right(ErrNo,4,"0")'W:'
  241.    else
  242.       MsgId = 'HRX'right(ErrNo,4,"0")'E:'
  243.  
  244.  
  245.    /* Select the error string based on the error number */
  246.  
  247.    select
  248.       when ErrNo = 0    then return
  249.       when ErrNo = 1001 then Msg = "Return code %1 from RxFuncAdd for SQLEXEC"
  250.       when ErrNo = 1002 then Msg = "Return code [%1] from SQLEXEC.  You are probably out-of-storage."
  251.       when ErrNo = 1003 then Msg = "SQL code [%1]: %2"
  252.       when ErrNo = 2002 then Msg = "File '%1' not found."
  253.       when ErrNo = 2003 then Msg = "Directory '%1' doesn't exist."
  254.       when ErrNo = 2004 then Msg = "Missing parameter. %1"
  255.       when ErrNo = 2005 then Msg = "Close failure on %1. %2"
  256.       when ErrNo = 2006 then Msg = "Open failure on %1. %2"
  257.       when ErrNo = 2007 then Msg = "Invalid parameter %1. %2"
  258.       when ErrNo = 3000 then Msg = "Urecognized message '%1' passed from message queue."
  259.       when ErrNo = 3001 then Msg = "Error from server: %1."
  260.       when ErrNo = 3002 then Msg = "Invalid keyword: %1. %2"
  261.       when ErrNo = 4000 then Msg = "Host screen doesn't match expected value of '%1'"
  262.       when ErrNo = 4001 then Msg = "Unexpected return code '%1' from HLLAPI verb '%2'"
  263.       when ErrNo = 4800 then Msg = "NetBIOS '%1' received a return code %2"
  264.       when ErrNo = 5005 then Msg = "Return code 5 from RxQueue. Not a valid queue name: '%1'"
  265.       when ErrNo = 5009 then Msg = "Return code 9 from RxQueue. Queue does not exist: '%1'"
  266.       when ErrNo = 5010 then Msg = "Return code 10 from RxQueue. Queue is busy: '%1'"
  267.       when ErrNo = 5012 then Msg = "Return code 12 from RxQueue. Memory failure on queue: '%1'"
  268.       when ErrNo = 6000 then Msg = "Return code 1000 from RxQueue. Initialization error on queue: '%1'"
  269.  
  270.       when ErrNo = 9999 then Msg = "%1"
  271.       otherwise              Msg = "[%1,%2,%3]"
  272.    end /* select */
  273.  
  274.    /* Render the string with the substituted parameters */
  275.  
  276.    Msg = ErrorRender('%1',String1,Msg)
  277.    Msg = ErrorRender('%2',String2,Msg)
  278.    Msg = ErrorRender('%3',String3,Msg)
  279.  
  280.    Callback = value("REXX.CALLBACK",,"OS2ENVIRONMENT")
  281.    if Callback = '1' then
  282.       call ErrorHandler Msg
  283.    else
  284.       say MsgId Msg
  285.  
  286.    /* Should we terminate? */
  287.  
  288.    if Fatal then exit ErrNo
  289.    return 0
  290.  
  291.  
  292. ErrorRegister: procedure
  293.    /**
  294.    *** This will register a callback to the calling routine for error handling
  295.    *** after the error message has been rendered.
  296.    ***
  297.    *** If this code is called, the caller MUST have a routine called
  298.    *** 'ErrorHandler' that is used to display the error message in an
  299.    *** appropriate way.
  300.    ***
  301.    **/
  302.  
  303.    parse arg callback
  304.    if callback = '' then
  305.       callback = '1'
  306.  
  307.    code = value("REXX.CALLBACK",callback,"OS2ENVIRONMENT")
  308.    return 0
  309.  
  310.  
  311. ErrorRender: procedure
  312.  
  313.    parse arg Symbol,SymValue,Line
  314.  
  315.    if pos(Symbol, Line) > 0 then
  316.       do
  317.       parse var Line prefix (Symbol) suffix
  318.       Line = prefix || SymValue || suffix
  319.       end
  320.    return Line
  321.  
  322. Close: procedure
  323.    /**
  324.    ***  Close a file I/O stream
  325.    **/
  326.    parse arg file
  327.    if file = '' then
  328.       do
  329.       call Error 2005,1,file,"No file name was passed to the CLOSE routine."
  330.       return
  331.       end
  332.    message = stream(file,c,'CLOSE')
  333.    if (message <> 'READY:') & (message <> '') then
  334.       call Error 2005,1,file,message
  335.    return file
  336.  
  337.  
  338. Exists: procedure
  339.    /**
  340.    *** Return a Boolean indicating whether the file exists or not
  341.    **/
  342.    arg file
  343.  
  344.    file = stream(file,c,'QUERY EXIST')
  345.    if (file = '') then
  346.       return 0
  347.    else
  348.       return 1
  349.  
  350.  
  351. Open: procedure
  352.    /**
  353.    *** Open a file for READ, WRITE, APPEND or RANDOM (read/write)
  354.    **/
  355.    parse arg file, rw
  356.  
  357.    if file = '' then
  358.       do
  359.       call Error 2006,0,file,'No file name passed on OPEN call.'
  360.       return ''
  361.       end
  362.  
  363.    rw = translate(rw)
  364.  
  365.    select
  366.       when rw = 'WRITE' then
  367.          do
  368.          file_ = stream(file,c,'QUERY EXIST')
  369.          if file_ <> '' then
  370.             '@erase "'file'" 2> NUL'
  371.          end
  372.       when rw = 'APPEND' then
  373.          rw = 'WRITE'
  374.       when rw = 'READ' then
  375.          rw = 'READ'
  376.       when rw = 'RANDOM' then
  377.          rw = ''
  378.       otherwise
  379.          rw = 'READ'
  380.    end /* select */
  381.  
  382.    message = stream(file,c,'OPEN' rw)
  383.    if (message \= 'READY:') then
  384.       do
  385.       call Error 2006,0,file,message
  386.       return ''
  387.       end
  388.    return file
  389.  
  390. /* #include LoadFunctions.rex */
  391.  
  392. LoadFunctions: procedure
  393.    /**
  394.    ***   This will load the DLL for the Rexx system functions supplied
  395.    ***   with OS/2 v2.0
  396.    **/
  397.    call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  398.    call SysLoadFuncs
  399.    return
  400.  
  401. /* #include <parseopt.rex> */
  402.  
  403. ParseOptions: procedure expose Opt.
  404.    /**
  405.    ***  This will parse the command line options.  Those parameters that
  406.    ***  begin with a minus (-) or forward slash (/) are considered flags
  407.    ***  and are placed in Opt.Flag.   The remaining options are placed
  408.    ***  into Opt.parm.<x>.
  409.    ***
  410.    ***  NOTE:  This code does not clear out the 'Opt.' stem variable since
  411.    ***         the caller may want to establish defaults prior to calling
  412.    ***         this code.
  413.    ***
  414.    ***  LIMITATIONS:  The code currently only looks for the double quote
  415.    ***         character (").  The apostrophe is treated like any other
  416.    ***         character.  The way this is currently coded, multiple blanks
  417.    ***         in a quoted string are compressed to a single blanks and
  418.    ***         probably should not be.
  419.    ***
  420.    **/
  421.  
  422.    parse arg arguments
  423.  
  424.    Opt.Flag.List = ''
  425.    Opt.State = 'Normal'
  426.    j = 0
  427.    do i = 1 to words(arguments)
  428.       argument = word(arguments, i)
  429.  
  430.       select
  431.          when Opt.State = 'Quoted Positional' then
  432.             do
  433.             /* Keep appending the words to this parm until an ending quote */
  434.             /* is found.                                                   */
  435.  
  436.             Opt.Parm.j = Opt.Parm.j argument
  437.             if right(argument,1) = '"' then
  438.                do
  439.                Opt.Parm.j = strip(Opt.Parm.j, 'Both', '"')
  440.                Opt.State = 'Normal'
  441.                end
  442.             end
  443.          when Opt.State = 'Quoted Flag' then
  444.             do
  445.             /* Keep appending until the terminating quote is found */
  446.  
  447.             Opt.Flag.Flagname = Opt.Flag.FlagName argument
  448.             if right(argument,1) = '"' then
  449.                do
  450.                Opt.Flag.Flagname = strip(Opt.Flag.Flagname, 'Both', '"')
  451.                Opt.State = 'Normal'
  452.                end
  453.             end
  454.          when Opt.State = 'Normal' then
  455.             do
  456.             FirstChar = left(argument, 1)
  457.             if ((FirstChar = '-') | (FirstChar = '/')) then
  458.                do
  459.                /*  This is a flag.  The value of the flag is the remainder of  */
  460.                /*  the string.  If the remainder is the null string, then it   */
  461.                /*  has an implicit value of '+' implying "on" or "true"        */
  462.  
  463.                FlagName = substr(argument, 2, 1)   /* Second character     */
  464.                FlagName = translate(FlagName)      /* Convert to uppercase */
  465.  
  466.                /* See if this flag parm is quoted */
  467.  
  468.                if substr(argument, 3, 1) = '"' then
  469.                   Opt.State = 'Quoted Flag'
  470.  
  471.                /* If any of the flag names are not a valid character for a REXX */
  472.                /* variable, we have to translate into a mnemonic.               */
  473.  
  474.                if ((FlagName < 'A') | (FlagName > 'Z')) then
  475.                   do
  476.                   select
  477.                      when FlagName = '?' then FlagName = 'SYNTAX'
  478.                      when FlagName = '!' then FlagName = 'BANG'
  479.                      when FlagName = '*' then FlagName = 'STAR'
  480.                      when FlagName = '#' then FlagName = 'POUND'
  481.                      when FlagName = '$' then FlagName = 'DOLLAR'
  482.                      when FlagName = '%' then FlagName = 'PERCENT'
  483.                      when FlagName = '^' then FlagName = 'HAT'
  484.                      when FlagName = '&' then FlagName = 'AMP'
  485.                      when FlagName = '(' then FlagName = 'LPAR'
  486.                      when FlagName = ')' then FlagName = 'RPAR'
  487.                      when FlagName = '-' then FlagName = 'DASH'
  488.                      when FlagName = '=' then FlagName = 'EQUAL'
  489.                      otherwise /* Force a syntax message */
  490.                         FlagName = 'SYNTAX'
  491.                   end /* select */
  492.                   end /* if */
  493.  
  494.                FlagValue = substr(argument, 3)     /* Remainder of string */
  495.                if FlagValue = '' then
  496.                   FlagValue = '+'
  497.  
  498.                Opt.Flag.FlagName = FlagValue
  499.                Opt.Flag.List = FlagName Opt.Flag.List
  500.                end
  501.             else /* it is a positional parameter */
  502.                do
  503.                j = j + 1
  504.                Opt.Parm.j = argument
  505.                if left(argument,1) = '"' then
  506.                   Opt.State = 'Quoted Positional'
  507.                end
  508.          end /* 'Normal' */
  509.       otherwise
  510.          nop
  511.       end /* select */
  512.    end /* do i... */
  513.    Opt.Parm.0 = j
  514.    return 0
  515.