pstotext-1.9-quote-chars-fix.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. diff -urN pstotext-1.9.orig/main.c pstotext-1.9/main.c
  2. --- pstotext-1.9.orig/main.c 2004-01-09 11:17:38.000000000 +0100
  3. +++ pstotext-1.9/main.c 2006-05-19 11:43:52.000000000 +0200
  4. @@ -126,12 +126,14 @@
  5. static int cleanup(void) {
  6. int gsstatus, status = 0;
  7. pstotextExit(instance);
  8. - if (gs!=NULL) {
  9. #ifdef VMS
  10. + if (gs!=NULL) {
  11. gsstatus = fclose(gs);
  12. + }
  13. #else
  14. - gsstatus = pclose(gs);
  15. + waitpid(-1, &gsstatus, 0);
  16. #endif
  17. + if (gsstatus) {
  18. if (WIFEXITED(gsstatus)) {
  19. if (WEXITSTATUS(gsstatus)!=0) status = 3;
  20. else if (WIFSIGNALED(gsstatus)) status = 4;
  21. @@ -166,8 +168,13 @@
  22. static int do_it(char *path) {
  23. /* If "path" is NULL, then "stdin" should be processed. */
  24. - char *gs_cmdline;
  25. - char *input;
  26. + char *gs_argv[32];
  27. + int gs_argc=0;
  28. +#ifdef DEBUG
  29. + int i;
  30. +#endif
  31. + int fd[2];
  32. + pid_t p;
  33. int status;
  34. char norotate[] = "";
  35. FILE *fileout;
  36. @@ -201,47 +208,31 @@
  37. exit(1);
  38. }
  39. - if (path==NULL) {
  40. - input = (char*)malloc(2);
  41. - if (input == NULL) {
  42. - fprintf(stderr,"No memory available\n");
  43. - cleanup();
  44. - exit(1);
  45. - }
  46. - strcpy(input, "-");
  47. - } else {
  48. - input = (char*)malloc(strlen(path) + 6);
  49. - if (input == NULL) {
  50. - fprintf(stderr,"No memory available\n");
  51. - cleanup();
  52. - exit(1);
  53. - }
  54. - strcpy(input, "-- '"); strcat(input, path); strcat(input, "'");
  55. + gs_argv[gs_argc++] = "gs";
  56. + gs_argv[gs_argc++] = "-r72";
  57. + gs_argv[gs_argc++] = "-dNODISPLAY";
  58. + gs_argv[gs_argc++] = "-dFIXEDMEDIA";
  59. + gs_argv[gs_argc++] = "-dDELAYBIND";
  60. + gs_argv[gs_argc++] = "-dWRITESYSTEMDICT";
  61. + if (!debug) {
  62. + gs_argv[gs_argc++] = "-q";
  63. + }
  64. + gs_argv[gs_argc++] = "-dNOPAUSE";
  65. + gs_argv[gs_argc++] = "-dSAFER";
  66. + if (rotate_path && strcmp(rotate_path, "")) {
  67. + gs_argv[gs_argc++] = rotate_path;
  68. + }
  69. + if (ocr_path && strcmp(ocr_path, "")) {
  70. + gs_argv[gs_argc++] = ocr_path;
  71. + }
  72. + if (path == NULL ) {
  73. + gs_argv[gs_argc++] = "-";
  74. + }
  75. + else {
  76. + gs_argv[gs_argc++] = "--";
  77. + gs_argv[gs_argc++] = path;
  78. }
  79. -
  80. - gs_cmdline = (char*)malloc(strlen(gs_cmd)+strlen(rotate_path)+
  81. - strlen(ocr_path) + strlen(input) + 128);
  82. -
  83. - if (gs_cmdline == NULL) {
  84. - fprintf(stderr, "No memory available\n");
  85. - cleanup();
  86. - exit(1);
  87. - }
  88. -
  89. - sprintf(
  90. - gs_cmdline,
  91. -#ifdef VMS
  92. - "%s -r72 \"-dNODISPLAY\" \"-dFIXEDMEDIA\" \"-dDELAYBIND\" \"-dWRITESYSTEMDICT\" %s \"-dNOPAUSE\" %s %s %s",
  93. -#else
  94. - "%s -r72 -dNODISPLAY -dFIXEDMEDIA -dDELAYBIND -dWRITESYSTEMDICT %s -dNOPAUSE %s %s %s",
  95. -#endif
  96. - gs_cmd,
  97. - (debug ? "" : "-q"),
  98. - rotate_path,
  99. - ocr_path,
  100. - input
  101. - );
  102. - if (debug) fprintf(stderr, "%s\n", gs_cmdline);
  103. + gs_argv[gs_argc++] = NULL;
  104. #ifdef VMS
  105. cmdfile = tempnam("SYS$SCRATCH:","PS2TGS");
  106. gsoutfile = tempnam("SYS$SCRATCH:","GSRES");
  107. @@ -259,8 +250,25 @@
  108. exit(1);
  109. }
  110. #else
  111. - gs = popen(gs_cmdline, "r");
  112. - if (gs==0) {perror(cmd); exit(1);}
  113. + if (pipe(fd)) {
  114. + perror("pipe failed: "); exit(1);
  115. + };
  116. + p = fork();
  117. + if (p == -1) {
  118. + perror("fork failed: "); exit(1);
  119. + }
  120. + if (p == 0) { /* child */
  121. + close(fd[0]);
  122. + dup2(fd[1], 1); /* Redirect stdout into pipe to parent */
  123. + execvp("/usr/bin/gs", gs_argv);
  124. + perror("execvp: "); status=cleanup(); exit(1);
  125. + } else { /* parent */
  126. + close(fd[1]);
  127. + gs = fdopen(fd[0], "r");
  128. + if (gs == NULL) {
  129. + perror("fdopen: "); status=cleanup(); exit(1);
  130. + }
  131. + }
  132. #endif
  133. status = pstotextInit(&instance);
  134. if (status!=0) {