Advertisement
robinwatts

Untitled

Nov 22nd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. static int
  2. handle_dash_c(pl_main_instance_t *pmi, arg_list *pal, char **collected_commands, const char **arg)
  3. {
  4. bool ats = pal->expand_ats;
  5. int code = 0;
  6.  
  7. *arg = NULL;
  8. pal->expand_ats = false;
  9. while ((code = arg_next(pal, (const char **)arg, pmi->memory)) > 0) {
  10. size_t arglen;
  11. if ((*arg)[0] == '@' ||
  12. ((*arg)[0] == '-' && !isdigit((unsigned char)(*arg)[1]))
  13. )
  14. break;
  15. code = gs_lib_ctx_stash_sanitized_arg(pmi->memory->gs_lib_ctx, "?");
  16. if (code < 0)
  17. goto error_exit;
  18. arglen = strlen(*arg);
  19. if (*collected_commands == NULL) {
  20. *collected_commands = (char *)gs_alloc_bytes(pmi->memory, arglen+1,
  21. "-c buffer");
  22. if (*collected_commands == NULL) {
  23. code = gs_note_error(gs_error_VMerror);
  24. break;
  25. }
  26. memcpy(*collected_commands, *arg, arglen+1);
  27. } else {
  28. char *newc;
  29. size_t oldlen = strlen(*collected_commands);
  30. newc = (char *)gs_resize_object(pmi->memory,
  31. *collected_commands,
  32. oldlen + 1 + arglen + 1,
  33. "-c buffer");
  34. if (newc == NULL) {
  35. code = gs_note_error(gs_error_VMerror);
  36. break;
  37. }
  38. newc[oldlen] = 32;
  39. memcpy(newc + oldlen + 1, *arg, arglen + 1);
  40. *collected_commands = newc;
  41. }
  42. *arg = NULL;
  43. }
  44. if (code == gs_error_VMerror)
  45. dmprintf(pmi->memory, "Failed to allocate memory while handling -c\n");
  46. else if (code < 0)
  47. dmprintf(pmi->memory, "Syntax: -c <postscript commands>\n");
  48. pal->expand_ats = ats;
  49.  
  50. return code;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement