enum e_ErrorLevel
{
LEVEL_WARNING,
LEVEL_ERROR,
};
enum e_WorkStage
{
STAGE_COMPILE,
STAGE_LINK,
};
void handle_exception(int stage, int level, char *fmt, va_list ap)
{
char buf[1024];
vsprintf(buf, fmt, ap);
if (stage == STAGE_COMPILE)
{
if (level == LEVEL_WARNING)
printf("%s(第%d行): 编译警告: %s!\n", filename, line_num, buf);
else
{
printf("%s(第%d行): 编译错误: %s!\n", filename, line_num, buf);
exit(-1);
}
}
else
{
printf("链接错误: %s!\n", buf);
exit(-1);
}
}
void error(char *fmt,...)
{
va_list va;
va_start(ap, fmt);
handle_exception(STAGE_COMPILE, LEVEL_ERROR, fmt, ap);
va_end(ap);
}