diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/anagram/support/port.cpp	Sat Dec 22 17:52:45 2007 -0500
@@ -0,0 +1,64 @@
+/*
+ * AnaGram, A System for Syntax Directed Programming
+ * Copyright 2006 David A. Holland. All rights reserved.
+ * See the file COPYING for license and usage terms.
+ *
+ * port.cpp - portability file
+ */
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include "port.h"
+
+#include "assert.h"
+
+////////////////////////////////////////////////////////////
+//
+// OS issues
+//
+
+#ifdef AG_ON_UNIX
+
+/*
+ * This function is standard in most/all DOS compilers and C libraries;
+ * I think it originated in Turbo C.
+ */
+char *strlwr(char *string) {
+  for (char *s = string; *s; s++) {
+    *s = tolower((unsigned char) *s);
+  }
+  return string;
+}
+
+#endif
+
+////////////////////////////////////////////////////////////
+//
+// Compiler issues
+//
+
+#ifdef __IBMCPP__
+
+/*
+ * Obsolete compiler, no snprintf.
+ *
+ * Ignoring the maximum length is less than desirable but will have to
+ * do. This is being used to replace unchecked sprintfs anyway.
+ */
+int snprintf(char *buf, unsigned maxlen, const char *fmt, ...) {
+  va_list ap;
+  int ret;
+
+  va_start(ap, fmt);
+  ret = vsprintf(buf, fmt, ap);
+  va_end(ap);
+
+  /* prevent catastrophe, hopefully */
+  assert(ret < 0 || (unsigned)ret < maxlen);
+
+  return ret;
+}
+
+#endif /* __IBMCPP__ */
+