diff options
author | Simon Josefsson <simon@josefsson.org> | 2013-03-24 10:28:25 +0100 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2013-03-24 10:28:25 +0100 |
commit | 36f03daf3361187cc556a35dd36761302ccd94d5 (patch) | |
tree | 2bab7700940de89f49f038b7f6b093e5590099bf /src | |
parent | f36dd027a9002fcd2eec72aa3f445e03b8c7984d (diff) | |
download | libtasn1-36f03daf3361187cc556a35dd36761302ccd94d5.tar.gz |
Indent code.
Diffstat (limited to 'src')
-rw-r--r-- | src/asn1Coding.c | 16 | ||||
-rw-r--r-- | src/asn1Decoding.c | 69 | ||||
-rw-r--r-- | src/asn1Parser.c | 9 | ||||
-rw-r--r-- | src/benchmark.c | 27 | ||||
-rw-r--r-- | src/benchmark.h | 12 |
5 files changed, 68 insertions, 65 deletions
diff --git a/src/asn1Coding.c b/src/asn1Coding.c index 700e958..202d5fc 100644 --- a/src/asn1Coding.c +++ b/src/asn1Coding.c @@ -214,8 +214,7 @@ main (int argc, char *argv[]) fputs ("Parse: done.\n", stderr); break; case ASN1_FILE_NOT_FOUND: - fprintf (stderr, "asn1Coding: FILE %s NOT FOUND\n", - inputFileAsnName); + fprintf (stderr, "asn1Coding: FILE %s NOT FOUND\n", inputFileAsnName); break; case ASN1_SYNTAX_ERROR: case ASN1_IDENTIFIER_NOT_FOUND: @@ -223,8 +222,7 @@ main (int argc, char *argv[]) fprintf (stderr, "asn1Coding: %s\n", errorDescription); break; default: - fprintf (stderr, "libtasn1 ERROR: %s\n", - asn1_strerror (asn1_result)); + fprintf (stderr, "libtasn1 ERROR: %s\n", asn1_strerror (asn1_result)); } if (asn1_result != ASN1_SUCCESS) @@ -240,7 +238,7 @@ main (int argc, char *argv[]) if (inputFile == NULL) { fprintf (stderr, "asn1Coding: file '%s' not found\n", - inputFileAssignmentName); + inputFileAssignmentName); free (inputFileAsnName); free (inputFileAssignmentName); exit (1); @@ -250,7 +248,7 @@ main (int argc, char *argv[]) putc ('\n', stderr); while ((last_ra = readAssignment (inputFile, varName, value)) - == ASSIGNMENT_SUCCESS) + == ASSIGNMENT_SUCCESS) { fprintf (stderr, "var=%s, value=%s\n", varName, value); if (structure == NULL) @@ -263,7 +261,7 @@ main (int argc, char *argv[]) if (asn1_result != ASN1_SUCCESS) { fprintf (stderr, "libtasn1 ERROR: %s\n", - asn1_strerror (asn1_result)); + asn1_strerror (asn1_result)); asn1_delete_structure (&definitions); asn1_delete_structure (&structure); @@ -331,8 +329,8 @@ main (int argc, char *argv[]) if (outputFile == NULL) { fprintf (stderr, - "asn1Coding: output file '%s' not available\n", - outputFileName); + "asn1Coding: output file '%s' not available\n", + outputFileName); free (der); free (inputFileAsnName); free (inputFileAssignmentName); diff --git a/src/asn1Decoding.c b/src/asn1Decoding.c index 00156c5..2a9cc96 100644 --- a/src/asn1Decoding.c +++ b/src/asn1Decoding.c @@ -33,7 +33,8 @@ #include <read-file.h> #include "benchmark.h" -static int decode(asn1_node definitions, const char* typeName, void* der, int der_len, int benchmark); +static int decode (asn1_node definitions, const char *typeName, void *der, + int der_len, int benchmark); /* This feature is available in gcc versions 2.5 and later. */ #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) @@ -101,9 +102,9 @@ main (int argc, char *argv[]) case 'h': /* HELP */ usage (EXIT_SUCCESS); break; - case 'b': - benchmark = 1; - break; + case 'b': + benchmark = 1; + break; case 'v': /* VERSION */ version_etc (stdout, program_name, PACKAGE, VERSION, "Fabio Fiorina", NULL); @@ -147,8 +148,7 @@ main (int argc, char *argv[]) fprintf (stderr, "Parse: done.\n"); break; case ASN1_FILE_NOT_FOUND: - fprintf (stderr, "asn1Decoding: FILE %s NOT FOUND\n", - inputFileAsnName); + fprintf (stderr, "asn1Decoding: FILE %s NOT FOUND\n", inputFileAsnName); break; case ASN1_SYNTAX_ERROR: case ASN1_IDENTIFIER_NOT_FOUND: @@ -156,8 +156,7 @@ main (int argc, char *argv[]) fprintf (stderr, "asn1Decoding: %s\n", errorDescription); break; default: - fprintf (stderr, "libtasn1 ERROR: %s\n", - asn1_strerror (asn1_result)); + fprintf (stderr, "libtasn1 ERROR: %s\n", asn1_strerror (asn1_result)); } if (asn1_result != ASN1_SUCCESS) @@ -178,7 +177,7 @@ main (int argc, char *argv[]) if (der == NULL) { fprintf (stderr, "asn1Decoding: could not read '%s'\n", - inputFileDerName); + inputFileDerName); asn1_delete_structure (&definitions); free (inputFileAsnName); @@ -203,7 +202,7 @@ main (int argc, char *argv[]) fclose(inputFile); */ - if (decode( definitions, typeName, der, der_len, benchmark) != ASN1_SUCCESS) + if (decode (definitions, typeName, der, der_len, benchmark) != ASN1_SUCCESS) { asn1_delete_structure (&definitions); free (inputFileAsnName); @@ -212,7 +211,7 @@ main (int argc, char *argv[]) free (der); exit (1); } - + asn1_delete_structure (&definitions); free (der); @@ -227,12 +226,14 @@ main (int argc, char *argv[]) exit (0); } -static int simple_decode(asn1_node definitions, const char* typeName, void* der, int der_len, int benchmark) +static int +simple_decode (asn1_node definitions, const char *typeName, void *der, + int der_len, int benchmark) { - -int asn1_result; -asn1_node structure = NULL; -char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; + + int asn1_result; + asn1_node structure = NULL; + char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; asn1_result = asn1_create_element (definitions, typeName, &structure); @@ -242,7 +243,7 @@ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; if (asn1_result != ASN1_SUCCESS) { fprintf (stderr, "Structure creation: %s\n", - asn1_strerror (asn1_result)); + asn1_strerror (asn1_result)); asn1_delete_structure (&structure); return asn1_result; } @@ -262,31 +263,35 @@ char errorDescription[ASN1_MAX_ERROR_DESCRIPTION_SIZE]; if (!benchmark) { fprintf (stderr, "\nDECODING RESULT:\n"); - asn1_print_structure (stdout, structure, "", ASN1_PRINT_NAME_TYPE_VALUE); + asn1_print_structure (stdout, structure, "", + ASN1_PRINT_NAME_TYPE_VALUE); } asn1_delete_structure (&structure); return ASN1_SUCCESS; } -static int decode(asn1_node definitions, const char* typeName, void* der, int der_len, int benchmark) +static int +decode (asn1_node definitions, const char *typeName, void *der, int der_len, + int benchmark) { -struct benchmark_st st; + struct benchmark_st st; - if (benchmark == 0) return simple_decode(definitions, typeName, der, der_len, benchmark); + if (benchmark == 0) + return simple_decode (definitions, typeName, der, der_len, benchmark); else { - start_benchmark(&st); - + start_benchmark (&st); + do - { - simple_decode(definitions, typeName, der, der_len, benchmark); - st.size++; - } - while(benchmark_must_finish == 0); - - stop_benchmark(&st, "structures"); - fprintf(stdout, "\n"); - + { + simple_decode (definitions, typeName, der, der_len, benchmark); + st.size++; + } + while (benchmark_must_finish == 0); + + stop_benchmark (&st, "structures"); + fprintf (stdout, "\n"); + } return ASN1_SUCCESS; } diff --git a/src/asn1Parser.c b/src/asn1Parser.c index 64bf16b..d77dab0 100644 --- a/src/asn1Parser.c +++ b/src/asn1Parser.c @@ -100,8 +100,7 @@ main (int argc, char *argv[]) switch (option_result) { case 0: - fprintf (stderr, "option %s", - long_options[option_index].name); + fprintf (stderr, "option %s", long_options[option_index].name); if (optarg) fprintf (stderr, " with arg %s", optarg); putc ('\n', stderr); @@ -174,8 +173,7 @@ main (int argc, char *argv[]) fputs ("Done.\n", stderr); break; case ASN1_FILE_NOT_FOUND: - fprintf (stderr, "asn1Parser: file %s was not found\n", - inputFileName); + fprintf (stderr, "asn1Parser: file %s was not found\n", inputFileName); break; case ASN1_SYNTAX_ERROR: case ASN1_IDENTIFIER_NOT_FOUND: @@ -183,8 +181,7 @@ main (int argc, char *argv[]) fprintf (stderr, "asn1Parser: %s\n", errorDescription); break; default: - fprintf (stderr, "libtasn1 ERROR: %s\n", - asn1_strerror (parse_result)); + fprintf (stderr, "libtasn1 ERROR: %s\n", asn1_strerror (parse_result)); } diff --git a/src/benchmark.c b/src/benchmark.c index 1ebf6b6..e7430cf 100644 --- a/src/benchmark.c +++ b/src/benchmark.c @@ -48,7 +48,7 @@ alarm_handler (int signo) static void value2human (unsigned long bytes, double secs, double *data, double *speed, - char *metric) + char *metric) { if (bytes > 1000 && bytes < 1000 * 1000) { @@ -80,9 +80,10 @@ value2human (unsigned long bytes, double secs, double *data, double *speed, } } -void start_benchmark(struct benchmark_st * st) +void +start_benchmark (struct benchmark_st *st) { - memset(st, 0, sizeof(*st)); + memset (st, 0, sizeof (*st)); #ifndef _WIN32 st->old_handler = signal (SIGALRM, alarm_handler); #endif @@ -94,28 +95,30 @@ void start_benchmark(struct benchmark_st * st) if (st->wtimer == NULL) { fprintf (stderr, "error: CreateWaitableTimer %u\n", GetLastError ()); - exit(1); + exit (1); } st->wthread = CreateThread (NULL, 0, alarm_handler, &st->wtimer, 0, NULL); if (st->wthread == NULL) { fprintf (stderr, "error: CreateThread %u\n", GetLastError ()); - exit(1); + exit (1); } st->alarm_timeout.QuadPart = (5) * 10000000; - if (SetWaitableTimer (st->wtimer, &st->alarm_timeout, 0, NULL, NULL, FALSE) == 0) + if (SetWaitableTimer (st->wtimer, &st->alarm_timeout, 0, NULL, NULL, FALSE) + == 0) { fprintf (stderr, "error: SetWaitableTimer %u\n", GetLastError ()); - exit(1); + exit (1); } #else alarm (5); #endif - + } /* returns the elapsed time */ -double stop_benchmark(struct benchmark_st * st, const char* metric) +double +stop_benchmark (struct benchmark_st *st, const char *metric) { double secs; unsigned long lsecs; @@ -129,18 +132,18 @@ double stop_benchmark(struct benchmark_st * st, const char* metric) if (st->wthread != NULL) CloseHandle (st->wthread); #else - signal(SIGALRM, st->old_handler); + signal (SIGALRM, st->old_handler); #endif gettime (&stop); lsecs = (stop.tv_sec * 1000 + stop.tv_nsec / (1000 * 1000) - - (st->start.tv_sec * 1000 + st->start.tv_nsec / (1000 * 1000))); + (st->start.tv_sec * 1000 + st->start.tv_nsec / (1000 * 1000))); secs = lsecs; secs /= 1000; if (metric == NULL) - { /* assume bytes/sec */ + { /* assume bytes/sec */ value2human (st->size, secs, &ddata, &dspeed, imetric); printf (" Processed %.2f %s in %.2f secs: ", ddata, imetric, secs); printf ("%.2f %s/sec\n", dspeed, imetric); diff --git a/src/benchmark.h b/src/benchmark.h index e7d3386..3d5838a 100644 --- a/src/benchmark.h +++ b/src/benchmark.h @@ -21,11 +21,11 @@ #include <time.h> #include <signal.h> #if defined(_WIN32) -# include <windows.h> +#include <windows.h> #endif -#include "timespec.h" /* gnulib gettime */ +#include "timespec.h" /* gnulib gettime */ -typedef void (*sighandler_t)(int); +typedef void (*sighandler_t) (int); struct benchmark_st { @@ -41,12 +41,12 @@ struct benchmark_st extern int benchmark_must_finish; -void start_benchmark(struct benchmark_st * st); -double stop_benchmark(struct benchmark_st * st, const char* metric); +void start_benchmark (struct benchmark_st *st); +double stop_benchmark (struct benchmark_st *st, const char *metric); inline static unsigned int timespec_sub_ms (struct timespec *a, struct timespec *b) { return (a->tv_sec * 1000 + a->tv_nsec / (1000 * 1000) - - (b->tv_sec * 1000 + b->tv_nsec / (1000 * 1000))); + (b->tv_sec * 1000 + b->tv_nsec / (1000 * 1000))); } |