annotate src/unexencap.c @ 22293:0544aa57ff27

(cperl-style-alist): New variable, since `c-mode' is no longer loaded. - (Somebody who uses the styles should check that they work OK!) - (a lot of work is needed, especially with new `cperl-fix-line-spacing'). Old value of style is memorized when choosing a new style, may be restored from the same menu. (cperl-perldoc, cperl-pod-to-manpage): New commands; thanks to Anthony Foiani <afoiani@uswest.com> and Nick Roberts <Nick.Roberts@src.bae.co.uk>. (`Perl doc', `Regexp'): New submenus (latter to allow short displays). (cperl-clobber-lisp-bindings): New cfg variable. (cperl-find-pods-heres): $a->y() is not y///. (cperl-after-block-p): Add save-excursion. (cperl-init-faces): Was failing. Init faces when loading `ps-print'. (cperl-toggle-autohelp): New command. (cperl-electric-paren): `while SPACE LESS' was buggy. (cperl-init-faces): `-text' in `[-text => 1]' was not highlighted. (cperl-after-block-p): was FALSE after `sub f {}'. (cperl-electric-keyword): `foreachmy', `formy' expanded too, Expands `=pod-directive'. (cperl-linefeed): behaves reasonable in POD-directive lines. (cperl-message-electric-keyword): new cfg variable. (cperl-electric-keyword): print a message, governed by `cperl-message-electric-keyword'. (cperl-electric-paren): Typing `}' was not checking for being block or not. (cperl-beautify-regexp-piece): Did not know about lookbehind; finding *which* level to work with was not intuitive. (cperl-beautify-levels): New command. (cperl-electric-keyword): Allow here-docs contain `=head1' and friends for keyword expansion. Fix for broken `font-lock-unfontify-region-function'. Should preserve `syntax-table' properties even with `lazy-lock'. (cperl-indent-region-fix-else): New command. (cperl-fix-line-spacing): New command. (cperl-invert-if-unless): New command (C-c C-t and in Menu). (cperl-hints): mention 20.2's goods/bads. (cperl-extra-newline-before-brace-multiline): Started to use it. (cperl-break-one-line-blocks-when-indent): New cfg variable. (cperl-fix-hanging-brace-when-indent): New cfg variable. (cperl-merge-trailing-else): New cfg variable. Workaround for another `font-lock's `syntax-table' text-property bug. `zerop' could be applied to nil. At last, may work with `font-lock' without setting `cperl-font-lock'. (cperl-indent-region-fix-constructs): Renamed from `cperl-indent-region-fix-constructs'. (cperl-fix-line-spacing): could be triggered inside strings, would not know what to do with BLOCKs of map/printf/etc. (cperl-merge-trailing-else): Handle `continue' too. (cperl-fix-line-spacing): Likewise. (cperl-calculate-indent): Knows about map/printf/etc before {BLOCK}; treat after-comma lines as continuation lines. (cperl-mode): `continue' made electric. (cperl-electric-keyword): Electric `do' inserts `do/while'. (cperl-fontify-syntaxically): New function. (cperl-syntaxify-by-font-lock): New cfg variable. Make syntaxification to be autoredone via `font-lock', switched on by `cperl-syntaxify-by-font-lock', off by default so far. Remove some commented out chunks. (cperl-set-style-back): Old value of style is memorized when choosing a new style, may be restored from the same menu. Mode-documentation added to micro-docs. (cperl-praise): updated. (cperl-toggle-construct-fix): New command. Added on C-c C-w and menu. (auto-fill-mode): added on C-c C-f and menu. (cperl-style-alist): `PerlStyle' style added. (cperl-find-pods-heres): Message for termination of scan corrected. (cperl-speed): New variable with hints. (cperl-electric-else): Make backspace electric after expansion of `else/continue' too. Fixed customization to honor cperl-hairy. Created customization groups. All the compile-time warnings fixed. (cperl-syntaxify-by-font-lock): Interaction with `font-lock-hot-pass' fixed. (cperl-after-block-and-statement-beg): It is BLOCK if we reach lim when backup sexp. (cperl-after-block-p, cperl-after-expr-p): Likewise. (cperl-indent-region): Make a marker for END - text added/removed. (cperl-style-alist): Include `cperl-merge-trailing-else' where the value is clear. (cperl-styles-entries): Likewise. (cperl-tips, cperl-problems): Improvements to docs.
author Richard M. Stallman <rms@gnu.org>
date Sat, 30 May 1998 15:43:16 +0000
parents 80cdb2387043
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Waiting for papers! */
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 /*
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 * Do an unexec() for coff encapsulation. Uses the approach I took
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 * for AKCL, so don't be surprised if it doesn't look too much like
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 * the other unexec() routines. Assumes NO_REMAP. Should be easy to
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 * adapt to the emacs style unexec() if that is desired, but this works
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 * just fine for me with GCC/GAS/GLD under System V. - Jordan
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 */
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 #include <sys/types.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 #include <sys/fcntl.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 #include <sys/file.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 #include <stdio.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 #include "/usr/gnu/lib/gcc/gcc-include/a.out.h"
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 filecpy(to, from, n)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 FILE *to, *from;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 register int n;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 char buffer[BUFSIZ];
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 for (;;)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 if (n > BUFSIZ) {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 fread(buffer, BUFSIZ, 1, from);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 fwrite(buffer, BUFSIZ, 1, to);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 n -= BUFSIZ;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 } else if (n > 0) {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 fread(buffer, 1, n, from);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 fwrite(buffer, 1, n, to);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 break;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 } else
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 break;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 /* ****************************************************************
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 * unexec
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 *
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 * driving logic.
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 * ****************************************************************/
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 unexec (new_name, a_name, data_start, bss_start, entry_address)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 char *new_name, *a_name;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 unsigned data_start, bss_start, entry_address;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 struct coffheader header1;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 struct coffscn *tp, *dp, *bp;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 struct exec header;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 int stsize;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 char *original_file = a_name;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 char *save_file = new_name;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 char *data_begin, *data_end;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 int original_data;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 FILE *original, *save;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 register int n;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 register char *p;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 extern char *sbrk();
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 char stdin_buf[BUFSIZ], stdout_buf[BUFSIZ];
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 fclose(stdin);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 original = fopen(original_file, "r");
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 if (stdin != original || original->_file != 0) {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 fprintf(stderr, "unexec: Can't open the original file.\n");
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 exit(1);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 setbuf(original, stdin_buf);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 fclose(stdout);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 unlink(save_file);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 n = open(save_file, O_CREAT|O_WRONLY, 0777);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 if (n != 1 || (save = fdopen(n, "w")) != stdout) {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 fprintf(stderr, "unexec: Can't open the save file.\n");
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 exit(1);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 setbuf(save, stdout_buf);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 fread(&header1, sizeof(header1), 1, original);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 tp = &header1.scns[0];
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 dp = &header1.scns[1];
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 bp = &header1.scns[2];
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 fread(&header, sizeof(header), 1, original);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 data_begin=(char *)N_DATADDR(header);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 data_end = sbrk(0);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 original_data = header.a_data;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 header.a_data = data_end - data_begin;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 header.a_bss = 0;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 dp->s_size = header.a_data;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 bp->s_paddr = dp->s_vaddr + dp->s_size;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 bp->s_vaddr = bp->s_paddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 bp->s_size = 0;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 header1.tsize = tp->s_size;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 header1.dsize = dp->s_size;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 header1.bsize = bp->s_size;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 fwrite(&header1, sizeof(header1), 1, save);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 fwrite(&header, sizeof(header), 1, save);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 filecpy(save, original, header.a_text);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 for (n = header.a_data, p = data_begin; ; n -= BUFSIZ, p += BUFSIZ)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 if (n > BUFSIZ)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 fwrite(p, BUFSIZ, 1, save);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 else if (n > 0) {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 fwrite(p, 1, n, save);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 break;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 } else
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 break;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 fseek(original, original_data, 1);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 filecpy(save, original, header.a_syms+header.a_trsize+header.a_drsize);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 fread(&stsize, sizeof(stsize), 1, original);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 fwrite(&stsize, sizeof(stsize), 1, save);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 filecpy(save, original, stsize - sizeof(stsize));
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 fclose(original);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 fclose(save);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 }