home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / TRIBBS / TBAPI501.ZIP / DEMO1.C next >
Text File  |  1994-01-04  |  2KB  |  85 lines

  1. /*
  2.     demo1.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 <conio.h>
  9. #include <share.h>
  10. #include "tbapi.h"
  11.  
  12. void main(int argc, char **argv)
  13. {
  14.     SHORT i, j, conferencenumber, compressionflag, numberofmessages;
  15.     USHORT l, inbufferlength;
  16.     unsigned char *inbuffer, *outbuffer, *workbuffer;
  17.  
  18.     /* Display opening screen */
  19.     printf("TBAPI Demo Program No. 1 1.0\n");
  20.     printf("Copyright (c) 1994 By TriSoft\n\n");
  21.  
  22.     if (argc < 2) {
  23.         printf("Use as:\n\n");
  24.         printf("DEMO1 conferencenumber\n\n");
  25.         printf("Where:\n\n");
  26.         printf("conferencenumber    is the number of the message conference.\n");
  27.         exit(1);
  28.     }
  29.     conferencenumber = atoi(argv[1]);
  30.     
  31.     /* Open SYSDAT2.DAT and point the API to Node 1's main directory */
  32.     TBReadSYSDAT2DAT();
  33.     strcpy(Node1sMainDirectory, SysDat2Data.Node1sMainDirectory);
  34.  
  35.     /* Initialize the TriBBS API */
  36.     TBInitialize();
  37.  
  38.     /* Allocate the buffers need to perform compression */
  39.     inbuffer = (unsigned char *)malloc(40000U);
  40.     outbuffer = (unsigned char *)malloc(40000U);
  41.     workbuffer = (unsigned char *)malloc(40000U);
  42.  
  43.     /* Get the conference's MCONF.DAT record */
  44.     TBOpenMCONFDAT();
  45.     TBReadMCONFDAT(conferencenumber);
  46.     fclose(MConfFile);
  47.     printf("Reading Conference: %s\n\n", MConfData.ConferenceName);
  48.  
  49.     TBOpenMnnnnPTR(conferencenumber);
  50.     numberofmessages = TBNumberInMnnnnPTR();
  51.     TBOpenMnnnnTXT(conferencenumber);
  52.     for (i = 0; i < numberofmessages; i++) {
  53.         fsread(&inbufferlength, sizeof(USHORT), 1, MTxtFile);
  54.         fsread(&compressionflag, sizeof(SHORT), 1, MTxtFile);
  55.         fsread(inbuffer, inbufferlength, 1, MTxtFile);
  56.         if (compressionflag)
  57.             l = TBUncompress(inbuffer, inbufferlength, outbuffer, workbuffer);
  58.         else {
  59.             memmove(outbuffer, inbuffer, inbufferlength);
  60.             l = inbufferlength;
  61.         }
  62.         printf("Message %d of %d\n", i + 1, numberofmessages);
  63.         for (j = 0; j < l; j++) {
  64.             if (outbuffer[j])
  65.                 putch(outbuffer[j]);
  66.             else
  67.                 printf("\n");
  68.         }
  69.         printf("\n\n");
  70.         while (!kbhit()) ;
  71.         switch (getch()) {
  72.             case 0:
  73.                 getch();
  74.                 break;
  75.             case 27:
  76.                 fclose(MTxtFile);
  77.                 fclose(MPtrFile);
  78.                 exit(0);
  79.         }
  80.     }
  81.     fclose(MTxtFile);
  82.     fclose(MPtrFile);
  83.     exit(0);
  84. }
  85.