~ubuntu-branches/ubuntu/intrepid/dis51/intrepid

« back to all changes in this revision

Viewing changes to main.c

  • Committer: Bazaar Package Importer
  • Author(s): Uwe Hermann
  • Date: 2008-02-17 15:52:20 UTC
  • Revision ID: james.westby@ubuntu.com-20080217155220-mnsnjsovxvw46y0i
Tags: upstream-0.5
ImportĀ upstreamĀ versionĀ 0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* main.c
 
2
 *
 
3
 * Main function for Dis51.
 
4
 *
 
5
 * Copyright 2001 - 2003 by David Sullins
 
6
 *
 
7
 * This file is part of Dis51.
 
8
 * 
 
9
 * Dis51 is free software; you can redistribute it and/or modify it under the
 
10
 * terms of the GNU General Public License as published by the Free Software
 
11
 * Foundation, version 2 of the License.
 
12
 * 
 
13
 * Dis51 is distributed in the hope that it will be useful, but WITHOUT ANY
 
14
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
16
 * details.
 
17
 * 
 
18
 * You should have received a copy of the GNU General Public License along with
 
19
 * Dis51; if not, write to the Free Software Foundation, Inc., 59 Temple
 
20
 * Place, Suite 330, Boston, MA 02111-1307 USA
 
21
 * 
 
22
 * You may contact the author at davesullins@earthlink.net.
 
23
 *
 
24
 * HISTORY:
 
25
 * 0.4, 3 Nov 2003: Only documentation changes.
 
26
 * 0.3, 14 Feb 2003: Updated for newer libhexfile.
 
27
 * 0.2: first numbered version, updated for new libhexfile.
 
28
 */
 
29
 
 
30
#include <stdio.h>
 
31
#include <stdlib.h>
 
32
#include <string.h>
 
33
#include <hexfile.h>
 
34
#include "global.h"
 
35
#include "pass1.h"
 
36
#include "pass2.h"
 
37
 
 
38
int main(int argc, char **argv)
 
39
{
 
40
        struct hexfile hf;
 
41
        int i;
 
42
        int entry = 0;
 
43
        char *p, *q;
 
44
        unsigned long ul; 
 
45
        
 
46
        Lst = 0;
 
47
        
 
48
        /* clear memory */
 
49
        memset(lbl, 0, 65536*2);
 
50
        
 
51
        /* read hex file from stdin */
 
52
        if (init_hexfile(&hf, 65536, stdin, NULL)) {
 
53
                fprintf(stderr, "Error opening hex file.\n");
 
54
                exit(1);
 
55
        }
 
56
        if (read_hex(&hf)) {
 
57
                fprintf(stderr, "Error reading hex file.\n");
 
58
                exit(1);
 
59
        }
 
60
        
 
61
        if (argc > 1) {
 
62
                i = 1;
 
63
                /* Set listing mode */
 
64
                if(!strcmp(argv[i],"-l")) {
 
65
                        Lst=1;
 
66
                        ++i;
 
67
                        /* use entry point 0 if none given on command line */
 
68
                        if (argc == i)
 
69
                                pass1(&hf, 0);
 
70
                }
 
71
 
 
72
                /* use entry points from command line */
 
73
                for (; i < argc; ++i) {
 
74
                        if(!Lst)
 
75
                                sscanf(argv[i], "%d", &entry);
 
76
                        else {
 
77
                                p = q = argv[i];
 
78
                                if(*p == '\0') {
 
79
                                        fprintf(stderr, "Warning: NULL argument on command line.\n");
 
80
                                        continue;
 
81
                                }
 
82
                                ul = strtoul(p, &q, 0);
 
83
                                if(*q != 0) {
 
84
                                        fprintf(stderr, "Error: Bad address '%s'. Abort\n", argv[i]);
 
85
                                        exit(1);
 
86
                                }
 
87
                                entry = (int)ul;
 
88
                        }
 
89
                        pass1(&hf, entry);
 
90
                }
 
91
        }
 
92
        else
 
93
                /* use entry point 0 if none given on command line */
 
94
                pass1(&hf, 0);
 
95
        
 
96
        /* disassemble to stdout */
 
97
        pass2(stdout, &hf);
 
98
 
 
99
        return 0;
 
100
}