📄 consolefunctions.cc
字号:
sz = string-start;
dStrncpy(ret, start, sz);
ret[sz] = 0;
// copy remaining chunks
sz = dStrcspn(string, set); // skip chunk we're removing
if(string[sz] == 0) { // if that was the last...
if(string != start) {
ret[string - start - 1] = 0; // then kill any trailing delimiter
}
return ret; // and bail
}
string += sz + 1; // skip the extra field delimiter
dStrcat(ret, string);
return ret;
}
//--------------------------------------
ConsoleFunctionGroupBegin( FieldManipulators, "Functions to manipulate data returned in the form of \"x y z\".");
ConsoleFunction(getWord, const char *, 3, 3, "(string text, int index)")
{
argc;
return getUnit(argv[1], dAtoi(argv[2]), " \t\n");
}
ConsoleFunction(getWords, const char *, 3, 4, "(string text, int index, int endIndex=INF)")
{
U32 endIndex;
if(argc==3)
endIndex = 1000000;
else
endIndex = dAtoi(argv[3]);
return getUnits(argv[1], dAtoi(argv[2]), endIndex, " \t\n");
}
ConsoleFunction(setWord, const char *, 4, 4, "newText = setWord(text, index, replace)")
{
argc;
return setUnit(argv[1], dAtoi(argv[2]), argv[3], " \t\n");
}
ConsoleFunction(removeWord, const char *, 3, 3, "newText = removeWord(text, index)")
{
argc;
return removeUnit(argv[1], dAtoi(argv[2]), " \t\n");
}
ConsoleFunction(getWordCount, S32, 2, 2, "getWordCount(text)")
{
argc;
return getUnitCount(argv[1], " \t\n");
}
//--------------------------------------
ConsoleFunction(getField, const char *, 3, 3, "getField(text, index)")
{
argc;
return getUnit(argv[1], dAtoi(argv[2]), "\t\n");
}
ConsoleFunction(getFields, const char *, 3, 4, "getFields(text, index [,endIndex])")
{
U32 endIndex;
if(argc==3)
endIndex = 1000000;
else
endIndex = dAtoi(argv[3]);
return getUnits(argv[1], dAtoi(argv[2]), endIndex, "\t\n");
}
ConsoleFunction(setField, const char *, 4, 4, "newText = setField(text, index, replace)")
{
argc;
return setUnit(argv[1], dAtoi(argv[2]), argv[3], "\t\n");
}
ConsoleFunction(removeField, const char *, 3, 3, "newText = removeField(text, index)" )
{
argc;
return removeUnit(argv[1], dAtoi(argv[2]), "\t\n");
}
ConsoleFunction(getFieldCount, S32, 2, 2, "getFieldCount(text)")
{
argc;
return getUnitCount(argv[1], "\t\n");
}
//--------------------------------------
ConsoleFunction(getRecord, const char *, 3, 3, "getRecord(text, index)")
{
argc;
return getUnit(argv[1], dAtoi(argv[2]), "\n");
}
ConsoleFunction(getRecords, const char *, 3, 4, "getRecords(text, index [,endIndex])")
{
U32 endIndex;
if(argc==3)
endIndex = 1000000;
else
endIndex = dAtoi(argv[3]);
return getUnits(argv[1], dAtoi(argv[2]), endIndex, "\n");
}
ConsoleFunction(setRecord, const char *, 4, 4, "newText = setRecord(text, index, replace)")
{
argc;
return setUnit(argv[1], dAtoi(argv[2]), argv[3], "\n");
}
ConsoleFunction(removeRecord, const char *, 3, 3, "newText = removeRecord(text, index)" )
{
argc;
return removeUnit(argv[1], dAtoi(argv[2]), "\n");
}
ConsoleFunction(getRecordCount, S32, 2, 2, "getRecordCount(text)")
{
argc;
return getUnitCount(argv[1], "\n");
}
//--------------------------------------
ConsoleFunction(firstWord, const char *, 2, 2, "firstWord(text)")
{
argc;
const char *word = dStrchr(argv[1], ' ');
U32 len;
if(word == NULL)
len = dStrlen(argv[1]);
else
len = word - argv[1];
char *ret = Con::getReturnBuffer(len + 1);
dStrncpy(ret, argv[1], len);
ret[len] = 0;
return ret;
}
ConsoleFunction(restWords, const char *, 2, 2, "restWords(text)")
{
argc;
const char *word = dStrchr(argv[1], ' ');
if(word == NULL)
return "";
char *ret = Con::getReturnBuffer(dStrlen(word + 1) + 1);
dStrcpy(ret, word + 1);
return ret;
}
static bool isInSet(char c, const char *set)
{
if (set)
while (*set)
if (c == *set++)
return true;
return false;
}
ConsoleFunction(NextToken,const char *,4,4,"nextToken(str,token,delim)")
{
argc;
char *str = (char *) argv[1];
const char *token = argv[2];
const char *delim = argv[3];
if (str)
{
// skip over any characters that are a member of delim
// no need for special '\0' check since it can never be in delim
while (isInSet(*str, delim))
str++;
// skip over any characters that are NOT a member of delim
const char *tmp = str;
while (*str && !isInSet(*str, delim))
str++;
// terminate the token
if (*str)
*str++ = 0;
#ifdef TGE_RPG_SCRIPT
if(token[0] == '$')
Con::setVariable(token,tmp);
else
#endif
// set local variable if inside a function
if (gEvalState.stack.size() && gEvalState.stack.last()->scopeName)
Con::setLocalVariable(token,tmp);
else
Con::setVariable(token,tmp);
// advance str past the 'delim space'
while (isInSet(*str, delim))
str++;
}
return str;
}
ConsoleFunctionGroupEnd( FieldManipulators )
//----------------------------------------------------------------
ConsoleFunctionGroupBegin( TaggedStrings, "Functions dealing with tagging/detagging strings.");
ConsoleFunction(detag, const char *, 2, 2, "detag(textTagString)")
{
argc;
if(argv[1][0] == StringTagPrefixByte)
{
const char *word = dStrchr(argv[1], ' ');
if(word == NULL)
return "";
char *ret = Con::getReturnBuffer(dStrlen(word + 1) + 1);
dStrcpy(ret, word + 1);
return ret;
}
else
return argv[1];
}
ConsoleFunction(getTag, const char *, 2, 2, "getTag(textTagString)")
{
argc;
if(argv[1][0] == StringTagPrefixByte)
{
const char * space = dStrchr(argv[1], ' ');
U32 len;
if(space)
len = space - argv[1];
else
len = dStrlen(argv[1]) + 1;
char * ret = Con::getReturnBuffer(len);
dStrncpy(ret, argv[1] + 1, len - 1);
ret[len - 1] = 0;
return(ret);
}
else
return(argv[1]);
}
ConsoleFunctionGroupEnd( TaggedStrings );
//----------------------------------------------------------------
ConsoleFunctionGroupBegin( Output, "Functions to output to the console." );
ConsoleFunction(echo, void, 2, 0, "echo(text [, ... ])")
{
U32 len = 0;
S32 i;
for(i = 1; i < argc; i++)
len += dStrlen(argv[i]);
char *ret = Con::getReturnBuffer(len + 1);
ret[0] = 0;
for(i = 1; i < argc; i++)
dStrcat(ret, argv[i]);
Con::printf("%s", ret);
ret[0] = 0;
}
ConsoleFunction(warn, void, 2, 0, "warn(text [, ... ])")
{
U32 len = 0;
S32 i;
for(i = 1; i < argc; i++)
len += dStrlen(argv[i]);
char *ret = Con::getReturnBuffer(len + 1);
ret[0] = 0;
for(i = 1; i < argc; i++)
dStrcat(ret, argv[i]);
Con::warnf(ConsoleLogEntry::General, "%s", ret);
ret[0] = 0;
}
ConsoleFunction(error, void, 2, 0, "error(text [, ... ])")
{
U32 len = 0;
S32 i;
for(i = 1; i < argc; i++)
len += dStrlen(argv[i]);
char *ret = Con::getReturnBuffer(len + 1);
ret[0] = 0;
for(i = 1; i < argc; i++)
dStrcat(ret, argv[i]);
Con::errorf(ConsoleLogEntry::General, "%s", ret);
ret[0] = 0;
}
ConsoleFunction(expandEscape, const char *, 2, 2, "expandEscape(text)")
{
argc;
char *ret = Con::getReturnBuffer(dStrlen(argv[1])*2 + 1); // worst case situation
expandEscape(ret, argv[1]);
return ret;
}
ConsoleFunction(collapseEscape, const char *, 2, 2, "collapseEscape(text)")
{
argc;
char *ret = Con::getReturnBuffer(dStrlen(argv[1]) + 1); // worst case situation
dStrcpy( ret, argv[1] );
collapseEscape( ret );
return ret;
}
ConsoleFunction(setLogMode, void, 2, 2, "setLogMode(mode);")
{
argc;
Con::setLogMode(dAtoi(argv[1]));
}
ConsoleFunction(setEchoFileLoads, void, 2, 2, "setEchoFileLoads(bool);")
{
argc;
ResourceManager->setFileNameEcho(dAtob(argv[1]));
}
ConsoleFunctionGroupEnd( Output );
//----------------------------------------------------------------
ConsoleFunction(quit, void, 1, 1, "quit() End execution of Torque.")
{
argc; argv;
Platform::postQuitMessage(0);
}
ConsoleFunction(quitWithErrorMessage, void, 2, 2, "quitWithErrorMessage(msg)"
" - Quit, showing the provided error message. This is equivalent"
" to an AssertISV.")
{
AssertISV(false, argv[1]);
}
//----------------------------------------------------------------
ConsoleFunction( gotoWebPage, void, 2, 2, "( address ) - Open a web page in the user's favorite web browser." )
{
argc;
Platform::openWebBrowser( argv[1] );
}
//----------------------------------------------------------------
ConsoleFunctionGroupBegin(MetaScripting, "Functions that let you manipulate the scripting engine programmatically.");
ConsoleFunction(call, const char *, 2, 0, "call(funcName [,args ...])")
{
return Con::execute(argc - 1, argv + 1);
}
static U32 execDepth = 0;
static U32 journalDepth = 1;
ConsoleFunction(compile, bool, 2, 2, "compile(fileName)")
{
argc;
char nameBuffer[512];
char* script = NULL;
U32 scriptSize = 0;
Stream *compiledStream = NULL;
FileTime comModifyTime, scrModifyTime;
Con::expandScriptFilename(scriptFilenameBuffer, sizeof(scriptFilenameBuffer), argv[1]);
dSprintf(nameBuffer, sizeof(nameBuffer), "%s.dso", scriptFilenameBuffer);
ResourceObject *rScr = ResourceManager->find(scriptFilenameBuffer);
ResourceObject *rCom = ResourceManager->find(nameBuffer);
if(rCom)
rCom->getFileTimes(NULL, &comModifyTime);
if(rScr)
rScr->getFileTimes(NULL, &scrModifyTime);
Stream *s = ResourceManager->openStream(scriptFilenameBuffer);
if(s)
{
scriptSize = ResourceManager->getSize(scriptFilenameBuffer);
script = new char [scriptSize+1];
s->read(scriptSize, script);
ResourceManager->closeStream(s);
script[scriptSize] = 0;
}
if (!scriptSize || !script)
{
delete [] script;
Con::errorf(ConsoleLogEntry::Script, "compile: invalid script file %s.", scriptFilenameBuffer);
return false;
}
// compile this baddie.
Con::printf("Compiling %s...", scriptFilenameBuffer);
CodeBlock *code = new CodeBlock();
code->compile(nameBuffer, scriptFilenameBuffer, script);
delete code;
code = NULL;
delete[] script;
return true;
}
ConsoleFunction(exec, bool, 2, 4, "exec(fileName [, nocalls [,journalScript]])")
{
bool journal = false;
execDepth++;
if(journalDepth >= execDepth)
journalDepth = execDepth + 1;
else
journal = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -