77#include < linear.h>
88#include < tron.h>
99
10+ #include < linear_locales.h>
11+
1012#ifdef ENABLED_OPENMP
1113#include < omp.h>
1214#endif
1315
14-
1516typedef signed char schar;
1617template <class T > static inline void swap (T& x, T& y) { T t=x; x=y; y=t; }
1718#ifndef min
@@ -2932,12 +2933,7 @@ int save_model(const char *model_file_name, const struct model *model_)
29322933 FILE *fp = fopen (model_file_name," w" );
29332934 if (fp==NULL ) return -1 ;
29342935
2935- char *old_locale = setlocale (LC_ALL, NULL );
2936- if (old_locale)
2937- {
2938- old_locale = strdup (old_locale);
2939- }
2940- setlocale (LC_ALL, " C" );
2936+ locale_handle old_locale = set_c_locale ();
29412937
29422938 int nr_w;
29432939 if (model_->nr_class ==2 && model_->param .solver_type != MCSVM_CS)
@@ -2969,8 +2965,7 @@ int save_model(const char *model_file_name, const struct model *model_)
29692965 fprintf (fp, " \n " );
29702966 }
29712967
2972- setlocale (LC_ALL, old_locale);
2973- free (old_locale);
2968+ restore_locale (old_locale);
29742969
29752970 if (ferror (fp) != 0 || fclose (fp) != 0 ) return -1 ;
29762971 else return 0 ;
@@ -2991,21 +2986,16 @@ struct model *load_model(const char *model_file_name)
29912986
29922987 model_->label = NULL ;
29932988
2994- char *old_locale = setlocale (LC_ALL, NULL );
2995- if (old_locale)
2996- {
2997- old_locale = strdup (old_locale);
2998- }
2999- setlocale (LC_ALL, " C" );
2989+ locale_handle old_locale = set_c_locale ();
30002990
30012991 char cmd[81 ];
30022992 while (1 )
30032993 {
3004- fscanf (fp," %80s" ,cmd);
2994+ int r = fscanf (fp," %80s" ,cmd);
30052995 if (strcmp (cmd," solver_type" )==0 )
30062996 {
3007- fscanf (fp," %80s" ,cmd);
3008- int i;
2997+ int r = fscanf (fp," %80s" ,cmd);
2998+ int i ;
30092999 for (i=0 ;solver_type_table[i];i++)
30103000 {
30113001 if (strcmp (solver_type_table[i],cmd)==0 )
@@ -3018,26 +3008,25 @@ struct model *load_model(const char *model_file_name)
30183008 {
30193009 fprintf (stderr," unknown solver type.\n " );
30203010
3021- setlocale (LC_ALL, old_locale);
3011+ restore_locale ( old_locale);
30223012 free (model_->label );
30233013 free (model_);
3024- free (old_locale);
30253014 return NULL ;
30263015 }
30273016 }
30283017 else if (strcmp (cmd," nr_class" )==0 )
30293018 {
3030- fscanf (fp," %d" ,&nr_class);
3019+ int r = fscanf (fp," %d" ,&nr_class);
30313020 model_->nr_class =nr_class;
30323021 }
30333022 else if (strcmp (cmd," nr_feature" )==0 )
30343023 {
3035- fscanf (fp," %d" ,&nr_feature);
3024+ int r = fscanf (fp," %d" ,&nr_feature);
30363025 model_->nr_feature =nr_feature;
30373026 }
30383027 else if (strcmp (cmd," bias" )==0 )
30393028 {
3040- fscanf (fp," %lf" ,&bias);
3029+ int r = fscanf (fp," %lf" ,&bias);
30413030 model_->bias =bias;
30423031 }
30433032 else if (strcmp (cmd," w" )==0 )
@@ -3048,16 +3037,16 @@ struct model *load_model(const char *model_file_name)
30483037 {
30493038 int nr_class = model_->nr_class ;
30503039 model_->label = Malloc (int ,nr_class);
3051- for (int i=0 ;i<nr_class;i++)
3052- fscanf (fp," %d" ,&model_->label [i]);
3040+ for (int i=0 ;i<nr_class;i++) {
3041+ int r = fscanf (fp," %d" ,&model_->label [i]);
3042+ }
30533043 }
30543044 else
30553045 {
30563046 fprintf (stderr," unknown text in model file: [%s]\n " ,cmd);
3057- setlocale (LC_ALL, old_locale);
3047+ restore_locale ( old_locale);
30583048 free (model_->label );
30593049 free (model_);
3060- free (old_locale);
30613050 return NULL ;
30623051 }
30633052 }
@@ -3077,14 +3066,13 @@ struct model *load_model(const char *model_file_name)
30773066 model_->w =Malloc (double , w_size*nr_w);
30783067 for (i=0 ; i<w_size; i++)
30793068 {
3080- int j;
3081- for (j= 0 ; j<nr_w; j++)
3082- fscanf (fp, " %lf " , &model_-> w [i*nr_w+j]);
3083- fscanf (fp, " \n " );
3069+ for ( int j= 0 ; j<nr_w; j++) {
3070+ int r = fscanf (fp, " %lf " , &model_-> w [i*nr_w+j]);
3071+ }
3072+ int r = fscanf (fp, " \n " );
30843073 }
30853074
3086- setlocale (LC_ALL, old_locale);
3087- free (old_locale);
3075+ restore_locale (old_locale);
30883076
30893077 if (ferror (fp) != 0 || fclose (fp) != 0 ) return NULL ;
30903078
0 commit comments