Mercurial > libpst
comparison src/lspst.c @ 50:fb3818370dd6 stable-0-6-4
more fixes for 64 bit format
author | carl |
---|---|
date | Sat, 19 Jan 2008 16:30:16 -0800 |
parents | f66078abed38 |
children | 034641c26ab9 |
comparison
equal
deleted
inserted
replaced
49:17654fbdf76b | 50:fb3818370dd6 |
---|---|
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 #include <time.h> | 13 #include <time.h> |
14 #include <string.h> | 14 #include <string.h> |
15 #include <ctype.h> | 15 #include <ctype.h> |
16 #include <errno.h> | 16 #include <errno.h> |
17 #include <unistd.h> | |
17 | 18 |
18 #include "libpst.h" | 19 #include "libpst.h" |
19 #include "timeconv.h" | 20 #include "timeconv.h" |
20 | 21 |
21 struct file_ll { | 22 struct file_ll { |
27 }; | 28 }; |
28 | 29 |
29 | 30 |
30 void canonicalize_filename(char *fname); | 31 void canonicalize_filename(char *fname); |
31 void debug_print(char *fmt, ...); | 32 void debug_print(char *fmt, ...); |
33 int usage(char *prog_name); | |
34 int version(); | |
32 | 35 |
33 // global settings | 36 // global settings |
34 pst_file pstfile; | 37 pst_file pstfile; |
35 | 38 |
36 | 39 |
86 // Process Contact item | 89 // Process Contact item |
87 if (ff.type != PST_TYPE_CONTACT) { | 90 if (ff.type != PST_TYPE_CONTACT) { |
88 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. Processing anyway\n")); | 91 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. Processing anyway\n")); |
89 } | 92 } |
90 printf("Contact"); | 93 printf("Contact"); |
91 if (item->contact->fullname != NULL) | 94 if (item->contact->fullname) |
92 printf("\t%s", pst_rfc2426_escape(item->contact->fullname)); | 95 printf("\t%s", pst_rfc2426_escape(item->contact->fullname)); |
93 printf("\n"); | 96 printf("\n"); |
94 | 97 |
95 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) { | 98 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) { |
96 // Process Email item | 99 // Process Email item |
97 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_REPORT)) { | 100 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_REPORT)) { |
98 DEBUG_MAIN(("main: I have an email, but the folder isn't an email folder. Processing anyway\n")); | 101 DEBUG_MAIN(("main: I have an email, but the folder isn't an email folder. Processing anyway\n")); |
99 } | 102 } |
100 printf("Email"); | 103 printf("Email"); |
101 if (item->email->outlook_sender_name != NULL) | 104 if (item->email->outlook_sender_name) |
102 printf("\tFrom: %s", item->email->outlook_sender_name); | 105 printf("\tFrom: %s", item->email->outlook_sender_name); |
103 if (item->email->subject->subj != NULL) | 106 if (item->email->subject && item->email->subject->subj) |
104 printf("\tSubject: %s", item->email->subject->subj); | 107 printf("\tSubject: %s", item->email->subject->subj); |
105 printf("\n"); | 108 printf("\n"); |
106 | 109 |
107 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) { | 110 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) { |
108 // Process Journal item | 111 // Process Journal item |
109 if (ff.type != PST_TYPE_JOURNAL) { | 112 if (ff.type != PST_TYPE_JOURNAL) { |
110 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n")); | 113 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n")); |
111 } | 114 } |
112 printf("Journal\t%s\n", pst_rfc2426_escape(item->email->subject->subj)); | 115 if (item->email && item->email->subject && item->email->subject->subj) |
116 printf("Journal\t%s\n", pst_rfc2426_escape(item->email->subject->subj)); | |
113 | 117 |
114 } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) { | 118 } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) { |
115 // Process Calendar Appointment item | 119 // Process Calendar Appointment item |
116 DEBUG_MAIN(("main: Processing Appointment Entry\n")); | 120 DEBUG_MAIN(("main: Processing Appointment Entry\n")); |
117 if (ff.type != PST_TYPE_APPOINTMENT) { | 121 if (ff.type != PST_TYPE_APPOINTMENT) { |
118 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n")); | 122 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n")); |
119 } | 123 } |
120 printf("Appointment"); | 124 printf("Appointment"); |
121 if (item->email != NULL && item->email->subject != NULL) | 125 if (item->email && item->email->subject) |
122 printf("\tSUMMARY: %s", pst_rfc2426_escape(item->email->subject->subj)); | 126 printf("\tSUMMARY: %s", pst_rfc2426_escape(item->email->subject->subj)); |
123 if (item->appointment != NULL) { | 127 if (item->appointment->start) |
124 if (item->appointment->start != NULL) | 128 printf("\tSTART: %s", pst_rfc2445_datetime_format(item->appointment->start)); |
125 printf("\tSTART: %s", pst_rfc2445_datetime_format(item->appointment->start)); | 129 if (item->appointment->end) |
126 if (item->appointment->end != NULL) | 130 printf("\tEND: %s", pst_rfc2445_datetime_format(item->appointment->end)); |
127 printf("\tEND: %s", pst_rfc2445_datetime_format(item->appointment->end)); | 131 printf("\tALL DAY: %s", (item->appointment->all_day==1 ? "Yes" : "No")); |
128 printf("\tALL DAY: %s", (item->appointment->all_day==1 ? "Yes" : "No")); | |
129 } | |
130 printf("\n"); | 132 printf("\n"); |
131 | 133 |
132 } else { | 134 } else { |
133 ff.skip_count++; | 135 ff.skip_count++; |
134 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n", | 136 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n", |
144 } | 146 } |
145 close_enter_dir(&ff); | 147 close_enter_dir(&ff); |
146 } | 148 } |
147 | 149 |
148 | 150 |
151 int usage(char *prog_name) { | |
152 DEBUG_ENT("usage"); | |
153 version(); | |
154 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name); | |
155 printf("OPTIONS:\n"); | |
156 printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readlog to print it\n"); | |
157 printf("\t-h\t- Help. This screen\n"); | |
158 printf("\t-V\t- Version. Display program version\n"); | |
159 DEBUG_RET(); | |
160 return 0; | |
161 } | |
162 | |
163 | |
164 int version() { | |
165 DEBUG_ENT("version"); | |
166 printf("lspst / LibPST v%s\n", VERSION); | |
167 #if BYTE_ORDER == BIG_ENDIAN | |
168 printf("Big Endian implementation being used.\n"); | |
169 #elif BYTE_ORDER == LITTLE_ENDIAN | |
170 printf("Little Endian implementation being used.\n"); | |
171 #else | |
172 # error "Byte order not supported by this library" | |
173 #endif | |
174 #ifdef __GNUC__ | |
175 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__); | |
176 #endif | |
177 DEBUG_RET(); | |
178 return 0; | |
179 } | |
180 | |
181 | |
149 int main(int argc, char** argv) { | 182 int main(int argc, char** argv) { |
150 pst_item *item = NULL; | 183 pst_item *item = NULL; |
151 pst_desc_ll *d_ptr; | 184 pst_desc_ll *d_ptr; |
152 char *temp = NULL; //temporary char pointer | 185 char *temp = NULL; //temporary char pointer |
186 int c; | |
153 char *d_log = NULL; | 187 char *d_log = NULL; |
154 | 188 |
155 if (argc <= 1) DIE(("Missing PST filename.\n")); | 189 while ((c = getopt(argc, argv, "d:hV"))!= -1) { |
190 switch (c) { | |
191 case 'd': | |
192 d_log = optarg; | |
193 break; | |
194 case 'h': | |
195 usage(argv[0]); | |
196 exit(0); | |
197 break; | |
198 case 'V': | |
199 version(); | |
200 exit(0); | |
201 break; | |
202 default: | |
203 usage(argv[0]); | |
204 exit(1); | |
205 break; | |
206 } | |
207 } | |
156 | 208 |
157 #ifdef DEBUG_ALL | 209 #ifdef DEBUG_ALL |
158 // force a log file | 210 // force a log file |
159 if (!d_log) d_log = "lspst.log"; | 211 if (!d_log) d_log = "lspst.log"; |
160 #endif // defined DEBUG_ALL | 212 #endif // defined DEBUG_ALL |
161 DEBUG_INIT(d_log); | 213 DEBUG_INIT(d_log); |
162 DEBUG_REGISTER_CLOSE(); | 214 DEBUG_REGISTER_CLOSE(); |
163 DEBUG_ENT("main"); | 215 DEBUG_ENT("main"); |
164 | 216 |
217 if (argc <= optind) { | |
218 usage(argv[0]); | |
219 exit(2); | |
220 } | |
221 | |
165 // Open PST file | 222 // Open PST file |
166 if (pst_open(&pstfile, argv[1], "r")) DIE(("Error opening File\n")); | 223 if (pst_open(&pstfile, argv[optind], "r")) DIE(("Error opening File\n")); |
167 | 224 |
168 // Load PST index | 225 // Load PST index |
169 if (pst_load_index(&pstfile)) DIE(("Index Error\n")); | 226 if (pst_load_index(&pstfile)) DIE(("Index Error\n")); |
170 | 227 |
171 pst_load_extended_attributes(&pstfile); | 228 pst_load_extended_attributes(&pstfile); |
210 DEBUG_ENT("canonicalize_filename"); | 267 DEBUG_ENT("canonicalize_filename"); |
211 if (fname == NULL) { | 268 if (fname == NULL) { |
212 DEBUG_RET(); | 269 DEBUG_RET(); |
213 return; | 270 return; |
214 } | 271 } |
215 while ((fname = strpbrk(fname, "/\\:")) != NULL) | 272 while (fname = strpbrk(fname, "/\\:")) |
216 *fname = '_'; | 273 *fname = '_'; |
217 DEBUG_RET(); | 274 DEBUG_RET(); |
218 } | 275 } |
219 | 276 |
220 | 277 |