⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 !best004.c

📁 supplementary source file 1 for The BESTLibrary
💻 C
📖 第 1 页 / 共 2 页
字号:
/*==========================================================================
 *
 *  !BEST004.C                                        Sunday, April 17, 1994
 *
 *  .INI file routines
 *  supplementary source file 4 for The BESTLibrary
 *
 *  Authored independently by George Vanous
 *
 *==========================================================================*/


/* ------------------------------------------------------------------------ */
/* ----------------------------  INCLUDE FILES  --------------------------- */

#include <dir.h>
#include <dos.h>
#include <alloc.h>
#include <stdlib.h>
#include "!bestlib.h"                  // include !BESTLIB.H in compilation

/* ------------------------------------------------------------------------ */
/* ------------------------------  CONSTANTS  ----------------------------- */

/* used in procedure "ini_get_error" */
#define BOOLEAN  0
#define COLOR    1
#define NUMBER   2
#define POSITION 3
#define ROWS     4
#define STATE    5
#define STRING   6

/* ------------------------------------------------------------------------ */
/* ---------------------------  ERROR MESSAGES  --------------------------- */

#define ERR03 "\nI cannot open the initialization file -- I need this file to continue.\n\n"
#define ERR04 "\nIt seems the initialization file is incorrect\n\nI do not know this color:  %s\n\nThis color is located here:\n%s\n\nThe colors I know are:  BLACK  BLUE  GREEN  CYAN  RED  MAGENTA  BROWN  LIGHTGREYDARKGREY  LIGHTBLUE  LIGHTGREEN  LIGHTCYAN  LIGHTRED  LIGHTMAGENT  YELLOW  WHITE\n"
#define ERR05 "\nI believe the initialization file is incorrect\n\nThere is an invalid text string located here:\n%s\n\nThe offensive string is:  %s\n\nA valid string must be enclosed within quotation marks:  \"This string is OK!\"\n\nPlease remedy this problem.\n\n"
#define ERR06 "\nI have found something incorrect in the initialization file\n\nThere is a section header missing from section:  %s\n\nI can not find this header:  %s\n\nPlease type it in.\n\n"
#define ERR07 "\nThere is a problem with the initialization file\n\nI have located an open section\n\nI can not find this section terminator:  %s\n\nPlease input it.\n\n"
#define ERR08 "\nI think something needs to be added to the initialization file\n\nI am missing an important option from this section:  %s\n\nCan you please insert this option:  %s\n\n"
#define ERR09 "\nI cannot seem to understand one part of the initialization file\n\nI think an equality symbol, =, is missing from this section:\n%s\n\nI can not locate the = symbol for this option:  %s\n\nCan you please input it for me?\n\n"
#define ERR10 "\nMaybe you can help me understand the initialization file\n\nThe problem lies in this section:\n%s\n\nThe parameter I am having trouble with is:  %s\n\nI think it can only be TRUE or FALSE -- can you please correct this problem?\n\n"
#define ERR11 "\nThere seems to be an invalid number in the initialization file\n\nThe offensive number lies in this section:\n%s\n\nThe number I do not recognize is:  %s\n\nPlease try to correct this problem.\n\n"
#define ERR12 "\nI am having difficulty understanding the initialization file\n\nMy question comes from this section:\n%s\n\nI do not know what is meant by this parameter:  %s\n\nI expected it to be either ON, OFF, or UNMODIFY -- can you help me?\n\n"
#define ERR13 "\nThe initialization file must be in error\n\nI do not understand this screen location: %s\n\nIt is located in this section:\n%s\n\nI only understand these two screen positions:  TOP  BOTTOM\n\nPlease correct this problem and try again.\n\n"
#define ERR14 "\nI think there is something that needs correcting in the initialization file\n\nI can only display 25 or 50 rows per screen, but in the section:\n%s\n\nI am asked to display %s rows.\n\nPlease input one of these values:  25, 50, or UNMODIFY.  Thank you.\n\n"
#define ERR15 "\nI cannot find the file %s -- it was requested in the initialization file\n\nThis is the section that asked for the file:\n%s\n\nEither this file is not in the current directory or it is misspelled.\n\n"

/* ------------------------------------------------------------------------ */
/* -------------------------  FUNCTION PROTOTYPES  ------------------------ */

void ini_get_error(char *section, char *str, word *ptr, byte type);
char *ini_verify_format(char *section, char *section_title,
                        char *option, word *ptr);

/* ------------------------------------------------------------------------ */


