]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/annosbr.c
1 /* annosbr.c - prepend annotation to messages */
3 static char ident
[] = "@(#)$Id: annosbr.c,v 2.6 1993/08/25 17:24:39 jromine Exp $";
7 #include "../zotnet/tws.h"
10 #include <sys/types.h>
20 annotate (file
, comp
, text
, inplace
, datesw
)
30 if ((fd
= lkopen (file
, 2)) == NOTOK
) {
36 admonish (file
, "unable to lock and open");
42 i
= annosbr (fd
, file
, comp
, text
, inplace
, datesw
);
44 (void) lkclose (fd
, file
);
51 static annosbr (src
, file
, comp
, text
, inplace
, datesw
)
68 mode
= fstat (src
, &st
) != NOTOK
? (st
.st_mode
& 0777) : m_gmprot ();
70 (void) strcpy (tmpfil
, m_scratch (file
, "annotate"));
72 if ((tmp
= fopen (tmpfil
, "w")) == NULL
) {
73 admonish (tmpfil
, "unable to create");
76 (void) chmod (tmpfil
, mode
);
79 fprintf (tmp
, "%s: %s\n", comp
, dtimenow ());
82 while (*cp
== ' ' || *cp
== '\t')
85 while (*cp
&& *cp
++ != '\n')
88 fprintf (tmp
, "%s: %*.*s", comp
, cp
- sp
, cp
- sp
, sp
);
90 if (cp
[-1] != '\n' && cp
!= text
)
91 (void) putc ('\n', tmp
);
94 cpydata (src
, fileno (tmp
), file
, tmpfil
);
98 if ((fd
= open (tmpfil
, 0)) == NOTOK
)
99 adios (tmpfil
, "unable to open for re-reading");
100 (void) lseek (src
, (off_t
)0, 0);
101 cpydata (fd
, src
, tmpfil
, file
);
103 (void) unlink (tmpfil
);
106 (void) strcpy (buffer
, m_backup (file
));
107 if (rename (file
, buffer
) == NOTOK
) {
109 case ENOENT
: /* unlinked early - no annotations */
110 (void) unlink (tmpfil
);
114 admonish (buffer
, "unable to rename %s to", file
);
119 if (rename (tmpfil
, file
) == NOTOK
) {
120 admonish (file
, "unable to rename %s to", tmpfil
);