📄 com.java
字号:
/* * Com.java * Copyright (C) 2003 * * $Id: Com.java,v 1.14 2005/12/16 21:17:08 salomo Exp $ *//*Copyright (C) 1997-2001 Id Software, Inc.This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, 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 ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/package jake2.qcommon;import jake2.Defines;import jake2.Globals;import jake2.client.CL;import jake2.client.Console;import jake2.game.Cmd;import jake2.server.SV_MAIN;import jake2.sys.Sys;import jake2.util.*;import java.io.*;/** * Com * */public final class Com{ static String debugContext = ""; static String _debugContext = ""; static int com_argc; static String[] com_argv= new String[Defines.MAX_NUM_ARGVS]; public abstract static class RD_Flusher { public abstract void rd_flush(int target, StringBuffer buffer); } static int rd_target; static StringBuffer rd_buffer; static int rd_buffersize; static RD_Flusher rd_flusher; public static void BeginRedirect(int target, StringBuffer buffer, int buffersize, RD_Flusher flush) { if (0 == target || null == buffer || 0 == buffersize || null == flush) return; rd_target= target; rd_buffer= buffer; rd_buffersize= buffersize; rd_flusher= flush; rd_buffer.setLength(0); } public static void EndRedirect() { rd_flusher.rd_flush(rd_target, rd_buffer); rd_target= 0; rd_buffer= null; rd_buffersize= 0; rd_flusher= null; } static boolean recursive= false; static String msg= ""; // helper class to replace the pointer-pointer public static class ParseHelp { public ParseHelp(String in) { if (in == null) { data= null; length = 0; } else { data= in.toCharArray(); length = data.length; } index= 0; } public ParseHelp(char in[]) { this(in, 0); } public ParseHelp(char in[], int offset) { data= in; index= offset; if (data != null) length = data.length; else length = 0; } public char getchar() { if (index < length) { return data[index]; } return 0; } public char nextchar() { // faster than if index++; if (index < length) { return data[index]; } return 0; } public char prevchar() { if (index > 0) { index--; return data[index]; } return 0; } public boolean isEof() { return index >= length; } public int index; public char data[]; private int length; public char skipwhites() { char c = 0; while ( index < length && ((c= data[index]) <= ' ') && c != 0) index++; return c; } public char skipwhitestoeol() { char c = 0; while ( index < length &&((c= data[index]) <= ' ') && c != '\n' && c != 0) index++; return c; } public char skiptoeol() { char c = 0; while ( index < length &&(c= data[index]) != '\n' && c != 0) index++; return c; } } public static char com_token[]= new char[Defines.MAX_TOKEN_CHARS]; // See GameSpanw.ED_ParseEdict() to see how to use it now. public static String Parse(ParseHelp hlp) { int c; int len = 0; if (hlp.data == null) { return ""; } while (true) { // skip whitespace hlp.skipwhites(); if (hlp.isEof()) { hlp.data = null; return ""; } // skip // comments if (hlp.getchar() == '/') { if (hlp.nextchar() == '/') { hlp.skiptoeol(); // goto skip whitespace continue; } else { hlp.prevchar(); break; } } else break; } // handle quoted strings specially if (hlp.getchar() == '\"') { hlp.nextchar(); while (true) { c = hlp.getchar(); hlp.nextchar(); if (c == '\"' || c == 0) { return new String(com_token, 0, len); } if (len < Defines.MAX_TOKEN_CHARS) { com_token[len] = (char) c; len++; } } } // parse a regular word c = hlp.getchar(); do { if (len < Defines.MAX_TOKEN_CHARS) { com_token[len] = (char) c; len++; } c = hlp.nextchar(); } while (c > 32); if (len == Defines.MAX_TOKEN_CHARS) { Com.Printf("Token exceeded " + Defines.MAX_TOKEN_CHARS + " chars, discarded.\n"); len = 0; } return new String(com_token, 0, len); } public static xcommand_t Error_f= new xcommand_t() { public void execute() throws longjmpException { Error(Defines.ERR_FATAL, Cmd.Argv(1)); } }; public static void Error(int code, String fmt) throws longjmpException { Error(code, fmt, null); } public static void Error(int code, String fmt, Vargs vargs) throws longjmpException { // va_list argptr; // static char msg[MAXPRINTMSG]; if (recursive) { Sys.Error("recursive error after: " + msg); } recursive= true; msg= sprintf(fmt, vargs); if (code == Defines.ERR_DISCONNECT) { CL.Drop(); recursive= false; throw new longjmpException(); } else if (code == Defines.ERR_DROP) { Com.Printf("********************\nERROR: " + msg + "\n********************\n"); SV_MAIN.SV_Shutdown("Server crashed: " + msg + "\n", false); CL.Drop(); recursive= false; throw new longjmpException(); } else { SV_MAIN.SV_Shutdown("Server fatal crashed: %s" + msg + "\n", false); CL.Shutdown(); } Sys.Error(msg); } /** * Com_InitArgv checks the number of command line arguments * and copies all arguments with valid length into com_argv. */ static void InitArgv(String[] args) throws longjmpException { if (args.length > Defines.MAX_NUM_ARGVS) { Com.Error(Defines.ERR_FATAL, "argc > MAX_NUM_ARGVS"); } Com.com_argc= args.length; for (int i= 0; i < Com.com_argc; i++) { if (args[i].length() >= Defines.MAX_TOKEN_CHARS) Com.com_argv[i]= ""; else Com.com_argv[i]= args[i]; } } public static void DPrintf(String fmt) { _debugContext = debugContext; DPrintf(fmt, null); _debugContext = ""; } public static void dprintln(String fmt) { DPrintf(_debugContext + fmt + "\n", null); } public static void Printf(String fmt) { Printf(_debugContext + fmt, null); } public static void DPrintf(String fmt, Vargs vargs) { if (Globals.developer == null || Globals.developer.value == 0) return; // don't confuse non-developers with techie stuff... _debugContext = debugContext; Printf(fmt, vargs); _debugContext=""; } /** Prints out messages, which can also be redirected to a remote client. */ public static void Printf(String fmt, Vargs vargs) { String msg= sprintf(_debugContext + fmt, vargs); if (rd_target != 0) { if ((msg.length() + rd_buffer.length()) > (rd_buffersize - 1)) { rd_flusher.rd_flush(rd_target, rd_buffer); rd_buffer.setLength(0); } rd_buffer.append(msg); return; } Console.Print(msg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -