Version 15.218.3

This commit is contained in:
Antonio Cañas Vargas 2016-06-04 14:21:01 +02:00
parent 83288f99bc
commit 148d359b6a
7 changed files with 56 additions and 54 deletions

View File

@ -26,7 +26,6 @@
/*****************************************************************************/
#include <linux/stddef.h> // For NULL
#include <locale.h> // For setlocale
#include <stdio.h> // For fprintf
#include <stdlib.h> // For malloc and free
#include <string.h> // For string functions

View File

@ -133,13 +133,14 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.218.2 (2016-06-04)"
#define Log_PLATFORM_VERSION "SWAD 15.218.3 (2016-06-04)"
#define CSS_FILE "swad15.218.css"
#define JS_FILE "swad15.216.js"
// Number of lines (includes comments but not blank lines) has been got with the following command:
// nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1
/*
Version 15.218.3: Jun 04, 2016 Code refactoring related to setlocale. (201952 lines)
Version 15.218.2: Jun 04, 2016 Checked value returned by setlocale in all calls. (201957 lines)
Version 15.218.1: Jun 04, 2016 Change in listing of courses. (201934 lines)
Version 15.218: Jun 03, 2016 New module swad_MFU for most frequently used actions.

View File

@ -25,9 +25,9 @@
/********************************* Headers ***********************************/
/*****************************************************************************/
#include <locale.h> // For setlocale
#include <limits.h> // For INT_MAX, LONG_MAX
#include <linux/stddef.h> // For NULL
#include <locale.h> // For setlocale
#include <stdlib.h> // For exit, system, malloc, calloc, free, etc
#include <string.h> // For string functions
#include <sys/time.h> // For gettimeofday
@ -83,7 +83,12 @@ void Gbl_InitializeGlobals (void)
extern const unsigned Txt_Current_CGI_SWAD_Language;
Txt_Language_t Lan;
if (!setlocale (LC_NUMERIC,"es_ES.utf8"))
Gbl.Layout.WritingHTMLStart =
Gbl.Layout.HTMLStartWritten =
Gbl.Layout.DivsEndWritten =
Gbl.Layout.HTMLEndWritten = false;
if (!setlocale (LC_ALL,"es_ES.utf8")) // TODO: this should be internationalized!!!!!!!
exit (1);
gettimeofday (&Gbl.tvStart, &Gbl.tz);
@ -116,11 +121,6 @@ void Gbl_InitializeGlobals (void)
Gbl.Error = false;
Gbl.Layout.WritingHTMLStart =
Gbl.Layout.HTMLStartWritten =
Gbl.Layout.DivsEndWritten =
Gbl.Layout.HTMLEndWritten = false;
Gbl.DB.DatabaseIsOpen = false;
Gbl.DB.LockedTables = false;

View File

@ -867,12 +867,10 @@ float Str_GetFloatNumFromStr (const char *Str)
if (Str)
{
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
if (sscanf (Str,"%f",&Num) != 1)
Lay_ShowErrorAndExit ("Bad floating point format.");
if (!setlocale (LC_NUMERIC,"es_ES.utf8"))
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
}
else // Str == NULL
Num = 0.0;
@ -880,6 +878,29 @@ float Str_GetFloatNumFromStr (const char *Str)
return Num;
}
/*****************************************************************************/
/**** Change decimal point to US system in order to get/print it as a dot ****/
/*****************************************************************************/
void Str_SetDecimalPointToUS (void)
{
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get/print the floating point as a dot
if (Gbl.Layout.HTMLStartWritten)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
}
/*****************************************************************************/
/****************** Change decimal point to local system *********************/
/*****************************************************************************/
void Str_SetDecimalPointToLocal (void)
{
// TODO: this should be internationalized!!!!!!!
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to local system
if (Gbl.Layout.HTMLStartWritten)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
}
/*****************************************************************************/
/*************** Add a string to a Query, changing ' for &#39; ***************/
/*****************************************************************************/

View File

