home *** CD-ROM | disk | FTP | other *** search
/ The Arcade BBS / arcadebbs.zip / arcadebbs / bbstools / FIDO / NETS200.ZIP / ALIASES.C next >
Encoding:
C/C++ Source or Header  |  1991-01-07  |  6.4 KB  |  223 lines

  1. /*
  2.  ****************************************************************************
  3.  * Version: ALIASES.C v1.00                                                 *
  4.  *                                                                          *
  5.  * Purpose: This program reads your WWIV user list and outputs, in a style  *
  6.  *          that NetSEX can understand, a list of aliases.  This program    *
  7.  *          automates the creation and update of your aliases index.        *
  8.  *          NetSEX v1.00 uses a linked list to store the IN_ALIAS and       *
  9.  *          OUT_ALIAS declarations, so your only limitation is free heap.   *
  10.  *          There is a #define that supposedly limits the number (MAX_ALIAS *
  11.  *          I think) in my copy of the source, but I have surpassed this    *
  12.  *          limit by far.                                                   *
  13.  *                                                                          *
  14.  * Notes:   The credit for this program goes wholly and entirely to         *
  15.  *          Darkster 1@3114.  I saw this on his board and he gave it to me. *
  16.  *          I didn't like its output, so I reworked it.  It functionally    *
  17.  *          does the same thing, though.                                    *
  18.  *                                                                          *
  19.  * Files:   CONFIG.DAT (Binary Input)                                       *
  20.  *          USER.LST (Binary Input)                                         *
  21.  *          ALIASES.TXT (Text Output)                                       *
  22.  ****************************************************************************
  23.  * TCC Command line:                                                        *
  24.  *                                                                          *
  25.  *       tcc -G -O -d -r -mt -N- -Z -a -lt -2 aliases                       *
  26.  ****************************************************************************
  27.  */
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <io.h>
  32. #include <fcntl.h>
  33. #include <string.h>
  34. #include <sys\stat.h>
  35. #include "vardec.h"
  36.  
  37. /* comment out to leave names as they are in the user file */
  38. #define NAMES_UPPERCASE
  39.  
  40. /* holds WWIV static system configuration */
  41. configrec syscfg;
  42.  
  43. /* this is the user file variable; set to -1 to represent a closed file */
  44. int userfile = -1;
  45.  
  46. void init()
  47. /*
  48.  * Read WWIV's CONFIG.DAT to get WWIVnet node number and data directory.
  49.  * Program is aborted with a DOS errorlevel of 1 if CONFIG.DAT does not
  50.  * exist.
  51.  *
  52.  * Parameters: None
  53.  *
  54.  * Returns: Nothing
  55.  */
  56. {
  57.   int configfile;
  58.   char s[81];
  59.  
  60.   strcpy(s,"CONFIG.DAT");
  61.   configfile=open(s,O_RDWR | O_BINARY);
  62.   if (configfile<0) {
  63.     printf("%s NOT FOUND.\n",s);
  64.     exit(1);
  65.   }
  66.   read(configfile,(void *) (&syscfg), sizeof(configrec));
  67.   close(configfile);
  68. }
  69.  
  70. void read_user(unsigned int un, userrec *u)
  71. /*
  72.  * Modified version of Wayne's read_user routine to get a user
  73.  * at a specified offset in the user file; no functionality gone,
  74.  * just stupid useless code Wayne added
  75.  *
  76.  * Parameters: u  = the user number (record offset)
  77.  *             *u = points to the user record to place the record requested
  78.  *
  79.  * Returns: Nothing
  80.  */
  81. {
  82.   long pos;
  83.   char s[80];
  84.   int i;
  85.  
  86.   if (userfile == -1) {
  87.     sprintf(s, "%sUSER.LST", syscfg.datadir);
  88.     userfile = open(s, O_RDWR | O_BINARY);
  89.     if (userfile < 0) {
  90.       u->inact = inact_deleted;
  91.       return;
  92.     }
  93.   }
  94.   pos = (long) (sizeof(userrec) * (long) un);
  95.   if (filelength(userfile) <= pos) {
  96.     u->inact = inact_deleted;
  97.     return;
  98.   }
  99.   lseek(userfile, pos, SEEK_SET);
  100.   read(userfile, (void *)u, sizeof(userrec));
  101.   if (u->realname[0] == 0) {
  102.     u->inact = inact_deleted;
  103.     return;
  104.   }
  105.   if (!strchr(u->realname, ' ')) {
  106.     u->inact = inact_deleted;
  107.     return;
  108.   }
  109.   if (strchr(u->realname, '=')) {
  110.     u->inact = inact_deleted;
  111.     return;
  112.   }
  113. }
  114.  
  115. void close_user()
  116. /*
  117.  * Closes user file if it is not already closed.
  118.  *
  119.  * Parameters: None
  120.  *
  121.  * Returns: Nothing
  122.  */
  123. {
  124.   if (userfile!=-1) {
  125.     close(userfile);
  126.     userfile=-1;
  127.   }
  128. }
  129.  
  130. char *returnstr(char *st)
  131. /*
  132.  * This routine formats the string in the desired way and returns the
  133.  * modified string.  The purpose of this as a separate routine would be
  134.  * for someone to modify it to allow it to, say, convert all letters to
  135.  * lower case except for the first letters in each word.
  136.  *
  137.  * Parameters: *st = string to be formatting
  138.  *
  139.  * Returns: formatted string
  140.  */
  141. {
  142. #ifdef NAMES_UPPERCASE
  143.   return(strupr(st));
  144. #else
  145.   return(st);
  146. #endif
  147. }
  148.  
  149. void run()
  150. /*
  151.  * This is the meat routine.  It reads in each user record, and if
  152.  * that user has a valid real name, and it is not a deleted record,
  153.  * then write the IN_ALIAS and OUT_ALIAS entries to ALIASES.TXT in the
  154.  * WWIV DATA directory.
  155.  *
  156.  * Parameters: None
  157.  *
  158.  * Returns: Nothing
  159.  */
  160. {
  161.   int f, i, count;
  162.   char s[255];
  163.   userrec u;
  164.  
  165.   read_user(1, &u);
  166.   if (userfile < 0) {
  167.     printf("Could not open user file properly.\r\n");
  168.     exit(1);
  169.   }
  170.   count = (int)(filelength(userfile) / sizeof(userrec));
  171.   --count;
  172.   sprintf(s, "%sALIASES.TXT", syscfg.datadir);
  173.   f = open(s, O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
  174.   if (f > 0) {
  175.     for (i = 1; i <= count; i++) {
  176.       read_user(i, &u);
  177.       printf("Processing user #%d/%d\r", i, count);
  178.       if (u.inact != inact_deleted) {
  179.         sprintf(s, "IN_ALIAS: %s=n%d u%d\r\n", returnstr(u.realname),
  180.                                                syscfg.systemnumber, i);
  181.         write(f,(void *)s,strlen(s));
  182.         sprintf(s, "OUT_ALIAS: n%d u%d=%s\r\n", syscfg.systemnumber, i,
  183.                                                 returnstr(u.realname));
  184.         write(f,(void *)s,strlen(s));
  185.       } else {
  186.         printf("User %d skipped: Deleted/Invalid Real Name\r\n", i);
  187.       }
  188.     }
  189.     close_user();
  190.     close(f);
  191.   } else {
  192.     printf("Could not open %sALIASES.TXT\r\n", syscfg.datadir);
  193.     exit(1);
  194.   }
  195. }
  196.  
  197. void done()
  198. /*
  199.  * Does nothing.  Something would be present if there was a need for
  200.  * global shutdown code.
  201.  *
  202.  * Parameters: None
  203.  *
  204.  * Returns: Nothing
  205.  */
  206. {
  207. }
  208.  
  209. void main()
  210. /*
  211.  * Main program.  Simply a shell that calls the initialization routine and
  212.  * the meat routine.  A blank shutdown routine is defined.
  213.  *
  214.  * Parameters: None
  215.  *
  216.  * Returns: Nothing
  217.  */
  218. {
  219.   init();
  220.   run();
  221.   done();
  222. }
  223.