home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
SRC
/
unc.lzh
/
UNC
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-12
|
6KB
|
269 lines
/*
* SCCS: %W% %G% %U%
* Main routine etc.
*
*EMACS_MODES:c
*/
#define VERSION "OSK V. 1.0 June 1991 reto/hcz"
#include <stdio.h>
#define __MAIN__
#include "a.out.h"
#include "osk.h"
#include "ctype.h"
#include "unc.h"
#define LINELNG 70
void inturdat(), intutext(), intudat(), intlsym(), bfclose();
void ptext(), pdata(), pabs(), lscan(), usage();
char *strdup();
extern int par_entry, par_round; /* 68000 parameters */
extern int nmods; /* Number of modules it looks like */
char *tfnam = "split";
char *fnam = NULL, *ofnam;
int ipath;
char lsyms; /* Generate local symbols */
extern char noabs; /* No non-global absolutes */
int rel; /* File being analysed is relocatable */
extern int lpos;
symbol dosymb();
extern int errno;
void clean(err)
{
bfclose(&mainfile);
exit(err);
}
/*
* Open binary files. Arrange to erase them when finished.
*/
void bfopen(nam, fid)
char *nam;
ef_fid fid;
{
char fnam[80];
(void) sprintf(fnam, "%s.tx", nam);
if ((fid->ef_t = open(fnam, O_RDWR|O_CREAT, 0666)) < 0) {
efil: (void) fprintf(stderr, "Help could not open %s\n", fnam);
exit(4);
}
fid->t_name = strdup(fnam);
(void) sprintf(fnam, "%s.dt", nam);
if ((fid->ef_d = open(fnam, O_RDWR|O_CREAT, 0666)) < 0)
goto efil;
fid->d_name = strdup(fnam);
}
/*
* Close binary files. They should get zapped anyway.
*/
void bfclose(fid)
ef_fid fid;
{
(void) close(fid->ef_t);
(void) close(fid->ef_d);
unlink(fid->t_name);
unlink(fid->d_name);
}
/*
* Main routine.
*/
main(argc, argv)
int argc;
char *argv[];
{
int i;
char *progname = argv[0];
char *msg;
register struct libit *lfd;
setbuf(stdout,NULL);
setbuf(stderr,NULL);
popt = ropt = 0;
verbose = 1;
getparms(argc, argv);
if (fnam == 0)
{
usage();
clean(_errmsg(1, "No input file"));
}
bfopen(tfnam, &mainfile);
if ((ipath = open(fnam, O_RDONLY, 0)) < 0)
clean(_errmsg(errno, "cannot open '%s'\n", fnam));
if (verbose) (void) fprintf(stderr, "Scanning text\n");
if ( (rtext(ipath, &mainfile) != ISOK)
|| rdata(ipath, &mainfile) != ISOK)
clean(_errmsg(1, "Bad format input file - reading %s\n", fnam));
(void) close(lfd->lf_fd);
if (verbose) (void) fprintf(stderr, "End of input\n");
if (mainfile.ef_stvec != NULL)
{
free(mainfile.ef_stvec);
mainfile.ef_stvec = NULL;
mainfile.ef_stcnt = 0;
}
if (verbose)
(void) fprintf(stderr, "Text anal 1\n");
intutext();
if (verbose)
(void) fprintf(stderr, "Text anal 2\n");
if (lsyms) {
if (verbose)
(void) fprintf(stderr, "Local symbol scan\n");
/* intlsym(); hcz */
}
pabs();
ptext(&mainfile);
pdata(&mainfile);
bfclose(&mainfile);
clean(0);
}
/*
* Talk about implemented things.....
*/
void unimpl(msg)
char *msg;
{
(void) fprintf(stderr, "Warning: handling of \"%s\" not implemented\n", msg);
}
int getparms(argc, argv)
int argc;
char *argv[];
{
char c, *parm, *getstr();
int i;
for (i=1; i < argc; i++)
{
parm = argv[i];
if(*parm != '-')
{
if (fnam == NULL)
fnam = parm;
else
clean(_errmsg(1, "illegal argument '%s'\n", parm));
continue;
}
parm++;
while( (c = *parm++) != '\0')
switch( tolower(c) )
{
case 'd': debug++; break;
case 'x': xact=getint(&parm,1); break;
case 's': lsyms++; break;
case 'q': verbose=getint(&parm, 0);
case 'p': popt = getint(&parm, 1);
case 'a': noabs++; break;
case 'r': ropt++; break;
/* case 'o':
ofnam=getstr(&parm, NULL);
if (ofnam == NULL)
clean(_errmsg(1, "missing output filename"));
if (reopen(ofnam, "w", stdout) == 0)
clean(_errmsg(errno, "can't open %s", ofnam));
break; */
case '?': usage(); clean(0); break;
case 'v': fputs(VERSION, stderr); clean(0);
default:
usage();
clean(_errmsg(1, "illegal option '%c'\n", c)) ;
}
}
}
/* getint(&par) und getstr(&par) untersuchen den String ab **par.
* *par wird erhöht und steht 1 hinter dem letzten erkannten Zeichen
* bei ungültigem oder nicht vorhandenem Argument wird der übergebene
* Defaultwert zurückgegeben.
*/
int getint(par, difauld)
char **par;
int difauld;
{
int i;
if (**par == '=')
++*par;
if (isdigit(**par))
i = atoi(*par); /* Zahl zurückgeben */
else
i = difauld;
while (isdigit(**par)) /* skippen bis Zahlende */
++*par;
return(i);
}
int gethex(par, difauld)
char **par;
int difauld;
{
int i;
if (**par == '=')
++*par;
if (**par == '0' || **par == '$')
++*par;
if (**par == 'x' || **par == 'X')
++*par;
if (sscanf(*par, "%x", &i) != 1)
i = difauld; /* nix gefunden */
while (isxdigit(**par)) /* skippen bis Zahlende */
++*par;
return(i);
}
char *getstr(par, difauld)
char **par, *difauld;
{
char *cp;
if (**par == '=')
++*par;
if (**par != '\0')
{
cp = *par; /* Übergabe: Stringbeginn */
while(**par) ++*par; /* skippen bis Stringende */
return(cp);
}
return(difauld);
}
void usage()
{
fputs(
"\
Syntax: unc {-<opts>} <file> {-<opts>}\n\
Funkcion: 68k Disassembler\n\
Options: -p print address and opcode values too\n\
-x=<n> exactness mode\n\
<n> = 0: Best guess,\n\
1: no check for labels falling into instruction argument,\n\
2: as above plus no check for bad jsr/bxx thread,\n\
3: don't check instruction thread at all\n\
-d debug mode\n\
"
, stderr); fputs("\
"
, stderr);
}