Fix license for SPRTF modules.

Also correct the coding style to conform to HTML Tidy standard.
This commit is contained in:
Geoff McLane 2017-02-12 17:37:14 +01:00
parent 6a83918d33
commit ea49ca0b1d
2 changed files with 51 additions and 85 deletions

View File

@ -1,36 +1,23 @@
/*
* SPRTF - Log output utility
* SPRTF - Log output utility - part of the HTML Tidy project
*
* Author: Geoff R. McLane <reports _at_ geoffair _dot_ info>
* License: GPL v2 (or later at your choice)
* License: MIT (see tidy.h for the copyright notice)
*
* Revision 1.0.2 2017/02/12 17:06:02 geoff - correct license and coding style
* Revision 1.0.1 2012/11/06 13:01:25 geoff
* Revision 1.0.0 2012/10/17 00:00:00 geoff
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*
*/
#ifdef _MSC_VER
#pragma warning( disable : 4995 )
#endif
// Module: sprtf.cxx
// Debug log file output
#include <stdio.h> // fopen()...
#include <string.h> // strcpy
#include <stdarg.h> // va_start, va_end, ...
/* Module: sprtf.c */
/* Debug log file output */
#include <stdio.h> /* fopen()... */
#include <string.h> /* strcpy */
#include <stdarg.h> /* va_start, va_end, ... */
#ifdef _MSC_VER
#include <WinSock2.h>
#include <sys/timeb.h>
@ -38,16 +25,16 @@
#include <Strsafe.h>
#endif
#else /* !_MSC_VER */
#include <sys/time.h> // gettimeoday(), struct timeval,...
#include <sys/time.h> /* gettimeoday(), struct timeval,... */
#endif /* _MSC_VER y/n */
#include <time.h>
#include <stdlib.h> // for exit() in unix
#include <stdlib.h> /* for exit() in unix */
#include "sprtf.h"
#ifdef _MSC_VER
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#endif // #ifndef _CRT_SECURE_NO_DEPRECATE
#endif /* #ifndef _CRT_SECURE_NO_DEPRECATE */
#pragma warning( disable:4996 )
#else
#define strcmpi strcasecmp
@ -72,7 +59,7 @@ char *GetNxtBuf()
}
#define MXIO 512
#ifdef _MSC_VER // use local log
#ifdef _MSC_VER /* use local log */
static char def_log[] = "tempex.txt";
#else
static char def_log[] = "ex.log";
@ -137,7 +124,7 @@ int add_append_log( int val )
#ifdef _MSC_VER
static const char *mode = "wb"; // in window sprtf looks after the line endings
static const char *mode = "wb"; /* in window sprtf looks after the line endings */
#else
static const char *mode = "w";
#endif
@ -148,7 +135,7 @@ int open_log_file( void )
strcpy(logfile,def_log);
if (append_to_log) {
#ifdef _MSC_VER
mode = "ab"; // in window sprtf looks after the line endings
mode = "ab"; /* in window sprtf looks after the line endings */
#else
mode = "a";
#endif
@ -157,7 +144,7 @@ int open_log_file( void )
if( outfile == 0 ) {
outfile = (FILE *)-1;
sprtf("ERROR: Failed to open log file [%s] ...\n", logfile);
exit(1); /* failed */
/* exit(1); failed */
return 0; /* failed */
}
return 1; /* success */
@ -175,7 +162,7 @@ char * get_log_file( void )
{
if (logfile[0] == 0)
strcpy(logfile,def_log);
if (outfile == (FILE *)-1) // disable the log file
if (outfile == (FILE *)-1) /* disable the log file */
return (char *)"none";
return logfile;
}
@ -185,14 +172,14 @@ void set_log_file( char * nf, int open )
if (logfile[0] == 0)
strcpy(logfile,def_log);
if ( nf && *nf && strcmpi(nf,logfile) ) {
close_log_file(); // remove any previous
strcpy(logfile,nf); // set new name
if (strcmp(logfile,"none") == 0) { // if equal 'none'
outfile = (FILE *)-1; // disable the log file
close_log_file(); /* remove any previous */
strcpy(logfile,nf); /* set new name */
if (strcmp(logfile,"none") == 0) { /* if equal 'none' */
outfile = (FILE *)-1; /* disable the log file */
} else if (open) {
open_log_file(); // and open it ... anything previous written is 'lost'
open_log_file(); /* and open it ... anything previous written is 'lost' */
} else
outfile = 0; // else set 0 to open on first write
outfile = 0; /* else set 0 to open on first write */
}
}
@ -211,7 +198,7 @@ int gettimeofday(struct timeval *tp, void *tzp)
return 0;
}
#endif // _MSC_VER
#endif /* _MSC_VER */
void add_date_stg( char *ps, struct timeval *ptv )
{
@ -313,17 +300,17 @@ static void oi( char * psin )
if (add2listview) {
LVInsertItem(ps);
}
#endif // ADD_LISTVIEW
#endif /* ADD_LISTVIEW */
#ifdef ADD_SCREENOUT
if (add2screen) {
Add_String(ps); // add string to screen list
Add_String(ps); /* add string to screen list */
}
#endif // #ifdef ADD_SCREENOUT
#endif /* #ifdef ADD_SCREENOUT */
}
}
#ifdef _MSC_VER
// service to ensure line endings in windows only
/* service to ensure line endings in windows only */
static void prt( char * ps )
{
static char _s_buf[1024];
@ -360,21 +347,14 @@ static void prt( char * ps )
oi(pb);
k = 0;
}
} // for length of string
} /* for length of string */
if( k ) {
//if( ( gbCheckCrLf ) &&
// ( d != 0x0a ) ) {
// add Cr/Lf pair
//pb[k++] = 0x0d;
//pb[k++] = 0x0a;
//pb[k] = 0;
//}
pb[k] = 0;
oi( pb );
}
}
}
#endif // #ifdef _MSC_VER
#endif /* #ifdef _MSC_VER */
int direct_out_it( char *cp )
{
@ -386,8 +366,8 @@ int direct_out_it( char *cp )
return (int)strlen(cp);
}
// STDAPI StringCchVPrintf( OUT LPTSTR pszDest,
// IN size_t cchDest, IN LPCTSTR pszFormat, IN va_list argList );
/* STDAPI StringCchVPrintf( OUT LPTSTR pszDest,
* IN size_t cchDest, IN LPCTSTR pszFormat, IN va_list argList ); */
int MCDECL sprtf( const char *pf, ... )
{
static char _s_sprtfbuf[M_MAX_SPRTF+4];
@ -398,7 +378,7 @@ int MCDECL sprtf( const char *pf, ... )
i = vsnprintf( pb, M_MAX_SPRTF, pf, arglist );
va_end(arglist);
#ifdef _MSC_VER
prt(pb); // ensure CR/LF
prt(pb); /* ensure CR/LF */
#else
oi(pb);
#endif
@ -406,22 +386,22 @@ int MCDECL sprtf( const char *pf, ... )
}
#ifdef UNICODE
// WIDE VARIETY
/* WIDE VARIETY */
static void wprt( PTSTR ps )
{
static char _s_woibuf[1024];
char * cp = _s_woibuf;
int len = (int)lstrlen(ps);
if(len) {
int ret = WideCharToMultiByte( CP_ACP, // UINT CodePage, // code page
0, // DWORD dwFlags, // performance and mapping flags
ps, // LPCWSTR lpWideCharStr, // wide-character string
len, // int cchWideChar, // number of chars in string.
cp, // LPSTR lpMultiByteStr, // buffer for new string
1024, // int cbMultiByte, // size of buffer
NULL, // LPCSTR lpDefaultChar, // default for unmappable chars
NULL ); // LPBOOL lpUsedDefaultChar // set when default char used
//oi(cp);
int ret = WideCharToMultiByte( CP_ACP, /* UINT CodePage, // code page */
0, /* DWORD dwFlags, // performance and mapping flags */
ps, /* LPCWSTR lpWideCharStr, // wide-character string */
len, /* int cchWideChar, // number of chars in string. */
cp, /* LPSTR lpMultiByteStr, // buffer for new string */
1024, /* int cbMultiByte, // size of buffer */
NULL, /* LPCSTR lpDefaultChar, // default for unmappable chars */
NULL ); /* LPBOOL lpUsedDefaultChar // set when default char used */
/* oi(cp); */
prt(cp);
}
}
@ -435,12 +415,11 @@ int MCDECL wsprtf( PTSTR pf, ... )
va_start(arglist, pf);
*pb = 0;
StringCchVPrintf(pb,1024,pf,arglist);
//i = vswprintf( pb, pf, arglist );
va_end(arglist);
wprt(pb);
return i;
}
#endif // #ifdef UNICODE
#endif /* #ifdef UNICODE */
// eof - sprtf.cxx
/* eof - sprtf.c */

View File

@ -1,30 +1,17 @@
/*
* SPRTF - Log output utility
* SPRTF - Log output utility - part of the HTML Tidy project
*
* Author: Geoff R. McLane <reports _at_ geoffair _dot_ info>
* License: GPL v2 (or later at your choice)
* License: MIT (see tidy.h for the copyright notice)
*
* Revision 1.0.2 2017/02/12 17:06:02 geoff - correct license and coding style
* Revision 1.0.1 2012/11/06 13:01:25 geoff
* Revision 1.0.0 2012/10/17 00:00:00 geoff
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*
*/
// Module: sprtf.hxx
// Debug log file output
/* Module: sprtf.h */
/* Debug log file output */
#ifndef _SPRTF_HXX_
#define _SPRTF_HXX_
#include "tidyplatform.h"
@ -73,5 +60,5 @@ TIDY_EXPORT int gettimeofday(struct timeval *tp, void *tzp);
#ifdef __cplusplus
}
#endif
#endif // #ifndef _SPRTF_HXX_
// oef - sprtf.hxx
#endif /* #ifndef _SPRTF_HXX_*/
/* eof - sprtf.h */