home *** CD-ROM | disk | FTP | other *** search
- /*
- * File: wx_utils.h
- * Purpose: Miscellaneous utilities
- *
- * wxWindows 1.40
- * Copyright (c) 1993 Artificial Intelligence Applications Institute,
- * The University of Edinburgh
- *
- * Author: Julian Smart
- * Date: 18-4-93
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose is hereby granted without fee, provided
- * that the above copyright notice, author statement and this permission
- * notice appear in all copies of this software and related documentation.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
- * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
- * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
- * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
- * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
- * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
- * THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
- #ifndef wx_utilsh
- #define wx_utilsh
- #include "wx_obj.h"
- #include "wx_list.h"
-
- #ifdef wx_x
- #include <dirent.h>
- #include <unistd.h>
- #endif
-
- // sprintf is often needed, but we don't always want to include the whole
- // of stdio.h!
- #ifdef wx_msw
- extern "C" int __cdecl sprintf(char *, const char *, ...);
- #endif
- #ifdef wx_x
- extern "C" char * sprintf(char *, const char *, ...);
- #endif
-
- // Make a copy of this string using 'new'
- char *copystring(char *s);
-
- // Generate a unique ID
- long NewId(void);
-
- // Ensure subsequent IDs don't clash with this one
- void RegisterId(long id);
-
- // Useful buffer
- extern char wxBuffer[];
-
- // Various conversions
- void StringToFloat(char *s, float *number);
- char *FloatToString(float number);
- void StringToDouble(char *s, double *number);
- char *DoubleToString(double number);
- void StringToInt(char *s, int *number);
- void StringToLong(char *s, long *number);
- char *IntToString(int number);
- char *LongToString(long number);
-
- // Matches string one within string two regardless of case
- Bool StringMatch(char *one, char *two);
-
- // Some file utilities
-
- // Path searching
- class wxPathList: public wxList
- {
- public:
-
- void AddEnvList(char *envVariable); // Adds all paths in environment variable
- void Add(char *path);
- char *FindValidPath(char *filename); // Find the first full path
- // for which the file exists
- void EnsureFileAccessible(char *path); // Given full path and filename,
- // add path to list
- Bool Member(char *path);
- };
-
- Bool FileExists(char *filename);
- Bool IsAbsolutePath(char *filename);
-
- // Get filename
- char *FileNameFromPath(char *path);
-
- // Get directory
- char *PathOnly(char *path);
-
- void Dos2UnixFilename(char *s);
- void Unix2DosFilename(char *s);
-
- // Does the pattern contain wildcards?
- Bool wxIsWild(char *pattern);
-
- // Does the pattern match the text (usually a filename)?
- // If dot_special is TRUE, doesn't match * against . (eliminating
- // `hidden' dot files)
- Bool wxMatchWild(char *pattern, char *text, Bool dot_special = TRUE);
-
- // Execute another program. Returns FALSE if there was an error.
- Bool wxExecute(char *command);
-
- // Concatenate two files to form third
- Bool wxConcatFiles(char *file1, char *file2, char *file3);
-
- // Copy file1 to file2
- Bool wxCopyFile(char *file1, char *file2);
-
- // Remove file
- Bool wxRemoveFile(char *file);
-
- // Rename file
- Bool wxRenameFile(char *file1, char *file2);
-
- // Sleep for nSecs seconds under UNIX, do nothing under Windows
- void wxSleep(int nSecs);
-
- // Debug Log
- #ifdef DEBUG
- #include <fstream.h>
- class wxLogClass
- {
- ofstream *the_stream;
- char *log_file;
- public:
- wxLogClass(char *file);
- ~wxLogClass();
- void Open(void);
- void Close(void);
-
- wxLogClass& operator << (char *s);
- wxLogClass& operator << (int i);
- wxLogClass& operator << (double i);
- };
-
- extern wxLogClass wxLog;
- #endif
-
- #ifndef max
- // inline int max(int a, int b) { return a > b ? a : b; }
- #define max(a,b) (((a) > (b)) ? (a) : (b))
- #endif
- #ifndef min
- // inline int max(int a, int b) { return a < b ? a : b; }
- #define min(a,b) (((a) < (b)) ? (a) : (b))
- #endif
-
- #endif // wx_utilsh
-