home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsf / gsm / GSM / qpage_c < prev    next >
Encoding:
Text File  |  1995-06-05  |  1.6 KB  |  91 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. extern int getpid();
  7.  
  8. #define        MSGDIR    "/var/spool/pager"
  9.  
  10. int main(argc, argv)
  11.      int argc;
  12.      char **argv;
  13. {
  14.     int i;
  15.     char buffer1[1024];
  16.     char buffer2[1024];
  17.     char number[33];
  18.     char message[161];
  19.     int mypid = getpid();
  20.     FILE *fh;
  21.  
  22.     if (argc != 3)
  23.     {
  24.     fprintf(stderr, "Usage: %s <phone number> \"<message>\"\n", argv[0]);
  25.     exit(1);
  26.     }
  27.  
  28.     for(i=0; argv[1][i] != 0; i++)
  29.     {
  30.     if (!isdigit(argv[1][i]))
  31.     {
  32.         fprintf(stderr, "%s: The phone number must only contain digits.\n", argv[0]);
  33.         exit(1);
  34.     }
  35.     }
  36.  
  37.     if (argv[1][0] == '0')
  38.     {
  39.     strcpy(number, "44");
  40.     strcat(number, argv[1]+1);
  41.     }
  42.     else
  43.     {
  44.     strcpy(number, argv[1]);
  45.     }
  46.  
  47.     if (i > 32)
  48.     {
  49.     fprintf(stderr, "%s: The phone number must be less than 32 digits\n", argv[0]);
  50.     exit(1);
  51.     }
  52.  
  53.     if (strlen(argv[2]) >= 160)
  54.     {
  55.     fprintf(stderr, "%s: The message must be less than 160 characters long\n", argv[0]);
  56.     exit(1);
  57.     }
  58.  
  59.     for(i=0; argv[2][i] != 0; i++)
  60.     {
  61.     if (iscntrl(argv[2][i]))
  62.         message[i] = ' ';
  63.     else
  64.         message[i] = argv[2][i];
  65.     }
  66.     message[i] = 0;
  67.  
  68.     sprintf(buffer1, "%s/.%d", MSGDIR, mypid);
  69.     sprintf(buffer2, "%s/%06d%08lx", MSGDIR, mypid, time(0));
  70.  
  71.     fh = fopen(buffer1, "w");
  72.     
  73.     if (fh == NULL)
  74.     {
  75.     fprintf(stderr, "%s: Could not open message output file\n", argv[0]);
  76.     exit(1);
  77.     }
  78.  
  79.     fprintf(fh, "%s\n%s\n", number, message);
  80.  
  81.     fclose(fh);
  82.  
  83.     if (rename(buffer1, buffer2) < 0)
  84.     {
  85.     perror("Rename failed");
  86.     exit(1);
  87.     }
  88.  
  89.     return 0;
  90. }
  91.