3 /* expand a path relative to some `.' */
5 abspath(char *path, char *dot, String *to)
8 to = s_append(to, path);
10 to = s_append(to, dot);
11 to = s_append(to, "/");
12 to = s_append(to, path);
17 /* return a pointer to the base component of a pathname */
23 cp = strrchr(path, '/');
24 return cp==0 ? path : cp+1;
27 /* append a sub-expression match onto a String */
29 append_match(Resub *subexp, String *sp, int se)
41 * check for shell characters in a String
43 static char *illegalchars = "\r\n";
50 for(sp=illegalchars; *sp; sp++)
56 static char *specialchars = " ()<>{};=\\'`^&|";
57 static char *escape = "%%";
70 * rewrite a string to escape shell characters
73 escapespecial(String *s)
78 for(sp = specialchars; *sp; sp++)
79 if(strchr(s_to_c(s), *sp))
85 for(sp = s_to_c(s); *sp; sp++){
86 if(strchr(specialchars, *sp)){
88 s_putc(ns, hexchar(*sp>>4));
89 s_putc(ns, hexchar(*sp));
101 if(x >= '0' && x <= '9')
103 if(x >= 'A' && x <= 'F')
104 return (x - 'A') + 10;
105 if(x >= 'a' && x <= 'f')
106 return (x - 'a') + 10;
111 * rewrite a string to remove shell characters escapes
114 unescapespecial(String *s)
120 if(strstr(s_to_c(s), escape) == 0)
125 for(sp = s_to_c(s); *sp; sp++){
126 if(strncmp(sp, escape, n) == 0){
127 c = (hex2uint(sp[n])<<4) + hex2uint(sp[n+1]);
144 returnable(char *path)
147 return strcmp(path, "/dev/null") != 0;