home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / fmtag210.zip / FMTAG.C < prev    next >
C/C++ Source or Header  |  1993-01-02  |  7KB  |  227 lines

  1. /*
  2.  
  3. FMTAG -- Force message area tagging of a specified area for the current user
  4.  
  5. Version 1.0   (1/02/93)
  6. Written by Bob Quinlan of Austin, Texas, USA
  7. Sysop of Red October at 512-834-2593 (1:382/111)
  8.  
  9. Copyright 1993 by Bob Quinlan
  10.  
  11. Compatible with Maximus 2.01
  12.  
  13.  
  14. FMTAG forces a message area to be tagged for the current user.  It will
  15. not do anything if the user does not already have a message tag record
  16. in the file, so if the user has never tagged any areas it will fail.  It
  17. requires you to supply the message area "number" for the area you want
  18. tagged.  Here are the parameters you can specify:
  19.  
  20.     /Llastuserfile  LastUser file to use.  Defaults to LASTUSER.BBS in
  21.                     the current directory.
  22.  
  23.     /Messagearea    Message area "number" to be tagged.  This must be
  24.                     supplied.
  25.  
  26.     /Ttagfile       Message Tag file to use.  Defaults to MTAG.BBS in
  27.                     the current directory.
  28.  
  29. Warning:  FMTAG does not check to see if the message area "number" you
  30. give it is valid.  Be careful to specify a valid "number" or you will
  31. add useless data to the MTAG.BBS file that Maximus will not remove.
  32. (Checking for a valid "number" would take longer than everything else
  33. put together, so it was left out in the interest of greater efficiency.)
  34.  
  35.  
  36. FMTAG returns ERRORLEVEL 0 after a successful run.  ERRORLEVEL 1
  37. indicates that the user does not yet have a message tag record in the
  38. file.  ERRORLEVEL 2 is returned to indicate an error.
  39.  
  40. NOTICE:  You may use, copy, and distribute this program freely as long
  41. as you insure that both the executable and the documentation (.DOC)
  42. files are included in the distribution package.  The source code does
  43. not need to be included.  You may modify this program and document, so
  44. long as reasonable credit is given to the original author if a
  45. substantial portion of the original remains intact.  The author is not
  46. responsible for any losses which may occur either directly or indirectly
  47. as a result of using this program.
  48.  
  49. This program uses the Maximus structures written by Scott J. Dudley.
  50.  
  51. HISTORY:
  52. Version 1.0   (1/02/93) -- Original release.  Written in Borland C.
  53.  
  54. Large memory model
  55. */
  56.  
  57. #include <ctype.h>
  58. #include <fcntl.h>
  59. #include <io.h>
  60. #include <share.h>
  61. #include <stdio.h>
  62. #include <stdlib.h>
  63. #include <string.h>
  64. #include <sys\stat.h>
  65. #include <mstruct.h>   /*  Maximus structures by Scott J. Dudley  */
  66.  
  67.  
  68. #define MAXPATH     (128)
  69. #define MAXAREA     (40)
  70. #ifndef FALSE
  71.     #define FALSE   0
  72.     #define TRUE    1
  73. #endif
  74.  
  75.  
  76. main(int argc, char *argv[])
  77. {
  78.     struct  _usr        lastuser;
  79.     struct  _tagdata    tagdata;
  80.  
  81.     char    lastuser_file[MAXPATH] = {"LASTUSER.BBS"};
  82.     int     lastuser_fh;
  83.     char    tag_file[MAXPATH] = {"MTAG.BBS"};
  84.     int     tag_fh;
  85.     char    area[MAXAREA+1] = {"\x1"};
  86.  
  87.     int     tagdata_len;
  88.  
  89.     int     match = FALSE;
  90.  
  91.     char    *ch;
  92.     int     i, j, k;
  93.  
  94.  
  95.     /***********/
  96.     /*  FMTAG  */
  97.     /***********/
  98.  
  99.     printf("FMTAG 1.0 -- Copyright 1992 by Bob Quinlan (1/02/93)\n");
  100.  
  101.     /*  Process switches  */
  102.     for (i = 1; i < argc; i++)
  103.     {
  104.         switch (tolower(argv[i][1]))
  105.         {
  106.             case 'l':  /*  lastuser file  */
  107.                 strcpy(lastuser_file, argv[i]+2);
  108.                 break;
  109.             case 'm':  /*  message area "number"  */
  110.                 /*  The first byte of area is the leading '\x1'  */
  111.                 strcpy(area+1, argv[i]+2);
  112.                 strupr(area+1);
  113.                 break;
  114.             case 't':  /*  tag file  */
  115.                 strcpy(tag_file, argv[i]+2);
  116.                 break;
  117.             default:
  118.                 fprintf(stderr, "Unknown switch: %s\n", argv[i]);
  119.                 break;
  120.         }
  121.     }
  122.  
  123.     /*  Check to see if a message area has been specified  */
  124.     if (area[1] == '\0')
  125.     {
  126.         fprintf(stderr, "No area to tag.  You must specify a /m parameter.\n");
  127.         exit(2);
  128.     }
  129.  
  130.     /*  Open the lastuser file  */
  131.     if ((lastuser_fh = sopen(lastuser_file, O_RDONLY | O_BINARY, SH_DENYNO))
  132.         == -1)
  133.     {
  134.         fprintf(stderr, "Unable to open %s\n", lastuser_file);
  135.         exit(2);
  136.     }
  137.  
  138.     /*  Read the user record  */
  139.     if (read(lastuser_fh, &lastuser, sizeof(struct _usr)) < sizeof(struct _usr))
  140.     {
  141.         fprintf(stderr, "Unable to read %s\n", lastuser_file);
  142.         exit(2);
  143.     }
  144.  
  145.     /*  Close the lastuser file  */
  146.     close(lastuser_fh);
  147.  
  148.     /*  Open the tag file  */
  149.     if ((tag_fh = sopen(tag_file, O_RDWR | O_BINARY, SH_DENYNO)) == -1)
  150.     {
  151.         fprintf(stderr, "Unable to open %s\n", tag_file);
  152.         exit(2);
  153.     }
  154.  
  155.     /*  Read the record size from the first record  */
  156.     if (read(tag_fh, &tagdata_len, sizeof(int)) < sizeof(int))
  157.     {
  158.         fprintf(stderr, "Unable to read %s\n", tag_file);
  159.         exit(2);
  160.     }
  161.     /*  If the record size is invalid assume the structure size  */
  162.     if (tagdata_len <= 0)
  163.     {
  164.         tagdata_len = sizeof(struct _tagdata);
  165.     }
  166.  
  167.     /*  Seek to the appropriate record of the tag file  */
  168.     lseek(tag_fh, (long)lastuser.lastread_ptr*tagdata_len, SEEK_SET);
  169.     /*  Read the current user's record from the tag file  */
  170.     if (read(tag_fh, &tagdata, sizeof(struct _tagdata)) <
  171.         sizeof(struct _tagdata))
  172.     {
  173.         printf("%s is not in %s\n", lastuser.name, tag_file);
  174.         printf("%s not tagged.\n", area+1);
  175.         exit(1);
  176.     }
  177.  
  178.     /*  Check to be sure the record names match  */
  179.     if (strcmpi(tagdata.name, lastuser.name) != 0)
  180.     {
  181.         printf("%s shows as \"%s\" in %s\n", lastuser.name, tagdata.name,
  182.             tag_file);
  183.         printf("%s not tagged.\n", area+1);
  184.         exit(1);
  185.     }
  186.  
  187.     /*  Scan through the tag data looking for the area to be forced  */
  188.     ch = tagdata.areas;
  189.     /*  Position to the next match  */
  190.     while ((ch = strstr(ch, area)) != NULL)
  191.     {
  192.         /*  Position to the end of the match  */
  193.         ch += strlen(area);
  194.         /*  Check to see if the match is complete  */
  195.         if ((ch[0] == '\x1') || (ch[0] == '\0'))
  196.         {
  197.             printf("%s already tagged.\n", area+1);
  198.             match = TRUE;
  199.         }
  200.     }
  201.  
  202.     /*  If no match was found tag the forced area  */
  203.     if (match == FALSE)
  204.     {
  205.         /*  Add the forced area to the end of the tag list data  */
  206.         strcpy(tagdata.areas+strlen(tagdata.areas), area);
  207.         /*  Lock the user's record of the tag file  */
  208.         lock(tag_fh, (long)lastuser.lastread_ptr*tagdata_len,
  209.             sizeof(struct _tagdata));
  210.         /*  Seek to the user's record  */
  211.         lseek(tag_fh, (long)lastuser.lastread_ptr*tagdata_len, SEEK_SET);
  212.         /*  Write the new tag list  */
  213.         write(tag_fh, &tagdata, sizeof(struct _tagdata));
  214.         /*  Unlock the user's record  */
  215.         unlock(tag_fh, (long)lastuser.lastread_ptr*tagdata_len,
  216.             sizeof(struct _tagdata));
  217.         printf("%s now tagged.\n", area+1);
  218.     }
  219.  
  220.     /*  Close the tag file  */
  221.     close(tag_fh);
  222.  
  223.     return 0;
  224. }
  225.  
  226.  
  227.