static pic_value pic_port_read_string(pic_state *pic){ struct pic_port *port = pic_stdin(pic), *buf; pic_str *str; int k, i; int c; pic_get_args(pic, "i|p", &k, &port); assert_port_profile(port, PIC_PORT_IN | PIC_PORT_TEXT, PIC_PORT_OPEN, "read-stritg"); c = EOF; buf = pic_open_output_string(pic); for(i = 0; i < k; ++i) { if((c = xfgetc(port->file)) == EOF){ break; } xfputc(c, buf->file); } str = pic_get_output_string(pic, buf); if (pic_strlen(str) == 0 && c == EOF) { return pic_eof_object(); } else { return pic_obj_value(str); } }
static pic_value pic_port_write_blob(pic_state *pic) { struct pic_blob *blob; struct pic_port *port; int n; size_t start, end, i; n = pic_get_args(pic, "b|pkk", &blob, &port, &start, &end); switch (n) { case 1: port = pic_stdout(pic); case 2: start = 0; case 3: end = blob->len; } assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_BINARY, PIC_PORT_OPEN, "write-bytevector"); for (i = start; i < end; ++i) { xfputc(blob->data[i], port->file); } return pic_none_value(); }
static void write_str(pic_state *pic, pic_str *str, xFILE *file, int mode) { size_t i; const char *cstr = pic_str_cstr(pic, str); if (mode == DISPLAY_MODE) { xfprintf(pic, file, "%s", pic_str_cstr(pic, str)); return; } xfprintf(pic, file, "\""); for (i = 0; i < pic_str_len(str); ++i) { if (cstr[i] == '"' || cstr[i] == '\\') { xfputc(pic, '\\', file); } xfputc(pic, cstr[i], file); } xfprintf(pic, file, "\""); }
static pic_value pic_port_write_byte(pic_state *pic) { int i; struct pic_port *port = pic_stdout(pic); pic_get_args(pic, "i|p", &i, &port); assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_BINARY, PIC_PORT_OPEN, "write-u8"); xfputc(i, port->file); return pic_none_value(); }
static pic_value pic_port_write_char(pic_state *pic) { char c; struct pic_port *port = pic_stdout(pic); pic_get_args(pic, "c|p", &c, &port); assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_TEXT, PIC_PORT_OPEN, "write-char"); xfputc(c, port->file); return pic_none_value(); }
static Boolean flush(unsigned int n) /***************************************************************************** * 0 if ok 1 if error in static global err_status *****************************************************************************/ { assert(n < 256); xfputc(n, gif_save_file); if (xfwrite(gif_byte_buff, 1, n, gif_save_file) < n) { err_status = xerrno(); return(1); } return(0); }
int xfprintf(XFILE *file, const char *fmt, ...) { ENV *env = get_env_ptr(); int cnt, j; va_list arg; va_start(arg, fmt); cnt = vsprintf(env->term_buf, fmt, arg); va_end(arg); for (j = 0; j < cnt; j++) { if (xfputc(env->term_buf[j], file) < 0) { cnt = -1; break; } } return cnt; }
void show_MAT ( XFILE * fp, const MAT mat, const int mrow, const int mcol){ if(NULL==fp){ return;} if(NULL==mat){ return;} const int nrow = mat->nrow; const int ncol = mat->ncol; const int maxrow = (mrow!=0 && mrow<nrow)?mrow:nrow; const int maxcol = (mcol!=0 && mcol<ncol)?mcol:ncol; for( int row=0 ; row<maxrow ; row++){ xfprintf(fp,"%d:",row+1); for ( int col=0 ; col<maxcol ; col++){ xfprintf(fp," %#8.2f",mat->x[col*nrow+row]); } if(maxcol<ncol){ xfprintf(fp,"\t... (%u others)",ncol-maxcol); } xfputc('\n',fp); } if( maxrow<nrow){ xfprintf(fp,"... (%u others)\n",nrow-maxrow); } }
static void write_char(pic_state *pic, char c, xFILE *file, int mode) { if (mode == DISPLAY_MODE) { xfputc(pic, c, file); return; } switch (c) { default: xfprintf(pic, file, "#\\%c", c); break; case '\a': xfprintf(pic, file, "#\\alarm"); break; case '\b': xfprintf(pic, file, "#\\backspace"); break; case 0x7f: xfprintf(pic, file, "#\\delete"); break; case 0x1b: xfprintf(pic, file, "#\\escape"); break; case '\n': xfprintf(pic, file, "#\\newline"); break; case '\r': xfprintf(pic, file, "#\\return"); break; case ' ': xfprintf(pic, file, "#\\space"); break; case '\t': xfprintf(pic, file, "#\\tab"); break; } }
static pic_value pic_port_write_string(pic_state *pic) { char *str; struct pic_port *port; int start, end, n, i; n = pic_get_args(pic, "z|pii", &str, &port, &start, &end); switch (n) { case 1: port = pic_stdout(pic); case 2: start = 0; case 3: end = INT_MAX; } assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_TEXT, PIC_PORT_OPEN, "write-string"); for (i = start; i < end && str[i] != '\0'; ++i) { xfputc(str[i], port->file); } return pic_none_value(); }
static pic_value pic_port_read_line(pic_state *pic) { int c; struct pic_port *port = pic_stdin(pic), *buf; struct pic_string *str; pic_get_args(pic, "|p", &port); assert_port_profile(port, PIC_PORT_IN | PIC_PORT_TEXT, PIC_PORT_OPEN, "read-line"); buf = pic_open_output_string(pic); while ((c = xfgetc(port->file)) != EOF && c != '\n') { xfputc(c, buf->file); } str = pic_get_output_string(pic, buf); if (pic_strlen(str) == 0 && c == EOF) { return pic_eof_object(); } else { return pic_obj_value(str); } }
void ICACHE_FLASH_ATTR shell_putc(char c) { xfputc(_z_out_cb, 0, c); }
pic_value pic_xvfformat(pic_state *pic, xFILE *file, const char *fmt, va_list ap) { char c; pic_value irrs = pic_nil_value(); while ((c = *fmt++)) { switch (c) { default: xfputc(pic, c, file); break; case '%': c = *fmt++; if (! c) goto exit; switch (c) { default: xfputc(pic, c, file); break; case '%': xfputc(pic, '%', file); break; case 'c': xfprintf(pic, file, "%c", va_arg(ap, int)); break; case 's': xfprintf(pic, file, "%s", va_arg(ap, const char *)); break; case 'd': xfprintf(pic, file, "%d", va_arg(ap, int)); break; case 'p': xfprintf(pic, file, "%p", va_arg(ap, void *)); break; case 'f': xfprintf(pic, file, "%f", va_arg(ap, double)); break; } break; case '~': c = *fmt++; if (! c) goto exit; switch (c) { default: xfputc(pic, c, file); break; case '~': xfputc(pic, '~', file); break; case '%': xfputc(pic, '\n', file); break; case 'a': irrs = pic_cons(pic, pic_fdisplay(pic, va_arg(ap, pic_value), file), irrs); break; case 's': irrs = pic_cons(pic, pic_fwrite(pic, va_arg(ap, pic_value), file), irrs); break; } break; } } exit: return pic_reverse(pic, irrs); }