diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-11-07 16:03:47 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-11-07 16:03:47 -0800 |
commit | 167ad7fa3a339da96798da49d05c3125045a87c2 (patch) | |
tree | cef81cd9a3fc39878ec8a4c874ffe71905877d0a /xhost.c | |
parent | 4b54c211e5e86d6ed62386ad9b7d676808b55766 (diff) |
Use gettext() to localize messages if available
Originally fixed for Solaris in May 2000 by Steve Swales under
Sun bug 4256527 "xhost messages not internationalized"
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xhost.c')
-rw-r--r-- | xhost.c | 89 |
1 files changed, 57 insertions, 32 deletions
@@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2004, 2022, Oracle and/or its affiliates. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -119,6 +119,13 @@ extern int getdomainname(char *name, size_t len); #endif #endif +#ifdef USE_GETTEXT +# include <locale.h> /* setlocale() */ +# include <libintl.h> /* gettext(), textdomain(), etc. */ +#else +# define gettext(a) (a) +#endif + static int change_host(Display *dpy, char *name, Bool add); static const char *get_hostname(XHostAddress *ha); static int local_xerror(Display *dpy, XErrorEvent *rep); @@ -179,15 +186,29 @@ main(int argc, char *argv[]) Bool enabled = False; Display *dpy; +#ifdef USE_GETTEXT + const char *domaindir; + + setlocale(LC_ALL, ""); + textdomain("xhost"); + + /* mainly for debugging */ + if ((domaindir = getenv("TEXTDOMAINDIR")) == NULL) { + domaindir = LOCALEDIR; + } + bindtextdomain("xhost", domaindir); +#endif + ProgramName = argv[0]; if (argc == 2 && !strcmp(argv[1], "-help")) { - fprintf(stderr, "usage: %s [[+-]hostname ...]\n", argv[0]); + fprintf(stderr, gettext("usage: %s [[+-]hostname ...]\n"), argv[0]); exit(1); } if ((dpy = XOpenDisplay(NULL)) == NULL) { - fprintf(stderr, "%s: unable to open display \"%s\"\n", + fprintf(stderr, + gettext("%s: unable to open display \"%s\"\n"), ProgramName, XDisplayName (NULL)); exit(1); } @@ -199,9 +220,9 @@ main(int argc, char *argv[]) sethostent(1); /* don't close the data base each time */ list = XListHosts(dpy, &nhosts, &enabled); if (enabled) - printf ("access control enabled, only authorized clients can connect\n"); + printf (gettext("access control enabled, only authorized clients can connect\n")); else - printf ("access control disabled, clients can connect from any host\n"); + printf (gettext("access control disabled, clients can connect from any host\n")); if (nhosts != 0) { for (i = 0; i < nhosts; i++ ) { @@ -230,16 +251,16 @@ main(int argc, char *argv[]) printf("SI:"); break; default: - printf("<unknown family type %d>:", list[i].family); + printf(gettext("<unknown family type %d>:"), list[i].family); break; } printf ("%s", hostname); } else { - printf ("<unknown address in family %d>", + printf (gettext("<unknown address in family %d>"), list[i].family); } if (nameserver_timedout) { - printf("\t(no nameserver response within %d seconds)\n", + printf(gettext("\t(no nameserver response within %d seconds)\n"), NAMESERVER_TIMEOUT); nameserver_timedout = 0; } else @@ -256,26 +277,26 @@ main(int argc, char *argv[]) if (*arg == '-') { if (!argv[i][1] && ((i+1) == argc)) { - printf ("access control enabled, only authorized clients can connect\n"); + printf (gettext("access control enabled, only authorized clients can connect\n")); XEnableAccessControl(dpy); } else { arg = argv[i][1]? &argv[i][1] : argv[++i]; if (!change_host (dpy, arg, False)) { - fprintf (stderr, "%s: bad hostname \"%s\"\n", + fprintf (stderr, gettext("%s: bad hostname \"%s\"\n"), ProgramName, arg); nfailed++; } } } else { if (*arg == '+' && !argv[i][1] && ((i+1) == argc)) { - printf ("access control disabled, clients can connect from any host\n"); + printf (gettext("access control disabled, clients can connect from any host\n")); XDisableAccessControl(dpy); } else { if (*arg == '+') { arg = argv[i][1]? &argv[i][1] : argv[++i]; } if (!change_host (dpy, arg, True)) { - fprintf (stderr, "%s: bad hostname \"%s\"\n", + fprintf (stderr, gettext("%s: bad hostname \"%s\"\n"), ProgramName, arg); nfailed++; } @@ -316,12 +337,13 @@ change_host(Display *dpy, char *name, Bool add) #endif #endif char *cp; - static const char *add_msg = "being added to access control list"; - static const char *remove_msg = "being removed from access control list"; + const char *add_msg = gettext("being added to access control list"); + const char *remove_msg = gettext("being removed from access control list"); namelen = strlen(name); if ((lname = (char *)malloc(namelen+1)) == NULL) { - fprintf (stderr, "%s: malloc bombed in change_host\n", ProgramName); + fprintf (stderr, gettext("%s: malloc bombed in change_host\n"), + ProgramName); exit (1); } for (i = 0; i < namelen; i++) { @@ -333,7 +355,7 @@ change_host(Display *dpy, char *name, Bool add) family = FamilyInternet; name += 5; #else - fprintf (stderr, "%s: not compiled for TCP/IP\n", ProgramName); + fprintf (stderr, gettext("%s: not compiled for TCP/IP\n"), ProgramName); free(lname); return 0; #endif @@ -343,7 +365,7 @@ change_host(Display *dpy, char *name, Bool add) family = FamilyInternet6; name += 6; #else - fprintf (stderr, "%s: not compiled for IPv6\n", ProgramName); + fprintf (stderr, gettext("%s: not compiled for IPv6\n"), ProgramName); free(lname); return 0; #endif @@ -355,14 +377,14 @@ change_host(Display *dpy, char *name, Bool add) family = FamilyInternet6; name += 7; #else - fprintf (stderr, "%s: not compiled for IPv6\n", ProgramName); + fprintf (stderr, gettext("%s: not compiled for IPv6\n"), ProgramName); free(lname); return 0; #endif } #endif /* ACCEPT_INETV6 */ else if (!strncmp("dnet:", lname, 5)) { - fprintf (stderr, "%s: not compiled for DECnet\n", ProgramName); + fprintf (stderr, gettext("%s: not compiled for DECnet\n"), ProgramName); free(lname); return 0; } @@ -371,7 +393,7 @@ change_host(Display *dpy, char *name, Bool add) family = FamilyNetname; name += 4; #else - fprintf (stderr, "%s: not compiled for Secure RPC\n", ProgramName); + fprintf (stderr, gettext("%s: not compiled for Secure RPC\n"), ProgramName); free(lname); return 0; #endif @@ -381,7 +403,7 @@ change_host(Display *dpy, char *name, Bool add) family = FamilyKrb5Principal; name +=4; #else - fprintf (stderr, "%s: not compiled for Kerberos 5\n", ProgramName); + fprintf (stderr, gettext("%s: not compiled for Kerberos 5\n"), ProgramName); free(lname); return 0; #endif @@ -404,7 +426,7 @@ change_host(Display *dpy, char *name, Bool add) #endif { *cp = '\0'; - fprintf (stderr, "%s: unknown address family \"%s\"\n", + fprintf (stderr, gettext("%s: unknown address family \"%s\"\n"), ProgramName, lname); free(lname); return 0; @@ -418,8 +440,8 @@ change_host(Display *dpy, char *name, Bool add) cp = strchr(name, ':'); if (cp == NULL || cp == name) { - fprintf(stderr, - "%s: type must be specified for server interpreted family \"%s\"\n", + fprintf(stderr, gettext( + "%s: type must be specified for server interpreted family \"%s\"\n"), ProgramName, name); return 0; } @@ -447,7 +469,7 @@ change_host(Display *dpy, char *name, Bool add) retval = krb5_parse_name(name, &princ); if (retval) { krb5_init_ets(); /* init krb errs for error_message() */ - fprintf(stderr, "%s: cannot parse Kerberos name: %s\n", + fprintf(stderr, gettext("%s: cannot parse Kerberos name: %s\n"), ProgramName, error_message(retval)); return 0; } @@ -474,7 +496,7 @@ change_host(Display *dpy, char *name, Bool add) XAddHost(dpy, &ha); else XRemoveHost(dpy, &ha); - printf( "non-network local connections %s\n", add ? add_msg : remove_msg); + printf( gettext("non-network local connections %s\n"), add ? add_msg : remove_msg); return 1; } /* @@ -493,12 +515,12 @@ change_host(Display *dpy, char *name, Bool add) *cp = '\0'; pwd = getpwnam(name); if (!pwd) { - fprintf(stderr, "no such user \"%s\"\n", name); + fprintf(stderr, gettext("no such user \"%s\"\n"), name); return 0; } getdomainname(domainname, sizeof(domainname)); if (!user2netname(username, pwd->pw_uid, domainname)) { - fprintf(stderr, "failed to get netname for \"%s\"\n", name); + fprintf(stderr, gettext("failed to get netname for \"%s\"\n"), name); return 0; } netname = username; @@ -610,8 +632,11 @@ change_host(Display *dpy, char *name, Bool add) familyMsg = "inet "; } - fprintf(stderr, "%s: unable to get %saddress for \"%s\"\n", - ProgramName, familyMsg, name); + /* L10N_Comments - Parts composed to make full error string + 'unable to get' ['inet'|'inetv6'|''] 'address for' <address> */ + fprintf (stderr, "%s: %s %s%s \"%s\"\n", ProgramName, + gettext("unable to get"), familyMsg, gettext("address for"), + name); } freeaddrinfo(addresses); return 1; @@ -852,13 +877,13 @@ local_xerror(Display *dpy, XErrorEvent *rep) { if ((rep->error_code == BadAccess) && (rep->request_code == X_ChangeHosts)) { fprintf (stderr, - "%s: must be on local machine to add or remove hosts.\n", + gettext("%s: must be on local machine to add or remove hosts.\n"), ProgramName); return 1; } else if ((rep->error_code == BadAccess) && (rep->request_code == X_SetAccessControl)) { fprintf (stderr, - "%s: must be on local machine to enable or disable access control.\n", + gettext("%s: must be on local machine to enable or disable access control.\n"), ProgramName); return 1; } else if ((rep->error_code == BadValue) && |