[libpst-commits] r73 - trunk
Chris Halls
halls at alioth.debian.org
Fri Jan 5 17:16:45 CET 2007
Author: halls
Date: 2007-01-05 17:16:44 +0100 (Fri, 05 Jan 2007)
New Revision: 73
Modified:
trunk/ChangeLog
trunk/lspst.c
Log:
lspst: Add usage mesage and option parsing using getopt (SourceForge #304199)
Index: trunk/lspst.c
===================================================================
--- trunk/lspst.c (revision 72)
+++ trunk/lspst.c (revision 73)
@@ -13,6 +13,7 @@
#include <string.h>
#include <ctype.h>
#include <errno.h>
+#include <unistd.h>
#include "libpst.h"
#include "define.h"
@@ -36,6 +37,8 @@
void debug_print(char *fmt, ...);
char *rfc2426_escape(char *str);
char *rfc2445_datetime_format(FILETIME *ft);
+int usage(char *prog_name);
+int version();
// }}}1
#define LSPST_DEBUG_MAIN(x) debug_print x;
// int main(int argc, char** argv) {{{1
@@ -48,13 +51,47 @@
char *temp = NULL; //temporary char pointer
int skip_child = 0;
struct file_ll *f = NULL, *head = NULL;
+ int c;
+ char *d_log = NULL;
// }}}2
- if (argc <= 1)
- DIE(("Missing PST filename.\n"));
+ while ((c = getopt(argc, argv, "d:hV"))!= -1) {
+ switch (c) {
+ case 'd':
+ d_log = optarg;
+ break;
+ case 'h':
+ usage(argv[0]);
+ exit(0);
+ break;
+ case 'V':
+ version();
+ exit(0);
+ break;
+ default:
+ usage(argv[0]);
+ exit(1);
+ break;
+ }
+ }
+
+#ifdef DEBUG_ALL
+ // initialize log file
+ if (d_log != NULL) {
+ DEBUG_INIT(d_log);
+ DEBUG_REGISTER_CLOSE();
+ }
+#endif // defined DEBUG_ALL
+ DEBUG_ENT("main");
+
+ if (argc <= optind) {
+ usage(argv[0]);
+ exit(2);
+ }
+
// Open PST file
- if ( pst_open(&pstfile, argv[1], "r") )
+ if ( pst_open(&pstfile, argv[optind], "r") )
DIE(("Error opening File\n"));
// Load PST index
if ( pst_load_index(&pstfile) )
@@ -425,5 +462,37 @@
}
// }}}1
+// int usage() {{{1
+int usage(char *prog_name) {
+ DEBUG_ENT("usage");
+ version();
+ printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
+ printf("OPTIONS:\n");
+ printf("\t-d\t- Debug to file. This is a binary log. Use readlog to print it\n");
+ printf("\t-h\t- Help. This screen\n");
+ printf("\t-V\t- Version. Display program version\n");
+ DEBUG_RET();
+ return 0;
+}
+// }}}1
+// int version() {{{1
+int version() {
+ DEBUG_ENT("version");
+ printf("lspst / LibPST v%s\n", PST_VERSION);
+#if BYTE_ORDER == BIG_ENDIAN
+ printf("Big Endian implementation being used.\n");
+#elif BYTE_ORDER == LITTLE_ENDIAN
+ printf("Little Endian implementation being used.\n");
+#else
+# error "Byte order not supported by this library"
+#endif
+#ifdef __GNUC__
+ printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__);
+#endif
+ DEBUG_RET();
+ return 0;
+}
+// }}}1
+
// vim:sw=4 ts=4:
// vim600: set foldlevel=0 foldmethod=marker:
Index: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog (revision 72)
+++ trunk/ChangeLog (revision 73)
@@ -2,6 +2,8 @@
===============================
* Map IPM.Task items to PST_TYPE_TASK.
+ * lspst: Add usage mesage and option parsing using getopt
+ (SourceForge #304199)
--
More information about the libpst-commits
mailing list