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 / register.c < prev    next >
C/C++ Source or Header  |  1992-07-11  |  3KB  |  140 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <modes.h>
  4. #include <errno.h>
  5. #include "mailbox.h"
  6.  
  7. struct userstruct user;
  8.  
  9. main (argc, argv)
  10. char *argv[];
  11. {
  12.     char *name, *call;
  13.     char str[99];
  14.     int zip = -1;
  15.     struct msg_header head, *phead;
  16.     char *maildir = "MAIL/";
  17.     int outfile;
  18.     int date, time, tick;
  19.     short day;
  20.  
  21.     
  22.     if (argc < 3) {
  23.         printf ("register <call> <name>\n");
  24.         exit (0);
  25.     }
  26.     call = argv[1];
  27.     name = argv[2];
  28.     upper (call);
  29.     caps (name);
  30.     strcpy (user.uscall, call);
  31.     printf ("Thank you, %s.  Would you like to register %s as your \"home BBS\"?\n",
  32.         name, MYCALL);
  33.     printf ("This means your mail will be routed here for you to pick up.\n");
  34.     if (!yes ()) {
  35.         printf ("\nOK, if you change your mind in the future, use the N)ame command again.\n");
  36.         exit (0);
  37.     }
  38.     do {
  39.         zip = -1;
  40.         printf ("\nWhat is your zip code?  ");  fflush (stdout);
  41.         gets (str);
  42.         if (feof (stdin)) exit (0);
  43.         if (!iszip (str)) {
  44.             printf ("Sorry, that doesn't look like a 5-digit zipcode to me, please try again.\n");
  45.             continue;
  46.             }
  47.         printf ("\n");
  48.         zip = atoi (str);
  49.         sprintf (str, "zip %d", zip);
  50.         if (system (str) == 0) {
  51.             printf ("Correct?  ");
  52.             if (!yes ())
  53.                 zip = -1;
  54.             }
  55.     } while (zip < 0);
  56.  
  57.     _sysdate (0, &time, &date, &day, &tick);
  58.     open_mail ();
  59.     head.mhsize = 0;
  60.     head.mhtype = 'P';
  61.     head.mhstat = 'X';
  62.     strcpy (head.mhfrom, MYCALL);
  63.     strcpy (head.mhto, "WPAGE");
  64.     strcpy (head.mhbbs, WPAGESERVER);
  65.     strcpy (head.mhtit, "WP auto-update");
  66.     if ((outfile = creat_msg (&head, &phead)) == -1) {
  67.         printf ("Error %d creating message file %s.\n", errno, str);
  68.         close_mail ();
  69.         exit (0);
  70.         }
  71.     sprintf (str, "%s QTH %s ON %02d%02d%02d NAME %s ZIP %05d\n",
  72.         call, MYCALL,
  73.         (date >> 16) % 100,
  74.         (date >> 8) & 0xff,
  75.         date & 0xff,
  76.         name, zip);
  77.     write (outfile, str, strlen (str));
  78.     phead->mhsize = _gs_size (outfile);
  79.     close (outfile);
  80.     phead->mhstat = 'N';
  81.     update_mail ();
  82.     close_mail ();
  83.     log_send (phead, 0);
  84.  
  85.     printf ("\nThank you for the information, it will be entered\n");
  86.     printf ("into the \"White Pages\" directory.\n");
  87. }
  88.  
  89. yes ()
  90. {
  91.     char str[99];
  92.  
  93.     while (1) {
  94.         printf ("(Yes or No): ");  fflush (stdout);
  95.         fgets (str, 99, stdin);
  96.         if (feof (stdin)) exit (0);
  97.         if (*str == 'Y' || *str == 'y')
  98.             return 1;
  99.         else if (*str == 'N' || *str == 'n')
  100.             return 0;
  101.         }
  102.     }
  103.     
  104.  
  105. iszip (str)
  106. char *str;
  107. {
  108.     char *p;
  109.  
  110.     upper (str);
  111.     if (strlen (str) == 5) {
  112.         for (p = str; *p; p++)
  113.             if (!isdigit (*p))
  114.                 return 0;
  115.         }
  116.     else if (strlen (str) == 6) {
  117.         if (!isalpha (str[0]) ||
  118.             !isdigit (str[1]) ||
  119.             !isalpha (str[2]) ||
  120.             !isdigit (str[3]) ||
  121.             !isalpha (str[4]) ||
  122.             !isdigit (str[5]))
  123.                 return 0;
  124.         }
  125.     else
  126.         return 0;
  127.     return 1;
  128.     }
  129.  
  130. caps (s)
  131. char *s;
  132. {
  133.     *s = toupper (*s);
  134.     s++;
  135.     while (*s) {
  136.         *s = tolower (*s);
  137.         s++;
  138.     }
  139. }
  140.