windres.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,010 行 · 第 1/2 页
C
1,010 行
a = (struct res_entry **) xmalloc (c * sizeof (struct res_entry *)); for (i = 0, re = resdir->entries; re != NULL; re = re->next, i++) a[i] = re; qsort (a, c, sizeof (struct res_entry *), cmp_res_entry); resdir->entries = a[0]; for (i = 0; i < c - 1; i++) a[i]->next = a[i + 1]; a[i]->next = NULL; free (a); /* Now sort the subdirectories. */ for (re = resdir->entries; re != NULL; re = re->next) if (re->subdir) re->u.dir = sort_resources (re->u.dir); return resdir;}/* Return whether the dialog resource DIALOG is a DIALOG or a DIALOGEX. */intextended_dialog (dialog) const struct dialog *dialog;{ const struct dialog_control *c; if (dialog->ex != NULL) return 1; for (c = dialog->controls; c != NULL; c = c->next) if (c->data != NULL || c->help != 0) return 1; return 0;}/* Return whether MENUITEMS are a MENU or a MENUEX. */intextended_menu (menu) const struct menu *menu;{ return extended_menuitems (menu->items);}static intextended_menuitems (menuitems) const struct menuitem *menuitems;{ const struct menuitem *mi; for (mi = menuitems; mi != NULL; mi = mi->next) { if (mi->help != 0 || mi->state != 0) return 1; if (mi->popup != NULL && mi->id != 0) return 1; if ((mi->type & ~ (MENUITEM_CHECKED | MENUITEM_GRAYED | MENUITEM_HELP | MENUITEM_INACTIVE | MENUITEM_MENUBARBREAK | MENUITEM_MENUBREAK)) != 0) return 1; if (mi->popup != NULL) { if (extended_menuitems (mi->popup)) return 1; } } return 0;}/* Convert a string to a format type, or exit if it can't be done. */static enum res_formatformat_from_name (name) const char *name;{ const struct format_map *m; for (m = format_names; m->name != NULL; m++) if (strcasecmp (m->name, name) == 0) break; if (m->name == NULL) { non_fatal (_("unknown format type `%s'"), name); fprintf (stderr, _("%s: supported formats:"), program_name); for (m = format_names; m->name != NULL; m++) fprintf (stderr, " %s", m->name); fprintf (stderr, "\n"); xexit (1); } return m->format;}/* Work out a format type given a file name. If INPUT is non-zero, it's OK to look at the file itself. */static enum res_formatformat_from_filename (filename, input) const char *filename; int input;{ const char *ext; FILE *e; unsigned char b1, b2, b3, b4, b5; int magic; /* If we have an extension, see if we recognize it as implying a particular format. */ ext = strrchr (filename, '.'); if (ext != NULL) { const struct format_map *m; ++ext; for (m = format_fileexts; m->name != NULL; m++) if (strcasecmp (m->name, ext) == 0) return m->format; } /* If we don't recognize the name of an output file, assume it's a COFF file. */ if (! input) return RES_FORMAT_COFF; /* Read the first few bytes of the file to see if we can guess what it is. */ e = fopen (filename, FOPEN_RB); if (e == NULL) fatal ("%s: %s", filename, strerror (errno)); b1 = getc (e); b2 = getc (e); b3 = getc (e); b4 = getc (e); b5 = getc (e); fclose (e); /* A PE executable starts with 0x4d 0x5a. */ if (b1 == 0x4d && b2 == 0x5a) return RES_FORMAT_COFF; /* A COFF .o file starts with a COFF magic number. */ magic = (b2 << 8) | b1; switch (magic) { case 0x14c: /* i386 */ case 0x166: /* MIPS */ case 0x184: /* Alpha */ case 0x268: /* 68k */ case 0x1f0: /* PowerPC */ case 0x290: /* PA */ return RES_FORMAT_COFF; } /* A RES file starts with 0x0 0x0 0x0 0x0 0x20 0x0 0x0 0x0. */ if (b1 == 0 && b2 == 0 && b3 == 0 && b4 == 0 && b5 == 0x20) return RES_FORMAT_RES; /* If every character is printable or space, assume it's an RC file. */ if ((isprint (b1) || isspace (b1)) && (isprint (b2) || isspace (b2)) && (isprint (b3) || isspace (b3)) && (isprint (b4) || isspace (b4)) && (isprint (b5) || isspace (b5))) return RES_FORMAT_RC; /* Otherwise, we give up. */ fatal (_("can not determine type of file `%s'; use the -I option"), filename); /* Return something to silence the compiler warning. */ return RES_FORMAT_UNKNOWN;}/* Print a usage message and exit. */static voidusage (stream, status) FILE *stream; int status;{ fprintf (stream, _("Usage: %s [options] [input-file] [output-file]\n"), program_name); fprintf (stream, _("\Options:\n\ -i FILE, --input FILE Name input file\n\ -o FILE, --output FILE Name output file\n\ -I FORMAT, --input-format FORMAT\n\ Specify input format\n\ -O FORMAT, --output-format FORMAT\n\ Specify output format\n\ -F TARGET, --target TARGET Specify COFF target\n\ --preprocessor PROGRAM Program to use to preprocess rc file\n\ --include-dir DIR Include directory when preprocessing rc file\n\ -DSYM[=VAL], --define SYM[=VAL]\n\ Define SYM when preprocessing rc file\n\ -v Verbose - tells you what it's doing\n\ --language VAL Set language when reading rc file\n\ --use-temp-file Use a temporary file instead of popen to read\n\ the preprocessor output\n\ --no-use-temp-file Use popen (default)\n"));#ifdef YYDEBUG fprintf (stream, _("\ --yydebug Turn on parser debugging\n"));#endif fprintf (stream, _("\ --help Print this help message\n\ --version Print version information\n")); fprintf (stream, _("\FORMAT is one of rc, res, or coff, and is deduced from the file name\n\extension if not specified. A single file name is an input file.\n\No input-file is stdin, default rc. No output-file is stdout, default rc.\n")); list_supported_targets (program_name, stream); if (status == 0) fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO); exit (status);}/* Quote characters that will confuse the shell when we run the preprocessor */static const char *quot (string) const char *string;{ static char *buf = 0; static int buflen = 0; int slen = strlen (string); const char *src; char *dest; if ((buflen < slen * 2 + 2) || !buf) { buflen = slen * 2 + 2; if (buf) free (buf); buf = (char *) xmalloc (buflen); } for (src=string, dest=buf; *src; src++, dest++) { if (*src == '(' || *src == ')' || *src == ' ') *dest++ = '\\'; *dest = *src; } *dest = 0; return buf;}/* The main function. */intmain (argc, argv) int argc; char **argv;{ int c; char *input_filename; char *output_filename; enum res_format input_format; enum res_format output_format; char *target; char *preprocessor; char *preprocargs; const char *quotedarg; int language; struct res_directory *resources; int use_temp_file;#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) setlocale (LC_MESSAGES, "");#endif bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); program_name = argv[0]; xmalloc_set_program_name (program_name); bfd_init (); set_default_bfd_target (); res_init (); input_filename = NULL; output_filename = NULL; input_format = RES_FORMAT_UNKNOWN; output_format = RES_FORMAT_UNKNOWN; target = NULL; preprocessor = NULL; preprocargs = NULL; language = -1; use_temp_file = 0; while ((c = getopt_long (argc, argv, "i:o:I:O:F:D:v", long_options, (int *) 0)) != EOF) { switch (c) { case 'i': input_filename = optarg; break; case 'o': output_filename = optarg; break; case 'I': input_format = format_from_name (optarg); break; case 'O': output_format = format_from_name (optarg); break; case 'F': target = optarg; break; case OPTION_PREPROCESSOR: preprocessor = optarg; break; case 'D': case OPTION_DEFINE: if (preprocargs == NULL) { quotedarg = quot (optarg); preprocargs = xmalloc (strlen (quotedarg) + 3); sprintf (preprocargs, "-D%s", quotedarg); } else { char *n; quotedarg = quot (optarg); n = xmalloc (strlen (preprocargs) + strlen (quotedarg) + 4); sprintf (n, "%s -D%s", preprocargs, quotedarg); free (preprocargs); preprocargs = n; } break; case 'v': verbose ++; break; case OPTION_INCLUDE_DIR: if (preprocargs == NULL) { quotedarg = quot (optarg); preprocargs = xmalloc (strlen (quotedarg) + 3); sprintf (preprocargs, "-I%s", quotedarg); } else { char *n; quotedarg = quot (optarg); n = xmalloc (strlen (preprocargs) + strlen (quotedarg) + 4); sprintf (n, "%s -I%s", preprocargs, quotedarg); free (preprocargs); preprocargs = n; } { struct include_dir *n, **pp; n = (struct include_dir *) xmalloc (sizeof *n); n->next = NULL; n->dir = optarg; for (pp = &include_dirs; *pp != NULL; pp = &(*pp)->next) ; *pp = n; } break; case OPTION_LANGUAGE: language = strtol (optarg, (char **) NULL, 16); break; case OPTION_USE_TEMP_FILE: use_temp_file = 1; break; case OPTION_NO_USE_TEMP_FILE: use_temp_file = 0; break;#ifdef YYDEBUG case OPTION_YYDEBUG: yydebug = 1; break;#endif case OPTION_HELP: usage (stdout, 0); break; case OPTION_VERSION: print_version ("windres"); break; default: usage (stderr, 1); break; } } if (input_filename == NULL && optind < argc) { input_filename = argv[optind]; ++optind; } if (output_filename == NULL && optind < argc) { output_filename = argv[optind]; ++optind; } if (argc != optind) usage (stderr, 1); if (input_format == RES_FORMAT_UNKNOWN) { if (input_filename == NULL) input_format = RES_FORMAT_RC; else input_format = format_from_filename (input_filename, 1); } if (output_format == RES_FORMAT_UNKNOWN) { if (output_filename == NULL) output_format = RES_FORMAT_RC; else output_format = format_from_filename (output_filename, 0); } /* Read the input file. */ switch (input_format) { default: abort (); case RES_FORMAT_RC: resources = read_rc_file (input_filename, preprocessor, preprocargs, language, use_temp_file); break; case RES_FORMAT_RES: resources = read_res_file (input_filename); break; case RES_FORMAT_COFF: resources = read_coff_rsrc (input_filename, target); break; } if (resources == NULL) fatal (_("no resources")); /* Sort the resources. This is required for COFF, convenient for rc, and unimportant for res. */ resources = sort_resources (resources); /* Write the output file. */ reswr_init (); switch (output_format) { default: abort (); case RES_FORMAT_RC: write_rc_file (output_filename, resources); break; case RES_FORMAT_RES: write_res_file (output_filename, resources); break; case RES_FORMAT_COFF: write_coff_file (output_filename, target, resources); break; } xexit (0); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?