[hackers] [scc] [cpp] keep count of command-line macros || Quentin Rameau

From: <git_AT_suckless.org>
Date: Mon, 18 Jul 2016 18:06:43 +0200 (CEST)

commit 946ce5f09e298d5bbcc1f7f099aa79041cdd94b6
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Wed Jun 29 12:42:10 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Wed Jun 29 13:26:59 2016 +0200

    [cpp] keep count of command-line macros
    
    This way we can print a pseudo line number corresponding to the
    parameter number.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 777619d..1c1d46a 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -382,7 +382,7 @@ extern int moreinput(void);
 extern void expect(unsigned tok);
 extern void discard(void);
 extern int addinput(char *fname);
-extern void allocinput(char *fname, FILE *fp, char *s);
+extern void allocinput(char *fname, FILE *fp, char *line);
 extern void delinput(void);
 extern void setsafe(int type);
 extern void ilex(void);
diff --git a/cc1/cpp.c b/cc1/cpp.c
index 6cabce2..ee9aa9a 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -13,6 +13,7 @@
 
 static char *argp, *macroname;
 static unsigned arglen;
+static unsigned ncmdlines;
 static Symbol *symline, *symfile;
 static unsigned char ifstatus[NR_COND];
 static int ninclude;
_AT_@ -32,6 +33,7 @@ defdefine(char *macro, char *val)
 
         sprintf(def, fmt, macro, val);
         allocinput("command-line", NULL, def);
+ input->nline = ++ncmdlines;
         cpp();
         delinput();
 }
_AT_@ -87,6 +89,8 @@ icpp(void)
 
         for (bp = list; *bp; ++bp)
                 defdefine(*bp, NULL);
+
+ ncmdlines = 0;
 }
 
 static void
diff --git a/cc1/lex.c b/cc1/lex.c
index 78d9a2d..1119f59 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -23,18 +23,16 @@ static int safe, eof;
 Input *input;
 
 void
-allocinput(char *fname, FILE *fp, char *s)
+allocinput(char *fname, FILE *fp, char *line)
 {
         Input *ip = xmalloc(sizeof(Input));
 
- if (s) {
- ip->p = ip->begin = ip->line = s;
- ip->nline = 1;
- } else {
- ip->p = ip->begin = ip->line = xmalloc(INPUTSIZ);
- ip->p[0] = '\0';
- ip->nline = 0;
+ if (!line) {
+ line = xmalloc(INPUTSIZ);
+ line[0] = '\0';
         }
+ ip->p = ip->begin = ip->line = line;
+ ip->nline = 0;
         ip->fname = xstrdup(fname);
         ip->next = input;
         ip->fp = fp;
Received on Mon Jul 18 2016 - 18:06:43 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 18 2016 - 18:12:47 CEST