📄 main.h
字号:
/* =============================================================================== Author: Hammer, May 2002, For www.cprogramming.com/cboard/ File: main.h Contents: All the definitions needed for the app, along with the function prototypes. This is the only header file used by this program. ===============================================================================*/#ifndef __PHONE__#define __PHONE__#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>/* * #defines * Field lengths - These do NOT include the 1 byte for the NULL terminator */#define MAXL_NAME 100#define MAXL_PHONENUM 20#define MAXL_MISC 256#define MAXL_FIELD 256#define MAXL_ADDR 100#define MAXL_FIELD_NAME 50#define DEF_LINES_PER_PAGE 10#define MAX_LINES_PER_PAGE 999/* * String variables */#define STR_FILENAME "phonebk.dat"#define STR_CFG_FILENAME "phonebk.cfg"#define PRG_VERSION "1.1"#define RC_BAD -1/* * boolean style vars */#define TRUE 1#define FALSE 0/* * Record status flags */#define ST_DELETED 0x1/* * Macros */#define FLUSH_INPUT while(getchar() != '\n')/* * enums */enum RECORD_FIELDS {RECF_DUMMY, RECF_ID, RECF_NAME, RECF_PHONENUM1, RECF_PHONENUM2, RECF_PHONENUM3, RECF_ADDRLINE1, RECF_ADDRLINE2, RECF_ADDRLINE3, RECF_ADDRLINE4, RECF_ADDRLINE5, RECF_EMAILADDR, RECF_MISC, RECF_END_MARKER};/* * typedefs */typedef int bool_t;/* * Structures */struct Record{ int ID; /* Assigned at load time, sequential based on input, not related to tree */ char Name[MAXL_NAME + 1]; /* All in name field, holds any type, so user can decide own format */ char PhoneNum1[MAXL_PHONENUM + 1]; /* 3 phone num fields, user decides what to put where */ char PhoneNum2[MAXL_PHONENUM + 1]; char PhoneNum3[MAXL_PHONENUM + 1]; char AddrLine1[MAXL_ADDR+1]; char AddrLine2[MAXL_ADDR+1]; char AddrLine3[MAXL_ADDR+1]; char AddrLine4[MAXL_ADDR+1]; char AddrLine5[MAXL_ADDR+1]; char EmailAddr[MAXL_ADDR+1]; char Misc[MAXL_MISC + 1]; /* Freeform text field, for user comments. */ unsigned char Status; /* See the ST_... variables */};struct Node{ void *DataPtr; struct Node *Next;};struct appdata{ struct Node *MainList; enum RECORD_FIELDS SearchField; char SearchText[MAXL_FIELD + 1]; bool_t DataChanged; int LinesDisplayedSoFar;};struct appconfig{ bool_t AutoSave; int LinesPerDisplay; enum RECORD_FIELDS SortField; };struct menu_item{ char *Text; void (*fptr) (void *); void *args;};/* * more typedefs */typedef void (*FPTR_Action) (void *);typedef int (*FPTR_Compare) (const struct Record *, const struct Record *);typedef int (*FPTR_CompareDelete) (const struct Record *, void *);/* * Global vars / externs */extern int gl_HighestID;extern struct appdata gl_AppData;extern struct appconfig gl_AppCfg;extern struct menu_item MainMenu[];/* * Prototypes for ListUtilities */struct Node *li_Create(void);struct Node *nd_Create(void *, struct Node *);void nd_Destroy(struct Node *);int li_Traverse(struct Node *, FPTR_Action);struct Node *li_Insert(struct Node *, void *, FPTR_Compare);struct Node *li_Destroy(struct Node *);struct Record *li_GetDataPtrByID(struct Node *, int );struct Node *li_DeleteNodeAndData(struct Node *, void *, FPTR_CompareDelete);int li_Count(struct Node *);void li_Sort(struct Node *, FPTR_Compare);/* * Prototypes for RecordUtilities */int rec_Compare(const struct Record *, const struct Record *);int rec_CompareID(const struct Record *, void *);int rec_CompareStatus(const struct Record *rec, void *);void rec_PrintShort(void *);void rec_PrintLong(void *);void rec_SearchAndPrint(void *);char *rec_GetFieldPointer(const struct Record *, enum RECORD_FIELDS);/* * Prototypes for ioUtilities */void io_WriteRecordToFile(void *);struct Node *io_LoadPhoneBookFromFile(struct Node *);int io_WriteAllRecordsToFile(struct Node *);int io_GetInt(int);void io_EnterToContinue(void);int io_GetLine(char *, int , FILE *);bool_t io_GetYesNo(char *);void io_LoadAppConfig(void);void io_SaveAppConfig(void);/* * Prototypes for UserInterfaceUtilities */void ui_AddNewEntry(void *);void ui_DeleteEntry(void *);void ui_UndeleteEntry(void *);void ui_UpdateEntry(void *);void ui_AddOrUpdateEntry(struct Record *);void ui_DisplayAll(void *);void ui_Save(void *);void ui_PurgeDeleted(void *);void ui_SearchAll(void *);void ui_SearchByID(void);void ui_DisplayMenu(void *);void ui_ShowInfo(void *);void ui_ToggleAutoSave(void *);void ui_SetLinesPerDisplay(void *);void ui_SetSortBy(void *);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -