1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sourcemm/metamod_util.h Thu Oct 04 20:15:25 2007 +0000
1.3 @@ -0,0 +1,98 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * ======================================================
1.7 + * Metamod:Source
1.8 + * Copyright (C) 2004-2007 AlliedModders LLC and authors.
1.9 + * All rights reserved.
1.10 + * ======================================================
1.11 + *
1.12 + * This software is provided 'as-is', without any express or implied warranty.
1.13 + * In no event will the authors be held liable for any damages arising from
1.14 + * the use of this software.
1.15 + *
1.16 + * Permission is granted to anyone to use this software for any purpose,
1.17 + * including commercial applications, and to alter it and redistribute it
1.18 + * freely, subject to the following restrictions:
1.19 + *
1.20 + * 1. The origin of this software must not be misrepresented; you must not
1.21 + * claim that you wrote the original software. If you use this software in a
1.22 + * product, an acknowledgment in the product documentation would be
1.23 + * appreciated but is not required.
1.24 + * 2. Altered source versions must be plainly marked as such, and must not be
1.25 + * misrepresented as being the original software.
1.26 + * 3. This notice may not be removed or altered from any source distribution.
1.27 + *
1.28 + * Version: $Id$
1.29 + */
1.30 +
1.31 +#ifndef _INCLUDE_UTIL_H
1.32 +#define _INCLUDE_UTIL_H
1.33 +
1.34 +#include <stdarg.h>
1.35 +
1.36 +/**
1.37 + * @brief Utility functions
1.38 + * @file util.h
1.39 + */
1.40 +
1.41 +/**
1.42 + * @brief Returns true is string is not blank, false otherwise.
1.43 + */
1.44 +#define IS_STR_FILLED(var) (var != NULL && var[0] != '\0')
1.45 +
1.46 +/**
1.47 + * @brief Returns a pointer to the extension in a file name.
1.48 + */
1.49 +const char *UTIL_GetExtension(const char *file);
1.50 +
1.51 +/**
1.52 + * @brief Removes C-style comments from string.
1.53 + */
1.54 +void UTIL_TrimComments(char *buffer);
1.55 +
1.56 +/**
1.57 + * @brief Removes whitespace characters from left side of string.
1.58 + */
1.59 +void UTIL_TrimLeft(char *buffer);
1.60 +
1.61 +/**
1.62 + * @brief Removes whitespace characters from right side of string.
1.63 + */
1.64 +void UTIL_TrimRight(char *buffer);
1.65 +
1.66 +/**
1.67 + * @brief Breaks a string at the first space until it reaches a non-space.
1.68 + */
1.69 +void UTIL_KeySplit(const char *str, char *buf1, size_t len1, char *buf2, size_t len2);
1.70 +
1.71 +/**
1.72 + * @brief Compares two file paths.
1.73 + */
1.74 +bool UTIL_PathCmp(const char *path1, const char *path2);
1.75 +
1.76 +/**
1.77 + * @brief Same as snprintf except that it ensures the string buffer is null terminated.
1.78 + */
1.79 +size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
1.80 +
1.81 +/**
1.82 + * @brief Same as vsnprintf except that it ensures the string buffer is null terminated.
1.83 + */
1.84 +size_t UTIL_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list params);
1.85 +
1.86 +/**
1.87 + * @brief Forms a relative path given two absolute paths.
1.88 + *
1.89 + * @param buffer Buffer to store relative path in.
1.90 + * @param maxlength Maximum length of the output buffer.
1.91 + * @param relTo Destination folder to use as a working directory.
1.92 + * Final folder name should not be pathchar-terminated.
1.93 + * @param relFrom Source file or folder to use as a target.
1.94 + * @return True on success, false on failure.
1.95 + */
1.96 +bool UTIL_Relatize(char buffer[],
1.97 + size_t maxlength,
1.98 + const char *relTo,
1.99 + const char *relFrom);
1.100 +
1.101 +#endif //_INCLUDE_UTIL_H