Version 15.171

This commit is contained in:
Antonio Cañas Vargas 2016-04-01 03:09:45 +02:00
parent 0f315d2f6f
commit 8242ade95f
6 changed files with 56 additions and 109 deletions

View File

@ -138,13 +138,14 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.170 (2016-04-01)"
#define Log_PLATFORM_VERSION "SWAD 15.171 (2016-04-01)"
#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.171: Apr 01, 2016 Code refactoring in function to get a parameter. (197259 lines)
Version 15.170: Apr 01, 2016 Code refactoring in function to receive file. (197310 lines)
Version 15.169.6: Mar 31, 2016 Code refactoring in function to get a parameter. (197313 lines)
Version 15.169.5: Mar 31, 2016 Code refactoring in function to get a parameter. (197292 lines)

View File

@ -165,21 +165,6 @@ bool Fil_ReadStdinIntoTmpFile (void)
}
rewind (Gbl.F.Tmp);
/*
FILE *FileTgt;
***** Open destination file *****
if ((FileTgt = fopen ("/tmp/borrame.txt","wb")) == NULL)
Lay_ShowErrorAndExit ("Can not open target file.");
***** Copy source file into destination file *****
Fil_FastCopyOfOpenFiles (Gbl.F.Tmp,FileTgt);
***** Close the files *****
rewind (Gbl.F.Tmp);
fclose (FileTgt);
*/
return true;
}

View File

@ -63,7 +63,6 @@ static void Par_GetBoundary (void);
static void Par_CreateListOfParamsFromQueryString (void);
static void Par_CreateListOfParamsFromTmpFile (void);
static bool Par_ReadTmpFileUntilDelimitStr (const char *BoundaryStr,unsigned LengthBoundaryStr);
static int Par_ReadTmpFileUntilQuote (void);
static int Par_ReadTmpFileUntilReturn (void);
@ -305,8 +304,11 @@ static void Par_CreateListOfParamsFromTmpFile (void)
/***** Go over the file
getting start positions and lengths of parameters *****/
if (Par_ReadTmpFileUntilDelimitStr (Gbl.Boundary.StrWithoutCRLF,
Gbl.Boundary.LengthWithoutCRLF)) // Delimiter string found
if (Str_ReadFileUntilBoundaryStr (Gbl.F.Tmp,NULL,
Gbl.Boundary.StrWithoutCRLF,
Gbl.Boundary.LengthWithoutCRLF,
Fil_MAX_FILE_SIZE) == 1) // Delimiter string found
for (CurPos = 0;
CurPos < Gbl.Params.ContentLength;
)
@ -392,8 +394,10 @@ static void Par_CreateListOfParamsFromTmpFile (void)
/***** Get parameter value or file content *****/
CurPos = (unsigned long) ftell (Gbl.F.Tmp); // At start of value or file content
if (!Par_ReadTmpFileUntilDelimitStr (Gbl.Boundary.StrWithCRLF,
Gbl.Boundary.LengthWithCRLF)) break; // Delimiter string not found
if (Str_ReadFileUntilBoundaryStr (Gbl.F.Tmp,NULL,
Gbl.Boundary.StrWithCRLF,
Gbl.Boundary.LengthWithCRLF,
Fil_MAX_FILE_SIZE) != 1) break; // Boundary string not found
// Delimiter string found
Param->Value.Start = CurPos;
@ -404,62 +408,6 @@ static void Par_CreateListOfParamsFromTmpFile (void)
}
}
/*****************************************************************************/
/******************** Read from file until quote '\"' ************************/
/*****************************************************************************/
// 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 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;
unsigned i;
bool Found;
for (StartIndex = 0,
NumBytesReadButNoDiscarded = 0,
Found = false;
!Found;
StartIndex = (StartIndex + 1) % LengthBoundaryStr,
NumBytesReadButNoDiscarded--)
{
if (!NumBytesReadButNoDiscarded)
{ // Read next character
Buffer[StartIndex] = fgetc (Gbl.F.Tmp);
if (feof (Gbl.F.Tmp))
return false;
NumBytesReadButNoDiscarded++;
}
if (Buffer[StartIndex] == (int) BoundaryStr[0]) // First character identical
{
for (NumBytesIdentical = 1,
i = (StartIndex + 1) % LengthBoundaryStr;
NumBytesIdentical < LengthBoundaryStr;
NumBytesIdentical++,
i = (i + 1) % LengthBoundaryStr)
{
if (NumBytesReadButNoDiscarded == NumBytesIdentical) // Last character is identical
{
Buffer[i] = fgetc (Gbl.F.Tmp); // Read next character
if (feof (Gbl.F.Tmp))
return false;
NumBytesReadButNoDiscarded++;
}
if (Buffer[i] != (int) BoundaryStr[NumBytesIdentical]) // Next character is different
break;
}
if (NumBytesIdentical == LengthBoundaryStr) // Boundary found
Found = true;
}
}
return true;
}
/*****************************************************************************/
/******************** Read from file until quote '\"' ************************/
/*****************************************************************************/

