- can_resize = TRUE; /* it's safe to resize now */
- hide_cursor();
- if( should_resize )
- refresh_screen();
- ch = getch();
- show_cursor();
- can_resize = FALSE; /* it's not safe to resize anymore */
- switch( ch ) {
- case 'q': return;
- case '?': display_help(mainhelp); break;
- case 'a': add_item(); break;
- case '\r': edit_item(-1); break;
- case KEY_DC:
- case 'd':
- case 'r': remove_items(); break;
- case 12: refresh_screen(); break;
-
- case 'k':
- case KEY_UP: scroll_up(); break;
- case 'j':
- case KEY_DOWN: scroll_down(); break;
- case 'K':
- case KEY_PPAGE: page_up(); break;
- case 'J':
- case KEY_NPAGE: page_down(); break;
-
- case 'H':
- case KEY_HOME: goto_home(); break;
- case 'E':
- case KEY_END: goto_end(); break;
-
- case 'w': save_database();
- break;
- case 'l': read_database(); break;
- case 'i': import_database(); break;
- case 'e': export_database(); break;
- case 'C': clear_database(); break;
-
- case 'y': edit_options(); break;
- case 'o': open_datafile(); break;
-
- case 's': sort_database(); break;
- case 'S': sort_surname(); break;
-
- case '/': find(0); break;
- case '\\': find(1); break;
-
- case ' ': if(curitem >= 0) {
- selected[curitem] = !selected[curitem];
- print_number_of_items();
- refresh_list();
- }
+ int option_index = 0;
+ enum {
+ OPT_ADD_EMAIL,
+ OPT_ADD_EMAIL_QUIET,
+ OPT_MUTT_QUERY,
+ OPT_CONVERT,
+ OPT_INFORMAT,
+ OPT_OUTFORMAT,
+ OPT_INFILE,
+ OPT_OUTFILE,
+ OPT_FORMATS
+ };
+ static struct option long_options[] = {
+ { "help", 0, 0, 'h' },
+ { "add-email", 0, 0, OPT_ADD_EMAIL },
+ { "add-email-quiet", 0, 0, OPT_ADD_EMAIL_QUIET },
+ { "datafile", 1, 0, 'f' },
+ { "mutt-query", 1, 0, OPT_MUTT_QUERY },
+ { "config", 1, 0, 'C' },
+ { "convert", 0, 0, OPT_CONVERT },
+ { "informat", 1, 0, OPT_INFORMAT },
+ { "outformat", 1, 0, OPT_OUTFORMAT },
+ { "infile", 1, 0, OPT_INFILE },
+ { "outfile", 1, 0, OPT_OUTFILE },
+ { "formats", 0, 0, OPT_FORMATS },
+ { 0, 0, 0, 0 }
+ };
+
+ c = getopt_long(argc, argv, "hC:",
+ long_options, &option_index);
+
+ if(c == -1)
+ break;
+
+ switch(c) {
+ case 'h':
+ show_usage();
+ exit(1);
+ case OPT_ADD_EMAIL:
+ change_mode(&mode, MODE_ADD_EMAIL);