summaryrefslogtreecommitdiff
path: root/xlsfonts.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-12-05 15:41:28 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-12-16 10:17:02 -0800
commit2b9d8f5bac5d2352f8021548b4852014ed683b2c (patch)
tree5d946a5b389ac2741323ca2800b273f1e4be9987 /xlsfonts.c
parente53bf74c4662c8473690c7f5fb00cd80fb86fdd7 (diff)
Fix -Wincompatible-pointer-types warning from gcc (issue #1)
xlsfonts.c: In function ‘get_list’: xlsfonts.c:204:23: warning: assignment to ‘char **’ from incompatible pointer type ‘const char **’ [-Wincompatible-pointer-types] 204 | fonts = &pattern; | ^ v2: Split the open vs. list code to allow preserving the constness of the argument to get_list, at the cost of less code sharing between the two paths Closes: #1 Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xlsfonts.c')
-rw-r--r--xlsfonts.c105
1 files changed, 59 insertions, 46 deletions
diff --git a/xlsfonts.c b/xlsfonts.c
index b834637..0afc53f 100644
--- a/xlsfonts.c
+++ b/xlsfonts.c
@@ -58,7 +58,7 @@ static int font_cnt = 0;
static int min_max;
typedef struct {
- char *name;
+ const char *name;
XFontStruct *info;
} FontList;
@@ -73,7 +73,7 @@ static int IgnoreError(Display *disp, XErrorEvent *event);
static void PrintProperty(XFontProp *prop);
static void ComputeFontType(XFontStruct *fs);
static void print_character_metrics(register XFontStruct *info);
-static void do_query_font(Display *dpy, char *name);
+static void do_query_font(Display *dpy, const char *name);
void
usage(const char *errmsg)
@@ -191,57 +191,70 @@ main(int argc, char **argv)
static void
get_list(const char *pattern)
{
- int available = nnames + 1, i;
- char **fonts;
XFontStruct *info;
- /* Get list of fonts matching pattern */
- for (;;) {
- if (open_instead_of_list) {
- info = XLoadQueryFont(dpy, pattern);
+ if (open_instead_of_list) {
+ info = XLoadQueryFont(dpy, pattern);
- if (info) {
- fonts = &pattern;
- available = 1;
- XUnloadFont(dpy, info->fid);
- }
- else {
- fonts = NULL;
- }
- break;
+ if (info == NULL) {
+ fprintf(stderr, "%s: pattern \"%s\" unmatched\n",
+ program_name, pattern);
+ return;
}
- if (long_list == L_MEDIUM)
- fonts = XListFontsWithInfo(dpy, pattern, nnames, &available, &info);
- else
- fonts = XListFonts(dpy, pattern, nnames, &available);
- if (fonts == NULL || available < nnames)
- break;
- if (long_list == L_MEDIUM)
- XFreeFontInfo(fonts, info, available);
- else
- XFreeFontNames(fonts);
- nnames = available * 2;
- }
-
- if (fonts == NULL) {
- fprintf(stderr, "%s: pattern \"%s\" unmatched\n",
- program_name, pattern);
- return;
- }
-
- font_list = realloc(font_list, (font_cnt + available) * sizeof(FontList));
- if (font_list == NULL)
- Fatal_Error("Out of memory!");
- for (i = 0; i < available; i++) {
- font_list[font_cnt].name = fonts[i];
- if (long_list == L_MEDIUM)
- font_list[font_cnt].info = info + i;
- else
+ font_list = realloc(font_list, (font_cnt + 1) * sizeof(FontList));
+ if (font_list == NULL)
+ Fatal_Error("Out of memory!");
+ font_list[font_cnt].name = pattern;
+ if (long_list == L_MEDIUM) {
+ font_list[font_cnt].info = info;
+ XUnloadFont(dpy, info->fid);
+ }
+ else {
font_list[font_cnt].info = NULL;
-
+ XFreeFont(dpy, info);
+ }
font_cnt++;
}
+ else {
+ /* Get list of fonts matching pattern */
+ int available = nnames + 1;
+ char **fonts;
+
+ for (;;) {
+ if (long_list == L_MEDIUM)
+ fonts = XListFontsWithInfo(dpy, pattern, nnames, &available,
+ &info);
+ else
+ fonts = XListFonts(dpy, pattern, nnames, &available);
+ if (fonts == NULL) {
+ fprintf(stderr, "%s: pattern \"%s\" unmatched\n",
+ program_name, pattern);
+ return;
+ }
+ if (available < nnames)
+ break;
+ if (long_list == L_MEDIUM)
+ XFreeFontInfo(fonts, info, available);
+ else
+ XFreeFontNames(fonts);
+ nnames = available * 2;
+ }
+
+ font_list = realloc(font_list,
+ (font_cnt + available) * sizeof(FontList));
+ if (font_list == NULL)
+ Fatal_Error("Out of memory!");
+ for (int i = 0; i < available; i++) {
+ font_list[font_cnt].name = fonts[i];
+ if (long_list == L_MEDIUM)
+ font_list[font_cnt].info = info + i;
+ else
+ font_list[font_cnt].info = NULL;
+
+ font_cnt++;
+ }
+ }
}
static int
@@ -625,7 +638,7 @@ print_character_metrics(register XFontStruct *info)
}
static void
-do_query_font(Display *display, char *name)
+do_query_font(Display *display, const char *name)
{
register int i;
register XFontStruct *info = XLoadQueryFont(display, name);