[BACK]Return to list.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ftp

Annotation of src/usr.bin/ftp/list.c, Revision 1.3

1.3     ! martynas    1: /*     $OpenBSD: list.c,v 1.2 2008/10/21 17:54:00 martynas Exp $       */
        !             2:
1.1       martynas    3: /*
                      4:  * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18:
                     19: #ifndef SMALL
1.3     ! martynas   20:
1.1       martynas   21: #include <string.h>
                     22:
                     23: void
                     24: parse_unix(char **line, char *type)
                     25: {
                     26:        char *tok;
                     27:        int field = 0;
                     28:
                     29:        while ((tok = strsep(line, " \t")) != NULL) {
                     30:                if (*tok == '\0')
                     31:                        continue;
                     32:
                     33:                if (field == 0)
                     34:                        *type = *tok;
                     35:
                     36:                if (field == 7) {
                     37:                        while (**line == ' ' || **line == '\t')
                     38:                                (*line)++;
                     39:                        break;
                     40:                }
                     41:
                     42:                field++;
                     43:        }
                     44: }
                     45:
                     46: void
                     47: parse_windows(char **line, char *type)
                     48: {
                     49:        char *tok;
                     50:        int field = 0;
                     51:
                     52:        *type = '-';
                     53:        while ((tok = strsep(line, " \t")) != NULL) {
                     54:                if (*tok == '\0')
                     55:                        continue;
                     56:
                     57:                if (field == 2 && strcmp(tok, "<DIR>") == 0)
                     58:                        *type = 'd';
                     59:
                     60:                if (field == 2) {
                     61:                        while (**line == ' ' || **line == '\t')
                     62:                                (*line)++;
                     63:                        break;
                     64:                }
                     65:
                     66:                field++;
                     67:        }
                     68: }
                     69:
                     70: void
                     71: parse_list(char **line, char *type)
                     72: {
                     73:        if (**line >= '0' && **line <= '9')
                     74:                return parse_windows(line, type);
                     75:
                     76:        return parse_unix(line, type);
                     77: }
                     78:
                     79: #endif /* !SMALL */
1.3     ! martynas   80: