1 |
/* |
---|
2 |
* Copyright (C) 2005-2008 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB. |
---|
8 |
* |
---|
9 |
* This program is free software: you can redistribute it and/or modify |
---|
10 |
* it under the terms of the GNU General Public License as published by |
---|
11 |
* the Free Software Foundation, either version 2 of the License, or |
---|
12 |
* (at your option) version 3 of the License. |
---|
13 |
* |
---|
14 |
* This program is distributed in the hope that it will be useful, |
---|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 |
* GNU General Public License for more details. |
---|
18 |
* |
---|
19 |
* You should have received a copy of the GNU General Public License |
---|
20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 |
* |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
#ifdef HAVE_CONFIG_H |
---|
25 |
#include <config.h> |
---|
26 |
#endif |
---|
27 |
|
---|
28 |
#include <argp.h> |
---|
29 |
#include <stdio.h> |
---|
30 |
#include <stdlib.h> |
---|
31 |
#include <string.h> |
---|
32 |
|
---|
33 |
#include "debugmodule/debugmodule.h" |
---|
34 |
|
---|
35 |
#include "src/DeviceStringParser.h" |
---|
36 |
|
---|
37 |
DECLARE_GLOBAL_DEBUG_MODULE; |
---|
38 |
|
---|
39 |
// Program documentation. |
---|
40 |
static char doc[] = "FFADO -- Watchdog test\n\n"; |
---|
41 |
|
---|
42 |
// A description of the arguments we accept. |
---|
43 |
static char args_doc[] = ""; |
---|
44 |
|
---|
45 |
|
---|
46 |
struct arguments |
---|
47 |
{ |
---|
48 |
short verbose; |
---|
49 |
}; |
---|
50 |
|
---|
51 |
// The options we understand. |
---|
52 |
static struct argp_option options[] = { |
---|
53 |
{"verbose", 'v', "n", 0, "Verbose level" }, |
---|
54 |
{ 0 } |
---|
55 |
}; |
---|
56 |
|
---|
57 |
//------------------------------------------------------------- |
---|
58 |
|
---|
59 |
// Parse a single option. |
---|
60 |
static error_t |
---|
61 |
parse_opt( int key, char* arg, struct argp_state* state ) |
---|
62 |
{ |
---|
63 |
// Get the input argument from `argp_parse', which we |
---|
64 |
// know is a pointer to our arguments structure. |
---|
65 |
struct arguments* arguments = ( struct arguments* ) state->input; |
---|
66 |
char* tail; |
---|
67 |
|
---|
68 |
errno = 0; |
---|
69 |
switch (key) { |
---|
70 |
case 'v': |
---|
71 |
if (arg) { |
---|
72 |
arguments->verbose = strtoll( arg, &tail, 0 ); |
---|
73 |
if ( errno ) { |
---|
74 |
fprintf( stderr, "Could not parse 'verbose' argument\n" ); |
---|
75 |
return ARGP_ERR_UNKNOWN; |
---|
76 |
} |
---|
77 |
} else { |
---|
78 |
if ( errno ) { |
---|
79 |
fprintf( stderr, "Could not parse 'verbose' argument\n" ); |
---|
80 |
return ARGP_ERR_UNKNOWN; |
---|
81 |
} |
---|
82 |
} |
---|
83 |
break; |
---|
84 |
default: |
---|
85 |
return ARGP_ERR_UNKNOWN; |
---|
86 |
} |
---|
87 |
return 0; |
---|
88 |
} |
---|
89 |
|
---|
90 |
// Our argp parser. |
---|
91 |
static struct argp argp = { options, parse_opt, args_doc, doc }; |
---|
92 |
|
---|
93 |
int main(int argc, char *argv[]) |
---|
94 |
{ |
---|
95 |
|
---|
96 |
struct arguments arguments; |
---|
97 |
|
---|
98 |
// Default values. |
---|
99 |
arguments.verbose = DEBUG_LEVEL_VERY_VERBOSE; |
---|
100 |
|
---|
101 |
// Parse our arguments; every option seen by `parse_opt' will |
---|
102 |
// be reflected in `arguments'. |
---|
103 |
if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { |
---|
104 |
fprintf( stderr, "Could not parse command line\n" ); |
---|
105 |
exit(1); |
---|
106 |
} |
---|
107 |
|
---|
108 |
setDebugLevel(arguments.verbose); |
---|
109 |
|
---|
110 |
DeviceStringParser p = DeviceStringParser(); |
---|
111 |
p.setVerboseLevel(arguments.verbose); |
---|
112 |
|
---|
113 |
p.parseString("hw:0;hw:1"); |
---|
114 |
p.parseString("hw:0;hw:1;"); |
---|
115 |
p.parseString("hw:0,0;hw:1,1;"); |
---|
116 |
p.parseString("hw:1,1;hw:1,0"); |
---|
117 |
p.parseString("guid:0x123456789"); |
---|
118 |
p.show(); |
---|
119 |
|
---|
120 |
return EXIT_SUCCESS; |
---|
121 |
} |
---|
122 |
|
---|
123 |
|
---|