Re: Double // in codepages list error



>  Hi, David!
>  
>  > Here's the quick fix using concat_dir_and_file.
>  
>  The problem is not in the error message.  concat_dir_and_file() should be
>  used in load_codepages_list() (it is not used) and the message should be
>  there, because only that function knows what happened, what file it
>  _actually_ tried to open and whether the problem is worth user's
>  attention.

I agree. I did this patch too, but I thought it might not be a good idea to
send it.

>  
>  I understand that my criticism really should be directed at Walery, but
>  I'm asking everybody to clean up the code being modified instead of
piling
>  one "quick fix" onto another.
>  
>  I'm not applying your patch - it cures the symptoms, not the disease.
>  
>  By the way, if you _have_ to introduce a new translatable message please
>  avoid that british "Can't" - write "Cannot" instead.
>  

The line was there before. It wasn't me: Don't blame me.
What about en_GB.po? Once someone complained in the list about it.

...and what about OK and Ok? How do "you" spell it?
(I'm actually Australian but I've lived in Spain since I was 4 :)
English humor, you know!

You made no changes in setup.c so the original message and the "//" 
stay there. Is this the final solution?

Keep in mind when changing charsets.c that the load_codepages_list() has two
"return" (...) and that the message is now displayed both when the file is
missing and when there are no codepages (<= 0).

Just in case it's of any use here's the second patch I made. Someone could
argue not to place GUI in charsets.c and this was the second reason no to
post it yesterday.

*8-) David





_______________________________________________________
¡Tienes cuentas de e-mail GRATIS en Excite España!
A tu disposición en http://correo.excite.es 
diff -upr mc-4.5.54a-proski/src/ChangeLog mc-4.5.54a/src/ChangeLog
--- mc-4.5.54a-proski/src/ChangeLog	Wed Aug  8 04:19:14 2001
+++ mc-4.5.54a/src/ChangeLog	Sat Aug 11 19:20:55 2001
@@ -1,3 +1,12 @@
+2001-08-11  David Martin  <dmartina excite es>
+
+	* charsets.c (load_codepages_list): Add error message when 
+	charsets index file is missing or has no valid entries. Invert
+	'if' clause to have a single exit (return) point.
+	
+	* setup.c (load_setup): Remove error message when
+	load_codepages_list() fails.
+
 2001-08-07  Pavel Roskin  <proski gnu org>
 
 	* view.c: Warning fixes. Include "cmd.h". Rename help_cmd()
diff -upr mc-4.5.54a-proski/src/charsets.c mc-4.5.54a/src/charsets.c
--- mc-4.5.54a-proski/src/charsets.c	Wed Aug  1 02:58:06 2001
+++ mc-4.5.54a/src/charsets.c	Sat Aug 11 18:56:39 2001
@@ -21,63 +21,68 @@ int load_codepages_list(void)
 {
     int result = -1;
     FILE *f;
+    char *fname;
     char buf[256];
     extern char* mc_home;
     extern int display_codepage;
     char * default_codepage = NULL;
 
-    strcpy ( buf, mc_home );
-    strcat ( buf, "/" CHARSETS_INDEX );
-    if ( !( f = fopen( buf, "r" ) ) )
-	return -1;
+    fname = concat_dir_and_file ( mc_home, CHARSETS_INDEX );
+    if ( ( f = fopen( fname, "r" ) ) ) {
 
-    for ( n_codepages=0; fgets( buf, sizeof buf, f ); )
-	if ( buf[0] != '\n' && buf[0] != '\0' && buf [0] != '#' )
-	    ++n_codepages;
-    rewind( f );
+	for ( n_codepages=0; fgets( buf, sizeof buf, f ); )
+	    if ( buf[0] != '\n' && buf[0] != '\0' && buf [0] != '#' )
+		++n_codepages;
+	rewind( f );
+
+	codepages = calloc( n_codepages + 1, sizeof(struct codepage_desc) );
+
+	for( n_codepages = 0; fgets( buf, sizeof buf, f ); ) {
+	    /* split string into id and cpname */
+	    char *p = buf;
+	    int buflen = strlen( buf );
+
+	    if ( *p == '\n' || *p == '\0' || *p == '#')
+		continue;
+
+	    if ( buflen > 0 && buf[ buflen - 1 ] == '\n' )
+		buf[ buflen - 1 ] = '\0';
+	    while ( *p != '\t' && *p != ' ' && *p != '\0' )
+		++p;
+	    if ( *p == '\0' )
+		goto fail;
+
+	    *p++ = 0;
+
+	    while ( *p == '\t' || *p == ' ' )
+		++p;
+	    if ( *p == '\0' )
+		goto fail;
+
+	    if (strcmp (buf, "default") == 0) {
+		default_codepage = strdup (p);
+		continue;
+	    }
 
-    codepages = calloc( n_codepages + 1, sizeof(struct codepage_desc) );
+	    codepages[n_codepages].id = strdup( buf  );
+	    codepages[n_codepages].name = strdup( p );
+	    ++n_codepages;
+	}
 
-    for( n_codepages = 0; fgets( buf, sizeof buf, f ); ) {
-	/* split string into id and cpname */
-	char *p = buf;
-	int buflen = strlen( buf );
-
-	if ( *p == '\n' || *p == '\0' || *p == '#')
-	    continue;
-
-	if ( buflen > 0 && buf[ buflen - 1 ] == '\n' )
-	    buf[ buflen - 1 ] = '\0';
-	while ( *p != '\t' && *p != ' ' && *p != '\0' )
-	    ++p;
-	if ( *p == '\0' )
-	    goto fail;
-
-	*p++ = 0;
-
-	while ( *p == '\t' || *p == ' ' )
-	    ++p;
-	if ( *p == '\0' )
-	    goto fail;
-
-	if (strcmp (buf, "default") == 0) {
-	    default_codepage = strdup (p);
-	    continue;
+	if (default_codepage) {
+	    display_codepage = get_codepage_index (default_codepage);
+	    free (default_codepage);
 	}
 
-	codepages[n_codepages].id = strdup( buf  );
-	codepages[n_codepages].name = strdup( p );
-	++n_codepages;
+	result = n_codepages;
+fail:
+	fclose( f );
     }
 
-    if (default_codepage) {
-	display_codepage = get_codepage_index (default_codepage);
-	free (default_codepage);
-    }
+    if ( result <= 0 )
+        message( 1, MSG_ERROR, _("Can't load %s"), fname );
 
-    result = n_codepages;
-fail:
-    fclose( f );
+    g_free ( fname );
     return result;
 }
 
diff -upr mc-4.5.54a-proski/src/setup.c mc-4.5.54a/src/setup.c
--- mc-4.5.54a-proski/src/setup.c	Tue Jul 24 02:22:05 2001
+++ mc-4.5.54a/src/setup.c	Sat Aug 11 19:07:25 2001
@@ -650,9 +650,7 @@ load_setup (void)
 #endif
 
 #ifdef HAVE_CHARSET
-    if ( load_codepages_list() <= 0 ) {
-	message( 1, MSG_ERROR, _("Can't load %s/%s"), mc_home, CHARSETS_INDEX );
-    } else {
+    if ( load_codepages_list() > 0 ) {
 	char cpname[128];
 	load_string( "Misc", "display_codepage", "",
 		     cpname, sizeof(cpname) );


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]