-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
147 lines (127 loc) · 3.62 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/****************************************************************************
*
* This code is Public Domain.
*
* ========================================================================
*
* Description: JWasm top level module
*
****************************************************************************/
#include <signal.h>
#include "globals.h"
#include "msgtext.h"
#include "cmdline.h"
#include "input.h" /* GetFNamePart() */
#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
#ifdef TRMEM
void tm_Init( void );
void tm_Fini( void );
#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
/* v2.11: _findfirst/next/close() handle, should be of type intptr_t.
* since this type isn't necessarily defined, type long is used as substitute.
*/
long fh;
const char *pfn;
int dirsize;
struct _finddata_t finfo;
char fname[FILENAME_MAX];
#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
#ifdef TRMEM
tm_Init();
#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
/* ParseCmdLine() returns NULL if no source file name has been found (anymore) */
while ( ParseCmdline( (const char **)argv, &numArgs ) ) {
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;
}
/* v2.12: _splitpath()/_makepath() removed */
//_splitpath( Options.names[ASM], drv, dir, NULL, NULL );
//DebugMsg(("main: _splitpath(%s): drv=\"%s\" dir=\"%s\"\n", Options.names[ASM], drv, dir ));
pfn = GetFNamePart( Options.names[ASM] );
dirsize = pfn - Options.names[ASM];
memcpy( fname, Options.names[ASM], dirsize );
do {
/* v2.12: _splitpath()/_makepath() removed */
//_makepath( fname, drv, dir, finfo.name, NULL );
//DebugMsg(("main: _makepath(\"%s\", \"%s\", \"%s\")=\"%s\"\n", drv, dir, finfo.name, fname ));
strcpy( &fname[dirsize], finfo.name );
DebugMsg(("main: fname=%s\n", 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( "%s", MsgGetEx( MSG_USAGE ) );
} else if ( numFiles == 0 )
EmitError( NO_FILENAME_SPECIFIED );
#ifdef TRMEM
tm_Fini();
#endif
DebugMsg(("main: exit, return code=%u\n", 1 - rc ));
return( 1 - rc ); /* zero if no errors */
}