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

📄 userinterfaceutilities.c

📁 这是一个由C语言开发的电话本程序,很有参考价值.
💻 C
📖 第 1 页 / 共 2 页
字号:
    			list will be written to disk and the record will be erased    			completely (undelete not available in this case).  ===============================================================================*/void ui_DeleteEntry(void *Dummy){	struct Record *rec;	int choice;	if (gl_HighestID == 0)	{		printf ("No entries in the database!\n");		io_EnterToContinue();		return;	}		printf("Enter Record ID Number (1-%d, x to exit) >", gl_HighestID);	if ((choice = io_GetInt(gl_HighestID)) == RC_BAD)		return;	if ((rec = li_GetDataPtrByID(gl_AppData.MainList, choice)) == NULL)	{		printf("No such entry: %d\n", choice);		io_EnterToContinue();		return;	}		rec_PrintLong(rec);		if (io_GetYesNo("Confirm Delete (y/n) >") == TRUE)	{		rec->Status = rec->Status | ST_DELETED;		gl_AppData.DataChanged = TRUE;		if (gl_AppCfg.AutoSave) (void)io_WriteAllRecordsToFile(gl_AppData.MainList);	}}/*  =============================================================================== 	Function: 	ui_UndeleteEntry    Args: 		None (NULL Pointer)    Returns: 	Nothing    Purpose:	Gets an ID from the user, and unsets the deleted flag.  ===============================================================================*/void ui_UndeleteEntry(void *Dummy){	struct Record *rec;	int choice;		if (gl_HighestID == 0)	{		printf ("No entries in the database!\n");		io_EnterToContinue();		return;	}		printf("Enter Record ID Number (1-%d, x to exit) >", gl_HighestID);	if ((choice = io_GetInt(gl_HighestID)) == RC_BAD)		return;	if ((rec = li_GetDataPtrByID(gl_AppData.MainList, choice)) == NULL)	{		printf("No such entry: %d\n", choice);		io_EnterToContinue();		return;	}		if (rec->Status & ST_DELETED)	{		rec->Status = rec->Status ^ ST_DELETED;		printf ("Record undeleted\n");		gl_AppData.DataChanged = TRUE;		if (gl_AppCfg.AutoSave) (void)io_WriteAllRecordsToFile(gl_AppData.MainList);	}	else		printf ("Record was not marked for deletion\n");		io_EnterToContinue();	}/*  =============================================================================== 	Function: 	ui_SearchByID    Args: 		None    Returns: 	Nothing    Purpose:	Gets an ID from the user, then display that Record in detail  ===============================================================================*/void ui_SearchByID(void){	struct Record *rec;	int choice;		if (gl_HighestID == 0)	{		printf ("No entries in the database!\n");		io_EnterToContinue();		return;	}	printf("Enter Record ID Number (1-%d, x to exit) >", gl_HighestID);	if ((choice = io_GetInt(gl_HighestID)) == RC_BAD)		return;	if ((rec = li_GetDataPtrByID(gl_AppData.MainList, choice)) == NULL)		printf("No such entry: %d\n", choice);	else rec_PrintLong(rec);	io_EnterToContinue();}/*  =============================================================================== 	Function: 	ui_SearchAll    Args: 		Field type    Returns: 	Nothing    Purpose:	Gets search criteria from user, the traverses the list, short    			printing each record that matches the criteria.  ===============================================================================*/void ui_SearchAll(void *WhichField){	char	buffer[MAXL_FIELD + 1];	int		i, len;	if (gl_HighestID == 0)	{		printf ("No entries in the database!\n");		io_EnterToContinue();		return;	}		if ((enum RECORD_FIELDS)WhichField == RECF_ID) 	{		ui_SearchByID();		return;	}		printf("Enter Criteria >");		if ((len = io_GetLine(buffer, MAXL_FIELD + 1, stdin)) != 0)	{		gl_AppData.SearchField = (enum RECORD_FIELDS)WhichField;		for (i = 0; i < len; i++)	/* convert to lower case for search */			if (isupper(buffer[i])) buffer[i] = tolower(buffer[i]);		strncpy(gl_AppData.SearchText, buffer, MAXL_FIELD + 1);		gl_AppData.LinesDisplayedSoFar = 0;		(void)li_Traverse(gl_AppData.MainList, rec_SearchAndPrint);	}	io_EnterToContinue();}/*  =============================================================================== 	Function: 	ui_DisplayAll    Args: 		None    Returns: 	Nothing    Purpose:	Traverses the list and does a short print of each record  ===============================================================================*/void ui_DisplayAll(void *Dummy){	if (gl_HighestID == 0)	{		printf ("No entries in the database!\n");		io_EnterToContinue();		return;	}		gl_AppData.LinesDisplayedSoFar = 0;	gl_AppData.SearchField = RECF_DUMMY;	(void)li_Traverse(gl_AppData.MainList, rec_SearchAndPrint);	io_EnterToContinue();}/*  =============================================================================== 	Function: 	ui_Save    Args: 		None (NULL Pointer)    Returns: 	Nothing    Purpose:	Gets confirmation from the user, then saves the current list to disk  ===============================================================================*/void ui_Save(void *Dummy){	if (io_GetYesNo("Confirm Save (including purge of deleted records) (y/n) >") == TRUE)	{		(void)io_WriteAllRecordsToFile(gl_AppData.MainList);	}}/*  =============================================================================== 	Function: 	ui_PurgeDeleted    Args: 		None (NULL Pointer)    Returns: 	Nothing    Purpose:	Gets confirmation from the user, then traverses the list,    			removing (free'ing) any records that are marked as deleted  ===============================================================================*/void ui_PurgeDeleted(void *Dummy){	unsigned char status = ST_DELETED;		if (gl_HighestID == 0)	{		printf ("No entries in the database!\n");		io_EnterToContinue();		return;	}		if (io_GetYesNo("Confirm Purge (y/n) >") == TRUE)		gl_AppData.MainList = li_DeleteNodeAndData (gl_AppData.MainList, &status, rec_CompareStatus);}/*  ===============================================================================    Function: 	ui_ShowInfo    Args: 		None (NULL Pointer)    Returns: 	Nothing    Purpose:	Displays stats about the program and the PhoneBook  =============================================================================== */void ui_ShowInfo(void *Dummy){	printf ("--->\n---> **PhoneBook** - Version: %s\n", PRG_VERSION);	printf ("---> Written By *Hammer* for the C Programming Contest\n");	printf ("---> held by http://www.cprogramming.com/cboard/ in May 2002\n");	printf ("---> You can contact the author via email: claw_hammer@hotmail.com\n");	printf ("--->\n---> The PhoneBook datafile is %s\n", STR_FILENAME);	printf ("---> The PhoneBook configuration file is %s\n", STR_CFG_FILENAME);	printf ("--->\n---> There are currently %d entries loaded.\n", li_Count(gl_AppData.MainList));	printf ("--->\n---> This program accepts command line information\n");	printf ("---> For example (assuming the program name is phone.exe):\n");	printf ("--->   >phone.exe hammer tommy\n");	printf ("---> will result in the database being searched for the\n");	printf ("---> names hammer and tommy and the results being displayed.\n");	printf ("---> In this case, the menu is not loaded, and the\n");	printf ("---> program terminates.  This is useful for quick lookups.\n");	printf ("--->\n");	io_EnterToContinue();}/*  =============================================================================== 	Function: 	ui_ToggleAutoSave    Args: 		None (NULL Pointer)    Returns: 	Nothing    Purpose:	Allows the user to turn auto-save off and on.  ===============================================================================*/void ui_ToggleAutoSave(void *Dummy){	printf ("Auto-Save is currently %s\n", (gl_AppCfg.AutoSave)?"On":"Off");	if (io_GetYesNo("Toggle auto-save (y/n) >") == TRUE)	{		gl_AppCfg.AutoSave = ~gl_AppCfg.AutoSave;		printf ("Auto-Save is now %s\n", (gl_AppCfg.AutoSave)?"On":"Off");		io_EnterToContinue();	}}/*  =============================================================================== 	Function: 	ui_SetLinesPerDisplay    Args: 		None (NULL Pointer)    Returns: 	Nothing    Purpose:	Allows the user to set the number of lines displayed in lists    			before a io_EnterToContinue is called.  ===============================================================================*/void ui_SetLinesPerDisplay(void *Dummy){	int Lines;		printf ("This option determines how many lines are output to the screen\nbefore a \"hit enter to continue\" message is displayed\n");	printf ("The current setting is %d\n", gl_AppCfg.LinesPerDisplay);	printf ("Enter a new number or x to exit >");		if ((Lines = io_GetInt(MAX_LINES_PER_PAGE)) == RC_BAD)		return;			gl_AppCfg.LinesPerDisplay = Lines;	printf ("The new setting is %d\n", gl_AppCfg.LinesPerDisplay);	io_EnterToContinue();}/*  =============================================================================== 	Function: 	ui_SetSortBy    Args: 		Field type    Returns: 	Nothing    Purpose:	Allows the user to set the sort order  ===============================================================================*/void ui_SetSortBy(void *WhichField){	gl_AppCfg.SortField = (enum RECORD_FIELDS)WhichField;		printf ("Sorting the data...");	li_Sort (gl_AppData.MainList, rec_Compare); 	printf ("Done!\n");	io_EnterToContinue();}

⌨️ 快捷键说明

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