summaryrefslogtreecommitdiff
path: root/cpp/cpp.c
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>2005-01-23 15:31:04 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:48:50 +0200
commit62c27c1c5cb6257b13dfc9be0394e0d2e86f2735 (patch)
treef702b7e5f80293367e1b6f9812bd45e80378be26 /cpp/cpp.c
parent6cb598cc5f1c8ae6d14381c2776338584368257e (diff)
downloaddev86-62c27c1c5cb6257b13dfc9be0394e0d2e86f2735.tar.gz
Import Dev86src-0.16.17.tar.gzv0.16.17
Diffstat (limited to 'cpp/cpp.c')
-rw-r--r--cpp/cpp.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/cpp/cpp.c b/cpp/cpp.c
index 7d287f4..616cf87 100644
--- a/cpp/cpp.c
+++ b/cpp/cpp.c
@@ -111,7 +111,7 @@ static void do_proc_tail P((void));
static int get_if_expression P((void));
static int_type get_expression P((int));
static int_type get_exp_value P((void));
-static void gen_substrings P((char *, char *, int));
+static void gen_substrings P((char *, char *, int, int));
static char * insert_substrings P((char *, struct arg_store *, int));
int
@@ -329,7 +329,7 @@ break_break:
}
/* We have arguments to process so lets do so. */
- gen_substrings(ptr->name, ptr->value, ptr->arg_count);
+ gen_substrings(ptr->name, ptr->value, ptr->arg_count, ptr->varargs);
/* Don't mark macros with arguments as in use, it's very
* difficult to say what the correct result would be so
@@ -822,6 +822,11 @@ do_proc_define()
cc++;
ptr->arg_count++;
ch=gettok_nosub();
+ if( ch == TK_ELLIPSIS ) {
+ ptr->varargs = 1;
+ ch=gettok_nosub();
+ if (ch == ',') ch = '*'; /* Force error if not ')' */
+ }
if( ch == ')' ) break;
if( ch == ',' ) continue;
}
@@ -1247,10 +1252,11 @@ get_exp_value()
}
void
-gen_substrings(macname, data_str, arg_count)
+gen_substrings(macname, data_str, arg_count, is_vararg)
char * macname;
char * data_str;
int arg_count;
+int is_vararg;
{
char * mac_text = 0;
struct arg_store *arg_list;
@@ -1289,7 +1295,9 @@ int arg_count;
if ( ch == '(' ) paren_count++;
if ( ch == '"' || ch == '\'' ) { in_quote = 1; quote_char = ch; }
if (paren_count == 0 && ch == ',' ) {
- commas_found++; continue;
+ commas_found++;
+ if (commas_found < arg_count)
+ continue;
}
if ( ch == ')' ) {
if (paren_count == 0) break;
@@ -1297,9 +1305,13 @@ int arg_count;
}
}
args_found = 1;
- /* Too many args; ignore rest */
- if (commas_found >= arg_count ) continue;
- ac = commas_found;
+ /* Too many args, deal with, or ignore, the rest. */
+ if (commas_found >= arg_count) {
+ if(arg_count == 0) continue;
+ ac = arg_count-1;
+ } else
+ ac = commas_found;
+
if (arg_list[ac].value == 0) {
cc = len = 0;
arg_list[ac].in_define = def_count;
@@ -1322,8 +1334,10 @@ int arg_count;
if (commas_found || args_found) args_found = commas_found+1;
- if( arg_count != args_found )
- cerror("Incorrect number of macro arguments");
+ if( arg_count == 0 && args_found != 0 )
+ cerror("Arguments given to macro without them.");
+ else if( !is_vararg && arg_count != args_found )
+ cwarn("Incorrect number of macro arguments");
mac_text = insert_substrings(data_str, arg_list, arg_count);