/********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ***********************************************************************/ #include #include #include #include int console_output=0; int console_rfcstyle=0; /* the integer value is for non-human control of the civserver process only. -1 => ignore 0 = for human eyes only 1 = version info 100 = success 200 = failure of requested operation 201 = failure of metaserver 300 = failure of syntax 4xx = failure of unrequested operation 500 = ready for input */ /* write to console without line-break */ int console_dump(int i,char *message, ...) { static char buf[512]; va_list args; va_start(args, message); vsprintf(buf, message, args); if ((console_rfcstyle) && (i >= 0)) printf("%.3d %s", i, buf); else printf("%s", buf); console_output=1; return strlen(message); } /* write to console and add line-break */ void console_write(int i, char *message, ...) { static char buf[512]; va_list args; va_start(args, message); vsprintf(buf, message, args); if ((console_rfcstyle) && (i >= 0)) printf("%.3d %s\n", i, buf); else printf("%s\n", buf); console_output=1; } /* ensure timely update */ void console_flush(void) { fflush(stdout); } /* end of turn stuff */ void console_show_prompt(void) { static int first=1; if (first) console_write(0, "\nGet a list of the available commands with 'h'."); if (console_output) console_dump(500,"> "); console_flush(); first = 0; console_output = 0; } /* set style */ void console_set_style( int i ) { console_rfcstyle = i; if (console_rfcstyle) console_write(100, "Ok. RFC-style set."); else console_write(100, "Ok. Standard style set."); }