Exemplo n.º 1
0
char		*ft_strtrim(const char *s)
{
	char	*cpy;
	int		i[2];
	int		l;

	i[0] = 0;
	if (s == NULL)
		return (NULL);
	l = ft_strlen(s);
	cpy = ft_strnew(l + 1);
	ft_memcpy(cpy, s, l);
	while (cpy[i[0]] && check_blank(cpy[i[0]]))
		i[0]++;
	i[1] = l - 1;
	while (i[1] > 0)
	{
		if (check_blank(cpy[i[1]]))
			i[1]--;
		else
		{
			cpy[i[1] + 1] = '\0';
			break ;
		}
	}
	return (ft_strdup(&cpy[i[0]]));
}
Exemplo n.º 2
0
int Nquick_draw_cmd(Nv_data * dc, Tcl_Interp * interp)
{
    int i, max;
    int *surf_list, *vol_list;

    GS_set_draw(GSD_BACK);
    GS_clear(dc->BGcolor);
    GS_ready_draw();
    surf_list = GS_get_surf_list(&max);

    max = GS_num_surfs();
    for (i = 0; i < max; i++) {
	if (check_blank(interp, surf_list[i]) == 0) {
	    GS_draw_wire(surf_list[i]);
	}
    }

    G_free(surf_list);

    vol_list = GVL_get_vol_list(&max);
    max = GVL_num_vols();
    for (i = 0; i < max; i++) {
	if (check_blank(interp, vol_list[i]) == 0) {
	    GVL_draw_wire(vol_list[i]);
	}
    }

    GS_done_draw();

/*** ACS_MODIFY flythrough  ONE LINE ***************/
    flythrough_postdraw_cb();

    return (TCL_OK);
}
Exemplo n.º 3
0
//figures out how many eyes are in the go board and returns that number
int
determine_eyes_black(char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE])
{
    int row=0, column=0, eyes=0;
    for(row=0; row<GO_BOARD_SIZE; row++)
    {
        for(column=0; column<GO_BOARD_SIZE; column++)
        {
            if(go_board[row][column]=='+')//goes through the go board and finds a blank space
            {
                if(check_blank(row, column, go_board))//calls function that will return true if the blank space is an eye
                {
                    eyes+=1;//increment eye count
                }
            }
        }
    }
    return eyes;//return eyes
}
Exemplo n.º 4
0
string read_text(char* filename){
	string buff_s = "";
	char buff;
	ifstream ifs;
	ifs.open(filename);

	if (!ifs.is_open() || !ifs.good()){
		cerr << "ERROR : couldn't load file " << filename << endl;
	}
	else{
		while (ifs.get(buff)){
			blank_to_space(buff);
			if (check_blank(buff_s, buff))
				buff_s.push_back(buff);
		}
	}

	ifs.close();
	return buff_s;
}
Exemplo n.º 5
0
//function that takes original eye and checks to see if there is an eye close enough to count as a two eye structure
Bool
doubledown(int row, int column, char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE])
{
    int row_x, col_x;
    for(row_x=row-2; row_x<row+3; row_x++)//steps through the spaces around the given space with a radius of two spaces
    {
        for(col_x=column-2; col_x<column+3; col_x++)
        {
            if((row_x>=0&&row_x<GO_BOARD_SIZE)&&//makes sure that the point is inside the board
               (col_x>=0&&col_x<GO_BOARD_SIZE))
            {
                if(go_board[row_x][col_x]=='+')//if the point is an empty space...
                {
                    if(check_blank(row_x, col_x, go_board))//check to see if its an eye
                        return TRUE;
                }
            }
        }
    }
    return FALSE;//else return false
}
Exemplo n.º 6
0
void player()
{
	int i,j,k,l,m,flag;
	f_count=0;
	for(i=0;i<10;i++)
		for (j=0;j<10;j++)
			user[i][j]='.';
	do
	{
		clrscr();

		flag=0;
		cout<<"::MineSweeper::"<<endl;
		cout<<endl;
		for(i=0;i<10;i++)
		{
			if(i==0)
				cout<<" ";
			cout<<"  "<<i;
		}
		cout<<endl;
		for(i=0;i<10;i++)
		{
			for(j=0;j<10;j++)
			{
				if(j==0)
					cout<<i;
				cout<<"  "<<user[i][j];
			}
			cout<<endl;
		}
		cout<<"\n Enter the Co-Ordinates:";
		cin>>x>>y;
		check_blank();
		check_1_2();
		flag=check_bomb();
		f_count++;
//		getch();
	}while(flag!=1);
}
Exemplo n.º 7
0
//determines how many two eye structures there are in the go board
//borrows the helper functions used in determine eyes function
int
determine_twoeyes_black(char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE])
{
    int twoeyes=0, row, column;
    for(row=0; row<GO_BOARD_SIZE; row++)
    {
        for(column=0; column<GO_BOARD_SIZE; column++)
        {
            if(go_board[row][column]=='+')//goes through and sees if there is a blank space
            {
                if(check_blank(row, column, go_board))//checks to see if there is an eye at that blank space
                {
                    if(doubledown(row, column, go_board))//now checks to see if there is an eye close enough to the eye found
                    {
                        twoeyes++;//if checks true, increment twoeyes
                    }
                }
            }
        }
    }
    return twoeyes/2;//returns twoeyes count. The reason we divide by two is because the twoeyes function will count a
    //two eye structure twice as a consequence of stepping through the array in a nested for loop
}
Exemplo n.º 8
0
static if_state get_cond_state( int i )
{
    uint_16     direct;
    if_state    cond_state;

    direct = AsmBuffer[i]->u.value;

    /* expand any constants if necessary */
    switch( direct ) {
    case T_IF:
    case T_IFDIF:
    case T_IFDIFI:
    case T_IFE:
    case T_IFIDN:
    case T_IFIDNI:
    case T_ELSEIF:
    case T_ELSEIFDIF:
    case T_ELSEIFDIFI:
    case T_ELSEIFE:
    case T_ELSEIFIDN:
    case T_ELSEIFIDNI:
        ExpandTheWorld( i+1, FALSE, TRUE );
    }

    switch( direct ) {
    case T_IF:
    case T_ELSEIF:
        cond_state = ( AsmBuffer[i+1]->token == T_NUM && AsmBuffer[i+1]->u.value )
                     ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    case T_IF1:
    case T_ELSEIF1:
        cond_state = Parse_Pass == PASS_1 ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    case T_IF2:
    case T_ELSEIF2:
        cond_state = Parse_Pass == PASS_1 ? LOOKING_FOR_TRUE_COND : ACTIVE;
        break;
    case T_IFB:
    case T_ELSEIFB:
        cond_state = check_blank( AsmBuffer[i+1]->string_ptr ) ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    case T_IFDEF:
    case T_ELSEIFDEF:
        cond_state = check_defd( AsmBuffer[i+1]->string_ptr )  ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    case T_IFE:
    case T_ELSEIFE:
        cond_state = ( AsmBuffer[i+1]->token == T_NUM && !AsmBuffer[i+1]->u.value )
                     ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    case T_IFDIF:
    case T_ELSEIFDIF:
        cond_state = check_dif( TRUE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    case T_IFDIFI:
    case T_ELSEIFDIFI:
        cond_state = check_dif( FALSE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    case T_IFIDN:
    case T_ELSEIFIDN:
        cond_state = !check_dif( TRUE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    case T_IFIDNI:
    case T_ELSEIFIDNI:
        cond_state = !check_dif( FALSE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    case T_IFNB:
    case T_ELSEIFNB:
        cond_state = !check_blank( AsmBuffer[i+1]->string_ptr ) ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    case T_IFNDEF:
    case T_ELSEIFNDEF:
        cond_state = !check_defd( AsmBuffer[i+1]->string_ptr )  ? ACTIVE : LOOKING_FOR_TRUE_COND;
        break;
    default:
        cond_state = DONE;
        break;
    }
    return( cond_state );
}
Exemplo n.º 9
0
int conditional_error_directive( int i )
/**************************************/
{
    uint_16         direct;

    direct = AsmBuffer[i]->u.value;

    /* expand any constants if necessary */
    switch( direct ) {
    case T_DOT_ERRE:
    case T_DOT_ERRNZ:
    case T_DOT_ERRDIF:
    case T_DOT_ERRDIFI:
    case T_DOT_ERRIDN:
    case T_DOT_ERRIDNI:
    case T_ERRIFE:
    case T_ERRIFDIF:
    case T_ERRIFDIFI:
    case T_ERRIFIDN:
    case T_ERRIFIDNI:
        ExpandTheWorld( i+1, FALSE, TRUE );
    }

    switch( direct ) {
    case T_DOT_ERR:
    case T_ERR:
        AsmErr( FORCED );
        return( ERROR );
    case T_DOT_ERRNZ:
        if( AsmBuffer[i+1]->token == T_NUM && AsmBuffer[i+1]->u.value ) {
            AsmErr( FORCED_NOT_ZERO, AsmBuffer[i+1]->u.value );
            return( ERROR );
        }
        break;
    case T_DOT_ERRE:
    case T_ERRIFE:
        if( AsmBuffer[i+1]->token == T_NUM && !AsmBuffer[i+1]->u.value ) {
            AsmErr( FORCED_EQUAL, AsmBuffer[i+1]->u.value );
            return( ERROR );
        }
        break;
    case T_DOT_ERRDEF:
    case T_ERRIFDEF:
        if( check_defd( AsmBuffer[i+1]->string_ptr ) ) {
            AsmErr( FORCED_DEF, AsmBuffer[i+1]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRNDEF:
    case T_ERRIFNDEF:
        if( !check_defd( AsmBuffer[i+1]->string_ptr ) ) {
            AsmErr( FORCED_NOT_DEF, AsmBuffer[i+1]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRB:
    case T_ERRIFB:
        if( AsmBuffer[i+1]->token == T_STRING &&
                check_blank( AsmBuffer[i+1]->string_ptr ) ) {
            AsmErr( FORCED_BLANK, AsmBuffer[i+1]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRNB:
    case T_ERRIFNB:
        if( AsmBuffer[i+1]->token != T_STRING ||
                !check_blank( AsmBuffer[i+1]->string_ptr ) ) {
            AsmErr( FORCED_NOT_BLANK, AsmBuffer[i+1]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRDIF:
    case T_ERRIFDIF:
        if( check_dif( TRUE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ) {
            AsmErr( FORCED_DIF, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRDIFI:
    case T_ERRIFDIFI:
        if( check_dif( FALSE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ) {
            AsmErr( FORCED_DIF, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRIDN:
    case T_ERRIFIDN:
        if( !check_dif( TRUE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ) {
            AsmErr( FORCED_IDN, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr );
            return( ERROR );
        }
        break;
    case T_DOT_ERRIDNI:
    case T_ERRIFIDNI:
        if( !check_dif( FALSE, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr ) ) {
            AsmErr( FORCED_IDN, AsmBuffer[i+1]->string_ptr, AsmBuffer[i+3]->string_ptr );
            return( ERROR );
        }
        break;
    }
    return( NOT_ERROR );
}
void parse_options(int argc, char **argv)
{
    int index, result;

    /*
     * TOOD: In the future we'll add -P for kernel parameter
     */
    const struct option long_options[] = {
        { "help",	 no_argument,		NULL, 'h'},
        { "bootprog",	 required_argument,	NULL, 'b' },
        { "device",	 required_argument,	NULL, 'd' },
        { "lun",	 required_argument,	NULL, 'l' },
        { "wwpn",	 required_argument,	NULL, 'w' },
        { "loadparm",	 required_argument,	NULL, 'L' },
        { "version",	 no_argument,		NULL, 'v' },
        { NULL,		 0,			NULL,  0  }
    };

    /* dont run without any argument */
    if (argc == 0 || argc == 1)
        print_usage_ripl(argv[0]);
    if  (strncmp(argv[1], "fcp", 3) == 0) {
        action = ACT_FCP;
        use_ccw = 0;
    } else if (strncmp(argv[1], "ccw", 3) == 0) {
        use_ccw = 1;
        action = ACT_CCW;
    } else if (strncmp(argv[1], "node", 4) == 0) {
        action = ACT_NODE;
    }
    /*
     *TODO: In the future we will have an additional argument called
     * nss with a parameter -n
     */
    while (1) {
        index = -1;
        result = getopt_long(argc, argv, "hcd:vw:l:f:L:b:",
                             long_options, &index);
        if (result == -1)
            break;		/* end of list */
        switch (result) {
        case 'h':
            print_usage_ripl(argv[0]);
            break;
        case 'd':
            check_blank(argv[optind - 1], optarg);
            set_devno(optarg);
            break;
        case 'l':
            check_blank(argv[optind - 1], optarg);
            set_lun(optarg);
            break;
        case 'w':
            check_blank(argv[optind - 1], optarg);
            set_wwpn(optarg);
            break;
        case 'L':
            check_blank(argv[optind - 1], optarg);
            set_loadparm(optarg);
            break;
        case 'b':
            check_blank(argv[optind - 1], optarg);
            set_bootprog(optarg);
            break;
        case 'v':
            print_version();
            break;
        case '?':
            printf("Try '%s' --help' for more information.\n",
                   name);
            exit(1);
            break;
        case -1:
            /*
             * we also run in this case if no argument was specified
             */
            break;
        default:
            print_usage_ripl(argv[0]);
        }
    }
    if (!action) {
        fprintf(stderr, "%s: No valid action specified\n", name);
        exit(1);
    }
    /*
     * optind is a index which points to the first unrecognised
     * command line argument
     */
    if (argc - optind > 1)
        parse_args(&argv[optind + 1], argc - optind - 1);

    /*
     * Check for valid option combinations
     */
    switch (action) {
    case ACT_FCP:
        check_fcp_opts();
        break;
    case ACT_CCW:
        check_ccw_opts();
        break;
    case ACT_NODE:
        check_node_opts();
        break;
    }
}