home *** CD-ROM | disk | FTP | other *** search
/ The CIA World Factbook 1992 / k3bimage.iso / sel / 02 / 0036 / msgchk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  5.2 KB  |  176 lines

  1. /*
  2.  
  3. MSGCHK -- Lists all users with unread messages in a specified area
  4.  
  5. Version 1.2  (8/7/89)
  6. Written by Bob Quinlan of Austin, TX, USA
  7.  
  8. Copyright 1989 by Bob Quinlan
  9.  
  10. Compatible with GT version 15
  11.  
  12.  
  13. This program checks through a specified message area and makes a list of
  14. all users with unread messages.  The path to the area you want checked
  15. must be specified as the first parameter on the command line.  The 
  16. second parameter should begin with a plus sign (+) if you want the 
  17. results appended to an existing list.  This option makes it easy to scan 
  18. multiple areas by running MSGCHK on each area and using the + on all 
  19. except the first.  If you want the list written to some particular file 
  20. you can specify that as the second parameter on the command line (after 
  21. the + and without any spaces between if you are using that option).  If 
  22. no output file is specified the list will be written to MSGCHK.BBS in 
  23. the GTPATH directory.  The program normally returns ERRORLEVEL 0.  If 
  24. any errors occur it will return ERRORLEVEL 1.
  25.  
  26. Here are a few examples along with what they do:
  27.  
  28.     MSGCHK C:\GT\GENERAL
  29.  
  30.        This will scan the general area and create a new list under the 
  31.        name MSGCHK.BBS in the GTPATH directory.
  32.  
  33.     MSGCHK C:\GT\GENERAL
  34.     MSGCHK C:\GT\NETMAIL +
  35.  
  36.         These two calls will create a combined list of users with 
  37.         messages in either the general or the netmail areas.  The 
  38.         results will be stored in MSGCHK.BBS in the GTPATH directory.
  39.  
  40.     MSGCHK C:\GT\GENERAL C:\GT\EXTRAS\MESSAGES.LST
  41.  
  42.         This will scan the general area and create a new list under the 
  43.         name MESSAGES.LST in the C:\GT\EXTRAS directory.
  44.  
  45.     MSGCHK C:\GT\GENERAL C:\GT\EXTRAS\MESSAGES.LST
  46.     MSGCHK C:\GT\NETMAIL +C:\GT\EXTRAS\MESSAGES.LST
  47.  
  48.         These two calls will create a combined list of users with 
  49.         messages in either the general or the netmail areas.  The 
  50.         results will be stored in MESSAGES.LST in the C:\GT\EXTRAS 
  51.         directory.
  52.  
  53. NOTICE:  You may use, copy, and distribute this program freely as long
  54. as you insure that both the executable and the documentation (.DOC)
  55. files are included in the distribution package.  The source code does
  56. not need to be included.  You may modify this program and document, so
  57. long as reasonable credit is given to the original author if a
  58. substantial portion of the original remains intact.  The author is not
  59. responsible for any losses which may occur either directly or indirectly
  60. as a result of using this program.
  61.  
  62. HISTORY:
  63. Version 1.2   (8/7/89)  -- Added output file appending to support scans 
  64.                            of multiple areas.
  65. Version 1.1   (7/22/89) -- Fixed bug that would fail to recognize unread
  66.                            messages with funny received fields.
  67. Version 1.0   (7/17/89) -- Original release.  Written in Turbo C.
  68.  
  69. */
  70.  
  71. #include <stdio.h>
  72. #include <stdlib.h>
  73. #include <string.h>
  74. #include "dram.h"    /*  From the GT Developer's Toolkit  */
  75.  
  76. #define MAXLINE        128
  77. #define MAXMODE        4
  78.  
  79.  
  80. /************/
  81. /*  MSGCHK  */
  82. /************/
  83.  
  84. main(int argc, char *argv[])
  85. {
  86. struct msg_record msg;
  87.  
  88. char   msgfn[MAXLINE];
  89. FILE   *msgfp;
  90.  
  91. char   outfn[MAXLINE];
  92. char   outmode[MAXMODE];
  93. FILE   *outfp;
  94.  
  95. int    i;
  96.  
  97.  
  98. printf("MSGCHK 1.2 -- Copyright 1989 by Bob Quinlan (8/7/89)\n");
  99.  
  100. /*  Check for message area path on command line  */
  101. if (argc < 2)
  102.     {
  103.     fprintf(stderr, "MSGCHK: No message area specified on command line\n");
  104.     exit(1);
  105.     }
  106. strcpy(msgfn, argv[1]);
  107. /*  Add final backslash to path if not already present  */
  108. i = strlen(msgfn);
  109. if (--i >= 0)
  110.     if ((msgfn[i] != '\\') && (msgfn[i] != ':'))
  111.     strcat(msgfn, "\\");
  112. /*  Append the message control file name  */
  113. strcat(msgfn, "MESSAGE.CTL");
  114. /*  Open the message file  */
  115. if ((msgfp = fopen(msgfn, "rb")) == NULL)
  116.     {
  117.     fprintf(stderr, "MSGCHK: Unable to open %s for input\n", msgfn);
  118.     exit(1);
  119.     }
  120.  
  121. /*  Check for output file on command line  */
  122. if (argc > 2)
  123.     if (*argv[2] == '+')
  124.     {
  125.     strcpy(outfn, argv[2]+1);
  126.     strcpy(outmode, "a");
  127.     }
  128.     else
  129.     {
  130.     strcpy(outfn, argv[2]);
  131.     strcpy(outmode, "w");
  132.     }
  133. else
  134.     {
  135.     *outfn = '\0';
  136.     strcpy(outmode, "w");
  137.     }
  138. if (*outfn == '\0')
  139.     /*  If not specified write to MSGCHK.BBS in the GTPATH directory  */
  140.     {
  141.     /*  Get the GTPATH value from the environment  */
  142.     strcpy(outfn, getenv("GTPATH"));
  143.     /*  Add final backslash to path if not already present  */
  144.     i = strlen(outfn);
  145.     if (--i >= 0)
  146.     if ((outfn[i] != '\\') && (outfn[i] != ':'))
  147.         strcat(outfn, "\\");
  148.     /*  Append the default output file name  */
  149.     strcat(outfn, "MSGCHK.BBS");
  150.     }
  151. if ((outfp = fopen(outfn, outmode)) == NULL)
  152.     {
  153.     fprintf(stderr, "MSGCHK: Unable to open %s for output\n", outfn);
  154.     exit(1);
  155.     }
  156.  
  157. /*  Skip the control record  */
  158. fread(&msg, sizeof(struct msg_record), 1, msgfp);
  159. /*  Scan for unread messages  */
  160. while (fread(&msg, sizeof(struct msg_record), 1, msgfp) > 0)
  161.     {
  162.     if ((msg.msg_deleted == 0) && ((msg.msg_received & 0x11) == 0))
  163.     {
  164.     fputs(msg.msg_addressee, outfp);
  165.     fputc('\n', outfp);
  166.     }
  167.     }
  168.  
  169. /*  Close the output file  */
  170. fclose(outfp);
  171. /*  Close the message file  */
  172. fclose(msgfp);
  173.  
  174. return 0;
  175. }
  176.