diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-27 14:45:13 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-27 14:46:17 +0200 |
commit | 455e422814105b0904c79639fd318f3cec25efe6 (patch) | |
tree | 6db771473947ef0d277f3014675e62c96d76ff83 | |
parent | b4f51d32d288a985019884d79515b1d7a8251529 (diff) | |
download | busybox-w32-455e422814105b0904c79639fd318f3cec25efe6.tar.gz busybox-w32-455e422814105b0904c79639fd318f3cec25efe6.tar.bz2 busybox-w32-455e422814105b0904c79639fd318f3cec25efe6.zip |
ash: move ifsbreakup() and ifsfree() up
Preparatory patch.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 220 |
1 files changed, 110 insertions, 110 deletions
diff --git a/shell/ash.c b/shell/ash.c index c575e1036..7acb33e7e 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -5568,6 +5568,116 @@ cvtnum(arith_t num) | |||
5568 | return len; | 5568 | return len; |
5569 | } | 5569 | } |
5570 | 5570 | ||
5571 | /* | ||
5572 | * Break the argument string into pieces based upon IFS and add the | ||
5573 | * strings to the argument list. The regions of the string to be | ||
5574 | * searched for IFS characters have been stored by recordregion. | ||
5575 | */ | ||
5576 | static void | ||
5577 | ifsbreakup(char *string, struct arglist *arglist) | ||
5578 | { | ||
5579 | struct ifsregion *ifsp; | ||
5580 | struct strlist *sp; | ||
5581 | char *start; | ||
5582 | char *p; | ||
5583 | char *q; | ||
5584 | const char *ifs, *realifs; | ||
5585 | int ifsspc; | ||
5586 | int nulonly; | ||
5587 | |||
5588 | start = string; | ||
5589 | if (ifslastp != NULL) { | ||
5590 | ifsspc = 0; | ||
5591 | nulonly = 0; | ||
5592 | realifs = ifsset() ? ifsval() : defifs; | ||
5593 | ifsp = &ifsfirst; | ||
5594 | do { | ||
5595 | p = string + ifsp->begoff; | ||
5596 | nulonly = ifsp->nulonly; | ||
5597 | ifs = nulonly ? nullstr : realifs; | ||
5598 | ifsspc = 0; | ||
5599 | while (p < string + ifsp->endoff) { | ||
5600 | q = p; | ||
5601 | if ((unsigned char)*p == CTLESC) | ||
5602 | p++; | ||
5603 | if (!strchr(ifs, *p)) { | ||
5604 | p++; | ||
5605 | continue; | ||
5606 | } | ||
5607 | if (!nulonly) | ||
5608 | ifsspc = (strchr(defifs, *p) != NULL); | ||
5609 | /* Ignore IFS whitespace at start */ | ||
5610 | if (q == start && ifsspc) { | ||
5611 | p++; | ||
5612 | start = p; | ||
5613 | continue; | ||
5614 | } | ||
5615 | *q = '\0'; | ||
5616 | sp = stzalloc(sizeof(*sp)); | ||
5617 | sp->text = start; | ||
5618 | *arglist->lastp = sp; | ||
5619 | arglist->lastp = &sp->next; | ||
5620 | p++; | ||
5621 | if (!nulonly) { | ||
5622 | for (;;) { | ||
5623 | if (p >= string + ifsp->endoff) { | ||
5624 | break; | ||
5625 | } | ||
5626 | q = p; | ||
5627 | if ((unsigned char)*p == CTLESC) | ||
5628 | p++; | ||
5629 | if (strchr(ifs, *p) == NULL) { | ||
5630 | p = q; | ||
5631 | break; | ||
5632 | } | ||
5633 | if (strchr(defifs, *p) == NULL) { | ||
5634 | if (ifsspc) { | ||
5635 | p++; | ||
5636 | ifsspc = 0; | ||
5637 | } else { | ||
5638 | p = q; | ||
5639 | break; | ||
5640 | } | ||
5641 | } else | ||
5642 | p++; | ||
5643 | } | ||
5644 | } | ||
5645 | start = p; | ||
5646 | } /* while */ | ||
5647 | ifsp = ifsp->next; | ||
5648 | } while (ifsp != NULL); | ||
5649 | if (nulonly) | ||
5650 | goto add; | ||
5651 | } | ||
5652 | |||
5653 | if (!*start) | ||
5654 | return; | ||
5655 | |||
5656 | add: | ||
5657 | sp = stzalloc(sizeof(*sp)); | ||
5658 | sp->text = start; | ||
5659 | *arglist->lastp = sp; | ||
5660 | arglist->lastp = &sp->next; | ||
5661 | } | ||
5662 | |||
5663 | static void | ||
5664 | ifsfree(void) | ||
5665 | { | ||
5666 | struct ifsregion *p; | ||
5667 | |||
5668 | INT_OFF; | ||
5669 | p = ifsfirst.next; | ||
5670 | do { | ||
5671 | struct ifsregion *ifsp; | ||
5672 | ifsp = p->next; | ||
5673 | free(p); | ||
5674 | p = ifsp; | ||
5675 | } while (p); | ||
5676 | ifslastp = NULL; | ||
5677 | ifsfirst.next = NULL; | ||
5678 | INT_ON; | ||
5679 | } | ||
5680 | |||
5571 | static size_t | 5681 | static size_t |
5572 | esclen(const char *start, const char *p) | 5682 | esclen(const char *start, const char *p) |
5573 | { | 5683 | { |
@@ -6849,116 +6959,6 @@ evalvar(char *p, int flag, struct strlist *var_str_list) | |||
6849 | } | 6959 | } |
6850 | 6960 | ||
6851 | /* | 6961 | /* |
6852 | * Break the argument string into pieces based upon IFS and add the | ||
6853 | * strings to the argument list. The regions of the string to be | ||
6854 | * searched for IFS characters have been stored by recordregion. | ||
6855 | */ | ||
6856 | static void | ||
6857 | ifsbreakup(char *string, struct arglist *arglist) | ||
6858 | { | ||
6859 | struct ifsregion *ifsp; | ||
6860 | struct strlist *sp; | ||
6861 | char *start; | ||
6862 | char *p; | ||
6863 | char *q; | ||
6864 | const char *ifs, *realifs; | ||
6865 | int ifsspc; | ||
6866 | int nulonly; | ||
6867 | |||
6868 | start = string; | ||
6869 | if (ifslastp != NULL) { | ||
6870 | ifsspc = 0; | ||
6871 | nulonly = 0; | ||
6872 | realifs = ifsset() ? ifsval() : defifs; | ||
6873 | ifsp = &ifsfirst; | ||
6874 | do { | ||
6875 | p = string + ifsp->begoff; | ||
6876 | nulonly = ifsp->nulonly; | ||
6877 | ifs = nulonly ? nullstr : realifs; | ||
6878 | ifsspc = 0; | ||
6879 | while (p < string + ifsp->endoff) { | ||
6880 | q = p; | ||
6881 | if ((unsigned char)*p == CTLESC) | ||
6882 | p++; | ||
6883 | if (!strchr(ifs, *p)) { | ||
6884 | p++; | ||
6885 | continue; | ||
6886 | } | ||
6887 | if (!nulonly) | ||
6888 | ifsspc = (strchr(defifs, *p) != NULL); | ||
6889 | /* Ignore IFS whitespace at start */ | ||
6890 | if (q == start && ifsspc) { | ||
6891 | p++; | ||
6892 | start = p; | ||
6893 | continue; | ||
6894 | } | ||
6895 | *q = '\0'; | ||
6896 | sp = stzalloc(sizeof(*sp)); | ||
6897 | sp->text = start; | ||
6898 | *arglist->lastp = sp; | ||
6899 | arglist->lastp = &sp->next; | ||
6900 | p++; | ||
6901 | if (!nulonly) { | ||
6902 | for (;;) { | ||
6903 | if (p >= string + ifsp->endoff) { | ||
6904 | break; | ||
6905 | } | ||
6906 | q = p; | ||
6907 | if ((unsigned char)*p == CTLESC) | ||
6908 | p++; | ||
6909 | if (strchr(ifs, *p) == NULL) { | ||
6910 | p = q; | ||
6911 | break; | ||
6912 | } | ||
6913 | if (strchr(defifs, *p) == NULL) { | ||
6914 | if (ifsspc) { | ||
6915 | p++; | ||
6916 | ifsspc = 0; | ||
6917 | } else { | ||
6918 | p = q; | ||
6919 | break; | ||
6920 | } | ||
6921 | } else | ||
6922 | p++; | ||
6923 | } | ||
6924 | } | ||
6925 | start = p; | ||
6926 | } /* while */ | ||
6927 | ifsp = ifsp->next; | ||
6928 | } while (ifsp != NULL); | ||
6929 | if (nulonly) | ||
6930 | goto add; | ||
6931 | } | ||
6932 | |||
6933 | if (!*start) | ||
6934 | return; | ||
6935 | |||
6936 | add: | ||
6937 | sp = stzalloc(sizeof(*sp)); | ||
6938 | sp->text = start; | ||
6939 | *arglist->lastp = sp; | ||
6940 | arglist->lastp = &sp->next; | ||
6941 | } | ||
6942 | |||
6943 | static void | ||
6944 | ifsfree(void) | ||
6945 | { | ||
6946 | struct ifsregion *p; | ||
6947 | |||
6948 | INT_OFF; | ||
6949 | p = ifsfirst.next; | ||
6950 | do { | ||
6951 | struct ifsregion *ifsp; | ||
6952 | ifsp = p->next; | ||
6953 | free(p); | ||
6954 | p = ifsp; | ||
6955 | } while (p); | ||
6956 | ifslastp = NULL; | ||
6957 | ifsfirst.next = NULL; | ||
6958 | INT_ON; | ||
6959 | } | ||
6960 | |||
6961 | /* | ||
6962 | * Add a file name to the list. | 6962 | * Add a file name to the list. |
6963 | */ | 6963 | */ |
6964 | static void | 6964 | static void |