| 1 | /* cmd.c -- Handle commands
|
|---|
| 2 | Copyright (c) 1991-1995 Eberhard Mattes
|
|---|
| 3 |
|
|---|
| 4 | This file is part of emxbind.
|
|---|
| 5 |
|
|---|
| 6 | emxbind is free software; you can redistribute it and/or modify it
|
|---|
| 7 | under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | emxbind is distributed in the hope that it will be useful,
|
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | GNU General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with emxbind; see the file COPYING. If not, write to
|
|---|
| 18 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
|---|
| 19 | Boston, MA 02111-1307, USA. */
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | #include <stdio.h>
|
|---|
| 23 | #include <stdlib.h>
|
|---|
| 24 | #include <string.h>
|
|---|
| 25 | #include "defs.h"
|
|---|
| 26 | #include "emxbind.h"
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 | /* Perform initializations for the bind operation. */
|
|---|
| 30 |
|
|---|
| 31 | static void init_bind (void)
|
|---|
| 32 | {
|
|---|
| 33 | if (dll_flag)
|
|---|
| 34 | {
|
|---|
| 35 | relocatable = TRUE;
|
|---|
| 36 | stack_size = 0;
|
|---|
| 37 | heap_size = 0;
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 | /* Change the application type. */
|
|---|
| 43 |
|
|---|
| 44 | static void exe_type (void)
|
|---|
| 45 | {
|
|---|
| 46 | read_os2_header ();
|
|---|
| 47 | exe_flags ();
|
|---|
| 48 | my_change (&out_file, &inp_file);
|
|---|
| 49 | my_seek (&out_file, inp_os2_pos);
|
|---|
| 50 | my_write (&os2_h, sizeof (os2_h), &out_file);
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 | /* Strip the symbols from a bound executable. */
|
|---|
| 55 |
|
|---|
| 56 | static void strip_symbols (void)
|
|---|
| 57 | {
|
|---|
| 58 | long size, pos, str_len;
|
|---|
| 59 |
|
|---|
| 60 | pos = a_in_pos + a_in_sym;
|
|---|
| 61 | size = my_size (&inp_file);
|
|---|
| 62 | if (pos + sizeof (str_len) <= size)
|
|---|
| 63 | {
|
|---|
| 64 | my_seek (&inp_file, pos);
|
|---|
| 65 | str_len = 4;
|
|---|
| 66 | my_write (&str_len, sizeof (str_len), &inp_file);
|
|---|
| 67 | my_trunc (&inp_file);
|
|---|
| 68 | a_in_h.a_syms = 0;
|
|---|
| 69 | my_seek (&inp_file, a_in_pos);
|
|---|
| 70 | my_write (&a_in_h, sizeof (a_in_h), &inp_file);
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | void cmd (int mode)
|
|---|
| 76 | {
|
|---|
| 77 | switch (mode)
|
|---|
| 78 | {
|
|---|
| 79 | case 'b':
|
|---|
| 80 |
|
|---|
| 81 | /* Bind an a.out file into an .exe file. */
|
|---|
| 82 |
|
|---|
| 83 | init_bind ();
|
|---|
| 84 | init_os2_header ();
|
|---|
| 85 | read_stub ();
|
|---|
| 86 | read_a_out_header ();
|
|---|
| 87 | if (opt_c != NULL)
|
|---|
| 88 | read_core ();
|
|---|
| 89 | read_res ();
|
|---|
| 90 | os2_fixup ();
|
|---|
| 91 | relocations ();
|
|---|
| 92 | sort_fixup ();
|
|---|
| 93 | set_exe_header ();
|
|---|
| 94 | set_os2_header ();
|
|---|
| 95 | write_header ();
|
|---|
| 96 | write_res ();
|
|---|
| 97 | copy_a_out ();
|
|---|
| 98 | write_nonres ();
|
|---|
| 99 | if (opt_m != NULL)
|
|---|
| 100 | write_map (opt_m);
|
|---|
| 101 | break;
|
|---|
| 102 |
|
|---|
| 103 | case 'e':
|
|---|
| 104 |
|
|---|
| 105 | /* Set the OS/2 application type. */
|
|---|
| 106 |
|
|---|
| 107 | exe_type ();
|
|---|
| 108 | break;
|
|---|
| 109 |
|
|---|
| 110 | case 's':
|
|---|
| 111 |
|
|---|
| 112 | /* Strip symbols. */
|
|---|
| 113 |
|
|---|
| 114 | strip_symbols ();
|
|---|
| 115 | break;
|
|---|
| 116 |
|
|---|
| 117 | default:
|
|---|
| 118 | abort ();
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|