Rev 3280 | Rev 3345 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3280 | Rev 3316 | ||
---|---|---|---|
Line 49... | Line 49... | ||
49 | 49 | ||
50 | #include "config.h" |
50 | #include "config.h" |
51 | #include "errors.h" |
51 | #include "errors.h" |
52 | #include "util.h" |
52 | #include "util.h" |
53 | 53 | ||
54 | /* Functions that just have no other home */ |
- | |
55 | - | ||
56 | /* Tests if string is an --option/-option */ |
- | |
57 | unsigned int is_option(char *string) |
- | |
58 | { |
- | |
59 | size_t i; |
- | |
60 | - | ||
61 | /* We have rubbish */ |
- | |
62 | if (NULL == string) |
- | |
63 | return 0; |
- | |
64 | - | ||
65 | /* - or -- means an option (or end of options) */ |
- | |
66 | for (i=0; i < strlen(string); i++) { |
- | |
67 | if (string[i] == '-' && i <= 1) |
- | |
68 | return 1; |
- | |
69 | } |
- | |
70 | - | ||
71 | return 0; |
- | |
72 | } |
- | |
73 | - | ||
74 | /* Returns the option count in an array of arguments */ |
- | |
75 | unsigned int count_options(char *argv[]) |
- | |
76 | { |
- | |
77 | unsigned int i; |
- | |
78 | unsigned int n = 0; |
- | |
79 | - | ||
80 | for (i=0; argv[i] != NULL; i++) { |
- | |
81 | if (is_option((char *)argv[i])) |
- | |
82 | n++; |
- | |
83 | } |
- | |
84 | - | ||
85 | return n; |
- | |
86 | } |
- | |
87 | 54 | ||
88 | /* some platforms do not have strdup, implement it here */ |
55 | /* some platforms do not have strdup, implement it here */ |
89 | char * cli_strdup(const char *s1) |
56 | char * cli_strdup(const char *s1) |
90 | { |
57 | { |
91 | size_t len = strlen(s1) + 1; |
58 | size_t len = strlen(s1) + 1; |
Line 141... | Line 108... | ||
141 | { |
108 | { |
142 | static char *last; |
109 | static char *last; |
143 | 110 | ||
144 | return (cli_strtok_r(s, delim, &last)); |
111 | return (cli_strtok_r(s, delim, &last)); |
145 | } |
112 | } |
146 | - | ||
147 | - |