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

📄 mfpdemo.c

📁 多格式数据录入库  
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
    MFPDEMO.C

    Written by Jerome G. Kahn 1990

    Produced by Pride Software Advancement Corporation...
*/

#include <stdio.h>
#include <dos.h>
#include <ctype.h>
#include <graph.h>
#include <mfp.h>        /* The MFP1 header */

/*
    internal function prototypes...
*/

void drawscrn( char * );
void nprompts( void );
void cprompts( void );
void mess24( char * );
void clearnio( void );
void clearcio( void );
void signoff( void );
void numeric( void );
void character( void );

/*
	Validation and hot key function prototypes
*/

void help( void );
void ninst( void );
void npost( void );
void cinst( void );
void cpost( void );
void datest( void );
void state( void );

/*
	Data entry variable definition
*/

struct NUM_BLK
{
    char 				name[ 21 ];
    short               binarys;
    int                 rel_lum;
    long                sfc_temp;
    unsigned            abs_lum;
    long                age_yrs;
    float 				magnitd;
    double 				distance;
} nio;

struct CHR_BLK
{
    char                fname[ 21 ];
    char                lname[ 21 ];
    char                street[ 21 ];
    char                city[ 21 ];
    char                state[ 3 ];
    char                zip[ 11 ];
    char                phone1[ 14 ];
    char                phone2[ 14 ];
    char                ssn[ 12 ];
    char                dob[ 9 ];
} cio;

/*

           MFP example_1[] = { buffer, "!!!", 5, 15, BLACK, WHITE, 0, 0 };
                  ^              ^       ^    ^   ^    ^      ^    ^  ^
Field Name -------+              |       |    |   |    |      |    |  |
Pointer to data variable --------+       |    |   |    |      |    |  |
Picture formatting string ---------------+    |   |    |      |    |  |
Row of field location ------------------------+   |    |      |    |  |
Column of field location -------------------------+    |      |    |  |
Foreground color of entry field -----------------------+      |    |  |
Background color of entry field ------------------------------+    |  |
Pre validation function pointer -----------------------------------+  |
Post validation function pointer -------------------------------------+


      One of the main features that makes MFP stand out is it's
      picture or data formatting capability. MFP uses a picture
      string to identify the data type and it's characteristics.
      Numeric variables are identified with a "%" percent symbol
      as the first picture character. Any other symbol in the first
      character position forces MFP to assume the data is a character
      array. Numeric data is always entered as BASE 10 or decimal.

      Character entry is filtered by MFP to not allow control codes into
      an entry field.

      Character formatting symbols are as follows:

        !                   Upper case conversion. ( alphanumeric )
        *                   Security echo. All characters are allowed.
        0 - 9               Numeric characters only, value limited by formatter
        A, a                Alpha only allowed
        H, h                Hexadecimal characters only
        X, x                Any ASCII character
        Y, y                Y or N only
        All others          used as stationary objects

      Numeric formatting requirements are as follows:

        "%nn[.][nn]|[L][l][h]|[d][u][f]"

        *   The first character must be a percent symbol.
        *   A length parameter must be provided. This will represent
            the entire entry field length including decimal points and sign.
        *   If a decimal point is provided a decimal length parameter is
            required to indicate the number of decimal positions. A decimal
            point cannot be used for non-floating point variables.

            NOTE: The length parameter must be at least three greater than
                  the decimal length. ie; "%5.3f" would be illegal, yet "%5.2f"
                  would be okay.

        *   Last is the variable type. MFP allows certain modifiers to the
            standard variable types. The legal types  are as follows:

            hd  --  Short integer.
            d   --  Signed integer.
            ld  --  Signed long integer.
            u   --  Unsigned integer.
            lu  --  Unsigned long integer.
            f   --  Single precision floating point.
            lf  --  Double precision floating point.
        *   Lf  --  Long double precision floating point.

        * Long double is not a standard variable type. Turbo C supports long
          double along with a few other compilers. The other versions of this
          library converts your long double to a double.
*/

/*
    Setup of the numeric entry screen...
*/

