Permalink
Browse files

clarified some codestyle requirements

  • Loading branch information...
1 parent 672290a commit 3b9962b63f29ba55a42e801e7b20cdb58dc0b6df Caleb James DeLisle committed May 29, 2012
View
@@ -65,7 +65,9 @@ int String_compare(const String* a, const String* b)
for (i = 0; i < (a->len < b->len ? a->len : b->len); i++)
{
d = a->bytes[i] - b->bytes[i];
- if (0 != d) return d;
+ if (0 != d) {
+ return d;
+ }
}
return a->len - b->len;
}
View
@@ -456,7 +456,8 @@ int main(int argc, char** argv)
Crypto_init();
Assert_true(argc > 0);
- if (argc == 2) { // one argument
+ if (argc == 2) {
+ // one argument
if (strcmp(argv[1], "--help") == 0) {
return usage(argv[0]);
} else if (strcmp(argv[1], "--genconf") == 0) {
@@ -472,10 +473,11 @@ int main(int argc, char** argv)
return 0;
} else {
fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], argv[1]);
- fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
+ fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
return -1;
}
- } else if (argc > 2) { // more than one argument?
+ } else if (argc > 2) {
+ // more than one argument?
fprintf(stderr, "%s: too many arguments\n", argv[0]);
fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
return -1;
@@ -437,14 +437,16 @@ static void applySeed(int argc, char** argv)
srand(seedValue);
}
-/* list of tests to run */
-static int (*testRunList[])(struct AppState* state, struct AddressMapper* map,
- struct TestInfo* info) = {
- runTest_replaceLeastRecentlyUsed,
- runTest_dontReplaceMostRecentlyUsed,
- runTest_removeAndPut,
- runTest_orderCheck,
- NULL
+/* list of tests to run (array of function pointers) */
+static int (*testRunList[])(struct AppState* state,
+ struct AddressMapper* map,
+ struct TestInfo* info) =
+{
+ runTest_replaceLeastRecentlyUsed,
+ runTest_dontReplaceMostRecentlyUsed,
+ runTest_removeAndPut,
+ runTest_orderCheck,
+ NULL
};
View
@@ -30,7 +30,8 @@ static void AbortHandler_callback(char* message, int code, struct ExceptionHandl
* The exception handler.
* Prints the message to stderr and aborts the program.
*/
-static struct ExceptionHandler* AbortHandler_INSTANCE = &(struct ExceptionHandler) {
+static struct ExceptionHandler* AbortHandler_INSTANCE = &(struct ExceptionHandler)
+{
.exception = AbortHandler_callback
};
View
@@ -51,6 +51,7 @@ sub error {
open FILE, "$fileName" or die $!;
my $lineNum = 1;
my $parenthCount = 0;
+ my $functionParenthCount = 0;
my $expectBracket = 0;
foreach my $line (split("\n", <FILE>)) {
@@ -87,6 +88,17 @@ sub error {
}
}
+ if ($functionParenthCount > 0 || $line =~ /^\w+\s.*(\(.*)$/) {
+ my $txt = ($functionParenthCount > 0) ? $line : $1;
+ $functionParenthCount += (($txt =~ tr/(//) - ($txt =~ tr/)//));
+ if ($functionParenthCount == 0) {
+ $txt = substr($txt, rindex($txt, ')') + 1);
+ if ($txt =~ /{/) {
+ error("please put the opening bracket on the next line.");
+ }
+ }
+ }
+
$lineInfo = "$fileName:$lineNum";
if (length($line) > 100) {
@@ -127,7 +139,7 @@ sub error {
$txt = substr($txt, rindex($txt, ')') + 1);
# for (x; y; z) ;
# is not an unbracketed block.
- if ($txt !~ /[\s]*;/ && $txt !~ /[\s]+{/) {
+ if ($txt !~ /^[\s]*;$/ && $txt !~ /^[\s]+{$/ && $txt !~ /^[\s]+{[\s]*\\$/) {
if ($txt =~ /[\s]*$/) {
$expectBracket = 1;
} else {
View
@@ -55,18 +55,25 @@ static inline uint32_t NumberCompress_getDecompressed(const uint64_t label,
* Fixed 4 bit scheme: 15 peers + 1 router
**********************/
# define NumberCompress_4_INTERFACES 16
-static inline uint32_t NumberCompress_4_bitsUsedForLabel(const uint64_t label) {
+static inline uint32_t NumberCompress_4_bitsUsedForLabel(const uint64_t label)
+{
return 4;
}
-static inline uint32_t NumberCompress_4_bitsUsedForNumber(const uint32_t number) {
+
+static inline uint32_t NumberCompress_4_bitsUsedForNumber(const uint32_t number)
+{
return 4;
}
+
static inline uint64_t NumberCompress_4_getCompressed(const uint32_t number,
- const uint32_t bitsUsed) {
+ const uint32_t bitsUsed)
+{
return number;
}
+
static inline uint32_t NumberCompress_4_getDecompressed(const uint64_t label,
- const uint32_t bitsUsed) {
+ const uint32_t bitsUsed)
+{
return label & 0xf;
}
@@ -80,35 +87,55 @@ static inline uint32_t NumberCompress_4_getDecompressed(const uint64_t label,
# define NumberCompress_8_INTERFACES 241
static inline uint32_t NumberCompress_8_bitsUsedForLabel(const uint64_t label)
{
- if (1 == (label & 0xf)) return 4;
+ if (1 == (label & 0xf)) {
+ return 4;
+ }
return 8;
}
static inline uint32_t NumberCompress_8_bitsUsedForNumber(const uint32_t number)
{
- if (1 == number) return 4;
+ if (1 == number) {
+ return 4;
+ }
return 8;
}
static inline uint64_t NumberCompress_8_getCompressed(const uint32_t number,
const uint32_t bitsUsed)
{
- if (1 == number) return 1;
- if (240 == number) return 0x10;
+ if (1 == number) {
+ return 1;
+ }
+
+ if (240 == number) {
+ return 0x10;
+ }
uint32_t low = number & 0xf;
uint32_t high = (number >> 4) & 0xf;
- if (high > 0) ++high;
+ if (high > 0) {
+ ++high;
+ }
return (low << 4) + high;
}
static inline uint32_t NumberCompress_8_getDecompressed(const uint64_t label,
const uint32_t bitsUsed)
{
uint32_t low = label & 0xf;
- if (1 == low) return 1;
- if (0x10 == (label & 0xff)) return 240;
+ if (1 == low) {
+ return 1;
+ }
+
+ if (0x10 == (label & 0xff)) {
+ return 240;
+ }
+
uint32_t high = (label >> 4) & 0xf;
- if (low > 0) --low; // low != 1
+
+ if (low > 0) {
+ --low; // low != 1
+ }
return (low << 4) + high;
}
@@ -125,8 +152,14 @@ static inline uint32_t NumberCompress_8_getDecompressed(const uint64_t label,
# define NumberCompress_dyn_INTERFACES 257
static inline uint32_t NumberCompress_dyn_bitsUsedForLabel(const uint64_t label)
{
- if (0 != (label & 0x1)) return 4;
- if (0 != (label & 0x2)) return 7;
+ if (0 != (label & 0x1)) {
+ return 4;
+ }
+
+ if (0 != (label & 0x2)) {
+ return 7;
+ }
+
return 10;
}
@@ -144,17 +177,26 @@ static inline uint32_t NumberCompress_dyn_bitsUsedForNumber(const uint32_t numbe
static inline uint64_t NumberCompress_dyn_getCompressed(const uint32_t number,
const uint32_t bitsUsed)
{
- if (1 == number) return 1;
+ if (1 == number) {
+ return 1;
+ }
+
switch (bitsUsed) {
case 4:
- if (0 == number) return 3;
+ if (0 == number) {
+ return 3;
+ }
return (number << 1) | 1;
case 7:
- if (0 == number) return 2;
+ if (0 == number) {
+ return 2;
+ }
// skip the number 1
return ((number-1) << 2) | 2;
case 10:
- if (0 == number) return 0;
+ if (0 == number) {
+ return 0;
+ }
// skip the number 1
return ((number-1) << 2);
default: return 0;
@@ -168,16 +210,24 @@ static inline uint32_t NumberCompress_dyn_getDecompressed(const uint64_t label,
switch (bitsUsed) {
case 4:
number = (label >> 1) & 0x7u;
- if (0 == number) return 1;
- if (1 == number) return 0;
+ if (0 == number) {
+ return 1;
+ }
+ if (1 == number) {
+ return 0;
+ }
return number;
case 7:
number = (label >> 2) & 0x1fu;
- if (0 != number) ++number; // skip the number 1
+ if (0 != number) {
+ ++number; // skip the number 1
+ }
return number;
case 10:
number = (label >> 2) & 0xffu;
- if (0 != number) ++number; // skip the number 1
+ if (0 != number) {
+ ++number; // skip the number 1
+ }
return number;
default: return 0;
}
@@ -188,17 +238,22 @@ static inline uint32_t NumberCompress_dyn_getDecompressed(const uint64_t label,
#if CJDNS_MAX_PEERS < 16
# define NumberCompress_INTERFACES NumberCompress_4_INTERFACES
-static inline uint32_t NumberCompress_bitsUsedForLabel(const uint64_t label) {
+static inline uint32_t NumberCompress_bitsUsedForLabel(const uint64_t label)
+{
return NumberCompress_4_bitsUsedForLabel(label);
}
-static inline uint32_t NumberCompress_bitsUsedForNumber(const uint32_t number) {
+
+static inline uint32_t NumberCompress_bitsUsedForNumber(const uint32_t number)
+{
return NumberCompress_4_bitsUsedForNumber(number);
}
+
static inline uint64_t NumberCompress_getCompressed(const uint32_t number,
const uint32_t bitsUsed)
{
return NumberCompress_4_getCompressed(number, bitsUsed);
}
+
static inline uint32_t NumberCompress_getDecompressed(const uint64_t label,
const uint32_t bitsUsed)
{
@@ -208,17 +263,22 @@ static inline uint32_t NumberCompress_getDecompressed(const uint64_t label,
#elif CJDNS_MAX_PEERS < 241
# define NumberCompress_INTERFACES NumberCompress_8_INTERFACES
-static inline uint32_t NumberCompress_bitsUsedForLabel(const uint64_t label) {
+static inline uint32_t NumberCompress_bitsUsedForLabel(const uint64_t label)
+{
return NumberCompress_8_bitsUsedForLabel(label);
}
-static inline uint32_t NumberCompress_bitsUsedForNumber(const uint32_t number) {
+
+static inline uint32_t NumberCompress_bitsUsedForNumber(const uint32_t number)
+{
return NumberCompress_8_bitsUsedForNumber(number);
}
+
static inline uint64_t NumberCompress_getCompressed(const uint32_t number,
const uint32_t bitsUsed)
{
return NumberCompress_8_getCompressed(number, bitsUsed);
}
+
static inline uint32_t NumberCompress_getDecompressed(const uint64_t label,
const uint32_t bitsUsed)
{
@@ -228,17 +288,22 @@ static inline uint32_t NumberCompress_getDecompressed(const uint64_t label,
#else
# define NumberCompress_INTERFACES NumberCompress_dyn_INTERFACES
-static inline uint32_t NumberCompress_bitsUsedForLabel(const uint64_t label) {
+static inline uint32_t NumberCompress_bitsUsedForLabel(const uint64_t label)
+{
return NumberCompress_dyn_bitsUsedForLabel(label);
}
-static inline uint32_t NumberCompress_bitsUsedForNumber(const uint32_t number) {
+
+static inline uint32_t NumberCompress_bitsUsedForNumber(const uint32_t number)
+{
return NumberCompress_dyn_bitsUsedForNumber(number);
}
+
static inline uint64_t NumberCompress_getCompressed(const uint32_t number,
const uint32_t bitsUsed)
{
return NumberCompress_dyn_getCompressed(number, bitsUsed);
}
+
static inline uint32_t NumberCompress_getDecompressed(const uint64_t label,
const uint32_t bitsUsed)
{
@@ -38,7 +38,8 @@ static void splice()
Assert_always(expected == out);
}
-static uint64_t routeToInterface(uint32_t number) {
+static uint64_t routeToInterface(uint32_t number)
+{
uint32_t bits = NumberCompress_bitsUsedForNumber(number);
return (1 << bits) | NumberCompress_getCompressed(number, bits);
}
@@ -23,7 +23,8 @@ static void numberCompressions_generic(
uint32_t (*bitsUsedForLabel)(const uint64_t label),
uint32_t (*bitsUsedForNumber)(const uint32_t number),
uint64_t (*getCompressed)(const uint32_t number, const uint32_t bitsUsed),
- uint32_t (*getDecompressed)(const uint64_t label, const uint32_t bitsUsed)) {
+ uint32_t (*getDecompressed)(const uint64_t label, const uint32_t bitsUsed))
+{
uint8_t bitWidths[64] = { 0 };
@@ -32,11 +33,15 @@ static void numberCompressions_generic(
}
for (uint32_t bits = 0; bits < 64; ++bits) {
- if (!bitWidths[bits]) continue;
+ if (!bitWidths[bits]) {
+ continue;
+ }
for (uint32_t i = 0; i < nInterfaces; ++i) {
/* only check for greater-or-equal bit widths */
- if (bits < bitsUsedForNumber(i)) continue;
+ if (bits < bitsUsedForNumber(i)) {
+ continue;
+ }
uint64_t label = getCompressed(i, bits);
@@ -42,7 +42,8 @@ static const uint8_t publicKey[32] = {
static const char publicKeyBase32[] = "r6jzx210usqbgnm3pdtm1z6btd14pvdtkn5j8qnpgqzknpggkuw0";
static const char ipv6[] = "fc68:cb2c:60db:cb96:19ac:34a8:fd34:03fc";
-int main() {
+int main()
+{
/* verify public key */
struct Address address;
crypto_scalarmult_curve25519_base(address.key, privateKey);

0 comments on commit 3b9962b

Please sign in to comment.