summaryrefslogtreecommitdiff
path: root/dist/api_err.py
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2011-02-01 21:25:48 +1100
committerMichael Cahill <michael.cahill@wiredtiger.com>2011-02-01 21:25:48 +1100
commit4086384cea8e1427c6caa40a5e9309976620ed63 (patch)
tree5b2b3d718b2bd4da05ac8e22c766db9fd50cdc2a /dist/api_err.py
parent1bfaaf10f1517b4870564bdab902a8702d9e15bb (diff)
downloadmongo-4086384cea8e1427c6caa40a5e9309976620ed63.tar.gz
Use Python idioms in api_err.py.
refs #26
Diffstat (limited to 'dist/api_err.py')
-rw-r--r--dist/api_err.py68
1 files changed, 35 insertions, 33 deletions
diff --git a/dist/api_err.py b/dist/api_err.py
index 891559eef87..4456f87213b 100644
--- a/dist/api_err.py
+++ b/dist/api_err.py
@@ -44,42 +44,44 @@ compare_srcfile(tmp_file, '../include/wiredtiger.in')
# Output the wiredtiger_strerror code.
tmp_file = '__tmp'
tfile = open(tmp_file, 'w')
-tfile.write('/* DO NOT EDIT: automatically built by dist/api_err.py. */\n\n')
-tfile.write('#include "wt_internal.h"\n\n')
-tfile.write('/*\n')
-tfile.write(' * wiredtiger_strerror --\n')
-tfile.write(' *\tReturn a string for any error value.\n')
-tfile.write(' */\n')
-tfile.write('char *\n')
-tfile.write('wiredtiger_strerror(int error)\n')
-tfile.write('{\n')
-tfile.write('\tstatic char errbuf[64];\n')
-tfile.write('\tchar *p;\n\n')
-tfile.write('\tif (error == 0)\n')
-tfile.write('\t\treturn ("Successful return: 0");\n\n')
-tfile.write('\tswitch (error) {\n')
+tfile.write('''/* DO NOT EDIT: automatically built by dist/api_err.py. */
+
+#include "wt_internal.h"
+
+/*
+ * wiredtiger_strerror --
+ * Return a string for any error value.
+ */
+const char *
+wiredtiger_strerror(int error)
+{
+ static char errbuf[64];
+ char *p;
+
+ if (error == 0)
+ return ("Successful return: 0");
+
+ switch (error) {
+''')
-# We don't want our error returns to conflict with any other
-# package, so use an uncommon range, specifically, -31,800 to
-# -31,999.
-v = -31800
for l in list:
tfile.write('\tcase ' + l[0] + ':\n')
tfile.write('\t\treturn ("' + l[0] + ': ' + l[1] + '");\n')
- v -= 1
-tfile.write('\tdefault:\n')
-tfile.write('\t\tif (error > 0 && (p = strerror(error)) != NULL)\n')
-tfile.write('\t\t\treturn (p);\n')
-tfile.write('\t\tbreak;\n')
-tfile.write('\t}\n\n')
-tfile.write('\t/*\n')
-tfile.write('\t * !!!\n')
-tfile.write('\t * Not thread-safe, but this is never supposed to happen.\n')
-tfile.write('\t */\n')
-tfile.write('\t(void)snprintf(errbuf, sizeof(errbuf), ' +\
- '"Unknown error: %d", error);\n')
-tfile.write('\treturn (errbuf);\n')
-tfile.write('}\n')
+tfile.write('''\
+ default:
+ if (error > 0 && (p = strerror(error)) != NULL)
+ return (p);
+ break;
+ }
+
+ /*
+ * !!!
+ * Not thread-safe, but this is never supposed to happen.
+ */
+ (void)snprintf(errbuf, sizeof(errbuf), "Unknown error: %d", error);
+ return (errbuf);
+}
+''')
tfile.close()
-compare_srcfile(tmp_file, '../src/support/strerror.c')
+compare_srcfile(tmp_file, '../src/api/strerror.c')