Back to index

texmacs  1.0.7.15
Defines | Functions
pst.c File Reference
#include <string.h>
#include <ctype.h>
#include "system.h"
#include "mem.h"
#include "error.h"
#include "dpxutil.h"
#include "pst_obj.h"
#include "pst.h"

Go to the source code of this file.

Defines

#define TYPE_CHECK(o, t)

Functions

static pst_objpst_parse_any (unsigned char **inbuf, unsigned char *inbufend)
static void skip_line (unsigned char **inbuf, unsigned char *inbufend)
static void skip_comments (unsigned char **inbuf, unsigned char *inbufend)
pst_objpst_get_token (unsigned char **inbuf, unsigned char *inbufend)

Define Documentation

#define TYPE_CHECK (   o,
 
)
Value:
do { \
                             if ((o) == NULL || pst_type_of((o)) != (t)) \
                                  ERROR("typecheck: object %p not of type %d.", (o), (t)); \
                             } while (0)

Definition at line 36 of file pst.c.


Function Documentation

pst_obj* pst_get_token ( unsigned char **  inbuf,
unsigned char *  inbufend 
)

Definition at line 105 of file pst.c.

{
  pst_obj *obj = NULL;
  unsigned char c;

  ASSERT(*inbuf <= inbufend && !*inbufend);

  skip_white_spaces(inbuf, inbufend);
  skip_comments(inbuf, inbufend);
  if (*inbuf >= inbufend)
    return NULL;
  c = **inbuf;
  switch (c) {
#if 0
  case '%':
    obj = pst_parse_comment(inbuf, inbufend);
    break;
#endif
  case '/':
    obj = pst_parse_name(inbuf, inbufend);
    break;
  case '[': case '{': /* This is wrong */
    obj = pst_new_mark();
    (*inbuf)++;
    break;
  case '<':
    if (*inbuf + 1 >= inbufend)
      return NULL;
    c = *(*inbuf+1);
    if (c == '<') {
      obj = pst_new_mark();
      *inbuf += 2;
    } else if (isxdigit(c))
      obj = pst_parse_string(inbuf, inbufend);
    else if (c == '~') /* ASCII85 */
      obj = pst_parse_string(inbuf, inbufend);
    break;
  case '(':
    obj = pst_parse_string(inbuf, inbufend);
    break;
  case '>':
    if (*inbuf + 1 >= inbufend || *(*inbuf+1) != '>') {
      ERROR("Unexpected end of ASCII hex string marker.");
    } else  {
      char *mark;

      mark = NEW(3, char);
      mark[0] = '>'; mark[1] = '>'; mark[2] = '\0';
      obj = pst_new_obj(PST_TYPE_UNKNOWN, mark);
      (*inbuf) += 2;
    }
    break;
  case ']': case '}': 
    {
      char *mark;

      mark = NEW(2, char);
      mark[0] = c; mark[1] = '\0';
      obj = pst_new_obj(PST_TYPE_UNKNOWN, mark);
      (*inbuf)++;
    }
    break;
  default:
    if (c == 't' || c == 'f')
      obj = pst_parse_boolean(inbuf, inbufend);
    else if (c == 'n')
      obj = pst_parse_null(inbuf, inbufend);
    else if (c == '+' || c == '-' || isdigit(c) || c == '.')
      obj = pst_parse_number(inbuf, inbufend);
    break;
  }

  if (!obj) {
    obj = pst_parse_any(inbuf, inbufend);
  }

  return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static pst_obj* pst_parse_any ( unsigned char **  inbuf,
unsigned char *  inbufend 
) [static]

Definition at line 42 of file pst.c.

{
  unsigned char *data;
  unsigned char *cur = *inbuf;
  unsigned long  len;

  while (cur < inbufend && !PST_TOKEN_END(cur, inbufend))
    cur++;

  len = cur - (*inbuf);
  data = NEW(len+1, unsigned char);
  memcpy(data, *inbuf, len);
  data[len] = '\0';

  *inbuf = cur;
  return pst_new_obj(PST_TYPE_UNKNOWN, data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void skip_comments ( unsigned char **  inbuf,
unsigned char *  inbufend 
) [static]

Definition at line 72 of file pst.c.

{
  while (*inbuf < inbufend && **inbuf == '%') {
    skip_line(inbuf, inbufend);
    skip_white_spaces(inbuf, inbufend);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void skip_line ( unsigned char **  inbuf,
unsigned char *  inbufend 
) [static]

Definition at line 61 of file pst.c.

{
  while (*inbuf < inbufend && **inbuf != '\n' && **inbuf != '\r')
    (*inbuf)++;
  if (*inbuf < inbufend && **inbuf == '\r')
    (*inbuf)++;
  if (*inbuf < inbufend && **inbuf == '\n')
    (*inbuf)++;
}