void urlconvience(Url *u) { int i; for(i = 0; u->src.nr >= ctab[i].len && runestrncmp(u->src.r, ctab[i].lead, ctab[i].len) != 0; i++) ; ctab[i].f(u); }
/* this is a HACK */ Rune* urlcombine(Rune *b, Rune *u) { Rune *p, *q, *sep, *s; Rune endrune[] = { L'?', L'#' }; int i, restore; if(u == nil) error("urlcombine: u == nil"); if(validurl(u)) return erunestrdup(u); if(b==nil || !validurl(b)) error("urlcombine: b==nil || !validurl(b)"); if(runestrncmp(u, L"//", 2) == 0){ q = runestrchr(b, L':'); return runesmprint("%.*S:%S", (int)(q-b), b, u); } p = runestrstr(b, L"://"); if(p != nil) p += 3; sep = L""; q = nil; if(*u ==L'/') q = runestrchr(p, L'/'); else if(*u==L'#' || *u==L'?'){ for(i=0; i<nelem(endrune); i++) if(q = runestrchr(p, endrune[i])) break; }else if(p != nil){ sep = L"/"; restore = 0; s = runestrchr(p, L'?'); if(s != nil){ *s = '\0'; restore = 1; } q = runestrrchr(p, L'/'); if(restore) *s = L'?'; }else sep = L"/"; if(q == nil) p = runesmprint("%S%S%S", b, sep, u); else p = runesmprint("%.*S%S%S", (int)(q-b), b, sep, u); urlcanon(p); return p; }
/* define macro - .de, .am, .ig */ void r_de(int argc, Rune **argv) { Rune *end, *p; Fmt fmt; int ignore, len; delreq(argv[1]); delraw(argv[1]); ignore = runestrcmp(argv[0], L("ig")) == 0; if(!ignore) runefmtstrinit(&fmt); end = L(".."); if(argc >= 3) end = argv[2]; if(runestrcmp(argv[0], L("am")) == 0 && (p=getds(argv[1])) != nil) fmtrunestrcpy(&fmt, p); len = runestrlen(end); while((p = readline(CopyMode)) != nil){ if(runestrncmp(p, end, len) == 0 && (p[len]==' ' || p[len]==0 || p[len]=='\t' || (p[len]=='\\' && p[len+1]=='}'))){ free(p); goto done; } if(!ignore) fmtprint(&fmt, "%S\n", p); free(p); } warn("eof in %C%S %S - looking for %#Q", dot, argv[0], argv[1], end); done: if(ignore) return; p = runefmtstrflush(&fmt); if(p == nil) sysfatal("out of memory"); ds(argv[1], p); free(p); }