diff -r 820027561946 usr/src/cmd/vi/port/exrecover.c --- a/usr/src/cmd/vi/port/exrecover.c Thu Sep 13 14:00:55 2007 -0400 +++ b/usr/src/cmd/vi/port/exrecover.c Mon Sep 24 21:05:25 2007 -0500 @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,9 +19,9 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. -*/ + */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ @@ -47,7 +46,7 @@ #include #include -#define DIRSIZ MAXNAMLEN +#define DIRSIZ MAXNAMLEN short tfile = -1; /* ditto */ @@ -100,11 +99,11 @@ main(int argc, char *argv[]) struct passwd *pp = getpwuid(getuid()); unsigned char rmcmd[PATH_MAX+1]; - (void)setlocale(LC_ALL, ""); + (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) -#define TEXT_DOMAIN "SYS_TEST" -#endif - (void)textdomain(TEXT_DOMAIN); +#define TEXT_DOMAIN "SYS_TEST" +#endif + (void) textdomain(TEXT_DOMAIN); cp = string; strcpy(mydir, USRPRESERVE); if (pp == NULL) { @@ -122,12 +121,12 @@ main(int argc, char *argv[]) endcore = fendcore - 2; iblock = oblock = -1; - while ((c=getopt(argc, (char **)argv, "rx")) != EOF) + while ((c = getopt(argc, (char **)argv, "rx")) != EOF) switch (c) { case 'r': rflg++; break; - + case 'x': xflag++; break; @@ -138,22 +137,22 @@ main(int argc, char *argv[]) } argc -= optind; argv = &argv[optind]; - - if (errflg) + + if (errflg) exit(2); - + /* * If given only a -r argument, then list the saved files. * (NOTE: single -r argument is scheduled to be replaced by -L). */ if (rflg && argc == 0) { - fprintf(stderr,"%s:\n", mydir); + fprintf(stderr, "%s:\n", mydir); listfiles(mydir); - fprintf(stderr,"%s:\n", TMPDIR); + fprintf(stderr, "%s:\n", TMPDIR); listfiles((unsigned char *)TMPDIR); exit(0); } - + if (argc != 2) error(gettext(" Wrong number of arguments to exrecover"), 0); @@ -167,40 +166,47 @@ main(int argc, char *argv[]) /* * Got (one of the versions of) it, write it back to the editor. */ - (void)cftime((char *)cp, "%a %h %d %T", &H.Time); + (void) cftime((char *)cp, "%a %h %d %T", &H.Time); fprintf(stderr, vercnt > 1 ? - gettext(" [Dated: %s, newest of %d saved]") : - gettext(" [Dated: %s]"), cp, vercnt); + gettext(" [Dated: %s, newest of %d saved]") : + gettext(" [Dated: %s]"), cp, vercnt); fprintf(stderr, "\r\n"); - - if(H.encrypted) { - if(xflag) { - kflag = run_setkey(perm, (unsigned char *)getenv("CrYpTkEy")); - } else + + if (H.encrypted) { + if (xflag) { + kflag = run_setkey(perm, + (unsigned char *)getenv("CrYpTkEy")); + } else { kflag = run_setkey(perm, mypass("Enter key:")); - if(kflag == -1) { + } + + if (kflag == -1) { kflag = 0; xflag = 0; - fprintf(stderr,gettext("Encryption facility not available\n")); + fprintf(stderr, + gettext("Encryption facility not available\n")); exit(-1); } - xtflag = 1; - if (makekey(tperm) != 0) { + + xtflag = 1; + if (makekey(tperm) != 0) { xtflag = 0; - fprintf(stderr,gettext("Warning--Cannot encrypt temporary buffer\n")); + fprintf(stderr, gettext("Warning--Cannot encrypt" \ + " temporary buffer\n")); exit(-1); - } - } - fprintf(stderr,gettext("\r\n [Hit return to continue]")); + } + } + fprintf(stderr, gettext("\r\n [Hit return to continue]")); fflush(stderr); setbuf(stdin, (char *)NULL); - while((c = getchar()) != '\n' && c != '\r'); + while ((c = getchar()) != '\n' && c != '\r') + ; H.Flines++; /* * Allocate space for the line pointers from the temp file. */ - if ((int) sbrk((int) (H.Flines * sizeof (line))) == -1) + if ((int)sbrk((int)(H.Flines * sizeof (line))) == -1) error(gettext(" Not enough core for lines"), 0); #ifdef DEBUG fprintf(stderr, "%d lines\n", H.Flines); @@ -213,10 +219,10 @@ main(int argc, char *argv[]) */ b = 0; while (H.Flines > 0) { - (void)lseek(tfile, (long) blocks[b] * BUFSIZE, 0); + (void) lseek(tfile, (long)blocks[b] * BUFSIZE, 0); i = H.Flines < BUFSIZE / sizeof (line) ? - H.Flines * sizeof (line) : BUFSIZE; - if (read(tfile, (char *) dot, i) != i) { + H.Flines * sizeof (line) : BUFSIZE; + if (read(tfile, (char *)dot, i) != i) { perror((char *)nb); exit(1); } @@ -254,7 +260,7 @@ main(int argc, char *argv[]) * ever edits with temporaries in "." anyways. */ if (nb[0] == '/') { - (void)unlink((const char *)nb); + (void) unlink((const char *)nb); sprintf((char *)rmcmd, "rmdir %s 2> /dev/null", (char *)mydir); system((char *)rmcmd); } @@ -279,7 +285,7 @@ error(str, inf) fprintf(stderr, (char *)str, inf); else fprintf(stderr, (char *)str); - + ioctl(2, TCGETA, &termio); if (termio.c_lflag & ICANON) fprintf(stderr, "\n"); @@ -316,9 +322,8 @@ listfiles(unsigned char *dirname) /* * Open usrpath(preserve), and go there to make things quick. */ - if ((dir = opendir((char *)dirname)) == NULL) - { - fprintf(stderr,gettext("No files saved.\n")); + if ((dir = opendir((char *)dirname)) == NULL) { + fprintf(stderr, gettext("No files saved.\n")); return; } if (chdir((const char *)dirname) < 0) { @@ -331,8 +336,7 @@ listfiles(unsigned char *dirname) */ fp = &svbuf[0]; ecount = 0; - while ((direntry = readdir64(dir)) != NULL) - { + while ((direntry = readdir64(dir)) != NULL) { filname = (unsigned char *)direntry->d_name; if (filname[0] != 'E') continue; @@ -352,31 +356,38 @@ listfiles(unsigned char *dirname) #endif continue; } - if (read(f, (char *) &H, sizeof H) != sizeof H) { + if (read(f, (char *)&H, sizeof (H)) != sizeof (H)) { #ifdef DEBUG fprintf(stderr, "could not read header\n"); #endif - (void)close(f); + (void) close(f); continue; } - (void)close(f); + (void) close(f); if (getuid() != H.Uid) { #ifdef DEBUG fprintf(stderr, "uid wrong\n"); #endif continue; } + + /* + * Store the new entry in the next available space until we run + * out of space. When we run out of space, we just pass the last + * space to enter and let it replace the oldest one instead. + */ + if (ecount + 1 < NENTRY) + ++fp; /* * Saved the day! */ - enter(fp++, filname, ecount); - ecount++; + enter(fp, filname, ecount++); #ifdef DEBUG fprintf(stderr, "entered file %s\n", filname); #endif } - (void)closedir(dir); + (void) closedir(dir); /* * If any files were saved, then sort them and print * them out. @@ -384,11 +395,14 @@ listfiles(unsigned char *dirname) if (ecount == 0) { fprintf(stderr, gettext("No files saved.\n")); return; - } - qsort(&svbuf[0], ecount, sizeof svbuf[0], qucmp); + } else if (ecount >= NENTRY) { + ecount = NENTRY; + } + + qsort(&svbuf[0], ecount, sizeof (svbuf[0]), qucmp); for (fp = &svbuf[0]; fp < &svbuf[ecount]; fp++) { - (void)cftime((char *)cp, "%a %b %d", &fp->sf_time); - (void)cftime((char *)cp2, "%R", &fp->sf_time); + (void) cftime((char *)cp, "%a %b %d", &fp->sf_time); + (void) cftime((char *)cp2, "%R", &fp->sf_time); fprintf(stderr, gettext("On %s at %s, saved %d lines of file \"%s\" "), cp, cp2, fp->sf_lines, fp->sf_name); @@ -404,23 +418,33 @@ enter(struct svfile *fp, unsigned char * enter(struct svfile *fp, unsigned char *fname, int count) { unsigned char *cp, *cp2; - struct svfile *f, *fl; + struct svfile *f, *fn; time_t curtime; f = 0; + + /* + * Have we run out of space? + */ if (count >= NENTRY) { - /* + /* + * Assume that we're going to use the first space unless we find + * a better one. + */ + fn = fp - (NENTRY - 1); + + /* * Trash the oldest as the most useless. */ - fl = fp - count + NENTRY - 1; - curtime = fl->sf_time; - for (f = fl; --f > fp-count; ) - if (f->sf_time < curtime) + curtime = fp->sf_time; + for (f = fp; f > fp - (NENTRY - 1); --f) { + if (f->sf_time < curtime) { curtime = f->sf_time; - for (f = fl; --f > fp-count; ) - if (f->sf_time == curtime) - break; - fp = f; + fn = f; + } + } + + fp = fn; } /* @@ -429,10 +453,10 @@ enter(struct svfile *fp, unsigned char * fp->sf_time = H.Time; fp->sf_lines = H.Flines; fp->sf_encrypted = H.encrypted; - for (cp2 = fp->sf_name, cp = savedfile; *cp;) + for (cp2 = fp->sf_name, cp = savedfile; *cp; ) *cp2++ = *cp++; *cp2++ = 0; - for (cp2 = fp->sf_entry, cp = fname; *cp && cp-fname < 14;) + for (cp2 = fp->sf_entry, cp = fname; *cp && cp-fname < 14; ) *cp2++ = *cp++; *cp2++ = 0; } @@ -447,10 +471,10 @@ qucmp(struct svfile *p1, struct svfile * int t; if (t = strcmp(p1->sf_name, p2->sf_name)) - return(t); + return (t); if (p1->sf_time > p2->sf_time) - return(-1); - return(p1->sf_time < p2->sf_time); + return (-1); + return (p1->sf_time < p2->sf_time); } /* @@ -491,13 +515,13 @@ findtmp(unsigned char *dir) */ tfile = bestfd; CP(nb, bestnb); - (void)lseek(tfile, 0l, 0); + (void) lseek(tfile, 0l, 0); /* * Gotta be able to read the header or fall through * to lossage. */ - if (read(tfile, (char *) &H, sizeof H) == sizeof H) + if (read(tfile, (char *)&H, sizeof (H)) == sizeof (H)) return; } @@ -525,10 +549,9 @@ searchdir(unsigned char *dirname) DIR *dir; unsigned char dbuf[BUFSIZE]; unsigned char *filname; - if ((dir = opendir((char *)dirname)) == NULL) + if ((dir = opendir((char *)dirname)) == NULL) return; - while ((direntry = readdir64(dir)) != NULL) - { + while ((direntry = readdir64(dir)) != NULL) { filname = (unsigned char *)direntry->d_name; if (filname[0] != 'E' || filname[1] != 'x') continue; @@ -538,7 +561,7 @@ searchdir(unsigned char *dirname) * later, and check that this is really a file * we are looking for. */ - (void)strcat(strcat(strcpy(nb, dirname), "/"), filname); + (void) strcat(strcat(strcpy(nb, dirname), "/"), filname); if (yeah(nb)) { /* * Well, it is the file we are looking for. @@ -548,7 +571,7 @@ searchdir(unsigned char *dirname) /* * A winner. */ - (void)close(bestfd); + (void) close(bestfd); bestfd = dup(tfile); besttime = H.Time; CP(bestnb, nb); @@ -558,9 +581,9 @@ searchdir(unsigned char *dirname) */ vercnt++; } - (void)close(tfile); - } - (void)closedir(dir); + (void) close(tfile); + } + (void) closedir(dir); } /* @@ -575,9 +598,9 @@ yeah(unsigned char *name) tfile = open(name, 2); if (tfile < 0) return (0); - if (read(tfile, (char *) &H, sizeof H) != sizeof H) { + if (read(tfile, (char *)&H, sizeof (H)) != sizeof (H)) { nope: - (void)close(tfile); + (void) close(tfile); return (0); } if (!eq(savedfile, file)) @@ -588,8 +611,8 @@ nope: * Old code: puts a word LOST in the header block, so that lost lines * can be made to point at it. */ - (void)lseek(tfile, (long)(BUFSIZE*HBLKS-8), 0); - (void)write(tfile, "LOST", 5); + (void) lseek(tfile, (long)(BUFSIZE*HBLKS-8), 0); + (void) write(tfile, "LOST", 5); return (1); } @@ -616,7 +639,7 @@ scrapbad(void) int bno, cnt, bad, was; unsigned char bk[BUFSIZE]; - (void)fstat64(tfile, &stbuf); + (void) fstat64(tfile, &stbuf); size = (off_t)stbuf.st_size; maxt = (size >> SHFT) | (BNDRY-1); bno = (maxt >> OFFBTS) & BLKMSK; @@ -630,13 +653,13 @@ scrapbad(void) * if the last block is. */ while (bno > 0) { - (void)lseek(tfile, (long) BUFSIZE * bno, 0); - cnt = read(tfile, (char *) bk, BUFSIZE); - if(xtflag) + (void) lseek(tfile, (long)BUFSIZE * bno, 0); + cnt = read(tfile, (char *)bk, BUFSIZE); + if (xtflag) if (run_crypt(0L, bk, CRSIZE, tperm) == -1) - rsyserror(); -#ifdef DEBUG - fprintf(stderr,"UNENCRYPTED: BLK %d\n",bno); + rsyserror(); +#ifdef DEBUG + fprintf(stderr, "UNENCRYPTED: BLK %d\n", bno); #endif while (cnt > 0) if (bk[--cnt] == 0) @@ -662,7 +685,8 @@ null: for (ip = one; ip <= dol; ip++) if (*ip > maxt) { #ifdef DEBUG - fprintf(stderr, "%d bad, %o > %o\n", ip - zero, *ip, maxt); + fprintf(stderr, "%d bad, %o > %o\n", ip - zero, *ip, + maxt); #endif if (was == 0) was = ip - zero; @@ -708,12 +732,12 @@ rputfile(void) fp = genbuf; do { #ifdef DEBUG - fprintf(stderr,"GETTING A LINE \n"); + fprintf(stderr, "GETTING A LINE \n"); #endif getline(*a1++); lp = linebuf; #ifdef DEBUG - fprintf(stderr,"LINE:%s\n",linebuf); + fprintf(stderr, "LINE:%s\n", linebuf); #endif for (;;) { if (--nib < 0) { @@ -782,26 +806,26 @@ getblock(atl) line atl; { int bno, off; - unsigned char *p1, *p2; - int n; - + unsigned char *p1, *p2; + int n; + bno = (atl >> OFFBTS) & BLKMSK; #ifdef DEBUG - fprintf(stderr,"GETBLOCK: BLK %d\n",bno); + fprintf(stderr, "GETBLOCK: BLK %d\n", bno); #endif off = (atl << SHFT) & LBTMSK; if (bno >= NMBLKS) error((unsigned char *)gettext(" Tmp file too large")); nleft = BUFSIZE - off; - if (bno == iblock) + if (bno == iblock) return (ibuff + off); iblock = bno; blkio(bno, ibuff, read); - if(xtflag) + if (xtflag) if (run_crypt(0L, ibuff, CRSIZE, tperm) == -1) rsyserror(); #ifdef DEBUG - fprintf(stderr,"UNENCRYPTED: BLK %d\n",bno); + fprintf(stderr, "UNENCRYPTED: BLK %d\n", bno); #endif return (ibuff + off); } @@ -811,9 +835,11 @@ blkio(short b, unsigned char *buf, int ( { int rc; - lseek(tfile, (long) (unsigned) b * BUFSIZE, 0); - if ((rc =(*iofcn)(tfile, buf, BUFSIZE)) != BUFSIZE) { - (void)fprintf(stderr,gettext("Failed on BLK: %d with %d/%d\n"),b,rc,BUFSIZE); + lseek(tfile, (long)(unsigned)b * BUFSIZE, 0); + if ((rc = (*iofcn)(tfile, buf, BUFSIZE)) != BUFSIZE) { + (void) fprintf(stderr, + gettext("Failed on BLK: %d with %d/%d\n"), b, rc, + BUFSIZE); perror(""); rsyserror(); } @@ -841,10 +867,10 @@ unsigned char *prompt; unsigned char *p; int c; static unsigned char pbuf[9]; - void (*sig)(); + void (*sig)(); static void catch(); - setbuf(stdin, (char*)NULL); + setbuf(stdin, (char *)NULL); sig = signal(SIGINT, catch); intrupt = 0; (void) ioctl(fileno(stdin), TCGETA, &ttyb); @@ -852,8 +878,9 @@ unsigned char *prompt; ttyb.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); (void) ioctl(fileno(stdin), TCSETAF, &ttyb); (void) fputs((char *)prompt, stderr); - for(p=pbuf; !intrupt && (c = getc(stdin)) != '\n' && c!= '\r' && c != EOF; ) { - if(p < &pbuf[8]) + for (p = pbuf; !intrupt && (c = getc(stdin)) != '\n' && c != '\r' && + c != EOF; ) { + if (p < &pbuf[8]) *p++ = c; } *p = '\0'; @@ -861,9 +888,9 @@ unsigned char *prompt; ttyb.c_lflag = flags; (void) ioctl(fileno(stdin), TCSETA, &ttyb); (void) signal(SIGINT, sig); - if(intrupt) + if (intrupt) (void) kill(getpid(), SIGINT); - return(pbuf); + return (pbuf); } static void diff -r 820027561946 usr/src/tools/scripts/cstyle.pl --- a/usr/src/tools/scripts/cstyle.pl Thu Sep 13 14:00:55 2007 -0400 +++ b/usr/src/tools/scripts/cstyle.pl Mon Sep 24 22:46:07 2007 -0500 @@ -597,7 +597,10 @@ line: while (<$filehandle>) { err("whitespace after left paren"); } # allow "for" statements to have empty "continue" clauses - if (/\s\)/ && !/^\s*for \([^;]*;[^;]*; \)/) { + if (/\s\)/ && !/^\s*for \([^;]*;[^;]*; \)/ && + !($prev =~ /^\s*for \([^;]*;/ && + (($prev =~ tr/\(//) != ($prev =~ tr/\)//)) && + /; \)/)) { err("whitespace before right paren"); } if (/^\s*\(void\)[^ ]/) {