diff options
Diffstat (limited to 'app/xkbprint/psgeom.c')
-rw-r--r-- | app/xkbprint/psgeom.c | 158 |
1 files changed, 98 insertions, 60 deletions
diff --git a/app/xkbprint/psgeom.c b/app/xkbprint/psgeom.c index c43dd10cd..2b441ace2 100644 --- a/app/xkbprint/psgeom.c +++ b/app/xkbprint/psgeom.c @@ -42,9 +42,6 @@ #include <X11/keysym.h> #include <X11/Xutil.h> -#if defined(sgi) -#include <malloc.h> -#endif #include <stdlib.h> @@ -131,16 +128,16 @@ static int nInternalFonts = (sizeof(internalFonts) / sizeof(PSFontDef)); static void ListInternalFonts(FILE *out, int first, int indent) { - register int i, n, nThisLine; + register int i, nThisLine; - for (n = 0; n < first; n++) { + for (int n = 0; n < first; n++) { putc(' ', out); } for (nThisLine = i = 0; i < nInternalFonts; i++) { if (nThisLine == 4) { fprintf(out, ",\n"); - for (n = 0; n < indent; n++) { + for (int n = 0; n < indent; n++) { putc(' ', out); } nThisLine = 0; @@ -160,10 +157,9 @@ static Bool PSIncludeFont(FILE *out, const char *font) { const char **pstr; - register int i; pstr = NULL; - for (i = 0; (i < nInternalFonts) && (pstr == NULL); i++) { + for (int i = 0; (i < nInternalFonts) && (pstr == NULL); i++) { if (uStringEqual(internalFonts[i].name, font)) pstr = internalFonts[i].def; } @@ -262,10 +258,14 @@ PSGRestore(FILE *out, PSState *state) static void PSShapeDef(FILE *out, PSState *state, XkbShapePtr shape) { - int o, p; + int o; XkbOutlinePtr ol; - fprintf(out, "/%s {\n", XkbAtomGetString(state->dpy, shape->name)); + { + char *a = XkbAtomGetString(state->dpy, shape->name); + fprintf(out, "/%s {\n", a); + XFree(a); + } fprintf(out, " gsave translate rotate /SOLID exch def\n"); for (o = 0, ol = shape->outlines; o < shape->num_outlines; o++, ol++) { XkbPointPtr pt; @@ -327,7 +327,7 @@ PSShapeDef(FILE *out, PSState *state, XkbShapePtr shape) if (ol->corner_radius < 1) { fprintf(out, " %3d %3d moveto\n", pt->x, pt->y); pt++; - for (p = 1; p < ol->num_points; p++, pt++) { + for (int p = 1; p < ol->num_points; p++, pt++) { fprintf(out, " %3d %3d lineto\n", pt->x, pt->y); } if ((pt->x != ol->points[0].x) || (pt->y != ol->points[0].y)) @@ -348,7 +348,7 @@ PSShapeDef(FILE *out, PSState *state, XkbShapePtr shape) fprintf(out, " /TY exch def /TX exch def pop pop newpath\n"); fprintf(out, " %% Now draw the shape\n"); fprintf(out, " TX TY moveto\n"); - for (p = 1; p < ol->num_points; p++) { + for (int p = 1; p < ol->num_points; p++) { if (p < (ol->num_points - 1)) last = &pt[p + 1]; else @@ -394,9 +394,10 @@ typedef struct { static void ClearFontStuff(FontStuff *stuff) { - if (stuff && stuff->foundry) + if (stuff) { free(stuff->foundry); - bzero(stuff, sizeof(FontStuff)); + bzero(stuff, sizeof(FontStuff)); + } return; } @@ -601,15 +602,15 @@ PSSetFont(FILE *out, PSState *state, int font, int size, int pts) static void PSProlog(FILE *out, PSState *state) { - register int i; - if (!state->args->wantEPS) { fprintf(out, "%%!PS-Adobe-2.0\n" "%%%%Creator: xkbprint\n"); - if (state->geom->name != None) - fprintf(out, "%%%%Title: %s\n", - XkbAtomGetString(state->dpy, state->geom->name)); + if (state->geom->name != None) { + char *a = XkbAtomGetString(state->dpy, state->geom->name); + fprintf(out, "%%%%Title: %s\n", a); + XFree(a); + } fprintf(out, "%%%%BoundingBox: (atend)\n" "%%%%Pages: 1\n" @@ -652,9 +653,11 @@ PSProlog(FILE *out, PSState *state) fprintf(out, "%%!PS-Adobe-2.0 EPSF-2.0\n"); fprintf(out, "%%%%BoundingBox: 0 0 %d %d\n", w, h); fprintf(out, "%%%%Creator: xkbprint\n"); - if (state->geom->name != None) - fprintf(out, "%%%%Title: %s\n", - XkbAtomGetString(state->dpy, state->geom->name)); + if (state->geom->name != None) { + char *a = XkbAtomGetString(state->dpy, state->geom->name); + fprintf(out, "%%%%Title: %s\n", a); + XFree(a); + } fprintf(out, "%%%%Pages: 1\n"); fprintf(out, "%%%%EndComments\n"); fprintf(out, "%%%%BeginProlog\n"); @@ -691,7 +694,7 @@ PSProlog(FILE *out, PSState *state) if (state->args->wantColor) { XkbGeometryPtr geom = state->geom; - for (i = 0; i < geom->num_colors; i++) { + for (int i = 0; i < geom->num_colors; i++) { PSColorDef(out, state, &geom->colors[i]); } if (state->black < 0) { @@ -709,7 +712,7 @@ PSProlog(FILE *out, PSState *state) PSColorDef(out, state, color); } } - for (i = 0; i < state->geom->num_shapes; i++) { + for (int i = 0; i < state->geom->num_shapes; i++) { PSShapeDef(out, state, &state->geom->shapes[i]); } if (state->args->label == LABEL_SYMBOLS) { @@ -841,8 +844,10 @@ PSPageTrailer(FILE *out, PSState *state) if ((!state->args->wantEPS) && ((state->kbPerPage == 1) || ((state->nPages & 1) == 1) || (state->nPages == state->totalKB))) { + char *a1 = NULL; + if ((name == NULL) && (geom->name != None)) - name = XkbAtomGetString(state->dpy, geom->name); + name = a1 = XkbAtomGetString(state->dpy, geom->name); baseline = 16; if ((name != NULL) || (state->args->label == LABEL_SYMBOLS)) { @@ -852,6 +857,7 @@ PSPageTrailer(FILE *out, PSState *state) if (state->args->label == LABEL_SYMBOLS) { char buf[40], *lbuf; const char *sName = NULL; + char *a2 = NULL; Atom sAtom; if (state->args->nLabelGroups == 1) @@ -874,7 +880,7 @@ PSPageTrailer(FILE *out, PSState *state) else sAtom = None; if (sAtom != None) - sName = XkbAtomGetString(state->dpy, sAtom); + sName = a2 = XkbAtomGetString(state->dpy, sAtom); if (sName == NULL) sName = "(unknown)"; @@ -888,6 +894,7 @@ PSPageTrailer(FILE *out, PSState *state) fprintf(out, "1 -1 scale (%s) show 1 -1 scale\n", lbuf); baseline += 16; free(lbuf); + XFree(a2); } if (name != NULL) { fprintf(out, "kbx kbdscalewidth 0 (%s) centeroffset pop add\n", @@ -896,10 +903,13 @@ PSPageTrailer(FILE *out, PSState *state) fprintf(out, " moveto\n"); fprintf(out, "1 -1 scale (%s) show 1 -1 scale\n", name); baseline += 16; + name = NULL; + XFree(a1); } if (state->args->label == LABEL_KEYCODE) { const char *sName = NULL; char *lbuf; + char *a3 = NULL; Atom sAtom; if (xkb->names != NULL) @@ -907,7 +917,7 @@ PSPageTrailer(FILE *out, PSState *state) else sAtom = None; if (sAtom != None) - sName = XkbAtomGetString(state->dpy, sAtom); + sName = a3 = XkbAtomGetString(state->dpy, sAtom); if (sName == NULL) sName = "(unknown)"; @@ -921,6 +931,7 @@ PSPageTrailer(FILE *out, PSState *state) fprintf(out, "1 -1 scale (%s) show 1 -1 scale\n", lbuf); baseline += 16; free(lbuf); + XFree(a3); } if (state->args->copies > 1) { for (p = 1; p < state->args->copies; p++) @@ -967,17 +978,18 @@ PSDoodad(FILE *out, PSState *state, XkbDoodadPtr doodad) { XkbDescPtr xkb; const char *name, *dname; + char *a1 = NULL, *a2 = NULL; int sz, leading; xkb = state->xkb; if (doodad->any.name != None) - dname = XkbAtomGetString(xkb->dpy, doodad->any.name); + dname = a1 = XkbAtomGetString(xkb->dpy, doodad->any.name); else dname = "NoName"; switch (doodad->any.type) { case XkbOutlineDoodad: case XkbSolidDoodad: - name = XkbAtomGetString(xkb->dpy, + name = a2 = XkbAtomGetString(xkb->dpy, XkbShapeDoodadShape(xkb->geom, &doodad->shape)->name); if (state->args->wantColor) { @@ -997,6 +1009,8 @@ PSDoodad(FILE *out, PSState *state, XkbDoodadPtr doodad) doodad->shape.angle, doodad->shape.left, doodad->shape.top, name, dname); } + name = NULL; + XFree(a2); break; case XkbTextDoodad: fprintf(out, "%% Doodad %s\n", dname); @@ -1041,7 +1055,7 @@ PSDoodad(FILE *out, PSState *state, XkbDoodadPtr doodad) PSGRestore(out, state); break; case XkbIndicatorDoodad: - name = XkbAtomGetString(xkb->dpy, + name = a2 = XkbAtomGetString(xkb->dpy, XkbIndicatorDoodadShape(xkb->geom, &doodad->indicator)-> name); @@ -1053,9 +1067,11 @@ PSDoodad(FILE *out, PSState *state, XkbDoodadPtr doodad) } fprintf(out, "false 0 %d %d %s %% Doodad %s\n", doodad->indicator.left, doodad->indicator.top, name, dname); + name = NULL; + XFree(a2); break; case XkbLogoDoodad: - name = XkbAtomGetString(xkb->dpy, + name = a2 = XkbAtomGetString(xkb->dpy, XkbLogoDoodadShape(xkb->geom, &doodad->logo)->name); if (state->args->wantColor) @@ -1063,8 +1079,11 @@ PSDoodad(FILE *out, PSState *state, XkbDoodadPtr doodad) fprintf(out, "false %d %d %d %s %% Doodad %s\n", doodad->shape.angle, doodad->shape.left, doodad->shape.top, name, dname); + name = NULL; + XFree(a2); break; } + XFree(a1); return; } @@ -1606,7 +1625,7 @@ FindKeysymsByName(XkbDescPtr xkb, char *name, PSState *state, KeyTop *top) int kc; KeySym sym, *syms, topSyms[NLABELS]; int level, group; - int eG, nG, gI, l, g; + int eG, nG, gI; bzero(top, sizeof(KeyTop)); kc = XkbFindKeycodeByName(xkb, name, True); @@ -1620,7 +1639,8 @@ FindKeysymsByName(XkbDescPtr xkb, char *name, PSState *state, KeyTop *top) eG = group; nG = XkbKeyNumGroups(xkb, kc); gI = XkbKeyGroupInfo(xkb, kc); - if ((state->args->wantDiffs) && (eG >= XkbKeyNumGroups(xkb, kc))) + if ((state->args != NULL) && (state->args->wantDiffs) && + (eG >= XkbKeyNumGroups(xkb, kc))) return False; /* XXX was a return with no value */ if (nG == 0) { return False; @@ -1643,10 +1663,10 @@ FindKeysymsByName(XkbDescPtr xkb, char *name, PSState *state, KeyTop *top) break; } } - for (g = 0; g < state->args->nLabelGroups; g++) { + for (int g = 0; g < state->args->nLabelGroups; g++) { if ((eG + g) >= nG) continue; - for (l = 0; l < 2; l++) { + for (int l = 0; l < 2; l++) { int font, sz; if (level + l >= XkbKeyGroupWidth(xkb, kc, (eG + g))) @@ -1756,7 +1776,7 @@ static void PSLabelKey(FILE *out, PSState *state, KeyTop *top, int x, int y, XkbBoundsPtr bounds, int kc, int btm) { - int w, h, i; + int w, h; int row_y[3]; int col_x[3]; int row_h[3]; @@ -1850,7 +1870,7 @@ PSLabelKey(FILE *out, PSState *state, KeyTop *top, int x, int y, case 0: return; } - for (i = 0; i < NLABELS; i++) { + for (int i = 0; i < NLABELS; i++) { if (present[i]) { int size; @@ -1903,8 +1923,17 @@ PSSection(FILE *out, PSState *state, XkbSectionPtr section) xkb = state->xkb; dpy = xkb->dpy; - fprintf(out, "%% Begin Section '%s'\n", (section->name != None ? - XkbAtomGetString(dpy, section-> name) : "NoName")); + { + const char *section_name; + char *atom_name = NULL; + + if (section->name != None) + section_name = atom_name = XkbAtomGetString(dpy, section->name); + else + section_name = "NoName"; + fprintf(out, "%% Begin Section '%s'\n", section_name); + XFree(atom_name); + } PSGSave(out, state); fprintf(out, "%d %d translate\n", section->left, section->top); if (section->angle != 0) @@ -1925,7 +1954,6 @@ PSSection(FILE *out, PSState *state, XkbSectionPtr section) for (r = 0, row = section->rows; r < section->num_rows; r++, row++) { int k; XkbKeyPtr key; - XkbShapePtr shape; if (row->vertical) offset = row->top; @@ -1934,21 +1962,22 @@ PSSection(FILE *out, PSState *state, XkbSectionPtr section) fprintf(out, "%% Begin %s %d\n", row->vertical ? "column" : "row", r + 1); for (k = 0, key = row->keys; k < row->num_keys; k++, key++) { - shape = XkbKeyShape(xkb->geom, key); + XkbShapePtr shape = XkbKeyShape(xkb->geom, key); + char *shape_name = XkbAtomGetString(dpy, shape->name); + offset += key->gap; if (row->vertical) { if (state->args->wantColor) { if (key->color_ndx != state->white) { PSSetColor(out, state, key->color_ndx); fprintf(out, "true 0 %d %d %s %% %s\n", - row->left, offset, - XkbAtomGetString(dpy, shape->name), + row->left, offset, shape_name, XkbKeyNameText(key->name.name, XkbMessage)); } PSSetColor(out, state, state->black); } fprintf(out, "false 0 %d %d %s %% %s\n", row->left, offset, - XkbAtomGetString(dpy, shape->name), + shape_name, XkbKeyNameText(key->name.name, XkbMessage)); offset += shape->bounds.y2; } @@ -1957,23 +1986,22 @@ PSSection(FILE *out, PSState *state, XkbSectionPtr section) if (key->color_ndx != state->white) { PSSetColor(out, state, key->color_ndx); fprintf(out, "true 0 %d %d %s %% %s\n", offset, - row->top, XkbAtomGetString(dpy, shape->name), + row->top, shape_name, XkbKeyNameText(key->name.name, XkbMessage)); } PSSetColor(out, state, state->black); } fprintf(out, "false 0 %d %d %s %% %s\n", offset, row->top, - XkbAtomGetString(dpy, shape->name), + shape_name, XkbKeyNameText(key->name.name, XkbMessage)); offset += shape->bounds.x2; } + XFree(shape_name); } } for (r = 0, row = section->rows; r < section->num_rows; r++, row++) { int k, kc = 0; XkbKeyPtr key; - XkbShapePtr shape; - XkbBoundsRec bounds; if (state->args->label == LABEL_NONE) break; @@ -1989,6 +2017,8 @@ PSSection(FILE *out, PSState *state, XkbSectionPtr section) char *name, *name2, buf[30], buf2[30]; int x, y; KeyTop top; + XkbShapePtr shape; + XkbBoundsRec bounds; shape = XkbKeyShape(xkb->geom, key); XkbComputeShapeTop(shape, &bounds); @@ -2069,20 +2099,26 @@ GeometryToPostScript(FILE *out, XkbFileInfo *pResult, XKBPrintArgs *args) XkbDrawablePtr first, draw; PSState state; Bool dfltBorder; - int i; if ((!pResult) || (!pResult->xkb) || (!pResult->xkb->geom)) return False; - state.xkb = pResult->xkb; - state.dpy = pResult->xkb->dpy; - state.geom = pResult->xkb->geom; - state.color = state.black = state.white = -1; - state.font = -1; - state.nPages = 0; - state.totalKB = 1; - state.kbPerPage = 1; - state.x1 = state.y1 = state.x2 = state.y2 = 0; - state.args = args; + state = (PSState) { + .xkb = pResult->xkb, + .dpy = pResult->xkb->dpy, + .geom = pResult->xkb->geom, + .color = -1, + .black = -1, + .white = -1, + .font = -1, + .nPages = 0, + .totalKB = 1, + .kbPerPage = 1, + .x1 = 0, + .y1 = 0, + .x2 = 0, + .y2 = 0, + .args = args + }; if ((args->label == LABEL_SYMBOLS) && (pResult->xkb->ctrls)) { if (args->nTotalGroups == 0) @@ -2110,11 +2146,13 @@ GeometryToPostScript(FILE *out, XkbFileInfo *pResult, XKBPrintArgs *args) name = XkbAtomGetString(state.dpy, draw->u.doodad->any.name); if ((name != NULL) && (uStrCaseEqual(name, "edges"))) { dfltBorder = False; + XFree(name); break; } + XFree(name); } } - for (i = 0; i < state.totalKB; i++) { + for (int i = 0; i < state.totalKB; i++) { PSPageSetup(out, &state, dfltBorder); for (draw = first; draw != NULL; draw = draw->next) { if (draw->type == XkbDW_Section) |