@ -79,6 +79,8 @@ char Str_ConvertToLowerLetter (char Ch);
void Str_WriteFloatNum (float Number);
void Str_ConvertStrFloatCommaToStrFloatPoint (char *Str);
float Str_GetFloatNumFromStr (const char *Str);
void Str_SetDecimalPointToUS (void);
void Str_SetDecimalPointToLocal (void);
void Str_AddStrToQuery (char *Query,const char *Str,size_t SizeOfQuery);
void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,

View File

@ -28,7 +28,6 @@
#include <limits.h> // For UINT_MAX
#include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL
#include <locale.h> // For setlocale, LC_NUMERIC...
#include <mysql/mysql.h> // To access MySQL databases
#include <stdbool.h> // For boolean type
#include <stdio.h> // For fprintf, etc.
@ -1172,7 +1171,7 @@ static void Tst_UpdateScoreQst (long QstCod,float ScoreThisQst,bool AnswerIsNotB
char Query[512];
/***** Update number of clicks and score of the question *****/
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To print the floating point as a dot
Str_SetDecimalPointToUS (); // To print the floating point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
if (AnswerIsNotBlank)
sprintf (Query,"UPDATE tst_questions"
@ -1184,8 +1183,7 @@ static void Tst_UpdateScoreQst (long QstCod,float ScoreThisQst,bool AnswerIsNotB
" SET NumHits=NumHits+1"
" WHERE QstCod='%ld'",
QstCod);
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
DB_QueryUPDATE (Query,"can not update the score of a question");
}
@ -2844,12 +2842,10 @@ static void Tst_ListOneOrMoreQuestionsToEdit (unsigned long NumRows,MYSQL_RES *m
Lay_ShowErrorAndExit ("Wrong number of hits not blank to a question.");
/* Get the acumulated score of the question (row[11]) */
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
if (sscanf (row[11],"%lf",&TotalScoreThisQst) != 1)
Lay_ShowErrorAndExit ("Wrong score of a question.");
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
/* Write number of times this question has been answered */
fprintf (Gbl.F.Out,"<td class=\"DAT_SMALL CENTER_TOP COLOR%u\">"
@ -5626,15 +5622,13 @@ double Tst_GetFloatAnsFromStr (char *Str)
Str_ConvertStrFloatCommaToStrFloatPoint (Str);
/***** The string is "scanned" in floating point (it must have a point, not a colon as decimal separator) *****/
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
if (sscanf (Str,"%lg",&DoubleNum) != 1) // If the string does not hold a valid floating point number...
{
DoubleNum = 0.0; // ...the number is reset to 0
Str[0] = '\0'; // ...and the string is reset to ""
}
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
return DoubleNum;
}
@ -6052,8 +6046,7 @@ static void Tst_InsertAnswersIntoDB (void)
DB_QueryINSERT (Query,"can not create answer");
break;
case Tst_ANS_FLOAT:
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To print the floating point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
Str_SetDecimalPointToUS (); // To print the floating point as a dot
for (i = 0;
i < 2;
i++)
@ -6066,8 +6059,7 @@ static void Tst_InsertAnswersIntoDB (void)
Gbl.Test.Answer.FloatingPoint[i]);
DB_QueryINSERT (Query,"can not create answer");
}
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
break;
case Tst_ANS_TRUE_FALSE:
sprintf (Query,"INSERT INTO tst_answers"
@ -6490,12 +6482,10 @@ static unsigned Tst_GetNumTstQuestions (Sco_Scope_t Scope,Tst_AnswerType_t AnsTy
if (sscanf (row[1],"%lu",&(Stats->NumHits)) != 1)
Lay_ShowErrorAndExit ("Error when getting total number of hits in test questions.");
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
if (sscanf (row[2],"%lf",&(Stats->TotalScore)) != 1)
Lay_ShowErrorAndExit ("Error when getting total score in test questions.");
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
}
else
{
@ -6948,15 +6938,13 @@ static void Tst_StoreScoreOfTestExamInDB (long TstCod,
char Query[256];
/***** Update score in test exam *****/
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To print the floating point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
Str_SetDecimalPointToUS (); // To print the floating point as a dot
sprintf (Query,"UPDATE tst_exams"
" SET NumQstsNotBlank='%u',Score='%lf'"
" WHERE TstCod='%ld'",
NumQstsNotBlank,Score,
TstCod);
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
DB_QueryUPDATE (Query,"can not update result of test exam");
}
@ -7186,8 +7174,7 @@ static void Tst_ShowResultsOfTestExams (struct UsrData *UsrDat)
NumQstsNotBlankInThisExam = 0;
/* Get score (row[5]) */
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
if (sscanf (row[5],"%lf",&ScoreInThisExam) == 1)
{
if (Gbl.Test.AllowTeachers)
@ -7195,8 +7182,7 @@ static void Tst_ShowResultsOfTestExams (struct UsrData *UsrDat)
}
else
ScoreInThisExam = 0.0;
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
/* Write number of questions */
fprintf (Gbl.F.Out,"<td class=\"%s RIGHT_TOP COLOR%u\">",
@ -7701,12 +7687,10 @@ static void Tst_GetExamDataByTstCod (long TstCod,time_t *TstTimeUTC,
*NumQstsNotBlank = 0;
/* Get score (row[5]) */
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To get the decimal point
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
Str_SetDecimalPointToUS (); // To get the decimal point as a dot
if (sscanf (row[5],"%lf",Score) != 1)
*Score = 0.0;
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
}
/***** Free structure that stores the query result *****/
@ -7729,8 +7713,7 @@ static void Tst_StoreOneExamQstInDB (long TstCod,long QstCod,unsigned NumQst,dou
Par_ReplaceSeparatorMultipleByComma (Gbl.Test.StrAnswersOneQst[NumQst],Answers);
/***** Insert question and user's answers into database *****/
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To print the floating point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
Str_SetDecimalPointToUS (); // To print the floating point as a dot
sprintf (Query,"INSERT INTO tst_exam_questions"
" (TstCod,QstCod,QstInd,Score,Indexes,Answers)"
" VALUES ('%ld','%ld','%u','%lf','%s','%s')",
@ -7739,8 +7722,7 @@ static void Tst_StoreOneExamQstInDB (long TstCod,long QstCod,unsigned NumQst,dou
Score,
Indexes,
Answers);
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
DB_QueryINSERT (Query,"can not insert a question of an exam");
}

View File

@ -94,7 +94,6 @@ cp -f /home/acanas/swad/swad/swad /var/www/cgi-bin/
#include <dirent.h> // For scandir, etc.
#include <linux/limits.h> // For PATH_MAX
#include <linux/stddef.h> // For NULL
#include <locale.h> // For setlocale, LC_NUMERIC...
#include <sys/stat.h> // For lstat
#include <string.h>
#include <stdsoap2.h>
@ -3736,8 +3735,7 @@ int swad__getTrivialQuestion (struct soap *soap,
"lowerScore or upperScore values not valid");
/***** Start query *****/
if (!setlocale (LC_NUMERIC,"en_US.utf8")) // To print the floating point as a dot
Lay_ShowAlert (Lay_ERROR,"Can not set locale to en_US.");
Str_SetDecimalPointToUS (); // To print the floating point as a dot
sprintf (Query,"SELECT DISTINCTROW tst_questions.QstCod,"
"tst_questions.AnsType,tst_questions.Shuffle,"
"tst_questions.Stem,tst_questions.Feedback,"
@ -3758,8 +3756,7 @@ int swad__getTrivialQuestion (struct soap *soap,
" ORDER BY RAND(NOW()) LIMIT 1",
DegreesStr,DegreesStr,
lowerScore,upperScore);
if (!setlocale (LC_NUMERIC,"es_ES.utf8")) // Return to spanish system (TODO: this should be internationalized!!!!!!!)
Lay_ShowAlert (Lay_ERROR,"Can not set locale to es_ES.");
Str_SetDecimalPointToLocal (); // Return to local system
NumRows = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get test questions");