Index: work/remote/animator/Makefile =================================================================== --- work/remote/animator/Makefile (revision 4739) +++ work/remote/animator/Makefile (revision 4740) @@ -12,3 +12,4 @@ $(SPHASH) $(SPH_VERBOSE) --prefix cmds --out cmds_hash < cmds +hid_anim.o: gc.h Index: work/remote/animator/gc.h =================================================================== --- work/remote/animator/gc.h (nonexistent) +++ work/remote/animator/gc.h (revision 4740) @@ -0,0 +1,108 @@ +typedef struct { + unsigned in_use:1; + unsigned xor:1; + char cap; + char color[16]; + double width; +} gc_t; + +#define NUM_GC 32 +gc_t gc[NUM_GC]; + +static void cmd_makeGC(proto_node_t *args) +{ + int n, found = 0; + + send_begin(&pctx, "MakeGC"); + send_open(&pctx, 0); + for(n = 0; n < NUM_GC; n++) { + if (!gc[n].in_use) { + found = 1; + memset(gc+n, 0, sizeof(gc_t)); + gc[n].in_use = 1; + sendf(&pctx, "%d", n); + break; + } + } + + if (!found) + sends(&pctx, "-1"); + + send_close(&pctx); + send_end(&pctx); +} + + +static void cmd_delGC(proto_node_t *args) +{ + char *gs = str(child1(args)); + if (gs != NULL) { + int idx = atoi(gs); + if ((idx >= 0) && (idx < NUM_GC)) + gc[idx].in_use = 0; + } +} + +#define get_gc(idx, idx_str) \ +do { \ + char *__end__; \ + idx = strtol(gs, &__end__, 10); \ + if ((*__end__ != '\0') || (idx < 0) || (idx >= NUM_GC) || !gc[idx].in_use) \ + return; \ +} while(0) + +static void cmd_clr(proto_node_t *args) +{ + int idx; + proto_node_t *ch1 = child1(args); + char *gs = str(ch1), *cs = str(next(ch1)); + + if ((cs == NULL) || (gs == NULL)) + return; + get_gc(idx, gs); + if ((strlen(cs) > 7) || (*cs != '#')) + return; + strcpy(gc[idx].color, cs); +} + +static void cmd_cap(proto_node_t *args) +{ + int idx; + proto_node_t *ch1 = child1(args); + char *gs = str(ch1), *cs = str(next(ch1)); + + if ((cs == NULL) || (gs == NULL)) + return; + get_gc(idx, gs); + if ((*cs == 'r') || (*cs == 'b') || (*cs == 's')) + gc[idx].cap = *cs; +} + +static void cmd_linwid(proto_node_t *args) +{ + int idx; + char *end; + double d; + proto_node_t *ch1 = child1(args); + char *gs = str(ch1), *ws = str(next(ch1)); + + if ((ws == NULL) || (gs == NULL)) + return; + get_gc(idx, gs); + d = strtod(ws, &end); + if (*end == '\0') + gc[idx].width = d; +} + +static void cmd_setxor(proto_node_t *args) +{ + int idx; + proto_node_t *ch1 = child1(args); + char *gs = str(ch1), *xs = str(next(ch1)); + + if ((xs == NULL) || (gs == NULL)) + return; + get_gc(idx, gs); + if ((*xs == '0') || (*xs == '1')) + gc[idx].xor = !!(xs - '0'); +} Index: work/remote/animator/hid_anim.c =================================================================== --- work/remote/animator/hid_anim.c (revision 4739) +++ work/remote/animator/hid_anim.c (revision 4740) @@ -46,116 +46,8 @@ send_end(&pctx); } -typedef struct { - unsigned in_use:1; - unsigned xor:1; - char cap; - char color[16]; - double width; -} gc_t; +#include "gc.h" -#define NUM_GC 32 -gc_t gc[NUM_GC]; - -static void cmd_makeGC(proto_node_t *args) -{ - int n, found = 0; - - send_begin(&pctx, "MakeGC"); - send_open(&pctx, 0); - for(n = 0; n < NUM_GC; n++) { - if (!gc[n].in_use) { - found = 1; - memset(gc+n, 0, sizeof(gc_t)); - gc[n].in_use = 1; - sendf(&pctx, "%d", n); - break; - } - } - - if (!found) - sends(&pctx, "-1"); - - send_close(&pctx); - send_end(&pctx); -} - - -static void cmd_delGC(proto_node_t *args) -{ - char *gs = str(child1(args)); - if (gs != NULL) { - int idx = atoi(gs); - if ((idx >= 0) && (idx < NUM_GC)) - gc[idx].in_use = 0; - } -} - -#define get_gc(idx, idx_str) \ -do { \ - char *__end__; \ - idx = strtol(gs, &__end__, 10); \ - if ((*__end__ != '\0') || (idx < 0) || (idx >= NUM_GC) || !gc[idx].in_use) \ - return; \ -} while(0) - -static void cmd_clr(proto_node_t *args) -{ - int idx; - proto_node_t *ch1 = child1(args); - char *gs = str(ch1), *cs = str(next(ch1)); - - if ((cs == NULL) || (gs == NULL)) - return; - get_gc(idx, gs); - if ((strlen(cs) > 7) || (*cs != '#')) - return; - strcpy(gc[idx].color, cs); -} - -static void cmd_cap(proto_node_t *args) -{ - int idx; - proto_node_t *ch1 = child1(args); - char *gs = str(ch1), *cs = str(next(ch1)); - - if ((cs == NULL) || (gs == NULL)) - return; - get_gc(idx, gs); - if ((*cs == 'r') || (*cs == 'b') || (*cs == 's')) - gc[idx].cap = *cs; -} - -static void cmd_linwid(proto_node_t *args) -{ - int idx; - char *end; - double d; - proto_node_t *ch1 = child1(args); - char *gs = str(ch1), *ws = str(next(ch1)); - - if ((ws == NULL) || (gs == NULL)) - return; - get_gc(idx, gs); - d = strtod(ws, &end); - if (*end == '\0') - gc[idx].width = d; -} - -static void cmd_setxor(proto_node_t *args) -{ - int idx; - proto_node_t *ch1 = child1(args); - char *gs = str(ch1), *xs = str(next(ch1)); - - if ((xs == NULL) || (gs == NULL)) - return; - get_gc(idx, gs); - if ((*xs == '0') || (*xs == '1')) - gc[idx].xor = !!(xs - '0'); -} - - static void read_netin(void) { P_size_t len, n;