Ticket #10: issue10_with_ifdef.patch

File issue10_with_ifdef.patch, 8.4 KB (added by miniupnp, 8 years ago)

This patch is using #ifdef to enable iconv only when applicable (linux/FreeBSD/etc.)

  • main.c

     
    469469  getcwd(Main_selector.Directory,MAX_PATH_CHARACTERS);
    470470#endif
    471471
     472#ifdef ENABLE_FILENAMES_ICONV
     473  // Initialisation de iconv
     474  // utilisé pour convertir les noms de fichiers
     475  cd = iconv_open(TOCODE, FROMCODE);  // From UTF8 to ANSI
     476  cd_inv = iconv_open(FROMCODE, TOCODE);  // From ANSI to UTF8
     477#endif /* ENABLE_FILENAMES_ICONV */
     478
    472479  // On en profite pour le mémoriser dans le répertoire principal:
    473480  strcpy(Initial_directory,Main_selector.Directory);
    474481
  • filesel.c

     
    230230  int         c;
    231231  int         other_cursor;
    232232  int         pos_last_dot;
     233#ifdef ENABLE_FILENAMES_ICONV
     234  /* convert file name from UTF8 to ANSI */
     235  char        converted_fname[MAX_PATH_CHARACTERS];
     236  {
     237    char * input = (char *)fname;
     238    size_t inbytesleft = strlen(fname);
     239    char * output = converted_fname;
     240    size_t outbytesleft = sizeof(converted_fname)-1;
     241    if(cd != (iconv_t)-1 && (ssize_t)iconv(cd, &input, &inbytesleft, &output, &outbytesleft) >= 0)
     242    {
     243      *output = '\0';
     244      fname = converted_fname;
     245    }
     246  }
     247#endif /* ENABLE_FILENAMES_ICONV */
    233248
    234249  // safety
    235250  if (max_length>40)
     
    10641079// Affiche Selector->Directory sur 37 caractères
    10651080//
    10661081{
     1082  char converted_name[MAX_PATH_CHARACTERS];
    10671083  char temp_name[MAX_DISPLAYABLE_PATH+1]; // Nom tronqué
    10681084  int  length; // length du répertoire courant
    10691085  int  index;   // index de parcours de la chaine complète
    10701086
     1087  strncpy(converted_name,Selector->Directory,sizeof(converted_name));
     1088  converted_name[sizeof(converted_name)-1] = '\0';
     1089#ifdef ENABLE_FILENAMES_ICONV
     1090  {
     1091    /* convert file name from UTF8 to ANSI */
     1092    char * input = Selector->Directory;
     1093    size_t inbytesleft = strlen(input);
     1094    char * output = converted_name;
     1095    size_t outbytesleft = sizeof(converted_name)-1;
     1096    if(cd != (iconv_t)-1 && (ssize_t)iconv(cd, &input, &inbytesleft, &output, &outbytesleft) >= 0)
     1097      *output = '\0';
     1098  }
     1099#endif /* ENABLE_FILENAMES_ICONV */
     1100
    10711101  Window_rectangle(10,84,37*8,8,MC_Light);
    10721102
    1073   length=strlen(Selector->Directory);
     1103  length=strlen(converted_name);
    10741104  if (length>MAX_DISPLAYABLE_PATH)
    10751105  { // Doh! il va falloir tronquer le répertoire (bouh !)
    10761106
    10771107    // On commence par copier bêtement les 3 premiers caractères (e.g. "C:\")
    10781108    for (index=0;index<3;index++)
    1079       temp_name[index]=Selector->Directory[index];
     1109      temp_name[index]=converted_name[index];
    10801110
    10811111    // On y rajoute 3 petits points:
    10821112    strcpy(temp_name+3,"...");
     
    10841114    //  Ensuite, on cherche un endroit à partir duquel on pourrait loger tout
    10851115    // le reste de la chaine (Ouaaaaaah!!! Vachement fort le mec!!)
    10861116    for (index++;index<length;index++)
    1087       if ( (Selector->Directory[index]==PATH_SEPARATOR[0]) &&
     1117      if ( (converted_name[index]==PATH_SEPARATOR[0]) &&
    10881118           (length-index<=MAX_DISPLAYABLE_PATH-6) )
    10891119      {
    10901120        // Ouf: on vient de trouver un endroit dans la chaîne à partir duquel
    10911121        // on peut faire la copie:
    1092         strcpy(temp_name+6,Selector->Directory+index);
     1122        strcpy(temp_name+6,converted_name+index);
    10931123        break;
    10941124      }
    10951125
     
    10971127    Print_in_window(10,84,temp_name,MC_Black,MC_Light);
    10981128  }
    10991129  else // Ahhh! La chaîne peut loger tranquillement dans la fenêtre
    1100     Print_in_window(10,84,Selector->Directory,MC_Black,MC_Light);
     1130    Print_in_window(10,84,converted_name,MC_Black,MC_Light);
    11011131   
    11021132  Update_window_area(10,84,37*8,8);
    11031133}
     
    11071137//
    11081138void Print_filename_in_fileselector(void)
    11091139{
     1140  char filename[32];
     1141  strncpy(filename, Selector_filename, sizeof(filename));
     1142#ifdef ENABLE_FILENAMES_ICONV
     1143  {
     1144    char * input = (char *)Selector_filename;
     1145    size_t inbytesleft = strlen(Selector_filename);
     1146    char * output = filename;
     1147    size_t outbytesleft = sizeof(filename)-1;
     1148    if(cd != (iconv_t)-1 && (ssize_t)iconv(cd, &input, &inbytesleft, &output, &outbytesleft) >= 0)
     1149      *output = '\0';
     1150  }
     1151#endif /* ENABLE_FILENAMES_ICONV */
    11101152  Window_rectangle(82,48,27*8,8,MC_Light);
    1111   Print_in_window_limited(82,48,Selector_filename,27,MC_Black,MC_Light);
     1153  Print_in_window_limited(82,48,filename,27,MC_Black,MC_Light);
    11121154  Update_window_area(82,48,27*8,8);
    11131155}
    11141156
     
    17341776            // current name is a highlighted directory
    17351777            Selector_filename[0]='\0';
    17361778        }
    1737         if (Readline(82,48,Selector_filename,27,INPUT_TYPE_FILENAME))
     1779        char filename_ansi[256];
     1780        strncpy(filename_ansi, Selector_filename, sizeof(filename_ansi));
     1781#ifdef ENABLE_FILENAMES_ICONV
     1782        { /* convert from UTF8 to ANSI */
     1783          char * input = (char *)Selector_filename;
     1784          size_t inbytesleft = strlen(input);
     1785          char * output = filename_ansi;
     1786          size_t outbytesleft = sizeof(filename_ansi)-1;
     1787          if(cd != (iconv_t)-1 && (ssize_t)iconv(cd, &input, &inbytesleft, &output, &outbytesleft) >= 0)
     1788            *output = '\0';
     1789        }
     1790#endif /* ENABLE_FILENAMES_ICONV */
     1791        if (Readline(82,48,filename_ansi,27,INPUT_TYPE_FILENAME))
    17381792        {
     1793#ifdef ENABLE_FILENAMES_ICONV
     1794          /* convert back from ANSI to UTF8 */
     1795          char * input = (char *)filename_ansi;
     1796          size_t inbytesleft = strlen(input);
     1797          char * output = Selector_filename;
     1798          size_t outbytesleft = sizeof(Selector_filename)-1;
     1799          if(cd_inv != (iconv_t)-1 && (ssize_t)iconv(cd_inv, &input, &inbytesleft, &output, &outbytesleft) >= 0)
     1800            *output = '\0';
     1801          else
     1802#endif /* ENABLE_FILENAMES_ICONV */
     1803            strncpy(Selector_filename, filename_ansi, sizeof(Selector_filename));
     1804
    17391805          //   On regarde s'il faut rajouter une extension. C'est-à-dire s'il
    17401806          // n'y a pas de '.' dans le nom du fichier.
    17411807          for(temp=0,dummy=0; ((Selector_filename[temp]) && (!dummy)); temp++)
  • text.c

     
    335335       #ifdef USE_FC
    336336       {
    337337        FcStrList* dirs;
     338        FcChar8 * fdir;
    338339        dirs = FcConfigGetFontDirs(NULL);
    339         char* fdir = FcStrListNext(dirs);
     340        fdir = FcStrListNext(dirs);
    340341        while(fdir != NULL)
    341342        {
    342             For_each_file(fdir,Add_font);
     343            For_each_file((char *)fdir,Add_font);
    343344            fdir = FcStrListNext(dirs);
    344345        }
    345346
  • windows.c

     
    799799  // Determine maximum size, in characters
    800800  max_size = 12 + (Screen_width / Menu_factor_X - 320) / 8;
    801801 
    802   string_size = strlen(Main_backups->Pages->Filename);
    803  
    804802  // Partial copy of the name
    805   strncpy(display_string, Main_backups->Pages->Filename, max_size);
     803  {
     804#ifdef ENABLE_FILENAMES_ICONV
     805    char * input = Main_backups->Pages->Filename;
     806    size_t inbytesleft = strlen(input);
     807    char * output = display_string;
     808    size_t outbytesleft = sizeof(display_string)-1;
     809    if(cd != (iconv_t)-1 && (ssize_t)iconv(cd, &input, &inbytesleft, &output, &outbytesleft) >= 0)
     810      *output = '\0';
     811    else
     812#endif /* ENABLE_FILENAMES_ICONV */
     813    {
     814      strncpy(display_string, Main_backups->Pages->Filename, sizeof(display_string)-1);
     815      display_string[sizeof(display_string)-1] = '\0';
     816    }
     817  }
     818  string_size = strlen(display_string);
    806819  display_string[max_size]='\0';
    807820
    808821  if (string_size > max_size)
  • Makefile

     
    364364        CC = gcc
    365365        OBJDIR = ../obj/unix
    366366        FCLOPT = -lfontconfig
     367        # enable UTF8 filename translation
     368        COPT += -DENABLE_FILENAMES_ICONV
    367369      endif
    368370      endif
    369371      endif
  • global.h

     
    854854/// Current line number when reading/writing gfx2.ini
    855855GFX2_GLOBAL int Line_number_in_INI_file;
    856856
     857// -- For iconv
     858
     859#ifdef ENABLE_FILENAMES_ICONV
     860#define TOCODE   "CP1252"
     861#define FROMCODE "UTF-8"
     862GFX2_GLOBAL iconv_t cd;
     863GFX2_GLOBAL iconv_t cd_inv;
     864#endif /* ENABLE_FILENAMES_ICONV */
     865
    857866// -- Specific to SDL
    858867
    859868/// Pointer to the program's screen.