fstobdf.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. Copyright 1990, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. * Copyright 1990 Network Computing Devices;
  20. * Portions Copyright 1987 by Digital Equipment Corporation
  21. *
  22. * Permission to use, copy, modify, distribute, and sell this software and
  23. * its documentation for any purpose is hereby granted without fee, provided
  24. * that the above copyright notice appear in all copies and that both that
  25. * copyright notice and this permission notice appear in supporting
  26. * documentation, and that the names of Network Computing Devices, or Digital
  27. * not be used in advertising or publicity pertaining to distribution
  28. * of the software without specific, written prior permission.
  29. *
  30. * NETWORK COMPUTING DEVICES, AND DIGITAL DISCLAIM ALL WARRANTIES WITH
  31. * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  32. * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES,
  33. * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  34. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  35. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  36. * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  37. * THIS SOFTWARE.
  38. */
  39. #ifdef HAVE_CONFIG_H
  40. # include "config.h"
  41. #endif
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #include "fstobdf.h"
  46. static void _X_NORETURN _X_COLD
  47. usage(const char *progName, const char *msg)
  48. {
  49. if (msg)
  50. fprintf(stderr, "%s: %s\n", progName, msg);
  51. fprintf(stderr,
  52. "Usage: %s [-server <font server>] -fn <font name>\n"
  53. " or: %s -version\n",
  54. progName, progName);
  55. exit(0);
  56. }
  57. static void _X_NORETURN _X_COLD
  58. Fail(const char *progName)
  59. {
  60. fprintf(stderr, "%s: unable to dump font\n", progName);
  61. exit(1);
  62. }
  63. int
  64. main(int argc, char *argv[])
  65. {
  66. FSServer *fontServer;
  67. Font fontID,
  68. dummy;
  69. FSBitmapFormat bitmapFormat;
  70. FSXFontInfoHeader fontHeader;
  71. FSPropInfo propInfo;
  72. FSPropOffset *propOffsets;
  73. unsigned char *propData;
  74. FILE *outFile;
  75. char *fontName;
  76. char *serverName;
  77. int i;
  78. fontName = NULL;
  79. serverName = NULL;
  80. outFile = stdout;
  81. for (i = 1; i < argc; i++) {
  82. if (!strncmp(argv[i], "-s", 2)) {
  83. if (argv[++i])
  84. serverName = argv[i];
  85. else
  86. usage(argv[0], "-server requires an argument");
  87. } else if (!strncmp(argv[i], "-fn", 3)) {
  88. if (argv[++i])
  89. fontName = argv[i];
  90. else
  91. usage(argv[0], "-fn requires an argument");
  92. }
  93. else if (!strcmp(argv[i], "-version")) {
  94. printf("%s\n", PACKAGE_STRING);
  95. exit(0);
  96. }
  97. else {
  98. fprintf(stderr, "%s: unrecognized option '%s'\n",
  99. argv[0], argv[i]);
  100. usage(argv[0], NULL);
  101. }
  102. }
  103. if (fontName == NULL)
  104. usage(argv[0], "No font name specified");
  105. fontServer = FSOpenServer(serverName);
  106. if (!fontServer) {
  107. const char *sn = FSServerName(serverName);
  108. if (sn)
  109. fprintf(stderr, "%s: can't open font server \"%s\"\n",
  110. argv[0], sn);
  111. else
  112. usage(argv[0], "No font server specified.");
  113. exit(0);
  114. }
  115. bitmapFormat = 0;
  116. fontID = FSOpenBitmapFont(fontServer, bitmapFormat, (FSBitmapFormatMask) 0,
  117. fontName, &dummy);
  118. if (!fontID) {
  119. printf("can't open font \"%s\"\n", fontName);
  120. exit(0);
  121. }
  122. FSQueryXInfo(fontServer, fontID, &fontHeader, &propInfo, &propOffsets,
  123. &propData);
  124. if (!EmitHeader(outFile, &fontHeader, &propInfo, propOffsets, propData))
  125. Fail(argv[0]);
  126. if (!EmitProperties(outFile, &fontHeader, &propInfo, propOffsets, propData))
  127. Fail(argv[0]);
  128. if (!EmitCharacters(outFile, fontServer, &fontHeader, fontID))
  129. Fail(argv[0]);
  130. fprintf(outFile, "ENDFONT\n");
  131. FSFree((char *) propOffsets);
  132. FSFree((char *) propData);
  133. exit (0);
  134. }