summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchoose9
-rw-r--r--urigetline.c31
2 files changed, 27 insertions, 13 deletions
diff --git a/choose b/choose
index 763c71c..aa191e7 100755
--- a/choose
+++ b/choose
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env bash
### this script is meant to take a \n delimited list of things
### then give the user a way of selecting on of them.
### it should output the selection on a line by itself.
@@ -11,6 +11,13 @@ if [ "$1" ];then
else
prompt="< $0 >"
fi
+
+if [ "${prompt}" != "${prompt:0:64}" ];then
+ prompt="${prompt:0:64}..."
+else
+ prompt="${prompt}"
+fi
+
if [ $DISPLAY ];then
#usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]
# [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]
diff --git a/urigetline.c b/urigetline.c
index 4c5c7b4..4963a84 100644
--- a/urigetline.c
+++ b/urigetline.c
@@ -35,7 +35,7 @@ int match(signed char rule,char *part,char *arg) {
int main(int argc,char *argv[]) {//argument needs to be the URI
int j;
int ret=1;
- struct uri u;
+ struct uri *u = malloc(sizeof(struct uri));
char matches;
signed char rule=MATCH_PATTERN;
char *line=malloc(LINE_LENGTH);
@@ -57,9 +57,10 @@ int main(int argc,char *argv[]) {//argument needs to be the URI
}
if(argc < 2) {
fprintf(stderr,"usage: urigetline [-a] uri < uristart.conf\n");
+ free(u);
return 1;
}
- urifromline(&u,argv[1]);//only argv[1] is a URI?
+ urifromline(u,argv[1]);//only argv[1] is a URI?
for(;fgets(line,LINE_LENGTH-1,stdin);) {//each line comes from the config. we need to split it on spaces.
if(strchr(line,'\r')) *strchr(line,'\r')=0;
if(strchr(line,'\n')) *strchr(line,'\n')=0;
@@ -76,7 +77,7 @@ int main(int argc,char *argv[]) {//argument needs to be the URI
}
a=line;
matches=1;
- for(;a;) {
+ for(;a && *a;) {
rule=MATCH_PATTERN;
j=0;
switch(a[0]) {
@@ -90,6 +91,7 @@ int main(int argc,char *argv[]) {//argument needs to be the URI
if(rule != MATCH_UNEXIST) {
if(!(b=strchr(a,' '))) {
fprintf(stderr,"argument '%s' wants a value in the next argument and didn't get it. throwing a fit. (pass -v to urigetline to help debug)\n",a);
+ free(u);
return 2;
}
*b=0; b++;
@@ -102,17 +104,18 @@ int main(int argc,char *argv[]) {//argument needs to be the URI
}
}
switch(a[j]) {
- case 's': if(!match(rule,u.scheme,b)) { matches=0;} break;
- case 'u': if(!match(rule,u.username,b)) { matches=0;} break;
- case 'k': if(!match(rule,u.password,b)) { matches=0;} break;
- case 'd': if(!match(rule,u.domain,b)) { matches=0;} break;
- case 'P': if(!match(rule,u.port,b)) { matches=0;} break;
- case 'p': if(!match(rule,u.path,b)) { matches=0;} break;
- case 'q': if(!match(rule,u.query_string,b)) { matches=0;} break;
- case 'f': if(!match(rule,u.fragment_id,b)) { matches=0;} break;
+ case 's': if(!match(rule,u->scheme,b)) { matches=0;} break;
+ case 'u': if(!match(rule,u->username,b)) { matches=0;} break;
+ case 'k': if(!match(rule,u->password,b)) { matches=0;} break;
+ case 'd': if(!match(rule,u->domain,b)) { matches=0;} break;
+ case 'P': if(!match(rule,u->port,b)) { matches=0;} break;
+ case 'p': if(!match(rule,u->path,b)) { matches=0;} break;
+ case 'q': if(!match(rule,u->query_string,b)) { matches=0;} break;
+ case 'f': if(!match(rule,u->fragment_id,b)) { matches=0;} break;
break;
default:
fprintf(stderr,"unknown url part letter! %s\n",a);
+ free(u);
return 3;
}
//if(b) printf("two: %s %s\n",a,b);
@@ -122,8 +125,12 @@ int main(int argc,char *argv[]) {//argument needs to be the URI
if(matches) {
//printf("comm: %s\n",command);
printf("%s\n",command);
- if(!all) return ret;//bail early if we only need first match
+ if(!all) {
+ free(u);
+ return ret;//bail early if we only need first match
+ }
}
}
+ free(u);
return ret;
}