コード例 #1
0
int
cChannelMap::read_config_file (string mapfile)
{
    ifstream cmfile;
    string s;
    size_t p;
    int tvmid;
    int n;

    cmfile.open (mapfile.c_str());
    if (!cmfile)
    {
        fprintf(stderr,"Unable to open channelmap file: %s.\n", mapfile.c_str());
        return -1;
    }

    fprintf(stderr,"Load '%s': ", mapfile.c_str());
    n = 0;
    while (!cmfile.eof ())
    {
        getline (cmfile, s);

        if (!s.empty ())
        {
            remove_whitespaces ((char *) s.c_str ());

            // remove comments
            p = s.find_first_of ("//");
            if (p != string::npos)
                s.erase (p);

            // split line
            p = s.find_first_of ("=");
            if ((p != string::npos) && (s.substr (p + 1).length ()))
            {
                char *ptr = NULL;
                tvmid = atoi (s.substr (0, p).c_str ());
                if ((ptr = strdup(s.substr (p + 1).c_str ())) != NULL)
                {
                    char *vpsptr = NULL;
                    // one of the chars "1yYjJ" separated from the channelids
                    // by a colon means the sender has VPS
                    vpsmap[tvmid] = false;
                    if ((vpsptr = index(ptr, ':')) != NULL)
                    {
                        *vpsptr++ = '\0';
                        vpsmap[tvmid] = (index("1yYjJ", *vpsptr) != NULL);
                    }
                    chanmap[tvmid].push_back(ptr);
                    // are there more channelids separated by commas?
                    while ((ptr = index(ptr, ',')) != NULL)
                    {
                        *ptr++ = '\0';
                        chanmap[tvmid].push_back(ptr);
                    }
                }
                n++;
            }
        }
    }
    cmfile.close ();
    fprintf(stderr,"%d channel mappings read.\n", n);
    return n;
}
コード例 #2
0
keylist * parse_config ( char * buf ){

   remove_remarks ( buf );
   remove_whitespaces ( buf );
   return parse_config_buf ( buf );
}
コード例 #3
0
ファイル: ilur.c プロジェクト: 123woodman/minko
/**
 * Assumed that the right image is bound to IL
 */
