[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
> I agree to both assertions. Care to make a patch?
Tested on linux. Hope the patch format is correct.
--- orig/dat2c.c 2003-05-14 22:08:14.000000000 +0200
+++ tools/dat2c.c 2003-05-14 22:09:45.000000000 +0200
@@ -926,21 +926,46 @@
+/* get_cident()
+ *
+ * Creates a valid cident from a string. The returned pointer is
dynamic memory.
+ */
+static char *get_cident(const char *src)
+{
+ char *cident, *dest;
+
+ cident = dest = malloc(strlen(src) + 1);
+ if(!cident) out_of_memory();
+
+ if (*src) {
+ if (isalpha(*src) || *src=='_')
+ *dest = toupper(*src);
+ else
+ *dest = '_';
+ src++;
+ dest++;
+ while (*src) {
+ if (isalnum(*src) || *src=='_')
+ *dest = toupper(*src);
+ else
+ *dest = '_';
+ src++;
+ dest++;
+ }
+ }
+ *dest = 0;
+ return cident;
+}
+
/* write_header_start()
*
* Writes the start of the header file.
*/
static void write_header_start(struct dat2c* dat2c)
{
- time_t tm = time(0);
- struct tm* stm = localtime(&tm);
- char dat2c_include_guard[22];
-
- sprintf(dat2c_include_guard,
- "DAT2C_%04d%02d%02d_%02d%02d%02d",
- stm->tm_year + 1900, stm->tm_mon + 1, stm->tm_mday,
- stm->tm_hour, stm->tm_min, stm->tm_sec);
+ char *dat2c_include_guard;
+ dat2c_include_guard = get_cident(dat2c->fname_h);
/* comment at top of file */
cwrite(dat2c, H, "/* $string$$n$"
" * $n$"
@@ -965,6 +990,7 @@
dat2c->fname_c,
dat2c_include_guard,
dat2c_include_guard);
+ free(dat2c_include_guard);
}