-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
125 lines (108 loc) · 2.95 KB
/
main.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/****************************************************************************
*
* This code is Public Domain.
*
* ========================================================================
*
* Description: JWasm top level module
*
****************************************************************************/
#include <signal.h>
#include "globals.h"
#include "msgtext.h"
#include "cmdline.h"
#if defined(__UNIX__) || defined(__CYGWIN__) || defined(__DJGPP__)
#define WILDCARDS 0
#define CATCHBREAK 0
#else
#define WILDCARDS 1
#ifdef __POCC__
#define CATCHBREAK 0
#else
#define CATCHBREAK 1
#endif
#endif
#if WILDCARDS
#ifdef __UNIX__
#include <unistd.h>
#else
#include <io.h>
#endif
#endif
static void genfailure( int signo )
/*********************************/
{
#if CATCHBREAK
if (signo != SIGBREAK)
#else
if (signo != SIGTERM)
#endif
EmitError( GENERAL_FAILURE );
close_files();
exit( EXIT_FAILURE );
}
int main( int argc, char **argv )
/*******************************/
{
char *pEnv;
int numArgs = 0;
int numFiles = 0;
int rc = 0;
#if WILDCARDS
long fh; /* _findfirst/next/close() handle, must be long! */
struct _finddata_t finfo;
char drv[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_PATH];
#endif
#if 0 //def DEBUG_OUT /* DebugMsg() cannot be used that early */
int i;
for ( i = 1; i < argc; i++ ) {
printf("argv[%u]=>%s<\n", i, argv[i] );
}
#endif
pEnv = getenv( "JWASM" );
if ( pEnv == NULL )
pEnv = "";
argv[0] = pEnv;
#ifndef DEBUG_OUT
signal(SIGSEGV, genfailure);
#endif
#if CATCHBREAK
signal(SIGBREAK, genfailure);
#else
signal(SIGTERM, genfailure);
#endif
MsgInit();
while ( 1 ) {
if ( ParseCmdline( (const char **)argv, &numArgs ) == NULL )
break; /* exit if no source file name supplied */
numFiles++;
write_logo();
#if WILDCARDS
if ((fh = _findfirst( Options.names[ASM], &finfo )) == -1 ) {
DebugMsg(("main: _findfirst(%s) failed\n", Options.names[ASM] ));
EmitErr( CANNOT_OPEN_FILE, Options.names[ASM], ErrnoStr() );
break;
}
_splitpath( Options.names[ASM], drv, dir, NULL, NULL );
DebugMsg(("main: _splitpath(%s): drv=\"%s\" dir=\"%s\"\n", Options.names[ASM], drv, dir ));
do {
_makepath( fname, drv, dir, finfo.name, NULL );
DebugMsg(("main: _makepath(\"%s\", \"%s\", \"%s\")=\"%s\"\n", drv, dir, finfo.name, fname ));
rc = AssembleModule( fname ); /* assemble 1 module */
} while ( ( _findnext( fh, &finfo ) != -1 ) );
_findclose( fh );
#else
rc = AssembleModule( Options.names[ASM] );
#endif
};
CmdlineFini();
if ( numArgs == 0 ) {
write_logo();
printf( MsgGetEx( MSG_USAGE ) );
} else if ( numFiles == 0 )
EmitError( NO_FILENAME_SPECIFIED );
MsgFini();
return( 1 - rc ); /* zero if no errors */
}