Fixes style: make style

This commit is contained in:
Romuald Conty 2012-12-09 20:09:55 +01:00
parent 007b78cbb4
commit 82c41b4fc1
9 changed files with 91 additions and 89 deletions

View file

@ -2387,11 +2387,11 @@ pn53x_InRelease(struct nfc_device *pnd, const uint8_t ui8Target)
// No much choice what to release actually...
uint8_t abtCmdRcs360[] = { InRelease, 0x01, 0x01 };
res = pn53x_transceive(pnd, abtCmdRcs360, sizeof(abtCmdRcs360), NULL, 0, -1);
return (res>=0) ? NFC_SUCCESS : res;
return (res >= 0) ? NFC_SUCCESS : res;
}
uint8_t abtCmd[] = { InRelease, ui8Target };
res = pn53x_transceive(pnd, abtCmd, sizeof(abtCmd), NULL, 0, -1);
return (res>=0) ? NFC_SUCCESS : res;
return (res >= 0) ? NFC_SUCCESS : res;
}
int

View file

@ -35,10 +35,10 @@
#define LIBNFC_CONFFILE LIBNFC_SYSCONFDIR"/libnfc.conf"
#define LIBNFC_DEVICECONFDIR LIBNFC_SYSCONFDIR"/devices.d"
static bool
conf_parse_file(const char* filename, void (*conf_keyvalue)(void* data, const char* key, const char* value), void* data)
static bool
conf_parse_file(const char *filename, void (*conf_keyvalue)(void *data, const char *key, const char *value), void *data)
{
FILE *f = fopen (filename, "r");
FILE *f = fopen(filename, "r");
if (!f) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Unable to open file: %s", filename);
return false;
@ -46,13 +46,13 @@ conf_parse_file(const char* filename, void (*conf_keyvalue)(void* data, const ch
char line[BUFSIZ];
const char *str_regex = "^[[:space:]]*([[:alnum:]_.]+)[[:space:]]*=[[:space:]]*(\"(.+)\"|([^[:space:]]+))[[:space:]]*$";
regex_t preg;
if(regcomp (&preg, str_regex, REG_EXTENDED|REG_NOTEOL) != 0) {
if (regcomp(&preg, str_regex, REG_EXTENDED | REG_NOTEOL) != 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Regular expression used for configuration file parsing is not valid.");
return false;
}
size_t nmatch = preg.re_nsub + 1;
regmatch_t *pmatch = malloc (sizeof (*pmatch) * nmatch);
if(!pmatch) {
regmatch_t *pmatch = malloc(sizeof(*pmatch) * nmatch);
if (!pmatch) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Not enough memory: malloc failed.");
return false;
}
@ -60,20 +60,22 @@ conf_parse_file(const char* filename, void (*conf_keyvalue)(void* data, const ch
int lineno = 0;
while (fgets(line, BUFSIZ, f) != NULL) {
lineno++;
switch(line[0]) {
switch (line[0]) {
case '#':
case '\n':
break;
default: {
int match;
if ((match = regexec (&preg, line, nmatch, pmatch, 0)) == 0) {
if ((match = regexec(&preg, line, nmatch, pmatch, 0)) == 0) {
const size_t key_size = pmatch[1].rm_eo - pmatch[1].rm_so;
const off_t value_pmatch = pmatch[3].rm_eo!=-1?3:4;
const off_t value_pmatch = pmatch[3].rm_eo != -1 ? 3 : 4;
const size_t value_size = pmatch[value_pmatch].rm_eo - pmatch[value_pmatch].rm_so;
char key[key_size+1];
char value[value_size+1];
strncpy(key, line+(pmatch[1].rm_so), key_size); key[key_size]='\0';
strncpy(value, line+(pmatch[value_pmatch].rm_so), value_size); value[value_size]='\0';
char key[key_size + 1];
char value[value_size + 1];
strncpy(key, line + (pmatch[1].rm_so), key_size);
key[key_size] = '\0';
strncpy(value, line + (pmatch[value_pmatch].rm_so), value_size);
value[value_size] = '\0';
conf_keyvalue(data, key, value);
} else {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Parse error on line #%d: %s", lineno, line);
@ -87,10 +89,10 @@ conf_parse_file(const char* filename, void (*conf_keyvalue)(void* data, const ch
return false;
}
static void
conf_keyvalue_context(void *data, const char* key, const char* value)
static void
conf_keyvalue_context(void *data, const char *key, const char *value)
{
nfc_context *context = (nfc_context*)data;
nfc_context *context = (nfc_context *)data;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "key: [%s], value: [%s]", key, value);
if (strcmp(key, "allow_autoscan") == 0) {
string_as_boolean(value, &(context->allow_autoscan));
@ -99,59 +101,59 @@ conf_keyvalue_context(void *data, const char* key, const char* value)
} else if (strcmp(key, "log_level") == 0) {
context->log_level = atoi(value);
} else if (strcmp(key, "device.name") == 0) {
if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count-1].name, "") != 0) {
if(context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) {
if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].name, "") != 0) {
if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices.");
return;
}
context->user_defined_device_count++;
}
strcpy(context->user_defined_devices[context->user_defined_device_count-1].name, value);
strcpy(context->user_defined_devices[context->user_defined_device_count - 1].name, value);
} else if (strcmp(key, "device.connstring") == 0) {
if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count-1].connstring, "") != 0) {
if(context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) {
if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].connstring, "") != 0) {
if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices.");
return;
}
context->user_defined_device_count++;
}
strcpy(context->user_defined_devices[context->user_defined_device_count-1].connstring, value);
strcpy(context->user_defined_devices[context->user_defined_device_count - 1].connstring, value);
} else {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Unknown key in config line: %s = %s", key, value);
}
}
static void
conf_keyvalue_device(void *data, const char* key, const char* value)
conf_keyvalue_device(void *data, const char *key, const char *value)
{
char newkey[BUFSIZ];
sprintf(newkey, "device.%s", key);
conf_keyvalue_context(data, newkey, value);
}
static void
static void
conf_devices_load(const char *dirname, nfc_context *context)
{
DIR *d = opendir(dirname);
if (!d) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open directory: %s", dirname);
} else {
struct dirent* de;
struct dirent *de;
while ((de = readdir(d))) {
if (de->d_name[0]!='.') {
if (de->d_name[0] != '.') {
const size_t filename_len = strlen(de->d_name);
const size_t extension_len = strlen(".conf");
if ((filename_len > extension_len) &&
(strncmp(".conf", de->d_name + (filename_len-extension_len), extension_len) == 0)) {
if ((filename_len > extension_len) &&
(strncmp(".conf", de->d_name + (filename_len - extension_len), extension_len) == 0)) {
char filename[BUFSIZ] = LIBNFC_DEVICECONFDIR"/";
strcat (filename, de->d_name);
strcat(filename, de->d_name);
struct stat s;
if (stat(filename, &s) == -1) {
perror("stat");
continue;
}
if(S_ISREG(s.st_mode)) {
conf_parse_file (filename, conf_keyvalue_device, context);
if (S_ISREG(s.st_mode)) {
conf_parse_file(filename, conf_keyvalue_device, context);
}
}
}
@ -159,7 +161,7 @@ conf_devices_load(const char *dirname, nfc_context *context)
}
}
void
void
conf_load(nfc_context *context)
{
conf_parse_file(LIBNFC_CONFFILE, conf_keyvalue_context, context);

View file

@ -210,8 +210,8 @@ const struct pn53x_io acr122_usb_io;
static int acr122_usb_init(nfc_device *pnd);
static int acr122_usb_ack(nfc_device *pnd);
static int acr122_usb_send_apdu(nfc_device *pnd,
const uint8_t ins, const uint8_t p1, const uint8_t p2, const uint8_t *const data, size_t data_len, const uint8_t le,
uint8_t *out, const size_t out_size);
const uint8_t ins, const uint8_t p1, const uint8_t p2, const uint8_t *const data, size_t data_len, const uint8_t le,
uint8_t *out, const size_t out_size);
static int
acr122_usb_bulk_read(struct acr122_usb_data *data, uint8_t abtRx[], const size_t szRx, const int timeout)
@ -568,15 +568,15 @@ acr122_usb_close(nfc_device *pnd)
uint32_t htole32(uint32_t u32);
uint32_t
uint32_t
htole32(uint32_t u32)
{
uint8_t u8[4];
for(int i=0; i<4; i++) {
for (int i = 0; i < 4; i++) {
u8[i] = (u32 & 0xff);
u32 >>= 8;
}
uint32_t *pu32 = (uint32_t*)u8;
uint32_t *pu32 = (uint32_t *)u8;
return *pu32;
}
@ -616,7 +616,7 @@ acr122_usb_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
return pnd->last_error;
}
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char*)&(DRIVER_DATA(pnd)->tama_frame), res, timeout)) < 0) {
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char *) & (DRIVER_DATA(pnd)->tama_frame), res, timeout)) < 0) {
pnd->last_error = res;
return pnd->last_error;
}
@ -657,7 +657,7 @@ read:
uint8_t attempted_response = RDR_to_PC_Escape; // ACR122U attempted response
size_t len;
switch(DRIVER_DATA(pnd)->model) {
switch (DRIVER_DATA(pnd)->model) {
case TOUCHATAG:
attempted_response = RDR_to_PC_DataBlock;
if (res == NFC_ETIMEOUT) {
@ -672,11 +672,11 @@ read:
}
if (abtRxBuf[offset] != attempted_response) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame header mismatch");
pnd->last_error = NFC_EIO;
pnd->last_error = NFC_EIO;
return pnd->last_error;
}
offset++;
len = abtRxBuf[offset++];
if (len != 2) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Wrong reply");
@ -685,7 +685,7 @@ read:
}
acr122_usb_send_apdu(pnd, APDU_GetAdditionnalData, 0x00, 0x00, NULL, 0, abtRxBuf[11], abtRxBuf, sizeof(abtRxBuf));
offset = 0;
break;
break;
case ACR122:
break;
case UNKNOWN:
@ -718,7 +718,7 @@ read:
// XXX In CCID specification, len is a 32-bits (dword), do we need to decode more than 1 byte ? (0-255 bytes for PN532 reply)
len = abtRxBuf[offset++];
if ((abtRxBuf[offset] != 0x00) && (abtRxBuf[offset+1] != 0x00) && (abtRxBuf[offset+2] != 0x00)) {
if ((abtRxBuf[offset] != 0x00) && (abtRxBuf[offset + 1] != 0x00) && (abtRxBuf[offset + 2] != 0x00)) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Not implemented: only 1-byte length is supported, please report this bug with a full trace.");
pnd->last_error = NFC_EIO;
return pnd->last_error;
@ -774,20 +774,20 @@ acr122_usb_ack(nfc_device *pnd)
if ((res = acr122_build_frame_from_tama(pnd, acr122_ack_frame, sizeof(acr122_ack_frame))) < 0)
return res;
res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char*)&(DRIVER_DATA(pnd)->tama_frame), res, 1000);
res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char *) & (DRIVER_DATA(pnd)->tama_frame), res, 1000);
uint8_t abtRxBuf[255 + sizeof(struct ccid_header)];
res = acr122_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), 1000);
return res;
}
static int
acr122_usb_send_apdu(nfc_device *pnd,
static int
acr122_usb_send_apdu(nfc_device *pnd,
const uint8_t ins, const uint8_t p1, const uint8_t p2, const uint8_t *const data, size_t data_len, const uint8_t le,
uint8_t *out, const size_t out_size)
{
int res;
size_t frame_len = acr122_build_frame_from_apdu(pnd, ins, p1, p2, data, data_len, le);
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char*)&(DRIVER_DATA(pnd)->apdu_frame), frame_len, 1000)) < 0)
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char *) & (DRIVER_DATA(pnd)->apdu_frame), frame_len, 1000)) < 0)
return res;
if ((res = acr122_usb_bulk_read(DRIVER_DATA(pnd), out, out_size, 1000)) < 0)
return res;
@ -835,7 +835,7 @@ acr122_usb_init(nfc_device *pnd)
.bMessageSpecific = { 0x01, 0x00, 0x00 },
};
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char*)&ccid_frame, sizeof(struct ccid_header), 1000)) < 0)
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char *)&ccid_frame, sizeof(struct ccid_header), 1000)) < 0)
return res;
if ((res = acr122_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), 1000)) < 0)
return res;

