diff -u MOO-1.8.1.dbopt/db_save_lambda_flush.c ../live/gammamoo/db_save_lambda_flush.c --- MOO-1.8.1.dbopt/db_save_lambda_flush.c 2004-02-25 23:11:30.503303312 +0000 +++ ../live/gammamoo/db_save_lambda_flush.c 2004-02-25 07:28:29.000000000 +0000 @@ -105,7 +105,34 @@ void dbio_write_string(const char *s) { - dbio_printf("%s\n", s ? s : ""); + int pos; + + /* Handle null strings */ + if (!s) { + fputc('\n', output); + return; + } + + /* Iterate over each character, printing to the file and Escaping as nessecary. */ + for (pos = 0; s[pos]; pos++) + { + switch (s[pos]) + { + case '\n': + fputc('\0', output); + fputc('n', output); + break; + case '\r': + fputc('\0', output); + fputc('r', output); + break; + default: + fputc(s[pos], output); + } + } + fputc('\n', output); + + /* dbio_printf("%s\n", s ? s : ""); */ } void diff -u MOO-1.8.1.dbopt/db_save_lambda_load.c ../live/gammamoo/db_save_lambda_load.c --- MOO-1.8.1.dbopt/db_save_lambda_load.c 2004-02-25 23:11:30.529299360 +0000 +++ ../live/gammamoo/db_save_lambda_load.c 2004-02-25 07:28:29.000000000 +0000 @@ -63,11 +63,67 @@ input = f; } +/* This function is used for reading string data from the database +* Anything that is stored as a string in the database has a special format. +* so that \n can be used in strings, in the file, \n will be replaced +* with the two-character identifier "\0n" The string representation in +* memory will remain unchanged (normal string thingie) +* +* Therefore, you can't use fgets here, and we must implement it ourselves +*/ + +int +dbio_read_line(char *s, int n) +{ + int pos, c; + const char *ptr; + for (pos = 0; pos < (n - 1); pos++) + { + c = fgetc(input); /* read next char from file */ + switch (c) + { + case '\n': + /* We have reached the end of the record, add the \0 and return */ + s[pos] = '\n'; + s[pos+1] = '\0'; + return 0; + break; + case EOF: + if (!pos) return -1; + s[pos] = '\0'; + return 0; + break; + case '\0': + /* Handle the special lil escaping thing */ + c = fgetc(input); + switch (c) + { + case 'n': + s[pos] = '\n'; + break; + case 'r': + s[pos] = '\r'; + break; + default: + errlog("DBIO_READ_LINE: Unknown escape character in string at file pos. %ld\n", + ftell(input)); + return -1; + } + break; + default: + s[pos] = c; + } + } + return 1; +} +/* void dbio_read_line(char *s, int n) { fgets(s, n, input); } +*/ + int dbio_scanf(const char *format,...) @@ -183,7 +239,7 @@ { static Stream *str = 0; static char buffer[1024]; - int len, used_stream = 0; + int len,status=0,used_stream = 0; prior_to_read_string = ftell(input); @@ -191,9 +247,9 @@ str = new_stream(1024); try_again: - fgets(buffer, sizeof(buffer), input); + status = dbio_read_line(buffer, sizeof(buffer)); len = strlen(buffer); - if (len == sizeof(buffer) - 1 && buffer[len - 1] != '\n') { + if (len == sizeof(buffer) - 1 && status > 0) { stream_add_string(str, buffer); used_stream = 1; goto try_again;