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:
parent
aeb512c444
commit
e506745890
@ -608,10 +608,13 @@ void AdminCache::DumpAdminCache(int cache_flags, bool rebuild)
|
||||
{
|
||||
List<IAdminListener *>::iterator iter;
|
||||
IAdminListener *pListener;
|
||||
cell_t result;
|
||||
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
|
||||
{
|
||||
pListener = (*iter);
|
||||
pListener->OnRebuildAdminCache(cache_flags);
|
||||
}
|
||||
m_pCacheFwd->PushCell(cache_flags);
|
||||
m_pCacheFwd->Execute(&result);
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +228,7 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\public\smn_admin.cpp"
|
||||
RelativePath="..\smn_admin.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
|
@ -428,6 +428,18 @@ static cell_t sm_WriteFileLine(IPluginContext *pContext, const cell_t *params)
|
||||
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;
|
||||
|
||||
REGISTER_NATIVES(filesystem)
|
||||
@ -446,5 +458,6 @@ REGISTER_NATIVES(filesystem)
|
||||
{"FileSize", sm_FileSize},
|
||||
{"RemoveDir", sm_RemoveDir},
|
||||
{"WriteFileLine", sm_WriteFileLine},
|
||||
{"BuildPath", sm_BuildPath},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
@ -48,6 +48,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t err_max, bool late)
|
||||
{
|
||||
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_SMRelDir, sizeof(m_SMRelDir), "addons/sourcemod");
|
||||
|
||||
/* Attempt to load the JIT! */
|
||||
char file[PLATFORM_MAX_PATH];
|
||||
@ -229,6 +230,8 @@ size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, c
|
||||
base = GetModPath();
|
||||
} else if (type == Path_SM) {
|
||||
base = GetSourceModPath();
|
||||
} else if (type == Path_SM_Rel) {
|
||||
base = m_SMRelDir;
|
||||
}
|
||||
|
||||
if (base)
|
||||
|
@ -56,6 +56,7 @@ private:
|
||||
void DoGlobalPluginLoads();
|
||||
private:
|
||||
char m_SMBaseDir[PLATFORM_MAX_PATH+1];
|
||||
char m_SMRelDir[PLATFORM_MAX_PATH+1];
|
||||
bool m_IsMapLoading;
|
||||
bool m_ExecPluginReload;
|
||||
};
|
||||
|
@ -1487,7 +1487,7 @@ void CPluginManager::OnRootConsoleCommand(const char *command, unsigned int argc
|
||||
g_RootMenu.ConsolePrint(" Description: %s", info->description);
|
||||
}
|
||||
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 {
|
||||
g_RootMenu.ConsolePrint(" Load error: %s", pl->m_errormsg);
|
||||
g_RootMenu.ConsolePrint(" File info: (title \"%s\") (version \"%s\")",
|
||||
|
@ -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).
|
||||
* @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.
|
||||
|
@ -22,13 +22,30 @@ enum FileType
|
||||
#define SEEK_CUR 1
|
||||
#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.
|
||||
* @note Directories are closed with CloseHandle().
|
||||
* @note Directories Handles can be cloned.
|
||||
*
|
||||
* @param path Path to open.
|
||||
* @return A Handle to the directory, INVALID_HANDLE on open error.
|
||||
* @return A Handle to the directory, INVALID_HANDLE on open error.
|
||||
*/
|
||||
native Handle:OpenDirectory(const String:path[]);
|
||||
|
||||
@ -41,7 +58,7 @@ native Handle:OpenDirectory(const String:path[]);
|
||||
* @param buffer String buffer to hold directory name.
|
||||
* @param maxlength Maximum size of string buffer.
|
||||
* @param type Optional variable to store the file type.
|
||||
* @return True on success, false if there are no more files to read.
|
||||
* @return True on success, false if there are no more files to read.
|
||||
* @error Invalid or corrupt Handle.
|
||||
*/
|
||||
native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown);
|
||||
@ -51,8 +68,8 @@ native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=
|
||||
* @note Files are closed with CloseHandle().
|
||||
* @note File Handles can be cloned.
|
||||
*
|
||||
* @param file File to open.
|
||||
* @param mode Open mode.
|
||||
* @param file File to open.
|
||||
* @param mode Open mode.
|
||||
* @return A Handle to the file, INVALID_HANDLE on open error.
|
||||
*/
|
||||
native Handle:OpenFile(const String:file[], const String:mode[]);
|
||||
@ -60,7 +77,7 @@ native Handle:OpenFile(const String:file[], const String:mode[]);
|
||||
/**
|
||||
* @brief Deletes a file.
|
||||
*
|
||||
* @param path Path of the file to delete.
|
||||
* @param path Path of the file to delete.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool:DeleteFile(const String:path[]);
|
||||
@ -71,14 +88,14 @@ native bool:DeleteFile(const String:path[]);
|
||||
* @param hndl Handle to the file.
|
||||
* @param buffer String buffer to hold the line.
|
||||
* @param maxlength Maximum size of string buffer.
|
||||
* @return True on success, false otherwise.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
|
||||
|
||||
/**
|
||||
* @brief Tests if the end of file has been reached.
|
||||
*
|
||||
* @param file Handle to the file.
|
||||
* @param file Handle to the file.
|
||||
* @return True if end of file has been reached, false otherwise.
|
||||
*/
|
||||
native bool:IsEndOfFile(Handle:file);
|
||||
@ -86,9 +103,9 @@ native bool:IsEndOfFile(Handle:file);
|
||||
/**
|
||||
* @brief Sets the file position indicator.
|
||||
*
|
||||
* @param file Handle to the file.
|
||||
* @param position Position relative to what is specified in whence.
|
||||
* @param whence Look at the SEEK_* definitions.
|
||||
* @param file Handle to the file.
|
||||
* @param position Position relative to what is specified in whence.
|
||||
* @param whence Look at the SEEK_* definitions.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool:FileSeek(Handle:file, position, whence);
|
||||
@ -96,7 +113,7 @@ native bool:FileSeek(Handle:file, position, whence);
|
||||
/**
|
||||
* @brief Get current position in the file.
|
||||
*
|
||||
* @param file Handle to the file.
|
||||
* @param file Handle to the file.
|
||||
* @return Value for the file position indicator.
|
||||
*/
|
||||
native FilePosition(Handle:file);
|
||||
@ -104,7 +121,7 @@ native FilePosition(Handle:file);
|
||||
/**
|
||||
* @brief Checks if a file exists.
|
||||
*
|
||||
* @param path Path to the file.
|
||||
* @param path Path to the file.
|
||||
* @return True if the file exists, false otherwise.
|
||||
*/
|
||||
native bool:FileExists(const String:path[]);
|
||||
@ -114,14 +131,14 @@ native bool:FileExists(const String:path[]);
|
||||
*
|
||||
* @param newpath New path to the file.
|
||||
* @param oldpath Path to the existing file.
|
||||
* @return True on success, false otherwise.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool:RenameFile(const String:newpath[], const String:oldpath[]);
|
||||
|
||||
/**
|
||||
* @brief Checks if a directory exists.
|
||||
*
|
||||
* @param path Path to the directory.
|
||||
* @param path Path to the directory.
|
||||
* @return True if the directory exists, false otherwise.
|
||||
*/
|
||||
native bool:DirExists(const String:path[]);
|
||||
@ -129,7 +146,7 @@ native bool:DirExists(const String:path[]);
|
||||
/**
|
||||
* @brief Get the file size in bytes.
|
||||
*
|
||||
* @param path Path to the file.
|
||||
* @param path Path to the file.
|
||||
* @return File size in bytes, -1 if file not found.
|
||||
*/
|
||||
native FileSize(const String:path[]);
|
||||
@ -138,7 +155,7 @@ native FileSize(const String:path[]);
|
||||
* @brief Removes a directory.
|
||||
* @note On most Operating Systems you cannot remove a directory which has files inside it.
|
||||
*
|
||||
* @param path Path to the directory.
|
||||
* @param path Path to the directory.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool:RemoveDir(const String:path[]);
|
||||
@ -147,9 +164,9 @@ native bool:RemoveDir(const String:path[]);
|
||||
* @brief Writes a line of text in a file.
|
||||
* @note This native will append the newline character.
|
||||
*
|
||||
* @param hndl Handle to the file.
|
||||
* @param format Formatting rules.
|
||||
* @param ... Variable number of format parameters.
|
||||
* @param hndl Handle to the file.
|
||||
* @param format Formatting rules.
|
||||
* @param ... Variable number of format parameters.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool:WriteFileLine(Handle:hndl, const String:format[], {Handle,Float,String,_}:...);
|
||||
|
@ -21,6 +21,7 @@ struct Plugin
|
||||
#include <handles>
|
||||
#include <string>
|
||||
#include <admin>
|
||||
#include <files>
|
||||
|
||||
/**
|
||||
* Declare this as a struct in your plugin to expose its information.
|
||||
@ -41,7 +42,7 @@ public Plugin:myinfo;
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
forward OnPluginInit(Handle:myself);
|
||||
forward OnPluginStart(Handle:myself);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
forward OnPluginUnload();
|
||||
forward OnPluginEnd();
|
||||
|
||||
/**
|
||||
* Called when the plugin's pause status is changing.
|
||||
|
165
plugins/include/textparse.inc
Normal file
165
plugins/include/textparse.inc
Normal 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);
|
@ -13,6 +13,7 @@ namespace SourceMod
|
||||
Path_None = 0,
|
||||
Path_Game,
|
||||
Path_SM,
|
||||
Path_SM_Rel,
|
||||
};
|
||||
|
||||
class ISourceMod : public SMInterface
|
||||
|
Loading…
Reference in New Issue
Block a user