home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / elm-2.4-pl20.tar.Z / elm-2.4-pl20.tar / lib / aliasdb.c < prev    next >
C/C++ Source or Header  |  1993-01-12  |  2KB  |  95 lines

  1. /*******************************************************************************
  2.  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
  3.  *
  4.  *            Copyright (c) 1988-1992 USENET Community Trust
  5.  *            Copyright (c) 1986,1987 Dave Taylor
  6.  *******************************************************************************
  7.  * Bug reports, patches, comments, suggestions should be sent to:
  8.  *
  9.  *    Syd Weinstein, Elm Coordinator
  10.  *    elm@DSI.COM            dsinc!elm
  11.  *
  12.  *******************************************************************************
  13.  * $Log: aliasdb.c,v $
  14.  * Revision 5.1  1992/12/20  05:14:05  syd
  15.  * Initial checkin
  16.  *
  17.  *
  18.  ******************************************************************************/
  19.  
  20. /** Alias interface with dbz routines.
  21.  
  22.     This code is shared with newalias and elm so that
  23.   it is easier to do updates while in elm.  The routines in
  24.   this file are interface routines between elm alias code,
  25.   newalias, and listalias and the dbm routines.
  26.  
  27. **/
  28.  
  29. #include "headers.h"
  30. #include <ctype.h>
  31. #include "ndbz.h"
  32.  
  33. #ifdef BSD
  34. #  include <sys/file.h>
  35. #  undef tolower
  36. #  undef toupper
  37. #endif
  38.  
  39. #ifdef DEBUG
  40. extern FILE *debugfile;
  41. extern int  debug;
  42. #endif
  43.  
  44. /* byte-ordering stuff */
  45. #define    MAPIN(o)    ((db->dbz_bytesame) ? (of_t) (o) : bytemap((of_t)(o), db->dbz_conf.bytemap, db->dbz_mybmap))
  46. #define    MAPOUT(o)    ((db->dbz_bytesame) ? (of_t) (o) : bytemap((of_t)(o), db->dbz_mybmap, db->dbz_conf.bytemap))
  47.  
  48. static of_t            /* transformed result */
  49. bytemap(ino, map1, map2)
  50. of_t ino;
  51. int *map1;
  52. int *map2;
  53. {
  54.     union oc {
  55.         of_t o;
  56.         char c[SOF];
  57.     };
  58.     union oc in;
  59.     union oc out;
  60.     register int i;
  61.  
  62.     in.o = ino;
  63.     for (i = 0; i < SOF; i++)
  64.         out.c[map2[i]] = in.c[map1[i]];
  65.     return(out.o);
  66. }
  67.  
  68. read_one_alias(db, ar)
  69. DBZ *db;
  70. struct alias_rec *ar;
  71. {
  72. /*
  73.  *    Read an alias (name, address, etc.) from the data file
  74.  */
  75.  
  76.     FILE *data_file = db->dbz_basef;
  77.  
  78.     if (data_file == NULL)
  79.         return(0);    /* no alias file, but hash exists, error condition */
  80.  
  81.     if (fread((char *) ar, sizeof(struct alias_rec), 1, data_file) <= 0)
  82.         return(0);
  83.  
  84.     ar->status = (int) MAPIN(ar->status);
  85.     ar->alias = (char *) MAPIN(ar->alias);
  86.     ar->last_name = (char *) MAPIN(ar->last_name);
  87.     ar->name = (char *) MAPIN(ar->name);
  88.     ar->comment = (char *) MAPIN(ar->comment);
  89.     ar->address = (char *) MAPIN(ar->address);
  90.     ar->type = (int) MAPIN(ar->type);
  91.     ar->length = (long) MAPIN(ar->length);
  92.  
  93.     return(1);
  94. }
  95.