44 "\nusage: prepend_md5\n\n"
46 " This program reads the first field (delimited by '\\t') of each line\n"
47 " computes the MD5 checksum of the field and then outputs the line with\n"
48 " the checksum prepended to the line\n"
52 struct AppPolicy :
Policy {
53 static void init_options() {
55 (
"md5-chars",
i32()->default_value(4),
"Name of checksum characters to output")
62 typedef Meta::list<AppPolicy, DefaultCommPolicy>
Policies;
69 int main(
int argc,
char **argv) {
73 char *line_buffer =
new char [ 1024 * 1024 ];
75 ios::sync_with_stdio(
false);
78 init_with_policies<Policies>(argc, argv);
87 int32_t checksum_chars = get_i32(
"md5-chars");
88 if (checksum_chars < 1 || checksum_chars > 32) {
89 cerr <<
"Invalid value for md5-chars, must be from 1 to 32" << endl;
95 cin.getline(line_buffer, 1024*1024);
97 if (*line_buffer == 0)
100 ptr = strchr(line_buffer,
'\t');
105 hexdigits[checksum_chars] = 0;
110 cout << hexdigits <<
" " << line_buffer <<
"\n";
114 catch (std::exception &e) {
115 cerr <<
"Error - " << e.what() << endl;
Declarations for configuration properties.
Interface and base of config policy.
static const CpuInfo & cpu_info()
Retrieves updated CPU information (see SystemInfo.h)
void init(int argc, char *argv[], const Desc *desc=NULL)
Initialize with default policy.
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
A dynamic, resizable memory buffer.
Po::typed_value< int32_t > * i32(int32_t *v=0)
Logging routines and macros.
static const OsInfo & os_info()
Retrieves updated Operating system information (see SystemInfo.h)
Compatibility Macros for C/C++.
Initialization helper for applications.
void md5_string(const char *input, char output[33])
Calculates the hex string of MD5 of null terminated input.
static const FsStat & fs_stat()
Retrieves updated Filesystem statistics (see SystemInfo.h)
int main(int argc, char **argv)
Meta::list< MyPolicy, DefaultPolicy > Policies
System information and statistics based on libsigar.
static const MemStat & mem_stat()
Retrieves updated Memory statistics (see SystemInfo.h)
static const NetInfo & net_info()
Retrieves updated Network information (see SystemInfo.h)