#include <string.h>#include <unistd.h>#include <signal.h>#include "gwlib/gwlib.h"Include dependency graph for test_octstr_dump.c:

Go to the source code of this file.
Functions | |
| int | main (int argc, char **argv) |
|
||||||||||||
|
Definition at line 69 of file test_octstr_dump.c. References data, debug(), filename, get_and_set_debugs(), gwlib_init(), gwlib_shutdown(), octstr_create, octstr_destroy(), octstr_dump, octstr_duplicate, octstr_get_cstr, octstr_hex_to_binary(), octstr_is_all_hex(), octstr_print(), octstr_read_file(), and octstr_strip_crlfs(). 00070 {
00071 Octstr *data, *filename, *hex;
00072
00073 gwlib_init();
00074
00075 get_and_set_debugs(argc, argv, NULL);
00076
00077 filename = octstr_create(argv[1]);
00078 data = octstr_read_file(octstr_get_cstr(filename));
00079
00080 /*
00081 * We test if this is a text/plain file with hex values in it.
00082 * Therefore copy the data and trail off any CR and LF from
00083 * beginning and end and test if the result is only hex chars.
00084 * If yes, then convert to binary before dumping.
00085 */
00086 hex = octstr_duplicate(data);
00087 octstr_strip_crlfs(hex);
00088 if (octstr_is_all_hex(hex)) {
00089 debug("",0,"Trying to converting from hex to binary.");
00090 if (octstr_hex_to_binary(hex) == 0) {
00091 FILE *f = fopen(argv[2], "w");
00092 debug("",0,"Convertion was successfull. Writing binary content to file `%s'",
00093 argv[2]);
00094 octstr_destroy(data);
00095 data = octstr_duplicate(hex);
00096 octstr_print(f, data);
00097 fclose(f);
00098 } else {
00099 debug("",0,"Failed to convert from hex?!");
00100 }
00101 }
00102
00103 debug("",0,"Dumping file `%s':", octstr_get_cstr(filename));
00104 octstr_dump(data, 0);
00105
00106 octstr_destroy(data);
00107 octstr_destroy(hex);
00108 gwlib_shutdown();
00109 return 0;
00110 }
|
Here is the call graph for this function:
