/* annosbr.c - prepend annotation to messages */
static char ident
[] = "@(#)$Id: annosbr.c,v 2.5 1992/12/15 00:20:22 jromine Exp $";
#include "../zotnet/tws.h"
annotate (file
, comp
, text
, inplace
, datesw
)
if ((fd
= lkopen (file
, 2)) == NOTOK
) {
admonish (file
, "unable to lock and open");
i
= annosbr (fd
, file
, comp
, text
, inplace
, datesw
);
(void) lkclose (fd
, file
);
static annosbr (src
, file
, comp
, text
, inplace
, datesw
)
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");
(void) chmod (tmpfil
, mode
);
fprintf (tmp
, "%s: %s\n", comp
, dtimenow ());
while (*cp
== ' ' || *cp
== '\t')
while (*cp
&& *cp
++ != '\n')
fprintf (tmp
, "%s: %*.*s", comp
, cp
- sp
, cp
- sp
, sp
);
if (cp
[-1] != '\n' && cp
!= text
)
cpydata (src
, fileno (tmp
), file
, tmpfil
);
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) strcpy (buffer
, m_backup (file
));
if (rename (file
, buffer
) == NOTOK
) {
case ENOENT
: /* unlinked early - no annotations */
admonish (buffer
, "unable to rename %s to", file
);
if (rename (tmpfil
, file
) == NOTOK
) {
admonish (file
, "unable to rename %s to", tmpfil
);