void startoutput(void) { char *align; double ps, vs, lm, rm, ti; Rune buf[200]; if(isoutput) return; isoutput = 1; if(getnr(L(".paragraph")) == 0) return; nr(L(".ns"), 0); isoutput = 1; ps = getnr(L(".s")); if(ps <= 1) ps = 10; ps /= 72.0; USED(ps); vs = getnr(L(".v"))*getnr(L(".ls")) * 1.0/UPI; vs /= (10.0/72.0); /* ps */ if(vs == 0) vs = 1.2; lm = (getnr(L(".o"))+getnr(L(".i"))) * 1.0/UPI; ti = getnr(L(".ti")) * 1.0/UPI; nr(L(".ti"), 0); rm = 8.0 - getnr(L(".l"))*1.0/UPI - getnr(L(".o"))*1.0/UPI; if(rm < 0) rm = 0; switch(getnr(L(".j"))){ default: case 0: align = "left"; break; case 1: align = "justify"; break; case 3: align = "center"; break; case 5: align = "right"; break; } if(getnr(L(".ce"))) align = "center"; if(!getnr(L(".margin"))) runesnprint(buf, nelem(buf), "<p style=\"line-height: %.1fem; text-indent: %.2fin; margin-top: 0; margin-bottom: 0; text-align: %s;\">\n", vs, ti, align); else runesnprint(buf, nelem(buf), "<p style=\"line-height: %.1fem; margin-left: %.2fin; text-indent: %.2fin; margin-right: %.2fin; margin-top: 0; margin-bottom: 0; text-align: %s;\">\n", vs, lm, ti, rm, align); outhtml(buf); }
/* .em - invoke macro when all input is over */ void r_em(int argc, Rune **argv) { Rune buf[20]; USED(argc); runesnprint(buf, nelem(buf), ".%S\n", argv[1]); as(L("eof"), buf); }
/* .sv - save a contiguous vertical block */ void sp(int v) { Rune buf[100]; double fv; br(); fv = v * 1.0/UPI; if(fv > 5) fv = eval(L("1v")) * 1.0/UPI; runesnprint(buf, nelem(buf), "<p style=\"margin-top: 0; margin-bottom: %.2fin\"></p>\n", fv); outhtml(buf); }
int e_w(void) { Rune *a; Rune buf[40]; a = getqarg(); runesnprint(buf, sizeof buf, "%ld", runestrlen(a)); pushinputstring(buf); nr(L("st"), 0); nr(L("sb"), 0); nr(L("ct"), 0); return 0; }
void readfile(Column *c, char *s) { Window *w; Rune rb[256]; int nr; Runestr rs; w = coladd(c, nil, nil, -1); if(s[0] != '/') runesnprint(rb, sizeof rb, "%s/%s", wdir, s); else runesnprint(rb, sizeof rb, "%s", s); nr = runestrlen(rb); rs = cleanrname(runestr(rb, nr)); winsetname(w, rs.r, rs.nr); textload(&w->body, 0, s, 1); w->body.file->mod = FALSE; w->dirty = FALSE; winsettag(w); winresize(w, w->r, FALSE, TRUE); textscrdraw(&w->body); textsetselect(&w->tag, w->tag.file->b.nc, w->tag.file->b.nc); }
void _appleputsnarf(char *s) { CFDataRef cfdata; PasteboardSyncFlags flags; /* fprint(2, "appleputsnarf\n"); */ if(strlen(s) >= SnarfSize) return; qlock(&clip.lk); strcpy(clip.buf, s); runesnprint(clip.rbuf, nelem(clip.rbuf), "%s", s); if(clip.apple == nil){ if(PasteboardCreate(kPasteboardClipboard, &clip.apple) != noErr){ fprint(2, "apple pasteboard create failed\n"); qunlock(&clip.lk); return; } } if(PasteboardClear(clip.apple) != noErr){ fprint(2, "apple pasteboard clear failed\n"); qunlock(&clip.lk); return; } flags = PasteboardSynchronize(clip.apple); if((flags&kPasteboardModified) || !(flags&kPasteboardClientIsOwner)){ fprint(2, "apple pasteboard cannot assert ownership\n"); qunlock(&clip.lk); return; } cfdata = CFDataCreate(kCFAllocatorDefault, (uchar*)clip.rbuf, runestrlen(clip.rbuf)*2); if(cfdata == nil){ fprint(2, "apple pasteboard cfdatacreate failed\n"); qunlock(&clip.lk); return; } if(PasteboardPutItemFlavor(clip.apple, (PasteboardItemID)1, CFSTR("public.utf16-plain-text"), cfdata, 0) != noErr){ fprint(2, "apple pasteboard putitem failed\n"); CFRelease(cfdata); qunlock(&clip.lk); return; } /* CFRelease(cfdata); ??? */ qunlock(&clip.lk); }
int e_w(void) { Rune *a; Rune buf[40]; static Rune zero; a = getqarg(); if(a == nil){ warn("no arg for \\w"); a = &zero; } runesnprint(buf, sizeof buf, "%ld", runestrlen(a)); pushinputstring(buf); nr(L("st"), 0); nr(L("sb"), 0); nr(L("ct"), 0); return 0; }
Window* openfile(Text *t, Expand *e) { Range r; Window *w, *ow; int eval, i, n; Rune *rp; Runestr rs; uint dummy; r.q0 = 0; r.q1 = 0; if(e->nname == 0){ w = t->w; if(w == nil) return nil; }else{ w = lookfile(e->name, e->nname); if(w == nil && e->name[0] != '/'){ /* * Unrooted path in new window. * This can happen if we type a pwd-relative path * 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. * Make the name a full path, just like we would if * opening via the plumber. */ n = utflen(wdir)+1+e->nname+1; rp = runemalloc(n); runesnprint(rp, n, "%s/%.*S", wdir, e->nname, e->name); rs = cleanrname(runestr(rp, n-1)); free(e->name); e->name = rs.r; e->nname = rs.nr; w = lookfile(e->name, e->nname); } } if(w){ t = &w->body; if(!t->col->safe && t->fr.maxlines==0) /* window is obscured by full-column window */ colgrow(t->col, t->col->w[0], 1); }else{ ow = nil; if(t) ow = t->w; w = makenewwindow(t); t = &w->body; winsetname(w, e->name, e->nname); if(textload(t, 0, e->bname, 1) >= 0) t->file->unread = FALSE; t->file->mod = FALSE; t->w->dirty = FALSE; winsettag(t->w); textsetselect(&t->w->tag, t->w->tag.file->b.nc, t->w->tag.file->b.nc); if(ow != nil){ for(i=ow->nincl; --i>=0; ){ n = runestrlen(ow->incl[i]); rp = runemalloc(n); runemove(rp, ow->incl[i], n); winaddincl(w, rp, n); } w->autoindent = ow->autoindent; }else w->autoindent = globalautoindent; xfidlog(w, "new"); } if(e->a1 == e->a0) eval = FALSE; else{ eval = TRUE; r = address(TRUE, t, range(-1,-1), range(t->q0, t->q1), e->u.at, e->a0, e->a1, e->agetc, &eval, &dummy); if(r.q0 > r.q1) { eval = FALSE; warning(nil, "addresses out of order\n"); } if(eval == FALSE) e->jump = FALSE; /* don't jump if invalid address */ } if(eval == FALSE){ r.q0 = t->q0; r.q1 = t->q1; } textshow(t, r.q0, r.q1, 1); winsettag(t->w); seltext = t; if(e->jump) moveto(mousectl, addpt(frptofchar(&t->fr, t->fr.p0), Pt(4, font->height-4))); return w; }