73 lines
1.3 KiB
C
73 lines
1.3 KiB
C
#include "line_handler.h"
|
|
#include "pp_define.h"
|
|
#include "pp_line_id.h"
|
|
#include "expand_line.h"
|
|
#include "pp_if.h"
|
|
#include "pp_ifdef.h"
|
|
#include "pp_inc.h"
|
|
|
|
int line_handler(char *line, void *def_map, const struct str_dyn_arr *inc_dirs,
|
|
FILE *source, FILE *out)
|
|
{
|
|
int ret;
|
|
int line_len;
|
|
|
|
if (IS_DEF_LINE(line))
|
|
return collect_def(line, def_map, source);
|
|
|
|
if (IS_UNDEF_LINE(line))
|
|
return apply_undef(line, def_map);
|
|
|
|
if (IS_IF_LINE(line)) {
|
|
line_len = strlen(line);
|
|
|
|
ret = fseek(source, -line_len, SEEK_CUR);
|
|
if (ret == -1)
|
|
return PP_FAILED;
|
|
|
|
ret = expand_if(def_map, inc_dirs, source, out);
|
|
if (ret == PP_FAILED)
|
|
return ret;
|
|
|
|
return PP_OK;
|
|
}
|
|
|
|
if (IS_IFDEF_LINE(line) || IS_IFNDEF_LINE(line)) {
|
|
line_len = strlen(line);
|
|
|
|
ret = fseek(source, -line_len, SEEK_CUR);
|
|
if (ret == -1)
|
|
return PP_FAILED;
|
|
|
|
ret = expand_ifdef(def_map, inc_dirs, source, out);
|
|
if (ret == PP_FAILED)
|
|
return ret;
|
|
|
|
return PP_OK;
|
|
}
|
|
|
|
if (IS_INC_LINE(line)) {
|
|
line_len = strlen(line);
|
|
|
|
ret = fseek(source, -line_len, SEEK_CUR);
|
|
if (ret == -1)
|
|
return PP_FAILED;
|
|
|
|
ret = expand_inc(def_map, inc_dirs, source, out);
|
|
if (ret == PP_FAILED)
|
|
return ret;
|
|
|
|
return PP_OK;
|
|
}
|
|
|
|
if (IS_ENDIF_LINE(line))
|
|
return PP_OK;
|
|
|
|
ret = write_expanded_line(def_map, line, out);
|
|
if (ret == PP_FAILED)
|
|
return ret;
|
|
|
|
return PP_OK;
|
|
}
|
|
|