home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / SCALL100.ZIP / SYSCALLS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-05  |  5.3 KB  |  192 lines

  1. /*********************************************************************
  2. ** FILENAME: syscalls.c                     VERSION: 1.00
  3. **
  4. ** DESCRIPTION: Recreate a RemoteAccess v2.0x SYSINFO.BBS file
  5. **
  6. ** NOTES: A Pascal string stores the length in the first byte.
  7. **        i.e. int length = string[0].  Following the first
  8. **        byte is the rest of the character string.  There is
  9. **        no NULL terminator in a Pascal string.
  10. **
  11. ** AUTHOR: John Kristoff                START DATE: 04/24/94
  12. **         Internet:   jkristof@xroads.chigate.com
  13. **                     jkristof@mica.meddean.luc.edu
  14. **         FidoNet:    1:115/743
  15. **         CompuServe: 74111,3652
  16. **
  17. ** VERSION  DATE     WHO  DETAIL
  18. ** 1.00     05May94  JK   Initial design and coding
  19. **
  20. **      Copyright John Kristoff, 1994.  All rights reserved.
  21. **      You may use this program or any part there-of as desired
  22. **      without restriction.
  23. */
  24.  
  25. #include <stdio.h>                      /* Standard i/o */
  26. #include <stdlib.h>                     /* Standard library */
  27. #include <limits.h>                     /* Macros for min/max values */
  28. #include "syscalls.h"                   /* Supporting functions/macros */
  29. #include "ra.h"                         /* RemoteAccess structures */
  30.  
  31. #define VERS       "1.00"               /* Program version */
  32. #define NAMELEN    35                   /* String length of username */
  33. #define FNAME      "SYSINFO.BBS"        /* Data file */
  34. #define FNAMELEN   81                   /* Fully qualified filepath + '\0' */
  35. #define ENVVAR     "RA"                 /* Environment variable for BBS */
  36.  
  37. int main( int argc, char * argv[] );    /* If you don't know, YUSC */
  38.  
  39. int
  40. main( int argc, char * argv[] )
  41. {
  42.     char LastCaller[128] = "System Operator";   /* Set default lastcaller */
  43.     char Filename[FNAMELEN] = FNAME;            /* Fully qualified */
  44.     char * DataDir = NULL;                      /* Pointer to ENVVAR */
  45.     SYSINFO * SysInfo = NULL;                   /* Pointer to data struct */
  46.     FILE * SysFile = NULL;                      /* Pointer to data file */
  47.  
  48.     printf( "\n"
  49.             "SYSCALLS v" VERS ", " __DATE__ ".\n"
  50.              "Total system calls editor for RemoteAccess v2.0x.\n"
  51.              "Copyright John Kristoff, 1994.  All rights reserved.\n"
  52.              "\n" );
  53.  
  54.  
  55.     /*
  56.     ** Check for proper command line arguments.
  57.     */
  58.  
  59.     if( argc < 2 )
  60.     {
  61.         Error( HELP, __LINE__, NULL );
  62.     }
  63.  
  64.  
  65.     /*
  66.     ** Allocate and clear memory for data structure.
  67.     */
  68.  
  69.     SysInfo = (SYSINFO *) calloc( 1, sizeof(SYSINFO) );
  70.     if( SysInfo == NULL )
  71.     {
  72.         Error( MEMORY, __LINE__, NULL );
  73.     }
  74.  
  75.  
  76.     /*
  77.     ** Get environment variable pointing to data path if it exists.
  78.     */
  79.  
  80.     DataDir = getenv( ENVVAR );
  81.     if( DataDir != NULL )
  82.     {
  83.         if( DataDir[strlen(Filename) - 1] != '\\')
  84.         {
  85.             sprintf( Filename, "%s\\%s", DataDir, FNAME );
  86.         }
  87.         else
  88.         {
  89.             sprintf( Filename, "%s%s", DataDir, FNAME );
  90.         }
  91.     }
  92.  
  93.  
  94.     /*
  95.     ** Get lastcaller name from data file if possible.
  96.     */
  97.  
  98.     SysFile = fopen(Filename, "rb");
  99.     if( SysFile == NULL )
  100.     {
  101.         printf( "WARNING: Could not open %s, creating...\n"
  102.                 "\n",
  103.                 Filename );
  104.     }
  105.     else
  106.     {
  107.         if( fread( SysInfo, sizeof(SYSINFO), 1, SysFile) == NULL )
  108.         {
  109.             Error( READ, __LINE__, Filename );
  110.         }
  111.  
  112.         fclose( SysFile );
  113.         
  114.         if( ferror(SysFile) )
  115.         {
  116.             Error( CLOSE, __LINE__, Filename );
  117.         }
  118.  
  119.         strncpy( LastCaller,
  120.                  SysInfo->lastcaller.string,
  121.                  SysInfo->lastcaller.l1 );
  122.  
  123.         LastCaller[SysInfo->lastcaller.l1] = '\0';
  124.     }
  125.  
  126.  
  127.     /*
  128.     ** Set total system calls from first command line argument.
  129.     */
  130.  
  131.     SysInfo->totalcalls = atol( argv[1] );
  132.     if( SysInfo->totalcalls < 0 || SysInfo->totalcalls > LONG_MAX )
  133.     {
  134.         Error( HELP, __LINE__, NULL );
  135.     }
  136.  
  137.  
  138.     /*
  139.     ** Get lastcaller username from second command line argument
  140.     ** if specified.
  141.     */
  142.  
  143.     if( argc > 2 )
  144.     {
  145.         strcpy( LastCaller, argv[2] );
  146.         if( strlen(LastCaller) > NAMELEN )
  147.         {
  148.             printf( "Truncating username to %d characters\n"
  149.                     "\n",
  150.                     NAMELEN );
  151.             LastCaller[NAMELEN + 1] = '\0';
  152.         }
  153.     }
  154.  
  155.  
  156.     /*
  157.     ** Put lastcaller information into data structure.
  158.     */
  159.  
  160.     strncpy( SysInfo->lastcaller.string, LastCaller, NAMELEN );
  161.     SysInfo->lastcaller.l1 = strlen(LastCaller);
  162.  
  163.  
  164.     /*
  165.     **  Re-create data file with new information.
  166.     */
  167.  
  168.     SysFile = fopen( Filename, "wb" );
  169.     if( SysFile == NULL )
  170.     {
  171.             Error( OPEN, __LINE__, Filename );
  172.     }
  173.  
  174.     if( fwrite( SysInfo, sizeof(SYSINFO), 1, SysFile) == NULL )
  175.     {
  176.         Error( WRITE, __LINE__, Filename );
  177.     }
  178.  
  179.     fclose( SysFile );
  180.     if( ferror(SysFile) )
  181.     {
  182.         Error( CLOSE, __LINE__, Filename );
  183.     }
  184.  
  185.     printf( "%s successfully recreated!\n"
  186.             "\n", Filename );
  187.     printf( "Total calls set to: %ld\n", SysInfo->totalcalls );
  188.     printf( "Last caller set to: %s\n", LastCaller );
  189.  
  190.     return( EXIT_SUCCESS );
  191. }
  192.