| 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 |
switch (key) { |
|---|
| 69 |
case 'v': |
|---|
| 70 |
if (arg) { |
|---|
| 71 |
arguments->verbose = strtoll( arg, &tail, 0 ); |
|---|
| 72 |
if ( errno ) { |
|---|
| 73 |
fprintf( stderr, "Could not parse 'verbose' argument\n" ); |
|---|
| 74 |
return ARGP_ERR_UNKNOWN; |
|---|
| 75 |
} |
|---|
| 76 |
} else { |
|---|
| 77 |
if ( errno ) { |
|---|
| 78 |
fprintf( stderr, "Could not parse 'verbose' argument\n" ); |
|---|
| 79 |
return ARGP_ERR_UNKNOWN; |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
break; |
|---|
| 83 |
default: |
|---|
| 84 |
return ARGP_ERR_UNKNOWN; |
|---|
| 85 |
} |
|---|
| 86 |
return 0; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
// Our argp parser. |
|---|
| 90 |
static struct argp argp = { options, parse_opt, args_doc, doc }; |
|---|
| 91 |
|
|---|
| 92 |
int main(int argc, char *argv[]) |
|---|
| 93 |
{ |
|---|
| 94 |
|
|---|
| 95 |
struct arguments arguments; |
|---|
| 96 |
|
|---|
| 97 |
// Default values. |
|---|
| 98 |
arguments.verbose = DEBUG_LEVEL_VERY_VERBOSE; |
|---|
| 99 |
|
|---|
| 100 |
// Parse our arguments; every option seen by `parse_opt' will |
|---|
| 101 |
// be reflected in `arguments'. |
|---|
| 102 |
if ( argp_parse ( &argp, argc, argv, 0, 0, &arguments ) ) { |
|---|
| 103 |
fprintf( stderr, "Could not parse command line\n" ); |
|---|
| 104 |
exit(1); |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
setDebugLevel(arguments.verbose); |
|---|
| 108 |
|
|---|
| 109 |
DeviceStringParser p = DeviceStringParser(); |
|---|
| 110 |
p.setVerboseLevel(arguments.verbose); |
|---|
| 111 |
|
|---|
| 112 |
p.parseString("hw:0;hw:1"); |
|---|
| 113 |
p.parseString("hw:0;hw:1;"); |
|---|
| 114 |
p.parseString("hw:0,0;hw:1,1;"); |
|---|
| 115 |
p.parseString("hw:1,1;hw:1,0"); |
|---|
| 116 |
p.parseString("guid:0x123456789"); |
|---|
| 117 |
p.show(); |
|---|
| 118 |
|
|---|
| 119 |
return EXIT_SUCCESS; |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
|
|---|