STATE* addstate (void) { STATE* clon; if (statedir==NULL) { if(getstate(wordd)!=NULL) { printf("\nEl estado ya existe!"); return NULL; } statedir=calloc(1,sizeof(STATE)); statedir->p2next=NULL; strcpy(statedir->nombre, wordd); ++statesnumb; return(statedir); } else { for(clon=statedir;clon->p2next!=NULL;clon=clon->p2next); if(getstate(wordd)!=NULL) { return NULL; } clon->p2next=calloc(1,sizeof(STATE)); clon->p2next->p2next=NULL; strcpy(clon->p2next->nombre, wordd); ++statesnumb; return(clon->p2next); } }
Window tryChildren(Display *dpy, Window win) { Window root, parent; Window *children; unsigned int nchildren; int i; Window inf = 0; Window child; if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren)) { return 0; } // Traverse bottom-up direction // for (i = 0; !inf && (i < nchildren); i++) { for (i = nchildren-1; !inf && (i >= 0); i--) { // NormalState per ICCM if (getstate(dpy, children[i]) == 1) { inf = children[i]; } else { child = tryChildren(dpy, children[i]); if (child) { inf = child; } } } if (children) { XFree(children); } return inf; }
/*ARGSUSED*/ static int ntwdt_open(dev_t *devp, int flag, int otyp, cred_t *credp) { int instance = getminor(*devp); int retval = 0; ntwdt_state_t *ntwdt_ptr = getstate(instance); if (ntwdt_ptr == NULL) { return (ENXIO); } /* * ensure caller is a priviledged process. */ if (drv_priv(credp) != 0) { return (EPERM); } mutex_enter(&ntwdt_ptr->ntwdt_mutex); if (ntwdt_ptr->ntwdt_open_flag) { retval = EAGAIN; } else { ntwdt_ptr->ntwdt_open_flag = 1; } mutex_exit(&ntwdt_ptr->ntwdt_mutex); return (retval); }
Window queryStack(Display* dpy, Window root, const QList<quint64>& pids) { Atom STACK = XInternAtom(dpy, "_NET_CLIENT_LIST_STACKING", False); unsigned long nitems, after; int format; Atom type = None; unsigned char* data = NULL; Window child; int i; if (!STACK) { return root; } if (Success == XGetWindowProperty(dpy, root, STACK, 0, 0x7FFFFFFF, False, XA_WINDOW, &type, &format, &nitems, &after, &data)) { for (i = (nitems-1); i >= 0; --i) { child = ((Window*)data)[i]; if (!dockWindow(dpy, child) && getstate(dpy, child) == 1 && pids.contains(pidOfXWindow(dpy, child))) { if (data) XFree(data); return child; } } } if (data) XFree(data); return None; }
STATE* statelinked (STATE* clon) { LINK* linkclon; if (clon == NULL) return NULL; linkclon= getorigin( clon->nombre ); if( linkclon != NULL ) return(getstate(linkclon->destino)); linkclon=getdestiny( clon->nombre ); if(linkclon != NULL) return(getstate(linkclon->origen)); return NULL; }
static void comm_flush(void) /* flush output to driver */ { putc(COM_FLUSH, devout); fflush(devout); if (getc(devin) != COM_FLUSH) reply_error("flush"); getstate(); }
// MW-2011-09-23: Ensures the buffering state is consistent with current flags // and state. void MCPlayer::syncbuffering(MCContext *p_dc) { bool t_should_buffer; // MW-2011-09-13: [[ Layers ]] If the layer is dynamic then the player must be buffered. t_should_buffer = getstate(CS_SELECTED) || getflag(F_ALWAYS_BUFFER) || getstack() -> getstate(CS_EFFECT) || (p_dc != nil && p_dc -> gettype() != CONTEXT_TYPE_SCREEN) || !MCModeMakeLocalWindows() || layer_issprite(); // MW-2014-04-24: [[ Bug 12249 ]] If we are not in browse mode for this object, then it should be buffered. t_should_buffer = t_should_buffer || getstack() -> gettool(this) != T_BROWSE; }
Window findActiveWindow(Display *dpy, Window win) { Window inf; if (getstate(dpy, win) == 1) { return win; } inf = tryChildren(dpy, win); if (!inf) inf = win; return inf; }
static enum bufferevent_filter_result zlib_output_filter(struct evbuffer *src, struct evbuffer *dst, ev_ssize_t lim, enum bufferevent_flush_mode state, void *ctx) { struct evbuffer_iovec v_in[1]; struct evbuffer_iovec v_out[1]; int nread, nwrite; int res, n; z_streamp p = ctx; do { /* let's do some compression */ n = evbuffer_peek(src, -1, NULL, v_in, 1); if (n) { p->avail_in = v_in[0].iov_len; p->next_in = v_in[0].iov_base; } else { p->avail_in = 0; p->next_in = 0; } evbuffer_reserve_space(dst, 4096, v_out, 1); p->next_out = v_out[0].iov_base; p->avail_out = v_out[0].iov_len; /* we need to flush zlib if we got a flush */ res = deflate(p, getstate(state)); /* let's figure out how much was decompressed */ nread = v_in[0].iov_len - p->avail_in; nwrite = v_out[0].iov_len - p->avail_out; evbuffer_drain(src, nread); v_out[0].iov_len = nwrite; evbuffer_commit_space(dst, v_out, 1); if (res==Z_BUF_ERROR) { /* We're out of space, or out of decodeable input. Only if nwrite == 0 assume the latter. */ if (nwrite == 0) return BEV_NEED_MORE; } else { assert(res == Z_OK || res == Z_STREAM_END); } } while (evbuffer_get_length(src) > 0); ++outfilter_calls; return (BEV_OK); }
static int uvfs_write (dev_t dev, struct uio *uio, int ioflag) { uvfs_softc *st = getstate (dev); int error = 0; #ifdef UVFS_DEBUG_DEV warn ("uvfs%d: write\n", minor (dev)); #endif /* UVFS_DEBUG_DEV */ error = krpc_copyin(&st->rpcq, uio); return error; }
MCRectangle MCPlayer::getpreferredrect() { if (!getstate(CS_PREPARED)) { MCRectangle t_bounds; MCU_set_rect(t_bounds, 0, 0, formattedwidth, formattedheight); return t_bounds; } MCRectangle t_bounds; MCU_set_rect(t_bounds, 0, 0, 0, 0); return t_bounds; }
/*ARGSUSED*/ static int ntwdt_close(dev_t dev, int flag, int otyp, cred_t *credp) { int instance = getminor(dev); ntwdt_state_t *ntwdt_ptr = getstate(instance); if (ntwdt_ptr == NULL) { return (ENXIO); } mutex_enter(&ntwdt_ptr->ntwdt_mutex); ntwdt_ptr->ntwdt_open_flag = 0; mutex_exit(&ntwdt_ptr->ntwdt_mutex); return (0); }
static int uvfs_close (dev_t dev, int fflags, int devtype, struct proc *p) { uvfs_softc *st = getstate (dev); #ifdef UVFS_DEBUG_DEV warn ("uvfs%d: close\n", minor (dev)); #endif /* UVFS_DEBUG_DEV */ /* need to flush all outstanding RPC requests */ krpc_deactivate (&st->rpcq); krpc_flush (&st->rpcq); st->busy = 0; return 0; }
static struct driver * final_connect(void) /* verify and initialize connection */ { putw(COM_SENDM, devout); fflush(devout); if (getw(devin) != COM_RECVM) return(NULL); /* get driver parameters */ getstate(); /* set error vectors */ erract[COMMAND].pf = comm_comout; /* doesn't work with raypcalls.c if (erract[WARNING].pf != NULL) erract[WARNING].pf = comm_comout; */ return(&comm_driver); }
static int uvfs_select (dev_t dev, int which, struct proc *p) { uvfs_softc *st = getstate (dev); #ifdef UVFS_DEBUG_DEV warn ("uvfs%d: select\n", minor (dev)); #endif /* UVFS_DEBUG_DEV */ if (which & FWRITE) return 1; else { if (st->rpcq.inq.tqh_first) return 1; st->flags |= UVFS_RSEL; selrecord (p, &st->sel); return 0; } }
static void comm_comin( /* read string from command line */ char *buf, char *prompt ) { putc(COM_COMIN, devout); if (prompt == NULL) putc(0, devout); else { putc(1, devout); myputs(prompt, devout); } fflush(devout); if (getc(devin) != COM_COMIN) reply_error("comin"); mygets(buf, devin); getstate(); }
static int uvfs_read (dev_t dev, struct uio *uio, int ioflag) { int error = 0; uvfs_softc *st = getstate (dev); #ifdef UVFS_DEBUG_DEV warn ("uvfs%d: read\n", minor (dev)); #endif /* UVFS_DEBUG_DEV */ error = krpc_copyout(&st->rpcq, uio); if (!(ioflag & O_NONBLOCK)) while (error == EAGAIN) { error = tsleep (st, PRIBIO|PCATCH, "uvfs", 0); if (error) return error; error = krpc_copyout(&st->rpcq, uio); } return error; }
Boolean MCPlayer::playstop() { formattedwidth = formattedheight = 0; if (!getstate(CS_PREPARED)) return False; Boolean needmessage = True; state &= ~(CS_PREPARED | CS_PAUSED); lasttime = 0; freetmp(); if (MCplayers) { if (MCplayers == this) MCplayers = nextplayer; else { MCPlayer *tptr = MCplayers; while (tptr->nextplayer && tptr->nextplayer != this) tptr = tptr->nextplayer; if (tptr->nextplayer == this) tptr->nextplayer = nextplayer; } } nextplayer = nil; if (disposable) { if (needmessage) getcard()->message_with_valueref_args(MCM_play_stopped, getname()); delete this; } else if (needmessage) message_with_valueref_args(MCM_play_stopped, getname()); return True; }
ifreechk() { register int i; ino_t inum; for (i=0; i<sblock.fs_ninode; i++) { inum = sblock.fs_inode[i]; switch (getstate(inum)) { case USTATE: continue; default: pwarn("ALLOCATED INODE(S) IN IFREE LIST"); if (preen) printf(" (FIXED)\n"); if (preen || reply("FIX") == 1) { sblock.fs_ninode = i-1; sbdirty(); } return; } } }
static void XMLCALL end(void *data, const char *el) { AppData *ad = (AppData *) data; int state; state = getstate((char*)el, ad->current_state); if(!ad->xmlcheck) { switch(state) { case LAYOUT: generateDisk(ad,ad->image_data,ad->buffer_size); ad->floppy = hxcfe_getFloppy (ad->fb); if(ad->interface_mode>=0) hxcfe_floppySetInterfaceMode(ad->floppycontext,ad->floppy,ad->interface_mode); break; case TRACK: hxcfe_popTrack (ad->fb); break; case SECTOR: hxcfe_popSector(ad->fb); break; } } if(ad->stack_ptr) { ad->stack_ptr--; } ad->current_state = ad->statestack[ad->stack_ptr].state; }
void MCCard::render(void) { MCTileCacheRef t_tiler; t_tiler = getstack() -> gettilecache(); bool t_reset_ids; t_reset_ids = MCTileCacheIsClean(t_tiler); if (getstate(CS_SIZE)) { MCTileCacheLayer t_fg_layer; t_fg_layer . id = m_fg_layer_id; t_fg_layer . region = selrect; t_fg_layer . is_opaque = false; t_fg_layer . opacity = 255; t_fg_layer . ink = GXblendSrcOver; t_fg_layer . callback = render_foreground; t_fg_layer . context = this; MCTileCacheRenderScenery(t_tiler, t_fg_layer); m_fg_layer_id = t_fg_layer . id; } else m_fg_layer_id = 0; MCObjptr *t_objptrs; t_objptrs = getobjptrs(); if (t_objptrs != nil) { MCObjptr *t_objptr; t_objptr = t_objptrs -> prev(); do { MCControl *t_control; t_control = t_objptr -> getref(); // If the tilecache is 'clean' then we must reset the attrs to // force a sync. if (t_reset_ids) t_control -> layer_resetattrs(); // Take note of whether the spriteness of a layer has changed. bool t_old_is_sprite; t_old_is_sprite = t_control -> layer_issprite(); // Sync the attributes, make sure we commit the new values. t_control -> layer_computeattrs(true); // Initialize the common layer props. MCTileCacheLayer t_layer; t_layer . id = t_control -> layer_getid(); t_layer . opacity = t_control -> getopacity(); t_layer . ink = t_control -> getink(); t_layer . context = t_control; // The opaqueness of a layer has already been computed. t_layer . is_opaque = t_control -> layer_isopaque(); // Now compute the layer's region/clip. if (!t_control -> getflag(F_VISIBLE) && !MCshowinvisibles) { // Invisible layers just have empty region/clip. t_layer . region = MCU_make_rect(0, 0, 0, 0); t_layer . clip = MCU_make_rect(0, 0, 0, 0); } else if (!t_control -> layer_isscrolling()) { // Non-scrolling layer's are the size of their effective rects. t_layer . region = t_control -> geteffectiverect(); t_layer . clip = t_layer . region; } else { // For a scrolling layer, the clip is the bounds of the control, while // the region we draw is the group's minrect. t_layer . region = t_control -> layer_getcontentrect(); t_layer . clip = t_control -> geteffectiverect(); } // Now render the layer - what method we use depends on whether the // layer is a sprite or not. if (t_control -> layer_issprite()) { // If the layer was not a sprite before, remove the scenery // layer that it was. if (!t_old_is_sprite && t_layer . id != 0) { MCTileCacheRemoveScenery(t_tiler, t_layer . id, t_control -> geteffectiverect()); t_layer . id = 0; } t_layer . callback = testtilecache_sprite_renderer; MCTileCacheRenderSprite(t_tiler, t_layer); } else { // If the layer was a sprite before, remove the sprite // layer that it was. if (t_old_is_sprite && t_layer . id != 0) { MCTileCacheRemoveSprite(t_tiler, t_layer . id); t_layer . id = 0; } t_layer . callback = testtilecache_scenery_renderer; MCTileCacheRenderScenery(t_tiler, t_layer); } // Upate the id. t_control -> layer_setid(t_layer . id); // Advance to the object below. t_objptr = t_objptr -> prev(); } while(t_objptr != t_objptrs -> prev()); } // Final step is to render the background. Note that the background layer // really only needs to be the rect rounded outward to the nearest tile // boundaries, but 8192, 8192 is bigger than it can ever be at present so // is an easier alternative. MCTileCacheLayer t_bg_layer; t_bg_layer . id = m_bg_layer_id; t_bg_layer . region = MCU_make_rect(0, 0, 8192, 8192); t_bg_layer . is_opaque = true; t_bg_layer . opacity = 255; t_bg_layer . ink = GXblendSrcOver; t_bg_layer . callback = render_background; t_bg_layer . context = this; MCTileCacheRenderScenery(t_tiler, t_bg_layer); m_bg_layer_id = t_bg_layer . id; }
void removestate (int x, int y) { char str[20]; STATE* clon; STATE* clon1; STATE* aux; if (statedir==NULL) { return; } for (clon1 = statedir; clon1 !=NULL; clon1= clon1->p2next) { if((x>=(clon1->x)) && (x<((clon1->x)+DIAM)) && (y>=(clon1->y)) && (y<(clon1->y)+DIAM)) break; } if(!clon1){return;} clon=clon1; strcpy(str,clon->nombre); if (getstate(str)==NULL) { return; } if((statedir->p2next)==NULL) { if(strcmp(statedir->nombre, str)) { } else { deletedep(str); free(statedir); statedir=NULL; --statesnumb; } return; } if(!strcmp(statedir->nombre,str)) { deletedep(str); aux=statedir->p2next; free(statedir); statedir = aux; --statesnumb; return; } for(clon=statedir;strcmp(clon->p2next->nombre,str);clon=clon->p2next) { if(clon->p2next==NULL) return; } deletedep(str); aux=clon->p2next->p2next; free(clon->p2next); clon->p2next = aux; --statesnumb; return; }
// This method updates all the layer attributes of the control to make sure they // are consistent with the controls current set of flags. If commit is false, // then the new layermode is returned without changing anything. MCLayerModeHint MCControl::layer_computeattrs(bool p_commit) { // If the attrs have not changed, there is nothing to do. if (!m_layer_attr_changed) return m_layer_mode; // If the layer id is 0, then it means we should clear current settings. if (m_layer_id == 0) { m_layer_mode = kMCLayerModeHintStatic; m_layer_is_opaque = false; m_layer_is_unadorned = false; m_layer_is_sprite = false; m_layer_is_direct = false; } // The opacity of a control depends on what flags it has set - in particular // the 'opaque' flag. However, as 'opaque' determines themed bg rendering this // is not a sufficient condition. // // If a control has external bitmap effects (drop shadow, outerglow) then it // cannot be opaque. Similarly, if the control is rendered with themed bgs then // it cannot be opaque. // // Opacity is more dynamic an attribute than adornedness and should be handled // as a separate computation in the future. // bool t_is_opaque; t_is_opaque = false; if (MCBitmapEffectsIsInteriorOnly(getbitmapeffects())) { switch(gettype()) { case CT_GROUP: // Only consider groups unadorned groups to be opaque. t_is_opaque = getflag(F_OPAQUE) && !getflag(F_HSCROLLBAR | F_VSCROLLBAR | F_SHOW_NAME | F_SHOW_BORDER); break; case CT_FIELD: // Only consider unadorned fields to be opaque. t_is_opaque = getflag(F_OPAQUE) && !getflag(F_HSCROLLBAR | F_VSCROLLBAR | F_SHOW_BORDER | F_SHADOW) && (extraflags & EF_NO_FOCUS_BORDER) != 0; break; case CT_BUTTON: case CT_IMAGE: case CT_SCROLLBAR: case CT_GRAPHIC: case CT_PLAYER: default: // The rest of the control types are hard to assess for opacity as // that depends on their content / or complex theming considerations. t_is_opaque = false; break; } } else t_is_opaque = false; // The unadorned state depends on control type, but in general means that the // control consists of background + content. For a group content is the child // controls, for a field its the text, for an image its the bits, for a button // its the icon (if any), for a graphic it means just its shape. // // If a control has bitmap effects, it is always adorned as this requires further // processing of the image. // // If a control is selected, it is always adorned, since the selection handles // are part of the object. // bool t_is_unadorned; if (getbitmapeffects() == nil && !getstate(CS_SELECTED)) { switch(gettype()) { case CT_GROUP: // A group is unadorned if it has no scrollbars, no border and doesn't // show a name. t_is_unadorned = !getflag(F_HSCROLLBAR | F_VSCROLLBAR | F_SHOW_NAME | F_SHOW_BORDER); break; case CT_FIELD: // A field is unadorned if it has no shadow, no scrollbars, no border and no focus // border. t_is_unadorned = !getflag(F_HSCROLLBAR | F_VSCROLLBAR | F_SHOW_BORDER | F_SHADOW) && (extraflags & EF_NO_FOCUS_BORDER) != 0; break; case CT_BUTTON: // A button is unadorned if it is not a combo-box is showing an icon, has no border, // no name, no shadow, no hilite border, no arm border and no focus border. if (((MCButton *)this) -> getmenumode() != WM_COMBO) t_is_unadorned = getflag(F_SHOW_ICON) && !getflag(F_SHOW_BORDER | F_SHOW_NAME | F_SHADOW | F_HILITE_BORDER | F_ARM_BORDER) && (extraflags & EF_NO_FOCUS_BORDER) != 0; else t_is_unadorned = false; break; case CT_IMAGE: // An image is unadorned if it is not a pict, has no border and no focus border. if (static_cast<MCImage*>(this)->getcompression() != F_PICT) t_is_unadorned = !getflag(F_SHOW_BORDER) && (extraflags & EF_NO_FOCUS_BORDER) != 0; else t_is_unadorned = false; break; case CT_SCROLLBAR: case CT_GRAPHIC: case CT_PLAYER: default: t_is_unadorned = false; break; } } else t_is_unadorned = false; // The actual type of layer we will use depends on opacity, adornedness, // type and ink. MCLayerModeHint t_layer_mode; if (m_layer_mode_hint == kMCLayerModeHintStatic) { // To be a static layer, we must have an ink that is GXcopy or // GXblendSrcOver. if (ink == GXcopy || ink == GXblendSrcOver) t_layer_mode = kMCLayerModeHintStatic; else t_layer_mode = kMCLayerModeHintDynamic; } else if (m_layer_mode_hint == kMCLayerModeHintDynamic) { // There is no restriction on what control props can be to be // a dynamic layer. t_layer_mode = kMCLayerModeHintDynamic; } else if (m_layer_mode_hint == kMCLayerModeHintScrolling) { // A scrolling layer must be unadorned and a group. if (gettype() == CT_GROUP && t_is_unadorned) t_layer_mode = kMCLayerModeHintScrolling; else t_layer_mode = kMCLayerModeHintDynamic; } else if (m_layer_mode_hint == kMCLayerModeHintContainer) { // A container layer must be unadorned, non-opaque and a group. if (gettype() == CT_GROUP && !t_is_opaque && t_is_unadorned) t_layer_mode = kMCLayerModeHintContainer; else t_layer_mode = kMCLayerModeHintStatic; } // Now compute the sprite attribute. bool t_is_sprite; if (t_layer_mode == kMCLayerModeHintDynamic || t_layer_mode == kMCLayerModeHintScrolling) t_is_sprite = true; else t_is_sprite = false; // And now the direct attribute. bool t_is_direct; if (t_is_sprite) { // An unadorned image or button are direct. if (t_is_unadorned && (gettype() == CT_IMAGE || gettype() == CT_BUTTON)) t_is_direct = true; else t_is_direct = false; } else t_is_direct = false; // Finally, sync the attribtues. if (p_commit) { m_layer_mode = t_layer_mode; m_layer_is_opaque = t_is_opaque; m_layer_is_unadorned = t_is_unadorned; m_layer_is_sprite = t_is_sprite; m_layer_is_direct = t_is_direct; // We've updated the layer attrs now - yay! m_layer_attr_changed = false; } return m_layer_mode; }
int64_t parsemode(const char *modestr, mode_t mode) { int64_t modeint = mode; enum { equal, plus, minus }; enum { a, u, g, o }; enum { r, w, x, /* X, */ s, t }; enum { whichnone, whichoctal, whichcopy, whichperm }; union { struct { uint16_t sign:2, modenum:12; }; struct { uint16_t signplaceholder:2, to:3, from:3, perm:6; }; struct { uint16_t filler:14, which:2; }; uint16_t all; } modearray[strlen(modestr)]; // bigger than it needs to be size_t arrpos = 0; char *tmp; #define egoto { printf("line: %d str: %s\n", __LINE__, modestr); goto badreturn; } if (*modestr == ',' || !*modestr) egoto; // finite state machine to convert human input to machine parsable data while (*modestr) { modearray[arrpos].all = 0; switch (getstate(modestr)) { default: // not reached but gcc and clang issue a warning otherwise case comma: if (*++modestr == ',') egoto; arrpos++; break; case error: egoto; case ugoa: do { switch (*modestr) { case 'u': modearray[arrpos].to |= 1; break; case 'g': modearray[arrpos].to |= 2; break; case 'o': modearray[arrpos].to |= 4; break; case 'a': modearray[arrpos].to |= 7; break; default: goto outugoa; } modestr++; } while (1); outugoa: if (getstate(modestr) != op || getstate(modestr+1) == octal) egoto; break; case octal: modearray[arrpos].which = whichoctal; modearray[arrpos].sign = equal; modearray[arrpos].modenum = 4095 & strtol(modestr, &tmp, 8); // 4095 == lowest 12 bits modestr = tmp; break; case op: gotoop: switch (*modestr++) { case '+': modearray[arrpos].sign = plus ; break; case '-': modearray[arrpos].sign = minus; break; case '=': modearray[arrpos].sign = equal; break; } switch (getstate(modestr)) { case end: case comma: break; case octal: modearray[arrpos].which = whichoctal; modearray[arrpos].modenum = 4095 & strtol(modestr, &tmp, 8); modestr = tmp; break; case ugoa: modearray[arrpos].which = whichcopy; switch (*modestr++) { case 'a': egoto; case 'u': modearray[arrpos].from = u; break; case 'g': modearray[arrpos].from = g; break; case 'o': modearray[arrpos].from = o; break; } break; case perm: modearray[arrpos].which = whichperm; do { switch (*modestr) { case 'r': modearray[arrpos].perm |= 1 << r; break; case 'w': modearray[arrpos].perm |= 1 << w; break; case 'x': modearray[arrpos].perm |= 1 << x; break; // case 'X': modearray[arrpos].perm |= 1 << X; break; case 's': modearray[arrpos].perm |= 1 << s; break; case 't': modearray[arrpos].perm |= 1 << t; break; default: goto outperm; } modestr++; } while (1); outperm: break; default: egoto; } switch (getstate(modestr)) { case op: modearray[arrpos+1].all = 0; modearray[arrpos+1].to = modearray[arrpos].to; arrpos++; goto gotoop; case end: break; default: egoto; } break; } } // the actual loop is now much simpler for (size_t i = 0; i < arrpos; i++) { uint16_t mask = 0; if (modearray[i].to & 1) mask |= S_IRWXU; if (modearray[i].to & 2) mask |= S_IRWXG; if (modearray[i].to & 4) mask |= S_IRWXO; switch (modearray[i].which) { default: // not reached case whichperm: if (modearray[i].perm & 1 << r) { modeint |= mask & (S_IRUSR|S_IRGRP|S_IROTH); break; } if (modearray[i].perm & 1 << w) { modeint |= mask & (S_IWUSR|S_IWGRP|S_IWOTH); break; } if (modearray[i].perm & 1 << x) { modeint |= mask & (S_IXUSR|S_IXGRP|S_IXOTH); break; } // if (modearray[i].perm & 1 << X) { modeint |= mask & (S_IXUSR|S_IXGRP|S_IXOTH); break; } if (modearray[i].perm & 1 << s) { modeint |= mask & (S_ISUID|S_ISGID ); break; } if (modearray[i].perm & 1 << t) { modeint |= (S_ISVTX ); break; } break; case whichcopy: switch (modearray[i].from) { case u: modearray[i].modenum = mode & S_IRWXU; break; case g: modearray[i].modenum = mode & S_IRWXG; break; case o: modearray[i].modenum = mode & S_IRWXO; break; } // fallthrough case whichoctal: switch (modearray[i].sign) { case equal: modeint = modearray[i].modenum; break; case minus: modeint &= ~modearray[i].modenum; break; case plus : modeint |= modearray[i].modenum; break; } break; } } printf("<%" PRId64 ">\n", modeint); return modeint; badreturn: printf("error %" PRId64 "\n", modeint); return INT64_MIN; }
LINK* addlink (char* fun,char ev,char* str, char* str2,ALLEGRO_DISPLAY *dis) { LINK* clon; if (!strcmp(str,str2)) { al_show_native_message_box(dis, "ERROR!", "ERROR!", "Cannot create this kind of link",NULL, ALLEGRO_MESSAGEBOX_ERROR); return NULL; } if (linkdir==NULL) { if(getstate(str)==NULL) { return NULL; } if(getstate(str2)==NULL) { return NULL; } if(getlink(str,str2)!=NULL) { return NULL; } linkdir=calloc(1,sizeof(LINK)); linkdir->p2next=NULL; strcpy(linkdir->origen, str); strcpy(linkdir->destino, str2); strcpy(linkdir->fun_transf,fun); (linkdir->evento)=ev; ++linknumb; al_show_native_message_box(dis, "SUCCESS!", "Link created successfully", "",NULL, ALLEGRO_MESSAGEBOX_WARN); return(linkdir); } else { for(clon=linkdir;clon->p2next!=NULL;clon=clon->p2next); if(getstate(str)==NULL) { al_show_native_message_box(dis, "ERROR!", "ERROR!", "That link does not exist!",NULL, ALLEGRO_MESSAGEBOX_ERROR); return NULL; } if(getstate(str2)==NULL) { al_show_native_message_box(dis, "ERROR!", "ERROR!", "El estado de origen no existe(Linkdir).",NULL, ALLEGRO_MESSAGEBOX_ERROR); return NULL; } // if(getlink(str,str2)!=NULL) // { // al_show_native_message_box(dis, "ERROR!", "ERROR!", "El enlace ya existe!",NULL, ALLEGRO_MESSAGEBOX_ERROR); // return NULL; // } clon->p2next=calloc(1,sizeof(LINK)); clon->p2next->p2next=NULL; strcpy(clon->p2next->origen, str); strcpy(clon->p2next->destino, str2); strcpy(clon->p2next->fun_transf,fun); clon->p2next->evento=ev; ++linknumb; al_show_native_message_box(dis, "SUCCESS!", "Link created successfully", "",NULL, ALLEGRO_MESSAGEBOX_WARN); return(clon->p2next); } }
/*ARGSUSED*/ static int ntwdt_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, int *rvalp) { int instance = getminor(dev); int retval = 0; ntwdt_state_t *ntwdt_ptr = NULL; ntwdt_runstate_t *ntwdt_state; lom_dogstate_t lom_dogstate; lom_dogctl_t lom_dogctl; uint32_t lom_dogtime; if ((ntwdt_ptr = getstate(instance)) == NULL) { return (ENXIO); } ntwdt_state = ntwdt_ptr->ntwdt_run_state; switch (cmd) { case LOMIOCDOGSTATE: mutex_enter(&ntwdt_state->ntwdt_runstate_mutex); lom_dogstate.reset_enable = ntwdt_state->ntwdt_reset_enabled; lom_dogstate.dog_enable = ntwdt_state->ntwdt_watchdog_enabled; lom_dogstate.dog_timeout = ntwdt_state->ntwdt_watchdog_timeout; mutex_exit(&ntwdt_state->ntwdt_runstate_mutex); if (ddi_copyout((caddr_t)&lom_dogstate, (caddr_t)arg, sizeof (lom_dogstate_t), mode) != 0) { retval = EFAULT; } break; case LOMIOCDOGCTL: if (ddi_copyin((caddr_t)arg, (caddr_t)&lom_dogctl, sizeof (lom_dogctl_t), mode) != 0) { retval = EFAULT; break; } NTWDT_DBG(NTWDT_DBG_IOCTL, ("reset_enable: %d, and dog_enable: " "%d, watchdog_timeout %d", lom_dogctl.reset_enable, lom_dogctl.dog_enable, ntwdt_state->ntwdt_watchdog_timeout)); /* * ignore request to enable reset while disabling watchdog. */ if (!lom_dogctl.dog_enable && lom_dogctl.reset_enable) { NTWDT_DBG(NTWDT_DBG_IOCTL, ("invalid combination of " "reset_enable: %d, and dog_enable: %d", lom_dogctl.reset_enable, lom_dogctl.dog_enable)); retval = EINVAL; break; } mutex_enter(&ntwdt_state->ntwdt_runstate_mutex); if (ntwdt_state->ntwdt_watchdog_timeout == 0) { /* * the LOMIOCDOGTIME has never been used to setup * a valid timeout. */ NTWDT_DBG(NTWDT_DBG_IOCTL, ("timeout has not been set" "watchdog_timeout: %d", ntwdt_state->ntwdt_watchdog_timeout)); retval = EINVAL; goto end; } /* * Store the user specified state in the softstate. */ ntwdt_state->ntwdt_reset_enabled = lom_dogctl.reset_enable; ntwdt_state->ntwdt_watchdog_enabled = lom_dogctl.dog_enable; if (ntwdt_state->ntwdt_watchdog_enabled != 0) { /* * The user wants to enable the watchdog. * Arm the watchdog and start the cyclic. */ ntwdt_arm_watchdog(ntwdt_state); if (ntwdt_state->ntwdt_timer_running == 0) { ntwdt_start_timer(ntwdt_ptr); } NTWDT_DBG(NTWDT_DBG_IOCTL, ("AWDT is enabled")); } else { /* * The user wants to disable the watchdog. */ if (ntwdt_state->ntwdt_timer_running != 0) { ntwdt_stop_timer(ntwdt_ptr); } NTWDT_DBG(NTWDT_DBG_IOCTL, ("AWDT is disabled")); } mutex_exit(&ntwdt_state->ntwdt_runstate_mutex); break; case LOMIOCDOGTIME: if (ddi_copyin((caddr_t)arg, (caddr_t)&lom_dogtime, sizeof (uint32_t), mode) != 0) { retval = EFAULT; break; } NTWDT_DBG(NTWDT_DBG_IOCTL, ("user set timeout: %d", lom_dogtime)); /* * Ensure specified timeout is valid. */ if ((lom_dogtime == 0) || (lom_dogtime > (uint32_t)NTWDT_MAX_TIMEOUT)) { retval = EINVAL; NTWDT_DBG(NTWDT_DBG_IOCTL, ("user set invalid " "timeout: %d", (int)TICK_TO_MSEC(lom_dogtime))); break; } mutex_enter(&ntwdt_state->ntwdt_runstate_mutex); ntwdt_state->ntwdt_watchdog_timeout = lom_dogtime; /* * If awdt is currently running, re-arm it with the * newly-specified timeout value. */ if (ntwdt_state->ntwdt_timer_running != 0) { ntwdt_arm_watchdog(ntwdt_state); } mutex_exit(&ntwdt_state->ntwdt_runstate_mutex); break; case LOMIOCDOGPAT: /* * Allow user to pat the watchdog timer. */ NTWDT_DBG(NTWDT_DBG_IOCTL, ("DOGPAT is invoked")); mutex_enter(&ntwdt_state->ntwdt_runstate_mutex); /* * If awdt is not enabled or underlying cyclic is not * running, exit. */ if (!(ntwdt_state->ntwdt_watchdog_enabled && ntwdt_state->ntwdt_timer_running)) { NTWDT_DBG(NTWDT_DBG_IOCTL, ("PAT: AWDT not enabled")); goto end; } if (ntwdt_state->ntwdt_watchdog_expired == 0) { /* * re-arm the awdt. */ ntwdt_arm_watchdog(ntwdt_state); NTWDT_DBG(NTWDT_DBG_IOCTL, ("AWDT patted, " "remainning seconds: %d", ntwdt_state->ntwdt_time_remaining)); } mutex_exit(&ntwdt_state->ntwdt_runstate_mutex); break; default: retval = EINVAL; break; } return (retval); end: mutex_exit(&ntwdt_state->ntwdt_runstate_mutex); return (retval); }
// MW-2011-09-06: [[ Redraw ]] Added 'sprite' option - if true, ink and opacity are not set. void MCEPS::draw(MCDC *dc, const MCRectangle &dirty, bool p_isolated, bool p_sprite) { MCRectangle trect = rect; if (flags & F_SHOW_BORDER) trect = MCU_reduce_rect(trect, borderwidth); if (flags & F_OPAQUE) { setforeground(dc, DI_BACK, False); dc->fillrect(trect); } if (state & (CS_SIZE | CS_MOVE)) { dc->setlineatts(0, LineDoubleDash, CapButt, JoinBevel); dc->setforeground(dc->getblack()); dc->setbackground(dc->getwhite()); dc->setfillstyle(FillSolid, nil, 0, 0); dc->setdashes(0, dashlist, 2); MCLineSegment segs[2]; segs[0].x1 = segs[1].x1 = trect.x; segs[0].x2 = segs[1].x2 = trect.x + trect.width; segs[0].y1 = segs[1].y2 = trect.y; segs[0].y2 = segs[1].y1 = trect.y + trect.height; dc->drawsegments(segs, 2); dc->setlineatts(0, LineSolid, CapButt, JoinBevel); dc->setbackground(MCzerocolor); } #ifdef HAVE_EPS else { const char *psprolog = postscript; uint4 psprologlength = 0; const char *ps; uint4 length; if ((pagecount == 0) || (pagecount == 1)) { ps = postscript; length = strlen(postscript); } else { psprologlength = pageIndex[0]; ps = &postscript[pageIndex[curpage - 1] - 1]; if (curpage != pagecount) length = pageIndex[curpage] - pageIndex[curpage - 1]; else length = size - pageIndex[curpage - 1]; } setforeground(dc, DI_FORE, False); const char *fontname; uint2 fheight, fontsize, fontstyle; MCFontStruct *font; getfontatts(fontname, fheight, fontsize, fontstyle, font); dc->draweps(trect.x * xf, -(trect.y * yf), angle, xscale, yscale, tx, ty, prolog, psprolog, psprologlength, ps, length, fontname, fontsize, fontstyle, font, trect); } #endif if (flags & F_SHOW_BORDER) trect = MCU_reduce_rect(trect, -borderwidth); if (flags & F_SHOW_BORDER) if (flags & F_3D) draw3d(dc, trect, ETCH_SUNKEN, borderwidth); else drawborder(dc, trect, borderwidth); if (getstate(CS_KFOCUSED)) drawfocus(dc, dirty); if (state & CS_SELECTED) drawselected(dc); }
Types Scanner::getType(string str) { if (str == "else") return ELSE; // if (str == "main") // return MAIN; if (str == "printf") return PRINTF; if (str == "scanf") return SCANF; if (str == "if") return IF; if (str == "int") return INT; if (str == "double") return DOUBLE; if (str == "char") return CHAR; if (str == "return") return RETURN; if (str == "void") return VOID; if (str == "while") return WHILE; if (str == "for") return FOR; if (str == "%") return MOD; if (str == "+") return PLUS; if (str == "-") return MINUS; if (str == "*") return MULTI; if (str == "/") return RDIV; if (str == "<") return LT; if (str == "<=") return LE; if (str == ">") return GT; if (str == ">=") return GE; if (str == "==") return EQ; if (str == "!=") return NEQ; if (str == "=") return ASSIGN; if (str == ";") return SEMI; if (str == ",") return COMMA; if (str == "(") return LPAREN; if (str == ")") return RPAREN; if (str == "[") return LMBRACKET; if (str == "]") return RMBRACKET; if (str == "{") return LBBRACKET; if (str == "}") return RBBRACKET; if (str == "/*") return LCOMMENT; if (str == "*/") return RCOMMENT; if (str == "&") return ADDR; if (str == "++") return PLUSPLUS; if (str == "--") return MINUSMINUS; for (int i = 0;i < str.length();i++) { int type = getstate(str[i]); if (i == 0) { if (type != DFAID) break; } else if (type != DFAID && type != DFANUM ) break; if (i == (str.length()-1)) return ID; } return ERROR; }
bool Scanner::scan() { deleteComment(); tokens.clear(); int line = 1; bool success = true; index = 0; Types type; string str; DFAState state = START; char ch; while(1) { if (state == START)//初始状态,空格 { str = ""; ch = getNext(); if (ch == '\0') break; if (ch == '\n') line++; state = getstate(ch); if (state != START && (state != DFACHAR) && (state != DFASTR)) str += ch; } else if(state == DFANUM) { if (ch == '-') { ch = getNext(); if (ch < '0' || ch > '9') { state = DONE; getBack(); state = SYM; } else { getBack(); } } else { bool isdouble = false; while(1) { ch = getNext(); if (ch == '\0') return false; state = getstate(ch); if (state != DFANUM) { if (ch == '.'&& !isdouble) { isdouble = true; str += ch; } else { if (state == DFAID) { type = ERROR; str += ch; break; } getBack(); state = DONE; type = NUM; break; } } else str += ch; } } } else if (state == DFACHAR) { bool isstr = false; while(!isstr) { ch = getNext(); if (ch != '\'') { if (ch == '\n') { cout <<line<<":"<<"缺少单引号!"<< endl; success = false; getBack(); state = START; break; } if (ch == '\0') { cout <<line<<":"<<"缺少单引号!"<< endl; return false; } str+=ch; } else { if (str.length() > 1) { cout <<line<<":"<<"Char长度非法!"<< endl; success = false; state = START; break; } isstr = true; type = STR; state = DONE; } } } else if (state == DFASTR) { bool isstr = false; while(!isstr) { ch = getNext(); if (ch != '\"') { if (ch == '\n') { cout <<line<<":"<<"缺少双引号!"<< endl; success = false; getBack(); state = START; break; } if (ch == '\0') { cout <<line<<":"<<"缺少双引号!"<< endl; return false; } char temp = getNext(); if (ch == '\\' && temp == 'n') str += 10; else { getBack(); str+=ch; } } else { isstr = true; type = STR; state = DONE; } } } else if (state == DFAID) { while(1) { ch = getNext(); if (ch == '\0') return false; state = getstate(ch); if (state != DFAID && state != DFANUM || ch == '-') { getBack(); state = DONE; break; } else str += ch; } } else if (state == SYM) { char temp = ch; ch = getNext(); if (ch == '\0') return false; else if (ch == '=') str += ch; else if ((ch == '+' && temp == '+')||(ch == '-' && temp == '-')) str += ch; else getBack(); state = DONE; } else if (state == DONE) { Token temp; if (type == ERROR) { cout <<line<<":"<< "非法变量!"<< endl; success =false; } else if (type == NUM||type == STR) { temp.type = type; temp.value = str; temp.linenode = line; tokens.push_back(temp); } else { temp.type = getType(str); if (temp.type == ERROR) { cout <<line<<":"<< "字符无法识别!"<< endl; success = false; } else { if (temp.type == ID) temp.value = str; temp.linenode = line; tokens.push_back(temp); } } state = START; type = ELSE; } } // this->success = success; for (int i = 0;i < tokens.size();i++) { if (tokens[i].type == ID && i + 1 < tokens.size() && tokens[i+1].type == LMBRACKET) { tokens[i].type = ARRAY; } } return success; }
bp::tuple time_pickle::getinitargs(const elliptics_time& time) { return getstate(time); }