commit 7a241631b2097b1acda431ff059b771c5d1c391c from: Russ Cox date: Mon Jun 10 20:01:10 2019 UTC 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. commit - 161742770e63fec914b0290def3ac063ad3d2cf9 commit + 7a241631b2097b1acda431ff059b771c5d1c391c blob - cbbc71bf5faf907167d57a7017bbb8c65b231cbf blob + 44e23ccacb63091a16d46e9230c5ffae32df2f35 --- src/cmd/acme/look.c +++ src/cmd/acme/look.c @@ -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(q1file->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