summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorEpoch Qwert <epoch@53flpnlls43fcguy.onion>2014-12-28 22:50:23 -0600
committerEpoch Qwert <epoch@53flpnlls43fcguy.onion>2014-12-28 22:50:23 -0600
commit05d677a3d3e9e540dffd35c76e35335bf43ead7d (patch)
treec1ee9dd68d26a0108ba0ba1fd849ec323b86d76e /src/bin
parent01b8e693a95c1ee4377998e0589f6ec1b7be7267 (diff)
downloadmisc-05d677a3d3e9e540dffd35c76e35335bf43ead7d.tar.gz
misc-05d677a3d3e9e540dffd35c76e35335bf43ead7d.zip
made gopherd symlink friendlier. normalpath was needed for that.
normalpath just tries to normalize a path, even if the files don't exist.
Diffstat (limited to 'src/bin')
-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;
+}