swad-core/swad_HTML.c

1882 lines
42 KiB
C
Raw Normal View History

2019-10-23 19:05:05 +02:00
// swad_HTML.c: tables, divs
2017-06-11 20:09:59 +02:00
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
2021-02-09 12:43:45 +01:00
Copyright (C) 1999-2021 Antonio Ca<EFBFBD>as Vargas
2017-06-11 20:09:59 +02:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
2019-10-04 01:35:40 +02:00
#define _GNU_SOURCE // For vasprintf
#include <stdarg.h> // For va_start, va_end
2019-12-30 22:32:06 +01:00
#include <stdio.h> // For vasprintf
2019-10-04 15:19:36 +02:00
#include <stdlib.h> // For free
2017-06-11 20:09:59 +02:00
#include "swad_error.h"
2017-06-11 20:09:59 +02:00
#include "swad_global.h"
2019-10-23 19:05:05 +02:00
#include "swad_HTML.h"
2017-06-11 20:09:59 +02:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
2019-10-13 18:19:26 +02:00
/*****************************************************************************/
/***************************** Private vatiables *****************************/
/*****************************************************************************/
2019-11-07 10:24:00 +01:00
static unsigned HTM_TABLE_NestingLevel = 0;
static unsigned HTM_TR_NestingLevel = 0;
static unsigned HTM_TH_NestingLevel = 0;
static unsigned HTM_TD_NestingLevel = 0;
static unsigned HTM_DIV_NestingLevel = 0;
static unsigned HTM_SPAN_NestingLevel = 0;
2019-11-11 00:15:44 +01:00
static unsigned HTM_OL_NestingLevel = 0;
2019-11-07 10:24:00 +01:00
static unsigned HTM_UL_NestingLevel = 0;
static unsigned HTM_LI_NestingLevel = 0;
2019-11-09 20:04:35 +01:00
static unsigned HTM_DL_NestingLevel = 0;
static unsigned HTM_DT_NestingLevel = 0;
static unsigned HTM_DD_NestingLevel = 0;
2019-11-07 10:24:00 +01:00
static unsigned HTM_A_NestingLevel = 0;
static unsigned HTM_SCRIPT_NestingLevel = 0;
static unsigned HTM_LABEL_NestingLevel = 0;
2019-11-09 20:15:38 +01:00
static unsigned HTM_BUTTON_NestingLevel = 0;
2019-10-31 17:42:05 +01:00
static unsigned HTM_TEXTAREA_NestingLevel = 0;
2019-11-07 10:24:00 +01:00
static unsigned HTM_SELECT_NestingLevel = 0;
2019-11-09 20:31:17 +01:00
static unsigned HTM_OPTGROUP_NestingLevel = 0;
2019-11-11 00:15:44 +01:00
static unsigned HTM_STRONG_NestingLevel = 0;
static unsigned HTM_EM_NestingLevel = 0;
2019-11-10 16:41:47 +01:00
static unsigned HTM_U_NestingLevel = 0;
2019-10-13 18:19:26 +02:00
2017-06-11 20:09:59 +02:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
2019-10-23 19:05:05 +02:00
static void HTM_TABLE_BeginWithoutAttr (void);
2019-10-13 22:13:17 +02:00
2020-03-04 15:37:05 +01:00
static void HTM_TBODY_BeginWithoutAttr (void);
2019-10-23 19:05:05 +02:00
static void HTM_TR_BeginWithoutAttr (void);
2019-10-12 19:10:32 +02:00
2019-10-23 19:05:05 +02:00
static void HTM_TH_BeginWithoutAttr (void);
static void HTM_TH_BeginAttr (const char *fmt,...);
2019-10-13 22:13:17 +02:00
2019-10-23 19:05:05 +02:00
static void HTM_TD_BeginWithoutAttr (void);
2019-10-10 23:14:13 +02:00
2019-10-23 21:37:01 +02:00
static void HTM_DIV_BeginWithoutAttr (void);
2019-11-07 10:24:00 +01:00
static void HTM_SPAN_BeginWithoutAttr (void);
2019-10-26 12:25:27 +02:00
static void HTM_UL_BeginWithoutAttr (void);
2019-10-26 22:49:13 +02:00
static void HTM_LI_BeginWithoutAttr (void);
2019-10-26 12:25:27 +02:00
2019-10-28 13:56:04 +01:00
static void HTM_A_BeginWithoutAttr (void);
2019-11-02 12:59:31 +01:00
static void HTM_LABEL_BeginWithoutAttr (void);
2019-10-31 17:42:05 +01:00
static void HTM_TEXTAREA_BeginWithoutAttr (void);
2019-11-05 08:46:38 +01:00
static void HTM_SELECT_BeginWithoutAttr (void);
2019-12-13 23:38:29 +01:00
static void HTM_SPTxt (const char *Txt);
2017-06-11 20:09:59 +02:00
/*****************************************************************************/
/******************************* Begin/end table *****************************/
2017-06-11 20:09:59 +02:00
/*****************************************************************************/
2019-10-23 19:05:05 +02:00
void HTM_TABLE_Begin (const char *fmt,...)
2019-10-04 01:35:40 +02:00
{
va_list ap;
int NumBytesPrinted;
char *Class;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Class,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-10-04 01:35:40 +02:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<table class=\"%s\">",Class);
2019-10-04 01:35:40 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_NestingLevel++;
2019-10-13 22:13:17 +02:00
2019-11-06 19:45:20 +01:00
free (Class);
2019-10-04 01:35:40 +02:00
}
else
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWithoutAttr ();
2019-10-04 01:35:40 +02:00
}
else
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWithoutAttr ();
2019-10-04 01:35:40 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TABLE_BeginPadding (unsigned CellPadding)
2017-06-11 20:09:59 +02:00
{
if (CellPadding)
2019-10-13 22:13:17 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<table class=\"CELLS_PAD_%u\">",
CellPadding); // CellPadding must be 0, 1, 2, 5 or 10
2019-10-13 22:13:17 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_NestingLevel++;
2019-10-13 22:13:17 +02:00
}
2019-10-03 22:43:36 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWithoutAttr ();
2017-06-11 20:09:59 +02:00
}
2019-10-23 19:05:05 +02:00
static void HTM_TABLE_BeginWithoutAttr (void)
2019-10-03 22:43:36 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<table>");
2019-10-13 22:13:17 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_NestingLevel++;
2019-10-03 22:43:36 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TABLE_BeginCenterPadding (unsigned CellPadding)
2017-06-11 20:09:59 +02:00
{
if (CellPadding)
2019-10-13 22:13:17 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<table class=\"FRAME_TBL_CENTER CELLS_PAD_%u\">",
CellPadding); // CellPadding must be 0, 1, 2, 5 or 10
2019-10-13 22:13:17 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_NestingLevel++;
2019-10-13 22:13:17 +02:00
}
2019-10-03 22:43:36 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginCenter ();
2019-10-03 22:43:36 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TABLE_BeginCenter (void)
2019-10-03 22:43:36 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<table class=\"FRAME_TBL_CENTER\">");
2019-10-13 22:13:17 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_NestingLevel++;
2017-06-11 20:09:59 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TABLE_BeginWidePadding (unsigned CellPadding)
2017-06-11 20:09:59 +02:00
{
if (CellPadding)
2019-10-13 22:13:17 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<table class=\"FRAME_TBL_WIDE CELLS_PAD_%u\">",
CellPadding); // CellPadding must be 0, 1, 2, 5 or 10
2019-10-13 22:13:17 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_NestingLevel++;
2019-10-13 22:13:17 +02:00
}
2019-10-03 22:43:36 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWide ();
2017-06-11 20:09:59 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TABLE_BeginWide (void)
2019-10-03 22:43:36 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<table class=\"FRAME_TBL_WIDE\">");
2019-10-13 22:13:17 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_NestingLevel++;
2019-10-03 22:43:36 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TABLE_BeginWideMarginPadding (unsigned CellPadding)
2017-06-11 20:09:59 +02:00
{
if (CellPadding)
2019-10-13 22:13:17 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<table class=\"FRAME_TBL_WIDE_MARGIN CELLS_PAD_%u\">",
2020-05-15 21:59:27 +02:00
CellPadding); // CellPadding must be 0, 1, 2, 5, 10, 20
2019-10-13 22:13:17 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_NestingLevel++;
2019-10-13 22:13:17 +02:00
}
2019-10-03 22:43:36 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TABLE_BeginWideMargin ();
2019-10-03 22:43:36 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TABLE_BeginWideMargin (void)
2019-10-03 22:43:36 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<table class=\"FRAME_TBL_WIDE_MARGIN\">");
2019-10-13 22:13:17 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_NestingLevel++;
2017-06-11 20:09:59 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TABLE_End (void)
2017-06-11 20:09:59 +02:00
{
2019-10-23 19:05:05 +02:00
if (HTM_TABLE_NestingLevel == 0) // No TABLE open
2019-10-13 22:13:17 +02:00
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened TABLE.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</table>");
2019-10-13 22:13:17 +02:00
2019-10-23 19:05:05 +02:00
HTM_TABLE_NestingLevel--;
2017-06-11 20:09:59 +02:00
}
2019-09-23 09:44:10 +02:00
2020-03-04 15:37:05 +01:00
/*****************************************************************************/
/********************************* Table body ********************************/
/*****************************************************************************/
void HTM_TBODY_Begin (const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2020-03-04 15:37:05 +01:00
/***** Print HTML *****/
HTM_TxtF ("<tbody %s>",Attr);
free (Attr);
}
else
HTM_TBODY_BeginWithoutAttr ();
}
else
HTM_TBODY_BeginWithoutAttr ();
}
static void HTM_TBODY_BeginWithoutAttr (void)
{
HTM_Txt ("<tbody>");
}
void HTM_TBODY_End (void)
{
HTM_Txt ("</tbody>");
}
2019-10-05 22:15:52 +02:00
/*****************************************************************************/
/**************************** Begin/end table row ****************************/
2019-10-05 22:15:52 +02:00
/*****************************************************************************/
2019-10-23 19:05:05 +02:00
void HTM_TR_Begin (const char *fmt,...)
2019-10-05 13:27:58 +02:00
{
2019-10-05 22:15:52 +02:00
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
2019-10-05 13:27:58 +02:00
{
2019-10-05 22:15:52 +02:00
if (fmt[0])
2019-10-05 13:27:58 +02:00
{
2019-10-05 22:15:52 +02:00
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-10-05 22:15:52 +02:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<tr %s>",Attr);
2019-10-05 22:15:52 +02:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-10-05 13:27:58 +02:00
}
else
2019-10-23 19:05:05 +02:00
HTM_TR_BeginWithoutAttr ();
2019-10-05 13:27:58 +02:00
}
else
2019-10-23 19:05:05 +02:00
HTM_TR_BeginWithoutAttr ();
2019-10-13 18:19:26 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_NestingLevel++;
2019-10-05 13:27:58 +02:00
}
2019-10-23 19:05:05 +02:00
static void HTM_TR_BeginWithoutAttr (void)
2019-10-04 01:35:40 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<tr>");
2019-10-04 01:35:40 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TR_End (void)
2019-10-04 01:35:40 +02:00
{
2019-10-23 19:05:05 +02:00
if (HTM_TR_NestingLevel == 0) // No TR open
2019-10-13 22:13:17 +02:00
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened TR.");
2019-10-13 18:19:26 +02:00
2019-12-13 23:38:29 +01:00
HTM_Txt ("</tr>");
2019-10-13 18:19:26 +02:00
2019-10-23 19:05:05 +02:00
HTM_TR_NestingLevel--;
2019-10-04 01:35:40 +02:00
}
2019-10-11 01:02:51 +02:00
/*****************************************************************************/
/***************************** Table heading cells ***************************/
/*****************************************************************************/
2019-10-23 19:05:05 +02:00
void HTM_TH (unsigned RowSpan,unsigned ColSpan,const char *Class,const char *Txt)
2019-10-12 19:42:10 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TH_Begin (RowSpan,ColSpan,Class);
2019-10-12 19:42:10 +02:00
if (Txt)
if (Txt[0])
2019-11-10 12:36:37 +01:00
HTM_Txt (Txt);
2019-10-23 19:05:05 +02:00
HTM_TH_End ();
2019-10-12 19:42:10 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TH_Begin (unsigned RowSpan,unsigned ColSpan,const char *Class)
2019-10-12 19:10:32 +02:00
{
if (RowSpan > 1 && ColSpan > 1)
{
if (Class)
2019-10-23 19:05:05 +02:00
HTM_TH_BeginAttr ("rowspan=\"%u\" colspan=\"%u\" class=\"%s\"",
2020-06-22 19:27:23 +02:00
RowSpan,ColSpan,Class);
2019-10-12 19:10:32 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TH_BeginAttr ("rowspan=\"%u\" colspan=\"%u\"",
2020-06-22 19:27:23 +02:00
RowSpan,ColSpan);
2019-10-12 19:10:32 +02:00
}
else if (RowSpan > 1)
{
if (Class)
2019-10-23 19:05:05 +02:00
HTM_TH_BeginAttr ("rowspan=\"%u\" class=\"%s\"",
2020-06-22 19:27:23 +02:00
RowSpan,Class);
2019-10-12 19:10:32 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TH_BeginAttr ("rowspan=\"%u\"",
2020-06-22 19:27:23 +02:00
RowSpan);
2019-10-12 19:10:32 +02:00
}
else if (ColSpan > 1)
{
if (Class)
2019-10-23 19:05:05 +02:00
HTM_TH_BeginAttr ("colspan=\"%u\" class=\"%s\"",
2020-06-22 19:27:23 +02:00
ColSpan,Class);
2019-10-12 19:10:32 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TH_BeginAttr ("colspan=\"%u\"",
2020-06-22 19:27:23 +02:00
ColSpan);
2019-10-12 19:10:32 +02:00
}
else
{
if (Class)
2019-10-23 19:05:05 +02:00
HTM_TH_BeginAttr ("class=\"%s\"",
2020-06-22 19:27:23 +02:00
Class);
2019-10-12 19:10:32 +02:00
else
2019-10-23 19:05:05 +02:00
HTM_TH_BeginWithoutAttr ();
2019-10-12 19:10:32 +02:00
}
}
2019-10-23 19:05:05 +02:00
static void HTM_TH_BeginAttr (const char *fmt,...)
2019-10-11 01:02:51 +02:00
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-10-11 01:02:51 +02:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<th %s>",Attr);
2019-10-11 01:02:51 +02:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-10-11 01:02:51 +02:00
}
else
2019-10-23 19:05:05 +02:00
HTM_TH_BeginWithoutAttr ();
2019-10-11 01:02:51 +02:00
}
else
2019-10-23 19:05:05 +02:00
HTM_TH_BeginWithoutAttr ();
2019-10-13 18:19:26 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_NestingLevel++;
2019-10-11 01:02:51 +02:00
}
2019-10-23 19:05:05 +02:00
static void HTM_TH_BeginWithoutAttr (void)
2019-10-11 01:02:51 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<th>");
2019-10-11 01:02:51 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TH_End (void)
2019-10-11 01:02:51 +02:00
{
2019-10-23 19:05:05 +02:00
if (HTM_TH_NestingLevel == 0) // No TH open
2019-10-13 22:13:17 +02:00
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened TR.");
2019-10-13 18:19:26 +02:00
2019-12-13 23:38:29 +01:00
HTM_Txt ("</th>");
2019-10-13 18:19:26 +02:00
2019-10-23 19:05:05 +02:00
HTM_TH_NestingLevel--;
2019-10-11 01:02:51 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TH_Empty (unsigned NumColumns)
2019-10-11 01:02:51 +02:00
{
unsigned NumCol;
for (NumCol = 0;
NumCol < NumColumns;
NumCol++)
{
2019-10-23 19:05:05 +02:00
HTM_TH_BeginAttr (NULL);
HTM_TH_End ();
2019-10-11 01:02:51 +02:00
}
}
2019-10-05 22:15:52 +02:00
/*****************************************************************************/
/********************************* Table cells *******************************/
/*****************************************************************************/
2019-10-23 19:05:05 +02:00
void HTM_TD_Begin (const char *fmt,...)
2019-10-07 22:28:16 +02:00
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-10-07 22:28:16 +02:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<td %s>",Attr);
2019-10-07 22:28:16 +02:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-10-07 22:28:16 +02:00
}
else
2019-10-23 19:05:05 +02:00
HTM_TD_BeginWithoutAttr ();
2019-10-07 22:28:16 +02:00
}
else
2019-10-23 19:05:05 +02:00
HTM_TD_BeginWithoutAttr ();
2019-10-13 18:19:26 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_NestingLevel++;
2019-10-07 22:28:16 +02:00
}
2019-10-23 19:05:05 +02:00
static void HTM_TD_BeginWithoutAttr (void)
2019-10-07 22:28:16 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<td>");
2019-10-07 22:28:16 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TD_End (void)
2019-10-06 12:00:55 +02:00
{
2019-10-26 12:25:27 +02:00
if (HTM_TD_NestingLevel == 0) // No TD open
2019-10-17 15:40:21 +02:00
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened TD.");
2019-10-13 18:19:26 +02:00
2019-12-13 23:38:29 +01:00
HTM_Txt ("</td>");
2019-10-13 18:19:26 +02:00
2019-10-23 19:05:05 +02:00
HTM_TD_NestingLevel--;
2019-10-06 12:00:55 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TD_Empty (unsigned NumColumns)
2019-10-05 13:27:58 +02:00
{
unsigned NumCol;
for (NumCol = 0;
NumCol < NumColumns;
NumCol++)
2019-10-10 23:14:13 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TD_Begin (NULL);
HTM_TD_End ();
2019-10-10 23:14:13 +02:00
}
2019-10-05 13:27:58 +02:00
}
2019-10-23 19:05:05 +02:00
void HTM_TD_ColouredEmpty (unsigned NumColumns)
2019-09-23 09:44:10 +02:00
{
unsigned NumCol;
for (NumCol = 0;
NumCol < NumColumns;
NumCol++)
2019-10-10 23:14:13 +02:00
{
2019-10-23 19:05:05 +02:00
HTM_TD_Begin ("class=\"COLOR%u\"",Gbl.RowEvenOdd);
HTM_TD_End ();
2019-10-10 23:14:13 +02:00
}
2019-09-23 09:44:10 +02:00
}
2019-10-23 20:07:56 +02:00
/*****************************************************************************/
/************************************ Divs ***********************************/
/*****************************************************************************/
2019-10-23 21:37:01 +02:00
void HTM_DIV_Begin (const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-10-23 21:37:01 +02:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<div %s>",Attr);
2019-10-23 21:37:01 +02:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-10-23 21:37:01 +02:00
}
else
HTM_DIV_BeginWithoutAttr ();
}
else
HTM_DIV_BeginWithoutAttr ();
HTM_DIV_NestingLevel++;
}
static void HTM_DIV_BeginWithoutAttr (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<div>");
2019-10-23 21:37:01 +02:00
}
2019-10-23 20:07:56 +02:00
void HTM_DIV_End (void)
{
2019-10-26 12:25:27 +02:00
if (HTM_DIV_NestingLevel == 0) // No DIV open
2019-10-23 21:37:01 +02:00
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened DIV.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</div>");
2019-10-23 21:37:01 +02:00
2019-10-26 12:25:27 +02:00
HTM_DIV_NestingLevel--;
2019-10-23 20:07:56 +02:00
}
2019-10-26 01:56:36 +02:00
/*****************************************************************************/
/******************************** Main zone **********************************/
/*****************************************************************************/
void HTM_MAIN_Begin (const char *Class)
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<main class=\"%s\">",Class);
2019-10-26 01:56:36 +02:00
}
void HTM_MAIN_End (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("</main>");
2019-10-26 01:56:36 +02:00
}
/*****************************************************************************/
/********************************* Articles **********************************/
/*****************************************************************************/
void HTM_ARTICLE_Begin (const char *ArticleId)
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<article id=\"%s\">",ArticleId);
2019-10-26 01:56:36 +02:00
}
void HTM_ARTICLE_End (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("</article>");
2019-10-26 01:56:36 +02:00
}
/*****************************************************************************/
/********************************* Sections **********************************/
/*****************************************************************************/
void HTM_SECTION_Begin (const char *SectionId)
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<section id=\"%s\">",SectionId);
2019-10-26 01:56:36 +02:00
}
void HTM_SECTION_End (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("</section>");
2019-10-26 01:56:36 +02:00
}
2019-10-26 02:19:42 +02:00
2019-11-07 10:24:00 +01:00
/*****************************************************************************/
/*********************************** Spans ***********************************/
/*****************************************************************************/
void HTM_SPAN_Begin (const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-07 10:24:00 +01:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<span %s>",Attr);
2019-11-07 10:24:00 +01:00
free (Attr);
}
else
HTM_SPAN_BeginWithoutAttr ();
}
else
HTM_SPAN_BeginWithoutAttr ();
HTM_SPAN_NestingLevel++;
}
static void HTM_SPAN_BeginWithoutAttr (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<span>");
2019-11-07 10:24:00 +01:00
}
void HTM_SPAN_End (void)
{
if (HTM_SPAN_NestingLevel == 0) // No SPAN open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened SPAN.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</span>");
2019-11-07 10:24:00 +01:00
HTM_SPAN_NestingLevel--;
}
2019-10-26 02:19:42 +02:00
/*****************************************************************************/
2019-11-11 00:15:44 +01:00
/*********************************** Lists ***********************************/
2019-10-26 02:19:42 +02:00
/*****************************************************************************/
2019-10-26 12:25:27 +02:00
2019-11-11 00:15:44 +01:00
void HTM_OL_Begin (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<ol>");
2019-11-11 00:15:44 +01:00
HTM_OL_NestingLevel++;
}
void HTM_OL_End (void)
{
if (HTM_OL_NestingLevel == 0) // No OL open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened OL.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</ol>");
2019-11-11 00:15:44 +01:00
HTM_OL_NestingLevel--;
}
2019-10-26 12:25:27 +02:00
void HTM_UL_Begin (const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-10-26 12:25:27 +02:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<ul %s>",Attr);
2019-10-26 12:25:27 +02:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-10-26 12:25:27 +02:00
}
else
HTM_UL_BeginWithoutAttr ();
}
else
HTM_UL_BeginWithoutAttr ();
HTM_UL_NestingLevel++;
}
static void HTM_UL_BeginWithoutAttr (void)
2019-10-26 02:19:42 +02:00
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<ul>");
2019-10-26 02:19:42 +02:00
}
2019-10-26 12:25:27 +02:00
2019-10-26 02:19:42 +02:00
void HTM_UL_End (void)
{
2019-10-26 12:25:27 +02:00
if (HTM_UL_NestingLevel == 0) // No UL open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened UL.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</ul>");
2019-10-26 12:25:27 +02:00
HTM_UL_NestingLevel--;
2019-10-26 02:19:42 +02:00
}
2019-10-26 22:49:13 +02:00
/*****************************************************************************/
/******************************** List items *********************************/
/*****************************************************************************/
void HTM_LI_Begin (const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-10-26 22:49:13 +02:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<li %s>",Attr);
2019-10-26 22:49:13 +02:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-10-26 22:49:13 +02:00
}
else
HTM_LI_BeginWithoutAttr ();
}
else
HTM_LI_BeginWithoutAttr ();
HTM_LI_NestingLevel++;
}
static void HTM_LI_BeginWithoutAttr (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<li>");
2019-10-26 22:49:13 +02:00
}
void HTM_LI_End (void)
{
if (HTM_LI_NestingLevel == 0) // No LI open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened LI.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</li>");
2019-10-26 22:49:13 +02:00
HTM_LI_NestingLevel--;
}
2019-10-28 13:56:04 +01:00
2019-11-09 20:04:35 +01:00
/*****************************************************************************/
/****************************** Definition lists *****************************/
/*****************************************************************************/
void HTM_DL_Begin (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<dl>");
2019-11-09 20:04:35 +01:00
HTM_DL_NestingLevel++;
}
void HTM_DL_End (void)
{
if (HTM_DL_NestingLevel == 0) // No DL open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened DL.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</dl>");
2019-11-09 20:04:35 +01:00
HTM_DL_NestingLevel--;
}
void HTM_DT_Begin (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<dt>");
2019-11-09 20:04:35 +01:00
HTM_DT_NestingLevel++;
}
void HTM_DT_End (void)
{
if (HTM_DL_NestingLevel == 0) // No DT open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened DT.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</dt>");
2019-11-09 20:04:35 +01:00
HTM_DT_NestingLevel--;
}
void HTM_DD_Begin (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<dd>");
2019-11-09 20:04:35 +01:00
HTM_DD_NestingLevel++;
}
void HTM_DD_End (void)
{
if (HTM_DD_NestingLevel == 0) // No DD open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened DD.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</dd>");
2019-11-09 20:04:35 +01:00
HTM_DD_NestingLevel--;
}
2019-10-28 13:56:04 +01:00
/*****************************************************************************/
/********************************** Anchors **********************************/
/*****************************************************************************/
void HTM_A_Begin (const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-10-28 13:56:04 +01:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<a %s>",Attr);
2019-10-28 13:56:04 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-10-28 13:56:04 +01:00
}
else
HTM_A_BeginWithoutAttr ();
}
else
HTM_A_BeginWithoutAttr ();
HTM_A_NestingLevel++;
}
static void HTM_A_BeginWithoutAttr (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<a>");
2019-10-28 13:56:04 +01:00
}
void HTM_A_End (void)
{
if (HTM_A_NestingLevel == 0) // No A open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened A.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</a>");
2019-10-28 13:56:04 +01:00
HTM_A_NestingLevel--;
}
2019-10-30 00:42:01 +01:00
2019-11-01 17:35:26 +01:00
/*****************************************************************************/
/*********************************** Scripts *********************************/
/*****************************************************************************/
void HTM_SCRIPT_Begin (const char *URL,const char *CharSet)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<script type=\"text/javascript\"");
2019-11-01 17:35:26 +01:00
if (URL)
if (URL[0])
2019-12-13 23:38:29 +01:00
HTM_TxtF (" src=\"%s\"",URL);
2019-11-01 17:35:26 +01:00
if (CharSet)
if (CharSet[0])
2019-12-13 23:38:29 +01:00
HTM_TxtF (" charset=\"%s\"",CharSet);
HTM_Txt (">\n");
2019-11-01 17:35:26 +01:00
HTM_SCRIPT_NestingLevel++;
}
void HTM_SCRIPT_End (void)
{
if (HTM_SCRIPT_NestingLevel == 0) // No SCRIPT open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened SCRIPT.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</script>\n");
2019-11-01 17:35:26 +01:00
HTM_SCRIPT_NestingLevel--;
}
2019-11-02 12:59:31 +01:00
/*****************************************************************************/
2019-11-09 20:26:13 +01:00
/********************************* Parameters ********************************/
/*****************************************************************************/
void HTM_PARAM (const char *Name,
const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Value;
if (fmt)
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Value,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-09 20:26:13 +01:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("\n<param name=\"%s\" value=\"%s\">",Name,Value);
2019-11-09 20:26:13 +01:00
free (Value);
}
}
/*****************************************************************************/
2019-11-02 12:59:31 +01:00
/*********************************** Labels **********************************/
/*****************************************************************************/
void HTM_LABEL_Begin (const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-02 12:59:31 +01:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<label %s>",Attr);
2019-11-02 12:59:31 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-11-02 12:59:31 +01:00
}
else
HTM_LABEL_BeginWithoutAttr ();
}
else
HTM_LABEL_BeginWithoutAttr ();
HTM_LABEL_NestingLevel++;
}
static void HTM_LABEL_BeginWithoutAttr (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<label>");
2019-11-02 12:59:31 +01:00
}
void HTM_LABEL_End (void)
{
if (HTM_LABEL_NestingLevel == 0) // No LABEL open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened LABEL.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</label>");
2019-11-02 12:59:31 +01:00
HTM_LABEL_NestingLevel--;
}
2019-11-03 18:22:11 +01:00
/*****************************************************************************/
2019-11-04 09:45:57 +01:00
/************************* Input text, email, url ****************************/
2019-11-03 18:22:11 +01:00
/*****************************************************************************/
2020-04-27 03:16:55 +02:00
void HTM_INPUT_TEXT (const char *Name,unsigned MaxLength,const char *Value,
HTM_SubmitOnChange_t SubmitOnChange,
2019-11-03 18:22:11 +01:00
const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"text\" name=\"%s\" maxlength=\"%u\" value=\"%s\"",
Name,MaxLength,Value);
2019-11-03 18:22:11 +01:00
2019-11-04 13:58:12 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-04 13:58:12 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-04 13:58:12 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-11-04 13:58:12 +01:00
}
}
2020-04-27 03:16:55 +02:00
if (SubmitOnChange == HTM_SUBMIT_ON_CHANGE)
2019-12-13 23:38:29 +01:00
HTM_TxtF (" onchange=\"document.getElementById('%s').submit();return false;\"",
Gbl.Form.Id);
2019-11-04 13:58:12 +01:00
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-11-04 13:58:12 +01:00
}
2019-11-04 21:00:57 +01:00
void HTM_INPUT_SEARCH (const char *Name,unsigned MaxLength,const char *Value,
2019-11-04 20:41:35 +01:00
const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"search\" name=\"%s\" maxlength=\"%u\" value=\"%s\"",
Name,MaxLength,Value);
2019-11-04 20:41:35 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-04 20:41:35 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-04 20:41:35 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-11-04 20:41:35 +01:00
}
}
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-11-04 20:41:35 +01:00
}
2020-04-27 03:16:55 +02:00
void HTM_INPUT_TEL (const char *Name,const char *Value,
HTM_SubmitOnChange_t SubmitOnChange,
2019-11-04 13:58:12 +01:00
const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"tel\" name=\"%s\" maxlength=\"%u\" value=\"%s\"",
Name,Usr_MAX_CHARS_PHONE,Value);
2019-11-04 13:58:12 +01:00
2019-11-03 18:22:11 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-03 18:22:11 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-03 18:22:11 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-11-03 18:22:11 +01:00
}
}
2020-04-27 03:16:55 +02:00
if (SubmitOnChange == HTM_SUBMIT_ON_CHANGE)
2019-12-13 23:38:29 +01:00
HTM_TxtF (" onchange=\"document.getElementById('%s').submit();return false;\"",
Gbl.Form.Id);
2019-11-04 12:25:48 +01:00
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-11-03 18:22:11 +01:00
}
2019-11-04 09:45:57 +01:00
void HTM_INPUT_EMAIL (const char *Name,unsigned MaxLength,const char *Value,
const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"email\" name=\"%s\" maxlength=\"%u\" value=\"%s\"",
Name,MaxLength,Value);
2019-11-04 09:45:57 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-04 09:45:57 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-04 09:45:57 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-11-04 09:45:57 +01:00
}
}
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-11-04 09:45:57 +01:00
}
2020-04-27 03:16:55 +02:00
void HTM_INPUT_URL (const char *Name,const char *Value,
HTM_SubmitOnChange_t SubmitOnChange,
2019-11-04 09:45:57 +01:00
const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-12-14 01:31:32 +01:00
HTM_TxtF ("<input type=\"url\" name=\"%s\" maxlength=\"%u\" value=\"%s\"",
2019-12-13 23:38:29 +01:00
Name,Cns_MAX_CHARS_WWW,Value);
2019-11-04 09:45:57 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-04 09:45:57 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-04 09:45:57 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-11-04 09:45:57 +01:00
}
}
2020-04-27 03:16:55 +02:00
if (SubmitOnChange == HTM_SUBMIT_ON_CHANGE)
2019-12-13 23:38:29 +01:00
HTM_TxtF (" onchange=\"document.getElementById('%s').submit();return false;\"",
Gbl.Form.Id);
2019-11-04 12:25:48 +01:00
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-11-04 09:45:57 +01:00
}
2020-04-27 03:16:55 +02:00
void HTM_INPUT_FILE (const char *Name,const char *Accept,
HTM_SubmitOnChange_t SubmitOnChange,
2019-11-11 00:15:44 +01:00
const char *fmt,...)
2019-11-04 10:03:37 +01:00
{
2019-11-11 00:15:44 +01:00
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"file\" name=\"%s\" accept=\"%s\"",
Name,Accept);
2019-11-11 00:15:44 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-11 00:15:44 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-11 00:15:44 +01:00
free (Attr);
}
}
2020-04-27 03:16:55 +02:00
if (SubmitOnChange == HTM_SUBMIT_ON_CHANGE)
2019-12-13 23:38:29 +01:00
HTM_TxtF (" onchange=\"document.getElementById('%s').submit();return false;\"",
Gbl.Form.Id);
HTM_Txt (" />");
2019-11-04 10:03:37 +01:00
}
2019-11-04 13:01:32 +01:00
void HTM_INPUT_BUTTON (const char *Name,const char *Value,const char *Attr)
{
extern const char *The_ClassInput[The_NUM_THEMES];
HTM_TxtF ("<input type=\"button\" name=\"%s\" value=\"%s\" class=\"%s\"%s />",
Name,Value,
The_ClassInput[Gbl.Prefs.Theme],
Attr);
2019-11-04 13:01:32 +01:00
}
2019-11-11 15:46:54 +01:00
void HTM_INPUT_IMAGE (const char *URL,const char *Icon,const char *Title,const char *Class)
2019-11-04 13:10:47 +01:00
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"image\" src=\"%s",URL);
2019-11-11 15:46:54 +01:00
if (Icon)
if (Icon[0])
2019-12-13 23:38:29 +01:00
HTM_TxtF ("/%s",Icon);
HTM_Txt ("\"");
2019-11-11 15:46:54 +01:00
2019-12-13 23:38:29 +01:00
HTM_TxtF (" alt=\"%s\" title=\"%s\" class=\"%s\" />",
Title,Title,Class);
2019-11-04 13:10:47 +01:00
}
2019-11-04 13:40:33 +01:00
void HTM_INPUT_PASSWORD (const char *Name,const char *PlaceHolder,
2019-11-12 15:41:58 +01:00
const char *AutoComplete,bool Required,
const char *fmt,...)
2019-11-04 13:40:33 +01:00
{
2019-11-12 15:41:58 +01:00
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"password\" name=\"%s\" size=\"18\" maxlength=\"%u\"",
Name,Pwd_MAX_CHARS_PLAIN_PASSWORD);
2019-11-04 13:40:33 +01:00
if (PlaceHolder)
if (PlaceHolder[0])
2019-12-13 23:38:29 +01:00
HTM_TxtF (" placeholder=\"%s\"",PlaceHolder);
2019-11-04 13:40:33 +01:00
if (AutoComplete)
if (AutoComplete[0])
2019-12-13 23:38:29 +01:00
HTM_TxtF (" autocomplete=\"%s\"",AutoComplete);
2019-11-04 13:40:33 +01:00
if (Required)
2019-12-13 23:38:29 +01:00
HTM_Txt (" required=\"required\"");
2019-11-12 15:41:58 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-12 15:41:58 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-12 15:41:58 +01:00
free (Attr);
}
}
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-11-04 13:40:33 +01:00
}
2020-04-27 03:16:55 +02:00
void HTM_INPUT_LONG (const char *Name,long Min,long Max,long Value,
HTM_SubmitOnChange_t SubmitOnChange,bool Disabled,
2019-11-27 01:01:27 +01:00
const char *fmt,...)
2019-11-04 13:50:33 +01:00
{
2019-11-12 15:41:58 +01:00
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"number\" name=\"%s\" min=\"%ld\" max=\"%ld\" value=\"%ld\"",
Name,Min,Max,Value);
2019-11-04 13:50:33 +01:00
if (Disabled)
2019-12-13 23:38:29 +01:00
HTM_Txt (" disabled=\"disabled\"");
2019-11-12 15:41:58 +01:00
2019-11-27 01:01:27 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-27 01:01:27 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-27 01:01:27 +01:00
free (Attr);
}
}
2020-04-27 03:16:55 +02:00
if (SubmitOnChange == HTM_SUBMIT_ON_CHANGE)
HTM_TxtF (" onchange=\"document.getElementById('%s').submit();return false;\"",
Gbl.Form.Id);
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-11-27 01:01:27 +01:00
}
2019-12-19 11:00:14 +01:00
void HTM_INPUT_FLOAT (const char *Name,double Min,double Max,
double Step, // Use 0 for "any"
double Value,bool Disabled,
2019-11-27 01:01:27 +01:00
const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
Str_SetDecimalPointToUS (); // To print the floating point as a dot
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"number\" name=\"%s\""
2020-01-11 15:22:02 +01:00
" min=\"%.15lg\" max=\"%.15lg\"",
2019-12-13 23:38:29 +01:00
Name,
2019-12-19 11:00:14 +01:00
Min,Max);
if (Step == 0.0)
HTM_Txt (" step=\"any\"");
else
2020-01-11 15:22:02 +01:00
HTM_TxtF (" step=\"%.15lg\"",Step);
HTM_TxtF (" value=\"%.15lg\"",Value);
2019-11-27 01:01:27 +01:00
Str_SetDecimalPointToLocal (); // Return to local system
if (Disabled)
2019-12-13 23:38:29 +01:00
HTM_Txt (" disabled=\"disabled\"");
2019-11-27 01:01:27 +01:00
2019-11-12 15:41:58 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-12 15:41:58 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-12 15:41:58 +01:00
free (Attr);
}
}
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-11-04 13:50:33 +01:00
}
2019-11-04 18:17:39 +01:00
void HTM_INPUT_RADIO (const char *Name,bool SubmitOnClick,
const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"radio\" name=\"%s\"",Name);
2019-11-04 18:17:39 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-04 18:17:39 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-04 18:17:39 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-11-04 18:17:39 +01:00
}
}
if (SubmitOnClick)
2019-12-13 23:38:29 +01:00
HTM_TxtF (" onchange=\"document.getElementById('%s').submit();return false;\"",
Gbl.Form.Id);
HTM_Txt (" />");
2019-11-04 18:17:39 +01:00
}
2020-03-12 13:53:37 +01:00
void HTM_INPUT_CHECKBOX (const char *Name,HTM_SubmitOnChange_t SubmitOnChange,
2019-11-04 20:41:35 +01:00
const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<input type=\"checkbox\" name=\"%s\"",Name);
2019-11-04 20:41:35 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-04 20:41:35 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-11-04 20:41:35 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-11-04 20:41:35 +01:00
}
}
2020-03-12 13:53:37 +01:00
if (SubmitOnChange == HTM_SUBMIT_ON_CHANGE)
2019-12-13 23:38:29 +01:00
HTM_TxtF (" onchange=\"document.getElementById('%s').submit();return false;\"",
Gbl.Form.Id);
2019-11-11 00:15:44 +01:00
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-11-04 20:41:35 +01:00
}
2019-11-09 20:15:38 +01:00
/*****************************************************************************/
/********************************** Buttons **********************************/
/*****************************************************************************/
2019-12-14 01:31:32 +01:00
void HTM_BUTTON_OnMouseDown_Begin (const char *Title,const char *Class)
2019-11-09 20:15:38 +01:00
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<button type=\"submit\"");
2019-12-03 19:36:30 +01:00
if (Title)
if (Title[0])
HTM_TxtF (" title=\"%s\"",Title);
if (Class)
if (Class[0])
HTM_TxtF (" class=\"%s\"",Class);
2019-12-14 01:31:32 +01:00
HTM_TxtF (" onmousedown=\"document.getElementById('%s').submit();return false;\">",
2019-12-13 23:38:29 +01:00
Gbl.Form.Id);
2019-11-18 09:20:44 +01:00
HTM_BUTTON_NestingLevel++;
}
2019-11-11 00:15:44 +01:00
2019-11-20 10:17:42 +01:00
void HTM_BUTTON_SUBMIT_Begin (const char *Title,const char *Class,const char *OnSubmit)
2019-11-18 09:20:44 +01:00
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<button type=\"submit\"");
2019-11-18 09:20:44 +01:00
if (Title)
if (Title[0])
HTM_TxtF (" title=\"%s\"",Title);
if (Class)
if (Class[0])
HTM_TxtF (" class=\"%s\"",Class);
2019-11-20 10:17:42 +01:00
if (OnSubmit) // JavaScript function to be called before submitting the form
2019-11-18 09:20:44 +01:00
if (OnSubmit[0])
2019-12-03 19:36:30 +01:00
HTM_TxtF (" onsubmit=\"%s;\"",OnSubmit);
2019-12-13 23:38:29 +01:00
HTM_Txt (">");
2019-11-19 00:17:23 +01:00
HTM_BUTTON_NestingLevel++;
}
2019-11-20 10:17:42 +01:00
void HTM_BUTTON_BUTTON_Begin (const char *Title,const char *Class,const char *OnClick)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<button type=\"button\"");
2019-11-20 10:17:42 +01:00
if (Title)
if (Title[0])
HTM_TxtF (" title=\"%s\"",Title);
if (Class)
if (Class[0])
HTM_TxtF (" class=\"%s\"",Class);
if (OnClick) // JavaScript function to be called when clicking the button
if (OnClick[0])
2019-12-03 19:36:30 +01:00
HTM_TxtF (" onclick=\"%s;\"",OnClick);
2019-12-13 23:38:29 +01:00
HTM_Txt (">");
2019-11-20 10:17:42 +01:00
HTM_BUTTON_NestingLevel++;
}
2019-11-19 00:17:23 +01:00
void HTM_BUTTON_Animated_Begin (const char *Title,const char *Class,const char *OnClick)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<button type=\"submit\"");
2019-11-19 00:17:23 +01:00
if (Title)
if (Title[0])
HTM_TxtF (" title=\"%s\"",Title);
if (Class)
if (Class[0])
HTM_TxtF (" class=\"%s\"",Class);
HTM_Txt (" onclick=\"");
2019-11-20 10:17:42 +01:00
if (OnClick) // JavaScript function to be called before when clicking the button
2019-11-19 00:17:23 +01:00
if (OnClick[0])
HTM_TxtF ("%s",OnClick);
HTM_TxtF ("AnimateIcon(%d);\">",Gbl.Form.Num);
2019-11-09 20:15:38 +01:00
HTM_BUTTON_NestingLevel++;
}
void HTM_BUTTON_End (void)
{
if (HTM_BUTTON_NestingLevel == 0) // No BUTTON open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened BUTTON.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</button>");
2019-11-09 20:15:38 +01:00
HTM_BUTTON_NestingLevel--;
}
2019-10-31 17:42:05 +01:00
/*****************************************************************************/
/********************************* Text areas ********************************/
/*****************************************************************************/
void HTM_TEXTAREA_Begin (const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-10-31 17:42:05 +01:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<textarea %s>",Attr);
2019-10-31 17:42:05 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-10-31 17:42:05 +01:00
}
else
HTM_TEXTAREA_BeginWithoutAttr ();
}
else
HTM_TEXTAREA_BeginWithoutAttr ();
HTM_TEXTAREA_NestingLevel++;
}
static void HTM_TEXTAREA_BeginWithoutAttr (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<textarea>");
2019-10-31 17:42:05 +01:00
}
void HTM_TEXTAREA_End (void)
{
if (HTM_TEXTAREA_NestingLevel == 0) // No TEXTAREA open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened TEXTAREA.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</textarea>");
2019-10-31 17:42:05 +01:00
HTM_TEXTAREA_NestingLevel--;
}
2019-11-05 08:46:38 +01:00
/*****************************************************************************/
/********************************** Selectors ********************************/
/*****************************************************************************/
2020-04-27 03:16:55 +02:00
void HTM_SELECT_Begin (HTM_SubmitOnChange_t SubmitOnChange,
2019-11-05 09:04:47 +01:00
const char *fmt,...)
2019-11-05 08:46:38 +01:00
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-05 08:46:38 +01:00
/***** Print HTML *****/
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<select %s",Attr);
2019-11-05 08:46:38 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-11-05 08:46:38 +01:00
}
else
HTM_SELECT_BeginWithoutAttr ();
}
else
HTM_SELECT_BeginWithoutAttr ();
2020-04-27 03:16:55 +02:00
if (SubmitOnChange == HTM_SUBMIT_ON_CHANGE)
2019-12-13 23:38:29 +01:00
HTM_TxtF (" onchange=\"document.getElementById('%s').submit();return false;\"",
Gbl.Form.Id);
2019-11-05 09:04:47 +01:00
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-11-05 15:47:35 +01:00
HTM_SELECT_NestingLevel++;
2019-11-05 08:46:38 +01:00
}
static void HTM_SELECT_BeginWithoutAttr (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<select");
2019-11-05 08:46:38 +01:00
}
void HTM_SELECT_End (void)
{
2019-11-05 15:47:35 +01:00
if (HTM_SELECT_NestingLevel == 0) // No SELECT open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened SELECT.");
2019-11-05 08:46:38 +01:00
2019-12-13 23:38:29 +01:00
HTM_Txt ("</select>");
2019-11-05 08:46:38 +01:00
2019-11-05 15:47:35 +01:00
HTM_SELECT_NestingLevel--;
2019-11-05 08:46:38 +01:00
}
2019-11-09 20:31:17 +01:00
void HTM_OPTGROUP_Begin (const char *Label)
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<optgroup label=\"%s\">",Label);
2019-11-09 20:31:17 +01:00
HTM_OPTGROUP_NestingLevel++;
}
void HTM_OPTGROUP_End (void)
{
if (HTM_OPTGROUP_NestingLevel == 0) // No OPTGROUP open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened OPTGROUP.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</optgroup>");
2019-11-09 20:31:17 +01:00
HTM_OPTGROUP_NestingLevel--;
}
2019-11-06 19:45:20 +01:00
void HTM_OPTION (HTM_Type_t Type,const void *ValuePtr,bool Selected,bool Disabled,
2019-11-05 23:11:31 +01:00
const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Content;
2019-12-13 23:38:29 +01:00
HTM_Txt ("<option value=\"");
2019-11-05 23:11:31 +01:00
switch (Type)
{
case HTM_Type_UNSIGNED:
2019-11-10 13:31:47 +01:00
HTM_Unsigned (*((unsigned *) ValuePtr));
2019-11-05 23:11:31 +01:00
break;
case HTM_Type_LONG:
2019-11-10 13:38:17 +01:00
HTM_Long (*((long *) ValuePtr));
2019-11-05 23:11:31 +01:00
break;
case HTM_Type_STRING:
2019-11-10 12:36:37 +01:00
HTM_Txt ((char *) ValuePtr);
2019-11-05 23:11:31 +01:00
break;
}
2019-12-13 23:38:29 +01:00
HTM_Txt ("\"");
2019-11-05 23:11:31 +01:00
if (Selected)
2019-12-13 23:38:29 +01:00
HTM_Txt (" selected=\"selected\"");
2019-11-05 23:11:31 +01:00
if (Disabled)
2019-12-13 23:38:29 +01:00
HTM_Txt (" disabled=\"disabled\"");
HTM_Txt (">");
2019-11-05 23:11:31 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Content,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-05 23:11:31 +01:00
/***** Print HTML *****/
2019-11-10 12:36:37 +01:00
HTM_Txt (Content);
2019-11-05 23:11:31 +01:00
2019-11-06 19:45:20 +01:00
free (Content);
2019-11-05 23:11:31 +01:00
}
}
2019-12-13 23:38:29 +01:00
HTM_Txt ("</option>");
2019-11-05 23:11:31 +01:00
}
2019-10-30 00:42:01 +01:00
/*****************************************************************************/
/********************************** Images ***********************************/
/*****************************************************************************/
2019-10-30 09:12:12 +01:00
void HTM_IMG (const char *URL,const char *Icon,const char *Title,
2019-10-30 22:31:03 +01:00
const char *fmt,...)
2019-10-30 00:42:01 +01:00
{
2019-10-30 22:31:03 +01:00
va_list ap;
int NumBytesPrinted;
char *Attr;
2019-10-30 00:42:01 +01:00
2019-12-13 23:38:29 +01:00
HTM_TxtF ("<img src=\"%s",URL);
2019-10-31 01:33:26 +01:00
if (Icon)
if (Icon[0])
2019-12-13 23:38:29 +01:00
HTM_TxtF ("/%s",Icon);
HTM_Txt ("\"");
2019-10-30 00:42:01 +01:00
if (Title)
{
if (Title[0])
2019-12-13 23:38:29 +01:00
HTM_TxtF (" alt=\"%s\" title=\"%s\"",Title,Title);
2019-10-30 00:42:01 +01:00
else
2019-12-13 23:38:29 +01:00
HTM_Txt (" alt=\"\"");
2019-10-30 00:42:01 +01:00
}
else
2019-12-13 23:38:29 +01:00
HTM_Txt (" alt=\"\"");
2019-10-30 00:42:01 +01:00
2019-10-30 22:31:03 +01:00
if (fmt)
{
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-10-30 22:31:03 +01:00
/***** Print attributes *****/
2019-12-13 23:38:29 +01:00
HTM_SPTxt (Attr);
2019-10-30 00:42:01 +01:00
2019-11-06 19:45:20 +01:00
free (Attr);
2019-10-30 22:31:03 +01:00
}
}
2019-10-30 00:42:01 +01:00
2019-12-13 23:38:29 +01:00
HTM_Txt (" />");
2019-10-30 00:42:01 +01:00
}
2019-11-09 21:08:20 +01:00
2019-11-11 00:15:44 +01:00
/*****************************************************************************/
/********************************** Strong ***********************************/
/*****************************************************************************/
void HTM_STRONG_Begin (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<strong>");
2019-11-11 00:15:44 +01:00
HTM_STRONG_NestingLevel++;
}
void HTM_STRONG_End (void)
{
if (HTM_STRONG_NestingLevel == 0) // No STRONG open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened STRONG.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</strong>");
2019-11-11 00:15:44 +01:00
HTM_STRONG_NestingLevel--;
}
/*****************************************************************************/
/********************************** Emphasis *********************************/
/*****************************************************************************/
void HTM_EM_Begin (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<em>");
2019-11-11 00:15:44 +01:00
HTM_EM_NestingLevel++;
}
void HTM_EM_End (void)
{
if (HTM_EM_NestingLevel == 0) // No EM open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened EM.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</em>");
2019-11-11 00:15:44 +01:00
HTM_EM_NestingLevel--;
}
2019-11-10 16:41:47 +01:00
/*****************************************************************************/
/******************************* Underlines **********************************/
/*****************************************************************************/
void HTM_U_Begin (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<u>");
2019-11-10 16:41:47 +01:00
HTM_U_NestingLevel++;
}
void HTM_U_End (void)
{
if (HTM_U_NestingLevel == 0) // No U open
Ale_ShowAlert (Ale_ERROR,"Trying to close unopened U.");
2019-12-13 23:38:29 +01:00
HTM_Txt ("</u>");
2019-11-10 16:41:47 +01:00
HTM_U_NestingLevel--;
}
2019-11-09 21:08:20 +01:00
/*****************************************************************************/
/****************************** Breaking lines *******************************/
/*****************************************************************************/
void HTM_BR (void)
{
2019-12-13 23:38:29 +01:00
HTM_Txt ("<br />");
2019-11-09 21:08:20 +01:00
}
2019-11-10 12:36:37 +01:00
/*****************************************************************************/
/********************************** Text *************************************/
/*****************************************************************************/
2019-11-11 00:15:44 +01:00
void HTM_TxtF (const char *fmt,...)
{
va_list ap;
int NumBytesPrinted;
char *Attr;
if (fmt)
if (fmt[0])
{
va_start (ap,fmt);
NumBytesPrinted = vasprintf (&Attr,fmt,ap);
va_end (ap);
2019-11-14 08:59:11 +01:00
if (NumBytesPrinted < 0) // -1 if no memory or any other error
Err_NotEnoughMemoryExit ();
2019-11-11 00:15:44 +01:00
/***** Print HTML *****/
HTM_Txt (Attr);
free (Attr);
}
}
2019-12-13 23:38:29 +01:00
static void HTM_SPTxt (const char *Txt)
{
HTM_Txt (" ");
HTM_Txt (Txt);
}
2019-11-10 12:36:37 +01:00
void HTM_Txt (const char *Txt)
{
2020-06-17 02:31:42 +02:00
if (Txt)
if (Txt[0])
fputs (Txt,Gbl.F.Out);
2019-11-10 13:16:39 +01:00
}
2020-06-18 20:06:17 +02:00
void HTM_TxtColon (const char *Txt)
{
HTM_Txt (Txt);
HTM_Colon ();
}
2020-01-11 15:22:02 +01:00
void HTM_TxtColonNBSP (const char *Txt)
{
HTM_Txt (Txt);
HTM_Colon ();
HTM_NBSP ();
}
2019-11-14 08:59:11 +01:00
void HTM_NBSP (void)
2019-11-10 13:16:39 +01:00
{
2019-11-11 10:59:24 +01:00
HTM_Txt ("&nbsp;");
2019-11-10 12:36:37 +01:00
}
2019-11-10 13:31:47 +01:00
2019-11-11 10:59:24 +01:00
void HTM_Colon (void)
2019-11-11 00:15:44 +01:00
{
HTM_Txt (":");
2019-11-10 13:51:07 +01:00
}
2019-11-11 00:15:44 +01:00
void HTM_Comma (void)
{
HTM_Txt (",");
}
2019-11-11 10:59:24 +01:00
void HTM_Hyphen (void)
2019-11-10 13:31:47 +01:00
{
2019-11-11 10:59:24 +01:00
HTM_Txt ("-");
2019-11-10 13:31:47 +01:00
}
2019-11-10 13:38:17 +01:00
2019-11-11 10:59:24 +01:00
void HTM_Asterisk (void)
2019-11-11 00:15:44 +01:00
{
2019-11-11 10:59:24 +01:00
HTM_Txt ("*");
2019-11-11 00:15:44 +01:00
}
2019-11-11 10:59:24 +01:00
void HTM_Unsigned (unsigned Num)
2019-11-11 00:15:44 +01:00
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("%u",Num);
2019-11-11 00:15:44 +01:00
}
2020-06-22 19:27:23 +02:00
void HTM_Light0 (void)
{
HTM_SPAN_Begin ("class=\"LIGHT\"");
HTM_Txt ("0");
HTM_SPAN_End ();
}
2019-11-11 10:59:24 +01:00
void HTM_Int (int Num)
2019-11-11 00:15:44 +01:00
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("%d",Num);
2019-11-11 00:15:44 +01:00
}
2019-11-10 16:47:05 +01:00
void HTM_UnsignedLong (unsigned long Num)
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("%lu",Num);
2019-11-10 16:47:05 +01:00
}
2019-11-10 13:38:17 +01:00
void HTM_Long (long Num)
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("%ld",Num);
2019-11-10 13:38:17 +01:00
}
2019-11-11 00:15:44 +01:00
void HTM_Double (double Num)
2019-12-14 13:35:35 +01:00
{
char *Str;
2020-01-11 15:22:02 +01:00
/***** Write from floating point number to string ****/
2019-12-14 13:35:35 +01:00
Str_DoubleNumToStr (&Str,Num);
/***** Write number from string to file *****/
HTM_Txt (Str);
/***** Free memory allocated for string *****/
free (Str);
}
2020-01-11 15:22:02 +01:00
void HTM_DoubleFewDigits (double Num)
{
char *Str;
/***** Write from floating point number to string with few digits ****/
Str_DoubleNumToStrFewDigits (&Str,Num);
/***** Write number from string to file *****/
HTM_Txt (Str);
/***** Free memory allocated for string *****/
free (Str);
}
2019-12-14 13:35:35 +01:00
void HTM_Double2Decimals (double Num)
2019-11-11 00:15:44 +01:00
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("%.2lf",Num);
2019-11-11 00:15:44 +01:00
}
void HTM_Percentage (double Percentage)
{
2019-12-13 23:38:29 +01:00
HTM_TxtF ("%5.2lf%%",Percentage);
2019-11-11 00:15:44 +01:00
}