home *** CD-ROM | disk | FTP | other *** search
- /*
- ** FILENAME: lastword.c
- **
- ** DESCRIPTION: Simple quote door for Bulletin Board Systems
- **
- ** NOTES: This program was written using Opendoors C library
- ** kit.
- **
- ** AUTHOR: John Kristoff START DATE: 11/14/93
- ** FIDOnet: 1:115/743
- ** Internet: jkristof@interaccess.com
- ** jkristof@bsd.meddean.luc.edu
- ** CompuServe: 74111,3652
- **
- ** Copyright John Kristoff 1993-96. All rights reserved.
- **
- ** VERSION DATE WHO DETAIL
- ** 1.00 14Nov93 JK Initial design and coding
- ** 1.01 16Nov93 JK Minor bug fixes
- ** 1.02 22Jan95 JK Compiled with OpenDoors 5.0, minor improvements
- ** 1.03 17Feb95 JK More minor improvements and bug fixes
- ** 1.04 19May96 JK Compiled w/ Opendoors 6.0, minor additions
- */
-
- #include <stdio.h> // Standard i/o
- #include <stdlib.h> // Standard library
- #include "opendoor.h" // Opendoors functions
- #include "od_error.h" // Error handling routines
-
- #define VERS "1.04" // Program version
-
- #define DATA_FILE "LASTWORD.DAT" // Stores quote and username
- #define MAX_LINES 5 // Max lines per quote
- #define LINE_LEN 70 // Max line length <=75
-
- typedef struct
- {
- char Line[MAX_LINES][LINE_LEN];
- char User[36];
-
- } WORDS;
-
- int main( int argc, char * argv[] ); // If you don't know, YUSC
- void ShowQuote( void ); // Display previous Quote
- void AddQuote( void ); // Get quote from user
-
- int
- main( int argc, char * argv[] )
- {
-
- /* --- Opendoors setup and initialization --- */
-
- strcpy( od_registered_to, "John Kristoff" );
- od_registration_key = 0000000000;
- od_control.od_clear_on_exit = FALSE;
- od_control.od_nocopyright = TRUE;
- od_init();
-
-
- /* --- Welcome screen --- */
-
- od_printf( "`bright cyan`LASTWORD v" VERS ", " __DATE__ ". " );
- od_printf( "`bright white`The Lastword Quote Door.\n\r" );
- od_printf( "`bright blue`Copyright John Kristoff, 1993-96. " );
- od_printf( "All rights reserved.\n\r" );
- od_printf( "\n\r" );
-
-
- /* --- Check for path to door file passed on command line --- */
-
- if( argc > 1 )
- {
- strncpy( od_control.info_path, argv[1], 59 );
- }
-
- ShowQuote();
-
- od_printf( "`grey`Would you like to add some lastwords [Y/n]:" );
-
- if( od_get_answer("YN") == 'Y' )
- {
- od_printf( "`bright cyan`Yes\n\r" );
- AddQuote();
- }
- else
- {
- od_printf( "`bright cyan`No\n\r" );
- }
-
- od_exit( 10, FALSE );
- return( EXIT_SUCCESS );
- }
-
-
-
- void
- ShowQuote( void )
- {
- WORDS Words; // Struct that holds quote/username
- int Current = 0; // Current line being entered
- FILE * fp = NULL; // Pointer to data/quote file
-
- if( (fp = fopen(DATA_FILE, "rb")) == NULL )
- {
- od_printf( "`bright red`No current Lastwords on file.\n\r" );
- }
-
- else
- {
- if( fread(&Words, sizeof(WORDS), 1, fp) == NULL )
- {
- Error( READ, __LINE__, DATA_FILE );
- }
-
- od_printf( "`grey`These Lastwords left by ");
- od_printf( "`bright cyan`%s\n\r", Words.User );
-
-
- /* --- Display top border --- */
-
- od_set_colour( L_BLUE, D_BLACK );
- od_putch( '╔' );
- od_repeat( '═', LINE_LEN + 1 );
- od_putch( '╗' );
- od_printf( "`grey`\n\r" );
-
-
- /* --- Display entire quote line by line --- */
-
- while( (Words.Line[Current][0] != '\0') && (Current < MAX_LINES) )
- {
- od_printf( " `cyan`%s\n\r", Words.Line[Current] );
- Current++;
- }
-
-
- /* --- Display bottom border --- */
-
- od_set_colour( L_BLUE, D_BLACK );
- od_putch( '╚' );
- od_repeat( '═', LINE_LEN + 1 );
- od_putch( '╝' );
- od_printf( "`grey`\n\r" );
- }
- }
-
-
-
- void
- AddQuote( void )
- {
- WORDS * Words; // Point to quote/data struct
- int Current = 0; // Current line being processed
- int Blank = FALSE; // Flag if line is empty/nul
- FILE * fp = NULL; // Pointer to data file
-
- if( (Words = (WORDS *) calloc(1, sizeof(WORDS))) == NULL )
- {
- Error( MEM, __LINE__, NULL );
- }
-
- od_printf( "`grey`Enter up to `bright cyan`%d`grey` lines.", MAX_LINES );
- od_printf( " A blank line ends.\n\r\n\r" );
-
-
- /* --- Cycle through input routine --- */
-
- while( (Current < MAX_LINES) && (Blank != TRUE) )
- {
- od_printf( "`bright cyan`%d`grey`: ", Current + 1 );
- od_input_str( Words->Line[Current], LINE_LEN - 1, 32, 127 );
-
- if( Words->Line[Current][0] == '\0' )
- {
- Blank = TRUE;
- }
-
- Current++;
- }
-
-
- /* --- If input was entered, save it --- */
-
- if( Words->Line[0][0] != '\0' )
- {
- od_printf( "`grey`Save these lastwords [Y/n]:" );
-
- if( od_get_answer("YN") == 'Y' )
- {
- od_printf( "`bright cyan`Yes\n\r" );
-
- strcpy( Words->User, od_control.user_name );
-
- if( (fp = fopen(DATA_FILE, "wb")) == NULL )
- {
- Error( OPEN, __LINE__, DATA_FILE );
- }
-
- if( fwrite(Words, sizeof(WORDS), 1, fp) == NULL )
- {
- Error( WRITE, __LINE__, DATA_FILE );
- }
-
- fclose( fp );
- }
- else
- {
- od_printf( "`bright cyan`No\n\r" );
- }
- }
- }
-