From 0f19db742fd6fa072e733e0202ea69051a37701f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Thu, 31 Mar 2016 19:36:30 +0200 Subject: [PATCH] Version 15.169.4 --- swad_changelog.h | 3 ++- swad_parameter.c | 53 +++++++++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index bb019d02..051dcf45 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -138,13 +138,14 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.169.3 (2016-03-31)" +#define Log_PLATFORM_VERSION "SWAD 15.169.4 (2016-03-31)" #define CSS_FILE "swad15.165.5.css" #define JS_FILE "swad15.131.3.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.169.4: Mar 31, 2016 Code refactoring in list of parameters. (197280 lines) Version 15.169.3: Mar 31, 2016 Code refactoring in list of parameters. (197271 lines) Version 15.169.2: Mar 31, 2016 Code refactoring in list of parameters. Not finished. (197298 lines) Version 15.169.1: Mar 31, 2016 Code refactoring in list of parameters. (197298 lines) diff --git a/swad_parameter.c b/swad_parameter.c index b61c8dd7..574565f7 100644 --- a/swad_parameter.c +++ b/swad_parameter.c @@ -407,51 +407,57 @@ static void Par_CreateListOfParamsFromTmpFile (void) /*****************************************************************************/ /******************** Read from file until quote '\"' ************************/ /*****************************************************************************/ -// Return true if delimiter string is found. -// File is positioned just after the last character in delimiter string +// Return true if boundary string is found. +// File is positioned just after the last character in boundary string static bool Par_ReadTmpFileUntilDelimitStr (const char *BoundaryStr,unsigned LengthBoundaryStr) { unsigned NumBytesIdentical; // Number of characters identical in each iteration of the loop - unsigned NumBytesReadButNoWritten = 0; // Number of characters read from the source file - // and not written in the destination file + unsigned NumBytesReadButNoDiscarded; // Number of characters read from the source file... + // ...and not fully discarded in search int Buffer[Par_MAX_LENGTH_BOUNDARY_WITH_CR_LF+1]; - unsigned StartIndex = 0; + unsigned StartIndex; unsigned i; + bool Found; - for (;;) + for (StartIndex = 0, + NumBytesReadButNoDiscarded = 0, + Found = false; + !Found; + StartIndex = (StartIndex + 1) % LengthBoundaryStr, + NumBytesReadButNoDiscarded--) { - if (!NumBytesReadButNoWritten) + if (!NumBytesReadButNoDiscarded) { // Read next character Buffer[StartIndex] = fgetc (Gbl.F.Tmp); if (feof (Gbl.F.Tmp)) return false; - NumBytesReadButNoWritten++; + NumBytesReadButNoDiscarded++; } if (Buffer[StartIndex] == (int) BoundaryStr[0]) // First character identical { - for (NumBytesIdentical = 1, i = (StartIndex + 1) % LengthBoundaryStr; + for (NumBytesIdentical = 1, + i = (StartIndex + 1) % LengthBoundaryStr; NumBytesIdentical < LengthBoundaryStr; - NumBytesIdentical++, i = (i + 1) % LengthBoundaryStr) + NumBytesIdentical++, + i = (i + 1) % LengthBoundaryStr) { - if (NumBytesReadButNoWritten == NumBytesIdentical) // Next character identical + if (NumBytesReadButNoDiscarded == NumBytesIdentical) // Last character is identical { Buffer[i] = fgetc (Gbl.F.Tmp); // Read next character if (feof (Gbl.F.Tmp)) return false; - NumBytesReadButNoWritten++; + NumBytesReadButNoDiscarded++; } - if (Buffer[i] != (int) BoundaryStr[NumBytesIdentical]) // Next different character + if (Buffer[i] != (int) BoundaryStr[NumBytesIdentical]) // Next character is different break; } - if (NumBytesIdentical == LengthBoundaryStr) // Str found - return true; + if (NumBytesIdentical == LengthBoundaryStr) // Boundary found + Found = true; } - NumBytesReadButNoWritten--; - StartIndex = (StartIndex + 1) % LengthBoundaryStr; } - return false; // Not reached + return true; } /*****************************************************************************/ @@ -523,10 +529,11 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName, unsigned i; struct Param *Param; char *PtrDst; - unsigned NumTimes = 0; + unsigned NumTimes; bool ParamFound = false; unsigned ParamNameLength; + /***** Default values returned *****/ ParamValue[0] = '\0'; // By default, the value of the parameter will be an empty string /***** Only some selected parameters can be passed by GET method *****/ @@ -534,15 +541,16 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName, if (!Par_CheckIsParamCanBeUsedInGETMethod (ParamName)) return 0; // Return no-parameters-found + /***** Initializations *****/ ParamNameLength = strlen (ParamName); - PtrDst = ParamValue; + /***** For multiple parameters, loop for any ocurrence of the parameter + For unique parameter, find only the first ocurrence *****/ for (Param = Gbl.Params.List, NumTimes = 0; Param != NULL && - (NumTimes < 1 || ParamType == Par_PARAM_MULTIPLE); + (ParamType == Par_PARAM_MULTIPLE || NumTimes < 1); NumTimes++) - { /***** Find next ocurrence of parameter in list of parameters *****/ for (ParamFound = false; Param != NULL && !ParamFound; @@ -618,7 +626,6 @@ unsigned Par_GetParameter (tParamType ParamType,const char *ParamName, } } } - } *PtrDst = '\0'; // Add the final NULL