DEADSOFTWARE

ppc: fix saves and more map loading improvements
[flatwaifu.git] / src / my.c
1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
23 #include <SDL.h>
24 #include "glob.h"
25 #include "error.h"
26 #include <stdio.h>
27 #include <stdint.h>
28 #include <assert.h>
30 void mysplitpath(const char* path, char* drv, char* dir, char* name, char* ext)
31 {
32 const char* end; /* end of processed string */
33 const char* p; /* search pointer */
34 const char* s; /* copy pointer */
36 /* extract drive name */
37 if (path[0] && path[1]==':') {
38 if (drv) {
39 *drv++ = *path++;
40 *drv++ = *path++;
41 *drv = '\0';
42 }
43 } else if (drv)
44 *drv = '\0';
46 /* search for end of string or stream separator */
47 for(end=path; *end && *end!=':'; )
48 end++;
50 /* search for begin of file extension */
51 for(p=end; p>path && *--p!='\\' && *p!='/'; )
52 if (*p == '.') {
53 end = p;
54 break;
55 }
57 if (ext)
58 for(s=end; (*ext=*s++); )
59 ext++;
61 /* search for end of directory name */
62 for(p=end; p>path; )
63 if (*--p=='\\' || *p=='/') {
64 p++;
65 break;
66 }
68 if (name) {
69 for(s=p; s<end; )
70 *name++ = *s++;
72 *name = '\0';
73 }
75 if (dir) {
76 for(s=path; s<p; )
77 *dir++ = *s++;
79 *dir = '\0';
80 }
81 }
83 size_t myfreadc (void *ptr, size_t size, size_t n, FILE *f) {
84 return fread(ptr, size, n, f);
85 }
87 void myfread (void *ptr, size_t size, size_t n, FILE *f) {
88 if (myfreadc(ptr, size, n, f) != n) {
89 ERR_fatal("File reading error\n");
90 }
91 }
93 void myfread8 (uint8_t *x, FILE *f) {
94 myfread(x, 1, 1, f);
95 }
97 void myfread16 (uint16_t *x, FILE *f) {
98 myfread(x, 2, 1, f);
99 *x = short2host(*x);
102 void myfread32 (uint32_t *x, FILE *f) {
103 myfread(x, 4, 1, f);
104 *x = int2host(*x);
107 void myfwrite (void *ptr, size_t size, size_t n, FILE *f) {
108 assert(fwrite(ptr, size, n, f) == n);
111 void myfwrite8 (uint8_t x, FILE *f) {
112 myfwrite(&x, 1, 1, f);
115 void myfwrite16 (uint16_t x, FILE *f) {
116 x = short2host(x);
117 myfwrite(&x, 2, 1, f);
120 void myfwrite32 (uint32_t x, FILE *f) {
121 x = int2host(x);
122 myfwrite(&x, 4, 1, f);
125 void myrandomize(void)
127 srand(SDL_GetTicks());
130 int fexists(char * filename)
132 FILE *f;
133 if ((f = fopen(filename, "r")))
135 fclose(f);
136 return 1;
138 return 0;