コード例 #1
0
ファイル: driver_parsetree.c プロジェクト: 01org/fMBT
int main(int argc, char *argv[]) {
  char *buf;
  D_ParseNode *pn;
  /* any number greater than sizeof(D_ParseNode_User) will do;
     below 1024 is used */
  D_Parser *p = new_D_Parser(&parser_tables_gram, 1024); 
  p->save_parse_tree = 1;

  if (argc!=2) {
    fprintf(stderr,"U¿ycie: %s FILE_to_parse\n",argv[0]);
    return -1;
  } else {
    buf = sbuf_read(argv[1]);
    if (buf == NULL) {
      fprintf(stderr, "error: empty buf\n");
      return -2;
    }
  }
  printf("file: %s\n", argv[1]);
  printf("----------\n%s", buf);
  printf("----------\n");

  if ((pn=dparse(p, buf, strlen(buf))) && !p->syntax_errors) {
    printf("\nparse tree\n");
    printf("----------\n");
    print_parsetree(parser_tables_gram, pn, NULL, NULL);
    printf("\n");
  } else {
    printf("\nfailure\n");
  }
  return 0;
}
コード例 #2
0
ファイル: stty.c プロジェクト: ShinySide/SM-G361H
static void stty_handler (int event, void* data)
{
	struct stty_device *stty = data;
	int i, cnt = 0;
	unsigned char buf[STTY_MAX_DATA_LEN] = {0};

	pr_debug("stty handler event=%d \n", event);

	switch(event) {
		case SBUF_NOTIFY_WRITE:
			break;
		case SBUF_NOTIFY_READ:
			cnt = sbuf_read(stty->pdata->dst, stty->pdata->channel,
					stty->pdata->bufid,(void *)buf, STTY_MAX_DATA_LEN, 0);
			pr_debug("stty handler read data len =%d \n", cnt);
			mutex_lock(&(stty->stat_lock));
			if ((stty->state == STTY_STATE_OPEN) && (cnt > 0)) {
				for(i = 0; i < cnt; i++) {
					tty_insert_flip_char(stty->port, buf[i], TTY_NORMAL);
				}
				tty_schedule_flip(stty->port);
			}
			mutex_unlock(&(stty->stat_lock));
			break;
		default:
			printk(KERN_ERR "Received event is invalid(event=%d)\n", event);
	}

	return;
}
コード例 #3
0
ファイル: download.c プロジェクト: Ferni7/tvheadend
static void
download_pipe_read(void *aux)
{
  download_t *dn = aux;
  ssize_t len;
  char *s, *p;

  if (dn->pipe_fd < 0 || dn->pipe_pid == 0)
    return;

  while (1) {
    if (dn->pipe_sbuf.sb_ptr > 50*1024*1024) {
      errno = EMSGSIZE;
      goto failed;
    }
    sbuf_alloc(&dn->pipe_sbuf, 2048);
    len = sbuf_read(&dn->pipe_sbuf, dn->pipe_fd);
    if (len == 0) {
      s = dn->url ? strdupa(dn->url) : strdupa("");
      p = strchr(s, ' ');
      if (p)
        *p = '\0';
      p = strrchr(s, '/');
      if (p)
        p++;
      sbuf_append(&dn->pipe_sbuf, "", 1);
      dn->process(dn->aux, p, NULL, (char *)dn->pipe_sbuf.sb_data, (size_t)dn->pipe_sbuf.sb_ptr);
      download_pipe_close(dn);
      return;
    } else if (len < 0) {
      if (ERRNO_AGAIN(errno))
        break;
failed:
      tvherror(dn->log, "pipe: read failed: %d", errno);
      download_pipe_close(dn);
      return;
    }
  }

  gtimer_arm_ms(&dn->pipe_read_timer, download_pipe_read, dn, 250);
}
コード例 #4
0
ファイル: test_parser.c プロジェクト: MatiasNAmendola/sugar
int
main(int argc, char *argv[]) {
  int i, len = 0;
  char *buf = NULL, *fn, *grammar_pathname;
  D_Parser *p;
  D_ParseNode *pn = NULL;
  unsigned char *str = NULL;
  unsigned int str_len;
  Grammar *g;
  D_ParserTables *parser_tables_gram;

  process_args(&arg_state, argv);
  if (arg_state.nfile_arguments < 2)
    help(&arg_state, NULL);

  /* build grammar */
  grammar_pathname = arg_state.file_argument[0];
  g = new_D_Grammar(grammar_pathname);
  g->set_op_priority_from_rule = set_op_priority_from_rule;
  g->right_recursive_BNF = right_recursive_BNF;
  g->states_for_whitespace = states_for_whitespace;
  g->states_for_all_nterms = states_for_all_nterms;
  g->tokenizer = tokenizer;
  g->longest_match = longest_match;
  g->scanner_blocks = scanner_blocks;
  g->scanner_block_size = scanner_block_size;
  
  if (!(str = (unsigned char*)sbuf_read(grammar_pathname)))
    d_fail("unable to read grammar file '%s'", grammar_pathname);
  mkdparse_from_string(g, (char*)str);
  str = 0;
  if (write_binary_tables_to_string(g, &str, &str_len) < 0)
    d_fail("unable to write tables to string '%s'", grammar_pathname);
  free_D_Grammar(g);

  /* execute parser */
  parser_tables_gram = read_binary_tables_from_string(str, spec_code, final_code);
  p = new_D_Parser(parser_tables_gram, SIZEOF_MY_PARSE_NODE);
  p->save_parse_tree = save_parse_tree;
  p->ambiguity_fn = ambiguity_count_fn;
  p->partial_parses = partial_parses;
  p->dont_fixup_internal_productions = !fixup;
  p->fixup_EBNF_productions = fixup_ebnf;
  p->dont_compare_stacks = !compare_stacks;
  p->commit_actions_interval = commit_actions_interval;
  p->start_state = start_state;
  for (i = 1; i < arg_state.nfile_arguments; i++) {
    p->loc.pathname = arg_state.file_argument[i];
    p->loc.line = 1;
    p->loc.col = p->loc.previous_col = 0;
    if (buf_read(arg_state.file_argument[i], &buf, &len) > 0)
      pn = dparse(p, buf, len);
    else 
      d_fail("unable to read file '%s'", arg_state.file_argument[i]);
    if (pn) {
      free_D_ParseNode(p, pn);
      pn = 0;
    } else {
      fn = d_dup_pathname_str(p->loc.pathname);
      fprintf(stderr, "fatal error, '%s' line %d\n", fn, p->loc.line);
      FREE(fn);
    }
    if (buf)
      FREE(buf);
  }
  free_D_Parser(p);
  free_args(&arg_state);
  exit(0);
}
コード例 #5
0
ファイル: iptv_udp.c プロジェクト: hencha69/tvheadend
static ssize_t
iptv_udp_read ( iptv_mux_t *im, size_t *off )
{
  return sbuf_read(&im->mm_iptv_buffer, im->mm_iptv_fd);
}