68 .
synopsis =
"Example of librnr checksum algorithms.",
71 "The %P command runs serveral checksum algorithms over a fixed body of " 72 "text and prints the results to stdout." 84 .has_arg = no_argument,
90 .opt_desc =
"Do [not] print poem." 104 static int init(
int argc,
char *argv[])
107 Argv0 = basename(argv[0]);
119 "Jabberwocky -- Lewis Carroll\n" 121 "'Twas brillig, and the slithy toves\n" 122 "Did gyre and gimble in the wabe;\n" 123 "All mimsy were the borogoves,\n" 124 "And the mome raths outgrabe.\n" 126 "\"Beware the Jabberwock, my son!\n" 127 "The jaws that bite, the claws that catch!\n" 128 "Beware the Jubjub bird, and shun\n" 129 "The frumious Bandersnatch!\"\n" 131 "He took his vorpal sword in hand:\n" 132 "Long time the manxome foe he sought—\n" 133 "So rested he by the Tumtum tree,\n" 134 "And stood awhile in thought.\n" 136 "And as in uffish thought he stood,\n" 137 "The Jabberwock, with eyes of flame,\n" 138 "Came whiffling through the tulgey wood,\n" 139 "And burbled as it came!\n" 141 "One, two! One, two! and through and through\n" 142 "The vorpal blade went snicker-snack!\n" 143 "He left it dead, and with its head\n" 144 "He went galumphing back.\n" 146 "\"And hast thou slain the Jabberwock?\n" 147 "Come to my arms, my beamish boy!\n" 148 "O frabjous day! Callooh! Callay!\"\n" 149 "He chortled in his joy.\n" 151 "'Twas brillig, and the slithy toves\n" 152 "Did gyre and gimble in the wabe;\n" 153 "All mimsy were the borogoves,\n" 154 "And the mome raths outgrabe.\n";
163 clock_gettime(CLOCK_REALTIME, pstart);
175 struct timespec tstop;
178 clock_gettime(CLOCK_REALTIME, &tstop);
180 nsec = (tstop.tv_sec - pstart->tv_sec) * 1000000000;
182 if( tstop.tv_nsec >= pstart->tv_nsec )
184 nsec += (tstop.tv_nsec - pstart->tv_nsec);
188 nsec += (1000000000 - pstart->tv_nsec + tstop.tv_nsec);
205 printf(
"Algorithm Result nSecs\n");
210 printf(
" 8-bit chksum %10u 0x%08x %6ld\n", chksum, chksum, nsec);
215 printf(
"16-bit chksum %10u 0x%08x %6ld\n", chksum, chksum, nsec);
220 printf(
"32-bit chksum %10u 0x%08x %6ld\n", chksum, chksum, nsec);
225 printf(
"32-bit crc %10u 0x%08x %6ld\n", chksum, chksum, nsec);
237 int main(
int argc,
char *argv[])
244 if( !
init(argc, argv) )
257 printf(
"Text: Jabberwocky -- Lewis Carroll\n");
258 printf(
"Length: %zu bytes\n", strlen(
Jabberwocky));
273 printf(
"Text: Jabberwocky, 1 byte swapped -- Lewis Carroll\n");
274 printf(
"Length: %zu bytes\n", strlen(sText));
287 sText =
new(strlen(
Jabberwocky) * (size_t)k + (
size_t)1);
289 for(i=0, *sText=0; i<k; ++i)
294 printf(
"Text: Jabberwocky * %d -- Lewis Carroll\n", k);
295 printf(
"Length: %zu bytes\n", strlen(sText));
static void starttimer(struct timespec *pstart)
Start nano second timer.
int OptsCvtArgBool(const char *argv0, const char *sOptName, char *optarg, void *pOptVal)
Convert options boolean argument to bool_t.
u32_t generate_checksum32(byte_t buf[], size_t len)
Computes the modular 32-bit checksum over buffer.
char * new_strdup(const char *s)
Duplicate a string.
Standard command-line options options and parsing.
Program Description Strings Info Structure.
u32_t generate_crc32(byte_t buf[], size_t len)
Computes the 32-bit cyclic redundance check over buffer.
Memory allocation and deallocation declarations.
u32_t uint_t
32-bit unsigned integer
static char * Argv0
the command
u16_t generate_checksum16(byte_t buf[], size_t len)
Computes the modular 16-bit checksum over buffer.
const char * synopsis
Simple program synopsis string.
static OptsPgmInfo_T PgmInfo
Program information.
static const PkgInfo_T PkgInfo
#define OPTS_NO_SHORT
no short option equivalent
static OptsInfo_T OptsInfo[]
Command line options information.
RoadNarrows Robotics common configuration file.
char ** OptsGet(const char *argv0, const PkgInfo_T *pPkgInfo, OptsPgmInfo_T *pPgmInfo, OptsInfo_T *pOptsInfo, bool_t bHasLogging, int *pargc, char *argv[])
Gets, validates, and sets all command line options.
Package version information.
static int init(int argc, char *argv[])
Main initialization.
int main(int argc, char *argv[])
Example main.
u8_t generate_checksum8(byte_t buf[], size_t len)
Computes the modular 8-bit checksum over buffer.
char * OptsFmtBool(char *buf, size_t buflen, void *pOptVal)
Boolean option value string formatter.
static bool_t OptsPrintPoem
do [not] print poem
static long stoptimer(struct timespec *pstart)
Stop nano second timer.
const char * long_opt
Long option string name.
Short and Long Options Info.
static char * Jabberwocky
Jabberwocky by Lewis Carroll.
static void profile(char *sText)
Profile the various checksum algorithms.