Kernel/VFS - Added warning (instead of LOG) when GetNodeFromInode is unsupported
[tpg/acess2.git] / Usermode / Applications / CLIShell_src / lib.c
1 /*\r
2  * AcessOS Shell Version 2\r
3  *\r
4  * See file COPYING for \r
5  */\r
6 #include "header.h"\r
7 #include <stddef.h>\r
8 \r
9 // === CODE ===\r
10 /**\r
11  * \fn int GeneratePath(char *file, char *base, char *Dest)\r
12  * \brief Generates a path given a base and a filename\r
13  * \param \r
14  */\r
15 int GeneratePath(char *file, char *base, char *Dest)\r
16 {\r
17         char    *pathComps[64];\r
18         char    *tmpStr;\r
19         int             iPos = 0;\r
20         int             iPos2 = 0;\r
21         \r
22         // Parse Base Path\r
23         if(file[0] != '/')\r
24         {\r
25                 pathComps[iPos++] = tmpStr = base+1;\r
26                 while(*tmpStr)\r
27                 {\r
28                         if(*tmpStr++ == '/')\r
29                         {\r
30                                 pathComps[iPos] = tmpStr;\r
31                                 iPos ++;\r
32                         }\r
33                 }\r
34         }\r
35         \r
36         //Print(" GeneratePath: Base Done\n");\r
37         \r
38         // Parse Argument Path\r
39         pathComps[iPos++] = tmpStr = file;\r
40         while(*tmpStr)\r
41         {\r
42                 if(*tmpStr++ == '/')\r
43                 {\r
44                         pathComps[iPos] = tmpStr;\r
45                         iPos ++;\r
46                 }\r
47         }\r
48         pathComps[iPos] = NULL;\r
49         \r
50         //Print(" GeneratePath: Path Done\n");\r
51         \r
52         // Cleanup\r
53         iPos2 = iPos = 0;\r
54         while(pathComps[iPos])\r
55         {\r
56                 tmpStr = pathComps[iPos];\r
57                 // Always Increment iPos\r
58                 iPos++;\r
59                 // ..\r
60                 if(tmpStr[0] == '.' && tmpStr[1] == '.' && (tmpStr[2] == '/' || tmpStr[2] == '\0') )\r
61                 {\r
62                         if(iPos2 != 0)\r
63                                 iPos2 --;\r
64                         continue;\r
65                 }\r
66                 // .\r
67                 if(tmpStr[0] == '.' && (tmpStr[1] == '/' || tmpStr[1] == '\0') )\r
68                 {\r
69                         continue;\r
70                 }\r
71                 // Empty\r
72                 if(tmpStr[0] == '/' || tmpStr[0] == '\0')\r
73                 {\r
74                         continue;\r
75                 }\r
76                 \r
77                 // Set New Position\r
78                 pathComps[iPos2] = tmpStr;\r
79                 iPos2++;\r
80         }\r
81         pathComps[iPos2] = NULL;\r
82         \r
83         // Build New Path\r
84         iPos2 = 1;      iPos = 0;\r
85         Dest[0] = '/';\r
86         while(pathComps[iPos])\r
87         {\r
88                 tmpStr = pathComps[iPos];\r
89                 while(*tmpStr && *tmpStr != '/')\r
90                 {\r
91                         Dest[iPos2++] = *tmpStr;\r
92                         tmpStr++;\r
93                 }\r
94                 Dest[iPos2++] = '/';\r
95                 iPos++;\r
96         }\r
97         if(iPos2 > 1)\r
98                 Dest[iPos2-1] = 0;\r
99         else\r
100                 Dest[iPos2] = 0;\r
101         \r
102         return iPos2;   //Length\r
103 }\r

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