Beispiel #1
0
/* ------------------------------------------------------------------------*/
static bool write_bookmark(bool create_bookmark_file, const char *bookmark)
{
    bool ret=true;

    if (!bookmark)
    {
       ret = false; /* something didn't happen correctly, do nothing */
    }
    else
    {
        if (global_settings.usemrb)
            ret = add_bookmark(RECENT_BOOKMARK_FILE, bookmark, true);


        /* writing the bookmark */
        if (create_bookmark_file)
        {
            char* name = playlist_get_name(NULL, global_temp_buffer,
                                       sizeof(global_temp_buffer));
            if (generate_bookmark_file_name(name))
            {
                ret = ret & add_bookmark(global_bookmark_file_name, bookmark, false);
            }
            else
            {
                ret = false; /* generating bookmark file failed */
            }
        }
    }

    splash(HZ, ret ? ID2P(LANG_BOOKMARK_CREATE_SUCCESS)
           : ID2P(LANG_BOOKMARK_CREATE_FAILURE));

    return ret;
}
Beispiel #2
0
/* Adds 'H' and 'z' default bookmarks. */
static void
add_default_bookmarks(void)
{
	LOG_FUNC_ENTER;

	add_bookmark('H', cfg.home_dir, "../");
	add_bookmark('z', cfg.config_dir, "../");
}
Beispiel #3
0
static void
create_rc_file(void)
{
	char command[PATH_MAX];

	snprintf(command, sizeof(command), CP_RC);
	file_exec(command);
	add_bookmark('H', getenv("HOME"), "../");
	add_bookmark('z', cfg.config_dir, "../");
}
Beispiel #4
0
int load_bookmarks(char* file_name)
{
  int bookmarkFD=-1;
  int i;
  bookmark_t new_bookmark;
  
  memset(&bookmark_set, 0, sizeof(bookmark_set));

  bookmarkFD = open(file_name, O_RDONLY);
  if(bookmarkFD != -1) {
    read(bookmarkFD, &bookmark_set, sizeof(bookmark_set));
    bookmark_set.first_bookmark = NULL;
    bookmark_set.last_bookmark = NULL;

    for(i=0; i < bookmark_set.num_bookmarks; ++i) {
      read(bookmarkFD, &new_bookmark, sizeof(new_bookmark));
      add_bookmark(new_bookmark.name, new_bookmark.offset, -1);
    }
    close(bookmarkFD);
    bookmarks = 1;
    
    return 1;
  }
  else
    print_error("Can not open bookmark file: %s", file_name);
  
  return 0;
}
Beispiel #5
0
int create_bookmark_at(offset_t offset)
{
  char buf[60];
  int idx;
  bookmark_t* current;

  if(!bookmarks) {
    memset(&bookmark_set, 0, sizeof(bookmark_set));
    print_info("New bookmark set!\n");
    print_info("What do you want to call it?\n");
    print_info("\t");
    get_a_str(bookmark_set.set_title, 60);
    bookmarks = 1;
  }
  print_info("What do you want to call this bookmark?\n");
  print_info("\t");
  get_a_str(buf, 60);
  idx = 0;
  current = bookmark_set.first_bookmark;

  while(current != NULL && offset > current->offset) {
    ++idx;
    current = current->next;
  }
  if(current==NULL)
    idx = -1;

  ++(bookmark_set.num_bookmarks);
  return add_bookmark(buf, offset, idx);
}
static void
message_add_cb (PlumaMessageBus *bus,
                PlumaMessage    *message,
                PlumaWindow     *window)
{
	GtkSourceView *view = NULL;
	GtkTextIter iter;

	message_get_view_iter (window, message, &view, &iter);

	if (!view)
	{
		return;
	}

	add_bookmark (GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))),
	              &iter);
}
static void
toggle_bookmark (GtkSourceBuffer *buffer,
                 GtkTextIter     *iter)
{
	GtkTextIter start;
	GtkSourceMark *bookmark = NULL;

	bookmark = get_bookmark_and_iter (buffer, iter, &start);

	if (bookmark != NULL)
	{
		remove_bookmark (buffer, &start);
	}
	else
	{
		add_bookmark (buffer, &start);
	}
}
Beispiel #8
0
int
read_config_file(void)
{
	FILE *fp;
	char config_file[PATH_MAX];
	char line[MAX_LEN];
	char *s1 = NULL;
	char *s2 = NULL;
	char *s3 = NULL;
	char *sx = NULL;
	int args;

	snprintf(config_file, sizeof(config_file), "%s/vifmrc", cfg.config_dir);


	if((fp = fopen(config_file, "r")) == NULL)
	{
		fprintf(stdout, "Unable to find configuration file.\n Using defaults.");
		load_default_configuration();
		return 0;
	}

	while(fgets(line, MAX_LEN, fp))
	{
		args = 0;
		if(line[0] == '#')
			continue;

		if((sx = s1 = strchr(line, '=')) != NULL)
		{
			s1++;
			chomp(s1);
			*sx = '\0';
			args = 1;
		}
		else
			continue;
		if((sx = s2 = strchr(s1, '=')) != NULL)
		{
			s2++;
			chomp(s2);
			*sx = '\0';
			args = 2;
		}
		/* COMMAND is handled here so that the command can have an '=' */
		if(!strcmp(line, "COMMAND"))
			add_command(s1, s2);
		else if((args == 2) && ((sx = s3 = strchr(s2, '=')) != NULL))
		{
			s3++;
			chomp(s3);
			*sx = '\0';
			args = 3;
		}
		if(args == 1)
		{
			if(!strcmp(line, "VI_COMMAND"))
			{
				if(cfg.vi_command != NULL)
					free(cfg.vi_command);

				cfg.vi_command = strdup(s1);
				continue;
			}

			if(!strcmp(line, "USE_TRASH"))
			{
				cfg.use_trash = atoi(s1);
				continue;
			}
			if(!strcmp(line, "USE_ONE_WINDOW"))
			{
				cfg.show_one_window = atoi(s1);
				continue;
			}
			if(!strcmp(line, "USE_SCREEN"))
			{
				cfg.use_screen = atoi(s1);
				continue;
			}
			if(!strcmp(line, "HISTORY_LENGTH"))
			{
				cfg.history_len = atoi(s1);
				continue;
			}
			if(!strcmp(line, "LEFT_WINDOW_SORT_TYPE"))
			{
				lwin.sort_type = atoi(s1);
				continue;
			}
			if(!strcmp(line, "RIGHT_WINDOW_SORT_TYPE"))
			{
				rwin.sort_type = atoi(s1);
				continue;
			}
			if(!strcmp(line, "LWIN_FILTER"))
			{
				lwin.filename_filter = (char *)realloc(lwin.filename_filter, 
				strlen(s1) +1);
				strcpy(lwin.filename_filter, s1);
				lwin.prev_filter = (char *)realloc(lwin.prev_filter, 
					strlen(s1) +1);
				strcpy(lwin.prev_filter, s1);
				continue;
			}
			if(!strcmp(line, "LWIN_INVERT"))
			{
				lwin.invert = atoi(s1);
				continue;
			}
			if(!strcmp(line, "RWIN_FILTER"))
			{
				rwin.filename_filter = (char *)realloc(rwin.filename_filter, 
				strlen(s1) +1);
				strcpy(rwin.filename_filter, s1);
				rwin.prev_filter = (char *)realloc(rwin.prev_filter, 
					strlen(s1) +1);
				strcpy(rwin.prev_filter, s1);
				continue;
			}
			if(!strcmp(line, "RWIN_INVERT"))
			{
				rwin.invert = atoi(s1);
				continue;
			}
			if(!strcmp(line, "USE_VIM_HELP"))
			{
				cfg.use_vim_help = atoi(s1);
				continue;
			}
			if(!strcmp(line, "RUN_EXECUTABLE"))
			{
				cfg.auto_execute = atoi(s1);
				continue;
			}
/*_SZ_BEGIN_*/
			if(!strcmp(line, "FUSE_HOME"))
			{
				if(cfg.fuse_home != NULL)
					free(cfg.fuse_home);

				cfg.fuse_home = strdup(s1);
				continue;
			}
/*_SZ_END_*/
		}
		if(args == 3)
		{
			if(!strcmp(line, "FILETYPE"))
			{
				add_filetype(s1, s2, s3);
				continue;
			}
			if(!strcmp(line, "BOOKMARKS"))
			{
				if(isalnum(*s1))
					add_bookmark(*s1, s2, s3);
				continue;
			}
		}
	}

	fclose(fp);

	read_color_scheme_file();

	return 1;
}
Beispiel #9
0
/* Returns zero on error */
static int
read_config_file(const char *config_file)
{
	FILE *fp;
	char line[4096];
	char *s1 = NULL;
	char *s2 = NULL;
	char *s3 = NULL;
	char *s4 = NULL;
	char *sx = NULL;

	if((fp = fopen(config_file, "r")) == NULL)
		return 0;

	while(fgets(line, sizeof(line), fp))
	{
		int args;

		if(line[0] == '#')
			continue;

		if((sx = s1 = strchr(line, '=')) != NULL)
		{
			s1++;
			chomp(s1);
			*sx = '\0';
			args = 1;
		}
		else
			continue;
		if((sx = s2 = strchr(s1, '=')) != NULL)
		{
			s2++;
			chomp(s2);
			*sx = '\0';
			args = 2;
		}
		/* COMMAND is handled here so that the command can have an '=' */
		if(!strcmp(line, "COMMAND"))
			add_command(s1, s2);
		else
		{
			if(args == 2 && (sx = s3 = strchr(s2, '=')) != NULL)
			{
				s3++;
				chomp(s3);
				*sx = '\0';
				args = 3;
			}
			if(args == 3 && (sx = s4 = strchr(s3, '=')) != NULL)
			{
				s4++;
				chomp(s4);
				*sx = '\0';
				args = 4;
			}
		}
		if(args == 1)
		{
			if(!strcmp(line, "VI_COMMAND"))
			{
				options.vicmd = strdup(s1);
				continue;
			}
			if(!strcmp(line, "USE_TRASH"))
			{
				options.trash = atoi(s1);
				continue;
			}
			if(!strcmp(line, "UNDO_LEVELS"))
			{
				options.undolevels = atoi(s1);
				continue;
			}
			if(!strcmp(line, "USE_ONE_WINDOW"))
			{
				tui.windows = atoi(s1) ? 1 : 2;
				continue;
			}
			if(!strcmp(line, "USE_SCREEN"))
			{
				state.use_screen = atoi(s1);
				continue;
			}
			if(!strcmp(line, "HISTORY_LENGTH"))
			{
				options.history = atoi(s1);
				continue;
			}
			if(!strcmp(line, "FAST_RUN"))
			{
				options.fastrun = atoi(s1);
				continue;
			}
			if(!strcmp(line, "SORT_NUMBERS"))
			{
				options.sortnumbers = atoi(s1);
				continue;
			}
			if(!strcmp(line, "LEFT_WINDOW_SORT_TYPE"))
			{
				tui.lwin_sort = atoi(s1);
				continue;
			}
			if(!strcmp(line, "RIGHT_WINDOW_SORT_TYPE"))
			{
				tui.rwin_sort = atoi(s1);
				continue;
			}
			if(!strcmp(line, "LWIN_FILTER"))
			{
				state.lwin_filter = strdup(s1);
				continue;
			}
			if(!strcmp(line, "LWIN_INVERT"))
			{
				state.lwin_inverted = atoi(s1);
				continue;
			}
			if(!strcmp(line, "RWIN_FILTER"))
			{
				state.rwin_filter = strdup(s1);
				continue;
			}
			if(!strcmp(line, "RWIN_INVERT"))
			{
				state.rwin_inverted = atoi(s1);
				continue;
			}
			if(!strcmp(line, "USE_VIM_HELP"))
			{
				options.vimhelp = atoi(s1);
				continue;
			}
			if(!strcmp(line, "SAVE_LOCATION"))
			{
				if(!atoi(s1))
				{
					vifminfo &= ~VIFMINFO_DHISTORY;
					vifminfo &= ~VIFMINFO_SAVEDIRS;
				}
				else
				{
					vifminfo |= VIFMINFO_DHISTORY;
					vifminfo |= VIFMINFO_SAVEDIRS;
				}
				continue;
			}
			if(!strcmp(line, "LWIN_PATH"))
			{
				lwin_dir = strdup(s1);
				continue;
			}
			if(!strcmp(line, "RWIN_PATH"))
			{
				rwin_dir = strdup(s1);
				continue;
			}
			if(!strcmp(line, "FOLLOW_LINKS"))
			{
				options.followlinks = atoi(s1);
				continue;
			}
			if(!strcmp(line, "RUN_EXECUTABLE"))
			{
				options.runexec = atoi(s1);
				continue;
			}
			if(!strcmp(line, "USE_IEC_PREFIXES"))
			{
				options.iec = atoi(s1);
				continue;
			}
			if(!strcmp(line, "COLOR_SCHEME"))
			{
				color_scheme = strdup(s1);
				continue;
			}
			if(!strcmp(line, "TIME_STAMP_FORMAT"))
			{
				options.timefmt = strdup(s1);
				continue;
			}
			if(!strcmp(line, "FUSE_HOME"))
			{
				options.fusehome = strdup(s1);
				continue;
			}
		}
		if(args == 3)
		{
			if(!strcmp(line, "BOOKMARKS"))
			{
				if(isalnum(*s1))
					add_bookmark(*s1, s2, s3);
				continue;
			}
			if(!strcmp(line, "FILETYPE")) /* backward compatibility */
			{
				add_filetype(s1, s2, "", s3);
				continue;
			}
		}
		if(args == 4)
		{
			if(!strcmp(line, "FILETYPE"))
			{
				add_filetype(s1, s2, s3, s4);
				continue;
			}
		}
	}

	fclose(fp);

	return 1;
}
Beispiel #10
0
void
read_info_file(int reread)
{
	/* TODO: refactor this function read_info_file() */

	FILE *fp;
	char info_file[PATH_MAX];
	char *line = NULL, *line2 = NULL, *line3 = NULL, *line4 = NULL;

	snprintf(info_file, sizeof(info_file), "%s/vifminfo", cfg.config_dir);

	if((fp = fopen(info_file, "r")) == NULL)
		return;

	while((line = read_vifminfo_line(fp, line)) != NULL)
	{
		const char type = line[0];
		const char *const line_val = line + 1;

		if(type == LINE_TYPE_COMMENT || type == '\0')
			continue;

		if(type == LINE_TYPE_OPTION)
		{
			if(line_val[0] == '[' || line_val[0] == ']')
			{
				FileView *v = curr_view;
				curr_view = (line_val[0] == '[') ? &lwin : &rwin;
				process_set_args(line_val + 1);
				curr_view = v;
			}
			else
			{
				process_set_args(line_val);
			}
		}
		else if(type == LINE_TYPE_FILETYPE)
		{
			if((line2 = read_vifminfo_line(fp, line2)) != NULL)
			{
				/* This is to prevent old builtin fake associations to be loaded. */
				if(!ends_with(line2, "}" VIFM_PSEUDO_CMD))
				{
					set_programs(line_val, line2, 0,
							curr_stats.env_type == ENVTYPE_EMULATOR_WITH_X);
				}
			}
		}
		else if(type == LINE_TYPE_XFILETYPE)
		{
			if((line2 = read_vifminfo_line(fp, line2)) != NULL)
			{
				set_programs(line_val, line2, 1,
						curr_stats.env_type == ENVTYPE_EMULATOR_WITH_X);
			}
		}
		else if(type == LINE_TYPE_FILEVIEWER)
		{
			if((line2 = read_vifminfo_line(fp, line2)) != NULL)
			{
				set_fileviewer(line_val, line2);
			}
		}
		else if(type == LINE_TYPE_COMMAND)
		{
			if((line2 = read_vifminfo_line(fp, line2)) != NULL)
			{
				char *cmdadd_cmd;
				if((cmdadd_cmd = format_str("command %s %s", line_val, line2)) != NULL)
				{
					exec_commands(cmdadd_cmd, curr_view, GET_COMMAND);
					free(cmdadd_cmd);
				}
			}
		}
		else if(type == LINE_TYPE_BOOKMARK)
		{
			if((line2 = read_vifminfo_line(fp, line2)) != NULL)
			{
				if((line3 = read_vifminfo_line(fp, line3)) != NULL)
				{
					add_bookmark(line_val[0], line2, line3);
				}
			}
		}
		else if(type == LINE_TYPE_ACTIVE_VIEW)
		{
			/* don't change active view on :restart command */
			if(line_val[0] == 'r' && !reread)
			{
				update_view_title(&lwin);
				update_view_title(&rwin);
				curr_view = &rwin;
				other_view = &lwin;
			}
		}
		else if(type == LINE_TYPE_QUICK_VIEW_STATE)
		{
			const int i = atoi(line_val);
			curr_stats.view = (i == 1);
		}
		else if(type == LINE_TYPE_WIN_COUNT)
		{
			const int i = atoi(line_val);
			cfg.show_one_window = (i == 1);
			curr_stats.number_of_windows = (i == 1) ? 1 : 2;
		}
		else if(type == LINE_TYPE_SPLIT_ORIENTATION)
		{
			curr_stats.split = (line_val[0] == 'v') ? VSPLIT : HSPLIT;
		}
		else if(type == LINE_TYPE_SPLIT_POSITION)
		{
			curr_stats.splitter_pos = atof(line_val);
		}
		else if(type == LINE_TYPE_LWIN_SORT)
		{
			get_sort_info(&lwin, line_val);
		}
		else if(type == LINE_TYPE_RWIN_SORT)
		{
			get_sort_info(&rwin, line_val);
		}
		else if(type == LINE_TYPE_LWIN_HIST)
		{
			int pos;

			if(line_val[0] == '\0')
			{
				if(reread)
					continue;
				if(lwin.history_num > 0)
					strcpy(lwin.curr_dir, lwin.history[lwin.history_pos].dir);
				continue;
			}

			if((line2 = read_vifminfo_line(fp, line2)) == NULL)
				continue;

			pos = read_possible_possible_pos(fp);
			get_history(&lwin, reread, line_val, line2, pos);
		}
		else if(type == LINE_TYPE_RWIN_HIST)
		{
			int pos;

			if(line_val[0] == '\0')
			{
				if(reread)
					continue;
				if(rwin.history_num > 0)
					strcpy(rwin.curr_dir, rwin.history[rwin.history_pos].dir);
				continue;
			}

			if((line2 = read_vifminfo_line(fp, line2)) == NULL)
				continue;

			pos = read_possible_possible_pos(fp);
			get_history(&rwin, reread, line_val, line2, pos);
		}
		else if(type == LINE_TYPE_CMDLINE_HIST)
		{
			inc_history(&cfg.cmd_history, &cfg.cmd_history_num, &cfg.history_len);
			save_command_history(line_val);
		}
		else if(type == LINE_TYPE_SEARCH_HIST)
		{
			inc_history(&cfg.search_history, &cfg.search_history_num,
					&cfg.history_len);
			save_search_history(line_val);
		}
		else if(type == LINE_TYPE_PROMPT_HIST)
		{
			inc_history(&cfg.prompt_history, &cfg.prompt_history_num,
					&cfg.history_len);
			save_prompt_history(line_val);
		}
		else if(type == LINE_TYPE_DIR_STACK)
		{
			if((line2 = read_vifminfo_line(fp, line2)) != NULL)
			{
				if((line3 = read_vifminfo_line(fp, line3)) != NULL)
				{
					if((line4 = read_vifminfo_line(fp, line4)) != NULL)
					{
						push_to_dirstack(line_val, line2, line3 + 1, line4);
					}
				}
			}
		}
		else if(type == LINE_TYPE_TRASH)
		{
			if((line2 = read_vifminfo_line(fp, line2)) != NULL)
			{
				if(!path_exists_at(cfg.trash_dir, line_val))
					continue;
				add_to_trash(line2, line_val);
			}
		}
		else if(type == LINE_TYPE_REG)
		{
			append_to_register(line_val[0], line_val + 1);
		}
		else if(type == LINE_TYPE_LWIN_FILT)
		{
			(void)replace_string(&lwin.prev_filter, line_val);
			set_filename_filter(&lwin, line_val);
		}
		else if(type == LINE_TYPE_RWIN_FILT)
		{
			(void)replace_string(&rwin.prev_filter, line_val);
			set_filename_filter(&rwin, line_val);
		}
		else if(type == LINE_TYPE_LWIN_FILT_INV)
		{
			const int i = atoi(line_val);
			lwin.invert = (i != 0);
		}
		else if(type == LINE_TYPE_RWIN_FILT_INV)
		{
			const int i = atoi(line_val);
			rwin.invert = (i != 0);
		}
		else if(type == LINE_TYPE_USE_SCREEN)
		{
			const int i = atoi(line_val);
			set_use_screen(i != 0);
		}
		else if(type == LINE_TYPE_COLORSCHEME)
		{
			strcpy(curr_stats.color_scheme, line_val);
		}
		else if(type == LINE_TYPE_LWIN_SPECIFIC || type == LINE_TYPE_RWIN_SPECIFIC)
		{
			FileView *view = (type == LINE_TYPE_LWIN_SPECIFIC) ? &lwin : &rwin;
			set_view_property(view, line_val[0], line_val + 1);
		}
	}

	free(line);
	free(line2);
	free(line3);
	free(line4);
	fclose(fp);
}