From 2c2744b7632d1f75447a3aa57cb519f040f9c6a6 Mon Sep 17 00:00:00 2001 From: "Andrew V. Samoilov" Date: Tue, 5 Jun 2001 01:00:26 +0000 Subject: [PATCH] * charsets.c (load_codepages_list): Lines in mc.charset beginning with a # are comments. Use "default character_set_name" in mc.charset to set default codepage for your system. (xstrncpy): Eliminate. --- src/ChangeLog | 7 +++++++ src/charsets.c | 39 ++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 7eb45e60c..534db7654 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2001-06-04 Andrew V. Samoilov + + * charsets.c (load_codepages_list): Lines in mc.charset beginning + with a # are comments. Use "default character_set_name" in mc.charset + to set default codepage for your system. + (xstrncpy): Eliminate. + 2001-06-04 Pavel Roskin * cmd.c (edit_symlink_cmd) [!HAVE_GNOME]: Warn if the current diff --git a/src/charsets.c b/src/charsets.c index d7b83b170..a92537df8 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -17,19 +17,14 @@ uchar conv_displ[256]; uchar conv_input[256]; uchar printable[256]; -static char *xstrncpy( char *dest, const char *src, int n ) -{ - strncpy( dest, src, n ); - dest[n] = '\0'; - return dest; -} - int load_codepages_list() { int result = -1; FILE *f; char buf[256]; extern char* mc_home; + extern int display_codepage; + char * default_codepage = NULL; strcpy ( buf, mc_home ); strcat ( buf, "/mc.charsets" ); @@ -37,7 +32,7 @@ int load_codepages_list() return -1; for ( n_codepages=0; fgets( buf, sizeof buf, f ); ) - if ( buf[0] != '\n' && buf[0] != '\0' ) + if ( buf[0] != '\n' && buf[0] != '\0' && buf [0] != '#' ) ++n_codepages; rewind( f ); @@ -47,7 +42,8 @@ int load_codepages_list() /* split string into id and cpname */ char *p = buf; int buflen = strlen( buf ); - if ( *p == '\n' || *p == '\0' ) + + if ( *p == '\n' || *p == '\0' || *p == '#') continue; if ( buflen > 0 && buf[ buflen - 1 ] == '\n' ) @@ -57,18 +53,28 @@ int load_codepages_list() if ( *p == '\0' ) goto fail; - codepages[n_codepages].id = malloc( p - buf + 1 ); - xstrncpy( codepages[n_codepages].id, buf, p - buf ); + *p++ = 0; while ( *p == '\t' || *p == ' ' ) ++p; if ( *p == '\0' ) goto fail; + if (strcmp (buf, "default") == 0) { + default_codepage = strdup (p); + continue; + } + + codepages[n_codepages].id = strdup( buf ); codepages[n_codepages].name = strdup( p ); ++n_codepages; } + if (default_codepage) { + display_codepage = get_codepage_index (default_codepage); + free (default_codepage); + } + result = n_codepages; fail: fclose( f ); @@ -162,24 +168,23 @@ char* init_translation_table( int cpsource, int cpdisplay ) for (i=128; i<=255; ++i) { ch = translate_character( cd, i ); conv_input[i] = (ch == UNKNCHAR) ? i : ch; + printable[i] = 1; } iconv_close( cd ); - /* ch = (strcmp( cpdisp, "ASCII" ) == 0) ? 0 : 1; */ - for (i=128; i<=255; ++i) - printable[i] = 1; - return NULL; } void convert_to_display( char *str ) { - while ( (*str++ = conv_displ[ (uchar) *str ]) ) ; + while ((*str = conv_displ[ (uchar) *str ])) + str++; } void convert_from_input( char *str ) { - while ( (*str++ = conv_input[ (uchar) *str ]) ) ; + while ((*str = conv_input[ (uchar) *str ])) + str++; } #endif /* HAVE_CHARSET */