Renamed Find_last_slash() to Find_last_separator() to make purpose more clear.

Append_path():
- when adding sub directories: don't add a "/" when last separator is a ":".
- when climbing upwards: don't remove the ":" it it's the last separator.

Those fixes help the file selector for scripts on AROS.


git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1979 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
mazzearos 2012-08-05 08:51:16 +00:00
parent d31b865482
commit d28a1df60b
7 changed files with 23 additions and 15 deletions

View File

@ -1197,7 +1197,7 @@ void Add_font_or_skin(const char *name)
int namelength; int namelength;
// Cut the long name to keep only filename (no directory) // Cut the long name to keep only filename (no directory)
fname = Find_last_slash(name); fname = Find_last_separator(name);
if (fname) if (fname)
fname++; fname++;
else else

View File

@ -685,7 +685,7 @@ void Main_handler(void)
Upload_infos_page_main(Main_backups->Pages); Upload_infos_page_main(Main_backups->Pages);
flimit = Find_last_slash(Drop_file_name); flimit = Find_last_separator(Drop_file_name);
*(flimit++) = '\0'; *(flimit++) = '\0';
Hide_cursor(); Hide_cursor();

View File

@ -33,7 +33,7 @@
#include "filesel.h" // Get_item_by_index #include "filesel.h" // Get_item_by_index
#include "global.h" #include "global.h"
#include "graph.h" #include "graph.h"
#include "io.h" // find_last_slash #include "io.h" // find_last_separator
#include "misc.h" #include "misc.h"
#include "pages.h" // Backup() #include "pages.h" // Backup()
#include "readline.h" #include "readline.h"
@ -1522,7 +1522,7 @@ void Add_script(const char *name, byte is_file, byte is_directory, byte is_hidde
const char * file_name; const char * file_name;
int len; int len;
file_name=Find_last_slash(name)+1; file_name=Find_last_separator(name)+1;
if (is_file) if (is_file)
{ {

View File

@ -1742,7 +1742,7 @@ byte Button_Load_or_Save(byte load, T_IO_Context *context)
Config.Bookmark_directory[clicked_button-10]=malloc(temp+1); Config.Bookmark_directory[clicked_button-10]=malloc(temp+1);
strcpy(Config.Bookmark_directory[clicked_button-10],Main_current_directory); strcpy(Config.Bookmark_directory[clicked_button-10],Main_current_directory);
directory_name=Find_last_slash(Main_current_directory); directory_name=Find_last_separator(Main_current_directory);
if (directory_name && directory_name[1]!='\0') if (directory_name && directory_name[1]!='\0')
directory_name++; directory_name++;
else else

View File

@ -165,7 +165,7 @@ int Write_dword_be(FILE *file, dword dw)
// Attention, sous Windows, il faut s'attendre aux deux car // Attention, sous Windows, il faut s'attendre aux deux car
// par exemple un programme lancé sous GDB aura comme argv[0]: // par exemple un programme lancé sous GDB aura comme argv[0]:
// d:\Data\C\GFX2\grafx2/grafx2.exe // d:\Data\C\GFX2\grafx2/grafx2.exe
char * Find_last_slash(const char * str) char * Find_last_separator(const char * str)
{ {
const char * position = NULL; const char * position = NULL;
for (; *str != '\0'; str++) for (; *str != '\0'; str++)
@ -182,7 +182,7 @@ char * Find_last_slash(const char * str)
// Récupère la partie "nom de file seul" d'un chemin // Récupère la partie "nom de file seul" d'un chemin
void Extract_filename(char *dest, const char *source) void Extract_filename(char *dest, const char *source)
{ {
const char * position = Find_last_slash(source); const char * position = Find_last_separator(source);
if (position) if (position)
strcpy(dest,position+1); strcpy(dest,position+1);
@ -195,7 +195,7 @@ void Extract_path(char *dest, const char *source)
char * position=NULL; char * position=NULL;
Realpath(source,dest); Realpath(source,dest);
position = Find_last_slash(dest); position = Find_last_separator(dest);
if (position) if (position)
*(position+1) = '\0'; *(position+1) = '\0';
else else
@ -217,7 +217,7 @@ void Append_path(char *path, const char *filename, char *reverse_path)
{ {
// Going up one directory // Going up one directory
long len; long len;
char * slash_pos; char * separator_pos;
// Remove trailing slash // Remove trailing slash
len=strlen(path); len=strlen(path);
@ -228,12 +228,18 @@ void Append_path(char *path, const char *filename, char *reverse_path)
)) ))
path[len-1]='\0'; path[len-1]='\0';
slash_pos=Find_last_slash(path); separator_pos=Find_last_separator(path);
if (slash_pos) if (separator_pos)
{ {
if (reverse_path) if (reverse_path)
strcpy(reverse_path, slash_pos+1); strcpy(reverse_path, separator_pos+1);
*slash_pos='\0'; #if 0
// Don't strip away the colon
if (*separator_pos == ':') *(separator_pos+1)='\0';
else *separator_pos='\0';
#else
*separator_pos='\0';
#endif
} }
else else
{ {
@ -258,6 +264,8 @@ void Append_path(char *path, const char *filename, char *reverse_path)
if (len && (strcmp(path+len-1,PATH_SEPARATOR) if (len && (strcmp(path+len-1,PATH_SEPARATOR)
#ifdef __WIN32__ #ifdef __WIN32__
&& path[len-1]!='/' && path[len-1]!='/'
#elif __AROS__
&& path[len-1]!=':' // To avoid paths like volume:/dir
#endif #endif
)) ))
{ {

View File

@ -68,7 +68,7 @@ void Extract_filename(char *dest, const char *source);
void Extract_path(char *dest, const char *source); void Extract_path(char *dest, const char *source);
/// Finds the rightmost path separator in a full filename. Used to separate directory from file. /// Finds the rightmost path separator in a full filename. Used to separate directory from file.
char * Find_last_slash(const char * str); char * Find_last_separator(const char * str);
#if defined(__WIN32__) #if defined(__WIN32__)
#define PATH_SEPARATOR "\\" #define PATH_SEPARATOR "\\"

View File

@ -168,7 +168,7 @@ void Add_font(const char *name)
strcpy(font->Label, " "); strcpy(font->Label, " ");
if (font->Is_truetype) if (font->Is_truetype)
font->Label[17]=font->Label[18]='T'; // Logo TT font->Label[17]=font->Label[18]='T'; // Logo TT
font_name=Find_last_slash(font->Name); font_name=Find_last_separator(font->Name);
if (font_name==NULL) if (font_name==NULL)
font_name=font->Name; font_name=font->Name;
else else