Beispiel #1
0
int main(int argc, char **argv)
{
	char  line[BUFSIZE];
	char* p_nl;
	MemoryContextInit();

	if (argc > 1 &&
		(strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0))
	{
		printf("Parse SQL query from stdin\nUSAGE: queryparser\nOPTIONS:\n\t--json: Output in JSON format\n\t--help: Show this help\n");
		return 0;
	}

	if (!fgets(line, BUFSIZE, stdin))
		return 2;  /* no data read */

	p_nl = strchr(line, (int) '\n');
	if (p_nl != NULL) {
		*(p_nl) = '\0';
	} else {
		return 3; /* no newline */
	}

	if (line[0] == '#' || line[0] == '\0')
		return 1;

	if (argc > 1 && strcmp(argv[1], "--json") == 0)
	{
		return do_parse(line, &nodeToJSONString) ? 0 : 1;
	}
	return do_parse(line, &nodeToString) ? 0 : 1;
}
Beispiel #2
0
void init_unformatted (variable * v)
{
  char *val;
  val = getenv (v->name);
  def = GFC_CONVERT_NONE;
  n_elist = 0;

  if (val == NULL)
    return;
  do_count = 1;
  p = val;
  do_parse ();
  if (do_count <= 0)
    {
      n_elist = 0;
      elist = NULL;
    }
  else
    {
      elist = xmallocarray (unit_count, sizeof (exception_t));
      do_count = 0;
      p = val;
      do_parse ();
    }
}
Beispiel #3
0
XMLNODE *xml_parse_string(XSLTGLOBALDATA *gctx, char *string, int has_allocator)
{
  if (string == NULL || strlen(string) == 0)
  {
    error("xml_parse_string:: empty string");
    return NULL;
  }

  memory_allocator *allocator = NULL;
  if (has_allocator == 0)
  {
    allocator = memory_allocator_create();
    memory_allocator_add_entry(allocator, pthread_self(), 1000000);
    memory_allocator_set_current(allocator);
  }

  XMLNODE *ret = do_parse(gctx, string, "(string)");
  if (ret == NULL) {
    if (allocator != NULL) memory_allocator_release(allocator);
    return NULL;
  }

  renumber_children(ret);
  ret->allocator = allocator;

  return ret;
}
Beispiel #4
0
bool sparql_parser::parse_string(string input_str,request_or_reply& r){
    clear();
    std::stringstream ss(input_str);
    string str;
    vector<string> token_vec;
    while(ss>>str){
        token_vec.push_back(str);
        if(str=="}"){
            break;
        }
    }
    do_parse(token_vec);
    if(!valid){
        return false;
    }
    if(req_template.place_holder_position.size()!=0){
        cout<<"[error] request with place_holder"<<endl;
        return false;
    }
    r=request_or_reply();
    if(join_step>=0){
        vector<int> join_vec;
        join_vec.push_back(0);
        join_vec.push_back(0);
        join_vec.push_back(join_cmd); //means join
        join_vec.push_back(join_step+1); // because we insert a new cmd in the middle
        req_template.cmd_chains.insert(req_template.cmd_chains.begin()+fork_step*4,
                                                join_vec.begin(),join_vec.end());
    }
    r.cmd_chains=req_template.cmd_chains;
    return true;
};
Beispiel #5
0
TEST(ExpressionTest, simple_string_with_expression_1) {
	EXPECT_TRUE(do_parse("HelloWorld${foobar}", v));
	ASSERT_EQ(2, v.size());
	EXPECT_EQ(false, v[0].is_variable);
	EXPECT_EQ("HelloWorld", v[0].name);
	EXPECT_EQ(true, v[1].is_variable);
	EXPECT_EQ("foobar", v[1].name);
}
Beispiel #6
0
int main( int argc, char * argv[] ){
  int i;
  char pgm[120]; /* source code file name */
  if (argc != 3){ 
    fprintf(stderr,"usage: %s <input> <output>\n",argv[0]);
    exit(1);
  }
  strcpy(pgm,argv[1]);
  if (strchr (pgm, '.') == NULL)
     strcat(pgm,".pas");
  source = fopen(pgm,"r");
  if (source == NULL){
    fprintf(stderr,"File %s not found\n",pgm);
    exit(1);
  }
  yyin = source;
  listing = stdout; /* send listing to screen */
  fprintf(listing,"\nPASCAL COMPILATION: %s\n",pgm);
  
  //scan begin
#ifdef SCAN_DEBUG
  yy_flex_debug = 1;
#endif

#ifdef PARSE_DEBUG
  yydebug = 1;
#endif
  
  auto syntaxTree = dynamic_cast<Program_Node*>(do_parse());

  st->global = 1;
  syntaxTree->build_symbol_table("");
  // puts("=========symtab debug============");
  // for (i=0; i<SIZE; i++) {
  //   if (st->units[i].use == 1) {
  //     puts("=======================");
  //     printf("name: %s", st->units[i].name.c_str()); puts("");
  //     printf("type: %s", st->units[i].type.c_str()); puts("");
  //     printf("array_start: %d", st->units[i].array_start); puts("");
  //     printf("volumn: %d", st->units[i].volumn); puts("");
  //     printf("isrecord: %d", st->units[i].volumn); puts("");
  //     printf("volumn: %d", st->units[i].volumn); puts("");
  //     printf("printer: %p\n", &(st->units[i]));
  //   }
  // }
  // puts("=========symtab debug  end========");

  /* code generation */
  CodeGenerator* cg = new CodeGenerator(syntaxTree, argv[2]);
  cg->generate();

  fclose(source);
  return 0;
}
Beispiel #7
0
/**
 * @return number of octets used by this protocol, or zero upon error
 */
