Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 28203f8

Browse files
committed
feat: 更详细的用户反馈
1 parent 947bdb7 commit 28203f8

File tree

8 files changed

+75
-33
lines changed

8 files changed

+75
-33
lines changed

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ set(CMAKE_INSTALL_RPATH
5151
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
5252
set(CMAKE_MACOSX_RPATH TRUE)
5353
include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}) # 添加默认的include路径
54-
add_compile_definitions(aFunVersion="${aFunVersion}" aFunDescription="${aFunDescription}")
55-
54+
set(base_compile_definitions
55+
aFunVersion="${aFunVersion}"
56+
aFunDescription="${aFunDescription}"
57+
systemName="${CMAKE_SYSTEM_NAME}"
58+
compilerID="${CMAKE_C_COMPILER_ID}") # 默认的预定义宏
59+
add_compile_definitions(${base_compile_definitions})
5660

5761
include(${CMAKE_CURRENT_LIST_DIR}/deps/deps.cmake) # 安装依赖
5862
add_subdirectory(src)

deps/fflags

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ file(GLOB include_h
1515
LIST_DIRECTORIES FALSE
1616
"${PROJECT_SOURCE_DIR}/include/*.h")
1717

18+
file(READ ${CMAKE_CURRENT_LIST_DIR}/help-info _help-info)
19+
string(REPLACE "\n" "\\n" help-info "${_help-info}")
20+
configure_file(${CMAKE_CURRENT_LIST_DIR}/help_info.c.in ${CMAKE_BINARY_DIR}/help_info.c @ONLY)
21+
list(APPEND source "${CMAKE_BINARY_DIR}/help_info.c")
22+
1823
option(AFUN_BUILD_ALL "Build all types of aFun" ON)
1924
set(_build_all ${AFUN_BUILD_ALL})
2025

@@ -31,6 +36,7 @@ endif()
3136
foreach(tgt IN LISTS aFunList)
3237
target_sources(${tgt} PRIVATE ${source} ${private_h} ${include_h})
3338
target_include_directories(${tgt} PRIVATE ${PROJECT_SOURCE_DIR}/include)
39+
get_target_property(tmp ${tgt} COMPILE_DEFINITIONS)
3440
set_target_properties(${tgt} PROPERTIES PUBLIC_HEADER "${include_h}")
3541
endforeach()
3642

src/help-info

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[option]
2+
help
3+
-v Show version info
4+
-h Show help page
5+
run
6+
-e/--eval Run argument as code
7+
-f/--file Run file (.aun or .aub)
8+
-s/--source Run source file
9+
-b/--byte Run byte-code file
10+
--no-aub Do not save byte-code after run source file
11+
--no-cl Do not use command line
12+
build
13+
-o File output path
14+
-p File output dir
15+
-f Force build
16+
17+
[Github page]
18+
<https://github.com/aFun-org/aFunlang>

src/help_info.c.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const char *help_info = "@help-info@";

src/main.c

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ff_defArg(run, true)
1313
ff_argRule('f', file, must, 'f')
1414
ff_argRule('s', source, must, 's')
1515
ff_argRule('b', byte, must, 'b')
16-
ff_argRule(NUL, no-afb, not, 'a')
16+
ff_argRule(NUL, no-aub, not, 'a')
1717
ff_argRule(NUL, no-cl, not, 'n')
1818
ff_endArg(run, true);
1919

@@ -33,10 +33,11 @@ static void printVersion(void);
3333
static void printHelp(void);
3434
static int mainRun(ff_FFlags *ff);
3535
static int mainBuild(ff_FFlags *ff);
36+
extern const char *help_info;
3637

