void PlMessage(const char *fm, ...) { va_list(args); va_start(args, fm); if ( hasConsole() ) { Sfprintf(Serror, "SWI-Prolog: "); Svfprintf(Serror, fm, args); Sfprintf(Serror, "\n"); } else { char buf[1024]; int64_t hwndi; HWND hwnd = NULL; static atom_t ATOM_hwnd = 0; if ( !ATOM_hwnd ) ATOM_hwnd = PL_new_atom("hwnd"); if ( PL_current_prolog_flag(ATOM_hwnd, PL_INTEGER, &hwndi) ) hwnd = (HWND)hwndi; vsprintf(buf, fm, args); MessageBox(hwnd, buf, "SWI-Prolog", MB_OK|MB_TASKMODAL); } va_end(args); }
static int ttl_put_uesc(IOSTREAM *s, int c) { if ( c <= 0xffff ) return Sfprintf(s, "\\u%04x", (unsigned)c); else return Sfprintf(s, "\\U%08x", (unsigned)c); }
static ssize_t /* encode */ chunked_write(void *handle, char *buf, size_t size) { chunked_context *ctx = handle; if ( Sfprintf(ctx->stream, "%x\r\n", size) >= 0 && Sfwrite(buf, sizeof(char), size, ctx->stream) == size && Sfprintf(ctx->stream, "\r\n") >= 0 ) return size; return -1; }
int addr_write(IOSTREAM *s, atom_t a, int flags) { PL_blob_t *type; size_t len; lo_address *p=(lo_address *)PL_blob_data(a,&len,&type); if (p) { const char *host = lo_address_get_hostname(*p); const char *port = lo_address_get_port(*p); if (host!=NULL && port!=NULL) { Sfprintf(s,"osc_address<%s:%s>",host,port); } else { Sfprintf(s,"osc_address<invalid>"); } } return TRUE; }
static int chunked_close(void *handle) { chunked_context *ctx = handle; int rc = 0; DEBUG(1, Sdprintf("chunked_close() ...\n")); if ( (ctx->chunked_stream->flags & SIO_OUTPUT) ) { if ( Sfprintf(ctx->stream, "0\r\n\r\n") < 0 ) rc = -1; } ctx->stream->encoding = ctx->parent_encoding; if ( ctx->close_parent ) { IOSTREAM *parent = ctx->stream; int rc2; free_chunked_context(ctx); rc2 = Sclose(parent); if ( rc == 0 ) rc = rc2; } else { free_chunked_context(ctx); } return rc; }
static int write_record_ref(IOSTREAM *s, atom_t aref, int flags) { recref *ref = PL_blob_data(aref, NULL, NULL); Sfprintf(s, "<record>(%p)", ref->record); return TRUE; }
gint write_plgi_blob(IOSTREAM *s, atom_t a, gint flags) { PLGIBlob *blob = PL_blob_data(a, NULL, NULL); Sfprintf(s, "<%s>(%p)", PL_atom_chars(blob->name), blob->data); return TRUE; }
static int write_clause_ref(IOSTREAM *s, atom_t aref, int flags) { clref *ref = PL_blob_data(aref, NULL, NULL); (void)flags; Sfprintf(s, "<clause>(%p)", ref->clause); return TRUE; }
static int write_archive(IOSTREAM *s, atom_t symbol, int flags) { archive_wrapper *ar = PL_blob_data(symbol, NULL, NULL); Sfprintf(s, "<archive>(%p)", ar); return TRUE; }
static int write_clingo(IOSTREAM *s, atom_t symbol, int flags) { (void)flags; clingo_wrapper *ar = PL_blob_data(symbol, NULL, NULL); Sfprintf(s, "<clingo>(%p)", ar); return TRUE; }
int printMessage(atom_t severity, ...) { GET_LD wakeup_state wstate; term_t av; predicate_t pred = PROCEDURE_print_message2; va_list args; int rc; if ( ++LD->in_print_message >= OK_RECURSIVE*3 ) fatalError("printMessage(): recursive call\n"); if ( !saveWakeup(&wstate, TRUE PASS_LD) ) { LD->in_print_message--; return FALSE; } av = PL_new_term_refs(2); va_start(args, severity); PL_put_atom(av+0, severity); rc = PL_unify_termv(av+1, args); va_end(args); if ( rc ) { if ( isDefinedProcedure(pred) && LD->in_print_message <= OK_RECURSIVE ) { rc = PL_call_predicate(NULL, PL_Q_NODEBUG|PL_Q_CATCH_EXCEPTION, pred, av); } else if ( LD->in_print_message <= OK_RECURSIVE*2 ) { Sfprintf(Serror, "Message: "); if ( ReadingSource ) Sfprintf(Serror, "%s:%d ", PL_atom_chars(source_file_name), (int)source_line_no); rc = PL_write_term(Serror, av+1, 1200, 0); Sfprintf(Serror, "\n"); } else /* in_print_message == 2 */ { Sfprintf(Serror, "printMessage(): recursive call\n"); } } restoreWakeup(&wstate PASS_LD); LD->in_print_message--; return rc; }
int server_write(IOSTREAM *s, atom_t a, int flags) { PL_blob_t *type; size_t len; my_server_thread *p=(my_server_thread *)PL_blob_data(a,&len,&type); if (p) { char *url=lo_server_get_url((*p)->s); Sfprintf(s,"osc_server<%s>",url); free(url); } return TRUE; }
int write_pnm_file(IOSTREAM *fd, XImage *img, Display *disp, Colormap cmap, int scale, int fmt, int encode) { int width = img->width; int height = img->height; XColor cdata[256]; XPixelInfo info; int x, y; if ( !scale ) scale = 255; if ( !fmt ) { if ( img->format == XYBitmap ) fmt = PNM_PBM; else fmt = PNM_PPM; } if ( fmt == PNM_PBM && encode == PNM_RUNLEN ) encode = PNM_RAWBITS; /* no use to runlen encode a bitmap */ if ( img->format != XYBitmap ) { info.cinfo = cdata; makeXPixelInfo(&info, img, disp, cmap); } Sfprintf(fd, "P%c\n", fmt + encode + '0'); Sfprintf(fd, "# Creator: XPCE version %s\n", strName(get(PCE,NAME_version,EAV))); Sfprintf(fd, "%d %d\n", width, height); if ( fmt != PNM_PBM ) Sfprintf(fd, "%d\n", scale); file_col = 0; switch(encode) { case PNM_ASCII: { switch(fmt) { case PNM_PBM: { for(y=0; y<height; y++) { for(x=0; x<width; x++) { unsigned long pixel = XGetPixel(img, x, y); if ( img->format != XYBitmap ) { XColor *c; int r; c = pixelToColor(img, pixel, &info); r = intensityXColor(c); pixel = r < 32768 ? 1 : 0; } if ( putNum(pixel, fd) < 0 ) return -1; } } break; } case PNM_PGM: { for(y=0; y<height; y++) { for(x=0; x<width; x++) { XColor *c; unsigned int r; c = pixelToColor(img, XGetPixel(img, x, y), &info); r = intensityXColor(c); r = rescale(r, BRIGHT, scale); if ( putNum(r, fd) < 0 ) return -1; } } break; } case PNM_PPM: { for(y=0; y<height; y++) { for(x=0; x<width; x++) { XColor *c; unsigned int r, g, b; c = pixelToColor(img, XGetPixel(img, x, y), &info); r = rescale(c->red, BRIGHT, scale); g = rescale(c->green, BRIGHT, scale); b = rescale(c->blue, BRIGHT, scale); if ( putNum(r, fd) < 0 || putNum(g, fd) < 0 || putNum(b, fd) < 0 ) return -1; } } break; } } if ( file_col && Sputc('\n', fd) == EOF ) return -1; file_col = 0; } case PNM_RAWBITS: { switch(fmt) { case PNM_PBM: { int byte = 0; int bit = 7; for(y=0; y<height; y++) { for(x=0; x<width; x++) { unsigned long pixel = XGetPixel(img, x, y); if ( img->format != XYBitmap ) { XColor *c; int r; c = pixelToColor(img, pixel, &info); r = intensityXColor(c); pixel = r < 32768 ? 1 : 0; } if ( pixel ) byte |= 1<<bit; if ( bit-- == 0 ) { if ( Sputc(byte, fd) == EOF ) return -1; bit = 7; byte = 0; } } if ( bit != 7 ) /* flush after finishing scanline */ { if ( Sputc(byte, fd) == EOF ) return -1; bit = 7; byte = 0; } } if ( bit != 7 ) { if ( Sputc(byte, fd) == EOF ) return -1; } break; } case PNM_PGM: { for(y=0; y<height; y++) { for(x=0; x<width; x++) { XColor *c; unsigned int r; c = pixelToColor(img, XGetPixel(img, x, y), &info); r = intensityXColor(c); r = rescale(r, BRIGHT, scale); if ( Sputc(r, fd) == EOF ) return -1; } } break; } case PNM_PPM: { for(y=0; y<height; y++) { for(x=0; x<width; x++) { XColor *c; unsigned int r, g, b; c = pixelToColor(img, XGetPixel(img, x, y), &info); r = rescale(c->red, BRIGHT, scale); g = rescale(c->green, BRIGHT, scale); b = rescale(c->blue, BRIGHT, scale); if ( Sputc(r, fd) == EOF || Sputc(g, fd) == EOF || Sputc(b, fd) == EOF ) return -1; } } break; } } } case PNM_RUNLEN: { int rlen=-1; unsigned long cpixel = NOPIXEL; switch(fmt) { case PNM_PGM: { for(y=0; y<height; y++) { for(x=0; x<width; x++) { unsigned long pixel = XGetPixel(img, x, y); if ( pixel == cpixel && rlen < 255 ) rlen++; else { XColor *c; int r; if ( rlen > 0 && Sputc(rlen, fd) == EOF ) return -1; cpixel = pixel; rlen = 1; c = pixelToColor(img, pixel, &info); r = intensityXColor(c); r = rescale(r, BRIGHT, scale); if ( Sputc(r, fd) == EOF ) return -1; } } } if ( Sputc(rlen, fd) == EOF ) return -1; break; } case PNM_PPM: { for(y=0; y<height; y++) { for(x=0; x<width; x++) { unsigned long pixel = XGetPixel(img, x, y); if ( pixel == cpixel && rlen < 255 ) rlen++; else { XColor *c; unsigned int r, g, b; if ( rlen > 0 && Sputc(rlen, fd) == EOF ) return -1; cpixel = pixel; rlen = 1; c = pixelToColor(img, pixel, &info); r = rescale(c->red, BRIGHT, scale); g = rescale(c->green, BRIGHT, scale); b = rescale(c->blue, BRIGHT, scale); if ( Sputc(r, fd) == EOF || Sputc(g, fd) == EOF || Sputc(b, fd) == EOF ) return -1; } } } if ( Sputc(rlen, fd) == EOF ) return -1; break; } } } } return 0; }