Example #1
0
int
main(int argc, char *argv[])
{
	char dir[PATH_MAX];
	char config_dir[PATH_MAX];
	char *console = NULL;
	int x;
	int rwin_args = 0;
	int lwin_args = 0;
	struct stat stat_buf;

	setlocale(LC_ALL, "");
	getcwd(dir, sizeof(dir));

	SetConsoleTitle("Vifm");

	/* Window initializations */
	rwin.curr_line = 0;
	rwin.top_line = 0;
	rwin.list_rows = 0;
	rwin.list_pos = 0;
	rwin.selected_filelist = NULL;
	rwin.history_num = 0;
	rwin.invert = 0;
	rwin.color_scheme = 0;

	lwin.curr_line = 0;
	lwin.top_line = 0;
	lwin.list_rows = 0;
	lwin.list_pos = 0;
	lwin.selected_filelist = NULL;
	lwin.history_num = 0;
	lwin.invert = 0;
	lwin.color_scheme = 0;

	/* These need to be initialized before reading the configuration file */
	cfg.command_num = 0;
	cfg.filetypes_num = 0;
	cfg.nmapped_num = 0;
	cfg.vim_filter = 0;
	cfg.show_one_window = 0;
	command_list = NULL;
	filetypes = NULL;

	cfg.search_history_len = 15;
	cfg.search_history_num = -1;
	cfg.search_history = (char **)calloc(cfg.search_history_len, sizeof(char*));
	cfg.cmd_history_len = 15;
	cfg.cmd_history_num = -1;
	cfg.cmd_history = (char **)calloc(cfg.cmd_history_len, sizeof(char *));
	cfg.auto_execute = 0;
	cfg.color_scheme_num = 0;
	//col_schemes = (Col_scheme *)calloc(1, sizeof(Col_scheme*));
	cfg.shell_cmd = strdup("cmd");

	/* Maximum argument length to pass to the shell */
		cfg.max_args = 4096; /* POSIX MINIMUM */


	init_config();
	set_config_dir();

	read_config_file();

	/* Misc configuration */

	lwin.prev_invert = lwin.invert;
	lwin.hide_dot = 1;
	strncpy(lwin.regexp, "\\..~$", sizeof(lwin.regexp));
	rwin.prev_invert = rwin.invert;
	rwin.hide_dot = 1;
	strncpy(rwin.regexp, "\\..~$", sizeof(rwin.regexp));
	cfg.timer = 10;
	curr_stats.yanked_files = NULL;
	curr_stats.num_yanked_files = 0;
	curr_stats.need_redraw = 0;
	curr_stats.getting_input = 0;
	curr_stats.menu = 0;
	curr_stats.redraw_menu = 0;
	curr_stats.is_updir = 0;
	curr_stats.last_char = 0;
	curr_stats.is_console = 0;
	curr_stats.search = 0;
	curr_stats.save_msg = 0;
	curr_stats.use_register = 0;
	curr_stats.curr_register = -1;
	curr_stats.register_saved = 0;
	curr_stats.show_full = 0;
	curr_stats.view = 0;


	if (cfg.show_one_window)
		curr_stats.number_of_windows = 1;
	else
		curr_stats.number_of_windows = 2;

	if(stat(config_dir, &stat_buf) == 0)
		curr_stats.config_file_mtime = stat_buf.st_mtime;
	else
		curr_stats.config_file_mtime = 0;


	/* Check if running in X */
	console = getenv("DISPLAY");
	if(!console || !*console)
		curr_stats.is_console = 1;


	/* Setup the ncurses interface. */
	if(!setup_ncurses_interface())
		return -1;

	/* Load the initial directory */
	snprintf(rwin.curr_dir, sizeof(rwin.curr_dir), "%s", dir);
	snprintf(lwin.curr_dir, sizeof(lwin.curr_dir), "%s", dir);
	rwin.dir_entry = (dir_entry_t *)malloc(sizeof(dir_entry_t));
	lwin.dir_entry = (dir_entry_t *)malloc(sizeof(dir_entry_t));
	rwin.dir_entry[0].name = malloc(sizeof("../") +1);
	lwin.dir_entry[0].name = malloc(sizeof("../") +1);
	strcpy(rwin.dir_entry[0].name, "../");
	strcpy(lwin.dir_entry[0].name, "../");
	change_directory(&rwin, dir);
	change_directory(&lwin, dir);
	other_view = &lwin;
	curr_view = &rwin;

	/* Get Command Line Arguments */
	for(x = 1; x < argc; x++)
	{
		if(argv[x] != NULL)
		{
				if(!strcmp(argv[x], "-f"))
				{
					cfg.vim_filter = 1;
				}
				else if(!strcmp(argv[x], "--version"))
				{
					endwin();
					system("clear");
					printf("vifm %.1f\n\n", VERSION);
					exit(0);
				}
				else if(!strcmp(argv[x], "--help"))
				{
					endwin();
					show_help_msg();
					exit(0);
				}
				else if(is_dir(argv[x]))
				{
					if(lwin_args)
					{
						snprintf(rwin.curr_dir, sizeof(rwin.curr_dir), 
								"%s", argv[x]);

						rwin_args++;

					}
					else
					{
						snprintf(lwin.curr_dir, sizeof(lwin.curr_dir),
							   	"%s", argv[x]);


						lwin_args++;
					}
				}
				else
				{
					endwin();
					show_help_msg();
					exit(0);
				}
		}
	}

	
	load_dir_list(&rwin, 0);

	if (rwin_args)
	{
		change_directory(&rwin, rwin.curr_dir);
		load_dir_list(&rwin, 0);
	}

	mvwaddstr(rwin.win, rwin.curr_line, 0, "*"); 
	wrefresh(rwin.win);

	/* This is needed for the sort_dir_list() which uses curr_view */
	switch_views();

	load_dir_list(&lwin, 0);

	if (lwin_args)
	{
		change_directory(&lwin, lwin.curr_dir);
		load_dir_list(&lwin, 0);
	}

	moveto_list_pos(&lwin, 0);
	update_all_windows();

	werase(status_bar);
	wnoutrefresh(status_bar);

	
	if(cfg.vim_filter)
		curr_stats.number_of_windows = 1;


	/* Enter the main loop. */
	main_key_press_cb(curr_view);

	return 0;
}
Example #2
0
static char* config_choose_startup_preset()
{
    int size = 0;

    /* by default, work in ML/SETTINGS dir */
    snprintf(config_dir, sizeof(config_dir), "ML/SETTINGS/");

    /* check for a preset file selected in menu */
    char* preset_name = (char*) read_entire_file(config_preset_file, &size);
    if (preset_name)
    {
        if (streq(preset_name, "Startup mode"))
        {
            /* will handle later */
            config_preset_index = config_new_preset_index = 1;
        }
        else if (streq(preset_name, "Startup key"))
        {
            /* will handle later */
            config_preset_index = config_new_preset_index = 2;
        }
        else
        {
            snprintf(config_selected_by_name, sizeof(config_selected_by_name), preset_name);
            char preset_dir[0x80];
            snprintf(preset_dir, sizeof(preset_dir), "ML/SETTINGS/%s", preset_name);
            if (!is_dir(preset_dir)) {
                FIO_CreateDirectory(preset_dir);
            }
            if (is_dir(preset_dir))
            {
                snprintf(config_dir, sizeof(config_dir), "%s/", preset_dir);
            }
        }
        fio_free(preset_name);
    }

    /* scan the preset files and populate the menu */
    config_preset_scan();

    /* special cases: key pressed at startup, or startup mode */

    /* key pressed at startup */
    if (config_preset_index == 2)
    {
        if (config_selected_by_key[0])
        {
            char preset_dir[0x80];
            snprintf(preset_dir, sizeof(preset_dir), "ML/SETTINGS/%s.KEY", config_selected_by_key);
            if (!is_dir(preset_dir)) {
                FIO_CreateDirectory(preset_dir);
            }
            if (is_dir(preset_dir))
            {
                /* success */
                snprintf(config_dir, sizeof(config_dir), "%s/", preset_dir);
                return config_selected_by_key;
            }
        }
        /* didn't work */
        return 0;
    }
    else config_selected_by_key[0] = 0;

    /* startup shooting mode (if selected in menu) */
    if (config_preset_index == 1)
    {
        snprintf(config_selected_by_mode, sizeof(config_selected_by_mode), "%s", get_shootmode_name(shooting_mode_custom));
        char preset_dir[0x80];
        snprintf(preset_dir, sizeof(preset_dir), "ML/SETTINGS/%s.MOD", config_selected_by_mode);
        if (!is_dir(preset_dir)) {
            FIO_CreateDirectory(preset_dir);
        }
        if (is_dir(preset_dir))
        {
            /* success */
            snprintf(config_dir, sizeof(config_dir), "%s/", preset_dir);
            return config_selected_by_mode;
        }
        /* didn't work */
        return 0;
    }

    /* lookup the current preset in menu */
    for (int i = 0; i < config_preset_num; i++)
    {
        if (streq(config_preset_choices[i], config_selected_by_name))
        {
            config_preset_index = config_new_preset_index = i;
            return config_selected_by_name;
        }
    }

    /* using default config */
    return 0;
}
Example #3
0
// edit or display a file with vertical & horizontal scrolling & text searching
int _near List_Cmd( LPTSTR pszCmdLine )
{
	int nFVal, nReturn = 0, argc;
	TCHAR szSource[MAXFILENAME+1], szFileName[MAXFILENAME+1], *pszArg;
	FILESEARCH dir;

	memset( &dir, '\0', sizeof(FILESEARCH) );
	
	// check for and remove switches
	if ( GetRange( pszCmdLine, &(dir.aRanges), 0 ) != 0 )
		return ERROR_EXIT;
	
	// check for /T"search string"
	GetMultiCharSwitch( pszCmdLine, _TEXT("T"), szSource, 255 );
	if ( szSource[0] == _TEXT('"') )
		sscanf( szSource+1, _TEXT("%79[^\"]"), szListFindWhat );
	else if ( szSource[0] )
		sprintf( szListFindWhat, FMT_PREC_STR, 79, szSource );
	
	if ( GetSwitches( pszCmdLine, _TEXT("*HIRSWX"), &lListFlags, 0 ) != 0 )
		return ( Usage( LIST_USAGE ));
	
	if ( szSource[0] )
		lListFlags |= LIST_SEARCH;
	
	// check for pipe to LIST w/o explicit /S switch
	if ( first_arg( pszCmdLine ) == NULL ) {

		if ( _isatty( STDIN ) == 0 )

				lListFlags |= LIST_STDIN;
			else if (( lListFlags & LIST_STDIN ) == 0 )
				return ( Usage( LIST_USAGE ));
	}
	
	// initialize buffers & globals
	
	if ( ListInit() )
		return ERROR_EXIT;
	nCurrent = nStart = 0;
	
	// ^C handling
	if ( setjmp( cv.env ) == -1 ) {
list_abort:
		FindClose( dir.hdir );
		Cls_Cmd( NULL );
		nReturn = CTRLC;
		goto list_bye;
	}
	
RestartFileSearch:
	for ( argc = 0; ; argc++ ) {
		
		// break if at end of arg list, & not listing STDIN
		if (( pszArg = ntharg( pszCmdLine, argc )) == NULL ) {
			if (( lListFlags & LIST_STDIN ) == 0 )
				break;
		} else
			strcpy( szSource, pszArg );
		
		for ( nFVal = FIND_FIRST; ; ) {
			
			szClip[0] = _TEXT('\0');
			
			// if not reading from STDIN, get the next matching file
			if (( lListFlags & LIST_STDIN ) == 0 ) {
				
				// qualify filename
				if ( nFVal == FIND_FIRST ) {
					mkfname( szSource, 0 );
					if ( is_dir( szSource ))
						mkdirname( szSource, WILD_FILE );
				}

				if ( stricmp( szSource, CLIP ) == 0 ) {
					
					RedirToClip( szClip, 99 );
					if ( CopyFromClipboard( szClip ) != 0 )
						break;
					strcpy( szFileName, szClip );
					
				} else if ( QueryIsPipeName( szSource )) {
					
					// only look for pipe once
					if ( nFVal == FIND_NEXT )
						break;
					copy_filename( szFileName, szSource );
					
				} else if ( find_file( nFVal, szSource, ( FIND_BYATTS | FIND_RANGE | FIND_EXCLUDE | 0x07), &dir, szFileName ) == NULL ) {
					nReturn = (( nFVal == FIND_FIRST ) ? ERROR_EXIT : 0 );
					break;
					
				} else if ( nStart < nCurrent ) {
					nStart++;
					nFVal = FIND_NEXT;
					continue;
					
				} else if ( dir.ulSize > 0L )
					LFile.lSize = dir.ulSize;
			}
			
			// clear the screen (scrolling the buffer first to save the current screen)

			Cls_Cmd( NULL );
			
			if (( nReturn = _list( szFileName )) == CTRLC )
				goto list_abort;
			
			if ( szClip[0] )
				remove( szClip );
			
			if ( nReturn != 0 )
				break;
			
			SetCurPos( nScreenRows, 0 );
			
			if (( szClip[0] ) || ( lListFlags & LIST_STDIN ))
				break;

			if ( LFile.hHandle > 0 )
				_close( LFile.hHandle );
			LFile.hHandle = -1;
			
			// increment index to current file
			if ( nCurrent < nStart ) {
				FindClose( dir.hdir );
				nStart = 0;
				goto RestartFileSearch;
			} else {
				nFVal = FIND_NEXT;
				nCurrent++;
				nStart++;
			}
		}
		
		// we can only read STDIN once!
		lListFlags &= ~LIST_STDIN;
	}
	
	crlf();
list_bye:
	FreeMem( LFile.lpBufferStart );
	if ( LFile.hHandle > 0 )
		_close( LFile.hHandle );
	LFile.hHandle = -1;
	
	return nReturn;
}
Example #4
0
void Directory::scan_dir(const ACE_TString& relative, DDS_Dirent& dir,
                         unsigned int overflow_index)
{
  ACE_TString path = physical_dirname_ + relative;
  add_slash(path);

  while (DDS_DIRENT* ent = dir.read()) {
    if (ent->d_name[0] == ACE_TEXT('.') && (!ent->d_name[1] ||
        (ent->d_name[1] == ACE_TEXT('.') && !ent->d_name[2]))) {
      continue; // skip '.' and '..'
    }

    ACE_TString file = path + ent->d_name;

    if (is_dir(file.c_str())) {
      ACE_TString phys(relative);
      add_slash(phys);
      phys += ent->d_name;

      if (ACE_OS::strncmp(ent->d_name, ACE_TEXT("_overflow."), 10) == 0) {
        unsigned int n = ACE_OS::atoi(ent->d_name + 10);
        DDS_Dirent overflow(file.c_str());
        scan_dir(ent->d_name, overflow, n);

      } else if (ACE_OS::strlen(ent->d_name) <= FSS_MAX_FILE_NAME_ENCODED) {
        dirs_[b32h_decode(ent->d_name)] = phys;
        ++overflow_[overflow_index];

      } else {
        CwdGuard cg(file);
        std::ifstream fn("_fullname");
        std::string fullname;

        if (!std::getline(fn, fullname)) {
          throw std::runtime_error("Can't read .../_fullname");
        }

        ACE_TString full_t(ACE_TEXT_CHAR_TO_TCHAR(fullname.c_str()));
        dirs_[full_t] = phys;
        ++overflow_[overflow_index];

        String_Index_t idx = phys.rfind(ACE_TEXT('.'));

        if (idx == ACE_TString::npos) {
          throw std::runtime_error("Badly formatted long dir name");
        }

        ACE_TString prefix(phys.c_str(), idx);
        unsigned int serial = ACE_OS::atoi(&phys[idx + 1]);
        unsigned int& counter = long_names_[prefix];

        if (serial >= counter) counter = serial + 1;
      }

    } else { // regular file
      if (ent->d_name[0] != ACE_TEXT('_')) {
        files_[b32h_decode(ent->d_name)] = ent->d_name;
        ++overflow_[overflow_index];
      }
    }
  }
}
Example #5
0
int
main (int argc, char *argv[])
{
  GError *error;
  GOptionContext *context;
  GFile *source, *dest, *target;
  gboolean dest_is_dir;
  char *basename;
  int i;
  GFileCopyFlags flags;
  int retval = 0;
  gchar *param;
  gchar *summary;

  setlocale (LC_ALL, "");

  bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  error = NULL;
  param = g_strdup_printf ("%s... %s", _("SOURCE"), _("DEST"));
  summary = _("Move one or more files from SOURCE to DEST.");

  context = g_option_context_new (param);
  g_option_context_set_summary (context, summary);
  g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
  g_option_context_parse (context, &argc, &argv, &error);

  if (error != NULL)
    {
      g_printerr (_("Error parsing commandline options: %s\n"), error->message);
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ());
      g_printerr ("\n");
      g_error_free (error);
      return 1;
    }

  if (argc <= 2)
    {
      show_help (context, _("Missing operand\n"));
      return 1;
    }

  dest = g_file_new_for_commandline_arg (argv[argc-1]);

  if (no_target_directory && argc > 3)
    {
      show_help (context, _("Too many arguments\n"));
      g_object_unref (dest);
      return 1;
    }

  dest_is_dir = is_dir (dest);

  if (!dest_is_dir && argc > 3)
    {
      g_printerr (_("Target %s is not a directory\n"), argv[argc-1]);
      show_help (context, NULL);
      g_object_unref (dest);
      return 1;
    }

  g_option_context_free (context);
  g_free (param);

  for (i = 1; i < argc - 1; i++)
    {
      source = g_file_new_for_commandline_arg (argv[i]);

      if (dest_is_dir && !no_target_directory)
	{
	  basename = g_file_get_basename (source);
	  target = g_file_get_child (dest, basename);
	  g_free (basename);
	}
      else
	target = g_object_ref (dest);

      flags = 0;
      if (backup)
	flags |= G_FILE_COPY_BACKUP;
      if (!interactive)
	flags |= G_FILE_COPY_OVERWRITE;

      error = NULL;
      if (!g_file_move (source, target, flags, NULL, progress?show_progress:NULL, NULL, &error))
	{
	  if (interactive && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
	    {
	      char line[16];

	      g_error_free (error);
	      error = NULL;

	      basename = g_file_get_basename (target);
	      g_print ("overwrite %s?", basename);
	      g_free (basename);

	      if (fgets(line, sizeof (line), stdin) &&
		  line[0] == 'y')
		{
		  flags |= G_FILE_COPY_OVERWRITE;
		  if (!g_file_move (source, target, flags, NULL, NULL, NULL, &error))
		    goto move_failed;
		}
	    }
	  else
	    {
	    move_failed:
	      g_printerr (_("Error moving file %s: %s\n"), argv[i], error->message);
	      g_error_free (error);
	      retval = 1;
	    }
	}

      g_object_unref (source);
      g_object_unref (target);
    }

  g_object_unref (dest);

  return retval;
}
Example #6
0
int filebrowser(void* scrbuf, char* file, char* title)
{
    char currentdir[FILENAME_MAX + 1];
    char* filenames[1024];
    char filenameinput[FILENAME_MAX + 1] = "";
    char blockc = '\0';
    int focus_filenameinput = 1;
    int num_files;
    int filescroll = 0;
    int fileselected = 0;
    int i;
    int inputpause = 0;
    if (get_last_doc(currentdir) != 0) {
        getcwd(currentdir, FILENAME_MAX + 1);
    }
    else {
        *(strrchr(currentdir, '/') + 1) = '\0';
    }

    num_files = get_filenames(currentdir, filenames);
    if (num_files == -1)
        return 1;

    wait_no_key_pressed();
    while (1) {
        //disp:
        clearScreen(scrbuf);
        filledRect(scrbuf, 0, TITLE_Y, SCREEN_WIDTH, TITLE_HEIGHT, 0);
        dispStringColor(scrbuf, 4, (TITLE_HEIGHT - CHAR_HEIGHT) / 2, title, WHITE_COLOR, 0);
        dispHorizLine(scrbuf, 0, DIR_Y + DIR_HEIGHT - 1, 320, 0);
        dispString(scrbuf, 4, DIR_Y + (DIR_HEIGHT - CHAR_HEIGHT) / 2, currentdir);
        dispHorizLine(scrbuf, 0, FILENAMEINPUT_Y, 320, 0);
        dispString(scrbuf, 4, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, "Filename:");
        dispString(scrbuf, 4 + 10 * CHAR_WIDTH, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, filenameinput);
        if (focus_filenameinput)//if cursor is in the file name input field, disp an underline to show it
            putChar(scrbuf, 4 + (10 + strlen(filenameinput)) * CHAR_WIDTH, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, '_');
        for (i = filescroll; i < filescroll + FILES_SHOWN && i < num_files; i++) {
            //disp file symbol
            if (is_dir(filenames[i]) && strcmp(filenames[i], ".") && strcmp(filenames[i], ".."))
                putChar(scrbuf, CHAR_WIDTH * 2, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, '\\');
            //disp filename, filesize and selection
            if (i != fileselected || focus_filenameinput) {
                dispString(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, filenames[i]);
                if (!is_dir(filenames[i])) {
                    char size[16];
                    get_filesize(filenames[i], size);
                    dispString(scrbuf, FILENAME_WIDTH, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, size);
                }
            }
            else {
                filledRect(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT - 1, SCREEN_WIDTH - CHAR_WIDTH * 4, CHAR_HEIGHT + 2, MENU_SELECTION_COLOR);
                dispStringColor(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, filenames[i], WHITE_COLOR, MENU_SELECTION_COLOR);
                if (!is_dir(filenames[i])) {
                    char size[16];
                    get_filesize(filenames[i], size);
                    dispStringColor(scrbuf, FILENAME_WIDTH, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, size, WHITE_COLOR, MENU_SELECTION_COLOR);
                }
            }
        }
        showBuffer(scrbuf);


        //input
        if (!any_key_pressed())
            inputpause = 0;
        else
            inputpause--;

        if (isKeyPressed(KEY_NSPIRE_ESC))
            break;
        if (isKeyPressed(KEY_NSPIRE_TAB)) {
            focus_filenameinput = !focus_filenameinput;
            wait_no_key_pressed();
        }

        if (!focus_filenameinput) {
            if (isKeyPressed(KEY_NSPIRE_ENTER) && (blockc != '\n' || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = '\n';
                if (is_dir(filenames[fileselected])) {
                    chdir(filenames[fileselected]);
                    filescroll = 0;
                    fileselected = 0;
                    free_filenames(filenames);
                    getcwd(currentdir, FILENAME_MAX + 1);
                    num_files = get_filenames(currentdir, filenames);
                }
                else {
                    strcpy(file, currentdir);
                    strcat(file, filenames[fileselected]);
                    free_filenames(filenames);
                    printf("%s\n", file);
                    return 0;
                }
            }
            else if (isKeyPressed(KEY_NSPIRE_UP) && (blockc != 0x1 || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = 0x1;
                fileselected--;
                if (fileselected < 0) {
                    fileselected = num_files - 1;
                    filescroll = num_files - FILES_SHOWN;
                    if (filescroll < 0)
                        filescroll = 0;
                }
                else if (fileselected - filescroll < 0)
                    filescroll--;
                strcpy(filenameinput, filenames[fileselected]);
            }
            else if (isKeyPressed(KEY_NSPIRE_DOWN) && (blockc != 0x2 || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = 0x2;
                fileselected++;
                if (fileselected >= num_files) {
                    fileselected = 0;
                    filescroll = 0;
                }
                else if (fileselected - filescroll >= FILES_SHOWN)
                    ++filescroll;
                strcpy(filenameinput, filenames[fileselected]);
            }
        }
        else { //focus_filenameinput
            char c = readc();
            if (c == blockc && inputpause > 0)
                continue;
            if (c != '\0' && c != '\t' && c != '\n') {
                inputpause = INPUTPAUSE;
                blockc = c;
                if (c == '\b') {
                    if (filenameinput[0] != '\0')
                        filenameinput[strlen(filenameinput) - 1] = '\0';
                }
                else {
                    filenameinput[strlen(filenameinput)] = c;
                    filenameinput[strlen(filenameinput) + 1] = '\0';
                }
            }
            if (isKeyPressed(KEY_NSPIRE_UP) || isKeyPressed(KEY_NSPIRE_TAB)) {
                inputpause = INPUTPAUSE;
                focus_filenameinput = 0;
            }
            if (isKeyPressed(KEY_NSPIRE_ENTER)) {
                strcpy(file, currentdir);
                strcat(file, filenameinput);
                free_filenames(filenames);
                printf("%s\n", file);
                return 0;
            }
        }
        sleep(10);
    }

    free_filenames(filenames);
    return 1;
}
Example #7
0
int
is_valid_dir(const char *path)
{
	return is_dir(path) || is_unc_root(path);
}