/*----------------------------------------------------------------------------
 * Translate the boolean word "TRUE" or "FALSE" into boolean TRUE or FALSE.
 *
 * "section"       - section text
 * "section_title" - section title to read from
 * "option"        - option to read from
 *
 * RETURNS:
 * = TRUE if found string "TRUE"
 * = FALSE if found string "FALSE"
 */
boolean ini_get_boolean(char *section, char *section_title, char *option)
{
  shortint value;                      // return value
  char *str;                           // parameter
  word  ptr[2];                        // two generic offset pointers

  str = ini_verify_format(section, section_title, option, ptr);

  if ((value = con_str_to_bool(str)) == -1)
    ini_get_error(section, str, ptr, BOOLEAN);

  return( (boolean)value );
}

/*----------------------------------------------------------------------------
 * Translate a color name into its numerical equivalent.
 *
 * "section"       - section text
 * "section_title" - section title to read from
 * "option"        - option to read from
 *
 * RETURNS:
 * = numerical equivalent of color name
 */
byte ini_get_color(char *section, char *section_title, char *option)
{
  shortint value;                      // return value
  char *str;                           // parameter
  word  ptr[2];                        // two generic offset pointers

  str = ini_verify_format(section, section_title, option, ptr);

  if ((value = con_str_to_color(str)) == -1)
    ini_get_error(section, str, ptr, COLOR);

  return( (byte)value );
}

/*----------------------------------------------------------------------------
 * Display the offending parameter in the initialization file and exit to DOS
 *   with the appropriate ERRORLEVEL.
 *
 * "section" - section text
 * "str"     - parameter in question
 * "ptr"     - two offset pointers
 * "type"    - type of error
 */
void ini_get_error(char *section, char *str, word *ptr, byte type)
{
  char error[1000];                    // ample space for error message

  // isolate the section containing the error
  *(section+ptr[0] + scan_byte(section+ptr[0], LF, NULL, FORWARD)-1) = NULL;

  // display the correct error message
  switch (type) {
    case BOOLEAN  : sprintf(error, ERR10, section+ptr[1], str            ); break;
    case COLOR    : sprintf(error, ERR04, str,            section+ptr[1] ); break;
    case NUMBER   : sprintf(error, ERR11, section+ptr[1], str            ); break;
    case POSITION : sprintf(error, ERR13, str,            section+ptr[1] ); break;
    case ROWS     : sprintf(error, ERR14, section+ptr[1], str            ); break;
    case STATE    : sprintf(error, ERR12, section+ptr[1], str            ); break;
    case STRING   : sprintf(error, ERR05, section+ptr[1], str            );
  }
  fprintf(stderr, error);
  beep(); exit(3);
}

/*----------------------------------------------------------------------------
 * Translate an ASCII representation of a number into its numerical equivalent.
 *
 * "section"       - section text
 * "section_title" - section title to read from
 * "option"        - option to read from
 *
 * RETURNS:
 * = numerical representation of number string
 */
int ini_get_number(char *section, char *section_title, char *option)
{
  char *str;                           // parameter
  word  ptr[2];                        // two generic offset pointers

  str = ini_verify_format(section, section_title, option, ptr);

  if (!is_number_dec(str))
    ini_get_error(section, str, ptr, NUMBER);

  return( atoi(str) );
}

/*----------------------------------------------------------------------------
 * Translate the screen position "TOP" or "BOTTOM" to the screen row number
 *   (taking into account a possible 50-line text mode).
 *
 * "section"       - section text
 * "section_title" - section title to read from
 * "option"        - option to read from
 *
 * RETURNS:
 * = screen row number
 */
int ini_get_position(char *section, char *section_title, char *option)
{
  char *str;                           // parameter
  word  ptr[2];                        // two generic offset pointers

  str = ini_verify_format(section, section_title, option, ptr);

  str_case_up(str);
  if (!str_cmp(str, "TOP"))
    return( 0 );
  if (str_cmp(str, "BOTTOM"))
    ini_get_error(section, str, ptr, POSITION);

  return( txt_rows() );
}

/*----------------------------------------------------------------------------
 * Translate the number of rows per screen page "25", "50", or "UNMODIFY",
 *   into the numerical equivalent.
 *
 * "section"       - section text
 * "section_title" - section title to read from
 * "option"        - option to read from
 *
 * RETURNS:
 * = rows per screen page
 */
int ini_get_rows(char *section, char *section_title, char *option)
{
  char *str;                           // parameter
  word num,                            // generic word
       ptr[2];                         // two generic offset pointers

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -