sourcemm/util.h
author David Anderson <dvander@alliedmods.net>
Tue Sep 18 20:03:47 2007 +0000 (2007-09-18)
branchsourcemm-1.6.0
changeset 347 e82968c21606
child 348 716af2e7be78
permissions -rw-r--r--
branched 1.4.2 to 1.6.0
     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 size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list params);
    60 
    61 /**
    62  * @brief Forms a relative path given two absolute paths.
    63  *
    64  * @param buffer		Buffer to store relative path in.
    65  * @param maxlength		Maximum length of the output buffer.
    66  * @param relTo			Destination folder to use as a working directory.
    67  *						Final folder name should not be pathchar-terminated.
    68  * @param relFrom		Source file or folder to use as a target.
    69  * @return				True on success, false on failure.
    70  */
    71 bool UTIL_Relatize(char buffer[],
    72 				   size_t maxlength,
    73 				   const char *relTo,
    74 				   const char *relFrom);
    75 
    76 #endif //_INCLUDE_UTIL_H