Example #1
0
sexp_t *read_one_sexp(sexp_mem_t *smem, sexp_iowrap_t *iow) {
  sexp_t  *sx = NULL;

  if (iow->cnt == 0) {
    iow->cnt = read(iow->fd,iow->buf,BUFSIZ);
    if (iow->cnt == 0) return NULL;
  }

  iow->cc = cparse_sexp(smem, iow->buf,iow->cnt,iow->cc);

  while (iow->cc->last_sexp == NULL) {
    if (iow->cc->error != 0) {
      fprintf(stderr,"ERROR\n");
      return NULL;
    }

    iow->cnt = read(iow->fd,iow->buf,BUFSIZ);

    if (iow->cnt == 0)
      return NULL;

    iow->cc = cparse_sexp(smem, iow->buf,iow->cnt,iow->cc);
  }

  sx = iow->cc->last_sexp;
  iow->cc->last_sexp = NULL;

  return sx;
}
Example #2
0
int main(int argc, char **argv) {
  unsigned int len;
  pcont_t *pc;
  char inbuf[256];
  char outbuf[1024];

  strcpy(inbuf,RAWSTRING);
  len = strlen(inbuf);

  pc = NULL;

  pc = cparse_sexp(inbuf,len,pc);

  if (sexp_errno == SEXP_ERR_INCOMPLETE) {
    printf("Incomplete expression detected.\n");
  } else {
    printf("Unexpected error: %d\n", sexp_errno);
    exit(EXIT_FAILURE);
  }

  print_pcont(pc,outbuf,1024);

  printf("%s\n",outbuf);

  destroy_continuation(pc);
  sexp_cleanup();
  
  exit(EXIT_SUCCESS);
}
Example #3
0
int main(int argc, char **argv) {
  sexp_t *sx_in, *sx_out;
  int fd;
  char *b;
  size_t l = 0;
  CSTRING *s = NULL;
  pcont_t *pc;

  /* read data */
  fd = open("testdata",O_RDONLY);
  if (fd <= 0) {
    printf("Error opening test data file ``testdata''\n");
    exit(1);
  }
  b = readfile(fd,&l,1024,256);
  close(fd);
  
  /* report */
  printf("Read %lu bytes of data.\n",(unsigned long)l);

  sx_in = (sexp_t *)malloc(sizeof(sexp_t));
  assert(sx_in != NULL);
  sx_in->ty = SEXP_VALUE;
  sx_in->next = sx_in->list = NULL;
  sx_in->aty = SEXP_BINARY;
  sx_in->bindata = b;
  sx_in->binlength = l;
  sx_in = new_sexp_list(sx_in);

  printf("Created expression.\n");

  print_sexp_cstr(&s,sx_in,l+1024);
  destroy_sexp(sx_in);

  b = NULL;
  sx_in = NULL;

  printf("Destroyed AST and buffer.\n");

  pc = init_continuation(NULL);
  pc->mode = PARSER_INLINE_BINARY;
  pc = cparse_sexp(s->base,s->len,pc);
  sx_out = pc->last_sexp;

  printf("Parsed unparsed version back to AST.\n");

  assert(sx_out != NULL);

  b = sx_out->list->bindata;
  l = sx_out->list->binlength;

  fd = open("testdata_out",O_RDWR|O_CREAT);
  if (fd <= 0) {
    printf("Error opening ``testdata_out'': Create empty file to write to.\n");
    exit(1);
  }
  write(fd,b,l);
  close(fd);

  printf("Extracted and wrote bindata from AST.\n");

  exit(1);
}