494be6ed63efa3aaf0c025b62351dcfca0c4d694
3 \details The driver assumes the existence of a bison-generated parser,
4 referenced by the external function 'yyparse'.
5 It also assumes the existence of a lexer which must be initialized
6 before parsing, referenced by the external function 'lexer_init'
7 which assumes standard error handling.
8 All input arguments are made available through the exposed (that is,
9 non-static) array of character pointers 'cargs', which point
10 to the non-duplicated strings in 'argv' directly from the system.
11 \author Jordan Lavatai
13 ----------------------------------------------------------------------------*/
15 #include <stdio.h> //print
16 #include <errno.h> //errors
17 #include <string.h> //strndupa
19 #include <stdlib.h> //exit
20 #include <unistd.h> //getopt, sysconf
21 #include <dirent.h> //opendir
24 #include "parser.tab.h" //bison
27 #define DEFAULT_PAGESIZE 4096
29 const char* apc_package_name
;
32 int main(int, char*[]);
37 int scanner_init(void);
39 void scanner_quit(void);
41 int scanner_scandir(DIR*);
47 int ir_condenser(void);
51 /* Main entry from terminal
52 parses the command line and kicks off recursive scanning
58 #define $($)#$ //stringifier
60 #define MAXERR "-%c allows at most " $(MAXSTR) " input characters\n", opt
62 #define USAGE "Usage %s [-d dir_root][-o output_file][-h]\n", argv[0]
65 "\t\t-d\tRoot directory to parse from \t[./]\n" \
66 "\t\t-o\tOutput filename \t\t[a.asspak]\n" \
67 "\t\t-h\tPrint this help\n"
72 char path_buf
[APC_NAME_MAX
];
74 cargs
= (const char**) malloc('Z');
76 switch (opt
= getopt(argc
, argv
, OPTS
))
79 if (strnlen(optarg
, MAXSTR
) != MAXSTR
)
80 { cargs
[opt
] = optarg
;
83 fprintf(stderr
, MAXERR
);
85 fprintf(stderr
, USAGE
);
94 if ((sys_pagesize
= sysconf(_SC_PAGESIZE
)) == 0)
95 sys_pagesize
= DEFAULT_PAGESIZE
;
102 scanpath
= cargs
['d'] ? cargs
['d'] : "./";
104 dirp
= opendir(scanpath
);
105 if (dirp
== NULL
|| errno
)
106 { fprintf(stderr
, "Path %s could not be accessed\n", scanpath
);
110 { fprintf(stderr
, "Could not change directory to %s \n", scanpath
);
113 apc_package_name
= path_iter
= getcwd(path_buf
, APC_NAME_MAX
- 1);
115 while (*path_iter
!= '\0')
116 { if (*path_iter
== '/')
117 apc_package_name
= path_iter
+ 1;
120 if (apc_package_name
== path_buf
)
121 { fprintf(stderr
, "Error resolving package name from path %s\n", path_buf
);
125 if (apc_package_name
== path_iter
)
126 { *--path_iter
= '\0';
129 if (scanner_scandir(dirp
))