コード例 #1
0
ファイル: json.c プロジェクト: chuanqi305/yacmd
int json_get_line(struct JSON *json)
{
	int line = 0, c = 0, offset = 0;
	struct JSON *root = json;
	while(root->parent!=NULL){
		root = root->parent;
	}
	offset = (json->position) - (root->position);
	offset_to_line(root->position, offset, &line, &c);
	return line;
}
コード例 #2
0
ファイル: json.c プロジェクト: chuanqi305/yacmd
struct JSON *json_parse(char *string)
{
	struct JSON *root;
	int ret = 0;
	int offset = 0; 
	char *msg = "no error.";
	char *tmp;
	int line, c;
	int len = strlen(string);
	char *str = NULL;

	if(string==NULL){
		return NULL;
	}
	str = (char *)malloc(len + 2);
	if(str==NULL){
		return NULL;
	}
	memcpy(str, string, len+1);

	root = alloc_node();
	if(root==NULL){
		return NULL;
	}
	ret = json_parse_all(str, root, &offset, &msg);
	if(ret==0){
		return root;
	}
	else{
		offset_to_line(str, offset, &line, &c);
		printf("error at line:%d character:%d, %s\n", line, c, msg);
		tmp = str + offset;
		while(*tmp!='\0' && *tmp!='\n'){
			tmp++;
		}	
		*tmp = '\0';
		printf("%s\n", str + offset - (c - 1));
		printf("%*c\n", c, '^');
		json_release(root);
		return NULL;
	}
}
コード例 #3
0
ファイル: term_redisplay.c プロジェクト: M1lan/zile
static void
draw_status_line (size_t line, Window wp)
{
  term_attrset (FONT_REVERSE);

  term_move (line, 0);
  for (size_t i = 0; i < get_window_ewidth (wp); ++i)
    term_addstr ("-");

  const char *eol_type;
  if (get_buffer_eol (cur_bp) == coding_eol_cr)
    eol_type = "(Mac)";
  else if (get_buffer_eol (cur_bp) == coding_eol_crlf)
    eol_type = "(DOS)";
  else
    eol_type = ":";

  term_move (line, 0);
  size_t n = offset_to_line (get_window_bp (wp), window_o (wp));
  astr as = astr_fmt ("--%s%2s  %-15s   %s %-9s (Fundamental",
                      eol_type, make_mode_line_flags (wp), get_buffer_name (get_window_bp (wp)),
                      make_screen_pos (wp), astr_cstr (astr_fmt ("(%zu,%zu)", n + 1,
                                                                 get_goalc_bp (get_window_bp (wp), window_o (wp)))));

  if (get_buffer_autofill (get_window_bp (wp)))
    astr_cat_cstr (as, " Fill");
  if (thisflag & FLAG_DEFINING_MACRO)
    astr_cat_cstr (as, " Def");
  if (get_buffer_isearch (get_window_bp (wp)))
    astr_cat_cstr (as, " Isearch");

  astr_cat_char (as, ')');
  term_addstr (astr_cstr (as));

  term_attrset (FONT_NORMAL);
}