static int _read_help_topic(int topic, int off, int len, VOIDFARPTR buf) { static int curr_topic = -1; static long curr_base; static int curr_len; int read_len; if ( topic != curr_topic ) { int t; char ch; int dummy; /* to quiet compiler */ curr_topic = topic; curr_base = topic_offset[topic]; curr_base += sizeof(int); /* skip flags */ help_seek(curr_base); dummy = read(help_file, (char *)&t, sizeof(int)); /* read num_pages */ curr_base += sizeof(int) + t*3*sizeof(int); /* skip page info */ if (t>0) help_seek(curr_base); dummy = read(help_file, &ch, 1); /* read title_len */ t = ch; curr_base += 1 + t; /* skip title */ if (t>0) help_seek(curr_base); dummy = read(help_file, (char *)&curr_len, sizeof(int)); /* read topic len */ curr_base += sizeof(int); } read_len = (off+len > curr_len) ? curr_len - off : len; if (read_len > 0) { help_seek(curr_base + off); farread(help_file, (char far *)buf, read_len); } return ( curr_len - (off+len) ); }
int loadStrings(res_majorid_t major , res_minorid_t minor , long length , FILE* f , void * const arg) { loadStatus *ls = arg; char fdid[sizeof(STRINGS_ID)]; string_size_t len, firstStr; string_index_t far*idx; int i; if((unsigned long)length >= 0x10000ul || (unsigned)length < STRINGS_HEADER_SIZE) { *ls = STRINGS_SIZE_MISMATCH; return 0; } fread(fdid, sizeof(STRINGS_ID) - 1, 1, f); if (memcmp(fdid, STRINGS_ID, sizeof(STRINGS_ID) - 1)) { *ls = STRINGS_ID_MISMATCH; return 0; /* Continue searching */ } /* immediately after the ID a trailer follows */ fseek(f, (long)STRINGS_ID_TRAILER, 1); /* Read the strings dimensionating parameters */ if(ferror(f) || fread(&strCnt, sizeof(strCnt), 1, f) != 1 || fread(&len, sizeof(len), 1, f) != 1) { /* Read error */ *ls = STRINGS_READ_ERROR; return 0; /* Continue searching */ } /* At this point f is positioned at the very first string index the data area is NUMBER_OF_STRINGS * sizeof(index) + SIZE_OF_STRINGS */ len += firstStr = strCnt * sizeof(string_index_t); if((unsigned)length - STRINGS_HEADER_SIZE < len) { *ls = STRINGS_SIZE_MISMATCH; return 0; } /* allocation mode: last fit, high first */ if ((msgSegm = allocBlk(len, 0x82)) == 0) { *ls = STRINGS_OUT_OF_MEMORY; return 0; } if(farread(MK_FP(msgSegm, 0), len, f) != len) { unloadMsgs(); /* Remove the message segment */ *ls = STRINGS_READ_ERROR; return 0; } /* Now the offset of the index array are updated to point to the real offset instead of the displacement based on the first byte of the string data area */ idx = MK_FP(msgSegm, 0); for(i = 0; i < strCnt; ++i) idx[i].index += firstStr; *ls = STRINGS_LOADED; return 1; /* Stop searching */ }
static int help_topic(HIST *curr, HIST *next, int flags) { int len; int key; int num_pages; int num_link; int page; int curr_link; char title[81]; long where; int draw_page; int action; BYTE ch; int dummy; /* to quiet compiler */ where = topic_offset[curr->topic_num]+sizeof(int); /* to skip flags */ curr_link = curr->link; help_seek(where); dummy = read(help_file, (char *)&num_pages, sizeof(int)); assert(num_pages>0 && num_pages<=max_pages); farread(help_file, (char far *)page_table, 3*sizeof(int)*num_pages); dummy = read(help_file, &ch, 1); len = ch; assert(len<81); dummy = read(help_file, (char *)title, len); title[len] = '\0'; where += sizeof(int) + num_pages*3*sizeof(int) + 1 + len + sizeof(int); for(page=0; page<num_pages; page++) if (curr->topic_off >= page_table[page].offset && curr->topic_off < page_table[page].offset+page_table[page].len ) break; assert(page < num_pages); action = -1; draw_page = 2; do { if (draw_page) { help_seek(where+page_table[page].offset); farread(help_file, buffer, page_table[page].len); num_link = 0; display_page(title, buffer, page_table[page].len, page, num_pages, page_table[page].margin, &num_link, link_table); if (draw_page==2) { assert(num_link<=0 || (curr_link>=0 && curr_link<num_link)); } else if (draw_page==3) curr_link = num_link - 1; else curr_link = 0; if (num_link > 0) color_link(&link_table[curr_link], C_HELP_CURLINK); draw_page = 0; } key = getakey(); switch(key) { case PAGE_DOWN: if (page<num_pages-1) { page++; draw_page = 1; } break; case PAGE_UP: if (page>0) { page--; draw_page = 1; } break; case HOME: if ( page != 0 ) { page = 0; draw_page = 1; } else do_move_link(link_table, num_link, &curr_link, NULL, 0); break; case END: if ( page != num_pages-1 ) { page = num_pages-1; draw_page = 3; } else do_move_link(link_table, num_link, &curr_link, NULL, num_link-1); break; case TAB: if ( !do_move_link(link_table, num_link, &curr_link, find_link_key, key) && page<num_pages-1 ) { ++page; draw_page = 1; } break; case BACK_TAB: if ( !do_move_link(link_table, num_link, &curr_link, find_link_key, key) && page>0 ) { --page; draw_page = 3; } break; case DOWN_ARROW: if ( !do_move_link(link_table, num_link, &curr_link, find_link_updown, 0) && page<num_pages-1 ) { ++page; draw_page = 1; } break; case UP_ARROW: if ( !do_move_link(link_table, num_link, &curr_link, find_link_updown, 1) && page>0 ) { --page; draw_page = 3; } break; case LEFT_ARROW: do_move_link(link_table, num_link, &curr_link, find_link_leftright, 1); break; case RIGHT_ARROW: do_move_link(link_table, num_link, &curr_link, find_link_leftright, 0); break; case ESC: /* exit help */ action = ACTION_QUIT; break; case BACKSPACE: /* prev topic */ case ALT_F1: if (flags & F_HIST) action = ACTION_PREV; break; case F1: /* help index */ if (!(flags & F_INDEX)) action = ACTION_INDEX; break; case ENTER: case ENTER_2: if (num_link > 0) { next->topic_num = link_table[curr_link].topic_num; next->topic_off = link_table[curr_link].topic_off; action = ACTION_CALL; } break; } /* switch */ } while ( action == -1 ); curr->topic_off = page_table[page].offset; curr->link = curr_link; return (action); }
int init_help(void) { struct help_sig_info hs; char path[FILE_MAX_PATH+1]; int dummy; /* to quiet compiler */ help_file = -1; #ifndef WINFRACT #ifndef XFRACT if (help_file == -1) /* now look for help files in FRACTINT.EXE */ { static FCODE err_no_open[] = "Help system was unable to open FRACTINT.EXE!\n"; static FCODE err_no_exe[] = "Help system couldn't find FRACTINT.EXE!\n"; static FCODE err_wrong_ver[] = "Wrong help version in FRACTINT.EXE!\n"; /* static FCODE err_not_in_exe[] = "Help not found in FRACTINT.EXE!\n"; */ if ( find_file(s_fractintexe, path) ) { #ifdef __TURBOC__ if ( (help_file = open(path, O_RDONLY|O_BINARY|O_DENYWRITE)) != -1 ) #else if ( (help_file = open(path, O_RDONLY|O_BINARY)) != -1 ) #endif { long help_offset; for (help_offset = -((long)sizeof(hs)); help_offset >= -128L; help_offset--) { lseek(help_file, help_offset, SEEK_END); dummy = read(help_file, (char *)&hs, sizeof(hs)); if (hs.sig == HELP_SIG) break; } if ( hs.sig != HELP_SIG ) { close(help_file); help_file = -1; /* (leave out the error message) stopmsg(1, err_not_in_exe); */ } else { if ( hs.version != HELP_VERSION ) { close(help_file); help_file = -1; stopmsg(1, err_wrong_ver); } else base_off = hs.base; } } else stopmsg(1, err_no_open); } else stopmsg(1, err_no_exe); } #endif #endif if (help_file == -1) /* look for FRACTINT.HLP */ { if ( find_file("fractint.hlp", path) ) { #ifdef __TURBOC__ if ( (help_file = open(path, O_RDONLY|O_BINARY|O_DENYWRITE)) != -1 ) #else if ( (help_file = open(path, O_RDONLY|O_BINARY)) != -1 ) #endif { dummy = read(help_file, (char *)&hs, sizeof(long)+sizeof(int)); if ( hs.sig != HELP_SIG ) { static FCODE msg[] = {"Invalid help signature in FRACTINT.HLP!\n"}; close(help_file); stopmsg(1, msg); } else if ( hs.version != HELP_VERSION ) { static FCODE msg[] = {"Wrong help version in FRACTINT.HLP!\n"}; close(help_file); stopmsg(1, msg); } else base_off = sizeof(long)+sizeof(int); } } } if (help_file == -1) /* Can't find the help files anywhere! */ { static FCODE msg[] = #ifndef XFRACT {"Help Files aren't in FRACTINT.EXE, and couldn't find FRACTINT.HLP!\n"}; #else {"Couldn't find fractint.hlp; set FRACTDIR to proper directory with setenv.\n"}; #endif stopmsg(1, msg); } help_seek(0L); dummy = read(help_file, (char *)&max_pages, sizeof(int)); dummy = read(help_file, (char *)&max_links, sizeof(int)); dummy = read(help_file, (char *)&num_topic, sizeof(int)); dummy = read(help_file, (char *)&num_label, sizeof(int)); help_seek((long)6*sizeof(int)); /* skip num_contents and num_doc_pages */ assert(max_pages > 0); assert(max_links >= 0); assert(num_topic > 0); assert(num_label > 0); /* allocate one big chunk for all three arrays */ topic_offset = (long far *)farmemalloc(sizeof(long)*num_topic + 2L*sizeof(int)*num_label + sizeof(HIST)*MAX_HIST); if (topic_offset == NULL) { static FCODE err_no_mem[] = "Not enough memory for help system!\n"; close(help_file); help_file = -1; stopmsg(1, err_no_mem); return (-2); } /* split off the other arrays */ label = (LABEL far *)(&topic_offset[num_topic]); hist = (HIST far *)(&label[num_label]); /* read in the tables... */ farread(help_file, topic_offset, num_topic*sizeof(long)); farread(help_file, label, num_label*2*sizeof(int)); /* finished! */ return (0); /* success */ } void end_help(void) { if (help_file != -1) { close(help_file); farmemfree((BYTE far *)topic_offset); help_file = -1; } }
void print_document(char *outfname, int (*msg_func)(int,int), int save_extraseg ) { static FCODE err_no_temp[] = "Unable to create temporary file.\n"; static FCODE err_no_out[] = "Unable to create output file.\n"; static FCODE err_badwrite[] = "Error writing temporary file.\n"; static FCODE err_badread[] = "Error reading temporary file.\nSystem may be corrupt!\nSave your image and re-start FRACTINT!\n"; PRINT_DOC_INFO info; int success = 0; int temp_file = -1; char far *msg = NULL; int dummy; /* to quiet compiler */ info.buffer = MK_FP(extraseg, 0); /* help_seek((long)sizeof(int)+sizeof(long)); Strange -- should be 8 -- CWM */ help_seek(8L); /* indeed it should - Bert */ dummy = read(help_file, (char *)&info.num_contents, sizeof(int)); dummy = read(help_file, (char *)&info.num_page, sizeof(int)); info.cnum = info.tnum = -1; info.content_pos = sizeof(long)+4*sizeof(int) + num_topic*sizeof(long) + num_label*2*sizeof(int); info.msg_func = msg_func; if ( msg_func != NULL ) msg_func(0, info.num_page); /* initialize */ if ( save_extraseg ) { if ( (temp_file=open(TEMP_FILE_NAME, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IREAD|S_IWRITE)) == -1 ) { msg = err_no_temp; goto ErrorAbort; } if ( farwrite(temp_file, info.buffer, PRINT_BUFFER_SIZE) != PRINT_BUFFER_SIZE ) { msg = err_badwrite; goto ErrorAbort; } } if ( (info.file = fopen(outfname, "wt")) == NULL ) { msg = err_no_out; goto ErrorAbort; } info.margin = PAGE_INDENT; info.start_of_line = 1; info.spaces = 0; success = process_document((PD_FUNC)print_doc_get_info, (PD_FUNC)print_doc_output, &info); fclose(info.file); if ( save_extraseg ) { if ( lseek(temp_file, 0L, SEEK_SET) != 0L ) { msg = err_badread; goto ErrorAbort; } if ( farread(temp_file, info.buffer, PRINT_BUFFER_SIZE) != PRINT_BUFFER_SIZE ) { msg = err_badread; goto ErrorAbort; } } ErrorAbort: if (temp_file != -1) { close(temp_file); remove(TEMP_FILE_NAME); temp_file = -1; } if ( msg != NULL ) { helptitle(); stopmsg(1, msg); } else if ( msg_func != NULL ) msg_func((success) ? -1 : -2, info.num_page ); }