void Y_set_vars(int nArgs) { Symbol *stack = sp - nArgs + 1; IOStream *file, *child; char **vars, **rvars; long i, nvars, nrvars; Dimension *dims; if (nArgs<2 || nArgs>3 || !stack[0].ops || !stack[1].ops) YError("set_vars takes exactly two or three arguments"); file = YGetFile(stack++); child = file->history? file->history->child : 0; vars = YGet_Q(stack++, 1, &dims); nvars = (vars&&dims)? (dims->next? -1 : dims->number) : 0; if (nArgs==3) { rvars = YGet_Q(stack++, 1, &dims); nrvars = (vars&&dims)? (dims->next? -1 : dims->number) : 0; } else { rvars = 0; nrvars = 0; } if (nvars<0 || nrvars<0) YError("set_vars var lists must be 1D"); if ((nvars && nvars!=file->dataTable.nItems) || (nrvars && nrvars!=(child? child->dataTable.nItems : 0))) YError("set_vars var lists must match number of vars in file"); if (nvars) { HashTable tmp; y_hashtmp *h = y_new_tmpobj(sizeof(y_hashtmp), y_zap_hashtmp); HashInit(&h->table, nvars); PushDataBlock(h); for (i=0 ; i<nvars ; i++) if (HashAdd(&h->table, vars[i], 0)) break; if (i<nvars) YError("duplicate names in set_vars static var list"); if (p_signalling) p_abort(); tmp = h->table; h->table = file->dataTable; file->dataTable = tmp; Drop(1); } if (nrvars) { HashTable tmp; y_hashtmp *h = y_new_tmpobj(sizeof(y_hashtmp), y_zap_hashtmp); HashInit(&h->table, nvars); PushDataBlock(h); for (i=0 ; i<nrvars ; i++) if (HashAdd(&h->table, rvars[i], 0)) break; if (i<nrvars) YError("duplicate names in set_vars record var list"); if (p_signalling) p_abort(); tmp = h->table; h->table = child->dataTable; child->dataTable = tmp; Drop(1); } }
int w_add_input(HANDLE wait_obj, void (*on_input)(void *), void *context) { int i; if (p_signalling) p_abort(); for (i=0 ; i<w_nputs ; i++) if (w_inputs[i]==wait_obj) break; if (on_input) { if (i==w_nputs) { if (w_nputs && !(w_nputs&7)) { HANDLE heap = GetProcessHeap(); w_inputs= HeapReAlloc(heap, HEAP_GENERATE_EXCEPTIONS, w_inputs, sizeof(HANDLE *)*(w_nputs+8)); w_in_items= HeapReAlloc(heap, HEAP_GENERATE_EXCEPTIONS, w_in_items, sizeof(struct w_input_item *)*(w_nputs+8)); } w_inputs[i] = wait_obj; } /* next three statements are a critical section */ w_in_items[i].on_input = on_input; w_in_items[i].context = context; w_nputs++; } else { /* this whole else clause is a critical section */ if (w_nputs>0) w_nputs--; for (; i<w_nputs ; i++) { w_inputs[i] = w_inputs[i+1]; w_in_items[i].on_input = w_in_items[i+1].on_input; w_in_items[i].context = w_in_items[i+1].context; } } return 0; }
void y_on_stdin(char *input_line) { int flag = ym_dbenter; ym_dbenter = yp_did_prompt = 0; if (!y_read_prompt) { if (input_line) while (input_line[0]==' ' || input_line[0]=='\t') input_line++; if (flag && input_line && input_line[0]) { extern void yg_got_expose(void); yp_continue = 0; if (p_signalling) p_abort(); /* drop current debug block plus task and clean up vm state */ ResetStack(0); yr_reset(); yg_got_expose(); p_clr_alarm(0, 0); } if (yg_blocking) { if (yg_blocking==2) { extern void yg_got_expose(void); yg_got_expose(); /* escape from pause on keyboard input */ if (input_line && input_line[0]) YputsErr("WARNING discarding keyboard input that aborts pause"); return; } else { YputsErr("WARNING discarding keyboard input during window wait"); return; } } y_add_line(input_line); } else { yr_reader(input_line); } }
char * YpNextLine(int context) { p_file *file; char *line; /* In skip-includes mode, remember where each line begins for * use by YpStandby. */ if (ypSkipIncludes && nYpIncludes && ypIncludes[nYpIncludes-1].file) rememberLine = p_ftell(ypIncludes[nYpIncludes-1].file); else rememberLine = -1; /* If there is an alternate input source, use it. */ if (YaltNextLine) { line = YaltNextLine(context); if (!line) YaltNextLine = 0; /* "close" alternate input source */ return line; } /* get the current include file */ if (nYpIncludes==0) { file = 0; } else for (;;) { if ((file=ypIncludes[nYpIncludes-1].file)) break; need_endif = 0; p_free(ypIncludes[nYpIncludes-1].filename); if (!(--nYpIncludes)) break; } if (!file && nYpInputs) do file = YpPop(); while (!file && nYpInputs); /* quit if input is not from include file. */ if (!file) return 0; for (;;) { if (p_signalling) p_abort(); /* Get an arbitrary (okay, < MAX_LINE) length input line. */ if (!GetNextLine(file, context)) return 0; /* if first line of file begins with #! discard it * (allows yorick source files to be scripts on most UNIX systems) */ if (nYpIncludes && ypIncludes[nYpIncludes-1].lastLineRead==1 && ypBuffer.line[0]=='#' && ypBuffer.line[1]=='!') { if (!GetNextLine(file, context)) return 0; } line = ypBuffer.line; if (line && context<=NL_CONTINUE) { int flag = yp_chk_hash(file, context, line); if (flag&1) { file = ypIncludes[nYpIncludes-1].file; continue; } } break; } yImpossible = 0; /* tell YError that a line has come in */ return line; }
void p_lines(p_win *w) { p_scr *s = w->s; Display *dpy = s->xdpy->dpy; GC gc = x_getgc(s, w, FillSolid); int nmx = XMaxRequestSize(dpy)-3; int n = x_pt_count; x_pt_count = 0; while (n>1) { if (n<nmx) nmx = n; XDrawLines(dpy, w->d, gc, x_pt_list, nmx, CoordModeOrigin); n -= nmx; } if (p_signalling) p_abort(); }
void p_segments(p_win *w) { p_scr *s = w->s; Display *dpy = s->xdpy->dpy; GC gc = x_getgc(s, w, FillSolid); int nmx = (XMaxRequestSize(dpy)-3)/2; int n = x_pt_count / 2; x_pt_count = 0; while (n>0) { if (n<nmx) nmx = n; /* note: assume here that XPoint[2] identical to XSegment */ XDrawSegments(dpy, w->d, gc, (XSegment *)x_pt_list, nmx); n -= nmx; } if (p_signalling) p_abort(); }
void p_rect(p_win *w, int x0, int y0, int x1, int y1, int border) { p_scr *s = w->s; Display *dpy = s->xdpy->dpy; GC gc = x_getgc(s, w, FillSolid); int tmp; if (x1 > x0) x1 -= x0; else tmp = x0-x1, x0 = x1, x1 = tmp; if (y1 > y0) y1 -= y0; else tmp = y0-y1, y0 = y1, y1 = tmp; if (border) XDrawRectangle(dpy, w->d, gc, x0, y0, x1, y1); else XFillRectangle(dpy, w->d, gc, x0, y0, x1, y1); if (p_signalling) p_abort(); }
void p_ellipse(p_win *w, int x0, int y0, int x1, int y1, int border) { p_scr *s = w->s; Display *dpy = s->xdpy->dpy; GC gc = x_getgc(s, w, FillSolid); int tmp; if (x1 > x0) x1 -= x0; else tmp = x0-x1, x0 = x1, x1 = tmp; if (y1 > y0) y1 -= y0; else tmp = y0-y1, y0 = y1, y1 = tmp; if (border) XDrawArc(dpy, w->d, gc, x0, y0, x1, y1, 0, 360*64); else XFillArc(dpy, w->d, gc, x0-1, y0-1, x1+2, y1+2, 0, 360*64); if (p_signalling) p_abort(); }
p_start() { char flag = 1; (void) s_gettok(); for (;;) { p_statementlist(flag); if (token == T_EOF || p_abort()) break; flag = 0; p_synerror(); while (token != T_EOL && token != T_EOF) { if (token == T_STR) str_free(token_str); (void) s_gettok(); } if (token == T_EOL) (void) s_gettok(); p_clearerr(); } }
/* possible results: * 0 -- this line was not #include (or ypSkipIncludes), #if, or #endif * or was a syntax error * 1 bit means get next line (successful include, #if 1, or #endif) * 2 -- this line was #include, file missing (YpError called) * 3 -- this line was #include, file pushed successfully * 4 -- this line was #if 0, no matching #endif * 5 -- this line was #if 0, skipped past matching #endif (in ypBuffer) * 7 -- this line was #if 1 * 9 -- this line was #endif */ static int yp_chk_hash(p_file *file, int context, char *line) { /* Check whether this is an include line or an if line. * Correct format is ([OWS] means optional whitespace characters): * [OWS]#[OWS]include[OWS]"filename"[OWS] * or * [OWS]#[OWS]include[OWS]<filename>[OWS] */ while (*line && (*line==' ' || *line=='\t' || *line=='\f')) line++; if (*line=='#' && line[1]) { char *incl= "include"; line++; while (*line && (*line==' ' || *line=='\t')) line++; while (*line && *incl && (*line++ == *incl++)); if (!*incl && context<NL_CONTINUE) { char delim; if (ypSkipIncludes) return 0; while (*line && (*line==' ' || *line=='\t')) line++; delim= *line; if (delim=='\"' || delim=='<') { char *filename= ++line; if (delim=='<') delim = '>'; while (*line && *line!=delim) line++; if (*line && line>filename) { *line++= '\0'; /* 0-terminate filename */ while (*line && (*line==' ' || *line=='\t')) line++; if (!*line) { char *msg; if ((file= YpPushInclude(filename))) return 3; msg= p_strncat("missing include file ", filename, 0); YpError(msg); p_free(msg); return 2; } } } } else if (incl[-1]=='n' && line[-1]=='f' && (line[0]==' ' || line[0]=='\t') && file) { /* this is #if line, maybe should skip to matching #endif */ line++; while (*line && (*line==' ' || *line=='\t')) line++; if ((line[0]=='0' || line[0]=='1') && (!line[1] || line[1]==' ' || line[1]=='\t')) { if (line[0]=='0') { int count = 0; for (;;) { if (p_signalling) p_abort(); if (!GetNextLine(file, context)) return 4; line = ypBuffer.line; while (*line && (*line==' ' || *line=='\t' || *line=='\f')) line++; if (*line=='#') { line++; while (*line && (*line==' ' || *line=='\t')) line++; if (line[0]=='i' && line[1]=='f' && (line[2]==' ' || line[2]=='\t')) { count++; /* nested #if (don't bother checking 0) */ } else { char *endi = "endif"; while (*line && *endi && (*line++ == *endi++)); if (!*endi && (!line[0] || line[0]==' ' || line[0]=='\t') && !count--) return 5; } } } } else { /* #if 1 */ need_endif++; return 7; } } } else if (need_endif && incl[-1]=='i' && line[-1]=='e' && line[0]=='n' && line[1]=='d' && line[2]=='i' && line[3]=='f' && (!line[4] || line[4]==' ' || line[4]=='\t')) { need_endif--; return 9; /* read line after #endif */ } } return 0; }
void GNEUndoList::p_clear() { p_abort(); clear(); }
XFontStruct * x_font(x_display *xdpy, int font, int pixsize) { char nm[128], *name; XFontStruct *f; if (tmp_fonts) tmp_free(); if (font>=P_GUI_FONT || font<0 || pixsize<=0 || pixsize>180) { f = xdpy->font; } else { int siz, i, j, pass, *ip, *jp; for (pass=siz=0 ;; pass++) { ip = jp = 0; j = -1; i = xdpy->most_recent; while (i>=0) { if (!xdpy->cached[i].f) { /* handle interrupted unload operation */ if (ip) *ip = -1; break; } if (xdpy->cached[i].font==font && xdpy->cached[i].pixsize==pixsize) { if (ip) { /* CRITICAL section */ *ip = xdpy->cached[i].next; xdpy->cached[i].next = xdpy->most_recent; xdpy->most_recent = i; } return xdpy->cached[i].f; } jp = ip; ip = &xdpy->cached[i].next; j = i; i = *ip; } if (pass) break; siz = x_substitute(xdpy, &font, &pixsize); if (font==P_GUI_FONT) return xdpy->font; } /* construct font name */ name = xdpy->available[font].names[siz]; if (!xdpy->available[font].sizes[siz]) { /* scalable, need to find specific instance */ char *pnm = nm; int n = 7; while (n--) while ((*(pnm++)= *(name++))!='-'); sprintf(pnm, "%d%n", pixsize, &n); strcpy(pnm+n, name); tmp_fonts = XListFonts(xdpy->dpy, nm, 4, &n); if (n<=0) return xdpy->font; /* should never happen (X server bug) */ strcpy(nm, tmp_fonts[0]); XFreeFontNames(tmp_fonts); tmp_free(); name = nm; } /* should be able to load it */ f = XLoadQueryFont(xdpy->dpy, name); if (!f) return xdpy->font; /* should never happen (X server bug) */ if (!xdpy->cached[0].f) { /* cache not yet full */ for (j=0 ; j<N_FONT_CACHE-1 ; j++) if (xdpy->cached[j+1].f) break; } else { /* cache is full, need to unload one, j is least recent */ XFontStruct *fold = xdpy->cached[j].f; xdpy->cached[j].f = 0; if (jp) *jp = -1; /* jp pointed to j, now least recent */ XFreeFont(xdpy->dpy, fold); } xdpy->cached[j].font = font; xdpy->cached[j].pixsize = pixsize; xdpy->cached[j].f = f; xdpy->cached[j].next = xdpy->most_recent; xdpy->most_recent = j; } if (p_signalling) p_abort(); return f; }
/* * name == 0 means we don't have a function name but * want to parse the arguments anyway. flag == 0 in this case. */ int p_function(const char *name, struct value *v, int flag) { struct value t; struct lcmd_tab *c = NULL; struct alias *a = NULL; struct lcmd_arg *ap; /* this arg */ struct lcmd_arg *lp = NULL; /* list arg */ int i; struct value av[LCMD_NARG + 1]; struct value *vp; if (name != NULL) { if ((c = lcmd_lookup(name))) name = c->lc_name; else if ((a = alias_lookup(name))) name = a->a_name; else { p_error("%s: No such command or alias.", name); flag = 0; } } for (vp = av; vp < &av[LCMD_NARG + 1]; vp++) vp->v_type = V_ERR; if (token == T_LP) (void) s_gettok(); i = 0; for (;;) { ap = NULL; vp = NULL; if (token == T_COMMA) /* null argument */ t.v_type = V_ERR; else { if (p_expr0(&t, flag) < 0) break; if (t.v_type == V_ERR) flag = 0; } if (token != T_ASSIGN) { if (i >= LCMD_NARG || (c != NULL && (ap = lp) == NULL && (ap = c->lc_arg + i)->arg_name == 0)) { p_error("%s: Too many arguments.", name); flag = 0; } else vp = &av[i++]; } else { char *tmp; if (p_convstr(&t) < 0) goto abort; tmp = t.v_type == V_STR ? t.v_str : 0; (void) s_gettok(); if (p_expr(&t, flag) < 0) { if (tmp) str_free(tmp); p_synerror(); goto abort; } if (t.v_type == V_ERR) flag = 0; if (tmp) { if (c == NULL) { /* an aliase */ p_error("%s: Bad alias syntax.", name); flag = 0; } else { for (ap = c->lc_arg, vp = av; ap != NULL && ap->arg_name != 0 && (*ap->arg_name == '\0' || !str_match(tmp, ap->arg_name, ap->arg_minlen)); ap++, vp++) ; if (ap == NULL || ap->arg_name == 0) { p_error("%s: Unknown argument \"%s\".", name, tmp); flag = 0; ap = NULL; vp = NULL; } } str_free(tmp); } } if (ap != NULL) { if (ap->arg_flags & ARG_LIST) { i = vp - av + 1; lp = ap; } if (vp && vp->v_type != V_ERR) { if (*ap->arg_name) p_error("%s: Argument %d (%s) duplicated.", name, (int)(vp - av + 1), ap->arg_name); else p_error("%s: Argument %d duplicated.", name, (int)(vp - av + 1)); flag = 0; vp = NULL; } else if (t.v_type == V_ERR) { /* do nothing */ } else if (((ap->arg_flags&ARG_TYPE) == ARG_NUM && t.v_type != V_NUM) || ((ap->arg_flags&ARG_TYPE) == ARG_STR && t.v_type != V_STR)) { if (*ap->arg_name) p_error("%s: Argument %d (%s) type mismatch.", name, (int)(vp - av + 1), ap->arg_name); else p_error("%s: Argument %d type mismatch.", name, (int)(vp - av + 1)); flag = 0; vp = NULL; } } if (vp != NULL) *vp = t; else val_free(t); if (token == T_COMMA) (void) s_gettok(); } if (p_erred()) flag = 0; if (token == T_RP) (void) s_gettok(); else if (token != T_EOL && token != T_EOF) flag = 0; /* look for legal follow set */ v->v_type = V_ERR; if (flag) { if (c != NULL) (*c->lc_func)(v, av); else { if (a->a_flags & A_INUSE) p_error("%s: Recursive alias.", a->a_name); else { a->a_flags |= A_INUSE; if (dolongcmd(a->a_buf, av, i) < 0) p_memerror(); a->a_flags &= ~A_INUSE; } } } if (p_abort()) { val_free(*v); v->v_type = V_ERR; goto abort; } for (vp = av; vp < &av[LCMD_NARG]; vp++) val_free(*vp); return 0; abort: for (vp = av; vp < &av[LCMD_NARG]; vp++) val_free(*vp); return -1; }