~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/xpdflib/pstokenizer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2005-02-24 22:09:16 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050224220916-9vxiiqjz066r5489
Tags: 6.0pre23-2
debian/control: Ipe should depend on exact version of libipe.
Closes: #296771.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//========================================================================
2
 
//
3
 
// PSTokenizer.cc
4
 
//
5
 
// Copyright 2002 Glyph & Cog, LLC
6
 
//
7
 
//========================================================================
8
 
 
9
 
#include "aconf.h"
10
 
 
11
 
#ifdef USE_GCC_PRAGMAS
12
 
#pragma implementation
13
 
#endif
14
 
 
15
 
#include <stdio.h>
16
 
#include "ocfile.h"
17
 
#include <stdlib.h>
18
 
#include "pstokenizer.h"
19
 
 
20
 
//------------------------------------------------------------------------
21
 
 
22
 
// A '1' in this array means the character is white space.  A '1' or
23
 
// '2' means the character ends a name or command.
24
 
static char specialChars[256] = {
25
 
  1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0,   // 0x
26
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // 1x
27
 
  1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2,   // 2x
28
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0,   // 3x
29
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // 4x
30
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0,   // 5x
31
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // 6x
32
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0,   // 7x
33
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // 8x
34
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // 9x
35
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // ax
36
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // bx
37
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // cx
38
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // dx
39
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   // ex
40
 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0    // fx
41
 
};
42
 
 
43
 
//------------------------------------------------------------------------
44
 
 
45
 
PSTokenizer::PSTokenizer(int (*getCharFuncA)(void *), void *dataA) {
46
 
  getCharFunc = getCharFuncA;
47
 
  data = dataA;
48
 
  charBuf = -1;
49
 
}
50
 
 
51
 
PSTokenizer::~PSTokenizer() {
52
 
}
53
 
 
54
 
GBool PSTokenizer::getToken(char *buf, int size, int *length) {
55
 
  GBool comment, backslash;
56
 
  int c;
57
 
  int i;
58
 
 
59
 
  // skip whitespace and comments
60
 
  comment = gFalse;
61
 
  while (1) {
62
 
    if ((c = getChar()) == EOF) {
63
 
      buf[0] = '\0';
64
 
      *length = 0;
65
 
      return gFalse;
66
 
    }
67
 
    if (comment) {
68
 
      if (c == '\x0a' || c == '\x0d') {
69
 
        comment = gFalse;
70
 
      }
71
 
    } else if (c == '%') {
72
 
      comment = gTrue;
73
 
    } else if (specialChars[c] != 1) {
74
 
      break;
75
 
    }
76
 
  }
77
 
 
78
 
  // read a token
79
 
  i = 0;
80
 
  buf[i++] = c;
81
 
  if (c == '(') {
82
 
    backslash = gFalse;
83
 
    while ((c = lookChar()) != EOF) {
84
 
      if (i < size - 1) {
85
 
        buf[i++] = c;
86
 
      }
87
 
      getChar();
88
 
      if (c == '\\') {
89
 
        backslash = gTrue;
90
 
      } else if (!backslash && c == ')') {
91
 
        break;
92
 
      } else {
93
 
        backslash = gFalse;
94
 
      }
95
 
    }
96
 
  } else if (c == '<') {
97
 
    while ((c = lookChar()) != EOF) {
98
 
      getChar();
99
 
      if (i < size - 1) {
100
 
        buf[i++] = c;
101
 
      }
102
 
      if (c == '>') {
103
 
        break;
104
 
      }
105
 
    }
106
 
  } else if (c != '[' && c != ']') {
107
 
    while ((c = lookChar()) != EOF && !specialChars[c]) {
108
 
      getChar();
109
 
      if (i < size - 1) {
110
 
        buf[i++] = c;
111
 
      }
112
 
    }
113
 
  }
114
 
  buf[i] = '\0';
115
 
  *length = i;
116
 
 
117
 
  return gTrue;
118
 
}
119
 
 
120
 
int PSTokenizer::lookChar() {
121
 
  if (charBuf < 0) {
122
 
    charBuf = (*getCharFunc)(data);
123
 
  }
124
 
  return charBuf;
125
 
}
126
 
 
127
 
int PSTokenizer::getChar() {
128
 
  int c;
129
 
 
130
 
  if (charBuf < 0) {
131
 
    charBuf = (*getCharFunc)(data);
132
 
  }
133
 
  c = charBuf;
134
 
  charBuf = -1;
135
 
  return c;
136
 
}