• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision4030 (tree)
Time2020-09-13 16:18:58
Authormagicant

Log Message

Remove unnecessary expansion in parsing word

Change Summary

Incremental Difference

--- yash/trunk/lineedit/compparse.c (revision 4029)
+++ yash/trunk/lineedit/compparse.c (revision 4030)
@@ -1,6 +1,6 @@
11 /* Yash: yet another shell */
22 /* compparse.c: simple parser for command line completion */
3-/* (C) 2007-2017 magicant */
3+/* (C) 2007-2020 magicant */
44
55 /* This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
@@ -75,9 +75,7 @@
7575 static bool cparse_for_command(void);
7676 static bool cparse_case_command(void);
7777 static bool cparse_function_definition(void);
78-static wchar_t *cparse_and_expand_word(
79- tildetype_T tilde, le_contexttype_T ctxttype)
80- __attribute__((malloc,warn_unused_result));
78+static bool ctryparse_word(tildetype_T tilde, le_contexttype_T ctxttype);
8179 static wordunit_T *cparse_word(
8280 bool testfunc(wchar_t c), tildetype_T tilde, le_contexttype_T ctxttype)
8381 __attribute__((nonnull,malloc,warn_unused_result));
@@ -361,12 +359,10 @@
361359
362360 if (BUF[INDEX] != L'(') {
363361 /* scalar variable */
364- wchar_t *value = cparse_and_expand_word(TT_MULTI, CTXT_ASSIGN);
365- if (value == NULL) {
362+ if (ctryparse_word(TT_MULTI, CTXT_ASSIGN)) {
366363 empty_pwords();
367364 return true;
368365 } else {
369- free(value);
370366 return false;
371367 }
372368 } else {
@@ -406,7 +402,6 @@
406402 size_t index = INDEX;
407403 le_contexttype_T type;
408404 bool result;
409- wchar_t *value;
410405
411406 while (iswdigit(BUF[index]))
412407 index++;
@@ -443,12 +438,10 @@
443438 }
444439
445440 skip_blanks();
446- value = cparse_and_expand_word(TT_SINGLE, type);
447- if (value == NULL) {
441+ if (ctryparse_word(TT_SINGLE, type)) {
448442 empty_pwords();
449443 return true;
450444 } else {
451- free(value);
452445 return false;
453446 }
454447
@@ -593,23 +586,18 @@
593586 /* Parses the word at the current position.
594587 * `skip_blanks' should be called before this function is called.
595588 * The `ctxttype' parameter is the context type of the word parsed.
596- * If the word was completely parsed, the word is expanded until quote removal
597- * and returned as a newly-malloced string.
598- * If the parser reached the end of the input string, the return value is NULL
589+ * If the word was completely parsed, the return value is false.
590+ * If the parser reached the end of the input string, the return value is true
599591 * and the result is saved in `pi->ctxt'. However, `pi->ctxt->pwords' is NULL
600592 * when the preceding words need to be determined by the caller. In this case,
601593 * the caller must update the `pwordc' and `pwords' member. */
602-wchar_t *cparse_and_expand_word(tildetype_T tilde, le_contexttype_T ctxttype)
594+bool ctryparse_word(tildetype_T tilde, le_contexttype_T ctxttype)
603595 {
604596 wordunit_T *w = cparse_word(is_token_delimiter_char, tilde, ctxttype);
605- if (w == NULL) {
606- return NULL;
607- } else {
608- wchar_t *s = expand_single(w, tilde, true, false);
609- wordfree(w);
610- assert(s != NULL);
611- return s;
612- }
597+ if (w == NULL)
598+ return true;
599+ wordfree(w);
600+ return false;
613601 }
614602
615603 /* Parses the word at the current position.
Show on old repository browser