xfsinfo.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * xfsinfo -- report info about a font server
  3. */
  4. /*
  5. Portions Copyright 1987, 1998 The Open Group
  6. Permission to use, copy, modify, distribute, and sell this software and its
  7. documentation for any purpose is hereby granted without fee, provided that
  8. the above copyright notice appear in all copies and that both that
  9. copyright notice and this permission notice appear in supporting
  10. documentation.
  11. The above copyright notice and this permission notice shall be included
  12. in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  16. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  17. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  18. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  19. OTHER DEALINGS IN THE SOFTWARE.
  20. Except as contained in this notice, the name of The Open Group shall
  21. not be used in advertising or otherwise to promote the sale, use or
  22. other dealings in this Software without prior written authorization
  23. from The Open Group.
  24. */
  25. /*
  26. * Copyright 1990 Network Computing Devices;
  27. * Portions Copyright 1987 by Digital Equipment Corporation
  28. *
  29. * Permission to use, copy, modify, distribute, and sell this software and its
  30. * documentation for any purpose is hereby granted without fee, provided that
  31. * the above copyright notice appear in all copies and that both that
  32. * copyright notice and this permission notice appear in supporting
  33. * documentation, and that the names of Network Computing Devices
  34. * or Digital not be used in advertising or
  35. * publicity pertaining to distribution of the software without specific,
  36. * written prior permission. Network Computing Devices and Digital
  37. * make no representations about the
  38. * suitability of this software for any purpose. It is provided "as is"
  39. * without express or implied warranty.
  40. *
  41. * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
  42. * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  43. * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
  44. * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  45. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  46. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  47. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  48. *
  49. */
  50. #ifdef HAVE_CONFIG_H
  51. # include "config.h"
  52. #endif
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55. #include <X11/Xos.h>
  56. #include <X11/fonts/FSlib.h>
  57. static void print_server_info(FSServer *svr);
  58. static void print_catalogue_info(FSServer *svr);
  59. static void print_extension_info(FSServer *svr);
  60. static void print_alternate_info(FSServer *svr);
  61. static char *progname;
  62. static void _X_NORETURN
  63. usage(void)
  64. {
  65. fprintf(stderr, "usage: %s [-server server_name] [-version]\n", progname);
  66. exit(-1);
  67. }
  68. int
  69. main(int argc, char *argv[])
  70. {
  71. FSServer *svr;
  72. char *servername = NULL;
  73. int i;
  74. progname = argv[0];
  75. for (i = 1; i < argc; i++) {
  76. if (strncmp(argv[i], "-s", 2) == 0) {
  77. if (++i >= argc) {
  78. fprintf (stderr, "%s: %s requires an argument\n",
  79. progname, argv[i-1]);
  80. usage();
  81. }
  82. servername = argv[i];
  83. } else if (strcmp(argv[i], "-version") == 0) {
  84. puts(PACKAGE_STRING);
  85. exit(0);
  86. } else {
  87. fprintf (stderr, "%s: unrecognized argument %s\n",
  88. progname, argv[i]);
  89. usage();
  90. }
  91. }
  92. svr = FSOpenServer(servername);
  93. if (!svr) {
  94. if (FSServerName(servername) == NULL) {
  95. if ((svr = FSOpenServer("unix/:-1")) == NULL) {
  96. fprintf(stderr, "%s: no font server defined\n", progname);
  97. exit(1);
  98. }
  99. }
  100. if (!svr) {
  101. fprintf(stderr, "%s: unable to open server \"%s\"\n",
  102. progname, FSServerName(servername));
  103. exit(1);
  104. }
  105. }
  106. print_server_info(svr);
  107. FSCloseServer(svr);
  108. exit(0);
  109. }
  110. static void
  111. print_server_info(FSServer *svr)
  112. {
  113. printf("name of server: %s\n", FSServerString(svr));
  114. printf("version number: %d\n", FSProtocolVersion(svr));
  115. printf("vendor string: %s\n", FSServerVendor(svr));
  116. printf("vendor release number: %d\n", FSVendorRelease(svr));
  117. if (strstr(FSServerVendor(svr), "X.Org")) {
  118. int vendrel = FSVendorRelease(svr);
  119. printf("X.Org xfs version: ");
  120. printf("%d.%d.%d", vendrel / 10000000,
  121. (vendrel / 100000) % 100,
  122. (vendrel / 1000) % 100);
  123. if (vendrel % 1000)
  124. printf(".%d", vendrel % 1000);
  125. printf("\n");
  126. }
  127. printf("maximum request size: %ld longwords (%ld bytes)\n",
  128. FSMaxRequestSize(svr), FSMaxRequestSize(svr) * sizeof(long));
  129. print_catalogue_info(svr);
  130. print_alternate_info(svr);
  131. print_extension_info(svr);
  132. }
  133. static void
  134. print_catalogue_info(FSServer *svr)
  135. {
  136. int n = 0;
  137. char **cats = FSListCatalogues(svr, "*", 1000, &n);
  138. printf("number of catalogues: %d\n", n);
  139. if (cats) {
  140. int i;
  141. for (i = 0; i < n; i++) {
  142. printf(" %s\n", cats[i]);
  143. }
  144. FSFreeCatalogues(cats);
  145. }
  146. }
  147. static void
  148. print_extension_info(FSServer *svr)
  149. {
  150. int n = 0;
  151. char **extlist = FSListExtensions(svr, &n);
  152. printf("number of extensions: %d\n", n);
  153. if (extlist) {
  154. int i;
  155. for (i = 0; i < n; i++) {
  156. printf(" %s\n", extlist[i]);
  157. }
  158. FSFreeExtensionList(extlist);
  159. }
  160. }
  161. static void
  162. print_alternate_info(FSServer *svr)
  163. {
  164. AlternateServer *alts;
  165. int i,
  166. num;
  167. num = FSNumAlternateServers(svr);
  168. printf("Number of alternate servers: %d\n", num);
  169. if (num) {
  170. alts = FSAlternateServers(svr);
  171. for (i = 0; i < num; i++) {
  172. printf(" #%1d\t%s%s\n", i, alts[i].name,
  173. (alts[i].subset) ? "(subset)" : "");
  174. }
  175. }
  176. }