static size_t parse(char *buf, size_t len, parse_frame *f, const parse_status *st)
{
  size_t bytes;
  /* sanity check packet */
  if (0 == len)
    return 0;
  bytes = do_parse(buf, len, f);
  if (f->pass)
    report(f, st);
  return bytes;
}
Beispiel #8
0
PyObject*
parse_request(PyObject* ignored, PyObject* args)
{
    PyObject* self;
    PyObject* source;
    PyObject* port = NULL;
    PyObject* ret = NULL;
    int status;

    if(!PyArg_ParseTuple(args, "OO", &self, &source)) return NULL;

    request_t* req = create_request(source);
    if(req == NULL) goto done;

    status = do_parse(req);
    if(status < 0) goto done;
    if(status == 0)
    {
        destroy_request(req);
        Py_RETURN_NONE;
    }
    
    // Move objects to self

    if(move_object(self, "method", &(req->method)) != 0) goto done;
    if(move_object(self, "uri", &(req->uri)) != 0) goto done;
    if(move_object(self, "scheme", &(req->scheme)) != 0) goto done;
    if(move_object(self, "host", &(req->host)) != 0) goto done;
    
    port = PyInt_FromLong(req->port);
    if(port == NULL) goto done;
    if(move_object(self, "port", &port) != 0) goto done;

    if(move_object(self, "path", &(req->path)) != 0) goto done;
    if(move_object(self, "query", &(req->query)) != 0) goto done;
    if(move_object(self, "fragment", &(req->fragment)) != 0) goto done;
    if(move_object(self, "version", &(req->version)) != 0) goto done;
    if(move_object(self, "headers", &(req->headers)) != 0) goto done;

    if(req->buflen > 0)
    {
        ret = PyString_FromStringAndSize(req->buffer, req->buflen);
    }
    else
    {
        ret = PyString_FromString("");
    }

done:
    Py_XDECREF(port);
    if(req != NULL) destroy_request(req);
    return ret;
}
Beispiel #9
0
/**
 * @return number of octets used by this protocol, or zero upon error
 */
static size_t parse(char *buf, size_t len, parse_frame *f, const parse_status *st)
{
  tivoconn *t = (tivoconn *)buf;
  static tivoconn_kv kv;
  size_t parsed;
  /* sanity check packet */
  /* convert endianness */
  /* parse */
  parsed = do_parse(buf, len, &kv);
  f->pass = &kv;
  return len; /* consume all bytes */
}
Beispiel #10
0
/**
 * @return number of octets used by this protocol, or zero upon error
 */
