Mercurial > libpst
comparison src/pst2dii.cpp.in @ 325:cb67b335afcc
patches from debian
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 18 Jan 2013 08:05:08 -0800 |
parents | db6db9a26a19 |
children |
comparison
equal
deleted
inserted
replaced
324:6b1399ab2d46 | 325:cb67b335afcc |
---|---|
40 const char* output_directory = "."; | 40 const char* output_directory = "."; |
41 const char* output_file = "load.dii"; | 41 const char* output_file = "load.dii"; |
42 char* font_file = NULL; | 42 char* font_file = NULL; |
43 int bates_color = 0xff0000; // color of bates header stamp | 43 int bates_color = 0xff0000; // color of bates header stamp |
44 int email_sequence = 0; // current pdf sequence number | 44 int email_sequence = 0; // current pdf sequence number |
45 char pdf_name[PATH_MAX]; // current pdf file name | 45 char* pdf_name = NULL; // current pdf file name |
46 FILE* dii_file = NULL; // the output dii load file | 46 FILE* dii_file = NULL; // the output dii load file |
47 pst_file pstfile; // the input pst file | 47 pst_file pstfile; // the input pst file |
48 | 48 |
49 // pdf writer globals | 49 // pdf writer globals |
50 bool pdf_open = false; // is pdf writer started | 50 bool pdf_open = false; // is pdf writer started |
342 | 342 |
343 static void close_png() | 343 static void close_png() |
344 { | 344 { |
345 if (png_open) { | 345 if (png_open) { |
346 png_open = false; | 346 png_open = false; |
347 char fn[PATH_MAX]; | 347 int len = 4 + 11 + 4 +1; |
348 snprintf(fn, sizeof(fn), "page%d.png", ++page_sequence); | 348 char *fn = (char*)pst_malloc(len); |
349 snprintf(fn, len, "page%d.png", ++page_sequence); | |
349 FILE *pngout = fopen(fn, "wb"); | 350 FILE *pngout = fopen(fn, "wb"); |
350 if (pngout) { | 351 if (pngout) { |
351 gdImagePng(image, pngout); | 352 gdImagePng(image, pngout); |
352 fclose(pngout); | 353 fclose(pngout); |
353 } | 354 } |
354 gdImageDestroy(image); // free memory | 355 gdImageDestroy(image); // free memory |
355 png_names.push_back(fn); | 356 png_names.push_back(fn); |
356 conversion += string(" ") + fn; | 357 conversion += string(" ") + fn; |
358 free(fn); | |
357 } | 359 } |
358 } | 360 } |
359 | 361 |
360 | 362 |
361 static void open_pdf(char *line); | 363 static void open_pdf(char *line); |
364 pst_folder = line; | 366 pst_folder = line; |
365 page_sequence = 0; | 367 page_sequence = 0; |
366 conversion = string(convert); | 368 conversion = string(convert); |
367 png_names.clear(); | 369 png_names.clear(); |
368 open_png(); | 370 open_png(); |
369 snprintf(pdf_name, sizeof(pdf_name), "dii%06d", ++email_sequence); | 371 /* Note; allocating the largest string length to pdf_name */ |
372 int len = strlen(output_directory) + 4 + 6 + 4 + 1; | |
373 pdf_name = (char*)pst_malloc(len); | |
374 snprintf(pdf_name, 3 + 6 + 1, "dii%06d", ++email_sequence); | |
370 fprintf(dii_file, "\n@T %s\n", pdf_name); | 375 fprintf(dii_file, "\n@T %s\n", pdf_name); |
371 snprintf(pdf_name, sizeof(pdf_name), "%s/dii%06d.pdf", output_directory, email_sequence); | 376 snprintf(pdf_name, len, "%s/dii%06d.pdf", output_directory, email_sequence); |
372 } | 377 } |
373 | 378 |
374 | 379 |
375 static void close_pdf(); | 380 static void close_pdf(); |
376 static void close_pdf() | 381 static void close_pdf() |
380 (void)system(conversion.c_str()); | 385 (void)system(conversion.c_str()); |
381 for (vector<string>::iterator i=png_names.begin(); i!=png_names.end(); i++) { | 386 for (vector<string>::iterator i=png_names.begin(); i!=png_names.end(); i++) { |
382 remove((*i).c_str()); | 387 remove((*i).c_str()); |
383 } | 388 } |
384 fprintf(dii_file, "@D %s\n", pdf_name); | 389 fprintf(dii_file, "@D %s\n", pdf_name); |
390 free(pdf_name); | |
385 } | 391 } |
386 | 392 |
387 | 393 |
388 static void write_simple(const char *tag, const char *value); | 394 static void write_simple(const char *tag, const char *value); |
389 static void write_simple(const char *tag, const char *value) | 395 static void write_simple(const char *tag, const char *value) |