Misc.
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 17 Jul 2006 14:39:54 +0000 (14:39 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 17 Jul 2006 14:39:54 +0000 (14:39 +0000)
Change a bunch of perror() calls by ones to strerror() to simplify the
code and to allow translators to choose the position of the message
themselves.

Move code around for viewing pleasure.

Try and avoid carrying 'res' around.  C has better ways.

Another language lesson:  use idioms.  'else if', 'else if', 'else
if' look a lot better as a switch statement.

Update Latvian translation.

git-svn-id: https://s.snth.net/svn/neverball/trunk@515 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/level.c
ball/set.c
ball/set.h
ball/st_set.c
po/lv.po

index e11bbba..515a247 100644 (file)
 void score_init_hs(struct score *s, int timer, int coins)
 {
     int i;
+
     strcpy(s->player[0], "Hard");
     strcpy(s->player[1], "Medium");
     strcpy(s->player[2], "Easy");
     strcpy(s->player[3], "");
+
     for (i = 0; i < NSCORE + 1; i++)
     {
         s->timer[i] = timer;
index bcf953e..d108af8 100644 (file)
@@ -109,23 +109,26 @@ static void set_load_hs(void)
                (strlen(states) == s->count));
         for (i = 0; i < s->count && res; i++)
         {
-            if (states[i] == 'L')
+            switch (states[i])
             {
+            case 'L':
                 level_v[i].is_locked = 1;
                 level_v[i].is_completed = 0;
-            }
-            else if (states[i] == 'C')
-            {
+                break;
+
+            case 'C':
                 level_v[i].is_locked = 0;
                 level_v[i].is_completed = 1;
-            }
-            else if (states[i] == 'O')
-            {
+                break;
+
+            case 'O':
                 level_v[i].is_locked = 0;
                 level_v[i].is_completed = 0;
-            }
-            else
+                break;
+
+            default:
                 res = 0;
+            }
         }
 
         res = res &&
@@ -145,35 +148,34 @@ static void set_load_hs(void)
 
     if (!res && errno != ENOENT)
     {
-        fprintf(stderr, _("Error while loading user high-score file '%s': "),
-                fn);
-        if (errno)
-            perror(NULL);
-        else
-            fprintf(stderr, _("Incorrect format\n"));
+        fprintf(stderr,
+                _("Error while loading user high-score file '%s': %s\n"),
+                fn, errno ? strerror(errno) : _("Incorrect format"));
     }
 }
 
-static char *chomp(char *str)
 /* Remove trailing \n if any */
