/* ** parse_amp ** ** parse ampersand ("&") */ BOOL parse_amp( INFILE *inpf ) { if ( !fatal_error ) { char *nxtwd; char nxtch; DLNODE *nd; /* write blank if necessary */ outstr( infgetcws( inpf ) ); /* get entity id */ nxtwd = infgetw( inpf ); /* search for entity in list */ nd = find_dlnode( defent->first, (APTR) nxtwd, cmp_strent ); if ( nd == NULL ) { message( WARN_UNKN_ENTITY, inpf ); errstr( "Unknown entity " ); errqstr( nxtwd ); errlf(); } /* check for closing ';' */ nxtch = infgetc( inpf ); if ( nxtch != ';' ) { message( WARN_EXPT_SEMIK, inpf ); errqstr( ";" ); errstr( " expected (found: " ); errqstr( ch2str( nxtch ) ); errstr( ")\n" ); } /* output whole entity */ outch( '&' ); outstr( nxtwd ); outch( nxtch ); } return (BOOL)( !fatal_error ); }
/* * lnexttoscreen * * Like nexttoscreen() but only for the cursor line. */ static void lnexttoscreen() { register char *np = Nextscreen + (Cline_row * Columns); register char *rp = Realscreen + (Cline_row * Columns); register char *endline; register int row, col; int gorow = -1, gocol = -1; endline = np + (Cline_size * Columns); row = Cline_row; col = 0; outstr(T_CI); /* disable cursor */ for ( ; np < endline ; np++,rp++ ) { /* If desired screen (contents of Nextscreen) does not */ /* match what's really there, put it there. */ if ( *np != *rp ) { /* if we are positioned at the right place, */ /* we don't have to use windgoto(). */ if (gocol != col || gorow != row) { /* * If we're just off by one, don't send * an entire esc. seq. (this happens a lot!) */ if (gorow == row && gocol+1 == col) { outchar(*(np-1)); gocol++; } else windgoto(gorow=row,gocol=col); } outchar(*rp = *np); gocol++; } if ( ++col >= Columns ) { col = 0; row++; } } outstr(T_CV); /* enable cursor again */ }
// prints cpu registers and flags (keep it on 2 lines) void print_cpu_context() { char tmpstr[160] = { 0 }; char nextinstr[160]; cpudef *cpu = get_cpu_struct(g_which_cpu); const char *s = NULL; // results returned by CPU ascii callback int reg = CPU_INFO_REG; // base register int x = 0; // our X position so we can apply word wrap // fill nextinstr with the disassembly of the next instruction cpu->dasm_callback(nextinstr, cpu->getpc_callback()); // print all registers we can for (reg = CPU_INFO_REG; reg < MAX_REGS; reg++) { s = cpu->ascii_info_callback(NULL, reg); // if we got something back ... if (s[0] != 0) { outstr(s); outstr(" "); // spacer after register info x += strlen(s) + 1; // +1 because we take into account space // if it's time to do a line feed ... if (x > 76) { newline(); x = 0; } } }; newline(); sprintf(tmpstr, "AT PC: [%02X - %s] FLAGS: [%s] ", cpu->getpc_callback(), nextinstr, cpu->ascii_info_callback(NULL, CPU_INFO_FLAGS) ); printline(tmpstr); }
void doformat(struct output *dest, const char *f, va_list ap) { #ifdef HAVE_VASPRINTF char *s; vasprintf(&s, f, ap); outstr(s, dest); free(s); #else /* !HAVE_VASPRINTF */ static const char digit_lower[] = "0123456789abcdef"; static const char digit_upper[] = "0123456789ABCDEF"; const char *digit; char c; char temp[TEMPSIZE]; int flushleft; int sharp; int width; int prec; int islong; int isquad; char *p; int sign; int64_t l; uint64_t num; unsigned base; int len; int size; int pad; while ((c = *f++) != '\0') { if (c != '%') { outc(c, dest); continue; } flushleft = 0; sharp = 0; width = 0; prec = -1; islong = 0; isquad = 0; for (;;) { if (*f == '-') flushleft++; else if (*f == '#') sharp++; else break; f++; } if (*f == '*') { width = va_arg(ap, int); f++; } else { while (is_digit(*f)) {
void dumplits( int size, int pr_label , int queueptr,int queuelab, unsigned char *queue) { int j, k,lit ; if ( queueptr ) { if ( pr_label ) { output_section("rodata_compiler"); // output_section("text"); prefix(); queuelabel(queuelab) ; col() ; nl(); } k = 0 ; while ( k < queueptr ) { /* pseudo-op to define byte */ if (infunc) j=1; else j=10; if (size == 1) defbyte(); else if (size == 4) deflong(); else if (size == 0 ) { defmesg(); j=30; } else defword(); while ( j-- ) { if (size==0) { lit=getint(queue+k,1); if (lit >= 32 && lit <= 126 && lit != '"' && lit != '\\' ) outbyte(lit); else { outstr("\"\n"); defbyte(); outdec(lit); nl(); lit=0; } k++; if ( j == 0 || k >=queueptr || lit == 0 ) { if (lit) outbyte('"'); nl(); break; } } else { outdec(getint(queue+k, size)); k += size ; if ( j == 0 || k >= queueptr ) { nl(); /* need <cr> */ break; } outbyte(','); /* separate bytes */ } } } output_section("code_compiler"); // output_section("code"); } nl(); }
errorsummary() { /* see if anything left hanging... */ if (ncmp) error("missing closing bracket"); /* open compound statement ... */ nl(); comment(); outdec(errcnt); /* total # errors */ outstr(" errors in compilation."); nl(); }
/* * updateline() - like s_refresh() but only for cursor line * * This determines whether or not we need to call s_refresh() to examine * the entire screen for changes. This occurs if the size of the cursor line * (in rows) has changed. */ static void updateline(void) { char *ptr; int col; int size; int j; if (RedrawingDisabled) /* Is this the correct action ? */ return; ptr = format_line(Curschar->linep->s, &col); size = 1 + ((col - 1) / Columns); if (Cline_size == size) { s_cursor_off(); windgoto(Cline_row, 0); if (P(P_NU)) { /* * This should be done more efficiently. */ outstr(mkline(cntllines(Filemem, Curschar))); } outstr(ptr); j = col; col %= Columns; if ((col != 0) || (j == 0)) { #ifdef T_END_L windgoto(Cline_row + size - 1, col); toutstr(T_END_L); #else for (; col < Columns; col++) outchar(' '); #endif } s_cursor_on(); } else { s_refresh(VALID_TO_CURSCHAR); } }
/* * fire_slime: * Fire a slime shot in the given direction */ static void fire_slime(PLAYER *pp, int req_index) { if (pp == NULL) return; #ifdef DEBUG if (req_index < 0 || req_index >= MAXSLIME) message(pp, "What you do?"); #endif while (req_index >= 0 && pp->p_ammo < slime_req[req_index]) req_index--; if (req_index < 0) { message(pp, "Not enough charges."); return; } if (pp->p_ncshot > MAXNCSHOT) return; if (pp->p_ncshot++ == MAXNCSHOT) { cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL); outstr(pp, " ", 3); } pp->p_ammo -= slime_req[req_index]; (void) snprintf(Buf, sizeof(Buf), "%3d", pp->p_ammo); cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL); outstr(pp, Buf, 3); add_shot(SLIME, pp->p_y, pp->p_x, pp->p_face, slime_req[req_index] * SLIME_FACTOR, pp, false, pp->p_face); pp->p_undershot = true; /* * Show the object to everyone */ showexpl(pp->p_y, pp->p_x, SLIME); for (pp = Player; pp < End_player; pp++) sendcom(pp, REFRESH); #ifdef MONITOR for (pp = Monitor; pp < End_monitor; pp++) sendcom(pp, REFRESH); #endif }
void print_tes(string tag) { char buf[BUFLEN]; /* danger: buffer overflow */ change_indent(- indent); if (xml) sprintf(buf, "</%s>",tag); else sprintf(buf, "tes"); (void) outstr(buf); end_line(); }
void print_set(string tag) { char buf[BUFLEN]; /* danger: buffer overflow */ if (xml) sprintf(buf, "<%s>", tag); else sprintf(buf, "set %s", tag); (void) outstr(buf); end_line(); change_indent(indent); }
void draw_screen(editor_t *ed) { int pos; int i; gotoxy(ed, 0, 0); outstr(ed, TEXT_COLOR); pos = ed->toppos; for (i = 0; i < ed->lines; i++) { if (pos < 0) { outstr(ed, CLREOL "\r\n"); } else { display_line(ed, pos, 1); pos = next_line(ed, pos); } } }
void con_getline(char *buf, int length) { int index = 0; char ch = 0; // loop until we encounter a linefeed or carriage return, or until we run out of space while (!get_quitflag()) { ch = con_getkey(); // if we get a linefeed or carriage return, we're done ... if ((ch == 10) || (ch == 13)) { break; } // backspace, it works but it doesn't look pretty on the screen else if (ch == 8) { if (index >0) { index = index - 1; outstr("[BACK]"); } } // if we've run out of space, terminate the string prematurely to avoid crashing else if (index >= (length - 1)) { break; } // otherwise if we get a printable character, add it to the string else if (ch >= ' ') { outchr(ch); // echo it to the screen buf[index] = ch; index = index + 1; } // else it was a non-printable character, so we ignore it } buf[index] = 0; // terminate the string newline(); // go to the next line }
void draw_full_statusline(editor_t *ed) { int namewidth = ed->cols - 28; gotoxy(ed, 0, ed->lines); sprintf(ed->linebuf, STATUS_COLOR "%*.*sF1=Help %c Ln %-6dCol %-4d" CLREOL TEXT_COLOR, -namewidth, namewidth, ed->title, ed->dirty ? '*' : ' ', ed->line + 1, column(ed, ed->linepos, ed->col) + 1); outstr(ed, ed->linebuf); }
void print_head(string tag, string type, int *dims) { char buf[128]; int *dp; if (strlen(type) == 1) { sprintf(buf, "%s %s", type_name(type), tag); (void) outstr(buf); } else { (void) outstr("struct { "); while (*type != (char) NULL) { sprintf(buf, "%s ", type_name(type++)); (void) outstr(buf); } sprintf(buf, "} %s", tag); (void) outstr(buf); } if (dims != NULL) /* is this a plural item? */ for (dp = dims; *dp != 0; dp++) { /* loop over dimensions */ sprintf(buf, "[%d]", *dp); /* format a dimension */ (void) outstr(buf); /* and print it out */ } }
void ConnectionInstance::sendDebugReply(string message) { string outstr("ZZZ "); json_t* topnode = json_object(); json_t* messagenode = json_string(message.c_str()); if (!messagenode) messagenode = json_string_nocheck("Failed to parse the debug reply as a valid UTF-8 string."); json_object_set_new_nocheck(topnode, "message", messagenode); const char* replystr = json_dumps(topnode, JSON_COMPACT); outstr += replystr; free((void*) replystr); json_decref(topnode); MessagePtr outMessage(MessageBuffer::FromString(outstr)); send(outMessage); }
/* * Close an include file */ void endinclude() { if (verbose) { toconsole(); outstr("#end include\n"); tofile(); } inpt2 = 0 ; lineno = saveline ; currfn = savecurr ; infunc = saveinfn ; fnstart = savestart ; }
/* Like outstr(), but quote for re-input into the shell. */ void outqstr(const char *p, struct output *file) { char ch; int inquotes; if (p[0] == '\0') { outstr("''", file); return; } /* Caller will handle '=' if necessary */ if (p[strcspn(p, "|&;<>()$`\\\"' \t\n*?[~#")] == '\0' || strcmp(p, "[") == 0) { outstr(p, file); return; } inquotes = 0; while ((ch = *p++) != '\0') { switch (ch) { case '\'': /* Can't quote single quotes inside single quotes. */ if (inquotes) outcslow('\'', file); inquotes = 0; outstr("\\'", file); break; default: if (!inquotes) outcslow('\'', file); inquotes = 1; outc(ch, file); } } if (inquotes) outcslow('\'', file); }
/** * Initialize the terminal of a player. * @param[in] pp A player. * [PSR] */ void stmonitor(PLAYER *pp) { int line; PLAYER *npp; memcpy(pp->p_maze, maze, sizeof maze); drawmaze(pp); (void) sprintf(gen_buf, "%5.5s%c%-10.10s %c", " ", stat_char(pp), pp->p_ident->i_name, pp->p_ident->i_team); line = STAT_MON_ROW + 1 + (pp - monitor); for (npp = player; npp < end_player; npp++) { cgoto(npp, line, STAT_NAME_COL); outstr(npp, gen_buf, STAT_NAME_LEN); } for (npp = monitor; npp < end_monitor; npp++) { cgoto(npp, line, STAT_NAME_COL); outstr(npp, gen_buf, STAT_NAME_LEN); } sendcom(pp, REFRESH); sendcom(pp, READY, 0); (void) fflush(pp->p_output); }
/* * "asm" pseudo-statement * * enters mode where assembly language statements are passed * intact through parser * */ doasm () { cmode = 0; FOREVER { xinline (); if (match ("#endasm")) break; if (feof (input)) break; outstr (line); nl (); } kill (); cmode = 1; }
/* * Print a list of valid signal names */ void printsignals(struct output *out, int len) { int n; if (len != 0) outc(' ', out); for (n = 1; n < NSIG; n++) { outfmt(out, "%s", trap_signame(n)); if ((n == NSIG/2) || n == (NSIG - 1)) outstr("\n", out); else outc(' ', out); } }
ostream _FAR & ostream::operator<< (long l) { char buf[MaxCharsInLong]; // result of conversion char *prefix = 0; // displayed numeric prefix string char *p; // find conversion base int base = (flags() & ios::hex) ? 16 : ((flags() & ios::oct) ? 8 : 10); // do we treat this as negative? (oct and hex are unsigned) int neg = base == 10 && l < 0; // value to use, exclusive of sign unsigned long ul = neg ? -l : l; if( base == 10 ) { p = todec(buf + MaxCharsInLong - 1, ul); // compute any sign prefix if( ul ) if( neg ) prefix = "-"; else if( flags() & ios::showpos ) prefix = "+"; } else if( base == 16 ) { int upper = (flags() & ios::uppercase) != 0; p = tohex(buf + MaxCharsInLong - 1, ul, upper); // compute any base prefix if( flags() & ios::showbase ) prefix = upper ? "0X" : "0x"; } else /* base == 8 */ { p = tooct(buf + MaxCharsInLong - 1, ul); // compute any base prefix if( flags() & ios::showbase ) prefix = "0"; } // now we have a formatted string for output, to be possibly padded outstr((char*)p, prefix); return *this; }
void screenclear() { register char *rp, *np; register char *end; outstr(T_ED); /* clear the display */ rp = Realscreen; end = Realscreen + Rows * Columns; np = Nextscreen; /* blank out the stored screens */ while (rp != end) *rp++ = *np++ = ' '; }
void #endif dumpvars() { int ident,type,storage; SYMBOL *ptr; if (!glbcnt) return; /* Start at the start! */ glbptr=STARTGLB; outstr("; --- Start of Static Variables ---\n\n"); /* Two different handlings, if an application then use defvars construct * if not, then just drop em using defs! * * Even more handlings...if asz80 used we dump into data sectio */ output_section("bss_compiler"); // output_section("bss"); ptr=STARTGLB; while (ptr < ENDGLB) { if (ptr->name[0] != 0 && ptr->name[0] != '0' ) { ident=ptr->ident; type =ptr->type; storage=ptr->storage; if (ident !=ENUM && type !=ENUM && ident != MACRO && ident != FUNCTION && storage != EXTERNAL && storage != DECLEXTN && storage != EXTERNP && storage != LSTKEXT && storage!=TYPDEF ) { prefix(); outname(ptr->name,1); col(); defstorage(); outdec(ptr->size); nl(); } } ++ptr; } /* Switch back to standard section */ output_section("code_compiler"); // output_section("code"); }
int outnameunderline(void) { char n[NAMESIZE]; if (!symname(n)) { error("invalid identifier"); kill_line(); return 1; } prefix(); outstr(n); return 0; }
void ConnectionInstance::sendError(int error) { string outstr("ERR "); json_t* topnode = json_object(); json_object_set_new_nocheck(topnode, "number", json_integer(error) ); json_object_set_new_nocheck(topnode, "message", json_string_nocheck(LuaConstants::getErrorMessage(error).c_str()) ); const char* errstr = json_dumps(topnode, JSON_COMPACT); outstr += errstr; MessagePtr message(MessageBuffer::FromString(outstr)); send(message); free((void*) errstr); json_decref(topnode); DLOG(INFO) << "Sending error to connection: " << outstr; }
/* * scan: * Turn on or increase length of a scan */ static void scan(PLAYER *pp) { if (pp->p_ammo <= 0) { message(pp, "No more charges"); return; } (void) snprintf(Buf, sizeof(Buf), "%3d", --pp->p_ammo); cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL); outstr(pp, Buf, 3); pp->p_scan += SCANLEN; if (pp->p_cloak >= 0) pp->p_cloak = -1; showstat(pp); }
void ConnectionInstance::sendError(int error, string message) { string outstr("ERR "); json_t* topnode = json_object(); json_object_set_new_nocheck(topnode, "number", json_integer(error) ); json_t* messagenode = json_string(message.c_str()); if (!messagenode) messagenode = json_string_nocheck("There was an error encoding this error message. Please report this to Kira."); json_object_set_new_nocheck(topnode, "message", messagenode); const char* errstr = json_dumps(topnode, JSON_COMPACT); outstr += errstr; MessagePtr outMessage(MessageBuffer::FromString(outstr)); send(outMessage); free((void*) errstr); json_decref(topnode); DLOG(INFO) << "Sending custom error to connection: " << outstr; }
void readline (void) { int k; FILE *unit; FOREVER { if (feof (input)) return; if ((unit = input2) == NULL) unit = input; kill_line (); while ((k = fgetc (unit)) != EOF) { if ((k == '\r') | (k == EOL) | (lptr >= LINEMAX)) break; line[lptr++] = k; } line_number++; line[lptr] = 0; if (k <= 0) if (input2 != NULL) { if (globals_h_in_process) { /* Add special treatment to ensure globals.h stuff appears at the beginning */ dumpglbs(); ol(".code"); globals_h_in_process = 0; } input2 = inclstk[--inclsp]; line_number = inclstk_line[inclsp]; fclose (unit); } if (lptr) { if ((ctext) & (cmode)) { flush_ins(); comment (); outstr (line); newl (); } lptr = 0; return; } } }
void mcputest::port_write(Uint16 Port, Uint8 Value) { char s[81] = { 0 }; Port &= 0xFF; // strip off high byte static Uint8 old_val[2][2] = { { 255, 255 }, { 1, 1 } }; Uint8 expected_val[2][2] = { { 0 } }; Uint8 which_cpu = cpu_getactivecpu(); if (Port > 1) { printline("WTF?"); return; } sprintf(s, "CPU #%u sends %u to port %u ... ", which_cpu, Value, Port); outstr(s); if (which_cpu == 0) { expected_val[0][Port] = (Uint8) (old_val[0][Port] + 1); } else { expected_val[1][Port] = (Uint8) (old_val[1][Port] - 1); } old_val[which_cpu][Port] = Value; if (expected_val[which_cpu][Port] == Value) { printline("CORRECT!"); } else { sprintf(s, "*** INCORRECT *** Expecting %u", expected_val[which_cpu][Port]); printline(s); } }
int echocmd(int argc, char **argv) { int nonl = 0; struct output *outs = out1; if (!*++argv) goto end; if (equal(*argv, "-n")) { nonl = ~nonl; if (!*++argv) goto end; } do { char c; c = *(*argv)++; if (!c) goto next; if (c != '\\') goto print; outstr(conv_escape_str(*argv - 1), outs); if (rval & 0x100) break; next: c = ' '; if (!*++argv) { end: if (nonl) { break; } c = '\n'; } print: outc(c, outs); } while (*argv); return 0; }