예제 #1
0
파일: gscanner.c 프로젝트: 0x0all/ROOT
void
g_scanner_input_text (GScanner	  *scanner,
		      const gchar *text,
		      guint	   text_len)
{
  g_return_if_fail (scanner != NULL);
  if (text_len)
    g_return_if_fail (text != NULL);
  else
    text = NULL;

  if (scanner->input_fd >= 0)
    g_scanner_sync_file_offset (scanner);

  scanner->token = G_TOKEN_NONE;
  scanner->value.v_int = 0;
  scanner->line = 1;
  scanner->position = 0;
  scanner->next_token = G_TOKEN_NONE;

  scanner->input_fd = -1;
  scanner->text = text;
  scanner->text_end = text + text_len;

  if (scanner->buffer)
    {
      g_free (scanner->buffer);
      scanner->buffer = NULL;
    }
}
예제 #2
0
파일: gscanner.c 프로젝트: north0808/haina
static guchar
g_scanner_get_char (GScanner	*scanner,
		    guint	*line_p,
		    guint	*position_p)
{
  guchar fchar;

  if (scanner->text < scanner->text_end)
    fchar = *(scanner->text++);
  else if (scanner->input_fd >= 0)
    {
      gint count;
      gchar *buffer;

      buffer = scanner->buffer;
      do
	{//scott
	  //count = read (scanner->input_fd, buffer, READ_BUFFER_SIZE);
		count = fread (buffer,1,READ_BUFFER_SIZE,_wfdopen(scanner->input_fd,L"r")); // scott
	}
      while (count == -1 && (glib_errno == EINTR || glib_errno == EAGAIN));

      if (count < 1)
	{
	  scanner->input_fd = -1;
	  fchar = 0;
	}
      else
	{
	  scanner->text = buffer + 1;
	  scanner->text_end = buffer + count;
	  fchar = *buffer;
	  if (!fchar)
	    {
	      g_scanner_sync_file_offset (scanner);
	      scanner->text_end = scanner->text;
	      scanner->input_fd = -1;
	    }
	}
    }
  else
    fchar = 0;
  
  if (fchar == '\n')
    {
      (*position_p) = 0;
      (*line_p)++;
    }
  else if (fchar)
    {
      (*position_p)++;
    }
  
  return fchar;
}
예제 #3
0
파일: gscanner.c 프로젝트: 0x0all/ROOT
void
g_scanner_input_file (GScanner *scanner,
		      gint	input_fd)
{
  g_return_if_fail (scanner != NULL);
  g_return_if_fail (input_fd >= 0);

  if (scanner->input_fd >= 0)
    g_scanner_sync_file_offset (scanner);

  scanner->token = G_TOKEN_NONE;
  scanner->value.v_int = 0;
  scanner->line = 1;
  scanner->position = 0;
  scanner->next_token = G_TOKEN_NONE;

  scanner->input_fd = input_fd;
  scanner->text = NULL;
  scanner->text_end = NULL;

  if (!scanner->buffer)
    scanner->buffer = g_new (gchar, READ_BUFFER_SIZE + 1);
}
예제 #4
0
파일: starfile.c 프로젝트: cmatei/GCX
/* read a star file frame (one s-expression) from the given file pointer,
   and return the stf of the root node */
struct stf *stf_read_frame(FILE *fp)
{
	GScanner *scan;
	GTokenType tok;
	int level = 0;
	int minus = 0;
	GList *sl;
	struct stf *ret = NULL;
	struct stf *lstf[STF_MAX_DEPTH];
	struct stf *stf=NULL, *nstf = NULL;

	lstf[0] = NULL;
	scan = init_scanner();
	g_scanner_input_file(scan, fileno(fp));
	do {
		tok = g_scanner_get_next_token(scan);
//		d3_printf("level %d ", level);
//		print_token(scan, tok);
		if (level == 0 && tok != '(')
			continue;
		if (level == 1 && tok == ')') {
			ret = lstf[0];
			break;
		}
		if (minus)
			minus --;
		switch(tok) {
		case '(':
			if (level >= STF_MAX_DEPTH - 1)
				break;
			nstf = stf_new();
			lstf[level] = nstf;
			if (level > 0) {
				stf->next = nstf;
				STF_SET_LIST(nstf, stf_new());
				stf = STF_LIST(nstf);
			} else {
				stf = nstf;
			}
			level ++;
			break;
		case ')':
			stf = lstf[level-1];
			level --;
			break;
		case G_TOKEN_SYMBOL:
			if (!STF_IS_NIL(stf)) {
				nstf = stf_new();
				stf->next = nstf;
				stf = nstf;
			}
			STF_SET_SYMBOL(stf, intval(scan));
			if (intval(scan) == SYM_STARS) {
				sl = read_star_list(scan);
				if (sl == NULL)
					break;
				nstf = stf_new();
				stf->next = nstf;
				stf = nstf;
				STF_SET_GLIST(stf, sl);
			}
			break;
		case '-':
			minus = 2;
			break;
		case G_TOKEN_FLOAT:
			if (!STF_IS_NIL(stf)) {
				nstf = stf_new();
				stf->next = nstf;
				stf = nstf;
			}
			STF_SET_DOUBLE(stf, minus?-floatval(scan):floatval(scan));
			break;
		case G_TOKEN_STRING:
			if (!STF_IS_NIL(stf)) {
				nstf = stf_new();
				stf->next = nstf;
				stf = nstf;
			}
			STF_SET_STRING(stf, strdup(stringval(scan)));
			break;
		case G_TOKEN_IDENTIFIER:
			err_printf("unexpected identifier: %s\n", stringval(scan));
//			if (!STF_IS_NIL(stf)) {
//				nstf = stf_new();
//				stf->next = nstf;
//				stf = nstf;
//			}
//			STF_SET_IDENT(stf, strdup(stringval(scan)));
//			break;
		default:
			err_printf("unexected token %d\n", tok);
			break;
		}
	} while (tok != G_TOKEN_EOF);
	g_scanner_sync_file_offset(scan);
	g_scanner_destroy(scan);
	return ret;
}