summaryrefslogtreecommitdiff
path: root/src/tools/asm/q3asm.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2009-10-03 11:52:53 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:15:28 +0000
commitb47a49a03370e7ea42f47623b9f72a5ca799f0e7 (patch)
tree9d64d778ded2971d7ebd05970d903d886bd81436 /src/tools/asm/q3asm.c
parent09ceb08b95978feb0a9b737f22ac0f662c7465d6 (diff)
* Merge ioq3-r1423
+ IPv6 + VoIP + Stereo rendering + Other minor stuff
Diffstat (limited to 'src/tools/asm/q3asm.c')
-rw-r--r--src/tools/asm/q3asm.c99
1 files changed, 52 insertions, 47 deletions
diff --git a/src/tools/asm/q3asm.c b/src/tools/asm/q3asm.c
index 1ac2939e..3c334815 100644
--- a/src/tools/asm/q3asm.c
+++ b/src/tools/asm/q3asm.c
@@ -132,7 +132,7 @@ typedef enum {
DATASEG, // initialized 32 bit data, will be byte swapped
LITSEG, // strings
BSSSEG, // 0 filled
- JTRGSEG, // psuedo-segment that contains only jump table targets
+ JTRGSEG, // pseudo-segment that contains only jump table targets
NUM_SEGMENTS
} segmentName_t;
@@ -227,16 +227,14 @@ int opcodesHash[ NUM_SOURCE_OPS ];
-int
-vreport (const char* fmt, va_list vp)
+static int vreport (const char* fmt, va_list vp)
{
if (options.verbose != qtrue)
return 0;
return vprintf(fmt, vp);
}
-int
-report (const char *fmt, ...)
+static int report (const char *fmt, ...)
{
va_list va;
int retval;
@@ -249,16 +247,14 @@ report (const char *fmt, ...)
/* The chain-and-bucket hash table. -PH */
-void
-hashtable_init (hashtable_t *H, int buckets)
+static void hashtable_init (hashtable_t *H, int buckets)
{
H->buckets = buckets;
H->table = calloc(H->buckets, sizeof(*(H->table)));
return;
}
-hashtable_t *
-hashtable_new (int buckets)
+static hashtable_t *hashtable_new (int buckets)
{
hashtable_t *H;
@@ -269,8 +265,7 @@ hashtable_new (int buckets)
/* No destroy/destructor. No need. */
-void
-hashtable_add (hashtable_t *H, int hashvalue, void *datum)
+static void hashtable_add (hashtable_t *H, int hashvalue, void *datum)
{
hashchain_t *hc, **hb;
@@ -294,15 +289,13 @@ hashtable_add (hashtable_t *H, int hashvalue, void *datum)
return;
}
-hashchain_t *
-hashtable_get (hashtable_t *H, int hashvalue)
+static hashchain_t *hashtable_get (hashtable_t *H, int hashvalue)
{
hashvalue = (abs(hashvalue) % H->buckets);
return (H->table[hashvalue]);
}
-void
-hashtable_stats (hashtable_t *H)
+static void hashtable_stats (hashtable_t *H)
{
int len, empties, longest, nodes;
int i;
@@ -342,8 +335,7 @@ hashtable_stats (hashtable_t *H)
/* Kludge. */
/* Check if symbol already exists. */
/* Returns 0 if symbol does NOT already exist, non-zero otherwise. */
-int
-hashtable_symbol_exists (hashtable_t *H, int hash, char *sym)
+static int hashtable_symbol_exists (hashtable_t *H, int hash, char *sym)
{
hashchain_t *hc;
symbol_t *s;
@@ -373,8 +365,7 @@ hashtable_symbol_exists (hashtable_t *H, int hash, char *sym)
/* Comparator function for quicksorting. */
-int
-symlist_cmp (const void *e1, const void *e2)
+static int symlist_cmp (const void *e1, const void *e2)
{
const symbol_t *a, *b;
@@ -390,8 +381,7 @@ symlist_cmp (const void *e1, const void *e2)
However, qsort(3) already exists, and I'm really lazy.
-PH
*/
-void
-sort_symbols ()
+static void sort_symbols ()
{
int i, elems;
symbol_t *s;
@@ -440,7 +430,7 @@ sort_symbols ()
This function is one big evil hack to work around this problem.
*/
-int atoiNoCap (const char *s)
+static int atoiNoCap (const char *s)
{
INT64 l;
union {
@@ -466,7 +456,7 @@ HashString
=============
*/
/* Default hash function of Kazlib 1.19, slightly modified. */
-unsigned int HashString (const char *key)
+static unsigned int HashString (const char *key)
{
static unsigned long randbox[] = {
0x49848f1bU, 0xe6255dbaU, 0x36da5bdcU, 0x47bf94e9U,
@@ -495,7 +485,7 @@ unsigned int HashString (const char *key)
CodeError
============
*/
-void CodeError( char *fmt, ... ) {
+static void CodeError( char *fmt, ... ) {
va_list argptr;
errorCount++;
@@ -512,7 +502,7 @@ void CodeError( char *fmt, ... ) {
EmitByte
============
*/
-void EmitByte( segment_t *seg, int v ) {
+static void EmitByte( segment_t *seg, int v ) {
if ( seg->imageUsed >= MAX_IMAGE ) {
Error( "MAX_IMAGE" );
}
@@ -525,7 +515,7 @@ void EmitByte( segment_t *seg, int v ) {
EmitInt
============
*/
-void EmitInt( segment_t *seg, int v ) {
+static void EmitInt( segment_t *seg, int v ) {
if ( seg->imageUsed >= MAX_IMAGE - 4) {
Error( "MAX_IMAGE" );
}
@@ -543,7 +533,7 @@ DefineSymbol
Symbols can only be defined on pass 0
============
*/
-void DefineSymbol( char *sym, int value ) {
+static void DefineSymbol( char *sym, int value ) {
/* Hand optimization by PhaethonH */
symbol_t *s;
char expanded[MAX_LINE_LENGTH];
@@ -599,7 +589,7 @@ LookupSymbol
Symbols can only be evaluated on pass 1
============
*/
-int LookupSymbol( char *sym ) {
+static int LookupSymbol( char *sym ) {
symbol_t *s;
char expanded[MAX_LINE_LENGTH];
int hash;
@@ -647,7 +637,7 @@ If a full line isn't parsed, returns NULL
Otherwise returns the updated parse pointer
===============
*/
-char *ExtractLine( char *data ) {
+static char *ExtractLine( char *data ) {
/* Goal:
Given a string `data', extract one text line into buffer `lineBuffer' that
is no longer than MAX_LINE_LENGTH characters long. Return value is
@@ -689,7 +679,7 @@ Parse
Parse a token out of linebuffer
==============
*/
-qboolean Parse( void ) {
+static qboolean Parse( void ) {
/* Hand-optimized by PhaethonH */
const char *p, *q;
@@ -725,7 +715,7 @@ qboolean Parse( void ) {
ParseValue
==============
*/
-int ParseValue( void ) {
+static int ParseValue( void ) {
Parse();
return atoiNoCap( token );
}
@@ -736,7 +726,7 @@ int ParseValue( void ) {
ParseExpression
==============
*/
-int ParseExpression(void) {
+static int ParseExpression(void) {
/* Hand optimization, PhaethonH */
int i, j;
char sym[MAX_LINE_LENGTH];
@@ -807,7 +797,7 @@ Note that the lit segment is read-write in the VM, so strings
aren't read only as in some architectures.
==============
*/
-void HackToSegment( segmentName_t seg ) {
+static void HackToSegment( segmentName_t seg ) {
if ( currentSegment == &segment[seg] ) {
return;
}
@@ -1166,7 +1156,7 @@ AssembleLine
==============
*/
-void AssembleLine( void ) {
+static void AssembleLine( void ) {
hashchain_t *hc;
sourceOps_t *op;
int i;
@@ -1321,7 +1311,7 @@ void InitTables( void ) {
WriteMapFile
==============
*/
-void WriteMapFile( void ) {
+static void WriteMapFile( void ) {
FILE *f;
symbol_t *s;
char imageName[MAX_OS_PATH];
@@ -1353,7 +1343,7 @@ void WriteMapFile( void ) {
WriteVmFile
===============
*/
-void WriteVmFile( void ) {
+static void WriteVmFile( void ) {
char imageName[MAX_OS_PATH];
vmHeader_t header;
FILE *f;
@@ -1432,7 +1422,7 @@ void WriteVmFile( void ) {
Assemble
===============
*/
-void Assemble( void ) {
+static void Assemble( void ) {
int i;
char filename[MAX_OS_PATH];
char *ptr;
@@ -1499,7 +1489,7 @@ ParseOptionFile
=============
*/
-void ParseOptionFile( const char *filename ) {
+static void ParseOptionFile( const char *filename ) {
char expanded[MAX_OS_PATH];
char *text, *text_p;
@@ -1527,6 +1517,19 @@ void ParseOptionFile( const char *filename ) {
}
}
+static void ShowHelp( char *argv0 ) {
+ Error("Usage: %s [OPTION]... [FILES]...\n\
+Assemble LCC bytecode assembly to Q3VM bytecode.\n\
+\n\
+ -o OUTPUT Write assembled output to file OUTPUT.qvm\n\
+ -f LISTFILE Read options and list of files to assemble from LISTFILE.q3asm\n\
+ -b BUCKETS Set symbol hash table to BUCKETS buckets\n\
+ -v Verbose compilation report\n\
+ -vq3 Produce a qvm file compatible with Q3 1.32b\n\
+ -h --help -? Show this help\n\
+", argv0);
+}
+
/*
==============
main
@@ -1539,15 +1542,7 @@ int main( int argc, char **argv ) {
// _chdir( "/quake3/jccode/cgame/lccout" ); // hack for vc profiler
if ( argc < 2 ) {
- Error("Usage: %s [OPTION]... [FILES]...\n\
-Assemble LCC bytecode assembly to Q3VM bytecode.\n\
-\n\
- -o OUTPUT Write assembled output to file OUTPUT.qvm\n\
- -f LISTFILE Read options and list of files to assemble from LISTFILE\n\
- -b BUCKETS Set symbol hash table to BUCKETS buckets\n\
- -v Verbose compilation report\n\
- -vq3 Produce a qvm file compatible with Q3 1.32b\n\
-", argv[0]);
+ ShowHelp( argv[0] );
}
start = I_FloatTime ();
@@ -1560,6 +1555,12 @@ Assemble LCC bytecode assembly to Q3VM bytecode.\n\
if ( argv[i][0] != '-' ) {
break;
}
+ if( !strcmp( argv[ i ], "-h" ) ||
+ !strcmp( argv[ i ], "--help" ) ||
+ !strcmp( argv[ i ], "-?") ) {
+ ShowHelp( argv[0] );
+ }
+
if ( !strcmp( argv[i], "-o" ) ) {
if ( i == argc - 1 ) {
Error( "-o must preceed a filename" );
@@ -1616,6 +1617,10 @@ Motivation: not wanting to scrollback for pages to find asm error.
asmFileNames[ numAsmFiles ] = copystring( argv[ i ] );
numAsmFiles++;
}
+ // In some case it Segfault without this check
+ if ( numAsmFiles == 0 ) {
+ Error( "No file to assemble\n" );
+ }
InitTables();
Assemble();