~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* defining IN_SFASL gets us fopen_binary  */
#define IN_RSYM

#include "config.h"
#include <stdio.h>
#include "ext_sym.h"




struct lsymbol_table tab;

int main(int argc,char *argv[],char **envp)
{
    char buf[1000];
    char *in = argv[1];
    char *out = argv[2];
    if ( argc != 3 ) {
        perror("bad arg count");
        fflush(stdout);
        exit(1);
    }

    fprintf ( stderr, "rsym_nt: %s %s\n", in, out );
    sprintf ( buf, "nm -g %s > _rsym1", argv[1] );
    if ( system ( buf ) ) {
        printf("failed: %s", buf);
        exit(1);
    }
    {
        FILE *fp = fopen("_rsym1","rb");
        FILE *symout;
        char buf1[1000];
        symout = fopen ( out, "wb" );
        if ( !symout ) {
            perror ( out );
            exit ( 1 );
        };
        tab.n_symbols=0;
        tab.tot_leng=0;
        fseek( symout, sizeof ( struct lsymbol_table ), 0 );
        {
            int addr;
            char ch;
            char *name;
            char name1[1000];

            while (1) {
                name = name1;
                fgets(buf1,sizeof(buf1),fp);
                if ( 3 == sscanf ( buf1, "%x %c %s", &addr, &ch, name )
                     && ch != '?' ) {
                    tab.n_symbols++;
                    fwrite ( (char *)&addr, sizeof ( int ), 1, symout );
                    while ( tab.tot_leng++, *name )
                        putc ( *name++, symout );
                    putc ( 0, symout );
                }
                if ( feof ( fp ) ) break;
            }
            fseek ( symout, 0, 0 );
            fwrite ( &tab, sizeof ( tab ), 1, symout );
            
            fclose ( symout );
        }
    }
    exit ( 0 );
}