diff options
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/normalpath.c | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/src/bin/normalpath.c b/src/bin/normalpath.c index 96f5506..2ea916f 100644 --- a/src/bin/normalpath.c +++ b/src/bin/normalpath.c @@ -4,6 +4,8 @@ #include <unistd.h> #include <sys/param.h> +#define DEBUG 0 + int main(int argc,char *argv[]) { int i,j,k,l; char *s=argv[1]; @@ -20,31 +22,51 @@ int main(int argc,char *argv[]) { strcat(out,"/"); } strcat(out,s); +#if DEBUG + printf("%s\n",out); +#endif 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(i=0;out[i];) { +#if DEBUG + printf("%s @ %s\n",out,out+i); +#endif + if(strlen(out+i) >= 4) { + if(out[i] == '/' && out[i+1] == '.' && out[i+2] == '.' && out[i+3] == '/') { + for(j=i-1;j>0 && out[j] != '/';j--) { + } + if(j<0) j=0; + for(k=j;out[k];k++) { + out[k]=out[k+(i-j)+3]; + if(!out[k]) break; + } + i=0; + continue; } - 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(strlen(out+i) >= 3) { + if(out[i] == '/' && out[i+1] == '.' && out[i+2] == '/') { + for(j=i;out[j];j++) { + out[j]=out[j+2]; + if(!out[j]) break; + } + i=0; + continue; + } } - if(out[i] == '/' && out[i+1] == '/') { - //leftshift over it. - for(j=i;out[j];j++) { - out[j]=out[j+1]; + if(strlen(out+i) >= 2) { + if(out[i] == '/' && out[i+1] == '/') { + //leftshift over it. + for(j=i;out[j];j++) { + out[j]=out[j+1]; + if(!out[j]) break; + } + i=0; + continue; } - i=0; } + i++; } printf("%s\n",out); return 0; |