f3266775a2453681642b697cbd49868d0888bb4d
[tpg/acess2.git] / Tools / DiskTool / src / helpers.c
1 /*
2  * Acess2 DiskTool
3  * - By John Hodge (thePowersGang)
4  *
5  * helpers.c
6  */
7 #include <stdlib.h>
8 #include <acess_logging.h>
9 #include <ctype.h>
10 #include <string.h>
11 #include <unistd.h>
12
13 // === GLOBALS ===
14 char    gsWorkingDirectory[1024];
15
16
17 // === CODE ===
18 size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path)
19 {
20          int    len;
21         const char *colon = strchr(Path, ':');
22
23         if( Path[0] == '#' )
24         {
25                 if(Buffer)
26                         strcpy(Buffer, Path+1);
27                 return strlen(Path) - 1;
28         }
29         
30         if( colon )
31         {
32                 const char *pos;
33                 for(pos = Path; pos < colon; pos ++)
34                 {
35                         if( !isalpha(*pos) )
36                                 goto native_path;
37                 }
38                 
39                 len = strlen("/Mount/");
40                 len += strlen(Path);
41                 if( Buffer ) {
42                         strcpy(Buffer, "/Mount/");
43                         strncat(Buffer+strlen("/Mount/"), Path, colon - Path);
44                         strcat(Buffer, colon + 1);
45                 }
46                 return len;
47         }
48         
49 native_path:
50
51         if( !gsWorkingDirectory[0] ) {  
52                 getcwd(gsWorkingDirectory, 1024);
53         }
54
55         len = strlen("/Native");
56         len += strlen( gsWorkingDirectory ) + 1;
57         len += strlen(Path);
58         if( Buffer ) {
59                 strcpy(Buffer, "/Native");
60                 strcat(Buffer, gsWorkingDirectory);
61                 strcat(Buffer, "/");
62                 strcat(Buffer, Path);
63         }
64         return len;
65 }

UCC git Repository :: git.ucc.asn.au