home *** CD-ROM | disk | FTP | other *** search
- /*
-
- LISTED -- Checks to see if the current user is on a list
-
- Version 1.1 (7/17/89)
- Written by Bob Quinlan of Austin, TX, USA
-
- Copyright 1989 by Bob Quinlan
-
- Compatible with GT versions 13 through 15
-
-
- This program is intended to be used with the MSGCHK program. By default
- it looks for the file MSGCHK.BBS in the GTPATH directory and checks to
- see if the name of the current user appears in that file. If the name
- is listed it returns ERRORLEVEL 1, otherwise it returns ERRORLEVEL 0. By
- checking the ERRORLEVEL you can have your batch file take different
- actions depending on the outcome. This gives you the freedom to set up
- any messages, utilities, or stacked key codes you would like. I use
- MSGCHK to check for mail in my private-only area and then use LISTED and
- STACKEY in the GTLOGON.BAT to put users directly into that message area
- if they have messages waiting.
-
- There are others ways of using the program. For instance, LISTED will
- accept any file name on the command line as the list to be checked (it
- will look for the file in the GTPATH directory as well as in the default
- directory or along the specified path). This would allow you to run
- MSGCHK several times on different message areas with different output
- files, and then use LISTED to figure out which areas the user needs to
- check.
-
- LISTED can also be used with any other program which produces a user
- list, such as WHOYOU. You could use LISTED to check WHOYOU's orphan
- list when a new user logs in to see whether there were already messages
- waiting. I imagine there are many other possibilities.
-
- NOTICE: You may use, copy, and distribute this program freely as long
- as you insure that both the executable and the documentation (.DOC)
- files are included in the distribution package. The source code does
- not need to be included. You may modify this program and document, so
- long as reasonable credit is given to the original author if a
- substantial portion of the original remains intact. The author is not
- responsible for any losses which may occur either directly or indirectly
- as a result of using this program.
-
- HISTORY:
- Version 1.1 (7/17/89) -- Changed default list file to MSGCHK.BBS.
- Modified the procedure for locating the list
- file.
- Version 1.0 (7/13/89) -- Original release. Written in Turbo C.
-
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
-
- #define MAXLINE 256
- #define MAXPATH 128
- #define PARAMS 8
-
-
- /************/
- /* LISTED */
- /************/
-
- main(int argc, char *argv[])
- {
- char gtpath[MAXPATH];
-
- char fields[MAXLINE];
- char *gtuser[PARAMS];
- int arg;
-
- char data[MAXLINE];
-
- char gtuser_fn[MAXPATH];
- FILE *gtuser_fp;
-
- char list_temp[MAXPATH];
- char list_fn[MAXPATH];
- FILE *list_fp;
-
- size_t offset;
-
- char *c;
- int i;
-
-
- printf("LISTED 1.1 -- Copyright 1989 by Bob Quinlan (7/17/89)\n");
-
- /* Read and adapt GTPATH */
- strcpy(gtpath, getenv("GTPATH"));
- i = strlen(gtpath);
- if (--i >= 0)
- if ((gtpath[i] != '\\') && (gtpath[i] != ':'))
- strcat(gtpath, "\\");
-
- /* Read in values from GTUSER.BBS */
- strcpy(gtuser_fn, gtpath);
- strcat(gtuser_fn, "GTUSER.BBS");
- if ((gtuser_fp = fopen(gtuser_fn, "r")) == NULL)
- {
- fprintf(stderr, "LISTED: Unable to open %s\n", gtuser_fn);
- exit(1);
- }
- if (fgets(fields, MAXLINE, gtuser_fp) == NULL)
- {
- fprintf(stderr, "LISTED: Unable to read %s\n", gtuser_fn);
- exit(1);
- }
- fclose(gtuser_fp);
-
- /* Parse access level and name from GTUSER.BBS */
- arg = 0;
- gtuser[arg] = strtok(fields, " \n");
- while (!isupper(gtuser[arg][1]))
- gtuser[++arg] = strtok(NULL, " \n");
-
- /* Reassemble username into one string */
- for (i=2; i<arg; i++)
- *(gtuser[i]-1) = ' ';
-
- /* Open the list file */
- if (argc > 1)
- strcpy(list_fn, argv[1]);
- else
- strcpy(list_fn, "MSGCHK.BBS");
- strcat(gtpath, list_fn);
- if ((list_fp = fopen(gtpath, "r")) == NULL)
- if ((list_fp = fopen(list_fn, "r")) == NULL)
- {
- fprintf(stderr, "LISTED: Unable to open %s\n", list_fp);
- exit(1);
- }
-
- /* Search list for this user */
- while (fgets(data, MAXLINE, list_fp) != NULL)
- {
- /* Ignore initial whitespace and final newline */
- offset = strspn(data, " \t");
- c = strchr(data+offset, '\n');
- if (c != NULL)
- *c = '\0';
- /* Compare names */
- if (strcmpi(gtuser[1], data+offset) == 0)
- {
- printf("User in list.\n");
- fclose(list_fp);
- exit(1);
- }
- }
- printf("User not in list.\n");
- fclose(list_fp);
-
- return 0;
- }