static void key_handler(void *data, Evas * evas, Evas_Object * obj, void *event_info) { eoi_help_info_t *info = data; if (!info->navigation) { char *app; if (!asprintf(&app, "help/%s", info->application)) err(1, "asprintf"); info->navigation = keys_alloc(app); free(app); } if (!info->keys) info->keys = keys_alloc("eoi_help"); const char *action = keys_lookup_by_event(info->navigation, eina_list_data_get(info->history), event_info); if (action && strlen(action)) { load_page(info, action); return; } action = keys_lookup_by_event(info->keys, "default", event_info); if (!action || !strlen(action)) return; if (!strcmp(action, "PageDown")) eoi_textbox_page_next(info->textbox); else if (!strcmp(action, "PageUp")) eoi_textbox_page_prev(info->textbox); else if (!strcmp(action, "Back")) { if (eina_list_prev(info->history)) { free(eina_list_data_get(info->history)); info->history = eina_list_prev(info->history); char *page = strdup(eina_list_data_get(info->history)); info->history = eina_list_remove_list(info->history, eina_list_next(info->history)); free(eina_list_data_get(info->history)); info->history = eina_list_prev(info->history); info->history = eina_list_remove_list(info->history, eina_list_next(info->history)); load_page(info, page); free(page); } else eoi_help_free(info->textbox); } else if (!strcmp(action, "Close")) eoi_help_free(info->textbox); }
int init_pages(void) { void *handler = NULL; struct dirent *file = NULL; struct page *new_page = NULL; char page_path[128]; char *file_ext = NULL; DIR *dir_s = opendir(pages_dir); while ((file = readdir(dir_s)) != NULL) { sprintf(page_path, "%s%s", pages_dir, file->d_name); file_ext = strrchr(page_path, '.'); if (file_ext == NULL) continue; else if (strcmp(file_ext, ".html")) continue; handler = dlopen(page_path, RTLD_LAZY); if (handler == NULL) { printf("[WARNING] loading of page %s failed, reason is %s.\n", page_path, dlerror()); continue; } else { new_page = (struct page *)dlsym(handler, "config"); load_page(new_page); new_page->handler = handler; } } return EXIT_SUCCESS; }
static Evas_Object * _eoi_help_new(Evas * canvas, const char *application, eoi_help_page_updated_t page_handler, eoi_help_closed_t closed, const char *page, keys_t * keys_info, const char *context) { eoi_help_info_t *info = (eoi_help_info_t *) malloc(sizeof(eoi_help_info_t)); info->textbox = eoi_textbox_new(canvas, THEME_EDJ, "help", help_page_update_handler); info->application = strdup(application); info->page_handler = page_handler; info->closed = closed; info->history = NULL; info->keys = NULL; info->navigation = NULL; info->keys_info = keys_info; info->keys_context = context; evas_object_event_callback_add(info->textbox, EVAS_CALLBACK_KEY_UP, &key_handler, (void *) info); if (!page) page = "index"; load_page(info, page); evas_object_data_set(info->textbox, "help-info", info); return info->textbox; }
static void load_pages(const xmlNode *pages, form_element_t *parent) { const xmlNode *items = find_by_path(pages, "ContainedItems"); const xmlNode *p = find_by_path(pages, "Properties/PagesRepresentation"); int pages_rep = PAGES_NO; if (p) if (p->children) if (p->children->content) { if (xstrcmp(p->children->content, "TabsOnTop") == 0) pages_rep = PAGES_ON_TOP; } form_element_t P; P.widget = gtk_notebook_new(); P.box = false; if (pages_rep == PAGES_NO) gtk_notebook_set_show_tabs(GTK_NOTEBOOK(P.widget), false); const xmlNode *cur_node = NULL; for (cur_node = items->children; cur_node; cur_node = cur_node->next) { if (is_oftype(cur_node, "Page")) { load_page(cur_node, &P); } } container_add(parent, P.widget); }
void offset_rindex::get_data(glong idx, guint32 &entry_offset, guint32 &entry_size) { load_page(idx/ENTR_PER_PAGE); glong idx_in_page=idx%ENTR_PER_PAGE; entry_offset = page.entries[idx_in_page].off; entry_size = page.entries[idx_in_page].size; }
static int load_next_page(const struct pref__obj *p, struct pref__buffer *const buf) { int rc; if (buf->refs[NEXT_PAGE_INDEX] == -1) { rc = 1; } else { rc = load_page(p, buf, buf->refs[NEXT_PAGE_INDEX]); buf->global_index += NEXT_PAGE_INDEX; } return rc; }
static void make_the_input_file(UnloadedPage *page) { char buf[2048], *b; if (!page->fpos.name) return; b = make_input_file_name(buf, page->fpos.name); if (inListAndNewer(b, page->fpos.name)) { printf("parsing: %s\n", page->name); if (setjmp(jmpbuf)) { printf("Syntax error!\n"); } else { load_page((HyperDocPage *)page); make_input_file_from_page(gWindow->page); } } }
void bin_index_t::file_node::validate_root_offset() const { root_page.reset(); file_offset_t sz=fi->get_size(); if(sz==0) { data_t d(parent.page_max_size,0); const_cast<file_node*>(this)->save_index_data(0,d); return; } data_t d(sizeof(file_offset_t)); load_index_data(0,d); page_ptr p(create_page()); p->page_offset=*reinterpret_cast<const file_offset_t*>(&d[0]); load_page(*p); const_cast<file_node*>(this)->add_page(p); root_page=p; }
bin_index_t::page_ptr bin_index_t::file_node::get_page(file_offset_t page_offset) { pages_t::iterator it=pages.find(page_offset); if(it!=pages.end()) { page_ptr p=it->second; if(!p->left.expired()) { remove_from_list(p); insert_into_list(p,first_page.lock()); } return p; } page_ptr p(create_page()); p->self=p; p->page_offset=page_offset; load_page(*p); add_page(p); return p; }
int acquire_page(unsigned num, page **page) /* Function waits until requested page is free to use and (if necessary) * * loads it from the hard drive. * * * * Function assumes that thread has a lock on the [data.mutex] * * * * MUTABLE PARAMETERS: page * * * * RETURN VALUE: * * 0 success * * PSIM_ECOND there was a problem with a operation on condition * * PSIM_ELOCK mutex lock operation failed * * PSIM_EUNLO mutex unlock operation failed * * IOERROR aio operation failed */ { *page = &data.pages[num]; int ret; while((*page)->state == PSIM_IN_USE) CHECK_NZERO(pthread_cond_wait(&((*page)->cond), &data.mutex), PSIM_ECOND); if((*page)->state == PSIM_EMPTY) RETHROW(load_page(num, *page), ret); (*page)->hits++; return 0; }
void get_new_window() { int val; char buf[128]; int frame; Window wid; HDWindow *htw; HyperDocPage *hpage; /* * If I am going to try and start a new window, then I should make sure I * have a coonection to listen on * * BUT This code is entered when a socket selects * * if (spad_socket == NULL) { spad_socket = * connect_to_local_server(SpadServer, MenuServer, 10); if (spad_socket * == NULL) { fprintf(stderr, "Get_new_window: Couldn't Connect to * SpadServer\n"); return -1; } } * */ frame = get_int(spad_socket); val = get_int(spad_socket); switch (val) { case StartPage: init_top_window(NULL); val = get_int(spad_socket); init_scanner(); input_type = SourceInputKind::SpadSocket; input_string = ""; gWindow->page = parse_page_from_socket(); gWindow->fAxiomFrame = frame; XFlush(gXDisplay); break; case LinkToPage: get_string_buf(spad_socket, buf, 128); if (init_top_window(buf) == -1) { fprintf(stderr, "get_new_window: Did not find page %s\n", buf); /* return -1; */ } gWindow->fAxiomFrame = frame; break; case PopUpPage: val = get_int(spad_socket); init_form_window(NULL, val); send_int(spad_socket, gWindow->fMainWindow); init_scanner(); input_type = SourceInputKind::SpadSocket; input_string = ""; gWindow->page = parse_page_from_socket(); compute_form_page(gWindow->page); XMapWindow(gXDisplay, gWindow->fMainWindow); gWindow->fWindowHashTable = gWindow->page->fLinkHashTable; gWindow->fAxiomFrame = frame; XFlush(gXDisplay); break; case PopUpNamedPage: val = get_int(spad_socket); get_string_buf(spad_socket, buf, 128); if (init_form_window(buf, val) == -1) { send_int(spad_socket, -1); break; } load_page(gWindow->page); compute_form_page(gWindow->page); XMapWindow(gXDisplay, gWindow->fMainWindow); gWindow->fWindowHashTable = gWindow->page->fLinkHashTable; gWindow->fAxiomFrame = frame; XFlush(gXDisplay); send_int(spad_socket, gWindow->fMainWindow); /* fprintf(stderr, "Window Id was %d\n", gWindow->fMainWindow); */ break; case ReplaceNamedPage: wid = (Window) get_int(spad_socket); get_string_buf(spad_socket, buf, 128); htw = (HDWindow *) hash_find(&gSessionHashTable,(char *)&wid); if (htw == NULL) break; hpage = (HyperDocPage *) hash_find(gWindow->fPageHashTable, buf); if (hpage == NULL) break; gWindow = htw; gWindow->page = hpage; display_page(gWindow->page); gWindow->fWindowHashTable = gWindow->page->fLinkHashTable; clear_exposures(gWindow->fMainWindow); clear_exposures(gWindow->fScrollWindow); XFlush(gXDisplay); break; case ReplacePage: wid = (Window) get_int(spad_socket); set_window(wid); init_scanner(); input_type = SourceInputKind::SpadSocket; input_string = ""; gWindow->page = parse_page_from_socket(); display_page(gWindow->page); gWindow->fWindowHashTable = gWindow->page->fLinkHashTable; clear_exposures(gWindow->fMainWindow); clear_exposures(gWindow->fScrollWindow); XFlush(gXDisplay); break; case KillPage: /* Here the user wishes to kill the page */ wid = (Window) get_int(spad_socket); htw = (HDWindow *) hash_find(&gSessionHashTable,(char *)&wid); if (htw !=NULL) { gWindow = htw; exitHyperDoc(); break; } break; } }
DllExport int call_conv pl_load_page() { prolog_term head, tail, result = 0; char *functor, *url = NULL, *data = NULL; char *username = NULL, *password = NULL; curl_opt options = init_options(); curl_ret ret_vals; check_thread_context tail = reg_term(CTXTc 1); if(!is_list(tail)) return curl2pl_error(ERR_DOMAIN, "source", tail); while(is_list(tail)){ head = p2p_car(tail); tail = p2p_cdr(tail); if(is_functor(head)){ functor = p2c_functor(head); if(!strcmp(functor,"source")){ prolog_term term_url_func, term_url = 0; term_url_func = p2p_arg(head, 1); if(is_functor(term_url_func)){ if(!strcmp(p2c_functor(term_url_func), "url")){ term_url = p2p_arg(term_url_func, 1); url = p2c_string(term_url); data = load_page(url, options, &ret_vals); } else{ return curl2pl_error(ERR_MISC, "source", term_url); } } else{ return curl2pl_error(ERR_MISC, "source", "Improper input format"); } } else if(!strcmp(functor,"options")){ prolog_term term_options = p2p_arg(head, 1); prolog_term term_option; while(is_list(term_options)){ term_option = p2p_car(term_options); if(!strcmp(p2c_functor(term_option), "redirect")) { if(!strcmp(p2c_string(p2p_arg(term_option, 1)), "true")) options.redir_flag = 1; else options.redir_flag = 0; } else if(!strcmp(p2c_functor(term_option), "secure")){ if(!strcmp(p2c_string(p2p_arg(term_option, 1)), "false")) options.secure.flag = 0; else options.secure.crt_name = p2c_string(p2p_arg(term_option, 1)); } else if(!strcmp(p2c_functor(term_option), "auth")){ username = p2c_string(p2p_arg(term_option, 1)); password = p2c_string(p2p_arg(term_option, 2)); options.auth.usr_pwd = (char *) malloc ((strlen(username) + strlen(password) + 2) * sizeof(char)); strcpy(options.auth.usr_pwd, username); strcat(options.auth.usr_pwd, ":"); strcat(options.auth.usr_pwd, password); } else if(!strcmp(p2c_functor(term_option), "timeout")){ options.timeout = (int)p2c_int(p2p_arg(term_option, 1)); } else if(!strcmp(p2c_functor(term_option), "url_prop")){ options.url_prop = options.redir_flag; } else if(!strcmp(p2c_functor(term_option), "user_agent")){ options.user_agent = p2c_string(p2p_arg(term_option, 1)); } else if(!strcmp(p2c_functor(term_option), "post")){ options.post_data = p2c_string(p2p_arg(term_option, 1)); } term_options = p2p_cdr(term_options); } } else if(!strcmp(functor,"document")){ result = p2p_arg(head, 1); } else if(!strcmp(functor,"properties")){ c2p_int(CTXTc (int) ret_vals.size, p2p_arg(head, 1)); /* the following code can be used to convert to local/UTC time, if necessary. Note: XSB uses local time, and ret_vals.modify_time is local, too. struct tm * timeinfo; timeinfo = gmtime(&(ret_vals.modify_time)); // UTC time timeinfo = localtime(&(ret_vals.modify_time)); // local time c2p_int(CTXTc (int) mktime(timeinfo), p2p_arg(head,2)); */ /* return modification time as an integer */ c2p_int(CTXTc (int) ret_vals.modify_time, p2p_arg(head,2)); /* The following converts time to string - not useful if (ctime(&ret_vals.modify_time) == NULL) c2p_string("", p2p_arg(head, 2)); else c2p_string(CTXTc (char *) ctime(&ret_vals.modify_time), p2p_arg(head, 2)); */ } } else{ return curl2pl_error(ERR_DOMAIN, "source", head); } } c2p_string(CTXTc data, result); return TRUE; }
static int load_first_page(const struct pref__obj *p, struct pref__buffer *const buf) { int rc = load_page(p, buf, buf->first_page_offset); buf->global_index = 0; return rc; }
void *get_vmvarlib (struct varlist *varlist, S4 vind, S8 ind, U1 access, struct vm_mem *vm_mem) { // get address of array variable index U1 type, cache_hit = 0; S8 i ALIGN; S8 addr ALIGN; S8 hits ALIGN; S8 page ALIGN; S8 read_ind ALIGN; S8 new_ind ALIGN; U1 *new_s_memptr; S2 *new_i_memptr; S4 *new_li_memptr; S8 *new_q_memptr; F8 *new_d_memptr; void *ret_memptr = NULL; vm_mem->error = FALSE; type = varlist[vind].type; if (!varlist[vind].vm) { /* variable not in virtual memory, read from normal array */ if (varlist[vind].size > 0) { /* array variable allocated, get pointer */ switch (type) { case INT_VAR: new_i_memptr = varlist[vind].i_m; new_i_memptr = new_i_memptr + ind; ret_memptr = (S2 *) new_i_memptr; break; case LINT_VAR: new_li_memptr = varlist[vind].li_m; new_li_memptr = new_li_memptr + ind; ret_memptr = (S4 *) new_li_memptr; break; case QINT_VAR: new_q_memptr = varlist[vind].q_m; new_q_memptr = new_q_memptr + ind; ret_memptr = (S8 *) new_q_memptr; break; case DOUBLE_VAR: new_d_memptr = varlist[vind].d_m; new_d_memptr = new_d_memptr + ind; ret_memptr = (F8 *) new_d_memptr; break; case BYTE_VAR: new_s_memptr = varlist[vind].s_m; new_s_memptr = new_s_memptr + ind; ret_memptr = (U1 *) new_s_memptr; break; } } else { /* array variable is deallocated, set error flag */ vm_mem->error = TRUE; return (NULL); } } else { /* variable is in virtual memory */ for (i = 0; i < MAXVMPAGES; i++) { /* printf ("get_vmvarlib: page_hits: %lli\n", varlist[vind].vm_pages.page_hits[i]); printf ("get_vmvarlib: page_start_addr: %lli\n", varlist[vind].vm_pages.page_start_addr[i]); printf ("get_vmvarlib: page_end_addr: %lli\n", varlist[vind].vm_pages.page_end_addr[i]); */ if ((varlist[vind].vm_pages.page_end_addr[i] != 0) && (ind >= varlist[vind].vm_pages.page_start_addr[i] && ind <= varlist[vind].vm_pages.page_end_addr[i])) { // found page cache_hit = 1; /* correct index */ new_ind = ind - varlist[vind].vm_pages.page_start_addr[i]; /* DEBUG */ /* if (new_ind > varlist[vind].vmcachesize - 1) { vm_mem->error = TRUE; printf ("get_vmvarlib: FATAL ERROR: page index out of range! [cache hit]\n"); return (NULL); } */ switch (type) { case INT_VAR: new_i_memptr = (S2 *) (varlist[vind].vm_pages.pages[i] + (new_ind * sizeof (S2))); ret_memptr = (S2 *) new_i_memptr; break; case LINT_VAR: new_li_memptr = (S4 *) (varlist[vind].vm_pages.pages[i] + (new_ind * sizeof (S4))); ret_memptr = (S4 *) new_li_memptr; break; case QINT_VAR: new_q_memptr = (S8 *) (varlist[vind].vm_pages.pages[i] + (new_ind * sizeof (S8))); ret_memptr = (S8 *) new_q_memptr; break; case DOUBLE_VAR: new_d_memptr = (F8 *) (varlist[vind].vm_pages.pages[i] + (new_ind * sizeof (F8))); ret_memptr = (F8 *) new_d_memptr; break; case BYTE_VAR: new_s_memptr = (U1 *) (varlist[vind].vm_pages.pages[i] + (new_ind * sizeof (U1))); ret_memptr = (U1 *) new_s_memptr; break; } varlist[vind].vm_pages.page_hits[i]++; if (access == VM_WRITE) { varlist[vind].vm_pages.page_mod[i] = PAGE_MODIFIED; // set page modified flag } break; /* BREAK for and continue */ } } if (cache_hit == 0) { /* no cache hit, search page memory to load */ hits = varlist[vind].vm_pages.page_hits[0]; page = 0; for (i = 1; i < MAXVMPAGES; i++) { // printf ("page hits: page %lli, hits %lli\n", i, varlist[vind].vm_pages.page_hits[i]); if (varlist[vind].vm_pages.page_hits[i] < hits) { hits = varlist[vind].vm_pages.page_hits[i]; page = i; } } if (varlist[vind].vm_pages.page_mod[page] == PAGE_MODIFIED) { if (save_page (varlist, vind, page) == FALSE) { vm_mem->error = TRUE; return (NULL); } } if (ind + varlist[vind].vmcachesize > varlist[vind].size - 1) { /* correct page read position */ read_ind = varlist[vind].size - varlist[vind].vmcachesize; if (load_page (varlist, vind, page, read_ind) == FALSE) { vm_mem->error = TRUE; return (NULL); } } else { if (load_page (varlist, vind, page, ind) == FALSE) { vm_mem->error = TRUE; return (NULL); } } varlist[vind].vm_pages.page_mod[page] = PAGE_READ; new_ind = ind - varlist[vind].vm_pages.page_start_addr[page]; /* DEBUG */ /* if (new_ind > varlist[vind].vmcachesize - 1) { vm_mem->error = TRUE; printf ("get_vmvarlib: FATAL ERROR: page index out of range! [cache load]\n"); return (NULL); } */ switch (type) { case INT_VAR: new_i_memptr = (S2 *) (varlist[vind].vm_pages.pages[page] + (new_ind * sizeof (S2))); ret_memptr = (S2 *) new_i_memptr; break; case LINT_VAR: new_li_memptr = (S4 *) (varlist[vind].vm_pages.pages[page] + (new_ind * sizeof (S4))); ret_memptr = (S4 *) new_li_memptr; break; case QINT_VAR: new_q_memptr = (S8 *) (varlist[vind].vm_pages.pages[page] + (new_ind * sizeof (S8))); ret_memptr = (S8 *) new_q_memptr; break; case DOUBLE_VAR: new_d_memptr = (F8 *) (varlist[vind].vm_pages.pages[page] + (new_ind * sizeof (F8))); ret_memptr = (F8 *) new_d_memptr; break; case BYTE_VAR: new_s_memptr = (U1 *) (varlist[vind].vm_pages.pages[page] + (new_ind * sizeof (U1))); ret_memptr = (U1 *) new_s_memptr; break; } if (access == VM_WRITE) { varlist[vind].vm_pages.page_mod[page] = PAGE_MODIFIED; // set page modified flag } } } return (ret_memptr); }
const gchar *offset_rindex::get_key(glong idx) { load_page(idx/ENTR_PER_PAGE); glong idx_in_page=idx%ENTR_PER_PAGE; return page.entries[idx_in_page].keystr; }
bool offset_rindex::lookup(const char *str, glong &idx) { bool bFound=false; glong iTo=npages-2; glong iFrom; glong iThisIndex; gint cmpint; if (strcmp(str, first.keystr.c_str())<0) { return false; } else if (strcmp(str, real_last.keystr.c_str()) >0) { return false; } else { iFrom=0; while (iFrom<=iTo) { iThisIndex=(iFrom+iTo)/2; cmpint = strcmp(str, get_first_on_page_key(iThisIndex)); if (cmpint>0) iFrom=iThisIndex+1; else if (cmpint<0) iTo=iThisIndex-1; else { bFound=true; break; } } if (!bFound) { // iTo - prev. page // the key must on page iTo if anywhere idx = iTo; } else { idx = iThisIndex; // the key found in the first position of this page } } // idx now is a page number where the key may be if (!bFound) { gulong netr=load_page(idx); iFrom=1; // Needn't search the first word anymore. iTo=netr-1; iThisIndex=0; while (iFrom<=iTo) { iThisIndex=(iFrom+iTo)/2; cmpint = strcmp(str, page.entries[iThisIndex].keystr); if (cmpint>0) iFrom=iThisIndex+1; else if (cmpint<0) iTo=iThisIndex-1; else { bFound=true; break; } } if(!bFound) return false; idx *= ENTR_PER_PAGE; idx += iThisIndex; return true; } else { idx *= ENTR_PER_PAGE; return true; } }