home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mag&info / jamapi.zip / HMB2JAM.ARJ / HMBSUB.C < prev    next >
C/C++ Source or Header  |  1993-07-01  |  4KB  |  173 lines

  1. /*
  2. **  JAM(mbp) - The Joaquim-Andrew-Mats Message Base Proposal
  3. **
  4. **  HMB to JAM converter
  5. **
  6. **  Written by Mats Wallin
  7. **
  8. **  ----------------------------------------------------------------------
  9. **
  10. **  hmbsub.c (JAMmb)
  11. **
  12. **  Common HMB routines used for the HMB2JAM program
  13. **
  14. **  Copyright 1993 Joaquim Homrighausen, Andrew Milner, Mats Birch, and
  15. **  Mats Wallin. ALL RIGHTS RESERVED.
  16. **
  17. **  93-06-28    MW
  18. **  Initial coding.
  19. */
  20.  
  21. #include <io.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25.  
  26. #ifdef __TURBOC__
  27. #include <dos.h>
  28. #else
  29. #include <time.h>
  30. #endif
  31.  
  32. #include "jammb.h"
  33. #include "hmbsub.h"
  34.  
  35.  
  36. /* ---------------------------------------------------------------------- *
  37.  *
  38.  *  HmbClose
  39.  *
  40.  * ---------------------------------------------------------------------- */
  41.  
  42. int HmbClose( HMBREC * pHmb )
  43. {
  44.   if( pHmb->InfoHandle  != -1 ) JAMsysClose( NULL, pHmb->InfoHandle );
  45.   if( pHmb->IdxHandle   != -1 ) JAMsysClose( NULL, pHmb->IdxHandle );
  46.   if( pHmb->ToidxHandle != -1 ) JAMsysClose( NULL, pHmb->ToidxHandle );
  47.   if( pHmb->HdrHandle   != -1 ) JAMsysClose( NULL, pHmb->HdrHandle );
  48.   if( pHmb->TxtHandle   != -1 ) JAMsysClose( NULL, pHmb->TxtHandle );
  49.  
  50.   return( 1 );
  51. }
  52.  
  53.  
  54. /* ---------------------------------------------------------------------- *
  55.  *
  56.  *  HmbOpen
  57.  *
  58.  * ---------------------------------------------------------------------- */
  59.  
  60. int HmbOpen( HMBREC * pHmb, int OpenMode, int ShareMode )
  61. {
  62.   if(( pHmb->InfoHandle  = JAMsysSopen( NULL, "MSGINFO.BBS",  OpenMode, ShareMode )) == -1 ||
  63.      ( pHmb->IdxHandle   = JAMsysSopen( NULL, "MSGIDX.BBS",   OpenMode, ShareMode )) == -1 ||
  64.      ( pHmb->ToidxHandle = JAMsysSopen( NULL, "MSGTOIDX.BBS", OpenMode, ShareMode )) == -1 ||
  65.      ( pHmb->HdrHandle   = JAMsysSopen( NULL, "MSGHDR.BBS",   OpenMode, ShareMode )) == -1 ||
  66.      ( pHmb->TxtHandle   = JAMsysSopen( NULL, "MSGTXT.BBS",   OpenMode, ShareMode )) == -1 )
  67.     {
  68.     perror( "Unable to open one or more of the HMB files" );
  69.  
  70.     HmbClose( pHmb );
  71.     return( 0 );
  72.     }
  73.  
  74.   JAMsysRead( NULL, pHmb->InfoHandle, &pHmb->Info, sizeof( HMBINFO ));
  75.  
  76.   return( 1 );
  77. }
  78.  
  79.  
  80. /* ---------------------------------------------------------------------- *
  81.  *
  82.  *  HmbReadFirstHdr
  83.  *
  84.  * ---------------------------------------------------------------------- */
  85.  
  86. int HmbReadFirstHdr( HMBREC * pHmb )
  87. {
  88.   JAMsysSeek( NULL, pHmb->HdrHandle, JAMSEEK_SET, 0L );
  89.  
  90.   return( HmbReadNextHdr( pHmb ));
  91. }
  92.  
  93.  
  94. /* ---------------------------------------------------------------------- *
  95.  *
  96.  *  HmbReadNextHdr
  97.  *
  98.  * ---------------------------------------------------------------------- */
  99.  
  100. int HmbReadNextHdr( HMBREC * pHmb )
  101. {
  102.   INT32   Len;
  103.  
  104.   if(( Len = JAMsysRead( NULL, pHmb->HdrHandle, &pHmb->Hdr, sizeof( HMBHDR ))) != sizeof( HMBHDR ))
  105.     {
  106.     if( Len != 0L )
  107.       puts( "Error reading the HMB header file" );
  108.     return( 1 );
  109.     }
  110.  
  111.   return( 0 );
  112. }
  113.  
  114.  
  115. /* ---------------------------------------------------------------------- *
  116.  *
  117.  *  InitHMBREC
  118.  *
  119.  * ---------------------------------------------------------------------- */
  120.  
  121. int InitHMBREC( HMBREC * pHmbRec )
  122. {
  123.   memset( pHmbRec, '\0', sizeof( HMBREC ));
  124.  
  125.   pHmbRec->InfoHandle = -1,
  126.     pHmbRec->IdxHandle = -1,
  127.       pHmbRec->ToidxHandle = -1,
  128.         pHmbRec->HdrHandle = -1,
  129.           pHmbRec->TxtHandle = -1;
  130.  
  131.   return( 1 );
  132. }
  133.  
  134.  
  135. /* ---------------------------------------------------------------------- *
  136.  *
  137.  *  Pascal2C
  138.  *
  139.  * ---------------------------------------------------------------------- */
  140.  
  141. CHAR8 * Pascal2C( CHAR8 * PascalStr, CHAR8 * CStr )
  142. {
  143.   memcpy( CStr, PascalStr, PascalStr [-1] );
  144.   CStr [PascalStr [-1]] = '\0';
  145.  
  146.   return( CStr );
  147. }
  148.  
  149.  
  150. /* ---------------------------------------------------------------------- *
  151.  *
  152.  *  HmbDateTimeToUnix
  153.  *
  154.  * ---------------------------------------------------------------------- */
  155.  
  156. UINT32 HmbDateTimeToUnix( CHAR8 * pDate, CHAR8 * pTime )
  157. {
  158.   struct JAMtm    TM;
  159.  
  160.   memset( &TM, '\0', sizeof( TM ));
  161.  
  162.   TM.tm_year = atoi( pDate + 6 );
  163.   TM.tm_mon  = atoi( pDate     ) - 1;
  164.   TM.tm_mday = atoi( pDate + 3 );
  165.   TM.tm_hour = atoi( pTime     );
  166.   TM.tm_min  = atoi( pTime + 3 );
  167.  
  168.   return( JAMsysMkTime( &TM ));
  169. }
  170.  
  171.  
  172. /* end of file "hmbsub.c" */
  173.