version.c revision f2e35a3a
1/* $XTermId: version.c,v 1.7 2020/06/23 22:46:02 tom Exp $ */ 2 3/* 4 * Copyright 2013-2019,2020 by Thomas E. Dickey 5 * 6 * All Rights Reserved 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the 10 * "Software"), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sublicense, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject to 14 * the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be included 17 * in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 * IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 23 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 * 27 * Except as contained in this notice, the name(s) of the above copyright 28 * holders shall not be used in advertising or otherwise to promote the 29 * sale, use or other dealings in this Software without prior written 30 * authorization. 31 */ 32 33#include <ctype.h> 34#include <xterm.h> 35#include <version.h> 36 37/* 38 * Returns the version-string used in the "-v' message as well as a few other 39 * places. It is derived (when possible) from the __vendorversion__ symbol 40 * that some newer imake configurations define. 41 */ 42const char * 43xtermVersion(void) 44{ 45 static const char vendor_version[] = __vendorversion__; 46 static char *buffer; 47 const char *result; 48 49 if (buffer == 0) { 50 const char *vendor = vendor_version; 51 52 buffer = malloc(sizeof(vendor_version) + 256); 53 if (buffer == 0) { 54 result = vendor; 55 } else { 56 char first[sizeof(vendor_version)]; 57 char second[sizeof(vendor_version)]; 58 59 /* some vendors leave trash in this string */ 60 for (;;) { 61 if (!strncmp(vendor, "Version ", (size_t) 8)) 62 vendor += 8; 63 else if (isspace(CharOf(*vendor))) 64 ++vendor; 65 else 66 break; 67 } 68 if (strlen(vendor) < BUFSIZ && 69 sscanf(vendor, "%[0-9.] %[A-Za-z_0-9.]", first, second) == 2) { 70 sprintf(buffer, "%.80s %.80s(%d)", second, first, XTERM_PATCH); 71 } else { 72 sprintf(buffer, "%.80s(%d)", vendor, XTERM_PATCH); 73 } 74 result = buffer; 75 } 76 } else { 77 result = buffer; 78 } 79 return result; 80} 81