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

  1. /*
  2.  
  3. LISTED -- Checks to see if the current user is on a list
  4.  
  5. Version 1.1  (7/17/89)
  6. Written by Bob Quinlan of Austin, TX, USA
  7.  
  8. Copyright 1989 by Bob Quinlan
  9.  
  10. Compatible with GT versions 13 through 15
  11.  
  12.  
  13. This program is intended to be used with the MSGCHK program.  By default 
  14. it looks for the file MSGCHK.BBS in the GTPATH directory and checks to 
  15. see if the name of the current user appears in that file.  If the name 
  16. is listed it returns ERRORLEVEL 1, otherwise it returns ERRORLEVEL 0. By 
  17. checking the ERRORLEVEL you can have your batch file take different 
  18. actions depending on the outcome.  This gives you the freedom to set up 
  19. any messages, utilities, or stacked key codes you would like.  I use 
  20. MSGCHK to check for mail in my private-only area and then use LISTED and 
  21. STACKEY in the GTLOGON.BAT to put users directly into that message area 
  22. if they have messages waiting.
  23.  
  24. There are others ways of using the program.  For instance, LISTED will 
  25. accept any file name on the command line as the list to be checked (it 
  26. will look for the file in the GTPATH directory as well as in the default 
  27. directory or along the specified path).  This would allow you to run 
  28. MSGCHK several times on different message areas with different output 
  29. files, and then use LISTED to figure out which areas the user needs to 
  30. check.
  31.  
  32. LISTED can also be used with any other program which produces a user 
  33. list, such as WHOYOU.  You could use LISTED to check WHOYOU's orphan 
  34. list when a new user logs in to see whether there were already messages 
  35. waiting.  I imagine there are many other possibilities.
  36.  
  37. NOTICE:  You may use, copy, and distribute this program freely as long 
  38. as you insure that both the executable and the documentation (.DOC) 
  39. files are included in the distribution package.  The source code does 
  40. not need to be included.  You may modify this program and document, so 
  41. long as reasonable credit is given to the original author if a 
  42. substantial portion of the original remains intact.  The author is not 
  43. responsible for any losses which may occur either directly or indirectly 
  44. as a result of using this program.
  45.  
  46. HISTORY:
  47. Version 1.1   (7/17/89) -- Changed default list file to MSGCHK.BBS.  
  48.                            Modified the procedure for locating the list 
  49.                            file.
  50. Version 1.0   (7/13/89) -- Original release.  Written in Turbo C.
  51.  
  52. */
  53.  
  54. #include <stdio.h>
  55. #include <stdlib.h>
  56. #include <string.h>
  57. #include <ctype.h>
  58.  
  59. #define MAXLINE 256
  60. #define MAXPATH 128
  61. #define PARAMS    8
  62.  
  63.  
  64. /************/
  65. /*  LISTED  */
  66. /************/
  67.  
  68. main(int argc, char *argv[])
  69. {
  70. char    gtpath[MAXPATH];
  71.  
  72. char    fields[MAXLINE];
  73. char    *gtuser[PARAMS];
  74. int    arg;
  75.  
  76. char    data[MAXLINE];
  77.  
  78. char    gtuser_fn[MAXPATH];
  79. FILE    *gtuser_fp;
  80.  
  81. char    list_temp[MAXPATH];
  82. char    list_fn[MAXPATH];
  83. FILE    *list_fp;
  84.  
  85. size_t    offset;
  86.  
  87. char    *c;
  88. int    i;
  89.  
  90.  
  91. printf("LISTED 1.1 -- Copyright 1989 by Bob Quinlan (7/17/89)\n");
  92.  
  93. /*  Read and adapt GTPATH  */
  94. strcpy(gtpath, getenv("GTPATH"));
  95. i = strlen(gtpath);
  96. if (--i >= 0)
  97.     if ((gtpath[i] != '\\') && (gtpath[i] != ':'))
  98.     strcat(gtpath, "\\");
  99.  
  100. /*  Read in values from GTUSER.BBS  */
  101. strcpy(gtuser_fn, gtpath);
  102. strcat(gtuser_fn, "GTUSER.BBS");
  103. if ((gtuser_fp = fopen(gtuser_fn, "r")) == NULL)
  104.     {
  105.     fprintf(stderr, "LISTED: Unable to open %s\n", gtuser_fn);
  106.     exit(1);
  107.     }
  108. if (fgets(fields, MAXLINE, gtuser_fp) == NULL)
  109.     {
  110.     fprintf(stderr, "LISTED: Unable to read %s\n", gtuser_fn);
  111.     exit(1);
  112.     }
  113. fclose(gtuser_fp);
  114.  
  115. /*  Parse access level and name from GTUSER.BBS  */
  116. arg = 0;
  117. gtuser[arg] = strtok(fields, " \n");
  118. while (!isupper(gtuser[arg][1]))
  119.     gtuser[++arg] = strtok(NULL, " \n");
  120.  
  121. /*  Reassemble username into one string  */
  122. for (i=2; i<arg; i++)
  123.     *(gtuser[i]-1) = ' ';
  124.  
  125. /*  Open the list file  */
  126. if (argc > 1)
  127.     strcpy(list_fn, argv[1]);
  128. else
  129.     strcpy(list_fn, "MSGCHK.BBS");
  130. strcat(gtpath, list_fn);
  131. if ((list_fp = fopen(gtpath, "r")) == NULL)
  132.     if ((list_fp = fopen(list_fn, "r")) == NULL)
  133.     {
  134.     fprintf(stderr, "LISTED: Unable to open %s\n", list_fp);
  135.     exit(1);
  136.     }
  137.  
  138. /*  Search list for this user  */
  139. while (fgets(data, MAXLINE, list_fp) != NULL)
  140.     {
  141.     /*  Ignore initial whitespace and final newline  */
  142.     offset = strspn(data, " \t");
  143.     c = strchr(data+offset, '\n');
  144.     if (c != NULL)
  145.     *c = '\0';
  146.     /*  Compare names  */
  147.     if (strcmpi(gtuser[1], data+offset) == 0)
  148.     {
  149.     printf("User in list.\n");
  150.     fclose(list_fp);
  151.     exit(1);
  152.     }
  153.     }
  154. printf("User not in list.\n");
  155. fclose(list_fp);
  156.  
  157. return 0;
  158. }
  159.