00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include "os/os.h"
00039 #include "mytypes.h"
00040 #include "stype.h"
00041 #include "input.h"
00042 #include "lex.h"
00043 #include "parse.h"
00044
00045 #include "program.h"
00046
00047 #define MAX_NAME_SIZE 64
00048 static char name_buf[MAX_NAME_SIZE + 1];
00049
00057 int program_file_process(stree_program_t *program, const char *fname)
00058 {
00059 input_t *input;
00060 lex_t lex;
00061 parse_t parse;
00062 int rc;
00063
00064 rc = input_new_file(&input, fname);
00065 if (rc != EOK) {
00066 printf("Failed opening source file '%s'.\n", fname);
00067 return EIO;
00068 }
00069
00070
00071 lex_init(&lex, input);
00072 parse_init(&parse, program, &lex);
00073 parse_module(&parse);
00074
00075
00076 if (parse.error)
00077 return EINVAL;
00078
00079 return EOK;
00080 }
00081
00093 int program_lib_process(stree_program_t *program)
00094 {
00095 int rc;
00096 char *path, *fname;
00097 char *tmp;
00098 char *cp;
00099
00100 FILE *f;
00101
00102 path = os_get_lib_path();
00103 fname = os_str_acat(path, "/libflist");
00104
00105 f = fopen(fname, "rt");
00106 if (f == NULL) {
00107 printf("Failed opening library list file '%s'.\n", fname);
00108 free(path);
00109 free(fname);
00110 return EIO;
00111 }
00112
00113 free(fname);
00114
00115 while (b_true) {
00116 if (fgets(name_buf, MAX_NAME_SIZE + 1, f) == NULL)
00117 break;
00118
00119
00120
00121
00122 cp = name_buf;
00123 while (*cp != '\0' && *cp != '\n')
00124 ++cp;
00125
00126 if (*cp == '\n')
00127 *cp = '\0';
00128
00129 tmp = os_str_acat(path, "/");
00130 fname = os_str_acat(tmp, name_buf);
00131 free(tmp);
00132
00133 rc = program_file_process(program, fname);
00134 if (rc != EOK) {
00135 free(fname);
00136 free(path);
00137 fclose(f);
00138 return rc;
00139 }
00140
00141 free(fname);
00142 }
00143
00144 if (ferror(f)) {
00145 printf("Error reading from library list file.\n");
00146 free(path);
00147 fclose(f);
00148 return EIO;
00149 }
00150
00151 free(path);
00152 fclose(f);
00153
00154 return EOK;
00155 }