-static void strip_line(char *line)
-{
- char *p = line + strlen(line) - 1;
-
- while (*line) {
- if (*p != '\n' && *p != '\r')
- break;
- *p-- = '\0';
- }
-}
-
-static char *parse_word(char **buf)
-{
- char *word, *next;
-
- word = *buf;
- if (*word == '\0')
- return NULL;
-
- word = skip_whitespace(word);
- next = skip_non_whitespace(word);
- if (*next)
- *next++ = '\0';
- *buf = next;
- return word;
-}
-
-static void parse_escape(char *word)
-{
- char *q, c;
- const char *p;
-
- if (!word)
- return;
-
- for (p = q = word; *p; q++) {
- c = *p++;
- if (c != '\\') {
- *q = c;
- } else {
- *q = bb_process_escape_sequence(&p);
- }
- }
- *q = '\0';
-}
-
-static int parse_fstab_line(char *line, struct fs_info **ret_fs)
-{
- char *device, *mntpnt, *type, *opts, *freq, *passno, *cp;
- struct fs_info *fs;
-
- *ret_fs = 0;
- strip_line(line);
- cp = strchr(line, '#');
- if (cp)
- *cp = '\0'; /* Ignore everything after the comment char */
- cp = line;
-
- device = parse_word(&cp);
- if (!device) return 0; /* Allow blank lines */
- mntpnt = parse_word(&cp);
- type = parse_word(&cp);
- opts = parse_word(&cp);
- freq = parse_word(&cp);
- passno = parse_word(&cp);
-
- if (!mntpnt || !type)
- return -1;
-
- parse_escape(device);
- parse_escape(mntpnt);
- parse_escape(type);
- parse_escape(opts);
- parse_escape(freq);
- parse_escape(passno);
-
- if (strchr(type, ','))
- type = NULL;
-
- fs = create_fs_device(device, mntpnt, type ? type : "auto", opts,
- freq ? atoi(freq) : -1,
- passno ? atoi(passno) : -1);
- *ret_fs = fs;
- return 0;
-}
-