int perform_operation(const char * operation, int verbose)
{
	/* Where to store the first parsing results? */
	char function[long_strlen], params[long_strlen], solid_params[long_strlen];
	/* Get the function name string and parameters string */
	parse_function(operation, function, params);
	/* Get rid of any whitespaces from the parameters string */
	remove_whitespaces(params, solid_params);
	if (verbose)
		printf("Calling %s(%s)\n", function, solid_params);
	/* What function was wanted? -1 means that we don't know */
	int function_index = -1;
	int i;
	for (i = 0; i < ILU_FUN_COUNT; i++)
		if (strncmp(function, ilu_functions[i].Name, short_strlen) == 0)
		{/* Yeah, this function was wanted. Let's have its index from the ilu_functions array */
			function_index = i;
			break;	/* nothing to do here any more */
		}
	if (function_index == -1)
	{/* Seems we haven't found anything... */
		fprintf(stderr, "Error: You have specified an invalid function name '%s' (have you called %s).\nRun '%s --help' command to get some help\n", function, operation, program_name);
		return 1;
	}
	/* We are going to try something and we want to know how it ended */
	ILboolean return_value;
	switch (ilu_functions[function_index].Parameter_type)
	{/* First semi-automatic processing according to type of parameters */
		case PARAM_VOID:
			{
				ILboolean (* function)() = ilu_functions[function_index].Callback;
				return_value = function();
				break;
			}/* endcase PARAM_VOID */
		case PARAM_ILUINT:
			{
				/* first assign and determine the type of the Callback */
				ILboolean (* function)(ILuint) = ilu_functions[function_index].Callback;
				/* then declare the parameter variables */
				ILuint param_value;
				/* fill them */
				int success = sscanf(solid_params, "%u", & param_value);
				if (success != 1)
				{/* see how it ended */
					fprintf(stderr, "Error interpreting '%s' as unsigned integer (when calling %s)\n", solid_params, operation);
					break;
				}
				/* execute the command and store the result */
				return_value = function(param_value);
				break;
			}/* endcase PARAM_ILUINT */
		case PARAM_ILFLOAT:
			{
				ILboolean (* function)(ILfloat) = ilu_functions[function_index].Callback;
				double param_value;
				int success = sscanf(solid_params, "%lf", & param_value);
				if (success != 1)
				{
					fprintf(stderr, "Error interpreting '%s' as float (when calling %s)\n", solid_params, operation);
					break;
				}
				return_value = function((ILfloat)param_value);
				break;
			}/* endcase PARAM_ILFLOAT */
		case PARAM_OTHERS:
			switch (function_index)
			{/* next, the manual processing according to names */
				case ILU_SHARPEN:
					{
						ILboolean (* function)(ILfloat, ILuint) = ilu_functions[function_index].Callback;
						double factor; 
						ILuint iter;
						int success = sscanf(solid_params, "%lf,%u", & factor, & iter);
						if (success != 2)
						{
							fprintf(stderr, "Error interpreting '%s' as floating-point number and unsigned integer separated by comma (when calling %s)\n", solid_params, operation);
							break;
						}
						return_value = function((ILfloat)factor, iter);
						break;
					}/* endcase ILU_SHARPEN */
				case ILU_CROP:
					{
						ILboolean (* function)(ILuint, ILuint, ILuint, ILuint, ILuint, ILuint ) = ilu_functions[function_index].Callback;
						ILuint xoff, yoff, zoff, width, height, depth;
						int success = sscanf(solid_params, "%u,%u,%u,%u,%u,%u", & xoff, & yoff, & zoff, & width, & height, & depth);
						if (success != 6)
						{
							fprintf(stderr, "Error interpreting '%s' as 6 unsigned integers separated by comma (when calling %s)\n", solid_params, operation);
							break;
						}
						return_value = function(xoff, yoff, zoff, width, height, depth);
						break;
					}/* endcase ILU_CROP */
				case ILU_ENLARGECANVAS:
				case ILU_SCALE:
					{
						ILboolean (* function)(ILuint, ILuint, ILuint) = ilu_functions[function_index].Callback;
						ILuint width, height, depth;
						int success = sscanf(solid_params, "%u,%u,%u", & width, & height, & depth);
						if (success != 3)
						{
							fprintf(stderr, "Error interpreting '%s' as 3 unsigned integers separated by comma (when calling %s)\n", solid_params, operation);
							break;
						}
						return_value = function(width, height, depth);
						break;
					}/* endcase ILU_ENLARGECANVAS + ILU_SCALE */
				case ILU_ENLARGEIMAGE:
				case ILU_SCALECOLOURS:
					{
						ILboolean (* function)(ILfloat, ILfloat, ILfloat) = ilu_functions[function_index].Callback;
						double first, second, third;
						int success = sscanf(solid_params, "%lf,%lf,%lf", & first, & second, & third);
						if (success != 3)
						{
							fprintf(stderr, "Error interpreting '%s' as 3 floating-point numbers separated by comma (when calling %s)\n", solid_params, operation);
							break;
						}
						return_value = function((ILfloat)first, (ILfloat)second, (ILfloat)third);
						break;
					}/* endcase ILU_ENLARGEIMAGE + ILU_SCALECOLOURS */
				case ILU_ROTATE3D:
				case ILU_SATURATE4F:
					{
						ILboolean (* function)(ILfloat, ILfloat, ILfloat, ILfloat) = ilu_functions[function_index].Callback;
						double first, second, third, fourth;
						int success = sscanf(solid_params, "%lf,%lf,%lf,%lf", & first, & second, & third, & fourth);
						if (success != 4)
						{
							fprintf(stderr, "Error interpreting '%s' as 4 floating-point numbers separated by comma (when calling %s)\n", solid_params, operation);
							break;
						}
						return_value = function((ILfloat)first, (ILfloat)second, (ILfloat)third, (ILfloat)fourth);
						break;
					}/* endcase ILU_ROTATE3D + ILU_SATURATE4F */
				case ILU_REPLACECOLOUR:
					{
						ILboolean (* function)(ILubyte, ILubyte, ILubyte, ILfloat ) = ilu_functions[function_index].Callback;
						ILuint red, green, blue;
						double tolerance;
						int success = sscanf(solid_params, "%u,%u,%u,%lf", & red, & green, & blue, & tolerance);
						if (success != 4)
						{
							fprintf(stderr, "Error interpreting '%s' as 3 8-bit unsigned integers and one floating-point number separated by comma (when calling %s)\n", solid_params, operation);
							break;
						}
						return_value = function((ILubyte)red, (ILubyte)green, (ILubyte)blue, (ILfloat)tolerance);
						break;
					}/* endcase ILU_ROTATE3D + ILU_SATURATE4F * */
				/* iluConvolution(ILint *matrix, ILint scale, ILint bias); Any idea about this? */ 
			}/* endswitch(function_index) */
			break;

	}/* endswitch (ilu_functions[function_index].Parameter_type) */
	/* It didn't end good for some reason... */
	if (return_value == IL_FALSE)
	{
		int error= ilGetError();
		fprintf(stderr, "Something got wrong when calling %s(%s): %s\n", function, solid_params, iluErrorString(error) );
		return error;
	}
	return 0;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: pedro2111/criptografia
int main(){
	
 	FILE *arq;
   	char *result;
	int i,j;
	int size_key = 8;
	char msg[] = "Uma criança nasce sem qualquer conhecimento, sem qualquer consciência de seu próprio eu. E quando uma criança nasce, a primeira coisa da qual ela se torna consciente não é ela mesma; a primeira coisa da qual ela se torna consciente é o outro. Isso é natural, porque os olhos se abrem para fora, as mãos tocam os outros, os ouvidos escutam os outros, a língua saboreia a comida e o nariz cheira o exterior. Todos esses sentidos abrem-se para fora. O nascimento é isso. Nascimento significa vir a esse mundo: o mundo exterior. Assim, quando uma criança nasce, ela nasce nesse mundo. Ela abre os olhos e vê os outros. O outro significa o tu.  Ela primeiro se torna consciente da mãe. Então, pouco a pouco, ela se torna consciente de seu próprio corpo. Esse também é o 'outro', também pertence ao mundo. Ela está com fome e passa a sentir o corpo; quando sua necessidade é satisfeita, ela esquece o corpo. É dessa maneira que a criança cresce. Primeiro ela se torna consciente do você, do tu, do outro, e então, pouco a pouco, contrastando com você, com tu, ela se torna consciente de si mesma. Essa consciência é uma consciência refletida. Ela não está consciente de quem ela é. Ela está simplesmente consciente da mãe e do que ela pensa a seu respeito. Se a mãe sorri, se a mãe aprecia a criança, se diz 'você é bonita', se ela a abraça e a beija, a criança sente-se bem a respeito de si mesma. Assim, um ego começa a nascer. Através da apreciação, do amor, do cuidado, ela sente que é ela boa, ela sente que tem valor, ela sente que tem importância. Um centro está nascendo. Mas esse centro é um centro refletido. Ele não é o ser verdadeiro. A criança não sabe quem ela é; ela simplesmente sabe o que os outros pensa a seu respeito. E esse é o ego: o reflexo, aquilo que os outros pensam. Se ninguém pensa que ela tem alguma utilidade, se ninguém a aprecia, se ninguém lhe sorri, então, também, um ego nasce - um ego doente, triste, rejeitado, como uma ferida, sentindo-se inferior, sem valor. Isso também é ego. Isso também é um reflexo.";
	int msg_lenght = (int) strlen (msg);

	Key *key;
	Cypher *original;
	Cypher *encripted;
	Cypher *desencripted;
	Cypher *breaked;

	key = (Key *)calloc(1,sizeof(Key));
	key->msg = (char *)calloc(size_key,sizeof(char));
	key->index = (int *)calloc(size_key,sizeof(int));

	original = (Cypher *)calloc(1,sizeof(Cypher));
	original->msg = (char *)calloc(msg_lenght,sizeof(char));
	original->lenght = msg_lenght;

	encripted = (Cypher *)calloc(1,sizeof(Cypher));
	encripted->msg = (char *)calloc(msg_lenght,sizeof(char));	
	encripted->lenght = msg_lenght;

	desencripted = (Cypher *)calloc(1,sizeof(Cypher));
	desencripted->msg = (char *)calloc(msg_lenght,sizeof(char));	
	desencripted->lenght = msg_lenght;

	breaked = (Cypher *)calloc(1,sizeof(Cypher));
	breaked->msg = (char *)calloc(msg_lenght,sizeof(char));	
	breaked->lenght = msg_lenght;

	strcpy(original->msg, msg);

	arq = fopen("key.txt", "rt");
 	if(arq == NULL)
		printf("Erro, nao foi possivel abrir o arquivo\n");
	
	while (!feof(arq)){
		result = fgets(key->msg, 100, arq);  
		if (result)
			printf("key: %s", key->msg);
		i++;
	}

	
	key->lenght = (int) strlen(key->msg);

	//Pegando o vetor de index
	get_indexKey(key);
	
	//Tirando os espaços em branco
	remove_whitespaces(original);
	original->lenght = (int) strlen(original->msg);
	
	//Preenchendo os espaços restantes
	fill_spaces(original);
	original->lenght = (int) strlen(original->msg);
	//Cifrando o texto
	cipher(key, original, encripted);
	encripted->lenght = (int) strlen(encripted->msg);
	//Decifrando o texto
	decipher(key, encripted, desencripted);
	
	for(j = 0; j < size_key;j++){
		printf("%d", key->index[j]);
	}

	printf("\nNormal: %s\n", original->msg);
	printf("\n\n");
	printf("Ciphed: %s\n", encripted->msg);
	printf("\n\n");
	printf("Deciphed: %s\n", desencripted->msg);
	printf("\n\n");
	
/*
	int key_break_size = 0;
	for (int i = 1; i <= 8; i++){
		key_break_size = i;
		permutations(K_SIZE, text);
    	}*/	

	//cypher(key, original, encripted);
	free(key);
	free(original);	
	free(encripted);
	free(desencripted);

	return 0;

}