/* static */ static int ConsolePipePutc (int sno, int ch) { StreamDesc *s = &GLOBAL_Stream[sno]; char c = ch; #if MAC || _MSC_VER if (ch == 10) { ch = '\n'; } #endif { int out = 0; while (!out) { out = write(s->u.pipe.fd, &c, sizeof(c)); if (out <0) { #if HAVE_STRERROR Yap_Error(PERMISSION_ERROR_INPUT_STREAM, TermNil, "error writing stream pipe: %s", strerror(errno)); #else Yap_Error(PERMISSION_ERROR_INPUT_STREAM, TermNil, "error writing stream pipe"); #endif } } } count_output_char(ch,s); return ((int) ch); }
/* static */ static int MemPutc(int sno, int ch) { StreamDesc *s = &GLOBAL_Stream[sno]; #if MAC || _MSC_VER if (ch == 10) { ch = '\n'; } #endif s->u.mem_string.buf[s->u.mem_string.pos++] = ch; if (s->u.mem_string.pos >= s->u.mem_string.max_size -8) { int old_src = s->u.mem_string.src, new_src; /* oops, we have reached an overflow */ Int new_max_size = s->u.mem_string.max_size + Yap_page_size; char *newbuf; if (old_src == MEM_BUF_CODE && (newbuf = Yap_AllocAtomSpace(new_max_size*sizeof(char))) != NULL) { new_src = MEM_BUF_CODE; #if HAVE_MEMMOVE memmove((void *)newbuf, (void *)s->u.mem_string.buf, (size_t)((s->u.mem_string.pos)*sizeof(char))); #else { Int n = s->u.mem_string.pos; char *to = newbuf; char *from = s->u.mem_string.buf; while (n-- >= 0) { *to++ = *from++; } } #endif Yap_FreeAtomSpace(s->u.mem_string.buf); #if !HAVE_SYSTEM_MALLOC } else if ((newbuf = (ADDR)realloc(s->u.mem_string.buf, new_max_size*sizeof(char))) != NULL) { new_src = MEM_BUF_MALLOC; #endif } else { if (GLOBAL_Stream[sno].u.mem_string.error_handler) { CACHE_REGS LOCAL_Error_Size = new_max_size*sizeof(char); save_machine_regs(); longjmp(*(jmp_buf *)GLOBAL_Stream[sno].u.mem_string.error_handler,1); } else { Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "YAP could not grow heap for writing to string"); } return -1; } if (old_src == MEM_BUF_CODE) { } s->u.mem_string.buf = newbuf; s->u.mem_string.max_size = new_max_size; s->u.mem_string.src = new_src; } count_output_char(ch,s); return ((int) ch); }