2007-10-04 22:15:25 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* ======================================================
|
|
|
|
* Metamod:Source
|
|
|
|
* Copyright (C) 2004-2007 AlliedModders LLC and authors.
|
|
|
|
* All rights reserved.
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
* In no event will the authors be held liable for any damages arising from
|
|
|
|
* the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
* freely, subject to the following restrictions:
|
2007-02-10 01:31:34 +01:00
|
|
|
*
|
2007-10-04 22:15:25 +02:00
|
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
* claim that you wrote the original software. If you use this software in a
|
|
|
|
* product, an acknowledgment in the product documentation would be
|
|
|
|
* appreciated but is not required.
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software.
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
2007-02-10 01:31:34 +01:00
|
|
|
*
|
2007-10-04 22:15:25 +02:00
|
|
|
* Version: $Id$
|
2007-02-10 01:31:34 +01:00
|
|
|
*/
|
2005-04-16 21:59:26 +02:00
|
|
|
|
|
|
|
#ifndef _INCLUDE_UTIL_H
|
|
|
|
#define _INCLUDE_UTIL_H
|
|
|
|
|
2007-03-21 18:45:28 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2005-04-16 21:59:26 +02:00
|
|
|
/**
|
2007-03-21 18:45:28 +01:00
|
|
|
* @brief Utility functions
|
2005-04-16 21:59:26 +02:00
|
|
|
* @file util.h
|
|
|
|
*/
|
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
/**
|
|
|
|
* @brief Returns true is string is not blank, false otherwise.
|
|
|
|
*/
|
|
|
|
#define IS_STR_FILLED(var) (var != NULL && var[0] != '\0')
|
|
|
|
|
2007-03-21 18:45:28 +01:00
|
|
|
/**
|
|
|
|
* @brief Returns a pointer to the extension in a file name.
|
|
|
|
*/
|
2005-04-16 21:59:26 +02:00
|
|
|
const char *UTIL_GetExtension(const char *file);
|
2007-03-21 18:45:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Removes C-style comments from string.
|
|
|
|
*/
|
2005-10-06 02:59:01 +02:00
|
|
|
void UTIL_TrimComments(char *buffer);
|
2007-03-21 18:45:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Removes whitespace characters from left side of string.
|
|
|
|
*/
|
2005-07-03 18:11:28 +02:00
|
|
|
void UTIL_TrimLeft(char *buffer);
|
2007-03-21 18:45:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Removes whitespace characters from right side of string.
|
|
|
|
*/
|
2005-07-03 18:11:28 +02:00
|
|
|
void UTIL_TrimRight(char *buffer);
|
2007-03-21 18:45:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Breaks a string at the first space until it reaches a non-space.
|
|
|
|
*/
|
2005-10-06 02:59:01 +02:00
|
|
|
void UTIL_KeySplit(const char *str, char *buf1, size_t len1, char *buf2, size_t len2);
|
2007-03-21 18:45:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Compares two file paths.
|
|
|
|
*/
|
2005-10-06 02:59:01 +02:00
|
|
|
bool UTIL_PathCmp(const char *path1, const char *path2);
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2007-03-21 18:45:28 +01:00
|
|
|
/**
|
|
|
|
* @brief Same as snprintf except that it ensures the string buffer is null terminated.
|
|
|
|
*/
|
|
|
|
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Same as vsnprintf except that it ensures the string buffer is null terminated.
|
|
|
|
*/
|
2007-05-02 16:08:57 +02:00
|
|
|
size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list params);
|
2007-03-21 18:45:28 +01:00
|
|
|
|
2007-05-02 16:08:57 +02:00
|
|
|
/**
|
|
|
|
* @brief Forms a relative path given two absolute paths.
|
|
|
|
*
|
|
|
|
* @param buffer Buffer to store relative path in.
|
|
|
|
* @param maxlength Maximum length of the output buffer.
|
|
|
|
* @param relTo Destination folder to use as a working directory.
|
|
|
|
* Final folder name should not be pathchar-terminated.
|
|
|
|
* @param relFrom Source file or folder to use as a target.
|
|
|
|
* @return True on success, false on failure.
|
|
|
|
*/
|
|
|
|
bool UTIL_Relatize(char buffer[],
|
|
|
|
size_t maxlength,
|
|
|
|
const char *relTo,
|
|
|
|
const char *relFrom);
|
2007-03-21 18:45:28 +01:00
|
|
|
|
2007-12-24 18:00:22 +01:00
|
|
|
void LogMessage(const char *msg, ...);
|
|
|
|
|
2005-04-16 21:59:26 +02:00
|
|
|
#endif //_INCLUDE_UTIL_H
|