MFP ln1[] = { nio.name,"!!!!!!!!!!!!!!!!!!!!", 5,20,BLACK,WHITE,ninst,npost };
MFP ln2[] = { &nio.binarys,  "%2hd",   	 7,20,BLACK,WHITE,ninst,npost };
MFP ln3[] = { &nio.rel_lum,  "%6d",      9,20,BLACK,WHITE,ninst,npost };
MFP ln4[] = { &nio.abs_lum,  "%6u",     11,20,BLACK,WHITE,ninst,npost };
MFP ln5[] = { &nio.sfc_temp, "%9ld",    13,20,BLACK,WHITE,ninst,npost };
MFP ln6[] = { &nio.age_yrs,  "%9lu",    15,20,BLACK,WHITE,ninst,npost };
MFP ln7[] = { &nio.magnitd,  "%9.3f",   17,20,BLACK,WHITE,ninst,npost };
MFP ln8[] = { &nio.distance, "%13.3lf", 19,20,BLACK,WHITE,ninst,npost };

/*
    The MFP list array defines which fields are to be entered
    and in what order. The fields in the MFP list must be defined.

    The MFP list is the first parameter that will be passed to the mfp()
    function.

        MFP *example[] = { example_1, example_2, example_3, 0 };

    The MFP list "example" will tell the mfp() function that fields
    example_1, example_2, and example_3 are to be input and in the order
    that they appear in the list. When the mfp() function has scanned
    and processed all of the defined fields and has read in the zero
    it will exit and return control to the calling program.
*/

/*
    Setup of the entry screen list...
*/

MFP *nlst[] = { ln1, ln2, ln3, ln4, ln5, ln6, ln7, ln8, 0 };

/*
    Setup of the character entry screen...
*/

MFP lc1[] = { cio.fname, "!!!!!!!!!!!!!!!!!!!!", 5, 20, BLACK,WHITE, cinst, cpost };
MFP lc2[] = { cio.lname, "!!!!!!!!!!!!!!!!!!!!", 7, 20, BLACK,WHITE, cinst, cpost };
MFP lc3[] = { cio.street,"!!!!!!!!!!!!!!!!!!!!", 9, 20, BLACK,WHITE, cinst, cpost };
MFP lc4[] = { cio.city,  "!!!!!!!!!!!!!!!!!!!!",11, 20, BLACK,WHITE, cinst, cpost };
MFP lc5[] = { cio.state, "!!",                  13, 20, BLACK,WHITE, cinst, state };
MFP lc6[] = { cio.zip,   "99999-9999",          13, 24, BLACK,WHITE, cinst, cpost };
MFP lc7[] = { cio.phone1,"(999)999-9999",       15, 20, BLACK,WHITE, cinst, cpost };
MFP lc8[] = { cio.phone2,"(999)999-9999",       17, 20, BLACK,WHITE, cinst, cpost };
MFP lc9[] = { cio.ssn,   "999-99-9999",         19, 20, BLACK,WHITE, cinst, cpost };
MFP lc10[] = { cio.dob,  "99/99/99",            21, 20, BLACK,WHITE, cinst, datest };

MFP *clst[] = { lc1, lc2, lc3, lc4, lc5, lc6, lc7, lc8, lc9, lc10, 0 };

/*

                Each menu item is defined using the typedef MENU. This
                simplifies your coding and makes defining a menu a snap.

                An example menu item is defined as follows:

                MENU item1[] = { 10, 20, "Edit", 'E', "Edit the above data." };

                The typedef MENU is followed by an item name which must be
                unique. The item must be declared as an array. The array is
                to be defined by direct assignment using the equals symbol
                followed by an open brace.

                The first parameters in the braces are the row and column
                respectively. This is the row and column where this item will
                appear on the screen.

                The next parameter is the item text that will be displayed.

                Following the item text is the alternate keyboard key that
                can also be used to select this item. If this key is pressed,
                this item will be selected and menu() will return with this
                menu item's value. This parameter MUST be uppercase, because
                the keyboard input will be converted to uppercase for testing.

                Last but not least, is the optional help text that will be
                displayed when this menu item is highlighted. If you do not
                want any help text to be displayed, you must place a zero in
                this parameter.

                Finally the menu declaration must be terminated with a close
                brace and a semicolon.

*/

