예제 #1
0
파일: hash.c 프로젝트: andyross/nasal
int naiHash_tryset(naRef hash, naRef key, naRef val)
{
    HashRec* hr = REC(hash);
    if(hr) {
        int ent, cell = findcell(hr, key, refhash(key));
        if((ent = TAB(hr)[cell]) >= 0) { ENTS(hr)[ent].val = val; return 1; }
    }
    return 0;
}
예제 #2
0
파일: hash.c 프로젝트: andyross/nasal
int naHash_get(naRef hash, naRef key, naRef* out)
{
    HashRec* hr = REC(hash);
    if(hr) {
        int ent, cell = findcell(hr, key, refhash(key));
        if((ent = TAB(hr)[cell]) < 0) return 0;
        *out = ENTS(hr)[ent].val;
        return 1;
    }
    return 0;
}
예제 #3
0
/*
 * Here when we get a keypress in a window.
 */
static void
dokey(GR_EVENT_KEYSTROKE *kp)
{
    if ((kp->wid != boardwid) || !playing)
        return;

    switch (kp->ch) {
    case ' ':			/* remember or forget mine */
        togglecell(findcell(kp->x, kp->y));
        break;
    }
}
예제 #4
0
파일: hash.c 프로젝트: andyross/nasal
static void hashset(HashRec* hr, naRef key, naRef val)
{
    int ent, cell = findcell(hr, key, refhash(key));
    if((ent = TAB(hr)[cell]) == ENT_EMPTY) {
        ent = hr->next++;
        if(ent >= NCELLS(hr)) return; /* race protection, don't overrun */
        TAB(hr)[cell] = ent;
        hr->size++;
        ENTS(hr)[ent].key = key;
    }
    ENTS(hr)[ent].val = val;
}
예제 #5
0
파일: hash.c 프로젝트: andyross/nasal
void naHash_delete(naRef hash, naRef key)
{
    HashRec* hr = REC(hash);
    if(hr) {
        int cell = findcell(hr, key, refhash(key));
        if(TAB(hr)[cell] >= 0) {
            TAB(hr)[cell] = ENT_DELETED;
            if(--hr->size < POW2(hr->lgsz-1))
                resize(PTR(hash).hash);
        }
    }
}
예제 #6
0
/*
 * Here when we get a button down event.
 */
static void
dobutton(GR_EVENT_BUTTON *bp)
{
    if (bp->wid == boardwid) {
        movetopos(findcell(bp->x, bp->y));
        return;
    }

    if (bp->wid == quitwid) {
        GrFillRect(quitwid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        if (savefile)
            writegame(savefile);
        GrClose();
        exit(0);
    }

    if (bp->wid == savewid) {
        GrFillRect(savewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        if (savefile == NULL)
            savefile = SAVEFILE;
        if (writegame(savefile))
            write(1, "\007", 1);
        else
            delay();
        GrFillRect(savewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
    }

    if (bp->wid == newgamewid) {
        GrFillRect(newgamewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        /*if (playing)
        	write(1, "\007", 1);
        else {*/
        newgame();
        delay();
        /*}*/
        GrFillRect(newgamewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
    }
}