home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / wxwin140 / include / wx_utils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  4.3 KB  |  158 lines

  1. /*
  2.  * File:     wx_utils.h
  3.  * Purpose:  Miscellaneous utilities
  4.  *
  5.  *                       wxWindows 1.40
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                       Date: 18-4-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #ifndef wx_utilsh
  30. #define wx_utilsh
  31. #include "wx_obj.h"
  32. #include "wx_list.h"
  33.  
  34. #ifdef wx_x
  35. #include <dirent.h>
  36. #include <unistd.h>
  37. #endif
  38.  
  39. // sprintf is often needed, but we don't always want to include the whole
  40. // of stdio.h!
  41. #ifdef wx_msw
  42. extern "C" int __cdecl sprintf(char *, const char *, ...);
  43. #endif
  44. #ifdef wx_x
  45. extern "C" char * sprintf(char *, const char *, ...);
  46. #endif
  47.  
  48. // Make a copy of this string using 'new'
  49. char *copystring(char *s);
  50.  
  51. // Generate a unique ID
  52. long NewId(void);
  53.  
  54. // Ensure subsequent IDs don't clash with this one
  55. void RegisterId(long id);
  56.  
  57. // Useful buffer
  58. extern char wxBuffer[];
  59.  
  60. // Various conversions
  61. void StringToFloat(char *s, float *number);
  62. char *FloatToString(float number);
  63. void StringToDouble(char *s, double *number);
  64. char *DoubleToString(double number);
  65. void StringToInt(char *s, int *number);
  66. void StringToLong(char *s, long *number);
  67. char *IntToString(int number);
  68. char *LongToString(long number);
  69.  
  70. // Matches string one within string two regardless of case
  71. Bool StringMatch(char *one, char *two);
  72.  
  73. // Some file utilities
  74.  
  75. // Path searching
  76. class wxPathList: public wxList
  77. {
  78.   public:
  79.  
  80.   void AddEnvList(char *envVariable);    // Adds all paths in environment variable
  81.   void Add(char *path);
  82.   char *FindValidPath(char *filename);   // Find the first full path
  83.                                          // for which the file exists
  84.   void EnsureFileAccessible(char *path); // Given full path and filename,
  85.                                          // add path to list
  86.   Bool Member(char *path);
  87. };
  88.  
  89. Bool FileExists(char *filename);
  90. Bool IsAbsolutePath(char *filename);
  91.  
  92. // Get filename
  93. char *FileNameFromPath(char *path);
  94.  
  95. // Get directory
  96. char *PathOnly(char *path);
  97.  
  98. void Dos2UnixFilename(char *s);
  99. void Unix2DosFilename(char *s);
  100.  
  101. // Does the pattern contain wildcards?
  102. Bool wxIsWild(char *pattern);
  103.  
  104. // Does the pattern match the text (usually a filename)?
  105. // If dot_special is TRUE, doesn't match * against . (eliminating
  106. // `hidden' dot files)
  107. Bool wxMatchWild(char *pattern, char *text, Bool dot_special = TRUE);
  108.  
  109. // Execute another program. Returns FALSE if there was an error.
  110. Bool wxExecute(char *command);
  111.  
  112. // Concatenate two files to form third
  113. Bool wxConcatFiles(char *file1, char *file2, char *file3);
  114.  
  115. // Copy file1 to file2
  116. Bool wxCopyFile(char *file1, char *file2);
  117.  
  118. // Remove file
  119. Bool wxRemoveFile(char *file);
  120.  
  121. // Rename file
  122. Bool wxRenameFile(char *file1, char *file2);
  123.  
  124. // Sleep for nSecs seconds under UNIX, do nothing under Windows
  125. void wxSleep(int nSecs);
  126.  
  127. // Debug Log
  128. #ifdef DEBUG
  129. #include <fstream.h>
  130. class wxLogClass
  131. {
  132.   ofstream *the_stream;
  133.   char *log_file;
  134.   public:
  135.     wxLogClass(char *file);
  136.     ~wxLogClass();
  137.     void Open(void);
  138.     void Close(void);
  139.  
  140.     wxLogClass& operator << (char *s);
  141.     wxLogClass& operator << (int i);
  142.     wxLogClass& operator << (double i);
  143. };
  144.  
  145. extern wxLogClass wxLog;
  146. #endif
  147.  
  148. #ifndef max
  149. // inline int max(int a, int b) { return a > b ? a : b; }
  150. #define max(a,b)            (((a) > (b)) ? (a) : (b))
  151. #endif
  152. #ifndef min
  153. // inline int max(int a, int b) { return a < b ? a : b; }
  154. #define min(a,b)            (((a) < (b)) ? (a) : (b))
  155. #endif
  156.  
  157. #endif // wx_utilsh
  158.