home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / LAST104.ZIP / LASTWORD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-20  |  5.6 KB  |  212 lines

  1. /*
  2. ** FILENAME: lastword.c
  3. **
  4. ** DESCRIPTION: Simple quote door for Bulletin Board Systems
  5. **
  6. ** NOTES: This program was written using Opendoors C library
  7. **        kit.
  8. **
  9. ** AUTHOR: John Kristoff                START DATE: 11/14/93
  10. **          FIDOnet: 1:115/743
  11. **         Internet: jkristof@interaccess.com
  12. **                   jkristof@bsd.meddean.luc.edu
  13. **       CompuServe: 74111,3652
  14. **
  15. **         Copyright John Kristoff 1993-96.  All rights reserved.
  16. **
  17. ** VERSION  DATE    WHO DETAIL
  18. ** 1.00     14Nov93 JK  Initial design and coding
  19. ** 1.01     16Nov93 JK  Minor bug fixes
  20. ** 1.02     22Jan95 JK  Compiled with OpenDoors 5.0, minor improvements
  21. ** 1.03     17Feb95 JK  More minor improvements and bug fixes
  22. ** 1.04     19May96 JK  Compiled w/ Opendoors 6.0, minor additions
  23. */
  24.  
  25. #include <stdio.h>                      // Standard i/o
  26. #include <stdlib.h>                     // Standard library
  27. #include "opendoor.h"                   // Opendoors functions
  28. #include "od_error.h"                   // Error handling routines
  29.  
  30. #define VERS       "1.04"               // Program version
  31.  
  32. #define DATA_FILE  "LASTWORD.DAT"       // Stores quote and username
  33. #define MAX_LINES  5                    // Max lines per quote
  34. #define LINE_LEN   70                   // Max line length <=75
  35.  
  36. typedef struct
  37. {
  38.     char Line[MAX_LINES][LINE_LEN];
  39.     char User[36];
  40.  
  41. } WORDS;
  42.  
  43. int main( int argc, char * argv[] );    // If you don't know, YUSC
  44. void ShowQuote( void );                 // Display previous Quote
  45. void AddQuote( void );                  // Get quote from user
  46.  
  47. int
  48. main( int argc, char * argv[] )
  49. {
  50.  
  51.     /* --- Opendoors setup and initialization --- */
  52.  
  53.     strcpy( od_registered_to, "John Kristoff" );
  54.     od_registration_key = 0000000000;
  55.     od_control.od_clear_on_exit = FALSE;
  56.     od_control.od_nocopyright = TRUE;
  57.     od_init();
  58.  
  59.  
  60.     /* --- Welcome screen --- */
  61.  
  62.     od_printf( "`bright cyan`LASTWORD v" VERS ", " __DATE__ ".  " );
  63.     od_printf( "`bright white`The Lastword Quote Door.\n\r" );
  64.     od_printf( "`bright blue`Copyright John Kristoff, 1993-96.  " );
  65.     od_printf( "All rights reserved.\n\r" );
  66.     od_printf( "\n\r" );
  67.  
  68.  
  69.     /* --- Check for path to door file passed on command line --- */
  70.  
  71.     if( argc > 1 )
  72.     {
  73.         strncpy( od_control.info_path, argv[1], 59 );
  74.     }
  75.  
  76.     ShowQuote();
  77.  
  78.     od_printf( "`grey`Would you like to add some lastwords [Y/n]:" );
  79.  
  80.     if( od_get_answer("YN") == 'Y' )
  81.     {
  82.         od_printf( "`bright cyan`Yes\n\r" );
  83.         AddQuote();
  84.     }
  85.     else
  86.     {
  87.         od_printf( "`bright cyan`No\n\r" );
  88.     }
  89.  
  90.     od_exit( 10, FALSE );
  91.     return( EXIT_SUCCESS );
  92. }
  93.  
  94.  
  95.  
  96. void
  97. ShowQuote( void )
  98. {
  99.     WORDS Words;                        // Struct that holds quote/username
  100.     int Current = 0;                    // Current line being entered
  101.     FILE * fp = NULL;                   // Pointer to data/quote file
  102.  
  103.     if( (fp = fopen(DATA_FILE, "rb")) == NULL )
  104.     {
  105.         od_printf( "`bright red`No current Lastwords on file.\n\r" );
  106.     }
  107.  
  108.     else
  109.     {
  110.         if( fread(&Words, sizeof(WORDS), 1, fp) == NULL )
  111.         {
  112.             Error( READ, __LINE__, DATA_FILE );
  113.         }
  114.  
  115.         od_printf( "`grey`These Lastwords left by ");
  116.         od_printf( "`bright cyan`%s\n\r", Words.User );
  117.  
  118.  
  119.         /* --- Display top border --- */
  120.  
  121.         od_set_colour( L_BLUE, D_BLACK );
  122.         od_putch( '╔' );
  123.         od_repeat( '═', LINE_LEN + 1 );
  124.         od_putch( '╗' );
  125.         od_printf( "`grey`\n\r" );
  126.  
  127.  
  128.         /* --- Display entire quote line by line --- */
  129.  
  130.         while( (Words.Line[Current][0] != '\0') && (Current < MAX_LINES) )
  131.         {
  132.             od_printf( "  `cyan`%s\n\r", Words.Line[Current] );
  133.             Current++;
  134.         }
  135.  
  136.  
  137.         /* --- Display bottom border --- */
  138.  
  139.         od_set_colour( L_BLUE, D_BLACK );
  140.         od_putch( '╚' );
  141.         od_repeat( '═', LINE_LEN + 1 );
  142.         od_putch( '╝' );
  143.         od_printf( "`grey`\n\r" );
  144.     }
  145. }
  146.  
  147.  
  148.  
  149. void
  150. AddQuote( void )
  151. {
  152.     WORDS * Words;                      // Point to quote/data struct
  153.     int Current = 0;                    // Current line being processed
  154.     int Blank = FALSE;                  // Flag if line is empty/nul
  155.     FILE * fp = NULL;                   // Pointer to data file
  156.  
  157.     if( (Words = (WORDS *) calloc(1, sizeof(WORDS))) == NULL )
  158.     {
  159.         Error( MEM, __LINE__, NULL );
  160.     }
  161.  
  162.     od_printf( "`grey`Enter up to `bright cyan`%d`grey` lines.", MAX_LINES );
  163.     od_printf( "  A blank line ends.\n\r\n\r" );
  164.  
  165.  
  166.     /* --- Cycle through input routine --- */
  167.  
  168.     while( (Current < MAX_LINES) && (Blank != TRUE) )
  169.     {
  170.         od_printf( "`bright cyan`%d`grey`: ", Current + 1 );
  171.         od_input_str( Words->Line[Current], LINE_LEN - 1, 32, 127 );
  172.  
  173.         if( Words->Line[Current][0] == '\0' )
  174.         {
  175.             Blank = TRUE;
  176.         }
  177.  
  178.         Current++;
  179.     }
  180.  
  181.  
  182.     /* --- If input was entered, save it --- */
  183.  
  184.     if( Words->Line[0][0] != '\0' )
  185.     {
  186.         od_printf( "`grey`Save these lastwords [Y/n]:" );
  187.  
  188.         if( od_get_answer("YN") == 'Y' )
  189.         {
  190.             od_printf( "`bright cyan`Yes\n\r" );
  191.  
  192.             strcpy( Words->User, od_control.user_name );
  193.  
  194.             if( (fp = fopen(DATA_FILE, "wb")) == NULL )
  195.             {
  196.                 Error( OPEN, __LINE__, DATA_FILE );
  197.             }
  198.  
  199.             if( fwrite(Words, sizeof(WORDS), 1, fp) == NULL )
  200.             {
  201.                 Error( WRITE, __LINE__, DATA_FILE );
  202.             }
  203.  
  204.             fclose( fp );
  205.         }
  206.         else
  207.         {
  208.             od_printf( "`bright cyan`No\n\r" );
  209.         }
  210.     }
  211. }
  212.