#ifndef STIB_UTIL_H #define STIB_UTIL_H /* ========================================================================== ** * util.h * * Copyright: * Copyright (C) 2007 by Christopher R. Hertel * * Email: crh@ubiqx.mn.org * * $Id: util.h 53 2011-04-25 20:39:01Z crh $ * * -------------------------------------------------------------------------- ** * * Description: * Utility functions used with the STiB tool. * * -------------------------------------------------------------------------- ** * * License: * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * -------------------------------------------------------------------------- ** * * Notes: * * ========================================================================== ** */ #include /* Standard library. */ #include /* Standard integeter types. */ #include /* Standard boolean type. */ #include /* Standard Input/Output. */ #include /* Variable argument lists. */ #include /* For strerror(3). */ #include /* For the external. */ /* -------------------------------------------------------------------------- ** * Macros: * * Err() - Shorthand for (void)fprintf( stderr, ... ) * Say() - Shorthand for (void)printf( ... ) * Yeah, these are kinda weenie but they're much quicker than * typing out the entire function call. * ErrStr - Shorthand for the error message associated with . */ #define Err( ... ) (void)fprintf( stderr, __VA_ARGS__ ) #define Say( ... ) (void)printf( __VA_ARGS__ ) #define ErrStr (strerror( errno )) /* -------------------------------------------------------------------------- ** * Exported functions: */ void Fail( char *fmt, ... ); /* ------------------------------------------------------------------------ ** * Format and print a failure message on , then exit the process. * * Input: fmt - Format string, as used in printf(), etc. * ... - Variable parameter list. * * Output: none * * Notes: Exits the process returning EXIT_FAILURE. * * ------------------------------------------------------------------------ ** */ void Usage( const char *msg[], const char *prognam ); /* ------------------------------------------------------------------------ ** * Print a usage message to . * * Input: msg[] - An array of strings; the usage message. * prognam - The program name. * * Output: * * Notes: The error message is printed to so that it can be * easily piped through a program like "more" or "less". * * ------------------------------------------------------------------------ ** */ int matchStr( const char *s, const char *m[] ); /* ------------------------------------------------------------------------ ** * Find a string that matches in the set of strings . * * Input: s - A string to be matched. * m[] - A set of strings that may match, presented as a * NULL-terminated variable-length array of strings. * * Output: The number (starting from 0) of the string in that * matched , or -1 if there was no match. * * Notes: The string comparison is case-insensitive using . * * ------------------------------------------------------------------------ ** */ bool prefixMatch( const char *src, const char *match, const unsigned int min ); /* ------------------------------------------------------------------------ ** * Perform a case-insensitive string match, limited to strlen( src ) bytes. * * Input: src - A pointer to a string that may be a prefix of . * match - A pointer to the string against which to test. * min - Minimum length of needed in order to declare * a match. * * Output: Boolean if the string in is a prefix of * and is at least bytes in length, otherwise . * * Notes: This function tests to see whether strlen( src ) bytes of * are the same as . So, for example: * prefixMatch( "foo", "fooberry", 1 ) == true * prefixMatch( "food", "fooberry", 1 ) == false * * The parameter is used to determine the minimum number * of characters in which must be matched. So: * prefixMatch( "foo", "fooberry", 3 ) == true * prefixMatch( "foo", "fooberry", 4 ) == false * since the string "foo" is not long enough to match 4 bytes of * "fooberry". * * The function is case insensitive, so: * prefixMatch( "foo", "Fooberry", 3 ) == true * * ------------------------------------------------------------------------ ** */ char *vString( char *Rev ); /* ------------------------------------------------------------------------ ** * Extract just the version number from a cvs or svn Revision string. * * Input: Rev - Full Revision string (including the dollar signs). * * Output: Pointer to static space that contains the extracted version * number string. * * ------------------------------------------------------------------------ ** */ /* ========================================================================== */ #endif /* STIB_UTIL_H */