home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- ** FILENAME: syscalls.c VERSION: 1.00
- **
- ** DESCRIPTION: Recreate a RemoteAccess v2.0x SYSINFO.BBS file
- **
- ** NOTES: A Pascal string stores the length in the first byte.
- ** i.e. int length = string[0]. Following the first
- ** byte is the rest of the character string. There is
- ** no NULL terminator in a Pascal string.
- **
- ** AUTHOR: John Kristoff START DATE: 04/24/94
- ** Internet: jkristof@xroads.chigate.com
- ** jkristof@mica.meddean.luc.edu
- ** FidoNet: 1:115/743
- ** CompuServe: 74111,3652
- **
- ** VERSION DATE WHO DETAIL
- ** 1.00 05May94 JK Initial design and coding
- **
- ** Copyright John Kristoff, 1994. All rights reserved.
- ** You may use this program or any part there-of as desired
- ** without restriction.
- */
-
- #include <stdio.h> /* Standard i/o */
- #include <stdlib.h> /* Standard library */
- #include <limits.h> /* Macros for min/max values */
- #include "syscalls.h" /* Supporting functions/macros */
- #include "ra.h" /* RemoteAccess structures */
-
- #define VERS "1.00" /* Program version */
- #define NAMELEN 35 /* String length of username */
- #define FNAME "SYSINFO.BBS" /* Data file */
- #define FNAMELEN 81 /* Fully qualified filepath + '\0' */
- #define ENVVAR "RA" /* Environment variable for BBS */
-
- int main( int argc, char * argv[] ); /* If you don't know, YUSC */
-
- int
- main( int argc, char * argv[] )
- {
- char LastCaller[128] = "System Operator"; /* Set default lastcaller */
- char Filename[FNAMELEN] = FNAME; /* Fully qualified */
- char * DataDir = NULL; /* Pointer to ENVVAR */
- SYSINFO * SysInfo = NULL; /* Pointer to data struct */
- FILE * SysFile = NULL; /* Pointer to data file */
-
- printf( "\n"
- "SYSCALLS v" VERS ", " __DATE__ ".\n"
- "Total system calls editor for RemoteAccess v2.0x.\n"
- "Copyright John Kristoff, 1994. All rights reserved.\n"
- "\n" );
-
-
- /*
- ** Check for proper command line arguments.
- */
-
- if( argc < 2 )
- {
- Error( HELP, __LINE__, NULL );
- }
-
-
- /*
- ** Allocate and clear memory for data structure.
- */
-
- SysInfo = (SYSINFO *) calloc( 1, sizeof(SYSINFO) );
- if( SysInfo == NULL )
- {
- Error( MEMORY, __LINE__, NULL );
- }
-
-
- /*
- ** Get environment variable pointing to data path if it exists.
- */
-
- DataDir = getenv( ENVVAR );
- if( DataDir != NULL )
- {
- if( DataDir[strlen(Filename) - 1] != '\\')
- {
- sprintf( Filename, "%s\\%s", DataDir, FNAME );
- }
- else
- {
- sprintf( Filename, "%s%s", DataDir, FNAME );
- }
- }
-
-
- /*
- ** Get lastcaller name from data file if possible.
- */
-
- SysFile = fopen(Filename, "rb");
- if( SysFile == NULL )
- {
- printf( "WARNING: Could not open %s, creating...\n"
- "\n",
- Filename );
- }
- else
- {
- if( fread( SysInfo, sizeof(SYSINFO), 1, SysFile) == NULL )
- {
- Error( READ, __LINE__, Filename );
- }
-
- fclose( SysFile );
-
- if( ferror(SysFile) )
- {
- Error( CLOSE, __LINE__, Filename );
- }
-
- strncpy( LastCaller,
- SysInfo->lastcaller.string,
- SysInfo->lastcaller.l1 );
-
- LastCaller[SysInfo->lastcaller.l1] = '\0';
- }
-
-
- /*
- ** Set total system calls from first command line argument.
- */
-
- SysInfo->totalcalls = atol( argv[1] );
- if( SysInfo->totalcalls < 0 || SysInfo->totalcalls > LONG_MAX )
- {
- Error( HELP, __LINE__, NULL );
- }
-
-
- /*
- ** Get lastcaller username from second command line argument
- ** if specified.
- */
-
- if( argc > 2 )
- {
- strcpy( LastCaller, argv[2] );
- if( strlen(LastCaller) > NAMELEN )
- {
- printf( "Truncating username to %d characters\n"
- "\n",
- NAMELEN );
- LastCaller[NAMELEN + 1] = '\0';
- }
- }
-
-
- /*
- ** Put lastcaller information into data structure.
- */
-
- strncpy( SysInfo->lastcaller.string, LastCaller, NAMELEN );
- SysInfo->lastcaller.l1 = strlen(LastCaller);
-
-
- /*
- ** Re-create data file with new information.
- */
-
- SysFile = fopen( Filename, "wb" );
- if( SysFile == NULL )
- {
- Error( OPEN, __LINE__, Filename );
- }
-
- if( fwrite( SysInfo, sizeof(SYSINFO), 1, SysFile) == NULL )
- {
- Error( WRITE, __LINE__, Filename );
- }
-
- fclose( SysFile );
- if( ferror(SysFile) )
- {
- Error( CLOSE, __LINE__, Filename );
- }
-
- printf( "%s successfully recreated!\n"
- "\n", Filename );
- printf( "Total calls set to: %ld\n", SysInfo->totalcalls );
- printf( "Last caller set to: %s\n", LastCaller );
-
- return( EXIT_SUCCESS );
- }
-