/* symorder orderlist symbolfile
* orderlist is a file containing symbols to be found in symbolfile,
* symbolfile is updated in place to put the requested symbols first
* in the symbol table, in the order specified. This is done
* by swapping the old symbols in the required spots with the
* new ones. If all of the order symbols are not found, an
* Modelled after nlist.c the nlist subroutine, which has been
* modified to succeed as soon as all sought symbols are found.
* This program was specifically designed to cut down on the read
* overhead of systat(ss) when getting symbols from /unix.
int a_magic
[] = {A_MAGIC1
, A_MAGIC2
, A_MAGIC3
, A_MAGIC4
, 0};
register struct nlist
*p
, *q
;
register int sa
, na
, i
, j
;
int nsym
= 0, symfound
= 0, n
, o
;
struct nlist order
[SPACE
];
fprintf(stderr
, "Usage: symorder orderlist file\n");
if((f
= fopen(argv
[1], "r")) == NULL
) {
fprintf(stderr
, "Can't open "); perror(argv
[1]);
for(p
= order
; fgets(buf
, sizeof buf
, f
) != NULL
; p
++, nsym
++)
for(i
= 0; i
< 8 && buf
[i
] != '\n'; i
++)
/*** for(i = 0; i < nsym; i++) ***/
/*** printf("\"%.8s\"\n", order[i].n_name); ***/
/*** printf("--------\n"); ***/
if((f
= fopen(argv
[2], "r")) == NULL
) {
fprintf(stderr
, "Can't open "); perror(argv
[2]);
if((o
= open(argv
[2], 1)) < 0) {
fprintf(stderr
, "Can't update "); perror(argv
[2]);
if((fread(&exec
, sizeof exec
, 1, f
)) != 1) {
fprintf(stderr
, "Can't read "); perror(argv
[2]);
for(i
=0; a_magic
[i
]; i
++)
if(a_magic
[i
] == exec
.a_magic
) break;
fprintf(stderr
, "Bad Header on %s\n", argv
[2]);
sa
= exec
.a_text
+ exec
.a_data
;
sa
+= exec
.a_trsize
+ exec
.a_drsize
;
while(n
&& symfound
< nsym
) {
if(fread(&nl1
, sizeof nl1
, 1, f
) != 1) {
fprintf(stderr
, "Short file "); perror(argv
[2]);
/*** printf("\"%.8s\"\n", nl1.n_name); ***/
/*** printf("Trying "); ***/
for(j
= 0; j
< nsym
; j
++) {
/*** printf("%s ", order[j].n_name); ***/
if(nl1
.n_name
[i
] != order
[j
].n_name
[i
])
/*** printf("Found: %.8s\n", nl1.n_name); ***/
fseek(f
, (i
= (sa
+(j
* sizeof nl1
))), 0);
if(fread(&nl2
, sizeof nl2
, 1, f
) != 1)
printf("Read err on 2nd sym\n");
if(write(o
, &nl1
, sizeof nl1
) == -1)
lseek(o
, na
-sizeof nl1
, 0);
if(write(o
, &nl2
, sizeof nl2
) == -1)
fprintf(stderr
, "%d Syms not found:\n", nsym
- symfound
);
for (i
= 0; i
< nsym
; i
++) {
if (order
[i
].n_value
== 0)
printf("%.8s\n", order
[i
].n_name
);