]>
diplodocus.org Git - nmh/blob - docs/historical/2.9BSD/cmds/annotate.c
2 static char sccsid
[] = "@(#)annotate.c 4.1 2/23/83";
10 /* annotate file component data
12 * prepends Component: data
16 annotate(file
, comp
, text
, inplace
)
17 char *file
, *comp
, *text
;
23 char buf
[BUFSIZ
], *sp
, tmpfil
[128];
28 if((src
= open((cp
= file
), 2)) == -1) { /* this should be an X-open*/
29 fprintf(stderr
, "Can't open ");
37 cp
= copy(buf
, tmpfil
);
40 copy(makename("ano",".tmp"), cp
);
42 if((tmp
= fopen(tmpfil
, "w")) == NULL
) {
43 fprintf(stderr
, "Can't create ");
47 chmod(tmpfil
, stbuf
.st_mode
&0777);
49 if(*cp
>= 'a' && *cp
<= 'z') *cp
-= 040;
52 cp
[9] = ' '; cp
[15] = 0;
54 fprintf(tmp
, "%s: <<%s>>\n", comp
, cp
);
57 if(*cp
== ' ' || *cp
== '\t') cp
++;
59 while(*cp
&& *cp
++ != '\n') ;
61 fprintf(tmp
, "%s: %*s", comp
, cp
-sp
, sp
);
63 if(cp
[-1] != '\n' && cp
!= text
) putc('\n', tmp
);
65 if((cnt
= read(src
, buf
, sizeof buf
)) > 0)
66 fwrite(buf
, cnt
, 1, tmp
);
67 while(cnt
== sizeof buf
);
70 fd
= open(tmpfil
, 0); /* reopen for reading */
73 if((cnt
= read(fd
, buf
, sizeof buf
)) > 0)
75 while(cnt
== sizeof buf
);
78 /* cp = copy(file, buf); */
80 /* copy(".bak", copy(file, buf)); */
85 while(--cp
>= buf
&& *cp
!= '/');
93 if(link(file
, buf
) == -1) {
94 fprintf(stderr
, "Can't rename %s to bak file.\n", file
);
97 if(unlink(file
) == -1) {
98 fprintf(stderr
, "Can't unlink %s\n", file
);
101 if(link(tmpfil
, file
) == -1) {
102 fprintf(stderr
, "Can't lnk temp file \"%s\" to %s\n",