1: /* $Header: artio.c,v 4.3 85/05/01 11:35:39 lwall Exp $
2: *
3: * $Log: artio.c,v $
4: * Revision 4.3 85/05/01 11:35:39 lwall
5: * Baseline for release with 4.3bsd.
6: *
7: */
8:
9: #include "EXTERN.h"
10: #include "common.h"
11: #include "server.h"
12: #include "INTERN.h"
13: #include "artio.h"
14:
15: void
16: artio_init()
17: {
18: ;
19: }
20:
21: /* open an article, unless it's already open */
22:
23: FILE *
24: artopen(artnum)
25: ART_NUM artnum;
26: {
27: #ifdef SERVER
28: static long our_pid;
29: char ser_line[256];
30: #endif
31: char artname[32]; /* filename of current article */
32:
33: #ifdef SERVER
34: if (our_pid == 0)
35: our_pid = getpid();
36: #endif
37:
38: if (artnum < 1)
39: return Nullfp;
40: if (openart == artnum) { /* this article is already open? */
41: fseek(artfp,0L,0); /* just get to the beginning */
42: return artfp; /* and say we succeeded */
43: }
44: if (artfp != Nullfp) { /* it was somebody else? */
45: fclose(artfp); /* put them out of their misery */
46: #ifdef SERVER
47: sprintf(artname, "/tmp/rrn%ld.%ld", (long) openart, our_pid);
48: UNLINK(artname);
49: #endif
50: openart = 0; /* and remember them no more */
51: }
52:
53: #ifdef SERVER
54: sprintf(artname,"/tmp/rrn%ld.%ld", (long) artnum, our_pid);
55: artfp = fopen(artname, "w+"); /* create the temporary article */
56: if (artfp == Nullfp) {
57: UNLINK(artname);
58: return Nullfp;
59: }
60: sprintf(ser_line, "ARTICLE %d", (long)artnum);
61: put_server(ser_line); /* ask the server for the article */
62: if (get_server(ser_line, sizeof(ser_line)) < 0) {
63: fprintf(stderr, "rrn: Unexpected close of server socket.\n");
64: finalize(1);
65: }
66: if (*ser_line != CHAR_OK) { /* and get it's reaction */
67: UNLINK(artname);
68: return Nullfp;
69: }
70:
71: for (;;) {
72: if (get_server(ser_line, sizeof(ser_line)) < 0) {
73: fprintf(stderr, "rrn: Unexpected close of server socket.\n");
74: finalize(1);
75: }
76: if (ser_line[0] == '.' && ser_line[1] == '\0')
77: break;
78: fputs((ser_line[0] == '.' ? ser_line + 1 : ser_line), artfp);
79: putc('\n', artfp);
80: }
81:
82: fseek(artfp, 0L, 0); /* Then get back to the start */
83: openart = artnum;
84: #else /* not SERVER */
85: sprintf(artname,"%ld",(long)artnum);
86: /* produce the name of the article */
87: if (artfp = fopen(artname,"r")) /* if we can open it */
88: openart = artnum; /* remember what we did here */
89: #endif /* SERVER */
90: #ifdef LINKART
91: {
92: char tmpbuf[256];
93: char *s;
94:
95: if (fstat(artfp->_file,&filestat))
96: return artfp;
97: if (filestat.st_size < (sizeof tmpbuf)) {
98: fgets(tmpbuf,(sizeof tmpbuf),artfp);
99: if (*tmpbuf == '/') { /* is a "link" to another article */
100: fclose(artfp);
101: if (s=index(tmpbuf,'\n'))
102: *s = '\0';
103: if (!(artfp = fopen(tmpbuf,"r")))
104: openart = 0;
105: else {
106: if (*linkartname)
107: free(linkartname);
108: linkartname = savestr(tmpbuf);
109: }
110: }
111: else
112: fseek(artfp,0L,0); /* get back to the beginning */
113: }
114: }
115: #endif
116: return artfp; /* and return either fp or NULL */
117: }
Defined functions
Defined variables
FILE
defined in line
23;
never used