diff options
Diffstat (limited to 'xorg-server/hw/dmx/config')
-rw-r--r-- | xorg-server/hw/dmx/config/Canvas.c | 132 | ||||
-rw-r--r-- | xorg-server/hw/dmx/config/dmxcompat.c | 160 | ||||
-rw-r--r-- | xorg-server/hw/dmx/config/dmxconfig.c | 340 | ||||
-rw-r--r-- | xorg-server/hw/dmx/config/dmxparse.c | 1295 | ||||
-rw-r--r-- | xorg-server/hw/dmx/config/dmxparse.h | 329 | ||||
-rw-r--r-- | xorg-server/hw/dmx/config/dmxprint.c | 373 | ||||
-rw-r--r-- | xorg-server/hw/dmx/config/dmxtodmx.c | 7 | ||||
-rw-r--r-- | xorg-server/hw/dmx/config/vdltodmx.c | 10 | ||||
-rw-r--r-- | xorg-server/hw/dmx/config/xdmxconfig.c | 1263 |
9 files changed, 2093 insertions, 1816 deletions
diff --git a/xorg-server/hw/dmx/config/Canvas.c b/xorg-server/hw/dmx/config/Canvas.c index c2eba876a..34a47a2bf 100644 --- a/xorg-server/hw/dmx/config/Canvas.c +++ b/xorg-server/hw/dmx/config/Canvas.c @@ -60,100 +60,106 @@ #include <X11/StringDefs.h> #include "CanvasP.h" -static void CanvasInitialize(Widget request, Widget w, - ArgList args, Cardinal *num_args) +static void +CanvasInitialize(Widget request, Widget w, ArgList args, Cardinal * num_args) { } -static void CanvasExpose(Widget w, XEvent *event, Region region) +static void +CanvasExpose(Widget w, XEvent * event, Region region) { CanvasExposeDataRec data; - data.w = w; - data.event = event; + data.w = w; + data.event = event; data.region = region; - - if (!XtIsRealized(w)) return; - XtCallCallbacks(w, XtNcanvasExposeCallback, (XtPointer)&data); + + if (!XtIsRealized(w)) + return; + XtCallCallbacks(w, XtNcanvasExposeCallback, (XtPointer) & data); } -static void CanvasResize(Widget w) +static void +CanvasResize(Widget w) { - if (!XtIsRealized(w)) return; - XtCallCallbacks(w, XtNcanvasResizeCallback, (XtPointer)w); + if (!XtIsRealized(w)) + return; + XtCallCallbacks(w, XtNcanvasResizeCallback, (XtPointer) w); } -static void CanvasAction(Widget w, XEvent *event, - String *params, Cardinal *num_params) +static void +CanvasAction(Widget w, XEvent * event, String * params, Cardinal * num_params) { - XtCallCallbacks(w, XtNcallback, (XtPointer)event); + XtCallCallbacks(w, XtNcallback, (XtPointer) event); } #define offset(field) XtOffsetOf(CanvasRec, canvas.field) static XtResource resources[] = { - { XtNcallback, XtCCallback, XtRCallback, - sizeof(XtCallbackList), offset(input_callback), XtRCallback, NULL }, - { XtNcanvasExposeCallback, XtCcanvasExposeCallback, XtRCallback, - sizeof(XtCallbackList), offset(expose_callback), XtRCallback, NULL }, - { XtNcanvasResizeCallback, XtCcanvasResizeCallback, XtRCallback, - sizeof(XtCallbackList), offset(resize_callback), XtRCallback, NULL }, + {XtNcallback, XtCCallback, XtRCallback, + sizeof(XtCallbackList), offset(input_callback), XtRCallback, NULL} + , + {XtNcanvasExposeCallback, XtCcanvasExposeCallback, XtRCallback, + sizeof(XtCallbackList), offset(expose_callback), XtRCallback, NULL} + , + {XtNcanvasResizeCallback, XtCcanvasResizeCallback, XtRCallback, + sizeof(XtCallbackList), offset(resize_callback), XtRCallback, NULL} + , }; + #undef offset -static XtActionsRec actions[] = -{ - {"canvas", CanvasAction}, +static XtActionsRec actions[] = { + {"canvas", CanvasAction}, }; -static char translations[] = -"<Key>: canvas()\n\ +static char translations[] = "<Key>: canvas()\n\ <Motion>: canvas()\n\ <BtnDown>: canvas()\n\ <BtnUp>: canvas()\n\ -" -; +"; #define Superclass (&widgetClassRec) CanvasClassRec canvasClassRec = { /* core */ { - (WidgetClass)Superclass, /* superclass */ - "Canvas", /* class_name */ - sizeof(CanvasRec), /* widget_size */ - NULL, /* class_initialize */ - NULL, /* class_part_initialize */ - False, /* class_inited */ - CanvasInitialize, /* initialize */ - NULL, /* initialize_hook */ - XtInheritRealize, /* realize */ - actions, /* actions */ - XtNumber(actions), /* num_actions */ - resources, /* resources */ - XtNumber(resources), /* num_resources */ - NULLQUARK, /* xrm_class */ - True, /* compress_motion */ - True, /* compress_exposure */ - True, /* compress_enterleave */ - False, /* visible_interest */ - NULL, /* destroy */ - CanvasResize, /* resize */ - CanvasExpose, /* expose */ - NULL, /* set_values */ - NULL, /* set_values_hook */ - XtInheritSetValuesAlmost, /* set_values_almost */ - NULL, /* get_values_hook */ - NULL, /* accept_focus */ - XtVersion, /* version */ - NULL, /* callback_private */ - translations, /* tm_table */ - XtInheritQueryGeometry, /* query_geometry */ - XtInheritDisplayAccelerator, /* display_accelerator */ - NULL, /* extension */ - }, + (WidgetClass) Superclass, /* superclass */ + "Canvas", /* class_name */ + sizeof(CanvasRec), /* widget_size */ + NULL, /* class_initialize */ + NULL, /* class_part_initialize */ + False, /* class_inited */ + CanvasInitialize, /* initialize */ + NULL, /* initialize_hook */ + XtInheritRealize, /* realize */ + actions, /* actions */ + XtNumber(actions), /* num_actions */ + resources, /* resources */ + XtNumber(resources), /* num_resources */ + NULLQUARK, /* xrm_class */ + True, /* compress_motion */ + True, /* compress_exposure */ + True, /* compress_enterleave */ + False, /* visible_interest */ + NULL, /* destroy */ + CanvasResize, /* resize */ + CanvasExpose, /* expose */ + NULL, /* set_values */ + NULL, /* set_values_hook */ + XtInheritSetValuesAlmost, /* set_values_almost */ + NULL, /* get_values_hook */ + NULL, /* accept_focus */ + XtVersion, /* version */ + NULL, /* callback_private */ + translations, /* tm_table */ + XtInheritQueryGeometry, /* query_geometry */ + XtInheritDisplayAccelerator, /* display_accelerator */ + NULL, /* extension */ + } + , /* canvas */ { - NULL, /* extension */ - } + NULL, /* extension */ + } }; -WidgetClass canvasWidgetClass = (WidgetClass)&canvasClassRec; +WidgetClass canvasWidgetClass = (WidgetClass) & canvasClassRec; diff --git a/xorg-server/hw/dmx/config/dmxcompat.c b/xorg-server/hw/dmx/config/dmxcompat.c index 1c72084fa..bd9f12738 100644 --- a/xorg-server/hw/dmx/config/dmxcompat.c +++ b/xorg-server/hw/dmx/config/dmxcompat.c @@ -52,80 +52,84 @@ #include <string.h> #include <ctype.h> -static int dmxVDLReadLine(FILE *str, char *buf, int len) +static int +dmxVDLReadLine(FILE * str, char *buf, int len) { - if (fgets(buf, len, str)) return strlen(buf); + if (fgets(buf, len, str)) + return strlen(buf); return 0; } -static int dmxVDLCount(const char *buf) +static int +dmxVDLCount(const char *buf) { return strtol(buf, NULL, 10); } -static void dmxVDLVirtualEntry(const char *buf, - char *name, int *len, - int *x, int *y) +static void +dmxVDLVirtualEntry(const char *buf, char *name, int *len, int *x, int *y) { - char *end; + char *end; const char *s; - char *d; - int start; - + char *d; + int start; + *x = strtol(buf, &end, 10); *y = strtol(end, &end, 10); for (s = end, d = name, start = 1; *s && *s != '['; ++s) { - if (start && isspace(*s)) continue; - *d++ = *s; + if (start && isspace(*s)) + continue; + *d++ = *s; start = 0; } *d = '\0'; - while (d > name && isspace(d[-1])) *--d = '\0'; /* remove trailing space */ + while (d > name && isspace(d[-1])) + *--d = '\0'; /* remove trailing space */ *len = strlen(name); } -static void dmxVDLDisplayEntry(const char *buf, - char *name, int *len, - int *x, int *y, - int *xoff, int *yoff, - int *xorig, int *yorig) +static void +dmxVDLDisplayEntry(const char *buf, + char *name, int *len, + int *x, int *y, int *xoff, int *yoff, int *xorig, int *yorig) { const char *pt; - char *end; - - pt = strchr(buf, ' '); - strlcpy(name, buf, 1+pt-buf); - *len = strlen(name); - - *x = strtol(pt, &end, 10); - *y = strtol(end, &end, 10); + char *end; + + pt = strchr(buf, ' '); + strlcpy(name, buf, 1 + pt - buf); + *len = strlen(name); + + *x = strtol(pt, &end, 10); + *y = strtol(end, &end, 10); *xorig = strtol(end, &end, 10); *yorig = strtol(end, &end, 10); - *xoff = strtol(end, &end, 10); - *yoff = strtol(end, NULL, 10); + *xoff = strtol(end, &end, 10); + *yoff = strtol(end, NULL, 10); } /** Read from the VDL format \a filename and return a newly allocated \a * DMXConfigEntryPtr */ -DMXConfigEntryPtr dmxVDLRead(const char *filename) +DMXConfigEntryPtr +dmxVDLRead(const char *filename) { - FILE *str; - char buf[2048]; /* RATS: Use ok */ - char *pt; - int lineno = 0; - DMXConfigEntryPtr entry = NULL; + FILE *str; + char buf[2048]; /* RATS: Use ok */ + char *pt; + int lineno = 0; + DMXConfigEntryPtr entry = NULL; DMXConfigVirtualPtr virtual = NULL; - DMXConfigSubPtr sub = NULL; + DMXConfigSubPtr sub = NULL; DMXConfigDisplayPtr display = NULL; - DMXConfigFullDimPtr fdim = NULL; - int vcount = 0; - int dcount = 0; - int icount = 0; - int x, y, xoff, yoff, xorig, yorig; - char name[2048]; /* RATS: Use ok */ - const char *tmp; - int len; + DMXConfigFullDimPtr fdim = NULL; + int vcount = 0; + int dcount = 0; + int icount = 0; + int x, y, xoff, yoff, xorig, yorig; + char name[2048]; /* RATS: Use ok */ + const char *tmp; + int len; enum { simulateFlag, virtualCount, @@ -134,15 +138,18 @@ DMXConfigEntryPtr dmxVDLRead(const char *filename) displayEntry, ignoreCount, ignoreEntry - } state = simulateFlag; + } state = simulateFlag; - if (!filename) str = stdin; - else str = fopen(filename, "r"); - if (!str) return NULL; + if (!filename) + str = stdin; + else + str = fopen(filename, "r"); + if (!str) + return NULL; while (dmxVDLReadLine(str, buf, sizeof(buf))) { DMXConfigCommentPtr comment = NULL; - + ++lineno; for (pt = buf; *pt; pt++) if (*pt == '\r' || *pt == '\n') { @@ -166,7 +173,7 @@ DMXConfigEntryPtr dmxVDLRead(const char *filename) case virtualEntry: len = sizeof(name); dmxVDLVirtualEntry(buf, name, &len, &x, &y); - tmp = dmxConfigCopyString(name, len); + tmp = dmxConfigCopyString(name, len); virtual = dmxConfigCreateVirtual(NULL, dmxConfigCreateString(T_STRING, lineno, @@ -186,41 +193,29 @@ DMXConfigEntryPtr dmxVDLRead(const char *filename) case displayEntry: dmxVDLDisplayEntry(buf, name, &len, &x, &y, &xoff, &yoff, &xorig, &yorig); - tmp = dmxConfigCopyString(name, len); - fdim = dmxConfigCreateFullDim( - dmxConfigCreatePartDim( - dmxConfigCreatePair(T_DIMENSION, - lineno, - NULL, - x, y, 0, 0), - dmxConfigCreatePair(T_OFFSET, - lineno, - NULL, - xoff, yoff, - xoff, yoff)), - NULL); - display = dmxConfigCreateDisplay(NULL, - dmxConfigCreateString(T_STRING, - lineno, - NULL, - tmp), - fdim, - dmxConfigCreatePair(T_ORIGIN, - lineno, - NULL, - xorig, yorig, - 0, 0), - NULL); + tmp = dmxConfigCopyString(name, len); + fdim = + dmxConfigCreateFullDim(dmxConfigCreatePartDim + (dmxConfigCreatePair + (T_DIMENSION, lineno, NULL, x, y, 0, 0), + dmxConfigCreatePair(T_OFFSET, lineno, + NULL, xoff, yoff, + xoff, yoff)), NULL); + display = + dmxConfigCreateDisplay(NULL, + dmxConfigCreateString(T_STRING, lineno, + NULL, tmp), fdim, + dmxConfigCreatePair(T_ORIGIN, lineno, + NULL, xorig, yorig, + 0, 0), NULL); sub = dmxConfigAddSub(sub, dmxConfigSubDisplay(display)); if (!--dcount) { - state = ignoreCount; + state = ignoreCount; virtual->subentry = sub; - entry = dmxConfigAddEntry(entry, - dmxConfigVirtual, - NULL, - virtual); - virtual = NULL; - sub = NULL; + entry = dmxConfigAddEntry(entry, + dmxConfigVirtual, NULL, virtual); + virtual = NULL; + sub = NULL; } break; case ignoreCount: @@ -228,7 +223,8 @@ DMXConfigEntryPtr dmxVDLRead(const char *filename) state = ignoreEntry; break; case ignoreEntry: - if (!--icount) state = virtualEntry; + if (!--icount) + state = virtualEntry; break; } } diff --git a/xorg-server/hw/dmx/config/dmxconfig.c b/xorg-server/hw/dmx/config/dmxconfig.c index a31e5f7f7..2cc9ab396 100644 --- a/xorg-server/hw/dmx/config/dmxconfig.c +++ b/xorg-server/hw/dmx/config/dmxconfig.c @@ -34,7 +34,6 @@ /** \file * Provides interface for reading DMX configuration files and for * combining that information with command-line configuration parameters. */ - #ifdef HAVE_DMX_CONFIG_H #include <dmx-config.h> @@ -49,7 +48,7 @@ #include "dmxstat.h" #include "parser.h" -extern int yyparse(void); +extern int yyparse(void); extern FILE *yyin; static char *dmxXkbRules; @@ -60,35 +59,39 @@ static char *dmxXkbOptions; /** Stores lists of configuration information. */ typedef struct DMXConfigListStruct { - const char *name; + const char *name; struct DMXConfigListStruct *next; } DMXConfigList, *DMXConfigListPtr; /** This stucture stores the parsed configuration information. */ typedef struct DMXConfigCmdStruct { - const char *filename; - const char *config; + const char *filename; + const char *config; DMXConfigList *displays; DMXConfigList *inputs; DMXConfigList *xinputs; } DMXConfigCmd, *DMXConfigCmdPtr; -DMXConfigEntryPtr dmxConfigEntry; -static DMXConfigCmd dmxConfigCmd; +DMXConfigEntryPtr dmxConfigEntry; +static DMXConfigCmd dmxConfigCmd; static int dmxDisplaysFromCommandLine; /** Make a note that \a display is the name of an X11 display that * should be initialized as a backend (output) display. Called from * #ddxProcessArgument. */ -void dmxConfigStoreDisplay(const char *display) +void +dmxConfigStoreDisplay(const char *display) { DMXConfigListPtr entry = malloc(sizeof(*entry)); + entry->name = strdup(display); entry->next = NULL; - if (!dmxConfigCmd.displays) dmxConfigCmd.displays = entry; + if (!dmxConfigCmd.displays) + dmxConfigCmd.displays = entry; else { DMXConfigList *pt; + for (pt = dmxConfigCmd.displays; pt->next; pt = pt->next); if (!pt) dmxLog(dmxFatal, "dmxConfigStoreDisplay: end of list non-NULL\n"); @@ -99,14 +102,18 @@ void dmxConfigStoreDisplay(const char *display) /** Make a note that \a input is the name of an X11 display that should * be used for input (either a backend or a console input device). */ -void dmxConfigStoreInput(const char *input) +void +dmxConfigStoreInput(const char *input) { DMXConfigListPtr entry = malloc(sizeof(*entry)); + entry->name = strdup(input); entry->next = NULL; - if (!dmxConfigCmd.inputs) dmxConfigCmd.inputs = entry; + if (!dmxConfigCmd.inputs) + dmxConfigCmd.inputs = entry; else { DMXConfigList *pt; + for (pt = dmxConfigCmd.inputs; pt->next; pt = pt->next); if (!pt) dmxLog(dmxFatal, "dmxConfigStoreInput: end of list non-NULL\n"); @@ -116,14 +123,18 @@ void dmxConfigStoreInput(const char *input) /** Make a note that \a input is the name of an X11 display that should * be used for input from XInput extension devices. */ -void dmxConfigStoreXInput(const char *input) +void +dmxConfigStoreXInput(const char *input) { DMXConfigListPtr entry = malloc(sizeof(*entry)); + entry->name = strdup(input); entry->next = NULL; - if (!dmxConfigCmd.xinputs) dmxConfigCmd.xinputs = entry; + if (!dmxConfigCmd.xinputs) + dmxConfigCmd.xinputs = entry; else { DMXConfigList *pt; + for (pt = dmxConfigCmd.xinputs; pt->next; pt = pt->next); if (!pt) dmxLog(dmxFatal, "dmxConfigStoreXInput: end of list non-NULL\n"); @@ -132,7 +143,8 @@ void dmxConfigStoreXInput(const char *input) } /** Make a note that \a file is the configuration file. */ -void dmxConfigStoreFile(const char *file) +void +dmxConfigStoreFile(const char *file) { if (dmxConfigCmd.filename) dmxLog(dmxFatal, "Only one -configfile allowed\n"); @@ -141,79 +153,89 @@ void dmxConfigStoreFile(const char *file) /** Make a note that \a config should be used as the configuration for * current instantiation of the DMX server. */ -void dmxConfigStoreConfig(const char *config) +void +dmxConfigStoreConfig(const char *config) { - if (dmxConfigCmd.config) dmxLog(dmxFatal, "Only one -config allowed\n"); + if (dmxConfigCmd.config) + dmxLog(dmxFatal, "Only one -config allowed\n"); dmxConfigCmd.config = strdup(config); } -static int dmxConfigReadFile(const char *filename, int debug) +static int +dmxConfigReadFile(const char *filename, int debug) { FILE *str; - if (!(str = fopen(filename, "r"))) return -1; + if (!(str = fopen(filename, "r"))) + return -1; dmxLog(dmxInfo, "Reading configuration file \"%s\"\n", filename); - yyin = str; + yyin = str; yydebug = debug; yyparse(); fclose(str); return 0; } -static const char *dmxConfigMatch(const char *target, DMXConfigEntryPtr entry) +static const char * +dmxConfigMatch(const char *target, DMXConfigEntryPtr entry) { - DMXConfigVirtualPtr v = entry->virtual; - const char *name = NULL; - - if (v && v->name) name = v->name; - - if (v && !dmxConfigCmd.config) return v->name ? v->name : "<noname>"; - if (!name) return NULL; - if (!strcmp(name, target)) return name; + DMXConfigVirtualPtr v = entry->virtual; + const char *name = NULL; + + if (v && v->name) + name = v->name; + + if (v && !dmxConfigCmd.config) + return v->name ? v->name : "<noname>"; + if (!name) + return NULL; + if (!strcmp(name, target)) + return name; return NULL; } -static DMXScreenInfo *dmxConfigAddDisplay(const char *name, - int scrnWidth, int scrnHeight, - int scrnX, int scrnY, - int scrnXSign, int scrnYSign, - int rootWidth, int rootHeight, - int rootX, int rootY, - int rootXSign, int rootYSign) +static DMXScreenInfo * +dmxConfigAddDisplay(const char *name, + int scrnWidth, int scrnHeight, + int scrnX, int scrnY, + int scrnXSign, int scrnYSign, + int rootWidth, int rootHeight, + int rootX, int rootY, int rootXSign, int rootYSign) { DMXScreenInfo *dmxScreen; - + if (!(dmxScreens = realloc(dmxScreens, - (dmxNumScreens+1) * sizeof(*dmxScreens)))) + (dmxNumScreens + 1) * sizeof(*dmxScreens)))) dmxLog(dmxFatal, "dmxConfigAddDisplay: realloc failed for screen %d (%s)\n", dmxNumScreens, name); - + dmxScreen = &dmxScreens[dmxNumScreens]; memset(dmxScreen, 0, sizeof(*dmxScreen)); - dmxScreen->name = name; - dmxScreen->index = dmxNumScreens; - dmxScreen->scrnWidth = scrnWidth; + dmxScreen->name = name; + dmxScreen->index = dmxNumScreens; + dmxScreen->scrnWidth = scrnWidth; dmxScreen->scrnHeight = scrnHeight; - dmxScreen->scrnX = scrnX; - dmxScreen->scrnY = scrnY; - dmxScreen->scrnXSign = scrnXSign; - dmxScreen->scrnYSign = scrnYSign; - dmxScreen->rootWidth = rootWidth; + dmxScreen->scrnX = scrnX; + dmxScreen->scrnY = scrnY; + dmxScreen->scrnXSign = scrnXSign; + dmxScreen->scrnYSign = scrnYSign; + dmxScreen->rootWidth = rootWidth; dmxScreen->rootHeight = rootHeight; - dmxScreen->rootX = rootX; - dmxScreen->rootY = rootY; - dmxScreen->stat = dmxStatAlloc(); + dmxScreen->rootX = rootX; + dmxScreen->rootY = rootY; + dmxScreen->stat = dmxStatAlloc(); ++dmxNumScreens; return dmxScreen; } -DMXInputInfo *dmxConfigAddInput(const char *name, int core) +DMXInputInfo * +dmxConfigAddInput(const char *name, int core) { DMXInputInfo *dmxInput; if (!(dmxInputs = realloc(dmxInputs, - (dmxNumInputs+1) * sizeof(*dmxInputs)))) + (dmxNumInputs + 1) * sizeof(*dmxInputs)))) dmxLog(dmxFatal, "dmxConfigAddInput: realloc failed for input %d (%s)\n", dmxNumInputs, name); @@ -221,71 +243,79 @@ DMXInputInfo *dmxConfigAddInput(const char *name, int core) dmxInput = &dmxInputs[dmxNumInputs]; memset(dmxInput, 0, sizeof(*dmxInput)); - dmxInput->name = name; + dmxInput->name = name; dmxInput->inputIdx = dmxNumInputs; - dmxInput->scrnIdx = -1; - dmxInput->core = core; + dmxInput->scrnIdx = -1; + dmxInput->core = core; ++dmxNumInputs; return dmxInput; } -static void dmxConfigCopyFromDisplay(DMXConfigDisplayPtr d) +static void +dmxConfigCopyFromDisplay(DMXConfigDisplayPtr d) { DMXScreenInfo *dmxScreen; - dmxScreen = dmxConfigAddDisplay(d->name, - d->scrnWidth, d->scrnHeight, - d->scrnX, d->scrnY, - d->scrnXSign, d->scrnYSign, - d->rootWidth, d->rootHeight, - d->rootX, d->rootY, - d->rootXSign, d->rootXSign); - dmxScreen->where = PosAbsolute; + dmxScreen = dmxConfigAddDisplay(d->name, + d->scrnWidth, d->scrnHeight, + d->scrnX, d->scrnY, + d->scrnXSign, d->scrnYSign, + d->rootWidth, d->rootHeight, + d->rootX, d->rootY, + d->rootXSign, d->rootXSign); + dmxScreen->where = PosAbsolute; dmxScreen->whereX = d->rootXOrigin; dmxScreen->whereY = d->rootYOrigin; } -static void dmxConfigCopyFromWall(DMXConfigWallPtr w) +static void +dmxConfigCopyFromWall(DMXConfigWallPtr w) { DMXConfigStringPtr pt; - DMXScreenInfo *dmxScreen; - int edge = dmxNumScreens; - int last = dmxNumScreens; + DMXScreenInfo *dmxScreen; + int edge = dmxNumScreens; + int last = dmxNumScreens; - if (!w->xwall && !w->ywall) { /* Try to make it square */ + if (!w->xwall && !w->ywall) { /* Try to make it square */ int count; - for (pt = w->nameList, count = 0; pt; pt = pt->next) ++count; + + for (pt = w->nameList, count = 0; pt; pt = pt->next) + ++count; w->xwall = sqrt(count) + .5; } for (pt = w->nameList; pt; pt = pt->next) { dmxScreen = dmxConfigAddDisplay(pt->string, w->width, w->height, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - if (pt == w->nameList) { /* Upper left */ - dmxScreen->where = PosAbsolute; + if (pt == w->nameList) { /* Upper left */ + dmxScreen->where = PosAbsolute; dmxScreen->whereX = 0; dmxScreen->whereY = 0; - } else if (w->xwall) { /* Tile left to right, then top to bottom */ - if (!((dmxNumScreens-1) % w->xwall)) { - dmxScreen->where = PosBelow; + } + else if (w->xwall) { /* Tile left to right, then top to bottom */ + if (!((dmxNumScreens - 1) % w->xwall)) { + dmxScreen->where = PosBelow; dmxScreen->whereRefScreen = edge; - edge = dmxNumScreens-1; - } else { - dmxScreen->where = PosRightOf; + edge = dmxNumScreens - 1; + } + else { + dmxScreen->where = PosRightOf; dmxScreen->whereRefScreen = last; } - } else { /* Tile top to bottom, then left to right */ - if (!((dmxNumScreens-1) % w->ywall)) { - dmxScreen->where = PosRightOf; + } + else { /* Tile top to bottom, then left to right */ + if (!((dmxNumScreens - 1) % w->ywall)) { + dmxScreen->where = PosRightOf; dmxScreen->whereRefScreen = edge; - edge = dmxNumScreens-1; - } else { - dmxScreen->where = PosBelow; + edge = dmxNumScreens - 1; + } + else { + dmxScreen->where = PosBelow; dmxScreen->whereRefScreen = last; } } - last = dmxNumScreens-1; + last = dmxNumScreens - 1; if (dmxScreen->where == PosAbsolute) dmxLog(dmxInfo, "Added %s at %d %d\n", pt->string, dmxScreen->whereX, dmxScreen->whereY); @@ -297,60 +327,79 @@ static void dmxConfigCopyFromWall(DMXConfigWallPtr w) } } -static void dmxConfigCopyFromOption(DMXConfigOptionPtr o) +static void +dmxConfigCopyFromOption(DMXConfigOptionPtr o) { DMXConfigStringPtr pt; - int argc = 0; - char **argv = NULL; + int argc = 0; + char **argv = NULL; - if (serverGeneration != 1) return; /* FIXME: only do once, for now */ - if (!o || !o->string) return; + if (serverGeneration != 1) + return; /* FIXME: only do once, for now */ + if (!o || !o->string) + return; for (pt = o->option; pt; pt = pt->next) { if (pt->string) { ++argc; - argv = realloc(argv, (argc+1) * sizeof(*argv)); - argv[argc] = (char *)pt->string; + argv = realloc(argv, (argc + 1) * sizeof(*argv)); + argv[argc] = (char *) pt->string; } } argv[0] = NULL; - ProcessCommandLine(argc+1, argv); + ProcessCommandLine(argc + 1, argv); free(argv); } -static void dmxConfigCopyFromParam(DMXConfigParamPtr p) +static void +dmxConfigCopyFromParam(DMXConfigParamPtr p) { const char **argv; - int argc; - + int argc; + if ((argv = dmxConfigLookupParam(p, "xkbrules", &argc)) && argc == 2) { dmxConfigSetXkbRules(argv[1]); - } else if ((argv = dmxConfigLookupParam(p, "xkbmodel", &argc)) - && argc == 2) { + } + else if ((argv = dmxConfigLookupParam(p, "xkbmodel", &argc)) + && argc == 2) { dmxConfigSetXkbModel(argv[1]); - } else if ((argv = dmxConfigLookupParam(p, "xkblayout", &argc)) - && argc == 2) { + } + else if ((argv = dmxConfigLookupParam(p, "xkblayout", &argc)) + && argc == 2) { dmxConfigSetXkbLayout(argv[1]); - } else if ((argv = dmxConfigLookupParam(p, "xkbvariant", &argc)) - && argc == 2) { + } + else if ((argv = dmxConfigLookupParam(p, "xkbvariant", &argc)) + && argc == 2) { dmxConfigSetXkbVariant(argv[1]); - } else if ((argv = dmxConfigLookupParam(p, "xkboptions", &argc)) - && argc == 2) { + } + else if ((argv = dmxConfigLookupParam(p, "xkboptions", &argc)) + && argc == 2) { dmxConfigSetXkbOptions(argv[1]); } } -static void dmxConfigCopyData(DMXConfigVirtualPtr v) +static void +dmxConfigCopyData(DMXConfigVirtualPtr v) { DMXConfigSubPtr sub; - - if (v->dim) dmxSetWidthHeight(v->dim->x, v->dim->y); - else dmxSetWidthHeight(0, 0); + + if (v->dim) + dmxSetWidthHeight(v->dim->x, v->dim->y); + else + dmxSetWidthHeight(0, 0); for (sub = v->subentry; sub; sub = sub->next) { switch (sub->type) { - case dmxConfigDisplay: dmxConfigCopyFromDisplay(sub->display); break; - case dmxConfigWall: dmxConfigCopyFromWall(sub->wall); break; - case dmxConfigOption: dmxConfigCopyFromOption(sub->option); break; - case dmxConfigParam: dmxConfigCopyFromParam(sub->param); break; + case dmxConfigDisplay: + dmxConfigCopyFromDisplay(sub->display); + break; + case dmxConfigWall: + dmxConfigCopyFromWall(sub->wall); + break; + case dmxConfigOption: + dmxConfigCopyFromOption(sub->option); + break; + case dmxConfigParam: + dmxConfigCopyFromParam(sub->param); + break; default: dmxLog(dmxFatal, "dmxConfigCopyData: not a display, wall, or value\n"); @@ -358,25 +407,29 @@ static void dmxConfigCopyData(DMXConfigVirtualPtr v) } } -static void dmxConfigFromCommandLine(void) +static void +dmxConfigFromCommandLine(void) { DMXConfigListPtr pt; - + dmxLog(dmxInfo, "Using configuration from command line\n"); for (pt = dmxConfigCmd.displays; pt; pt = pt->next) { DMXScreenInfo *dmxScreen = dmxConfigAddDisplay(pt->name, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + if (dmxNumScreens == 1) { - dmxScreen->where = PosAbsolute; + dmxScreen->where = PosAbsolute; dmxScreen->whereX = 0; dmxScreen->whereY = 0; dmxLog(dmxInfo, "Added %s at %d %d\n", dmxScreen->name, dmxScreen->whereX, dmxScreen->whereY); - } else { - dmxScreen->where = PosRightOf; + } + else { + dmxScreen->where = PosRightOf; dmxScreen->whereRefScreen = dmxNumScreens - 2; - if (dmxScreen->whereRefScreen < 0) dmxScreen->whereRefScreen = 0; + if (dmxScreen->whereRefScreen < 0) + dmxScreen->whereRefScreen = 0; dmxLog(dmxInfo, "Added %s %s %s\n", dmxScreen->name, dmxScreen->where == PosBelow ? "below" : "right of", @@ -385,14 +438,16 @@ static void dmxConfigFromCommandLine(void) } } -static void dmxConfigFromConfigFile(void) +static void +dmxConfigFromConfigFile(void) { DMXConfigEntryPtr pt; - const char *name; + const char *name; for (pt = dmxConfigEntry; pt; pt = pt->next) { - /* FIXME -- if an input is specified, use it */ - if (pt->type != dmxConfigVirtual) continue; + /* FIXME -- if an input is specified, use it */ + if (pt->type != dmxConfigVirtual) + continue; if ((name = dmxConfigMatch(dmxConfigCmd.config, pt))) { dmxLog(dmxInfo, "Using configuration \"%s\"\n", name); dmxConfigCopyData(pt->virtual); @@ -403,22 +458,26 @@ static void dmxConfigFromConfigFile(void) dmxConfigCmd.config, dmxConfigCmd.filename); } -static void dmxConfigConfigInputs(void) +static void +dmxConfigConfigInputs(void) { DMXConfigListPtr pt; - if (dmxNumInputs) return; - - if (dmxConfigCmd.inputs) { /* Use command line */ + if (dmxNumInputs) + return; + + if (dmxConfigCmd.inputs) { /* Use command line */ for (pt = dmxConfigCmd.inputs; pt; pt = pt->next) dmxConfigAddInput(pt->name, TRUE); - } else if (dmxNumScreens) { /* Use first display */ + } + else if (dmxNumScreens) { /* Use first display */ dmxConfigAddInput(dmxScreens[0].name, TRUE); - } else { /* Use dummy */ + } + else { /* Use dummy */ dmxConfigAddInput("dummy", TRUE); } - if (dmxConfigCmd.xinputs) { /* Non-core devices from command line */ + if (dmxConfigCmd.xinputs) { /* Non-core devices from command line */ for (pt = dmxConfigCmd.xinputs; pt; pt = pt->next) dmxConfigAddInput(pt->name, FALSE); } @@ -427,7 +486,8 @@ static void dmxConfigConfigInputs(void) /** Set up the appropriate global variables so that the DMX server will * be initialized using the configuration specified in the config file * and on the command line. */ -void dmxConfigConfigure(void) +void +dmxConfigConfigure(void) { if (dmxConfigEntry) { dmxConfigFreeEntry(dmxConfigEntry); @@ -440,7 +500,8 @@ void dmxConfigConfigure(void) dmxConfigCmd.filename); dmxConfigReadFile(dmxConfigCmd.filename, 0); dmxConfigFromConfigFile(); - } else { + } + else { if (dmxConfigCmd.config) dmxLog(dmxWarning, "Configuration name (%s) without configuration file\n", @@ -454,11 +515,13 @@ void dmxConfigConfigure(void) * sets MAXSCREENS to that value. This is difficult since the number * depends on the command line (which is easy to count) or on the config * file, which has to be parsed. */ -void dmxConfigSetMaxScreens(void) +void +dmxConfigSetMaxScreens(void) { static int processing = 0; - if (processing) return; /* Prevent reentry via ProcessCommandLine */ + if (processing) + return; /* Prevent reentry via ProcessCommandLine */ processing = 1; if (dmxConfigCmd.filename) { if (!dmxNumScreens) @@ -466,7 +529,8 @@ void dmxConfigSetMaxScreens(void) #ifndef MAXSCREENS SetMaxScreens(dmxNumScreens); #endif - } else + } + else #ifndef MAXSCREENS SetMaxScreens(dmxDisplaysFromCommandLine); #endif @@ -490,8 +554,8 @@ void dmxConfigSetMaxScreens(void) return (char *)(dmx##glob ? dmx##glob : def); \ } -GEN(rules, XkbRules, XKB_DFLT_RULES) -GEN(model, XkbModel, XKB_DFLT_MODEL) -GEN(layout, XkbLayout, XKB_DFLT_LAYOUT) -GEN(variant, XkbVariant, XKB_DFLT_VARIANT) -GEN(options, XkbOptions, XKB_DFLT_OPTIONS) +GEN(rules, XkbRules, XKB_DFLT_RULES) + GEN(model, XkbModel, XKB_DFLT_MODEL) + GEN(layout, XkbLayout, XKB_DFLT_LAYOUT) + GEN(variant, XkbVariant, XKB_DFLT_VARIANT) + GEN(options, XkbOptions, XKB_DFLT_OPTIONS) diff --git a/xorg-server/hw/dmx/config/dmxparse.c b/xorg-server/hw/dmx/config/dmxparse.c index f75151eac..cf510844d 100644 --- a/xorg-server/hw/dmx/config/dmxparse.c +++ b/xorg-server/hw/dmx/config/dmxparse.c @@ -1,607 +1,688 @@ -/*
- * Copyright 2002 Red Hat Inc., Durham, North Carolina.
- *
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation on the rights to use, copy, modify, merge,
- * publish, distribute, sublicense, and/or sell copies of the Software,
- * and to permit persons to whom the Software is furnished to do so,
- * subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial
- * portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-/*
- * Authors:
- * Rickard E. (Rik) Faith <faith@redhat.com>
- *
- */
-
-/** \file
- *
- * This file provides support routines and helper functions to be used
- * by the DMX configuration file parser.
- *
- * Because the DMX configuration file parsing should be capable of being
- * used in a stand-alone fashion (i.e., independent from the DMX server
- * source tree), no dependencies on other DMX routines are made. */
-
-#ifdef HAVE_DMX_CONFIG_H
-#include <dmx-config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include "dmxparse.h"
-
-/** A general error logging routine that does not depend on the dmxLog
- * functions. */
-void dmxConfigLog(const char *format, ...)
-{
- va_list args;
-
- va_start(args, format);
- vprintf(format, args); /* RATS: All calls to dmxConfigLog from
- * dmxparse.c and dmxprint.c use a
- * trusted format. */
- va_end(args);
-}
-
-void *dmxConfigAlloc(unsigned long bytes)
-{
- void *area = calloc(1, bytes);
- if (!area) {
- dmxConfigLog("dmxConfigAlloc: out of memory\n");
- return NULL;
- }
- return area;
-}
-
-void *dmxConfigRealloc(void *orig, unsigned long orig_bytes,
- unsigned long bytes)
-{
- unsigned char *area = realloc(orig, bytes);
- if (!area) {
- dmxConfigLog("dmxConfigRealloc: out of memory\n");
- return NULL;
- }
- memset(area + orig_bytes, 0, bytes - orig_bytes);
- return area;
-}
-
-const char *dmxConfigCopyString(const char *string, int length)
-{
- char *copy;
-
- if (!length) length = strlen(string);
- copy = dmxConfigAlloc(length + 1);
- if (length) strncpy(copy, string, length);
- copy[length] = '\0';
- return copy;
-}
-
-void dmxConfigFree(void *area)
-{
- free(area);
-}
-
-DMXConfigTokenPtr dmxConfigCreateToken(int token, int line,
- const char *comment)
-{
- DMXConfigTokenPtr pToken = dmxConfigAlloc(sizeof(*pToken));
- pToken->token = token;
- pToken->line = line;
- pToken->comment = comment;
- return pToken;
-}
-
-void dmxConfigFreeToken(DMXConfigTokenPtr p)
-{
- if (!p) return;
- dmxConfigFree((void *)p->comment);
- dmxConfigFree(p);
-}
-
-DMXConfigStringPtr dmxConfigCreateString(int token, int line,
- const char *comment,
- const char *string)
-{
- DMXConfigStringPtr pString = dmxConfigAlloc(sizeof(*pString));
-
- pString->token = token;
- pString->line = line;
- pString->comment = comment;
- pString->string = string;
- return pString;
-}
-
-void dmxConfigFreeString(DMXConfigStringPtr p)
-{
- DMXConfigStringPtr next;
-
- if (!p) return;
- do {
- next = p->next;
- dmxConfigFree((void *)p->comment);
- dmxConfigFree((void *)p->string);
- dmxConfigFree(p);
- } while ((p = next));
-}
-
-DMXConfigNumberPtr dmxConfigCreateNumber(int token, int line,
- const char *comment,
- int number)
-{
- DMXConfigNumberPtr pNumber = dmxConfigAlloc(sizeof(*pNumber));
-
- pNumber->token = token;
- pNumber->line = line;
- pNumber->comment = comment;
- pNumber->number = number;
- return pNumber;
-}
-
-void dmxConfigFreeNumber(DMXConfigNumberPtr p)
-{
- if (!p) return;
- dmxConfigFree((void *)p->comment);
- dmxConfigFree(p);
-}
-
-DMXConfigPairPtr dmxConfigCreatePair(int token, int line,
- const char *comment,
- int x, int y,
- int xsign, int ysign)
-{
- DMXConfigPairPtr pPair = dmxConfigAlloc(sizeof(*pPair));
-
- pPair->token = token;
- pPair->line = line;
- pPair->comment = comment;
- pPair->x = x;
- pPair->y = y;
- pPair->xsign = (xsign < 0) ? -1 : 1;
- pPair->ysign = (ysign < 0) ? -1 : 1;
- return pPair;
-}
-
-void dmxConfigFreePair(DMXConfigPairPtr p)
-{
- if (!p) return;
- dmxConfigFree((void *)p->comment);
- dmxConfigFree(p);
-}
-
-DMXConfigCommentPtr dmxConfigCreateComment(int token, int line,
- const char *comment)
-{
- DMXConfigCommentPtr pComment = dmxConfigAlloc(sizeof(*pComment));
-
- pComment->token = token;
- pComment->line = line;
- pComment->comment = comment;
- return pComment;
-}
-
-void dmxConfigFreeComment(DMXConfigCommentPtr p)
-{
- if (!p) return;
- dmxConfigFree((void *)p->comment);
- dmxConfigFree(p);
-}
-
-DMXConfigPartDimPtr dmxConfigCreatePartDim(DMXConfigPairPtr pDim,
- DMXConfigPairPtr pOffset)
-{
- DMXConfigPartDimPtr pPart = dmxConfigAlloc(sizeof(*pPart));
- pPart->dim = pDim;
- pPart->offset = pOffset;
- return pPart;
-}
-
-void dmxConfigFreePartDim(DMXConfigPartDimPtr p)
-{
- if (!p) return;
- dmxConfigFreePair(p->dim);
- dmxConfigFreePair(p->offset);
- dmxConfigFree(p);
-}
-
-DMXConfigFullDimPtr dmxConfigCreateFullDim(DMXConfigPartDimPtr pScrn,
- DMXConfigPartDimPtr pRoot)
-{
- DMXConfigFullDimPtr pFull = dmxConfigAlloc(sizeof(*pFull));
- pFull->scrn = pScrn;
- pFull->root = pRoot;
- return pFull;
-}
-
-void dmxConfigFreeFullDim(DMXConfigFullDimPtr p)
-{
- if (!p) return;
- dmxConfigFreePartDim(p->scrn);
- dmxConfigFreePartDim(p->root);
- dmxConfigFree(p);
-}
-
-DMXConfigDisplayPtr dmxConfigCreateDisplay(DMXConfigTokenPtr pStart,
- DMXConfigStringPtr pName,
- DMXConfigFullDimPtr pDim,
- DMXConfigPairPtr pOrigin,
- DMXConfigTokenPtr pEnd)
-{
- DMXConfigDisplayPtr pDisplay = dmxConfigAlloc(sizeof(*pDisplay));
-
- pDisplay->start = pStart;
- pDisplay->dname = pName;
- pDisplay->dim = pDim;
- pDisplay->origin = pOrigin;
- pDisplay->end = pEnd;
-
- pDisplay->name = pName ? pName->string : NULL;
- pDisplay->rootXOrigin = pOrigin ? pOrigin->x : 0;
- pDisplay->rootYOrigin = pOrigin ? pOrigin->y : 0;
-
- if (pDim && pDim->scrn && pDim->scrn->dim) {
- pDisplay->scrnWidth = pDim->scrn->dim->x;
- pDisplay->scrnHeight = pDim->scrn->dim->y;
- }
- if (pDim && pDim->scrn && pDim->scrn->offset) {
- pDisplay->scrnX = pDim->scrn->offset->x;
- pDisplay->scrnY = pDim->scrn->offset->y;
- pDisplay->scrnXSign = pDim->scrn->offset->xsign;
- pDisplay->scrnYSign = pDim->scrn->offset->ysign;
- }
-
- if (pDim && pDim->root) {
- if (pDim->root->dim) {
- pDisplay->rootWidth = pDim->root->dim->x;
- pDisplay->rootHeight = pDim->root->dim->y;
- }
- if (pDim->root->offset) {
- pDisplay->rootX = pDim->root->offset->x;
- pDisplay->rootY = pDim->root->offset->y;
- pDisplay->rootXSign = pDim->root->offset->xsign;
- pDisplay->rootYSign = pDim->root->offset->ysign;
- }
- } else { /* If no root specification, copy width
- * and height from scrn -- leave offset
- * as zero, since it is relative to
- * scrn. */
- pDisplay->rootWidth = pDisplay->scrnWidth;
- pDisplay->rootHeight = pDisplay->scrnHeight;
- }
-
-
- return pDisplay;
-}
-
-void dmxConfigFreeDisplay(DMXConfigDisplayPtr p)
-{
- if (!p) return;
- dmxConfigFreeToken(p->start);
- dmxConfigFreeString(p->dname);
- dmxConfigFreeFullDim(p->dim);
- dmxConfigFreeToken(p->end);
- dmxConfigFree(p);
-}
-
-DMXConfigWallPtr dmxConfigCreateWall(DMXConfigTokenPtr pStart,
- DMXConfigPairPtr pWallDim,
- DMXConfigPairPtr pDisplayDim,
- DMXConfigStringPtr pNameList,
- DMXConfigTokenPtr pEnd)
-{
- DMXConfigWallPtr pWall = dmxConfigAlloc(sizeof(*pWall));
-
- pWall->start = pStart;
- pWall->wallDim = pWallDim;
- pWall->displayDim = pDisplayDim;
- pWall->nameList = pNameList;
- pWall->end = pEnd;
-
- pWall->width = pDisplayDim ? pDisplayDim->x : 0;
- pWall->height = pDisplayDim ? pDisplayDim->y : 0;
- pWall->xwall = pWallDim ? pWallDim->x : 0;
- pWall->ywall = pWallDim ? pWallDim->y : 0;
-
- return pWall;
-}
-
-void dmxConfigFreeWall(DMXConfigWallPtr p)
-{
- if (!p) return;
- dmxConfigFreeToken(p->start);
- dmxConfigFreePair(p->wallDim);
- dmxConfigFreePair(p->displayDim);
- dmxConfigFreeString(p->nameList);
- dmxConfigFreeToken(p->end);
- dmxConfigFree(p);
-}
-
-DMXConfigOptionPtr dmxConfigCreateOption(DMXConfigTokenPtr pStart,
- DMXConfigStringPtr pOption,
- DMXConfigTokenPtr pEnd)
-{
- int length = 0;
- int offset = 0;
- DMXConfigStringPtr p;
- DMXConfigOptionPtr option = dmxConfigAlloc(sizeof(*option));
-
- for (p = pOption; p; p = p->next) {
- if (p->string) length += strlen(p->string) + 1;
- }
-
- option->string = dmxConfigAlloc(length + 1);
-
- for (p = pOption; p; p = p->next) {
- if (p->string) {
- int len = strlen(p->string);
- strncpy(option->string + offset, p->string, len);
- offset += len;
- if (p->next) option->string[offset++] = ' ';
- }
- }
- option->string[offset] = '\0';
-
- option->start = pStart;
- option->option = pOption;
- option->end = pEnd;
-
- return option;
-}
-
-void dmxConfigFreeOption(DMXConfigOptionPtr p)
-{
- if (!p) return;
- free(p->string);
- dmxConfigFreeToken(p->start);
- dmxConfigFreeString(p->option);
- dmxConfigFreeToken(p->end);
- dmxConfigFree(p);
-}
-
-const char **dmxConfigLookupParam(DMXConfigParamPtr p, const char *key,
- int *argc)
-{
- DMXConfigParamPtr pt;
-
- for (pt = p; pt; pt = pt->next) {
- if (pt->argv && !strcasecmp(pt->argv[0], key)) {
- *argc = pt->argc;
- return pt->argv;
- }
- }
- *argc = 0;
- return NULL;
-}
-
-DMXConfigParamPtr dmxConfigCreateParam(DMXConfigTokenPtr pStart,
- DMXConfigTokenPtr pOpen,
- DMXConfigStringPtr pParam,
- DMXConfigTokenPtr pClose,
- DMXConfigTokenPtr pEnd)
-{
- DMXConfigParamPtr param = dmxConfigAlloc(sizeof(*param));
- DMXConfigStringPtr pt;
-
- param->argc = 0;
- param->argv = NULL;
- for (pt = pParam; pt; pt = pt->next) {
- if (pt->string) {
- param->argv = realloc(param->argv,
- (param->argc+2) * sizeof(*param->argv));
- param->argv[param->argc] = pt->string;
- ++param->argc;
- }
- }
- if (param->argv) param->argv[param->argc] = NULL;
-
- param->start = pStart;
- param->open = pOpen;
- param->param = pParam;
- param->close = pClose;
- param->end = pEnd;
-
- return param;
-}
-
-void dmxConfigFreeParam(DMXConfigParamPtr p)
-{
- DMXConfigParamPtr next;
-
- if (!p) return;
- do {
- next = p->next;
- dmxConfigFreeToken(p->start);
- dmxConfigFreeToken(p->open);
- dmxConfigFreeString(p->param);
- dmxConfigFreeToken(p->close);
- dmxConfigFreeToken(p->end);
- dmxConfigFree(p->argv);
- dmxConfigFree(p);
- } while ((p = next));
-}
-
-DMXConfigSubPtr dmxConfigCreateSub(DMXConfigType type,
- DMXConfigCommentPtr comment,
- DMXConfigDisplayPtr display,
- DMXConfigWallPtr wall,
- DMXConfigOptionPtr option,
- DMXConfigParamPtr param)
-{
- DMXConfigSubPtr pSub = dmxConfigAlloc(sizeof(*pSub));
- pSub->type = type;
- switch (type) {
- case dmxConfigComment: pSub->comment = comment; break;
- case dmxConfigDisplay: pSub->display = display; break;
- case dmxConfigWall: pSub->wall = wall; break;
- case dmxConfigOption: pSub->option = option; break;
- case dmxConfigParam: pSub->param = param; break;
- default: dmxConfigLog("Type %d not supported in subentry\n", type); break;
- }
- return pSub;
-}
-
-void dmxConfigFreeSub(DMXConfigSubPtr sub)
-{
- DMXConfigSubPtr pt;
-
- for (pt = sub; pt; pt = pt->next) {
- switch (pt->type) {
- case dmxConfigComment: dmxConfigFreeComment(pt->comment); break;
- case dmxConfigDisplay: dmxConfigFreeDisplay(pt->display); break;
- case dmxConfigWall: dmxConfigFreeWall(pt->wall); break;
- case dmxConfigOption: dmxConfigFreeOption(pt->option); break;
- case dmxConfigParam: dmxConfigFreeParam(pt->param); break;
- default:
- dmxConfigLog("Type %d not supported in subentry\n", pt->type);
- break;
- }
- }
- dmxConfigFree(sub);
-}
-
-DMXConfigSubPtr dmxConfigSubComment(DMXConfigCommentPtr comment)
-{
- return dmxConfigCreateSub(dmxConfigComment, comment, NULL, NULL, NULL,
- NULL);
-}
-
-DMXConfigSubPtr dmxConfigSubDisplay(DMXConfigDisplayPtr display)
-{
- return dmxConfigCreateSub(dmxConfigDisplay, NULL, display, NULL, NULL,
- NULL);
-}
-
-DMXConfigSubPtr dmxConfigSubWall(DMXConfigWallPtr wall)
-{
- return dmxConfigCreateSub(dmxConfigWall, NULL, NULL, wall, NULL, NULL);
-}
-
-DMXConfigSubPtr dmxConfigSubOption(DMXConfigOptionPtr option)
-{
- return dmxConfigCreateSub(dmxConfigOption, NULL, NULL, NULL, option, NULL);
-}
-
-DMXConfigSubPtr dmxConfigSubParam(DMXConfigParamPtr param)
-{
- return dmxConfigCreateSub(dmxConfigParam, NULL, NULL, NULL, NULL, param);
-}
-
-extern DMXConfigSubPtr dmxConfigAddSub(DMXConfigSubPtr head,
- DMXConfigSubPtr sub)
-{
- DMXConfigSubPtr pt;
-
- if (!head) return sub;
- for (pt = head; pt->next; pt = pt->next);
- pt->next = sub;
- return head;
-}
-
-DMXConfigVirtualPtr dmxConfigCreateVirtual(DMXConfigTokenPtr pStart,
- DMXConfigStringPtr pName,
- DMXConfigPairPtr pDim,
- DMXConfigTokenPtr pOpen,
- DMXConfigSubPtr pSubentry,
- DMXConfigTokenPtr pClose)
-{
- DMXConfigVirtualPtr pVirtual = dmxConfigAlloc(sizeof(*pVirtual));
-
- pVirtual->start = pStart;
- pVirtual->vname = pName;
- pVirtual->dim = pDim;
- pVirtual->open = pOpen;
- pVirtual->subentry = pSubentry;
- pVirtual->close = pClose;
-
- pVirtual->name = pName ? pName->string : NULL;
- pVirtual->width = pDim ? pDim->x : 0;
- pVirtual->height = pDim ? pDim->y : 0;
-
- return pVirtual;
-}
-
-void dmxConfigFreeVirtual(DMXConfigVirtualPtr virtual)
-{
- dmxConfigFreeToken(virtual->start);
- dmxConfigFreeString(virtual->vname);
- dmxConfigFreePair(virtual->dim);
- dmxConfigFreeToken(virtual->open);
- dmxConfigFreeSub(virtual->subentry);
- dmxConfigFreeToken(virtual->close);
- dmxConfigFree(virtual);
-}
-
-DMXConfigEntryPtr dmxConfigCreateEntry(DMXConfigType type,
- DMXConfigCommentPtr comment,
- DMXConfigVirtualPtr virtual)
-{
- DMXConfigEntryPtr pEntry = dmxConfigAlloc(sizeof(*pEntry));
- pEntry->type = type;
- switch (type) {
- case dmxConfigComment: pEntry->comment = comment; break;
- case dmxConfigVirtual: pEntry->virtual = virtual; break;
- default: dmxConfigLog("Type %d not supported in entry\n", type); break;
- }
- return pEntry;
-}
-
-void dmxConfigFreeEntry(DMXConfigEntryPtr entry)
-{
- DMXConfigEntryPtr pt;
-
- for (pt = entry; pt; pt = pt->next) {
- switch (pt->type) {
- case dmxConfigComment: dmxConfigFreeComment(pt->comment); break;
- case dmxConfigVirtual: dmxConfigFreeVirtual(pt->virtual); break;
- default:
- dmxConfigLog("Type %d not supported in entry\n", pt->type);
- break;
- }
- }
- dmxConfigFree(entry);
-}
-
-DMXConfigEntryPtr dmxConfigAddEntry(DMXConfigEntryPtr head,
- DMXConfigType type,
- DMXConfigCommentPtr comment,
- DMXConfigVirtualPtr virtual)
-{
- DMXConfigEntryPtr child = dmxConfigCreateEntry(type, comment, virtual);
- DMXConfigEntryPtr pt;
-
- if (!head) return child;
-
- for (pt = head; pt->next; pt = pt->next);
- pt->next = child;
-
- return head;
-}
-
-DMXConfigEntryPtr dmxConfigEntryComment(DMXConfigCommentPtr comment)
-{
- return dmxConfigCreateEntry(dmxConfigComment, comment, NULL);
-}
-
-DMXConfigEntryPtr dmxConfigEntryVirtual(DMXConfigVirtualPtr virtual)
-{
- return dmxConfigCreateEntry(dmxConfigVirtual, NULL, virtual);
-}
+/* + * Copyright 2002 Red Hat Inc., Durham, North Carolina. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Authors: + * Rickard E. (Rik) Faith <faith@redhat.com> + * + */ + +/** \file + * + * This file provides support routines and helper functions to be used + * by the DMX configuration file parser. + * + * Because the DMX configuration file parsing should be capable of being + * used in a stand-alone fashion (i.e., independent from the DMX server + * source tree), no dependencies on other DMX routines are made. */ + +#ifdef HAVE_DMX_CONFIG_H +#include <dmx-config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> +#include "dmxparse.h" + +/** A general error logging routine that does not depend on the dmxLog + * functions. */ +void +dmxConfigLog(const char *format, ...) +{ + va_list args; + + va_start(args, format); + vprintf(format, args); /* RATS: All calls to dmxConfigLog from + * dmxparse.c and dmxprint.c use a + * trusted format. */ + va_end(args); +} + +void * +dmxConfigAlloc(unsigned long bytes) +{ + void *area = calloc(1, bytes); + + if (!area) { + dmxConfigLog("dmxConfigAlloc: out of memory\n"); + return NULL; + } + return area; +} + +void * +dmxConfigRealloc(void *orig, unsigned long orig_bytes, unsigned long bytes) +{ + unsigned char *area = realloc(orig, bytes); + + if (!area) { + dmxConfigLog("dmxConfigRealloc: out of memory\n"); + return NULL; + } + memset(area + orig_bytes, 0, bytes - orig_bytes); + return area; +} + +const char * +dmxConfigCopyString(const char *string, int length) +{ + char *copy; + + if (!length) + length = strlen(string); + copy = dmxConfigAlloc(length + 1); + if (length) + strncpy(copy, string, length); + copy[length] = '\0'; + return copy; +} + +void +dmxConfigFree(void *area) +{ + free(area); +} + +DMXConfigTokenPtr +dmxConfigCreateToken(int token, int line, const char *comment) +{ + DMXConfigTokenPtr pToken = dmxConfigAlloc(sizeof(*pToken)); + + pToken->token = token; + pToken->line = line; + pToken->comment = comment; + return pToken; +} + +void +dmxConfigFreeToken(DMXConfigTokenPtr p) +{ + if (!p) + return; + dmxConfigFree((void *) p->comment); + dmxConfigFree(p); +} + +DMXConfigStringPtr +dmxConfigCreateString(int token, int line, + const char *comment, const char *string) +{ + DMXConfigStringPtr pString = dmxConfigAlloc(sizeof(*pString)); + + pString->token = token; + pString->line = line; + pString->comment = comment; + pString->string = string; + return pString; +} + +void +dmxConfigFreeString(DMXConfigStringPtr p) +{ + DMXConfigStringPtr next; + + if (!p) + return; + do { + next = p->next; + dmxConfigFree((void *) p->comment); + dmxConfigFree((void *) p->string); + dmxConfigFree(p); + } while ((p = next)); +} + +DMXConfigNumberPtr +dmxConfigCreateNumber(int token, int line, const char *comment, int number) +{ + DMXConfigNumberPtr pNumber = dmxConfigAlloc(sizeof(*pNumber)); + + pNumber->token = token; + pNumber->line = line; + pNumber->comment = comment; + pNumber->number = number; + return pNumber; +} + +void +dmxConfigFreeNumber(DMXConfigNumberPtr p) +{ + if (!p) + return; + dmxConfigFree((void *) p->comment); + dmxConfigFree(p); +} + +DMXConfigPairPtr +dmxConfigCreatePair(int token, int line, + const char *comment, int x, int y, int xsign, int ysign) +{ + DMXConfigPairPtr pPair = dmxConfigAlloc(sizeof(*pPair)); + + pPair->token = token; + pPair->line = line; + pPair->comment = comment; + pPair->x = x; + pPair->y = y; + pPair->xsign = (xsign < 0) ? -1 : 1; + pPair->ysign = (ysign < 0) ? -1 : 1; + return pPair; +} + +void +dmxConfigFreePair(DMXConfigPairPtr p) +{ + if (!p) + return; + dmxConfigFree((void *) p->comment); + dmxConfigFree(p); +} + +DMXConfigCommentPtr +dmxConfigCreateComment(int token, int line, const char *comment) +{ + DMXConfigCommentPtr pComment = dmxConfigAlloc(sizeof(*pComment)); + + pComment->token = token; + pComment->line = line; + pComment->comment = comment; + return pComment; +} + +void +dmxConfigFreeComment(DMXConfigCommentPtr p) +{ + if (!p) + return; + dmxConfigFree((void *) p->comment); + dmxConfigFree(p); +} + +DMXConfigPartDimPtr +dmxConfigCreatePartDim(DMXConfigPairPtr pDim, DMXConfigPairPtr pOffset) +{ + DMXConfigPartDimPtr pPart = dmxConfigAlloc(sizeof(*pPart)); + + pPart->dim = pDim; + pPart->offset = pOffset; + return pPart; +} + +void +dmxConfigFreePartDim(DMXConfigPartDimPtr p) +{ + if (!p) + return; + dmxConfigFreePair(p->dim); + dmxConfigFreePair(p->offset); + dmxConfigFree(p); +} + +DMXConfigFullDimPtr +dmxConfigCreateFullDim(DMXConfigPartDimPtr pScrn, DMXConfigPartDimPtr pRoot) +{ + DMXConfigFullDimPtr pFull = dmxConfigAlloc(sizeof(*pFull)); + + pFull->scrn = pScrn; + pFull->root = pRoot; + return pFull; +} + +void +dmxConfigFreeFullDim(DMXConfigFullDimPtr p) +{ + if (!p) + return; + dmxConfigFreePartDim(p->scrn); + dmxConfigFreePartDim(p->root); + dmxConfigFree(p); +} + +DMXConfigDisplayPtr +dmxConfigCreateDisplay(DMXConfigTokenPtr pStart, + DMXConfigStringPtr pName, + DMXConfigFullDimPtr pDim, + DMXConfigPairPtr pOrigin, DMXConfigTokenPtr pEnd) +{ + DMXConfigDisplayPtr pDisplay = dmxConfigAlloc(sizeof(*pDisplay)); + + pDisplay->start = pStart; + pDisplay->dname = pName; + pDisplay->dim = pDim; + pDisplay->origin = pOrigin; + pDisplay->end = pEnd; + + pDisplay->name = pName ? pName->string : NULL; + pDisplay->rootXOrigin = pOrigin ? pOrigin->x : 0; + pDisplay->rootYOrigin = pOrigin ? pOrigin->y : 0; + + if (pDim && pDim->scrn && pDim->scrn->dim) { + pDisplay->scrnWidth = pDim->scrn->dim->x; + pDisplay->scrnHeight = pDim->scrn->dim->y; + } + if (pDim && pDim->scrn && pDim->scrn->offset) { + pDisplay->scrnX = pDim->scrn->offset->x; + pDisplay->scrnY = pDim->scrn->offset->y; + pDisplay->scrnXSign = pDim->scrn->offset->xsign; + pDisplay->scrnYSign = pDim->scrn->offset->ysign; + } + + if (pDim && pDim->root) { + if (pDim->root->dim) { + pDisplay->rootWidth = pDim->root->dim->x; + pDisplay->rootHeight = pDim->root->dim->y; + } + if (pDim->root->offset) { + pDisplay->rootX = pDim->root->offset->x; + pDisplay->rootY = pDim->root->offset->y; + pDisplay->rootXSign = pDim->root->offset->xsign; + pDisplay->rootYSign = pDim->root->offset->ysign; + } + } + else { /* If no root specification, copy width + * and height from scrn -- leave offset + * as zero, since it is relative to + * scrn. */ + pDisplay->rootWidth = pDisplay->scrnWidth; + pDisplay->rootHeight = pDisplay->scrnHeight; + } + + return pDisplay; +} + +void +dmxConfigFreeDisplay(DMXConfigDisplayPtr p) +{ + if (!p) + return; + dmxConfigFreeToken(p->start); + dmxConfigFreeString(p->dname); + dmxConfigFreeFullDim(p->dim); + dmxConfigFreeToken(p->end); + dmxConfigFree(p); +} + +DMXConfigWallPtr +dmxConfigCreateWall(DMXConfigTokenPtr pStart, + DMXConfigPairPtr pWallDim, + DMXConfigPairPtr pDisplayDim, + DMXConfigStringPtr pNameList, DMXConfigTokenPtr pEnd) +{ + DMXConfigWallPtr pWall = dmxConfigAlloc(sizeof(*pWall)); + + pWall->start = pStart; + pWall->wallDim = pWallDim; + pWall->displayDim = pDisplayDim; + pWall->nameList = pNameList; + pWall->end = pEnd; + + pWall->width = pDisplayDim ? pDisplayDim->x : 0; + pWall->height = pDisplayDim ? pDisplayDim->y : 0; + pWall->xwall = pWallDim ? pWallDim->x : 0; + pWall->ywall = pWallDim ? pWallDim->y : 0; + + return pWall; +} + +void +dmxConfigFreeWall(DMXConfigWallPtr p) +{ + if (!p) + return; + dmxConfigFreeToken(p->start); + dmxConfigFreePair(p->wallDim); + dmxConfigFreePair(p->displayDim); + dmxConfigFreeString(p->nameList); + dmxConfigFreeToken(p->end); + dmxConfigFree(p); +} + +DMXConfigOptionPtr +dmxConfigCreateOption(DMXConfigTokenPtr pStart, + DMXConfigStringPtr pOption, DMXConfigTokenPtr pEnd) +{ + int length = 0; + int offset = 0; + DMXConfigStringPtr p; + DMXConfigOptionPtr option = dmxConfigAlloc(sizeof(*option)); + + for (p = pOption; p; p = p->next) { + if (p->string) + length += strlen(p->string) + 1; + } + + option->string = dmxConfigAlloc(length + 1); + + for (p = pOption; p; p = p->next) { + if (p->string) { + int len = strlen(p->string); + + strncpy(option->string + offset, p->string, len); + offset += len; + if (p->next) + option->string[offset++] = ' '; + } + } + option->string[offset] = '\0'; + + option->start = pStart; + option->option = pOption; + option->end = pEnd; + + return option; +} + +void +dmxConfigFreeOption(DMXConfigOptionPtr p) +{ + if (!p) + return; + free(p->string); + dmxConfigFreeToken(p->start); + dmxConfigFreeString(p->option); + dmxConfigFreeToken(p->end); + dmxConfigFree(p); +} + +const char ** +dmxConfigLookupParam(DMXConfigParamPtr p, const char *key, int *argc) +{ + DMXConfigParamPtr pt; + + for (pt = p; pt; pt = pt->next) { + if (pt->argv && !strcasecmp(pt->argv[0], key)) { + *argc = pt->argc; + return pt->argv; + } + } + *argc = 0; + return NULL; +} + +DMXConfigParamPtr +dmxConfigCreateParam(DMXConfigTokenPtr pStart, + DMXConfigTokenPtr pOpen, + DMXConfigStringPtr pParam, + DMXConfigTokenPtr pClose, DMXConfigTokenPtr pEnd) +{ + DMXConfigParamPtr param = dmxConfigAlloc(sizeof(*param)); + DMXConfigStringPtr pt; + + param->argc = 0; + param->argv = NULL; + for (pt = pParam; pt; pt = pt->next) { + if (pt->string) { + param->argv = realloc(param->argv, + (param->argc + 2) * sizeof(*param->argv)); + param->argv[param->argc] = pt->string; + ++param->argc; + } + } + if (param->argv) + param->argv[param->argc] = NULL; + + param->start = pStart; + param->open = pOpen; + param->param = pParam; + param->close = pClose; + param->end = pEnd; + + return param; +} + +void +dmxConfigFreeParam(DMXConfigParamPtr p) +{ + DMXConfigParamPtr next; + + if (!p) + return; + do { + next = p->next; + dmxConfigFreeToken(p->start); + dmxConfigFreeToken(p->open); + dmxConfigFreeString(p->param); + dmxConfigFreeToken(p->close); + dmxConfigFreeToken(p->end); + dmxConfigFree(p->argv); + dmxConfigFree(p); + } while ((p = next)); +} + +DMXConfigSubPtr +dmxConfigCreateSub(DMXConfigType type, + DMXConfigCommentPtr comment, + DMXConfigDisplayPtr display, + DMXConfigWallPtr wall, + DMXConfigOptionPtr option, DMXConfigParamPtr param) +{ + DMXConfigSubPtr pSub = dmxConfigAlloc(sizeof(*pSub)); + + pSub->type = type; + switch (type) { + case dmxConfigComment: + pSub->comment = comment; + break; + case dmxConfigDisplay: + pSub->display = display; + break; + case dmxConfigWall: + pSub->wall = wall; + break; + case dmxConfigOption: + pSub->option = option; + break; + case dmxConfigParam: + pSub->param = param; + break; + default: + dmxConfigLog("Type %d not supported in subentry\n", type); + break; + } + return pSub; +} + +void +dmxConfigFreeSub(DMXConfigSubPtr sub) +{ + DMXConfigSubPtr pt; + + for (pt = sub; pt; pt = pt->next) { + switch (pt->type) { + case dmxConfigComment: + dmxConfigFreeComment(pt->comment); + break; + case dmxConfigDisplay: + dmxConfigFreeDisplay(pt->display); + break; + case dmxConfigWall: + dmxConfigFreeWall(pt->wall); + break; + case dmxConfigOption: + dmxConfigFreeOption(pt->option); + break; + case dmxConfigParam: + dmxConfigFreeParam(pt->param); + break; + default: + dmxConfigLog("Type %d not supported in subentry\n", pt->type); + break; + } + } + dmxConfigFree(sub); +} + +DMXConfigSubPtr +dmxConfigSubComment(DMXConfigCommentPtr comment) +{ + return dmxConfigCreateSub(dmxConfigComment, comment, NULL, NULL, NULL, + NULL); +} + +DMXConfigSubPtr +dmxConfigSubDisplay(DMXConfigDisplayPtr display) +{ + return dmxConfigCreateSub(dmxConfigDisplay, NULL, display, NULL, NULL, + NULL); +} + +DMXConfigSubPtr +dmxConfigSubWall(DMXConfigWallPtr wall) +{ + return dmxConfigCreateSub(dmxConfigWall, NULL, NULL, wall, NULL, NULL); +} + +DMXConfigSubPtr +dmxConfigSubOption(DMXConfigOptionPtr option) +{ + return dmxConfigCreateSub(dmxConfigOption, NULL, NULL, NULL, option, NULL); +} + +DMXConfigSubPtr +dmxConfigSubParam(DMXConfigParamPtr param) +{ + return dmxConfigCreateSub(dmxConfigParam, NULL, NULL, NULL, NULL, param); +} + +extern DMXConfigSubPtr +dmxConfigAddSub(DMXConfigSubPtr head, DMXConfigSubPtr sub) +{ + DMXConfigSubPtr pt; + + if (!head) + return sub; + for (pt = head; pt->next; pt = pt->next); + pt->next = sub; + return head; +} + +DMXConfigVirtualPtr +dmxConfigCreateVirtual(DMXConfigTokenPtr pStart, + DMXConfigStringPtr pName, + DMXConfigPairPtr pDim, + DMXConfigTokenPtr pOpen, + DMXConfigSubPtr pSubentry, DMXConfigTokenPtr pClose) +{ + DMXConfigVirtualPtr pVirtual = dmxConfigAlloc(sizeof(*pVirtual)); + + pVirtual->start = pStart; + pVirtual->vname = pName; + pVirtual->dim = pDim; + pVirtual->open = pOpen; + pVirtual->subentry = pSubentry; + pVirtual->close = pClose; + + pVirtual->name = pName ? pName->string : NULL; + pVirtual->width = pDim ? pDim->x : 0; + pVirtual->height = pDim ? pDim->y : 0; + + return pVirtual; +} + +void +dmxConfigFreeVirtual(DMXConfigVirtualPtr virtual) +{ + dmxConfigFreeToken(virtual->start); + dmxConfigFreeString(virtual->vname); + dmxConfigFreePair(virtual->dim); + dmxConfigFreeToken(virtual->open); + dmxConfigFreeSub(virtual->subentry); + dmxConfigFreeToken(virtual->close); + dmxConfigFree(virtual); +} + +DMXConfigEntryPtr +dmxConfigCreateEntry(DMXConfigType type, + DMXConfigCommentPtr comment, DMXConfigVirtualPtr virtual) +{ + DMXConfigEntryPtr pEntry = dmxConfigAlloc(sizeof(*pEntry)); + + pEntry->type = type; + switch (type) { + case dmxConfigComment: + pEntry->comment = comment; + break; + case dmxConfigVirtual: + pEntry->virtual = virtual; + break; + default: + dmxConfigLog("Type %d not supported in entry\n", type); + break; + } + return pEntry; +} + +void +dmxConfigFreeEntry(DMXConfigEntryPtr entry) +{ + DMXConfigEntryPtr pt; + + for (pt = entry; pt; pt = pt->next) { + switch (pt->type) { + case dmxConfigComment: + dmxConfigFreeComment(pt->comment); + break; + case dmxConfigVirtual: + dmxConfigFreeVirtual(pt->virtual); + break; + default: + dmxConfigLog("Type %d not supported in entry\n", pt->type); + break; + } + } + dmxConfigFree(entry); +} + +DMXConfigEntryPtr +dmxConfigAddEntry(DMXConfigEntryPtr head, + DMXConfigType type, + DMXConfigCommentPtr comment, DMXConfigVirtualPtr virtual) +{ + DMXConfigEntryPtr child = dmxConfigCreateEntry(type, comment, virtual); + DMXConfigEntryPtr pt; + + if (!head) + return child; + + for (pt = head; pt->next; pt = pt->next); + pt->next = child; + + return head; +} + +DMXConfigEntryPtr +dmxConfigEntryComment(DMXConfigCommentPtr comment) +{ + return dmxConfigCreateEntry(dmxConfigComment, comment, NULL); +} + +DMXConfigEntryPtr +dmxConfigEntryVirtual(DMXConfigVirtualPtr virtual) +{ + return dmxConfigCreateEntry(dmxConfigVirtual, NULL, virtual); +} diff --git a/xorg-server/hw/dmx/config/dmxparse.h b/xorg-server/hw/dmx/config/dmxparse.h index de81d23b7..7d31b6309 100644 --- a/xorg-server/hw/dmx/config/dmxparse.h +++ b/xorg-server/hw/dmx/config/dmxparse.h @@ -41,44 +41,44 @@ /** Stores tokens not stored in other structures (e.g., keywords and ;) */ typedef struct _DMXConfigToken { - int token; - int line; - const char *comment; + int token; + int line; + const char *comment; } DMXConfigToken, *DMXConfigTokenPtr; /** Stores parsed strings. */ typedef struct _DMXConfigString { - int token; - int line; - const char *comment; - const char *string; - struct _DMXConfigString *next; + int token; + int line; + const char *comment; + const char *string; + struct _DMXConfigString *next; } DMXConfigString, *DMXConfigStringPtr; /** Stores parsed numbers. */ typedef struct _DMXConfigNumber { - int token; - int line; - const char *comment; - int number; + int token; + int line; + const char *comment; + int number; } DMXConfigNumber, *DMXConfigNumberPtr; /** Stores parsed pairs (e.g., x y) */ typedef struct _DMXConfigPair { - int token; - int line; - const char *comment; - int x; - int y; - int xsign; - int ysign; + int token; + int line; + const char *comment; + int x; + int y; + int xsign; + int ysign; } DMXConfigPair, *DMXConfigPairPtr; /** Stores parsed comments not stored with a token. */ typedef struct _DMXConfigComment { - int token; - int line; - const char *comment; + int token; + int line; + const char *comment; } DMXConfigComment, *DMXConfigCommentPtr; typedef enum { @@ -92,206 +92,201 @@ typedef enum { /** Stores a geometry specification. */ typedef struct _DMXConfigPartDim { - DMXConfigPairPtr dim; - DMXConfigPairPtr offset; + DMXConfigPairPtr dim; + DMXConfigPairPtr offset; } DMXConfigPartDim, *DMXConfigPartDimPtr; /** Stores a pair of geometry specifications. */ typedef struct _DMXConfigFullDim { - DMXConfigPartDimPtr scrn; - DMXConfigPartDimPtr root; + DMXConfigPartDimPtr scrn; + DMXConfigPartDimPtr root; } DMXConfigFullDim, *DMXConfigFullDimPtr; /** Stores parsed display information. */ typedef struct _DMXConfigDisplay { - /* Summary information */ - const char *name; - /* Screen Window Geometry */ - int scrnWidth, scrnHeight; - int scrnX, scrnY; - int scrnXSign, scrnYSign; - /* Root Window Geometry */ - int rootWidth, rootHeight; - int rootX, rootY; - int rootXSign, rootYSign; - /* Origin in global space */ - int rootXOrigin, rootYOrigin; - - /* Raw configuration information */ - DMXConfigTokenPtr start; - DMXConfigStringPtr dname; - DMXConfigFullDimPtr dim; - DMXConfigPairPtr origin; - DMXConfigTokenPtr end; + /* Summary information */ + const char *name; + /* Screen Window Geometry */ + int scrnWidth, scrnHeight; + int scrnX, scrnY; + int scrnXSign, scrnYSign; + /* Root Window Geometry */ + int rootWidth, rootHeight; + int rootX, rootY; + int rootXSign, rootYSign; + /* Origin in global space */ + int rootXOrigin, rootYOrigin; + + /* Raw configuration information */ + DMXConfigTokenPtr start; + DMXConfigStringPtr dname; + DMXConfigFullDimPtr dim; + DMXConfigPairPtr origin; + DMXConfigTokenPtr end; } DMXConfigDisplay, *DMXConfigDisplayPtr; /** Stores parsed wall information. */ typedef struct _DMXConfigWall { - /* Summary information */ - int width, height; /* dimensions of displays */ - int xwall, ywall; /* dimensions of wall, in tiles */ + /* Summary information */ + int width, height; /* dimensions of displays */ + int xwall, ywall; /* dimensions of wall, in tiles */ - - /* Raw configuration informaiton */ - DMXConfigTokenPtr start; - DMXConfigPairPtr wallDim; - DMXConfigPairPtr displayDim; - DMXConfigStringPtr nameList; - DMXConfigTokenPtr end; + /* Raw configuration informaiton */ + DMXConfigTokenPtr start; + DMXConfigPairPtr wallDim; + DMXConfigPairPtr displayDim; + DMXConfigStringPtr nameList; + DMXConfigTokenPtr end; } DMXConfigWall, *DMXConfigWallPtr; /** Stores parsed option information. */ typedef struct _DMXConfigOption { - /* Summary information */ - char *string; - - /* Raw configuration informaiton */ - DMXConfigTokenPtr start; - DMXConfigStringPtr option; - DMXConfigTokenPtr end; + /* Summary information */ + char *string; + + /* Raw configuration informaiton */ + DMXConfigTokenPtr start; + DMXConfigStringPtr option; + DMXConfigTokenPtr end; } DMXConfigOption, *DMXConfigOptionPtr; /** Stores parsed param information. */ typedef struct _DMXConfigParam { - int argc; - const char **argv; - - DMXConfigTokenPtr start; - DMXConfigTokenPtr open; - DMXConfigStringPtr param; - DMXConfigTokenPtr close; - DMXConfigTokenPtr end; /* Either open/close OR end */ - struct _DMXConfigParam *next; + int argc; + const char **argv; + + DMXConfigTokenPtr start; + DMXConfigTokenPtr open; + DMXConfigStringPtr param; + DMXConfigTokenPtr close; + DMXConfigTokenPtr end; /* Either open/close OR end */ + struct _DMXConfigParam *next; } DMXConfigParam, *DMXConfigParamPtr; /** Stores options under an entry (subentry). */ typedef struct _DMXConfigSub { - DMXConfigType type; - DMXConfigCommentPtr comment; - DMXConfigDisplayPtr display; - DMXConfigWallPtr wall; - DMXConfigOptionPtr option; - DMXConfigParamPtr param; - struct _DMXConfigSub *next; + DMXConfigType type; + DMXConfigCommentPtr comment; + DMXConfigDisplayPtr display; + DMXConfigWallPtr wall; + DMXConfigOptionPtr option; + DMXConfigParamPtr param; + struct _DMXConfigSub *next; } DMXConfigSub, *DMXConfigSubPtr; /** Stores parsed virtual information. */ typedef struct _DMXConfigVirtual { - /* Summary information */ - const char *name; - int width, height; + /* Summary information */ + const char *name; + int width, height; - /* Raw configuration information */ - DMXConfigTokenPtr start; - DMXConfigStringPtr vname; - DMXConfigPairPtr dim; - DMXConfigTokenPtr open; - DMXConfigSubPtr subentry; - DMXConfigTokenPtr close; + /* Raw configuration information */ + DMXConfigTokenPtr start; + DMXConfigStringPtr vname; + DMXConfigPairPtr dim; + DMXConfigTokenPtr open; + DMXConfigSubPtr subentry; + DMXConfigTokenPtr close; } DMXConfigVirtual, *DMXConfigVirtualPtr; /** Heads entry storage. */ typedef struct _DMXConfigEntry { - DMXConfigType type; - DMXConfigCommentPtr comment; - DMXConfigVirtualPtr virtual; - struct _DMXConfigEntry *next; + DMXConfigType type; + DMXConfigCommentPtr comment; + DMXConfigVirtualPtr virtual; + struct _DMXConfigEntry *next; } DMXConfigEntry, *DMXConfigEntryPtr; -extern DMXConfigEntryPtr dmxConfigEntry; +extern DMXConfigEntryPtr dmxConfigEntry; -extern int yylex(void); -extern int yydebug; -extern void yyerror(const char *message); +extern int yylex(void); +extern int yydebug; +extern void yyerror(const char *message); -extern void dmxConfigLog(const char *format, ...); -extern void *dmxConfigAlloc(unsigned long bytes); -extern void *dmxConfigRealloc(void *orig, - unsigned long orig_bytes, - unsigned long bytes); -extern const char *dmxConfigCopyString(const char *string, - int length); -extern void dmxConfigFree(void *area); -extern DMXConfigTokenPtr dmxConfigCreateToken(int token, int line, - const char *comment); -extern void dmxConfigFreeToken(DMXConfigTokenPtr p); -extern DMXConfigStringPtr dmxConfigCreateString(int token, int line, - const char *comment, - const char *string); -extern void dmxConfigFreeString(DMXConfigStringPtr p); -extern DMXConfigNumberPtr dmxConfigCreateNumber(int token, int line, - const char *comment, - int number); -extern void dmxConfigFreeNumber(DMXConfigNumberPtr p); -extern DMXConfigPairPtr dmxConfigCreatePair(int token, int line, - const char *comment, - int x, int y, - int xsign, int ysign); -extern void dmxConfigFreePair(DMXConfigPairPtr p); +extern void dmxConfigLog(const char *format, ...); +extern void *dmxConfigAlloc(unsigned long bytes); +extern void *dmxConfigRealloc(void *orig, + unsigned long orig_bytes, unsigned long bytes); +extern const char *dmxConfigCopyString(const char *string, int length); +extern void dmxConfigFree(void *area); +extern DMXConfigTokenPtr dmxConfigCreateToken(int token, int line, + const char *comment); +extern void dmxConfigFreeToken(DMXConfigTokenPtr p); +extern DMXConfigStringPtr dmxConfigCreateString(int token, int line, + const char *comment, + const char *string); +extern void dmxConfigFreeString(DMXConfigStringPtr p); +extern DMXConfigNumberPtr dmxConfigCreateNumber(int token, int line, + const char *comment, + int number); +extern void dmxConfigFreeNumber(DMXConfigNumberPtr p); +extern DMXConfigPairPtr dmxConfigCreatePair(int token, int line, + const char *comment, + int x, int y, int xsign, int ysign); +extern void dmxConfigFreePair(DMXConfigPairPtr p); extern DMXConfigCommentPtr dmxConfigCreateComment(int token, int line, const char *comment); -extern void dmxConfigFreeComment(DMXConfigCommentPtr p); +extern void dmxConfigFreeComment(DMXConfigCommentPtr p); extern DMXConfigPartDimPtr dmxConfigCreatePartDim(DMXConfigPairPtr pDim, DMXConfigPairPtr pOffset); -extern void dmxConfigFreePartDim(DMXConfigPartDimPtr p); +extern void dmxConfigFreePartDim(DMXConfigPartDimPtr p); extern DMXConfigFullDimPtr dmxConfigCreateFullDim(DMXConfigPartDimPtr pScrn, DMXConfigPartDimPtr pRoot); -extern void dmxConfigFreeFullDim(DMXConfigFullDimPtr p); +extern void dmxConfigFreeFullDim(DMXConfigFullDimPtr p); extern DMXConfigDisplayPtr dmxConfigCreateDisplay(DMXConfigTokenPtr pStart, DMXConfigStringPtr pName, DMXConfigFullDimPtr pDim, DMXConfigPairPtr pOrigin, DMXConfigTokenPtr pEnd); -extern void dmxConfigFreeDisplay(DMXConfigDisplayPtr p); -extern DMXConfigWallPtr dmxConfigCreateWall(DMXConfigTokenPtr pStart, - DMXConfigPairPtr pWallDim, - DMXConfigPairPtr pDisplayDim, - DMXConfigStringPtr pNameList, - DMXConfigTokenPtr pEnd); -extern void dmxConfigFreeWall(DMXConfigWallPtr p); -extern DMXConfigOptionPtr dmxConfigCreateOption(DMXConfigTokenPtr pStart, - DMXConfigStringPtr pOption, - DMXConfigTokenPtr pEnd); -extern void dmxConfigFreeOption(DMXConfigOptionPtr p); -extern DMXConfigParamPtr dmxConfigCreateParam(DMXConfigTokenPtr pStart, - DMXConfigTokenPtr pOpen, - DMXConfigStringPtr pParam, - DMXConfigTokenPtr pClose, +extern void dmxConfigFreeDisplay(DMXConfigDisplayPtr p); +extern DMXConfigWallPtr dmxConfigCreateWall(DMXConfigTokenPtr pStart, + DMXConfigPairPtr pWallDim, + DMXConfigPairPtr pDisplayDim, + DMXConfigStringPtr pNameList, + DMXConfigTokenPtr pEnd); +extern void dmxConfigFreeWall(DMXConfigWallPtr p); +extern DMXConfigOptionPtr dmxConfigCreateOption(DMXConfigTokenPtr pStart, + DMXConfigStringPtr pOption, DMXConfigTokenPtr pEnd); -extern void dmxConfigFreeParam(DMXConfigParamPtr p); -extern const char **dmxConfigLookupParam(DMXConfigParamPtr p, - const char *key, - int *argc); -extern DMXConfigSubPtr dmxConfigCreateSub(DMXConfigType type, - DMXConfigCommentPtr comment, - DMXConfigDisplayPtr display, - DMXConfigWallPtr wall, - DMXConfigOptionPtr option, - DMXConfigParamPtr param); -extern void dmxConfigFreeSub(DMXConfigSubPtr sub); -extern DMXConfigSubPtr dmxConfigSubComment(DMXConfigCommentPtr comment); -extern DMXConfigSubPtr dmxConfigSubDisplay(DMXConfigDisplayPtr display); -extern DMXConfigSubPtr dmxConfigSubWall(DMXConfigWallPtr wall); -extern DMXConfigSubPtr dmxConfigSubOption(DMXConfigOptionPtr option); -extern DMXConfigSubPtr dmxConfigSubParam(DMXConfigParamPtr param); -extern DMXConfigSubPtr dmxConfigAddSub(DMXConfigSubPtr head, - DMXConfigSubPtr sub); +extern void dmxConfigFreeOption(DMXConfigOptionPtr p); +extern DMXConfigParamPtr dmxConfigCreateParam(DMXConfigTokenPtr pStart, + DMXConfigTokenPtr pOpen, + DMXConfigStringPtr pParam, + DMXConfigTokenPtr pClose, + DMXConfigTokenPtr pEnd); +extern void dmxConfigFreeParam(DMXConfigParamPtr p); +extern const char **dmxConfigLookupParam(DMXConfigParamPtr p, + const char *key, int *argc); +extern DMXConfigSubPtr dmxConfigCreateSub(DMXConfigType type, + DMXConfigCommentPtr comment, + DMXConfigDisplayPtr display, + DMXConfigWallPtr wall, + DMXConfigOptionPtr option, + DMXConfigParamPtr param); +extern void dmxConfigFreeSub(DMXConfigSubPtr sub); +extern DMXConfigSubPtr dmxConfigSubComment(DMXConfigCommentPtr comment); +extern DMXConfigSubPtr dmxConfigSubDisplay(DMXConfigDisplayPtr display); +extern DMXConfigSubPtr dmxConfigSubWall(DMXConfigWallPtr wall); +extern DMXConfigSubPtr dmxConfigSubOption(DMXConfigOptionPtr option); +extern DMXConfigSubPtr dmxConfigSubParam(DMXConfigParamPtr param); +extern DMXConfigSubPtr dmxConfigAddSub(DMXConfigSubPtr head, + DMXConfigSubPtr sub); extern DMXConfigVirtualPtr dmxConfigCreateVirtual(DMXConfigTokenPtr pStart, DMXConfigStringPtr pName, DMXConfigPairPtr pDim, DMXConfigTokenPtr pOpen, DMXConfigSubPtr pSubentry, DMXConfigTokenPtr pClose); -extern void dmxConfigFreeVirtual(DMXConfigVirtualPtr virtual); -extern DMXConfigEntryPtr dmxConfigCreateEntry(DMXConfigType type, - DMXConfigCommentPtr comment, - DMXConfigVirtualPtr virtual); -extern void dmxConfigFreeEntry(DMXConfigEntryPtr entry); -extern DMXConfigEntryPtr dmxConfigAddEntry(DMXConfigEntryPtr head, - DMXConfigType type, - DMXConfigCommentPtr comment, - DMXConfigVirtualPtr virtual); -extern DMXConfigEntryPtr dmxConfigEntryComment(DMXConfigCommentPtr comment); -extern DMXConfigEntryPtr dmxConfigEntryVirtual(DMXConfigVirtualPtr virtual); +extern void dmxConfigFreeVirtual(DMXConfigVirtualPtr virtual); +extern DMXConfigEntryPtr dmxConfigCreateEntry(DMXConfigType type, + DMXConfigCommentPtr comment, + DMXConfigVirtualPtr virtual); +extern void dmxConfigFreeEntry(DMXConfigEntryPtr entry); +extern DMXConfigEntryPtr dmxConfigAddEntry(DMXConfigEntryPtr head, + DMXConfigType type, + DMXConfigCommentPtr comment, + DMXConfigVirtualPtr virtual); +extern DMXConfigEntryPtr dmxConfigEntryComment(DMXConfigCommentPtr comment); +extern DMXConfigEntryPtr dmxConfigEntryVirtual(DMXConfigVirtualPtr virtual); #endif diff --git a/xorg-server/hw/dmx/config/dmxprint.c b/xorg-server/hw/dmx/config/dmxprint.c index 599ebf5df..3145fb56a 100644 --- a/xorg-server/hw/dmx/config/dmxprint.c +++ b/xorg-server/hw/dmx/config/dmxprint.c @@ -52,100 +52,126 @@ #include <stdarg.h> #include <ctype.h> -static FILE *str = NULL; -static int indent = 0; -static int pos = 0; +static FILE *str = NULL; +static int indent = 0; +static int pos = 0; /** Stack of indentation information used for pretty-printing * configuration information. */ static struct stack { - int base; - int comment; - int step; + int base; + int comment; + int step; struct stack *next; -} *stack, initialStack = { 0, 0, 4, NULL }; +} *stack, initialStack = { +0, 0, 4, NULL}; -static void dmxConfigIndent(void) +static void +dmxConfigIndent(void) { int i; - if (indent < 0) indent = 0; - if (indent > 40) indent = 40; - for (i = 0; i < indent; i++) fprintf(str, " "); + + if (indent < 0) + indent = 0; + if (indent > 40) + indent = 40; + for (i = 0; i < indent; i++) + fprintf(str, " "); } -static void dmxConfigNewline(void) +static void +dmxConfigNewline(void) { - if (pos) fprintf(str, "\n"); + if (pos) + fprintf(str, "\n"); pos = 0; } -static void dmxConfigPushState(int base, int comment, int step) +static void +dmxConfigPushState(int base, int comment, int step) { struct stack *new = dmxConfigAlloc(sizeof(*new)); - new->base = base; + + new->base = base; new->comment = comment; - new->step = step; - new->next = stack; - stack = new; - indent = base; + new->step = step; + new->next = stack; + stack = new; + indent = base; dmxConfigNewline(); } -static void dmxConfigPushComment(void) +static void +dmxConfigPushComment(void) { - if (stack) indent = stack->comment; + if (stack) + indent = stack->comment; } -static void dmxConfigPushStep(void) +static void +dmxConfigPushStep(void) { - if (stack) indent = stack->step; + if (stack) + indent = stack->step; } -static void dmxConfigPopState(void) +static void +dmxConfigPopState(void) { struct stack *old = stack; - if (!stack) return; + if (!stack) + return; indent = old->base; - stack = old->next; - if (!stack) dmxConfigLog("Stack underflow\n"); + stack = old->next; + if (!stack) + dmxConfigLog("Stack underflow\n"); dmxConfigFree(old); dmxConfigNewline(); } -static void dmxConfigOutput(int addSpace, int doNewline, const char *comment, - const char *format, ...) +static void +dmxConfigOutput(int addSpace, int doNewline, const char *comment, + const char *format, ...) { va_list args; - if (!pos) dmxConfigIndent(); - else if (addSpace) fprintf(str, " "); + if (!pos) + dmxConfigIndent(); + else if (addSpace) + fprintf(str, " "); if (format) { va_start(args, format); - /* RATS: This hasn't been audited -- it - * could probably result in a buffer - * overflow. */ - pos += vfprintf(str, format, args); /* assumes no newlines! */ + /* RATS: This hasn't been audited -- it + * could probably result in a buffer + * overflow. */ + pos += vfprintf(str, format, args); /* assumes no newlines! */ va_end(args); } if (comment) { - if (pos) fprintf(str, " "); + if (pos) + fprintf(str, " "); pos += fprintf(str, "#%s", comment); dmxConfigNewline(); dmxConfigPushComment(); - } else if (doNewline) dmxConfigNewline(); + } + else if (doNewline) + dmxConfigNewline(); } -static void dmxConfigPrintComment(DMXConfigCommentPtr p) +static void +dmxConfigPrintComment(DMXConfigCommentPtr p) { dmxConfigOutput(1, 1, p->comment, NULL); } -static void dmxConfigPrintTokenFlag(DMXConfigTokenPtr p, int flag) +static void +dmxConfigPrintTokenFlag(DMXConfigTokenPtr p, int flag) { - if (!p) return; + if (!p) + return; switch (p->token) { case T_VIRTUAL: dmxConfigPushState(0, 4, 4); @@ -169,14 +195,16 @@ static void dmxConfigPrintTokenFlag(DMXConfigTokenPtr p, int flag) break; case ';': dmxConfigOutput(0, 1, p->comment, ";"); - if (flag) dmxConfigPopState(); + if (flag) + dmxConfigPopState(); break; case '{': dmxConfigOutput(1, 1, p->comment, "{"); dmxConfigPushStep(); break; case '}': - if (flag) dmxConfigPopState(); + if (flag) + dmxConfigPopState(); dmxConfigOutput(0, 1, p->comment, "}"); break; case '/': @@ -187,49 +215,66 @@ static void dmxConfigPrintTokenFlag(DMXConfigTokenPtr p, int flag) } } -static void dmxConfigPrintToken(DMXConfigTokenPtr p) +static void +dmxConfigPrintToken(DMXConfigTokenPtr p) { dmxConfigPrintTokenFlag(p, 1); } -static void dmxConfigPrintTokenNopop(DMXConfigTokenPtr p) +static void +dmxConfigPrintTokenNopop(DMXConfigTokenPtr p) { dmxConfigPrintTokenFlag(p, 0); } -static int dmxConfigPrintQuotedString(const char *s) +static int +dmxConfigPrintQuotedString(const char *s) { const char *pt; - if (!s || !s[0]) return 1; /* Quote empty string */ - for (pt = s; *pt; ++pt) if (isspace(*pt)) return 1; + if (!s || !s[0]) + return 1; /* Quote empty string */ + for (pt = s; *pt; ++pt) + if (isspace(*pt)) + return 1; return 0; } -static void dmxConfigPrintString(DMXConfigStringPtr p, int quote) +static void +dmxConfigPrintString(DMXConfigStringPtr p, int quote) { DMXConfigStringPtr pt; - - if (!p) return; + + if (!p) + return; for (pt = p; pt; pt = pt->next) { if (quote && dmxConfigPrintQuotedString(pt->string)) { dmxConfigOutput(1, 0, pt->comment, "\"%s\"", pt->string ? pt->string : ""); - } else + } + else dmxConfigOutput(1, 0, pt->comment, "%s", pt->string ? pt->string : ""); } } -static int dmxConfigPrintPair(DMXConfigPairPtr p, int addSpace) +static int +dmxConfigPrintPair(DMXConfigPairPtr p, int addSpace) { const char *format = NULL; - - if (!p) return 0; + + if (!p) + return 0; switch (p->token) { - case T_ORIGIN: format = "@%dx%d"; break; - case T_DIMENSION: format = "%dx%d"; break; - case T_OFFSET: format = "%c%d%c%d"; break; + case T_ORIGIN: + format = "@%dx%d"; + break; + case T_DIMENSION: + format = "%dx%d"; + break; + case T_OFFSET: + format = "%c%d%c%d"; + break; } if (p->token == T_OFFSET) { if (!p->comment && !p->x && !p->y && p->xsign >= 0 && p->ysign >= 0) @@ -237,69 +282,79 @@ static int dmxConfigPrintPair(DMXConfigPairPtr p, int addSpace) dmxConfigOutput(addSpace, 0, p->comment, format, p->xsign < 0 ? '-' : '+', p->x, p->ysign < 0 ? '-' : '+', p->y); - } else { - if (!p->comment && !p->x && !p->y) return 0; + } + else { + if (!p->comment && !p->x && !p->y) + return 0; dmxConfigOutput(addSpace, 0, p->comment, format, p->x, p->y); } return 1; } -static void dmxConfigPrintDisplay(DMXConfigDisplayPtr p) +static void +dmxConfigPrintDisplay(DMXConfigDisplayPtr p) { - DMXConfigToken dummyStart = { T_DISPLAY, 0, NULL }; - DMXConfigToken dummyEnd = { ';', 0, NULL }; - DMXConfigToken dummySep = { '/', 0, NULL }; - DMXConfigString dummyName = { T_STRING, 0, NULL, NULL, NULL }; - DMXConfigPair dummySDim = { T_DIMENSION, 0, NULL, 0, 0, 0, 0 }; - DMXConfigPair dummySOffset = { T_OFFSET, 0, NULL, 0, 0, 0, 0 }; - DMXConfigPair dummyRDim = { T_DIMENSION, 0, NULL, 0, 0, 0, 0 }; - DMXConfigPair dummyROffset = { T_OFFSET, 0, NULL, 0, 0, 0, 0 }; - DMXConfigPair dummyOrigin = { T_ORIGIN, 0, NULL, 0, 0, 0, 0 }; - int output; - - if (p->dname) p->dname->string = p->name; - else dummyName.string = p->name; - + DMXConfigToken dummyStart = { T_DISPLAY, 0, NULL }; + DMXConfigToken dummyEnd = { ';', 0, NULL }; + DMXConfigToken dummySep = { '/', 0, NULL }; + DMXConfigString dummyName = { T_STRING, 0, NULL, NULL, NULL }; + DMXConfigPair dummySDim = { T_DIMENSION, 0, NULL, 0, 0, 0, 0 }; + DMXConfigPair dummySOffset = { T_OFFSET, 0, NULL, 0, 0, 0, 0 }; + DMXConfigPair dummyRDim = { T_DIMENSION, 0, NULL, 0, 0, 0, 0 }; + DMXConfigPair dummyROffset = { T_OFFSET, 0, NULL, 0, 0, 0, 0 }; + DMXConfigPair dummyOrigin = { T_ORIGIN, 0, NULL, 0, 0, 0, 0 }; + int output; + + if (p->dname) + p->dname->string = p->name; + else + dummyName.string = p->name; + if (p->dim && p->dim->scrn && p->dim->scrn->dim) { - p->dim->scrn->dim->x = p->scrnWidth; - p->dim->scrn->dim->y = p->scrnHeight; - } else { - dummySDim.x = p->scrnWidth; - dummySDim.y = p->scrnHeight; + p->dim->scrn->dim->x = p->scrnWidth; + p->dim->scrn->dim->y = p->scrnHeight; + } + else { + dummySDim.x = p->scrnWidth; + dummySDim.y = p->scrnHeight; } if (p->dim && p->dim->scrn && p->dim->scrn->offset) { p->dim->scrn->offset->x = p->scrnX; p->dim->scrn->offset->y = p->scrnY; - } else { - dummySOffset.x = p->scrnX; - dummySOffset.y = p->scrnY; } - + else { + dummySOffset.x = p->scrnX; + dummySOffset.y = p->scrnY; + } + if (p->dim && p->dim->root && p->dim->root->dim) { - p->dim->root->dim->x = p->rootWidth; - p->dim->root->dim->y = p->rootHeight; - } else { - dummyRDim.x = p->rootWidth; - dummyRDim.y = p->rootHeight; + p->dim->root->dim->x = p->rootWidth; + p->dim->root->dim->y = p->rootHeight; + } + else { + dummyRDim.x = p->rootWidth; + dummyRDim.y = p->rootHeight; } if (p->dim && p->dim->root && p->dim->root->offset) { p->dim->root->offset->x = p->rootX; p->dim->root->offset->y = p->rootY; - } else { - dummyROffset.x = p->rootX; - dummyROffset.y = p->rootY; + } + else { + dummyROffset.x = p->rootX; + dummyROffset.y = p->rootY; } if (p->origin) { - p->origin->x = p->rootXOrigin, p->origin->y = p->rootYOrigin; - p->origin->xsign = p->rootXSign, p->origin->ysign = p->rootYSign; - } else { - dummyOrigin.x = p->rootXOrigin, dummyOrigin.y = p->rootYOrigin; - dummyOrigin.xsign = p->rootXSign, dummyOrigin.ysign = p->rootYSign; + p->origin->x = p->rootXOrigin, p->origin->y = p->rootYOrigin; + p->origin->xsign = p->rootXSign, p->origin->ysign = p->rootYSign; + } + else { + dummyOrigin.x = p->rootXOrigin, dummyOrigin.y = p->rootYOrigin; + dummyOrigin.xsign = p->rootXSign, dummyOrigin.ysign = p->rootYSign; } - + dmxConfigPrintToken(p->start ? p->start : &dummyStart); dmxConfigPrintString(p->dname ? p->dname : &dummyName, 1); @@ -313,9 +368,7 @@ static void dmxConfigPrintDisplay(DMXConfigDisplayPtr p) dmxConfigPrintPair(&dummySOffset, !output); if (p->scrnWidth != p->rootWidth - || p->scrnHeight != p->rootHeight - || p->rootX - || p->rootY) { + || p->scrnHeight != p->rootHeight || p->rootX || p->rootY) { dmxConfigPrintToken(&dummySep); if (p->dim && p->dim->root && p->dim->root->dim) output = dmxConfigPrintPair(p->dim->root->dim, 1); @@ -331,7 +384,8 @@ static void dmxConfigPrintDisplay(DMXConfigDisplayPtr p) dmxConfigPrintToken(p->end ? p->end : &dummyEnd); } -static void dmxConfigPrintWall(DMXConfigWallPtr p) +static void +dmxConfigPrintWall(DMXConfigWallPtr p) { dmxConfigPrintToken(p->start); dmxConfigPrintPair(p->wallDim, 1); @@ -340,11 +394,12 @@ static void dmxConfigPrintWall(DMXConfigWallPtr p) dmxConfigPrintToken(p->end); } -static void dmxConfigPrintOption(DMXConfigOptionPtr p) +static void +dmxConfigPrintOption(DMXConfigOptionPtr p) { - DMXConfigToken dummyStart = { T_OPTION, 0, NULL }; + DMXConfigToken dummyStart = { T_OPTION, 0, NULL }; DMXConfigString dummyOption = { T_STRING, 0, NULL, NULL, NULL }; - DMXConfigToken dummyEnd = { ';', 0, NULL }; + DMXConfigToken dummyEnd = { ';', 0, NULL }; dummyOption.string = p->string; @@ -353,41 +408,59 @@ static void dmxConfigPrintOption(DMXConfigOptionPtr p) dmxConfigPrintToken(p->end ? p->end : &dummyEnd); } -static void dmxConfigPrintParam(DMXConfigParamPtr p) +static void +dmxConfigPrintParam(DMXConfigParamPtr p) { - if (!p) return; + if (!p) + return; if (p->start) { if (p->open && p->close) { dmxConfigPrintToken(p->start); dmxConfigPrintToken(p->open); dmxConfigPrintParam(p->next); dmxConfigPrintToken(p->close); - } else if (p->end && p->param) { + } + else if (p->end && p->param) { dmxConfigPrintToken(p->start); dmxConfigPrintString(p->param, 1); dmxConfigPrintToken(p->end); - } else + } + else dmxConfigLog("dmxConfigPrintParam: cannot handle format (a)\n"); - } else if (p->end && p->param) { + } + else if (p->end && p->param) { dmxConfigPrintString(p->param, 1); dmxConfigPrintTokenNopop(p->end); dmxConfigPrintParam(p->next); - } else + } + else dmxConfigLog("dmxConfigPrintParam: cannot handle format (b)\n"); } -static void dmxConfigPrintSub(DMXConfigSubPtr p) +static void +dmxConfigPrintSub(DMXConfigSubPtr p) { DMXConfigSubPtr pt; - if (!p) return; + if (!p) + return; for (pt = p; pt; pt = pt->next) { switch (pt->type) { - case dmxConfigComment: dmxConfigPrintComment(pt->comment); break; - case dmxConfigDisplay: dmxConfigPrintDisplay(pt->display); break; - case dmxConfigWall: dmxConfigPrintWall(pt->wall); break; - case dmxConfigOption: dmxConfigPrintOption(pt->option); break; - case dmxConfigParam: dmxConfigPrintParam(pt->param); break; + case dmxConfigComment: + dmxConfigPrintComment(pt->comment); + break; + case dmxConfigDisplay: + dmxConfigPrintDisplay(pt->display); + break; + case dmxConfigWall: + dmxConfigPrintWall(pt->wall); + break; + case dmxConfigOption: + dmxConfigPrintOption(pt->option); + break; + case dmxConfigParam: + dmxConfigPrintParam(pt->param); + break; default: dmxConfigLog("dmxConfigPrintSub:" " cannot handle type %d in subentry\n", pt->type); @@ -395,20 +468,24 @@ static void dmxConfigPrintSub(DMXConfigSubPtr p) } } -static void dmxConfigPrintVirtual(DMXConfigVirtualPtr p) +static void +dmxConfigPrintVirtual(DMXConfigVirtualPtr p) { - DMXConfigToken dummyStart = { T_VIRTUAL, 0, NULL }; - DMXConfigToken dummyOpen = { '{', 0, NULL }; - DMXConfigToken dummyClose = { '}', 0, NULL }; - DMXConfigString dummyName = { T_STRING, 0, NULL, NULL, NULL }; - DMXConfigPair dummyDim = { T_DIMENSION, 0, NULL, 0, 0 }; - - if (p->vname) p->vname->string = p->name; - else dummyName.string = p->name; + DMXConfigToken dummyStart = { T_VIRTUAL, 0, NULL }; + DMXConfigToken dummyOpen = { '{', 0, NULL }; + DMXConfigToken dummyClose = { '}', 0, NULL }; + DMXConfigString dummyName = { T_STRING, 0, NULL, NULL, NULL }; + DMXConfigPair dummyDim = { T_DIMENSION, 0, NULL, 0, 0 }; + + if (p->vname) + p->vname->string = p->name; + else + dummyName.string = p->name; - if (p->dim) p->dim->x = p->width, p->dim->y = p->height; - else dummyDim.x = p->width, dummyDim.y = p->height; - + if (p->dim) + p->dim->x = p->width, p->dim->y = p->height; + else + dummyDim.x = p->width, dummyDim.y = p->height; dmxConfigPrintToken(p->start ? p->start : &dummyStart); dmxConfigPrintString(p->vname ? p->vname : &dummyName, 1); @@ -420,36 +497,48 @@ static void dmxConfigPrintVirtual(DMXConfigVirtualPtr p) /** The configuration information in \a entry will be pretty-printed to * the \a stream. If \a stream is NULL, then stdout will be used. */ -void dmxConfigPrint(FILE *stream, DMXConfigEntryPtr entry) +void +dmxConfigPrint(FILE * stream, DMXConfigEntryPtr entry) { DMXConfigEntryPtr pt; - if (!stream) str = stdout; - else str = stream; - + if (!stream) + str = stdout; + else + str = stream; + stack = &initialStack; - + for (pt = entry; pt; pt = pt->next) { switch (pt->type) { - case dmxConfigComment: dmxConfigPrintComment(pt->comment); break; - case dmxConfigVirtual: dmxConfigPrintVirtual(pt->virtual); break; + case dmxConfigComment: + dmxConfigPrintComment(pt->comment); + break; + case dmxConfigVirtual: + dmxConfigPrintVirtual(pt->virtual); + break; default: dmxConfigLog("dmxConfigPrint: cannot handle type %d in entry\n", pt->type); } } - if (pos) dmxConfigNewline(); + if (pos) + dmxConfigNewline(); } /** The configuration information in \a p will be pretty-printed to the * \a stream. If \a stream is NULL, then stdout will be used. */ -void dmxConfigVirtualPrint(FILE *stream, DMXConfigVirtualPtr p) +void +dmxConfigVirtualPrint(FILE * stream, DMXConfigVirtualPtr p) { - if (!stream) str = stdout; - else str = stream; + if (!stream) + str = stdout; + else + str = stream; stack = &initialStack; - + dmxConfigPrintVirtual(p); - if (pos) dmxConfigNewline(); + if (pos) + dmxConfigNewline(); } diff --git a/xorg-server/hw/dmx/config/dmxtodmx.c b/xorg-server/hw/dmx/config/dmxtodmx.c index 0d4ee4c09..66342091e 100644 --- a/xorg-server/hw/dmx/config/dmxtodmx.c +++ b/xorg-server/hw/dmx/config/dmxtodmx.c @@ -37,10 +37,11 @@ #include "dmxprint.h" #include "dmxcompat.h" -extern int yyparse(void); -extern FILE *yyin; +extern int yyparse(void); +extern FILE *yyin; -int main(int argc, char **argv) +int +main(int argc, char **argv) { yydebug = 0; yyparse(); diff --git a/xorg-server/hw/dmx/config/vdltodmx.c b/xorg-server/hw/dmx/config/vdltodmx.c index 69563f16c..007416b33 100644 --- a/xorg-server/hw/dmx/config/vdltodmx.c +++ b/xorg-server/hw/dmx/config/vdltodmx.c @@ -36,18 +36,20 @@ #include "dmxprint.h" #include "dmxcompat.h" -int main(int argc, char **argv) +int +main(int argc, char **argv) { DMXConfigEntryPtr entry; - FILE *str; + FILE *str; - if (argc != 2 && argc !=3) { + if (argc != 2 && argc != 3) { fprintf(stderr, "Usage: vdltodmx inFile [outFile]\n"); return 1; } if (argc == 2) { str = stdout; - } else if (!(str = fopen(argv[2], "w"))) { + } + else if (!(str = fopen(argv[2], "w"))) { fprintf(stderr, "Cannot open %s for write\n", argv[2]); return 2; } diff --git a/xorg-server/hw/dmx/config/xdmxconfig.c b/xorg-server/hw/dmx/config/xdmxconfig.c index 3165ba000..f30841244 100644 --- a/xorg-server/hw/dmx/config/xdmxconfig.c +++ b/xorg-server/hw/dmx/config/xdmxconfig.c @@ -34,7 +34,7 @@ #ifdef HAVE_DMX_CONFIG_H #include <dmx-config.h> #endif - + #include <stdio.h> #include <stdlib.h> #include <X11/Intrinsic.h> @@ -55,8 +55,8 @@ #include "dmxprint.h" #include "dmxlog.h" -extern int yyparse(void); -extern FILE *yyin; +extern int yyparse(void); +extern FILE *yyin; #define DMX_INFO "xdmxconfig v0.9\nCopyright 2002 Red Hat Inc.\n" @@ -67,329 +67,379 @@ extern FILE *yyin; #define DMX_CANVAS_WIDTH 400 #define DMX_CANVAS_HEIGHT 500 -DMXConfigEntryPtr dmxConfigEntry; +DMXConfigEntryPtr dmxConfigEntry; static DMXConfigVirtualPtr dmxConfigCurrent, dmxConfigNewVirtual; static DMXConfigDisplayPtr dmxConfigCurrentDisplay, dmxConfigNewDisplay; -static int dmxConfigGrabbed, dmxConfigGrabbedFine; -static int dmxConfigGrabbedX, dmxConfigGrabbedY; -static char *dmxConfigFilename; -static GC dmxConfigGC, dmxConfigGCRev, dmxConfigGCHL; -static int dmxConfigGCInit = 0; -static Dimension dmxConfigWidgetWidth, dmxConfigWidgetHeight; -static Dimension dmxConfigWallWidth, dmxConfigWallHeight; -static double dmxConfigScaleX, dmxConfigScaleY; -static int dmxConfigNotSaved; +static int dmxConfigGrabbed, dmxConfigGrabbedFine; +static int dmxConfigGrabbedX, dmxConfigGrabbedY; +static char *dmxConfigFilename; +static GC dmxConfigGC, dmxConfigGCRev, dmxConfigGCHL; +static int dmxConfigGCInit = 0; +static Dimension dmxConfigWidgetWidth, dmxConfigWidgetHeight; +static Dimension dmxConfigWallWidth, dmxConfigWallHeight; +static double dmxConfigScaleX, dmxConfigScaleY; +static int dmxConfigNotSaved; static enum { dmxConfigStateOpen, dmxConfigStateSave -} dmxConfigState; +} dmxConfigState; /* Global widgets */ -static Widget canvas; -static Widget cnamebox, cdimbox; -static Widget openpopup, opendialog; -static Widget namebox, dimbox, rtbox, origbox; -static Widget okbutton, buttonpopup; -static Widget ecbutton, dcbutton; -static Widget ndbutton0, ndbutton1, edbutton, ddbutton; -static Widget ecpopup, ecdialog0, ecdialog1; -static Widget edpopup, eddialog0, eddialog1, eddialog2; -static Widget aboutpopup, quitpopup; - -static void dmxConfigCanvasGCs(void) +static Widget canvas; +static Widget cnamebox, cdimbox; +static Widget openpopup, opendialog; +static Widget namebox, dimbox, rtbox, origbox; +static Widget okbutton, buttonpopup; +static Widget ecbutton, dcbutton; +static Widget ndbutton0, ndbutton1, edbutton, ddbutton; +static Widget ecpopup, ecdialog0, ecdialog1; +static Widget edpopup, eddialog0, eddialog1, eddialog2; +static Widget aboutpopup, quitpopup; + +static void +dmxConfigCanvasGCs(void) { - Display *dpy = XtDisplay(canvas); - Window win = XtWindow(canvas); - XGCValues gcvals; + Display *dpy = XtDisplay(canvas); + Window win = XtWindow(canvas); + XGCValues gcvals; unsigned long mask; - Colormap colormap; - XColor fg, bg, hl, tmp; - - if (dmxConfigGCInit++) return; + Colormap colormap; + XColor fg, bg, hl, tmp; + + if (dmxConfigGCInit++) + return; XtVaGetValues(canvas, XtNcolormap, &colormap, NULL); XAllocNamedColor(XtDisplay(canvas), colormap, "black", &bg, &tmp); XAllocNamedColor(XtDisplay(canvas), colormap, "white", &fg, &tmp); - XAllocNamedColor(XtDisplay(canvas), colormap, "red", &hl, &tmp); + XAllocNamedColor(XtDisplay(canvas), colormap, "red", &hl, &tmp); mask = (GCFunction | GCPlaneMask | GCClipMask | GCForeground | GCBackground | GCLineWidth | GCLineStyle | GCCapStyle | GCFillStyle); - /* FIXME: copy this from widget */ - gcvals.function = GXcopy; + /* FIXME: copy this from widget */ + gcvals.function = GXcopy; gcvals.plane_mask = AllPlanes; - gcvals.clip_mask = None; + gcvals.clip_mask = None; gcvals.foreground = fg.pixel; gcvals.background = bg.pixel; gcvals.line_width = 0; gcvals.line_style = LineSolid; - gcvals.cap_style = CapNotLast; + gcvals.cap_style = CapNotLast; gcvals.fill_style = FillSolid; - - dmxConfigGC = XCreateGC(dpy, win, mask, &gcvals); + + dmxConfigGC = XCreateGC(dpy, win, mask, &gcvals); gcvals.foreground = hl.pixel; - dmxConfigGCHL = XCreateGC(dpy, win, mask, &gcvals); + dmxConfigGCHL = XCreateGC(dpy, win, mask, &gcvals); gcvals.foreground = bg.pixel; gcvals.background = fg.pixel; - dmxConfigGCRev = XCreateGC(dpy, win, mask, &gcvals); + dmxConfigGCRev = XCreateGC(dpy, win, mask, &gcvals); } -static void dmxConfigGetDims(int *maxWidth, int *maxHeight) +static void +dmxConfigGetDims(int *maxWidth, int *maxHeight) { - DMXConfigSubPtr pt; + DMXConfigSubPtr pt; DMXConfigEntryPtr e; - - *maxWidth = dmxConfigWallWidth = 0; + + *maxWidth = dmxConfigWallWidth = 0; *maxHeight = dmxConfigWallHeight = 0; - if (!dmxConfigCurrent) return; - - dmxConfigWallWidth = dmxConfigCurrent->width; + if (!dmxConfigCurrent) + return; + + dmxConfigWallWidth = dmxConfigCurrent->width; dmxConfigWallHeight = dmxConfigCurrent->height; if (!dmxConfigWallWidth || !dmxConfigWallHeight) { for (pt = dmxConfigCurrent->subentry; pt; pt = pt->next) { if (pt->type == dmxConfigDisplay) { - int x = pt->display->scrnWidth + pt->display->rootXOrigin; + int x = pt->display->scrnWidth + pt->display->rootXOrigin; int y = pt->display->scrnHeight + pt->display->rootYOrigin; - if (x > dmxConfigWallWidth) dmxConfigWallWidth = x; - if (y > dmxConfigWallHeight) dmxConfigWallHeight = y; + + if (x > dmxConfigWallWidth) + dmxConfigWallWidth = x; + if (y > dmxConfigWallHeight) + dmxConfigWallHeight = y; } } } - /* Compute maximums */ + /* Compute maximums */ *maxWidth = *maxHeight = 0; for (e = dmxConfigEntry; e; e = e->next) { - if (e->type != dmxConfigVirtual) continue; + if (e->type != dmxConfigVirtual) + continue; for (pt = e->virtual->subentry; pt; pt = pt->next) { if (pt->type == dmxConfigDisplay) { - int x = pt->display->scrnWidth + pt->display->rootXOrigin; + int x = pt->display->scrnWidth + pt->display->rootXOrigin; int y = pt->display->scrnHeight + pt->display->rootYOrigin; - if (x > *maxWidth) *maxWidth = x; - if (y > *maxHeight) *maxHeight = y; + + if (x > *maxWidth) + *maxWidth = x; + if (y > *maxHeight) + *maxHeight = y; } } } - if (dmxConfigWallWidth > *maxWidth) *maxWidth = dmxConfigWallWidth; - if (dmxConfigWallHeight > *maxHeight) *maxHeight = dmxConfigWallHeight; + if (dmxConfigWallWidth > *maxWidth) + *maxWidth = dmxConfigWallWidth; + if (dmxConfigWallHeight > *maxHeight) + *maxHeight = dmxConfigWallHeight; +} + +static int +scalex(int x) +{ + return (int) ((x * dmxConfigScaleX) + .5); +} + +static int +scaley(int y) +{ + return (int) ((y * dmxConfigScaleY) + .5); +} + +static int +unscalex(int x) +{ + return (int) ((x / dmxConfigScaleX) + .5); } -static int scalex(int x) { return (int)((x * dmxConfigScaleX) + .5); } -static int scaley(int y) { return (int)((y * dmxConfigScaleY) + .5); } -static int unscalex(int x) { return (int)((x / dmxConfigScaleX) + .5); } -static int unscaley(int y) { return (int)((y / dmxConfigScaleY) + .5); } +static int +unscaley(int y) +{ + return (int) ((y / dmxConfigScaleY) + .5); +} -static void dmxConfigDataUpdate(void) +static void +dmxConfigDataUpdate(void) { - /* FIXME: could result in buffer overflows */ - char cnambuf[512]; - char cdimbuf[128]; - char nambuf[512]; - char dimbuf[128]; - char rtbuf[128]; - char offbuf[128]; + /* FIXME: could result in buffer overflows */ + char cnambuf[512]; + char cdimbuf[128]; + char nambuf[512]; + char dimbuf[128]; + char rtbuf[128]; + char offbuf[128]; const char *name; if (!dmxConfigCurrent) { - XtVaSetValues(cnamebox, XtNlabel, "", XtNsensitive, False, NULL); - XtVaSetValues(cdimbox, XtNlabel, "", XtNsensitive, False, NULL); - XtVaSetValues(ecbutton, XtNsensitive, False, NULL); - XtVaSetValues(dcbutton, XtNsensitive, False, NULL); - XtVaSetValues(ndbutton0, XtNsensitive, False, NULL); - XtVaSetValues(ndbutton1, XtNsensitive, False, NULL); - } else { + XtVaSetValues(cnamebox, XtNlabel, "", XtNsensitive, False, NULL); + XtVaSetValues(cdimbox, XtNlabel, "", XtNsensitive, False, NULL); + XtVaSetValues(ecbutton, XtNsensitive, False, NULL); + XtVaSetValues(dcbutton, XtNsensitive, False, NULL); + XtVaSetValues(ndbutton0, XtNsensitive, False, NULL); + XtVaSetValues(ndbutton1, XtNsensitive, False, NULL); + } + else { name = dmxConfigCurrent->name; snprintf(cnambuf, sizeof(cnambuf), "%s", name ? name : ""); snprintf(cdimbuf, sizeof(cdimbuf), "%dx%d", - dmxConfigWallWidth, dmxConfigWallHeight); - XtVaSetValues(cnamebox, XtNlabel, cnambuf, XtNsensitive, True, NULL); - XtVaSetValues(cdimbox, XtNlabel, cdimbuf, XtNsensitive, True, NULL); - XtVaSetValues(ecbutton, XtNsensitive, True, NULL); - XtVaSetValues(dcbutton, XtNsensitive, True, NULL); - XtVaSetValues(ndbutton0, XtNsensitive, True, NULL); - XtVaSetValues(ndbutton1, XtNsensitive, True, NULL); + dmxConfigWallWidth, dmxConfigWallHeight); + XtVaSetValues(cnamebox, XtNlabel, cnambuf, XtNsensitive, True, NULL); + XtVaSetValues(cdimbox, XtNlabel, cdimbuf, XtNsensitive, True, NULL); + XtVaSetValues(ecbutton, XtNsensitive, True, NULL); + XtVaSetValues(dcbutton, XtNsensitive, True, NULL); + XtVaSetValues(ndbutton0, XtNsensitive, True, NULL); + XtVaSetValues(ndbutton1, XtNsensitive, True, NULL); } - + if (!dmxConfigCurrentDisplay) { XtVaSetValues(namebox, XtNlabel, "", XtNsensitive, False, NULL); - XtVaSetValues(dimbox, XtNlabel, "", XtNsensitive, False, NULL); - XtVaSetValues(rtbox, XtNlabel, "", XtNsensitive, False, NULL); + XtVaSetValues(dimbox, XtNlabel, "", XtNsensitive, False, NULL); + XtVaSetValues(rtbox, XtNlabel, "", XtNsensitive, False, NULL); XtVaSetValues(origbox, XtNlabel, "", XtNsensitive, False, NULL); - XtVaSetValues(edbutton, XtNsensitive, False, NULL); - XtVaSetValues(ddbutton, XtNsensitive, False, NULL); - } else { + XtVaSetValues(edbutton, XtNsensitive, False, NULL); + XtVaSetValues(ddbutton, XtNsensitive, False, NULL); + } + else { name = dmxConfigCurrentDisplay->name; snprintf(nambuf, sizeof(nambuf), "%s", name ? name : ""); snprintf(dimbuf, sizeof(dimbuf), "%dx%d%c%d%c%d", - dmxConfigCurrentDisplay->scrnWidth, - dmxConfigCurrentDisplay->scrnHeight, - dmxConfigCurrentDisplay->scrnXSign < 0 ? '-' : '+', - dmxConfigCurrentDisplay->scrnX, - dmxConfigCurrentDisplay->scrnYSign < 0 ? '-' : '+', - dmxConfigCurrentDisplay->scrnY); + dmxConfigCurrentDisplay->scrnWidth, + dmxConfigCurrentDisplay->scrnHeight, + dmxConfigCurrentDisplay->scrnXSign < 0 ? '-' : '+', + dmxConfigCurrentDisplay->scrnX, + dmxConfigCurrentDisplay->scrnYSign < 0 ? '-' : '+', + dmxConfigCurrentDisplay->scrnY); snprintf(rtbuf, sizeof(dimbuf), "%dx%d%c%d%c%d", - dmxConfigCurrentDisplay->rootWidth, - dmxConfigCurrentDisplay->rootHeight, - dmxConfigCurrentDisplay->rootXSign < 0 ? '-' : '+', - dmxConfigCurrentDisplay->rootX, - dmxConfigCurrentDisplay->rootYSign < 0 ? '-' : '+', - dmxConfigCurrentDisplay->rootY); + dmxConfigCurrentDisplay->rootWidth, + dmxConfigCurrentDisplay->rootHeight, + dmxConfigCurrentDisplay->rootXSign < 0 ? '-' : '+', + dmxConfigCurrentDisplay->rootX, + dmxConfigCurrentDisplay->rootYSign < 0 ? '-' : '+', + dmxConfigCurrentDisplay->rootY); snprintf(offbuf, sizeof(offbuf), "@%dx%d", - dmxConfigCurrentDisplay->rootXOrigin, - dmxConfigCurrentDisplay->rootYOrigin); + dmxConfigCurrentDisplay->rootXOrigin, + dmxConfigCurrentDisplay->rootYOrigin); XtVaSetValues(namebox, XtNlabel, nambuf, XtNsensitive, True, NULL); - XtVaSetValues(dimbox, XtNlabel, dimbuf, XtNsensitive, True, NULL); - XtVaSetValues(rtbox, XtNlabel, rtbuf, XtNsensitive, True, NULL); + XtVaSetValues(dimbox, XtNlabel, dimbuf, XtNsensitive, True, NULL); + XtVaSetValues(rtbox, XtNlabel, rtbuf, XtNsensitive, True, NULL); XtVaSetValues(origbox, XtNlabel, offbuf, XtNsensitive, True, NULL); - XtVaSetValues(edbutton, XtNsensitive, True, NULL); - XtVaSetValues(ddbutton, XtNsensitive, True, NULL); + XtVaSetValues(edbutton, XtNsensitive, True, NULL); + XtVaSetValues(ddbutton, XtNsensitive, True, NULL); } } -static void dmxConfigCanvasUpdate(void) +static void +dmxConfigCanvasUpdate(void) { DMXConfigSubPtr pt; - Display *dpy = XtDisplay(canvas); - Window win = XtWindow(canvas); - GContext gcontext = XGContextFromGC(dmxConfigGC); - XFontStruct *fs; - int w, h; + Display *dpy = XtDisplay(canvas); + Window win = XtWindow(canvas); + GContext gcontext = XGContextFromGC(dmxConfigGC); + XFontStruct *fs; + int w, h; XFillRectangle(dpy, win, dmxConfigGCRev, 0, 0, dmxConfigWidgetWidth, dmxConfigWidgetHeight); dmxConfigDataUpdate(); - if (!dmxConfigCurrent) return; + if (!dmxConfigCurrent) + return; w = scalex(dmxConfigWallWidth); h = scaley(dmxConfigWallHeight); - if (w > dmxConfigWidgetWidth - 1) w = dmxConfigWidgetWidth - 1; - if (h > dmxConfigWidgetHeight - 1) h = dmxConfigWidgetHeight - 1; + if (w > dmxConfigWidgetWidth - 1) + w = dmxConfigWidgetWidth - 1; + if (h > dmxConfigWidgetHeight - 1) + h = dmxConfigWidgetHeight - 1; XDrawRectangle(dpy, win, dmxConfigGC, 0, 0, w, h); fs = XQueryFont(dpy, gcontext); for (pt = dmxConfigCurrent->subentry; pt; pt = pt->next) { int x, y, len; int xo = 3, yo = fs->ascent + fs->descent + 2; - GC gc; - - if (pt->type != dmxConfigDisplay) continue; - gc = (pt->display == dmxConfigCurrentDisplay - ? dmxConfigGCHL - : dmxConfigGC); - x = scalex(pt->display->rootXOrigin); - y = scaley(pt->display->rootYOrigin); - w = scalex(pt->display->scrnWidth); - h = scaley(pt->display->scrnHeight); + GC gc; + + if (pt->type != dmxConfigDisplay) + continue; + gc = (pt->display == dmxConfigCurrentDisplay + ? dmxConfigGCHL : dmxConfigGC); + x = scalex(pt->display->rootXOrigin); + y = scaley(pt->display->rootYOrigin); + w = scalex(pt->display->scrnWidth); + h = scaley(pt->display->scrnHeight); len = pt->display->name ? strlen(pt->display->name) : 0; - if (x > dmxConfigWidgetWidth - 1) x = dmxConfigWidgetWidth - 1; - if (y > dmxConfigWidgetHeight - 1) y = dmxConfigWidgetHeight - 1; + if (x > dmxConfigWidgetWidth - 1) + x = dmxConfigWidgetWidth - 1; + if (y > dmxConfigWidgetHeight - 1) + y = dmxConfigWidgetHeight - 1; XDrawRectangle(dpy, win, gc, x, y, w, h); if (fs && len) { while (len && XTextWidth(fs, pt->display->name, len) >= w - 2 * xo) --len; if (len) - XDrawString(dpy, win, gc, x+xo, y+yo, pt->display->name, len); + XDrawString(dpy, win, gc, x + xo, y + yo, pt->display->name, + len); } } - if (fs) XFreeFontInfo(NULL, fs, 0); + if (fs) + XFreeFontInfo(NULL, fs, 0); } -static void dmxConfigCanvasDraw(Region region) +static void +dmxConfigCanvasDraw(Region region) { Display *dpy = XtDisplay(canvas); - int maxWidth, maxHeight; - + int maxWidth, maxHeight; + dmxConfigCanvasGCs(); if (region) { - XSetRegion(dpy, dmxConfigGC, region); + XSetRegion(dpy, dmxConfigGC, region); XSetRegion(dpy, dmxConfigGCRev, region); - XSetRegion(dpy, dmxConfigGCHL, region); + XSetRegion(dpy, dmxConfigGCHL, region); } XtVaGetValues(canvas, XtNwidth, &dmxConfigWidgetWidth, - XtNheight, &dmxConfigWidgetHeight, - NULL); + XtNheight, &dmxConfigWidgetHeight, NULL); dmxConfigGetDims(&maxWidth, &maxHeight); - dmxConfigScaleX = (double)dmxConfigWidgetWidth / maxWidth; - dmxConfigScaleY = (double)dmxConfigWidgetHeight / maxHeight; - if (dmxConfigScaleX > dmxConfigScaleY) dmxConfigScaleX = dmxConfigScaleY; - if (dmxConfigScaleY > dmxConfigScaleX) dmxConfigScaleY = dmxConfigScaleX; + dmxConfigScaleX = (double) dmxConfigWidgetWidth / maxWidth; + dmxConfigScaleY = (double) dmxConfigWidgetHeight / maxHeight; + if (dmxConfigScaleX > dmxConfigScaleY) + dmxConfigScaleX = dmxConfigScaleY; + if (dmxConfigScaleY > dmxConfigScaleX) + dmxConfigScaleY = dmxConfigScaleX; dmxConfigCanvasUpdate(); if (region) { - XSetClipMask(dpy, dmxConfigGC, None); + XSetClipMask(dpy, dmxConfigGC, None); XSetClipMask(dpy, dmxConfigGCRev, None); - XSetClipMask(dpy, dmxConfigGCHL, None); + XSetClipMask(dpy, dmxConfigGCHL, None); } } -static void dmxConfigSelectCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigSelectCallback(Widget w, XtPointer closure, XtPointer callData) { dmxConfigCurrent = closure; dmxConfigVirtualPrint(stdout, dmxConfigCurrent); dmxConfigCanvasDraw(NULL); } -static void dmxConfigCopystrings(void) +static void +dmxConfigCopystrings(void) { DMXConfigEntryPtr pt; - DMXConfigSubPtr sub; + DMXConfigSubPtr sub; - if (!dmxConfigCurrent) return; + if (!dmxConfigCurrent) + return; - /* FIXME: this is all a per-config file - * memory leak */ + /* FIXME: this is all a per-config file + * memory leak */ for (pt = dmxConfigEntry; pt; pt = pt->next) { if (pt->type == dmxConfigVirtual) { pt->virtual->name = XtNewString(pt->virtual->name - ? pt->virtual->name - : ""); + ? pt->virtual->name : ""); for (sub = pt->virtual->subentry; sub; sub = sub->next) { - if (sub->type != dmxConfigDisplay) continue; + if (sub->type != dmxConfigDisplay) + continue; sub->display->name = XtNewString(sub->display->name - ? sub->display->name - : ""); + ? sub->display->name : ""); } } } } -static void dmxConfigGetValueString(char **d, Widget w) +static void +dmxConfigGetValueString(char **d, Widget w) { const char *tmp = XawDialogGetValueString(w); - if (*d) XtFree(*d); + + if (*d) + XtFree(*d); *d = XtNewString(tmp); } -static void dmxConfigSetupCnamemenu(void) +static void +dmxConfigSetupCnamemenu(void) { - static Widget cnamemenu = NULL; - Widget w; + static Widget cnamemenu = NULL; + Widget w; DMXConfigEntryPtr pt; - if (cnamemenu) XtDestroyWidget(cnamemenu); + if (cnamemenu) + XtDestroyWidget(cnamemenu); cnamemenu = NULL; - if (!dmxConfigCurrent) return; + if (!dmxConfigCurrent) + return; cnamemenu = XtVaCreatePopupShell("cnamemenu", simpleMenuWidgetClass, - cnamebox, - NULL); - + cnamebox, NULL); + for (pt = dmxConfigEntry; pt; pt = pt->next) { if (pt->type == dmxConfigVirtual) { w = XtVaCreateManagedWidget(pt->virtual->name ? pt->virtual->name : "", - smeBSBObjectClass, cnamemenu, - NULL); - XtAddCallback(w, XtNcallback, - dmxConfigSelectCallback, pt->virtual); + smeBSBObjectClass, cnamemenu, NULL); + XtAddCallback(w, XtNcallback, dmxConfigSelectCallback, pt->virtual); } } } -static void dmxConfigReadFile(void) +static void +dmxConfigReadFile(void) { - FILE *str; + FILE *str; DMXConfigEntryPtr pt; if (!(str = fopen(dmxConfigFilename, "r"))) { @@ -397,7 +447,7 @@ static void dmxConfigReadFile(void) dmxConfigFilename); return; } - yyin = str; + yyin = str; yydebug = 0; yyparse(); fclose(str); @@ -410,8 +460,6 @@ static void dmxConfigReadFile(void) } } - - if (XtIsRealized(canvas)) { dmxConfigCopystrings(); dmxConfigSetupCnamemenu(); @@ -420,9 +468,10 @@ static void dmxConfigReadFile(void) dmxConfigVirtualPrint(stdout, dmxConfigCurrent); } -static void dmxConfigWriteFile(void) +static void +dmxConfigWriteFile(void) { - FILE *str; + FILE *str; if (!(str = fopen(dmxConfigFilename, "w"))) { dmxLog(dmxWarning, "Unable to write configuration file %s\n", @@ -433,31 +482,36 @@ static void dmxConfigWriteFile(void) fclose(str); } -static DMXConfigDisplayPtr dmxConfigFindDisplay(int x, int y) +static DMXConfigDisplayPtr +dmxConfigFindDisplay(int x, int y) { DMXConfigSubPtr pt; - if (!dmxConfigCurrent) return NULL; + if (!dmxConfigCurrent) + return NULL; for (pt = dmxConfigCurrent->subentry; pt; pt = pt->next) { DMXConfigDisplayPtr d = pt->display; - if (pt->type != dmxConfigDisplay) continue; + + if (pt->type != dmxConfigDisplay) + continue; if (x >= scalex(d->rootXOrigin) && x <= scalex(d->rootXOrigin + d->scrnWidth) && y >= scaley(d->rootYOrigin) - && y <= scaley(d->rootYOrigin + d->scrnHeight)) return d; + && y <= scaley(d->rootYOrigin + d->scrnHeight)) + return d; } return NULL; } -static void dmxConfigSetPopupPosition(Widget popup) +static void +dmxConfigSetPopupPosition(Widget popup) { - Position x, y; - Window t1, t2; - int root_x, root_y; - int temp_x, temp_y; + Position x, y; + Window t1, t2; + int root_x, root_y; + int temp_x, temp_y; unsigned int temp; - XtRealizeWidget(popup); if (!XQueryPointer(XtDisplay(popup), XtWindow(popup), &t1, &t2, &root_x, &root_y, &temp_x, &temp_y, &temp)) @@ -468,13 +522,15 @@ static void dmxConfigSetPopupPosition(Widget popup) XtVaSetValues(popup, XtNx, x, XtNy, y, NULL); } -static void dmxConfigPlaceMenu(Widget w, XEvent *event, - String *params, Cardinal *num_params) +static void +dmxConfigPlaceMenu(Widget w, XEvent * event, + String * params, Cardinal * num_params) { dmxConfigSetPopupPosition(buttonpopup); } -static void dmxConfigMove(int deltaX, int deltaY) +static void +dmxConfigMove(int deltaX, int deltaY) { dmxConfigCurrentDisplay->rootXOrigin += deltaX; dmxConfigCurrentDisplay->rootYOrigin += deltaY; @@ -492,40 +548,44 @@ static void dmxConfigMove(int deltaX, int deltaY) dmxConfigNotSaved = 1; } -static void dmxConfigCanvasInput(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigCanvasInput(Widget w, XtPointer closure, XtPointer callData) { - XEvent *e = (XEvent *)callData; + XEvent *e = (XEvent *) callData; DMXConfigDisplayPtr display = NULL; switch (e->type) { case ButtonPress: if (e->xbutton.button == Button1) { - dmxConfigGrabbed = 1; + dmxConfigGrabbed = 1; dmxConfigGrabbedFine = 0; - dmxConfigGrabbedX = e->xbutton.x; - dmxConfigGrabbedY = e->xbutton.y; + dmxConfigGrabbedX = e->xbutton.x; + dmxConfigGrabbedY = e->xbutton.y; } if (e->xbutton.button == Button2) { - dmxConfigGrabbed = 1; + dmxConfigGrabbed = 1; dmxConfigGrabbedFine = 1; - dmxConfigGrabbedX = e->xbutton.x; - dmxConfigGrabbedY = e->xbutton.y; + dmxConfigGrabbedX = e->xbutton.x; + dmxConfigGrabbedY = e->xbutton.y; } break; case ButtonRelease: - if (e->xbutton.button == Button1) dmxConfigGrabbed = 0; - if (e->xbutton.button == Button2) dmxConfigGrabbed = 0; + if (e->xbutton.button == Button1) + dmxConfigGrabbed = 0; + if (e->xbutton.button == Button2) + dmxConfigGrabbed = 0; break; case MotionNotify: if (dmxConfigGrabbed && dmxConfigCurrentDisplay) { int deltaX = e->xmotion.x - dmxConfigGrabbedX; int deltaY = e->xmotion.y - dmxConfigGrabbedY; + dmxConfigMove(dmxConfigGrabbedFine ? deltaX : unscalex(deltaX), dmxConfigGrabbedFine ? deltaY : unscaley(deltaY)); dmxConfigGrabbedX = e->xmotion.x; dmxConfigGrabbedY = e->xmotion.y; - } else { + } + else { display = dmxConfigFindDisplay(e->xmotion.x, e->xmotion.y); if (display != dmxConfigCurrentDisplay) { dmxConfigCurrentDisplay = display; @@ -535,31 +595,39 @@ static void dmxConfigCanvasInput(Widget w, XtPointer closure, break; case KeyPress: switch (XLookupKeysym(&e->xkey, 0)) { - case XK_Right: dmxConfigMove(1,0); break; - case XK_Left: dmxConfigMove(-1,0); break; - case XK_Down: dmxConfigMove(0,1); break; - case XK_Up: dmxConfigMove(0,-1); break; + case XK_Right: + dmxConfigMove(1, 0); + break; + case XK_Left: + dmxConfigMove(-1, 0); + break; + case XK_Down: + dmxConfigMove(0, 1); + break; + case XK_Up: + dmxConfigMove(0, -1); + break; } break; } } -static void dmxConfigCanvasResize(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigCanvasResize(Widget w, XtPointer closure, XtPointer callData) { dmxConfigCanvasDraw(NULL); } -static void dmxConfigCanvasExpose(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigCanvasExpose(Widget w, XtPointer closure, XtPointer callData) { - CanvasExposeDataPtr data = (CanvasExposeDataPtr)callData; + CanvasExposeDataPtr data = (CanvasExposeDataPtr) callData; dmxConfigCanvasDraw(data->region); } -static void dmxConfigOpenCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigOpenCallback(Widget w, XtPointer closure, XtPointer callData) { dmxConfigState = dmxConfigStateOpen; XtVaSetValues(okbutton, XtNlabel, "Open", NULL); @@ -567,8 +635,8 @@ static void dmxConfigOpenCallback(Widget w, XtPointer closure, XtPopup(openpopup, XtGrabExclusive); } -static void dmxConfigSaveCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigSaveCallback(Widget w, XtPointer closure, XtPointer callData) { dmxConfigState = dmxConfigStateSave; XtVaSetValues(okbutton, XtNlabel, "Save", NULL); @@ -576,69 +644,73 @@ static void dmxConfigSaveCallback(Widget w, XtPointer closure, XtPopup(openpopup, XtGrabExclusive); } -static void dmxConfigOkCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigOkCallback(Widget w, XtPointer closure, XtPointer callData) { dmxConfigGetValueString(&dmxConfigFilename, opendialog); XtPopdown(openpopup); - if (dmxConfigState == dmxConfigStateOpen) dmxConfigReadFile(); - else dmxConfigWriteFile(); + if (dmxConfigState == dmxConfigStateOpen) + dmxConfigReadFile(); + else + dmxConfigWriteFile(); dmxConfigNotSaved = 0; } -static void dmxConfigCanCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigCanCallback(Widget w, XtPointer closure, XtPointer callData) { XtPopdown(openpopup); } -static void dmxConfigECCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigECCallback(Widget w, XtPointer closure, XtPointer callData) { char buf[256]; /* RATS: Only used in snprintf */ - - if (!dmxConfigCurrent) return; + + if (!dmxConfigCurrent) + return; dmxConfigSetPopupPosition(ecpopup); XtVaSetValues(ecdialog0, XtNvalue, - dmxConfigCurrent->name ? dmxConfigCurrent->name : "", - NULL); + dmxConfigCurrent->name ? dmxConfigCurrent->name : "", NULL); snprintf(buf, sizeof(buf), "%dx%d", - dmxConfigCurrent->width, dmxConfigCurrent->height); + dmxConfigCurrent->width, dmxConfigCurrent->height); XtVaSetValues(ecdialog1, XtNvalue, buf, NULL); XtPopup(ecpopup, XtGrabExclusive); } -static void dmxConfigNCCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigNCCallback(Widget w, XtPointer closure, XtPointer callData) { - int width = 1280*2, height = 1024*2; + int width = 1280 * 2, height = 1024 * 2; if (dmxConfigCurrent) { - width = dmxConfigCurrent->width; + width = dmxConfigCurrent->width; height = dmxConfigCurrent->height; } - dmxConfigCurrent = dmxConfigCreateVirtual(NULL, NULL, NULL, - NULL, NULL, NULL); - dmxConfigNewVirtual = dmxConfigCurrent; - dmxConfigCurrent->width = width; + dmxConfigCurrent = dmxConfigCreateVirtual(NULL, NULL, NULL, + NULL, NULL, NULL); + dmxConfigNewVirtual = dmxConfigCurrent; + dmxConfigCurrent->width = width; dmxConfigCurrent->height = height; dmxConfigEntry = dmxConfigAddEntry(dmxConfigEntry, dmxConfigVirtual, NULL, dmxConfigCurrent); dmxConfigECCallback(w, closure, callData); } -static void dmxConfigDCCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigDCCallback(Widget w, XtPointer closure, XtPointer callData) { DMXConfigEntryPtr pt; - if (!dmxConfigEntry) return; + if (!dmxConfigEntry) + return; if (dmxConfigEntry && dmxConfigEntry->type == dmxConfigVirtual && dmxConfigEntry->virtual == dmxConfigCurrent) { dmxConfigEntry = dmxConfigEntry->next; - } else { + } + else { for (pt = dmxConfigEntry; pt && pt->next; pt = pt->next) if (pt->next->type == dmxConfigVirtual && pt->next->virtual == dmxConfigCurrent) { @@ -647,10 +719,10 @@ static void dmxConfigDCCallback(Widget w, XtPointer closure, } } dmxConfigFreeVirtual(dmxConfigCurrent); - dmxConfigCurrent = NULL; + dmxConfigCurrent = NULL; dmxConfigCurrentDisplay = NULL; - /* Make the first entry current */ + /* Make the first entry current */ for (pt = dmxConfigEntry; pt; pt = pt->next) { if (pt->type == dmxConfigVirtual) { dmxConfigCurrent = pt->virtual; @@ -662,93 +734,96 @@ static void dmxConfigDCCallback(Widget w, XtPointer closure, dmxConfigCanvasDraw(NULL); } -static void dmxConfigECOkCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigECOkCallback(Widget w, XtPointer closure, XtPointer callData) { const char *value; - char *endpt; + char *endpt; - dmxConfigGetValueString((char **)&dmxConfigCurrent->name, ecdialog0); - value = XawDialogGetValueString(ecdialog1); - dmxConfigCurrent->width = strtol(value, &endpt, 10); - dmxConfigCurrent->height = strtol(endpt+1, NULL, 10); + dmxConfigGetValueString((char **) &dmxConfigCurrent->name, ecdialog0); + value = XawDialogGetValueString(ecdialog1); + dmxConfigCurrent->width = strtol(value, &endpt, 10); + dmxConfigCurrent->height = strtol(endpt + 1, NULL, 10); XtPopdown(ecpopup); dmxConfigCurrentDisplay = NULL; - dmxConfigNewVirtual = NULL; + dmxConfigNewVirtual = NULL; dmxConfigSetupCnamemenu(); dmxConfigCanvasDraw(NULL); dmxConfigNotSaved = 1; } -static void dmxConfigECCanCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigECCanCallback(Widget w, XtPointer closure, XtPointer callData) { - if (dmxConfigNewVirtual) dmxConfigDCCallback(w, closure, callData); - dmxConfigNewVirtual = NULL; + if (dmxConfigNewVirtual) + dmxConfigDCCallback(w, closure, callData); + dmxConfigNewVirtual = NULL; XtPopdown(ecpopup); } -static void dmxConfigEDCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigEDCallback(Widget w, XtPointer closure, XtPointer callData) { char buf[256]; /* RATS: Only used in snprintf */ - - if (!dmxConfigCurrent || !dmxConfigCurrentDisplay) return; + + if (!dmxConfigCurrent || !dmxConfigCurrentDisplay) + return; dmxConfigSetPopupPosition(edpopup); XtVaSetValues(eddialog0, XtNvalue, dmxConfigCurrentDisplay->name - ? dmxConfigCurrentDisplay->name - : "", - NULL); + ? dmxConfigCurrentDisplay->name : "", NULL); snprintf(buf, sizeof(buf), "%dx%d%c%d%c%d", - dmxConfigCurrentDisplay->scrnWidth, - dmxConfigCurrentDisplay->scrnHeight, - dmxConfigCurrentDisplay->scrnXSign < 0 ? '-' : '+', - dmxConfigCurrentDisplay->scrnY, - dmxConfigCurrentDisplay->scrnYSign < 0 ? '-' : '+', - dmxConfigCurrentDisplay->scrnY); + dmxConfigCurrentDisplay->scrnWidth, + dmxConfigCurrentDisplay->scrnHeight, + dmxConfigCurrentDisplay->scrnXSign < 0 ? '-' : '+', + dmxConfigCurrentDisplay->scrnY, + dmxConfigCurrentDisplay->scrnYSign < 0 ? '-' : '+', + dmxConfigCurrentDisplay->scrnY); XtVaSetValues(eddialog1, XtNvalue, buf, NULL); snprintf(buf, sizeof(buf), "@%dx%d", - dmxConfigCurrentDisplay->rootXOrigin, - dmxConfigCurrentDisplay->rootYOrigin); + dmxConfigCurrentDisplay->rootXOrigin, + dmxConfigCurrentDisplay->rootYOrigin); XtVaSetValues(eddialog2, XtNvalue, buf, NULL); XtPopup(edpopup, XtGrabExclusive); } -static void dmxConfigNDCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigNDCallback(Widget w, XtPointer closure, XtPointer callData) { int width = 1280, height = 1024; - if (!dmxConfigCurrent) return; + if (!dmxConfigCurrent) + return; if (dmxConfigCurrentDisplay) { - width = dmxConfigCurrentDisplay->scrnWidth; + width = dmxConfigCurrentDisplay->scrnWidth; height = dmxConfigCurrentDisplay->scrnHeight; } dmxConfigCurrentDisplay = dmxConfigCreateDisplay(NULL, NULL, NULL, NULL, NULL); - dmxConfigNewDisplay = dmxConfigCurrentDisplay; - dmxConfigCurrentDisplay->scrnWidth = width; + dmxConfigNewDisplay = dmxConfigCurrentDisplay; + dmxConfigCurrentDisplay->scrnWidth = width; dmxConfigCurrentDisplay->scrnHeight = height; - + dmxConfigCurrent->subentry = dmxConfigAddSub(dmxConfigCurrent->subentry, dmxConfigSubDisplay(dmxConfigCurrentDisplay)); dmxConfigEDCallback(w, closure, callData); } -static void dmxConfigDDCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigDDCallback(Widget w, XtPointer closure, XtPointer callData) { DMXConfigSubPtr pt; - if (!dmxConfigCurrent || !dmxConfigCurrentDisplay) return; - /* First */ + if (!dmxConfigCurrent || !dmxConfigCurrentDisplay) + return; + /* First */ if (dmxConfigCurrent->subentry && dmxConfigCurrent->subentry->type == dmxConfigDisplay && dmxConfigCurrent->subentry->display == dmxConfigCurrentDisplay) { dmxConfigCurrent->subentry = dmxConfigCurrent->subentry->next; - } else { + } + else { for (pt = dmxConfigCurrent->subentry; pt && pt->next; pt = pt->next) if (pt->next->type == dmxConfigDisplay && pt->next->display == dmxConfigCurrentDisplay) { @@ -762,21 +837,21 @@ static void dmxConfigDDCallback(Widget w, XtPointer closure, dmxConfigCanvasDraw(NULL); } -static void dmxConfigAboutCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigAboutCallback(Widget w, XtPointer closure, XtPointer callData) { dmxConfigSetPopupPosition(aboutpopup); XtPopup(aboutpopup, XtGrabExclusive); } -static void dmxConfigAboutOkCallback(Widget w, XtPointer closure, - XtPointer CallData) +static void +dmxConfigAboutOkCallback(Widget w, XtPointer closure, XtPointer CallData) { XtPopdown(aboutpopup); } -static void dmxConfigQuitCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigQuitCallback(Widget w, XtPointer closure, XtPointer callData) { if (dmxConfigNotSaved) { dmxConfigSetPopupPosition(quitpopup); @@ -786,77 +861,82 @@ static void dmxConfigQuitCallback(Widget w, XtPointer closure, exit(0); } -static void dmxConfigQuitOkCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigQuitOkCallback(Widget w, XtPointer closure, XtPointer callData) { XtPopdown(quitpopup); exit(0); } -static void dmxConfigQuitCanCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigQuitCanCallback(Widget w, XtPointer closure, XtPointer callData) { XtPopdown(quitpopup); } -static void dmxConfigEDOkCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigEDOkCallback(Widget w, XtPointer closure, XtPointer callData) { char *value; char *endpt; - + dmxConfigNewDisplay = NULL; - dmxConfigGetValueString((char **)&dmxConfigCurrentDisplay->name, + dmxConfigGetValueString((char **) &dmxConfigCurrentDisplay->name, eddialog0); - value = XawDialogGetValueString(eddialog1); + value = XawDialogGetValueString(eddialog1); if (*value == '-' || *value == '+') { - dmxConfigCurrentDisplay->scrnWidth = 0; + dmxConfigCurrentDisplay->scrnWidth = 0; dmxConfigCurrentDisplay->scrnHeight = 0; - endpt = value; - } else { - dmxConfigCurrentDisplay->scrnWidth = strtol(value, &endpt, 10); - dmxConfigCurrentDisplay->scrnHeight = strtol(endpt+1, &endpt, 10); + endpt = value; + } + else { + dmxConfigCurrentDisplay->scrnWidth = strtol(value, &endpt, 10); + dmxConfigCurrentDisplay->scrnHeight = strtol(endpt + 1, &endpt, 10); } if (*endpt) { - dmxConfigCurrentDisplay->scrnXSign = (*endpt == '-') ? -1 : 1; - dmxConfigCurrentDisplay->scrnX = strtol(endpt+1, &endpt, 10); - dmxConfigCurrentDisplay->scrnYSign = (*endpt == '-') ? -1 : 1; - dmxConfigCurrentDisplay->scrnY = strtol(endpt+1, NULL, 10); + dmxConfigCurrentDisplay->scrnXSign = (*endpt == '-') ? -1 : 1; + dmxConfigCurrentDisplay->scrnX = strtol(endpt + 1, &endpt, 10); + dmxConfigCurrentDisplay->scrnYSign = (*endpt == '-') ? -1 : 1; + dmxConfigCurrentDisplay->scrnY = strtol(endpt + 1, NULL, 10); } if (dmxConfigCurrentDisplay->scrnX < 0) dmxConfigCurrentDisplay->scrnX = -dmxConfigCurrentDisplay->scrnX; if (dmxConfigCurrentDisplay->scrnY < 0) dmxConfigCurrentDisplay->scrnY = -dmxConfigCurrentDisplay->scrnY; - value = XawDialogGetValueString(eddialog2); - dmxConfigCurrentDisplay->rootXOrigin = strtol(value+1, &endpt, 10); - dmxConfigCurrentDisplay->rootYOrigin = strtol(endpt+1, NULL, 10); + value = XawDialogGetValueString(eddialog2); + dmxConfigCurrentDisplay->rootXOrigin = strtol(value + 1, &endpt, 10); + dmxConfigCurrentDisplay->rootYOrigin = strtol(endpt + 1, NULL, 10); XtPopdown(edpopup); dmxConfigSetupCnamemenu(); dmxConfigCanvasDraw(NULL); dmxConfigNotSaved = 1; } -static void dmxConfigEDCanCallback(Widget w, XtPointer closure, - XtPointer callData) +static void +dmxConfigEDCanCallback(Widget w, XtPointer closure, XtPointer callData) { - if (dmxConfigNewDisplay) dmxConfigDDCallback(w, closure, callData); + if (dmxConfigNewDisplay) + dmxConfigDDCallback(w, closure, callData); dmxConfigNewDisplay = NULL; XtPopdown(edpopup); } -static void dmxConfigOkAction(Widget w, XEvent *event, - String *params, Cardinal *num_params) +static void +dmxConfigOkAction(Widget w, XEvent * event, + String * params, Cardinal * num_params) { Widget p = XtParent(w); Widget t; - if (p == opendialog) dmxConfigOkCallback(w, NULL, NULL); + if (p == opendialog) + dmxConfigOkCallback(w, NULL, NULL); if (p == ecdialog0) { t = XtNameToWidget(ecdialog1, "value"); XWarpPointer(XtDisplay(t), None, XtWindow(t), 0, 0, 0, 0, 0, 10); } - if (p == ecdialog1) dmxConfigECOkCallback(w, NULL, NULL); + if (p == ecdialog1) + dmxConfigECOkCallback(w, NULL, NULL); if (p == eddialog0) { t = XtNameToWidget(eddialog1, "value"); @@ -866,322 +946,285 @@ static void dmxConfigOkAction(Widget w, XEvent *event, t = XtNameToWidget(eddialog2, "value"); XWarpPointer(XtDisplay(t), None, XtWindow(t), 0, 0, 0, 0, 0, 10); } - if (p == eddialog2) dmxConfigEDOkCallback(w, NULL, NULL); + if (p == eddialog2) + dmxConfigEDOkCallback(w, NULL, NULL); } -int main(int argc, char **argv) +int +main(int argc, char **argv) { - XtAppContext appContext; - Widget toplevel; - Widget parent, menubox, bottombox, databox, canvasbox; - Widget filebutton, helpbutton; - Widget filemenu, openbutton, savebutton, quitbutton; - Widget helpmenu, aboutbutton, aboutbox, aboutok; - Widget quitbox, quitok, quitcan; - Widget ncbutton; - Widget canbutton; - Widget ecbox, ecokbutton, eccanbutton; - Widget edbox, edokbutton; - Widget edcanbutton; - /* FIXME: add meta-i, ctrl,meta-z,v? */ - const char *opentrans = "<Key>Return: openOk()\n\ + XtAppContext appContext; + Widget toplevel; + Widget parent, menubox, bottombox, databox, canvasbox; + Widget filebutton, helpbutton; + Widget filemenu, openbutton, savebutton, quitbutton; + Widget helpmenu, aboutbutton, aboutbox, aboutok; + Widget quitbox, quitok, quitcan; + Widget ncbutton; + Widget canbutton; + Widget ecbox, ecokbutton, eccanbutton; + Widget edbox, edokbutton; + Widget edcanbutton; + + /* FIXME: add meta-i, ctrl,meta-z,v? */ + const char *opentrans = "<Key>Return: openOk()\n\ <Key>Linefeed: openOk()\n\ Ctrl<Key>M: openOk()\n\ Ctrl<Key>J: openOk()\n\ Ctrl<Key>O: noop()\n\ Ctrl<Key>N: noop()\n\ Ctrl<Key>P: noop()"; - const char *canvastrans = + const char *canvastrans = "<Btn3Down>: placeMenu() XtMenuPopup(buttonpopup)"; - XtActionsRec actiontable[] = { - { "openOk", dmxConfigOkAction }, - { "placeMenu", dmxConfigPlaceMenu }, - { "noop", NULL } + XtActionsRec actiontable[] = { + {"openOk", dmxConfigOkAction}, + {"placeMenu", dmxConfigPlaceMenu}, + {"noop", NULL} }; dmxConfigFilename = XtNewString((argc >= 2) ? argv[1] : ""); - toplevel = XtVaAppInitialize(&appContext, "XDmxconfig", - NULL, 0, - &argc, argv, - NULL, - NULL); - - /* Main boxes */ - parent = XtVaCreateManagedWidget("parent", formWidgetClass, toplevel, - XtNorientation, XtorientVertical, - XtNwidth, DMX_MAIN_WIDTH, - XtNheight, DMX_MAIN_HEIGHT, - NULL); - menubox = XtVaCreateManagedWidget("menubox", boxWidgetClass, parent, - XtNborderWidth, 0, - XtNorientation, XtorientHorizontal, - XtNtop, XtChainTop, - NULL); - bottombox = XtVaCreateManagedWidget("bottombox", formWidgetClass, parent, - XtNborderWidth, 0, - XtNfromVert, menubox, - XtNorientation, XtorientHorizontal, - NULL); - databox = XtVaCreateManagedWidget("databox", formWidgetClass, - bottombox, - XtNborderWidth, 0, - XtNhorizDistance, 0, - XtNwidth, DMX_DATA_WIDTH, - XtNheight, DMX_DATA_HEIGHT, - XtNleft, XtChainLeft, - XtNorientation, XtorientVertical, - NULL); - - /* Data */ - cnamebox = XtVaCreateManagedWidget("cnamebox", menuButtonWidgetClass, - databox, - XtNtop, XtChainTop, - XtNjustify, XtJustifyLeft, - XtNwidth, DMX_DATA_WIDTH, - XtNlabel, "", - XtNmenuName, "cnamemenu", - NULL); - cdimbox = XtVaCreateManagedWidget("cdimbox", labelWidgetClass, - databox, - XtNfromVert, cnamebox, - XtNjustify, XtJustifyLeft, - XtNwidth, DMX_DATA_WIDTH, - XtNlabel, "", - NULL); - namebox = XtVaCreateManagedWidget("namebox", labelWidgetClass, databox, - XtNfromVert, cdimbox, - XtNjustify, XtJustifyLeft, - XtNwidth, DMX_DATA_WIDTH, - XtNlabel, "", - NULL); - dimbox = XtVaCreateManagedWidget("dimbox", labelWidgetClass, - databox, - XtNfromVert, namebox, - XtNjustify, XtJustifyLeft, - XtNwidth, DMX_DATA_WIDTH, - XtNlabel, "", - NULL); - rtbox = XtVaCreateManagedWidget("rtbox", labelWidgetClass, - databox, - XtNfromVert, dimbox, - XtNjustify, XtJustifyLeft, - XtNwidth, DMX_DATA_WIDTH, - XtNlabel, "", - NULL); - origbox = XtVaCreateManagedWidget("origbox", labelWidgetClass, - databox, - XtNfromVert, rtbox, - XtNjustify, XtJustifyLeft, - XtNwidth, DMX_DATA_WIDTH, - XtNlabel, "", - NULL); - - /* Canvas */ - canvasbox = XtVaCreateManagedWidget("canvasbox", boxWidgetClass, - bottombox, - XtNborderWidth, 0, - XtNwidth, DMX_CANVAS_WIDTH, - XtNheight, DMX_CANVAS_HEIGHT, - XtNfromHoriz, databox, - NULL); - - canvas = XtVaCreateManagedWidget("canvas", canvasWidgetClass, - canvasbox, - XtNwidth, DMX_CANVAS_WIDTH, - XtNheight, DMX_CANVAS_HEIGHT, - NULL); - - - /* Main menu buttons */ - filebutton = XtVaCreateManagedWidget("File", menuButtonWidgetClass, - menubox, - XtNmenuName, "filemenu", - NULL); - helpbutton = XtVaCreateManagedWidget("Help", menuButtonWidgetClass, - menubox, - XtNmenuName, "helpmenu", - NULL); - - - /* File submenu buttons */ - filemenu = XtVaCreatePopupShell("filemenu", simpleMenuWidgetClass, - filebutton, NULL); - openbutton = XtVaCreateManagedWidget("Open File", smeBSBObjectClass, - filemenu, NULL); - savebutton = XtVaCreateManagedWidget("Save File", smeBSBObjectClass, - filemenu, - NULL); - ncbutton = XtVaCreateManagedWidget("New Global", smeBSBObjectClass, - filemenu, NULL); - ecbutton = XtVaCreateManagedWidget("Edit Global", smeBSBObjectClass, - filemenu, - NULL); - dcbutton = XtVaCreateManagedWidget("Delete Global", smeBSBObjectClass, - filemenu, - NULL); - ndbutton0 = XtVaCreateManagedWidget("New Display", smeBSBObjectClass, - filemenu, - NULL); - quitbutton = XtVaCreateManagedWidget("Quit", smeBSBObjectClass, - filemenu, NULL); - - /* Help submenu button */ - helpmenu = XtVaCreatePopupShell("helpmenu", simpleMenuWidgetClass, - helpbutton, NULL); - aboutbutton = XtVaCreateManagedWidget("About", smeBSBObjectClass, - helpmenu, NULL); - - /* Open popup */ - openpopup = XtVaCreatePopupShell("openpopup", transientShellWidgetClass, - toplevel, NULL); - opendialog = XtVaCreateManagedWidget("opendialog", dialogWidgetClass, - openpopup, - XtNlabel, "Filename: ", - XtNvalue, dmxConfigFilename, - NULL); - okbutton = XtVaCreateManagedWidget("Open", commandWidgetClass, - opendialog, NULL); - canbutton = XtVaCreateManagedWidget("Cancel", commandWidgetClass, - opendialog, NULL); - - /* EC popup */ - ecpopup = XtVaCreatePopupShell("ecpopup", transientShellWidgetClass, - toplevel, NULL); - ecbox = XtVaCreateManagedWidget("ecbox", boxWidgetClass, - ecpopup, NULL); - ecdialog0 = XtVaCreateManagedWidget("ecdialog0", dialogWidgetClass, - ecbox, - XtNlabel, "Name: ", - XtNvalue, "", - NULL); - ecdialog1 = XtVaCreateManagedWidget("ecdialog1", dialogWidgetClass, - ecbox, - XtNlabel, "Dimension: ", - XtNvalue, "", - NULL); - ecokbutton = XtVaCreateManagedWidget("OK", commandWidgetClass, - ecbox, NULL); - eccanbutton = XtVaCreateManagedWidget("Cancel", commandWidgetClass, - ecbox, NULL); - - /* ED popup */ - edpopup = XtVaCreatePopupShell("edpopup", transientShellWidgetClass, - toplevel, NULL); - edbox = XtVaCreateManagedWidget("edbox", boxWidgetClass, - edpopup, NULL); - eddialog0 = XtVaCreateManagedWidget("eddialog0", dialogWidgetClass, - edbox, - XtNlabel, "Display Name: ", - XtNvalue, "", - NULL); - eddialog1 = XtVaCreateManagedWidget("eddialog1", dialogWidgetClass, - edbox, - XtNlabel, "Geometry: ", - XtNvalue, "", - NULL); - eddialog2 = XtVaCreateManagedWidget("eddialog2", dialogWidgetClass, - edbox, - XtNlabel, "Offset: ", - XtNvalue, "", - NULL); - edokbutton = XtVaCreateManagedWidget("OK", commandWidgetClass, - edbox, NULL); - edcanbutton = XtVaCreateManagedWidget("Cancel", commandWidgetClass, - edbox, NULL); - - /* About popup */ - aboutpopup = XtVaCreatePopupShell("aboutpopup",transientShellWidgetClass, - toplevel, NULL); - aboutbox = XtVaCreateManagedWidget("aboutbox", boxWidgetClass, - aboutpopup, NULL); - XtVaCreateManagedWidget("abouttext", labelWidgetClass, - aboutbox, - XtNlabel, DMX_INFO, - NULL); - aboutok = XtVaCreateManagedWidget("OK", commandWidgetClass, - aboutbox, NULL); - - /* Quit popup */ - quitpopup = XtVaCreatePopupShell("quitpopup",transientShellWidgetClass, - toplevel, NULL); - quitbox = XtVaCreateManagedWidget("quitbox", boxWidgetClass, - quitpopup, NULL); - XtVaCreateManagedWidget("quittext", labelWidgetClass, - quitbox, - XtNlabel, - "Changes to the configuration\n" - "been made that have not yet\n" - "been saved. Do you want to\n" - "quit without saving?", - NULL); - quitok = XtVaCreateManagedWidget("Quit WITHOUT Saving", - commandWidgetClass, - quitbox, NULL); - quitcan = XtVaCreateManagedWidget("Continue Editing", - commandWidgetClass, - quitbox, NULL); - - /* Button popup */ - buttonpopup = XtVaCreatePopupShell("buttonpopup", simpleMenuWidgetClass, - toplevel, NULL); - ndbutton1 = XtVaCreateManagedWidget("New Display", smeBSBObjectClass, - buttonpopup, - NULL); - edbutton = XtVaCreateManagedWidget("Edit Display", smeBSBObjectClass, - buttonpopup, - NULL); - ddbutton = XtVaCreateManagedWidget("Delete Display", smeBSBObjectClass, - buttonpopup, - NULL); - - /* Callbacks */ - XtAddCallback(openbutton, XtNcallback, dmxConfigOpenCallback, NULL); - XtAddCallback(savebutton, XtNcallback, dmxConfigSaveCallback, NULL); - XtAddCallback(okbutton, XtNcallback, dmxConfigOkCallback, NULL); - XtAddCallback(canbutton, XtNcallback, dmxConfigCanCallback, NULL); - + toplevel = XtVaAppInitialize(&appContext, "XDmxconfig", + NULL, 0, &argc, argv, NULL, NULL); + + /* Main boxes */ + parent = XtVaCreateManagedWidget("parent", formWidgetClass, toplevel, + XtNorientation, XtorientVertical, + XtNwidth, DMX_MAIN_WIDTH, + XtNheight, DMX_MAIN_HEIGHT, NULL); + menubox = XtVaCreateManagedWidget("menubox", boxWidgetClass, parent, + XtNborderWidth, 0, + XtNorientation, XtorientHorizontal, + XtNtop, XtChainTop, NULL); + bottombox = XtVaCreateManagedWidget("bottombox", formWidgetClass, parent, + XtNborderWidth, 0, + XtNfromVert, menubox, + XtNorientation, XtorientHorizontal, + NULL); + databox = XtVaCreateManagedWidget("databox", formWidgetClass, + bottombox, + XtNborderWidth, 0, + XtNhorizDistance, 0, + XtNwidth, DMX_DATA_WIDTH, + XtNheight, DMX_DATA_HEIGHT, + XtNleft, XtChainLeft, + XtNorientation, XtorientVertical, NULL); + + /* Data */ + cnamebox = XtVaCreateManagedWidget("cnamebox", menuButtonWidgetClass, + databox, + XtNtop, XtChainTop, + XtNjustify, XtJustifyLeft, + XtNwidth, DMX_DATA_WIDTH, + XtNlabel, "", + XtNmenuName, "cnamemenu", NULL); + cdimbox = XtVaCreateManagedWidget("cdimbox", labelWidgetClass, + databox, + XtNfromVert, cnamebox, + XtNjustify, XtJustifyLeft, + XtNwidth, DMX_DATA_WIDTH, + XtNlabel, "", NULL); + namebox = XtVaCreateManagedWidget("namebox", labelWidgetClass, databox, + XtNfromVert, cdimbox, + XtNjustify, XtJustifyLeft, + XtNwidth, DMX_DATA_WIDTH, + XtNlabel, "", NULL); + dimbox = XtVaCreateManagedWidget("dimbox", labelWidgetClass, + databox, + XtNfromVert, namebox, + XtNjustify, XtJustifyLeft, + XtNwidth, DMX_DATA_WIDTH, + XtNlabel, "", NULL); + rtbox = XtVaCreateManagedWidget("rtbox", labelWidgetClass, + databox, + XtNfromVert, dimbox, + XtNjustify, XtJustifyLeft, + XtNwidth, DMX_DATA_WIDTH, + XtNlabel, "", NULL); + origbox = XtVaCreateManagedWidget("origbox", labelWidgetClass, + databox, + XtNfromVert, rtbox, + XtNjustify, XtJustifyLeft, + XtNwidth, DMX_DATA_WIDTH, + XtNlabel, "", NULL); + + /* Canvas */ + canvasbox = XtVaCreateManagedWidget("canvasbox", boxWidgetClass, + bottombox, + XtNborderWidth, 0, + XtNwidth, DMX_CANVAS_WIDTH, + XtNheight, DMX_CANVAS_HEIGHT, + XtNfromHoriz, databox, NULL); + + canvas = XtVaCreateManagedWidget("canvas", canvasWidgetClass, + canvasbox, + XtNwidth, DMX_CANVAS_WIDTH, + XtNheight, DMX_CANVAS_HEIGHT, NULL); + + /* Main menu buttons */ + filebutton = XtVaCreateManagedWidget("File", menuButtonWidgetClass, + menubox, + XtNmenuName, "filemenu", NULL); + helpbutton = XtVaCreateManagedWidget("Help", menuButtonWidgetClass, + menubox, + XtNmenuName, "helpmenu", NULL); + + /* File submenu buttons */ + filemenu = XtVaCreatePopupShell("filemenu", simpleMenuWidgetClass, + filebutton, NULL); + openbutton = XtVaCreateManagedWidget("Open File", smeBSBObjectClass, + filemenu, NULL); + savebutton = XtVaCreateManagedWidget("Save File", smeBSBObjectClass, + filemenu, NULL); + ncbutton = XtVaCreateManagedWidget("New Global", smeBSBObjectClass, + filemenu, NULL); + ecbutton = XtVaCreateManagedWidget("Edit Global", smeBSBObjectClass, + filemenu, NULL); + dcbutton = XtVaCreateManagedWidget("Delete Global", smeBSBObjectClass, + filemenu, NULL); + ndbutton0 = XtVaCreateManagedWidget("New Display", smeBSBObjectClass, + filemenu, NULL); + quitbutton = XtVaCreateManagedWidget("Quit", smeBSBObjectClass, + filemenu, NULL); + + /* Help submenu button */ + helpmenu = XtVaCreatePopupShell("helpmenu", simpleMenuWidgetClass, + helpbutton, NULL); + aboutbutton = XtVaCreateManagedWidget("About", smeBSBObjectClass, + helpmenu, NULL); + + /* Open popup */ + openpopup = XtVaCreatePopupShell("openpopup", transientShellWidgetClass, + toplevel, NULL); + opendialog = XtVaCreateManagedWidget("opendialog", dialogWidgetClass, + openpopup, + XtNlabel, "Filename: ", + XtNvalue, dmxConfigFilename, NULL); + okbutton = XtVaCreateManagedWidget("Open", commandWidgetClass, + opendialog, NULL); + canbutton = XtVaCreateManagedWidget("Cancel", commandWidgetClass, + opendialog, NULL); + + /* EC popup */ + ecpopup = XtVaCreatePopupShell("ecpopup", transientShellWidgetClass, + toplevel, NULL); + ecbox = XtVaCreateManagedWidget("ecbox", boxWidgetClass, ecpopup, NULL); + ecdialog0 = XtVaCreateManagedWidget("ecdialog0", dialogWidgetClass, + ecbox, + XtNlabel, "Name: ", + XtNvalue, "", NULL); + ecdialog1 = XtVaCreateManagedWidget("ecdialog1", dialogWidgetClass, + ecbox, + XtNlabel, "Dimension: ", + XtNvalue, "", NULL); + ecokbutton = XtVaCreateManagedWidget("OK", commandWidgetClass, ecbox, NULL); + eccanbutton = XtVaCreateManagedWidget("Cancel", commandWidgetClass, + ecbox, NULL); + + /* ED popup */ + edpopup = XtVaCreatePopupShell("edpopup", transientShellWidgetClass, + toplevel, NULL); + edbox = XtVaCreateManagedWidget("edbox", boxWidgetClass, edpopup, NULL); + eddialog0 = XtVaCreateManagedWidget("eddialog0", dialogWidgetClass, + edbox, + XtNlabel, "Display Name: ", + XtNvalue, "", NULL); + eddialog1 = XtVaCreateManagedWidget("eddialog1", dialogWidgetClass, + edbox, + XtNlabel, "Geometry: ", + XtNvalue, "", NULL); + eddialog2 = XtVaCreateManagedWidget("eddialog2", dialogWidgetClass, + edbox, + XtNlabel, "Offset: ", + XtNvalue, "", NULL); + edokbutton = XtVaCreateManagedWidget("OK", commandWidgetClass, edbox, NULL); + edcanbutton = XtVaCreateManagedWidget("Cancel", commandWidgetClass, + edbox, NULL); + + /* About popup */ + aboutpopup = XtVaCreatePopupShell("aboutpopup", transientShellWidgetClass, + toplevel, NULL); + aboutbox = XtVaCreateManagedWidget("aboutbox", boxWidgetClass, + aboutpopup, NULL); + XtVaCreateManagedWidget("abouttext", labelWidgetClass, + aboutbox, XtNlabel, DMX_INFO, NULL); + aboutok = XtVaCreateManagedWidget("OK", commandWidgetClass, aboutbox, NULL); + + /* Quit popup */ + quitpopup = XtVaCreatePopupShell("quitpopup", transientShellWidgetClass, + toplevel, NULL); + quitbox = XtVaCreateManagedWidget("quitbox", boxWidgetClass, + quitpopup, NULL); + XtVaCreateManagedWidget("quittext", labelWidgetClass, + quitbox, + XtNlabel, + "Changes to the configuration\n" + "been made that have not yet\n" + "been saved. Do you want to\n" + "quit without saving?", NULL); + quitok = XtVaCreateManagedWidget("Quit WITHOUT Saving", + commandWidgetClass, quitbox, NULL); + quitcan = XtVaCreateManagedWidget("Continue Editing", + commandWidgetClass, quitbox, NULL); + + /* Button popup */ + buttonpopup = XtVaCreatePopupShell("buttonpopup", simpleMenuWidgetClass, + toplevel, NULL); + ndbutton1 = XtVaCreateManagedWidget("New Display", smeBSBObjectClass, + buttonpopup, NULL); + edbutton = XtVaCreateManagedWidget("Edit Display", smeBSBObjectClass, + buttonpopup, NULL); + ddbutton = XtVaCreateManagedWidget("Delete Display", smeBSBObjectClass, + buttonpopup, NULL); + + /* Callbacks */ + XtAddCallback(openbutton, XtNcallback, dmxConfigOpenCallback, NULL); + XtAddCallback(savebutton, XtNcallback, dmxConfigSaveCallback, NULL); + XtAddCallback(okbutton, XtNcallback, dmxConfigOkCallback, NULL); + XtAddCallback(canbutton, XtNcallback, dmxConfigCanCallback, NULL); + XtAppAddActions(appContext, actiontable, XtNumber(actiontable)); XtOverrideTranslations(canvas, XtParseTranslationTable(canvastrans)); XtOverrideTranslations(XtNameToWidget(opendialog, "value"), - XtParseTranslationTable(opentrans)); + XtParseTranslationTable(opentrans)); XtOverrideTranslations(XtNameToWidget(ecdialog0, "value"), - XtParseTranslationTable(opentrans)); + XtParseTranslationTable(opentrans)); XtOverrideTranslations(XtNameToWidget(ecdialog1, "value"), - XtParseTranslationTable(opentrans)); + XtParseTranslationTable(opentrans)); XtOverrideTranslations(XtNameToWidget(eddialog0, "value"), - XtParseTranslationTable(opentrans)); + XtParseTranslationTable(opentrans)); XtOverrideTranslations(XtNameToWidget(eddialog1, "value"), - XtParseTranslationTable(opentrans)); + XtParseTranslationTable(opentrans)); XtOverrideTranslations(XtNameToWidget(eddialog2, "value"), - XtParseTranslationTable(opentrans)); - - XtAddCallback(ncbutton, XtNcallback, dmxConfigNCCallback, NULL); - XtAddCallback(ecbutton, XtNcallback, dmxConfigECCallback, NULL); - XtAddCallback(ecokbutton, XtNcallback, dmxConfigECOkCallback, NULL); - XtAddCallback(eccanbutton, XtNcallback, dmxConfigECCanCallback, NULL); - XtAddCallback(dcbutton, XtNcallback, dmxConfigDCCallback, NULL); - - XtAddCallback(ndbutton0, XtNcallback, dmxConfigNDCallback, NULL); - XtAddCallback(ndbutton1, XtNcallback, dmxConfigNDCallback, NULL); - XtAddCallback(edbutton, XtNcallback, dmxConfigEDCallback, NULL); - XtAddCallback(ddbutton, XtNcallback, dmxConfigDDCallback, NULL); - XtAddCallback(edokbutton, XtNcallback, dmxConfigEDOkCallback, NULL); - XtAddCallback(edcanbutton, XtNcallback, dmxConfigEDCanCallback, NULL); - - XtAddCallback(aboutbutton, XtNcallback, dmxConfigAboutCallback, NULL); - XtAddCallback(aboutok, XtNcallback, dmxConfigAboutOkCallback, NULL); - XtAddCallback(quitok, XtNcallback, dmxConfigQuitOkCallback, NULL); - XtAddCallback(quitcan, XtNcallback, dmxConfigQuitCanCallback, NULL); - - XtAddCallback(quitbutton, XtNcallback, dmxConfigQuitCallback, NULL); - - XtAddCallback(canvas, XtNcallback, dmxConfigCanvasInput, NULL); - XtAddCallback(canvas, XtNcanvasExposeCallback, dmxConfigCanvasExpose,NULL); - XtAddCallback(canvas, XtNcanvasResizeCallback, dmxConfigCanvasResize,NULL); - - if (dmxConfigFilename) dmxConfigReadFile(); - + XtParseTranslationTable(opentrans)); + + XtAddCallback(ncbutton, XtNcallback, dmxConfigNCCallback, NULL); + XtAddCallback(ecbutton, XtNcallback, dmxConfigECCallback, NULL); + XtAddCallback(ecokbutton, XtNcallback, dmxConfigECOkCallback, NULL); + XtAddCallback(eccanbutton, XtNcallback, dmxConfigECCanCallback, NULL); + XtAddCallback(dcbutton, XtNcallback, dmxConfigDCCallback, NULL); + + XtAddCallback(ndbutton0, XtNcallback, dmxConfigNDCallback, NULL); + XtAddCallback(ndbutton1, XtNcallback, dmxConfigNDCallback, NULL); + XtAddCallback(edbutton, XtNcallback, dmxConfigEDCallback, NULL); + XtAddCallback(ddbutton, XtNcallback, dmxConfigDDCallback, NULL); + XtAddCallback(edokbutton, XtNcallback, dmxConfigEDOkCallback, NULL); + XtAddCallback(edcanbutton, XtNcallback, dmxConfigEDCanCallback, NULL); + + XtAddCallback(aboutbutton, XtNcallback, dmxConfigAboutCallback, NULL); + XtAddCallback(aboutok, XtNcallback, dmxConfigAboutOkCallback, NULL); + XtAddCallback(quitok, XtNcallback, dmxConfigQuitOkCallback, NULL); + XtAddCallback(quitcan, XtNcallback, dmxConfigQuitCanCallback, NULL); + + XtAddCallback(quitbutton, XtNcallback, dmxConfigQuitCallback, NULL); + + XtAddCallback(canvas, XtNcallback, dmxConfigCanvasInput, NULL); + XtAddCallback(canvas, XtNcanvasExposeCallback, dmxConfigCanvasExpose, NULL); + XtAddCallback(canvas, XtNcanvasResizeCallback, dmxConfigCanvasResize, NULL); + + if (dmxConfigFilename) + dmxConfigReadFile(); + XtRealizeWidget(toplevel); dmxConfigCopystrings(); dmxConfigSetupCnamemenu(); |