Skip to content

Commit 45f8b5c

Browse files
committed
Updated print_version() to display the OS version, debug version, and supported encodings.
1 parent 9d4be91 commit 45f8b5c

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/options.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@ ag was originally created by Geoff Greer. More information (and the latest relea
122122
can be found at http://geoff.greer.fm/ag\n");
123123
}
124124

125+
#if SUPPORT_TWO_ENCODINGS
126+
/* Get the actual name of a code page */
127+
char *GetCPName(int iCP, LPCPINFOEX lpCpi) {
128+
int i;
129+
char *pszName = "";
130+
CPINFOEX cpi;
131+
if (!lpCpi) lpCpi = &cpi;
132+
if (GetCPInfoEx(iCP, 0, lpCpi)) { /* Most code pages have a good descrition in the CPINFOEX structure */
133+
/* (Including many that are not listed in the static list above) */
134+
pszName = lpCpi->CodePageName;
135+
/* Make a copy because we can't return the address of this one in the local stack frame */
136+
/* Skip the code page number copy at the beginning of the CPINFOEX name */
137+
while (strchr("0123456789", *pszName)) pszName++;
138+
while (isspace(*pszName)) pszName++; /* Skip spaces after the number */
139+
if (*pszName == '(') pszName++; /* Remove the leading '(' */
140+
pszName = strdup(pszName);
141+
i = (int)strlen(pszName) - 1;
142+
if (pszName[i] == ')') pszName[i] = '\0'; /* Remove the trailing ')' */
143+
}
144+
/* But some code pages have a description that's an empty string "" */
145+
if (!*pszName) pszName = "(Unknown name)";
146+
return pszName;
147+
}
148+
#endif /* SUPPORT_TWO_ENCODINGS */
149+
125150
void print_version(void) {
126151
char jit = '-';
127152
char lzma = '-';
@@ -137,9 +162,24 @@ void print_version(void) {
137162
zlib = '+';
138163
#endif
139164

140-
printf("ag version %s\n\n", PACKAGE_VERSION);
165+
printf("ag version %s", PACKAGE_VERSION);
166+
#if defined(HAS_MSVCLIBX)
167+
#if defined(_WIN64)
168+
#define OS_NAME "Win64"
169+
#else
170+
#define OS_NAME "Win32"
171+
#endif
172+
printf(" " OS_NAME DEBUG_VERSION);
173+
#endif /* defined(HAS_MSVCLIBX) */
174+
printf("\n\n");
141175
printf("Features:\n");
142176
printf(" %cjit %clzma %czlib\n", jit, lzma, zlib);
177+
#if SUPPORT_TWO_ENCODINGS
178+
printf("\nSupported text file encodings:\n");
179+
int iACP = GetACP(); /* Get the Windows System Code Page */
180+
printf(" Code Page %d = %s\n", iACP, GetCPName(iACP, NULL));
181+
printf(" Code Page 65001 = UTF-8\n");
182+
#endif /* SUPPORT_TWO_ENCODINGS */
143183
}
144184

145185
void init_options(void) {

0 commit comments

Comments
 (0)