summaryrefslogtreecommitdiff
path: root/toxrtp/tests/test_helper.c
blob: 526b6b38e3eee7684c0ef5878b3718426366ebf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*   test_helper.c
 *
 *   Tests support. !Red!
 *
 *
 *   Copyright (C) 2013 Tox project All Rights Reserved.
 *
 *   This file is part of Tox.
 *
 *   Tox is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Tox is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Tox.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "test_helper.h"

#include <string.h>
#include <stdlib.h>

arg_t* parse_args ( int argc, char* argv[] )
{
    arg_t* _list = calloc(sizeof(arg_t), 1);
    _list->next = _list->prev = NULL;

    arg_t* it = _list;

    size_t val;
    for ( val = 0; val < argc; val ++ ) {
        it->value = argv[val];

        if ( val < argc - 1 ) { /* just about to end */
            it->next = calloc(sizeof(arg_t), 1);
            it->next->prev = it;
            it = it->next;
            it->next = NULL;
        }
    }

    return _list;
}

int find_arg_simple ( arg_t* _head, const char* _id )
{
    arg_t* it = _head;

    int i;
    for ( i = 1; it != NULL; it = it->next ) {
        if ( strcmp ( _id, it->value ) == 0 ) {
            return i;
        }

        i++;
    }

    return FAILURE;
}

const char* find_arg_duble ( arg_t* _head, const char* _id )
{
    arg_t* _it;
    for ( _it = _head; _it != NULL; _it = _it->next ) {
        if ( strcmp ( _id, _it->value ) == 0 ) {
            if ( _it->next && _it->next->value[0] != '-' ) { /* exclude option */
                return _it->next->value;
            } else {
                return NULL;
            }
        }
    }

    return NULL;
}