static size_t parse(char *buf, size_t len, parse_frame *f, const parse_status *st)
{
    dcerpc_hdr *h = (dcerpc_hdr *)buf;
    size_t bytes;
    /* sanity check packet */
    if (sizeof *h > len)
        return 0;
    len -= sizeof *h;
    bytes = do_parse(buf + sizeof *h, len, h);
    if (bytes)
        bytes += sizeof *h;
    return bytes;
}
Beispiel #11
0
    rc_errno core_config::parse() {
        if (inited_)
            return RC_GOOD;
        
        std::ifstream ifs(cfg_file_.c_str(), std::ifstream::in);

        if (!ifs.is_open()) {
            glogger::l(FATAL, "failed to open configuration file %s", cfg_file_.c_str());
            return RC_ERROR;
        }
        
        return do_parse(ifs);
    }
Beispiel #12
0
/**
 * @return number of octets used by this protocol, or zero upon error
 */
static size_t parse(char *buf, size_t len, parse_frame *f, const parse_status *st)
{
  browse *b = (browse *)buf;
  size_t bytes;
  /* sanity check packet */
  if (sizeof *b > len)
    return 0;
  bytes = do_parse(b, buf + sizeof b->cmd, len - sizeof b->cmd, st);
  if (bytes > 0)
    bytes += sizeof b->cmd; /* includes trailing \0 */
  /* NOTE: bytes will normally == len; HOWEVER we can not assume that it will;
   * BROWSER over LLC pads with zero bytes */
  return bytes;
}
Beispiel #13
0
/**
 * @return number of octets used by this protocol, or zero upon error
 */
static size_t parse(char *buf, size_t len, parse_frame *f, const parse_status *st)
{
  cdp *c = (cdp *)buf;
  size_t bytes;
  /* sanity check packet */
  if (sizeof *c > len)
    return 0;
  /* convert endianness */
  c->chksum = ntohs(c->chksum);
  bytes = do_parse(buf + sizeof *c, len - sizeof *c);
  bytes += sizeof *c;
  assert(bytes == len);
  return bytes;
}
Beispiel #14
0
static PyObject *
cppparse_get_pt(PyObject *self, PyObject *args)
{
	const char *input;
	int input_length;
	PyObject *PTOut;

	if(!PyArg_ParseTuple(args, "s#", &input, &input_length))
		return NULL;

	PTOut = do_parse((unsigned char *)input, input_length);

	return Py_BuildValue("O", PTOut);
}
Beispiel #15
0
/*
 * Parse and display /etc/issue
 */
