main.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  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 char erase_seq[] = "\b \b"; /* erase sequence */
  57. static 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_AUTO_COMPLETE
  287. install_auto_complete();
  288. #endif
  289. #ifdef CONFIG_PREBOOT
  290. if ((p = getenv ("preboot")) != NULL) {
  291. # ifdef CONFIG_AUTOBOOT_KEYED
  292. int prev = disable_ctrlc(1); /* disable Control C checking */
  293. # endif
  294. # ifndef CONFIG_SYS_HUSH_PARSER
  295. run_command (p, 0);
  296. # else
  297. parse_string_outer(p, FLAG_PARSE_SEMICOLON |
  298. FLAG_EXIT_FROM_LOOP);
  299. # endif
  300. # ifdef CONFIG_AUTOBOOT_KEYED
  301. disable_ctrlc(prev); /* restore Control C checking */
  302. # endif
  303. }
  304. #endif /* CONFIG_PREBOOT */
  305. #if defined(CONFIG_UPDATE_TFTP)
  306. update_tftp ();
  307. #endif /* CONFIG_UPDATE_TFTP */
  308. #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
  309. s = getenv ("bootdelay");
  310. bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
  311. debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
  312. # ifdef CONFIG_BOOT_RETRY_TIME
  313. init_cmd_timeout ();
  314. # endif /* CONFIG_BOOT_RETRY_TIME */
  315. #ifdef CONFIG_POST
  316. if (gd->flags & GD_FLG_POSTFAIL) {
  317. s = getenv("failbootcmd");
  318. }
  319. else
  320. #endif /* CONFIG_POST */
  321. #ifdef CONFIG_BOOTCOUNT_LIMIT
  322. if (bootlimit && (bootcount > bootlimit)) {
  323. printf ("Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n",
  324. (unsigned)bootlimit);
  325. s = getenv ("altbootcmd");
  326. }
  327. else
  328. #endif /* CONFIG_BOOTCOUNT_LIMIT */
  329. s = getenv ("bootcmd");
  330. debug ("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");
  331. if (bootdelay >= 0 && s && !abortboot (bootdelay)) {
  332. # ifdef CONFIG_AUTOBOOT_KEYED
  333. int prev = disable_ctrlc(1); /* disable Control C checking */
  334. # endif
  335. # ifndef CONFIG_SYS_HUSH_PARSER
  336. run_command (s, 0);
  337. # else
  338. parse_string_outer(s, FLAG_PARSE_SEMICOLON |
  339. FLAG_EXIT_FROM_LOOP);
  340. # endif
  341. # ifdef CONFIG_AUTOBOOT_KEYED
  342. disable_ctrlc(prev); /* restore Control C checking */
  343. # endif
  344. }
  345. # ifdef CONFIG_MENUKEY
  346. if (menukey == CONFIG_MENUKEY) {
  347. s = getenv("menucmd");
  348. if (s) {
  349. # ifndef CONFIG_SYS_HUSH_PARSER
  350. run_command (s, 0);
  351. # else
  352. parse_string_outer(s, FLAG_PARSE_SEMICOLON |
  353. FLAG_EXIT_FROM_LOOP);
  354. # endif
  355. }
  356. }
  357. #endif /* CONFIG_MENUKEY */
  358. #endif /* CONFIG_BOOTDELAY */
  359. /*
  360. * Main Loop for Monitor Command Processing
  361. */
  362. #ifdef CONFIG_SYS_HUSH_PARSER
  363. parse_file_outer();
  364. /* This point is never reached */
  365. for (;;);
  366. #else
  367. for (;;) {
  368. #ifdef CONFIG_BOOT_RETRY_TIME
  369. if (rc >= 0) {
  370. /* Saw enough of a valid command to
  371. * restart the timeout.
  372. */
  373. reset_cmd_timeout();
  374. }
  375. #endif
  376. len = readline (CONFIG_SYS_PROMPT);
  377. flag = 0; /* assume no special flags for now */
  378. if (len > 0)
  379. strcpy (lastcommand, console_buffer);
  380. else if (len == 0)
  381. flag |= CMD_FLAG_REPEAT;
  382. #ifdef CONFIG_BOOT_RETRY_TIME
  383. else if (len == -2) {
  384. /* -2 means timed out, retry autoboot
  385. */
  386. puts ("\nTimed out waiting for command\n");
  387. # ifdef CONFIG_RESET_TO_RETRY
  388. /* Reinit board to run initialization code again */
  389. do_reset (NULL, 0, 0, NULL);
  390. # else
  391. return; /* retry autoboot */
  392. # endif
  393. }
  394. #endif
  395. if (len == -1)
  396. puts ("<INTERRUPT>\n");
  397. else
  398. rc = run_command (lastcommand, flag);
  399. if (rc <= 0) {
  400. /* invalid command or not repeatable, forget it */
  401. lastcommand[0] = 0;
  402. }
  403. }
  404. #endif /*CONFIG_SYS_HUSH_PARSER*/
  405. }
  406. #ifdef CONFIG_BOOT_RETRY_TIME
  407. /***************************************************************************
  408. * initialize command line timeout
  409. */
  410. void init_cmd_timeout(void)
  411. {
  412. char *s = getenv ("bootretry");
  413. if (s != NULL)
  414. retry_time = (int)simple_strtol(s, NULL, 10);
  415. else
  416. retry_time = CONFIG_BOOT_RETRY_TIME;
  417. if (retry_time >= 0 && retry_time < CONFIG_BOOT_RETRY_MIN)
  418. retry_time = CONFIG_BOOT_RETRY_MIN;
  419. }
  420. /***************************************************************************
  421. * reset command line timeout to retry_time seconds
  422. */
  423. void reset_cmd_timeout(void)
  424. {
  425. endtime = endtick(retry_time);
  426. }
  427. #endif
  428. #ifdef CONFIG_CMDLINE_EDITING
  429. /*
  430. * cmdline-editing related codes from vivi.
  431. * Author: Janghoon Lyu <nandy@mizi.com>
  432. */
  433. #define putnstr(str,n) do { \
  434. printf ("%.*s", (int)n, str); \
  435. } while (0)
  436. #define CTL_CH(c) ((c) - 'a' + 1)
  437. #define CTL_BACKSPACE ('\b')
  438. #define DEL ((char)255)
  439. #define DEL7 ((char)127)
  440. #define CREAD_HIST_CHAR ('!')
  441. #define getcmd_putch(ch) putc(ch)
  442. #define getcmd_getch() getc()
  443. #define getcmd_cbeep() getcmd_putch('\a')
  444. #define HIST_MAX 20
  445. #define HIST_SIZE CONFIG_SYS_CBSIZE
  446. static int hist_max = 0;
  447. static int hist_add_idx = 0;
  448. static int hist_cur = -1;
  449. unsigned hist_num = 0;
  450. char* hist_list[HIST_MAX];
  451. char hist_lines[HIST_MAX][HIST_SIZE + 1]; /* Save room for NULL */
  452. #define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
  453. static void hist_init(void)
  454. {
  455. int i;
  456. hist_max = 0;
  457. hist_add_idx = 0;
  458. hist_cur = -1;
  459. hist_num = 0;
  460. for (i = 0; i < HIST_MAX; i++) {
  461. hist_list[i] = hist_lines[i];
  462. hist_list[i][0] = '\0';
  463. }
  464. }
  465. static void cread_add_to_hist(char *line)
  466. {
  467. strcpy(hist_list[hist_add_idx], line);
  468. if (++hist_add_idx >= HIST_MAX)
  469. hist_add_idx = 0;
  470. if (hist_add_idx > hist_max)
  471. hist_max = hist_add_idx;
  472. hist_num++;
  473. }
  474. static char* hist_prev(void)
  475. {
  476. char *ret;
  477. int old_cur;
  478. if (hist_cur < 0)
  479. return NULL;
  480. old_cur = hist_cur;
  481. if (--hist_cur < 0)
  482. hist_cur = hist_max;
  483. if (hist_cur == hist_add_idx) {
  484. hist_cur = old_cur;
  485. ret = NULL;
  486. } else
  487. ret = hist_list[hist_cur];
  488. return (ret);
  489. }
  490. static char* hist_next(void)
  491. {
  492. char *ret;
  493. if (hist_cur < 0)
  494. return NULL;
  495. if (hist_cur == hist_add_idx)
  496. return NULL;
  497. if (++hist_cur > hist_max)
  498. hist_cur = 0;
  499. if (hist_cur == hist_add_idx) {
  500. ret = "";
  501. } else
  502. ret = hist_list[hist_cur];
  503. return (ret);
  504. }
  505. #ifndef CONFIG_CMDLINE_EDITING
  506. static void cread_print_hist_list(void)
  507. {
  508. int i;
  509. unsigned long n;
  510. n = hist_num - hist_max;
  511. i = hist_add_idx + 1;
  512. while (1) {
  513. if (i > hist_max)
  514. i = 0;
  515. if (i == hist_add_idx)
  516. break;
  517. printf("%s\n", hist_list[i]);
  518. n++;
  519. i++;
  520. }
  521. }
  522. #endif /* CONFIG_CMDLINE_EDITING */
  523. #define BEGINNING_OF_LINE() { \
  524. while (num) { \
  525. getcmd_putch(CTL_BACKSPACE); \
  526. num--; \
  527. } \
  528. }
  529. #define ERASE_TO_EOL() { \
  530. if (num < eol_num) { \
  531. printf("%*s", (int)(eol_num - num), ""); \
  532. do { \
  533. getcmd_putch(CTL_BACKSPACE); \
  534. } while (--eol_num > num); \
  535. } \
  536. }
  537. #define REFRESH_TO_EOL() { \
  538. if (num < eol_num) { \
  539. wlen = eol_num - num; \
  540. putnstr(buf + num, wlen); \
  541. num = eol_num; \
  542. } \
  543. }
  544. static void cread_add_char(char ichar, int insert, unsigned long *num,
  545. unsigned long *eol_num, char *buf, unsigned long len)
  546. {
  547. unsigned long wlen;
  548. /* room ??? */
  549. if (insert || *num == *eol_num) {
  550. if (*eol_num > len - 1) {
  551. getcmd_cbeep();
  552. return;
  553. }
  554. (*eol_num)++;
  555. }
  556. if (insert) {
  557. wlen = *eol_num - *num;
  558. if (wlen > 1) {
  559. memmove(&buf[*num+1], &buf[*num], wlen-1);
  560. }
  561. buf[*num] = ichar;
  562. putnstr(buf + *num, wlen);
  563. (*num)++;
  564. while (--wlen) {
  565. getcmd_putch(CTL_BACKSPACE);
  566. }
  567. } else {
  568. /* echo the character */
  569. wlen = 1;
  570. buf[*num] = ichar;
  571. putnstr(buf + *num, wlen);
  572. (*num)++;
  573. }
  574. }
  575. static void cread_add_str(char *str, int strsize, int insert, unsigned long *num,
  576. unsigned long *eol_num, char *buf, unsigned long len)
  577. {
  578. while (strsize--) {
  579. cread_add_char(*str, insert, num, eol_num, buf, len);
  580. str++;
  581. }
  582. }
  583. static int cread_line(const char *const prompt, char *buf, unsigned int *len)
  584. {
  585. unsigned long num = 0;
  586. unsigned long eol_num = 0;
  587. unsigned long wlen;
  588. char ichar;
  589. int insert = 1;
  590. int esc_len = 0;
  591. char esc_save[8];
  592. int init_len = strlen(buf);
  593. if (init_len)
  594. cread_add_str(buf, init_len, 1, &num, &eol_num, buf, *len);
  595. while (1) {
  596. #ifdef CONFIG_BOOT_RETRY_TIME
  597. while (!tstc()) { /* while no incoming data */
  598. if (retry_time >= 0 && get_ticks() > endtime)
  599. return (-2); /* timed out */
  600. WATCHDOG_RESET();
  601. }
  602. #endif
  603. ichar = getcmd_getch();
  604. if ((ichar == '\n') || (ichar == '\r')) {
  605. putc('\n');
  606. break;
  607. }
  608. /*
  609. * handle standard linux xterm esc sequences for arrow key, etc.
  610. */
  611. if (esc_len != 0) {
  612. if (esc_len == 1) {
  613. if (ichar == '[') {
  614. esc_save[esc_len] = ichar;
  615. esc_len = 2;
  616. } else {
  617. cread_add_str(esc_save, esc_len, insert,
  618. &num, &eol_num, buf, *len);
  619. esc_len = 0;
  620. }
  621. continue;
  622. }
  623. switch (ichar) {
  624. case 'D': /* <- key */
  625. ichar = CTL_CH('b');
  626. esc_len = 0;
  627. break;
  628. case 'C': /* -> key */
  629. ichar = CTL_CH('f');
  630. esc_len = 0;
  631. break; /* pass off to ^F handler */
  632. case 'H': /* Home key */
  633. ichar = CTL_CH('a');
  634. esc_len = 0;
  635. break; /* pass off to ^A handler */
  636. case 'A': /* up arrow */
  637. ichar = CTL_CH('p');
  638. esc_len = 0;
  639. break; /* pass off to ^P handler */
  640. case 'B': /* down arrow */
  641. ichar = CTL_CH('n');
  642. esc_len = 0;
  643. break; /* pass off to ^N handler */
  644. default:
  645. esc_save[esc_len++] = ichar;
  646. cread_add_str(esc_save, esc_len, insert,
  647. &num, &eol_num, buf, *len);
  648. esc_len = 0;
  649. continue;
  650. }
  651. }
  652. switch (ichar) {
  653. case 0x1b:
  654. if (esc_len == 0) {
  655. esc_save[esc_len] = ichar;
  656. esc_len = 1;
  657. } else {
  658. puts("impossible condition #876\n");
  659. esc_len = 0;
  660. }
  661. break;
  662. case CTL_CH('a'):
  663. BEGINNING_OF_LINE();
  664. break;
  665. case CTL_CH('c'): /* ^C - break */
  666. *buf = '\0'; /* discard input */
  667. return (-1);
  668. case CTL_CH('f'):
  669. if (num < eol_num) {
  670. getcmd_putch(buf[num]);
  671. num++;
  672. }
  673. break;
  674. case CTL_CH('b'):
  675. if (num) {
  676. getcmd_putch(CTL_BACKSPACE);
  677. num--;
  678. }
  679. break;
  680. case CTL_CH('d'):
  681. if (num < eol_num) {
  682. wlen = eol_num - num - 1;
  683. if (wlen) {
  684. memmove(&buf[num], &buf[num+1], wlen);
  685. putnstr(buf + num, wlen);
  686. }
  687. getcmd_putch(' ');
  688. do {
  689. getcmd_putch(CTL_BACKSPACE);
  690. } while (wlen--);
  691. eol_num--;
  692. }
  693. break;
  694. case CTL_CH('k'):
  695. ERASE_TO_EOL();
  696. break;
  697. case CTL_CH('e'):
  698. REFRESH_TO_EOL();
  699. break;
  700. case CTL_CH('o'):
  701. insert = !insert;
  702. break;
  703. case CTL_CH('x'):
  704. case CTL_CH('u'):
  705. BEGINNING_OF_LINE();
  706. ERASE_TO_EOL();
  707. break;
  708. case DEL:
  709. case DEL7:
  710. case 8:
  711. if (num) {
  712. wlen = eol_num - num;
  713. num--;
  714. memmove(&buf[num], &buf[num+1], wlen);
  715. getcmd_putch(CTL_BACKSPACE);
  716. putnstr(buf + num, wlen);
  717. getcmd_putch(' ');
  718. do {
  719. getcmd_putch(CTL_BACKSPACE);
  720. } while (wlen--);
  721. eol_num--;
  722. }
  723. break;
  724. case CTL_CH('p'):
  725. case CTL_CH('n'):
  726. {
  727. char * hline;
  728. esc_len = 0;
  729. if (ichar == CTL_CH('p'))
  730. hline = hist_prev();
  731. else
  732. hline = hist_next();
  733. if (!hline) {
  734. getcmd_cbeep();
  735. continue;
  736. }
  737. /* nuke the current line */
  738. /* first, go home */
  739. BEGINNING_OF_LINE();
  740. /* erase to end of line */
  741. ERASE_TO_EOL();
  742. /* copy new line into place and display */
  743. strcpy(buf, hline);
  744. eol_num = strlen(buf);
  745. REFRESH_TO_EOL();
  746. continue;
  747. }
  748. #ifdef CONFIG_AUTO_COMPLETE
  749. case '\t': {
  750. int num2, col;
  751. /* do not autocomplete when in the middle */
  752. if (num < eol_num) {
  753. getcmd_cbeep();
  754. break;
  755. }
  756. buf[num] = '\0';
  757. col = strlen(prompt) + eol_num;
  758. num2 = num;
  759. if (cmd_auto_complete(prompt, buf, &num2, &col)) {
  760. col = num2 - num;
  761. num += col;
  762. eol_num += col;
  763. }
  764. break;
  765. }
  766. #endif
  767. default:
  768. cread_add_char(ichar, insert, &num, &eol_num, buf, *len);
  769. break;
  770. }
  771. }
  772. *len = eol_num;
  773. buf[eol_num] = '\0'; /* lose the newline */
  774. if (buf[0] && buf[0] != CREAD_HIST_CHAR)
  775. cread_add_to_hist(buf);
  776. hist_cur = hist_add_idx;
  777. return 0;
  778. }
  779. #endif /* CONFIG_CMDLINE_EDITING */
  780. /****************************************************************************/
  781. /*
  782. * Prompt for input and read a line.
  783. * If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0,
  784. * time out when time goes past endtime (timebase time in ticks).
  785. * Return: number of read characters
  786. * -1 if break
  787. * -2 if timed out
  788. */
  789. int readline (const char *const prompt)
  790. {
  791. /*
  792. * If console_buffer isn't 0-length the user will be prompted to modify
  793. * it instead of entering it from scratch as desired.
  794. */
  795. console_buffer[0] = '\0';
  796. return readline_into_buffer(prompt, console_buffer);
  797. }
  798. int readline_into_buffer (const char *const prompt, char * buffer)
  799. {
  800. char *p = buffer;
  801. #ifdef CONFIG_CMDLINE_EDITING
  802. unsigned int len = CONFIG_SYS_CBSIZE;
  803. int rc;
  804. static int initted = 0;
  805. /*
  806. * History uses a global array which is not
  807. * writable until after relocation to RAM.
  808. * Revert to non-history version if still
  809. * running from flash.
  810. */
  811. if (gd->flags & GD_FLG_RELOC) {
  812. if (!initted) {
  813. hist_init();
  814. initted = 1;
  815. }
  816. if (prompt)
  817. puts (prompt);
  818. rc = cread_line(prompt, p, &len);
  819. return rc < 0 ? rc : len;
  820. } else {
  821. #endif /* CONFIG_CMDLINE_EDITING */
  822. char * p_buf = p;
  823. int n = 0; /* buffer index */
  824. int plen = 0; /* prompt length */
  825. int col; /* output column cnt */
  826. char c;
  827. /* print prompt */
  828. if (prompt) {
  829. plen = strlen (prompt);
  830. puts (prompt);
  831. }
  832. col = plen;
  833. for (;;) {
  834. #ifdef CONFIG_BOOT_RETRY_TIME
  835. while (!tstc()) { /* while no incoming data */
  836. if (retry_time >= 0 && get_ticks() > endtime)
  837. return (-2); /* timed out */
  838. WATCHDOG_RESET();
  839. }
  840. #endif
  841. WATCHDOG_RESET(); /* Trigger watchdog, if needed */
  842. #ifdef CONFIG_SHOW_ACTIVITY
  843. while (!tstc()) {
  844. extern void show_activity(int arg);
  845. show_activity(0);
  846. WATCHDOG_RESET();
  847. }
  848. #endif
  849. c = getc();
  850. /*
  851. * Special character handling
  852. */
  853. switch (c) {
  854. case '\r': /* Enter */
  855. case '\n':
  856. *p = '\0';
  857. puts ("\r\n");
  858. return (p - p_buf);
  859. case '\0': /* nul */
  860. continue;
  861. case 0x03: /* ^C - break */
  862. p_buf[0] = '\0'; /* discard input */
  863. return (-1);
  864. case 0x15: /* ^U - erase line */
  865. while (col > plen) {
  866. puts (erase_seq);
  867. --col;
  868. }
  869. p = p_buf;
  870. n = 0;
  871. continue;
  872. case 0x17: /* ^W - erase word */
  873. p=delete_char(p_buf, p, &col, &n, plen);
  874. while ((n > 0) && (*p != ' ')) {
  875. p=delete_char(p_buf, p, &col, &n, plen);
  876. }
  877. continue;
  878. case 0x08: /* ^H - backspace */
  879. case 0x7F: /* DEL - backspace */
  880. p=delete_char(p_buf, p, &col, &n, plen);
  881. continue;
  882. default:
  883. /*
  884. * Must be a normal character then
  885. */
  886. if (n < CONFIG_SYS_CBSIZE-2) {
  887. if (c == '\t') { /* expand TABs */
  888. #ifdef CONFIG_AUTO_COMPLETE
  889. /* if auto completion triggered just continue */
  890. *p = '\0';
  891. if (cmd_auto_complete(prompt, console_buffer, &n, &col)) {
  892. p = p_buf + n; /* reset */
  893. continue;
  894. }
  895. #endif
  896. puts (tab_seq+(col&07));
  897. col += 8 - (col&07);
  898. } else {
  899. ++col; /* echo input */
  900. putc (c);
  901. }
  902. *p++ = c;
  903. ++n;
  904. } else { /* Buffer full */
  905. putc ('\a');
  906. }
  907. }
  908. }
  909. #ifdef CONFIG_CMDLINE_EDITING
  910. }
  911. #endif
  912. }
  913. /****************************************************************************/
  914. static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen)
  915. {
  916. char *s;
  917. if (*np == 0) {
  918. return (p);
  919. }
  920. if (*(--p) == '\t') { /* will retype the whole line */
  921. while (*colp > plen) {
  922. puts (erase_seq);
  923. (*colp)--;
  924. }
  925. for (s=buffer; s<p; ++s) {
  926. if (*s == '\t') {
  927. puts (tab_seq+((*colp) & 07));
  928. *colp += 8 - ((*colp) & 07);
  929. } else {
  930. ++(*colp);
  931. putc (*s);
  932. }
  933. }
  934. } else {
  935. puts (erase_seq);
  936. (*colp)--;
  937. }
  938. (*np)--;
  939. return (p);
  940. }
  941. /****************************************************************************/
  942. int parse_line (char *line, char *argv[])
  943. {
  944. int nargs = 0;
  945. #ifdef DEBUG_PARSER
  946. printf ("parse_line: \"%s\"\n", line);
  947. #endif
  948. while (nargs < CONFIG_SYS_MAXARGS) {
  949. /* skip any white space */
  950. while ((*line == ' ') || (*line == '\t')) {
  951. ++line;
  952. }
  953. if (*line == '\0') { /* end of line, no more args */
  954. argv[nargs] = NULL;
  955. #ifdef DEBUG_PARSER
  956. printf ("parse_line: nargs=%d\n", nargs);
  957. #endif
  958. return (nargs);
  959. }
  960. argv[nargs++] = line; /* begin of argument string */
  961. /* find end of string */
  962. while (*line && (*line != ' ') && (*line != '\t')) {
  963. ++line;
  964. }
  965. if (*line == '\0') { /* end of line, no more args */
  966. argv[nargs] = NULL;
  967. #ifdef DEBUG_PARSER
  968. printf ("parse_line: nargs=%d\n", nargs);
  969. #endif
  970. return (nargs);
  971. }
  972. *line++ = '\0'; /* terminate current arg */
  973. }
  974. printf ("** Too many args (max. %d) **\n", CONFIG_SYS_MAXARGS);
  975. #ifdef DEBUG_PARSER
  976. printf ("parse_line: nargs=%d\n", nargs);
  977. #endif
  978. return (nargs);
  979. }
  980. /****************************************************************************/
  981. static void process_macros (const char *input, char *output)
  982. {
  983. char c, prev;
  984. const char *varname_start = NULL;
  985. int inputcnt = strlen (input);
  986. int outputcnt = CONFIG_SYS_CBSIZE;
  987. int state = 0; /* 0 = waiting for '$' */
  988. /* 1 = waiting for '(' or '{' */
  989. /* 2 = waiting for ')' or '}' */
  990. /* 3 = waiting for ''' */
  991. #ifdef DEBUG_PARSER
  992. char *output_start = output;
  993. printf ("[PROCESS_MACROS] INPUT len %d: \"%s\"\n", strlen (input),
  994. input);
  995. #endif
  996. prev = '\0'; /* previous character */
  997. while (inputcnt && outputcnt) {
  998. c = *input++;
  999. inputcnt--;
  1000. if (state != 3) {
  1001. /* remove one level of escape characters */
  1002. if ((c == '\\') && (prev != '\\')) {
  1003. if (inputcnt-- == 0)
  1004. break;
  1005. prev = c;
  1006. c = *input++;
  1007. }
  1008. }
  1009. switch (state) {
  1010. case 0: /* Waiting for (unescaped) $ */
  1011. if ((c == '\'') && (prev != '\\')) {
  1012. state = 3;
  1013. break;
  1014. }
  1015. if ((c == '$') && (prev != '\\')) {
  1016. state++;
  1017. } else {
  1018. *(output++) = c;
  1019. outputcnt--;
  1020. }
  1021. break;
  1022. case 1: /* Waiting for ( */
  1023. if (c == '(' || c == '{') {
  1024. state++;
  1025. varname_start = input;
  1026. } else {
  1027. state = 0;
  1028. *(output++) = '$';
  1029. outputcnt--;
  1030. if (outputcnt) {
  1031. *(output++) = c;
  1032. outputcnt--;
  1033. }
  1034. }
  1035. break;
  1036. case 2: /* Waiting for ) */
  1037. if (c == ')' || c == '}') {
  1038. int i;
  1039. char envname[CONFIG_SYS_CBSIZE], *envval;
  1040. int envcnt = input - varname_start - 1; /* Varname # of chars */
  1041. /* Get the varname */
  1042. for (i = 0; i < envcnt; i++) {
  1043. envname[i] = varname_start[i];
  1044. }
  1045. envname[i] = 0;
  1046. /* Get its value */
  1047. envval = getenv (envname);
  1048. /* Copy into the line if it exists */
  1049. if (envval != NULL)
  1050. while ((*envval) && outputcnt) {
  1051. *(output++) = *(envval++);
  1052. outputcnt--;
  1053. }
  1054. /* Look for another '$' */
  1055. state = 0;
  1056. }
  1057. break;
  1058. case 3: /* Waiting for ' */
  1059. if ((c == '\'') && (prev != '\\')) {
  1060. state = 0;
  1061. } else {
  1062. *(output++) = c;
  1063. outputcnt--;
  1064. }
  1065. break;
  1066. }
  1067. prev = c;
  1068. }
  1069. if (outputcnt)
  1070. *output = 0;
  1071. else
  1072. *(output - 1) = 0;
  1073. #ifdef DEBUG_PARSER
  1074. printf ("[PROCESS_MACROS] OUTPUT len %d: \"%s\"\n",
  1075. strlen (output_start), output_start);
  1076. #endif
  1077. }
  1078. /****************************************************************************
  1079. * returns:
  1080. * 1 - command executed, repeatable
  1081. * 0 - command executed but not repeatable, interrupted commands are
  1082. * always considered not repeatable
  1083. * -1 - not executed (unrecognized, bootd recursion or too many args)
  1084. * (If cmd is NULL or "" or longer than CONFIG_SYS_CBSIZE-1 it is
  1085. * considered unrecognized)
  1086. *
  1087. * WARNING:
  1088. *
  1089. * We must create a temporary copy of the command since the command we get
  1090. * may be the result from getenv(), which returns a pointer directly to
  1091. * the environment data, which may change magicly when the command we run
  1092. * creates or modifies environment variables (like "bootp" does).
  1093. */
  1094. int run_command (const char *cmd, int flag)
  1095. {
  1096. cmd_tbl_t *cmdtp;
  1097. char cmdbuf[CONFIG_SYS_CBSIZE]; /* working copy of cmd */
  1098. char *token; /* start of token in cmdbuf */
  1099. char *sep; /* end of token (separator) in cmdbuf */
  1100. char finaltoken[CONFIG_SYS_CBSIZE];
  1101. char *str = cmdbuf;
  1102. char *argv[CONFIG_SYS_MAXARGS + 1]; /* NULL terminated */
  1103. int argc, inquotes;
  1104. int repeatable = 1;
  1105. int rc = 0;
  1106. #ifdef DEBUG_PARSER
  1107. printf ("[RUN_COMMAND] cmd[%p]=\"", cmd);
  1108. puts (cmd ? cmd : "NULL"); /* use puts - string may be loooong */
  1109. puts ("\"\n");
  1110. #endif
  1111. clear_ctrlc(); /* forget any previous Control C */
  1112. if (!cmd || !*cmd) {
  1113. return -1; /* empty command */
  1114. }
  1115. if (strlen(cmd) >= CONFIG_SYS_CBSIZE) {
  1116. puts ("## Command too long!\n");
  1117. return -1;
  1118. }
  1119. strcpy (cmdbuf, cmd);
  1120. /* Process separators and check for invalid
  1121. * repeatable commands
  1122. */
  1123. #ifdef DEBUG_PARSER
  1124. printf ("[PROCESS_SEPARATORS] %s\n", cmd);
  1125. #endif
  1126. while (*str) {
  1127. /*
  1128. * Find separator, or string end
  1129. * Allow simple escape of ';' by writing "\;"
  1130. */
  1131. for (inquotes = 0, sep = str; *sep; sep++) {
  1132. if ((*sep=='\'') &&
  1133. (*(sep-1) != '\\'))
  1134. inquotes=!inquotes;
  1135. if (!inquotes &&
  1136. (*sep == ';') && /* separator */
  1137. ( sep != str) && /* past string start */
  1138. (*(sep-1) != '\\')) /* and NOT escaped */
  1139. break;
  1140. }
  1141. /*
  1142. * Limit the token to data between separators
  1143. */
  1144. token = str;
  1145. if (*sep) {
  1146. str = sep + 1; /* start of command for next pass */
  1147. *sep = '\0';
  1148. }
  1149. else
  1150. str = sep; /* no more commands for next pass */
  1151. #ifdef DEBUG_PARSER
  1152. printf ("token: \"%s\"\n", token);
  1153. #endif
  1154. /* find macros in this token and replace them */
  1155. process_macros (token, finaltoken);
  1156. /* Extract arguments */
  1157. if ((argc = parse_line (finaltoken, argv)) == 0) {
  1158. rc = -1; /* no command at all */
  1159. continue;
  1160. }
  1161. /* Look up command in command table */
  1162. if ((cmdtp = find_cmd(argv[0])) == NULL) {
  1163. printf ("Unknown command '%s' - try 'help'\n", argv[0]);
  1164. rc = -1; /* give up after bad command */
  1165. continue;
  1166. }
  1167. /* found - check max args */
  1168. if (argc > cmdtp->maxargs) {
  1169. cmd_usage(cmdtp);
  1170. rc = -1;
  1171. continue;
  1172. }
  1173. #if defined(CONFIG_CMD_BOOTD)
  1174. /* avoid "bootd" recursion */
  1175. if (cmdtp->cmd == do_bootd) {
  1176. #ifdef DEBUG_PARSER
  1177. printf ("[%s]\n", finaltoken);
  1178. #endif
  1179. if (flag & CMD_FLAG_BOOTD) {
  1180. puts ("'bootd' recursion detected\n");
  1181. rc = -1;
  1182. continue;
  1183. } else {
  1184. flag |= CMD_FLAG_BOOTD;
  1185. }
  1186. }
  1187. #endif
  1188. /* OK - call function to do the command */
  1189. if ((cmdtp->cmd) (cmdtp, flag, argc, argv) != 0) {
  1190. rc = -1;
  1191. }
  1192. repeatable &= cmdtp->repeatable;
  1193. /* Did the user stop this? */
  1194. if (had_ctrlc ())
  1195. return -1; /* if stopped then not repeatable */
  1196. }
  1197. return rc ? rc : repeatable;
  1198. }
  1199. /****************************************************************************/
  1200. #if defined(CONFIG_CMD_RUN)
  1201. int do_run (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  1202. {
  1203. int i;
  1204. if (argc < 2)
  1205. return cmd_usage(cmdtp);
  1206. for (i=1; i<argc; ++i) {
  1207. char *arg;
  1208. if ((arg = getenv (argv[i])) == NULL) {
  1209. printf ("## Error: \"%s\" not defined\n", argv[i]);
  1210. return 1;
  1211. }
  1212. #ifndef CONFIG_SYS_HUSH_PARSER
  1213. if (run_command (arg, flag) == -1)
  1214. return 1;
  1215. #else
  1216. if (parse_string_outer(arg,
  1217. FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
  1218. return 1;
  1219. #endif
  1220. }
  1221. return 0;
  1222. }
  1223. #endif