head 2.6; access; symbols; locks; strict; comment @ * @; 2.6 date 93.08.25.17.24.39; author jromine; state Exp; branches; next 2.5; 2.5 date 92.12.15.00.20.22; author jromine; state Exp; branches; next 2.4; 2.4 date 90.04.05.15.35.09; author sources; state Exp; branches; next 2.3; 2.3 date 90.04.05.14.54.53; author sources; state Exp; branches; next 2.2; 2.2 date 90.03.27.12.51.49; author sources; state Exp; branches; next 2.1; 2.1 date 90.02.06.13.15.57; author sources; state Exp; branches; next 2.0; 2.0 date 89.11.17.15.57.50; author sources; state Exp; branches; next 1.2; 1.2 date 88.06.30.08.28.41; author sources; state Exp; branches; next 1.1; 1.1 date 88.06.30.08.27.15; author sources; state Exp; branches; next ; desc @Original with no mods. @ 2.6 log @off_t fixes for BSD44 @ text @/* annosbr.c - prepend annotation to messages */ #ifndef lint static char ident[] = "@@(#)$Id: annosbr.c,v 2.5 1992/12/15 00:20:22 jromine Exp jromine $"; #endif /* lint */ #include "../h/mh.h" #include "../zotnet/tws.h" #include #include #include #include extern int errno; off_t lseek (); static annosbr(); /* */ annotate (file, comp, text, inplace, datesw) register char *file, *comp, *text; int inplace, datesw; { int i, fd; if ((fd = lkopen (file, 2)) == NOTOK) { switch (errno) { case ENOENT: break; default: admonish (file, "unable to lock and open"); break; } return 1; } i = annosbr (fd, file, comp, text, inplace, datesw); (void) lkclose (fd, file); return i; } /* */ static annosbr (src, file, comp, text, inplace, datesw) register char *file, *comp, *text; int src, inplace, datesw; { int mode, fd; register char *cp, *sp; char buffer[BUFSIZ], tmpfil[BUFSIZ]; struct stat st; register FILE *tmp; mode = fstat (src, &st) != NOTOK ? (st.st_mode & 0777) : m_gmprot (); (void) strcpy (tmpfil, m_scratch (file, "annotate")); if ((tmp = fopen (tmpfil, "w")) == NULL) { admonish (tmpfil, "unable to create"); return 1; } (void) chmod (tmpfil, mode); if (datesw) fprintf (tmp, "%s: %s\n", comp, dtimenow ()); if (cp = text) { do { while (*cp == ' ' || *cp == '\t') cp++; sp = cp; while (*cp && *cp++ != '\n') continue; if (cp - sp) fprintf (tmp, "%s: %*.*s", comp, cp - sp, cp - sp, sp); } while (*cp); if (cp[-1] != '\n' && cp != text) (void) putc ('\n', tmp); } (void) fflush (tmp); cpydata (src, fileno (tmp), file, tmpfil); (void) fclose (tmp); if (inplace) { if ((fd = open (tmpfil, 0)) == NOTOK) adios (tmpfil, "unable to open for re-reading"); (void) lseek (src, (off_t)0, 0); cpydata (fd, src, tmpfil, file); (void) close (fd); (void) unlink (tmpfil); } else { (void) strcpy (buffer, m_backup (file)); if (rename (file, buffer) == NOTOK) { switch (errno) { case ENOENT: /* unlinked early - no annotations */ (void) unlink (tmpfil); break; default: admonish (buffer, "unable to rename %s to", file); break; } return 1; } if (rename (tmpfil, file) == NOTOK) { admonish (file, "unable to rename %s to", tmpfil); return 1; } } return 0; } @ 2.5 log @endif sugar @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: annosbr.c,v 2.4 1990/04/05 15:35:09 sources Exp jromine $"; d15 1 a15 1 long lseek (); d100 1 a100 1 (void) lseek (src, 0L, 0); @ 2.4 log @add ID @ text @d3 2 a4 2 static char ident[] = "@@(#)$Id:$"; #endif lint @ 2.3 log @add ID @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id:"; @ 2.2 log @race condition. don't complain if target file is unlinked before annotations finish. @ text @d2 3 @ 2.1 log @ANSI Compilance @ text @d105 9 a113 1 admonish (buffer, "unable to rename %s to", file); @ 2.0 log @changes for SUN40 shared libraries and NNTP under bbc @ text @d13 1 @ 1.2 log @Added the code for fanno. Gary @ text @a11 4 #ifdef UCI int fanno = 0; #endif UCI d16 1 a16 1 annotate (file, comp, text, inplace) d20 2 a21 1 int inplace; d38 1 a38 1 i = annosbr (fd, file, comp, text, inplace); d47 1 a47 1 static annosbr (src, file, comp, text, inplace) d52 2 a53 1 inplace; d74 2 a75 4 #ifdef UCI if (!fanno) #endif UCI fprintf (tmp, "%s: %s\n", comp, dtimenow ()); @ 1.1 log @Initial revision @ text @d12 3 d76 3 @