[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.6

1.6     ! deraadt     1: /*     $OpenBSD: list.c,v 1.5 2010/07/03 00:21:14 halex Exp $  */
1.3       martynas    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>
1.6     ! deraadt    22:
        !            23: void   parse_list(char **, char *);
1.1       martynas   24:
                     25: void
                     26: parse_unix(char **line, char *type)
                     27: {
                     28:        char *tok;
                     29:        int field = 0;
                     30:
                     31:        while ((tok = strsep(line, " \t")) != NULL) {
                     32:                if (*tok == '\0')
                     33:                        continue;
                     34:
                     35:                if (field == 0)
                     36:                        *type = *tok;
                     37:
                     38:                if (field == 7) {
1.4       phessler   39:                        if (line == NULL || *line == NULL)
                     40:                                break;
1.1       martynas   41:                        while (**line == ' ' || **line == '\t')
                     42:                                (*line)++;
                     43:                        break;
                     44:                }
                     45:
                     46:                field++;
                     47:        }
                     48: }
                     49:
                     50: void
                     51: parse_windows(char **line, char *type)
                     52: {
                     53:        char *tok;
                     54:        int field = 0;
                     55:
                     56:        *type = '-';
                     57:        while ((tok = strsep(line, " \t")) != NULL) {
                     58:                if (*tok == '\0')
                     59:                        continue;
                     60:
                     61:                if (field == 2 && strcmp(tok, "<DIR>") == 0)
                     62:                        *type = 'd';
                     63:
                     64:                if (field == 2) {
1.4       phessler   65:                        if (line == NULL || *line == NULL)
                     66:                                break;
1.1       martynas   67:                        while (**line == ' ' || **line == '\t')
                     68:                                (*line)++;
                     69:                        break;
                     70:                }
                     71:
                     72:                field++;
                     73:        }
                     74: }
                     75:
                     76: void
                     77: parse_list(char **line, char *type)
                     78: {
                     79:        if (**line >= '0' && **line <= '9')
1.5       halex      80:                parse_windows(line, type);
                     81:        else
                     82:                parse_unix(line, type);
1.1       martynas   83: }
                     84:
                     85: #endif /* !SMALL */
1.3       martynas   86: