Added more path building stuff

Addeed text parsing API

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40350
This commit is contained in:
David Anderson 2007-01-25 04:37:23 +00:00
parent aeb512c444
commit e506745890
11 changed files with 228 additions and 24 deletions

View File

@ -608,10 +608,13 @@ void AdminCache::DumpAdminCache(int cache_flags, bool rebuild)
{ {
List<IAdminListener *>::iterator iter; List<IAdminListener *>::iterator iter;
IAdminListener *pListener; IAdminListener *pListener;
cell_t result;
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
{ {
pListener = (*iter); pListener = (*iter);
pListener->OnRebuildAdminCache(cache_flags); pListener->OnRebuildAdminCache(cache_flags);
} }
m_pCacheFwd->PushCell(cache_flags);
m_pCacheFwd->Execute(&result);
} }
} }

View File

@ -228,7 +228,7 @@
> >
</File> </File>
<File <File
RelativePath="..\..\public\smn_admin.cpp" RelativePath="..\smn_admin.cpp"
> >
</File> </File>
<File <File

View File

@ -428,6 +428,18 @@ static cell_t sm_WriteFileLine(IPluginContext *pContext, const cell_t *params)
return 1; return 1;
} }
static cell_t sm_BuildPath(IPluginContext *pContext, const cell_t *params)
{
char path[PLATFORM_MAX_PATH], *fmt, *buffer;
int arg = 4;
pContext->LocalToString(params[2], &buffer);
pContext->LocalToString(params[4], &fmt);
atcprintf(path, sizeof(path), fmt, pContext, params, &arg);
return g_SourceMod.BuildPath(Path_SM_Rel, buffer, params[3], "%s", path);
}
static FileNatives s_FileNatives; static FileNatives s_FileNatives;
REGISTER_NATIVES(filesystem) REGISTER_NATIVES(filesystem)
@ -446,5 +458,6 @@ REGISTER_NATIVES(filesystem)
{"FileSize", sm_FileSize}, {"FileSize", sm_FileSize},
{"RemoveDir", sm_RemoveDir}, {"RemoveDir", sm_RemoveDir},
{"WriteFileLine", sm_WriteFileLine}, {"WriteFileLine", sm_WriteFileLine},
{"BuildPath", sm_BuildPath},
{NULL, NULL}, {NULL, NULL},
}; };

View File

@ -48,6 +48,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t err_max, bool late)
{ {
g_BaseDir.assign(g_SMAPI->GetBaseDir()); g_BaseDir.assign(g_SMAPI->GetBaseDir());
g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/addons/sourcemod", g_BaseDir.c_str()); g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/addons/sourcemod", g_BaseDir.c_str());
g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "addons/sourcemod");
/* Attempt to load the JIT! */ /* Attempt to load the JIT! */
char file[PLATFORM_MAX_PATH]; char file[PLATFORM_MAX_PATH];
@ -229,6 +230,8 @@ size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, c
base = GetModPath(); base = GetModPath();
} else if (type == Path_SM) { } else if (type == Path_SM) {
base = GetSourceModPath(); base = GetSourceModPath();
} else if (type == Path_SM_Rel) {
base = m_SMRelDir;
} }
if (base) if (base)

View File

@ -56,6 +56,7 @@ private:
void DoGlobalPluginLoads(); void DoGlobalPluginLoads();
private: private:
char m_SMBaseDir[PLATFORM_MAX_PATH+1]; char m_SMBaseDir[PLATFORM_MAX_PATH+1];
char m_SMRelDir[PLATFORM_MAX_PATH+1];
bool m_IsMapLoading; bool m_IsMapLoading;
bool m_ExecPluginReload; bool m_ExecPluginReload;
}; };

View File

@ -1487,7 +1487,7 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc
g_RootMenu.ConsolePrint(" Description: %s", info->description); g_RootMenu.ConsolePrint(" Description: %s", info->description);
} }
g_RootMenu.ConsolePrint(" Debugging: %s", pl->IsDebugging() ? "yes" : "no"); g_RootMenu.ConsolePrint(" Debugging: %s", pl->IsDebugging() ? "yes" : "no");
g_RootMenu.ConsolePrint(" Paused: %s", pl->GetStatus() == Plugin_Running ? "yes" : "no"); g_RootMenu.ConsolePrint(" Paused: %s", pl->GetStatus() == Plugin_Running ? "no" : "yes");
} else { } else {
g_RootMenu.ConsolePrint(" Load error: %s", pl->m_errormsg); g_RootMenu.ConsolePrint(" Load error: %s", pl->m_errormsg);
g_RootMenu.ConsolePrint(" File info: (title \"%s\") (version \"%s\")", g_RootMenu.ConsolePrint(" File info: (title \"%s\") (version \"%s\")",

View File

@ -144,7 +144,7 @@ native bool:GetAdmGroupAddFlag(GroupId:id, AdminFlag:flag);
* @param total Total number of flags that can be stored in the array (AdminFlags_TOTAL, usually). * @param total Total number of flags that can be stored in the array (AdminFlags_TOTAL, usually).
* @return Number of flags that were written to the array. * @return Number of flags that were written to the array.
*/ */
native GetAdmGroupAddFlagBits(GroupId:id, bool flags[], total); native GetAdmGroupAddFlagBits(GroupId:id, bool:flags[], total);
/** /**
* Toggles a generic immunity type. * Toggles a generic immunity type.

View File

@ -22,6 +22,23 @@ enum FileType
#define SEEK_CUR 1 #define SEEK_CUR 1
#define SEEK_END 2 #define SEEK_END 2
enum PathType
{
Path_SM, /* SourceMod root folder */
};
/**
* @brief Builds a path relative to the SourceMod folder.
*
* @param type Type of path to build as the base.
* @param buffer Buffer to store the path.
* @param maxlength Maximum length of buffer.
* @param fmt Format string.
* @param ... Format arguments.
* @return Number of bytes written to buffer (not including null terminator).
*/
native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[], ...);
/** /**
* @brief Opens a directory/folder for contents enumeration. * @brief Opens a directory/folder for contents enumeration.
* @note Directories are closed with CloseHandle(). * @note Directories are closed with CloseHandle().

View File

@ -21,6 +21,7 @@ struct Plugin
#include <handles> #include <handles>
#include <string> #include <string>
#include <admin> #include <admin>
#include <files>
/** /**
* Declare this as a struct in your plugin to expose its information. * Declare this as a struct in your plugin to expose its information.
@ -41,7 +42,7 @@ public Plugin:myinfo;
* *
* @noreturn * @noreturn
*/ */
forward OnPluginInit(Handle:myself); forward OnPluginStart(Handle:myself);
/** /**
* Called before OnPluginInit, in case the plugin wants to check for load failure. * Called before OnPluginInit, in case the plugin wants to check for load failure.
@ -65,7 +66,7 @@ forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
* *
* @noreturn * @noreturn
*/ */
forward OnPluginUnload(); forward OnPluginEnd();
/** /**
* Called when the plugin's pause status is changing. * Called when the plugin's pause status is changing.

View File

@ -0,0 +1,165 @@
#if defined _textparse_included
#endinput
#endif
#define _textparse_included
/********************************
* Everything below describes the SMC Parse, or "SourceMod Configuration" format.
* This parser is entirely event based. You must hook events to receive data.
* The file format itself is nearly identical to Valve's KeyValues format.
********************************/
enum SMCResult
{
SMCParse_Continue, //continue parsing
SMCParse_Halt, //stop parsing here
SMCParse_HaltFail //stop parsing and return failure
};
enum SMCError
{
SMCError_Okay = 0, //no error
SMCError_StreamOpen, //stream failed to open
SMCError_StreamError, //the stream died... somehow
SMCError_Custom, //a custom handler threw an error
SMCError_InvalidSection1, //a section was declared without quotes, and had extra tokens
SMCError_InvalidSection2, //a section was declared without any header
SMCError_InvalidSection3, //a section ending was declared with too many unknown tokens
SMCError_InvalidSection4, //a section ending has no matching beginning
SMCError_InvalidSection5, //a section beginning has no matching ending
SMCError_InvalidTokens, //there were too many unidentifiable strings on one line
SMCError_TokenOverflow, //the token buffer overflowed
SMCError_InvalidProperty1, //a property was declared outside of any section
};
/**
* Creates a new SMC file format parser. This is used to set parse hooks.
*
* @return A new Handle to an SMC Parse structure.
*/
native Handle:SMC_CreateParse();
/**
* Parses an SMC file.
*
* @param smc A Handle to an SMC Parse structure.
* @param file A string containing the file path.
* @param line An optional by reference cell to store the last line number read.
* @param col An optional by reference cell to store the last column number read.
* @return An SMCParseError result.
* @error Invalid or corrupt Handle.
*/
native SMCError:SMC_ParseFile(Handle:smc, const String:file[], &line=0, &col=0);
/**
* Gets an error string for an SMCError code.
* @note SMCError_Okay returns false.
* @note SMCError_Custom (which is thrown on SMCParse_HaltFail) returns false.
*
* @param error The SMCParseError code.
* @param buffer A string buffer for the error (contents undefined on failure).
* @param buf_max The maximum size of the buffer.
* @return True on success, false otherwise.
*/
native bool:SMC_GetErrorString(SMCError:error, String:buffer[], buf_max);
/**
* Called when parsing is started.
*
* @param smc The SMC Parse Handle.
* @noreturn
*/
functag SMC_ParseStart public(Handle:smc);
/**
* Sets the SMC_ParseStart function of a parse Handle.
*
* @param smc Handle to an SMC Parse.
* @param func SMC_ParseStart function.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native SMC_SetParseStart(Handle:smc, SMC_ParseStart:func);
/**
* Called when parsing is halted.
*
* @param smc The SMC Parse Handle.
* @param halted True if abnormally halted, false otherwise.
* @param failed True if parsing failed, false otherwise.
* @noreturn
*/
functag SMC_ParseEnd public(Handle:smc, bool:halted, bool:failed);
/**
* Sets the SMC_ParseEnd of a parse handle.
*
* @param smc Handle to an SMC Parse.
* @param func SMC_ParseEnd function.
* @noreturn
* @error Invalid or corrupt Handle.
*/
native SMC_SetParseEnd(Handle:smc, SMC_ParseEnd:func);
/**
* Called when the parser is entering a new section or sub-section.
* @note Enclosing quotes are always stripped.
*
* @param smc The SMC Parse Handle.
* @param name String containing section name.
* @param opt_quotes True if the section name was quote-enclosed in the file.
* @return An SMCResult action to take.
*/
functag SMC_NewSection SMCResult:public(Handle:smc, const String:name[], bool:opt_quotes);
/**
* Called when the parser finds a new key/value pair.
* @note Enclosing quotes are always stripped.
*
* @param smc The SMC Parse Handle.
* @param key String containing key name.
* @param value String containing value name.
* @param key_quotes Whether or not the key was enclosed in quotes.
* @param value_quotes Whether or not the value was enclosed in quotes.
* @return An SMCResult action to take.
*/
functag SMC_KeyValue SMCResult:public(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes);
/**
* Called when the parser finds the end of the current section.
*
* @param smc The SMC Parse Handle.
* @return An SMCResult action to take.
*/
functag SMC_EndSection SMCResult:public(Handle:smc);
/**
* Sets the three main reader functions.
*
* @param smc An SMC parse Handle.
* @param ns An SMC_NewSection function pointer.
* @param kv An SMC_KeyValue function pointer.
* @param es An SMC_EndSection function pointer.
* @noreturn
*/
native SMC_SetReaders(Handle:smc, SMC_NewSection:ns, SMC_KeyValue:kv, SMC_EndSection:es);
/**
* Called whenever a raw line is read.
*
* @param smc The SMC Parse Handle.
* @param line A string containing the raw line from the file.
* @param lineno The line number it occurs on.
* @return An SMCResult action to take.
*/
functag SMC_RawLine SMCResult:public(Handle:smc, const String:line[], lineno);
/**
* Sets a raw line reader on an SMC parser Handle.
*
* @param smc Handle to an SMC Parse.
* @param func SMC_RawLine function.
* @noreturn
*/
native SMC_SetRawLine(Handle:smc, SMC_Rawline:func);

View File

@ -13,6 +13,7 @@ namespace SourceMod
Path_None = 0, Path_None = 0,
Path_Game, Path_Game,
Path_SM, Path_SM,
Path_SM_Rel,
}; };
class ISourceMod : public SMInterface class ISourceMod : public SMInterface