version.c revision 01037d57
1/* $XTermId: version.c,v 1.2 2015/04/10 08:35:33 tom Exp $ */ 2 3/* 4 * Copyright 2013,2015 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 char first[BUFSIZ]; 52 char second[BUFSIZ]; 53 54 buffer = CastMallocN(char, strlen(vendor) + 9); 55 if (buffer == 0) { 56 result = vendor; 57 } else { 58 /* some vendors leave trash in this string */ 59 for (;;) { 60 if (!strncmp(vendor, "Version ", (size_t) 8)) 61 vendor += 8; 62 else if (isspace(CharOf(*vendor))) 63 ++vendor; 64 else 65 break; 66 } 67 if (strlen(vendor) < BUFSIZ && 68 sscanf(vendor, "%[0-9.] %[A-Za-z_0-9.]", first, second) == 2) { 69 sprintf(buffer, "%s %s(%d)", second, first, XTERM_PATCH); 70 } else { 71 sprintf(buffer, "%s(%d)", vendor, XTERM_PATCH); 72 } 73 result = buffer; 74 } 75 } else { 76 result = buffer; 77 } 78 return result; 79} 80