]> icculus.org git repositories - btb/d2x.git/blob - misc/strutil.c
added fullscreen toggle while playing movies
[btb/d2x.git] / misc / strutil.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13  
14 #ifdef HAVE_CONFIG_H
15 #include <conf.h>
16 #endif
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <ctype.h>
21 #include <string.h>
22
23 #include "u_mem.h"
24 #include "error.h"
25
26 #if 0
27 // string compare without regard to case
28
29 int stricmp( char *s1, char *s2 )
30 {
31         while( *s1 && *s2 )     {
32                 if ( tolower(*s1) != tolower(*s2) )     return 1;
33                 s1++;
34                 s2++;
35         }
36         if ( *s1 || *s2 ) return 1;
37         return 0;
38 }
39
40 int strnicmp( char *s1, char *s2, int n )
41 {
42         while( *s1 && *s2 && n) {
43                 if ( tolower(*s1) != tolower(*s2) )     return 1;
44                 s1++;
45                 s2++;
46                 n--;
47         }
48         if (n) return 1;
49         return 0;
50 }
51 #endif
52
53 #ifndef __MINGW32__
54 #ifndef __DJGPP__
55 void strlwr( char *s1 )
56 {
57         while( *s1 )    {
58                 *s1 = tolower(*s1);
59                 s1++;
60         }
61 }
62
63 void strupr( char *s1 )
64 {
65         while( *s1 )    {
66                 *s1 = toupper(*s1);
67                 s1++;
68         }
69 }
70
71 #endif
72
73 void strrev( char *s1 )
74 {
75         char *h, *t;
76         h = s1;
77         t = s1 + strlen(s1) - 1;
78         while (h < t) {
79                 char c;
80                 c = *h;
81                 *h++ = *t;
82                 *t-- = c;
83         }
84 }
85
86 void _splitpath(char *name, char *drive, char *path, char *base, char *ext)
87 {
88         char *s, *p;
89
90         p = name;
91         s = strchr(p, ':');
92         if ( s != NULL ) {
93                 if (drive) {
94                         *s = '\0';
95                         strcpy(drive, p);
96                         *s = ':';
97                 }
98                 p = s+1;
99                 if (!p)
100                         return;
101         } else if (drive)
102                 *drive = '\0';
103         
104         s = strrchr(p, '\\');
105         if ( s != NULL) {
106                 if (path) {
107                         char c;
108                         
109                         c = *(s+1);
110                         *(s+1) = '\0';
111                         strcpy(path, p);
112                         *(s+1) = c;
113                 }
114                 p = s+1;
115                 if (!p)
116                         return;
117         } else if (path)
118                 *path = '\0';
119
120         s = strchr(p, '.');
121         if ( s != NULL) {
122                 if (base) {
123                         *s = '\0';
124                         strcpy(base, p);
125                         *s = '.';
126                 }
127                 p = s+1;
128                 if (!p)
129                         return;
130         } else if (base)
131                 *base = '\0';
132                 
133         if (ext)
134                 strcpy(ext, p);         
135 }
136 #endif
137
138 #if 0
139 void main()
140 {
141         char drive[10], path[50], name[16], ext[5];
142         
143         drive[0] = path[0] = name[0] = ext[0] = '\0';
144         _splitpath("f:\\tmp\\x.out", drive, path, name, ext);
145         drive[0] = path[0] = name[0] = ext[0] = '\0';
146         _splitpath("tmp\\x.out", drive, path, name, ext);
147         drive[0] = path[0] = name[0] = ext[0] = '\0';
148         _splitpath("f:\\tmp\\a.out", NULL, NULL, name, NULL);
149         drive[0] = path[0] = name[0] = ext[0] = '\0';
150         _splitpath("tmp\\*.dem", drive, path, NULL, NULL);
151         drive[0] = path[0] = name[0] = ext[0] = '\0';
152         _splitpath(".\\tmp\\*.dem", drive, path, NULL, NULL);
153 }
154 #endif