Subversion Repositories Kolibri OS

Rev

Rev 300 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 300 Rev 333
Line 27... Line 27...
27
static const char
27
static const char
28
rcsid[] = "$Id: m_misc.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
28
rcsid[] = "$Id: m_misc.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
Line 29... Line 29...
29
 
29
 
30
#include 
30
#include 
-
 
31
#include 
Line 31... Line 32...
31
#include 
32
//#include "//kolibc.h"
Line 32... Line 33...
32
 
33
 
Line 33... Line 34...
33
extern int access(char *file, int mode);
34
//extern int access(char *file, int mode);
Line 117... Line 118...
117
    handle = fopen ( name, "wb");
118
    handle = fopen ( name, "wb");
Line 118... Line 119...
118
 
119
 
119
    if (handle == NULL)
120
    if (handle == NULL)
Line 120... Line 121...
120
	return false;
121
        return false;
121
 
122
 
Line 122... Line 123...
122
    count = fwrite (source, 1, length, handle);
123
  //  count = fwrite (source, 1, length, handle);
123
    fclose (handle);
124
    fclose (handle);
Line 139... Line 140...
139
{
140
{
140
    FILE *handle;
141
    FILE *handle;
141
    int count, length;
142
    int count, length;
142
    byte	*buf;
143
    byte        *buf;
Line -... Line 144...
-
 
144
 
-
 
145
    handle=0;
-
 
146
    buf=0;
143
	
147
        
144
    handle = fopen (name, "rb");
148
    handle = fopen (name, "rb");
145
    if (handle == NULL)
149
    if (handle == NULL)
146
	I_Error ("Couldn't read file %s", name);
150
        I_Error ("Couldn't read file %s", name);
147
    fseek(handle, 0, SEEK_END);
151
    fseek(handle, 0, SEEK_END);
Line 226... Line 230...
226
 
230
 
227
    {"key_right",&key_right, KEY_RIGHTARROW},
231
    {"key_right",&key_right, KEY_RIGHTARROW},
228
    {"key_left",&key_left, KEY_LEFTARROW},
232
    {"key_left",&key_left, KEY_LEFTARROW},
229
    {"key_up",&key_up, KEY_UPARROW},
233
    {"key_up",&key_up, KEY_UPARROW},
-
 
234
    {"key_down",&key_down, KEY_DOWNARROW},
-
 
235
 
-
 
236
//    {"key_right",&key_right, KEY_D},
-
 
237
//    {"key_left",&key_left, KEY_A},
-
 
238
//    {"key_up",&key_up, KEY_W},
-
 
239
//    {"key_down",&key_down, KEY_S},
230
    {"key_down",&key_down, KEY_DOWNARROW},
240
 
231
    {"key_strafeleft",&key_strafeleft, ','},
241
    {"key_strafeleft",&key_strafeleft, ','},
Line 232... Line 242...
232
    {"key_straferight",&key_straferight, '.'},
242
    {"key_straferight",&key_straferight, '.'},
233
 
243
 
Line 308... Line 318...
308
//
318
//
309
// M_LoadDefaults
319
// M_LoadDefaults
310
//
320
//
311
extern byte	scantokey[128];
321
extern byte     scantokey[128];
Line -... Line 322...
-
 
322
 
-
 
323
size_t FileSize(FILE *handle);
312
 
324
 
313
void M_LoadDefaults (void)
325
void M_LoadDefaults (void)
314
{
326
{
315
    int		i;
327
    int         i;
316
    int		len;
328
    int         len;
317
    FILE*	f;
329
    FILE*       f;
318
    char	def[80];
330
    char        def[80];
319
    char	strparm[100];
331
    char        strparm[100];
320
    char*	newstring;
332
    char*       newstring;
321
    int		parm;
333
    int         parm;
-
 
334
    boolean     isstring;
-
 
335
    char        *buf;
Line -... Line 336...
-
 
336
    char        *p;
322
    boolean	isstring;
337
    
323
    
338
    size_t val;
324
    // set everything to base values
339
    // set everything to base values
325
    numdefaults = sizeof(defaults)/sizeof(defaults[0]);
340
    numdefaults = sizeof(defaults)/sizeof(defaults[0]);
Line 333... Line 348...
333
	defaultfile = myargv[i+1];
348
        defaultfile = myargv[i+1];
334
//	__libclog_printf ("	default file: %s\n",defaultfile);
349
//      __libclog_printf ("     default file: %s\n",defaultfile);
335
    }
350
    }
336
    else
351
    else
337
	defaultfile = basedefault;
352
        defaultfile = basedefault;
338
/**********
353
 
339
    // read the file in, overriding any set defaults
354
    // read the file in, overriding any set defaults
340
    f = fopen (defaultfile, "r");
355
    f = fopen (defaultfile, "rb");
341
    if (f)
356
    if (f)
342
    {
357
    {
-
 
358
      len=FileSize(f)+1;  
-
 
359
      buf = malloc(len);
-
 
360
      memset(buf,0,len);
-
 
361
      val = fread(buf,1,len,f);
343
	while (!feof(f))
362
      fclose (f);
-
 
363
      
-
 
364
      p = buf;
-
 
365
      
-
 
366
      while(*p)
344
	{
367
      {
345
	    isstring = false;
368
        isstring = false;
-
 
369
 
346
	    if (fscanf (f, "%79s %[^\n]\n", def, strparm) == 2)
370
        if (sscanf (p, "%79s %[^\n]\n", def, strparm) == 2)
347
	    {
371
        {
348
		if (strparm[0] == '"')
372
          if (strparm[0] == '"')
349
		{
373
          {
350
		    // get a string default
374
                    // get a string default
351
		    isstring = true;
375
            isstring = true;
352
		    len = strlen(strparm);
376
            len = strlen(strparm);
353
		    newstring = (char *) malloc(len);
377
            newstring = (char *) malloc(len);
354
		    strparm[len-1] = 0;
378
            strparm[len-1] = 0;
355
		    strcpy(newstring, strparm+1);
379
            strcpy(newstring, strparm+1);
356
		}
380
          }
-
 
381
          else
357
		else if (strparm[0] == '0' && strparm[1] == 'x')
382
           if (strparm[0] == '0' && strparm[1] == 'x')
358
		    sscanf(strparm+2, "%x", &parm);
383
             sscanf(strparm+2, "%x", &parm);
359
		else
384
           else
360
		    sscanf(strparm, "%i", &parm);
385
             sscanf(strparm, "%i", &parm);
361
		for (i=0 ; i
386
           for (i=0 ; i
362
		    if (!strcmp(def, defaults[i].name))
387
             if (!strcmp(def, defaults[i].name))
363
		    {
388
             {
364
			if (!isstring)
389
               if (!isstring)
365
			    *defaults[i].location = parm;
390
                 *defaults[i].location = parm;
366
			else
391
               else
367
			    *defaults[i].location =
392
                 *defaults[i].location = (int) newstring;
368
				(int) newstring;
-
 
369
			break;
393
               break;
370
		    }
394
             }
-
 
395
        };
-
 
396
        p=strchr(p, '\n')+1;
-
 
397
      };
-
 
398
      free(buf); 
371
	    }
399
    };
372
	}
400
};
-
 
401
 
Line 373... Line -...
373
		
-
 
374
	fclose (f);
-
 
375
    }
-
 
376
**********/    
-
 
Line 377... Line 402...
377
}
402
 
378
 
403
 
379
 
404