home *** CD-ROM | disk | FTP | other *** search
- static int movealias(first, p, pprintaliased)
- REP *first, *p;
- int *pprintaliased;
- {
- char *fstart;
- int ret;
-
- strcpy(pathbuf, p->r_hto->h_name);
- fstart = pathbuf + strlen(pathbuf);
- strcpy(fstart, TEMP);
- for (
- ret = 0;
- sprintf(fstart + STRLEN(TEMP), "%03d", ret),
- fsearch(fstart, p->r_hto->h_di) != NULL;
- ret++
- )
- ;
- if (rename(fullrep, pathbuf)) {
- fprintf(stderr,
- "%s -> %s has failed.\n", fullrep, pathbuf);
- *pprintaliased = snap(first, p);
- }
- return(ret);
- }
-
-
- static int snap(first, p)
- REP *first, *p;
- {
- char fname[80];
- int redirected = 0;
-
- if (noex)
- exit(1);
-
- failed = 1;
- #ifdef MSDOS
- ctrlbrk((int (*)())breakstat);
- #else
- signal(SIGINT, breakstat);
- #endif
- if (
- badstyle == ASKBAD &&
- isatty(fileno(stdout)) &&
- getreply("Redirect standard output to file? ", 0)
- ) {
- redirected = 1;
- #ifndef MSDOS
- umask(oldumask);
- #endif
- while (
- fprintf(stderr, "File name> "),
- (outfile = fopen(gets(fname), "w")) == NULL
- )
- fprintf(stderr, "Can't open %s.\n", fname);
- }
- if (redirected || !verbose)
- showdone(p);
- fprintf(outfile, "The following left undone:\n");
- noex = 1;
- return(first != p);
- }
-
-
- static void showdone(fin)
- REP *fin;
- {
- REP *first, *p;
-
- for (first = hrep.r_next; ; first = first->r_next)
- for (p = first; p != NULL; p = p->r_thendo) {
- if (p == fin)
- return;
- fprintf(outfile, "%s%s %c%c %s%s : done%s\n",
- p->r_hfrom->h_name, p->r_ffrom->fi_name,
- p->r_flags & R_ISALIASED ? '=' : '-',
- p->r_flags & R_ISCYCLE ? '^' : '>',
- p->r_hto->h_name, p->r_nto,
- (p->r_fdel != NULL && !(op & APPEND)) ? " (*)" : "");
- }
- }
-
-
- static void breakout()
- {
- fflush(stdout);
- fprintf(stderr, "Aborting, nothing done.\n");
- exit(1);
- }
-
-
- static int breakrep()
- {
- gotsig = 1;
- return(1);
- }
-
-
- static void breakstat()
- {
- exit(1);
- }
-
-
- static void quit()
- {
- fprintf(stderr, "Aborting, nothing done.\n");
- exit(1);
- }
-
-
- static int copymove(p)
- REP *p;
- {
- #ifndef MSDOS
- #ifndef SYSV
- {
- int llen;
- char linkbuf[MAXPATH];
-
- if ((llen = readlink(pathbuf, linkbuf, MAXPATH - 1)) != 1) {
- linkbuf[llen] = '\0';
- return(symlink(linkbuf, fullrep) || myunlink(pathbuf, p->r_ffrom));
- }
- }
- #endif
- #endif
- return(copy(p->r_ffrom, -1) || myunlink(pathbuf, p->r_ffrom));
- }
-
-
-
- #define IRWMASK (S_IREAD | S_IWRITE)
- #define RWMASK (IRWMASK | (IRWMASK >> 3) | (IRWMASK >> 6))
-
- static int copy(ff, len)
- FILEINFO *ff;
- long len;
- {
- char buf[BUFSIZE], c;
- int f, t, k, mode, perm;
- #ifdef MSDOS
- struct ftime tim;
- #else
- #ifdef SYSV
- struct utimbuf tim;
- #else
- struct timeval tim[2];
- #endif
- struct stat fstat;
- #endif
-
- if ((f = open(pathbuf, O_RDONLY | O_BINARY, 0)) < 0)
- return(-1);
- perm =
- #ifdef MSDOS
- IRWMASK /* will _chmod it later (to get all the attributes) */
- #else
- (op & (APPEND | OVERWRITE)) ?
- (~oldumask & RWMASK) | (ff->fi_mode & ~RWMASK) :
- ff->fi_mode
- #endif
- ;
- mode = O_CREAT |
- #ifdef MSDOS
- O_BINARY | (op & ZAPPEND ? O_RDWR : O_WRONLY)
- #else
- O_WRONLY
- #endif
- ;
- if (!(op & APPEND))
- mode |= O_TRUNC;
- if ((t = open(fullrep, mode, perm)) < 0) {
- close(f);
- return(-1);
- }
- if (op & APPEND)
- lseek(t, 0, 2);
- #ifdef MSDOS
- if (op & ZAPPEND && filelength(t) != 0) {
- if (lseek(t, -1, 1) == -1L || read(t, &c, 1) != 1) {
- close(f);
- close(t);
- return(-1);
- }
- if (c == 26)
- lseek(t, -1, 1);
- }
- #endif
- if ((op & APPEND) && len != -1L) {
- while (
- len != 0 &&
- (k = read(f, buf, len > BUFSIZE ? BUFSIZE : (unsigned)len)) > 0 &&
- write(t, buf, k) == k
- )
- len -= k;
- if (len == 0)
- k = 0;
- }
- else
- while ((k = read(f, buf, BUFSIZE)) > 0 && write(t, buf, k) == k)
- ;
- if (!(op & (APPEND | OVERWRITE)))
- if (
- #ifdef MSDOS
- getftime(f, &tim) ||
- setftime(t, &tim) ||
- _chmod(fullrep, 1, ff->fi_attrib) == -1
- #else
- stat(pathbuf, &fstat) ||
- (
- #ifdef SYSV
- tim.actime = fstat.st_atime,
- tim.modtime = fstat.st_mtime,
- #else
- tim[0].tv_sec = fstat.st_atime,
- tim[1].tv_sec = fstat.st_mtime,
- #endif
- utimes(fullrep, tim)
- )
- #endif
- )
- fprintf(stderr, "Strange, couldn't transfer time from %s to %s.\n",
- pathbuf, fullrep);
-
- close(f);
- close(t);
- if (k != 0) {
- if (!(op & APPEND))
- unlink(fullrep);
- return(-1);
- }
- return(0);
- }
-
-
- #ifndef RENAME
- static int rename(from, to)
- char *from, *to;
- {
- if (link(from, to))
- return(-1);
- if (unlink(from)) {
- unlink(to);
- return(-1);
- }
- return(0);
- }
- #endif
-
-
- static int myunlink(n, f)
- char *n;
- FILEINFO *f;
- {
- #ifdef MSDOS
- int a;
-
- if (((a = f->fi_attrib) & FA_RDONLY) && _chmod(n, 1, a & ~FA_RDONLY) < 0) {
- fprintf(stderr, "Strange, can not _chmod (or unlink) %s.\n", f);
- return(-1);
- }
- #endif
- if (unlink(n)) {
- fprintf(stderr, "Strange, can not unlink %s.\n", n);
- return(-1);
- }
- return(0);
- }
-
-
- static int getreply(m, failact)
- char *m;
- int failact;
- {
- static FILE *tty = NULL;
- int c, r;
-
- fprintf(stderr, m);
- if (tty == NULL && (tty = fopen(TTY, "r")) == NULL) {
- fprintf(stderr, "Can not open %s to get reply.\n", TTY);
- if (failact == -1)
- quit();
- else
- return(failact);
- }
- for (;;) {
- r = fgetc(tty);
- if (r == EOF) {
- fprintf(stderr, "Can not get reply.\n");
- if (failact == -1)
- quit();
- else
- return(failact);
- }
- if (r != '\n')
- while ((c = fgetc(tty)) != '\n' && c != EOF)
- ;
- r = mylower(r);
- if (r == 'y' || r == 'n')
- return(r == 'y');
- fprintf(stderr, "Yes or No? ");
- }
- }
-
-
- static void *myalloc(k)
- unsigned k;
- {
- void *ret;
-
- if (k == 0)
- return(NULL);
- if ((ret = (void *)malloc(k)) == NULL) {
- fprintf(stderr, "Insufficient memory.\n");
- quit();
- }
- return(ret);
- }
-
-
- static void *challoc(k, which)
- int which;
- int k;
- {
- void *ret;
- CHUNK *p, *q;
- SLICER *sl = &(slicer[which]);
-
- if (k > sl->sl_len) {
- for (
- q = NULL, p = freechunks;
- p != NULL && (sl->sl_len = p->ch_len) < k;
- q = p, p = p->ch_next
- )
- ;
- if (p == NULL) {
- sl->sl_len = CHUNKSIZE - sizeof(CHUNK *);
- p = (CHUNK *)myalloc(CHUNKSIZE);
- }
- else if (q == NULL)
- freechunks = p->ch_next;
- else
- q->ch_next = p->ch_next;
- p->ch_next = sl->sl_first;
- sl->sl_first = p;
- sl->sl_unused = (char *)&(p->ch_len);
- }
- sl->sl_len -= k;
- ret = (void *)sl->sl_unused;
- sl->sl_unused += k;
- return(ret);
- }
-
-
- static void chgive(p, k)
- void *p;
- unsigned k;
- {
- ((CHUNK *)p)->ch_len = k - sizeof(CHUNK *);
- ((CHUNK *)p)->ch_next = freechunks;
- freechunks = (CHUNK *)p;
- }
-
-
- #ifndef MSDOS
- static void memmove(to, from, k)
- char *to, *from;
- unsigned k;
- {
- if (from > to)
- while (k-- != 0)
- *(to++) = *(from++);
- else {
- from += k;
- to += k;
- while (k-- != 0)
- *(--to) = *(--from);
- }
- }
- #endif
-
-
- static int mygetc()
- {
- static int lastc = 0;
-
- if (lastc == EOF)
- return(EOF);
- return(lastc = getchar());
- }
-
-
- #ifdef MSDOS
- static int leave()
- {
- return(0);
- }
-
- static void cleanup()
- {
- int i;
-
- if (patch.ph_safeid) {
- for (i = 0; i < nhandles; i++) {
- if (!(handles[i]->h_di->di_flags & DI_CLEANED)) {
- sprintf(pathbuf, "%s%s%03d",
- handles[i]->h_name, IDF, handles[i]->h_di->di_did);
- if (unlink(pathbuf))
- fprintf(stderr, "Strange, couldn't unlink %s.\n", pathbuf);
- handles[i]->h_di->di_flags |= DI_CLEANED;
- }
- }
- }
- /*
- Write device availability: undocumented internal MS-D*S function.
- Restore previous value.
- */
- bdos(0x37, olddevflag, 3);
- }
-
- #endif
-