diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-09-10 10:18:20 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-09-10 10:18:20 -0700 |
commit | 4d54d9ad3a46815792c094fbea82351ed61c66d7 (patch) | |
tree | 38fc9ef7a94958d0ef53e3fe732ed9c885df37ce | |
parent | 230df18221211dbbe064c561fa9bcc7ac87c0872 (diff) |
Convert sources to standard X.Org code style
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | chars.c | 126 | ||||
-rw-r--r-- | fstobdf.c | 94 | ||||
-rw-r--r-- | fstobdf.h | 16 | ||||
-rw-r--r-- | header.c | 128 | ||||
-rw-r--r-- | props.c | 110 |
5 files changed, 234 insertions, 240 deletions
@@ -67,16 +67,15 @@ in this Software without prior written authorization from The Open Group. :(nBytes) == 8 ? ((((bits) + 63) >> 3) & ~7) /* pad to 8 bytes */\ : 0) - static void EmitBitmap(FILE *outFile, - FSXFontInfoHeader *fontHeader, - FSXCharInfo *charInfo, - unsigned int encoding, - int bpr, - unsigned char *data) + FSXFontInfoHeader *fontHeader, + FSXCharInfo *charInfo, + unsigned int encoding, + int bpr, + unsigned char *data) { - char *glyphName; + char *glyphName; unsigned int row; /*- @@ -98,65 +97,62 @@ EmitBitmap(FILE *outFile, fprintf(outFile, "STARTCHAR "); glyphName = XKeysymToString((KeySym) encoding); if (glyphName) - fputs(glyphName, outFile); + fputs(glyphName, outFile); else - fprintf(outFile, (fontHeader->char_range.min_char.low > 0 ? - "C%06o" : "C%03o"), encoding); + fprintf(outFile, (fontHeader->char_range.min_char.low > 0 ? + "C%06o" : "C%03o"), encoding); fputc('\n', outFile); fprintf(outFile, "ENCODING %u\n", encoding); fprintf(outFile, "SWIDTH %ld 0\n", - (((long) charInfo->width) * 72000L) / - (pointSize * yResolution)); + (((long) charInfo->width) * 72000L) / (pointSize * yResolution)); fprintf(outFile, "DWIDTH %d 0\n", charInfo->width); fprintf(outFile, "BBX %d %d %d %d\n", - charInfo->right - charInfo->left, - charInfo->ascent + charInfo->descent, - charInfo->left, - -charInfo->descent); + charInfo->right - charInfo->left, + charInfo->ascent + charInfo->descent, + charInfo->left, + -charInfo->descent); if (charInfo->attributes) - fprintf(outFile, "ATTRIBUTES %04x\n", charInfo->attributes); + fprintf(outFile, "ATTRIBUTES %04x\n", charInfo->attributes); /* * emit the bitmap */ fprintf(outFile, "BITMAP\n"); for (row = 0; row < (charInfo->ascent + charInfo->descent); row++) { - unsigned byte; - unsigned bit; - - static unsigned maskTab[] = - { - (1 << 7), (1 << 6), (1 << 5), (1 << 4), - (1 << 3), (1 << 2), (1 << 1), (1 << 0), - }; - - byte = 0; - for (bit = 0; bit < (charInfo->right - charInfo->left); bit++) { - byte |= maskTab[bit & 7] & data[bit >> 3]; - if ((bit & 7) == 7) { - fprintf(outFile, "%02x", byte); - byte = 0; - } - } - if ((bit & 7) != 0) - fprintf(outFile, "%02x", byte); - fputc('\n', outFile); - data += bpr; + unsigned byte; + unsigned bit; + + static unsigned maskTab[] = { + (1 << 7), (1 << 6), (1 << 5), (1 << 4), + (1 << 3), (1 << 2), (1 << 1), (1 << 0), + }; + + byte = 0; + for (bit = 0; bit < (charInfo->right - charInfo->left); bit++) { + byte |= maskTab[bit & 7] & data[bit >> 3]; + if ((bit & 7) == 7) { + fprintf(outFile, "%02x", byte); + byte = 0; + } + } + if ((bit & 7) != 0) + fprintf(outFile, "%02x", byte); + fputc('\n', outFile); + data += bpr; } fprintf(outFile, "ENDCHAR\n"); } - Bool EmitCharacters(FILE *outFile, - FSServer *fontServer, - FSXFontInfoHeader *fontHeader, - Font fontID) + FSServer *fontServer, + FSXFontInfoHeader *fontHeader, + Font fontID) { FSXCharInfo *extents; FSXCharInfo *charInfo; unsigned int encoding; - FSOffset *offsets; + FSOffset *offsets; unsigned char *glyph; unsigned char *glyphs; unsigned int nChars; @@ -170,26 +166,25 @@ EmitCharacters(FILE *outFile, nChars = 0; - format = BYTE_ORDER | BIT_ORDER | SCANLINE_UNIT | - SCANLINE_PAD | EXTENTS; + format = BYTE_ORDER | BIT_ORDER | SCANLINE_UNIT | SCANLINE_PAD | EXTENTS; firstCharLow = fontHeader->char_range.min_char.low; firstCharHigh = fontHeader->char_range.min_char.high; lastCharLow = fontHeader->char_range.max_char.low; lastCharHigh = fontHeader->char_range.max_char.high; (void) FSQueryXExtents16(fontServer, fontID, True, (FSChar2b *) 0, 0, - &extents); + &extents); (void) FSQueryXBitmaps16(fontServer, fontID, format, True, (FSChar2b *) 0, - 0, &offsets, &glyphs); + 0, &offsets, &glyphs); charInfo = extents; /* calculate the actual number of chars */ - for (chHigh = 0; chHigh <= (lastCharHigh-firstCharHigh); chHigh++) { - for (chLow = 0; chLow <= (lastCharLow-firstCharLow); chLow++) { - if ((charInfo->width != 0) || (charInfo->left != charInfo->right)) - nChars++; - charInfo++; - } + for (chHigh = 0; chHigh <= (lastCharHigh - firstCharHigh); chHigh++) { + for (chLow = 0; chLow <= (lastCharLow - firstCharLow); chLow++) { + if ((charInfo->width != 0) || (charInfo->left != charInfo->right)) + nChars++; + charInfo++; + } } fprintf(outFile, "CHARS %u\n", nChars); @@ -200,18 +195,19 @@ EmitCharacters(FILE *outFile, charInfo = extents; glyph = glyphs; for (chHigh = firstCharHigh; chHigh <= lastCharHigh; chHigh++) { - for (chLow = firstCharLow; chLow <= lastCharLow; chLow++) { - int bpr; - - bpr = GLWIDTHBYTESPADDED((charInfo->right - charInfo->left), - SCANLINE_PAD_BYTES); - encoding=(chHigh << 8)+chLow; - if ((charInfo->width != 0) || (charInfo->right != charInfo->left)) - EmitBitmap(outFile, fontHeader, charInfo, encoding, bpr, glyph); - glyph = glyphs + - offsets[encoding-((firstCharHigh << 8)+firstCharLow) + 1].position; - charInfo++; - } + for (chLow = firstCharLow; chLow <= lastCharLow; chLow++) { + int bpr; + + bpr = GLWIDTHBYTESPADDED((charInfo->right - charInfo->left), + SCANLINE_PAD_BYTES); + encoding = (chHigh << 8) + chLow; + if ((charInfo->width != 0) || (charInfo->right != charInfo->left)) + EmitBitmap(outFile, fontHeader, charInfo, encoding, bpr, glyph); + glyph = glyphs + + offsets[encoding - ((firstCharHigh << 8) + firstCharLow) + + 1].position; + charInfo++; + } } FSFree((char *) extents); FSFree((char *) glyphs); @@ -44,7 +44,7 @@ in this Software without prior written authorization from The Open Group. */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include <stdio.h> @@ -59,9 +59,8 @@ usage(const char *progName, const char *msg) if (msg) fprintf(stderr, "%s: %s\n", progName, msg); fprintf(stderr, - "Usage: %s [-server <font server>] -fn <font name>\n" - " or: %s -version\n", - progName, progName); + "Usage: %s [-server <font server>] -fn <font name>\n" + " or: %s -version\n", progName, progName); exit(0); } @@ -75,79 +74,78 @@ Fail(const char *progName) int main(int argc, char *argv[]) { - FSServer *fontServer; - Font fontID, - dummy; + FSServer *fontServer; + Font fontID, dummy; FSBitmapFormat bitmapFormat; FSXFontInfoHeader fontHeader; - FSPropInfo propInfo; + FSPropInfo propInfo; FSPropOffset *propOffsets; unsigned char *propData; - FILE *outFile; - char *fontName; - char *serverName; - int i; + FILE *outFile; + char *fontName; + char *serverName; + int i; fontName = NULL; serverName = NULL; outFile = stdout; for (i = 1; i < argc; i++) { - if (!strncmp(argv[i], "-s", 2)) { - if (argv[++i]) - serverName = argv[i]; - else - usage(argv[0], "-server requires an argument"); - } else if (!strncmp(argv[i], "-fn", 3)) { - if (argv[++i]) - fontName = argv[i]; - else - usage(argv[0], "-fn requires an argument"); - } - else if (!strcmp(argv[i], "-version")) { - printf("%s\n", PACKAGE_STRING); - exit(0); - } - else { - fprintf(stderr, "%s: unrecognized option '%s'\n", - argv[0], argv[i]); - usage(argv[0], NULL); - } + if (!strncmp(argv[i], "-s", 2)) { + if (argv[++i]) + serverName = argv[i]; + else + usage(argv[0], "-server requires an argument"); + } + else if (!strncmp(argv[i], "-fn", 3)) { + if (argv[++i]) + fontName = argv[i]; + else + usage(argv[0], "-fn requires an argument"); + } + else if (!strcmp(argv[i], "-version")) { + printf("%s\n", PACKAGE_STRING); + exit(0); + } + else { + fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], argv[i]); + usage(argv[0], NULL); + } } if (fontName == NULL) - usage(argv[0], "No font name specified"); + usage(argv[0], "No font name specified"); fontServer = FSOpenServer(serverName); if (!fontServer) { - const char *sn = FSServerName(serverName); - if (sn) - fprintf(stderr, "%s: can't open font server \"%s\"\n", - argv[0], sn); - else - usage(argv[0], "No font server specified."); - exit(0); + const char *sn = FSServerName(serverName); + + if (sn) + fprintf(stderr, "%s: can't open font server \"%s\"\n", argv[0], sn); + else + usage(argv[0], "No font server specified."); + exit(0); } bitmapFormat = 0; fontID = FSOpenBitmapFont(fontServer, bitmapFormat, (FSBitmapFormatMask) 0, - fontName, &dummy); + fontName, &dummy); if (!fontID) { - printf("can't open font \"%s\"\n", fontName); - exit(0); + printf("can't open font \"%s\"\n", fontName); + exit(0); } FSQueryXInfo(fontServer, fontID, &fontHeader, &propInfo, &propOffsets, - &propData); + &propData); if (!EmitHeader(outFile, &fontHeader, &propInfo, propOffsets, propData)) - Fail(argv[0]); + Fail(argv[0]); if (!EmitProperties(outFile, &fontHeader, &propInfo, propOffsets, propData)) - Fail(argv[0]); + Fail(argv[0]); if (!EmitCharacters(outFile, fontServer, &fontHeader, fontID)) - Fail(argv[0]); + Fail(argv[0]); fprintf(outFile, "ENDFONT\n"); FSFree((char *) propOffsets); FSFree((char *) propData); - exit (0); + exit(0); } @@ -26,14 +26,14 @@ #include <X11/fonts/FSlib.h> -extern Bool EmitHeader ( FILE *outFile, FSXFontInfoHeader *fontHeader, - FSPropInfo *propInfo, FSPropOffset *propOffsets, - unsigned char *propData ); -extern Bool EmitProperties ( FILE *outFile, FSXFontInfoHeader *fontHeader, - FSPropInfo *propInfo, FSPropOffset *propOffsets, - unsigned char *propData ); -extern Bool EmitCharacters ( FILE *outFile, FSServer *fontServer, - FSXFontInfoHeader *fontHeader, Font fontID ); +extern Bool EmitHeader(FILE *outFile, FSXFontInfoHeader *fontHeader, + FSPropInfo *propInfo, FSPropOffset *propOffsets, + unsigned char *propData); +extern Bool EmitProperties(FILE *outFile, FSXFontInfoHeader *fontHeader, + FSPropInfo *propInfo, FSPropOffset *propOffsets, + unsigned char *propData); +extern Bool EmitCharacters(FILE *outFile, FSServer *fontServer, + FSXFontInfoHeader *fontHeader, Font fontID); extern unsigned long yResolution; /* intended vertical resolution for font */ extern unsigned long pointSize; /* font height in points */ @@ -49,11 +49,10 @@ in this Software without prior written authorization from The Open Group. #include <string.h> #include "fstobdf.h" -unsigned long pointSize; -unsigned long yResolution; +unsigned long pointSize; +unsigned long yResolution; -static const char *warning[] = -{ +static const char *warning[] = { "COMMENT ", "COMMENT WARNING: This bdf file was generated from a font server using", "COMMENT fstobdf. The resulting font is subject to the same copyright,", @@ -66,10 +65,10 @@ static const char *warning[] = static char * FindStringProperty(const char *propName, - unsigned int *propLength, - FSPropInfo *propInfo, - FSPropOffset *propOffsets, - unsigned char *propData) + unsigned int *propLength, + FSPropInfo *propInfo, + FSPropOffset *propOffsets, + unsigned char *propData) { FSPropOffset *propOffset; unsigned int length; @@ -78,24 +77,25 @@ FindStringProperty(const char *propName, propOffset = &propOffsets[0]; length = (unsigned int) strlen(propName); for (i = propInfo->num_offsets; i--; propOffset++) { - if (propOffset->type == PropTypeString) { + if (propOffset->type == PropTypeString) { #ifdef DEBUG - char pname[256]; + char pname[256]; - memcpy(pname, propData + propOffset->name.position, + memcpy(pname, propData + propOffset->name.position, propOffset->name.length); - pname[propOffset->name.length] = '\0'; - fprintf(stderr, "prop name: %s (len %d)\n", - pname, propOffset->name.length); + pname[propOffset->name.length] = '\0'; + fprintf(stderr, "prop name: %s (len %d)\n", + pname, propOffset->name.length); #endif - if ((propOffset->name.length == length) && - !strncmp((char*)propData + propOffset->name.position, propName, length)) { - *propLength = propOffset->value.length; - return (char *)(propData + propOffset->value.position); - } - } + if ((propOffset->name.length == length) && + !strncmp((char *) propData + propOffset->name.position, + propName, length)) { + *propLength = propOffset->value.length; + return (char *) (propData + propOffset->value.position); + } + } } *propLength = 0; return (NULL); @@ -103,10 +103,10 @@ FindStringProperty(const char *propName, static int FindNumberProperty(const char *propName, - unsigned long *propValue, - FSPropInfo *propInfo, - FSPropOffset *propOffsets, - unsigned char *propData) + unsigned long *propValue, + FSPropInfo *propInfo, + FSPropOffset *propOffsets, + unsigned char *propData) { FSPropOffset *propOffset; unsigned int i; @@ -115,14 +115,15 @@ FindNumberProperty(const char *propName, propOffset = &propOffsets[0]; length = (unsigned int) strlen(propName); for (i = propInfo->num_offsets; i--; propOffset++) { - if ((propOffset->type == PropTypeSigned) || - (propOffset->type == PropTypeUnsigned)) { - if ((propOffset->name.length == length) && - !strncmp((char*)propData + propOffset->name.position, propName, length)) { - *propValue = propOffset->value.position; - return (propOffset->type); - } - } + if ((propOffset->type == PropTypeSigned) || + (propOffset->type == PropTypeUnsigned)) { + if ((propOffset->name.length == length) && + !strncmp((char *) propData + propOffset->name.position, + propName, length)) { + *propValue = propOffset->value.position; + return (propOffset->type); + } + } } return (-1); } @@ -133,14 +134,14 @@ FindNumberProperty(const char *propName, */ Bool EmitHeader(FILE *outFile, - FSXFontInfoHeader *fontHeader, - FSPropInfo *propInfo, - FSPropOffset *propOffsets, - unsigned char *propData) + FSXFontInfoHeader *fontHeader, + FSPropInfo *propInfo, + FSPropOffset *propOffsets, + unsigned char *propData) { unsigned int len; - int type; - char *cp; + int type; + char *cp; const char **cpp; unsigned long xResolution; @@ -149,27 +150,27 @@ EmitHeader(FILE *outFile, /* * find COPYRIGHT message and print it first, followed by warning */ - cp = FindStringProperty("COPYRIGHT", &len, propInfo, propOffsets, - propData); + cp = FindStringProperty("COPYRIGHT", &len, propInfo, propOffsets, propData); if (cp) { - fprintf(outFile, "COMMENT \nCOMMENT "); - fwrite(cp, 1, len, outFile); - fputc('\n', outFile); + fprintf(outFile, "COMMENT \nCOMMENT "); + fwrite(cp, 1, len, outFile); + fputc('\n', outFile); } for (cpp = warning; *cpp; cpp++) - fprintf(outFile, "%s\n", *cpp); + fprintf(outFile, "%s\n", *cpp); /* * FONT name */ cp = FindStringProperty("FONT", &len, propInfo, propOffsets, propData); if (cp) { - fprintf(outFile, "FONT "); - fwrite(cp, 1, len, outFile); - fputc('\n', outFile); - } else { - fprintf(stderr, "unable to find FONT property\n"); - return (False); + fprintf(outFile, "FONT "); + fwrite(cp, 1, len, outFile); + fputc('\n', outFile); + } + else { + fprintf(stderr, "unable to find FONT property\n"); + return (False); } /* @@ -178,34 +179,33 @@ EmitHeader(FILE *outFile, * Get XLFD values if possible, else fake it */ type = FindNumberProperty("RESOLUTION_X", &xResolution, propInfo, - propOffsets, propData); + propOffsets, propData); if ((type != PropTypeUnsigned) && (type != PropTypeSigned)) - xResolution = 72; + xResolution = 72; type = FindNumberProperty("RESOLUTION_Y", &yResolution, propInfo, - propOffsets, propData); + propOffsets, propData); if ((type != PropTypeUnsigned) && (type != PropTypeSigned)) - yResolution = 72; + yResolution = 72; type = FindNumberProperty("POINT_SIZE", &pointSize, propInfo, - propOffsets, propData); + propOffsets, propData); if ((type == PropTypeUnsigned) || (type == PropTypeSigned)) - pointSize = (pointSize + 5) / 10; + pointSize = (pointSize + 5) / 10; else - pointSize = ((fontHeader->font_ascent + fontHeader->font_descent) - * 72) / yResolution; + pointSize = ((fontHeader->font_ascent + fontHeader->font_descent) + * 72) / yResolution; - fprintf(outFile, "SIZE %lu %lu %lu\n", pointSize, xResolution, - yResolution); + fprintf(outFile, "SIZE %lu %lu %lu\n", pointSize, xResolution, yResolution); /* * FONTBOUNDINGBOX width height xoff yoff * */ fprintf(outFile, "FONTBOUNDINGBOX %d %d %d %d\n", - fontHeader->max_bounds.right - fontHeader->min_bounds.left, - fontHeader->max_bounds.ascent + fontHeader->max_bounds.descent, - fontHeader->min_bounds.left, - -fontHeader->max_bounds.descent); + fontHeader->max_bounds.right - fontHeader->min_bounds.left, + fontHeader->max_bounds.ascent + fontHeader->max_bounds.descent, + fontHeader->min_bounds.left, + -fontHeader->max_bounds.descent); return (True); } @@ -56,27 +56,27 @@ AddQuotes(unsigned char *string, unsigned int length) end = string + length; for (cp = &new[1]; string < end; cp++, string++) { - *cp = *string; - if (*cp == '"') - *++cp = '"'; + *cp = *string; + if (*cp == '"') + *++cp = '"'; } *cp++ = '"'; *cp = '\0'; - return (char *)(new); + return (char *) (new); } Bool EmitProperties(FILE *outFile, - FSXFontInfoHeader *fontHeader, - FSPropInfo *propInfo, - FSPropOffset *propOffsets, - unsigned char *propData) + FSXFontInfoHeader *fontHeader, + FSPropInfo *propInfo, + FSPropOffset *propOffsets, + unsigned char *propData) { - unsigned int nProperties; + unsigned int nProperties; FSPropOffset *property; - Bool needDefaultChar; - Bool needFontAscent; - Bool needFontDescent; + Bool needDefaultChar; + Bool needFontAscent; + Bool needFontDescent; needDefaultChar = True; needFontAscent = True; @@ -84,60 +84,60 @@ EmitProperties(FILE *outFile, nProperties = propInfo->num_offsets; for (property = &propOffsets[0]; nProperties--; property++) { - char *name; - unsigned int length; - - name = (char *)propData + property->name.position; - length = property->name.length; - - if ((length == 12) && (!strncmp(name, "DEFAULT_CHAR", 12))) - needDefaultChar = False; - else if ((length == 11) && (!strncmp(name, "FONT_ASCENT", 11))) - needFontAscent = False; - else if ((length == 12) && (!strncmp(name, "FONT_DESCENT", 12))) - needFontDescent = False; + char *name; + unsigned int length; + + name = (char *) propData + property->name.position; + length = property->name.length; + + if ((length == 12) && (!strncmp(name, "DEFAULT_CHAR", 12))) + needDefaultChar = False; + else if ((length == 11) && (!strncmp(name, "FONT_ASCENT", 11))) + needFontAscent = False; + else if ((length == 12) && (!strncmp(name, "FONT_DESCENT", 12))) + needFontDescent = False; } nProperties = propInfo->num_offsets; fprintf(outFile, "STARTPROPERTIES %d\n", nProperties + - (needDefaultChar ? 1 : 0) + (needFontAscent ? 1 : 0) + - (needFontDescent ? 1 : 0)); + (needDefaultChar ? 1 : 0) + (needFontAscent ? 1 : 0) + + (needFontDescent ? 1 : 0)); for (property = &propOffsets[0]; nProperties--; property++) { - unsigned long value; - - /* Don't emit properties that are computed by bdftosnf */ - - fwrite(propData + property->name.position, 1, property->name.length, - outFile); - fputc(' ', outFile); - - value = property->value.position; - switch (property->type) { - case PropTypeString: - fprintf(outFile, "%s\n", AddQuotes(propData + value, - property->value.length)); - break; - case PropTypeUnsigned: - fprintf(outFile, "%lu\n", value); - break; - case PropTypeSigned: - fprintf(outFile, "%ld\n", (signed long) value); - break; - default: - fprintf(stderr, "unknown property type\n"); - return (False); - } + unsigned long value; + + /* Don't emit properties that are computed by bdftosnf */ + + fwrite(propData + property->name.position, 1, property->name.length, + outFile); + fputc(' ', outFile); + + value = property->value.position; + switch (property->type) { + case PropTypeString: + fprintf(outFile, "%s\n", AddQuotes(propData + value, + property->value.length)); + break; + case PropTypeUnsigned: + fprintf(outFile, "%lu\n", value); + break; + case PropTypeSigned: + fprintf(outFile, "%ld\n", (signed long) value); + break; + default: + fprintf(stderr, "unknown property type\n"); + return (False); + } } if (needDefaultChar) { - fprintf(outFile, "DEFAULT_CHAR %lu\n", - (long) (fontHeader->default_char.high << 8) - | (fontHeader->default_char.low)); + fprintf(outFile, "DEFAULT_CHAR %lu\n", + (long) (fontHeader->default_char.high << 8) + | (fontHeader->default_char.low)); } if (needFontAscent) - fprintf(outFile, "FONT_ASCENT %d\n", fontHeader->font_ascent); + fprintf(outFile, "FONT_ASCENT %d\n", fontHeader->font_ascent); if (needFontDescent) - fprintf(outFile, "FONT_DESCENT %d\n", fontHeader->font_descent); + fprintf(outFile, "FONT_DESCENT %d\n", fontHeader->font_descent); fprintf(outFile, "ENDPROPERTIES\n"); return (True); } |