/*
    Setup the main menu
*/

MENU mm1[] = {  8, 10, "Character Demonstration Screen.", 'C',
               "Execute the character demonstration program..." };

MENU mm2[] = { 10, 10, "Numeric Demonstration Screen...", 'N',
               "Execute the numeric demonstration program..." };

MENU mm3[] = { 12, 10, "Exit to DOS....................", 'E',
               "Terminate the MFP1 demonstration and return to DOS..." };

/*
                The menu list directs menu() to show the menu items in the
                order you established in the list, the return value starting
                from zero indicates the selection the user made, the first item
                in the menu list being zero and the last; N - 1. The menu list
                MUST be terminated with a zero. The menu list must be declared
                with the typedef MENU as an array of pointers.
*/

MENU *mmlist[] = { mm1, mm2, mm3, 0 };

/*
    Setup the numeric  and character menu
*/

MENU mn1[] = { 24, 5, "Edit",    'E', 
              "Go back and edit the above screen..." };
MENU mn2[] = { 24,15, "Save",    'S',
              "Save the above screen..." };
MENU mn3[] = { 24,25, "Delete",  'D',
              "Delete the above data from disk...", };
MENU mn4[] = { 24,35, "Abandon", 'A',
              "Abandon the above data, no deletion will occur..." };
MENU mn5[] = { 24,45, "Recall",  'R',
              "Recall a previously saved data record from disk..." };
MENU mn6[] = { 24,55, "Quit",    'Q',
              "Return to the Main Menu..." };

MENU *mnlist[] = { mn1, mn2, mn3, mn4, mn5, mn6, 0 };

/*
    The second parameter that can be passed to the MFP function is a
    procedure list that sets up a relationship of keyboard keys to
    functions.

    The procedure is called when the defined key is pressed. When the
    procedure is finished MFP regains control from where it left off.

    The typedef PROC defines a structure that is used to define the
    link between key and function. A PROC variable is defined and a
    list of PROC variables is passed to the MFP function.

    The PROC variable needs the integer key value returned by inkey()
    and a pointer to the function.

    Any key that the inkey() function can detect is legal for use
    as a hot key.
*/

/*
    The second parameter that can be passed to the MFP function is a
    procedure list that sets up a relationship of keyboard keys to
    functions.

    The procedure is called when the defined key is pressed. When the
    procedure is finished MFP regains control from where it left off.

    The typedef PROC defines a structure that is used to define the
    link between key and function. A PROC variable is defined and a
    list of PROC variables is passed to the MFP function.

    The PROC variable needs the integer key value returned by inkey()
    and a pointer to the function.

    Any key that the inkey() function can detect is legal for use
    as a hot key.

    The following is an example of hot key definitions:

        void help( void );
        void popup_1( void );
        void popup_2( void );

        PROC  hotkey_1[] = { FN1, help };
        PROC  hotkey_2[] = { FN2, popup_1 };
        PROC  hotkey_3[] = { FN3, popup_2 };

        PROC  *hotkeys[] = { hotkey_1, hotkey_2, hotkey_3, 0 };

    The PROC list "hotkeys" is an array of pointers to variables of type PROC.

    The order in which the hot keys are listed does not affect operation.

    The "hotkeys" variable would be passed as the second parameter in the
    mfp() function call. Any time F1, F2, or F3 were pressed when mfp() was
    executed the functions help(), popup_1(), or popup_2() would execute
    then return control to mfp().

    NOTE: The PROC list, like the MFP list, must be terminated with a
          zero.
*/

/*
	Setup the hot key procedures
*/

PROC p1[] = { FN1, help };

/*
                Fast() is primarily designed to operate as a function key
                procedure used in a MFP edit session. It is assigned a
                function key within a PROC declaration.

                A global edit list called "ed_list" must be intialized.

                Fast() uses this "ed_list" to know the fields that can
                be edited. Commonly the ed_list is made equal to the
                mfp list that you pass to MFP. This allows fast() to
                access all fields on the screen.

                In some cases you may want certain fields excluded or
                extra fields included. You should set up a seperate edit
                list for these occasions.

                The ed_list is defined in the MFP library. This means
                you can make up several fast edit lists and before calling
                mfp() you can make "ed_list" equal to that list.

                In the example program described in the MFP section you
                will notice the fast() function being assigned to function
                key two. You should also notice that the "ed_list" is made
                equal to the mfp list in line 49. This makes all fields
                defined in that mfp list accessable to the fast() function.

                Any function that uses the PROC list for function key
                procedures may use fast() to allow field editing.
*/
PROC p2[] = { FN2, fast };

