|
|
1.1 ! root 1: #include <X11/Xlib.h> ! 2: #include <X11/Xutil.h> ! 3: #include <stdio.h> ! 4: #include "dsimple.h" ! 5: ! 6: #define N_START 1000 /* Maximum # of fonts to start with */ ! 7: ! 8: int long_list; ! 9: int force_columns; ! 10: int force_1column; ! 11: int nnames = N_START; ! 12: int font_cnt; ! 13: int min_max; ! 14: typedef struct { ! 15: char *name; ! 16: XFontStruct *info; ! 17: } FontList; ! 18: FontList *font_list; ! 19: ! 20: ! 21: usage() ! 22: { ! 23: fprintf(stderr,"%s: usage: %s [host:display] [pattern]\n", program_name, ! 24: program_name); ! 25: exit(1); ! 26: } ! 27: ! 28: main(argc, argv) ! 29: int argc; ! 30: char **argv; ! 31: { ! 32: int argcnt, i; ! 33: ! 34: INIT_NAME; ! 35: ! 36: /* Handle command line arguments, open display */ ! 37: Setup_Display_And_Screen(&argc, argv); ! 38: for (argv++, argc--; argc; argv++, argc--) { ! 39: if (argv[0][0] == '-') { ! 40: for (i=1; argv[0][i]; i++) ! 41: switch(argv[0][i]) { ! 42: case 'l': ! 43: long_list++; ! 44: break; ! 45: case 'm': ! 46: min_max++; ! 47: break; ! 48: case 'C': ! 49: force_columns++; ! 50: force_1column = 0; ! 51: break; ! 52: case '1': ! 53: force_1column++; ! 54: force_columns = 0; ! 55: break; ! 56: default: ! 57: usage(); ! 58: break; ! 59: } ! 60: if (i == 1) ! 61: usage(); ! 62: } else { ! 63: argcnt++; ! 64: get_list(argv[0]); ! 65: } ! 66: } ! 67: if (argcnt == 0) ! 68: get_list("*"); ! 69: show_fonts(); ! 70: exit(0); ! 71: } ! 72: ! 73: get_list(pattern) ! 74: char *pattern; ! 75: { ! 76: int available = nnames+1, ! 77: i; ! 78: char **fonts; ! 79: XFontStruct *info; ! 80: ! 81: /* Get list of fonts matching pattern */ ! 82: for (;;) { ! 83: if (long_list) ! 84: fonts = XListFontsWithInfo(dpy, ! 85: pattern, nnames, &available, &info); ! 86: else ! 87: fonts = XListFonts(dpy, pattern, nnames, &available); ! 88: if (fonts == NULL || available < nnames) ! 89: break; ! 90: if (long_list) ! 91: XFreeFontInfo(fonts, info, available); ! 92: else ! 93: XFreeFontNames(fonts); ! 94: nnames = available * 2; ! 95: } ! 96: ! 97: if (fonts == NULL) { ! 98: fprintf(stderr, "%s: pattern \"%s\" unmatched\n", ! 99: program_name, pattern); ! 100: return; ! 101: } ! 102: ! 103: font_list = (FontList *)Realloc(font_list, ! 104: (font_cnt + available) * sizeof(FontList)); ! 105: for (i=0; i<available; i++) { ! 106: font_list[font_cnt].name = fonts[i]; ! 107: if (long_list) ! 108: font_list[font_cnt].info = info + i; ! 109: else ! 110: font_list[font_cnt].info = NULL; ! 111: font_cnt++; ! 112: } ! 113: } ! 114: ! 115: compare(f1, f2) ! 116: FontList *f1, *f2; ! 117: { ! 118: char *p1 = f1->name, ! 119: *p2 = f2->name; ! 120: ! 121: while (*p1 && *p2 && *p1 == *p2) ! 122: p1++, p2++; ! 123: return(*p1 - *p2); ! 124: } ! 125: ! 126: show_fonts() ! 127: { ! 128: int i; ! 129: ! 130: if (font_cnt == 0) ! 131: return; ! 132: ! 133: /* first sort the output */ ! 134: qsort(font_list, font_cnt, sizeof(FontList), compare); ! 135: ! 136: if (long_list) { ! 137: XFontStruct *pfi; ! 138: char *string; ! 139: ! 140: printf("DIR "); ! 141: printf("MIN "); ! 142: printf("MAX "); ! 143: printf("EXIST "); ! 144: printf("DFLT "); ! 145: printf("PROP "); ! 146: printf("ASC "); ! 147: printf("DESC "); ! 148: printf("NAME"); ! 149: printf("\n"); ! 150: for (i=0; i<font_cnt; i++) { ! 151: pfi = font_list[i].info; ! 152: switch(pfi->direction) { ! 153: case FontLeftToRight: string = "-->"; break; ! 154: case FontRightToLeft: string = "<--"; break; ! 155: default: string = "???"; break; ! 156: } ! 157: printf("%-4s", string); ! 158: if (pfi->min_byte1 == 0 ! 159: && pfi->max_byte1 == 0) { ! 160: printf(" %3d ", pfi->min_char_or_byte2); ! 161: printf(" %3d ", pfi->max_char_or_byte2); ! 162: } else { ! 163: printf("*%3d ", pfi->min_byte1); ! 164: printf("*%3d ", pfi->max_byte1); ! 165: } ! 166: printf("%5s ", pfi->all_chars_exist ? "all" : "some"); ! 167: printf("%4d ", pfi->default_char); ! 168: printf("%4d ", pfi->n_properties); ! 169: printf("%3d ", pfi->ascent); ! 170: printf("%4d ", pfi->descent); ! 171: printf("%s\n", font_list[i].name); ! 172: if (min_max) { ! 173: char min[ BUFSIZ ], ! 174: max[ BUFSIZ ]; ! 175: char *pmax = max, ! 176: *pmin = min; ! 177: int w; ! 178: ! 179: strcpy(pmin, " min(l,r,w,a,d) = ("); ! 180: strcpy(pmax, " max(l,r,w,a,d) = ("); ! 181: pmin += strlen(pmin); ! 182: pmax += strlen(pmax); ! 183: ! 184: copy_number(&pmin, &pmax, ! 185: pfi->min_bounds.lbearing, ! 186: pfi->max_bounds.lbearing); ! 187: *pmin++ = *pmax++ = ','; ! 188: copy_number(&pmin, &pmax, ! 189: pfi->min_bounds.rbearing, ! 190: pfi->max_bounds.rbearing); ! 191: *pmin++ = *pmax++ = ','; ! 192: copy_number(&pmin, &pmax, ! 193: pfi->min_bounds.width, ! 194: pfi->max_bounds.width); ! 195: *pmin++ = *pmax++ = ','; ! 196: copy_number(&pmin, &pmax, ! 197: pfi->min_bounds.ascent, ! 198: pfi->max_bounds.ascent); ! 199: *pmin++ = *pmax++ = ','; ! 200: copy_number(&pmin, &pmax, ! 201: pfi->min_bounds.descent, ! 202: pfi->max_bounds.descent); ! 203: *pmin++ = *pmax++ = ')'; ! 204: *pmin = *pmax = '\0'; ! 205: printf("%s\n", min); ! 206: printf("%s\n", max); ! 207: } ! 208: } ! 209: return; ! 210: } ! 211: ! 212: if ((!force_1column && isatty(1)) || force_columns) { ! 213: int width, ! 214: max_width = 0, ! 215: columns, ! 216: lines_per_column, ! 217: j, ! 218: index; ! 219: ! 220: for (i=0; i<font_cnt; i++) { ! 221: width = strlen(font_list[i].name); ! 222: if (width > max_width) ! 223: max_width = width; ! 224: } ! 225: if (max_width == 0) ! 226: Fatal_Error("Max width of font names is 0!"); ! 227: max_width += 3; ! 228: columns = (79 + max_width - 1) / max_width; ! 229: if (font_cnt < columns) ! 230: columns = font_cnt; ! 231: lines_per_column = (font_cnt + columns - 1) / columns; ! 232: ! 233: for (i=0; i<lines_per_column; i++) { ! 234: for (j=0; j<columns; j++) { ! 235: index = j * lines_per_column + i; ! 236: if (index >= font_cnt) ! 237: break; ! 238: if (j+1 == columns) ! 239: printf("%s", font_list[ index ]); ! 240: else ! 241: printf("%-*s", ! 242: max_width, font_list[ index ]); ! 243: } ! 244: printf("\n"); ! 245: } ! 246: return; ! 247: } ! 248: ! 249: for (i=0; i<font_cnt; i++) ! 250: printf("%s\n", font_list[i].name); ! 251: } ! 252: ! 253: max(i, j) ! 254: int i, j; ! 255: { ! 256: if (i > j) ! 257: return (i); ! 258: return(j); ! 259: } ! 260: ! 261: copy_number(pp1, pp2, n1, n2) ! 262: char **pp1, **pp2; ! 263: int n1, n2; ! 264: { ! 265: char *p1 = *pp1; ! 266: char *p2 = *pp2; ! 267: int w; ! 268: ! 269: sprintf(p1, "%d", n1); ! 270: sprintf(p2, "%d", n2); ! 271: w = max(strlen(p1), strlen(p2)); ! 272: sprintf(p1, "%*d", w, n1); ! 273: sprintf(p2, "%*d", w, n2); ! 274: p1 += strlen(p1); ! 275: p2 += strlen(p2); ! 276: *pp1 = p1; ! 277: *pp2 = p2; ! 278: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.