home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / tulp-3.0.3 / part01 / ad.c next >
Encoding:
C/C++ Source or Header  |  1993-04-15  |  2.6 KB  |  87 lines

  1. /*-------------------------------------------------------------------------
  2.  *  Listserv - Unix Mailing List manager (sub-set of FRECP's
  3.  *             Bitnet Listserv tool.
  4.  *
  5.  *  Copyright (C) 1991,1992  Kimmo Suominen, Christophe Wolfhugel
  6.  *
  7.  *  Please read the files COPYRIGHT and AUTHORS for the extended
  8.  *  copyrights refering to this file.
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 1, or (at your option)
  13.  *  any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  *
  24.  *----------------------------------------------------------------------*/
  25.  
  26. static char rcsid[] = "@(#)$Id: ad.c,v 1.5 93/03/02 22:46:33 wolf Exp $";
  27.  
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include "conf.h"
  31. #include "ext.h"
  32.  
  33. static char *adrs,*name;
  34. static char line[3][MAXLINE];
  35.  
  36. void adChange(s)
  37. char *s;
  38. {
  39.    int state,i,j,quote=0,parlvl=0;
  40.    char *lns[3],*save=s;
  41.  
  42.    state=0; memset(line[0],0,sizeof(line));
  43.    lns[0]=line[0]; lns[1]=line[1]; lns[2]=line[2];
  44.    while (*s!=0) {
  45.       if (*s=='"') quote=1-quote;
  46.       if (quote==1) { *lns[state]++= *s; s++; continue; }
  47.       switch (*s) {
  48.       case '<':
  49.          state=1;
  50.          break;
  51.       case '(':
  52.          parlvl++;
  53.          state=2;
  54.      if (parlvl > 1) *lns[state]++ = '(';
  55.          break;
  56.       case '>':
  57.          state=0;
  58.          break;
  59.       case ')':
  60.          if (--parlvl) { *lns[state]++ = ')'; break; }
  61.          state=0;
  62.          break;
  63.       default:
  64.          *lns[state]++= *s;
  65.       } /* endswitch */
  66.       s++;
  67.    } /* endwhile */
  68.    lns[0]=line[0]; lns[1]=line[1]; lns[2]=line[2];
  69.    for (i=0; i<2; i++) {
  70.       while (*lns[i]==' ') lns[i]++;
  71.       j=strlen(lns[i]);
  72.       while (j>0 && lns[i][j-1]==' ') lns[i][--j]=0;
  73.    } /* endfor */
  74.    if (lns[1][0]!=0) {    /* Adress between <> */
  75.       adrs=lns[1];
  76.       name=lns[0];
  77.    } else {
  78.       adrs=lns[0];
  79.       name=lns[2];
  80.    } /* endif */
  81.    if (strchr(adrs,'@')==NULL && strchr(adrs,'!')==NULL) {
  82.       strcat(adrs,"@");
  83.       strcat(adrs,HOST);
  84.    } /* endif */
  85.    if (*name!=0) sprintf(save,"%s (%s)",adrs,name); else strcpy(save,adrs);
  86. }
  87.