void newAssoc(Name name, Any obj) { PceITFSymbol symbol; Any old; if ( (old = getObjectAssoc(name)) ) deleteAssoc(old); deleteAssoc(obj); if ( onFlag(name, F_ITFNAME) ) { symbol = getMemberHashTable(NameToITFTable, name); symbol->object = obj; appendHashTable(ObjectToITFTable, obj, symbol); setFlag(obj, F_ASSOC); } else { symbol = newSymbol(obj, name); setFlag(name, F_ITFNAME); if ( isObject(obj) ) setFlag(obj, F_ASSOC); appendHashTable(ObjectToITFTable, obj, symbol); appendHashTable(NameToITFTable, name, symbol); } if ( isObject(obj) ) lockObj(obj); }
void ws_status_timer(Timer tm, Name status) { UINT id; if ( (id = getIdTimer(tm)) ) { KillTimer(NULL, id); deleteHashTable(TimerTable, toInt(id)); setIdTimer(tm, 0); } if ( status != NAME_idle ) { long msec = (long) (valReal(tm->interval) * 1000.0); if ( (id = SetTimer(NULL, 0, (UINT)msec, (TIMERPROC) timer_proc)) ) { if ( !TimerTable ) { TimerTable = globalObject(CtoName("active_timers"), ClassHashTable, EAV); assign(TimerTable, refer, NAME_none); } appendHashTable(TimerTable, toInt(id), tm); setIdTimer(tm, id); DEBUG(NAME_timer, Cprintf("Created timer of %d milliseconds (id = %d)\n", msec, id)); } else Cprintf("Failed SetTimer()\n"); } }
static status initialiseSyntaxTable(SyntaxTable t, Name name, SyntaxTable def) { unsigned short *flags; unsigned char *context; if ( isDefault(name) ) name = NIL; if ( notDefault(def) ) { flags = def->table; context = def->context; assign(t, sentence_end, def->paragraph_end); assign(t, paragraph_end, def->paragraph_end); } else { flags = char_flags; context = char_context; assign(t, sentence_end, newObject(ClassRegex, CtoName("[.?!]\\s"), EAV)); assign(t, paragraph_end, newObject(ClassRegex, CtoName("\\s*\n"), EAV)); } assign(t, name, name); assign(t, size, toInt(256)); t->table = alloc(FLAGS_SIZE(t)); t->context = alloc(CONTEXT_SIZE(t)); memcpy(t->table, flags, FLAGS_SIZE(t)); memcpy(t->context, context, CONTEXT_SIZE(t)); if ( notNil(name) ) appendHashTable(SyntaxTables, name, t); succeed; }
static HashTable LoadColourNames() { if ( !ColourNames ) { xcolourdef *cd; ColourNames = globalObject(NAME_colourNames, ClassHashTable, EAV); for(cd = x11_colours; cd->name; cd++) { COLORREF rgb = RGB(cd->red, cd->green, cd->blue); char buf[100]; const char *s = cd->name; char *q = buf; for( ; *s; s++ ) { if ( *s == ' ' ) *q++ = '_'; else *q++ = tolower(*s); } *q = '\0'; appendHashTable(ColourNames, CtoKeyword(buf), toInt(rgb)); } ws_system_colours(CurrentDisplay(NIL)); } return ColourNames; }
static status initialiseElevation(Elevation e, Any name, Int height, Any colour, Any relief, Any shadow, Name kind, Any bg) { if ( isDefault(name) ) name = NIL; assign(e, name, name); assign(e, background, bg); if ( isDefault(height) && isInteger(name) ) height = name; if ( notDefault(colour) ) assign(e, colour, colour); if ( notDefault(relief) ) assign(e, relief, relief); if ( notDefault(shadow) ) assign(e, shadow, shadow); if ( notDefault(kind) ) assign(e, kind, kind); if ( notDefault(height) ) assign(e, height, height); obtainClassVariablesObject(e); if ( notNil(name) ) appendHashTable(ElevationTable, name, e); succeed; }
static status prependChainTable(ChainTable ct, Any name, Any value) { Chain ch; if ( (ch = getMemberHashTable((HashTable) ct, name)) ) prependChain(ch, value); else appendHashTable((HashTable) ct, name, newObject(ClassChain, value, EAV)); succeed; }
static HashTable LoadColourNames() { if ( !ColourNames ) { FileObj f = answerObject(ClassFile, CtoName("$PCEHOME/lib/rgb.txt"), EAV); ColourNames = globalObject(NAME_colourNames, ClassHashTable, EAV); if ( send(f, NAME_open, NAME_read, EAV) ) { char line[256]; int r, g, b; char name[80]; while( fgets(line, sizeof(line), f->fd) ) { switch( sscanf(line, "%d%d%d%[^\n]", &r, &g, &b, name) ) { case 4: { char *s; char *e; COLORREF rgb; Name cname; for(s=name; *s && *s <= ' '; s++) ; for(e = s + strlen(s); e > s && e[-1] <= ' '; e--) ; *e = EOS; for(e=s; *e; e++) { if ( isupper(*e) ) *e = tolower(*e); else if ( *e == ' ' ) *e = '_'; } cname = CtoKeyword(s); rgb = RGB(r, g, b); appendHashTable(ColourNames, cname, toInt(rgb)); DEBUG(NAME_colour, Cprintf("%s --> 0x%lx\n", pp(cname), (long) rgb)); break; } } } send(f, NAME_close, EAV); } } return ColourNames; }
static HashTable LoadX11ColourNames() { if ( !X11ColourNames ) { xcolourdef *cd; X11ColourNames = globalObject(CtoName("_x11_colour_names"), ClassHashTable, EAV); for(cd = x11_colours; cd->name; cd++) { COLORREF rgb = RGB(cd->red, cd->green, cd->blue); appendHashTable(X11ColourNames, toInt(rgb), CtoName(cd->name)); } } return X11ColourNames; }
status initialiseImage(Image image, SourceSink data, Int w, Int h, Name kind) { Name name = FAIL; if ( isDefault(data) ) data = (SourceSink) NIL; if ( notNil(data) && hasGetMethodObject(data, NAME_name) ) name = get(data, NAME_name, EAV); if ( !name ) name = NIL; assign(image, name, name); assign(image, background, DEFAULT); assign(image, foreground, DEFAULT); ws_init_image(image); if ( isNil(data) || notDefault(w) || notDefault(h) || notDefault(kind) ) { if ( isDefault(w) ) w = toInt(16); if ( isDefault(h) ) h = toInt(16); if ( isDefault(kind) ) kind = NAME_bitmap; assign(image, kind, kind); assign(image, file, NIL); assign(image, depth, kind == NAME_bitmap ? ONE : (Int) DEFAULT); assign(image, size, newObject(ClassSize, w, h, EAV)); assign(image, access, NAME_both); } else { assign(image, kind, NAME_bitmap); assign(image, file, data); assign(image, depth, ONE); assign(image, size, newObject(ClassSize, EAV)); TRY(loadImage(image, DEFAULT, DEFAULT)); assign(image, access, NAME_read); } if ( notNil(name) ) { protectObject(image); appendHashTable(ImageTable, name, image); } succeed; }
static HashTable LoadX11ColourNames() { if ( !X11ColourNames ) { FileObj f = answerObject(ClassFile, CtoName("$PCEHOME/lib/rgb.txt"), EAV); X11ColourNames = globalObject(CtoName("_x11_colour_names"), ClassHashTable, EAV); if ( send(f, NAME_open, NAME_read, EAV) ) { char line[256]; int r, g, b; char name[80]; while( fgets(line, sizeof(line), f->fd) ) { switch( sscanf(line, "%d%d%d%[^\n]", &r, &g, &b, name) ) { case 4: { char *s; char *e; COLORREF rgb; for(s=name; *s && *s <= ' '; s++) ; for(e = s + strlen(s); e > s && e[-1] <= ' '; e--) ; *e = EOS; rgb = RGB(r, g, b); appendHashTable(X11ColourNames, toInt(rgb), CtoName(s)); break; } } } send(f, NAME_close, EAV); } } return X11ColourNames; }
static status initialiseVar(Var v, Type type, Name name, Any value) { if ( isDefault(type) ) type = TypeUnchecked; if ( isDefault(name) ) /* local var */ name = NIL; assign(v, name, name); assign(v, type, type); assign(v, global_value, value); v->value = value; if ( isObject(value) ) addCodeReference(value); if ( notNil(name) ) { if ( getMemberHashTable(VarTable, name) ) errorPce(v, NAME_redeclaredVar); appendHashTable(VarTable, name, v); protectObject(v); } return initialiseFunction((Function) v); }