예제 #1
0
파일: apev.c 프로젝트: adderly/cmoon
NameEntry* name_push(char *name, NameEntry **entry)
{
    if (name_find(*entry, name) >= 0) return *entry;

    NameEntry *n = name_new(name);
    n->next = *entry;
    *entry = n;

    return n;
}
예제 #2
0
int file_run(FILE* data)
{
    product* work_product = NULL;
    char *file_menu[] = {
        "Show file data;\n",
        "Add record;\n",
        "Edit record;\n",
        "Sort records;\n",
        "Delete record;\n",
        "Save & close the file;\n"
    };

    char menu_symb[] = "0";
    char work_name[NAM_LEN + 1];

    int work_line = 0;
    int menu_count = 0;
    int incorrect_choice = 1;
    int exit = 0;

    do
    {
        incorrect_choice = 1;
        system("clear");
        for(menu_count = 0; menu_count < 6; menu_count++)
            printf("%d) %s", menu_count + 1, file_menu[menu_count]);

        printf("Input the number of menu item:\n");
        while(incorrect_choice)
        {
            menu_symb[0] = getche();
            if(!strpbrk(menu_symb, "123456"))
                printf("Unknown value: %c; repeat the choice\n", menu_symb[0]);
            else
                incorrect_choice = 0;
        }

        switch(menu_symb[0])
        {
        case '1':
        {
            file_read(data);
        }
            break;
        case '2':
        {
            work_product = product_input();
            if(work_product)
            {
                sorted_insert(data, work_product);
                product_destroy(work_product);
            }
        }
            break;
        case '3':
        {
            puts("Input the name of the product to edit:");
            string_input(stdin, NAM_LEN, work_name, 0);

            work_line = name_find(data, work_name);
            if(!work_line)
                alert("\tNo such product;");
            else
            {
                work_product = product_read(data, work_line);
                deleting(data, work_line);
                product_update(work_product);
                product_write(data, work_line, work_product);
                product_destroy(work_product);
            }
        }
            break;
        case '4':
        {

        }
            break;
        case '5':
        {
            puts("Input the name of the product to delete:");
            string_input(stdin, NAM_LEN, work_name, 0);

            work_line = name_find(data, work_name);
            if(!work_line)
                alert("\tNo such product;");
            else
                deleting(data, work_line);
        }
            break;
        case '6':
        {
            file_close(data);
            exit = 1;
        }
            break;
        }

    }while(!exit);

    return menu_symb[0] - '0';
}