home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / TRIBBS / TBAPI501.ZIP / DEMO2.C < prev    next >
Text File  |  1994-01-04  |  5KB  |  155 lines

  1. /*
  2.     demo2.c - TriBBS API Demo Program
  3.     Copyright (c) 1994 By TriSoft
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <time.h>
  9. #include <ctype.h>
  10. #include <share.h>
  11. #include "tbapi.h"
  12.  
  13. void main(int argc, char **argv)
  14. {
  15.     SHORT i, privateflag, conferencenumber, nlines, cflag;
  16.     USHORT ilength, olength;
  17.     char line[256], recipientsname[81], filename[81];
  18.     unsigned char *inbuffer, *outbuffer, *workbuffer, *ibuffer;
  19.     FILE *file;
  20.  
  21.     /* Display opening screen */
  22.     printf("TBAPI Demo Program No. 2 1.0\n");
  23.     printf("Copyright (c) 1994 By TriSoft\n\n");
  24.  
  25.     if (argc < 5) {
  26.         printf("Use as:\n\n");
  27.         printf("DEMO2 \"name\" privateflag conferencenumber file\n\n");
  28.         printf("Where:\n\n");
  29.         printf("\"name\"               is the name of the recipient.\n");
  30.         printf("privateflag          is 'Y' for a private message, 'N' for a\n");
  31.         printf("                     public message.\n");
  32.         printf("conference number    is the number of the conference the message is\n");
  33.         printf("                     to be posted to.\n");
  34.         printf("file                 name of the file to be imported.\n");
  35.         exit(1);
  36.     }
  37.     strcpy(recipientsname, argv[1]);
  38.     TBStripSpaces(recipientsname);
  39.     TBInitialCaps(recipientsname);
  40.     if (toupper(*argv[2]) == 'Y')
  41.         privateflag = TRUE;
  42.     else
  43.         privateflag = FALSE;
  44.     conferencenumber = atoi(argv[3]);
  45.     strcpy(filename, argv[4]);
  46.  
  47.     /* Open SYSDAT2.DAT and point the API to Node 1's main directory */
  48.     TBReadSYSDAT2DAT();
  49.     strcpy(Node1sMainDirectory, SysDat2Data.Node1sMainDirectory);
  50.  
  51.     /* Initialize the TriBBS API */
  52.     TBInitialize();
  53.  
  54.     /* Abort if invalid message conference */
  55.     if (conferencenumber < 1 || conferencenumber > NumberOfMessageAreas)
  56.         TBErrorRoutine("Invalid conference number!\n");
  57.  
  58.     /* Allocate the buffers needed for compression */
  59.     inbuffer = (unsigned char *)malloc(40000U);
  60.     outbuffer = (unsigned char *)malloc(40000U);
  61.     workbuffer = (unsigned char *)malloc(40000U);
  62.  
  63.     if ((file = fopen(filename, "rt")) == NULL)
  64.         TBErrorRoutine("Unable to open: %s\n", strupr(filename));
  65.  
  66.     ilength = 0;
  67.     ibuffer = inbuffer;
  68.     *ibuffer = 0;
  69.     nlines = 0;
  70.     while (!feof(file)) {
  71.         if (fgets(line, 256, file) == NULL)
  72.             break;
  73.         TBStripNewline(line);
  74.         if (!(*line))
  75.             strcpy(line, " ");
  76.         if (ilength + strlen(line) + 1 >= 40000U)
  77.             break;
  78.         strcpy((char *)ibuffer, line);
  79.         ibuffer += strlen(line) + 1;
  80.         ilength += strlen(line) + 1;
  81.         nlines++;
  82.         if (nlines == 200)
  83.             break;
  84.     }
  85.     fclose(file);
  86.     olength = TBCompress(inbuffer, ilength, outbuffer, workbuffer);
  87.     TBOpenMnnnnTXT(conferencenumber);
  88.     fseek(MTxtFile, 0L, SEEK_END);
  89.     MPtrData.OffsetIntoTextFile = ftell(file);
  90.     if (olength < ilength) {
  91.         fswrite(&olength, sizeof(olength), 1, MTxtFile);
  92.         cflag = COMPRESSED;
  93.         fswrite(&cflag, sizeof(cflag), 1, MTxtFile);
  94.         fswrite(outbuffer, olength, 1, MTxtFile);
  95.     }
  96.     else {
  97.         fswrite(&ilength, sizeof(ilength), 1, MTxtFile);
  98.         cflag = UNCOMPRESSED;
  99.         fswrite(&cflag, sizeof(cflag), 1, MTxtFile);
  100.         fswrite(inbuffer, ilength, 1, MTxtFile);
  101.     }
  102.     fclose(MTxtFile);            
  103.     TBOpenMCONFDAT();
  104.     TBReadMCONFDAT(conferencenumber);
  105.     MConfData.HighestMessageNumber++;
  106.     TBWriteMCONFDAT(conferencenumber);
  107.     fclose(MConfFile);
  108.     _strdate(line);
  109.     strcpy(MPtrData.DateAndTime, line);
  110.     strcat(MPtrData.DateAndTime, " ");
  111.     _strtime(line);
  112.     line[5] = 0;
  113.     strcat(MPtrData.DateAndTime, line);
  114.     strcpy(MPtrData.From, "Cdemo2");
  115.     strcpy(MPtrData.To, recipientsname);
  116.     strcpy(MPtrData.Subject, "A Sample of CDEMO2");
  117.     MPtrData.EchoMessageFlag = MConfData.NetworkedConferenceFlag;
  118.     MPtrData.ThreadedMessageFlag = FALSE;
  119.     MPtrData.PrivateMessageFlag = privateflag;
  120.     MPtrData.DeletedMessageFlag = FALSE;
  121.     MPtrData.ReceivedMessageFlag = FALSE;
  122.     MPtrData.PermanentMessageFlag = FALSE;
  123.     MPtrData.NetMailFromZone = 0;
  124.     MPtrData.NetMailFromNet = 0;
  125.     MPtrData.NetMailFromNode = 0;
  126.     MPtrData.NetMailFromPoint = 0;
  127.     MPtrData.NetMailToZone = 0;
  128.     MPtrData.NetMailToNet = 0;
  129.     MPtrData.NetMailToNode = 0;
  130.     MPtrData.NetMailToPoint = 0;
  131.     MPtrData.Number = MConfData.HighestMessageNumber;
  132.     MPtrData.NumberOfMessageThisRepliesTo = 0;
  133.     *MPtrData.NameOfAttachedFile = 0;
  134.     MIdxData.FromCRC = TBStrCrc32(MPtrData.From);
  135.     MIdxData.ToCRC = TBStrCrc32(MPtrData.To);
  136.     MIdxData.Number = MPtrData.Number;
  137.     MIdxData.NumberOfMessageThisRepliesTo = 0;
  138.     TBOpenMnnnnPTR(conferencenumber);
  139.     TBOpenMnnnnIDX(conferencenumber);
  140.     i = TBNumberInMnnnnPTR() + 1;
  141.     TBWriteMnnnnPTR(i);
  142.     TBWriteMnnnnIDX(i);
  143.     fclose(MPtrFile);
  144.     fclose(MIdxFile);
  145.     TBUpdateFromAndTo(MIdxData.FromCRC, MIdxData.ToCRC, conferencenumber);
  146.     TBReadSYSDAT1DAT();
  147.     SysDat1Data.MessagesToday++;
  148.     TBWriteSYSDAT1DAT();
  149.     fcloseall();
  150.     printf("Message Inserted into Message Base!\n");
  151.     exit(0);
  152. }
  153.  
  154. 
  155.