DiskTool - Cleanup, copy command
[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( colon )
24         {
25                 const char *pos;
26                 for(pos = Path; pos < colon; pos ++)
27                 {
28                         if( !isalpha(*pos) )
29                                 goto native_path;
30                 }
31                 
32                 len = strlen("/Mount/");
33                 len += strlen(Path);
34                 if( Buffer ) {
35                         strcpy(Buffer, "/Mount/");
36                         strncat(Buffer+strlen("/Mount/"), Path, colon - Path);
37                         strcat(Buffer, colon + 1);
38                 }
39                 return len;
40         }
41         
42 native_path:
43
44         if( !gsWorkingDirectory[0] ) {  
45                 getcwd(gsWorkingDirectory, 1024);
46         }
47
48         len = strlen("/Native");
49         len += strlen( gsWorkingDirectory ) + 1;
50         len += strlen(Path);
51         if( Buffer ) {
52                 strcpy(Buffer, "/Native");
53                 strcat(Buffer, gsWorkingDirectory);
54                 strcat(Buffer, "/");
55                 strcat(Buffer, Path);
56         }
57         return len;
58 }

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