PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/TeXmacs-1.0.7.11-src/src/Plugins/Pdf/dvipdfmx/pst.c

#
C | 182 lines | 137 code | 21 blank | 24 comment | 59 complexity | 67bbd61719197cc49e164613842fab96 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /* $Header: /home/cvsroot/dvipdfmx/src/pst.c,v 1.6 2008/01/11 18:04:15 matthias Exp $
  2. This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
  3. Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata,
  4. the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
  5. Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  17. */
  18. #include <string.h>
  19. #include <ctype.h>
  20. #include "system.h"
  21. #include "mem.h"
  22. #include "error.h"
  23. #include "dpxutil.h"
  24. #include "pst_obj.h"
  25. #include "pst.h"
  26. #define TYPE_CHECK(o, t) do { \
  27. if ((o) == NULL || pst_type_of((o)) != (t)) \
  28. ERROR("typecheck: object %p not of type %d.", (o), (t)); \
  29. } while (0)
  30. static pst_obj *
  31. pst_parse_any (unsigned char **inbuf, unsigned char *inbufend)
  32. {
  33. unsigned char *data;
  34. unsigned char *cur = *inbuf;
  35. unsigned long len;
  36. while (cur < inbufend && !PST_TOKEN_END(cur, inbufend))
  37. cur++;
  38. len = cur - (*inbuf);
  39. data = NEW(len+1, unsigned char);
  40. memcpy(data, *inbuf, len);
  41. data[len] = '\0';
  42. *inbuf = cur;
  43. return pst_new_obj(PST_TYPE_UNKNOWN, data);
  44. }
  45. static void
  46. skip_line (unsigned char **inbuf, unsigned char *inbufend)
  47. {
  48. while (*inbuf < inbufend && **inbuf != '\n' && **inbuf != '\r')
  49. (*inbuf)++;
  50. if (*inbuf < inbufend && **inbuf == '\r')
  51. (*inbuf)++;
  52. if (*inbuf < inbufend && **inbuf == '\n')
  53. (*inbuf)++;
  54. }
  55. static void
  56. skip_comments (unsigned char **inbuf, unsigned char *inbufend)
  57. {
  58. while (*inbuf < inbufend && **inbuf == '%') {
  59. skip_line(inbuf, inbufend);
  60. skip_white_spaces(inbuf, inbufend);
  61. }
  62. }
  63. #if 0
  64. static pst_obj *
  65. pst_parse_comment (unsigned char **inbuf, unsigned char *inbufend)
  66. {
  67. unsigned char *data;
  68. unsigned char *cur = *inbuf;
  69. unsigned long len;
  70. if (*cur != '%')
  71. return NULL;
  72. while (cur < inbufend && *cur != '\n' && *cur != '\r')
  73. cur++;
  74. len = cur - (*inbuf);
  75. data = NEW(len+1, unsigned char);
  76. memcpy(data, *inbuf, len);
  77. data[len] = '\0';
  78. *inbuf = cur;
  79. return pst_new_obj(PST_TYPE_UNKNOWN, data);
  80. }
  81. #endif
  82. /* NOTE: the input buffer must be null-terminated, i.e., *inbufend == 0 */
  83. pst_obj *
  84. pst_get_token (unsigned char **inbuf, unsigned char *inbufend)
  85. {
  86. pst_obj *obj = NULL;
  87. unsigned char c;
  88. ASSERT(*inbuf <= inbufend && !*inbufend);
  89. skip_white_spaces(inbuf, inbufend);
  90. skip_comments(inbuf, inbufend);
  91. if (*inbuf >= inbufend)
  92. return NULL;
  93. c = **inbuf;
  94. switch (c) {
  95. #if 0
  96. case '%':
  97. obj = pst_parse_comment(inbuf, inbufend);
  98. break;
  99. #endif
  100. case '/':
  101. obj = pst_parse_name(inbuf, inbufend);
  102. break;
  103. case '[': case '{': /* This is wrong */
  104. obj = pst_new_mark();
  105. (*inbuf)++;
  106. break;
  107. case '<':
  108. if (*inbuf + 1 >= inbufend)
  109. return NULL;
  110. c = *(*inbuf+1);
  111. if (c == '<') {
  112. obj = pst_new_mark();
  113. *inbuf += 2;
  114. } else if (isxdigit(c))
  115. obj = pst_parse_string(inbuf, inbufend);
  116. else if (c == '~') /* ASCII85 */
  117. obj = pst_parse_string(inbuf, inbufend);
  118. break;
  119. case '(':
  120. obj = pst_parse_string(inbuf, inbufend);
  121. break;
  122. case '>':
  123. if (*inbuf + 1 >= inbufend || *(*inbuf+1) != '>') {
  124. ERROR("Unexpected end of ASCII hex string marker.");
  125. } else {
  126. char *mark;
  127. mark = NEW(3, char);
  128. mark[0] = '>'; mark[1] = '>'; mark[2] = '\0';
  129. obj = pst_new_obj(PST_TYPE_UNKNOWN, mark);
  130. (*inbuf) += 2;
  131. }
  132. break;
  133. case ']': case '}':
  134. {
  135. char *mark;
  136. mark = NEW(2, char);
  137. mark[0] = c; mark[1] = '\0';
  138. obj = pst_new_obj(PST_TYPE_UNKNOWN, mark);
  139. (*inbuf)++;
  140. }
  141. break;
  142. default:
  143. if (c == 't' || c == 'f')
  144. obj = pst_parse_boolean(inbuf, inbufend);
  145. else if (c == 'n')
  146. obj = pst_parse_null(inbuf, inbufend);
  147. else if (c == '+' || c == '-' || isdigit(c) || c == '.')
  148. obj = pst_parse_number(inbuf, inbufend);
  149. break;
  150. }
  151. if (!obj) {
  152. obj = pst_parse_any(inbuf, inbufend);
  153. }
  154. return obj;
  155. }