PROC *plist[] = { p1, p2, 0 };

FILE *fp;

/*
    The following text is used for the numeric entry fields...
*/

char *name_txt[] = { 	"Please enter the name",
						"of the stellar system.",
						"",
						"The name can be any",
						"combination of letters",
						"or numbers up to twenty",
						"characters long.",
						0
					};
char *size_txt[] = 	{	"Please enter the number",
						"of stellar mass bodies",
						"in this system.",
						"",
						"A binary system would",
						"have two stellar masses.",
						"",
						"A system like our sun's",
						"would have only one.",
						0
					};
char *lux_txt[] =	{	"Please enter the relative",
						"intensity of the stellar",
						"system in units of lux.",
						"",
						"This must be the relative",
						"value not the absolute.",
						"",
						"This value may be positive",
						"or negative with limits to",
						"+/- 32000.",
						"",
						"It also must be a whole",
						"number.",
						0
					};
char *alux_txt[] =	{	"Please enter the absolute",
						"intensity of the stellar",
						"system in units of lux.",
						"",
						"This must be the absolute",
						"value and not the relative.",
						"",
						"This value must be positive.",
						"Largest value cannot exceed",
						"65,535. It must also be a",
						"whole number.",
						0
					};
char *sftp_txt[] =	{
						"Please enter the surface",
						"temparature in degrees",
						"Kelvin.",
						"",
						"The measured temparature",
						"must be in whole degrees",
						"and may be positive or",
						"negative.",
						"",
						"In the case of a multiple",
						"unit system, please enter",
						"the average temparature.",
						0
					};
char *age_txt[] =	{
						"Please enter the age of",
						"he system in years.",
						"",
						"The age can be approximated",
						"by the apparent luminosity",
						"and the surface temp.",
						"",
						"The age cannot exceed 32",
						"billion years.",
						0
					};
char *magn_txt[] =	{
						"Please enter the magnitude",
						"of the largest body in this",
						"system.",
						"",
						"The magnitude of this system",
						"can be entered as a floating",
						"point value.",
						0
					};
char *ltyr_txt[] =	{
						"Please enter the distance",
						"from gravitaional center of",
						"our solar system to the",
						"gravitational center of",
						"this system.",
						"",
						"This value must be entered",
						"in light years. Fractional",
						"light years are permitted.",
						0
					};
char *mass_txt[] =	{
						"Please enter the systems",
						"total mass in grams.",
						"",
						"This includes all masses",
						"that rotate around the",
						"the center of mass of this",
						"system.",
						"",
						"Planetary bodies can be",
						"ommitted if no data is",
						"present.",
						0
					};
char **num_txt[] =	{
						name_txt,
						size_txt,
						lux_txt,
						alux_txt,
						sftp_txt,
						age_txt,
						magn_txt,
						ltyr_txt,
						mass_txt
					};

/*
    Character entry instructional text...
*/

char *fname_txt[] = {
                        "Please enter the first name.",
                        "",
                        "The entry will be capital-",
                        "ized for you.",
                        "",
                        "This is a twenty character",
                        "field.",
                        0
                    };
char *lname_txt[] = {
                        "Please enter the last name.",
                        "",
                        "The entry will be capital-",
                        "ized for you.",
                        "",
                        "This is a twenty character",
                        "field.",
                        0
                    };
char *strt_txt[]  = {
                        "Please enter the street",
                        "address.",
                        "",
                        "The entry will be capital-",
                        "ized for you.",
                        "",
                        "This is a twenty character",
                        "field.",
                        0
                    };
char *city_txt[]  = {
                        "Please enter the city name.",
                        "",
                        "The entry will be capital-",
                        "ized for you.",
                        "",

⌨️ 快捷键说明

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