int Win32ResExtractor::do_resources_recurs(WinLibrary *fi, WinResource *base, WinResource *type_wr, WinResource *name_wr, WinResource *lang_wr, const char *type, char *name, char *lang, byte **data) { int c, rescnt; WinResource *wr; uint32 size = 0; /* get a list of all resources at this level */ wr = list_resources(fi, base, &rescnt); if (wr == NULL) { return size; } /* process each resource listed */ for (c = 0; c < rescnt; c++) { /* (over)write the corresponding WinResource holder with the current */ memcpy(WINRESOURCE_BY_LEVEL(wr[c].level), wr+c, sizeof(WinResource)); /* go deeper unless there is something that does NOT match */ if (LEVEL_MATCHES(type) && LEVEL_MATCHES(name) && LEVEL_MATCHES(lang)) { if (wr->is_directory) size = do_resources_recurs(fi, wr+c, type_wr, name_wr, lang_wr, type, name, lang, data); else size = extract_resources(fi, wr+c, type_wr, name_wr, lang_wr, data); } } /* since we're moving back one level after this, unset the * WinResource holder used on this level */ memset(WINRESOURCE_BY_LEVEL(wr[0].level), 0, sizeof(WinResource)); return size; }
/*{{{ main() */ int main (int argc, char *argv[]) { int i; char *val, **cmd_argv = NULL; /* "WINDOWID=\0" = 10 chars, UINT_MAX = 10 chars */ static char windowid_string[20], *display_string; for (i = 0; i < argc; i++) { if (!strcmp (argv[i], "-e")) { argc = i; argv[argc] = NULL; if (argv[argc + 1] != NULL) { cmd_argv = (argv + argc + 1); if (cmd_argv[0] != NULL) rs_iconName = rs_title = my_basename (cmd_argv[0]); } break; } } rs_name = my_basename (argv[0]); /* * Open display, get options/resources and create the window */ if ((display_name = getenv ("DISPLAY")) == NULL) display_name = ":0"; get_options (argc, argv); Xdisplay = XOpenDisplay (display_name); if (!Xdisplay) { print_error ("can't open display %s", display_name); exit (EXIT_FAILURE); } extract_resources (Xdisplay, rs_name); /* * set any defaults not already set */ if (!rs_title) rs_title = rs_name; if (!rs_iconName) rs_iconName = rs_name; if (!rs_saveLines || (TermWin.saveLines = atoi (rs_saveLines)) < 0) TermWin.saveLines = SAVELINES; /* no point having a scrollbar without having any scrollback! */ if (!TermWin.saveLines) Options &= ~Opt_scrollBar; #ifdef PRINTPIPE if (!rs_print_pipe) rs_print_pipe = PRINTPIPE; #endif if (!rs_cutchars) rs_cutchars = CUTCHARS; #ifndef NO_BOLDFONT if (rs_font[0] == NULL && rs_boldFont != NULL) { rs_font[0] = rs_boldFont; rs_boldFont = NULL; } #endif for (i = 0; i < NFONTS; i++) { if (!rs_font[i]) rs_font[i] = def_fontName[i]; #ifdef KANJI if (!rs_kfont[i]) rs_kfont[i] = def_kfontName[i]; #endif } #ifdef XTERM_REVERSE_VIDEO /* this is how xterm implements reverseVideo */ if (Options & Opt_reverseVideo) { if (!rs_color[fgColor]) rs_color[fgColor] = def_colorName[bgColor]; if (!rs_color[bgColor]) rs_color[bgColor] = def_colorName[fgColor]; } #endif for (i = 0; i < NRS_COLORS; i++) if (!rs_color[i]) rs_color[i] = def_colorName[i]; #ifndef XTERM_REVERSE_VIDEO /* this is how we implement reverseVideo */ if (Options & Opt_reverseVideo) { const char *name; /* swap foreground/background colors */ name = rs_color[fgColor]; rs_color[fgColor] = rs_color[bgColor]; rs_color[bgColor] = name; name = def_colorName[fgColor]; def_colorName[fgColor] = def_colorName[bgColor]; def_colorName[bgColor] = name; } #endif /* convenient aliases for setting fg/bg to colors */ color_aliases (fgColor); color_aliases (bgColor); #ifndef NO_CURSORCOLOR color_aliases (cursorColor); color_aliases (cursorColor2); #endif /* NO_CURSORCOLOR */ #ifndef NO_BOLDUNDERLINE color_aliases (colorBD); color_aliases (colorUL); #endif /* NO_BOLDUNDERLINE */ Create_Windows (argc, argv); scr_reset (); /* initialize screen */ Gr_reset (); /* reset graphics */ /* add scrollBar, do it directly to avoid resize() */ scrollbar_mapping (Options & Opt_scrollBar); #ifdef DEBUG_X XSynchronize (Xdisplay, True); XSetErrorHandler ((XErrorHandler) abort); #else XSetErrorHandler ((XErrorHandler) xerror_handler); #endif #ifdef DISPLAY_IS_IP /* Fixup display_name for export over pty to any interested terminal * clients via "ESC[7n" (e.g. shells). Note we use the pure IP number * (for the first non-loopback interface) that we get from * network_display(). This is more "name-resolution-portable", if you * will, and probably allows for faster x-client startup if your name * server is beyond a slow link or overloaded at client startup. Of * course that only helps the shell's child processes, not us. * * Giving out the display_name also affords a potential security hole */ val = display_name = network_display (display_name); if (val == NULL) #endif /* DISPLAY_IS_IP */ val = XDisplayString (Xdisplay); if (display_name == NULL) display_name = val; /* use broken `:0' value */ i = strlen (val); display_string = MALLOC ((i + 9) * sizeof (char), "display_string"); sprintf (display_string, "DISPLAY=%s", val); sprintf (windowid_string, "WINDOWID=%u", (unsigned int) TermWin.parent); /* add entries to the environment: * @ DISPLAY: in case we started with -display * @ WINDOWID: X window id number of the window * @ COLORTERM: terminal sub-name and also indicates its color * @ TERM: terminal name */ putenv (display_string); putenv (windowid_string); if (Xdepth <= 2) { putenv ("COLORTERM=" COLORTERMENV "-mono"); putenv ("TERM=" TERMENV); } else { #ifdef XPM_BACKGROUND putenv ("COLORTERM=" COLORTERMENV "-xpm"); #else putenv ("COLORTERM=" COLORTERMENV); #endif #ifdef DEFINE_XTERM_COLOR putenv ("TERM=" TERMENV "-color"); #else putenv ("TERM=" TERMENV); #endif } init_command (cmd_argv); main_loop (); /* main processing loop */ return EXIT_SUCCESS; }