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 SERVER
  31:     char artname[32];           /* filename of current article */
  32: 
  33: #ifdef SERVER
  34:     if (our_pid == 0)
  35:     our_pid = getpid();
  36: #endif SERVER
  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 SERVER
  50:     openart = 0;            /* and remember them no more */
  51:     }
  52: 
  53: #ifdef SERVER
  54: 
  55:     sprintf(artname,"/tmp/rrn%ld.%ld", (long) artnum, our_pid);
  56:     artfp = fopen(artname, "w+");   /* create the temporary article */
  57:     if (artfp == Nullfp) {
  58:     UNLINK(artname);
  59:     return Nullfp;
  60:     }
  61:     sprintf(ser_line, "ARTICLE %ld", (long)artnum);
  62:     put_server(ser_line);       /* ask the server for the article */
  63:     if (get_server(ser_line, sizeof(ser_line)) < 0) {
  64:     fprintf(stderr, "rrn: Unexpected close of server socket.\n");
  65:     finalize(1);
  66:     }
  67:     if (*ser_line != CHAR_OK) {     /* and get it's reaction */
  68:     fclose(artfp);
  69:     artfp = Nullfp;
  70:     UNLINK(artname);
  71:         return Nullfp;
  72:     }
  73: 
  74:     for (;;) {
  75:         if (get_server(ser_line, sizeof(ser_line)) < 0) {
  76:         fprintf(stderr, "rrn: Unexpected close of server socket.\n");
  77:         finalize(1);
  78:     }
  79:     if (ser_line[0] == '.' && ser_line[1] == '\0')
  80:         break;
  81:     fputs((ser_line[0] == '.' ? ser_line + 1 : ser_line), artfp);
  82:     putc('\n', artfp);
  83:     }
  84: 
  85:     fseek(artfp, 0L, 0);        /* Then get back to the start */
  86:     openart = artnum;
  87: 
  88: #else not SERVER
  89: 
  90:     sprintf(artname,"%ld",(long)artnum);
  91:                     /* produce the name of the article */
  92:     if (artfp = fopen(artname,"r")) /* if we can open it */
  93:     openart = artnum;       /* remember what we did here */
  94: 
  95: #endif SERVER
  96: #ifdef LINKART
  97:     {
  98:     char tmpbuf[256];
  99:     char *s;
 100: 
 101:     if (fstat(artfp->_file,&filestat))
 102:         return artfp;
 103:     if (filestat.st_size < (sizeof tmpbuf)) {
 104:         fgets(tmpbuf,(sizeof tmpbuf),artfp);
 105:         if (*tmpbuf == '/') {   /* is a "link" to another article */
 106:         fclose(artfp);
 107:         if (s=index(tmpbuf,'\n'))
 108:             *s = '\0';
 109:         if (!(artfp = fopen(tmpbuf,"r")))
 110:             openart = 0;
 111:         else {
 112:             if (*linkartname)
 113:             free(linkartname);
 114:             linkartname = savestr(tmpbuf);
 115:         }
 116:         }
 117:         else
 118:         fseek(artfp,0L,0);      /* get back to the beginning */
 119:     }
 120:     }
 121: #endif
 122:     return artfp;           /* and return either fp or NULL */
 123: }

Defined functions

artio_init defined in line 15; used 2 times

Defined variables

FILE defined in line 23; never used
Last modified: 1987-08-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2754
Valid CSS Valid XHTML 1.0 Strict