Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/support/port.cpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 2006 David A. Holland. All rights reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * port.cpp - portability file | |
7 */ | |
8 | |
9 #include <ctype.h> | |
10 #include <stdio.h> | |
11 #include <stdarg.h> | |
12 #include "port.h" | |
13 | |
14 #include "assert.h" | |
15 | |
16 //////////////////////////////////////////////////////////// | |
17 // | |
18 // OS issues | |
19 // | |
20 | |
21 #ifdef AG_ON_UNIX | |
22 | |
23 /* | |
24 * This function is standard in most/all DOS compilers and C libraries; | |
25 * I think it originated in Turbo C. | |
26 */ | |
27 char *strlwr(char *string) { | |
28 for (char *s = string; *s; s++) { | |
29 *s = tolower((unsigned char) *s); | |
30 } | |
31 return string; | |
32 } | |
33 | |
34 #endif | |
35 | |
36 //////////////////////////////////////////////////////////// | |
37 // | |
38 // Compiler issues | |
39 // | |
40 | |
41 #ifdef __IBMCPP__ | |
42 | |
43 /* | |
44 * Obsolete compiler, no snprintf. | |
45 * | |
46 * Ignoring the maximum length is less than desirable but will have to | |
47 * do. This is being used to replace unchecked sprintfs anyway. | |
48 */ | |
49 int snprintf(char *buf, unsigned maxlen, const char *fmt, ...) { | |
50 va_list ap; | |
51 int ret; | |
52 | |
53 va_start(ap, fmt); | |
54 ret = vsprintf(buf, fmt, ap); | |
55 va_end(ap); | |
56 | |
57 /* prevent catastrophe, hopefully */ | |
58 assert(ret < 0 || (unsigned)ret < maxlen); | |
59 | |
60 return ret; | |
61 } | |
62 | |
63 #endif /* __IBMCPP__ */ | |
64 |