Пример #1
0
int main(int argc, char **argv) {
    if(argc < 2) {
        fprintf(stderr, "Please specify the file to parse.\n");
        return 1;
    }
    ast *t;
    position p;
    const char *err;
    if((err = mmap_open(argv[1], &p))) {
        fprintf(stderr, "mmap_open failed on file \"%s\": %s\n", argv[1], err);
        return 1;
    }
    t = alloc_ast();
    if(!t) {
        fprintf(stderr, "alloc_ast could not allocate memory.\n");
        mmap_close(&p);
        return 1;
    }
    if((err = start_parser(t, &p))) {
        log_err(err, p);
        mmap_close(&p);
    } else {
        mmap_close(&p);
        ast_callback(t, argc - 2, argv + 2);
    }
    delete_ast(t);
}
Пример #2
0
int parser_load(struct katcp_dispatch *d, char *filename){

  int rtn;
  
  struct kcs_basic *kb;
  struct p_parser *p;
  kb = get_mode_katcp(d,KCS_MODE_BASIC);
  
  if (kb == NULL)
    return KATCP_RESULT_FAIL;

  p = kb->b_parser;

  if (p != NULL){
    clean_up_parser(p);
  }
  
  p = malloc(sizeof(struct p_parser));
  p->lcount   = 0;
  p->labels   = NULL;
  p->comments = NULL;
  p->comcount = 0;
  p->fsize    = 0;
  rtn = start_parser(p,filename);
  
  if (rtn != 0){
    log_message_katcp(d,KATCP_LEVEL_ERROR,NULL,"%s",strerror(rtn)); 
    clean_up_parser(p);
    return KATCP_RESULT_FAIL;
  }

  p->filename = strdup(filename);
  kb->b_parser = p;

  log_message_katcp(d,KATCP_LEVEL_INFO,NULL,"Configuration file loaded");

  return KATCP_RESULT_OK;
}