@@ -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' )
1818ff_endArg (run , true);
1919
@@ -33,10 +33,11 @@ static void printVersion(void);
3333static void printHelp (void );
3434static int mainRun (ff_FFlags * ff );
3535static int mainBuild (ff_FFlags * ff );
36+ extern const char * help_info ;
3637
3738int 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+
6269static 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 */
7178static 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
154162static 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
247255error :
248- printHelp ( );
256+ printError ( ff );
249257 return EXIT_FAILURE ;
250258}
0 commit comments