View file

@ -25,7 +25,7 @@
#include <stdarg.h>
#include <fcntl.h>
void
void
log_init(const nfc_context *context)
{
char str[32];
@ -56,8 +56,8 @@ log_put(const uint8_t group, const char *category, const uint8_t priority, const
// printf("log_level = %"PRIu32" group = %"PRIu8" priority = %"PRIu8"\n", log_level, group, priority);
if (log_level) { // If log is not disabled by log_level=none
if ( ((log_level & 0x00000003) >= priority) || // Global log level
(((log_level >> (group*2)) & 0x00000003) >= priority) ) { // Group log level
if (((log_level & 0x00000003) >= priority) || // Global log level
(((log_level >> (group * 2)) & 0x00000003) >= priority)) { // Group log level
va_list va;
va_start(va, format);
fprintf(stderr, "%s\t%s\t", log_priority_to_str(priority), category);

View file

@ -24,7 +24,7 @@
#include <string.h>
/*
int
int
log_priority_to_int(const char* priority)
{
if (strcmp("none", priority) == 0) {
@ -54,10 +54,10 @@ log_priority_to_int(const char* priority)
}
*/
const char*
const char *
log_priority_to_str(const int priority)
{
switch(priority) {
switch (priority) {
case NFC_LOG_PRIORITY_ERROR:
return "error";
case NFC_LOG_PRIORITY_INFO:

View file

@ -50,7 +50,7 @@
*/
//int log_priority_to_int(const char* priority);
const char* log_priority_to_str(const int priority);
const char *log_priority_to_str(const int priority);
#if defined LOG

View file

@ -33,23 +33,23 @@
#define LOG_GROUP NFC_LOG_GROUP_GENERAL
#define LOG_CATEGORY "libnfc.general"
void
string_as_boolean(const char* s, bool *value)
void
string_as_boolean(const char *s, bool *value)
{
if (s) {
if (!(*value)) {
if ( (strcmp(s, "yes") == 0) ||
(strcmp(s, "true") == 0) ||
(strcmp(s, "1") == 0) ) {
*value = true;
return;
if ((strcmp(s, "yes") == 0) ||
(strcmp(s, "true") == 0) ||
(strcmp(s, "1") == 0)) {
*value = true;
return;
}
} else {
if ( (strcmp(s, "no") == 0) ||
(strcmp(s, "false") == 0) ||
(strcmp(s, "0") == 0) ) {
*value = false;
return;
if ((strcmp(s, "no") == 0) ||
(strcmp(s, "false") == 0) ||
(strcmp(s, "0") == 0)) {
*value = false;
return;
}
}
}
@ -74,7 +74,7 @@ nfc_context_new(void)
#endif
// Clear user defined devices array
for (int i=0; i<MAX_USER_DEFINED_DEVICES; i++) {
for (int i = 0; i < MAX_USER_DEFINED_DEVICES; i++) {
strcpy(res->user_defined_devices[i].name, "");
strcpy(res->user_defined_devices[i].connstring, "");
}
@ -111,11 +111,11 @@ nfc_context_new(void)
#else
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "log_level is set to %"PRIu32, res->log_level);
#endif
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "allow_autoscan is set to %s", (res->allow_autoscan)?"true":"false");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "allow_intrusive_scan is set to %s", (res->allow_intrusive_scan)?"true":"false");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "allow_autoscan is set to %s", (res->allow_autoscan) ? "true" : "false");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "allow_intrusive_scan is set to %s", (res->allow_intrusive_scan) ? "true" : "false");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%d device(s) defined by user", res->user_defined_device_count);
for(uint32_t i=0; i<res->user_defined_device_count; i++) {
for (uint32_t i = 0; i < res->user_defined_device_count; i++) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, " #%d name: \"%s\", connstring: \"%s\"", i, res->user_defined_devices[i].name, res->user_defined_devices[i].connstring);
}
return res;

View file

@ -108,9 +108,9 @@
} while (0)
typedef enum {
NOT_INTRUSIVE,
INTRUSIVE,
NOT_AVAILABLE,
NOT_INTRUSIVE,
INTRUSIVE,
NOT_AVAILABLE,
} scan_type_enum;
struct nfc_driver {
@ -207,7 +207,7 @@ struct nfc_device {
nfc_device *nfc_device_new(const nfc_context *context, const nfc_connstring connstring);
void nfc_device_free(nfc_device *dev);
void string_as_boolean(const char* s, bool *value);
void string_as_boolean(const char *s, bool *value);
void iso14443_cascade_uid(const uint8_t abtUID[], const size_t szUID, uint8_t *pbtCascadedUID, size_t *pszCascadedUID);

View file

@ -187,7 +187,7 @@ nfc_open(nfc_context *context, const nfc_connstring connstring)
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open \"%s\".", ncs);
return pnd;
}
for (uint32_t i=0; i>context->user_defined_device_count; i++) {
for (uint32_t i = 0; i > context->user_defined_device_count; i++) {
if (strcmp(ncs, context->user_defined_devices[i].connstring) == 0) {
// This is a device sets by user, we use the device name given by user
strcpy(pnd->name, context->user_defined_devices[i].name);
@ -237,16 +237,16 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
const struct nfc_driver **pndr = nfc_drivers;
if (!context) {
printf ("NULL context is not supported anymore! Please fix your code.\n");
printf("NULL context is not supported anymore! Please fix your code.\n");
exit(EXIT_FAILURE);
}
// Load manually configured devices (from config file and env variables)
// TODO From env var...
for (uint32_t i=0; i<context->user_defined_device_count; i++) {
strcpy((char*)(connstrings+device_found), context->user_defined_devices[i].connstring);
for (uint32_t i = 0; i < context->user_defined_device_count; i++) {
strcpy((char *)(connstrings + device_found), context->user_defined_devices[i].connstring);
device_found++;
if(device_found >= connstrings_len)
if (device_found >= connstrings_len)
return device_found;
}
@ -254,7 +254,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
if (context->allow_autoscan) {
while ((ndr = *pndr)) {
size_t _device_found = 0;
if((ndr->scan_type == NOT_INTRUSIVE) || ((context->allow_intrusive_scan) && (ndr->scan_type == INTRUSIVE))) {
if ((ndr->scan_type == NOT_INTRUSIVE) || ((context->allow_intrusive_scan) && (ndr->scan_type == INTRUSIVE))) {
_device_found = ndr->scan(context, connstrings + (device_found), connstrings_len - (device_found));
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%ld device(s) found using %s driver", (unsigned long) _device_found, ndr->name);
if (_device_found > 0) {
@ -666,7 +666,7 @@ nfc_initiator_transceive_bytes(nfc_device *pnd, const uint8_t *pbtTx, const size
* CRC bytes. Using this feature you are able to simulate these frames.
*/
int
nfc_initiator_transceive_bits(nfc_device *pnd,
nfc_initiator_transceive_bits(nfc_device *pnd,
const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
uint8_t *pbtRx, const size_t szRx,
uint8_t *pbtRxPar)
@ -702,8 +702,8 @@ nfc_initiator_transceive_bits(nfc_device *pnd,
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
*/
int
nfc_initiator_transceive_bytes_timed(nfc_device *pnd,
const uint8_t *pbtTx, const size_t szTx,
nfc_initiator_transceive_bytes_timed(nfc_device *pnd,
const uint8_t *pbtTx, const size_t szTx,
uint8_t *pbtRx, const size_t szRx,
uint32_t *cycles)
{
@ -746,10 +746,10 @@ nfc_initiator_target_is_present(nfc_device *pnd, const nfc_target nt)
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
*/
int
nfc_initiator_transceive_bits_timed(nfc_device *pnd,
nfc_initiator_transceive_bits_timed(nfc_device *pnd,
const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
uint8_t *pbtRx, const size_t szRx,
uint8_t *pbtRxPar,
uint8_t *pbtRx, const size_t szRx,
uint8_t *pbtRxPar,
uint32_t *cycles)
{
(void)szRx;