DiskTool - Usability fixes
[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                 len = strlen(Path+1);
26                 if(Buffer) {
27                         strcpy(Buffer, Path+1);
28                 }
29         }
30         else if( Path[0] == ':' )
31         {
32                 len = strlen("/Devices/LVM/");
33                 len += strlen(Path+1);
34                 if(Buffer) {
35                         strcpy(Buffer, "/Devices/LVM/");
36                         strcat(Buffer, Path+1);
37                 }
38         }
39         else if( colon )
40         {
41                 const char *pos;
42                 for(pos = Path; pos < colon; pos ++)
43                 {
44                         if( !isalpha(*pos) )
45                                 goto native_path;
46                 }
47                 
48                 len = strlen("/Mount/");
49                 len += strlen(Path);
50                 if( Buffer ) {
51                         strcpy(Buffer, "/Mount/");
52                         strncat(Buffer+strlen("/Mount/"), Path, colon - Path);
53                         strcat(Buffer, colon + 1);
54                 }
55         }
56         else
57         {
58         native_path:
59                 if( !gsWorkingDirectory[0] ) {  
60                         getcwd(gsWorkingDirectory, 1024);
61                 }
62         
63                 len = strlen("/Native");
64                 len += strlen( gsWorkingDirectory ) + 1;
65                 len += strlen(Path);
66                 if( Buffer ) {
67                         strcpy(Buffer, "/Native");
68                         strcat(Buffer, gsWorkingDirectory);
69                         strcat(Buffer, "/");
70                         strcat(Buffer, Path);
71                 }
72         }
73         return len;
74 }

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