use stdarg when compiling with ANSI C compiler

This commit is contained in:
ceriel 1995-08-18 07:26:18 +00:00
parent 1aa9149ff9
commit b9a67e72ca
5 changed files with 131 additions and 2 deletions

View file

@ -21,9 +21,14 @@
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <varargs.h>
#include <stdio.h> #include <stdio.h>
#include <em_path.h> #include <em_path.h>
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
/* /*
Version producing cc-compatible .o files in one pass. Version producing cc-compatible .o files in one pass.
@ -117,7 +122,11 @@ int c_flag = 0;
int v_flag = 0; int v_flag = 0;
int O_flag = 0; int O_flag = 0;
#if __STDC__
char *mkstr(char *, ...);
#else
char *mkstr(); char *mkstr();
#endif
char *malloc(); char *malloc();
char *alloc(); char *alloc();
char *extension(); char *extension();
@ -483,6 +492,32 @@ concat(al1, al2)
} }
} }
#if __STDC__
/*VARARGS*/
char *
mkstr(char *dst, ...)
{
va_list ap;
va_start(ap, dst);
{
register char *p;
register char *q;
q = dst;
p = va_arg(ap, char *);
while (p) {
while (*q++ = *p++);
q--;
p = va_arg(ap, char *);
}
}
va_end(ap);
return dst;
}
#else
/*VARARGS*/ /*VARARGS*/
char * char *
mkstr(va_alist) mkstr(va_alist)
@ -509,6 +544,7 @@ mkstr(va_alist)
return dst; return dst;
} }
#endif
basename(str, dst) basename(str, dst)
char *str; char *str;

View file

@ -1,6 +1,11 @@
#include <ctype.h> #include <ctype.h>
#include <system.h> #include <system.h>
#if __STDC__
#include <stdarg.h>
extern out(char *, ...);
#else
#include <varargs.h> #include <varargs.h>
#endif
#define CODE_EXPANDER #define CODE_EXPANDER
#include "em.h" #include "em.h"
@ -99,6 +104,17 @@ int seg;
} }
} }
#if __STDC__
/*VARARGS*/
out(char *fmt, ...)
{
va_list pvar;
va_start(pvar, fmt);
doprnt( outfile, fmt, pvar);
va_end(pvar);
}
#else
/*VARARGS*/ /*VARARGS*/
out(va_alist) out(va_alist)
va_dcl va_dcl
@ -111,6 +127,7 @@ va_dcl
doprnt( outfile, fmt, pvar); doprnt( outfile, fmt, pvar);
va_end(pvar); va_end(pvar);
} }
#endif
char *suffix( str, suf) char *suffix( str, suf)
char *str, *suf; char *str, *suf;

View file

@ -1,4 +1,10 @@
#include "varargs.h" #if __STDC__
#include <stdarg.h>
extern out(char *, ...);
extern error(char *, ...);
#else
#include <varargs.h>
#endif
#include "decl.h" #include "decl.h"
/* All the functions in this file will be called by the parser. /* All the functions in this file will be called by the parser.
@ -208,6 +214,32 @@ operand_clean()
n_ops = 0; n_ops = 0;
} }
#if __STDC__
/*VARARGS*/
out(char *fmt, ...)
{
va_list pvar;
va_start(pvar, fmt);
doprnt( outfile, fmt, pvar);
va_end(pvar);
}
extern int nerrors;
/*VARARGS*/
error(char *fmt, ...)
{
va_list pvar;
nerrors++;
va_start(pvar, fmt);
fprint( STDERR, "!! ERROR : ");
doprnt( STDERR, fmt, pvar);
fprint( STDERR, " !!\n");
va_end(pvar);
}
#else
/*VARARGS*/ /*VARARGS*/
out(va_alist) out(va_alist)
va_dcl va_dcl
@ -238,6 +270,7 @@ va_dcl
fprint( STDERR, " !!\n"); fprint( STDERR, " !!\n");
va_end(pvar); va_end(pvar);
} }
#endif
inc_ops() inc_ops()
{ {

View file

@ -1,7 +1,12 @@
#include <ctype.h> #include <ctype.h>
#include <system.h> #include <system.h>
#include <stdio.h> #include <stdio.h>
#if __STDC__
#include <stdarg.h>
extern error(char *, ...);
#else
#include <varargs.h> #include <varargs.h>
#endif
#include "as.h" #include "as.h"
#include "const.h" #include "const.h"
@ -224,6 +229,22 @@ char *mnem;
/*** Error ****************************************************************/ /*** Error ****************************************************************/
#if __STDC__
/*VARARGS*/
error(char *fmt, ...)
{
va_list args;
extern int yylineno;
extern int nerrors;
va_start(args, fmt);
fprint( STDERR, "ERROR in line %d : ", yylineno);
doprnt( STDERR, fmt, args);
fprint( STDERR, "\n");
va_end(args);
nerrors++;
}
#else
/*VARARGS*/ /*VARARGS*/
error(va_alist) error(va_alist)
va_dcl va_dcl
@ -241,3 +262,4 @@ error(va_alist)
va_end(args); va_end(args);
nerrors++; nerrors++;
} }
#endif

View file

@ -4,7 +4,11 @@
#include "header.h" #include "header.h"
#include "back.h" #include "back.h"
#include "mach.h" #include "mach.h"
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h> #include <varargs.h>
#endif
/* Mysprint() stores the string directly in the string_arae. This saves /* Mysprint() stores the string directly in the string_arae. This saves
* a copy action. It is assumed that the strings stored in the string-table * a copy action. It is assumed that the strings stored in the string-table
@ -13,6 +17,22 @@
#define MAXSTRLEN 1024 #define MAXSTRLEN 1024
#if __STDC__
/*VARARGS*/
static int mysprint(char *fmt, ...)
{
va_list args;
int retval;
va_start(args, fmt);
while (string + MAXSTRLEN - string_area > size_string)
mem_string();
retval = _format(string, fmt, args);
string[retval] = '\0';
va_end(args);
return retval;
}
#else
/*VARARGS*/ /*VARARGS*/
static int mysprint(va_alist) static int mysprint(va_alist)
va_dcl va_dcl
@ -30,6 +50,7 @@ static int mysprint(va_alist)
va_end(args); va_end(args);
return retval; return retval;
} }
#endif
/* The extnd_*()s make a name unique. The resulting string is directly stored /* The extnd_*()s make a name unique. The resulting string is directly stored
* in the symbol_table (by mysprint()). Later additional fields in the * in the symbol_table (by mysprint()). Later additional fields in the