main.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Add to readline cmdline-editing by
  6. * (C) Copyright 2005
  7. * JinHua Luo, GuangDong Linux Center, <luo.jinhua@gd-linux.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. /* #define DEBUG */
  28. #include <common.h>
  29. #include <watchdog.h>
  30. #include <command.h>
  31. #ifdef CONFIG_MODEM_SUPPORT
  32. #include <malloc.h> /* for free() prototype */
  33. #endif
  34. #ifdef CONFIG_SYS_HUSH_PARSER
  35. #include <hush.h>
  36. #endif
  37. #include <post.h>
  38. #if defined(CONFIG_SILENT_CONSOLE) || defined(CONFIG_POST) || defined(CONFIG_CMDLINE_EDITING)
  39. DECLARE_GLOBAL_DATA_PTR;
  40. #endif
  41. /*
  42. * Board-specific Platform code can reimplement show_boot_progress () if needed
  43. */
  44. void inline __show_boot_progress (int val) {}
  45. void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progress")));
  46. #if defined(CONFIG_UPDATE_TFTP)
  47. void update_tftp (void);
  48. #endif /* CONFIG_UPDATE_TFTP */
  49. #define MAX_DELAY_STOP_STR 32
  50. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  51. static int abortboot(int);
  52. #endif
  53. #undef DEBUG_PARSER
  54. char console_buffer[CONFIG_SYS_CBSIZE + 1]; /* console I/O buffer */
  55. static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen);
  56. static const char erase_seq[] = "\b \b"; /* erase sequence */
  57. static const char tab_seq[] = " "; /* used to expand TABs */
  58. #ifdef CONFIG_BOOT_RETRY_TIME
  59. static uint64_t endtime = 0; /* must be set, default is instant timeout */
  60. static int retry_time = -1; /* -1 so can call readline before main_loop */
  61. #endif
  62. #define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk())
  63. #ifndef CONFIG_BOOT_RETRY_MIN
  64. #define CONFIG_BOOT_RETRY_MIN CONFIG_BOOT_RETRY_TIME
  65. #endif
  66. #ifdef CONFIG_MODEM_SUPPORT
  67. int do_mdm_init = 0;
  68. extern void mdm_init(void); /* defined in board.c */
  69. #endif
  70. /***************************************************************************
  71. * Watch for 'delay' seconds for autoboot stop or autoboot delay string.
  72. * returns: 0 - no key string, allow autoboot
  73. * 1 - got key string, abort
  74. */
  75. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  76. # if defined(CONFIG_AUTOBOOT_KEYED)
  77. static __inline__ int abortboot(int bootdelay)
  78. {
  79. int abort = 0;
  80. uint64_t etime = endtick(bootdelay);
  81. struct {
  82. char* str;
  83. u_int len;
  84. int retry;
  85. }
  86. delaykey [] = {
  87. { str: getenv ("bootdelaykey"), retry: 1 },
  88. { str: getenv ("bootdelaykey2"), retry: 1 },
  89. { str: getenv ("bootstopkey"), retry: 0 },
  90. { str: getenv ("bootstopkey2"), retry: 0 },
  91. };
  92. char presskey [MAX_DELAY_STOP_STR];
  93. u_int presskey_len = 0;
  94. u_int presskey_max = 0;
  95. u_int i;
  96. # ifdef CONFIG_AUTOBOOT_PROMPT
  97. printf(CONFIG_AUTOBOOT_PROMPT);
  98. # endif
  99. # ifdef CONFIG_AUTOBOOT_DELAY_STR
  100. if (delaykey[0].str == NULL)
  101. delaykey[0].str = CONFIG_AUTOBOOT_DELAY_STR;
  102. # endif
  103. # ifdef CONFIG_AUTOBOOT_DELAY_STR2
  104. if (delaykey[1].str == NULL)
  105. delaykey[1].str = CONFIG_AUTOBOOT_DELAY_STR2;
  106. # endif
  107. # ifdef CONFIG_AUTOBOOT_STOP_STR
  108. if (delaykey[2].str == NULL)
  109. delaykey[2].str = CONFIG_AUTOBOOT_STOP_STR;
  110. # endif
  111. # ifdef CONFIG_AUTOBOOT_STOP_STR2
  112. if (delaykey[3].str == NULL)
  113. delaykey[3].str = CONFIG_AUTOBOOT_STOP_STR2;
  114. # endif
  115. for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
  116. delaykey[i].len = delaykey[i].str == NULL ?
  117. 0 : strlen (delaykey[i].str);
  118. delaykey[i].len = delaykey[i].len > MAX_DELAY_STOP_STR ?
  119. MAX_DELAY_STOP_STR : delaykey[i].len;
  120. presskey_max = presskey_max > delaykey[i].len ?
  121. presskey_max : delaykey[i].len;
  122. # if DEBUG_BOOTKEYS
  123. printf("%s key:<%s>\n",
  124. delaykey[i].retry ? "delay" : "stop",
  125. delaykey[i].str ? delaykey[i].str : "NULL");
  126. # endif
  127. }
  128. /* In order to keep up with incoming data, check timeout only
  129. * when catch up.
  130. */
  131. do {
  132. if (tstc()) {
  133. if (presskey_len < presskey_max) {
  134. presskey [presskey_len ++] = getc();
  135. }
  136. else {
  137. for (i = 0; i < presskey_max - 1; i ++)
  138. presskey [i] = presskey [i + 1];
  139. presskey [i] = getc();
  140. }
  141. }
  142. for (i = 0; i < sizeof(delaykey) / sizeof(delaykey[0]); i ++) {
  143. if (delaykey[i].len > 0 &&
  144. presskey_len >= delaykey[i].len &&
  145. memcmp (presskey + presskey_len - delaykey[i].len,
  146. delaykey[i].str,
  147. delaykey[i].len) == 0) {
  148. # if DEBUG_BOOTKEYS
  149. printf("got %skey\n",
  150. delaykey[i].retry ? "delay" : "stop");
  151. # endif
  152. # ifdef CONFIG_BOOT_RETRY_TIME
  153. /* don't retry auto boot */
  154. if (! delaykey[i].retry)
  155. retry_time = -1;
  156. # endif
  157. abort = 1;
  158. }
  159. }
  160. } while (!abort && get_ticks() <= etime);
  161. # if DEBUG_BOOTKEYS
  162. if (!abort)
  163. puts("key timeout\n");
  164. # endif
  165. #ifdef CONFIG_SILENT_CONSOLE
  166. if (abort)
  167. gd->flags &= ~GD_FLG_SILENT;
  168. #endif
  169. return abort;
  170. }
  171. # else /* !defined(CONFIG_AUTOBOOT_KEYED) */
  172. #ifdef CONFIG_MENUKEY
  173. static int menukey = 0;
  174. #endif
  175. static __inline__ int abortboot(int bootdelay)
  176. {
  177. int abort = 0;
  178. #ifdef CONFIG_MENUPROMPT
  179. printf(CONFIG_MENUPROMPT);
  180. #else
  181. printf("Hit any key to stop autoboot: %2d ", bootdelay);
  182. #endif
  183. #if defined CONFIG_ZERO_BOOTDELAY_CHECK
  184. /*
  185. * Check if key already pressed
  186. * Don't check if bootdelay < 0
  187. */
  188. if (bootdelay >= 0) {
  189. if (tstc()) { /* we got a key press */
  190. (void) getc(); /* consume input */
  191. puts ("\b\b\b 0");
  192. abort = 1; /* don't auto boot */
  193. }
  194. }
  195. #endif
  196. while ((bootdelay > 0) && (!abort)) {
  197. int i;
  198. --bootdelay;
  199. /* delay 100 * 10ms */
  200. for (i=0; !abort && i<100; ++i) {
  201. if (tstc()) { /* we got a key press */
  202. abort = 1; /* don't auto boot */
  203. bootdelay = 0; /* no more delay */
  204. # ifdef CONFIG_MENUKEY
  205. menukey = getc();
  206. # else
  207. (void) getc(); /* consume input */
  208. # endif
  209. break;
  210. }
  211. udelay(10000);
  212. }
  213. printf("\b\b\b%2d ", bootdelay);
  214. }
  215. putc('\n');
  216. #ifdef CONFIG_SILENT_CONSOLE
  217. if (abort)
  218. gd->flags &= ~GD_FLG_SILENT;
  219. #endif
  220. return abort;
  221. }
  222. # endif /* CONFIG_AUTOBOOT_KEYED */
  223. #endif /* CONFIG_BOOTDELAY >= 0 */
  224. /****************************************************************************/
  225. void main_loop (void)
  226. {
  227. #ifndef CONFIG_SYS_HUSH_PARSER
  228. static char lastcommand[CONFIG_SYS_CBSIZE] = { 0, };
  229. int len;
  230. int rc = 1;
  231. int flag;
  232. #endif
  233. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  234. char *s;
  235. int bootdelay;
  236. #endif
  237. #ifdef CONFIG_PREBOOT
  238. char *p;
  239. #endif
  240. #ifdef CONFIG_BOOTCOUNT_LIMIT
  241. unsigned long bootcount = 0;
  242. unsigned long bootlimit = 0;
  243. char *bcs;
  244. char bcs_set[16];
  245. #endif /* CONFIG_BOOTCOUNT_LIMIT */
  246. #if defined(CONFIG_VFD) && defined(VFD_TEST_LOGO)
  247. ulong bmp = 0; /* default bitmap */
  248. extern int trab_vfd (ulong bitmap);
  249. #ifdef CONFIG_MODEM_SUPPORT
  250. if (do_mdm_init)
  251. bmp = 1; /* alternate bitmap */
  252. #endif
  253. trab_vfd (bmp);
  254. #endif /* CONFIG_VFD && VFD_TEST_LOGO */
  255. #ifdef CONFIG_BOOTCOUNT_LIMIT
  256. bootcount = bootcount_load();
  257. bootcount++;
  258. bootcount_store (bootcount);
  259. sprintf (bcs_set, "%lu", bootcount);
  260. setenv ("bootcount", bcs_set);
  261. bcs = getenv ("bootlimit");
  262. bootlimit = bcs ? simple_strtoul (bcs, NULL, 10) : 0;
  263. #endif /* CONFIG_BOOTCOUNT_LIMIT */
  264. #ifdef CONFIG_MODEM_SUPPORT
  265. debug ("DEBUG: main_loop: do_mdm_init=%d\n", do_mdm_init);
  266. if (do_mdm_init) {
  267. char *str = strdup(getenv("mdm_cmd"));
  268. setenv ("preboot", str); /* set or delete definition */
  269. if (str != NULL)
  270. free (str);
  271. mdm_init(); /* wait for modem connection */
  272. }
  273. #endif /* CONFIG_MODEM_SUPPORT */
  274. #ifdef CONFIG_VERSION_VARIABLE
  275. {
  276. extern char version_string[];
  277. setenv ("ver", version_string); /* set version variable */
  278. }
  279. #endif /* CONFIG_VERSION_VARIABLE */
  280. #ifdef CONFIG_SYS_HUSH_PARSER
  281. u_boot_hush_start ();
  282. #endif
  283. #if defined(CONFIG_HUSH_INIT_VAR)
  284. hush_init_var ();
  285. #endif
  286. #ifdef CONFIG_PREBOOT
  287. if ((p = getenv ("preboot")) != NULL) {
  288. # ifdef CONFIG_AUTOBOOT_KEYED
  289. int prev = disable_ctrlc(1); /* disable Control C checking */
  290. # endif
  291. # ifndef CONFIG_SYS_HUSH_PARSER
  292. run_command (p, 0);
  293. # else
  294. parse_string_outer(p, FLAG_PARSE_SEMICOLON |
  295. FLAG_EXIT_FROM_LOOP);
  296. # endif
  297. # ifdef CONFIG_AUTOBOOT_KEYED
  298. disable_ctrlc(prev); /* restore Control C checking */
  299. # endif
  300. }
  301. #endif /* CONFIG_PREBOOT */
  302. #if defined(CONFIG_UPDATE_TFTP)
  303. update_tftp ();
  304. #endif /* CONFIG_UPDATE_TFTP */
  305. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  306. s = getenv ("bootdelay");
  307. bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
  308. debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
  309. # ifdef CONFIG_BOOT_RETRY_TIME
  310. init_cmd_timeout ();
  311. # endif /* CONFIG_BOOT_RETRY_TIME */
  312. #ifdef CONFIG_POST
  313. if (gd->flags & GD_FLG_POSTFAIL) {
  314. s = getenv("failbootcmd");
  315. }
  316. else
  317. #endif /* CONFIG_POST */
  318. #ifdef CONFIG_BOOTCOUNT_LIMIT
  319. if (bootlimit && (bootcount > bootlimit)) {
  320. printf ("Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n",
  321. (unsigned)bootlimit);
  322. s = getenv ("altbootcmd");
  323. }
  324. else
  325. #endif /* CONFIG_BOOTCOUNT_LIMIT */
  326. s = getenv ("bootcmd");
  327. debug ("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");
  328. if (bootdelay >= 0 && s && !abortboot (bootdelay)) {
  329. # ifdef CONFIG_AUTOBOOT_KEYED
  330. int prev = disable_ctrlc(1); /* disable Control C checking */
  331. # endif
  332. # ifndef CONFIG_SYS_HUSH_PARSER
  333. run_command (s, 0);
  334. # else
  335. parse_string_outer(s, FLAG_PARSE_SEMICOLON |
  336. FLAG_EXIT_FROM_LOOP);
  337. # endif
  338. # ifdef CONFIG_AUTOBOOT_KEYED
  339. disable_ctrlc(prev); /* restore Control C checking */
  340. # endif
  341. }
  342. # ifdef CONFIG_MENUKEY
  343. if (menukey == CONFIG_MENUKEY) {
  344. s = getenv("menucmd");
  345. if (s) {
  346. # ifndef CONFIG_SYS_HUSH_PARSER
  347. run_command (s, 0);
  348. # else
  349. parse_string_outer(s, FLAG_PARSE_SEMICOLON |
  350. FLAG_EXIT_FROM_LOOP);
  351. # endif
  352. }
  353. }
  354. #endif /* CONFIG_MENUKEY */
  355. #endif /* CONFIG_BOOTDELAY */
  356. /*
  357. * Main Loop for Monitor Command Processing
  358. */
  359. #ifdef CONFIG_SYS_HUSH_PARSER
  360. parse_file_outer();
  361. /* This point is never reached */
  362. for (;;);
  363. #else
  364. for (;;) {
  365. #ifdef CONFIG_BOOT_RETRY_TIME
  366. if (rc >= 0) {
  367. /* Saw enough of a valid command to
  368. * restart the timeout.
  369. */
  370. reset_cmd_timeout();
  371. }
  372. #endif
  373. len = readline (CONFIG_SYS_PROMPT);
  374. flag = 0; /* assume no special flags for now */
  375. if (len > 0)
  376. strcpy (lastcommand, console_buffer);
  377. else if (len == 0)
  378. flag |= CMD_FLAG_REPEAT;
  379. #ifdef CONFIG_BOOT_RETRY_TIME
  380. else if (len == -2) {
  381. /* -2 means timed out, retry autoboot
  382. */
  383. puts ("\nTimed out waiting for command\n");
  384. # ifdef CONFIG_RESET_TO_RETRY
  385. /* Reinit board to run initialization code again */
  386. do_reset (NULL, 0, 0, NULL);
  387. # else
  388. return; /* retry autoboot */
  389. # endif
  390. }
  391. #endif
  392. if (len == -1)
  393. puts ("<INTERRUPT>\n");
  394. else
  395. rc = run_command (lastcommand, flag);
  396. if (rc <= 0) {
  397. /* invalid command or not repeatable, forget it */
  398. lastcommand[0] = 0;
  399. }
  400. }
  401. #endif /*CONFIG_SYS_HUSH_PARSER*/
  402. }
  403. #ifdef CONFIG_BOOT_RETRY_TIME
  404. /***************************************************************************
  405. * initialize command line timeout
  406. */
  407. void init_cmd_timeout(void)
  408. {
  409. char *s = getenv ("bootretry");
  410. if (s != NULL)
  411. retry_time = (int)simple_strtol(s, NULL, 10);
  412. else
  413. retry_time = CONFIG_BOOT_RETRY_TIME;
  414. if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
  415. retry_time = CONFIG_BOOT_RETRY_MIN;
  416. }
  417. /***************************************************************************
  418. * reset command line timeout to retry_time seconds
  419. */
  420. void reset_cmd_timeout(void)
  421. {
  422. endtime = endtick(retry_time);
  423. }
  424. #endif
  425. #ifdef CONFIG_CMDLINE_EDITING
  426. /*
  427. * cmdline-editing related codes from vivi.
  428. * Author: Janghoon Lyu <nandy@mizi.com>
  429. */
  430. #define putnstr(str,n) do { \
  431. printf ("%.*s", (int)n, str); \
  432. } while (0)
  433. #define CTL_CH(c) ((c) - 'a' + 1)
  434. #define CTL_BACKSPACE ('\b')
  435. #define DEL ((char)255)
  436. #define DEL7 ((char)127)
  437. #define CREAD_HIST_CHAR ('!')
  438. #define getcmd_putch(ch) putc(ch)
  439. #define getcmd_getch() getc()
  440. #define getcmd_cbeep() getcmd_putch('\a')
  441. #define HIST_MAX 20
  442. #define HIST_SIZE CONFIG_SYS_CBSIZE
  443. static int hist_max = 0;
  444. static int hist_add_idx = 0;
  445. static int hist_cur = -1;
  446. unsigned hist_num = 0;
  447. char* hist_list[HIST_MAX];
  448. char hist_lines[HIST_MAX][HIST_SIZE + 1]; /* Save room for NULL */
  449. #define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
  450. static void hist_init(void)
  451. {
  452. int i;
  453. hist_max = 0;
  454. hist_add_idx = 0;
  455. hist_cur = -1;
  456. hist_num = 0;
  457. for (i = 0; i < HIST_MAX; i++) {
  458. hist_list[i] = hist_lines[i];
  459. hist_list[i][0] = '\0';
  460. }
  461. }
  462. static void cread_add_to_hist(char *line)
  463. {
  464. strcpy(hist_list[hist_add_idx], line);
  465. if (++hist_add_idx >= HIST_MAX)
  466. hist_add_idx = 0;
  467. if (hist_add_idx > hist_max)
  468. hist_max = hist_add_idx;
  469. hist_num++;
  470. }
  471. static char* hist_prev(void)
  472. {
  473. char *ret;
  474. int old_cur;
  475. if (hist_cur < 0)
  476. return NULL;
  477. old_cur = hist_cur;
  478. if (--hist_cur < 0)
  479. hist_cur = hist_max;
  480. if (hist_cur == hist_add_idx) {
  481. hist_cur = old_cur;
  482. ret = NULL;
  483. } else
  484. ret = hist_list[hist_cur];
  485. return (ret);
  486. }
  487. static char* hist_next(void)
  488. {
  489. char *ret;
  490. if (hist_cur < 0)
  491. return NULL;
  492. if (hist_cur == hist_add_idx)
  493. return NULL;
  494. if (++hist_cur > hist_max)
  495. hist_cur = 0;
  496. if (hist_cur == hist_add_idx) {
  497. ret = "";
  498. } else
  499. ret = hist_list[hist_cur];
  500. return (ret);
  501. }
  502. #ifndef CONFIG_CMDLINE_EDITING
  503. static void cread_print_hist_list(void)
  504. {
  505. int i;
  506. unsigned long n;
  507. n = hist_num - hist_max;
  508. i = hist_add_idx + 1;
  509. while (1) {
  510. if (i > hist_max)
  511. i = 0;
  512. if (i == hist_add_idx)
  513. break;
  514. printf("%s\n", hist_list[i]);
  515. n++;
  516. i++;
  517. }
  518. }
  519. #endif /* CONFIG_CMDLINE_EDITING */
  520. #define BEGINNING_OF_LINE() { \
  521. while (num) { \
  522. getcmd_putch(CTL_BACKSPACE); \
  523. num--; \
  524. } \
  525. }
  526. #define ERASE_TO_EOL() { \
  527. if (num < eol_num) { \
  528. printf("%*s", (int)(eol_num - num), ""); \
  529. do { \
  530. getcmd_putch(CTL_BACKSPACE); \
  531. } while (--eol_num > num); \
  532. } \
  533. }
  534. #define REFRESH_TO_EOL() { \
  535. if (num < eol_num) { \
  536. wlen = eol_num - num; \
  537. putnstr(buf + num, wlen); \
  538. num = eol_num; \
  539. } \
  540. }
  541. static void cread_add_char(char ichar, int insert, unsigned long *num,
  542. unsigned long *eol_num, char *buf, unsigned long len)
  543. {
  544. unsigned long wlen;
  545. /* room ??? */
  546. if (insert || *num == *eol_num) {
  547. if (*eol_num > len - 1) {
  548. getcmd_cbeep();
  549. return;
  550. }
  551. (*eol_num)++;
  552. }
  553. if (insert) {
  554. wlen = *eol_num - *num;
  555. if (wlen > 1) {
  556. memmove(&buf[*num+1], &buf[*num], wlen-1);
  557. }
  558. buf[*num] = ichar;
  559. putnstr(buf + *num, wlen);
  560. (*num)++;
  561. while (--wlen) {
  562. getcmd_putch(CTL_BACKSPACE);
  563. }
  564. } else {
  565. /* echo the character */
  566. wlen = 1;
  567. buf[*num] = ichar;
  568. putnstr(buf + *num, wlen);
  569. (*num)++;
  570. }
  571. }
  572. static void cread_add_str(char *str, int strsize, int insert, unsigned long *num,
  573. unsigned long *eol_num, char *buf, unsigned long len)
  574. {
  575. while (strsize--) {
  576. cread_add_char(*str, insert, num, eol_num, buf, len);
  577. str++;
  578. }
  579. }
  580. static int cread_line(const char *const prompt, char *buf, unsigned int *len)
  581. {
  582. unsigned long num = 0;
  583. unsigned long eol_num = 0;
  584. unsigned long wlen;
  585. char ichar;
  586. int insert = 1;
  587. int esc_len = 0;
  588. char esc_save[8];
  589. int init_len = strlen(buf);
  590. if (init_len)
  591. cread_add_str(buf, init_len, 1, &num, &eol_num, buf, *len);
  592. while (1) {
  593. #ifdef CONFIG_BOOT_RETRY_TIME
  594. while (!tstc()) { /* while no incoming data */
  595. if (retry_time >= 0 && get_ticks() > endtime)
  596. return (-2); /* timed out */
  597. WATCHDOG_RESET();
  598. }
  599. #endif
  600. ichar = getcmd_getch();
  601. if ((ichar == '\n') || (ichar == '\r')) {
  602. putc('\n');
  603. break;
  604. }
  605. /*
  606. * handle standard linux xterm esc sequences for arrow key, etc.
  607. */
  608. if (esc_len != 0) {
  609. if (esc_len == 1) {
  610. if (ichar == '[') {
  611. esc_save[esc_len] = ichar;
  612. esc_len = 2;
  613. } else {
  614. cread_add_str(esc_save, esc_len, insert,
  615. &num, &eol_num, buf, *len);
  616. esc_len = 0;
  617. }
  618. continue;
  619. }
  620. switch (ichar) {
  621. case 'D': /* <- key */
  622. ichar = CTL_CH('b');
  623. esc_len = 0;
  624. break;
  625. case 'C': /* -> key */
  626. ichar = CTL_CH('f');
  627. esc_len = 0;
  628. break; /* pass off to ^F handler */
  629. case 'H': /* Home key */
  630. ichar = CTL_CH('a');
  631. esc_len = 0;
  632. break; /* pass off to ^A handler */
  633. case 'A': /* up arrow */
  634. ichar = CTL_CH('p');
  635. esc_len = 0;
  636. break; /* pass off to ^P handler */
  637. case 'B': /* down arrow */
  638. ichar = CTL_CH('n');
  639. esc_len = 0;
  640. break; /* pass off to ^N handler */
  641. default:
  642. esc_save[esc_len++] = ichar;
  643. cread_add_str(esc_save, esc_len, insert,
  644. &num, &eol_num, buf, *len);
  645. esc_len = 0;
  646. continue;
  647. }
  648. }
  649. switch (ichar) {
  650. case 0x1b:
  651. if (esc_len == 0) {
  652. esc_save[esc_len] = ichar;
  653. esc_len = 1;
  654. } else {
  655. puts("impossible condition #876\n");
  656. esc_len = 0;
  657. }
  658. break;
  659. case CTL_CH('a'):
  660. BEGINNING_OF_LINE();
  661. break;
  662. case CTL_CH('c'): /* ^C - break */
  663. *buf = '\0'; /* discard input */
  664. return (-1);
  665. case CTL_CH('f'):
  666. if (num < eol_num) {
  667. getcmd_putch(buf[num]);
  668. num++;
  669. }
  670. break;
  671. case CTL_CH('b'):
  672. if (num) {
  673. getcmd_putch(CTL_BACKSPACE);
  674. num--;
  675. }
  676. break;
  677. case CTL_CH('d'):
  678. if (num < eol_num) {
  679. wlen = eol_num - num - 1;
  680. if (wlen) {
  681. memmove(&buf[num], &buf[num+1], wlen);
  682. putnstr(buf + num, wlen);
  683. }
  684. getcmd_putch(' ');
  685. do {
  686. getcmd_putch(CTL_BACKSPACE);
  687. } while (wlen--);
  688. eol_num--;
  689. }
  690. break;
  691. case CTL_CH('k'):
  692. ERASE_TO_EOL();
  693. break;
  694. case CTL_CH('e'):
  695. REFRESH_TO_EOL();
  696. break;
  697. case CTL_CH('o'):
  698. insert = !insert;
  699. break;
  700. case CTL_CH('x'):
  701. case CTL_CH('u'):
  702. BEGINNING_OF_LINE();
  703. ERASE_TO_EOL();
  704. break;
  705. case DEL:
  706. case DEL7:
  707. case 8:
  708. if (num) {
  709. wlen = eol_num - num;
  710. num--;
  711. memmove(&buf[num], &buf[num+1], wlen);
  712. getcmd_putch(CTL_BACKSPACE);
  713. putnstr(buf + num, wlen);
  714. getcmd_putch(' ');
  715. do {
  716. getcmd_putch(CTL_BACKSPACE);
  717. } while (wlen--);
  718. eol_num--;
  719. }
  720. break;
  721. case CTL_CH('p'):
  722. case CTL_CH('n'):
  723. {
  724. char * hline;
  725. esc_len = 0;
  726. if (ichar == CTL_CH('p'))
  727. hline = hist_prev();
  728. else
  729. hline = hist_next();
  730. if (!hline) {
  731. getcmd_cbeep();
  732. continue;
  733. }
  734. /* nuke the current line */
  735. /* first, go home */
  736. BEGINNING_OF_LINE();
  737. /* erase to end of line */
  738. ERASE_TO_EOL();
  739. /* copy new line into place and display */
  740. strcpy(buf, hline);
  741. eol_num = strlen(buf);
  742. REFRESH_TO_EOL();
  743. continue;
  744. }
  745. #ifdef CONFIG_AUTO_COMPLETE
  746. case '\t': {
  747. int num2, col;
  748. /* do not autocomplete when in the middle */
  749. if (num < eol_num) {
  750. getcmd_cbeep();
  751. break;
  752. }
  753. buf[num] = '\0';
  754. col = strlen(prompt) + eol_num;
  755. num2 = num;
  756. if (cmd_auto_complete(prompt, buf, &num2, &col)) {
  757. col = num2 - num;
  758. num += col;
  759. eol_num += col;
  760. }
  761. break;
  762. }
  763. #endif
  764. default:
  765. cread_add_char(ichar, insert, &num, &eol_num, buf, *len);
  766. break;
  767. }
  768. }
  769. *len = eol_num;
  770. buf[eol_num] = '\0'; /* lose the newline */
  771. if (buf[0] && buf[0] != CREAD_HIST_CHAR)
  772. cread_add_to_hist(buf);
  773. hist_cur = hist_add_idx;
  774. return 0;
  775. }
  776. #endif /* CONFIG_CMDLINE_EDITING */
  777. /****************************************************************************/
  778. /*
  779. * Prompt for input and read a line.
  780. * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0,
  781. * time out when time goes past endtime (timebase time in ticks).
  782. * Return: number of read characters
  783. * -1 if break
  784. * -2 if timed out
  785. */
  786. int readline (const char *const prompt)
  787. {
  788. /*
  789. * If console_buffer isn't 0-length the user will be prompted to modify
  790. * it instead of entering it from scratch as desired.
  791. */
  792. console_buffer[0] = '\0';
  793. return readline_into_buffer(prompt, console_buffer);
  794. }
  795. int readline_into_buffer (const char *const prompt, char * buffer)
  796. {
  797. char *p = buffer;
  798. #ifdef CONFIG_CMDLINE_EDITING
  799. unsigned int len = CONFIG_SYS_CBSIZE;
  800. int rc;
  801. static int initted = 0;
  802. /*
  803. * History uses a global array which is not
  804. * writable until after relocation to RAM.
  805. * Revert to non-history version if still
  806. * running from flash.
  807. */
  808. if (gd->flags & GD_FLG_RELOC) {
  809. if (!initted) {
  810. hist_init();
  811. initted = 1;
  812. }
  813. if (prompt)
  814. puts (prompt);
  815. rc = cread_line(prompt, p, &len);
  816. return rc < 0 ? rc : len;
  817. } else {
  818. #endif /* CONFIG_CMDLINE_EDITING */
  819. char * p_buf = p;
  820. int n = 0; /* buffer index */
  821. int plen = 0; /* prompt length */
  822. int col; /* output column cnt */
  823. char c;
  824. /* print prompt */
  825. if (prompt) {
  826. plen = strlen (prompt);
  827. puts (prompt);
  828. }
  829. col = plen;
  830. for (;;) {
  831. #ifdef CONFIG_BOOT_RETRY_TIME
  832. while (!tstc()) { /* while no incoming data */
  833. if (retry_time >= 0 && get_ticks() > endtime)
  834. return (-2); /* timed out */
  835. WATCHDOG_RESET();
  836. }
  837. #endif
  838. WATCHDOG_RESET(); /* Trigger watchdog, if needed */
  839. #ifdef CONFIG_SHOW_ACTIVITY
  840. while (!tstc()) {
  841. extern void show_activity(int arg);
  842. show_activity(0);
  843. WATCHDOG_RESET();
  844. }
  845. #endif
  846. c = getc();
  847. /*
  848. * Special character handling
  849. */
  850. switch (c) {
  851. case '\r': /* Enter */
  852. case '\n':
  853. *p = '\0';
  854. puts ("\r\n");
  855. return (p - p_buf);
  856. case '\0': /* nul */
  857. continue;
  858. case 0x03: /* ^C - break */
  859. p_buf[0] = '\0'; /* discard input */
  860. return (-1);
  861. case 0x15: /* ^U - erase line */
  862. while (col > plen) {
  863. puts (erase_seq);
  864. --col;
  865. }
  866. p = p_buf;
  867. n = 0;
  868. continue;
  869. case 0x17: /* ^W - erase word */
  870. p=delete_char(p_buf, p, &col, &n, plen);
  871. while ((n > 0) && (*p != ' ')) {
  872. p=delete_char(p_buf, p, &col, &n, plen);
  873. }
  874. continue;
  875. case 0x08: /* ^H - backspace */
  876. case 0x7F: /* DEL - backspace */
  877. p=delete_char(p_buf, p, &col, &n, plen);
  878. continue;
  879. default:
  880. /*
  881. * Must be a normal character then
  882. */
  883. if (n < CONFIG_SYS_CBSIZE-2) {
  884. if (c == '\t') { /* expand TABs */
  885. #ifdef CONFIG_AUTO_COMPLETE
  886. /* if auto completion triggered just continue */
  887. *p = '\0';
  888. if (cmd_auto_complete(prompt, console_buffer, &n, &col)) {
  889. p = p_buf + n; /* reset */
  890. continue;
  891. }
  892. #endif
  893. puts (tab_seq+(col&07));
  894. col += 8 - (col&07);
  895. } else {
  896. ++col; /* echo input */
  897. putc (c);
  898. }
  899. *p++ = c;
  900. ++n;
  901. } else { /* Buffer full */
  902. putc ('\a');
  903. }
  904. }
  905. }
  906. #ifdef CONFIG_CMDLINE_EDITING
  907. }
  908. #endif
  909. }
  910. /****************************************************************************/
  911. static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen)
  912. {
  913. char *s;
  914. if (*np == 0) {
  915. return (p);
  916. }
  917. if (*(--p) == '\t') { /* will retype the whole line */
  918. while (*colp > plen) {
  919. puts (erase_seq);
  920. (*colp)--;
  921. }
  922. for (s=buffer; s<p; ++s) {
  923. if (*s == '\t') {
  924. puts (tab_seq+((*colp) & 07));
  925. *colp += 8 - ((*colp) & 07);
  926. } else {
  927. ++(*colp);
  928. putc (*s);
  929. }
  930. }
  931. } else {
  932. puts (erase_seq);
  933. (*colp)--;
  934. }
  935. (*np)--;
  936. return (p);
  937. }
  938. /****************************************************************************/
  939. int parse_line (char *line, char *argv[])
  940. {
  941. int nargs = 0;
  942. #ifdef DEBUG_PARSER
  943. printf ("parse_line: \"%s\"\n", line);
  944. #endif
  945. while (nargs < CONFIG_SYS_MAXARGS) {
  946. /* skip any white space */
  947. while ((*line == ' ') || (*line == '\t')) {
  948. ++line;
  949. }
  950. if (*line == '\0') { /* end of line, no more args */
  951. argv[nargs] = NULL;
  952. #ifdef DEBUG_PARSER
  953. printf ("parse_line: nargs=%d\n", nargs);
  954. #endif
  955. return (nargs);
  956. }
  957. argv[nargs++] = line; /* begin of argument string */
  958. /* find end of string */
  959. while (*line && (*line != ' ') && (*line != '\t')) {
  960. ++line;
  961. }
  962. if (*line == '\0') { /* end of line, no more args */
  963. argv[nargs] = NULL;
  964. #ifdef DEBUG_PARSER
  965. printf ("parse_line: nargs=%d\n", nargs);
  966. #endif
  967. return (nargs);
  968. }
  969. *line++ = '\0'; /* terminate current arg */
  970. }
  971. printf ("** Too many args (max. %d) **\n", CONFIG_SYS_MAXARGS);
  972. #ifdef DEBUG_PARSER
  973. printf ("parse_line: nargs=%d\n", nargs);
  974. #endif
  975. return (nargs);
  976. }
  977. /****************************************************************************/
  978. static void process_macros (const char *input, char *output)
  979. {
  980. char c, prev;
  981. const char *varname_start = NULL;
  982. int inputcnt = strlen (input);
  983. int outputcnt = CONFIG_SYS_CBSIZE;
  984. int state = 0; /* 0 = waiting for '$' */
  985. /* 1 = waiting for '(' or '{' */
  986. /* 2 = waiting for ')' or '}' */
  987. /* 3 = waiting for ''' */
  988. #ifdef DEBUG_PARSER
  989. char *output_start = output;
  990. printf ("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", strlen (input),
  991. input);
  992. #endif
  993. prev = '\0'; /* previous character */
  994. while (inputcnt && outputcnt) {
  995. c = *input++;
  996. inputcnt--;
  997. if (state != 3) {
  998. /* remove one level of escape characters */
  999. if ((c == '\\') && (prev != '\\')) {
  1000. if (inputcnt-- == 0)
  1001. break;
  1002. prev = c;
  1003. c = *input++;
  1004. }
  1005. }
  1006. switch (state) {
  1007. case 0: /* Waiting for (unescaped) $ */
  1008. if ((c == '\'') && (prev != '\\')) {
  1009. state = 3;
  1010. break;
  1011. }
  1012. if ((c == '$') && (prev != '\\')) {
  1013. state++;
  1014. } else {
  1015. *(output++) = c;
  1016. outputcnt--;
  1017. }
  1018. break;
  1019. case 1: /* Waiting for ( */
  1020. if (c == '(' || c == '{') {
  1021. state++;
  1022. varname_start = input;
  1023. } else {
  1024. state = 0;
  1025. *(output++) = '$';
  1026. outputcnt--;
  1027. if (outputcnt) {
  1028. *(output++) = c;
  1029. outputcnt--;
  1030. }
  1031. }
  1032. break;
  1033. case 2: /* Waiting for ) */
  1034. if (c == ')' || c == '}') {
  1035. int i;
  1036. char envname[CONFIG_SYS_CBSIZE], *envval;
  1037. int envcnt = input - varname_start - 1; /* Varname # of chars */
  1038. /* Get the varname */
  1039. for (i = 0; i < envcnt; i++) {
  1040. envname[i] = varname_start[i];
  1041. }
  1042. envname[i] = 0;
  1043. /* Get its value */
  1044. envval = getenv (envname);
  1045. /* Copy into the line if it exists */
  1046. if (envval != NULL)
  1047. while ((*envval) && outputcnt) {
  1048. *(output++) = *(envval++);
  1049. outputcnt--;
  1050. }
  1051. /* Look for another '$' */
  1052. state = 0;
  1053. }
  1054. break;
  1055. case 3: /* Waiting for ' */
  1056. if ((c == '\'') && (prev != '\\')) {
  1057. state = 0;
  1058. } else {
  1059. *(output++) = c;
  1060. outputcnt--;
  1061. }
  1062. break;
  1063. }
  1064. prev = c;
  1065. }
  1066. if (outputcnt)
  1067. *output = 0;
  1068. else
  1069. *(output - 1) = 0;
  1070. #ifdef DEBUG_PARSER
  1071. printf ("[PROCESS_MACROS] OUTPUT len %d: \"%s\"\n",
  1072. strlen (output_start), output_start);
  1073. #endif
  1074. }
  1075. /****************************************************************************
  1076. * returns:
  1077. * 1 - command executed, repeatable
  1078. * 0 - command executed but not repeatable, interrupted commands are
  1079. * always considered not repeatable
  1080. * -1 - not executed (unrecognized, bootd recursion or too many args)
  1081. * (If cmd is NULL or "" or longer than CONFIG_SYS_CBSIZE-1 it is
  1082. * considered unrecognized)
  1083. *
  1084. * WARNING:
  1085. *
  1086. * We must create a temporary copy of the command since the command we get
  1087. * may be the result from getenv(), which returns a pointer directly to
  1088. * the environment data, which may change magicly when the command we run
  1089. * creates or modifies environment variables (like "bootp" does).
  1090. */
  1091. int run_command (const char *cmd, int flag)
  1092. {
  1093. cmd_tbl_t *cmdtp;
  1094. char cmdbuf[CONFIG_SYS_CBSIZE]; /* working copy of cmd */
  1095. char *token; /* start of token in cmdbuf */
  1096. char *sep; /* end of token (separator) in cmdbuf */
  1097. char finaltoken[CONFIG_SYS_CBSIZE];
  1098. char *str = cmdbuf;
  1099. char *argv[CONFIG_SYS_MAXARGS + 1]; /* NULL terminated */
  1100. int argc, inquotes;
  1101. int repeatable = 1;
  1102. int rc = 0;
  1103. #ifdef DEBUG_PARSER
  1104. printf ("[RUN_COMMAND] cmd[%p]=\"", cmd);
  1105. puts (cmd ? cmd : "NULL"); /* use puts - string may be loooong */
  1106. puts ("\"\n");
  1107. #endif
  1108. clear_ctrlc(); /* forget any previous Control C */
  1109. if (!cmd || !*cmd) {
  1110. return -1; /* empty command */
  1111. }
  1112. if (strlen(cmd) >= CONFIG_SYS_CBSIZE) {
  1113. puts ("## Command too long!\n");
  1114. return -1;
  1115. }
  1116. strcpy (cmdbuf, cmd);
  1117. /* Process separators and check for invalid
  1118. * repeatable commands
  1119. */
  1120. #ifdef DEBUG_PARSER
  1121. printf ("[PROCESS_SEPARATORS] %s\n", cmd);
  1122. #endif
  1123. while (*str) {
  1124. /*
  1125. * Find separator, or string end
  1126. * Allow simple escape of ';' by writing "\;"
  1127. */
  1128. for (inquotes = 0, sep = str; *sep; sep++) {
  1129. if ((*sep=='\'') &&
  1130. (*(sep-1) != '\\'))
  1131. inquotes=!inquotes;
  1132. if (!inquotes &&
  1133. (*sep == ';') && /* separator */
  1134. ( sep != str) && /* past string start */
  1135. (*(sep-1) != '\\')) /* and NOT escaped */
  1136. break;
  1137. }
  1138. /*
  1139. * Limit the token to data between separators
  1140. */
  1141. token = str;
  1142. if (*sep) {
  1143. str = sep + 1; /* start of command for next pass */
  1144. *sep = '\0';
  1145. }
  1146. else
  1147. str = sep; /* no more commands for next pass */
  1148. #ifdef DEBUG_PARSER
  1149. printf ("token: \"%s\"\n", token);
  1150. #endif
  1151. /* find macros in this token and replace them */
  1152. process_macros (token, finaltoken);
  1153. /* Extract arguments */
  1154. if ((argc = parse_line (finaltoken, argv)) == 0) {
  1155. rc = -1; /* no command at all */
  1156. continue;
  1157. }
  1158. /* Look up command in command table */
  1159. if ((cmdtp = find_cmd(argv[0])) == NULL) {
  1160. printf ("Unknown command '%s' - try 'help'\n", argv[0]);
  1161. rc = -1; /* give up after bad command */
  1162. continue;
  1163. }
  1164. /* found - check max args */
  1165. if (argc > cmdtp->maxargs) {
  1166. cmd_usage(cmdtp);
  1167. rc = -1;
  1168. continue;
  1169. }
  1170. #if defined(CONFIG_CMD_BOOTD)
  1171. /* avoid "bootd" recursion */
  1172. if (cmdtp->cmd == do_bootd) {
  1173. #ifdef DEBUG_PARSER
  1174. printf ("[%s]\n", finaltoken);
  1175. #endif
  1176. if (flag & CMD_FLAG_BOOTD) {
  1177. puts ("'bootd' recursion detected\n");
  1178. rc = -1;
  1179. continue;
  1180. } else {
  1181. flag |= CMD_FLAG_BOOTD;
  1182. }
  1183. }
  1184. #endif
  1185. /* OK - call function to do the command */
  1186. if ((cmdtp->cmd) (cmdtp, flag, argc, argv) != 0) {
  1187. rc = -1;
  1188. }
  1189. repeatable &= cmdtp->repeatable;
  1190. /* Did the user stop this? */
  1191. if (had_ctrlc ())
  1192. return -1; /* if stopped then not repeatable */
  1193. }
  1194. return rc ? rc : repeatable;
  1195. }
  1196. /****************************************************************************/
  1197. #if defined(CONFIG_CMD_RUN)
  1198. int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1199. {
  1200. int i;
  1201. if (argc < 2)
  1202. return cmd_usage(cmdtp);
  1203. for (i=1; i<argc; ++i) {
  1204. char *arg;
  1205. if ((arg = getenv (argv[i])) == NULL) {
  1206. printf ("## Error: \"%s\" not defined\n", argv[i]);
  1207. return 1;
  1208. }
  1209. #ifndef CONFIG_SYS_HUSH_PARSER
  1210. if (run_command (arg, flag) == -1)
  1211. return 1;
  1212. #else
  1213. if (parse_string_outer(arg,
  1214. FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
  1215. return 1;
  1216. #endif
  1217. }
  1218. return 0;
  1219. }
  1220. #endif