1: #include "parms.h"
   2: #include "structs.h"
   3: #include "newsgate.h"
   4: 
   5: #ifdef  RCSIDENT
   6: static char rcsid[] = "$Header: newsgroup.c,v 1.7 85/01/18 15:21:09 notes Rel $";
   7: #endif	RCSIDENT
   8: 
   9: /*
  10:  *	newsgroup(lookfor, mapped,direct)
  11:  *
  12:  *	This routine looks in the file specified by NEWSALIAS
  13:  *	for a correspondence between the notesfile name supplied
  14:  *	and a news(1) newsgroup.
  15:  *	The resultant match is placed where the second parameter points.
  16:  *	In the event of no match, the same name is passed back.
  17:  *
  18:  *	direct gives us the direction of mapping:
  19:  *	NFNEWS says that lookfor is a notesfile and we find a newsgroup
  20:  *	NEWSNF says that lookfor is a newsgroup and we find a nf
  21:  *	in both cases lookfor is the input and mapped is the output
  22:  *
  23:  *	Original Coding:	Ray Essick	April 7, 1982
  24:  */
  25: 
  26: newsgroup (lookfor, mapped, direct)
  27: char   *lookfor;
  28: char   *mapped;
  29: {
  30: 
  31:     FILE * groups;
  32:     char    linebuf[CMDLEN];                /* lines in file */
  33:     char   *p,
  34:            *q,
  35:            *r;
  36:     int     c;
  37: 
  38:     strcpy (mapped, lookfor);               /* ready to fail */
  39: 
  40:     sprintf (linebuf, "%s/%s/%s", Mstdir, UTILITY, NEWSALIAS);
  41:     if ((groups = fopen (linebuf, "r")) == NULL)
  42:     return (-1);                    /* no file, too bad */
  43: 
  44:     while (1)
  45:     {
  46:     p = linebuf;                    /* start line */
  47:     while ((c = getc (groups)) != EOF && c != '\n')
  48:         *p++ = c;
  49:     if (c == EOF)
  50:     {
  51:         fclose (groups);
  52:         return 0;                   /* no match */
  53:     }
  54:     *p = '\0';                  /* terminate string */
  55:     if (linebuf[0] == '#' || linebuf[0] == '\0')
  56:         continue;                   /* comment or empty */
  57: 
  58:     q = linebuf;                    /* find colon */
  59:     while (*q != ':' && *q)
  60:         q++;                    /* try next */
  61:     if (*q != ':')                  /* formatted ok? */
  62:     {
  63:         fprintf (stderr, "Bad line in newsgroup file: %s\n", linebuf);
  64:         continue;                   /* skip the line */
  65:     }
  66:     *q++ = '\0';                    /* break into parts */
  67: 
  68: /*
  69:  *	Grab the `response' group if there is one.
  70:  */
  71:     r = q;                      /* start here */
  72:     while (*r != ':' && *r)
  73:         r++;                    /* not this one */
  74:     if (*r == ':')                  /* we have a response group */
  75:     {
  76:         *r++ = '\0';                /* null terminate base group */
  77:         if (!*r)                    /* see if empty field */
  78:         r = q;                  /* give it base group */
  79:     }
  80:     else
  81:     {
  82:         r = q;                  /* base group */
  83:     }
  84: 
  85: /*
  86:  *	Now decide which to match and which to fill
  87:  */
  88: 
  89:     switch (direct)                 /* which direction */
  90:     {
  91:         case NFBASENEWS:                /* notesfile base note */
  92:         if (strcmp (linebuf, lookfor) == 0) /* match ? */
  93:         {
  94:             strcpy (mapped, q);         /* copy it to caller */
  95:             fclose (groups);
  96:             return 1;               /* success */
  97:         }
  98:         break;                  /* out of switch */
  99: 
 100:         case NEWSNF:                /* newsgroup to notesfile */
 101:         if (strcmp (q, lookfor) == 0)
 102:         {
 103:             strcpy (mapped, linebuf);       /* move find */
 104:             fclose (groups);
 105:             return 1;               /* success */
 106:         }
 107:         break;                  /* from switch */
 108: 
 109:         case NFRESPNEWS:                /* nf response to news */
 110:         if (strcmp (linebuf, lookfor) == 0) /* match ? */
 111:         {
 112:             strcpy (mapped, r);         /* copy to caller */
 113:             fclose (groups);
 114:             return 1;               /* success */
 115:         }
 116:         break;                  /* out of switch */
 117: 
 118:         default:
 119:         fclose (groups);
 120:         return (-1);                /* what the heck */
 121: 
 122:     }
 123:     }
 124: /*	yes, we know that this statement is unreachable! */
 125:     return (-1);                    /* to satisfy lint */
 126: }

Defined functions

newsgroup defined in line 26; used 3 times

Defined variables

rcsid defined in line 6; never used
Last modified: 1985-01-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2350
Valid CSS Valid XHTML 1.0 Strict