From: Eric S. Raymond Date: Tue, 27 Nov 2012 06:46:50 +0000 (-0500) Subject: cppcheck cleanup. Also, use C99 bools for flags. X-Git-Tag: 2.5~2 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=8760f8b98d7beb8494f7dc227359bf797853f68f;p=morse-classic.git cppcheck cleanup. Also, use C99 bools for flags. --- diff --git a/morse.d/morse.c b/morse.d/morse.c index 6214696..4ad3a31 100644 --- a/morse.d/morse.c +++ b/morse.d/morse.c @@ -81,32 +81,32 @@ static float intra_char_time; static float inter_char_time; static float inter_word_time; static float catchup_time; -static int showletters = 0; -static int showmorse = 0; -static int wordsbefore = 0; -static int wordsafter = 0; -static int fancyending = 1; -static int noticebad = 0; -static int testing = 0; -static int showtesting = 0; -static int keepquiet = 0; -static int dynamicspeed = 0; -static int charbychar = 0; -static int international = 0; -static int allprosigns = 0; -static int allpunctuation = 0; +static bool showletters = false; +static bool showmorse = false; +static bool wordsbefore = false; +static bool wordsafter = false; +static bool fancyending = true; +static bool noticebad = false; +static bool testing = false; +static bool showtesting = false; +static bool keepquiet = false; +static bool dynamicspeed = false; +static bool charbychar = false; +static bool international = false; +static bool allprosigns = false; +static bool allpunctuation = false; static int tryagaincount = 1; static float words_per_minute = WORDS_PER_MINUTE; static float error_frequency = ERROR_FREQUENCY; static float error_volume = ERROR_VOLUME; static float fwords_per_minute; -static int randomletters = 0; +static bool randomletters = false; #define LETMESEE 2 -static int typeaway = 0; +static bool typeaway = 0; static int totalhitcount = 0; static int totalmisscount = 0; -static int helpmeflag = 0; +static bool helpmeflag = false; #define MAXWORDLEN 20 #define TESTBUFSZ ((MAXWORDLEN+1)*10) @@ -349,116 +349,116 @@ struct sigaction handler; switch ((char) ch) { case 'A': - international = 1; + international = true; break; case 'B': - allpunctuation = 1; + allpunctuation = true; break; case 'C': user_charset = optarg; break; case 'E': - testing = 1; - sscanf (optarg, "%d", &error_threshold); + testing = true; + error_threshold = atoi (optarg); if (error_threshold < error_floor) error_floor = error_threshold; break; case 'F': - sscanf (optarg, "%f", &fwords_per_minute); + fwords_per_minute = atof (optarg); break; case 'I': typeaway = LETMESEE; break; case 'M': - testing = 1; - sscanf (optarg, "%d", &max_behindness); + testing = true; + max_behindness = atoi (optarg); if (max_behindness < 1) max_behindness = 0; break; case 'N': - sscanf (optarg, "%d", &wordcount); + wordcount = atoi(optarg); if (wordcount < 1) wordcount = -1; break; case 'R': - sscanf (optarg, "%d", &timeout); + timeout = atoi (optarg); timeout *= 60; if (timeout < 1) timeout = -1; break; case 'S': - allprosigns = 1; + allprosigns = true; break; case 'T': - testing = 1; - showtesting = 1; + testing = true; + showtesting = true; break; case 'X': - sscanf (optarg, "%f", &error_volume); + error_volume = atof (optarg); break; case 'a': - wordsafter = 1; + wordsafter = true; break; case 'b': - wordsbefore = 1; + wordsbefore = true; break; case 'c': - noticebad = 1; + noticebad = true; break; case 'd': - dynamicspeed = 1; + dynamicspeed = true; break; case 'e': - fancyending = 0; + fancyending = false; break; case 'f': - sscanf (optarg, "%f", &frequency1); + frequency1 = atof (optarg); break; case 'g': - sscanf (optarg, "%f", &frequency2); + frequency2 = atof (optarg); break; case 'i': - typeaway = 1; + typeaway = true; break; case 'l': - showletters = 1; + showletters = true; break; case 'm': - showmorse = 1; + showmorse = true; break; case 'n': - sscanf (optarg, "%d", &wordlen); + wordlen = atoi (optarg); if (wordlen < 1) wordlen = 1; if (wordlen > MAXWORDLEN) wordlen = MAXWORDLEN; break; case 'p': - charbychar = 1; - testing = 1; - sscanf (optarg, "%d", &tryagaincount); + charbychar = true; + testing = true; + tryagaincount = atoi (optarg); break; case 'q': - keepquiet = 1; + keepquiet = true; break; case 'r': - randomletters = 1; + randomletters = true; break; case 's': - charbychar = 1; - testing = 1; + charbychar = true; + testing = true; break; case 't': - testing = 1; + testing = true; break; case 'v': - sscanf (optarg, "%f", &volume); + volume = atof (optarg); if (volume < 0.) volume = 0.; if (volume > 1.) volume = 1.; break; case 'w': - sscanf (optarg, "%f", &words_per_minute); + words_per_minute = atof (optarg); break; case 'x': - sscanf (optarg, "%f", &error_frequency); + error_frequency = atof (optarg); break; default: fprintf (stderr, "Type \"morse\" without arguments to get self-doc!\n"); @@ -647,8 +647,8 @@ struct sigaction handler; { bool notdoneyet; - testing = 0; - showtesting = 0; + testing = false; + showtesting = false; charbychar = 0; wordsbefore = 0; wordsafter = 0; @@ -925,7 +925,7 @@ char *wordp; pollyou (); /* Forget the past */ - helpmeflag = 0; + helpmeflag = false; behindness = 0; testlength = 0; yourlength = 0; @@ -1520,7 +1520,7 @@ int resync; } else if (yourchar == '\b') { - helpmeflag = 1; + helpmeflag = true; } /* The _other_ pointer wasn't used; don't increment it. */