[hackers] [scc] [cc1] move file open handling from ilex to addinput || Quentin Rameau

From: <git_AT_suckless.org>
Date: Wed, 29 Jun 2016 13:51:52 +0200 (CEST)

commit b3f2f478c75b4649c5bdb99c0d23b681ec2f18fe
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Mon Jun 27 15:22:30 2016 +0200
Commit: Quentin Rameau <quinq_AT_fifth.space>
CommitDate: Tue Jun 28 11:15:23 2016 +0200

    [cc1] move file open handling from ilex to addinput

diff --git a/cc1/cc1.h b/cc1/cc1.h
index bdf1f6d..a0acda3 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -383,7 +383,7 @@ extern void expect(unsigned tok);
 extern void discard(void);
 extern int addinput(char *fname);
 extern void setsafe(int type);
-extern void ilex(char *fname);
+extern void ilex(void);
 #define accept(t) ((yytoken == (t)) ? next() : 0)
 
 /* code.c */
diff --git a/cc1/lex.c b/cc1/lex.c
index 7e51d8d..992cb2c 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -38,7 +38,7 @@ allocinput(char *fname, FILE *fp)
 }
 
 void
-ilex(char *fname)
+ilex(void)
 {
         static struct keyword keys[] = {
                 {"auto", SCLASS, AUTO},
_AT_@ -78,18 +78,6 @@ ilex(char *fname)
                 {"while", WHILE, WHILE},
                 {NULL, 0, 0},
         };
- FILE *fp;
-
- if (!fname) {
- fp = stdin;
- fname = "<stdin>";
- } else {
- if ((fp = fopen(fname, "r")) == NULL) {
- die("error: failed to open input file '%s': %s",
- fname, strerror(errno));
- }
- }
- allocinput(fname, fp);
         keywords(keys, NS_KEYWORD);
 }
 
_AT_@ -98,8 +86,13 @@ addinput(char *fname)
 {
         FILE *fp;
 
- if ((fp = fopen(fname, "r")) == NULL)
- return 0;
+ if (fname) {
+ if ((fp = fopen(fname, "r")) == NULL)
+ return 0;
+ } else {
+ fp = stdin;
+ fname = "<stdin>";
+ }
         allocinput(fname, fp);
         return 1;
 }
diff --git a/cc1/main.c b/cc1/main.c
index 8527747..2d1f66f 100644
--- a/cc1/main.c
+++ b/cc1/main.c
_AT_@ -46,6 +46,7 @@ main(int argc, char *argv[])
 
         atexit(clean);
         icpp();
+ ilex();
 
         /* if run as cpp, only run the preprocessor */
         name = (cp = strrchr(*argv, '/')) ? cp + 1 : *argv;
_AT_@ -88,7 +89,10 @@ main(int argc, char *argv[])
         for (i = 0; i < uflags.n; ++i)
                 undefmacro(uflags.s[i]);
 
- ilex(*argv);
+ if (!addinput(*argv)) {
+ die("error: failed to open input file '%s': %s",
+ *argv, strerror(errno));
+ }
         if (onlycpp) {
                 outcpp();
         } else {
Received on Wed Jun 29 2016 - 13:51:52 CEST

This archive was generated by hypermail 2.3.0 : Wed Jun 29 2016 - 14:00:19 CEST