Mercurial > libpst
comparison src/pst2dii.cpp.in @ 73:3cb02cb1e6cd stable-0-6-10
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
More changes for Fedora packaging (#434727)
Fixes for const correctness.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 29 May 2008 18:51:02 -0700 |
parents | 63c02a242ca9 |
children | 56fa05fd5271 |
comparison
equal
deleted
inserted
replaced
72:c21e9c001256 | 73:3cb02cb1e6cd |
---|---|
38 type = 0; | 38 type = 0; |
39 }; | 39 }; |
40 }; | 40 }; |
41 | 41 |
42 // global settings | 42 // global settings |
43 char* convert = "@CONVERT@"; // fully qualified path of the convert program from image magick | 43 const char* convert = "@CONVERT@"; // fully qualified path of the convert program from image magick |
44 char* prog_name = NULL; // our arg0 name | 44 const char* prog_name = NULL; // our arg0 name |
45 char* bates_prefix = ""; // string to prefix bates numbers | 45 const char* bates_prefix = ""; // string to prefix bates numbers |
46 int bates_index = 0; // current bates sequence | 46 int bates_index = 0; // current bates sequence |
47 char* output_directory = "."; | 47 const char* output_directory = "."; |
48 char* output_file = "load.dii"; | 48 const char* output_file = "load.dii"; |
49 char* font_file = NULL; | 49 char* font_file = NULL; |
50 int bates_color = 0xff0000; // color of bates header stamp | 50 int bates_color = 0xff0000; // color of bates header stamp |
51 int email_sequence = 0; // current pdf sequence number | 51 int email_sequence = 0; // current pdf sequence number |
52 char pdf_name[PATH_MAX]; // current pdf file name | 52 char pdf_name[PATH_MAX]; // current pdf file name |
53 FILE* dii_file = NULL; // the output dii load file | 53 FILE* dii_file = NULL; // the output dii load file |
162 DEBUG_RET(); | 162 DEBUG_RET(); |
163 return; | 163 return; |
164 } | 164 } |
165 char *tt = t; | 165 char *tt = t; |
166 bool fixed = false; | 166 bool fixed = false; |
167 while (t = strpbrk(t, " /\\:")) { | 167 while ((t = strpbrk(t, " /\\:"))) { |
168 // while there are characters in the second string that we don't want | 168 // while there are characters in the second string that we don't want |
169 *t = '_'; //replace them with an underscore | 169 *t = '_'; //replace them with an underscore |
170 fixed = true; | 170 fixed = true; |
171 } | 171 } |
172 if (fixed) fname = string(tt); | 172 if (fixed) fname = string(tt); |
212 DEBUG_EMAIL(("Saving attachment to %s\n", temp)); | 212 DEBUG_EMAIL(("Saving attachment to %s\n", temp)); |
213 if (!(fp = fopen(temp, "wb"))) { | 213 if (!(fp = fopen(temp, "wb"))) { |
214 WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp)); | 214 WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp)); |
215 } else { | 215 } else { |
216 if (current_attach->data) | 216 if (current_attach->data) |
217 fwrite(current_attach->data, 1, current_attach->size, fp); | 217 pst_fwrite(current_attach->data, 1, current_attach->size, fp); |
218 else { | 218 else { |
219 (void)pst_attach_to_file(pst, current_attach, fp); | 219 (void)pst_attach_to_file(pst, current_attach, fp); |
220 } | 220 } |
221 fclose(fp); | 221 fclose(fp); |
222 } | 222 } |
225 DEBUG_RET(); | 225 DEBUG_RET(); |
226 return rc; | 226 return rc; |
227 } | 227 } |
228 | 228 |
229 | 229 |
230 static void print_pdf_short(char *line, int len, int color); | 230 static void print_pdf_short(const char *line, int len, int color); |
231 static void print_pdf_short(char *line, int len, int color) | 231 static void print_pdf_short(const char *line, int len, int color) |
232 { | 232 { |
233 if (line_number >= line_max) { | 233 if (line_number >= line_max) { |
234 close_png(); | 234 close_png(); |
235 open_png(); | 235 open_png(); |
236 } | 236 } |
239 strex.flags = gdFTEX_RESOLUTION; | 239 strex.flags = gdFTEX_RESOLUTION; |
240 strex.linespacing = 1.20; | 240 strex.linespacing = 1.20; |
241 strex.charmap = 0; | 241 strex.charmap = 0; |
242 strex.hdpi = DPI; | 242 strex.hdpi = DPI; |
243 strex.vdpi = DPI; | 243 strex.vdpi = DPI; |
244 char x = line[len]; | 244 char xline[len+1]; |
245 line[len] = '\0'; | 245 memcpy(xline, line, len); |
246 xline[len] = '\0'; | |
246 char *p; | 247 char *p; |
247 char *l = line; | 248 char *l = xline; |
248 while (p = strchr(l, '&')) { | 249 while ((p = strchr(l, '&'))) { |
249 *p = '\0'; | 250 *p = '\0'; |
250 char *err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, l, &strex); | 251 char *err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, l, &strex); |
251 if (err) printf(err); | 252 if (err) printf(err); |
252 x_position += (brect[2]-brect[6]); | 253 x_position += (brect[2]-brect[6]); |
253 l = p+1; | 254 l = p+1; |
254 err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, "&", &strex); | 255 err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, (char*)"&", &strex); |
255 if (err) printf(err); | 256 if (err) printf(err); |
256 x_position += (brect[2]-brect[6]); | 257 x_position += (brect[2]-brect[6]); |
257 } | 258 } |
258 char *err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, l, &strex); | 259 char *err = gdImageStringFTEx(image, &brect[0], color, font_file, sz, 0.0, x_position, y_position, l, &strex); |
259 if (err) printf(err); | 260 if (err) printf(err); |
260 line[len] = x; | |
261 x_position += (brect[2]-brect[6]); | 261 x_position += (brect[2]-brect[6]); |
262 col_number += len; | 262 col_number += len; |
263 } | 263 } |
264 | 264 |
265 | 265 |
271 x_position = margin; | 271 x_position = margin; |
272 col_number = 0; | 272 col_number = 0; |
273 } | 273 } |
274 | 274 |
275 | 275 |
276 static void print_pdf_single(char *line, int color); | 276 static void print_pdf_single(const char *line, int color); |
277 static void print_pdf_single(char *line, int color) | 277 static void print_pdf_single(const char *line, int color) |
278 { | 278 { |
279 while (*line == '\t') { | 279 while (*line == '\t') { |
280 char blanks[5]; | 280 char blanks[5]; |
281 memset(blanks, ' ', 5); | 281 memset(blanks, ' ', 5); |
282 print_pdf_short(blanks, 4, color); | 282 print_pdf_short(blanks, 4, color); |
293 if (n) new_line(); | 293 if (n) new_line(); |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 | 297 |
298 static void print_pdf_only(char *line, int color); | 298 static void print_pdf_only(const char *line, int color); |
299 static void print_pdf_only(char *line, int color) | 299 static void print_pdf_only(const char *line, int color) |
300 { | 300 { |
301 char *p; | 301 char *p; |
302 while (p = strchr(line, '\n')) { | 302 while ((p = strchr(line, '\n'))) { |
303 *p = '\0'; | 303 *p = '\0'; |
304 print_pdf_single(line, color); | 304 print_pdf_single(line, color); |
305 *p = '\n'; | 305 *p = '\n'; |
306 line = p+1; | 306 line = p+1; |
307 new_line(); | 307 new_line(); |
308 } | 308 } |
309 print_pdf_single(line, color); | 309 print_pdf_single(line, color); |
310 } | 310 } |
311 | 311 |
312 | 312 |
313 static void print_pdf(char *line); | 313 static void print_pdf(const char *line); |
314 static void print_pdf(char *line) | 314 static void print_pdf(const char *line) |
315 { | 315 { |
316 fwrite(line, 1, strlen(line), dii_file); | 316 pst_fwrite(line, 1, strlen(line), dii_file); |
317 print_pdf_only(line, black); | 317 print_pdf_only(line, black); |
318 } | 318 } |
319 | 319 |
320 | 320 |
321 static void open_png() | 321 static void open_png() |
322 { | 322 { |
323 if (!png_open) { | 323 if (!png_open) { |
324 png_open = true; | 324 png_open = true; |
325 int brect[8]; | 325 int brect[8]; |
326 image = gdImageCreate(PAGE_WIDTH, PAGE_HEIGHT); | 326 image = gdImageCreate(PAGE_WIDTH, PAGE_HEIGHT); |
327 int w = gdImageColorAllocate(image, 255, 255, 255); // background color first one allocated | 327 gdImageColorAllocate(image, 255, 255, 255); // background color first one allocated |
328 black = gdImageColorAllocate(image, 0, 0, 0); | 328 black = gdImageColorAllocate(image, 0, 0, 0); |
329 int r = (bates_color & 0xff0000) >> 16; | 329 int r = (bates_color & 0xff0000) >> 16; |
330 int g = (bates_color & 0x00ff00) >> 8; | 330 int g = (bates_color & 0x00ff00) >> 8; |
331 int b = (bates_color & 0x0000ff); | 331 int b = (bates_color & 0x0000ff); |
332 red = gdImageColorAllocate(image, r, g, b); | 332 red = gdImageColorAllocate(image, r, g, b); |
337 strex.charmap = 0; | 337 strex.charmap = 0; |
338 strex.hdpi = DPI; | 338 strex.hdpi = DPI; |
339 strex.vdpi = DPI; | 339 strex.vdpi = DPI; |
340 | 340 |
341 char line[LINE_SIZE]; | 341 char line[LINE_SIZE]; |
342 char *err = gdImageStringFTEx(NULL, &brect[0], black, font_file, sz, 0.0, margin, margin, "LMgqQ", &strex); | 342 char *err = gdImageStringFTEx(NULL, &brect[0], black, font_file, sz, 0.0, margin, margin, (char*)"LMgqQ", &strex); |
343 if (err) printf(err); | 343 if (err) printf(err); |
344 line_height = (brect[3]-brect[7]) * 12/10; | 344 line_height = (brect[3]-brect[7]) * 12/10; |
345 char_width = (brect[2]-brect[6]) / 5; | 345 char_width = (brect[2]-brect[6]) / 5; |
346 col_number = 0; | 346 col_number = 0; |
347 col_max = (PAGE_WIDTH - margin*2) / char_width; | 347 col_max = (PAGE_WIDTH - margin*2) / char_width; |
399 } | 399 } |
400 fprintf(dii_file, "@D %s\n", pdf_name); | 400 fprintf(dii_file, "@D %s\n", pdf_name); |
401 } | 401 } |
402 | 402 |
403 | 403 |
404 static void write_simple(char *tag, const char *value); | 404 static void write_simple(const char *tag, const char *value); |
405 static void write_simple(char *tag, const char *value) | 405 static void write_simple(const char *tag, const char *value) |
406 { | 406 { |
407 if (value) fprintf(dii_file, "@%s %s\n", tag, value); | 407 if (value) fprintf(dii_file, "@%s %s\n", tag, value); |
408 } | 408 } |
409 | 409 |
410 | 410 |
411 static void write_simple(char *tag, string value); | 411 static void write_simple(const char *tag, string value); |
412 static void write_simple(char *tag, string value) | 412 static void write_simple(const char *tag, string value) |
413 { | 413 { |
414 fprintf(dii_file, "@%s %s\n", tag, value.c_str()); | 414 fprintf(dii_file, "@%s %s\n", tag, value.c_str()); |
415 } | 415 } |
416 | 416 |
417 | 417 |
418 static void write_simple(char *tag, const char *value, const char *value2); | 418 static void write_simple(const char *tag, const char *value, const char *value2); |
419 static void write_simple(char *tag, const char *value, const char *value2) | 419 static void write_simple(const char *tag, const char *value, const char *value2) |
420 { | 420 { |
421 if (value) { | 421 if (value) { |
422 if (value2) fprintf(dii_file, "@%s \"%s\" <%s>\n", tag, value, value2); | 422 if (value2) fprintf(dii_file, "@%s \"%s\" <%s>\n", tag, value, value2); |
423 else fprintf(dii_file, "@%s \"%s\"\n", tag, value); | 423 else fprintf(dii_file, "@%s \"%s\"\n", tag, value); |
424 } | 424 } |
425 } | 425 } |
426 | 426 |
427 | 427 |
428 static string extract_header(char *headers, char *field); | 428 static string extract_header(char *headers, const char *field); |
429 static string extract_header(char *headers, char *field) | 429 static string extract_header(char *headers, const char *field) |
430 { | 430 { |
431 string rc; | 431 string rc; |
432 int len = strlen(field) + 4; | 432 int len = strlen(field) + 4; |
433 char f[len]; | 433 char f[len]; |
434 snprintf(f, len, "\n%s: ", field); | 434 snprintf(f, len, "\n%s: ", field); |
528 print_pdf(line); | 528 print_pdf(line); |
529 } | 529 } |
530 | 530 |
531 } else { | 531 } else { |
532 //make up our own headers | 532 //make up our own headers |
533 char *temp = item->email->outlook_sender; | 533 const char *temp = item->email->outlook_sender; |
534 if (!temp) temp = ""; | 534 if (!temp) temp = ""; |
535 snprintf(line, sizeof(line), "From: \"%s\" <%s>\n", item->email->outlook_sender_name, temp); | 535 snprintf(line, sizeof(line), "From: \"%s\" <%s>\n", item->email->outlook_sender_name, temp); |
536 print_pdf(line); | 536 print_pdf(line); |
537 | 537 |
538 if (item->email->subject) { | 538 if (item->email->subject) { |