+
+static char *chomp(char *str)
 {
     char *p = str + strlen(str) - 1;
-    if (p >= str && *p == '\n') *p = 0;
+    if (p >= str && *p == '\n')
+        *p = 0;
     return str;
 }
 
 static int set_load(struct set *s, const char *filename)
 {
     FILE *fin;
-
     char buf[MAXSTR];
     int res;
 
     fin = fopen(config_data(filename), "r");
+
     if (!fin)
     {
-        fprintf(stderr, _("Cannot load the set file '%s':"), filename);
-        perror(NULL);
+        fprintf(stderr, _("Cannot load the set file '%s': %s\n"),
+                filename, strerror(errno));
         return 0;
     }
 
@@ -186,7 +188,7 @@ static int set_load(struct set *s, const char *filename)
 
     /* Load set metadata. */
 
-    strcpy(s->file, config_data(filename));
+    strcpy(s->file, filename);
 
     if ((res = fgets(buf, MAXSTR, fin) != NULL))
         strcpy(s->name, chomp(buf));
@@ -251,37 +253,26 @@ static int set_load(struct set *s, const char *filename)
 
 void set_init()
 {
-    struct set *set;
     FILE *fin;
-
+    struct set *set;
     char filename[MAXSTR];
-    int res;
 
     current_set = NULL;
-
     count = 0;
 
     if ((fin = fopen(config_data(SET_FILE), "r")))
     {
-        res = 1;
-        while (count < MAXSET && res)
+        while (count < MAXSET && fgets(filename, MAXSTR, fin))
         {
+            chomp(filename);
             set = &(set_v[count]);
-            res = (fgets(filename, MAXSTR, fin) != NULL);
 
-            if (res)
+            if (set_load(set, filename))
             {
-                chomp(filename);
-
-                res = set_load(set, filename);
-                if (res)
-                {
-                    set->number = count;
-                    count++;
-                }
+                set->number = count;
+                count++;
             }
         }
-
         fclose(fin);
     }
 }
@@ -331,7 +322,7 @@ static void set_load_levels(void)
     int i = 0, res;
     int nb = 1, bnb = 1;
 
-    if ((fin = fopen(current_set->file, "r")))
+    if ((fin = fopen(config_data(current_set->file), "r")))
     {
         res = 1;
 
index 91d4d84..9883b20 100644 (file)
@@ -16,7 +16,8 @@ struct set
     /* set global info */
     int number;               /* number of the set */
 
-    char file[MAXSTR];        /* set file description */
+    char file[PATHMAX];
+
     char user_scores[MAXSTR]; /* user highscore file */
     char setname[MAXSTR];     /* internal set name */
 
index aacb320..f4880bf 100644 (file)
@@ -94,10 +94,9 @@ static int set_enter(void)
 
     int id, jd, kd;
 
-
     set_init();
 
-    /* Reset last set if it do not exists */
+    /* Reset last set if it does not exist */
     if (!set_exists(last_set))
     {
         b = 0;
@@ -118,12 +117,12 @@ static int set_enter(void)
 
         if ((jd = gui_harray(id)))
         {
-            shot_id = gui_image(jd, get_set(last_set)->shot, 7 * w / 16,
-                                7 * h / 16);
+            shot_id = gui_image(jd, get_set(last_set)->shot,
+                                7 * w / 16, 7 * h / 16);
 
             if ((kd = gui_varray(jd)))
             {
-                /* Display levels */
+                /* Display sets */
                 for (i = b * SET_GROUP; i < (b + 1) * SET_GROUP && set_exists(i); i++)
                     gui_set(kd, i);
 
@@ -134,7 +133,8 @@ static int set_enter(void)
         }
 
         gui_space(id);
-        desc_id = gui_multi(id, " \\ \\ \\ \\ \\", GUI_SML, GUI_ALL, gui_yel, gui_wht);
+        desc_id = gui_multi(id, " \\ \\ \\ \\ \\", GUI_SML, GUI_ALL,
+                            gui_yel, gui_wht);
 
         gui_layout(id, 0, 0);
     }
index 4a205c6..21e546a 100644 (file)
--- a/po/lv.po
+++ b/po/lv.po
@@ -8,7 +8,7 @@ msgstr ""
 "Project-Id-Version: Neverball 1.4.1\n"
 "Report-Msgid-Bugs-To: robert.kooima@gmail.com\n"
 "POT-Creation-Date: 2006-07-16 20:04+0300\n"
-"PO-Revision-Date: 2006-07-11 15:27+0300\n"
+"PO-Revision-Date: 2006-07-16 20:08+0300\n"
 "Last-Translator: Jānis Rūcis <parasti@gmail.com>\n"
 "Language-Team: Latvian\n"
 "MIME-Version: 1.0\n"
@@ -51,14 +51,13 @@ msgid "Manual"
 msgstr "Manuālais"
 
 #: ball/level.c:130
-#, fuzzy, c-format
+#, c-format
 msgid "Error while loading level file '%s': %s\n"
-msgstr "Kļūda, ielādējot līmeņa failu '%s': "
+msgstr "Kļūda, ielādējot līmeņa failu '%s': %s\n"
 
 #: ball/level.c:131
-#, fuzzy
 msgid "Not a valid level file"
-msgstr "nederīgs līmeņa fails.\n"
+msgstr "nederīgs līmeņa fails"
 
 #: ball/level.c:209 ball/st_help.c:219 ball/st_start.c:251
 msgid "Challenge"
@@ -78,7 +77,7 @@ msgstr "Viens"
 
 #: ball/level.c:213 ball/level.c:228
 msgid "Unknown"
-msgstr ""
+msgstr "Nezināms"
 
 #: ball/level.c:223
 msgid "Aborted"
@@ -141,9 +140,9 @@ msgid "Failure to establish config directory\n"
 msgstr "Neizdevās noteikt iestatījumu katalogu\n"
 
 #: ball/main.c:323
-#, fuzzy, c-format
+#, c-format
 msgid "Replay file '%s': %s\n"
-msgstr "Ieraksta fails '%s':  %s\n"
+msgstr "Ieraksta fails '%s': %s\n"
 
 #: ball/main.c:324
 msgid "Not a replay file"
@@ -167,7 +166,7 @@ msgstr "nepareizs formāts\n"
 #: ball/set.c:175
 #, c-format
 msgid "Cannot load the set file '%s':"
-msgstr ""
+msgstr "Nav iespējams ielādēt komplekta failu '%s':"
 
 #: ball/set.c:355
 #, c-format
@@ -260,7 +259,7 @@ msgstr "Spēlētāja vārds"
 
 #: ball/st_demo.c:174 ball/st_name.c:40 putt/st_all.c:476
 msgid "Player"
-msgstr ""
+msgstr "Spēlētājs"
 
 #: ball/st_demo.c:178
 msgid "State"
@@ -524,7 +523,7 @@ msgstr "Līmeņu komplekts"
 
 #: ball/st_start.c:100
 msgid "Play this bonus level in practice mode"
-msgstr ""
+msgstr "Spēlē šo papildus līmeni treniņrežīmā"
 
 #: ball/st_start.c:103
 msgid "Play this level in practice mode"
@@ -532,7 +531,7 @@ msgstr "Spēlē šo līmeni treniņrežīmā"
 
 #: ball/st_start.c:110
 msgid "Play this bonus level in normal mode"
-msgstr "Spēlē šo papildlīmeni normālajā režīmā"
+msgstr "Spēlē šo papildus līmeni normālajā režīmā"
 
 #: ball/st_start.c:112
 msgid "Play this level in normal mode"