sourcemm/metamod_util.h
author Pavol Marko <pavolmarko@gmail.com>
Sun Oct 07 22:45:22 2007 +0000 (2007-10-07)
changeset 384 264cab8ff2cc
parent 371 751179604513
child 485 d8f0a0416936
permissions -rw-r--r--
correct version now... i guess i'm just tired :)
     1 /**
     2  * vim: set ts=4 :
     3  * ======================================================
     4  * Metamod:Source
     5  * Copyright (C) 2004-2007 AlliedModders LLC and authors.
     6  * All rights reserved.
     7  * ======================================================
     8  *
     9  * This software is provided 'as-is', without any express or implied warranty.
    10  * In no event will the authors be held liable for any damages arising from 
    11  * the use of this software.
    12  * 
    13  * Permission is granted to anyone to use this software for any purpose, 
    14  * including commercial applications, and to alter it and redistribute it 
    15  * freely, subject to the following restrictions:
    16  *
    17  * 1. The origin of this software must not be misrepresented; you must not 
    18  * claim that you wrote the original software. If you use this software in a 
    19  * product, an acknowledgment in the product documentation would be 
    20  * appreciated but is not required.
    21  * 2. Altered source versions must be plainly marked as such, and must not be
    22  * misrepresented as being the original software.
    23  * 3. This notice may not be removed or altered from any source distribution.
    24  *
    25  * Version: $Id$
    26  */
    27 
    28 #ifndef _INCLUDE_UTIL_H
    29 #define _INCLUDE_UTIL_H
    30 
    31 #include <stdarg.h>
    32 
    33 /**
    34  * @brief Utility functions
    35  * @file util.h
    36  */
    37 
    38 /**
    39  * @brief Returns true is string is not blank, false otherwise.
    40  */
    41 #define IS_STR_FILLED(var) (var != NULL && var[0] != '\0')
    42 
    43 /**
    44  * @brief Returns a pointer to the extension in a file name.
    45  */
    46 const char *UTIL_GetExtension(const char *file);
    47 
    48 /**
    49  * @brief Removes C-style comments from string.
    50  */
    51 void UTIL_TrimComments(char *buffer);
    52 
    53 /**
    54  * @brief Removes whitespace characters from left side of string.
    55  */
    56 void UTIL_TrimLeft(char *buffer);
    57 
    58 /**
    59  * @brief Removes whitespace characters from right side of string.
    60  */
    61 void UTIL_TrimRight(char *buffer);
    62 
    63 /**
    64  * @brief Breaks a string at the first space until it reaches a non-space.
    65  */
    66 void UTIL_KeySplit(const char *str, char *buf1, size_t len1, char *buf2, size_t len2);
    67 
    68 /**
    69  * @brief Compares two file paths.
    70  */
    71 bool UTIL_PathCmp(const char *path1, const char *path2);
    72 
    73 /**
    74  * @brief Same as snprintf except that it ensures the string buffer is null terminated.
    75  */
    76 size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
    77 
    78 /**
    79  * @brief Same as vsnprintf except that it ensures the string buffer is null terminated.
    80  */
    81 size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list params);
    82 
    83 /**
    84  * @brief Forms a relative path given two absolute paths.
    85  *
    86  * @param buffer		Buffer to store relative path in.
    87  * @param maxlength		Maximum length of the output buffer.
    88  * @param relTo			Destination folder to use as a working directory.
    89  *						Final folder name should not be pathchar-terminated.
    90  * @param relFrom		Source file or folder to use as a target.
    91  * @return				True on success, false on failure.
    92  */
    93 bool UTIL_Relatize(char buffer[],
    94 				   size_t maxlength,
    95 				   const char *relTo,
    96 				   const char *relFrom);
    97 
    98 #endif //_INCLUDE_UTIL_H