PCTRLDATA getCtrlData(int ctrlId) { if(ID2Index(ctrlId) < TABLESIZE(ctrlData) ) { //return ctrlData + ID2Index(ctrlId); return &ctrlData[ID2Index(ctrlId)]; } return NULL; }
void init_ttymodes(int pn) { int speed_code, n; dump_ttymodes("init_ttymodes", pn); #ifdef UNIX if (pn==0) { fflush(stdout); # if USE_POSIX_TERMIOS || USE_TERMIO tcgetattr(0, &old_modes); speed_code = cfgetospeed(&old_modes); # else # if USE_SGTTY gtty(0, &old_modes); ioctl(0, TIOCGETC, &old_tchars); ioctl(0, TIOCGLTC, &old_ltchars); speed_code = old_modes.sg_ospeed; # endif # endif new_modes = old_modes; for (n = 0; n < TABLESIZE(speeds); n++) { if (speeds[n].name == speed_code) { tty_speed = speeds[n].code; break; } } } else { putchar(BEL); fflush(stdout); inflush(); new_modes = old_modes; sleep(2); } # if USE_POSIX_TERMIOS || USE_TERMIO new_modes.c_iflag = BRKINT | old_modes.c_iflag; new_modes.c_oflag &= ~tabs; # else /* USE_SGTTY */ new_modes.sg_flags = old_modes.sg_flags | CBREAK; # endif set_ttymodes(&new_modes); # ifdef HAVE_FCNTL_H # ifndef O_NDELAY # define O_NDELAY O_NONBLOCK /* O_NONBLOCK is POSIX */ # endif close(2); open("/dev/tty", O_RDWR|O_NDELAY); # endif #endif /* UNIX */ dump_ttymodes("...init_ttymodes", pn); }
/* * VT500 & up * * Test if the terminal can change the cursor's appearance */ static int tst_DECSCUSR(MENU_ARGS) { size_t n; vt_move(1, 1); for (n = 0; n < TABLESIZE(tbl_decscusr); ++n) { if (n != 0) holdit(); decscusr(tbl_decscusr[n].code); println(tbl_decscusr[n].text); } return MENU_HOLD; }
static int rpt_DECSCUSR(MENU_ARGS) { size_t n; vt_move(1, 1); for (n = 0; n < TABLESIZE(tbl_decscusr); ++n) { if (n != 0) holdit(); vt_clear(2); decscusr(tbl_decscusr[n].code); (void) any_decrqss(tbl_decscusr[n].text, " q"); } return MENU_HOLD; }
static void begin_elapsed(const char *txt) { ETRACE(("%d:%s", elapsed_sp, txt)); if (elapsed_sp + 1 < (int) TABLESIZE(elapsed_stack)) { BI_DATA *p = find_elapsed(txt + strlen(T_CALLED)); if (p != 0) { ELAPSED_DATA *q = p->data; elapsed_stack[elapsed_sp] = p; if (!(q->nesting_time++)) { (void) vl_elapsed(&(q->this_time), TRUE); } } } ++elapsed_sp; }
static char *pretty_html(int c) { char *src = LYKeycodeToString(c, TRUE); if (src != 0) { /* *INDENT-OFF* */ static const struct { int code; const char *name; } table[] = { { '<', "<" }, { '>', ">" }, { '"', """ }, { '&', "&" } }; /* *INDENT-ON* */ static char buf[30]; char *dst = buf; int adj = 0; unsigned n; BOOLEAN found; while ((c = *src++) != 0) { found = FALSE; for (n = 0; n < TABLESIZE(table); n++) { if (c == table[n].code) { found = TRUE; LYStrNCpy(dst, table[n].name, sizeof(dst) - 1); adj += (int) strlen(dst) - 1; dst += (int) strlen(dst); break; } } if (!found) { *dst++ = (char) c; } } adj -= (int) (dst - buf) - PRETTY_LEN; while (adj-- > 0) *dst++ = ' '; *dst = 0; return buf; } return 0; }
static int rpt_DECSCUSR(MENU_ARGS) { size_t n; vt_move(1, 1); for (n = 0; n < TABLESIZE(tbl_decscusr); ++n) { char expected[10]; if (n != 0) holdit(); vt_clear(2); decscusr(tbl_decscusr[n].code); sprintf(expected, "%d", tbl_decscusr[n].code ? tbl_decscusr[n].code : 1); (void) any_decrqss2(tbl_decscusr[n].text, " q", expected); } return MENU_HOLD; }
static void end_elapsed(void) { if (elapsed_sp > 0) { if (--elapsed_sp < (int) TABLESIZE(elapsed_stack)) { BI_DATA *p = elapsed_stack[elapsed_sp]; ETRACE(("%d:%s::%s\n", elapsed_sp, T_RETURN, p->bi_key)); if (p != 0) { ELAPSED_DATA *q = p->data; if (!(--(q->nesting_time))) { q->total_time += vl_elapsed(&(q->this_time), FALSE); q->total_calls += 1; } } } } }
int ttwatchfd(int fd, WATCHTYPE type, long *idp) { #if USE_SELECT *idp = (long) fd; if (fd > watchfd_maxfd) watchfd_maxfd = fd; if (type & WATCHREAD) FD_SET(fd, &watchfd_read_fds); if (type & WATCHWRITE) FD_SET(fd, &watchfd_write_fds); #else /* USE_SELECT */ #if USE_POLL int n; for (n = 0; n < watch_max; n++) { if (watch_fds[n].fd == fd) break; } if (n < (int) TABLESIZE(watch_fds) - 1) { *idp = (long) fd; if (n >= watch_max) watch_max = n + 1; watch_fds[n].fd = fd; if (type & WATCHREAD) watch_fds[n].events |= POLLIN; if (type & WATCHWRITE) watch_fds[n].events |= POLLOUT; } else { return FALSE; } #else #ifdef __BEOS__ if (fd < (int) sizeof(watch_fds)) { *idp = (long) fd; if (fd > watch_max) watch_max = fd; watch_fds[fd] |= type; } #endif /* __BEOS__ */ #endif /* USE_POLL */ #endif /* USE_SELECT */ return TRUE; }
static void usage(void) { static const char *tbl[] = { "Usage: dtd_util [options]", "", "Options:", " -c generate C-source" " -h generate C-header" " -l load", " -o filename specify output (default: stdout)", " -s strict (HTML DTD 0)", " -t tagsoup (HTML DTD 1)", }; unsigned n; for (n = 0; n < TABLESIZE(tbl); ++n) { fprintf(stderr, "%s\n", tbl[n]); } exit(EXIT_FAILURE); }
static void usage(void) { static const char *tbl[] = { "Usage: makeuctb [parameters]", "", "Utility to convert .tbl into .h files for Lynx compilation.", "", "Parameters (all are optional):", " 1: the input file (normally {filename}.tbl, but \"-\" for stdin", " 2: the output file (normally {filename}.tbl but \"-\" for stdout", " 3: charset mime name", " 4: charset display name" }; unsigned n; for (n = 0; n < TABLESIZE(tbl); n++) { fprintf(stderr, "%s\n", tbl[n]); }; done(EX_USAGE); }
BOOLEAN editor_can_position(void) { char *value; HTList *p = positionable_editor; static const char *table[] = { #ifdef VMS "sedt", "SEDT" #else "emacs", "jed", "jmacs", "joe", "jove", "jpico", "jstar", "nano", "pico", "rjoe", "vi" #endif }; unsigned n; for (n = 0; n < TABLESIZE(table); n++) { if (strstr(editor, table[n]) != 0) { return TRUE; } } if (positionable_editor != NULL) { while ((value = (char *) HTList_nextObject(p)) != NULL) { if (strcmp(editor, value) == 0) { return TRUE; } } } return FALSE; }
static SGMLContent s2SGMLContent(const char *value) { static SGMLContent table[] = { SGML_EMPTY, SGML_LITTERAL, SGML_CDATA, SGML_SCRIPT, SGML_RCDATA, SGML_MIXED, SGML_ELEMENT, SGML_PCDATA }; unsigned n; SGMLContent result = SGML_EMPTY; for (n = 0; n < TABLESIZE(table); ++n) { if (!strcmp(SGMLContent2s(table[n]), value)) { result = table[n]; break; } } return result; }
void options_t::reset() { options_t *o = this; memset(o, 0, sizeof(*o)); o->crp.reset(); o->cmd = CMD_NONE; o->method = M_NONE; o->level = 10; o->filter = FT_NONE; o->backup = -1; o->overlay = -1; o->preserve_mode = true; o->preserve_ownership = true; o->preserve_timestamp = true; o->console = CON_FILE; #if defined(__DJGPP__) o->console = CON_INIT; #elif (USE_SCREEN_WIN32) o->console = CON_INIT; #elif 1 && defined(__linux__) o->console = CON_INIT; #endif o->verbose = 2; o->win32_pe.compress_exports = 1; o->win32_pe.compress_icons = 2; o->win32_pe.compress_resources = -1; for (unsigned i = 0; i < TABLESIZE(o->win32_pe.compress_rt); i++) o->win32_pe.compress_rt[i] = -1; o->win32_pe.compress_rt[24] = false; // 24 == RT_MANIFEST o->win32_pe.strip_relocs = -1; o->win32_pe.keep_resource = ""; }
void print_usage(int code) { static const char *const options[] = { "-h display [Help] on startup", "-c command execute the given ex-style command", #if OPT_EVAL || OPT_DEBUGMACROS "-D trace macros into [Trace] buffer", #endif "-e edit in \"noview\" mode -- changes permitted", #if OPT_SELECTIONS&&OPT_FILTER "-F run syntax filter only, write to stdout", #endif "-I use vileinit.rc to initialize", #if OPT_ENCRYPT "-k cryptkey for encrypted files", #endif "-R edit files \"read-only\" -- no writes permitted", #if OPT_TAGS # if DISP_X11 /* because -title is predefined */ "-T tagname look up a tag", # else "-t tagname look up a tag", # endif #endif "-v edit in \"view\" mode -- no changes permitted", "-V for version info", "use @cmdfile to run cmdfile as commands (this suppresses " DFT_STARTUP_FILE ")", #if SYS_VMS "", "VMS-specific:", "-80 80-column mode", "-132 132-column mode", #endif #if DISP_BORLAND "", "DOS-specific:", "-2 25-line mode", "-4 43-line mode", "-5 50-line mode", "-6 60-line mode", "(see help file for more screen resolutions)", #endif #if SYS_WINNT "", "Win32-specific:", # if DISP_NTWIN "-fn fontspec change font", "-geometry CxR set initial size to R rows and C columns", "-i set current-directory to pathname of file-parameter", # if defined(VILE_OLE) "-Oa invoke as an OLE Automation server", "-Or register ole automation interface and exit", "-Ou unregister ole automation interface and exit", "-invisible OLE Automation server does not initially show a window", "-multiple multiple instances of OLE Automation server permitted", # endif # endif /* DISP_NTWIN */ # if DISP_NTCONS "-console if stdin is not a tty, start editor in a new console", # endif #endif /* SYS_WINNT */ #if DISP_X11 "", "X11-specific:", "-class name change class name for X resources (default XVile)", "-name name change program name for X resources", "-title name set name in title bar", "-fg color change foreground color", "-bg color change background color", "-fn fontname change font", "-fork spawn xvile immediately on startup", "+fork force xvile to not spawn on startup", "-display displayname to change the default display", "-rv for reverse video", "-geometry CxR set initial size to R rows and C columns", "-xrm resource change an xvile resource", "-leftbar put scrollbar(s) on left", "-rightbar put scrollbar(s) on right (default)", #endif /* DISP_X11 */ "", "Obsolete:", "-g NNN or simply +NNN to go to line NNN", "-s string or +/string to search for \"string\"", }; term.clean(TRUE); #if DISP_NTWIN gui_usage(prog_arg, options, TABLESIZE(options)); #else fflush(stdout); (void) fprintf(stderr, "usage: %s [-flags] [@cmdfile] files...\n", prog_arg); { unsigned j; for (j = 0; j < TABLESIZE(options); j++) { char *colon = strrchr(options[j], ':'); if (colon != 0 && colon[1] == EOS) { (void) fprintf(stderr, "%s\n", options[j]); } else { (void) fprintf(stderr, "\t%s\n", options[j]); } } } #endif ExitProgram(code); }
{273, LYE_ENTER}, #endif {-1, LYE_UNKNOWN} }; #endif /* USE_ALT_BINDINGS */ LYEditConfig LYLineEditors[] = { {"Default Binding", initDefaultEditor, DefaultEditBinding}, #ifdef USE_ALT_BINDINGS {"Alternate Bindings", initBetterEditor, BetterEditBinding}, {"Bash-like Bindings", initBashlikeEditor, BashlikeEditBinding}, #endif }; const char *LYEditorNames[TABLESIZE(LYLineEditors) + 1]; /* * Add the URL (relative to helpfilepath) used for context-dependent * help on form field editing. * * The order must correspond to that of LYLineditNames. */ const char *LYLineeditHelpURLs[] = { EDIT_HELP, #ifdef USE_ALT_BINDINGS ALT_EDIT_HELP, BASHLIKE_EDIT_HELP, #endif (char *) 0
// This function displays brief command line help to the user. // Parameters: // char* argv[] : Pointer to command line parameter pointer array // void PrintProgramHelp (void) { static const char *help[] = { "C(++) Beautifier " VERSION, "", "Program Was Written By Steven De Toni, December 1995", "Modified/revised by Thomas E. Dickey 1996-2003,2004", "All Parts Of This Program Are Freely Distributable.", "", "Usage: bcpp [Parameters] [Input File Name] [Output File Name]", "", "Options:", "", "[-bcl] [-bnl] [-cc <num>] [-f <num>] [-fi <string>] [-fnc <string>]", "[-fo <string>] [-h] [-i <num>] [-lg]", "[-na] [-nb] [-nbbi] [-nbi] [-nc] [-nkcwc] [-nlcnc] [-no] [-nq]", "[-qb] [-s] [-t]", "[-ya] [-yb] [-ybbi] [-ybi] [-ykcwc] [-ylcnc] [-yo] [-yq]", "[<string>] [<string>]", "", "[] = Optional <> = Parameter Requirement", "", "* Support For I/O Redirection Is Provided *", }; unsigned n; for (n = 0; n < TABLESIZE(help); n++) verbose("%s\n", help[n]); if (prompt("More Detail")) { static const char *details[] = { "-bcl : Open braces on code line", "-bnl : Open braces on new line", "-cc <num> : Column to align comments with code", "-f <num> : Function line spacing", "-fi <string> : Input file name", "-fnc <string> : Load custom configuration file", "-fo <string> : Output file name", "-h or -? : This help message", "-i <num> : Indent space length", "-lg : Leave graphic chars", "-nc <num> : Column to align comments with no code", "-qb <num> : Define internal queue buffer size", "-s : Use spaces in indenting", "-t : Use tabs in indenting", "-tbcl : Top-level open braces on code line", "-tbnl : Top-level open braces on new line", "", "Options beginning with -n or -y disable/enable functions:", " a : Remove non-ASCII chars", " b : Backup input file with .bac extension", " bbi : Indent both braces of a block", " bi : Indent trailing brace of block", " kcwc : Keep comments with Code", " lcnc : Leave comments with NoCode", " o : Program output", " q : Change non-ASCII chars in quotes to octal", }; for (n = 0; n < TABLESIZE(details); n++) verbose("%s\n", details[n]); } }
SVS_AUTOSORT, 10, 10, 320, 150, IDC_SCROLLVIEW, "", 0 }, }; static DLGTEMPLATE DlgBook = { WS_BORDER | WS_CAPTION, WS_EX_NONE, 0, 0, 350, 200, CAPTION, 0, 0, TABLESIZE(CtrlBook), NULL, 0 }; int MiniGUIMain (int argc, const char* argv[]) { #ifdef _MGRM_PROCESSES JoinLayer(NAME_DEF_LAYER , "scrollview" , 0 , 0); #endif DlgBook.controls = CtrlBook; DialogBoxIndirectParam (&DlgBook, HWND_DESKTOP, BookProc, 0L); return 0; }
static int BookProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam) { switch (message) { case MSG_INITDIALOG: { SVITEMINFO svii; static int i = 0; hScrollView = GetDlgItem (hDlg, IDC_SCROLLVIEW); SetWindowBkColor (hScrollView, PIXEL_lightwhite); SendMessage (hScrollView, SVM_SETITEMCMP, 0, (LPARAM)myCmpItem); SendMessage (hScrollView, SVM_SETITEMDRAW, 0, (LPARAM)myDrawItem); for (i = 0; i < TABLESIZE(people); i++) { svii.nItemHeight = 32; svii.addData = (DWORD)people[i]; svii.nItem = i; SendMessage (hScrollView, SVM_ADDITEM, 0, (LPARAM)&svii); SendMessage (hScrollView, SVM_SETITEMADDDATA, i, (DWORD)people[i]); } break; } case MSG_COMMAND: { int id = LOWORD (wParam); int code = HIWORD (wParam); switch (id) { case IDC_SCROLLVIEW: if (code == SVN_CLICKED) { int sel; const char *info; sel = SendMessage (hScrollView, SVM_GETCURSEL, 0, 0); info = (const char *)SendMessage (hScrollView, SVM_GETITEMADDDATA, sel, 0); } break; } break; } case MSG_KEYDOWN: if (wParam == SCANCODE_REMOVE) { int idx = SendMessage (hScrollView, SVM_GETCURSEL, 0, 0); SendMessage (hScrollView, SVM_DELITEM, idx, 0); SendMessage (hScrollView, SVM_SETCURSEL, idx, 0); return 0; } break; case MSG_CLOSE: { EndDialog (hDlg, 0); return 0; } } return DefaultDialogProc (hDlg, message, wParam, lParam); }
static int decode_key_event(INPUT_RECORD * irp) { DWORD state = irp->Event.KeyEvent.dwControlKeyState; int key; int i; if (!irp->Event.KeyEvent.bKeyDown) return (NOKYMAP); TRACE(("decode_key_event(%c=%02x, Virtual=%#x,%#x, State=%#x)\n", irp->Event.KeyEvent.uChar.AsciiChar, irp->Event.KeyEvent.uChar.AsciiChar, irp->Event.KeyEvent.wVirtualKeyCode, irp->Event.KeyEvent.wVirtualScanCode, irp->Event.KeyEvent.dwControlKeyState)); if ((key = (UCHAR) irp->Event.KeyEvent.uChar.AsciiChar) != 0) { if (isCntrl(key)) { DWORD cstate = state & ~(LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED); if (isModified(cstate)) key = modified_key(key, cstate); } return key; } key = irp->Event.KeyEvent.wVirtualKeyCode; if ((state & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) != 0 && (state & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED | SHIFT_PRESSED)) == state) { /* * Control-shift-6 is control/^, control/~ or control/`. */ if (key == '6' || key == '^' || key == '\036') { TRACE(("...decode_key_event ^^\n")); return '\036'; } } key = NOKYMAP; for (i = 0; i < TABLESIZE(keyxlate); i++) { if (keyxlate[i].windows == irp->Event.KeyEvent.wVirtualKeyCode) { /* * Add the modifiers that we recognize. Specifically, we don't * care about ENHANCED_KEY, since we already have portable * pageup/pagedown and arrow key bindings that would be lost if we * used the Win32-only definition. */ if (isModified(state)) { key = modified_key(keyxlate[i].vile, state); if (keyxlate[i].vile == '2') { if ((key & mod_CTRL) && ((key & mod_ALT) == 0)) { /* either ^2 or ^@, => nul char */ key = 0; } else if ((key & mod_SHIFT) && ((key & (mod_ALT | mod_CTRL)) == 0)) { /* * this will be mapped to '@' if we let Windows do * the translation */ key = NOKYMAP; } } } else key = keyxlate[i].vile; TRACE(("... %#x -> %#x\n", irp->Event.KeyEvent.wVirtualKeyCode, key)); break; } } return key; }
int ColorSelDialog (HWND hWnd, int x, int y, int w, int h, PCOLORDATA pClrData) { SCOLORDIA scldata; CTRLDATA ColorCtrl [] = { { "static", WS_CHILD | WS_VISIBLE | SS_GRAYFRAME, 10, 10, 240, 240, IDC_SPACE, "", 0}, { "static", WS_CHILD | WS_VISIBLE | SS_GRAYFRAME, 255, 10, 30, 240, IDC_YSPACE, "", 0}, { "static", WS_CHILD | WS_VISIBLE | SS_GRAYFRAME, 10, 255, 35, 40, IDC_COLOR, "", 0}, { "static", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 35, 255, 20, 15, IDC_STATIC , "Y :", 0}, { "static", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 35, 275, 20, 15, IDC_STATIC , "U :", 0}, { "static", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 35, 295, 20, 15, IDC_STATIC , "V :", 0}, { "static", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 105, 255, 20, 15, IDC_STATIC , "R :", 0}, { "static", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 105, 275, 20, 15, IDC_STATIC , "G :", 0}, { "static", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 105, 295, 20, 15, IDC_STATIC , "B :", 0}, { "sledit", WS_CHILD | WS_VISIBLE, 95, 255, 25, 15, IDC_VALUE_Y , "180", 0}, { "sledit", WS_CHILD | WS_VISIBLE, 95, 275, 25, 15, IDC_VALUE_U , "128", 0}, { "sledit", WS_CHILD | WS_VISIBLE, 95, 295, 25, 15, IDC_VALUE_V , "128", 0}, { "sledit", WS_CHILD | WS_VISIBLE, 165, 255, 25, 15, IDC_VALUE_R , "64", 0}, { "sledit", WS_CHILD | WS_VISIBLE, 165, 275, 25, 15, IDC_VALUE_G , "128", 0}, { "sledit", WS_CHILD | WS_VISIBLE, 165, 295, 25, 15, IDC_VALUE_B , "128", 0}, { "button", WS_CHILD | WS_VISIBLE, 200, 255, 80, 30, IDC_OK, NULL, 0, WS_EX_TRANSPARENT}, { "button", WS_CHILD | WS_VISIBLE , 200, 290, 80, 30, IDC_CANCEL, NULL, 0 ,WS_EX_TRANSPARENT} }; DLGTEMPLATE ColorDlg = { #ifdef _FLAT_WINDOW_STYLE WS_BORDER | WS_CAPTION | WS_MINIMIZEBOX, WS_EX_NONE, #else WS_BORDER | WS_CAPTION, WS_EX_NONE, #endif 0, 0, 0, 0, NULL, 0, 0, TABLESIZE(ColorCtrl), NULL }; ColorDlg.x = x; ColorDlg.y = y; ColorDlg.w = w; ColorDlg.h = h; scldata.pclr = pClrData; InitColorCtrl (ColorCtrl, x, y, w, h, &scldata); ColorCtrl [15].caption = GetSysText(IDS_MGST_OK); ColorCtrl [16].caption = GetSysText(IDS_MGST_CANCEL); ColorDlg.caption = GetSysText(IDS_MGST_COLORSEL); ColorDlg.controls = ColorCtrl; return DialogBoxIndirectParam (&ColorDlg, hWnd, ColorDlgProc, (LPARAM)(&scldata)); }
*/ #include <src0_HTMLDTD.h> #include <src1_HTMLDTD.h> /* Dummy space, will be filled with the contents of either tags_table1 or tags_table0 on calling HTSwitchDTD - kw */ static HTTag tags[HTML_ALL_ELEMENTS]; const SGML_dtd HTML_dtd = { tags, HTML_ELEMENTS, entities, /* probably unused */ TABLESIZE(entities), }; /* This function fills the "tags" part of the HTML_dtd structure with what we want to use, either tags_table0 or tags_table1. Note that it has to be called at least once before HTML_dtd is used, otherwise the HTML_dtd contents will be invalid! This could be coded in a way that would make an initialisation call unnecessary, but my C knowledge is limited and I didn't want to list the whole tags_table1 table twice... - kw */ void HTSwitchDTD(int new_flag) { if (TRACE) CTRACE((tfp, "HTMLDTD: Copying %s DTD element info of size %d, %d * %d\n", new_flag ? "strict" : "tagsoup",
void PackArmPe::pack(OutputFile *fo) { // FIXME: we need to think about better support for --exact if (opt->exact) throwCantPackExact(); const unsigned objs = ih.objects; isection = new pe_section_t[objs]; fi->seek(pe_offset+sizeof(ih),SEEK_SET); fi->readx(isection,sizeof(pe_section_t)*objs); rvamin = isection[0].vaddr; infoHeader("[Processing %s, format %s, %d sections]", fn_basename(fi->getName()), getName(), objs); // check the PE header // FIXME: add more checks if (!opt->force && ( (ih.cpu != 0x1c0 && ih.cpu != 0x1c2) || (ih.opthdrsize != 0xe0) || ((ih.flags & EXECUTABLE) == 0) || (ih.subsystem != 9) || (ih.entry == 0 /*&& !isdll*/) || (ih.ddirsentries != 16) // || IDSIZE(PEDIR_EXCEPTION) // is this used on arm? // || IDSIZE(PEDIR_COPYRIGHT) )) throwCantPack("unexpected value in PE header (try --force)"); if (IDSIZE(PEDIR_SEC)) IDSIZE(PEDIR_SEC) = IDADDR(PEDIR_SEC) = 0; // throwCantPack("compressing certificate info is not supported"); if (IDSIZE(PEDIR_COMRT)) throwCantPack(".NET files (win32/net) are not yet supported"); if (isdll) opt->win32_pe.strip_relocs = false; else if (opt->win32_pe.strip_relocs < 0) opt->win32_pe.strip_relocs = (ih.imagebase >= 0x10000); if (opt->win32_pe.strip_relocs) { if (ih.imagebase < 0x10000) throwCantPack("--strip-relocs is not allowed when imagebase < 0x10000"); else ih.flags |= RELOCS_STRIPPED; } if (memcmp(isection[0].name,"UPX",3) == 0) throwAlreadyPackedByUPX(); if (!opt->force && IDSIZE(15)) throwCantPack("file is possibly packed/protected (try --force)"); if (ih.entry && ih.entry < rvamin) throwCantPack("run a virus scanner on this file!"); if (!opt->force && ih.subsystem == 1) throwCantPack("subsystem 'native' is not supported (try --force)"); if (ih.filealign < 0x200) throwCantPack("filealign < 0x200 is not yet supported"); handleStub(fi,fo,pe_offset); const unsigned usize = ih.imagesize; const unsigned xtrasize = UPX_MAX(ih.datasize, 65536u) + IDSIZE(PEDIR_IMPORT) + IDSIZE(PEDIR_BOUNDIM) + IDSIZE(PEDIR_IAT) + IDSIZE(PEDIR_DELAYIMP) + IDSIZE(PEDIR_RELOC); ibuf.alloc(usize + xtrasize); // BOUND IMPORT support. FIXME: is this ok? fi->seek(0,SEEK_SET); fi->readx(ibuf,isection[0].rawdataptr); Interval holes(ibuf); unsigned ic,jc,overlaystart = 0; ibuf.clear(0, usize); for (ic = jc = 0; ic < objs; ic++) { if (isection[ic].rawdataptr && overlaystart < isection[ic].rawdataptr + isection[ic].size) overlaystart = ALIGN_UP(isection[ic].rawdataptr + isection[ic].size,ih.filealign); if (isection[ic].vsize == 0) isection[ic].vsize = isection[ic].size; if ((isection[ic].flags & PEFL_BSS) || isection[ic].rawdataptr == 0 || (isection[ic].flags & PEFL_INFO)) { holes.add(isection[ic].vaddr,isection[ic].vsize); continue; } if (isection[ic].vaddr + isection[ic].size > usize) throwCantPack("section size problem"); if (((isection[ic].flags & (PEFL_WRITE|PEFL_SHARED)) == (PEFL_WRITE|PEFL_SHARED))) if (!opt->force) throwCantPack("writable shared sections not supported (try --force)"); if (jc && isection[ic].rawdataptr - jc > ih.filealign) throwCantPack("superfluous data between sections"); fi->seek(isection[ic].rawdataptr,SEEK_SET); jc = isection[ic].size; if (jc > isection[ic].vsize) jc = isection[ic].vsize; if (isection[ic].vsize == 0) // hack for some tricky programs - may this break other progs? jc = isection[ic].vsize = isection[ic].size; if (isection[ic].vaddr + jc > ibuf.getSize()) throwInternalError("buffer too small 1"); fi->readx(ibuf + isection[ic].vaddr,jc); jc += isection[ic].rawdataptr; } // check for NeoLite if (find(ibuf + ih.entry, 64+7, "NeoLite", 7) >= 0) throwCantPack("file is already compressed with another packer"); unsigned overlay = file_size - stripDebug(overlaystart); if (overlay >= (unsigned) file_size) { #if 0 if (overlay < file_size + ih.filealign) overlay = 0; else if (!opt->force) throwNotCompressible("overlay problem (try --force)"); #endif overlay = 0; } checkOverlay(overlay); Resource res; Interval tlsiv(ibuf); Export xport((char*)(unsigned char*)ibuf); const unsigned dllstrings = processImports(); processTls(&tlsiv); // call before processRelocs!! processResources(&res); processExports(&xport); processRelocs(); //OutputFile::dump("x1", ibuf, usize); // some checks for broken linkers - disable filter if necessary bool allow_filter = true; if (ih.codebase == ih.database || ih.codebase + ih.codesize > ih.imagesize || (isection[virta2objnum(ih.codebase,isection,objs)].flags & PEFL_CODE) == 0) allow_filter = false; const unsigned oam1 = ih.objectalign - 1; // FIXME: disabled: the uncompressor would not allocate enough memory //objs = tryremove(IDADDR(PEDIR_RELOC),objs); // FIXME: if the last object has a bss then this won't work // newvsize = (isection[objs-1].vaddr + isection[objs-1].size + oam1) &~ oam1; // temporary solution: unsigned newvsize = (isection[objs-1].vaddr + isection[objs-1].vsize + oam1) &~ oam1; //fprintf(stderr,"newvsize=%x objs=%d\n",newvsize,objs); if (newvsize + soimport + sorelocs > ibuf.getSize()) throwInternalError("buffer too small 2"); memcpy(ibuf+newvsize,oimport,soimport); memcpy(ibuf+newvsize+soimport,orelocs,sorelocs); cimports = newvsize - rvamin; // rva of preprocessed imports crelocs = cimports + soimport; // rva of preprocessed fixups ph.u_len = newvsize + soimport + sorelocs; // some extra data for uncompression support unsigned s = 0; upx_byte * const p1 = ibuf + ph.u_len; memcpy(p1 + s,&ih,sizeof (ih)); s += sizeof (ih); memcpy(p1 + s,isection,ih.objects * sizeof(*isection)); s += ih.objects * sizeof(*isection); if (soimport) { set_le32(p1 + s,cimports); set_le32(p1 + s + 4,dllstrings); s += 8; } if (sorelocs) { set_le32(p1 + s,crelocs); p1[s + 4] = (unsigned char) (big_relocs & 6); s += 5; } if (soresources) { set_le16(p1 + s,icondir_count); s += 2; } // end of extra data set_le32(p1 + s,ptr_diff(p1,ibuf) - rvamin); s += 4; ph.u_len += s; obuf.allocForCompression(ph.u_len); // prepare packheader ph.u_len -= rvamin; // prepare filter Filter ft(ph.level); ft.buf_len = ih.codesize; ft.addvalue = ih.codebase - rvamin; // compress int filter_strategy = allow_filter ? 0 : -3; // disable filters for files with broken headers if (ih.codebase + ih.codesize > ph.u_len) { ft.buf_len = 1; filter_strategy = -3; } // limit stack size needed for runtime decompression upx_compress_config_t cconf; cconf.reset(); cconf.conf_lzma.max_num_probs = 1846 + (768 << 4); // ushort: ~28 KiB stack compressWithFilters(&ft, 2048, &cconf, filter_strategy, ih.codebase, rvamin, 0, NULL, 0); // info: see buildLoader() newvsize = (ph.u_len + rvamin + ph.overlap_overhead + oam1) &~ oam1; /* if (tlsindex && ((newvsize - ph.c_len - 1024 + oam1) &~ oam1) > tlsindex + 4) tlsindex = 0; */ const unsigned lsize = getLoaderSize(); int identsize = 0; const unsigned codesize = getLoaderSection("IDENTSTR",&identsize); assert(identsize > 0); getLoaderSection("UPX1HEAD",(int*)&ic); identsize += ic; pe_section_t osection[4]; // section 0 : bss // 1 : [ident + header] + packed_data + unpacker + tls // 2 : not compressed data // 3 : resource data -- wince 5 needs a new section for this // identsplit - number of ident + (upx header) bytes to put into the PE header int identsplit = pe_offset + sizeof(osection) + sizeof(oh); if ((identsplit & 0x1ff) == 0) identsplit = 0; else if (((identsplit + identsize) ^ identsplit) < 0x200) identsplit = identsize; else identsplit = ALIGN_GAP(identsplit, 0x200); ic = identsize - identsplit; const unsigned c_len = ((ph.c_len + ic) & 15) == 0 ? ph.c_len : ph.c_len + 16 - ((ph.c_len + ic) & 15); obuf.clear(ph.c_len, c_len - ph.c_len); const unsigned s1size = ALIGN_UP(ic + c_len + codesize,4u) + sotls; const unsigned s1addr = (newvsize - (ic + c_len) + oam1) &~ oam1; const unsigned ncsection = (s1addr + s1size + oam1) &~ oam1; const unsigned upxsection = s1addr + ic + c_len; Reloc rel(1024); // new relocations are put here static const char* symbols_to_relocate[] = { "ONAM", "BIMP", "BREL", "FIBE", "FIBS", "ENTR", "DST0", "SRC0" }; for (unsigned s2r = 0; s2r < TABLESIZE(symbols_to_relocate); s2r++) { unsigned off = linker->getSymbolOffset(symbols_to_relocate[s2r]); if (off != 0xdeaddead) rel.add(off + upxsection, 3); } // new PE header memcpy(&oh,&ih,sizeof(oh)); oh.filealign = 0x200; // identsplit depends on this memset(osection,0,sizeof(osection)); oh.entry = upxsection; oh.objects = 4; oh.chksum = 0; // fill the data directory ODADDR(PEDIR_DEBUG) = 0; ODSIZE(PEDIR_DEBUG) = 0; ODADDR(PEDIR_IAT) = 0; ODSIZE(PEDIR_IAT) = 0; ODADDR(PEDIR_BOUNDIM) = 0; ODSIZE(PEDIR_BOUNDIM) = 0; // tls is put into section 1 ic = s1addr + s1size - sotls; super::processTls(&rel,&tlsiv,ic); ODADDR(PEDIR_TLS) = sotls ? ic : 0; ODSIZE(PEDIR_TLS) = sotls ? 0x18 : 0; ic += sotls; // these are put into section 2 ic = ncsection; // wince wants relocation data at the beginning of a section processRelocs(&rel); ODADDR(PEDIR_RELOC) = soxrelocs ? ic : 0; ODSIZE(PEDIR_RELOC) = soxrelocs; ic += soxrelocs; processImports(ic, linker->getSymbolOffset("IATT") + upxsection); ODADDR(PEDIR_IMPORT) = ic; ODSIZE(PEDIR_IMPORT) = soimpdlls; ic += soimpdlls; processExports(&xport,ic); ODADDR(PEDIR_EXPORT) = soexport ? ic : 0; ODSIZE(PEDIR_EXPORT) = soexport; if (!isdll && opt->win32_pe.compress_exports) { ODADDR(PEDIR_EXPORT) = IDADDR(PEDIR_EXPORT); ODSIZE(PEDIR_EXPORT) = IDSIZE(PEDIR_EXPORT); } ic += soexport; ic = (ic + oam1) &~ oam1; const unsigned res_start = ic; if (soresources) processResources(&res,ic); ODADDR(PEDIR_RESOURCE) = soresources ? ic : 0; ODSIZE(PEDIR_RESOURCE) = soresources; ic += soresources; const unsigned onam = ncsection + soxrelocs + ih.imagebase; linker->defineSymbol("start_of_dll_names", onam); linker->defineSymbol("start_of_imports", ih.imagebase + rvamin + cimports); linker->defineSymbol("start_of_relocs", crelocs + rvamin + ih.imagebase); linker->defineSymbol("filter_buffer_end", ih.imagebase + ih.codebase + ih.codesize); linker->defineSymbol("filter_buffer_start", ih.imagebase + ih.codebase); linker->defineSymbol("original_entry", ih.entry + ih.imagebase); linker->defineSymbol("uncompressed_length", ph.u_len); linker->defineSymbol("start_of_uncompressed", ih.imagebase + rvamin); linker->defineSymbol("compressed_length", ph.c_len); linker->defineSymbol("start_of_compressed", ih.imagebase + s1addr + identsize - identsplit); defineDecompressorSymbols(); relocateLoader(); MemBuffer loader(lsize); memcpy(loader, getLoader(), lsize); patchPackHeader(loader, lsize); // this is computed here, because soxrelocs changes some lines above const unsigned ncsize = soxrelocs + soimpdlls + soexport; const unsigned fam1 = oh.filealign - 1; // fill the sections strcpy(osection[0].name,"UPX0"); strcpy(osection[1].name,"UPX1"); strcpy(osection[2].name, "UPX2"); strcpy(osection[3].name, ".rsrc"); osection[0].vaddr = rvamin; osection[1].vaddr = s1addr; osection[2].vaddr = ncsection; osection[3].vaddr = res_start; osection[0].size = 0; osection[1].size = (s1size + fam1) &~ fam1; osection[2].size = (ncsize + fam1) &~ fam1; osection[3].size = (soresources + fam1) &~ fam1; osection[0].vsize = osection[1].vaddr - osection[0].vaddr; //osection[1].vsize = (osection[1].size + oam1) &~ oam1; //osection[2].vsize = (osection[2].size + oam1) &~ oam1; osection[1].vsize = osection[1].size; osection[2].vsize = osection[2].size; osection[3].vsize = osection[3].size; osection[0].rawdataptr = 0; osection[1].rawdataptr = (pe_offset + sizeof(oh) + sizeof(osection) + fam1) &~ fam1; osection[2].rawdataptr = osection[1].rawdataptr + osection[1].size; osection[3].rawdataptr = osection[2].rawdataptr + osection[2].size; osection[0].flags = (unsigned) (PEFL_BSS|PEFL_EXEC|PEFL_WRITE|PEFL_READ); osection[1].flags = (unsigned) (PEFL_DATA|PEFL_EXEC|PEFL_WRITE|PEFL_READ); osection[2].flags = (unsigned) (PEFL_DATA|PEFL_READ); osection[3].flags = (unsigned) (PEFL_DATA|PEFL_READ); oh.imagesize = (osection[3].vaddr + osection[3].vsize + oam1) &~ oam1; oh.bsssize = osection[0].vsize; oh.datasize = osection[2].vsize + osection[3].vsize; oh.database = osection[2].vaddr; oh.codesize = osection[1].vsize; oh.codebase = osection[1].vaddr; oh.headersize = osection[1].rawdataptr; if (rvamin < osection[0].rawdataptr) throwCantPack("object alignment too small"); if (opt->win32_pe.strip_relocs && !isdll) oh.flags |= RELOCS_STRIPPED; //for (ic = 0; ic < oh.filealign; ic += 4) // set_le32(ibuf + ic,get_le32("UPX ")); ibuf.clear(0, oh.filealign); info("Image size change: %u -> %u KiB", ih.imagesize / 1024, oh.imagesize / 1024); infoHeader("[Writing compressed file]"); if (soresources == 0) { oh.objects = 3; memset(&osection[3], 0, sizeof(osection[3])); } // write loader + compressed file fo->write(&oh,sizeof(oh)); fo->write(osection,sizeof(osection)); // some alignment if (identsplit == identsize) { unsigned n = osection[1].rawdataptr - fo->getBytesWritten() - identsize; assert(n <= oh.filealign); fo->write(ibuf, n); } fo->write(loader + codesize,identsize); infoWriting("loader", fo->getBytesWritten()); fo->write(obuf,c_len); infoWriting("compressed data", c_len); fo->write(loader,codesize); if (opt->debug.dump_stub_loader) OutputFile::dump(opt->debug.dump_stub_loader, loader, codesize); if ((ic = fo->getBytesWritten() & 3) != 0) fo->write(ibuf,4 - ic); fo->write(otls,sotls); if ((ic = fo->getBytesWritten() & fam1) != 0) fo->write(ibuf,oh.filealign - ic); fo->write(oxrelocs,soxrelocs); fo->write(oimpdlls,soimpdlls); fo->write(oexport,soexport); if ((ic = fo->getBytesWritten() & fam1) != 0) fo->write(ibuf,oh.filealign - ic); fo->write(oresources,soresources); if ((ic = fo->getBytesWritten() & fam1) != 0) fo->write(ibuf,oh.filealign - ic); #if 0 printf("%-13s: program hdr : %8ld bytes\n", getName(), (long) sizeof(oh)); printf("%-13s: sections : %8ld bytes\n", getName(), (long) sizeof(osection)); printf("%-13s: ident : %8ld bytes\n", getName(), (long) identsize); printf("%-13s: compressed : %8ld bytes\n", getName(), (long) c_len); printf("%-13s: decompressor : %8ld bytes\n", getName(), (long) codesize); printf("%-13s: tls : %8ld bytes\n", getName(), (long) sotls); printf("%-13s: resources : %8ld bytes\n", getName(), (long) soresources); printf("%-13s: imports : %8ld bytes\n", getName(), (long) soimpdlls); printf("%-13s: exports : %8ld bytes\n", getName(), (long) soexport); printf("%-13s: relocs : %8ld bytes\n", getName(), (long) soxrelocs); #endif // verify verifyOverlappingDecompression(); // copy the overlay copyOverlay(fo, overlay, &obuf); // finally check the compression ratio if (!checkFinalCompressionRatio(fo)) throwNotCompressible(); }
int main(int argc, char **argv) { static const char *first_ifdefs[] = { "/*", " * Compile-in this chunk of code unless we've turned it off specifically", " * or in general (id=%s).", " */", "", "#ifndef INCL_CHARSET%s", "#define INCL_CHARSET%s 1", "", "/*ifdef NO_CHARSET*/", "#ifdef NO_CHARSET", "#undef NO_CHARSET", "#endif", "#define NO_CHARSET 0 /* force default to always be active */", "", "/*ifndef NO_CHARSET%s*/", "#ifndef NO_CHARSET%s", "", "#if ALL_CHARSETS", "#define NO_CHARSET%s 0", "#else", "#define NO_CHARSET%s 1", "#endif", "", "#endif /* ndef(NO_CHARSET%s) */", "", "#if NO_CHARSET%s", "#define UC_CHARSET_SETUP%s /*nothing*/", "#else" }; static const char *last_ifdefs[] = { "", "#endif /* NO_CHARSET%s */", "", "#endif /* INCL_CHARSET%s */" }; FILE *ctbl; char buffer[65536]; char *outname = 0; unsigned n; int fontlen; int i, nuni, nent; int fp0 = 0, fp1 = 0, un0, un1; char *p, *p1; char *tbuf, ch; if (argc < 2 || argc > 5) { usage(); } if (!strcmp(argv[1], "-")) { ctbl = stdin; tblname = "stdin"; } else { ctbl = fopen(tblname = argv[1], "r"); if (!ctbl) { perror(tblname); done(EX_NOINPUT); } } if (argc > 2) { if (!strcmp(argv[2], "-")) { chdr = stdout; hdrname = "stdout"; } else { hdrname = argv[2]; } } else if (ctbl == stdin) { chdr = stdout; hdrname = "stdout"; } else if ((outname = (char *) malloc(strlen(tblname) + 3)) != 0) { strcpy(outname, tblname); hdrname = outname; if ((p = strrchr(outname, '.')) == 0) p = outname + strlen(outname); strcpy(p, ".h"); } else { perror("malloc"); done(EX_NOINPUT); } if (chdr == 0) { chdr = fopen(hdrname, "w"); if (!chdr) { perror(hdrname); done(EX_NOINPUT); } } /* * For now we assume the default font is always 256 characters. */ fontlen = 256; /* * Initialize table. */ for (i = 0; i < fontlen; i++) { unicount[i] = 0; } /* * Now we comes to the tricky part. Parse the input table. */ while (fgets(buffer, sizeof(buffer), ctbl) != NULL) { if ((p = strchr(buffer, '\n')) != NULL) { *p = '\0'; } else { fprintf(stderr, "%s: Warning: line too long or incomplete.\n", tblname); } /* * Syntax accepted: * <fontpos> <unicode> <unicode> ... * <fontpos> <unicode range> <unicode range> ... * <fontpos> idem * <range> idem * <range> <unicode range> * <unicode> :<replace> * <unicode range> :<replace> * <unicode> "<C replace>" * <unicode range> "<C replace>" * * where <range> ::= <fontpos>-<fontpos> * and <unicode> ::= U+<h><h><h><h> * and <h> ::= <hexadecimal digit> * and <replace> any string not containing '\n' or '\0' * and <C replace> any string with C backslash escapes. */ p = buffer; while (*p == ' ' || *p == '\t') { p++; } if (!(*p) || *p == '#') { /* * Skip comment or blank line. */ continue; } switch (*p) { /* * Raw Unicode? I.e. needs some special * processing. One digit code. */ case 'R': if (p[1] == 'a' || p[1] == 'A') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "RawOrEnc", 8)) { p += 8; } } p++; while (*p == ' ' || *p == '\t') { p++; } RawOrEnc = strtol(p, 0, 10); Raw_found = 1; continue; /* * Is this the default table? */ case 'D': if (p[1] == 'e' || p[1] == 'E') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "Default", 7)) { p += 7; } } p++; while (*p == ' ' || *p == '\t') { p++; } this_isDefaultMap = (*p == '1' || TOLOWER(*p) == 'y'); continue; /* * Is this the default table? */ case 'F': if (p[1] == 'a' || p[1] == 'A') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "FallBack", 8)) { p += 8; } } p++; while (*p == ' ' || *p == '\t') { p++; } useDefaultMap = (*p == '1' || TOLOWER(*p) == 'y'); continue; case 'M': if (p[1] == 'i' || p[1] == 'I') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "MIMEName", 8)) { p += 8; } } p++; while (*p == ' ' || *p == '\t') { p++; } sscanf(p, "%40s", this_MIMEcharset); continue; /* * Display charset name for options screen. */ case 'O': if (p[1] == 'p' || p[1] == 'P') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "OptionName", 10)) { p += 10; } } p++; while (*p == ' ' || *p == '\t') { p++; } for (i = 0; *p && i < UC_MAXLEN_LYNXCSNAME; p++, i++) { this_LYNXcharset[i] = *p; } this_LYNXcharset[i] = '\0'; continue; /* * Codepage number. Three or four digit code. */ case 'C': if (p[1] == 'o' || p[1] == 'O') { buffer[sizeof(buffer) - 1] = '\0'; if (!strncasecomp(p, "CodePage", 8)) { p += 8; } } p++; while (*p == ' ' || *p == '\t') { p++; } CodePage = strtol(p, 0, 10); continue; } if (*p == 'U') { un0 = getunicode(&p); if (un0 < 0) { fprintf(stderr, "Bad input line: %s\n", buffer); done(EX_DATAERR); fprintf(stderr, "%s: Bad Unicode range corresponding to font position range 0x%x-0x%x\n", tblname, fp0, fp1); done(EX_DATAERR); } un1 = un0; while (*p == ' ' || *p == '\t') { p++; } if (*p == '-') { p++; while (*p == ' ' || *p == '\t') { p++; } un1 = getunicode(&p); if (un1 < 0 || un1 < un0) { fprintf(stderr, "%s: Bad Unicode range U+%x-U+%x\n", tblname, un0, un1); fprintf(stderr, "Bad input line: %s\n", buffer); done(EX_DATAERR); } while (*p == ' ' || *p == '\t') { p++; } } if (*p != ':' && *p != '"') { fprintf(stderr, "No ':' or '\"' where expected: %s\n", buffer); continue; } /* * Allocate a string large enough for the worst-case use in the * loop using sprintf. */ tbuf = (char *) malloc(5 * strlen(p)); if (!(p1 = tbuf)) { fprintf(stderr, "%s: Out of memory\n", tblname); done(EX_DATAERR); } if (*p == '"') { /* * Handle "<C replace>". * Copy chars verbatim until first '"' not \-escaped or * end of buffer. */ int escaped = 0; for (ch = *(++p); (ch = *p) != '\0'; p++) { if (escaped) { escaped = 0; } else if (ch == '"') { break; } else if (ch == '\\') { escaped = 1; } *p1++ = ch; } if (escaped || ch != '"') { fprintf(stderr, "Warning: String not terminated: %s\n", buffer); if (escaped) *p1++ = '\n'; } } else { /* * We had ':'. */ for (ch = *(++p); (ch = *p) != '\0'; p++, p1++) { if (UCH(ch) < 32 || ch == '\\' || ch == '\"' || UCH(ch) >= 127) { sprintf(p1, "\\%.3o", UCH(ch)); p1 += 3; } else { *p1 = ch; } } } *p1 = '\0'; for (i = un0; i <= un1; i++) { addpair_str(tbuf, i); } continue; } /* * Input line (after skipping spaces) doesn't start with one * of the specially recognized characters, so try to interpret * it as starting with a fontpos. */ fp0 = strtol(p, &p1, 0); if (p1 == p) { fprintf(stderr, "Bad input line: %s\n", buffer); done(EX_DATAERR); } p = p1; while (*p == ' ' || *p == '\t') { p++; } if (*p == '-') { p++; fp1 = strtol(p, &p1, 0); if (p1 == p) { fprintf(stderr, "Bad input line: %s\n", buffer); done(EX_DATAERR); } p = p1; } else { fp1 = 0; } if (fp0 < 0 || fp0 >= fontlen) { fprintf(stderr, "%s: Glyph number (0x%x) larger than font length\n", tblname, fp0); done(EX_DATAERR); } if (fp1 && (fp1 < fp0 || fp1 >= fontlen)) { fprintf(stderr, "%s: Bad end of range (0x%x)\n", tblname, fp1); done(EX_DATAERR); } if (fp1) { /* * We have a range; expect the word "idem" * or a Unicode range of the same length. */ while (*p == ' ' || *p == '\t') { p++; } if (!strncmp(p, "idem", 4)) { for (i = fp0; i <= fp1; i++) { addpair(i, i); } p += 4; } else { un0 = getunicode(&p); while (*p == ' ' || *p == '\t') { p++; } if (*p != '-') { fprintf(stderr, "%s: Corresponding to a range of font positions,", tblname); fprintf(stderr, " there should be a Unicode range.\n"); done(EX_DATAERR); } p++; un1 = getunicode(&p); if (un0 < 0 || un1 < 0) { fprintf(stderr, "%s: Bad Unicode range corresponding to font position range 0x%x-0x%x\n", tblname, fp0, fp1); done(EX_DATAERR); } if (un1 - un0 != fp1 - fp0) { fprintf(stderr, "%s: Unicode range U+%x-U+%x not of the same length", tblname, un0, un1); fprintf(stderr, " as font position range 0x%x-0x%x\n", fp0, fp1); done(EX_DATAERR); } for (i = fp0; i <= fp1; i++) { addpair(i, un0 - fp0 + i); } } } else { /* * No range; expect a list of unicode values * or unicode ranges for a single font position, * or the word "idem" */ while (*p == ' ' || *p == '\t') { p++; } if (!strncmp(p, "idem", 4)) { addpair(fp0, fp0); p += 4; } while ((un0 = getunicode(&p)) >= 0) { addpair(fp0, un0); while (*p == ' ' || *p == '\t') { p++; } if (*p == '-') { p++; un1 = getunicode(&p); if (un1 < un0) { fprintf(stderr, "%s: Bad Unicode range 0x%x-0x%x\n", tblname, un0, un1); done(EX_DATAERR); } for (un0++; un0 <= un1; un0++) { addpair(fp0, un0); } } } } while (*p == ' ' || *p == '\t') { p++; } if (*p && *p != '#') { fprintf(stderr, "%s: trailing junk (%s) ignored\n", tblname, p); } } /* * Okay, we hit EOF, now output tables. */ fclose(ctbl); /* * Compute total size of Unicode list. */ nuni = 0; for (i = 0; i < fontlen; i++) { nuni += unicount[i]; } if (argc > 3) { strncpy(this_MIMEcharset, argv[3], UC_MAXLEN_MIMECSNAME); } else if (this_MIMEcharset[0] == '\0') { strncpy(this_MIMEcharset, tblname, UC_MAXLEN_MIMECSNAME); if ((p = strchr(this_MIMEcharset, '.')) != 0) { *p = '\0'; } } for (p = this_MIMEcharset; *p; p++) { *p = TOLOWER(*p); } if (argc > 4) { strncpy(this_LYNXcharset, argv[4], UC_MAXLEN_LYNXCSNAME); } else if (this_LYNXcharset[0] == '\0') { strncpy(this_LYNXcharset, this_MIMEcharset, UC_MAXLEN_LYNXCSNAME); } if (this_isDefaultMap == -1) { this_isDefaultMap = !strncmp(this_MIMEcharset, "iso-8859-1", 10); } fprintf(stderr, "makeuctb: %s: %stranslation map", this_MIMEcharset, (this_isDefaultMap ? "default " : "")); if (this_isDefaultMap == 1) { *id_append = '\0'; } else { for (i = 0, p = this_MIMEcharset; *p && (i < UC_MAXLEN_ID_APPEND - 1); p++, i++) { id_append[i + 1] = isalnum(UCH(*p)) ? *p : '_'; } id_append[i + 1] = '\0'; } fprintf(stderr, " (%s).\n", id_append); for (n = 0; n < TABLESIZE(first_ifdefs); n++) { fprintf(chdr, first_ifdefs[n], id_append); fprintf(chdr, "\n"); } fprintf(chdr, "\n\ /*\n\ * uni_hash.tbl\n\ *\n\ * Do not edit this file; it was automatically generated by\n\ *\n\ * %s %s\n\ *\n\ */\n\ \n\ static const u8 dfont_unicount%s[%d] = \n\ {\n\t", argv[0], argv[1], id_append, fontlen); for (i = 0; i < fontlen; i++) { if (i >= 128 && unicount[i] > 0 && i < lowest_eight) { lowest_eight = i; } fprintf(chdr, "%3d", unicount[i]); if (i == (fontlen - 1)) { fprintf(chdr, "\n};\n"); } else if ((i % 8) == 7) { fprintf(chdr, ",\n\t"); } else { fprintf(chdr, ", "); } } /* * If lowest_eightbit is anything else but 999, * this can't be 7-bit only. */ if (lowest_eight != 999 && !RawOrEnc) { RawOrEnc = UCT_ENC_8BIT; } if (nuni) { fprintf(chdr, "\nstatic const u16 dfont_unitable%s[%d] = \n{\n\t", id_append, nuni); } else { fprintf(chdr, "\nstatic const u16 dfont_unitable%s[1] = {0}; /* dummy */\n", id_append); } fp0 = 0; nent = 0; for (i = 0; i < nuni; i++) { while (nent >= unicount[fp0]) { fp0++; nent = 0; } fprintf(chdr, "0x%04x", unitable[fp0][nent++]); if (i == (nuni - 1)) { fprintf(chdr, "\n};\n"); } else if ((i % 8) == 7) { fprintf(chdr, ",\n\t"); } else { fprintf(chdr, ", "); } } if (themap_str.entry_ct) { fprintf(chdr, "\n\ static struct unipair_str repl_map%s[%d] = \n\ {\n\t", id_append, themap_str.entry_ct); } else { fprintf(chdr, "\n\ /* static struct unipair_str repl_map%s[]; */\n", id_append); } for (i = 0; i < themap_str.entry_ct; i++) { fprintf(chdr, "{0x%x,\"%s\"}", themap_str.entries[i].unicode, themap_str.entries[i].replace_str); if (i == (themap_str.entry_ct - 1)) { fprintf(chdr, "\n};\n"); } else if ((i % 4) == 3) { fprintf(chdr, ",\n\t"); } else { fprintf(chdr, ", "); } } if (themap_str.entry_ct) { fprintf(chdr, "\n\ static const struct unimapdesc_str dfont_replacedesc%s = {%d,repl_map%s,", id_append, themap_str.entry_ct, id_append); } else {
static int tst_DECUDK(MENU_ARGS) { int key; /* *INDENT-OFF* */ static struct { int code; const char *name; } keytable[] = { /* xterm programs these: */ { 11, "F1" }, { 12, "F2" }, { 13, "F3" }, { 14, "F4" }, { 15, "F5" }, /* vt420 programs these: */ { 17, "F6" }, { 18, "F7" }, { 19, "F8" }, { 20, "F9" }, { 21, "F10" }, { 23, "F11" }, { 24, "F12" }, { 25, "F13" }, { 26, "F14" }, { 28, "F15" }, { 29, "F16" }, { 31, "F17" }, { 32, "F18" }, { 33, "F19" }, { 34, "F20" } }; /* *INDENT-ON* */ for (key = 0; key < TABLESIZE(keytable); key++) { char temp[80]; const char *s; temp[0] = '\0'; for (s = keytable[key].name; *s; s++) sprintf(temp + strlen(temp), "%02x", *s & 0xff); do_dcs("1;1|%d/%s", keytable[key].code, temp); } vt_move(1, 1); println(the_title); println("Press 'q' to quit. Function keys should echo their labels."); println("(On a DEC terminal you must press SHIFT as well)."); set_tty_raw(TRUE); set_tty_echo(FALSE); for (;;) { char *report = instr(); if (*report == 'q') break; vt_move(5, 10); vt_clear(0); chrprint(report); } do_dcs("0"); /* clear all keys */ restore_ttymodes(); vt_move(max_lines - 1, 1); return MENU_HOLD; }
static void tcapopen(void) { char *t, *p; char tcbuf[2048]; char *tv_stype; char err_str[72]; int i, j; static int already_open = 0; static const struct { char *name; char **data; } tc_strings[] = { { "AL", &AL } /* add p1 lines above cursor */ ,{ "DL", &DL } /* delete p1 lines, begin at cursor */ ,{ "al", &al } /* add line below cursor */ ,{ "ce", &CE } /* clear to end of line */ ,{ "cl", &CL } /* clear screen, cursor to home */ ,{ "cm", &CM } /* move cursor to row p1, col p2 */ ,{ "cs", &CS } /* set scrolling to rows p1 .. p2 */ ,{ "dl", &dl } /* delete line */ ,{ "ke", &KE } /* end keypad-mode */ ,{ "ks", &KS } /* start keypad-mode */ ,{ "se", &SE } /* end standout-mode */ ,{ "sf", &SF } /* scroll forward 1 line */ ,{ "so", &SO } /* start standout-mode */ ,{ "sr", &SR } /* scroll reverse 1 line */ ,{ "te", &TE } /* end cursor-motion program */ ,{ "ti", &TI } /* initialize cursor-motion program */ #if OPT_COLOR ,{ "AF", &Sf } /* set ANSI foreground-color */ ,{ "AB", &Sb } /* set ANSI background-color */ ,{ "Sf", &Sf } /* set foreground-color */ ,{ "Sb", &Sb } /* set background-color */ ,{ "op", &orig_colors } /* set to original color pair */ ,{ "oc", &orig_colors } /* set to original colors */ #endif #if OPT_FLASH ,{ "vb", &vb } /* visible bell */ #endif #if OPT_VIDEO_ATTRS ,{ "me", &ME } /* turn off all attributes */ ,{ "md", &MD } /* turn on bold attribute */ ,{ "us", &US } /* underline-start */ ,{ "ue", &UE } /* underline-end */ #endif }; if (already_open) return; if ((tv_stype = getenv("TERM")) == NULL) { puts("Environment variable TERM not defined!"); ExitProgram(BADEXIT); } if ((tgetent(tcbuf, tv_stype)) != 1) { (void)lsprintf(err_str, "Unknown terminal type %s!", tv_stype); puts(err_str); ExitProgram(BADEXIT); } /* Get screen size from system, or else from termcap. */ getscreensize(&term.t_ncol, &term.t_nrow); if ((term.t_nrow <= 1) && (term.t_nrow=(short)tgetnum("li")) == -1) { term.t_nrow = 24; } if ((term.t_ncol <= 1) &&(term.t_ncol=(short)tgetnum("co")) == -1){ term.t_ncol = 80; } /* are we probably an xterm? */ p = tcbuf; i_am_xterm = FALSE; if (strncmp(tv_stype, "xterm", sizeof("xterm") - 1) == 0) { i_am_xterm = TRUE; x_origin = 0; y_origin = 0; } else while (*p && *p != ':') { if (*p == 'x' && strncmp(p, "xterm", sizeof("xterm") - 1) == 0) { i_am_xterm = TRUE; x_origin = 0; y_origin = 0; break; } p++; } term.t_mrow = term.t_nrow; term.t_mcol = term.t_ncol; p = tcapbuf; for (i = 0; i < TABLESIZE(tc_strings); i++) { /* allow aliases */ if (*(tc_strings[i].data) == 0) *(tc_strings[i].data) = tgetstr(tc_strings[i].name, &p); } #if HAVE_EXTERN_TCAP_PC t = tgetstr("pc", &p); if(t) PC = *t; #endif if (SO != NULL) revexist = TRUE; if(CL == NULL || CM == NULL) { puts("Incomplete termcap entry\n"); ExitProgram(BADEXIT); } if (CE == NULL) /* will we be able to use clear to EOL? */ eolexist = FALSE; if (!CS || !SR) { /* some xterm's termcap entry is missing entries */ if (i_am_xterm) { if (!CS) CS = "\033[%i%d;%dr"; if (!SR) SR = "\033[M"; } } if (CS && SR) { if (SF == NULL) /* assume '\n' scrolls forward */ SF = "\n"; term.t_scroll = tcapscroll_reg; } else if ((DL && AL) || (dl && al)) { term.t_scroll = tcapscroll_delins; } else { term.t_scroll = null_t_scroll; } #if OPT_COLOR if (orig_colors == 0) orig_colors = tgetstr("me", &p); set_palette(initpalettestr); #endif #if OPT_VIDEO_ATTRS if (US == 0 && UE == 0) { /* if we don't have underline, do bold */ US = MD; UE = ME; } #endif for (i = TABLESIZE(keyseqs); i--; ) { char *seq = tgetstr(keyseqs[i].capname, &p); if (seq) { int len; #define DONT_MAP_DEL 1 #if DONT_MAP_DEL /* NetBSD, FreeBSD, etc. have the kD (delete) function key defined as the DEL char. i don't like this hack, but until we (and we may never) have separate system "map" and "map!" maps, we can't allow this -- DEL has different semantics in insert and command mode, whereas KEY_Delete has the same semantics (whatever they may be) in both. KEY_Delete is the only non-motion system map, by the way -- so the rest are benign in insert or command mode. */ if (strcmp(seq,"\177") == 0) continue; #endif addtosysmap(seq, len = strlen(seq), keyseqs[i].code); /* * Termcap represents nulls as octal 200, which is ambiguous * (ugh). To avoid losing escape sequences that may contain * nulls, check here, and add a mapping for the strings with * explicit nulls. */ #define TCAP_NULL '\200' if (strchr(seq, TCAP_NULL) != 0) { char temp[BUFSIZ]; (void)strcpy(temp, seq); for (j = 0; j < len; j++) if (char2int(temp[j]) == TCAP_NULL) temp[j] = '\0'; addtosysmap(temp, len, keyseqs[i].code); } } } #if OPT_XTERM addtosysmap("\033[M", 3, KEY_Mouse); #if OPT_XTERM >= 3 addtosysmap("\033[t", 3, KEY_text); addtosysmap("\033[T", 3, KEY_textInvalid); #endif #endif if (p >= &tcapbuf[TCAPSLEN]) { puts("Terminal description too big!\n"); ExitProgram(BADEXIT); } ttopen(); already_open = TRUE; }