aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorepochqwert <epoch@53flpnlls43fcguy.onion>2015-01-17 01:06:06 -0600
committerepochqwert <epoch@53flpnlls43fcguy.onion>2015-01-17 01:06:06 -0600
commitabe09a4717370f331b050ad39da3a7e9a478f02d (patch)
treeaf1a66e4701e01c915f7bd86ee2b65ef8394744b /src
parentfd9f6169e93cab12eaa8d4d9b968afe67ddca878 (diff)
downloadmisc-abe09a4717370f331b050ad39da3a7e9a478f02d.tar.gz
misc-abe09a4717370f331b050ad39da3a7e9a478f02d.zip
updated normalpath for some edge cases and added debug
Diffstat (limited to 'src')
-rw-r--r--src/bin/normalpath.c56
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;