home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 April A
/
Pcwk4a98.iso
/
Wtestowe
/
OnNet16
/
LIBRARY.SCR
< prev
next >
Wrap
Text File
|
1997-01-08
|
11KB
|
369 lines
*---------------------------------------------------------------------*
* "LIBRARY.SCR" : Relay/PC Gold Library Creation *
*---------------------------------------------------------------------*
*
* (c) Copyright 1983,1993 RELAY Technology Inc.
*
* This program creates a Library file for use with Relay/PC Gold.
* The user is prompted for the library fileid and the member
* list fileid.
*
* Supplied arguments (optional) are:
* &1 = Library fileid
* &2 = List fileid
* &3+= Options:
* "QUIET" to execute quietly, without messages
* "APPEND" or "ADD" to add to an existing library
* "STRIP" to run STRIPSCR on members added
*
* Member-list records have the form:
*
* 1) d:filename.ext - for a new member
*
* 2) aliasname=membername - to define an alias
*
* 3) + minsp align - to align size to multiple of "align",
* reserving an least "minsp".
*
* 4) /name args - to execute script "name" before continuing.
*
* Notes:
*
* 1) The member files must reside on the same directory as
* the list file (the second argument).
*
*---------------------------------------------------------------------*
* Module History *
*---------------------------------------------------------------------*
* *
* Latest Revision - *
* *
* $Revision: 1.8 $ *
* *
* Modification Log - *
* *
* M0001V70 Put Relay Source Files under PVCS Control *
* by JMM on 12/18/95 *
* *
*---------------------------------------------------------------------*
*
* on error
on nomemory stop error "WInsufficient memory to run &0!"
*
* Initialize variables
*
&OUTFILE = &1 ;* Library fileid (output file)
&LISTFILE = &2 ;* List fileid (input file)
&OUTSIZE=0 ;* Accumulated size of output file
&MFILE="" ;* Member fileid
&MNAME="" ;* Member name
&LSTCNT=0 ;* Count of member list items
&DIRCNT=0 ;* Count of actual directory entries
&DIRFST=0 ;* Record offset to write directory at
&LSTCNT=0 ;* Current member list item
&ENTNUM=0 ;* Alternate directory entry number
&INPFN0="" ;* Array is list of file names
&DIRMN1="" ;* Array is list of member names
&DIRNO1=0 ;* Array is member offset in file
&DIRLN1=0 ;* Array is length of member
&QUIET = NO ;* Execute quietly?
&APPEND=NO ;* Appending to existing library?
&MAXMEM=999999 ;* Maximum members allowed to add
&STRIPM=NO ;* Strip members?
&TMPID="&FDIR(&DOSENV(TMP))$$LIB$$.SCX" ;* A temporary fileid
&LONGMSG="";&TOTLINES=0
*
* Introduction & prompts
*
&ARG = 2
-OPT1 &ARG=&ARG+1
if (&ARG>&N) goto -OPT2
if (&&ARG~"QUIET") &QUIET="YES" ; goto -OPT1
if (&&ARG~"APPEND") &APPEND="YES" ; goto -OPT1
if (&&ARG~"ADD") &APPEND="YES" ; goto -OPT1
if (&&ARG~"STRIP") &STRIPM="YES" ; goto -OPT1
stop error "W&0 - Invalid option: &&ARG"
-OPT2
if (&QUIET="YES") goto -SKIP1
if (&WHERE<>"OFF") and (&WHERE<>"BATCH") goto -SKIP1
CLEAR
-SKIP1
IF (&OUTFILE<>"") GOTO -CHECK1
-ASK1 if (&QUIET="YES") stop 99
display dialogbox INPUT "Library Utility" "Enter the fileid for the Library to be created: " &OUTFILE
IF (&OUTFILE="") STOP 99 "INo library created!"
-CHECK1 &OUTFILE=&UPPER(&TRIM(&OUTFILE))
IF NOT VALID &OUTFILE GOTO -ASK1
IF (&LISTFILE<>"") GOTO -CHECK2
-ASK2 if (&QUIET="YES") stop 99
display dialogbox INPUT "Library Utility" "Enter the fileid for the list of members: " &LISTFILE
IF (&LISTFILE="") STOP 99 "INo library created!"
-CHECK2 &LISTFILE=&UPPER(&TRIM(&LISTFILE))
IF NOT VALID &LISTFILE GOTO -ASK2
*
* If we are appending to an existing library, we must have
* space between the end of the directory and the first member.
*
if (&APPEND<>"YES") goto -OLD1
OPEN &OUTFILE AS #2 LENGTH 16 BINARY
FIELD #2 1 8 &DIRMN&LSTNUM CHAR
FIELD #2 * 2 &DIRNO&LSTNUM DEC
FIELD #2 * 2 &DIRLN&LSTNUM DEC
&LSTNUM = 1
read record #2
&LSTNUM = 0
read record #2
close #2
&OUTSIZE = &DIRNO1*16
&DIRFST = &DIRLN1+1
&MAXMEM = &DIRNO0-&DIRFST
-OLD1
*
* The first directory entry is a library identifier
*
&MFILE = "PDSDIR"
GOSUB -ADDMEM
*
* Process the List File (read member names)
*
OPEN &LISTFILE AS #1 FOR INPUT
&MEMDRV = &FDIR(&LISTFILE)
READ FILE #1 &MFILE
LOOP -RDLST WHILE FOUND
IF (&LEFT(&MFILE,1)<>"*") GOSUB -ADDMEM
then if (&RC>0) goto -BADMEM
-RDLST READ FILE #1 &MFILE
CLOSE #1
if (&DIRCNT-1>&MAXMEM) stop 97 "ENo room left in library directory for append!"
*
* Begin Library Creation: Reserve space for the directory.
*
if (&APPEND="YES") &AS = "APPEND" ; else &AS = "OUTPUT"
OPEN &OUTFILE AS #2 FOR &AS STREAM BINARY BUFFERSIZE 4096
if (&APPEND="YES") goto -PREDIR1
LOOP *+1 &DIRCNT
WRITE FILE #2 &STRING(&NULL,16)
&OUTSIZE = &OUTSIZE+16*&DIRCNT
-PREDIR1
*
* Add members to the library.
*
gosub -TYPEIT "Adding members ..."
global &STRIPID ;* Used by STRIPSCR.EDS
&LSTNUM = 2
LOOP -COPIED &LSTCNT-1
&MFILE = &INPFN&LSTNUM
&MNAME = &DIRMN&LSTNUM
IF (&LEFT(&MNAME,1)="+") GOTO -RESERVE
IF (&LEFT(&MNAME,1)="/") GOTO -EXECSCR
IF (&LEFT(&MFILE,1)="=") GOTO -CALIAS
&MFILE = &MEMDRV.&MFILE
if (&STRIPM="YES")
then copyfile &MFILE &TMPID
then &STRIPID = &fileid(&MFILE)
then edit &TMPID nodisplay exec stripscr.eds
then &MFILE = &TMPID
&DIRNO&LSTNUM = &OUTSIZE/16
&DIRLN&LSTNUM = &FSIZE(&MFILE)
&AT = "&RIGHT(000&HEX(&DIRNO&LSTNUM)0,5)h"
gosub -TYPEIT "&MNAME (offset &AT length &DIRLN&LSTNUM)"
if (&DIRLN&LSTNUM>65535) GOTO -TOOBIG
OPEN &MFILE AS #1 FOR INPUT STREAM BINARY BUFFERSIZE 4096
READ FILE #1 &RECORD
LOOP *+2 WHILE FOUND
WRITE FILE #2 &RECORD
READ FILE #1 &RECORD
CLOSE #1
&OUTSIZE = &OUTSIZE+&DIRLN&LSTNUM
&LEFTOVER = 16-(&DIRLN&LSTNUM\16)
IF (&LEFTOVER<16) WRITE FILE #2 &STRING(&NULL,&LEFTOVER)
THEN &OUTSIZE=&OUTSIZE+&LEFTOVER
if (&STRIPM="YES") erase &TMPID
GOTO -COPIED
-CALIAS &MFILE = &SUBSTR(&MFILE,2)
GOSUB -LOOKUP
&DIRNO&LSTNUM = &DIRNO&ENTNUM
&DIRLN&LSTNUM = &DIRLN&ENTNUM
gosub -TYPEIT "&MNAME = &DIRMN&ENTNUM"
GOTO -COPIED
-RESERVE &MNAME = &substr(&MNAME,2)
argstring &MNAME
&RESERVE = 0
if (&OUTSIZE\&2>0) gosub -RWRITE &CALC(&2-(&OUTSIZE\&2))
if (&RESERVE<&1) gosub -RWRITE &CALC(&1-&RESERVE)
then if (&OUTSIZE\&2>0) gosub -RWRITE &CALC(&2-(&OUTSIZE\&2))
gosub -typeit "+ &RESERVE"
GOTO -COPIED
-EXECSCR sub command quiet exec &substr(&MNAME,2)
if (&RC>0) &RTC = &RC ; close #2 ; stop &RTC
-COPIED &LSTNUM = &LSTNUM+1
CLOSE #2
*
* Write the Library Directory
*
&DIRNO1 = &OUTSIZE/16
&DIRLN1 = &DIRLN1+&DIRCNT-1
OPEN &OUTFILE AS #2 LENGTH 16 BINARY
FIELD #2 1 8 &DIRMN&LSTNUM CHAR
FIELD #2 * 2 &DIRNO&LSTNUM DEC
FIELD #2 * 2 &DIRLN&LSTNUM DEC
FIELD #2 * 4 &NULL
&LSTNUM = 1
if (&APPEND="YES") point #2 1 ; WRITE RECORD #2 ; point #2 &DIRFST+1
then &LSTNUM=2 ; &LSTCNT=&LSTCNT-1
LOOP -WRTDIR &LSTCNT
&MFILE = &INPFN&LSTNUM
IF (&LEFT(&MFILE,1)="+") GOTO -WRTDIR
IF (&LEFT(&MFILE,1)="/") GOTO -WRTDIR
WRITE RECORD #2
-WRTDIR &LSTNUM = &LSTNUM+1
CLOSE #2
*
* Library Creation is complete
*
gosub -TYPEIT
display dialogbox OK 'Library Utility' "Library &OUTFILE has been created from &DIRLN1 members."
&RTC = 0
-EXIT reset &STRIPID
STOP &RTC
*
* Error: Invalid member list
*
-BADMEM close #1
display dialogbox OK "Invalid member list file: &LISTFILE"
&RTC = 98
goto -EXIT
*
* Error: Library is too large
*
-TOOBIG close #2
display dialogbox OK "Library or library member is too large!"
&RTC = 98
goto -EXIT
*---------------------------------------------------------------------*
* Subroutine to add member name to list *
*---------------------------------------------------------------------*
-ADDMEM &MFILE = &UPPER(&TRIM(&MFILE))
&LSTCNT = &LSTCNT+1
IF (&LEFT(&MFILE,1)="+") GOTO -ARESERV
IF (&LEFT(&MFILE,1)="/") GOTO -AEXECSC
&DIRCNT = &DIRCNT+1
&POSN = &INSTR(&MFILE,"=",1)
IF (&POSN>0) GOTO -AALIAS
&MNAME = &MFILE
&POSN = &INSTR(&MNAME,":",1)
IF (&POSN>0) &MNAME = &SUBSTR(&MNAME,&POSN+1)
&POSN = &INSTR(&MNAME,".",1)
IF (&POSN>0) &MNAME = &SUBSTR(&MNAME,1,&POSN-1)
&DIRMN&LSTCNT = &LEFT(&MNAME,8)
&INPFN&LSTCNT = &MFILE
RETURN 0
-AALIAS &MNAME = &SUBSTR(&MFILE,1,&POSN-1)
&DIRMN&LSTCNT = &LEFT(&MNAME,8)
&INPFN&LSTCNT = &SUBSTR(&MFILE,&POSN)
RETURN 0
-AEXECSC &DIRMN&LSTCNT = &MFILE
&INPFN&LSTCNT = "/"
return 0
-ARESERV &MFILE = &substr(&MFILE,2)
argstring &MFILE
if (&n<>2) return 1
if (&DATATYPE(&1)<>NUM) return 1
if (&DATATYPE(&2)<>NUM) return 1
&DIRMN&LSTCNT = "+ &1 &2"
&INPFN&LSTCNT = "+"
return 0
*---------------------------------------------------------------------*
* Subroutine to lookup name in member list *
*---------------------------------------------------------------------*
-LOOKUP &ENTNUM = 2
LOOP *+2 &LSTCNT-1
IF (&TRIM(&DIRMN&ENTNUM)=&MFILE) RETURN
&ENTNUM = &ENTNUM+1
&ENTNUM = 0
RETURN
*---------------------------------------------------------------------*
* Subroutine to type a line *
*---------------------------------------------------------------------*
-TYPEIT if (&QUIET="YES") return
if (&WHERE<>"OFF") and (&WHERE<>"BATCH") return
* type "&1"
* If total lines in dialogbox less than 5, then append message
if (&TOTLINES<5) then &LONGMSG=&LONGMSG.&1&lf
then &TOTLINES=&TOTLINES+1
then goto DISP1
* Otherwise, remove first message to make room for next message
&POS = &instr(&LONGMSG,&lf)
if (&POS>0) then &LONGMSG=&substr(&LONGMSG,&POS+1)
&LONGMSG=&LONGMSG.&1&lf
&TOTLINES=&TOTLINES+1
-DISP1
display dialogbox infomessage "Library Utility" "&LONGMSG"
return
*---------------------------------------------------------------------*
* Subroutine to write reserved space *
*---------------------------------------------------------------------*
-RWRITE &WSIZE = &1
&CHUNK = 256
&RESERVE = &RESERVE+&WSIZE
loop -RCHUNK while (&WSIZE>0)
if (&CHUNK>&WSIZE) &CHUNK=&WSIZE
write file #2 &string(&null,&CHUNK)
&OUTSIZE=&OUTSIZE+&CHUNK
-RCHUNK &WSIZE = &WSIZE-&CHUNK
return