Beispiel #1
0
bool
pager_read(struct view *view, char *data)
{
	if (!data)
		return TRUE;

	return pager_common_read(view, data, get_line_type(data));
}
Beispiel #2
0
bool
pager_read(struct view *view, struct buffer *buf)
{
	if (!buf)
		return true;

	return pager_common_read(view, buf->data, get_line_type(buf->data), NULL);
}
Beispiel #3
0
/*!
  \brief Read feature from OGR layer at given offset (level 1)
  
  This function implements random access on level 1.

  \param Map pointer to Map_info structure 
  \param[out] line_p container used to store line points within
  \param[out] line_c container used to store line categories within
  \param offset given offset 
  
  \return line type
  \return 0 dead line
  \return -2 no more features
  \return -1 out of memory
*/
int V1_read_line_ogr(struct Map_info *Map,
		     struct line_pnts *line_p, struct line_cats *line_c, off_t offset)
{
    long FID;
    int type;
    OGRGeometryH hGeom;

    G_debug(4, "V1_read_line_ogr() offset = %lu offset_num = %lu",
	    (long) offset, (long) Map->fInfo.ogr.offset_num);

    if (offset >= Map->fInfo.ogr.offset_num)
	return -2;
    
    if (line_p != NULL)
	Vect_reset_line(line_p);
    if (line_c != NULL)
	Vect_reset_cats(line_c);

    FID = Map->fInfo.ogr.offset[offset];
    G_debug(4, "  FID = %ld", FID);
    
    /* coordinates */
    if (line_p != NULL) {
	/* Read feature to cache if necessary */
	if (Map->fInfo.ogr.feature_cache_id != FID) {
	    G_debug(4, "Read feature (FID = %ld) to cache", FID);
	    if (Map->fInfo.ogr.feature_cache) {
		OGR_F_Destroy(Map->fInfo.ogr.feature_cache);
	    }
	    Map->fInfo.ogr.feature_cache =
		OGR_L_GetFeature(Map->fInfo.ogr.layer, FID);
	    if (Map->fInfo.ogr.feature_cache == NULL) {
		G_fatal_error(_("Unable to get feature geometry, FID %ld"),
			      FID);
	    }
	    Map->fInfo.ogr.feature_cache_id = FID;
	}
	
	hGeom = OGR_F_GetGeometryRef(Map->fInfo.ogr.feature_cache);
	if (hGeom == NULL) {
	    G_fatal_error(_("Unable to get feature geometry, FID %ld"),
			  FID);
	}
	
	type = read_line(Map, hGeom, offset + 1, line_p);
    }
    else {
	type = get_line_type(Map, FID);
    }

    /* category */
    if (line_c != NULL) {
	Vect_cat_set(line_c, 1, (int) FID);
    }

