[Tux4kids-tuxtype-dev] [Patch] Replace printf() with fprintf()
Jerome Portal
jerome.portal.2 at gmail.com
Fri Apr 12 17:09:50 UTC 2013
Hello,
There were still some printf(...) in tuxtype code, so I replaced them using
the fprintf(stderr, ...) that are used elsewhere. Here is the diff :
>From 0724d11278b50c4abfa8c7f91fdc7e76a635644c Mon Sep 17 00:00:00 2001
From: Jerome Portal <jerome.portal.2 at gmail.com>
Date: Fri, 12 Apr 2013 18:44:29 +0200
Subject: [PATCH 3/3] Replace the printf(...) by fprintf(stderr, ...)
---
src/SDL_extras.c | 4 ++--
src/alphabet.c | 10 +++++-----
src/loaders.c | 4 ++--
src/practice.c | 8 ++++----
src/scandir.c | 8 ++++----
src/setup.c | 6 +++---
6 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/SDL_extras.c b/src/SDL_extras.c
index b1ebe97..2cd747a 100644
--- a/src/SDL_extras.c
+++ b/src/SDL_extras.c
@@ -312,9 +312,9 @@ SDL_Surface* Blend(SDL_Surface* S1, SDL_Surface* S2,
float gamma)
// Check that both images have the same width dimension
if (S1->w != S2->w)
{
- printf("S1->w %d, S2->w %d; S1->h %d, S2->h %d\n",
+ fprintf(stderr, "S1->w %d, S2->w %d; S1->h %d, S2->h %d\n",
S1->w, S2->w, S1->h, S2->h);
- printf("Both images must have the same width dimensions\n");
+ fprintf(stderr, "Both images must have the same width dimensions\n");
return S1;
}
}
diff --git a/src/alphabet.c b/src/alphabet.c
index a6ddbd7..a6ad2f2 100644
--- a/src/alphabet.c
+++ b/src/alphabet.c
@@ -1190,18 +1190,18 @@ void GenerateKeyboard(SDL_Surface* keyboard)
char buf[8];
// TTF_Font* smallfont = NULL;
- DEBUGCODE { printf("Entering GenerateKeyboard\n"); }
+ DEBUGCODE { fprintf(stderr, "Entering GenerateKeyboard\n"); }
if(!keyboard)
{
- DEBUGCODE { printf("Error - keyboard SDL_Surface ptr null\n"); }
+ DEBUGCODE { fprintf(stderr, "Error - keyboard SDL_Surface ptr
null\n"); }
return;
}
// smallfont = LoadFont(settings.theme_font_name, 15);
// if(!smallfont)
// {
-// DEBUGCODE { printf("Error loading font\n"); }
+// DEBUGCODE { fprintf(stderr, "Error loading font\n"); }
// return;
// }
@@ -1247,7 +1247,7 @@ void GenerateKeyboard(SDL_Surface* keyboard)
new.y -= 9;
}
- DEBUGCODE { printf("Making %d :
%C\n",i,keyboard_list[i].unicode_value); }
+ DEBUGCODE { fprintf(stderr, "Making %d :
%C\n",i,keyboard_list[i].unicode_value); }
ConvertToUTF8(t, buf, 8);
tmp = SimpleText(buf, 15, &black);
// tmp = TTF_RenderUNICODE_Blended((TTF_Font*)smallfont, t, black);
@@ -1261,7 +1261,7 @@ void GenerateKeyboard(SDL_Surface* keyboard)
//Know this is safe - if NULL would have returned above:
// TTF_CloseFont(smallfont);
- DEBUGCODE { printf("Leaving GenerateKeyboard\n"); }
+ DEBUGCODE { fprintf(stderr, "Leaving GenerateKeyboard\n"); }
}
diff --git a/src/loaders.c b/src/loaders.c
index 0f1b252..4663d91 100644
--- a/src/loaders.c
+++ b/src/loaders.c
@@ -368,7 +368,7 @@ int LoadBothBkgds(const char* datafile)
DEBUGCODE
{
- printf("Scaling %dx%d to: %dx%d, %dx%d\n",
+ fprintf(stderr, "Scaling %dx%d to: %dx%d, %dx%d\n",
orig->w, orig->h, RES_X, RES_Y, fs_res_x, fs_res_y);
}
@@ -397,7 +397,7 @@ int LoadBothBkgds(const char* datafile)
DEBUGCODE
{
- printf("%d images scaled\nLeaving LoadBothBkgds()\n", ret);
+ fprintf(stderr, "%d images scaled\nLeaving LoadBothBkgds()\n", ret);
}
return ret;
}
diff --git a/src/practice.c b/src/practice.c
index 603a2e5..b57bd9e 100644
--- a/src/practice.c
+++ b/src/practice.c
@@ -861,7 +861,7 @@ static int practice_load_media(void)
int load_failed = 0;
int labels_ok = 0;
- DEBUGCODE { printf("Entering practice_load_media\n"); }
+ DEBUGCODE { fprintf(stderr, "Entering practice_load_media\n"); }
/* load needed SDL_Surfaces: */
@@ -916,7 +916,7 @@ static int practice_load_media(void)
GenerateKeyboard(keyboard);
LOG("DONE - Loading practice media\n");
- DEBUGCODE { printf("Leaving practice_load_media\n"); }
+ DEBUGCODE { fprintf(stderr, "Leaving practice_load_media\n"); }
return 1;
}
@@ -1237,7 +1237,7 @@ static int load_phrases(const char* phrase_file)
return 0;
}
- DEBUGCODE { printf("load_phrases(): phrases file is '%s'\n", fn ); }
+ DEBUGCODE { fprintf(stderr, "load_phrases(): phrases file is '%s'\n", fn
); }
/* We know it will open OK because we already ran CheckFile() on it */
fp = fopen(fn, "r");
@@ -1251,7 +1251,7 @@ static int load_phrases(const char* phrase_file)
if (EOF != fscanf(fp, "%[^\n]\n", buf))
{
ConvertFromUTF8(phrases[num_phrases], buf, MAX_PHRASE_LENGTH);
- DEBUGCODE {printf("phrase %d:\t%S\n", num_phrases,
phrases[num_phrases]);}
+ DEBUGCODE {fprintf(stderr, "phrase %d:\t%S\n", num_phrases,
phrases[num_phrases]);}
num_phrases++;
}
}
diff --git a/src/scandir.c b/src/scandir.c
index c6996f1..e4f5452 100644
--- a/src/scandir.c
+++ b/src/scandir.c
@@ -206,7 +206,7 @@ int scandir(const char *dirname, struct dirent
***namelist, int (*sdfilter)(stru
len = strlen(dirname);
findIn = (char *)malloc(len+5);
strcpy(findIn, dirname);
- printf("scandir : findIn orign=%s\n", findIn);
+ fprintf(stderr, "scandir : findIn orign=%s\n", findIn);
for (d = findIn; *d; d++)
if (*d=='/')
*d='\\';
@@ -234,10 +234,10 @@ int scandir(const char *dirname, struct dirent
***namelist, int (*sdfilter)(stru
*d = 0;
}
- printf("scandir : findIn processed=%s\n", findIn);
+ fprintf(stderr, "scandir : findIn processed=%s\n", findIn);
if ((h=FindFirstFile(findIn, &find))==INVALID_HANDLE_VALUE)
{
- printf("scandir : FindFirstFile error\n");
+ fprintf(stderr, "scandir : FindFirstFile error\n");
ret = GetLastError();
if (ret != ERROR_NO_MORE_FILES)
{
@@ -248,7 +248,7 @@ int scandir(const char *dirname, struct dirent
***namelist, int (*sdfilter)(stru
}
do
{
- printf("scandir : findFile=%s\n", find.cFileName);
+ fprintf(stderr, "scandir : findFile=%s\n", find.cFileName);
selectDir=(struct dirent*)malloc(sizeof(struct
dirent)+strlen(find.cFileName));
strcpy(selectDir->d_name, find.cFileName);
if (!sdfilter || (*sdfilter)(selectDir))
diff --git a/src/setup.c b/src/setup.c
index 47a5e89..2318258 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -245,7 +245,7 @@ int LoadSettings(void)
LOG("WIN32 not defined\n");
#endif
- DEBUGCODE { printf("LoadSettings: settings file is '%s'\n", fn ); }
+ DEBUGCODE { fprintf(stderr, "LoadSettings: settings file is '%s'\n", fn
); }
LOG("LoadSettings: trying to open settings file\n");
@@ -403,14 +403,14 @@ void SaveSettings(void)
snprintf( fn, FNLEN-1, (const char*)"%s/settings.txt",
settings.user_settings_path );
- DEBUGCODE { printf("SaveSettings: settings file is '%s'\n", fn ); }
+ DEBUGCODE { fprintf(stderr, "SaveSettings: settings file is '%s'\n",
fn ); }
LOG("SaveSettings: trying to open settings file\n");
settingsFile = fopen( fn, "w" );
if (settingsFile == NULL) {
- printf("SaveSettings: Settings file cannot be created!\n");
+ fprintf(stderr, "SaveSettings: Settings file cannot be
created!\n");
return;
}
--
1.7.9.5
I also saw that some parts of the code are using a #ifdef DEBUG { ... }
structure to log messages. Wouldn't it be better to replace them with
DEBUGCODE { ... } (or LOG { ... }, if possible) ?
Regards,
Jérôme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/tux4kids-tuxtype-dev/attachments/20130412/21273c67/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Replace-the-printf-.-by-fprintf-stderr.patch
Type: application/octet-stream
Size: 6995 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/tux4kids-tuxtype-dev/attachments/20130412/21273c67/attachment-0001.obj>
More information about the Tux4kids-tuxtype-dev
mailing list