3738
int main(int argc, char **argv) {
3839
int exit_code = EXIT_SUCCESS;
39-
ff_FFlags *ff = ff_initFFlags(argc, argv, true, false, aFunlang_exe);
40+
ff_FFlags *ff = ff_initFFlags(argc, argv, true, false, stderr, aFunlang_exe);
4041
if (ff == NULL)
4142
return EXIT_FAILURE;
4243
char *child = ff_getChild(ff);
@@ -59,17 +60,23 @@ static void printVersion(void) {
5960
printf(aFunDescription "\n");
6061
}
6162

63+
static void printWelcomeInfo(void) {
64+
printf("\naFunlang " aFunVersion " CommandLine (" __DATE__ ", " __TIME__ ")\n");
65+
printf("["compilerID"] on "systemName"\n");
66+
printf("(Enter the aFun code to run in the top activity)\n");
67+
}
68+
6269
static void printHelp(void) {
6370
printf("aFunlang Usage:\n");
64-
printf("Github: <https://github.com/aFun-org/aFunlang>\n");
71+
printf("%s\n", help_info);
6572
}
6673

6774
/*
6875
* 函数名: printError
6976
* 目标: 打印参数错误信息
7077
*/
7178
static void printError(ff_FFlags *ff) {
72-
fprintf(stderr, "Command line argumenterror (%s)\n", ff_getChild(ff));
79+
fprintf(stderr, "[aFunlang] Command line argument error (%s)\n", ff_getChild(ff));
7380
printHelp();
7481
}
7582

@@ -106,14 +113,14 @@ static int mainHelp(ff_FFlags *ff) {
106113
return EXIT_SUCCESS;
107114
}
108115

109-
static RunList *getRunList(ff_FFlags *ff, bool *command_line, bool *save_afb) {
116+
static RunList *getRunList(ff_FFlags *ff, bool *command_line, bool *save_aub) {
110117
char *text = NULL;
111118
RunList *run_list = NULL;
112119
RunList **prl = &run_list;
113120
int mark;
114121

115122
*command_line = true;
116-
*save_afb = true;
123+
*save_aub = true;
117124

118125
while (1) {
119126
mark = ff_getopt(&text, ff);
@@ -134,11 +141,12 @@ static RunList *getRunList(ff_FFlags *ff, bool *command_line, bool *save_afb) {
134141
*command_line = false;
135142
break;
136143
case 'a':
137-
*save_afb = false;
144+
*save_aub = false;
138145
break;
139146
case -1:
140147
goto out;
141148
default:
149+
*command_line = false; // 命令行也不启动
142150
printError(ff);
143151
freeAllRunList(run_list);
144152
return NULL;
@@ -153,22 +161,25 @@ static RunList *getRunList(ff_FFlags *ff, bool *command_line, bool *save_afb) {
153161

154162
static int mainRun(ff_FFlags *ff) {
155163
bool command_line = true;
156-
bool save_afb = true;
164+
bool save_aub = true;
157165
int exit_code;
158-
RunList *rl = getRunList(ff, &command_line, &save_afb);
166+
RunList *rl = getRunList(ff, &command_line, &save_aub);
159167

160-
af_Environment *env = creatAFunEnviroment();
161-
if (rl != NULL)
162-
exit_code = runCodeFromRunList(rl, NULL, save_afb, env);
163-
else if (!command_line) {
164-
fprintf(stderr, "Not code to run.\n");
165-
printHelp();
168+
if (rl == NULL && !command_line) {
169+
fprintf(stderr, "[aFunlang] There are not code to run.\n");
170+
printError(ff);
166171
return EXIT_FAILURE;
167172
}
168173

169-
if (command_line) {
170-
while (isCoreExit(env) != 1)
174+
af_Environment *env = creatAFunEnviroment();
175+
if (rl != NULL)
176+
exit_code = runCodeFromRunList(rl, NULL, save_aub, env);
177+
178+
if (command_line && isCoreExit(env) != 1) {
179+
printWelcomeInfo();
180+
do
171181
exit_code = runCodeFromStdin("stdin", stderr, env);
182+
while (isCoreExit(env) != 1);
172183
}
173184

174185
destructAFunEnvironment(env);
@@ -189,14 +200,14 @@ static int mainBuild(ff_FFlags *ff) {
189200
switch (mark) {
190201
case 'o':
191202
if (path != NULL) {
192-
fprintf(stderr, "Parameter conflict.\n");
203+
fprintf(stderr, "[aFunlang] Argument conflict (out, path).\n");
193204
goto error;
194205
}
195206
out_put = text;
196207
break;
197208
case 'p':
198209
if (out_put != NULL) {
199-
fprintf(stderr, "Parameter conflict.\n");
210+
fprintf(stderr, "[aFunlang] Argument conflict (out, path).\n");
200211
goto error;
201212
}
202213
path = text;
@@ -207,8 +218,7 @@ static int mainBuild(ff_FFlags *ff) {
207218
case -1:
208219
goto out;
209220
default:
210-
printError(ff);
211-
return EXIT_FAILURE;
221+
goto error;
212222
}
213223
}
214224

@@ -218,17 +228,15 @@ static int mainBuild(ff_FFlags *ff) {
218228

219229
/* 如果没有参数 */
220230
if (!ff_getopt_wild(&text, ff)) {
221-
fprintf(stderr, "No source file to build.\n");
222-
printHelp();
223-
return EXIT_FAILURE;
231+
fprintf(stderr, "[aFunlang] There are not source file to build.\n");
232+
goto error;
224233
} else
225234
in = text;
226235

227236
/* 如果还有第二个参数 */
228237
if (ff_getopt_wild(&text, ff)) {
229-
fprintf(stderr, "Too many source file to build.\n");
230-
printHelp();
231-
return EXIT_FAILURE;
238+
fprintf(stderr, "[aFunlang] There are too many source file to build. (Do not use --out option)\n");
239+
goto error;
232240
}
233241

234242
return buildFileOutput(out_put, in, force);
@@ -245,6 +253,6 @@ static int mainBuild(ff_FFlags *ff) {
245253
return exit_code;
246254

247255
error:
248-
printHelp();
256+
printError(ff);
249257
return EXIT_FAILURE;
250258
}

src/main_build.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ int buildFileOutput(FilePath out, FilePath in, bool force) {
1010
return -1;
1111
}
1212

13-
if (time_2 >= time_1)
13+
if (time_2 >= time_1) {
14+
fprintf(stdout, "[aFunlang] Source already build (%s), use --force to build again.\n", in);
1415
return 0;
16+
}
1517
}
1618

19+
fprintf(stdout, "[aFunlang] File (%s) will be build. (%s)\n", in, out);
1720
return buildFile(out, in, stderr);
1821
}
1922

src/main_run.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ int runCodeFromRunList(RunList *run_list, RunList **bak, bool save_afb, af_Envir
7878
break;
7979
}
8080

81-
if (exit_code != 0)
81+
if (isCoreExit(env) == 1) {
82+
fprintf((exit_code == 0) ? stdout : stderr, "[aFunlang] aFun core exit, exit_code = %d\n", exit_code);
8283
break;
84+
}
8385
}
8486

8587
if (bak != NULL)

0 commit comments

Comments
 (0)