misc.c 2.68 KB
/*====================================================================
 * misc.c
 *
 * Copyright 1995, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/

#include <ultra64.h>

/*
 * globals set by the boot arguments
 */
int verbose     = 0;
int debugger    = 0;
int rspsim      = 0;
int drawtri     = 0;
int logging	    = 0;

static int myatoi(char *str)
{
    int		log10[5], logn = 0, val = 0, i, pow10 = 1;

    if (str == NULL || *str == '\0')
	return(-1);

    while (*str != '\0') {
	if (!(*str == '0' ||
	      *str == '1' ||
	      *str == '2' ||
	      *str == '3' ||
	      *str == '4' ||
	      *str == '5' ||
	      *str == '6' ||
	      *str == '7' ||
	      *str == '8' ||
	      *str == '9')) {
	    logn = 0;
	    break;
	}

	log10[logn++] = *str - '0';
	str++;
    }

    if (logn == 0)
	return(-1);

    for (i=logn-1; i>= 0; i--) {
	val += log10[i] * pow10;
	pow10 *= 10;
    }
    return (val);
}

void parse_args(char *argstring)
{
    int		argc = 1, i;
    char	*arglist[32], **argv = arglist;	/* max 32 args */
    char	*c, *ptr;

    if (argstring == NULL || argstring[0] == '\0')
	return;

    /* re-organize argstring to be like main(argv,argc) */
    ptr = argstring;
    while (*ptr != '\0') {
	while (*ptr != '\0' && (*ptr == ' ')) {
	    *ptr = '\0';
	    ptr++;
	}
	if (*ptr != '\0')
	    arglist[argc++] = ptr;
	while (*ptr != '\0' && (*ptr != ' ')) {
	    ptr++;
	}
    }

    /* process the arguments: */
    while ((argc > 1) && (argv[1][0] == '-')) {
	switch(argv[1][1]) {

            case 'r':
                rspsim = 1;
                break;
	    
            case 'd':
                debugger = 1;
                break;
	    
            case 'v':
                verbose = 1;
                break;
            
            case 't':
                drawtri = 1;
                break;
            
            case 'l':
                logging = 1;
                break;
            
            default:
                break;
	}
	argc--;
	argv++;
    }
}