X-Git-Url: http://cgit.sxemacs.org/?p=sxemacs;a=blobdiff_plain;f=src%2Fprint.c;h=d1d3c2ab5b8a7d351649296edcd60f99e4d49727;hp=4f8e3bc2dbc3dc1c8788e37de395ece40c811e32;hb=182f58aeacc32908883b6b7d8d808c0ca16b5c0a;hpb=c3d0458e37856dc7628b139c7c48713b3a19f9d5 diff --git a/src/print.c b/src/print.c index 4f8e3bc..d1d3c2a 100644 --- a/src/print.c +++ b/src/print.c @@ -134,26 +134,25 @@ std_handle_out_external(FILE * stream, Lisp_Object lstream, } -#define SXE_VSNPRINT_VA(ret,sbuf,buf,size,spec,tries,type,fmt,args) \ +#define SXE_VSNPRINT_VA(ret__,sbuf__,buf__,size__,spec__,tries__,type__,fmt__,args__) \ do { \ - --tries; \ - ret = vsnprintf((char*)buf,size,fmt,args); \ - if ( retval == 0 ) { \ + --tries__; \ + ret__ = vsnprintf((char*)buf__,size__,fmt__,args__); \ + if ( ret__ == 0 ) { \ /* Nothing to write */ \ break; \ - } else if ( ret < 0 ) { \ - XMALLOC_UNBIND(buf,size,spec); \ - size *= 2; \ - XMALLOC_OR_ALLOCA(buf,size,type); \ - ret = 0; \ - } else if ( (size_t)ret > (size_t)size ) { \ + } else if ( ret__ < 0 ) { \ + XMALLOC_UNBIND(buf__,size__,spec__); \ + size__ *= 2; \ + XMALLOC_OR_ALLOCA(buf__,size__,type__); \ + } else if ( (size_t)ret__ > (size_t)size__ ) { \ /* We need more space, so we need to allocate it */ \ - XMALLOC_UNBIND(buf,size,spec); \ - size = ret + 1; \ - XMALLOC_OR_ALLOCA(buf,size,type); \ - ret = 0; \ + XMALLOC_UNBIND(buf__,size__,spec__); \ + size__ = ret__ + 1; \ + XMALLOC_OR_ALLOCA(buf__,size__,type__); \ + ret__ = -1; \ } \ - } while( ret == 0 && tries > 0 ) + } while( ret__ < 0 && tries__ > 0 ) int write_fmt_str(Lisp_Object stream, const char* fmt, ...) @@ -161,8 +160,8 @@ int write_fmt_str(Lisp_Object stream, const char* fmt, ...) char *kludge; va_list args; int bufsize, retval, tries = 3; - /* write_fmt_str is used for small prints usually... */ - char buffer[64+1]; + /* write_fmt_str is used for small prints usually... */ + char buffer[64+1]; int speccount = specpdl_depth(); va_start(args, fmt); @@ -236,12 +235,12 @@ static int std_handle_out_va(FILE * stream, const char *fmt, va_list args) kludge = buffer; SXE_VSNPRINT_VA(retval,buffer,kludge,bufsize,speccount,tries,Bufbyte,fmt,args); - + if (retval == 0) /* nothing to write */ return retval; - use_fprintf = ! initialized ||fatal_error_in_progress || + use_fprintf = ! initialized ||fatal_error_in_progress || inhibit_non_essential_printing_operations; if (retval > 0) { @@ -293,9 +292,9 @@ int stdout_out(const char *fmt, ...) int retval; va_list args; va_start(args, fmt); - retval = std_handle_out_va(stdout, - (initialized && !fatal_error_in_progress - ? GETTEXT(fmt) : fmt), + retval = std_handle_out_va(stdout, + (initialized && !fatal_error_in_progress + ? GETTEXT(fmt) : fmt), args); va_end(args); return retval; @@ -307,9 +306,9 @@ DOESNT_RETURN fatal(const char *fmt, ...) va_start(args, fmt); stderr_out("\nSXEmacs: "); - std_handle_out_va(stderr, - (initialized && !fatal_error_in_progress - ? GETTEXT(fmt) : fmt), + std_handle_out_va(stderr, + (initialized && !fatal_error_in_progress + ? GETTEXT(fmt) : fmt), args); stderr_out("\n"); @@ -326,7 +325,7 @@ write_string_to_stdio_stream(FILE * stream, struct console *con, Lisp_Object coding_system, int must_flush) { Extcount extlen; - const Extbyte *extptr; + const Extbyte *extptr = NULL; /* #### yuck! sometimes this function is called with string data, and the following call may gc. */ @@ -334,17 +333,18 @@ write_string_to_stdio_stream(FILE * stream, struct console *con, Bufbyte *puta = (Bufbyte *) alloca(len); memcpy(puta, str + offset, len); - if (initialized && !inhibit_non_essential_printing_operations) + if (initialized && !inhibit_non_essential_printing_operations) { TO_EXTERNAL_FORMAT(DATA, (puta, len), ALLOCA, (extptr, extlen), coding_system); - else { + } + if( extptr == NULL ) { extptr = (Extbyte *) puta; extlen = (Bytecount) len; } } - + if (stream) { std_handle_out_external(stream, Qnil, extptr, extlen, stream == stdout @@ -912,6 +912,8 @@ Display ERROR-OBJECT on STREAM in a user-friendly way. Lisp_Object Vfloat_output_format; +void float_to_string(char *buf, fpfloat data, int maxlen); + /* * This buffer should be at least as large as the max string size of the * largest float, printed in the biggest notation. This is undoubtedly @@ -923,7 +925,7 @@ Lisp_Object Vfloat_output_format; * I assume that IEEE-754 format numbers can take 329 bytes for the worst * case of -1e307 in 20d float_output_format. What is one to do (short of * re-writing _doprnt to be more sane)? - * -wsr + * -wsr */ void float_to_string(char *buf, fpfloat data, int maxlen) { @@ -1275,7 +1277,7 @@ printing_major_badness(Lisp_Object printcharfun, len = snprintf(buf, sizeof(buf), "%s object %p", badness_string, val); break; default: - len = snprintf(buf, sizeof(buf), "%s unknown badness %d", + len = snprintf(buf, sizeof(buf), "%s unknown badness %d", badness_string, badness); break; } @@ -1321,12 +1323,12 @@ print_internal(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) output. */ #endif - /* Try out custom printing */ - if (UNLIKELY(!(bool)inhibit_autoloads && !(bool)nodumpfile) && + /* Try out custom printing */ + if (UNLIKELY(!(bool)inhibit_autoloads && !(bool)nodumpfile) && !EQ(Qnil, Vcustom_object_printer) && - !EQ(Qnil, apply1(Vcustom_object_printer, - Fcons(obj, Fcons(printcharfun, Qnil))))) { - return; + !EQ(Qnil, apply1(Vcustom_object_printer, + Fcons(obj, Fcons(printcharfun, Qnil))))) { + return; } /* Detect circularities and truncate them. @@ -1711,15 +1713,22 @@ to 0. Bufbyte str[MAX_EMCHAR_LEN]; Bytecount len; int extlen; - const Extbyte *extptr; + const Extbyte *extptr = NULL; CHECK_CHAR_COERCE_INT(character); len = set_charptr_emchar(str, XCHAR(character)); TO_EXTERNAL_FORMAT(DATA, (str, len), ALLOCA, (extptr, extlen), Qterminal); - memcpy(alternate_do_string + alternate_do_pointer, extptr, extlen); - alternate_do_pointer += extlen; - alternate_do_string[alternate_do_pointer] = 0; + if ( extptr != NULL ) { + memcpy(alternate_do_string + alternate_do_pointer, extptr, extlen); + alternate_do_pointer += extlen; + alternate_do_string[alternate_do_pointer] = 0; + } else { + /* Better bad transcoding than nothing I guess... */ + memcpy(alternate_do_string + alternate_do_pointer, str, len); + alternate_do_pointer += len; + alternate_do_string[alternate_do_pointer] = 0; + } return character; }