1 Star 0 Fork 0

zhyulo/Stream

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.c 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
zhyulo 提交于 2021-07-28 23:00 . 文件缩进方式统一整改为4空格
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "alloc.h"
#include "input.h"
#include "lex.h"
#include "str.h"
#include "expr.h"
#include "log.h"
#include "output.h"
static void compile(const char *sourcePath, const char *outPath)
{
char *path, *name, *tmp;
path = (char*) malloc(strlen(sourcePath) + 1);
if (path == NULL) {
LOGE("Memory exhausted");
exit(EXT_MemoryFull);
}
strcpy(path, sourcePath);
name = strrchr(path, '\\');
if (name == NULL) {
name = strrchr(path, '/');
} else {
tmp = strrchr(name, '/');
if (tmp != NULL) name = tmp;
}
if (name == NULL) {
name = path;
} else {
*name = '\0';
name++;
}
tmp = strrchr(name, '.');
if (tmp != NULL && tmp != name) {
*tmp = '\0';
}
if (outPath == NULL && path != name) {
outPath = path;
}
InitHeap(MainHeap);
InitString();
LOGV("start compile %s", sourcePath);
ReadSourceFile(sourcePath);
NextToken();
AstNode root = ParseSourceFile();
LOGV("end parse and start output");
PrintCode(root, outPath, name);
LOGV("stop compile %s", sourcePath);
FreeHeap(MainHeap);
}
int main(int argc, char *argv[])
{
InitLexer();
if (argc < 3) {
printf("Usage: Stream [options] -i stmfile\n");
printf("Options:\n");
printf(" -o file Place the output into 'file'\n");
printf(" -t indent Indent of output file\n");
printf(" -e Output the enumeration definition\n");
exit(0);
}
const char *inFile = NULL;
const char *outPath = NULL;
int i;
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-' && argv[i][2] == '\0') {
switch(argv[i][1]) {
case 'i':
i++;
inFile = argv[i];
break;
case 'o':
i++;
outPath = argv[i];
break;
case 't':
i++;
Indent = argv[i];
break;
case 'e':
OutputEnumDefine = 1;
break;
}
} else {
LOGE("Unknown cmd arg : %s", argv[i]);
exit(0);
}
}
if (inFile == NULL) {
LOGE("There is no input file.");
exit(0);
}
compile(inFile, outPath);
DestroyHeap(MainHeap);
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/zhyulo/Stream.git
git@gitee.com:zhyulo/Stream.git
zhyulo
Stream
Stream
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385