From 05d677a3d3e9e540dffd35c76e35335bf43ead7d Mon Sep 17 00:00:00 2001 From: Epoch Qwert Date: Sun, 28 Dec 2014 22:50:23 -0600 Subject: made gopherd symlink friendlier. normalpath was needed for that. normalpath just tries to normalize a path, even if the files don't exist. --- src/bin/normalpath.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/bin/normalpath.c (limited to 'src/bin') 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 +#include +#include +#include +#include + +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; +} -- cgit v1.2.3