예제 #1
0
static void browser_delete_file()
{
	struct stat stat_result;

	browser_menu_overlay = browser_menu;
	stat(current_file, &stat_result);
	if(S_ISDIR(stat_result.st_mode)) {
		browser_rmdir(current_file);
	}
	else if(unlink(current_file) == -1) {
		pz_perror(current_file);
		return;
	}
	
	while(browser_menu_overlay->parent != NULL)
		browser_menu_overlay = menu_destroy(browser_menu_overlay);
	menu_delete_item(browser_menu_overlay, browser_menu_overlay->sel);
}
예제 #2
0
파일: products.c 프로젝트: mooseman/pdutils
static void
main_loop (void)
{
	List *products;
	char input[INPUT_BUFFER_SIZE];
	char *t;
	int invalid;

	products = db_load_products ();

	while (1)
	{
		menu_print_main ();
		fgets (input, INPUT_BUFFER_SIZE, stdin);

		/* Check if input is longer than one character */
		invalid = 0;
		for (t = input + 1; t < input + INPUT_BUFFER_SIZE; t++)
		{
			if (*t == 0) break;

			if (*t > 20)
			{
				invalid = 1;
				break;
			}
		}

		if (invalid)
		{
			printf ("Invalid input string\n");
			continue;
		}

		if (*input == 'q' || *input == 'Q')
		{
			break;
		}

		switch (*input)
		{
			case '1':
				products = menu_create_item (products);
				break;
			case '2':
				products = menu_edit_item (products);
				break;
			case '3':
				menu_view_item (products);
				break;
			case '4':
				products = menu_delete_item (products);
				break;
			case '5':
				menu_list_items (products);
				break;
			default:
				printf ("Invalid selection '%c'\n\n", *input);
		}
	}

	db_write_products (products);

	list_foreach (products, LIST_FUNC (product_free));
	list_free (products);
}