]>
diplodocus.org Git - nmh/blob - docs/historical/SRI-NOSC/annotate.c
4 /* annotate file component data
6 * prepends Component: data
10 /*extern int inplace;*/ /* preserve links in anno */
11 int inplace
1; /* preserve links in anno */
13 annotate(file
, comp
, text
)
14 char *file
, *comp
, *text
;
16 register int src
, tmp
;
19 char buf
[512], *sp
, tmpfil
[128];
23 if((src
= open((cp
= file
), 2)) == -1) { /* this should be an X-open*/
24 printf("Can't open "); flush();
30 while(*cp
) if(*cp
++ == '/') sp
= cp
;
33 cp
= copy(buf
, tmpfil
);
36 copy(makename("annot",".tmp"), cp
);
38 if((tmp
= creat(tmpfil
, stbuf
.i_mode
&0777)) == -1) {
39 printf("Can't create "); flush();
44 if(*cp
>= 'a' && *cp
<= 'z') *cp
=- 040;
49 cp
[9] = ' '; cp
[15] = 0;
56 if(*cp
== ' ' || *cp
== '\t') cp
++;
58 while(*cp
&& *cp
++ != '\n') ;
62 write(tmp
, sp
, cp
-sp
);
65 if(cp
[-1] != '\n' && cp
!= text
) type(tmp
, "\n");
67 if((cnt
= read(src
, buf
, sizeof buf
)) > 0)
69 while(cnt
== sizeof buf
);
72 tmp
= open(tmpfil
, 0); /* reopen for reading */
75 if((cnt
= read(tmp
, buf
, sizeof buf
)) > 0)
77 while(cnt
== sizeof buf
);
79 /* cp = copy(file, buf); */
81 /* copy(".bak", copy(file, buf)); */
86 while(--cp
>= buf
&& *cp
!= '/');
87 *++cp
= ','; /* New backup convention */
89 if(link(file
, buf
) == -1) {
90 printf("Can't rename %s to bak file.\n", file
);
93 if(unlink(file
) == -1) {
94 printf("Can't unlink %s\n", file
);
97 if(link(tmpfil
, file
) == -1) {
98 printf("Can't lnk temp file \"%s\" to %s\n",