version.c revision 0bd37d32
1/* $XTermId: version.c,v 1.1 2013/01/01 12:10:44 tom Exp $ */ 2 3/* 4 * Copyright 2013 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 */ 42char * 43xtermVersion(void) 44{ 45 static char vendor_version[] = __vendorversion__; 46 static char *result; 47 48 if (result == 0) { 49 char *vendor = vendor_version; 50 char first[BUFSIZ]; 51 char second[BUFSIZ]; 52 53 result = CastMallocN(char, strlen(vendor) + 9); 54 if (result == 0) 55 result = vendor; 56 else { 57 /* some vendors leave trash in this string */ 58 for (;;) { 59 if (!strncmp(vendor, "Version ", (size_t) 8)) 60 vendor += 8; 61 else if (isspace(CharOf(*vendor))) 62 ++vendor; 63 else 64 break; 65 } 66 if (strlen(vendor) < BUFSIZ && 67 sscanf(vendor, "%[0-9.] %[A-Za-z_0-9.]", first, second) == 2) 68 sprintf(result, "%s %s(%d)", second, first, XTERM_PATCH); 69 else 70 sprintf(result, "%s(%d)", vendor, XTERM_PATCH); 71 } 72 } 73 return result; 74} 75