Wednesday, December 07, 2011

sdl input handling
while (Running) eating up processor - how to overcome
- generating events by timer purely not good, somehow fill message queue
- when simple logic based key handling the status then it is possible...

then good code found on webkinesia...

Friday, November 25, 2011

if ((Grid[id[0]] != GRID_TYPE_NONE)&&
(Grid[id[0]] == Grid[id[1]] == Grid[id[2]])){
evaluation order!!!

Saturday, August 05, 2006

templates

http://www.programmers-corner.com/viewTutorial.php?ID=2
http://www.comeaucomputing.com/techtalk/templates/
http://www.dgp.toronto.edu/people/JamesStewart/270/9697f/notes/Nov25-tut.html
http://www.cprogramming.com/tutorial/templates.html

Monday, June 26, 2006

making command line option parsing

using getopt_long
- man 3 getopt long
- handling unknown parameter
- handling parameter in optarg
- switch off error message of unknown parameter


#include
#include
#include

void help_option_handling()
{
printf("\n help text:\n");
}

void handle_user_option( char *fname)
{
printf("\nprocessing user file : %s\n", fname);
}

void handle_version_info()
{
printf("\nThis is version 0.1\n");
}

void handle_not_supported_option()
{
printf("\nnot supported option: %c\n", optopt);
}

void handle_unhandled_option()
{
printf("\n not handled option: %s\n", optarg);
}

int main(int argc, char* argv[])
{

int get_opt = -1;
static struct option my_long_option[]=
{
{"user", required_argument, NULL, 'u'},
{"verbose", no_argument, NULL, 'v'},
{"Version", no_argument,NULL, 'V'},
{"help", no_argument,NULL, 'h'},
{ NULL, 0, NULL, 0 }
};

char my_short_options[] = "+u:Vvh";
int option_index;
int verbose_mode = 0;

int original_opterr = opterr;
opterr = 0; //to prevent error messages

while (1)
{
get_opt = getopt_long( argc,
argv,
my_short_options,
my_long_option,
&option_index );
if (get_opt == -1)
{
break;
}
switch (get_opt)
{
case 'h':
help_option_handling();
break;
case 'u':
handle_user_option( optarg );
break;
case 'v':
verbose_mode = 1;
opterr = original_opterr;
break;
case 'V':
handle_version_info();
break;
case '?':
//the unsupported option handling
handle_not_supported_option();
break;

case '1':
handle_unhandled_option();
break;
}
}

return 0;

}

Wednesday, May 17, 2006

about the usage of cvs

Wednesday, February 22, 2006

/*
VALUE
NAME

*/
#include

#include
#include
#include

using namespace std;

map summary;
map counter;

enum Sign{ NAME, NUMBER, NIHIL};

Sign current_sign = NIHIL;
double number_value;
string c_name;

void store_values()
{
summary[c_name] += number_value;
counter[c_name] += 1;
}

Sign get_char()
{

char ch = 0;
cin >> ch;
if( isspace(ch) )
{
switch( current_sign )
{
case NIHIL:
return current_sign;
case NUMBER:
current_sign = NIHIL;
store_values();
return current_sign;
case NAME:
c_name += ch;
return current_sign;
default:
return current_sign;
}
}

switch(ch)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '.':
if ( current_sign == NIHIL ) return current_sign;
current_sign = NUMBER;
cin.putback(ch);
cin>>number_value;
break;
default:
if ( isalpha(ch) )
{
switch (current_sign)
{
case NIHIL:
current_sign = NAME;
c_name = ch;
return current_sign;
case NUMBER:
current_sign = NAME;
store_values();
c_name = ch;
return current_sign;
default:
return current_sign;
}
}
return current_sign;

}
}

void print( const pair& r )
{
cout << r.first << r.second << '\n';
}

int main()
{
while (cin)
{
get_char();
}
for_each( summary.begin(), summary.end(), print );
return 0;
}