value make_constant(constant c, bool save_location, fncode fn) { struct obj *cst; switch (c->vclass) { case cst_string: cst = (value)alloc_string(c->u.string); SET_READONLY(cst); SET_IMMUTABLE(cst); return cst; case cst_gsymbol: return make_gsymbol(c->u.string, fn); case cst_quote: return make_quote(c, save_location, fn); case cst_list: return make_list(c, c->u.constants, 1, save_location, fn); case cst_array: return make_array(c->u.constants, fn); case cst_int: return makeint(c->u.integer); case cst_float: return alloc_mudlle_float(c->u.mudlle_float); case cst_table: return make_table(c->u.constants, fn); case cst_symbol: return make_symbol(c->u.constpair, fn); default: abort(); } }
/* Parenthesize an expression. Set expr to the node after the first full * expression. */ NODE *paren_expr(NODE **expr, BOOLEAN inparen) { NODE *first = NIL, *tree = NIL, *pproc, *retval; NODE **ifnode = (NODE **)NIL; if (*expr == NIL) { if (inparen) err_logo(PAREN_MISMATCH, NIL); return *expr; } first = car(*expr); pop(*expr); if (nodetype(first) == CASEOBJ && !numberp(first)) { if (first == Left_Paren) { tree = paren_expr(expr, TRUE); tree = paren_infix(tree, expr, -1, TRUE); if (*expr == NIL) err_logo(PAREN_MISMATCH, NIL); else if (car(*expr) != Right_Paren) { /* throw the rest away */ int parens; for (parens = 0; *expr; pop(*expr)) { if (car(*expr) == Left_Paren) parens++; else if (car(*expr) == Right_Paren) if (parens-- == 0) { pop(*expr); break; } } first = tree /* car(tree) */ ; /* 6.0 */ tree = cons(Not_Enough_Node, NIL); /* tell eval */ tree_dk_how=UNBOUND; if (is_list(first)) first = car(first); if (nodetype(first) != CASEOBJ || procnode__caseobj(first) == UNDEFINED) err_logo(DK_HOW, first); else err_logo(TOO_MUCH, first); } else pop(*expr); retval = tree; } else if (first == Right_Paren) { err_logo(UNEXPECTED_PAREN, NIL); if (inparen) push(first, *expr); retval = NIL; } else if (first == Minus_Sign) { push(Minus_Tight, *expr); retval = paren_infix(make_intnode((FIXNUM) 0), expr, -1, inparen); } else { /* it must be a procedure */ check_library(first); pproc = procnode__caseobj(first); if (pproc == UNDEFINED) { if (missing_space(first)) { push(missing_numeric, *expr); first = missing_alphabetic; pproc = procnode__caseobj(first); retval = gather_args(first, pproc, expr, inparen, ifnode); if (retval != UNBOUND) { retval = cons(first, retval); } } else if (is_setter(first)) { retval = gather_some_args(0, 1, expr, inparen, ifnode); if (retval != UNBOUND) { retval = cons(first, retval); } } else { retval = cons(first, NIL); tree_dk_how = first; } } else if (nodetype(pproc) == INFIX && NOT_THROWING) { err_logo(NOT_ENOUGH, first); retval = cons(first, NIL); } else { /* Kludge follows to turn IF to IFELSE sometimes. */ if (isName(first, Name_if)) { ifnode = &first; } retval = gather_args(first, pproc, expr, inparen, ifnode); if (retval != UNBOUND) { retval = cons(first, retval); } } } } else if (is_list(first)) { /* quoted list */ retval = make_quote(first); } else { return first; } return retval; }
NODE *runparse_node(NODE *nd, NODE **ndsptr) { NODE *outline = NIL, *tnode = NIL, *lastnode = NIL, *snd; char *wptr, *tptr; struct string_block *whead; int wlen, wcnt, tcnt, isnumb, gotdot; NODETYPES wtyp; BOOLEAN monadic_minus = FALSE; if (nd == Minus_Tight) return cons(nd, NIL); snd = cnv_node_to_strnode(nd); wptr = getstrptr(snd); wlen = getstrlen(snd); wtyp = nodetype(snd); wcnt = 0; whead = getstrhead(snd); while (wcnt < wlen) { if (*wptr == ';') { *ndsptr = NIL; break; } if (*wptr == '"') { tcnt = 0; tptr = ++wptr; wcnt++; while (wcnt < wlen && !parens(*wptr)) { if (wtyp == BACKSLASH_STRING && getparity(*wptr)) wtyp = PUNBOUND; /* flag for "\( case */ wptr++, wcnt++, tcnt++; } if (wtyp == PUNBOUND) { wtyp = BACKSLASH_STRING; tnode = cons(make_quote(intern(make_strnode(tptr, NULL, tcnt, wtyp, noparity_strnzcpy))), NIL); } else tnode = cons(make_quote(intern(make_strnode(tptr, whead, tcnt, wtyp, strnzcpy))), NIL); } else if (*wptr == ':') { tcnt = 0; tptr = ++wptr; wcnt++; while (wcnt < wlen && !parens(*wptr) && !infixs(*wptr)) wptr++, wcnt++, tcnt++; tnode = cons(make_colon(intern(make_strnode(tptr, whead, tcnt, wtyp, strnzcpy))), NIL); } else if (wcnt == 0 && *wptr == '-' && monadic_minus == FALSE && wcnt+1 < wlen && !white_space(*(wptr+1))) { /* minus sign with space before and no space after is unary */ tnode = cons(make_intnode((FIXNUM)0), NIL); monadic_minus = TRUE; } else if (parens(*wptr) || infixs(*wptr)) { if (monadic_minus) tnode = cons(Minus_Tight, NIL); else if (wcnt+1 < wlen && ((*wptr == '<' && (*(wptr+1) == '=' || *(wptr+1) == '>')) || (*wptr == '>' && *(wptr+1) == '='))) { tnode = cons(intern(make_strnode(wptr, whead, 2, STRING, strnzcpy)), NIL); wptr++, wcnt++; } else tnode = cons(intern(make_strnode(wptr, whead, 1, STRING, strnzcpy)), NIL); monadic_minus = FALSE; wptr++, wcnt++; } else { tcnt = 0; tptr = wptr; /* isnumb 4 means nothing yet; * 0 means digits so far, 1 means just saw * 'e' so minus can be next, 2 means no longer * eligible even if an 'e' comes along */ isnumb = 4; gotdot = 0; if (*wptr == '?') { isnumb = 3; /* turn ?5 to (? 5) */ wptr++, wcnt++, tcnt++; } while (wcnt < wlen && !parens(*wptr) && (!infixs(*wptr) || (isnumb == 1 && (*wptr == '-' || *wptr == '+')))) { if (isnumb == 4 && isdigit(*wptr)) isnumb = 0; if (isnumb == 0 && tcnt > 0 && (*wptr == 'e' || *wptr == 'E')) isnumb = 1; else if (!(isdigit(*wptr) || (!gotdot && *wptr == '.')) || isnumb == 1) isnumb = 2; if (*wptr == '.') gotdot++; wptr++, wcnt++, tcnt++; } if (isnumb == 3 && tcnt > 1) { /* ?5 syntax */ NODE *qmtnode; qmtnode = cons_list(0, Left_Paren, Query, cnv_node_to_numnode (make_strnode(tptr+1, whead, tcnt-1, wtyp, strnzcpy)), END_OF_LIST); if (outline == NIL) { outline = qmtnode; } else { setcdr(lastnode, qmtnode); } lastnode = cddr(qmtnode); tnode = cons(Right_Paren, NIL); } else if (isnumb < 2 && tcnt > 0) { tnode = cons(cnv_node_to_numnode(make_strnode(tptr, whead, tcnt, wtyp, strnzcpy)), NIL); } else tnode = cons(intern(make_strnode(tptr, whead, tcnt, wtyp, strnzcpy)), NIL); } if (outline == NIL) outline = tnode; else setcdr(lastnode, tnode); lastnode = tnode; } return(outline); }
NODE *maybe_quote(NODE *nd) { if (nd == UNBOUND || aggregate(nd) || numberp(nd)) return (nd); return (make_quote(nd)); }
void ServerLogger::prepare() { map_name = make_quote(get_map_name()).c_str(); map_description = make_quote(get_map_description()).c_str(); }
void ServerLogger::log(LogType type, const std::string& text, Player *p1, Player *p2, const void *data1, const void *data2, const void *data3, const void *data4) { if (verbose) { time_t t = time(0); strftime (time_buffer, sizeof(time_buffer), "%Y-%m-%d %H:%M:%S", localtime(&t)); switch (type) { case LogTypePlayerConnect: case LogTypePlayerDisconnect: /* TIME LOG TEXT PLAYER_NAME */ sprintf(buffer, "%s %03d %s %s", time_buffer, type, make_quote(text).c_str(), make_quote(p1->get_player_name()).c_str()); break; case LogTypeNewMap: /* TIME LOG MAP MAP_DESC */ sprintf(buffer, "%s %03d %s %s", time_buffer, type, map_name.c_str(), map_description.c_str()); break; case LogTypeChatMessage: case LogTypeWarmUp: case LogTypeGameBegins: case LogTypeGameOver: /* TIME LOG MAP MAP_DESC TEXT */ sprintf(buffer, "%s %03d %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str()); break; case LogTypeFrag: /* TIME LOG MAP MAP_DESC TEXT FRAG_PLAYER KILL_PLAYER REASON */ sprintf(buffer, "%s %03d %s %s %s %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str(), make_quote(p1->get_player_name()).c_str(), make_quote(p2->get_player_name()).c_str(), make_quote(static_cast<const char *>(data1)).c_str()); break; case LogTypeKill: /* TIME LOG MAP MAP_DESC TEXT PLAYER_NAME REASON */ sprintf(buffer, "%s %03d %s %s %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str(), make_quote(p1->get_player_name()).c_str(), make_quote(static_cast<const char *>(data1)).c_str()); break; case LogTypeRedTeamJoin: case LogTypeBlueTeamJoin: case LogTypeRedFlagPicked: case LogTypeRedFlagDropped: case LogTypeRedFlagSaved: case LogTypeBlueFlagPicked: case LogTypeBlueFlagDropped: case LogTypeBlueFlagSaved: case LogTypeCoinPicked: case LogTypeCoinDropped: case LogTypeJoin: /* TIME LOG MAP MAP_DESC TEXT PLAYER_NAME */ sprintf(buffer, "%s %03d %s %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str(), make_quote(p1->get_player_name()).c_str()); break; case LogTypeRedFlagReturned: case LogTypeBlueFlagReturned: /* TIME LOG MAP MAP_DESC TEXT */ sprintf(buffer, "%s %03d %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str()); break; case LogTypeTeamRedScored: case LogTypeTeamBlueScored: /* TIME LOG MAP MAP_DESC TEXT PLAYER_NAME */ sprintf(buffer, "%s %03d %s %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str(), make_quote(p1->get_player_name()).c_str()); break; case LogTypeRoundFinished: /* TIME LOG MAP MAP_DESC TEXT PLAYER TIME_IN_S */ sprintf(buffer, "%s %03d %s %s %s %s %.2f", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str(), make_quote(p1->get_player_name()).c_str(), *static_cast<const float *>(data1)); break; case LogTypeEndOfStats: /* TIME LOG MAP MAP_DESC TEXT */ sprintf(buffer, "%s %03d %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str()); break; case LogTypeStatsTDMTeamScore: case LogTypeStatsCTFTeamScore: case LogTypeStatsGOHTeamScore: /* TIME LOG MAP MAP_DESC TEXT TEAM_RED SCORE TEAM_BLUE SCORE */ sprintf(subbuffer, "%s %d %s %d", make_quote(static_cast<const char *>(data1)).c_str(), *static_cast<const score_t *>(data2), make_quote(static_cast<const char *>(data3)).c_str(), *static_cast<const score_t *>(data4)); sprintf(buffer, "%s %03d %s %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str(), subbuffer); break; case LogTypeStatsDM: case LogTypeStatsTDMTeamRed: case LogTypeStatsTDMTeamBlue: case LogTypeStatsCTFTeamRed: case LogTypeStatsCTFTeamBlue: case LogTypeStatsGOHTeamRed: case LogTypeStatsGOHTeamBlue: /* TIME LOG MAP MAP_DESC TEXT RANK PLAYER SCORE FRAGS KILLS */ sprintf(subbuffer, "%d %s %d %d %d", *static_cast<const int *>(data1), make_quote(p1->get_player_name()).c_str(), *static_cast<const sscore_t *>(data2), *static_cast<const score_t *>(data3), *static_cast<const score_t *>(data4)); sprintf(buffer, "%s %03d %s %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str(), subbuffer); break; case LogTypeStatsSR: /* TIME LOG MAP MAP_DESC TEXT RANK PLAYER LAPS BEST LAST */ if (!data3) { sprintf(subbuffer, "%d %s %d N/A N/A", *static_cast<const int *>(data1), make_quote(p1->get_player_name()).c_str(), *static_cast<const int *>(data2)); } else { sprintf(subbuffer, "%d %s %d %.2f %.2f", *static_cast<const int *>(data1), make_quote(p1->get_player_name()).c_str(), *static_cast<const int *>(data2), *static_cast<const float *>(data3), *static_cast<const float *>(data4)); } sprintf(buffer, "%s %03d %s %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str(), subbuffer); break; case LogTypeStatsCTC: /* TIME LOG MAP MAP_DESC TEXT RANK PLAYER MIN:SEC */ sprintf(subbuffer, "%d %s %d:%02d", *static_cast<const int *>(data1), make_quote(p1->get_player_name()).c_str(), *static_cast<const int *>(data2), *static_cast<const int *>(data3)); sprintf(buffer, "%s %03d %s %s %s %s", time_buffer, type, map_name.c_str(), map_description.c_str(), make_quote(text).c_str(), subbuffer); break; case LogTypePlayerNameChange: /* TIME LOG TEXT OLD_NAME NEW_NAME */ sprintf(buffer, "%s %03d %s %s %s", time_buffer, type, make_quote(text).c_str(), make_quote(static_cast<const char *>(data1)).c_str(), make_quote(static_cast<const char *>(data2)).c_str()); break; case _LogTypeMAX: /* do nothing */ return; break; } stream << buffer << std::endl; } else { if (text.length()) { stream << text << std::endl; } } }