Use lkfile_t as base file structure
authorAlexey Gladkov <gladkov.alexey@gmail.com>
Sat, 17 Dec 2011 23:45:16 +0000 (03:45 +0400)
committerAlexey Gladkov <legion@altlinux.org>
Sun, 24 Jun 2012 22:11:02 +0000 (02:11 +0400)
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
src/findfile.c
src/findfile.h
src/loadkeys.analyze.l

index f7551f9..3082b57 100644 (file)
@@ -20,11 +20,11 @@ void fpclose(FILE *fp) {
             fclose(fp);
 }
 
-void fpclose1(FILE *fp, int is_pipe) {
-       if (is_pipe)
-               pclose(fp);
+void fpclose1(lkfile_t *fp) {
+       if (fp->pipe)
+               pclose(fp->fd);
        else
-               fclose(fp);
+               fclose(fp->fd);
 }
 
 #define SIZE(a) (sizeof(a)/sizeof(a[0]))
index e97a016..19fe61d 100644 (file)
@@ -4,14 +4,13 @@
 typedef struct lkfile {
        FILE *fd;
        int pipe;
-} lkfile_y;
+} lkfile_t;
 
 extern char pathname[];
 extern int ispipe;
 
 extern void fpclose(FILE *fp);
-extern void fpclose1(FILE *fp, int pipe);
-//extern void fpclose1(lkfile_t *fp);
+extern void fpclose1(lkfile_t *fp);
 extern FILE *findfile(char *fnam, char **dirpath, char **suffixes);
 
 #endif /* _FINDFILE_H */
index c18dcea..bc7e2b9 100644 (file)
@@ -33,9 +33,8 @@ void stack_push(FILE *fd, int is_pipe, char *fname);
 /* Include file handling - unfortunately flex-specific. */
 #define MAX_INCLUDE_DEPTH 20
 static struct infile {
-       FILE *fd;
+       lkfile_t fp;
        char *filename;
-       int  pipe;
        int  linenr;
        YY_BUFFER_STATE buffer;
 } infile_stack[MAX_INCLUDE_DEPTH];
@@ -53,8 +52,8 @@ void stack_push(FILE *fd, int is_pipe, char *fname) {
        infile_stack_ptr++;
 
        infile_stack[infile_stack_ptr].buffer   = yy_create_buffer(fd, YY_BUF_SIZE);
-       infile_stack[infile_stack_ptr].fd       = fd;
-       infile_stack[infile_stack_ptr].pipe     = is_pipe;
+       infile_stack[infile_stack_ptr].fp.fd    = fd;
+       infile_stack[infile_stack_ptr].fp.pipe  = is_pipe;
        infile_stack[infile_stack_ptr].filename = strdup(fname);
        infile_stack[infile_stack_ptr].linenr   = line_nr;
 
@@ -66,7 +65,7 @@ void stack_push(FILE *fd, int is_pipe, char *fname) {
 }
 
 static int stack_pop(void) {
-       fpclose1(infile_stack[infile_stack_ptr].fd, infile_stack[infile_stack_ptr].pipe);
+       fpclose1(&infile_stack[infile_stack_ptr].fp);
 
        // Free previous filename
        xfree(infile_stack[infile_stack_ptr].filename);
@@ -78,8 +77,7 @@ static int stack_pop(void) {
 
        if (infile_stack_ptr >= 0) {
                // Set new state
-               //yyin     = infile_stack[infile_stack_ptr].fd; // ???
-               ispipe   = infile_stack[infile_stack_ptr].pipe;
+               ispipe   = infile_stack[infile_stack_ptr].fp.pipe;
                filename = infile_stack[infile_stack_ptr].filename;
                line_nr  = infile_stack[infile_stack_ptr].linenr;