home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
wwwmrg.zip
/
WWWMERGE.CMD
next >
Wrap
OS/2 REXX Batch file
|
1994-12-05
|
17KB
|
515 lines
/**
*** ╔════════════════════════════════════════════════════════════════════╗
*** ║ ║
*** ║ WWWMerge - version 1.0 ║
*** ║ ║
*** ║ ────────────────────────────────────────────────────────────────── ║
*** ║ This will merge two EXPLORE.INI files into the EXPLORE.INI file ║
*** ║ found in the %ETC% subdirectory. If the URL appears in the file ║
*** ║ EXCLUDE.INI in the %ETC% subdirectory, then it will not be added. ║
*** ║ ────────────────────────────────────────────────────────────────── ║
*** ║ ║
*** ║ This code is provided on an as-is basis. There is no warranty ║
*** ║ expressed or implied in the code. There is no official support ║
*** ║ for this code. However, you are welcome to contact Hilbert ║
*** ║ Computing for questions or comments on the code. If you make your ║
*** ║ own changes to the code and wish to upload the modified code to ║
*** ║ a public forum, please note your modifications to the code. ║
*** ║ ║
*** ║ Many of the routines require the REXX suppliment DLLs found in ║
*** ║ OS/2 v2.0 and later. ║
*** ║ ║
*** ║ I can be reached at: ║
*** ║ ║
*** ║ Gary Murphy, Sr. Programmer ║
*** ║ Hilbert Computing ║
*** ║ 1022 N. Cooper ║
*** ║ Olathe, KS 66061 ║
*** ║ ║
*** ║ BBS/Fax.. (913) 829-2450 8N1 14.4Kbps ║
*** ║ CIS...... [73457,365] ║
*** ║ ║
*** ║ ────────────────────────────────────────────────────────────────── ║
*** ║ Copyright (c) 1992-1994 Hilbert Computing ║
*** ╚════════════════════════════════════════════════════════════════════╝
**/
parse arg commandline
call LoadFunctions
Opt. = ''
call ParseOptions commandline
MergeFile = Opt.Parm.1
if MergeFile = '' then
call Error 2004,1,MergeFile,"You must enter a file name to merge."
call SysFileTree MergeFile, "Found", "FO"
if Found.0 = 0 then
call Error 2002,1,MergeFile
else
MergeFile = Found.1
etc = value("ETC",,"OS2ENVIRONMENT")
if etc = '' then
call Error 2008,1,"ETC"
call ReadExploreIni
call ReadExploreIni MergeFile
call ReadExploreIni etc"\EXCLUDE.INI"
call GetNewList
call WriteNewIniFile
exit
WriteNewIniFile: procedure expose explore.
/**
*** This will write the old INI file plus the new entries in the merge list
**/
etc = value("ETC",,"OS2ENVIRONMENT")
say "Backing up EXPLORE.INI..."
"@copy" etc"\EXPLORE.INI" etc"\EXPLORE.BAK > NUL 2> NUL"
new = Open(etc"\EXPLORE.INI","Write")
do i = 1 to explore.!pre.1.0 ; call lineout new,explore.!pre.1.i ; end
call lineout new,"[quicklist]"
do i = 1 to explore.!ql.1.0
parse var explore.!ql.1.i "|" DescText "|" URL "|"
call lineout new,"quicklist= "DescText
call lineout new,URL
end
say "Adding" explore.!ql.4.0 "entries..."
do i = 1 to explore.!ql.4.0
parse var explore.!ql.4.i "|" DescText "|" URL "|"
call lineout new,"quicklist= "DescText
call lineout new,URL
end
call lineout new," "
do i = 1 to explore.!post.1.0; call lineout new,explore.!post.1.i ; end
code = Close(new)
return
IsInList: procedure expose explore.
/**
*** Return a boolean indicating whether the reference is in the list
*** indexed
**/
parse arg ref,l
do i = 1 to explore.!ql.l.0
if explore.!ql.l.i = ref then return 1
end
return 0
GetNewList: procedure expose explore.
/**
*** Determine which of the things in the merge list are new and not
*** in the exclude list
**/
l = 1
do i = 1 to explore.!ql.2.0
if IsInList(explore.!ql.2.i, 1) = 0 then /* If not in original list */
if IsInList(explore.!ql.2.i, 3) = 0 then /* If not in exclude list */
do
explore.!ql.4.l = explore.!ql.2.i /* Add to the new list */
l = l + 1
end
end
explore.!ql.4.0 = l - 1
return
ReadExploreIni: procedure expose explore.
/**
*** This will read an EXPLORE.INI formatted file. If no file name is
*** passed, this will assume the live INI file in the ETC directory.
**/
parse arg ExploreIni
if ExploreIni = '' then
do
etc = value("ETC",,"OS2ENVIRONMENT")
ExploreIni = etc"\EXPLORE.INI"
end
if value(explore.0) = "EXPLORE.0" then
do
explore. = ''
explore.0 = 0
end
/* Increment the number of explore files */
j = explore.0
j = j + 1
explore.0 = j
if Exists(ExploreIni) = 0 then
do
explore.!pre.j.0 = 0
explore.!ql.j.0 = 0
explore.!post.j.0 = 0
end
call charout ,"Reading" translate(ExploreIni)"..."
ExploreIni = Open(ExploreIni,'Read')
l = 1
Found = 0
/* Load all of the information up to the QuickList into the stem */
do while(lines(ExploreIni) > 0) & (Found = 0)
explore.!pre.j.l = linein(ExploreIni)
if translate(explore.!pre.j.l) = '[QUICKLIST]' then
do
Found = 1
explore.!pre.j.0 = l - 1
end
l = l + 1
end /* while */
if Found = 0 then
call Error 3003,1,ExploreIni
/* Load the quicklist into the stem */
l = 1
Found = 0
do while(lines(ExploreIni) > 0) & (Found = 0)
Description = linein(ExploreIni) /* Text description */
if Description = '' then
do
Found = 1
explore.!ql.j.0 = l - 1
end
else
do
parse var Description . '= ' DescText
URL = linein(ExploreIni) /* URL */
explore.!ql.j.l = '|'strip(DescText)'|'URL'|'
end
l = l + 1
end /* while */
say explore.!ql.j.0 "entries."
l = 1
Found = 0
do while(lines(ExploreIni) > 0) & (Found = 0)
explore.!post.j.l = linein(ExploreIni)
l = l + 1
end /* while */
explore.!post.j.0 = l - 1
code = Close(ExploreIni)
return
/* #include <io.rex> */
/* #include <error.rex> */
/**
*** ╔═══════════════════════════════════════════════════════════════════════╗
*** ║ Error Handler ║
*** ╚═══════════════════════════════════════════════════════════════════════╝
**/
Error: procedure
/**
*** This is a centralized processor for error messages and error handling
**/
parse arg ErrNo,Fatal,String1,String2,String3
if Fatal = 0 then
MsgId = 'HRX'right(ErrNo,4,"0")'W:'
else
MsgId = 'HRX'right(ErrNo,4,"0")'E:'
/* Select the error string based on the error number */
select
when ErrNo = 0 then return
when ErrNo = 1001 then Msg = "Return code %1 from RxFuncAdd for SQLEXEC"
when ErrNo = 1002 then Msg = "Return code [%1] from SQLEXEC. You are probably out-of-storage."
when ErrNo = 1003 then Msg = "SQL code [%1]: %2"
when ErrNo = 2002 then Msg = "File '%1' not found."
when ErrNo = 2003 then Msg = "Directory '%1' doesn't exist."
when ErrNo = 2004 then Msg = "Missing parameter. %1"
when ErrNo = 2005 then Msg = "Close failure on %1. %2"
when ErrNo = 2006 then Msg = "Open failure on %1. %2"
when ErrNo = 2007 then Msg = "Invalid parameter %1. %2"
when ErrNo = 3000 then Msg = "Urecognized message '%1' passed from message queue."
when ErrNo = 3001 then Msg = "Error from server: %1."
when ErrNo = 3002 then Msg = "Invalid keyword: %1. %2"
when ErrNo = 4000 then Msg = "Host screen doesn't match expected value of '%1'"
when ErrNo = 4001 then Msg = "Unexpected return code '%1' from HLLAPI verb '%2'"
when ErrNo = 4800 then Msg = "NetBIOS '%1' received a return code %2"
when ErrNo = 5005 then Msg = "Return code 5 from RxQueue. Not a valid queue name: '%1'"
when ErrNo = 5009 then Msg = "Return code 9 from RxQueue. Queue does not exist: '%1'"
when ErrNo = 5010 then Msg = "Return code 10 from RxQueue. Queue is busy: '%1'"
when ErrNo = 5012 then Msg = "Return code 12 from RxQueue. Memory failure on queue: '%1'"
when ErrNo = 6000 then Msg = "Return code 1000 from RxQueue. Initialization error on queue: '%1'"
when ErrNo = 9999 then Msg = "%1"
otherwise Msg = "[%1,%2,%3]"
end /* select */
/* Render the string with the substituted parameters */
Msg = ErrorRender('%1',String1,Msg)
Msg = ErrorRender('%2',String2,Msg)
Msg = ErrorRender('%3',String3,Msg)
Callback = value("REXX.CALLBACK",,"OS2ENVIRONMENT")
if Callback = '1' then
call ErrorHandler Msg
else
say MsgId Msg
/* Should we terminate? */
if Fatal then exit ErrNo
return 0
ErrorRegister: procedure
/**
*** This will register a callback to the calling routine for error handling
*** after the error message has been rendered.
***
*** If this code is called, the caller MUST have a routine called
*** 'ErrorHandler' that is used to display the error message in an
*** appropriate way.
***
**/
parse arg callback
if callback = '' then
callback = '1'
code = value("REXX.CALLBACK",callback,"OS2ENVIRONMENT")
return 0
ErrorRender: procedure
parse arg Symbol,SymValue,Line
if pos(Symbol, Line) > 0 then
do
parse var Line prefix (Symbol) suffix
Line = prefix || SymValue || suffix
end
return Line
Close: procedure
/**
*** Close a file I/O stream
**/
parse arg file
if file = '' then
do
call Error 2005,1,file,"No file name was passed to the CLOSE routine."
return
end
message = stream(file,c,'CLOSE')
if (message <> 'READY:') & (message <> '') then
call Error 2005,1,file,message
return file
Exists: procedure
/**
*** Return a Boolean indicating whether the file exists or not
**/
arg file
file = stream(file,c,'QUERY EXIST')
if (file = '') then
return 0
else
return 1
Open: procedure
/**
*** Open a file for READ, WRITE, APPEND or RANDOM (read/write)
**/
parse arg file, rw
if file = '' then
do
call Error 2006,0,file,'No file name passed on OPEN call.'
return ''
end
rw = translate(rw)
select
when rw = 'WRITE' then
do
file_ = stream(file,c,'QUERY EXIST')
if file_ <> '' then
'@erase "'file'" 2> NUL'
end
when rw = 'APPEND' then
rw = 'WRITE'
when rw = 'READ' then
rw = 'READ'
when rw = 'RANDOM' then
rw = ''
otherwise
rw = 'READ'
end /* select */
message = stream(file,c,'OPEN' rw)
if (message \= 'READY:') then
do
call Error 2006,0,file,message
return ''
end
return file
/* #include LoadFunctions.rex */
LoadFunctions: procedure
/**
*** This will load the DLL for the Rexx system functions supplied
*** with OS/2 v2.0
**/
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
return
/* #include <parseopt.rex> */
ParseOptions: procedure expose Opt.
/**
*** This will parse the command line options. Those parameters that
*** begin with a minus (-) or forward slash (/) are considered flags
*** and are placed in Opt.Flag. The remaining options are placed
*** into Opt.parm.<x>.
***
*** NOTE: This code does not clear out the 'Opt.' stem variable since
*** the caller may want to establish defaults prior to calling
*** this code.
***
*** LIMITATIONS: The code currently only looks for the double quote
*** character ("). The apostrophe is treated like any other
*** character. The way this is currently coded, multiple blanks
*** in a quoted string are compressed to a single blanks and
*** probably should not be.
***
**/
parse arg arguments
Opt.Flag.List = ''
Opt.State = 'Normal'
j = 0
do i = 1 to words(arguments)
argument = word(arguments, i)
select
when Opt.State = 'Quoted Positional' then
do
/* Keep appending the words to this parm until an ending quote */
/* is found. */
Opt.Parm.j = Opt.Parm.j argument
if right(argument,1) = '"' then
do
Opt.Parm.j = strip(Opt.Parm.j, 'Both', '"')
Opt.State = 'Normal'
end
end
when Opt.State = 'Quoted Flag' then
do
/* Keep appending until the terminating quote is found */
Opt.Flag.Flagname = Opt.Flag.FlagName argument
if right(argument,1) = '"' then
do
Opt.Flag.Flagname = strip(Opt.Flag.Flagname, 'Both', '"')
Opt.State = 'Normal'
end
end
when Opt.State = 'Normal' then
do
FirstChar = left(argument, 1)
if ((FirstChar = '-') | (FirstChar = '/')) then
do
/* This is a flag. The value of the flag is the remainder of */
/* the string. If the remainder is the null string, then it */
/* has an implicit value of '+' implying "on" or "true" */
FlagName = substr(argument, 2, 1) /* Second character */
FlagName = translate(FlagName) /* Convert to uppercase */
/* See if this flag parm is quoted */
if substr(argument, 3, 1) = '"' then
Opt.State = 'Quoted Flag'
/* If any of the flag names are not a valid character for a REXX */
/* variable, we have to translate into a mnemonic. */
if ((FlagName < 'A') | (FlagName > 'Z')) then
do
select
when FlagName = '?' then FlagName = 'SYNTAX'
when FlagName = '!' then FlagName = 'BANG'
when FlagName = '*' then FlagName = 'STAR'
when FlagName = '#' then FlagName = 'POUND'
when FlagName = '$' then FlagName = 'DOLLAR'
when FlagName = '%' then FlagName = 'PERCENT'
when FlagName = '^' then FlagName = 'HAT'
when FlagName = '&' then FlagName = 'AMP'
when FlagName = '(' then FlagName = 'LPAR'
when FlagName = ')' then FlagName = 'RPAR'
when FlagName = '-' then FlagName = 'DASH'
when FlagName = '=' then FlagName = 'EQUAL'
otherwise /* Force a syntax message */
FlagName = 'SYNTAX'
end /* select */
end /* if */
FlagValue = substr(argument, 3) /* Remainder of string */
if FlagValue = '' then
FlagValue = '+'
Opt.Flag.FlagName = FlagValue
Opt.Flag.List = FlagName Opt.Flag.List
end
else /* it is a positional parameter */
do
j = j + 1
Opt.Parm.j = argument
if left(argument,1) = '"' then
Opt.State = 'Quoted Positional'
end
end /* 'Normal' */
otherwise
nop
end /* select */
end /* do i... */
Opt.Parm.0 = j
return 0