home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / OSKBox.lzh / MAILBOX / CC / editusers.c < prev    next >
C/C++ Source or Header  |  1991-02-03  |  4KB  |  185 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include "mailbox.h"
  4.  
  5. struct userstruct user;
  6.  
  7. main (argc, argv)
  8. char *argv[];
  9. {
  10.     char line[256];
  11.     long user_rec;
  12.     int i, userfile, found;
  13.     int mod = 0;
  14.     char *noname = "new user";
  15.  
  16.     for (i = 1; i < argc; i++)
  17.         upper (argv[i]);
  18.     chdir (HOME);
  19.     if ((userfile = open ("users", 1)) <= 0) {
  20.         printf ("Error: can't open user file\n");
  21.         exit (0);
  22.         }
  23.     found = 0;
  24.     while (1) {
  25.         user_rec = lseek (userfile, 0L, 1);
  26.         if (read (userfile, &user, sizeof (user)) == 0) break;
  27.         if (strcmp (user.uscall, argv[1]) == 0) {
  28.             found = 1;
  29.             break;
  30.             }
  31.         }
  32.     close (userfile);
  33.     if (!found) {
  34.         printf ("Can't find %s, create him? ", argv[1]);
  35.         gets (line);
  36.         if (toupper (*line) != 'Y')
  37.             exit (0);
  38.         strcpy (user.usname, noname);
  39.         strcpy (user.uscall, argv[1]);
  40.         user.usopt = 0;
  41.         user.ustime = 0;
  42.         user.usdate = 0;
  43.         user.uscnt = 0;
  44.         user.usnmr = 0;
  45.         userfile = open ("users", 3);
  46.         user_rec = lseek (userfile, 0L, 2);
  47.         write (userfile, &user, sizeof (user));
  48.         close (userfile);
  49.         }
  50.     printuser (1);
  51.     printf ("\n");
  52.     printf ("Deleted user (%c): ", (user.usopt & ISDELETED) ? 'Y' : 'N');
  53.     gets (line);
  54.     if (toupper (*line) == 'Y') {
  55.         user.usopt |= ISDELETED;
  56.         goto modified;
  57.         }
  58.     else if (toupper (*line) == 'N') {
  59.         user.usopt &= ~ISDELETED;
  60.         mod = 1;
  61.         }
  62.     printf ("Callsign (%s): ", user.uscall);
  63.     gets (line);
  64.     if (*line) {
  65.         upper (line);
  66.         strncpy (user.uscall, line, sizeof (user.uscall));
  67.         mod = 1;
  68.         }
  69.     printf ("Last message (%d): ", user.usnmr);
  70.     gets (line);
  71.     if (*line) {
  72.         user.usnmr = atoi (line);
  73.         mod = 1;
  74.         }
  75.     printf ("Expert (%c): ", (user.usopt & ISEXPERT) ? 'Y' : 'N');
  76.     gets (line);
  77.     if (toupper (*line) == 'Y') {
  78.         user.usopt |= ISEXPERT;
  79.         mod = 1;
  80.         }
  81.     else if (toupper (*line) == 'N') {
  82.         user.usopt &= ~ISEXPERT;
  83.         mod = 1;
  84.         }
  85.     printf ("Persona non grata (%c): ", (user.usopt & ISPNG) ? 'Y' : 'N');
  86.     gets (line);
  87.     if (toupper (*line) == 'Y') {
  88.         user.usopt |= ISPNG;
  89.         mod = 1;
  90.         }
  91.     else if (toupper (*line) == 'N') {
  92.         user.usopt &= ~ISPNG;
  93.         mod = 1;
  94.         }
  95.     printf ("Is a BBS (%c): ", (user.usopt & ISBBS) ? 'Y' : 'N');
  96.     gets (line);
  97.     if (toupper (*line) == 'Y') {
  98.         user.usopt |= ISBBS;
  99.         mod = 1;
  100.         }
  101.     else if (toupper (*line) == 'N') {
  102.         user.usopt &= ~ISBBS;
  103.         mod = 1;
  104.         }
  105.     printf ("Is a SuperUser (%c): ", (user.usopt & ISSUPER) ? 'Y' : 'N');
  106.     gets (line);
  107.     if (toupper (*line) == 'Y') {
  108.         user.usopt |= ISSUPER;
  109.         mod = 1;
  110.         }
  111.     else if (toupper (*line) == 'N') {
  112.         user.usopt &= ~ISSUPER;
  113.         mod = 1;
  114.         }
  115.     printf ("Is Stupid (%c): ", (user.usopt & ISSTUPID) ? 'Y' : 'N');
  116.     gets (line);
  117.     if (toupper (*line) == 'Y') {
  118.         user.usopt |= ISSTUPID;
  119.         mod = 1;
  120.         }
  121.     else if (toupper (*line) == 'N') {
  122.         user.usopt &= ~ISSTUPID;
  123.         mod = 1;
  124.         }
  125.     printf ("Name (%s): ", user.usname);
  126.     gets (line);
  127.     if (*line) {
  128.         strncpy (user.usname, line, sizeof (user.usname));
  129.         mod = 1;
  130.         }
  131.     printf ("Path (%s): ", user.uspath);
  132.     gets (line);
  133.     if (*line) {
  134.         upper (line);
  135.         strncpy (user.uspath, line, sizeof (user.uspath));
  136.         mod = 1;
  137.         }
  138.     if (mod) {
  139. modified:
  140.         userfile = open ("users", 3);
  141.         lseek (userfile, user_rec, 0);
  142.         write (userfile, &user, sizeof (user));
  143.         close (userfile);
  144.         printuser (1);
  145.         }
  146.     }
  147.  
  148. printuser (flag)
  149. {
  150.     char *ctl = 
  151. "%-6.6s %02d%02d%02d %02d%02d %04.4d %6.6d       %2d%c%c%c%c%c  %-12.12s%s\n";
  152.  
  153.     if (flag) {
  154.         printf ("Call   Date   Time Logd    Msg Hm BBS SXPBSS  Name        Path\n");
  155.         flag = 1;
  156.         }
  157.     printf (ctl, user.uscall, (user.usdate >> 16) % 100,
  158.     (user.usdate >> 8) & 0xff, user.usdate & 0xff,
  159.     (user.ustime >> 16) & 0xff, (user.ustime >> 8) & 0xff,
  160.     user.uscnt, user.usnmr, user.usssid, (user.usopt & ISEXPERT) ? 'Y' : 'N',
  161.     (user.usopt & ISPNG) ? 'Y' : 'N', 
  162.     (user.usopt & ISBBS) ? 'Y' : 'N', 
  163.     (user.usopt & ISSUPER) ? 'Y' : 'N', 
  164.     (user.usopt & ISSTUPID) ? 'Y' : 'N', 
  165.     user.usname, user.uspath);
  166.     }
  167.  
  168. upper (s)
  169. char *s;
  170. {
  171.     while (*s) {
  172.         *s = toupper (*s);
  173.         s++;
  174.         }
  175.     }
  176.  
  177. strncpy (s1, s2, len)
  178. char *s1, *s2;
  179. {
  180.     while (*s2 && --len)
  181.         *s1++ = *s2++;
  182.     *s1 = '\0';
  183.     }
  184.  
  185.