/*! form in window event */ void event_wform(void) { if(buf[3] == PETIT_FORM) { switch(buf[4]) { case PF_CONFIRME : case PF_APPLIQUE : win[buf[3]].w_cont.w_form.w_tree[buf[4]].ob_state &= ~SELECTED; free(&win[PETIT_FORM].w_cont.w_form.w_bak); /* free memory */ bak_rsc(win[PETIT_FORM].w_cont.w_form.w_tree, &win[PETIT_FORM].w_cont.w_form.w_bak); if(_app) trame_desk(); break; case PF_ANNULE : case PF_RAZ : win[buf[3]].w_cont.w_form.w_tree[buf[4]].ob_state &= ~SELECTED; if(buf[4] == PF_RAZ) objc_xedit(win[PETIT_FORM].w_cont.w_form.w_tree, /* remove cursor */ ZERO, win[PETIT_FORM].w_cont.w_form.w_edit, &win[PETIT_FORM].w_cont.w_form.w_pos, ED_END, TRUE, PETIT_FORM); res_rsc(win[PETIT_FORM].w_cont.w_form.w_tree, &win[PETIT_FORM].w_cont.w_form.w_bak); if(buf[4] == PF_RAZ) objc_xedit(win[PETIT_FORM].w_cont.w_form.w_tree, /* put back cursor */ ZERO, win[PETIT_FORM].w_cont.w_form.w_edit, &win[PETIT_FORM].w_cont.w_form.w_pos, ED_INIT, TRUE, PETIT_FORM); break; } /* end switch case */ if(buf[4] == PF_RAZ) print_page(PETIT_FORM); } /* small form */ else if(buf[3] == GRAND_FORM) { switch(buf[4]) { case GF_CONFIRME : case GF_APPLIQUE : win[buf[3]].w_cont.w_form.w_tree[buf[4]].ob_state &= ~SELECTED; free(&win[GRAND_FORM].w_cont.w_form.w_bak); /* Libérer mémoire */ bak_rsc(win[GRAND_FORM].w_cont.w_form.w_tree, &win[GRAND_FORM].w_cont.w_form.w_bak); if(_app) objets_desk(); break; case GF_ANNULE : case GF_RAZ : win[buf[3]].w_cont.w_form.w_tree[buf[4]].ob_state &= ~SELECTED; res_rsc(win[GRAND_FORM].w_cont.w_form.w_tree, &win[GRAND_FORM].w_cont.w_form.w_bak); break; } /* end switch case */ if((buf[4] == GF_RAZ) ||(buf[4] == GF_APPLIQUE)) print_page(GRAND_FORM); } /* large form */ } /* endof event_wform */
void print_table( int page ) { int x1, y1, x2, y2; calculate_page_frame( &x1, &y1, &x2, &y2 ); draw_frame( x1, y1, x2, y2 ); lower_limit = y2; print_page( page, char_per_row( ) * char_per_col( ) ); }
int main(int argc, char **argv){ int nPage, cnt; int iOfst; if( argc!=2 ){ fprintf(stderr,"Usage: %s FILENAME\n", argv[0]); exit(1); } db = fopen(argv[1], "rb"); if( db==0 ){ fprintf(stderr,"%s: can't open %s\n", argv[0], argv[1]); exit(1); } fseek(db, 0, SEEK_END); fileSize = ftell(db); printf("journal file size: %d bytes\n", fileSize); fseek(db, 0, SEEK_SET); iOfst = 0; while( iOfst<fileSize ){ cnt = nPage = (int)decode_journal_header(iOfst); if( cnt==0 ){ cnt = (fileSize - sectorSize)/(pageSize+8); } iOfst += sectorSize; while( cnt && iOfst<fileSize ){ print_page(iOfst); iOfst += pageSize+8; } iOfst = (iOfst/sectorSize + 1)*sectorSize; } fclose(db); return 0; }
/* * refresh window content */ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw, int cur_y, int cur_x) { print_page(box, boxh, boxw); print_position(dialog); wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); }
static void print_last_page(MY_OBJ * obj) { int high = getmaxy(obj->obj.win) - (2 * MARGIN + (obj->obj.bg_task ? 1 : 3)); int wide = getmaxx(obj->text); last_lines(obj, high); print_page(obj, high, wide); }
void page_path_stack_push(uint8_t page_id) { if (page_stack_ptr >= 7) { load_error_page(ERROR_PAGE_PAGE_STACK_OVERFLOW); print_page(); return; } page_stack[page_stack_ptr++] = page_id; }
/*! Toolbar events */ void event_tool(void) { if(buf[3] == TEXTE) { if((buf[4] == TL_FONT) ||(buf[4] == TL_SIZE)) set_font(); if(buf[4] == TL_INV) { if(win[TEXTE].w_bar[TL_INV].ob_state & SELECTED) set_work(TEXTE, 8, BLACK); else set_work(TEXTE, ZERO, WHITE); } if(buf[4] != TL_INV) print_page(TEXTE); } } /* end of event_tool */
uint8_t page_path_stack_pop(void) { uint8_t page_id; if (page_stack_ptr == 0) { load_error_page(ERROR_PAGE_PAGE_STACK_UNDERFLOW); print_page(); return 255; } page_id = page_stack[--page_stack_ptr]; return page_id; }
int form(char *banner, app_input_t form_questions[], size_t num_fields) { char *update_tok; page_option pg_opt; if (g_page_idx > g_last_page_completed + 1) { printf("You must complete the previous page before proceeding to this page\n"); g_page_idx = g_last_page_completed + 1; return -1; } int i; int unfinished = FALSE; for (i=0; i < num_fields; i++) { if (form_questions[i].input == NULL) { unfinished = TRUE; g_last_page_completed = g_page_idx - 1; break; } } if ( g_page_idx == g_last_page_completed + 1 || unfinished) { pg_opt = fill_out_form(form_questions, num_fields); if (pg_opt == NOOP) { g_last_page_completed++; } else if (pg_opt == UPDATE) { printf("Cannot update field until all fields are inputted\n"); return pg_opt; } else { return pg_opt; } } print_page(banner, form_questions, num_fields); printf("\nType **next to continue\n"); pg_opt = get_response(); if (pg_opt == UPDATE) { update_tok = g_user_resp; strsep(&update_tok, " "); if (update_field(update_tok, form_questions, num_fields) != 0) printf("Update Unsuccessful\n"); } return pg_opt; }
int main(int argc, char **argv){ struct stat sbuf; unsigned char zPgSz[2]; if( argc<2 ){ usage(argv[0]); exit(1); } db = open(argv[1], O_RDONLY); if( db<0 ){ fprintf(stderr,"%s: can't open %s\n", argv[0], argv[1]); exit(1); } zPgSz[0] = 0; zPgSz[1] = 0; lseek(db, 16, SEEK_SET); read(db, zPgSz, 2); pagesize = zPgSz[0]*256 + zPgSz[1]*65536; if( pagesize==0 ) pagesize = 1024; printf("Pagesize: %d\n", pagesize); fstat(db, &sbuf); mxPage = sbuf.st_size/pagesize; printf("Available pages: 1..%d\n", mxPage); if( argc==2 ){ int i; for(i=1; i<=mxPage; i++) print_page(i); }else{ int i; for(i=2; i<argc; i++){ int iStart, iEnd; char *zLeft; if( strcmp(argv[i], "dbheader")==0 ){ print_db_header(); continue; } if( strcmp(argv[i], "pgidx")==0 ){ page_usage_report(argv[1]); continue; } if( !isdigit(argv[i][0]) ){ fprintf(stderr, "%s: unknown option: [%s]\n", argv[0], argv[i]); continue; } iStart = strtol(argv[i], &zLeft, 0); if( zLeft && strcmp(zLeft,"..end")==0 ){ iEnd = mxPage; }else if( zLeft && zLeft[0]=='.' && zLeft[1]=='.' ){ iEnd = strtol(&zLeft[2], 0, 0); }else if( zLeft && zLeft[0]=='b' ){ int ofst, nByte, hdrSize; unsigned char *a; if( iStart==1 ){ ofst = hdrSize = 100; nByte = pagesize-100; }else{ hdrSize = 0; ofst = (iStart-1)*pagesize; nByte = pagesize; } a = getContent(ofst, nByte); decode_btree_page(a, iStart, hdrSize, &zLeft[1]); free(a); continue; }else if( zLeft && zLeft[0]=='t' ){ unsigned char *a; int detail = 0; int recursive = 0; int i; for(i=1; zLeft[i]; i++){ if( zLeft[i]=='r' ) recursive = 1; if( zLeft[i]=='d' ) detail = 1; } decode_trunk_page(iStart, pagesize, detail, recursive); continue; }else{ iEnd = iStart; } if( iStart<1 || iEnd<iStart || iEnd>mxPage ){ fprintf(stderr, "Page argument should be LOWER?..UPPER?. Range 1 to %d\n", mxPage); exit(1); } while( iStart<=iEnd ){ print_page(iStart); iStart++; } } } close(db); }
/* * Display text from a file in a dialog box. */ int dialog_textbox(const char *title, const char *file, int height, int width) { /* *INDENT-OFF* */ static DLG_KEYS_BINDING binding[] = { HELPKEY_BINDINGS, ENTERKEY_BINDINGS, DLG_KEYS_DATA( DLGK_GRID_DOWN, 'J' ), DLG_KEYS_DATA( DLGK_GRID_DOWN, 'j' ), DLG_KEYS_DATA( DLGK_GRID_DOWN, KEY_DOWN ), DLG_KEYS_DATA( DLGK_GRID_LEFT, 'H' ), DLG_KEYS_DATA( DLGK_GRID_LEFT, 'h' ), DLG_KEYS_DATA( DLGK_GRID_LEFT, KEY_LEFT ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'L' ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'l' ), DLG_KEYS_DATA( DLGK_GRID_RIGHT, KEY_RIGHT ), DLG_KEYS_DATA( DLGK_GRID_UP, 'K' ), DLG_KEYS_DATA( DLGK_GRID_UP, 'k' ), DLG_KEYS_DATA( DLGK_GRID_UP, KEY_UP ), DLG_KEYS_DATA( DLGK_PAGE_FIRST, 'g' ), DLG_KEYS_DATA( DLGK_PAGE_FIRST, KEY_HOME ), DLG_KEYS_DATA( DLGK_PAGE_LAST, 'G' ), DLG_KEYS_DATA( DLGK_PAGE_LAST, KEY_END ), DLG_KEYS_DATA( DLGK_PAGE_LAST, KEY_LL ), DLG_KEYS_DATA( DLGK_PAGE_NEXT, ' ' ), DLG_KEYS_DATA( DLGK_PAGE_NEXT, KEY_NPAGE ), DLG_KEYS_DATA( DLGK_PAGE_PREV, 'B' ), DLG_KEYS_DATA( DLGK_PAGE_PREV, 'b' ), DLG_KEYS_DATA( DLGK_PAGE_PREV, KEY_PPAGE ), DLG_KEYS_DATA( DLGK_BEGIN, '0' ), DLG_KEYS_DATA( DLGK_BEGIN, KEY_BEG ), DLG_KEYS_DATA( DLGK_FIELD_NEXT, TAB ), DLG_KEYS_DATA( DLGK_FIELD_PREV, KEY_BTAB ), END_KEYS_BINDING }; /* *INDENT-ON* */ #ifdef KEY_RESIZE int old_height = height; int old_width = width; #endif long fpos; int x, y, cur_x, cur_y; int key = 0, fkey; int next = 0; int i, code, passed_end; char search_term[MAX_LEN + 1]; MY_OBJ obj; WINDOW *dialog; bool moved; int result = DLG_EXIT_UNKNOWN; int button = dlg_default_button(); int min_width = 12; search_term[0] = '\0'; /* no search term entered yet */ memset(&obj, 0, sizeof(obj)); obj.begin_reached = TRUE; obj.buffer_first = TRUE; obj.end_reached = FALSE; obj.buttons = dlg_exit_label(); /* Open input file for reading */ if ((obj.fd = open(file, O_RDONLY)) == -1) dlg_exiterr("Can't open input file %s", file); /* Get file size. Actually, 'file_size' is the real file size - 1, since it's only the last byte offset from the beginning */ lseek_end(&obj, 0L); /* Restore file pointer to beginning of file after getting file size */ lseek_set(&obj, 0L); read_high(&obj, BUF_SIZE); dlg_button_layout(obj.buttons, &min_width); #ifdef KEY_RESIZE retry: #endif moved = TRUE; dlg_auto_sizefile(title, file, &height, &width, 2, min_width); dlg_print_size(height, width); dlg_ctl_size(height, width); x = dlg_box_x_ordinate(width); y = dlg_box_y_ordinate(height); dialog = dlg_new_window(height, width, y, x); dlg_register_window(dialog, "textbox", binding); dlg_register_buttons(dialog, "textbox", obj.buttons); dlg_mouse_setbase(x, y); /* Create window for text region, used for scrolling text */ obj.text = dlg_sub_window(dialog, PAGE_LENGTH, PAGE_WIDTH, y + 1, x + 1); /* register the new window, along with its borders */ dlg_mouse_mkbigregion(0, 0, PAGE_LENGTH + 2, width, KEY_MAX, 1, 1, 1 /* lines */ ); dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr); dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr); dlg_draw_title(dialog, title); dlg_draw_buttons(dialog, PAGE_LENGTH + 2, 0, obj.buttons, button, FALSE, width); (void) wnoutrefresh(dialog); getyx(dialog, cur_y, cur_x); /* Save cursor position */ dlg_attr_clear(obj.text, PAGE_LENGTH, PAGE_WIDTH, dialog_attr); while (result == DLG_EXIT_UNKNOWN) { /* * Update the screen according to whether we shifted up/down by a line * or not. */ if (moved) { if (next < 0) { (void) scrollok(obj.text, TRUE); (void) scroll(obj.text); /* Scroll text region up one line */ (void) scrollok(obj.text, FALSE); print_line(&obj, PAGE_LENGTH - 1, PAGE_WIDTH); (void) wnoutrefresh(obj.text); } else if (next > 0) { /* * We don't call print_page() here but use scrolling to ensure * faster screen update. However, 'end_reached' and * 'page_length' should still be updated, and 'in_buf' should * point to start of next page. This is done by calling * get_line() in the following 'for' loop. */ (void) scrollok(obj.text, TRUE); (void) wscrl(obj.text, -1); /* Scroll text region down one line */ (void) scrollok(obj.text, FALSE); obj.page_length = 0; passed_end = 0; for (i = 0; i < PAGE_LENGTH; i++) { if (!i) { print_line(&obj, 0, PAGE_WIDTH); /* print first line of page */ (void) wnoutrefresh(obj.text); } else (void) get_line(&obj); /* Called to update 'end_reached' and 'in_buf' */ if (!passed_end) obj.page_length++; if (obj.end_reached && !passed_end) passed_end = 1; } } else { print_page(&obj, PAGE_LENGTH, PAGE_WIDTH); } print_position(&obj, dialog, height, width); (void) wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh(dialog); } moved = FALSE; /* assume we'll not move */ next = 0; /* ...but not scroll by a line */ key = dlg_mouse_wgetch(dialog, &fkey); if (dlg_result_key(key, fkey, &result)) break; if (!fkey && (code = dlg_char_to_button(key, obj.buttons)) >= 0) { result = dlg_ok_buttoncode(code); break; } if (fkey) { switch (key) { default: if (is_DLGK_MOUSE(key)) { result = dlg_exit_buttoncode(key - M_EVENT); if (result < 0) result = DLG_EXIT_OK; } else { beep(); } break; case DLGK_FIELD_NEXT: button = dlg_next_button(obj.buttons, button); if (button < 0) button = 0; dlg_draw_buttons(dialog, height - 2, 0, obj.buttons, button, FALSE, width); break; case DLGK_FIELD_PREV: button = dlg_prev_button(obj.buttons, button); if (button < 0) button = 0; dlg_draw_buttons(dialog, height - 2, 0, obj.buttons, button, FALSE, width); break; case DLGK_ENTER: if (dialog_vars.nook) result = DLG_EXIT_OK; else result = dlg_exit_buttoncode(button); break; case DLGK_PAGE_FIRST: if (!obj.begin_reached) { obj.begin_reached = 1; /* First page not in buffer? */ fpos = ftell_obj(&obj); if (fpos > obj.fd_bytes_read) { /* Yes, we have to read it in */ lseek_set(&obj, 0L); read_high(&obj, BUF_SIZE); } obj.in_buf = 0; moved = TRUE; } break; case DLGK_PAGE_LAST: obj.end_reached = TRUE; /* Last page not in buffer? */ fpos = ftell_obj(&obj); if (fpos < obj.file_size) { /* Yes, we have to read it in */ lseek_end(&obj, -BUF_SIZE); read_high(&obj, BUF_SIZE); } obj.in_buf = obj.bytes_read; back_lines(&obj, (long) PAGE_LENGTH); moved = TRUE; break; case DLGK_GRID_UP: /* Previous line */ if (!obj.begin_reached) { back_lines(&obj, obj.page_length + 1); next = 1; moved = TRUE; } break; case DLGK_PAGE_PREV: /* Previous page */ case DLGK_MOUSE(KEY_PPAGE): if (!obj.begin_reached) { back_lines(&obj, obj.page_length + PAGE_LENGTH); moved = TRUE; } break; case DLGK_GRID_DOWN: /* Next line */ if (!obj.end_reached) { obj.begin_reached = 0; next = -1; moved = TRUE; } break; case DLGK_PAGE_NEXT: /* Next page */ case DLGK_MOUSE(KEY_NPAGE): if (!obj.end_reached) { obj.begin_reached = 0; moved = TRUE; } break; case DLGK_BEGIN: /* Beginning of line */ if (obj.hscroll > 0) { obj.hscroll = 0; /* Reprint current page to scroll horizontally */ back_lines(&obj, obj.page_length); moved = TRUE; } break; case DLGK_GRID_LEFT: /* Scroll left */ if (obj.hscroll > 0) { obj.hscroll--; /* Reprint current page to scroll horizontally */ back_lines(&obj, obj.page_length); moved = TRUE; } break; case DLGK_GRID_RIGHT: /* Scroll right */ if (obj.hscroll < MAX_LEN) { obj.hscroll++; /* Reprint current page to scroll horizontally */ back_lines(&obj, obj.page_length); moved = TRUE; } break; #ifdef KEY_RESIZE case KEY_RESIZE: /* reset data */ height = old_height; width = old_width; back_lines(&obj, obj.page_length); /* repaint */ dlg_clear(); dlg_del_window(dialog); refresh(); dlg_mouse_free_regions(); goto retry; #endif } } else { switch (key) { case '/': /* Forward search */ case 'n': /* Repeat forward search */ case '?': /* Backward search */ case 'N': /* Repeat backward search */ moved = perform_search(&obj, height, width, key, search_term); fkey = FALSE; break; default: beep(); break; } } } dlg_del_window(dialog); free(obj.buf); (void) close(obj.fd); dlg_mouse_free_regions(); return result; }
int main(int argc, char **argv){ sqlite3_int64 szFile; unsigned char *zPgSz; const char *zPrg = argv[0]; /* Name of this executable */ char **azArg = argv; int nArg = argc; /* Check for the "--uri" or "-uri" switch. */ if( nArg>1 ){ if( sqlite3_stricmp("-raw", azArg[1])==0 || sqlite3_stricmp("--raw", azArg[1])==0 ){ g.bRaw = 1; azArg++; nArg--; } } if( nArg<2 ){ usage(zPrg); exit(1); } fileOpen(zPrg, azArg[1]); szFile = fileGetsize(); zPgSz = fileRead(16, 2); g.pagesize = zPgSz[0]*256 + zPgSz[1]*65536; if( g.pagesize==0 ) g.pagesize = 1024; sqlite3_free(zPgSz); printf("Pagesize: %d\n", g.pagesize); g.mxPage = (int)((szFile+g.pagesize-1)/g.pagesize); printf("Available pages: 1..%d\n", g.mxPage); if( nArg==2 ){ int i; for(i=1; i<=g.mxPage; i++) print_page(i); }else{ int i; for(i=2; i<nArg; i++){ int iStart, iEnd; char *zLeft; if( strcmp(azArg[i], "dbheader")==0 ){ print_db_header(); continue; } if( strcmp(azArg[i], "pgidx")==0 ){ page_usage_report(zPrg, azArg[1]); continue; } if( strcmp(azArg[i], "ptrmap")==0 ){ ptrmap_coverage_report(azArg[1]); continue; } if( strcmp(azArg[i], "help")==0 ){ usage(zPrg); continue; } if( !ISDIGIT(azArg[i][0]) ){ fprintf(stderr, "%s: unknown option: [%s]\n", zPrg, azArg[i]); continue; } iStart = strtol(azArg[i], &zLeft, 0); if( zLeft && strcmp(zLeft,"..end")==0 ){ iEnd = g.mxPage; }else if( zLeft && zLeft[0]=='.' && zLeft[1]=='.' ){ iEnd = strtol(&zLeft[2], 0, 0); }else if( zLeft && zLeft[0]=='b' ){ int ofst, nByte, hdrSize; unsigned char *a; if( iStart==1 ){ ofst = hdrSize = 100; nByte = g.pagesize-100; }else{ hdrSize = 0; ofst = (iStart-1)*g.pagesize; nByte = g.pagesize; } a = fileRead(ofst, nByte); decode_btree_page(a, iStart, hdrSize, &zLeft[1]); sqlite3_free(a); continue; }else if( zLeft && zLeft[0]=='t' ){ int detail = 0; int recursive = 0; int j; for(j=1; zLeft[j]; j++){ if( zLeft[j]=='r' ) recursive = 1; if( zLeft[j]=='d' ) detail = 1; } decode_trunk_page(iStart, detail, recursive); continue; }else{ iEnd = iStart; } if( iStart<1 || iEnd<iStart || iEnd>g.mxPage ){ fprintf(stderr, "Page argument should be LOWER?..UPPER?. Range 1 to %d\n", g.mxPage); exit(1); } while( iStart<=iEnd ){ print_page(iStart); iStart++; } } } fileClose(); return 0; }
int main(int argc, char **argv) { HPDF_Doc pdf; HPDF_Font font; HPDF_Page index_page; HPDF_Page page[9]; HPDF_Destination dst; char fname[256]; HPDF_Rect rect; HPDF_Point tp; HPDF_Annotation annot; HPDF_UINT i; const char *uri = "http://libharu.org"; strcpy (fname, argv[0]); strcat (fname, ".pdf"); pdf = HPDF_New (error_handler, NULL); if (!pdf) { printf ("error: cannot create PdfDoc object\n"); return 1; } if (setjmp(env)) { HPDF_Free (pdf); return 1; } /* create default-font */ font = HPDF_GetFont (pdf, "Helvetica", NULL); /* create index page */ index_page = HPDF_AddPage (pdf); HPDF_Page_SetWidth (index_page, 300); HPDF_Page_SetHeight (index_page, 220); /* Add 7 pages to the document. */ for (i = 0; i < 7; i++) { page[i] = HPDF_AddPage (pdf); print_page(page[i], font, i + 1); } HPDF_Page_BeginText (index_page); HPDF_Page_SetFontAndSize (index_page, font, 10); HPDF_Page_MoveTextPos (index_page, 15, 200); HPDF_Page_ShowText (index_page, "Link Annotation Demo"); HPDF_Page_EndText (index_page); /* * Create Link-Annotation object on index page. */ HPDF_Page_BeginText(index_page); HPDF_Page_SetFontAndSize (index_page, font, 8); HPDF_Page_MoveTextPos (index_page, 20, 180); HPDF_Page_SetTextLeading (index_page, 23); /* page1 (HPDF_ANNOT_NO_HIGHTLIGHT) */ tp = HPDF_Page_GetCurrentTextPos (index_page); HPDF_Page_ShowText (index_page, "Jump to Page1 (HilightMode=HPDF_ANNOT_NO_HIGHTLIGHT)"); rect.left = tp.x - 4; rect.bottom = tp.y - 4; rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4; rect.top = tp.y + 10; HPDF_Page_MoveToNextLine (index_page); dst = HPDF_Page_CreateDestination (page[0]); annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst); HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_NO_HIGHTLIGHT); /* page2 (HPDF_ANNOT_INVERT_BOX) */ tp = HPDF_Page_GetCurrentTextPos (index_page); HPDF_Page_ShowText (index_page, "Jump to Page2 (HilightMode=HPDF_ANNOT_INVERT_BOX)"); rect.left = tp.x - 4; rect.bottom = tp.y - 4; rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4; rect.top = tp.y + 10; HPDF_Page_MoveToNextLine (index_page); dst = HPDF_Page_CreateDestination (page[1]); annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst); HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_INVERT_BOX); /* page3 (HPDF_ANNOT_INVERT_BORDER) */ tp = HPDF_Page_GetCurrentTextPos (index_page); HPDF_Page_ShowText (index_page, "Jump to Page3 (HilightMode=HPDF_ANNOT_INVERT_BORDER)"); rect.left = tp.x - 4; rect.bottom = tp.y - 4; rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4; rect.top = tp.y + 10; HPDF_Page_MoveToNextLine (index_page); dst = HPDF_Page_CreateDestination (page[2]); annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst); HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_INVERT_BORDER); /* page4 (HPDF_ANNOT_DOWN_APPEARANCE) */ tp = HPDF_Page_GetCurrentTextPos (index_page); HPDF_Page_ShowText (index_page, "Jump to Page4 (HilightMode=HPDF_ANNOT_DOWN_APPEARANCE)"); rect.left = tp.x - 4; rect.bottom = tp.y - 4; rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4; rect.top = tp.y + 10; HPDF_Page_MoveToNextLine (index_page); dst = HPDF_Page_CreateDestination (page[3]); annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst); HPDF_LinkAnnot_SetHighlightMode (annot, HPDF_ANNOT_DOWN_APPEARANCE); /* page5 (dash border) */ tp = HPDF_Page_GetCurrentTextPos (index_page); HPDF_Page_ShowText (index_page, "Jump to Page5 (dash border)"); rect.left = tp.x - 4; rect.bottom = tp.y - 4; rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4; rect.top = tp.y + 10; HPDF_Page_MoveToNextLine (index_page); dst = HPDF_Page_CreateDestination (page[4]); annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst); HPDF_LinkAnnot_SetBorderStyle (annot, 1, 3, 2); /* page6 (no border) */ tp = HPDF_Page_GetCurrentTextPos (index_page); HPDF_Page_ShowText (index_page, "Jump to Page6 (no border)"); rect.left = tp.x - 4; rect.bottom = tp.y - 4; rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4; rect.top = tp.y + 10; HPDF_Page_MoveToNextLine (index_page); dst = HPDF_Page_CreateDestination (page[5]); annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst); HPDF_LinkAnnot_SetBorderStyle (annot, 0, 0, 0); /* page7 (bold border) */ tp = HPDF_Page_GetCurrentTextPos (index_page); HPDF_Page_ShowText (index_page, "Jump to Page7 (bold border)"); rect.left = tp.x - 4; rect.bottom = tp.y - 4; rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4; rect.top = tp.y + 10; HPDF_Page_MoveToNextLine (index_page); dst = HPDF_Page_CreateDestination (page[6]); annot = HPDF_Page_CreateLinkAnnot (index_page, rect, dst); HPDF_LinkAnnot_SetBorderStyle (annot, 2, 0, 0); /* URI link */ tp = HPDF_Page_GetCurrentTextPos (index_page); HPDF_Page_ShowText (index_page, "URI ("); HPDF_Page_ShowText (index_page, uri); HPDF_Page_ShowText (index_page, ")"); rect.left = tp.x - 4; rect.bottom = tp.y - 4; rect.right = HPDF_Page_GetCurrentTextPos (index_page).x + 4; rect.top = tp.y + 10; HPDF_Page_CreateURILinkAnnot (index_page, rect, uri); HPDF_Page_EndText (index_page); /* save the document to a file */ HPDF_SaveToFile (pdf, fname); /* clean up */ HPDF_Free (pdf); return 0; }
/* * Display text from a file in a dialog box. */ int dialog_textbox (const char *title, const char *file, int height, int width) { int i, x, y, cur_x, cur_y, fpos, key = 0, dir, temp, temp1; #ifdef HAVE_LIBNCURSES int passed_end; #endif char search_term[MAX_LEN + 1], *tempptr, *found; WINDOW *dialog, *text; search_term[0] = '\0'; /* no search term entered yet */ /* Open input file for reading */ if ((fd = open (file, O_RDONLY)) == -1) { endwin (); fprintf (stderr, "\nCan't open input file in dialog_textbox().\n"); exit (-1); } /* Get file size. Actually, 'file_size' is the real file size - 1, since it's only the last byte offset from the beginning */ if ((file_size = lseek (fd, 0, SEEK_END)) == -1) { endwin (); fprintf (stderr, "\nError getting file size in dialog_textbox().\n"); exit (-1); } /* Restore file pointer to beginning of file after getting file size */ if (lseek (fd, 0, SEEK_SET) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } /* Allocate space for read buffer */ if ((buf = malloc (BUF_SIZE + 1)) == NULL) { endwin (); fprintf (stderr, "\nCan't allocate memory in dialog_textbox().\n"); exit (-1); } if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { endwin (); fprintf (stderr, "\nError reading file in dialog_textbox().\n"); exit (-1); } buf[bytes_read] = '\0'; /* mark end of valid data */ page = buf; /* page is pointer to start of page to be displayed */ /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; #ifdef HAVE_LIBNCURSES if (use_shadow) draw_shadow (stdscr, y, x, height, width); #endif dialog = newwin (height, width, y, x); mouse_setbase (x, y); keypad (dialog, TRUE); /* Create window for text region, used for scrolling text */ text = subwin (dialog, height - 4, width - 2, y + 1, x + 1); keypad (text, TRUE); /* register the new window, along with its borders */ mouse_mkbigregion (0, 0, height - 2, width, 1, 0, 2 /* not normal */ ); draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset (dialog, border_attr); wmove (dialog, height - 3, 0); waddch (dialog, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch (dialog, ACS_HLINE); wattrset (dialog, dialog_attr); waddch (dialog, ACS_RTEE); wmove (dialog, height - 2, 1); for (i = 0; i < width - 2; i++) waddch (dialog, ' '); if (title != NULL) { wattrset (dialog, title_attr); wmove (dialog, 0, (width - strlen (title)) / 2 - 1); waddch (dialog, ' '); waddstr (dialog, title); waddch (dialog, ' '); } print_button (dialog, " EXIT ", height - 2, width / 2 - 4, TRUE); wnoutrefresh (dialog); getyx (dialog, cur_y, cur_x); /* Save cursor position */ /* Print first page of text */ attr_clear (text, height - 4, width - 2, dialog_attr); print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); while ((key != ESC) && (key != '\n')) { key = mouse_wgetch (dialog); switch (key) { case M_EVENT + 'E': case 'E': /* Exit */ case 'e': delwin (dialog); free (buf); close (fd); return 0; case 'g': /* First page */ case KEY_HOME: if (!begin_reached) { begin_reached = 1; /* First page not in buffer? */ if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } if (fpos > bytes_read) { /* Yes, we have to read it in */ if (lseek (fd, 0, SEEK_SET) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in " "dialog_textbox().\n"); exit (-1); } if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { endwin (); fprintf (stderr, "\nError reading file in dialog_textbox().\n"); exit (-1); } buf[bytes_read] = '\0'; } page = buf; print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); } break; case 'G': /* Last page */ #ifdef HAVE_LIBNCURSES case KEY_END: #endif end_reached = 1; /* Last page not in buffer? */ if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } if (fpos < file_size) { /* Yes, we have to read it in */ if (lseek (fd, -BUF_SIZE, SEEK_END) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { endwin (); fprintf (stderr, "\nError reading file in dialog_textbox().\n"); exit (-1); } buf[bytes_read] = '\0'; } page = buf + bytes_read; back_lines (height - 4); print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); break; case 'K': /* Previous line */ case 'k': case KEY_UP: if (!begin_reached) { back_lines (page_length + 1); #ifdef HAVE_LIBNCURSES /* We don't call print_page() here but use scrolling to ensure faster screen update. However, 'end_reached' and 'page_length' should still be updated, and 'page' should point to start of next page. This is done by calling get_line() in the following 'for' loop. */ scrollok (text, TRUE); wscrl (text, -1); /* Scroll text region down one line */ scrollok (text, FALSE); page_length = 0; passed_end = 0; for (i = 0; i < height - 4; i++) { if (!i) { /* print first line of page */ print_line (text, 0, width - 2); wnoutrefresh (text); } else /* Called to update 'end_reached' and 'page' */ get_line (); if (!passed_end) page_length++; if (end_reached && !passed_end) passed_end = 1; } #else print_page (text, height - 4, width - 2); #endif print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); } break; case 'B': /* Previous page */ case 'b': case KEY_PPAGE: if (begin_reached) break; back_lines (page_length + height - 4); print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; case 'J': /* Next line */ case 'j': case KEY_DOWN: if (!end_reached) { begin_reached = 0; scrollok (text, TRUE); scroll (text); /* Scroll text region up one line */ scrollok (text, FALSE); print_line (text, height - 5, width - 2); #ifndef HAVE_LIBNCURSES wmove (text, height - 5, 0); waddch (text, ' '); wmove (text, height - 5, width - 3); waddch (text, ' '); #endif wnoutrefresh (text); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); } break; case ' ': /* Next page */ case KEY_NPAGE: if (end_reached) break; begin_reached = 0; print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; case '0': /* Beginning of line */ case 'H': /* Scroll left */ case 'h': case KEY_LEFT: if (hscroll <= 0) break; if (key == '0') hscroll = 0; else hscroll--; /* Reprint current page to scroll horizontally */ back_lines (page_length); print_page (text, height - 4, width - 2); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; case 'L': /* Scroll right */ case 'l': case KEY_RIGHT: if (hscroll >= MAX_LEN) break; hscroll++; /* Reprint current page to scroll horizontally */ back_lines (page_length); print_page (text, height - 4, width - 2); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; case '/': /* Forward search */ case 'n': /* Repeat forward search */ case '?': /* Backward search */ case 'N': /* Repeat backward search */ /* set search direction */ dir = (key == '/' || key == 'n') ? 1 : 0; if (dir ? !end_reached : !begin_reached) { if (key == 'n' || key == 'N') { if (search_term[0] == '\0') { /* No search term yet */ fprintf (stderr, "\a"); /* beep */ break; } } else /* Get search term from user */ if (get_search_term (text, search_term, height - 4, width - 2) == -1) { /* ESC pressed in get_search_term(). Reprint page to clear box */ wattrset (text, dialog_attr); back_lines (page_length); print_page (text, height - 4, width - 2); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; } /* Save variables for restoring in case search term can't be found */ tempptr = page; temp = begin_reached; temp1 = end_reached; if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in " "dialog_textbox().\n"); exit (-1); } fpos -= bytes_read; /* update 'page' to point to next (previous) line before forward (backward) searching */ back_lines (dir ? page_length - 1 : page_length + 1); found = NULL; if (dir) /* Forward search */ while ((found = strstr (get_line (), search_term)) == NULL) { if (end_reached) break; } else /* Backward search */ while ((found = strstr (get_line (), search_term)) == NULL) { if (begin_reached) break; back_lines (2); } if (found == NULL) { /* not found */ fprintf (stderr, "\a"); /* beep */ /* Restore program state to that before searching */ if (lseek (fd, fpos, SEEK_SET) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in " "dialog_textbox().\n"); exit (-1); } if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { endwin (); fprintf (stderr, "\nError reading file in " "dialog_textbox().\n"); exit (-1); } buf[bytes_read] = '\0'; page = tempptr; begin_reached = temp; end_reached = temp1; /* move 'page' to point to start of current page in order to re-print current page. Note that 'page' always points to start of next page, so this is necessary */ back_lines (page_length); } else /* Search term found */ back_lines (1); /* Reprint page */ wattrset (text, dialog_attr); print_page (text, height - 4, width - 2); if (found != NULL) print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); } else /* no need to find */ fprintf (stderr, "\a"); /* beep */ break; case ESC: break; } } delwin (dialog); free (buf); close (fd); return -1; /* ESC pressed */ }
int main(int argc, char **argv) { FILE *f; /* our input file */ uchar *p; /* storage of pages read */ int bytes; /* bytes read count */ ulint ct; /* current page number (0 based) */ ulint start_page= 0, end_page= 0, use_end_page= 0; /* for starting and ending at certain pages */ off_t offset= 0; int c; int fd; fpos_t pos; /* remove arguments */ while ((c= getopt(argc, argv, "s:e:p:")) != -1) { switch (c) { case 's': start_page= atoi(optarg); break; case 'e': end_page= atoi(optarg); use_end_page= 1; break; case 'p': start_page= atoi(optarg); end_page= atoi(optarg); use_end_page= 1; break; case ':': fprintf(stderr, "option -%c requires an argument\n", optopt); return 1; break; case '?': fprintf(stderr, "unrecognized option: -%c\n", optopt); return 1; break; } } /* make sure we have the right arguments */ if (optind >= argc) { printf("InnoDB page printer.\n"); printf("usage: [-s <start page>] [-e <end page>] [-p <page>] %s <filename>\n", argv[0]); printf("\t-s n\tstart on this page number (0 based)\n"); printf("\t-e n\tend at this page number (0 based)\n"); printf("\t-p n\tcheck only this page (0 based)\n"); return 1; } f = fopen(argv[optind], "r"); if (!f) { perror("error opening file"); return 1; } /* seek to the necessary position */ if (start_page) { fd= fileno(f); if (!fd) { perror("unable to obtain file descriptor number"); return 1; } offset= (off_t)start_page * (off_t)UNIV_PAGE_SIZE; if (lseek(fd, offset, SEEK_SET) != offset) { perror("unable to seek to necessary offset"); return 1; } } /* allocate buffer for reading (so we don't realloc every time) */ p= (uchar *)malloc(UNIV_PAGE_SIZE); ct= start_page; while (!feof(f)) { fgetpos(f, &pos); bytes= fread(p, 1, UNIV_PAGE_SIZE, f); if (!bytes && feof(f)) return 0; if (bytes != UNIV_PAGE_SIZE) { fprintf(stderr, "bytes read (%d) doesn't match universal page size (%d)\n", bytes, UNIV_PAGE_SIZE); return 1; } print_page(p); /* end if this was the last page we were supposed to check */ if (use_end_page && (ct >= end_page)) return 0; ct++; } return 0; }
int main(int argc, char **argv) { char *in_name, *out_name, *s; struct umatrix *umat; struct eps_info einfo; int average = 0; int median = 0; FILE *out_fp; struct file_info *out_fi; global_options(argc, argv); if (extract_parameter(argc, argv, "-help", OPTION2)) { printhelp(); exit(0); } in_name = NULL; out_name = NULL; /* default page size is A4 */ set_paper(get_paper_by_id(PAPER_A4)); /* parse args */ if (extract_parameter(argc, argv, "-border", OPTION2)) doborder = 1; if (extract_parameter(argc, argv, "-portrait", OPTION2)) orientation = PORTRAIT; if (extract_parameter(argc, argv, "-landscape", OPTION2)) orientation = LANDSCAPE; if (extract_parameter(argc, argv, "-ps", OPTION2)) mode = OUTPUT_PS; if (extract_parameter(argc, argv, "-eps", OPTION2)) mode = OUTPUT_EPS; white_treshold = oatof(extract_parameter(argc, argv, "-W", OPTION), 1.0); black_treshold = oatof(extract_parameter(argc, argv, "-B", OPTION), 0.0); out_name = extract_parameter(argc, argv, "-o", OPTION); if (mode == 0) mode = guess_mode(out_name); if ((s = extract_parameter(argc, argv, "-font", OPTION))) fontname = s; fontsize = oatof(extract_parameter(argc, argv, "-fontsize", OPTION), -1.0); title = extract_parameter(argc, argv, "-title", OPTION); if (extract_parameter(argc, argv, "-notitle", OPTION2)) notitle = 1; if ((s = extract_parameter(argc, argv, "-paper", OPTION))) { struct paper_info *p = get_paper_by_name(s); if (p == NULL) { fprintf(stderr, "Unknown paper type: %s\n", s); exit(1); } set_paper(p); } if (extract_parameter(argc, argv, "-average", OPTION2)) average = 1; if (extract_parameter(argc, argv, "-median", OPTION2)) median = 1; if (extract_parameter(argc, argv, "-onlylabs", OPTION2)) drawblocks = 0; if (extract_parameter(argc, argv, "-nolabs", OPTION2)) drawlabels = 0; in_name = extract_parameter(argc, argv, IN_CODE_FILE, ALWAYS); if ((s = getenv("UMAT_HEADERFILE"))) headerfile = s; if ((s = extract_parameter(argc, argv, "-headerfile", OPTION))) headerfile = s; label_not_needed(1); if ((umat = read_map(in_name, 0, 0)) == NULL) { fprintf(stderr, "Can't load file\n"); exit(1); } calc_umatrix(umat, 0, 0); if (average) average_umatrix(umat); if (median) median_umatrix(umat); if (mode == 0) mode = OUTPUT_EPS; if (orientation == BEST) orientation = (umat->mxdim >= umat->mydim) ? LANDSCAPE : PORTRAIT; if ((out_fi = open_file(out_name, "w")) == NULL) { fprintf(stderr, "can't open output file\n"); free_umat(umat); exit(1); } out_fp = fi2fp(out_fi); einfo.umat = umat; einfo.title = title ? title : in_name; image_size(&einfo, 0); if (mode == OUTPUT_EPS) print_eps(out_fp, &einfo); else print_page(out_fp, &einfo); free_umat(umat); umat = NULL; if (out_fi) close_file(out_fi); return 0; }
int dialog_textyesno (const char *title, const char *file, int height, int width) { int i, x, y, cur_x, cur_y, fpos, key = 0, button = 0; int passed_end; char search_term[MAX_LEN + 1]; WINDOW *dialog, *text; search_term[0] = '\0'; /* no search term entered yet */ /* Open input file for reading */ if ((fd = open (file, O_RDONLY)) == -1) { endwin (); fprintf (stderr, "\nCan't open input file in dialog_textbox().\n"); exit (-1); } /* Get file size. Actually, 'file_size' is the real file size - 1, since it's only the last byte offset from the beginning */ if ((file_size = lseek (fd, 0, SEEK_END)) == -1) { endwin (); fprintf (stderr, "\nError getting file size in dialog_textbox().\n"); exit (-1); } /* Restore file pointer to beginning of file after getting file size */ if (lseek (fd, 0, SEEK_SET) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } /* Allocate space for read buffer */ if ((buf = malloc (BUF_SIZE + 1)) == NULL) { endwin (); fprintf (stderr, "\nCan't allocate memory in dialog_textbox().\n"); exit (-1); } if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { endwin (); fprintf (stderr, "\nError reading file in dialog_textbox().\n"); exit (-1); } buf[bytes_read] = '\0'; /* mark end of valid data */ page = buf; /* page is pointer to start of page to be displayed */ /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow (stdscr, y, x, height, width); dialog = newwin (height, width, y, x); keypad (dialog, TRUE); /* Create window for text region, used for scrolling text */ text = subwin (dialog, height - 4, width - 2, y + 1, x + 1); wattrset (text, dialog_attr); wbkgdset (text, dialog_attr & A_COLOR); keypad (text, TRUE); /* register the new window, along with its borders */ draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); wattrset (dialog, border_attr); mvwaddch (dialog, height-3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch (dialog, ACS_HLINE); wattrset (dialog, dialog_attr); wbkgdset (dialog, dialog_attr & A_COLOR); waddch (dialog, ACS_RTEE); if (title != NULL && strlen(title) >= width-2 ) { /* truncate long title -- mec */ char * title2 = malloc(width-2+1); memcpy( title2, title, width-2 ); title2[width-2] = '\0'; title = title2; } if (title != NULL) { wattrset (dialog, title_attr); mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); waddstr (dialog, (char *)title); waddch (dialog, ' '); } //Nenad instered this print_buttons(dialog, height, width, 0); wnoutrefresh (dialog); getyx (dialog, cur_y, cur_x); /* Save cursor position */ /* Print first page of text */ attr_clear (text, height - 4, width - 2, dialog_attr); print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); while ((key != ESC) && (key != '\n')) { key = wgetch (dialog); switch (key) { case 'Y': /* Exit */ case 'y': delwin (dialog); free (buf); close (fd); return 0; case 'N': case 'n': delwin (dialog); free (buf); close (fd); return 1; case 'g': /* First page */ case KEY_HOME: if (!begin_reached) { begin_reached = 1; /* First page not in buffer? */ if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } if (fpos > bytes_read) { /* Yes, we have to read it in */ if (lseek (fd, 0, SEEK_SET) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in " "dialog_textbox().\n"); exit (-1); } if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { endwin (); fprintf (stderr, "\nError reading file in dialog_textbox().\n"); exit (-1); } buf[bytes_read] = '\0'; } page = buf; print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); } break; case 'G': /* Last page */ case KEY_END: end_reached = 1; /* Last page not in buffer? */ if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } if (fpos < file_size) { /* Yes, we have to read it in */ if (lseek (fd, -BUF_SIZE, SEEK_END) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); exit (-1); } if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { endwin (); fprintf (stderr, "\nError reading file in dialog_textbox().\n"); exit (-1); } buf[bytes_read] = '\0'; } page = buf + bytes_read; back_lines (height - 4); print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); break; case 'K': /* Previous line */ case 'k': case KEY_UP: if (!begin_reached) { back_lines (page_length + 1); /* We don't call print_page() here but use scrolling to ensure faster screen update. However, 'end_reached' and 'page_length' should still be updated, and 'page' should point to start of next page. This is done by calling get_line() in the following 'for' loop. */ scrollok (text, TRUE); wscrl (text, -1); /* Scroll text region down one line */ scrollok (text, FALSE); page_length = 0; passed_end = 0; for (i = 0; i < height - 4; i++) { if (!i) { /* print first line of page */ print_line (text, 0, width - 2); wnoutrefresh (text); } else /* Called to update 'end_reached' and 'page' */ get_line (); if (!passed_end) page_length++; if (end_reached && !passed_end) passed_end = 1; } print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); } break; case 'B': /* Previous page */ case 'b': case KEY_PPAGE: if (begin_reached) break; back_lines (page_length + height - 4); print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; case 'J': /* Next line */ case 'j': case KEY_DOWN: if (!end_reached) { begin_reached = 0; scrollok (text, TRUE); scroll (text); /* Scroll text region up one line */ scrollok (text, FALSE); print_line (text, height - 5, width - 2); wnoutrefresh (text); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); /* Restore cursor position */ wrefresh (dialog); } break; case KEY_NPAGE: /* Next page */ if (end_reached) break; begin_reached = 0; print_page (text, height - 4, width - 2); print_position (dialog, height, width); wmove (dialog, cur_y, cur_x); wrefresh (dialog); break; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh (dialog); break; case ' ': case '\n': delwin (dialog); free (buf); close (fd); return button; case ESC: break; } } delwin (dialog); free (buf); close (fd); return -1; /* ESC pressed */ }
int main(int argc, char *argv[]) { if (!parseArgs(the_args, &argc, argv) || argc < 2 || show_help) { printUsage(argv[0], "DOCUMENT", the_args); exit(1); } if (show_text[0]) { if (!memcmp(show_text, "physical", 9)) { show_text_layout = poppler::page::physical_layout; } else if (!memcmp(show_text, "raw", 4)) { show_text_layout = poppler::page::raw_order_layout; } else { error(std::string("unrecognized text mode: '") + show_text + "'"); } } std::string file_name(argv[1]); std::auto_ptr<poppler::document> doc(poppler::document::load_from_file(file_name)); if (!doc.get()) { error("loading error"); } if (doc->is_locked()) { error("encrypted document"); } std::cout.setf(std::ios_base::boolalpha); if (show_all) { show_info = true; show_perm = true; show_metadata = true; show_toc = true; show_fonts = true; show_embedded_files = true; show_pages = true; } if (show_info) { print_info(doc.get()); } if (show_perm) { print_perm(doc.get()); } if (show_metadata) { print_metadata(doc.get()); } if (show_toc) { std::auto_ptr<poppler::toc> doctoc(doc->create_toc()); print_toc(doctoc.get()); } if (show_fonts) { print_fonts(doc.get()); } if (show_embedded_files) { print_embedded_files(doc.get()); } if (show_pages) { const int pages = doc->pages(); for (int i = 0; i < pages; ++i) { std::cout << "Page " << (i + 1) << "/" << pages << ":" << std::endl; std::auto_ptr<poppler::page> p(doc->create_page(i)); print_page(p.get()); } } if (show_text[0]) { const int pages = doc->pages(); for (int i = 0; i < pages; ++i) { std::cout << "Page " << (i + 1) << "/" << pages << ":" << std::endl; std::auto_ptr<poppler::page> p(doc->create_page(i)); print_page_text(p.get()); } } return 0; }
int main(int argc, char *argv[]) { // commandline argument parser options struct arg_lit *help = arg_lit0("h", "help", "print this help and exit"); struct arg_lit *vers = arg_lit0("v", "version", "print version information and exit"); struct arg_file *file = arg_file1("f", "file", "<file>", "Score file"); struct arg_int *page = arg_int0("p", "page", "<int>", "Page ID"); struct arg_file *output = arg_file0("o", "output", "<file>", "Output file"); struct arg_end *end = arg_end(20); void* argtable[] = {help,vers,file,page,output,end}; const char* progname = "scoretool"; // Make sure everything got allocated if(arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); goto exit_0; } // Parse arguments int nerrors = arg_parse(argc, argv, argtable); // Handle help if(help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); printf("\nArguments:\n"); arg_print_glossary(stdout, argtable, "%-25s %s\n"); goto exit_0; } // Handle version if(vers->count > 0) { printf("%s v0.1\n", progname); printf("Command line One Must Fall 2097 Score file editor.\n"); printf("Source code is available at https://github.com/omf2097 under MIT license.\n"); printf("(C) 2014 Tuomas Virtanen\n"); goto exit_0; } // Handle errors if(nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); goto exit_0; } // Get score information sd_score score; sd_score_create(&score); int ret = sd_score_load(&score, file->filename[0]); if(ret != SD_SUCCESS) { printf("Score file %s could not be loaded: %s\n", file->filename[0], sd_get_error(ret)); goto exit_0; } // See if we want to print a single page or all pages if(page->count > 0) { int page_id = page->ival[0]; if(page_id < 0 || page_id >= SD_SCORE_PAGES) { printf("Page must be between 0 and 3.\n"); goto exit_1; } // Print only this page print_page(&score, page_id); } else { for(int i = 0; i < SD_SCORE_PAGES; i++) { print_page(&score, i); printf("\n"); } } // Save if necessary if(output->count > 0) { ret = sd_score_save(&score, output->filename[0]); if(ret != SD_SUCCESS) { printf("Failed to save scores file to %s: %s\n", output->filename[0], sd_get_error(ret)); } } exit_1: sd_score_free(&score); exit_0: arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 0; }