View File

@ -2495,38 +2495,46 @@ void Str_FilePrintStrChangingBRToRetAndNBSPToSpace (FILE *FileTgt,const char *St
/*
Search in the file FileSrc the string StrDelimit.
Write in the file FileTgt and/or StrDst the characters read from FileSrc, not including StrDelimit!.
FileTgt and StrDst can be NULL if you don't want to use them.
StrDst can be NULL if you don't want to use them.
If StrDelimit is found, return 1.
If what is read exceed MaxLength, abort and return 0.
If StrDelimit is not found, return -1.
*/
#define MAX_LENGTH_STR_DELIMIT 100
#define MAX_LENGTH_BOUNDARY_STR 100
int Str_ReceiveFileUntilDelimitStr (FILE *FileSrc, FILE *FileTgt, char *StrDst, const char *StrDelimit, unsigned long long MaxLength)
int Str_ReadFileUntilBoundaryStr (FILE *FileSrc,char *StrDst,
const char *BoundaryStr,
unsigned LengthBoundaryStr,
unsigned long long MaxLength)
{
int NumBytesIdentical, // Number of characters identical in each iteration of the loop
NumBytesReadButNoWritten = 0, // Number of characters read from the source file
// and not written in the destination file
LengthStrDelimit = strlen (StrDelimit);
int Buffer[MAX_LENGTH_STR_DELIMIT+1];
unsigned long long LengthDst = 0;
int StartIndex = 0, i;
unsigned NumBytesIdentical; // Number of characters identical in each iteration of the loop
unsigned NumBytesReadButNotDiscarded; // Number of characters read from the source file...
// ...and not fully discarded in search
int Buffer[MAX_LENGTH_BOUNDARY_STR+1];
unsigned StartIndex;
unsigned i;
char *Ptr; // Pointer used to go through StrDst writing characters
unsigned long long LengthDst;
if (!LengthStrDelimit)
/***** Checkings on boundary string *****/
if (!LengthBoundaryStr)
{
if (StrDst != NULL)
*StrDst = '\0';
return 1;
}
if (strlen (StrDelimit) > MAX_LENGTH_STR_DELIMIT)
if (LengthBoundaryStr > MAX_LENGTH_BOUNDARY_STR)
Lay_ShowErrorAndExit ("Delimiter string too large.");
Ptr = StrDst;
StartIndex = 0;
NumBytesReadButNotDiscarded = 0;
LengthDst = 0;
for (;;)
{
if (!NumBytesReadButNoWritten)
if (!NumBytesReadButNotDiscarded)
{ // Read next character
Buffer[StartIndex] = fgetc (FileSrc);
if (feof (FileSrc))
@ -2535,15 +2543,16 @@ int Str_ReceiveFileUntilDelimitStr (FILE *FileSrc, FILE *FileTgt, char *StrDst,
*Ptr = '\0';
return -1;
}
NumBytesReadButNoWritten++;
NumBytesReadButNotDiscarded++;
}
if (Buffer[StartIndex] == (int) StrDelimit[0]) // First character identical
if (Buffer[StartIndex] == (int) BoundaryStr[0]) // First character identical
{
for (NumBytesIdentical = 1, i = (StartIndex + 1) % LengthStrDelimit;
NumBytesIdentical < LengthStrDelimit;
NumBytesIdentical++, i = (i + 1) % LengthStrDelimit)
for (NumBytesIdentical = 1, i = (StartIndex + 1) % LengthBoundaryStr;
NumBytesIdentical < LengthBoundaryStr;
NumBytesIdentical++, i = (i + 1) % LengthBoundaryStr)
{
if (NumBytesReadButNoWritten == NumBytesIdentical) // Next character identical
if (NumBytesReadButNotDiscarded == NumBytesIdentical) // Last character is identical
{
Buffer[i] = fgetc (FileSrc); // Read next character
if (feof (FileSrc))
@ -2552,31 +2561,32 @@ int Str_ReceiveFileUntilDelimitStr (FILE *FileSrc, FILE *FileTgt, char *StrDst,
*Ptr = '\0';
return -1;
}
NumBytesReadButNoWritten++;
NumBytesReadButNotDiscarded++;
}
if (Buffer[i] != (int) StrDelimit[NumBytesIdentical]) // Next different character
if (Buffer[i] != (int) BoundaryStr[NumBytesIdentical]) // Next character is different
break;
}
if (NumBytesIdentical == LengthStrDelimit) // Str found
if (NumBytesIdentical == LengthBoundaryStr) // Boundary found
{
if (StrDst != NULL)
*Ptr = '\0';
return 1;
}
}
if (LengthDst == MaxLength)
{
if (StrDst != NULL)
*Ptr = '\0';
return 0;
}
if (FileTgt != NULL)
fputc (Buffer[StartIndex],FileTgt); // Add the first character to the destination file
if (StrDst != NULL)
*Ptr++ = (char) Buffer[StartIndex];
StartIndex = (StartIndex + 1) % LengthBoundaryStr;
NumBytesReadButNotDiscarded--;
LengthDst++;
NumBytesReadButNoWritten--;
StartIndex = (StartIndex+1) % LengthStrDelimit;
}
return 0; // Not reached

View File

@ -108,8 +108,10 @@ bool Str_FileIsHTML (const char *FileName);
bool Str_Path1BeginsByPath2 (const char *Path1,const char *Path2);
void Str_SkipSpacesInFile (FILE *FileSrc);
void Str_FilePrintStrChangingBRToRetAndNBSPToSpace (FILE *FileTgt,const char *Str);
int Str_ReceiveFileUntilDelimitStr (FILE *FileSrc, FILE *FileTgt, char *StrDst, const char *StrDelimit, unsigned long long MaxLength);
int Str_SkipFileUntilDelimitStr (FILE *FileSrc, const char *StrDelimit);
int Str_ReadFileUntilBoundaryStr (FILE *FileSrc,char *StrDst,
const char *BoundaryStr,
unsigned LengthBoundaryStr,
unsigned long long MaxLength);
bool Str_ConvertFilFolLnkNameToValid (char *FileName);
void Str_ConvertToValidFileName (char *Str);
void Str_WriteSizeInBytesBrief (double SizeInBytes);

View File

@ -399,8 +399,9 @@ static void Syl_LoadToMemory (void)
LstItemsSyllabus.Lst[NumItem].CodItem[N] = CodItem[N];
/* Get the text of the item */
Result = Str_ReceiveFileUntilDelimitStr (Gbl.F.XML, NULL, LstItemsSyllabus.Lst[NumItem].Text,"</item>",
(unsigned long long) Syl_MAX_BYTES_TEXT_ITEM);
Result = Str_ReadFileUntilBoundaryStr (Gbl.F.XML,LstItemsSyllabus.Lst[NumItem].Text,
"</item>",strlen ("</item>"),
(unsigned long long) Syl_MAX_BYTES_TEXT_ITEM);
if (Result == 0) // Str too long
{
if (!Str_FindStrInFile (Gbl.F.XML,"</item>",Str_NO_SKIP_HTML_COMMENTS)) // End the search
@ -459,8 +460,8 @@ int Syl_ReadLevelItemSyllabus (void)
if (!Str_FindStrInFile (Gbl.F.XML,"nivel=\"",Str_NO_SKIP_HTML_COMMENTS))
Lay_ShowErrorAndExit ("Wrong syllabus format.");
if (Str_ReceiveFileUntilDelimitStr (Gbl.F.XML,NULL,StrlLevel,"\"",
(unsigned long long) (11+1)) != 1)
if (Str_ReadFileUntilBoundaryStr (Gbl.F.XML,StrlLevel,"\"",1,
(unsigned long long) (11+1)) != 1)
Lay_ShowErrorAndExit ("Wrong syllabus format.");
if (sscanf (StrlLevel,"%d",&Level) != 1)
Lay_ShowErrorAndExit ("Wrong syllabus format.");