home *** CD-ROM | disk | FTP | other *** search
- -h- acopy.arc 267
- { acopy -- copy n characters from fdi to fdo }
- procedure acopy (fdi, fdo : filedesc; n : integer);
- var
- c : character;
- i : integer;
- begin
- for i := 1 to n do
- if (getcf(c, fdi) = ENDFILE) then
- error('archive: end of file in acopy')
- else
- putcf(c, fdo)
- end;
-
- -h- addfile.arc 423
- { addfile -- add file "name" to archive }
- procedure addfile (var name : string; fd : filedesc);
- var
- head : string;
- nfd : filedesc;
- {$include:'makehdr.arc'}
- begin
- nfd := open(name, IOREAD);
- if (nfd = IOERROR) then begin
- putstr(name, STDERR);
- message(': can''t add');
- errcount := errcount + 1
- end;
- if (errcount = 0) then begin
- makehdr(name, head);
- putstr(head, fd);
- fcopy(nfd, fd);
- xclose(nfd)
- end
- end;
-
- -h- archive.arc 939
- { archive -- file maintainer }
- procedure archive;
- const
- MAXFILES = 100; { or whatever }
- var
- aname : string; { archive name }
- cmd : string; { command type }
- fname : array [1..MAXFILES] of string; { filename args }
- fstat : array [1..MAXFILES] of boolean; { true=in archive }
- nfiles : integer; { number of filename arguments }
- errcount : integer; { number of errors }
- archtemp : string; { temp file name 'artemp' }
- archhdr : string; { header string '-h-' }
- {$include:'archproc.arc'}
- begin
- initarch;
- if (not getarg(1, cmd, MAXSTR))
- or (not getarg(2, aname, MAXSTR)) then
- help;
- getfns;
- if (length(cmd) <> 2) or (cmd[1] <> ord('-')) then
- help
- else if (cmd[2] = ord('c')) or (cmd[2] = ord('u')) then
- update(aname, cmd[2])
- else if (cmd[2] = ord('t')) then
- table(aname)
- else if (cmd[2] = ord('x')) or (cmd[2] = ord('p')) then
- extract(aname, cmd[2])
- else if (cmd[2] = ord('d')) then
- delete(aname)
- else
- help
- end;
-
- -h- archproc.arc 464
- { archproc -- include procedures for archive }
- {$include:'getword.arc' }
- {$include:'gethdr.arc' }
- {$include:'filearg.arc' }
- {$include:'fskip.arc' }
- {$include:'fmove.arc' }
- {$include:'acopy.arc' }
- {$include:'notfound.arc'}
- {$include:'addfile.arc' }
- {$include:'replace.arc' }
- {$include:'help.arc' }
- {$include:'getfns.arc' }
- {$include:'update.arc' }
- {$include:'table.arc' }
- {$include:'extract.arc' }
- {$include:'delete.arc' }
- {$include:'initarch.arc'}
-
- -h- delete.arc 478
- { delete -- delete files from archive }
- procedure delete (var aname : string);
- var
- afd, tfd : filedesc;
- begin
- if (nfiles <= 0) then { protect innocents }
- error('archive: -d requires explicit file names');
- afd := mustopen(aname, IOREAD);
- tfd := mustcreate(archtemp, IOWRITE);
- replace(afd, tfd, ord('d'));
- notfound;
- xclose(afd);
- xclose(tfd);
- if (errcount = 0) then
- fmove(archtemp, aname)
- else
- message('fatal errors - archive not altered');
- remove(archtemp)
- end;
-
- -h- extract.arc 724
- { extract -- extract files from archive }
- procedure extract (var aname: string; cmd : character);
- var
- ename, inline : string;
- afd, efd : filedesc;
- size : integer;
- begin
- afd := mustopen(aname, IOREAD);
- if (cmd = ord('p')) then
- efd := STDOUT
- else { cmd is 'x' }
- efd := IOERROR;
- while (gethdr(afd, inline, ename, size)) do
- if (not filearg(ename)) then
- fskip(afd, size)
- else begin
- if (efd <> STDOUT) then
- efd := create(ename, IOWRITE);
- if (efd = IOERROR) then begin
- putstr(ename, STDERR);
- message(': can''t create');
- errcount := errcount + 1;
- fskip(afd, size)
- end
- else begin
- acopy(afd, efd, size);
- if (efd <> STDOUT) then
- xclose(efd)
- end
- end;
- notfound
- end;
-
- -h- fequal.arc 376
- { fequal -- test two filenames for equality, ignoring leading x: if present }
- function fequal (var str1, str2 : string) : boolean;
- var
- i,j : integer;
- begin
- i := 1;
- j := 1;
- if (str1[2] = COLON) then i := 3;
- if (str2[2] = COLON) then j := 3;
- while (str1[i] = str2[j]) and (str1[i] <> ENDSTR) do begin
- i := i + 1;
- j := j + 1;
- end;
- fequal := (str1[i] = str2[j])
- end;
- -h- filearg.arc 434
- { filearg -- check if name matches argument list }
- function filearg (var name : string) : boolean;
- var
- i : integer;
- found : boolean;
- {$include:'fequal.arc'}
- begin
- if (nfiles <= 0) then
- filearg := true
- else begin
- found := false;
- i := 1;
- while (not found) and (i <= nfiles) do begin
- if (fequal(name, fname[i])) then begin
- fstat[i] := true;
- found := true
- end;
- i := i + 1
- end;
- filearg := found
- end
- end;
-
- -h- fmove.arc 235
- { fmove -- move file name1 to name2 }
- procedure fmove (var name1, name2 : string);
- var
- fd1, fd2 : filedesc;
- begin
- fd1 := mustopen(name1, IOREAD);
- fd2 := mustcreate(name2, IOWRITE);
- fcopy(fd1, fd2);
- xclose(fd1);
- xclose(fd2)
- end;
-
- -h- fsize.arc 263
- { fsize -- size of file in characters }
- function fsize (var name : string) : integer;
- var
- c : character;
- fd : filedesc;
- n : integer;
- begin
- n := 0;
- fd := mustopen(name, IOREAD);
- while (getcf(c, fd) <> ENDFILE) do
- n := n + 1;
- xclose(fd);
- fsize := n
- end;
-
- -h- fskip.arc 231
- { fskip -- skip n characters on file fd }
- procedure fskip (fd : filedesc; n : integer);
- var
- c : character;
- i : integer;
- begin
- for i := 1 to n do
- if (getcf(c, fd) = ENDFILE) then
- error('archive: end of file in fskip')
- end;
-
- -h- getfns.arc 524
- { getfns -- get filenames into fname, look for duplicates }
- procedure getfns;
- var
- i, j : integer;
- junk : boolean;
- begin
- errcount := 0;
- nfiles := nargs - 2;
- if (nfiles > MAXFILES) then
- error('archive: too many file names');
- for i := 1 to nfiles do
- junk := getarg(i+2, fname[i], MAXSTR);
- for i := 1 to nfiles do
- fstat[i] := false;
- for i := 1 to nfiles - 1 do
- for j := i + 1 to nfiles do
- if (equal(fname[i], fname[j])) then begin
- putstr(fname[i], STDERR);
- error(': duplicate file name')
- end
- end;
-
- -h- gethdr.arc 432
- { gethdr -- get header info from fd }
- function gethdr (fd : filedesc; var buf, name : string;
- var size : integer) : boolean;
- var
- temp : string;
- i : integer;
- begin
- if (getline(buf, fd, MAXSTR) = false) then
- gethdr := false
- else begin
- i := getword(buf, 1, temp);
- if (not equal(temp, archhdr)) then
- error('archive not in proper format');
- i := getword(buf, i, name);
- size := ctoi(buf, i);
- gethdr := true
- end
- end;
-
- -h- getword.arc 407
- { getword -- get word from s[i] into out }
- function getword (var s : string; i : integer;
- var out : string) : integer;
- var
- j : integer;
- begin
- while (s[i] in [BLANK, TAB, NEWLINE]) do
- i := i + 1;
- j := 1;
- while (not (s[i] in [ENDSTR,BLANK,TAB,NEWLINE])) do begin
- out[j] := s[i];
- i := i + 1;
- j := j + 1
- end;
- out[j] := ENDSTR;
- if (s[i] = ENDSTR) then
- getword := 0
- else
- getword := i
- end;
-
- -h- help.arc 124
- { help -- print diagnostic for archive }
- procedure help;
- begin
- error('usage: archive -[cdptux] archname [files...]')
- end;
-
- -h- initarch.arc 438
- { initarch -- initialize variables for archive }
- procedure initarch;
- begin
- { setstring(archtemp, 'artemp'); }
- archtemp[1] := ord('a');
- archtemp[2] := ord('r');
- archtemp[3] := ord('t');
- archtemp[4] := ord('e');
- archtemp[5] := ord('m');
- archtemp[6] := ord('p');
- archtemp[7] := ENDSTR;
- { setstring(archhdr, '-h-'); }
- archhdr[1] := ord('-');
- archhdr[2] := ord('h');
- archhdr[3] := ord('-');
- archhdr[4] := ENDSTR;
- end;
-
- -h- makehdr.arc 417
- { makehdr -- make header line for archive member }
- procedure makehdr (var name, head : string);
- var
- i,j : integer;
- {$include:'fsize.arc'}
- begin
- scopy(archhdr, 1, head, 1);
- i := length(head) + 1;
- head[i] := BLANK;
- j := 1;
- if (name[2] = COLON) then j := 3;
- scopy(name, j, head, i+1);
- i := length(head) + 1;
- head[i] := BLANK;
- i := itoc(fsize(name), head, i+1);
- head[i] := NEWLINE;
- head[i+1] := ENDSTR
- end;
-
-
- -h- notfound.arc 247
- { notfound -- print "not found" warning }
- procedure notfound;
- var
- i : integer;
- begin
- for i := 1 to nfiles do
- if (fstat[i] = false) then begin
- putstr(fname[i], STDERR);
- message(': not in archive');
- errcount := errcount + 1
- end
- end;
-
- -h- replace.arc 415
- { replace -- replace or delete files }
- procedure replace (afd, tfd : filedesc; cmd : integer);
- var
- inline, uname : string;
- size : integer;
- begin
- while (gethdr(afd, inline, uname, size)) do
- if (filearg(uname)) then begin
- if (cmd = ord('u')) then { add new one }
- addfile(uname, tfd);
- fskip(afd, size) { discard old one }
- end
- else begin
- putstr(inline, tfd);
- acopy(afd, tfd, size)
- end
- end;
-
- -h- table.arc 338
- { table -- print table of archive contents }
- procedure table (var aname : string);
- var
- head, name : string;
- size : integer;
- afd : filedesc;
- {$include:'tprint.arc'}
- begin
- afd := mustopen(aname, IOREAD);
- while (gethdr(afd, head, name, size)) do begin
- if (filearg(name)) then
- tprint(head);
- fskip(afd, size)
- end;
- notfound
- end;
-
- -h- tprint.arc 445
- { tprint -- print table entry for one member }
- procedure tprint (var buf : string);
- var
- i,j : integer;
- temp : string;
- begin
- i := getword(buf, 1, temp); { header }
- i := getword(buf, i, temp); { name }
- putstr(temp, STDOUT);
- for j := 1 to (MAXFN-length(temp)) do putc(BLANK); {trailing blanks}
- i := getword(buf, i, temp); { size }
- for j := 1 to (6-length(temp)) do putc(BLANK); {leading blanks}
- putstr(temp, STDOUT);
- putc(NEWLINE)
- end;
-
- -h- update.arc 608
- { update -- update existing files, add new ones at end }
- procedure update (var aname : string; cmd : character);
- var
- i : integer;
- afd, tfd : filedesc;
- begin
- tfd := mustcreate(archtemp, IOWRITE);
- if (cmd = ord('u')) then begin
- afd := mustopen(aname, IOREAD);
- replace(afd, tfd, ord('u')); { update existing }
- xclose(afd)
- end;
- for i := 1 to nfiles do { add new ones }
- if (fstat[i] = false) then begin
- addfile(fname[i], tfd);
- fstat[i] := true
- end;
- xclose(tfd);
- if (errcount = 0) then
- fmove(archtemp, aname)
- else
- message('fatal errors - archive not altered');
- remove(archtemp)
- end;
- -h- archive.pas 769
- {$debug-}
- program outer (input,output);
-
- {$include:'globcons.inc'}
- {$include:'globtyps.inc'}
-
- {$include:'initio.dcl'}
- {$include:'flush.dcl' }
-
- {$include:'getline.dcl' }
- {$include:'equal.dcl' }
- {$include:'error.dcl' }
- {$include:'message.dcl' }
- {$include:'ctoi.dcl' }
- {$include:'itoc.dcl' }
- {$include:'getcf.dcl' }
- {$include:'putc.dcl' }
- {$include:'putcf.dcl' }
- {$include:'putstr.dcl' }
- {$include:'create.dcl' }
- {$include:'mustopen.dcl'}
- {$include:'mustcrea.dcl'}
- {$include:'fcopy.dcl' }
- {$include:'length.dcl' }
- {$include:'open.dcl' }
- {$include:'close.dcl' }
- {$include:'nargs.dcl' }
- {$include:'getarg.dcl' }
- {$include:'scopy.dcl' }
- {$include:'remove.dcl' }
-
- {$include:'archive.arc' }
- BEGIN
- minitio; initio;
- archive;
- flush(0);
- END.
- -h- archive.mak 181
- archive+initio+getfcb+flush+error+getarg+nargs+length+
- getline+equal+ctoi+itoc+getcf+putc+putcf+putstr+fcopy+
- mustopen+mustcrea+create+message+close+getc+isdigit+
- scopy+remove+open