aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/normalpath.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/bin/normalpath.c b/src/bin/normalpath.c
new file mode 100644
index 0000000..96f5506
--- /dev/null
+++ b/src/bin/normalpath.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
+
+int main(int argc,char *argv[]) {
+ int i,j,k,l;
+ char *s=argv[1];
+ char *out=malloc(MAXPATHLEN+1);
+ switch(s[0]) {
+ case '/':
+ strcpy(out,"/");
+ break;
+ case '~':
+ strcpy(out,(char *)getenv("HOME"));
+ break;
+ default:
+ getcwd(out,MAXPATHLEN);
+ strcat(out,"/");
+ }
+ strcat(out,s);
+ l=strlen(out)-1;
+ if(out[l] == '.' && out[l-1] == '/') strcat(out,"/");
+ if(out[l] == '.' && out[l-1] == '.' && out[l-2] == '/') strcat(out,"/");
+ for(i=0;out[i];i++) {
+ if(out[i] == '/' && out[i+1] == '.' && out[i+2] == '.' && out[i+3] == '/') {
+ for(j=i-1;out[j] != '/';j--) {
+ }
+ for(k=j;out[k];k++) {
+ out[k]=out[k+(i-j)+3];
+ }
+ i=0;
+ }
+ if(out[i] == '/' && out[i+1] == '.' && out[i+2] == '/') {
+ for(j=i;out[j];j++) {
+ out[j]=out[j+2];
+ }
+ i=0;
+ }
+ if(out[i] == '/' && out[i+1] == '/') {
+ //leftshift over it.
+ for(j=i;out[j];j++) {
+ out[j]=out[j+1];
+ }
+ i=0;
+ }
+ }
+ printf("%s\n",out);
+ return 0;
+}