static void do_issue(char *tty)
{
	FILE *fp;
	char buf[BUFSIZ] = "Welcome to \\s \\v \\n \\l\n\n";
	struct utsname uts;

	/*
	 * Get data about this machine.
	 */
	uname(&uts);

	fp = fopen("/etc/issue", "r");
	if (fp) {
		while (fgets(buf, sizeof(buf), fp))
			do_parse(buf, &uts, tty);

		fclose(fp);
	} else {
		do_parse(buf, &uts, tty);
	}

	do_parse("\\n login: ", &uts, tty);
}
Beispiel #16
0
unsigned sys_erase(struct FAB *fab)
{
    unsigned sts;
    int ifi_no = 1;
    int wcc_flag = 0;
    struct WCCFILE *wccfile = NULL;
    struct NAM *nam = fab->fab$l_nam;
    if (fab->fab$w_ifi != 0) return RMS$_IFI;
    while (ifi_table[ifi_no] != NULL && ifi_no < IFI_MAX) ifi_no++;
    if (ifi_no >= IFI_MAX) return RMS$_IFI;
    if (nam != NULL) {
        wccfile = (struct WCCFILE *) fab->fab$l_nam->nam$l_wcc;
    }
    if (wccfile == NULL) {
        sts = do_parse(fab,&wccfile);
        if (sts & 1) {
            wcc_flag = 1;
            if (wccfile->wcf_status & STATUS_WILDCARD) {
                sts = RMS$_WLD;
            } else {
                sts = do_search(fab,wccfile);
            }
        }
    } else {
        sts = 1;
    }
    if (sts & 1) {
        struct fibdef fibblk;
        struct dsc$descriptor fibdsc,serdsc;
        fibdsc.dsc$w_length = sizeof(struct fibdef);
        fibdsc.dsc$a_pointer = (char *) &fibblk;
        serdsc.dsc$w_length = wccfile->wcf_wcd.wcd_reslen;
        serdsc.dsc$a_pointer = wccfile->wcf_result + wccfile->wcf_wcd.wcd_prelen;
        memcpy(&fibblk.fib$w_did_num,&wccfile->wcf_wcd.wcd_dirid,sizeof(struct fiddef));
        fibblk.fib$w_nmctl = 0;
        fibblk.fib$l_acctl = 0;
        fibblk.fib$w_fid_num = 0;
        fibblk.fib$w_fid_seq = 0;
        fibblk.fib$b_fid_rvn = 0;
        fibblk.fib$b_fid_nmx = 0;
        fibblk.fib$l_wcc = 0;
        sts = direct(wccfile->wcf_vcb,&fibdsc,&serdsc,NULL,NULL,1);
        if (sts & 1) sts = accesserase(wccfile->wcf_vcb,&wccfile->wcf_fid);
    }
    if (wcc_flag) {
        cleanup_wcf(wccfile);
        if (nam != NULL) nam->nam$l_wcc = 0;
    }
    return sts;
}
Beispiel #17
0
bool sparql_parser::parse_template(string filename,request_template& r){
    clear();
    vector<string> token_vec=get_token_vec(filename);
    do_parse(token_vec);
    if(!valid){
        return false;
    }
    if(req_template.place_holder_position.size()==0){
        cout<<"[error] request_template without place_holder"<<endl;
        return false;
    }
    r=req_template;
    return true;
};
TEST(PerfDataTest, value_various_reparse) {
	std::vector<std::string> strings;
	strings.push_back("'aaa'=1g;0;4;2;5");
	strings.push_back("'aaa'=6g;1;2;3;4");
	strings.push_back("'aaa'=6g;;2;3;4");
	strings.push_back("'aaa'=6g;1;;3;4");
	strings.push_back("'aaa'=6g;1;2;;4");
	strings.push_back("'aaa'=6g;1;2;3");
	strings.push_back("'aaa'=6g;;;3;4");
	strings.push_back("'aaa'=6g;1;;;4");
	strings.push_back("'aaa'=6g;1;2");
	strings.push_back("'aaa'=6g");
	BOOST_FOREACH(std::string s, strings) {
		EXPECT_EQ(s.c_str(), do_parse(s));
	}
/* ************************************************** */
int main(int argc, char *argv[]) {
    if (do_parse(argc, argv) ||  /* parse arguments */
	do_init()            ||  /* initialization  */
	do_configuration()   ||  /* configuration   */
	do_bootstrap()) {        /* bootstrap       */
        goto end;
    }
    do_observe();                /* observe         */
    do_end();                    /* end             */
    goto end;

 end:
    do_clean();                  /* clean           */
    return 0;
}
Beispiel #20
0
TEST(ExpressionTest, complext_string_with_expressions_p) {
    EXPECT_TRUE(do_parse("HelloWorld%(foobar)MoreData%(test)-))((-%(test((2)", v));
    ASSERT_EQ(6, v.size());
    EXPECT_EQ("HelloWorld", v[0].name);
    EXPECT_FALSE(v[0].is_variable);
    EXPECT_EQ("foobar", v[1].name);
    EXPECT_TRUE(v[1].is_variable);
    EXPECT_EQ("MoreData", v[2].name);
    EXPECT_FALSE(v[2].is_variable);
    EXPECT_EQ("test", v[3].name);
    EXPECT_TRUE(v[3].is_variable);
    EXPECT_EQ("-))((-", v[4].name);
    EXPECT_FALSE(v[4].is_variable);
    EXPECT_EQ("test((2", v[5].name);
    EXPECT_TRUE(v[5].is_variable);
}
Beispiel #21
0
TEST(ExpressionTest, complext_string_with_expressions) {
	EXPECT_TRUE(do_parse("HelloWorld${foobar}MoreData${test}-}}{{-${test{{2}", v));
	ASSERT_EQ(6, v.size());
	EXPECT_EQ("HelloWorld", v[0].name);
	EXPECT_EQ(false, v[0].is_variable);
	EXPECT_EQ("foobar", v[1].name);
	EXPECT_EQ(true, v[1].is_variable);
	EXPECT_EQ("MoreData", v[2].name);
	EXPECT_EQ(false, v[2].is_variable);
	EXPECT_EQ("test", v[3].name);
	EXPECT_EQ(true, v[3].is_variable);
	EXPECT_EQ("-}}{{-", v[4].name);
	EXPECT_EQ(false, v[4].is_variable);
	EXPECT_EQ("test{{2", v[5].name);
	EXPECT_EQ(true, v[5].is_variable);
}
Beispiel #22
0
APU_DECLARE(apr_status_t) apr_xml_parser_done(apr_xml_parser *parser,
        apr_xml_doc **pdoc)
{
    char end;
    apr_status_t status = do_parse(parser, &end, 0, 1 /* is_final */);

    /* get rid of the parser */
    (void) apr_pool_cleanup_run(parser->p, parser, cleanup_parser);

    if (status)
        return status;

    if (pdoc != NULL)
        *pdoc = parser->doc;
    return APR_SUCCESS;
}
GstVaapiDecoderStatus
gst_vaapi_decoder_parse (GstVaapiDecoder * decoder,
    GstVideoCodecFrame * base_frame, GstAdapter * adapter, gboolean at_eos,
    guint * got_unit_size_ptr, gboolean * got_frame_ptr)
{
  g_return_val_if_fail (decoder != NULL,
      GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER);
  g_return_val_if_fail (base_frame != NULL,
      GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER);
  g_return_val_if_fail (adapter != NULL,
      GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER);
  g_return_val_if_fail (got_unit_size_ptr != NULL,
      GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER);
  g_return_val_if_fail (got_frame_ptr != NULL,
      GST_VAAPI_DECODER_STATUS_ERROR_INVALID_PARAMETER);

  return do_parse (decoder, base_frame, adapter, at_eos,
      got_unit_size_ptr, got_frame_ptr);
}
Beispiel #24
0
void BidlParser::parse(const std::string& bidl) {
    do_parse(bidl);

    int32_t matrix_size = _input_bidls.size();
    if (matrix_size > MATRIX_SIZE) {
        myerror("too mary include bidls. max size is %d", MATRIX_SIZE);
    }

    relation2matrix();
    check4circle();

    std::vector<std::string> ordered_input_bidls = get_ordered_bidl();

    std::vector<std::string>::const_iterator itr;
    for (itr = ordered_input_bidls.begin();
            itr != ordered_input_bidls.end();
            ++itr) {
        check_symbol(*itr);
    }
    generate_source_code();
}
Beispiel #25
0
/**
 * @return number of octets used by this protocol, or zero upon error
 */
size_t smb_parse(char *buf, size_t len, parse_frame *f, const parse_status *st)
{
  smb_hdr *h = (smb_hdr *)buf;
  size_t bytes;
  /* sanity check packet */
  if (sizeof *h > len)
    return 0;
  /* convert endianness */
  h->treeid = ntohs(h->treeid);
  h->procid = ntohs(h->procid);
  h->userid = ntohs(h->userid);
  bytes = do_parse(buf + sizeof *h, len - sizeof *h, h);
#if 1
  printf("%s %s do_parse=%u bytes: ",
    __FILE__, __func__, (unsigned)bytes);
  dump_chars(buf + sizeof *h, bytes, stdout);
  fputc('\n', stdout);
#endif
  bytes += sizeof *h;
  return bytes;
}
Beispiel #26
0
unsigned sys_open(struct FAB *fab)
{
    unsigned sts;
    int ifi_no = 1;
    int wcc_flag = 0;
    struct WCCFILE *wccfile = NULL;
    struct NAM *nam = fab->fab$l_nam;
    if (fab->fab$w_ifi != 0) return RMS$_IFI;
    while (ifi_table[ifi_no] != NULL && ifi_no < IFI_MAX) ifi_no++;
    if (ifi_no >= IFI_MAX) return RMS$_IFI;
    if (nam != NULL) {
        wccfile = (struct WCCFILE *) nam->nam$l_wcc;
    }
    if (wccfile == NULL) {
        sts = do_parse(fab,&wccfile);
        if (sts & 1) {
            wcc_flag = 1;
            if (wccfile->wcf_status & STATUS_WILDCARD) {
                sts = RMS$_WLD;
            } else {
                sts = do_search(fab,wccfile);
            }
            wccfile->wcf_status |= STATUS_TMPWCC;
        }
    } else {
        sts = 1;
    }
    if (sts & 1) sts = accessfile(wccfile->wcf_vcb,&wccfile->wcf_fid,&wccfile->wcf_fcb,0);
    if (sts & 1) {
        ifi_table[ifi_no] = wccfile;
        fab->fab$w_ifi = ifi_no;
        sys_display(fab);
    }
    if (wcc_flag && ((sts & 1) == 0)) {
        cleanup_wcf(wccfile);
        if (nam != NULL) nam->nam$l_wcc = 0;
    }
    return sts;
}
Beispiel #27
0
int main(int argc, char **argv)
{
	char  line[BUFSIZE];
	char* p_nl;
	MemoryContextInit();

	if (!fgets(line, BUFSIZE, stdin))
		return 2;  /* no data read */

	p_nl = strchr(line, (int) '\n');
	if (p_nl != NULL) {
		*(p_nl) = '\0';
	} else {
		return 3; /* no newline */
	}

	if (line[0] == '#' || line[0] == '\0')
		return 1;

	do_parse(line);

	return 0;
}
Beispiel #28
0
int strategy_conf::load()
{
    FILE * fp = fopen(_fullpath, "r");
    ASSERT_WARNING(fp != NULL,"open query dict failed. path[%s]", _fullpath);

    char line[SIZE_LEN_1024];
    char * ptr = NULL;
    
    _cfg.clear();
    std::vector<std::string> tmp_vec;
    while (fgets(line, 1024, fp))
    {
        if('\0' == line[0]){
            continue;
        }

        ptr = im_chomp(line);
        if (ptr == NULL || *ptr == '\0'|| *ptr == '#')
            continue;
        
        SplitString(ptr, "=", &tmp_vec, SPLIT_MODE_ONE | SPLIT_MODE_TRIM);
        if (tmp_vec.size() != 2)
            continue;

        _cfg.insert(std::make_pair(trim(tmp_vec[0].c_str()), trim(tmp_vec[1].c_str())));
    }
    fclose(fp);

    do_parse();

    struct stat st;
    stat(_fullpath, &st);
    _last_load = st.st_mtime;

    return 0;
}
Beispiel #29
0
bool sparql_parser::parse(string filename,request_or_reply& r){
    clear();
    vector<string> token_vec=get_token_vec(filename);
    do_parse(token_vec);
    if(!valid){
        return false;
    }
    if(req_template.place_holder_position.size()!=0){
        cout<<"[error] request with place_holder"<<endl;
        return false;
    }
    r=request_or_reply();
    if(join_step>=0){
        vector<int> join_vec;
        join_vec.push_back(0);
        join_vec.push_back(0);
        join_vec.push_back(join_cmd); //means join
        join_vec.push_back(join_step+1); // because we insert a new cmd in the middle
        req_template.cmd_chains.insert(req_template.cmd_chains.begin()+fork_step*4,
                                                join_vec.begin(),join_vec.end());
    }
    r.cmd_chains=req_template.cmd_chains;
    return true;
};
Beispiel #30
0
void BidlParser::do_parse(const std::string& bidl) {
    std::string dir;
    if (!g_parser.is_bidl_exist_in_bidl_include_dirs(bidl, dir)) {
        myerror("file %s is not exist", bidl.c_str());
    }
    std::string fullname = dir + bidl;
    if (is_bidl_parsed(bidl)) {
        return;
    }

    _input_bidls.push_back(bidl);
    g_cur_bidl_file_name = bidl;

    FILE* fp = fopen(fullname.c_str(), "r");
    if (!fp) {
        myerror("open %s failed: %s", fullname.c_str(), strerror(errno));
    }

    ParseResult* pr;
    pr = parse_fp(fp);
    fclose(fp);

    if (!pr || !pr->bt) {
        myerror("parse %s failed", fullname.c_str());
    }
    _filename2parseresult.insert(std::make_pair(bidl, pr));

    std::vector<std::string>::const_iterator citr;
    for (citr = pr->include_bidls.begin();
            citr != pr->include_bidls.end();
            ++citr) {
        do_parse(*citr);
    }

    g_parseresult = NULL;
}