    return type;
}
Beispiel #4
0
static bool
log_read(struct view *view, struct buffer *buf)
{
	struct line *line = NULL;
	enum line_type type;
	struct log_state *state = view->private;
	size_t len;
	char *commit;
	char *data;

	if (!buf)
		return true;

	data = buf->data;
	commit = strstr(data, "commit ");
	if (commit && get_graph_indent(data) == commit - data)
		state->graph_indent = commit - data;

	type = get_line_type(data + state->graph_indent);
	len = strlen(data + state->graph_indent);

	if (type == LINE_COMMIT)
		state->commit_title_read = true;
	else if (state->commit_title_read && len < 1) {
		state->commit_title_read = false;
		state->after_commit_header = true;
	} else if (state->after_commit_header && len < 1) {
		state->after_commit_header = false;
		state->reading_diff_stat = true;
	} else if (state->reading_diff_stat) {
		line = diff_common_add_diff_stat(view, data, state->graph_indent);
		if (line) {
			if (state->graph_indent)
				line->graph_indent = 1;
			return true;
		}
		state->reading_diff_stat = false;
	}

	if (!pager_common_read(view, data, type, &line))
		return false;
	if (line && state->graph_indent)
		line->graph_indent = 1;
	return true;
}
Beispiel #5
0
static bool
branch_read(struct view *view, char *line)
{
	struct branch_state *state = view->private;
	const char *title = NULL;
	const struct ident *author = NULL;
	struct time time = {};
	size_t i;

	if (!line)
		return TRUE;

	switch (get_line_type(line)) {
	case LINE_COMMIT:
		string_copy_rev_from_commit_line(state->id, line);
		return TRUE;

	case LINE_AUTHOR:
		parse_author_line(line + STRING_SIZE("author "), &author, &time);
		break;

	default:
		title = line + STRING_SIZE("title ");
	}

	for (i = 0; i < view->lines; i++) {
		struct branch *branch = view->line[i].data;

		if (strcmp(branch->ref->id, state->id))
			continue;

		if (author) {
			branch->author = author;
			branch->time = time;
		}

		if (title)
			string_expand(branch->title, sizeof(branch->title), title, 1);

		view->line[i].dirty = TRUE;
	}

	return TRUE;
}
Beispiel #6
0
t_map		*parse_lemin()
{
  t_map		*map;
  char		*buffer;
  int		step;
  t_info	info;

  init_map(&map);
  step = 0;
  info.command = 0;
  while ((buffer = get_next_line(0)) != NULL)
    {
      info.type = get_line_type(buffer);
      info.command = parse_type(info, buffer, &step, map);
      info.command = get_command(info.command, step, map);
      free(buffer);
    }
  is_valid_map(map);
  return (map);
}
Beispiel #7
0
static bool
tree_read_date(struct view *view, struct buffer *buf, struct tree_state *state)
{
	char *text = buf ? buf->data : NULL;

	if (!text && state->read_date) {
		state->read_date = FALSE;
		return TRUE;

	} else if (!text) {
		/* Find next entry to process */
		const char *log_file[] = {
			"git", "log", encoding_arg, "--no-color", "--pretty=raw",
				"--cc", "--raw", view->ops->id, "--", "%(directory)", NULL
		};

		if (!view->lines) {
			tree_entry(view, LINE_HEADER, view->env->directory, NULL, NULL, 0);
			tree_entry(view, LINE_DIRECTORY, "..", "040000", view->ref, 0);
			report("Tree is empty");
			return TRUE;
		}

		if (!begin_update(view, repo.cdup, log_file, OPEN_EXTRA)) {
			report("Failed to load tree data");
			return TRUE;
		}

		state->read_date = TRUE;
		return FALSE;

	} else if (*text == 'c' && get_line_type(text) == LINE_COMMIT) {
		string_copy_rev_from_commit_line(state->commit, text);

	} else if (*text == 'a' && get_line_type(text) == LINE_AUTHOR) {
		parse_author_line(text + STRING_SIZE("author "),
				  &state->author, &state->author_time);

	} else if (*text == ':') {
		char *pos;
		size_t annotated = 1;
		size_t i;

		pos = strrchr(text, '\t');
		if (!pos)
			return TRUE;
		text = pos + 1;
		if (*view->env->directory && !strncmp(text, view->env->directory, strlen(view->env->directory)))
			text += strlen(view->env->directory);
		pos = strchr(text, '/');
		if (pos)
			*pos = 0;

		for (i = 1; i < view->lines; i++) {
			struct line *line = &view->line[i];
			struct tree_entry *entry = line->data;

			annotated += !!entry->author;
			if (entry->author || strcmp(entry->name, text))
				continue;

			string_copy_rev(entry->commit, state->commit);
			entry->author = state->author;
			entry->time = state->author_time;
			line->dirty = 1;
			view_column_info_update(view, line);
			break;
		}

		if (annotated == view->lines)
			io_kill(view->pipe);
	}
	return TRUE;
}
int file_compare(char* filename1, char* filename2, int* err_line1, int* err_line2)
{
    FILE* fp1 = NULL;
    FILE* fp2 = NULL;

    char* line_ptr1 = NULL;
    char* line_ptr2 = NULL;

    size_t len1 = 0;
    size_t len2 = 0;

    ssize_t read1;
    ssize_t read2;

    int diff_count = 0;

    int line_count1 = 0;
    int line_count2 = 0;

    *err_line1 = 0;
    *err_line2 = 0;

    // Open files for read
    if((fp1 = fopen(filename1, "r")) == NULL)
    {
        fprintf(stderr, "Unable to open: %s\n", filename1);
        exit(EXIT_FAILURE);
    }
    if((fp2 = fopen(filename2, "r")) == NULL)
    {
        fprintf(stderr, "Unable to open: %s\n", filename2);
        exit(EXIT_FAILURE);
    }

    // Get both to first block
    while(((read1 = getline(&line_ptr1, &len1, fp1)) != -1) &&
            (get_line_type(line_ptr1) != BLOCK_START)) { line_count1++; }

    while(((read2 = getline(&line_ptr2, &len2, fp2)) != -1) &&
            (get_line_type(line_ptr2) != BLOCK_START)) { line_count2++; }

    while(true)
    {
        int new_diff = 0;

        // Keep going until hit a NUMBERS line
        while(((read1 = getline(&line_ptr1, &len1, fp1)) != -1) &&
                (get_line_type(line_ptr1) != NUMBERS)) { line_count1++; }

        while(((read2 = getline(&line_ptr2, &len2, fp2)) != -1) &&
                (get_line_type(line_ptr2) != NUMBERS)) { line_count2++; }

        // If one file is at the end, the remainder of the other is different
        if(read1 == -1)
        {
            while((read2 = getline(&line_ptr2, &len2, fp2)) != -1)
            {
                diff_count++;
                puts(line_ptr2);
            }
            break;
        }
        if(read2 == -1)
        {
            while((read1 = getline(&line_ptr1, &len1, fp1)) != -1)
            {
                diff_count++;
                puts(line_ptr1);
            }
            break;
        }

        if((new_diff = line_compare(line_ptr1, line_ptr2)) > 0)
        {
            if(*err_line1 == 0)
                *err_line1 = line_count1;

            if(*err_line2 == 0)
                *err_line2 = line_count2;

            diff_count += new_diff;
            printf("%s: %s", filename1, line_ptr1);
            printf("%s: %s\n", filename2, line_ptr2);
        }
    }

    free(line_ptr1);
    free(line_ptr2);

    fclose(fp1);
    fclose(fp2);

    return diff_count;
}