From abe09a4717370f331b050ad39da3a7e9a478f02d Mon Sep 17 00:00:00 2001 From: epochqwert Date: Sat, 17 Jan 2015 01:06:06 -0600 Subject: updated normalpath for some edge cases and added debug --- src/bin/normalpath.c | 56 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'src') 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 #include +#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; -- cgit v1.2.3