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