Exemplo n.º 1
0
void
ui_open_datafile()
{
    char *filename;

    filename = ask_filename(_("File to open: "));

    if(!filename || ! *filename) {
        free(filename);
        refresh_screen();
        return;
    }

    if(opt_get_bool(BOOL_AUTOSAVE))
        save_database();
    else if(statusline_ask_boolean(_("Save current database"), FALSE))
        save_database();

    close_database();

    load_database(filename);

    if(list_is_empty()) {
        statusline_msg(_("Sorry, the specified file appears not to be a valid abook addressbook"));
        load_database(datafile);
    } else {
        free(datafile);
        datafile = xstrdup(filename);
    }

    refresh_screen();
    free(filename);

    alternative_datafile = TRUE;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
    init_args(argc, argv);
    load_params();
    init_graphics();

    /* not used */
    load_database();
    draw();
    set_texture_coord();
    save_database();
    return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
  char option;
  int op;
  RBTree *tree = NULL;

  while ( 1 )
  {
    show_menu(tree);

    printf("Indiqui la opcio: ");
    scanf("%c", &option);
    flush();
    
    printf("option: [%c]\n", option);

    switch ( option )
    {
      case '1':
        clean_up(tree);
        tree = import_database();
        break;
      case '2':
        save_database(tree);
        break;
      case '3':
        clean_up(tree);
        tree = malloc(sizeof(RBTree));
        op = load_database(tree);
        if ( op == PRS_FILE_NOT_FOUND ) {
          free(tree);
          tree = NULL;
        }
        break;
      case '4':
        generate_statistics(tree);
        break;
      case '5':
        clean_up(tree);
        exit(0);
        break;
      default:
        printf("\nOption not recognised.\n");
        break;
    }
  }

  return 0;
}
Exemplo n.º 4
0
bool idaapi do_backup_database(void *)
{
  if (!netnode::inited())
    return false;

  char outfile[QMAXPATH];
  SYSTEMTIME st;
  GetSystemTime(&st);

  qsnprintf(outfile, QMAXPATH, "%s_%02d-%02d-%4d-%02d-%02d-%02d.idb", 
    get_filename_no_idb(), st.wMonth, st.wDay, st.wYear, st.wHour, st.wMinute, st.wSecond);

  save_database(outfile, false);
  msg("Database backed up to: %s\n", outfile);

  return false;
}
Exemplo n.º 5
0
void
Display(void)
{
    DisplayCount++;
    switch (DisplayCount) {
    case 10:
	draw();
	break;
    case 11:
	saveSkin();
	break;
    case 12:
	set_texture_coord();
	save_database();
	break;
    case 20:
	exit(0);
	break;
    }
    glutSwapBuffers();
    glutPostRedisplay();
}
// global variables used: clouds_dir, database_dir
int 
vtree_user::start()
{
	//if init build and save the database
	if (command.compare("/init") == 0)
	{
		build_database(clouds_dir);
		save_database(database_dir);
	}
	//load previously built database and perform recognition
	else if (command.compare("/load") == 0)
		load_database(database_dir);

	//only extract features and save them in a specified images_directory
	else if (command.compare("/features_only") == 0)
	{
		std::vector<FeatureVector> clouds;
		trace_directory(clouds_dir.c_str(), "", clouds, true);	// TODO: What does this do?
	}
	else
		return 1;
	
	return 0;
}
Exemplo n.º 7
0
void
get_commands()
{
    int ch;

    for(;;) {
        can_resize = TRUE; /* it's safe to resize now */
        if(!opt_get_bool(BOOL_SHOW_CURSOR))
            hide_cursor();
        if(should_resize)
            refresh_screen();
        ch = getch();
        if(!opt_get_bool(BOOL_SHOW_CURSOR))
            show_cursor();
        can_resize = FALSE; /* it's not safe to resize anymore */
        switch(ch) {
        case 'q':
            return;
        case 'Q':
            quit_abook(QUIT_DONTSAVE);
            break;
        case 'P':
            print_stderr(selected_items() ?
                         -1 : list_get_curitem());
            return;
        case '?':
            display_help(HELP_MAIN);
            refresh_screen();
            break;
        case 'a':
            add_item();
            break;
        case '\r':
            edit_item(-1);
            break;
        case KEY_DC:
        case 'd':
        case 'r':
            ui_remove_items();
            break;
        case 'D':
            duplicate_item();
            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 'g':
        case KEY_HOME:
            goto_home();
            break;
        case 'G':
        case KEY_END:
            goto_end();
            break;

        case 'w':
            save_database();
            break;
        case 'l':
            ui_read_database();
            break;
        case 'i':
            import_database();
            break;
        case 'e':
            export_database();
            break;
        case 'C':
            ui_clear_database();
            break;

        case 'o':
            ui_open_datafile();
            break;

        case 's':
            sort_by_field("name");
            break;
        case 'S':
            sort_surname();
            break;
        case 'F':
            sort_by_field(NULL);
            break;

        case '/':
            ui_find(0);
            break;
        case '\\':
            ui_find(1);
            break;

        case ' ':
            if(list_get_curitem() >= 0) {
                list_invert_curitem_selection();
                ui_print_number_of_items();
                refresh_list();
            }
            break;
        case '+':
            select_all();
            refresh_list();
            break;
        case '-':
            select_none();
            refresh_list();
            break;
        case '*':
            invert_selection();
            refresh_list();
            break;
        case 'A':
            move_curitem(MOVE_ITEM_UP);
            break;
        case 'Z':
            move_curitem(MOVE_ITEM_DOWN);
            break;

        case 'm':
            launch_mutt(selected_items() ?
                        -1 : list_get_curitem());
            refresh_screen();
            break;

        case 'p':
            ui_print_database();
            break;

        case 'v':
            launch_wwwbrowser(list_get_curitem());
            refresh_screen();
            break;
        case 'H':
            launch_callpgm(list_get_curitem(), 'H');
            refresh_screen();
            break;
        case 'W':
            launch_callpgm(list_get_curitem(), 'W');
            refresh_screen();
            break;
        case 'M':
            launch_callpgm(list_get_curitem(), 'M');
            refresh_screen();
            break;
        }
    }
}
Exemplo n.º 8
0
// main() function - where the action all starts...
int main(int argc, char *argv[])
{
	int selection, i,j;
	char ch;
	char name[NAMELENGTH],phone[NOLENGTH];
	struct entry *p;
	
	for (i=0;i<SIZE;i++)
		head[i] = tail[i] = NULL;

	if (argc == 2)
	{
		load_database(argv[1]);
	}
	else
		argv[1] = "phonebook.txt";
    
	printf("********************************\n");
   	printf("Welcome to the SAT Phone Book!\n");
    
   	while (selection  != 5)
   	{
        	printf("Please make your selection.\n");
          	printf("1 - Add a Name to the Phone Book\n");
          	printf("2 - Delete a Name from the Phone Book\n");
          	printf("3 - Display all Names in the Phone Book\n");
          	printf("4 - Display all Names of A Specific Letter\n");
		printf("5 - Quit\n");
          
		selection = 0;
		scanf("%d",&selection);
		  
		printf("********************************\n");
		  
		switch (selection)
		{
			case 1:
				printf("Type in the First Name\n");
				scanf("%s",name);
				printf("Type in the Phone Number\n");
				scanf("%s",phone);
			      	insert(name,phone);
			      	break;
			case 2:
				printf("Type in the First Name\n");
				scanf("%s",name);
				delete(name);
			      	break;
			case 3:
			      	display();
			      	break;
			case 4:
				printf("What is the first letter ");
				printf("of the first name?\n");
				scanf("\n%c",&ch);
				display_letter(&ch);
				break;

			case 5:
				save_database(argv[1]);
				break;
			default:
				printf("Sorry, your menu selection ");
				printf("is invalid.\n");
				break;
		}
		  
		printf("********************************\n");
	}
	    
	return 0;
}
Exemplo n.º 9
0
int main(int argc, char ** argv) {
	check();

	// Передан файл базы как параметр
	if (argc == 2) {
		db_filename = argv[1];
	}
	// Файл не передан, используется имя по умолчанию
	else if (argc == 1) {
		db_filename = "default.db";
	}
	// Неправильное использование
	else {
		fprintf( stderr, "Usage: dictionary [words.db]\n");
		exit( EXIT_WRONG_USAGE);
	}

	assert(NULL != db_filename);

	FILE * f = NULL;
	int code = access(db_filename, R_OK | W_OK);
	// Нет прав, не существует файл или что-нибудь ещё
	if (-1 == code) {
		// Нет файла, можно создавать
		if ( errno == ENOENT) {
			f = fopen(db_filename, "w+");
			fprintf( stderr, "INFO: Файл не существовал и теперь создан.\n");
		} else if ( errno == EACCES) {
			fprintf( stderr, "FATAL: Нет прав доступа к базе.\n");
			exit( EXIT_WRONG_RIGHTS);
		} else {
			printf("errno = %d\n", errno);
			exit( EXIT_WTF);
		}
	}
	// Есть права и файл существует
	else {
		f = fopen(db_filename, "r+");
		fprintf( stderr, "INFO: Существующий файл открыт для работы.\n");
	}
	assert(NULL != f);

	fseek(f, 0, SEEK_END);
	int length = ftell(f);
	fprintf( stderr, "DEBUG: Длина файла: %d\n", length);

	if (length < HEADER_SIZE) {
		// Длина файла заведомо меньше размера header. Пишем новый.
		write_new_header(&header, f);
	} else {
		// Читаем
		read_header(&header, f);

		// Проверяем
		if (header.version != 1 || header.actual_words > header.total_words) {
			fprintf( stderr,
					"FATAL: База данных (%s), вероятно, испорчена. Возможно, стоит её удалить.\n",
					db_filename);
			WTF();
		}
	}

	// Всё есть. Можно работать.
	printf("Введите help для справки, quit для выхода.\n");
	int working = 1;
	while (working) {
		printf("> ");

		char str[6];
		fgets(str, 6, stdin);
		remove_newline(str);
		if (strcmp(str, "help") == 0) {
			command_help();
		} else if (strcmp(str, "quit") == 0 || strcmp(str, "exit") == 0
				|| strcmp(str, "bye") == 0) {
			save_database(f);
			exit( EXIT_SUCCESS);
		} else if (strcmp(str, "add") == 0) {
			command_add(f);
		} else if (strcmp(str, "find") == 0) {
			command_find(f);
		} else if (strcmp(str, "del") == 0 || strcmp(str, "rm") == 0) {
			command_remove(f);
		} else if (strcmp(str, "frag") == 0) {
			command_defragment(f);
		} else {
			fprintf( stderr, "ERROR: Неизвестная команда '%s'\n", str);
		}
	}

	/*
	 Операции:
	 1. Добавить слово. Имя (128 байт), содержание (не ограничено) ->
	 2. Найти слово. Имя -> содержание
	 3. Удалить. Имя ->
	 */
	if (f != NULL)
		fclose(f);

	return EXIT_SUCCESS;
}