int main(){ char *home = getenv("HOME"); person *got; time_t rawtm; struct tm *ti; char *file = malloc((strlen(home) + 10)*sizeof(char)); sprintf(file, "%s/.vyrocia", home); time(&rawtm); ti = localtime(&rawtm); FILE *f = fopen(file, "r"); if(!f){ perror(file); return 1; } got = read_entry(f); while(got != NULL){ if(got->day == ti->tm_mday && got->month - 1 == ti->tm_mon){ printf("MATCH FOUND\nName: %s\nEvent: %s\n", got->name, got->event); } free(got); got = read_entry(f); } fclose(f); return 0; }
static int find_pos(uint64 key) { int left, right, mid; entry_t entry[1]; // binary search (finds the leftmost entry) left = 0; right = BookSize-1; ASSERT(left<=right); while (left < right) { mid = (left + right) / 2; ASSERT(mid>=left&&mid<right); read_entry(entry,mid); if (key <= entry->key) { right = mid; } else { left = mid+1; } } ASSERT(left==right); read_entry(entry,left); return (entry->key == key) ? left : BookSize; }
/* reads the canned reply file and returns a list of structs */ struct entry* read_datafile(const char* name) { struct entry* list = NULL; struct entry* last = NULL; struct entry* current = NULL; FILE *in; int lineno = 0; uint32_t default_ttl = 0; ldns_rdf* origin = NULL; ldns_rdf* prev_rr = NULL; int entry_num = 0; if((in=fopen(name, "r")) == NULL) { error("could not open file %s: %s", name, strerror(errno)); } while((current = read_entry(in, name, &lineno, &default_ttl, &origin, &prev_rr))) { if(last) last->next = current; else list = current; last = current; entry_num ++; } verbose(1, "%s: Read %d entries\n", prog_name, entry_num); fclose(in); ldns_rdf_deep_free(origin); ldns_rdf_deep_free(prev_rr); return list; }
size_t MemTranspositionTable<CAPACITY>::size() const { size_t count = 0; for (size_t i=0; i<CAPACITY/10240; i++) if (TpResult(read_entry(i).result) != TpResult::NONE) count++; return count*10240; }
const aku_Entry *PageHeader::read_entry_at(uint32_t index) const { if (index < count) { auto offset = page_index(index)->offset; return read_entry(offset); } return 0; }
int PageHeader::get_entry_length(uint32_t offset) const { auto entry_ptr = read_entry(offset); if (entry_ptr) { return entry_ptr->length; } return 0; }
int vrpn_File_Connection::reset() { // make it as if we never saw any messages from our previous activity d_endpoints[0]->drop_connection(); // If we are accumulating, reset us back to the beginning of the memory // buffer chain. Otherwise, go back to the beginning of the file and // then read the magic cookie and then the first entry again. if (d_accumulate) { d_currentLogEntry = d_startEntry; } else { rewind(d_file); read_cookie(); read_entry(); d_startEntry = d_currentLogEntry = d_logHead; } d_time = d_startEntry->data.msg_time; // reset for mainloop() d_last_time.tv_usec = d_last_time.tv_sec = 0; d_filetime_accum.reset_at_time( d_last_time ); // This is useful to play the initial system messages // (the sender/type ones) automatically. These might not be // time synched so if we don't play them automatically they // can mess up playback if their timestamps are later then // the first user message. if (vrpn_FILE_CONNECTIONS_SHOULD_SKIP_TO_USER_MESSAGES) { play_to_user_message(); } return 0; }
// checks if there is at least one log entry that occurs // between the current d_time and the given filetime // // [juliano 9/24/99] the above comment is almost right // the upper bound of the interval is not open, // but closed at time_we_want_to_play_to. // // this function checks if the next message to play back // from the stream file has a timestamp LESSTHAN OR EQUAL TO // the argument to this function (which is the time that we // wish to play to). If it does, then a pos value is returned // // you can pause playback of a streamfile by ceasing to increment // the value that is passed to this function. However, if the next // message in the streamfile has the same timestamp as the previous // one, it will get played anyway. Pause will not be achieved until // all such messages have been played. // // Beware: make sure you put the correct timestamps on individual // messages when recording them in chunks (batches) // to a time to a streamfile. // int vrpn_File_Connection::need_to_play( timeval time_we_want_to_play_to ) { // This read_entry() call may be useful to test the state, but // it should be the case that d_currentLogEntry is non-NULL except // when we are at the end. This is because read_entry() and the // constructor now both read the next one in when they are finished. if (!d_currentLogEntry) { int retval = read_entry(); if (retval < 0) { return -1; } // error reading from file if (retval > 0) { return 0; } // end of file; nothing to replay d_currentLogEntry = d_logTail; // If read_entry() returns 0, this will be non-NULL } vrpn_HANDLERPARAM & header = d_currentLogEntry->data; // [juliano 9/24/99] is this right? // this is a ">" test, not a ">=" test // consequently, this function keeps returning true until the // next message is timestamped greater. So, if a group of // messages share a timestamp, you cannot pause streamfile // replay anywhere inside the group. // // this is true, but do you ever want to pause in the middle of // such a group? This was a problem prior to fixing the // timeval overflow bug, but now that it's fixed, (who cares?) return vrpn_TimevalGreater( time_we_want_to_play_to, header.msg_time ); }
static pa_hook_result_t source_new_hook_callback(pa_core *c, pa_source_new_data *new_data, struct userdata *u) { char *name; struct entry *e; pa_assert(c); pa_assert(new_data); pa_assert(u); pa_assert(u->restore_port); name = pa_sprintf_malloc("source:%s", new_data->name); if ((e = read_entry(u, name))) { if (e->port_valid) { if (!new_data->active_port) { pa_log_info("Restoring port for source %s.", name); pa_source_new_data_set_port(new_data, e->port); new_data->save_port = TRUE; } else pa_log_debug("Not restoring port for source %s, because already set.", name); } pa_xfree(e); } pa_xfree(name); return PA_HOOK_OK; }
int remove_words(FILE * f, char * word) { int count = 0; // асимптотика квадратичная :) // TODO: сделать параметр from в find_word, чтобы сделать её линейной. while (1) { uint64 start = find_word(f, word); if (start == 0) { // Если нет слова, и мы его не удаляли return count; } struct entry_t entry; // TODO: дважды read_entry -- плохо read_entry(f, &entry, start, READ_ENTRY_ALL); mark_deleted_entry(&entry); count++; int code = fseek(f, start, SEEK_SET); if (0 != code) WTF(); write_entry(f, &entry); header.actual_words--; write_header(&header, f); } }
void command_defragment(FILE * f) { uint64 read_index, write_index, index; read_index = write_index = jump_to_first_word(f); int read_count = 0; int write_count = 0; struct entry_t entry; again: if (write_count < header.actual_words) { index = read_entry(f, &entry, read_index, READ_ENTRY_ALL); if (existent_entry(&entry)) { read_index = index; read_count++; int code = fseek(f, write_index, SEEK_SET); if (0 != code) WTF(); write_entry(f, &entry); write_count++; write_index += entry_size(&entry); goto again; } else { read_index = index; goto again; } } else { header.total_words = header.actual_words; write_header(&header, f); ftruncate(fileno(f), write_index); } }
int main (int argc, char *argv[]) { int type; void *data; int num_nums = argc - 1; int i; long nums [num_nums]; for (i = 0; i < num_nums; ++i) nums [i] = strtoul (argv [i + 1], NULL, 16); while ((type = read_entry (stdin, &data)) != SGEN_PROTOCOL_EOF) { gboolean match = FALSE; for (i = 0; i < num_nums; ++i) { if (is_match ((gpointer) nums [i], type, data)) { match = TRUE; break; } } if (match) print_entry (type, data); free (data); } return 0; }
static int t3_write_read_check_multiple(void) { int ret = 0; int fd; char write_item[] = "0x44332211, " "0x00000000, " "0xA0000000, " "0xB0000000, " "0xC0000000, " "0x00000000, " "0x00000000, " "0xD0000000, " "0xE0000000, " "0xF0000000 "; char read_item[sizeof(write_item)]; if (!enable_test[3]) return 0; fd = open("/dev/smem_log", O_RDWR); if (fd < 0) { perror("open"); return -1; } ret = ioctl(fd, SMIOC_SETMODE, SMIOC_TEXT); if (ret == -1) { printf("ERROR %s:%i ioctl(SMIOC_BINARY): %s\n", __func__, __LINE__, strerror(errno)); goto free_resources; } ret = write_entry(fd, write_item, sizeof(write_item)); if (ret == -1) goto free_resources; ret = read_entry(fd, read_item, sizeof(read_item)); if (ret == -1) goto free_resources; D("read_item = %.*s\n", sizeof(read_item), read_item); D("write_item = %.*s\n", sizeof(write_item), write_item); ret = is_equal_multiple(read_item, write_item); if (ret == -1) { printf("ERROR:%s:%i\n", __func__, __LINE__-4); goto free_resources; } free_resources: close(fd); return ret; }
int main(int argc, char **argv, char **env_p) { g_env = env_p; if (argc != 1 || argv[1]) ft_putstr("Minishell do not take any argument !\n"); else read_entry(0); return (0); }
static void no_more_lines(char *line, t_env *env) { while (read_entry(ft_strsplit(line, ';'), &env) != -1) { prompt(env); ft_strdel(&line); get_next_line(0, &line); } ft_strdel(&line); }
static int t2_write_read_check(void) { int ret = 0; int fd; char write_item[] = "0x11223344, " "0x00000000, " "0x10000000, " "0x20000000, " "0x30000000 "; char read_item[sizeof(write_item)]; if (!enable_test[2]) return 0; fd = open("/dev/smem_log", O_RDWR); if (fd < 0) { perror("open"); return -1; } ret = ioctl(fd, SMIOC_SETMODE, SMIOC_TEXT); if (ret == -1) { printf("ERROR %s:%i ioctl(SMIOC_BINARY): %s\n", __func__, __LINE__, strerror(errno)); goto free_resources; } ret = write_entry(fd, write_item, sizeof(write_item)); if (ret == -1) goto free_resources; ret = read_entry(fd, read_item, sizeof(read_item)); if (ret == -1) goto free_resources; ret = is_equal(read_item, write_item); if (ret == -1) { read_item[sizeof(read_item)-1] = '\0'; write_item[sizeof(write_item)-1] = '\0'; printf("ERROR:%s:%i\n", __func__, __LINE__-4); printf("read_item = %s\n", read_item); printf("write_item = %s\n", write_item); goto free_resources; } free_resources: close(fd); return ret; }
int PageHeader::copy_entry(uint32_t offset, aku_Entry *receiver) const { auto entry_ptr = read_entry(offset); if (entry_ptr) { if (entry_ptr->length > receiver->length) { return -1*entry_ptr->length; } memcpy((void*)receiver, (void*)entry_ptr, entry_ptr->length); return entry_ptr->length; } return 0; }
void GetMenuBar(std::string const& name, wxFrame *window, agi::Context *c) { menu_items const& items = get_menu(name); std::auto_ptr<CommandMenuBar> menu(new CommandMenuBar(c)); for (menu_items::const_iterator it = items.begin(); it != items.end(); ++it) { std::string submenu, disp; read_entry(*it, "submenu", &submenu); read_entry(*it, "text", &disp); if (!submenu.empty()) { menu->Append(build_menu(submenu, c, &menu->cm), _(lagi_wxString(disp))); } else { read_entry(*it, "special", &submenu); if (submenu == "automation") menu->Append(new AutomationMenu(c, &menu->cm), _(lagi_wxString(disp))); } } window->Bind(wxEVT_MENU_OPEN, &CommandManager::OnMenuOpen, &menu->cm); window->Bind(wxEVT_COMMAND_MENU_SELECTED, &CommandManager::OnMenuClick, &menu->cm); window->SetMenuBar(menu.get()); #ifdef __WXGTK__ // GTK silently swallows keypresses for accelerators whose associated // menu items are disabled. As we don't update the menu until it's // opened, this means that conditional hotkeys don't work if the menu // hasn't been opened since they became valid. // // To work around this, we completely disable accelerators from menu // item. wxGTK doesn't expose any way to do this other that at wx // compile time (SetAcceleratorTable is a no-op), so have some fun with // the implementation details of undocumented methods. Detaching via // wxMenuBar::Detach removes the accelerator table, and then // wxMenuBarBase::Attch is used to avoid readding it. menu->Detach(); menu->wxMenuBarBase::Attach(window); #endif menu.release(); }
main() { FILE *fp; int i,rc; DB_PTR entry; char name_to_search [16]; fp = fopen ("file.in", "r"); if (fp == NULL) { printf ("failed to open file.in\n"); exit (-1); } for (i = 0; i < MAX_HASH_BUCKETS; i++) { hashtable[i] = NULL; } while (1) { entry = malloc (sizeof (struct database)); if (entry == NULL) { printf ("malloc failed\n"); exit (-2); } rc = read_entry (fp, entry); if (rc == -1) { free (entry); break; } int index = hash (entry->name); add_to_hash_list (&hashtable[index], entry); } printf("%s\n", hashtable[0]->name); while (1) { printf ("entry name to search: "); scanf ("%s", name_to_search); printf ("\n"); if (strcmp (name_to_search, "exit") == 0) { printf ("bye\n"); exit (0); } entry = search_hash_list (hashtable, name_to_search); if (entry) { printf ("weight = %d height = %d\n", entry->weight, entry->height); } else { printf ("Name not found\n"); } } }
// Advance to next entry. If there is no next entry, and if we have // not preloaded, then try to read one in. int vrpn_File_Connection::advance_currentLogEntry(void) { d_currentLogEntry = d_currentLogEntry->next; if (!d_currentLogEntry && !d_preload) { int retval = read_entry(); if (retval != 0) { return -1; // error reading from file or EOF } d_currentLogEntry = d_logTail; // If read_entry() returns zero, this will be non-NULL } return 0; }
// returns 1 if we're at the EOF, -1 on error int vrpn_File_Connection::eof() { if (d_currentLogEntry) { return 0; } // read from disk if not in memory int ret = read_entry(); if (ret == 0) { d_currentLogEntry = d_logTail; // If read_entry() returns zero, this will be non-NULL } return ret; }
int book_move(board_t * board) { int best_move; int best_score; int pos; entry_t entry[1]; int move; int score; list_t list[1]; int i; ASSERT(board!=NULL); if (BookFile != NULL && BookSize != 0) { // draw a move according to a fixed probability distribution best_move = MoveNone; best_score = 0; for (pos = find_pos(board->key); pos < BookSize; pos++) { read_entry(entry,pos); if (entry->key != board->key) break; move = entry->move; score = entry->count; // pick this move? ASSERT(score>0); best_score += score; if (my_random(best_score) < score) best_move = move; } if (best_move != MoveNone) { // convert PolyGlot move into Fruit move; TODO: handle promotes gen_legal_moves(list,board); for (i = 0; i < list->size; i++) { move = list->move[i]; if ((move & 07777) == best_move) return move; } } } return MoveNone; }
int main (int argc, char *argv[]) { int type; void *data; int num_args = argc - 1; int num_nums = 0; int num_vtables = 0; int i; long nums [num_args]; long vtables [num_args]; for (i = 0; i < num_args; ++i) { char *arg = argv [i + 1]; char *next_arg = argv [i + 2]; if (!strcmp (arg, "--all")) { dump_all = TRUE; } else if (!strcmp (arg, "-v") || !strcmp (arg, "--vtable")) { vtables [num_vtables++] = strtoul (next_arg, NULL, 16); ++i; } else { nums [num_nums++] = strtoul (arg, NULL, 16); } } while ((type = read_entry (stdin, &data)) != SGEN_PROTOCOL_EOF) { gboolean match = FALSE; for (i = 0; i < num_nums; ++i) { if (is_match ((gpointer) nums [i], type, data)) { match = TRUE; break; } } if (!match) { for (i = 0; i < num_vtables; ++i) { if (is_vtable_match ((gpointer) vtables [i], type, data)) { match = TRUE; break; } } } if (dump_all) printf (match ? "* " : " "); if (match || dump_all) print_entry (type, data); free (data); } return 0; }
/************************************************************************** * Function: get_private_profile_int() * Arguments: <char *> section - the name of the section to search for * <char *> entry - the name of the entry to find the value of * <int> def - the default value in the event of a failed read * <char *> file_name - the name of the .ini file to read from * Returns: the value located at entry ***************************************************************************/ int get_private_profile_int(char *section, char *entry, int def, char *file_name) { FILE *fp = fopen(file_name,"r"); char buff[MAX_LINE_LENGTH]; if( !fp ) return def; /* Return default value if file does not exist */ if (!read_section (fp, section)) goto err; if (!read_entry (fp, entry, buff, MAX_LINE_LENGTH)) goto err; def = read_int_value (buff, def); err: fclose (fp); return def; }
entry *load_entry(char *path, uint8_t *key) { size_t size = 0; void *addr = mmfile(path, &size); box *box = addr; if (!addr) return NULL; if (!decrypt_box(key, box, ENTRY_LEN(size))) { munmap(addr, size); return NULL; } return read_entry(BOX_DATA(box), size); }
void command_find(FILE * f) { char word[130]; read_word(word, 130); uint64 index = find_word(f, word); if (0 == index) { // слова нет, сообщить fprintf( stderr, "[INFO] нет такого слова\n"); } else { // слово есть, выводим //fseek( f, index, SEEK_SET ); struct entry_t entry; read_entry(f, &entry, index, READ_ENTRY_CONTENT | READ_ENTRY_DO_SEEK); printf("Значение: %s\n", entry.content); } }
int parse_entry_xml(const char *data, int data_len, entry_t **dst) { int res = 0; xmlDocPtr doc; /* the resulting document tree */ if (dst) *dst = NULL; doc = xmlReadMemory(data, data_len, NULL, NULL, xml_parser_flags); if (doc == NULL) { ERROR_LOG("can't parse document\n"); return -1; } res = read_entry(xmlDocGetRootElement(doc), dst); xmlFreeDoc(doc); return res; }
static pa_hook_result_t source_fixate_hook_callback(pa_core *c, pa_source_new_data *new_data, struct userdata *u) { char *name; struct entry *e; pa_assert(c); pa_assert(new_data); pa_assert(u); pa_assert(u->restore_volume || u->restore_muted); name = pa_sprintf_malloc("source:%s", new_data->name); if ((e = read_entry(u, name))) { if (u->restore_volume && e->volume_valid) { if (!new_data->volume_is_set) { pa_cvolume v; pa_log_info("Restoring volume for source %s.", new_data->name); v = e->volume; pa_cvolume_remap(&v, &e->channel_map, &new_data->channel_map); pa_source_new_data_set_volume(new_data, &v); new_data->save_volume = TRUE; } else pa_log_debug("Not restoring volume for source %s, because already set.", new_data->name); } if (u->restore_muted && e->muted_valid) { if (!new_data->muted_is_set) { pa_log_info("Restoring mute state for source %s.", new_data->name); pa_source_new_data_set_muted(new_data, e->muted); new_data->save_muted = TRUE; } else pa_log_debug("Not restoring mute state for source %s, because already set.", new_data->name); } pa_xfree(e); } pa_xfree(name); return PA_HOOK_OK; }
int read_dictionary(Dictionary dict) { if (!link_advance(dict)) { return 0; } while (dict->token[0] != '\0') { if (!read_entry(dict)) { return 0; } } dict->root = dsw_tree_to_vine(dict->root); dict->root = dsw_vine_to_tree(dict->root, dict->num_entries); return 1; }
int read_fh_to_tar_entry(cfile *src_cfh, tar_entry **tar_entries, unsigned long *total_count) { tar_entry *entries; unsigned long array_size=10000; unsigned long count =0; signed int err = 0; if((entries = (tar_entry *)calloc(array_size,sizeof(tar_entry)))==NULL){ return MEM_ERROR; } while(!err) { if(count==array_size) { /* out of room, resize */ if ((entries = (tar_entry *)realloc(entries ,(array_size += 10000)*sizeof(tar_entry)))==NULL){ v0printf("unable to allocate %lu tar entries (needed), bailing\n", array_size); return MEM_ERROR; } } err = read_entry(src_cfh, (count == 0 ? 0 : entries[count - 1].end), &entries[count]); count++; } if(err != TAR_EMPTY_ENTRY) { // not deallocing the alloc'd mem for each entry (fullname), fix this prior to going lib free(entries); return err; } count--; if(!count) return EOF_ERROR; if ((entries=(tar_entry *)realloc(entries, count * sizeof(tar_entry)))==NULL){ v0printf("error reallocing tar array (specifically releasing, odd), bailing\n"); return MEM_ERROR; } *tar_entries = entries; *total_count = count; return 0; }