ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/SteeringWheelRemote/SteeringWheelRemote.cpp
Revision: 3
Committed: 2007-04-26T01:51:35-07:00 (15 years, 9 months ago) by douglas
File size: 1134 byte(s)
Log Message:
Stuffs!

File Contents

# User Rev Content
1 douglas 1 // Steering Wheel Remote
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include <iostream>
8     #include <string>
9    
10 douglas 2 #include <err.h>
11 douglas 1 #include <fcntl.h>
12     #include <usbhid.h>
13    
14 douglas 3 #include <common.hpp>
15 douglas 2 #include <foreach.hpp>
16     #include <posix.hpp>
17 douglas 3 #include <regex.hpp>
18 douglas 2
19 douglas 3 int Usage(const std::string &program)
20 douglas 1 {
21 douglas 3 std::cout << _B("Usage: ") << program << _B(" [-debug] [-device=device]") << std::endl;
22    
23     return 1;
24 douglas 2 }
25    
26 douglas 3 int main(int argc, char *argv[])
27 douglas 2 {
28 douglas 3 bool debug(false);
29     std::string device;
30 douglas 2
31 douglas 1 {
32 douglas 3 Pcre::RegEx devicePath(_B("^-device=(/.+)$"));
33     Pcre::RegEx deviceNumber(_B("^-device=([0-9]+)$"));
34     Pcre::RegEx deviceName(_B("^-device=(.+)$"));
35 douglas 1
36 douglas 3 _forall (int, index, 1, argc)
37     if (argv[index] == _B("-debug"))
38     debug = true;
39     else if (Pcre::RegEx::Match match = devicePath(argv[index]))
40     device = match[1];
41     else if (Pcre::RegEx::Match match = deviceNumber(argv[index]))
42     device = _B("/dev/uhid") + match[1];
43     else if (Pcre::RegEx::Match match = deviceName(argv[index]))
44     device = _B("/dev/") + match[1];
45     else
46     return Usage(argv[0]);
47 douglas 1 }
48    
49 douglas 3 if (device.empty())
50     return Usage(argv[0]);
51 douglas 2
52 douglas 3 std::cerr << device << std::endl;
53 douglas 2
54 douglas 1 return 0;
55     }

Properties

Name Value
svn:keywords Id