コード例 #1
0
ファイル: service.c プロジェクト: trailofbits/cb-multios
/**
 * Function to handle command line meta commands
 * @param cmd Pointer to the command line
 * @return Returns nothing
 **/
void exec_command( char *cmd )
{
    char *ps = NULL;
    int index = 0;
    psetArray psa = NULL;

    if ( cmd == NULL ) {
        goto end;
    }

    if ( strcmp( cmd, ".l") == 0 ) {
        _terminate(0);
    } else if ( strcmp( cmd, ".h") == 0 ) {
        printf("setx = |\"data\", sety|\tInitialize a set\n");
	printf("setx = seta+setb\tunion\n");
	printf("setx = seta^setb\tintersect\n");
	printf("setx = seta-setb\tset difference\n");
	printf("setx = seta~setb\tsymmetric difference\n");
	printf("seta @@ setb\t\tsubset. Returns TRUE or FALSE\n");
	printf(".h\t\tPrint this menu\n");
	printf(".l\t\tExit the program\n");
	printf(".p\t\tPrint sets and their elements\n");
	printf(".ps <setvar>\tPrint an expanded set\n");
    } else if ( memcmp( cmd, ".ps", 3) == 0 ) {
	cmd += 3;

        /// Skip any spaces
	while( *cmd == ' ' ) { ++cmd; }

        /// Skip to the end of the argument
	while( isalnum(cmd[index]) ) { index++; }

        /// Add a null
	cmd[index] = 0x00;
	
	psa = retrieve_set( cmd );

	if ( psa == NULL ) {
            printf("!!Failed to find set: @s\n", cmd );
            goto end;
        }
#ifdef PATCHED
        ps = print_subsets( psa, 1, 0);
#else
        ps = print_subsets( psa, 1 );
#endif 
        if ( ps != NULL ) {
        	printf("@s\n", ps);
		deallocate(ps, cgc_strlen(ps)+1);
	}
    } else if ( strcmp( cmd, ".p") == 0 ) {
        print_sets();
    } else {
        printf("!!Unrecognized command: @s\n", cmd);
        goto end;
    }

end:
    return;
}
コード例 #2
0
ファイル: 8.2.c プロジェクト: deepw/FirstRepo
int main (int argc, char *argv[]) {
	int i =0 ;
	int size = 1;
	if (argv[1]) 
		size = atoi(argv[1]);
	printf ("size=%d.\n", size);
	//for (i=0; i<5; i++) {
	    //printf ("{");
	    print_subsets (i, 5, size, vals[i]);
	  //  printf ("\n");
	//}
	printf ("\n");
	return 0;
}
コード例 #3
0
ファイル: 8.2.c プロジェクト: deepw/FirstRepo
void print_subsets (int begin, int end, int size, int item) {
    int i =0;
    if (begin > end) 
	    return;
    if (size == 0) {
	    //printf ("\n");
	    return;
    } else if (size == 1) {
	    printf ("%d\t", vals[begin]);
	    //return;
    }
    //printf ("%d\t", item);
    for (i=begin;i<end;i++) {
        printf ("%d\t ", vals[i]);
        print_subsets (begin+1, end, size-1, vals[i]);
        printf ("\n");
    }
    //printf ("\n");
    return;
}
コード例 #4
0
ファイル: service.c プロジェクト: trailofbits/cb-multios
char * print_subsets( psetArray r, int addName )
#endif
{
	char *outbuff = NULL;
	char *t = NULL;
	char data[DATAMAX];
	int index = 0;
	int ei = 0;
#ifdef PATCHED
    if (depth > 10) {
        return NULL;
    }
#endif 

	if ( r == NULL ) {
		return NULL;
	}

	bzero( data, DATAMAX);

	if (addName != 0 ) {
		index = copymem( data, r->varName, index, cgc_strlen(r->varName) );
		index = copymem( data, " = ", index, 3 );
	}

	data[index++] = '|';

	for ( ei = 0; ei < r->varCount; ei++) {
		if ( r->sElems[ei]->type == VALUE ) {
#ifdef PATCHED
			if ( index < DATAMAX-1 )
#endif
				data[index++] = '"';

			t = r->sElems[ei]->value;

#ifdef PATCHED
			if ( index + cgc_strlen(t) >= DATAMAX-1 ) {
				goto end;
			}
#endif
			index = copymem( data, t, index, cgc_strlen(t));

#ifdef PATCHED
			if ( index < DATAMAX-1 )
#endif
				data[index++] = '"';
		} else {
			psetArray tp = retrieve_set( r->sElems[ei]->value);
#ifdef PATCHED
            t = print_subsets( tp, 0, depth + 1);
#else
			t = print_subsets( tp, 0 );
#endif

			if ( t == NULL ) {
				outbuff = NULL;
				goto end;
			}

#ifdef PATCHED
			if ( index + cgc_strlen(t) >= DATAMAX-1 ) {
				deallocate(t, cgc_strlen(t) + 1 );
				goto end;
			}
#endif

			index = copymem( data, t, index, cgc_strlen(t));
			deallocate(t, cgc_strlen(t) + 1 );	
		}

#ifdef PATCHED
		if ( index < DATAMAX - 1 )
#endif
			data[index++] = ',';
	}

#ifdef PATCHED
	if ( index < DATAMAX-2 )
#endif
	{
		if ( data[index-1] == ',' ) {
			data[index-1] = '|';
			data[index] = 0x00;
		} else {
			data[index] = '|';
			data[index+1] = 0x00;
		}
	}

	if ( allocate( cgc_strlen(data) + 1, 0, (void*)&outbuff) != 0 ) {
		outbuff = NULL;
		goto end;
	}

	bzero( outbuff, cgc_strlen(data) + 1 );

	copymem( outbuff, data, 0, cgc_strlen(data) );

end:
	return outbuff;
}