First prototype of argument parsing for device description (issue #87).
This commit is contained in:
parent
7945dd18fa
commit
4bc522cd1e
3 changed files with 58 additions and 13 deletions
51
libnfc/nfc.c
51
libnfc/nfc.c
|
|
@ -1026,10 +1026,51 @@ const char* nfc_device_name(nfc_device_t* pnd)
|
|||
*/
|
||||
const char* nfc_version(void)
|
||||
{
|
||||
#ifdef SVN_REVISION
|
||||
return PACKAGE_VERSION" (r"SVN_REVISION")";
|
||||
#else
|
||||
return PACKAGE_VERSION;
|
||||
#endif // SVN_REVISION
|
||||
#ifdef SVN_REVISION
|
||||
return PACKAGE_VERSION" (r"SVN_REVISION")";
|
||||
#else
|
||||
return PACKAGE_VERSION;
|
||||
#endif // SVN_REVISION
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tries to parse arguments to find device descriptions.
|
||||
* @return Returns the list of found device descriptions.
|
||||
*/
|
||||
nfc_device_desc_t* nfc_parse_device_desc(int argc, const char *argv[], size_t* szFound)
|
||||
{
|
||||
nfc_device_desc_t* pndd = 0;
|
||||
*szFound = 0;
|
||||
int arg;
|
||||
|
||||
// Get commandline options
|
||||
for (arg=1;arg<argc;arg++) {
|
||||
|
||||
if (0 == strcmp(argv[arg], "--device")) {
|
||||
|
||||
if (argc > arg+1) {
|
||||
|
||||
pndd = malloc(sizeof(nfc_device_desc_t));
|
||||
|
||||
char buffer[256];
|
||||
strncpy(buffer, argv[++arg], 256);
|
||||
|
||||
// Driver.
|
||||
pndd->pcDriver = (char *)malloc(256);
|
||||
strcpy(pndd->pcDriver, strtok(buffer, ":"));
|
||||
|
||||
// Port.
|
||||
pndd->pcPort = (char *)malloc(256);
|
||||
strcpy(pndd->pcPort, strtok(NULL, ":"));
|
||||
|
||||
// Speed.
|
||||
sscanf(strtok(NULL, ":"), "%d", &pndd->uiSpeed);
|
||||
|
||||
*szFound = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pndd;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue