acme: accept expanded URLs in look
Just as look expands a click in /etc/passwd to the full name (provided that file exists), it now expands a click in https://9fans.net/ to the full URL (provided the prefix is http:// or https://). Probably more adjustment is needed.
This commit is contained in:
parent
161742770e
commit
7a241631b2
1 changed files with 39 additions and 9 deletions
|
|
@ -30,7 +30,7 @@ plumbthread(void *v)
|
|||
|
||||
USED(v);
|
||||
threadsetname("plumbproc");
|
||||
|
||||
|
||||
/*
|
||||
* Loop so that if plumber is restarted, acme need not be.
|
||||
*/
|
||||
|
|
@ -46,7 +46,7 @@ plumbthread(void *v)
|
|||
}
|
||||
plumbeditfid = fid;
|
||||
plumbsendfid = plumbopenfid("send", OWRITE|OCEXEC);
|
||||
|
||||
|
||||
/*
|
||||
* Relay messages.
|
||||
*/
|
||||
|
|
@ -432,9 +432,9 @@ includename(Text *t, Rune *r, int n)
|
|||
char buf[128];
|
||||
Rune Lsysinclude[] = { '/', 's', 'y', 's', '/', 'i', 'n', 'c', 'l', 'u', 'd', 'e', 0 };
|
||||
Rune Lusrinclude[] = { '/', 'u', 's', 'r', '/', 'i', 'n', 'c', 'l', 'u', 'd', 'e', 0 };
|
||||
Rune Lusrlocalinclude[] = { '/', 'u', 's', 'r', '/', 'l', 'o', 'c', 'a', 'l',
|
||||
Rune Lusrlocalinclude[] = { '/', 'u', 's', 'r', '/', 'l', 'o', 'c', 'a', 'l',
|
||||
'/', 'i', 'n', 'c', 'l', 'u', 'd', 'e', 0 };
|
||||
Rune Lusrlocalplan9include[] = { '/', 'u', 's', 'r', '/', 'l', 'o', 'c', 'a', 'l',
|
||||
Rune Lusrlocalplan9include[] = { '/', 'u', 's', 'r', '/', 'l', 'o', 'c', 'a', 'l',
|
||||
'/', 'p', 'l', 'a', 'n', '9', '/', 'i', 'n', 'c', 'l', 'u', 'd', 'e', 0 };
|
||||
Runestr file;
|
||||
int i;
|
||||
|
|
@ -443,7 +443,7 @@ includename(Text *t, Rune *r, int n)
|
|||
sprint(buf, "/%s/include", objtype);
|
||||
objdir = bytetorune(buf, &i);
|
||||
objdir = runerealloc(objdir, i+1);
|
||||
objdir[i] = '\0';
|
||||
objdir[i] = '\0';
|
||||
}
|
||||
|
||||
w = t->w;
|
||||
|
|
@ -514,6 +514,19 @@ dirname(Text *t, Rune *r, int n)
|
|||
return tmp;
|
||||
}
|
||||
|
||||
static int
|
||||
texthas(Text *t, uint q0, Rune *r)
|
||||
{
|
||||
int i;
|
||||
|
||||
if((int)q0 < 0)
|
||||
return FALSE;
|
||||
for(i=0; r[i]; i++)
|
||||
if(q0+i >= t->file->b.nc || textreadc(t, q0+i) != r[i])
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
expandfile(Text *t, uint q0, uint q1, Expand *e)
|
||||
{
|
||||
|
|
@ -522,12 +535,14 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
|
|||
Rune *r, c;
|
||||
Window *w;
|
||||
Runestr rs;
|
||||
Rune Lhttpcss[] = {'h', 't', 't', 'p', ':', '/', '/', 0};
|
||||
Rune Lhttpscss[] = {'h', 't', 't', 'p', 's', ':', '/', '/', 0};
|
||||
|
||||
amax = q1;
|
||||
if(q1 == q0){
|
||||
colon = -1;
|
||||
while(q1<t->file->b.nc && isfilec(c=textreadc(t, q1))){
|
||||
if(c == ':'){
|
||||
if(c == ':' && !texthas(t, q1-4, Lhttpcss) && !texthas(t, q1-5, Lhttpscss)){
|
||||
colon = q1;
|
||||
break;
|
||||
}
|
||||
|
|
@ -535,7 +550,7 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
|
|||
}
|
||||
while(q0>0 && (isfilec(c=textreadc(t, q0-1)) || isaddrc(c) || isregexc(c))){
|
||||
q0--;
|
||||
if(colon<0 && c==':')
|
||||
if(colon<0 && c==':' && !texthas(t, q0-4, Lhttpcss) && !texthas(t, q0-5, Lhttpscss))
|
||||
colon = q0;
|
||||
}
|
||||
/*
|
||||
|
|
@ -565,8 +580,23 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
|
|||
if(n == 0)
|
||||
return FALSE;
|
||||
/* see if it's a file name */
|
||||
r = runemalloc(n);
|
||||
r = runemalloc(n+1);
|
||||
bufread(&t->file->b, q0, r, n);
|
||||
r[n] = 0;
|
||||
/* is it a URL? look for http:// and https:// prefix */
|
||||
if(runestrncmp(r, Lhttpcss, 7) == 0 || runestrncmp(r, Lhttpscss, 8) == 0){
|
||||
// Avoid capturing end-of-sentence punctuation.
|
||||
if(r[n-1] == '.') {
|
||||
e->q1--;
|
||||
n--;
|
||||
}
|
||||
e->name = r;
|
||||
e->nname = n;
|
||||
e->u.at = t;
|
||||
e->a0 = e->q1;
|
||||
e->a1 = e->q1;
|
||||
return TRUE;
|
||||
}
|
||||
/* first, does it have bad chars? */
|
||||
nname = -1;
|
||||
for(i=0; i<n; i++){
|
||||
|
|
@ -728,7 +758,7 @@ openfile(Text *t, Expand *e)
|
|||
/*
|
||||
* Unrooted path in new window.
|
||||
* This can happen if we type a pwd-relative path
|
||||
* in the topmost tag or the column tags.
|
||||
* in the topmost tag or the column tags.
|
||||
* Most of the time plumber takes care of these,
|
||||
* but plumber might not be running or might not
|
||||
* be configured to accept plumbed directories.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue