home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / doalias.c < prev    next >
Text File  |  1994-09-25  |  3KB  |  111 lines

  1. /*  doalias.c    Routine to substitute an alias with the actual mail address.
  2.     Copyright (C) 1990, 1993  Rick Adams and Bob Billson
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. /* Search aliases (.aliases under OSK) file in the user's home directory
  26.    alias.  Any line starting with #, * or CR  is are considered comment lines
  27.    and ignored.  Returns TRUE if an alias was found and put in 'address'.
  28.    FALSE if no alias was found.  'address' remains unchanged.
  29.  
  30.    An entry may be in the form:
  31.       <alias> <address>
  32.    or
  33.       <alias> <username> <address>
  34.  
  35.    <username> may be either quoted as in:
  36.  
  37.       "Rick Adams"
  38.  
  39.    or separate as in:
  40.  
  41.       Rick Adams
  42.  
  43.    Any number of spaces can separate the fields.  Right now the <username>
  44.    field is ignored.  This is for compatibility with Jeff Shepler's Palm. */
  45.  
  46.  
  47. #include "uucp.h"
  48.  
  49. #define WORDSIZE   30
  50.  
  51. EXTERN QQ int debug;
  52.  
  53.  
  54. int doalias (address)
  55. char address[];
  56. {
  57.      static char aliasfile[128];
  58.      static int firstpass = TRUE;
  59.      char line[SYSLINE];
  60.      register char *p;
  61.      char *words[WORDSIZE], *aptr;
  62.      FILE *file;
  63.      int foundalias, n;
  64.  
  65.      foundalias = FALSE;
  66.      p = line;
  67.  
  68.      if (firstpass)
  69.        {
  70. #ifdef _OSK
  71.           sprintf (aliasfile, "%s/.aliases", homedir);
  72. #else
  73.           sprintf (aliasfile, "%s/%s/aliases", homedir, uudir);
  74. #endif
  75.           firstpass = FALSE;
  76.        }
  77.  
  78.      if ((file = fopen (aliasfile, "r")) != NULL)
  79.        {
  80.           while (mfgets (p, sizeof (line), file) != NULL)
  81.             {
  82.                if (ISCOMMENT (*p) ||  *p == '*')
  83.                     continue;
  84.  
  85.                n = getargs (words, p, WORDSIZE);
  86.                aptr = n > 2 ? *(words + (n - 1)) : *(words + 1);
  87.  
  88.                if (debug >= 3)
  89.                     printf ("doalias: alias= %s  new adrs= %s\n",
  90.                                 *words, aptr);
  91.  
  92.                if (strucmp (address, *words) == 0)
  93.                  {
  94.                     if (debug >= 3)
  95.                          printf ("doalias: substituting '%s' for '%s'\n",
  96.                                      aptr, *words);
  97.  
  98.                     strcpy (address, aptr);
  99.                     foundalias = TRUE;
  100.                     break;
  101.                  }
  102.             }
  103.           fclose (file);
  104.        }
  105.  
  106.      if (debug >= 3)
  107.           printf ("doalias: address = '%s'\n", address);
  108.  
  109.      return (foundalias);
  110. }
  111.