sourcemm/util.h
author David Anderson <dvander@alliedmods.net>
Thu Apr 05 17:56:06 2007 +0000 (2007-04-05)
changeset 306 099c92dfd2d4
parent 296 ba7337defd34
child 320 c955cb69efe3
permissions -rw-r--r--
added a sample config file
added a restart option to the config file
     1 /* ======== SourceMM ========
     2  * Copyright (C) 2004-2007 Metamod:Source Development Team
     3  * No warranties of any kind
     4  *
     5  * License: zlib/libpng
     6  *
     7  * Author(s): David "BAILOPAN" Anderson
     8  * ============================
     9  */
    10 
    11 #ifndef _INCLUDE_UTIL_H
    12 #define _INCLUDE_UTIL_H
    13 
    14 #include <stdarg.h>
    15 
    16 /**
    17  * @brief Utility functions
    18  * @file util.h
    19  */
    20 
    21 /**
    22  * @brief Returns a pointer to the extension in a file name.
    23  */
    24 const char *UTIL_GetExtension(const char *file);
    25 
    26 /**
    27  * @brief Removes C-style comments from string.
    28  */
    29 void UTIL_TrimComments(char *buffer);
    30 
    31 /**
    32  * @brief Removes whitespace characters from left side of string.
    33  */
    34 void UTIL_TrimLeft(char *buffer);
    35 
    36 /**
    37  * @brief Removes whitespace characters from right side of string.
    38  */
    39 void UTIL_TrimRight(char *buffer);
    40 
    41 /**
    42  * @brief Breaks a string at the first space until it reaches a non-space.
    43  */
    44 void UTIL_KeySplit(const char *str, char *buf1, size_t len1, char *buf2, size_t len2);
    45 
    46 /**
    47  * @brief Compares two file paths.
    48  */
    49 bool UTIL_PathCmp(const char *path1, const char *path2);
    50 
    51 /**
    52  * @brief Same as snprintf except that it ensures the string buffer is null terminated.
    53  */
    54 size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
    55 
    56 /**
    57  * @brief Same as vsnprintf except that it ensures the string buffer is null terminated.
    58  */
    59 inline size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list params)
    60 {
    61 	size_t len = vsnprintf(buffer, maxlength, fmt, params);
    62 
    63 	if (len >= maxlength)
    64 	{
    65 		len = maxlength - 1;
    66 		buffer[len] = '\0';
    67 	}
    68 
    69 	return len;
    70 }
    71 
    72 #endif //_INCLUDE_UTIL_H