/* * Creating controls. */ control newcontrol(char *text, rect r) { control obj; ensure_window(); obj = newwindow(text, r, ChildWindow | TrackMouse); if (obj) { obj->kind = UserObject; obj->die = private_delcontrol; } set_new_winproc(obj); /* set custom winproc */ show(obj); return obj; }
void listwindow () { Window r_root, r_parent, *r_ch; unsigned int n_ch, i; if (!XQueryTree (Dpy, Root, &r_root, &r_parent, &r_ch, &n_ch)) return; n = 0; for (i = 0; i < n_ch; i++) newwindow (r_ch[i]); XFree (r_ch); }
void wikinew(char *arg) { static int n; Wiki *w; w = emalloc(sizeof *w); if(arg) arg = estrdup(arg); w->arg = arg; w->win = newwindow(); w->isnew = ++n; proccreate(wineventproc, w->win, STACK); threadcreate(wikithread, w, STACK); }
int mesgopen(char *s) { char *p, tmp[40]; int fd, n; Article *m; n = atoi(s); if(n==0) return 0; for(m=mlist; m; m=m->next){ if(m->n == n){ ctlprint(m->w->ctl, "show\n"); return 1; } } sprint(tmp, "%d/article", n); p = estrstrdup(dir, tmp); if((fd = open(p, OREAD)) < 0){ free(p); return 0; } m = emalloc(sizeof(*m)); m->w = newwindow(); m->n = n; proccreate(wineventproc, m->w, STACK); p[strlen(p)-strlen("article")] = '\0'; winname(m->w, p); if(canpost) wintagwrite(m->w, "Reply ", 6); wintagwrite(m->w, "Headers ", 8); free(p); if(mlist){ m->next = mlist; mlist->prev = m; } mlist = m; threadcreate(mesgthread, m, STACK); fillmesgwindow(fd, m); close(fd); windormant(m->w); return 1; }
/* winProgressBar(width, title, label, min, max, initial) */ SEXP winProgressBar(SEXP call, SEXP op, SEXP args, SEXP env) { SEXP tmp, ptr; int width, iv; double d; const char *title, *label; winprogressbar *pbar; Rboolean haveLabel; args = CDR(args); pbar = Calloc(1, winprogressbar); width = asInteger(CAR(args)); args = CDR(args); if(width == NA_INTEGER || width < 0) width = 200; tmp = CAR(args); args = CDR(args); if(!isString(tmp) || length(tmp) < 1 || STRING_ELT(tmp, 0) == NA_STRING) errorcall(call, "invalid '%s' argument", "title"); title = translateChar(STRING_ELT(tmp, 0)); tmp = CAR(args); args = CDR(args); if(!isString(tmp) || length(tmp) < 1 || STRING_ELT(tmp, 0) == NA_STRING) errorcall(call, "invalid '%s' argument", "Label"); label = translateChar(STRING_ELT(tmp, 0)); haveLabel = strlen(label) > 0; d = asReal(CAR(args)); args = CDR(args); if (!R_FINITE(d)) errorcall(call, "invalid '%s' argument", "min"); pbar->min = d; d = asReal(CAR(args)); args = CDR(args); if (!R_FINITE(d)) errorcall(call, "invalid '%s' argument", "max"); pbar->max = d; d = asReal(CAR(args)); args = CDR(args); if (!R_FINITE(d)) errorcall(call, "invalid '%s' argument", "initial"); pbar->val = d; pbar->width = width; pbar->wprog = newwindow(title, rect(0, 0, width+40, haveLabel ? 100: 80), Titlebar | Centered); setbackground(pbar->wprog, dialog_bg()); if(haveLabel) pbar->lab = newlabel(label, rect(10, 15, width+20, 25), AlignCenter); pbar->pb = newprogressbar(rect(20, haveLabel ? 50 : 30, width, 20), 0, width, 1, 1); iv = pbar->width * (pbar->val - pbar->min)/(pbar->max - pbar->min); setprogressbar(pbar->pb, iv); show(pbar->wprog); ptr = R_MakeExternalPtr(pbar, install("winProgressBar"), R_NilValue); R_RegisterCFinalizerEx(ptr, pbarFinalizer, TRUE); return ptr; }
void threadmain(int argc, char **argv) { Scsi *s; Drive *d; char buf[80]; ARGBEGIN{ case 'v': debug++; scsiverbose++; }ARGEND if(argc != 1) usage(); fmtinstall('M', msfconv); if((s = openscsi(argv[0])) == nil) error("opening scsi: %r"); d = malloc(sizeof(*d)); if(d == nil) error("out of memory"); memset(d, 0, sizeof d); d->scsi = s; d->w = newwindow(); d->ctocdisp = chancreate(sizeof(Toc), 0); d->cdbreq = chancreate(sizeof(Toc), 0); d->cdbreply = chancreate(sizeof(Toc), 0); d->cstatus = chancreate(sizeof(Cdstatus), 0); proccreate(wineventproc, d->w, STACK); proccreate(cddbproc, d, STACK); proccreate(cdstatusproc, d, STACK); cleanname(argv[0]); snprint(buf, sizeof(buf), "%s/", argv[0]); winname(d->w, buf); wintagwrite(d->w, "Stop Pause Resume Eject Ingest ", 5+6+7+6+7); eventwatcher(d); }
static window init_askstr_dialog(const char *title, const char *question, const char *default_str) { window win; dialog_data *d; int tw, bw, h, middle; if (! question) question= ""; if (! default_str) default_str = ""; tw = strwidth(SystemFont, G_("Cancel")) * 8; h = getheight(SystemFont); if (tw < 150) tw = 150; win = newwindow(title, rect(0,0,tw+30,h*9+12), Titlebar | Centered | Modal); setbackground(win, dialog_bg()); add_data(win); d = data(win); d->question = newlabel(question, rect(10,h,tw+4,h*2+2), AlignLeft); if (title == PASSWORD_TITLE) d->text = newpassword(default_str, rect(10,h*4,tw+4,h*3/2)); else d->text = newfield(default_str, rect(10,h*4,tw+4,h*3/2)); middle = (tw+30)/2; bw = strwidth(SystemFont, G_("Cancel")) * 3/2; d->yes = newbutton(G_("OK"), rect(middle-bw-10, h*7, bw, h+10), hit_button); setvalue(d->yes, YES); d->cancel = newbutton(G_("Cancel"), rect(middle+10, h*7, bw, h+10), hit_button); setvalue(d->cancel, CANCEL); setkeydown(win, hit_key); return win; }
int newpipewin(int pid, char *p) { int id; Window *w; Wpid *wp; w = newwindow(); winname(w, p); wintagwrite(w, "Send ", 5); wp = emalloc(sizeof(Wpid)); wp->pid = pid; wp->w = w; wp->next = wpid; /* BUG: this happens in fsread proc (we don't use wpid, so it's okay) */ wpid = wp; id = w->id; sendp(newpipechan, w); return id; }
static void create_dialog() { setcursor(ArrowCursor); /* not `busy' cursor */ win = newwindow("t-test entry", rect(0, 0, 200, 200), Titlebar | Centered | Modal); setbackground(win, dialog_bg()); setkeydown(win, hit_key); bApply = newbutton("Apply", rect(20, 160, 50, 25), apply); bCancel = newbutton("Cancel", rect(120, 160, 50, 25), NULL); l_var1 = newlabel("x", rect(10, 10, 30, 20), AlignLeft); var1 = newfield("", rect(40, 10, 130, 20)); l_var2 = newlabel("y", rect(10, 40, 30, 20), AlignLeft); var2 = newfield("", rect(40, 40, 130, 20)); paired = newcheckbox("paired", rect(10, 70, 80, 20), NULL); varequal = newcheckbox("equal var", rect(110, 70, 80, 20), NULL); alt = newdroplist(alts , rect(30, 90, 120, 20), NULL); setlistitem(alt, 0); l_lvl = newlabel("confidence level", rect(20, 120, 90, 20), AlignLeft); lvl = newfield("0.95", rect(120, 120, 40, 20)); }
void mainloop () { XEvent e; Window wn; XSelectInput (Dpy, Root, SubstructureRedirectMask | SubstructureNotifyMask); for (;;) { XNextEvent (Dpy, &e); switch (e.type) { case ConfigureRequest: wn = e.xconfigurerequest.window; if ((e.xconfigurerequest.value_mask & CWStackMode) && (!e.xconfigurerequest.above) && (e.xconfigurerequest.detail == Above)) { XRaiseWindow (Dpy, wn); listwindow (); arrange (); } else if (e.xconfigurerequest.value_mask & CWWidth && wn == client[n - 1]) { w = e.xconfigurerequest.width; arrange (); } break; case MapRequest: wn = e.xmaprequest.window; XMapRaised (Dpy, wn); newwindow (wn); arrange (); break; case UnmapNotify: listwindow (); arrange (); break; } } }
int wikiopen(char *arg, char *addr) { Dir *d; char *p; Wiki *w; /* if(arg==nil){ if(write(mapfd, title, strlen(title)) < 0 || seek(mapfd, 0, 0) < 0 || (n=read(mapfd, tmp, sizeof(tmp)-2)) < 0){ fprint(2, "Wiki: no page '%s' found: %r\n", title); return -1; } if(tmp[n-1] == '\n') tmp[--n] = '\0'; tmp[n++] = '/'; tmp[n] = '\0'; arg = tmp; } */ /* replace embedded '\n' in links by ' ' */ for(p=arg; *p; p++) if(*p=='\n') *p = ' '; if(strncmp(arg, dir, strlen(dir))==0 && arg[strlen(dir)]=='/' && arg[strlen(dir)+1]) arg += strlen(dir)+1; else if(arg[0] == '/') return -1; if((d = dirstat(arg)) == nil) return -1; if((d->mode&DMDIR) && arg[strlen(arg)-1] != '/'){ p = emalloc(strlen(arg)+2); strcpy(p, arg); strcat(p, "/"); arg = p; }else if(!(d->mode&DMDIR) && arg[strlen(arg)-1]=='/'){ arg = estrdup(arg); arg[strlen(arg)-1] = '\0'; }else arg = estrdup(arg); free(d); /* rewrite /current into / */ if(strlen(arg) > 8 && strcmp(arg+strlen(arg)-8, "/current")==0) arg[strlen(arg)-8+1] = '\0'; /* look for window already open */ for(w=wlist; w; w=w->next){ if(strcmp(w->arg, arg)==0){ ctlprint(w->win->ctl, "show\n"); return 0; } } w = emalloc(sizeof *w); w->arg = arg; w->addr = addr; w->win = newwindow(); link(w); proccreate(wineventproc, w->win, STACK); threadcreate(wikithread, w, STACK); return 0; }
SEXP Win_selectlist(SEXP args) { SEXP choices, preselect, ans = R_NilValue; const char **clist; int i, j = -1, n, mw = 0, multiple, nsel = 0; int xmax, ymax, ylist, fht, h0; Rboolean haveTitle; choices = CAR(args); if(!isString(choices)) error(_("invalid '%s' argument"), "choices"); preselect = CADR(args); if(!isNull(preselect) && !isString(preselect)) error(_("invalid '%s' argument"), "preselect"); multiple = asLogical(CADDR(args)); if(multiple == NA_LOGICAL) multiple = 0; haveTitle = isString(CADDDR(args)); if(!multiple && isString(preselect) && LENGTH(preselect) != 1) error(_("invalid '%s' argument"), "preselect"); n = LENGTH(choices); clist = (const char **) R_alloc(n + 1, sizeof(char *)); for(i = 0; i < n; i++) { clist[i] = translateChar(STRING_ELT(choices, i)); mw = max(mw, gstrwidth(NULL, SystemFont, clist[i])); } clist[n] = NULL; fht = getSysFontSize().height; xmax = max(170, mw+60); /* allow for scrollbar */ if(ismdi()) { RECT *pR = RgetMDIsize(); h0 = pR->bottom; } else { h0 = deviceheight(NULL); } ymax = min(80+fht*n, h0-100); /* allow for window widgets, toolbar */ ylist = ymax - 60; wselect = newwindow(haveTitle ? translateChar(STRING_ELT(CADDDR(args), 0)): (multiple ? _("Select one or more") : _("Select one")), rect(0, 0, xmax, ymax), Titlebar | Centered | Modal | Floating); setbackground(wselect, dialog_bg()); if(multiple) f_list = newmultilist(clist, rect(10, 10, xmax-25, ylist), NULL, finish); else f_list = newlistbox(clist, rect(10, 10, xmax-25, ylist), NULL, finish); if(!isNull(preselect) && LENGTH(preselect)) { for(i = 0; i < n; i++) for(j = 0; j < LENGTH(preselect); j++) if(strcmp(clist[i], translateChar(STRING_ELT(preselect, j))) == 0) { setlistitem(f_list, i); break; } } bFinish = newbutton(G_("OK"), rect(xmax-160, ymax-40, 70, 25), finish); bCancel = newbutton(G_("Cancel"), rect(xmax-80, ymax-40, 70, 25), cancel); setkeydown(wselect, key1); show(wselect); done = 0; while(!done) { R_WaitEvent(); R_ProcessEvents(); } if(multiple) { if (done == 1) { /* Finish */ for(i = 0; i < n; i++) if(isselected(f_list, i)) nsel++; PROTECT(ans = allocVector(STRSXP, nsel)); for(i = 0, j = 0; i < n; i++) if(isselected(f_list, i)) SET_STRING_ELT(ans, j++, mkChar(clist[i])); } else { /* cancel */ PROTECT(ans = allocVector(STRSXP, 0)); } } else PROTECT(ans = mkString(selected)); cleanup(); show(RConsole); R_ProcessEvents(); UNPROTECT(1); return ans; }
void mkreply(Message *m, char *label, char *to, Plumbattr *attr, char *quotetext) { char buf[100]; CFid *fd; Message *r; char *dir, *t; int quotereply; Plumbattr *a; quotereply = (label[0] == 'Q'); if(quotereply && m && m->replywinid > 0){ snprint(buf, sizeof buf, "%d/body", m->replywinid); if((fd = fsopen(acmefs, buf, OWRITE)) != nil){ dir = estrstrdup(mbox.name, m->name); quote(m, fd, dir, quotetext); free(dir); return; } } r = emalloc(sizeof(Message)); r->isreply = 1; if(m != nil) r->replyname = estrdup(m->name); r->next = replies.head; r->prev = nil; if(replies.head != nil) replies.head->prev = r; replies.head = r; if(replies.tail == nil) replies.tail = r; r->name = emalloc(strlen(mbox.name)+strlen(label)+10); sprint(r->name, "%s%s%d", mbox.name, label, ++replyid); r->w = newwindow(); if(m) m->replywinid = r->w->id; winname(r->w, r->name); ctlprint(r->w->ctl, "cleartag"); wintagwrite(r->w, "fmt Look Post Undo", 4+5+5+4); r->tagposted = 1; threadcreate(mesgctl, r, STACK); winopenbody(r->w, OWRITE); if(to!=nil && to[0]!='\0') fsprint(r->w->body, "%s\n", to); for(a=attr; a; a=a->next) fsprint(r->w->body, "%s: %s\n", a->name, a->value); dir = nil; if(m != nil){ dir = estrstrdup(mbox.name, m->name); if(to == nil && attr == nil){ /* Reply goes to replyto; Reply all goes to From and To and CC */ if(strstr(label, "all") == nil) fsprint(r->w->body, "To: %s\n", m->replyto); else{ /* Replyall */ if(strlen(m->from) > 0) fsprint(r->w->body, "To: %s\n", m->from); if(strlen(m->to) > 0) fsprint(r->w->body, "To: %s\n", m->to); if(strlen(m->cc) > 0) fsprint(r->w->body, "CC: %s\n", m->cc); } } if(strlen(m->subject) > 0){ t = "Subject: Re: "; if(strlen(m->subject) >= 3) if(tolower(m->subject[0])=='r' && tolower(m->subject[1])=='e' && m->subject[2]==':') t = "Subject: "; fsprint(r->w->body, "%s%s\n", t, m->subject); } if(!quotereply){ fsprint(r->w->body, "Include: %sraw\n", dir); free(dir); } } fsprint(r->w->body, "\n"); if(m == nil) fsprint(r->w->body, "\n"); else if(quotereply){ quote(m, r->w->body, dir, quotetext); free(dir); } winclosebody(r->w); if(m==nil && (to==nil || to[0]=='\0')) winselect(r->w, "0", 0); else winselect(r->w, "$", 0); winclean(r->w); windormant(r->w); }
static pager pagercreate(void) { ConsoleData p; int w, h, i, x, y, w0, h0; pager c; menuitem m; p = newconsoledata((consolefn) ? consolefn : FixedFont, pagerrow, pagercol, 0, 0, guiColors, PAGER, 0, 0); if (!p) return NULL; /* if (ismdi()) { x = y = w = h = 0; } else { w = WIDTH ; h = HEIGHT; x = (devicewidth(NULL) - w) / 2; y = (deviceheight(NULL) - h) / 2 ; } */ w = WIDTH ; h = HEIGHT; /* centre a single pager, randomly place each of multiple pagers */ #ifdef USE_MDI if(ismdi()) { RECT *pR = RgetMDIsize(); w0 = pR->right; h0 = pR->bottom; } else { #endif w0 = devicewidth(NULL); h0 = deviceheight(NULL); #ifdef USE_MDI } #endif x = (w0 - w) / 2; x = x > 20 ? x:20; y = (h0 - h) / 2; y = y > 20 ? y:20; if(pagerMultiple) { #ifdef Win32 DWORD rand = GetTickCount(); #else int rand = 0; #endif int w0 = 0.4*x, h0 = 0.4*y; w0 = w0 > 20 ? w0 : 20; h0 = h0 > 20 ? h0 : 20; x += (rand % w0) - w0/2; y += ((rand/w0) % h0) - h0/2; } c = (pager) newwindow("PAGER", rect(x, y, w, h), Document | StandardWindow | Menubar | VScrollbar | HScrollbar | TrackMouse); if (!c) { freeConsoleData(p); return NULL; } setdata(c, p); if(h == 0) HEIGHT = getheight(c); if(w == 0) WIDTH = getwidth(c); COLS = WIDTH / FW - 1; ROWS = HEIGHT / FH - 1; BORDERX = (WIDTH - COLS*FW) / 2; BORDERY = (HEIGHT - ROWS*FH) / 2; gsetcursor(c, ArrowCursor); gchangescrollbar(c, VWINSB, 0, 0, ROWS, 0); gchangescrollbar(c, HWINSB, 0, COLS-1, COLS, 1); setbackground(c, guiColors[pagerbg]); #ifdef USE_MDI if (ismdi()) { int btsize = 24; rect r = rect(2, 2, btsize, btsize); control tb, bt; addto(c); MCHECK(tb = newtoolbar(btsize + 4)); gsetcursor(tb, ArrowCursor); addto(tb); MCHECK(bt = newtoolbutton(open_image, r, menueditoropen)); MCHECK(addtooltip(bt, G_("Open script"))); gsetcursor(bt, ArrowCursor); /* wants NULL as data, not the pager */ r.x += (btsize + 6) ; MCHECK(bt = newtoolbutton(copy1_image, r, pagerpaste)); MCHECK(addtooltip(bt, G_("Paste to console"))); gsetcursor(bt, ArrowCursor); setdata(bt, (void *) c); r.x += (btsize + 6) ; MCHECK(bt = newtoolbutton(copy1_image, r, pagerpastecmds)); MCHECK(addtooltip(bt, G_("Paste commands to console"))); gsetcursor(bt, ArrowCursor); setdata(bt, (void *) c); r.x += (btsize + 6) ; MCHECK(bt = newtoolbutton(print_image, r, pagerprint)); MCHECK(addtooltip(bt, G_("Print"))); gsetcursor(bt, ArrowCursor); setdata(bt, (void *) c); r.x += (btsize + 6) ; MCHECK(bt = newtoolbutton(console_image, r, pagerconsole)); MCHECK(addtooltip(bt, G_("Return focus to Console"))); gsetcursor(bt, ArrowCursor); setdata(bt, (void *) c); } #endif addto(c); MCHECK(m = gpopup(pagermenuact, PagerPopup)); setdata(m, c); setdata(p->mpopcopy = PagerPopup[0].m, c); setdata(p->mpoppaste = PagerPopup[1].m, c); setdata(p->mpoppastecmds = PagerPopup[2].m, c); setdata(PagerPopup[3].m, c); setdata(PagerPopup[5].m, c); setdata(PagerPopup[7].m, c); MCHECK(m = newmenubar(pagermenuact)); setdata(m, c); MCHECK(newmenu(G_("File"))); MCHECK(m = newmenuitem(G_("New script"), 'N', menueditornew)); MCHECK(m = newmenuitem(G_("Open script..."), 'O', menueditoropen)); MCHECK(m = newmenuitem(G_("Print..."), 'P', pagerprint)); setdata(m, c); MCHECK(m = newmenuitem(G_("Save to File..."), 'S', pagersavefile)); setdata(m, c); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(m = newmenuitem(G_("Close"), 0, pagerclose)); setdata(m, c); MCHECK(newmenu(G_("Edit"))); MCHECK(p->mcopy = newmenuitem(G_("Copy"), 'C', pagercopy)); setdata(p->mcopy, c); MCHECK(p->mpaste = newmenuitem(G_("Paste to console"), 'V', pagerpaste)); setdata(p->mpaste, c); MCHECK(p->mpastecmds = newmenuitem(G_("Paste commands to console"), 0, pagerpastecmds)); setdata(p->mpastecmds, c); MCHECK(m = newmenuitem(G_("Select all"), 'A', pagerselectall)); setdata(m, c); if (!pagerMultiple) { MCHECK(newmenu(G_("View"))); for (i = 0; i < PAGERMAXKEPT; i++) { snprintf(pagerTitles[i], PAGERMAXTITLE+8, "&%c. ", 'A' + i); MCHECK(pagerMenus[i] = newmenuitem(&pagerTitles[i][1], 0, pagerchangeview)); setvalue(pagerMenus[i], i); } } #ifdef USE_MDI if (ismdi()) newmdimenu(); if (ismdi() && !(RguiMDI & RW_TOOLBAR)) toolbar_hide(); #endif MCHECK(BM = newbitmap(WIDTH, HEIGHT, 2)); setdata(c, p); sethit(c, console_sbf); setresize(c, consoleresize); setredraw(c, drawconsole); setdel(c, delpager); setclose(c, pagerbclose); setkeyaction(c, console_ctrlkeyin); setkeydown(c, console_normalkeyin); setmousedrag(c, console_mousedrag); setmouserepeat(c, console_mouserep); setmousedown(c, console_mousedown); return(c); }
void threadmain(int argc, char *argv[]) { char *s, *name; char err[ERRMAX], *cmd; int i, newdir; Fmt fmt; doquote = needsrcquote; quotefmtinstall(); /* open these early so we won't miss notification of new mail messages while we read mbox */ if((plumbsendfd = plumbopenfid("send", OWRITE|OCEXEC)) == nil) fprint(2, "warning: open plumb/send: %r\n"); if((plumbseemailfd = plumbopenfid("seemail", OREAD|OCEXEC)) == nil) fprint(2, "warning: open plumb/seemail: %r\n"); if((plumbshowmailfd = plumbopenfid("showmail", OREAD|OCEXEC)) == nil) fprint(2, "warning: open plumb/showmail: %r\n"); shortmenu = 0; srvname = "mail"; ARGBEGIN{ case 's': shortmenu = 1; break; case 'S': shortmenu = 2; break; case 'o': outgoing = EARGF(usage()); break; case 'm': smprint(maildir, "%s/", EARGF(usage())); break; case 'n': srvname = EARGF(usage()); break; default: usage(); }ARGEND acmefs = nsmount("acme",nil); if(acmefs == nil) error("cannot mount acme: %r"); mailfs = nsmount(srvname, nil); if(mailfs == nil) error("cannot mount %s: %r", srvname); name = "mbox"; newdir = 1; if(argc > 0){ i = strlen(argv[0]); if(argc>2 || i==0) usage(); /* see if the name is that of an existing /mail/fs directory */ if(argc==1 && argv[0][0] != '/' && ismaildir(argv[0])){ name = argv[0]; mboxname = estrdup(name); newdir = 0; }else{ if(argv[0][i-1] == '/') argv[0][i-1] = '\0'; s = strrchr(argv[0], '/'); if(s == nil) mboxname = estrdup(argv[0]); else{ *s++ = '\0'; if(*s == '\0') usage(); mailboxdir = argv[0]; mboxname = estrdup(s); } if(argc > 1) name = argv[1]; else name = mboxname; } } user = getenv("user"); if(user == nil) user = "******"; home = getenv("home"); if(home == nil) home = getenv("HOME"); if(home == nil) error("can't find $home"); if(mailboxdir == nil) mailboxdir = estrstrdup(home, "/mail"); if(outgoing == nil) outgoing = estrstrdup(mailboxdir, "/outgoing"); mbox.ctlfd = fsopen(mailfs, estrstrdup(mboxname, "/ctl"), OWRITE); if(mbox.ctlfd == nil) error("can't open %s: %r", estrstrdup(mboxname, "/ctl")); fsname = estrdup(name); if(newdir && argc > 0){ s = emalloc(5+strlen(mailboxdir)+strlen(mboxname)+strlen(name)+10+1); for(i=0; i<10; i++){ sprint(s, "open %s/%s %s", mailboxdir, mboxname, fsname); if(fswrite(mbox.ctlfd, s, strlen(s)) >= 0) break; err[0] = '\0'; errstr(err, sizeof err); if(strstr(err, "mbox name in use") == nil) error("can't create directory %s for mail: %s", name, err); free(fsname); fsname = emalloc(strlen(name)+10); sprint(fsname, "%s-%d", name, i); } if(i == 10) error("can't open %s/%s: %r", mailboxdir, mboxname); free(s); } s = estrstrdup(fsname, "/"); mbox.name = estrstrdup(maildir, s); mbox.level= 0; readmbox(&mbox, maildir, s); home = getenv("home"); if(home == nil) home = "/"; wbox = newwindow(); winname(wbox, mbox.name); wintagwrite(wbox, "Put Mail Delmesg ", 3+1+4+1+7+1); threadcreate(mainctl, wbox, STACK); fmtstrinit(&fmt); fmtprint(&fmt, "Mail"); if(shortmenu) fmtprint(&fmt, " -%c", "sS"[shortmenu-1]); if(outgoing) fmtprint(&fmt, " -o %s", outgoing); fmtprint(&fmt, " %s", name); cmd = fmtstrflush(&fmt); if(cmd == nil) sysfatal("out of memory"); winsetdump(wbox, "/acme/mail", cmd); mbox.w = wbox; mesgmenu(wbox, &mbox); winclean(wbox); /* wctlfd = open("/dev/wctl", OWRITE|OCEXEC); /* for acme window */ wctlfd = -1; cplumb = chancreate(sizeof(Plumbmsg*), 0); cplumbshow = chancreate(sizeof(Plumbmsg*), 0); if(strcmp(name, "mbox") == 0){ /* * Avoid creating multiple windows to send mail by only accepting * sendmail plumb messages if we're reading the main mailbox. */ plumbsendmailfd = plumbopenfid("sendmail", OREAD|OCEXEC); cplumbsend = chancreate(sizeof(Plumbmsg*), 0); proccreate(plumbsendproc, nil, STACK); threadcreate(plumbsendthread, nil, STACK); } /* start plumb reader as separate proc ... */ proccreate(plumbproc, nil, STACK); proccreate(plumbshowproc, nil, STACK); threadcreate(plumbshowthread, nil, STACK); fswrite(mbox.ctlfd, "refresh", 7); /* ... and use this thread to read the messages */ plumbthread(); }
int mesgopen(Message *mbox, char *dir, char *s, Message *mesg, int plumbed, char *digest) { char *t, *u, *v; Message *m; char *direlem[10]; int i, ndirelem, reuse; /* find white-space-delimited first word */ for(t=s; *t!='\0' && !isspace(*t); t++) ; u = emalloc(t-s+1); memmove(u, s, t-s); /* separate it on slashes */ ndirelem = tokenizec(u, direlem, nelem(direlem), "/"); if(ndirelem <= 0){ Error: free(u); return 0; } if(plumbed){ write(wctlfd, "top", 3); write(wctlfd, "current", 7); } /* open window for message */ m = mesglookup(mbox, direlem[0], digest); if(m == nil) goto Error; if(mesg!=nil && m!=mesg) /* string looked like subpart but isn't part of this message */ goto Error; if(m->opened == 0){ if(m->w == nil){ reuse = 0; m->w = newwindow(); }else{ reuse = 1; /* re-use existing window */ if(winsetaddr(m->w, "0,$", 1)){ if(m->w->data < 0) m->w->data = winopenfile(m->w, "data"); write(m->w->data, "", 0); } } v = estrstrdup(mbox->name, m->name); winname(m->w, v); free(v); if(!reuse){ if(m->deleted) wintagwrite(m->w, "Q Reply all UnDelmesg Save ", 2+6+4+10+5); else wintagwrite(m->w, "Q Reply all Delmesg Save ", 2+6+4+8+5); } threadcreate(mesgctl, m, STACK); winopenbody(m->w, OWRITE); mesgload(m, dir, m->name, m->w); winclosebody(m->w); winclean(m->w); m->opened = 1; if(ndirelem == 1){ free(u); return 1; } } if(ndirelem == 1 && plumbport(m->type, m->filename) <= 0){ /* make sure dot is visible */ ctlprint(m->w->ctl, "show\n"); return 0; } /* walk to subpart */ dir = estrstrdup(dir, m->name); for(i=1; i<ndirelem; i++){ m = mesglookup(m, direlem[i], digest); if(m == nil) break; dir = egrow(dir, m->name, nil); } if(m != nil && plumbport(m->type, m->filename) > 0) plumb(m, dir); free(dir); free(u); return 1; }
void threadmain(int argc, char *argv[]) { int i, j; char *dir, *tag, *name; char buf[1024], **av; quotefmtinstall(); rfork(RFNAMEG); ARGBEGIN{ case 'd': debug = 1; chatty9p++; break; case 'e': eraseinput = 1; break; case 'D': {extern int _threaddebuglevel; _threaddebuglevel = 1<<20; } }ARGEND if(argc == 0){ av = emalloc(3*sizeof(char*)); av[0] = "rc"; av[1] = "-i"; name = getenv("sysname"); }else{ av = argv; name = utfrrune(av[0], '/'); if(name) name++; else name = av[0]; } if(getwd(buf, sizeof buf) == 0) dir = "/"; else dir = buf; dir = estrdup(dir); tag = estrdup(dir); tag = eappend(estrdup(tag), "/-", name); win = newwindow(); snprint(buf, sizeof buf, "%d", win->id); putenv("winid", buf); winname(win, tag); wintagwrite(win, "Send Noscroll", 5+8); threadcreate(mainctl, win, STACK); mountcons(); threadcreate(fsloop, nil, STACK); startpipe(); startcmd(av, ¬epg); strcpy(buf, "win"); j = 3; for(i=0; i<argc && j+1+strlen(argv[i])+1<sizeof buf; i++){ strcpy(buf+j, " "); strcpy(buf+j+1, argv[i]); j += 1+strlen(argv[i]); } ctlprint(win->ctl, "scroll"); winsetdump(win, dir, buf); }
int mboxcommand(Window *w, char *s) { char *args[10], **targs, *save; Window *sbox; Message *m, *next; int ok, nargs, i, j; CFid *searchfd; char buf[128], *res; nargs = tokenize(s, args, nelem(args)); if(nargs == 0) return 0; if(strcmp(args[0], "Mail") == 0){ if(nargs == 1) mkreply(nil, "Mail", "", nil, nil); else mkreply(nil, "Mail", args[1], nil, nil); return 1; } if(strcmp(s, "Del") == 0){ if(mbox.dirty){ mbox.dirty = 0; fprint(2, "mail: mailbox not written\n"); return 1; } if(w != mbox.w){ windel(w, 1); return 1; } ok = 1; for(m=mbox.head; m!=nil; m=next){ next = m->next; if(m->w){ if(windel(m->w, 0)) m->w = nil; else ok = 0; } } for(m=replies.head; m!=nil; m=next){ next = m->next; if(m->w){ if(windel(m->w, 0)) m->w = nil; else ok = 0; } } if(ok){ windel(w, 1); removeupasfs(); threadexitsall(nil); } return 1; } if(strcmp(s, "Put") == 0){ rewritembox(wbox, &mbox); return 1; } if(strcmp(s, "Get") == 0){ fswrite(mbox.ctlfd, "refresh", 7); return 1; } if(strcmp(s, "Delmesg") == 0){ save = nil; if(nargs > 1) save = args[1]; s = winselection(w); if(s == nil) return 1; nargs = 1; for(i=0; s[i]; i++) if(s[i] == '\n') nargs++; targs = emalloc(nargs*sizeof(char*)); /* could be too many for a local array */ nargs = getfields(s, targs, nargs, 1, "\n"); for(i=0; i<nargs; i++){ if(!isdigit(targs[i][0])) continue; j = atoi(targs[i]); /* easy way to parse the number! */ if(j == 0) continue; snprint(buf, sizeof buf, "%s%d", mbox.name, j); delmesg(buf, nil, 1, save); } free(s); free(targs); return 1; } if(strcmp(s, "Search") == 0){ if(nargs <= 1) return 1; s = estrstrdup(mboxname, "/search"); searchfd = fsopen(mailfs, s, ORDWR); if(searchfd == nil) return 1; save = estrdup(args[1]); for(i=2; i<nargs; i++) save = eappend(save, " ", args[i]); fswrite(searchfd, save, strlen(save)); fsseek(searchfd, 0, 0); j = fsread(searchfd, buf, sizeof buf - 1); if(j == 0){ fprint(2, "[%s] search %s: no results found\n", mboxname, save); fsclose(searchfd); free(save); return 1; } free(save); buf[j] = '\0'; res = estrdup(buf); j = fsread(searchfd, buf, sizeof buf - 1); for(; j != 0; j = fsread(searchfd, buf, sizeof buf - 1), buf[j] = '\0') res = eappend(res, "", buf); fsclose(searchfd); sbox = newwindow(); winname(sbox, s); free(s); threadcreate(mainctl, sbox, STACK); winopenbody(sbox, OWRITE); /* show results in reverse order */ m = mbox.tail; save = nil; for(s=strrchr(res, ' '); s!=nil || save!=res; s=strrchr(res, ' ')){ if(s != nil){ save = s+1; *s = '\0'; } else save = res; save = estrstrdup(save, "/"); for(; m && strcmp(save, m->name) != 0; m=m->prev); free(save); if(m == nil) break; fsprint(sbox->body, "%s%s\n", m->name, info(m, 0, 0)); m = m->prev; } free(res); winclean(sbox); winclosebody(sbox); return 1; } return 0; }
static editor neweditor(void) { int x, y, w, h, w0, h0; editor c; menuitem m; textbox t; long flags; font editorfn = (consolefn ? consolefn : FixedFont); EditorData p = neweditordata(0, NULL); DWORD rand; w = (pagercol + 1)*fontwidth(editorfn); h = (pagerrow + 1)*fontheight(editorfn) + 1; #ifdef USE_MDI if(ismdi()) { RECT *pR = RgetMDIsize(); w0 = pR->right; h0 = pR->bottom; } else { #endif w0 = devicewidth(NULL); h0 = deviceheight(NULL); #ifdef USE_MDI } #endif x = (w0 - w) / 2; x = x > 20 ? x : 20; y = (h0 - h) / 2; y = y > 20 ? y : 20; rand = GetTickCount(); w0 = 0.4*x; h0 = 0.4*y; w0 = w0 > 20 ? w0 : 20; h0 = h0 > 20 ? h0 : 20; x += (rand % w0) - w0/2; y += ((rand/w0) % h0) - h0/2; flags = StandardWindow | Menubar; #ifdef USE_MDI if (ismdi()) flags |= Document; #endif c = (editor) newwindow("", rect(x, y, w, h), flags); t = newrichtextarea(NULL, rect(0, 0, w, h)); setdata(c, t); setdata(t, p); gsetcursor(c, ArrowCursor); setforeground(c, guiColors[editorfg]); setbackground(c, guiColors[editorbg]); setbackground(t, guiColors[editorbg]); #ifdef USE_MDI if (ismdi() && (RguiMDI & RW_TOOLBAR)) { int btsize = 24; rect r = rect(2, 2, btsize, btsize); control tb, bt; addto(c); MCHECK(tb = newtoolbar(btsize + 4)); addto(tb); MCHECK(bt = newtoolbutton(open_image, r, menueditoropen)); MCHECK(addtooltip(bt, G_("Open script"))); setdata(bt, c); r.x += (btsize + 1) ; MCHECK(bt = newtoolbutton(save_image, r, menueditorsave)); MCHECK(addtooltip(bt, G_("Save script"))); setdata(bt, c); r.x += (btsize + 6); MCHECK(bt = newtoolbutton(copy1_image, r, menueditorrun)); MCHECK(addtooltip(bt, G_("Run line or selection"))); setdata(bt, t); r.x += (btsize + 6); MCHECK(bt = newtoolbutton(console_image, r, editorconsole)); MCHECK(addtooltip(bt, G_("Return focus to Console"))); r.x += (btsize + 6); MCHECK(bt = newtoolbutton(print_image, r, editorprint)); MCHECK(addtooltip(bt, G_("Print script"))); setdata(bt, t); MCHECK(addtooltip(bt, G_("Print"))); } #endif addto(c); /* Right-click context menu */ MCHECK(m = gpopup(editormenuact, EditorPopup)); setdata(m, t); setdata(EditorPopup[0].m, t); setdata(EditorPopup[2].m, t); setdata(p->mpopcut = EditorPopup[4].m, t); setdata(p->mpopcopy = EditorPopup[5].m, t); setdata(EditorPopup[6].m, t); setdata(p->mpopdelete = EditorPopup[7].m, t); setdata(EditorPopup[9].m, t); addto(c); MCHECK(m = newmenubar(editormenuact)); setdata(m, t); MCHECK(newmenu(G_("File"))); MCHECK(m = newmenuitem(G_("New script"), 'N', menueditornew)); setdata(m, c); MCHECK(m = newmenuitem(G_("Open script..."), 'O', menueditoropen)); setdata(m, c); MCHECK(m = newmenuitem(G_("Save"), 'S', menueditorsave)); setdata(m, c); MCHECK(m = newmenuitem(G_("Save as..."), 0, menueditorsaveas)); setdata(m, c); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(m = newmenuitem(G_("Print..."), 0, editorprint)); setdata(m, t); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(m = newmenuitem(G_("Close script"), 0, menueditorclose)); setdata(m, c); MCHECK(newmenu(G_("Edit"))); MCHECK(m = newmenuitem(G_("Undo"), 'Z', editorundo)); setdata(m, t); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(p->mcut = newmenuitem(G_("Cut"), 'X', editorcut)); setdata(p->mcut, t); MCHECK(p->mcopy = newmenuitem(G_("Copy"), 'C', editorcopy)); setdata(p->mcopy, t); MCHECK(m = newmenuitem(G_("Paste"), 'V', editorpaste)); setdata(m, t); MCHECK(p->mdelete = newmenuitem(G_("Delete"), 0, editordelete)); setdata(p->mdelete, t); MCHECK(m = newmenuitem(G_("Select all"), 'A', editorselectall)); setdata(m, t); MCHECK(newmenuitem(G_("Clear console"), 'L', menuclear)); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(m = newmenuitem(G_("Run line or selection"), 'R', menueditorrun)); setdata(m, t); MCHECK(m = newmenuitem(G_("Run all"), 0, editorrunall)); setdata(m, t); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(p->mfind = newmenuitem(G_("Find..."), 'F', editorfind)); setdata(p->mfind, t); MCHECK(p->mreplace = newmenuitem(G_("Replace..."), 'H', editorreplace)); setdata(p->mreplace, t); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(newmenuitem(G_("GUI preferences..."), 0, menuconfig)); /* Packages menu should go here */ p->pmenu = (PkgMenuItems) malloc(sizeof(struct structPkgMenuItems)); RguiPackageMenu(p->pmenu); #ifdef USE_MDI newmdimenu(); /* Create and fill the 'Window' menu */ #endif MCHECK(m = newmenu(G_("Help"))); MCHECK(newmenuitem(G_("Editor"), 0, menueditorhelp)); MCHECK(newmenuitem("-", 0, NULL)); p->hmenu = (HelpMenuItems) malloc(sizeof(struct structHelpMenuItems)); RguiCommonHelp(m, p->hmenu); settextfont(t, editorfn); setforeground(t, guiColors[editorfg]); setresize(c, editorresize); setclose(c, editorclose); setdel(c, editordel); setdel(t, textboxdel); setonfocus(c, editorfocus); setkeyaction(t, editorcontrolkeydown); setkeydown(t, editorasciikeydown); /* Store pointer to new editor in global array */ REditors[neditors] = c; ++neditors; return c; }
void lockscreen(void) { enum { Nfld = 5, Fldlen = 12, Cursorlen = 2*4 + 2*2*16, }; char *s; char buf[Nfld*Fldlen], *flds[Nfld], newcmd[128], cbuf[Cursorlen]; int fd, dx, dy; Image *i; Point p; Rectangle r; Tm *tm; fd = open("/dev/screen", OREAD); if(fd < 0) error("can't open /dev/screen: %r"); if(read(fd, buf, Nfld*Fldlen) != Nfld*Fldlen) error("can't read /dev/screen: %r"); close(fd); buf[sizeof buf-1] = 0; if(tokenize(buf, flds, Nfld) != Nfld) error("can't tokenize /dev/screen header"); snprint(newcmd, sizeof newcmd, "-r %s %s %d %d", flds[1], flds[2], atoi(flds[3]) - 1, atoi(flds[4]) - 1); newwindow(newcmd); if (initdraw(nil, nil, "screenlock") < 0) sysfatal("initdraw failed"); if(display == nil) error("no display"); /* screen is now open and covered. grab mouse and hold on tight */ procrfork(grabmouse, nil, 4096, RFFDG); procrfork(blanker, nil, 4096, RFFDG); fd = open(pic, OREAD); if(fd > 0){ i = readimage(display, fd, 0); if(i){ r = screen->r; p = Pt(r.max.x / 2, r.max.y * 2 / 3); dx = (Dx(screen->r) - Dx(i->r)) / 2; r.min.x += dx; r.max.x -= dx; dy = (Dy(screen->r) - Dy(i->r)) / 2; r.min.y += dy; r.max.y -= dy; draw(screen, screen->r, display->black, nil, ZP); draw(screen, r, i, nil, i->r.min); flushimage(display, 1); } close(fd); /* identify the user on screen, centered */ tm = localtime(time(0)); s = smprint("user %s at %d:%02.2d", getuser(), tm->hour, tm->min); p = subpt(p, Pt(stringwidth(font, "m") * strlen(s) / 2, 0)); screenstring(p, s); } /* clear the cursor */ fd = open("/dev/cursor", OWRITE); if(fd > 0){ memset(cbuf, 0, sizeof cbuf); write(fd, cbuf, sizeof cbuf); /* leave it open */ } }
static void showDialog(Gui gui) { char buf[100]; wconfig = newwindow(G_("Rgui Configuration Editor"), rect(0, 0, 550, 450), Titlebar | Centered | Modal); setbackground(wconfig, dialog_bg()); l_mdi = newlabel("Single or multiple windows", rect(10, 10, 140, 20), AlignLeft); rb_mdi = newradiobutton("MDI", rect(150, 10 , 70, 20), cMDI); rb_sdi = newradiobutton("SDI", rect(220, 10 , 70, 20), cSDI); toolbar = newcheckbox("MDI toolbar", rect(300, 10, 100, 20), NULL); if(gui->toolbar) check(toolbar); statusbar = newcheckbox("MDI statusbar", rect(420, 10, 130, 20), NULL); if(gui->statusbar) check(statusbar); if(gui->MDI) { check(rb_mdi); cMDI(rb_mdi); } else { check(rb_sdi); cSDI(rb_sdi); } l_mwin = newlabel("Pager style", rect(10, 40, 90, 20), AlignLeft); g_mwin = newradiogroup(); rb_mwin = newradiobutton("multiple windows", rect(150, 40, 150, 20), NULL); rb_swin = newradiobutton("single window", rect(150, 60 , 150, 20), NULL); if(gui->pagerMultiple) check(rb_mwin); else check(rb_swin); l_lang = newlabel("Language for menus\nand messages", rect(320, 40, 130, 40), AlignLeft); f_lang = newfield(gui->language, rect(450, 45, 60, 20)); /* Font, pointsize, style */ l_font = newlabel("Font", rect(10, 100, 40, 20), AlignLeft); f_font = newdropfield(FontsList, rect(50, 100, 120, 20), scrollFont); tt_font = newcheckbox("TrueType only", rect(180, 100, 110, 20), changeFont); if (gui->tt_font) check(tt_font); settext(f_font, gui->font); l_point = newlabel("size", rect(310, 100, 30, 20), AlignLeft); d_point = newdropfield(PointsList, rect(345, 100, 50, 20), scrollPoints); snprintf(buf, 100, "%d", gui->pointsize); settext(d_point, buf); l_style = newlabel("style", rect(410, 100, 40, 20), AlignLeft); f_style = newdroplist(StyleList, rect(450, 100, 80, 20), scrollStyle); setlistitem(f_style, cmatch(gui->style, StyleList)); /* Console size, set widthonresize */ l_crows = newlabel("Console rows", rect(10, 150, 100, 20), AlignLeft); snprintf(buf, 100, "%d", gui->crows); f_crows = newfield(buf, rect(110, 150, 30, 20)); l_ccols = newlabel("columns", rect(150, 150, 60, 20), AlignLeft); snprintf(buf, 100, "%d", gui->ccols); f_ccols = newfield(buf, rect(220, 150, 30, 20)); l_cx = newlabel("Initial left", rect(270, 150, 70, 20), AlignLeft); snprintf(buf, 100, "%d", gui->cx); f_cx = newfield(buf, rect(350, 150, 40, 20)); l_cy = newlabel("top", rect(430, 150, 30, 20), AlignLeft); snprintf(buf, 100, "%d", gui->cy); f_cy = newfield(buf, rect(480, 150, 40, 20)); c_resize = newcheckbox("set options(width) on resize?", rect(20, 175, 200, 20), NULL); if(gui->setWidthOnResize) check(c_resize); l_cbb = newlabel("buffer chars", rect(270, 175, 70, 20), AlignLeft); snprintf(buf, 100, "%d", gui->cbb); f_cbb = newfield(buf, rect(350, 175, 60, 20)); l_cbl = newlabel("lines", rect(430, 175, 50, 20), AlignLeft); snprintf(buf, 100, "%d", gui->cbl); f_cbl = newfield(buf, rect(480, 175, 40, 20)); c_buff = newcheckbox("buffer console by default?", rect(20, 190, 200, 20), NULL); if(gui->buffered) check(c_buff); /* Cursor blink */ l_blink = newlabel("Cursor blink", rect(270, 200,100, 30), AlignLeft); f_blink = newdroplist(BlinkList, rect(350, 200, 80, 20), NULL); setlistitem(f_blink, gui->cursor_blink); /* Pager size */ l_prows = newlabel("Pager rows", rect(10, 230, 100, 20), AlignLeft); snprintf(buf, 100, "%d", gui->prows); f_prows = newfield(buf, rect(110, 230, 30, 20)); l_pcols = newlabel("columns", rect(150, 230, 60, 20), AlignLeft); snprintf(buf, 100, "%d", gui->pcols); f_pcols = newfield(buf, rect(220, 230, 30, 20)); /* Graphics window */ l_grx = newlabel("Graphics windows: initial left", rect(10, 270, 190, 20), AlignLeft); snprintf(buf, 100, "%d", gui->grx); f_grx = newfield(buf, rect(200, 270, 40, 20)); l_gry = newlabel("top", rect(270, 270, 30, 20), AlignLeft); snprintf(buf, 100, "%d", gui->gry); f_gry = newfield(buf, rect(300, 270, 40, 20)); /* Font colours */ l_cols = newlabel("Console and Pager Colours", rect(10, 310, 520, 20), AlignCenter); guielement = newlistbox(GuiElementNames, rect(50, 330, 100, 80), changeElement, NULL); guicolor = newlistbox(ColorName, rect(205, 330, 100, 80), clickColor, NULL); guisample = newrichtextarea("Sample text", rect(350, 330, 150, 55)); for (int i=0; i<numGuiColors; i++) dialogColors[i] = gui->guiColors[i]; setlistitem(guielement, 0); changeElement(guielement, 0); sampleFontNum = cmatch(gettext(f_font), FontsList); samplePointsize = atoi(gettext(d_point)); scrollStyle(f_style, 0); /* the 0 is ignored */ bApply = newbutton("Apply", rect(50, 410, 70, 25), apply); bSave = newbutton("Save...", rect(130, 410, 70, 25), save); bLoad = newbutton("Load...", rect(210, 410, 70, 25), load); bOK = newbutton("OK", rect(350, 410, 70, 25), ok); bCancel = newbutton("Cancel", rect(430, 410, 70, 25), cancel); show(wconfig); }
void threadmain(int argc, char **argv) { char *p, *q; Dir *d; Window *w; ARGBEGIN{ case 'D': debug++; break; case 'd': dir = EARGF(usage()); break; default: usage(); break; }ARGEND if(argc != 1) usage(); from = findfrom(); group = estrdup(argv[0]); /* someone will be cute */ while(q=strchr(group, '/')) *q = '.'; p = estrdup(argv[0]); while(q=strchr(p, '.')) *q = '/'; p = estrstrstrdup(dir, "/", p); cleanname(p); if((d = dirstat(p)) == nil){ /* maybe it is a new group */ if((d = dirstat(dir)) == nil){ fprint(2, "dirstat(%s) fails: %r\n", dir); threadexitsall(nil); } if((d->mode&DMDIR)==0){ fprint(2, "%s not a directory\n", dir); threadexitsall(nil); } free(d); if((d = dirstat(p)) == nil){ fprint(2, "stat %s: %r\n", p); threadexitsall(nil); } } if((d->mode&DMDIR)==0){ fprint(2, "%s not a directory\n", dir); threadexitsall(nil); } free(d); dir = estrstrdup(p, "/"); q = estrstrdup(dir, "post"); canpost = access(q, AWRITE)==0; w = newwindow(); root = w; proccreate(wineventproc, w, STACK); proccreate(timerproc, w, STACK); winname(w, dir); if(canpost) wintagwrite(w, "Newpost ", 8); wintagwrite(w, "More ", 5); dirwindow(w); threadcreate(dirthread, w, STACK); threadexits(nil); }
int setupui(void) { char *p, *ctype, Rlocale[1000] = ""; /* Windows' locales can be very long */ initapp(0, 0); /* set locale before doing anything with menus */ setlocale(LC_CTYPE, ""); /* necessary in case next fails to set a valid locale */ if((p = getenv("LC_ALL"))) strcpy(Rlocale, p); if((p = getenv("LC_CTYPE"))) strcpy(Rlocale, p); if (strcmp(Rlocale, "C") == 0) strcpy(Rlocale, "en"); setlocale(LC_CTYPE, Rlocale); mbcslocale = MB_CUR_MAX > 1; ctype = setlocale(LC_CTYPE, NULL); p = strrchr(ctype, '.'); if(p && isdigit(p[1])) localeCP = atoi(p+1); else localeCP = 1252; readconsolecfg(); int flags = StandardWindow | Document | Menubar; if(mbcslocale) flags |= UseUnicode; if (RguiMDI & RW_MDI) { TRACERUI("Rgui"); RFrame = newwindow( #ifdef _WIN64 "RGui (64-bit)", #else "RGui (32-bit)", #endif MDIsize, StandardWindow | Menubar | Workspace); setclose(RFrame, closeconsole); show(RFrame); TRACERUI("Rgui done"); TRACERUI("Console"); if (!(RConsole = newconsole("R Console", flags ))) return 0; TRACERUI("Console done"); } else { TRACERUI("Console"); #ifdef _WIN64 if (!(RConsole = newconsole("R Console (64-bit)", flags ))) return 0; #else if (!(RConsole = newconsole("R Console (32-bit)", flags ))) return 0; #endif TRACERUI("Console done"); } if (ismdi()) { int btsize = 24; rect r = rect(2, 2, btsize, btsize); control tb, bt; MCHECK(tb = newtoolbar(btsize + 4)); addto(tb); MCHECK(bt = newtoolbutton(open_image, r, menueditoropen)); MCHECK(addtooltip(bt, G_("Open script"))); r.x += (btsize + 1) ; MCHECK(bt = newtoolbutton(open1_image, r, menuloadimage)); MCHECK(addtooltip(bt, G_("Load workspace"))); r.x += (btsize + 1) ; MCHECK(bt = newtoolbutton(save_image, r, menusaveimage)); MCHECK(addtooltip(bt, G_("Save workspace"))); r.x += (btsize + 6); MCHECK(bt = newtoolbutton(copy_image, r, buttoncopy)); MCHECK(addtooltip(bt, G_("Copy"))); r.x += (btsize + 1); MCHECK(bt = newtoolbutton(paste_image, r, buttonpaste)); MCHECK(addtooltip(bt, G_("Paste"))); r.x += (btsize + 1); MCHECK(bt = newtoolbutton(copypaste_image, r, buttoncopypaste)); MCHECK(addtooltip(bt, G_("Copy and paste"))); r.x += (btsize + 6); MCHECK(bt = newtoolbutton(stop_image, r, buttonkill)); MCHECK(addtooltip(bt, G_("Stop current computation"))); r.x += (btsize + 6) ; MCHECK(bt = newtoolbutton(print_image, r, menuprint)); MCHECK(addtooltip(bt, G_("Print"))); } if (ismdi() && (RguiMDI & RW_STATUSBAR)) { TRACERUI("status bar"); addstatusbar(); addto(RConsole); TRACERUI("status bar done"); } if (ismdi()) { char s[256]; PrintVersionString(s, 256); setstatus(s); } addto(RConsole); setclose(RConsole, closeconsole); setdrop(RConsole, dropconsole); MCHECK(RConsolePopup = gpopup(popupact, ConsolePopup)); MCHECK(RMenuBar = newmenubar(menuact)); MCHECK(newmenu(G_("File"))); MCHECK(msource = newmenuitem(G_("Source R code..."), 0, menusource)); MCHECK(newmenuitem(G_("New script"), 0, menueditornew)); MCHECK(newmenuitem(G_("Open script..."), 0, menueditoropen)); MCHECK(mdisplay = newmenuitem(G_("Display file(s)..."), 0, menudisplay)); MCHECK(newmenuitem("-", 0, NULL)); MCHECK(mload = newmenuitem(G_("Load Workspace..."), 0, menuloadimage)); MCHECK(msave = newmenuitem(G_("Save Workspace..."), 'S', menusaveimage)); MCHECK(newmenuitem("-", 0, NULL)); MCHECK(mloadhistory = newmenuitem(G_("Load History..."), 0, menuloadhistory)); MCHECK(msavehistory = newmenuitem(G_("Save History..."), 0, menusavehistory)); MCHECK(newmenuitem("-", 0, NULL)); MCHECK(newmenuitem(G_("Change dir..."), 0, menuchangedir)); MCHECK(newmenuitem("-", 0, NULL)); MCHECK(newmenuitem(G_("Print..."), 'P', menuprint)); MCHECK(newmenuitem(G_("Save to File..."), 0, menusavefile)); MCHECK(newmenuitem("-", 0, NULL)); MCHECK(newmenuitem(G_("Exit"), 0, menuexit)); MCHECK(newmenu(G_("Edit"))); MCHECK(mcopy = newmenuitem(G_("Copy"), 'C', menucopy)); MCHECK(mpaste = newmenuitem(G_("Paste"), 'V', menupaste)); MCHECK(mpastecmds = newmenuitem(G_("Paste commands only"), 0, menupastecmds)); MCHECK(mcopypaste = newmenuitem(G_("Copy and Paste"), 'X', menucopypaste)); MCHECK(newmenuitem(G_("Select all"), 0, menuselectall)); MCHECK(newmenuitem(G_("Clear console"), 'L', menuclear)); MCHECK(newmenuitem("-", 0, NULL)); MCHECK(mde = newmenuitem(G_("Data editor..."), 0, menude)); MCHECK(newmenuitem("-", 0, NULL)); MCHECK(mconfig = newmenuitem(G_("GUI preferences..."), 0, menuconfig)); if (ismdi()) { MCHECK(newmenu(G_("View"))); MCHECK(mtools = newmenuitem(G_("Toolbar"), 0, menutools)); MCHECK(mstatus = newmenuitem(G_("Statusbar"), 0, menustatus)); if(RguiMDI & RW_TOOLBAR) check(mtools); if(RguiMDI & RW_STATUSBAR) check(mstatus); } MCHECK(newmenu(G_("Misc"))); MCHECK(newmenuitem(G_("Stop current computation \tESC"), 0, menukill)); MCHECK(newmenuitem(G_("Stop all computations"), 0, menukillall)); if (DebugMenuitem || isdebuggerpresent()) MCHECK(newmenuitem(G_("Break to debugger"), 0, menudebug)); MCHECK(newmenuitem("-", 0, NULL)); MCHECK(mlazy = newmenuitem(G_("Buffered output"), 'W', menulazy)); MCHECK(mcomplete = newmenuitem(G_("Word completion"), 0, menucomplete)); check(mcomplete); MCHECK(mfncomplete = newmenuitem(G_("Filename completion"), 0, menufncomplete)); if(check_file_completion()) check(mfncomplete); else uncheck(mfncomplete); MCHECK(newmenuitem("-", 0, NULL)); MCHECK(mls = newmenuitem(G_("List objects"), 0, menuls)); MCHECK(mrm = newmenuitem(G_("Remove all objects"), 0, menurm)); MCHECK(msearch = newmenuitem(G_("List search &path"), 0, menusearch)); pmenu = (PkgMenuItems) malloc(sizeof(struct structPkgMenuItems)); RguiPackageMenu(pmenu); RguiWindowMenu(); MCHECK(m = newmenu(G_("Help"))); MCHECK(newmenuitem(G_("Console"), 0, menuconsolehelp)); MCHECK(newmenuitem("-", 0, NULL)); CheckForManuals(); hmenu = (HelpMenuItems) malloc(sizeof(struct structHelpMenuItems)); RguiCommonHelp(m, hmenu); consolesetbrk(RConsole, menukill, ESC, 0); wgl_hist_init(R_HistorySize, 0); if (R_RestoreHistory) wgl_loadhistory(R_HistoryFile); if (ismdi() && !(RguiMDI & RW_TOOLBAR)) toolbar_hide(); show(RConsole); return 1; }