meta,
C++
424 Methoden:
/* private: */ void safe_uts :: rm_tree_
|
/* public: */ BOOL safe_uts :: ok_Identifier
/* public: */ BOOL safe_uts :: ok_access
/* public: */ BOOL safe_uts :: ok_asChar
/* public: */ BOOL safe_uts :: ok_assert_in_str
/* public: */ BOOL safe_uts :: ok_atComm
/* public: */ BOOL safe_uts :: ok_check_str
/* public: */ BOOL safe_uts :: ok_cp_prefix // return substr
/* public: */ BOOL safe_uts :: ok_escaped
/* public: */ BOOL safe_uts :: ok_file_substr
/* public: */ BOOL safe_uts :: ok_goto_str
/* public: */ BOOL safe_uts :: ok_in_Range
/* public: */ BOOL safe_uts :: ok_in_name
/* public: */ BOOL safe_uts :: ok_is_ext
/* public: */ BOOL safe_uts :: ok_is_prefix
/* public: */ BOOL safe_uts :: ok_names
/* public: */ BOOL safe_uts :: ok_not_escaped // obsolete
/* public: */ BOOL safe_uts :: ok_not_htm
/* public: */ BOOL safe_uts :: ok_not_text
/* public: */ BOOL safe_uts :: ok_path_exists
/* public: */ BOOL safe_uts :: ok_path_exists
/* public: */ BOOL safe_uts :: ok_path_stat
/* public: */ BOOL safe_uts :: ok_quote
/* public: */ BOOL safe_uts :: ok_select_this
/* public: */ BOOL safe_uts :: ok_str_in_file
/* public: */ BOOL safe_uts :: ok_strchecker
/* public: */ BOOL safe_uts :: ok_rm_unicode
/* public: */ FILE * safe_uts :: ok_crAppend
/* public: */ FILE * safe_uts :: ok_create
/* public: */ FILE * safe_uts :: ok_create
/* public: */ FILE * safe_uts :: ok_create
/* public: */ FILE * safe_uts :: ok_create_
/* public: */ FILE * safe_uts :: ok_create_me
/* public: */ FILE * safe_uts :: ok_fopen
/* public: */ FILE * safe_uts :: ok_nextf
/* public: */ char safe_uts :: ok_ABC_sec
/* public: */ char safe_uts :: ok_askChar
/* public: */ char safe_uts :: ok_charOf
/* public: */ char safe_uts :: ok_environment
/* public: */ char safe_uts :: ok_eoName
/* public: */ char safe_uts :: ok_eoStr
/* public: */ char safe_uts :: ok_fastAlphaNum
/* public: */ char safe_uts :: ok_goto_word
/* public: */ char safe_uts :: ok_is_a
/* public: */ char safe_uts :: ok_toEndOfStr
/* public: */ char * safe_uts :: ok_Appwin_exists
/* public: */ char * safe_uts :: ok_MMDD
/* public: */ char * safe_uts :: ok_backto
/* public: */ char * safe_uts :: ok_backto
/* public: */ char * safe_uts :: ok_backtoSucc
/* public: */ char * safe_uts :: ok_corrStr
/* public: */ char * safe_uts :: ok_currentTime
/* public: */ char * safe_uts :: ok_cutAt
/* public: */ char * safe_uts :: ok_cutstr
/* public: */ char * safe_uts :: ok_dir_at
/* public: */ char * safe_uts :: ok_eosAt
/* public: */ char * safe_uts :: ok_es_
/* public: */ char * safe_uts :: ok_exePath
/* public: */ char * safe_uts :: ok_file_Time
/* public: */ char * safe_uts :: ok_getenv
/* public: */ char * safe_uts :: ok_in_str
/* public: */ char * safe_uts :: ok_koSEL
/* public: */ char * safe_uts :: ok_mae2win
/* public: */ char * safe_uts :: ok_memstr
/* public: */ char * safe_uts :: ok_namAnf
/* public: */ char * safe_uts :: ok_normName
/* public: */ char * safe_uts :: ok_norm_date
/* public: */ char * safe_uts :: ok_ourHome
/* public: */ char * safe_uts :: ok_retVar
/* public: */ char * safe_uts :: ok_s2fstr
/* public: */ char * safe_uts :: ok_skip_Br
/* public: */ char * safe_uts :: ok_skip_comment
/* public: */ char * safe_uts :: ok_skip_cout_cerr
/* public: */ char * safe_uts :: ok_skip_nest_o_str
/* public: */ char * safe_uts :: ok_skip_phpstr
/* public: */ char * safe_uts :: ok_skip_str
/* public: */ char * safe_uts :: ok_skip_str1
/* public: */ char * safe_uts :: ok_strNorm
/* public: */ char * safe_uts :: ok_subSTR
/* public: */ char * safe_uts :: ok_subStr
/* public: */ char * safe_uts :: ok_substr
/* public: */ char * safe_uts :: ok_thisDir
/* public: */ char * safe_uts :: ok_tmp_
/* public: */ char * safe_uts :: ok_to_o_str
/* public: */ char * safe_uts :: ok_toz
/* public: */ char * safe_uts :: ok_trimm
/* public: */ char * safe_uts :: ok_trimm
/* public: */ char * safe_uts :: ok_utf2win
/* public: */ char * safe_uts :: ok_werde_fNam
/* public: */ char * safe_uts :: to_upper
/* public: */ char * safe_uts :: utf
/* public: */ float safe_uts :: ok_DECNr
/* public: */ float safe_uts :: ok_MaxAbsfp
/* public: */ float safe_uts :: ok_decdecNr
/* public: */ int safe_uts :: ok_Value
/* public: */ int safe_uts :: ok_anz
/* public: */ int safe_uts :: ok_clone
/* public: */ int safe_uts :: ok_common
/* public: */ int safe_uts :: ok_get
/* public: */ int safe_uts :: ok_get_more
/* public: */ int safe_uts :: ok_get_more
/* public: */ int safe_uts :: ok_get_word
/* public: */ int safe_uts :: ok_max_me
/* public: */ int safe_uts :: ok_memcmp
/* public: */ int safe_uts :: ok_replace
/* public: */ int safe_uts :: ok_showComm
/* public: */ int safe_uts :: ok_trace_strIn
/* public: */ long safe_uts :: ok_decNr
/* public: */ long safe_uts :: ok_file_len
/* public: */ long safe_uts :: ok_file_len
/* public: */ long safe_uts :: ok_file_len
/* public: */ long safe_uts :: ok_file_pos
/* public: */ long safe_uts :: ok_file_pos
/* public: */ long safe_uts :: ok_seek
/* public: */ long safe_uts :: ok_seek
/* public: */ long safe_uts :: ok_time_of
/* public: */ safe_uts :: safe_uts
/* public: */ safe_uts :: ~safe_uts
/* public: */ time_t safe_uts :: ok_file_Surr
/* public: */ uchar safe_uts :: ok_umlaut
/* public: */ uchar safe_uts :: ok_zufchar
/* public: */ uint safe_uts :: ok_ersUtf_HTM
/* public: */ uint safe_uts :: ok_prefix_match
/* public: */ uint safe_uts :: ok_schmutz
/* public: */ uint safe_uts :: ok_str_match
/* public: */ uint safe_uts :: ok_substr_match
/* public: */ uint safe_uts :: ok_tmpName
/* public: */ uint safe_uts :: ok_toUtf8
/* public: */ uint safe_uts :: ok_trace_utf
/* public: */ uint safe_uts :: ok_wait_for
/* public: */ uint safe_uts :: ok_word_match
/* public: */ unsigned long safe_uts :: ok_size_Surr
/* public: */ void safe_uts :: Syntax
/* public: */ void safe_uts :: ok_1m
/* public: */ void safe_uts :: ok_ABC
/* public: */ void safe_uts :: ok_DEL
/* public: */ void safe_uts :: ok_Do
/* public: */ void safe_uts :: ok_EXIT
/* public: */ void safe_uts :: ok_KILL
/* public: */ void safe_uts :: ok_XMLUmlaute
/* public: */ void safe_uts :: ok_abc
/* public: */ void safe_uts :: ok_add_to_path
/* public: */ void safe_uts :: ok_append
/* public: */ void safe_uts :: ok_append
/* public: */ void safe_uts :: ok_checker
/* public: */ void safe_uts :: ok_checkstr
/* public: */ void safe_uts :: ok_close
/* public: */ void safe_uts :: ok_close
/* public: */ void safe_uts :: ok_close_Appwins
/* public: */ void safe_uts :: ok_close_to
/* public: */ void safe_uts :: ok_close_windows
/* public: */ void safe_uts :: ok_copy
/* public: */ void safe_uts :: ok_copy
/* public: */ void safe_uts :: ok_cp_file
/* public: */ void safe_uts :: ok_cp_file
/* public: */ void safe_uts :: ok_cp_file
/* public: */ void safe_uts :: ok_cp_ms_project
/* public: */ void safe_uts :: ok_cp_section
/* public: */ void safe_uts :: ok_cp_tree
/* public: */ void safe_uts :: ok_cp_tree
/* public: */ void safe_uts :: ok_create
/* public: */ void safe_uts :: ok_def_subset
/* public: */ void safe_uts :: ok_dir_exist
/* public: */ void safe_uts :: ok_dir_exist_empty
/* public: */ void safe_uts :: ok_doAnderswo
/* public: */ void safe_uts :: ok_endword
/* public: */ void safe_uts :: ok_ersChar
/* public: */ void safe_uts :: ok_escto
/* public: */ void safe_uts :: ok_execAt
/* public: */ void safe_uts :: ok_execute
/* public: */ void safe_uts :: ok_existiere_Leer
/* public: */ void safe_uts :: ok_exit_if_no
/* public: */ void safe_uts :: ok_expansion
/* public: */ void safe_uts :: ok_extract_sections
/* public: */ void safe_uts :: ok_f_to_dir
/* public: */ void safe_uts :: ok_fazit_trace
/* public: */ void safe_uts :: ok_file_exist_dir_fn
/* public: */ void safe_uts :: ok_get
/* public: */ void safe_uts :: ok_get_header_files
/* public: */ void safe_uts :: ok_getfw
/* public: */ void safe_uts :: ok_goto_str
/* public: */ void safe_uts :: ok_hoAus // hole aus ... bis zu str
/* public: */ void safe_uts :: ok_max_str
/* public: */ void safe_uts :: ok_memshift
/* public: */ void safe_uts :: ok_move
/* public: */ void safe_uts :: ok_no_xNUL
/* public: */ void safe_uts :: ok_notAllCapital
/* public: */ void safe_uts :: ok_popup
/* public: */ void safe_uts :: ok_put
/* public: */ void safe_uts :: ok_put
/* public: */ void safe_uts :: ok_putfw
/* public: */ void safe_uts :: ok_resInto
/* public: */ void safe_uts :: ok_rette_fs
/* public: */ void safe_uts :: ok_rm_tree
/* public: */ void safe_uts :: ok_see_str
/* public: */ void safe_uts :: ok_see_tree
/* public: */ void safe_uts :: ok_setenv
/* public: */ void safe_uts :: ok_show_ascii
/* public: */ void safe_uts :: ok_show_pos
/* public: */ void safe_uts :: ok_show_str
/* public: */ void safe_uts :: ok_show_text
/* public: */ void safe_uts :: ok_shrink
/* public: */ void safe_uts :: ok_skip_space_and_comment
/* public: */ void safe_uts :: ok_skip_strXXXXXXX
/* public: */ void safe_uts :: ok_sprintf
/* public: */ void safe_uts :: ok_strTrace
/* public: */ void safe_uts :: ok_strUm
/* public: */ void safe_uts :: ok_subdir
/* public: */ void safe_uts :: ok_system
/* public: */ void safe_uts :: ok_temp_file
/* public: */ void safe_uts :: ok_upperName
/* public: */ void safe_uts :: ok_win2utf8
#define static
#include safe_uts.h : cpp
#include safe_uts.c1 : cpp
#undef BB
#undef BBStr
#undef bb
#undef bbStr
#define BB
#define BBStr( x,y,z ) ;
#define bb
#define bbStr( x,y,z ) ;
#ifndef procNestOn
#undef LB_
#undef LE_
#undef LE_ret
#undef ret
#undef ret_
#undef __
#undef ___
#define LB_( x ) {
#define LE_ }
#define ret_ return ;
#define LE_ret( x ) return( x ); }
#define ret( x ) return( x );
#define __
#define ___
#endif
#define sf if ( showfdes )
static char str_currDate[ 32 ] ; // see ok_currentDate static char str_ct [ 80 ] ; // see ok_currentTime
static char * f_showStr ;
static long a_showStr ;
static long x_showStr ;
static char * f_otpos ;
static long a_otpos ;
static long x_otpos ;
static int clockNr ;
static int showComm ;
static int stops ;
static int openfiles , maxopenfiles ;
/* public: */ safe_uts :: ~safe_uts(
// -----------------------------------------------------------------------------
)
LB_("safe_uts.~safe_uts")
#ifdef doAtNester
KVStore st ;
if ( procALL && procALL -> GetFirst( st ) )
{
// Registriert werden nur Methoden, deren LB_ in Include ./testerTrace
// spezifiziert wurde:
printf( "\n\n-: Zeigt, welche Methoden wie oft aufgerufen wurden:"
"\n-: ------------------------------------------------"
"\n-: " );
KVStore st ; Surr s = procALL -> GetFirst( st );
while ( s )
{
printf( "\n-: %7s %s", st.c, st.k );
s = procALL -> Next( st );
}
delete( procALL );
printf( "\n\n" );
}
#endif
deconstruct += 1 ; if ( errno ) { _1( errno ) ok }
if ( 1 < deconstruct )
{
printf( "\nError in ~safe_uts(), exit\n" ); exit(1);
}
deconstruct -= 1 ;
// if ( tmpDir && *tmpDir ) rm_tree( tmpDir ); ok
ok_no_xNUL();
LE_
/* public: */ safe_uts :: safe_uts(
// -----------------------------------------------------------------------------
)
LB_("safe_uts.safe_uts")
// #include "nesterTrace" // klappt nicht
AtNester = 1 ;
procALL = 0 ;
nA.a = ( nestrec * ) malloc( 20000 * sizeof( nestrec ) );
nA.e = 1 ;
nA.a[0].p = "safe_uts :: safe_uts" ;
#ifdef doAtNester
AtNester = 0 ; // wenn Methoden-Abdeckung gezeigt werden soll ...
procALL = ( AtNester )? 0 : new Btree();
#endif
// .............................................................................
processNr = _getpid();
neuNam = 0 ;
neuNrMax = 0 ;
neuNrs = 0 ;
if (0)
{
neuNam = "1/1.h" ; // beobachte, wo diese Datei neu erzeugt wird
neuNrMax = 1111 ; // breche sptestens hier ab
}
checkerNr = 0 ;
clockNr = 0 ;
showSysCalls = 0 ;
ok_sysRes = 0 ;
e_tmps = 0 ;
eM = "MS Explorer may be in a folder already deleted,\n"
"or you may not have enough permissions (see the ACL above),\n"
"or the file may be locked by another application, "
"e.g. Adobe Reader" ;
tmp_DR = 'R' ; // Ramdisk = Default
//
// _1(is_dir( "R:/" )) // Liefert falsches Ergebnis !!!!
char * e = getenv( "trace_DIR" ); if ( *e ) tmp_DR = *e ;
if ( tmp_DR == 'R' && not_is_dir( "R:/tmp.tmp" ) )
then {
tmp_DR = *tmpDir ; // tmpDir == exut.TMPDir
}
s_( tmpsAt, "%c:/tmp.tmp", tmp_DR );
if (0)
{
_4( e, tmp_DR, tmpsAt, tmpDir )
printf( "\n tmpsAt = %s", tmpsAt );
printf( "\n tmpDir = %s", tmpDir );
}
if ( tmpDir && *tmpDir ) rm_tree( tmpDir ); ok
dir_exist( tmpsAt );
nameNr = traceNr = 0 ;
maestro_Umlaute = "ᄔ" ;
maestro_Umlaute[ 1 ] = ( uchar ) 225 ;
maestro_Umlaute[ 2 ] = ( uchar ) 132 ;
maestro_Umlaute[ 3 ] = ( uchar ) 148 ;
maestro_Umlaute[ 4 ] = ( uchar ) 129 ;
maestro_Umlaute[ 5 ] = ( uchar ) 142 ;
maestro_Umlaute[ 6 ] = ( uchar ) 153 ;
maestro_Umlaute[ 7 ] = ( uchar ) 154 ;
if not_in_str( ( uchar ) 225, maestro_Umlaute ) fErr
deconstruct = 0 ;
showfdes = showfcre = showComm ;
openfiles = 0 ; maxopenfiles = 20 ; stops = x_step = 0 ;
time( &x_start );
f_showStr = "x_show" ;
f_otpos = "x_otpos" ;
x_showStr = 1 ; if path_exists( f_showStr )
then {
FILE * f = fopen( f_showStr, "r" );
sf printf( "\n_files.open = %2i, %p r ", ++openfiles, f ); if ( ! f ) fErr
fscanf( f, "showStr %ld", &a_showStr );
close( f );
}
else a_showStr = 0 ;
x_otpos = 1 ; if path_exists( f_otpos )
then {
FILE * f = fopen( f_otpos, "r" );
sf printf( "\n_files.open = %2i, %p r ", ++openfiles, f ); if ( ! f ) fErr
fscanf( f, "otpos %ld", &a_otpos );
close( f );
}
else a_otpos = 0 ;
// -----------------------------------------------------------------------------
a_showStr -= 1 ;
a_otpos -= 32 ; // printf( "\na_otpos = %i", a_otpos );
if not_is_dir( tmpsAt )
{
m_errMess "System: No such folder: %s" m_
tmpsAt, ret_error
}
// if not_is_dir( tmpDir ) ?errS No such folder: %s", tmpDir ;
// _2( tmpsAt, tmpDir ) // tmpDir = exut.TMPDir
if (1) { rm_tree( tmpDir ); ok }
LE_
/* public: */ void safe_uts :: ok_1m (
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_1m")
if ( 4000 < openfiles ) fErr1( openfiles )
ret_
tr_files = 1 ;
printf( "\nopenfiles = %i", openfiles );
if ( 100 < openfiles ) fErr1( openfiles )
if ( 40 < maxopenfiles ) fErr2( openfiles, maxopenfiles )
LE_
// #include "nesterTrace" // klappt nicht
/* public: */ int safe_uts :: ok_showComm (
// -----------------------------------------------------------------------------
)
{
return( showComm );
}
/* public: */ void safe_uts :: ok_nester
/* -----------------------------------------------------------------------------
to trace method calls (is a basis for test coverage reporter)
-----------------------------------------------------------------------------
*/ (
BOOL rein // 1 = proc_rein, 0 = proc_raus
, char * proc
)
{
if ( AtNester ) ret_
#ifdef doAtNester
if ( rein )
then {
printf( "\n-=> %4i %s", nA.e, proc );
nA.a[ nA.e++ ].p = proc ;
if ( mx_nALen <= nA.e ) fErr1( nA.e - mx_nALen )
KVStore st ;
AtNester = 1 ;
if ( procALL -> Get( proc, st ) )
then {
s_( st.c, "%i", decNr( st.c ) + 1 );
procALL -> StrIns( 'e', st.k, st.c );
}
else procALL -> StrIns( 'i', proc, "1" );
AtNester = 0 ;
}
else {
printf( "\n-=< %4i", nA.e-1 );
if ( 0 < nA.e ) nA.e-- ;
}
#endif
}
/* public: */ void safe_uts :: ok_show_LB
/* -----------------------------------------------------------------------------
a trace function
-----------------------------------------------------------------------------
*/ (
char p
, char * proc
)
{
if ( *proc == p )
{
if ( atProc == proc ) then printf( "." );
else printf( "\n-> %s", proc );
atProc = proc ;
}
}
/* public: */ void safe_uts :: ok_teile
/* -----------------------------------------------------------------------------
quot * n + rem = z
-----------------------------------------------------------------------------
*/ (
int z // calculate div_t = z/n
, int n //
, int & quot //
, int & rem //
)
LB_("safe_uts.ok_teile")
if ( n )
then {
quot = z/n ; rem = z - quot * n ; errno = 0 ;
}
else errno = -1 ;
LE_
#ifdef GNU
/* public: */ void safe_uts :: ok_memshift
/* -----------------------------------------------------------------------------
the same as memcpy (but now overlaps are allowed)
-----------------------------------------------------------------------------
*/ (
void * dest //
, void * src //
, size_t n // move n bytes from src to dest
)
LB_("safe_uts.ok_memshift")
char s[n] ; memcpy( s, src, n ); memcpy( dest, s, n );
LE_
#endif
/* public: */ long safe_uts :: ok_seek
// -----------------------------------------------------------------------------
(
int f
, long offset
, int from
)
LB_("safe_uts.ok_seek")
LE_ret( lseek( f, offset, from ) )
/* public: */ long safe_uts :: ok_seek
// -----------------------------------------------------------------------------
(
FILE * f
, long offset
, int from
)
LB_("safe_uts.ok_seek")
// fseek arbeitet anders als lseek:
if ( fseek( f, offset, from ) ) fErr
LE_ret( ftell( f ) )
/* public: */ FILE * safe_uts :: ok_fopen
// -----------------------------------------------------------------------------
(
char * fn
, char * mode // posit 0 : "r" read , "r+" read & write
// , "w+" create or recreate
// posit eof : "a" append , "a+" read & write
)
LB_("safe_uts.ok_fopen")
while At( fn, "//" ) fn++ ;
if in_str( *fn, "<>:" ) { traceStr( "fn-4", fn-4, 100 ); fErr1( fn ) }
//
if ( ! mode ) fErr
if ( ! fn ) fErr
if ( ! * fn ) fErr
path fN ; strcpy( fN, fn );
char * c = fN - 1 ;
#ifdef UNIX
while ( *( ++c ) ) if ( *c == '\\' ) *c = '/' ;
#else
while ( *( ++c ) ) if ( *c == '/' ) *c = '\\' ;
#endif
#undef fopen
L1: FILE * f = fopen( fN, mode ); if ( f ) ok else
{
char * x = eos( fN );
while ( fN <= x && not_in_str( *x, "\\/" ) ) x-- ;
if ( fN < x )
{
char m = *x ; *x = 0 ; S_ "can_stat %s", fN _Do
*x = m ; f = fopen( fN, mode ); if ( f ) ok
}
}
if ( errno )
{ ok
sleep( 1 ); f = fopen( fN, mode ); _1(f)
}
#define fopen safe_ut.ok_fopen
if ( errno )
{ _1(fN) traceStr( "fN", fN, 200 );
int merke = errno ; ok
if is_dir( fn )
{
m_errMess "User: Cannot open dir %s as a file." m_
fN, ret_error
}
if in_str( '*', fN )
{
m_errMess "User: Not a path: %s" m_
fN, ret_error
}
;
printf( "\nACL at %s:\n", fN );
char800 xx ; strcpy( xx, fN );
char * x = eos( xx );
while ( xx < x && *x != '\\' ) x-- ; *x = 0 ; _1( is_dir( xx ) )
S_ "cacls \"%s\"", fN _Do // to show access permissions (i.e. ACLs)
printf( "\n|\nend of ACL at %s", fN );
fflush( stdout );
errno = merke ;
char800 cwd ; strcpy( cwd, getcwd( cwd, 800 ) );
{
m_errMess "User: f = %p: cannot fopen %s %s (errno = %i)\n"
"currDir = %s\n%s" m_
f, mode, fN, errno, cwd, eM, ret_error
}
;
}
if ( errno ) fErr3( fN, mode, errno )
LE_ret( f )
/* public: */ long safe_uts :: ok_file_len
/* -----------------------------------------------------------------------------
ret length of open file f
-----------------------------------------------------------------------------
*/ (
FILE * f
)
LB_("safe_uts.ok_file_len")
if ( ! f ) fErr
// fseek arbeitet anders als lseek:
long pos = ftell( f ) ; fseek( f, 0L, SEEK_END );
long len = ftell( f ) ;
if ( fseek( f, pos, SEEK_SET ) ) fErr
LE_ret( len )
/* public: */ long safe_uts :: ok_file_len
/* -----------------------------------------------------------------------------
return length of file
-----------------------------------------------------------------------------
*/ (
char * fn
)
LB_("safe_uts.ok_file_len")
if ( ! fn ) fErr
if is_dir( fn ) ret( -1 )
FILE * f = fopen( fn, "r+" );
if ( ! f )
{
m_errMess "System: file_len() cannot open the file %s" m_
fn, ret_error
}
;
long len = ok_file_len( f ); close( f );
// len = filesize( fn ); EE
LE_ret( len )
/* public: */ long safe_uts :: ok_file_len ( int f
/* -----------------------------------------------------------------------------
ret length of open file f
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_file_len")
long pos = lseek( f, 0L, SEEK_CUR );
if ( errno || pos < 0 ) S_ "%li, %i = pos, f\n", pos, f _fErr
long len = lseek( f, 0L, SEEK_END ); // tell is not known to GNU C++
if ( pos != lseek( f, pos, SEEK_SET ) ) fErr
LE_ret( len )
/* public: */ long safe_uts :: ok_file_pos
/* -----------------------------------------------------------------------------
ret number of bytes in front of current position
-----------------------------------------------------------------------------
*/ (
int f
)
LB_("safe_uts.ok_file_pos")
long pos = lseek( f, 0L, SEEK_CUR ); if ( pos < 0 ) fErr
LE_ret( pos )
/* public: */ long safe_uts :: ok_file_pos
/* -----------------------------------------------------------------------------
ret number of bytes in front of current position
-----------------------------------------------------------------------------
*/ (
FILE * f
)
LB_("safe_uts.ok_file_pos")
LE_ret( ftell( f ) ) // fseek arbeitet anders als lseek !!
/* public: */ char * safe_uts :: ok_getenv
/* -----------------------------------------------------------------------------
a better getenv
-----------------------------------------------------------------------------
*/ (
char * name
)
LB_("safe_uts.ok_getenv")
if ( name )
then {
char * c = name ; while ( *c ) if ( ! in_name( *c++ ) )
{
S_ "name = (%s)\n", name _fErr
}
// getenv renders core dump if, e.g. name = "\\tmp"
# undef getenv
char * v = getenv( name ); if (v) ret( v );
# define getenv safe_ut.ok_getenv
}
else Ret( EN_NULL_pointer, "" )
LE_ret( "" )
#ifndef MICROSOFT
/* public: */ BOOL safe_uts :: ok_path_stat
/* -----------------------------------------------------------------------------
check whether file (or directory) exists; if so, fill stat B
-----------------------------------------------------------------------------
*/ (
char * file // a path into the file system
, struct stat & B // file status structure
)
LB_("safe_uts.ok_path_stat")
if ( ! file ) fErr
if ( ! file[ 0 ] ) ret(1) // current directory
errno = 0 ; stat( (char *)file, &B );
if ( ! no_such_file )
then {
if ( errno ) fErr else ret(1)
}
else errno = 0 ;
LE_ret( 0 )
#endif
/* public: */ BOOL safe_uts :: ok_path_exists
/* -----------------------------------------------------------------------------
check whether file (or directory) exists
-----------------------------------------------------------------------------
*/ (
char * file // a path into the file system
)
LB_("safe_uts.ok_path_exists")
if ( ! file ) fErr
if ( ! file[ 0 ] ) ret(1) // current directory
path fn ; strcpy( fn, file ); dos_me( fn );
if is_( fn, "/" ) ret( 1 )
ok struct stat B ; stat( file, &B );
if no_such_file
then {
ok ret( 0 )
}
esif ( errno ) S_ "errno %i: file( %s )", errno, file _fErr
else ret(1)
LE_ret( 0 )
/* public: */ void safe_uts :: ok_exit_if_no
/* -----------------------------------------------------------------------------
check whether file (or directory) exists
-----------------------------------------------------------------------------
*/ (
BOOL stop //
, char * name // a path into the file system
, char * ext // rest of path
)
LB_("safe_uts.ok_exit_if_no")
if ( ! name ) fErr
if ( ! ext ) fErr
path file ; char * e = file ; char * x = name ;
while ( *x && not_space( *x ) ) *e++ = *x++ ; x = ext ;
while ( *x && not_space( *x ) ) *e++ = *x++ ; *e = 0 ;
if ( ! file[ 0 ] ) ret_ // current directory
if not_path_exists( file ) stops += 1 ;
if ( stop ) if ( stops ) exit(1) ;
LE_
/* public: */ BOOL safe_uts :: ok_path_exists
/* -----------------------------------------------------------------------------
fs = fs + ext ; return BOOL( fs + ext ) exists )
-----------------------------------------------------------------------------
*/ (
char * fs // 1st part of path
, char * fs_e // the NULL position thereof
, char * ext // 2nd part of path
)
LB_("safe_uts.ok_path_exists")
strcpy( fs_e, ext );
LE_ret( path_exists( fs ) )
/* public: */ void safe_uts :: ok_expansion
/* -----------------------------------------------------------------------------
replace substrings representing defined environment variables
-----------------------------------------------------------------------------
*/ (
char * two // a string
, char * one // the same path with substrings %xxx\ re-
// placed by XXX if XXX was found to be
// the value of environment variable xxx .
)
LB_("safe_uts.ok_expansion")
int s = 0 ; ok
int k = 0 ;
int a = 0 ;
while ( one[ s ] )
{
if ( one[ s ] == '%' )
then {
int j = s ; while( in_name( one[ ++j ] ) ){} ; s++ ;
j = j-s ; if ( L_path < j ) fErr
path x ; memcpy( x, one+s, j ); x[j] = 0 ;
j = 0 ; while( isalpha( x[j] ) ) j++ ;
if ( j )
then {
x[ j-- ] = NULL ;
if ( getenv( x ) )
then {
if ( one[ s += j+1 ] == '%' ) s++ ;
path z ; strcpy( z, getenv( x ));
j = 0 ; while ( z[j] ) { two[ k++ ] = z[ j++ ] ; }
a++ ;
}
else two[ k++ ] = one[ s++ ] ;
}
else s++ ;
}
else two[ k++ ] = one[ s++ ] ;
}
two[ k ] = 0 ;
if ( L_path <= k ) fErr3( k, one, two )
LE_
/* public: */ void safe_uts :: ok_dir_exist_empty
/* -----------------------------------------------------------------------------
guarantees existence of directory, backslashes in the path,
and must n o t be the current directory
-----------------------------------------------------------------------------
*/ (
char * pf // path to dir root
)
LB_("safe_uts.ok_dir_exist_empty")
if ( ! pf ) fErr
if ( ! pf[ 0 ] ) ret_ // because 'pf is the current dir
if is_( pf, "." ) fErr
rm_tree( pf ); ok_dir_exist( pf ) ;
LE_
/* public: */ void safe_uts :: ok_dir_exist
/* -----------------------------------------------------------------------------
guarantees existence of directory, backslashes in the path,
and may be the current directory
-----------------------------------------------------------------------------
*/ (
char * pf // a path into the file system
)
LB_("safe_uts.ok_dir_exist")
if ( ! pf ) fErr
if ( ! pf[ 0 ] ) ret_ // because pf == current dir
path pa ; ok_expansion( pa, pf ); dos_me( pa );
if ( *pa != '.' && *pa != ':' )
if not_in_name( pa[0] )
if not_in_name( pa[1] ) fErr1( pa )
// _1(pa)
if ( path_exists( pa ) )
{
path pa_ ; sprintf( pa_, "%s\\_", pa ); ok
if ( substr( "\\Temp\\_", pa_ ) && is_dir( pa ) ) ret_
FILE * f ; create( f, pa_ ); // ( ! f ) fErr
if ( f )
then {
close( f ); Unlink( pa_ );
}
esif substr( "\\Temp\\_", pa_ ) ret_
else
{
m_errMess "System: cannot create %s" m_
pa, ret_error
}
// Now we are sure that pa is a directory (i.e. not just a file or
// not in existence).
//
// Note: We know that we have write access here because otherwise you
// should have called path_exists().
ret_
}
strcat( pa, "\\" );
for ( int j = 0 ; pa[ ++j ] ; ) if ( pa[j] == '\\' )
{
if ( pa[ j-1 ] == ':' ) { if ( j != 2 ) fErr1( pf ) } else
{
pa[j] = 0 ;
if ( ! path_exists( pa ) )
then {
if ( tr_files ) printf( "\nmkdir %s", pa );
_mkdir( pa ); ok
if not_is_dir( pa )
{
_1( CWD )
S_ "cannot create dir( %s )\n", pa _fErr
}
}
if ( pa[ j+1 ] ) pa[j] = '\\' ;
}
}
LE_
/* public: */ void safe_uts :: ok_file_exist_dir_fn
// -----------------------------------------------------------------------------
(
char * dir
, char * fn
)
LB_("safe_uts.ok_file_exist_dir_fn")
if ( ! dir ) dir = "." ;
char1000 xx ; s_( xx, "%s/%s", dir, fn ); FILE * f = create( xx );
close( f );
LE_
/* public: */ FILE * safe_uts :: ok_create
/* -----------------------------------------------------------------------------
create file 'dir/fn
-----------------------------------------------------------------------------
*/ (
char * x // a path to a dir
, char * plus //
)
LB_("safe_uts.ok_create")
path cr ; strcpy( cr, x ); strcat( cr, plus );
LE_ret( create( cr ) )
/* public: */ FILE * safe_uts :: ok_create
/* -----------------------------------------------------------------------------
create file 'dir/nr.ext
-----------------------------------------------------------------------------
*/ (
int n // 0, 1, 2, ...
, char * ext //
, char * dir //
, char * dir_e //
)
LB_("safe_uts.ok_create")
if ( n < 0 ) fErr
s_( dir_e, "%i.%s", n, ext );
FILE * f = create( dir ); if ( errno ) fErr2( dir, errno )
LE_ret( f )
/* public: */ FILE * safe_uts :: ok_create_me( char * x
/* -----------------------------------------------------------------------------
create file x and also dir
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_create_me(")
FILE * f = create( x ); fprintf( f, "\n %s\n\n", x );
LE_ret( f )
/* public: */ FILE * safe_uts :: ok_create_( char * x
/* -----------------------------------------------------------------------------
create file x and also dir
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_create_(")
// if substr( "Atomare-", x )
if ( ! x || ! *x ) fErr
if in_str( '\\', x ) unix_me( x );
char * e = eos( x ) - 1 ; if in_str( *e, "/\\:" ) fErr1( x )
if in_str( '/', x )
{
char * e = eos( x ); while ( *e != '/' ) e-- ;
*e = 0 ; dir_exist( x );
*e = '/' ;
}
if in_str( '/', x )
{
char * e = eos( x ); while ( *e != '/' ) e-- ;
*e = 0 ; dir_exist( x );
*e = '/' ;
}
LE_ret( create( x ) )
/* public: */ FILE * safe_uts :: ok_create
/* -----------------------------------------------------------------------------
create file x
-----------------------------------------------------------------------------
*/ (
char * x // a path
)
LB_("safe_uts.ok_create")
while At( x, "//" ) x++ ;
if substr( "core/Schu", x ) printf( "\nfNEU: call_nr %i, %s\n", call_nr, x );
// if substr( "177.", x )
if ( neuNam && substr( neuNam, x ) )
{
printf( "\nNEU: neuNr %i, %s\n", ++neuNrs, x );
if ( neuNrMax <= neuNrs ) fErr3( neuNrs, neuNrMax, x )
}
if ( ! *x ) fErr
if substr( "(null)", x ) fErr1( x )
if ( L_path < strlen( x ) ) fErr1( x )
FILE * f ; create( f, x ); // macht das dos_me
path xx ; strcpy( xx, x ); char * s = xx + strlen( xx );
while ( xx < s && *s != '/' && *s != '\\' ) s-- ;
sprintf( s, "INDX\\%s", x + ( s - xx ) ); Unlink( xx );
if ( showComm ) printf( "\nfileno = %i for %s\n", fileno( f ), x );
//
// damit wird sichtbar, ob die Zahl offener Files stndig steigt.
if ( neuNam && substr( neuNam, x ) )
{
fstop = f ; s_( fschr, x );
}
if substr( "core/Schulw", x )
{
merke1 = f ; strcpy( merke1fAt, x );
}
LE_ret( f )
/* public: */ void safe_uts :: ok_create
/* -----------------------------------------------------------------------------
create file x
-----------------------------------------------------------------------------
*/ (
FILE * & fx //
, char * x // a path into the file system
)
LB_("safe_uts.ok_create")
while At( x, "//" ) x++ ;
path fn ; dos_expansion( fn, x ); fx = fopen( fn, "w+" );
#ifdef USE_DOS_NAMES
{
char * c = fn ; int n = 0 ; if ( c[1] == ':' ) c += 2 ;
c -= 1 ;
while ( *( ++c ) )
{
if ( *c == '\\' )
then {
if ( 8 < ++n ) S_ "not a DOS path: %s\n", fn _fErr
n = 0 ;
}
else n += 1 ;
}
if ( n <= 0 ) S_ "not a file name: %s\n", fn _fErr
}
#endif
if ( ! fx )
{
_1( CWD )
{
m_errMess "System: cannot create( %s )" m_
fn, ret_error
}
}
ok // da auch erfolgreiches create errno = EN_no_such_file sagen kann:
// dann nmlich, wenn die Datei zuvor nicht existiert hat.
fflush( fx ); EE
int i = strlen( fn ) - 2 ;
sf printf( "\n_files.create = %2i, %p c %s", ++openfiles, fx, fn );
if ( maxopenfiles < openfiles ) fErr2( maxopenfiles, openfiles )
LE_
/* public: */ FILE * safe_uts :: ok_crAppend ( char * fAt
/* -----------------------------------------------------------------------------
open or create file for appending data
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_crAppend")
char800 zz ; strcpy( zz, fAt ); dos_me( zz ); ok
FILE * f = fopen( zz, "a" );
if ( ! f || errno != 0 ) fErr3( errno, f, fAt )
LE_ret( f )
/* public: */ void safe_uts :: ok_close_to
// -----------------------------------------------------------------------------
(
FILE * & f
, char * nch
, char * tmp
)
LB_("safe_uts.ok_close_to")
close( f ); cp_file( nch, tmp ); unlink( tmp ); ok
LE_
/* public: */ void safe_uts :: ok_close
/* -----------------------------------------------------------------------------
close file
-----------------------------------------------------------------------------
*/ (
FILE * & f
, char * File
, int Line
)
LB_("safe_uts.ok_close")
if ( ! f )
{
{
m_errMess "System: cannot close file %p in line %i of %s" m_
f, Line, File, ret_error
}
}
ok fflush( f ); // flush i s necessary on DOS - see pretty.exe
if ( errno )
{
{
m_errMess "System: ?zerror: Disk full ??\n" m_
ret_error
}
;
}
if ( f == fstop )
{
fstop = 0 ; printf( "\nClose: %s", fschr );
}
//
sf printf( "\n_FILE.close = %2i, %p", --openfiles, f );
if ( openfiles < 0 ) fErr
BOOL check = ( f == merke1 );
# undef fclose
fclose( f ); f = 0 ; ok
# define fclose(x) safe_ut.ok_close(x,_FL_)
if ( 1 && check )
{
merke1 = 0 ;
// if file_substr( merke1fAt, "0-98Noch" ) fErr1( merke1fAt )
if file_substr( merke1fAt, "/x.htm" ) fErr1( merke1fAt )
//
}
LE_
/* public: */ void safe_uts :: ok_close
/* -----------------------------------------------------------------------------
close file
-----------------------------------------------------------------------------
*/ (
int & f
, char * File
, int Line
)
LB_("safe_uts.ok_close")
if ( errno ) _1( errno ) ok
if ( errno )
{
{
m_errMess "System: cannot close file %i in line %i of %s" m_
f, Line, File, ret_error
}
}
if ( f == -1 ) ret_
if ( 1000 < f )
{
{
m_errMess "System: cannot create %s -- do you create it recursively ???" m_
File, ret_error
}
;
}
// if ( 1000 < f ) fErr4( f, File, Line )
//
sf printf( "\n_fdes.close = %2i, %8i", --openfiles, f );
if ( openfiles < 0 ) fErr
# undef close
# ifdef MICROSOFT
if ( 1 < f ) { _close( f ); f = -1 ; }
# else
if ( 1 < f ) { close( f ); f = -1 ; }
# endif
# define close(x) safe_ut.ok_close(x,_FL_)
if ( errno )
{
printf( "\nerror: errno = %i, cannot close file, disk full ???", errno );
ok // fErr3( File, Line, errno )
}
LE_
/* public: */ void safe_uts :: ok_no_xNUL(
/* -----------------------------------------------------------------------------
delete ./xNUL_*
-----------------------------------------------------------------------------
*/ )
{
FILE * f = create( "xNUL" ); close( f );
#undef system
system( "type xNUL_* > xNUL 2>NUL" );
if ( 0 < file_len( "xNUL" ) )
then {
printf( "\nxNUL = %u\n\n", file_len( "xNUL" ) );
system( "DEL xNUL_* 2>NUL" );
}
else Unlink( "xNUL" )
#define system safe_ut.ok_system
}
/* public: */ void safe_uts :: ok_system_do( char * comm
/* -----------------------------------------------------------------------------
execute a command as if on the command line
Use system_do iff stdout of the command must not vanish in xNUL_*
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_system_do(")
if ( ! comm || ! *comm ) fErr else _1( comm )
fprintf( stderr, "\n%s", comm );
if iAt( comm, "pskill" ) { KILL( comm ); ret_ }
#undef system
fflush( stdout ); // muss sein
system( comm ); ok
#define system safe_ut.ok_system
LE_
/* public: */ void safe_uts :: ok_system( char * comm
/* -----------------------------------------------------------------------------
execute a command as if on the command line
Wichtig: 2>&1 muss stets ganz am Ende des Kommandos stehen
(d.h. statt exe 2>&1 1>x muss exe > x 2&1 stehen)
Postcondition:
Hat comm die Form ?..., so wird danach sysRes auf eine Kopie des
per 2>&1 nach stdout geschriebenen Outputs zeigen.
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_system(")
if ( !comm || At( comm, "cannot " ) ) fErr2( comm, CWD )
if (1) // Unsinniges unterlassen:
{
char * x = substr( "notepad ", comm );
if ( x )
{
to_space( x ); skip_space( x );
if ( not_is_file( x ) || ! file_len( x ) ) ret_
}
}
if iAt( comm, "pskill" ) { KILL( comm ); ret_ }
BOOL seeRes = ( *comm == '?' );
if ( seeRes )
{
comm += 1 ;
Delete( sysRes );
}
__
#undef system
system( "DEL xNUL* 2>&1 1>NUL" ); ok
char100 xN ; s_( xN, "xNUL_%ld", clock() + clockNr++ );
long i = clock() ;
while path_exists( xN ) s_( xN, "xNUL_%ld", ++i );
char100 e2 ; s_( e2 , " 2> %s" , xN );
char100 e12 ; s_( e12, " 2>&1 1> %s" , xN );
if ( ! comm ) fErr
char * um = in_str( '>', comm )? e2 : e12 ;
if ( *comm == '+' )
then {
comm++ ;
}
else printf( "\nCALL %s (IN: %s)\n", comm, CWD );
// else
if ( iAt( comm, "DEL " ) || iAt( comm, "copy " ) )
then {
char800 com1 ; s_( com1, "%s 2>NUL 1>NUL", comm );
dos_me( com1 );
system( com1 ); ret_
}
esif ( is_( comm, "cls" ) || iAt( comm, "dir " ) )
{
system( comm ); ret_
}
__
BOOL trace = ( *comm == '+' );
if ( trace ) { comm++ ; printf( "\n--> %s", comm ); }
/*
if is( comm, "rm -rf", 6 )
{
char * x = comm + 6 ; while space( *x ) x++ ; rm_tree( x ); ret_
}
*/
if ( strlen( comm ) == 0 ) fErr
char4000 cm ;
if ( *comm != '-' )
then {
sprintf( cm, "%s%s", comm, um ); //now dos_me( cm ):
char * s = comm ; if ( *s == '/' ) *s = '\\' ;
while ( *(++s) ) if ( *s == '/' )
{
if ( s[-1] == ' ' ) break ; else *s = '\\' ;
}
}
else sprintf( cm, "%s%s", comm + 1, um );
__
if ( not_in_str( '>', cm ) && ( At( cm, "rm " )
|| At( cm, "copy " )
))
then {
// s_( eos( cm ) - 1, "%s\n", " 1>>NUL 2>>NUL" );
}
__
if ( not_in_str( '<', cm ) && not_in_str( '|', cm ) )
{
strcat( cm, " < NUL" ); // damit nicht man nicht auf Eingabe wartet
}
if not_substr( "DONE", cm )
if ( tr_files || showComm )
then {
_1( ro_currDir )
printf( "\nsystem: %s\n", cm );
}
if (1)
then {
// Check existence of result fAt position:
{
_1(cm) char * x = in_str( '>', cm );
if ( x && At( x, "&1" ) ) x = in_str( '>', x+1 );
if ( x )
{
// 2>&1 muss immer vor dem eigentlichen > ... stehen
if At( x, ">>" ) goto Lx ; // muss sein
x++ ; skip_space( x );
char * e = x ; while ( *e && not_space( *e ) ) e++ ;
char m = *e ; *e = 0 ;
FILE * f = create( x ); close( f );
*e = m ;
}
}
Lx: // Check existence of executable:
path pro ;
path exe ; strcpy( exe, cm );
char * z = exe ; while ( *z && not_space( *z ) ) z++ ;
if At( z-4, ".exe" ) strcpy( z, "" ); else strcpy( z, ".exe" );
_searchenv( exe, "PATH", pro );
if ( not_At( exe, "mkdir." )
&& not_At( exe, "xcopy." )
&& not_At( exe, "copy." )
&& not_At( exe, "type." )
&& not_At( exe, "del." )
&& not_At( exe, "cmd." )
&& not_At( exe, "cls." )
)
{
if ( ! *pro )
{
strcpy( z, ".bat" ); _searchenv( exe, "PATH", pro );
}
if ( ! *pro )
{
strcpy( z, ".cmd" ); _searchenv( exe, "PATH", pro );
}
if ( ! *pro )
{
*z = 0 ;
if not_in_str( '.', exe )
printf( "\nexe/bat/cmd %s not found on PATH = %s\n"
, exe, getenv( "PATH" ) );
}
if ( *pro && ( tr_files || showComm ) )
{
printf( "\nexe/bat/cmd %s = %s\n", exe, pro );
}
}
}
char * x = substr( "/S/E/R/K ", cm );
x = backtoSucc( cm, "|" );
if ( cm < x )
{
x = in_str( '<', x ); if ( x ) *x = 0 ;
}
//
//
// fprintf( stderr, "\nsystem>2: %s\n", cm );
fflush( stdout );
fflush( stderr );
// _1( cm+11-11 )
#ifdef __WIN_OR_QUICK_WIN__
WinExec( cm, SW_SHOWNORMAL );
#else
system( cm );
#endif
// if isubstr( "taskkill", cm ) errno = 0 ;
if ( showSysCalls ) printf( "\n:: %s", cm );
int err = errno ;
if ( errno )
{
printf( "\nexit.errno = %i", errno );
printf( "\nError: %s", strerror( max( 0, errno ) ) );
char * x = comm ; while ( *x && not_space( *x ) ) x++ ; *x = 0 ;
needsOnPath( comm, 0 );
}
# ifndef __OPTIMIZED__
{
path x ; strcpy( x, comm ) ; S_ "system( '%s' )\n", x _TR
//
// weil 'comm' auch mittels S_ nach exec->ccc geschrieben wurde
}
# endif
// char4000 xx ;
// s_( xx, "echo do : %s >> xNUL" , cm ); system( xx ); ok
// s_( xx, "type %s >> xNUL" , xN ); system( xx ); ok
// s_( xx, "echo done(%i): %s >> xNUL" , err, cm ); system( xx ); ok
// s_( xx, "type %s && del %s" , xN , xN ); system( xx ); ok
if ( trace ) printf( "\n<-- %s", comm );
fflush( stderr );
fflush( stdout );
if ( ! is_file( xN ) ) ret_
s_( cm, "grep error \"%s\"", xN ); system( cm );
#define system safe_ut.ok_system
if ( seeRes && file_len( xN ) )
{
// Let sysRes point to a copy of the content of output 2>&1 :
rBuffer B( xN, "" );
B.z[ B.e ] = 0 ;
sysRes = ( char * ) malloc( B.e+3 - B.a );
strcpy( sysRes, B.z + B.a );
_1(sysRes)
printf( "\n\n%s: %s...\n", xN, sysRes );
}
Unlink( xN )
// if ( is_file( xN ) && file_len( xN ) == 0 ) unlink( xN ); ok
// Nein -- man darf das noch nicht wegwerfen !!!!!!! Warum aber
LE_
/* public: */ uchar safe_uts :: ok_umlaut ( uchar c
// -----------------------------------------------------------------------------
)
{
if ( ( uint )c == 148 ) return( 'o' ); // Umlaut oe
esif ( ( uint )c == 246 ) return( 'o' ); // Umlaut oe
esif ( ( uint )c == 132 ) return( 'a' ); // Umlaut ae
esif ( ( uint )c == 228 ) return( 'a' ); // Umlaut ae
esif ( ( uint )c == 129 ) return( 'u' ); // Umlaut ue
esif ( ( uint )c == 252 ) return( 'u' ); // Umlaut ue
esif ( ( uint )c == 153 ) return( 'O' ); // Umlaut Oe
esif ( ( uint )c == 214 ) return( 'O' ); // Umlaut Oe
esif ( ( uint )c == 142 ) return( 'A' ); // Umlaut Ae
esif ( ( uint )c == 196 ) return( 'A' ); // Umlaut Ae
esif ( ( uint )c == 154 ) return( 'U' ); // Umlaut Ue
esif ( ( uint )c == 220 ) return( 'U' ); // Umlaut Ue
esif ( ( uint )c == 225 ) return( 's' ); // Umlaut sz
esif ( ( uint )c == 223 ) return( 's' ); // Umlaut sz
else return( 0 );
}
/* public: */ char * safe_uts :: ok_ersUmlaute ( char * str
// -----------------------------------------------------------------------------
// ersetzt jeden Umlaut durch den entsprechenden einfachen Buchstaben
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_ersUmlaute")
char * x = str - 1 ;
while ( *(++x) ) if umlaut( *x ) then *x = umlaut( *x );
LE_ret( str )
/* public: */ char * safe_uts :: ok_cutAt
/* -----------------------------------------------------------------------------
return pointer to first substring of 'of' equal to 'part'
-----------------------------------------------------------------------------
*/ (
char * str
, char * ustr
)
LB_("safe_uts.ok_cutAt")
char * x = substr( ustr, str ); if ( x ) *x = 0 ;
LE_ret( x )
/* public: */ char * safe_uts :: ok_subStr
/* -----------------------------------------------------------------------------
return pointer to first substring of 'of' equal to 'part'
starting before the first ee char
-----------------------------------------------------------------------------
*/ (
char * part
, char * of // any string
, char ee // any character
)
LB_("safe_uts.ok_subStr")
int n = strlen( part ); if ( n == 0 ) return( of ) ;
while ( *of != ee )
{
if ( ! memcmp( part, of, n ) ) return( of ) ;
of++ ;
}
LE_ret( 0 )
/* public: */ char * safe_uts :: ok_substr
/* -----------------------------------------------------------------------------
return pointer to first substring of 'of' equal to 'part'
-----------------------------------------------------------------------------
*/ (
char * part
, char * of // any string
)
LB_("safe_uts.ok_substr")
int n = strlen( part ); if ( n == 0 ) return( of ) ;
while ( *of )
{
if ( ! memcmp( part, of, n ) ) return( of ) ;
of++ ;
}
LE_ret( 0 )
/* public: */ char * safe_uts :: ok_subSTR
/* -----------------------------------------------------------------------------
return pointer to first substring of 'of' equal to 'part'
-- compare ignoring case --
-----------------------------------------------------------------------------
*/ (
char * part
, char * of // any string
)
LB_("safe_uts.ok_subSTR")
int n = strlen( part ); if ( n == 0 ) return( of ) ;
while ( *of )
{
if ( ! memicmp( part, of, n ) ) return( of ) ;
of++ ;
}
LE_ret( 0 )
/* public: */ char * safe_uts :: ok_cutstr
/* -----------------------------------------------------------------------------
cut away trailing characters 'tc'
return pointer to end of string (at NULL)
-----------------------------------------------------------------------------
*/ (
char tc //
, char * str // any string
)
LB_("safe_uts.ok_cutstr")
char * c = str ; while( *c ) c++ ; --c ;
while ( str <= c && *c == tc ) *c-- = 0 ;
LE_ret( c+1 )
/* public: */ void safe_uts :: ok_putfw
/* -----------------------------------------------------------------------------
file == ( kopf + satz[] ), effect: file.satz[ n ] = from
-----------------------------------------------------------------------------
*/ (
int f // the open file
, long kL // length of kopf
, long n // nr of satz ( 0 <= n )
, uint sL // length of satz
, void * from // source
)
LB_("safe_uts.ok_putfw")
if ( n < 0 ) fErr1( n ) // _2(f,n+0+0)
long at = kL + n * sL ;
long schr = at - ok_file_len( f ) ;
if ( 0 < schr )
{
lseek( f, 0, SEEK_END ); EE
long sch ; if ( UINT_MAX < schr ) fErr else sch = schr ;
if ( schr != _write( f, from, sch ) ) fErr5( f, kL, n, sL, from )
// notwendig, da DOS nicht erlaubt jenseits des Dateiendes zu schreiben
if ( ok_file_len( f ) != at ) fErr2( at, ok_file_len( f ) )
if ( ok_file_pos( f ) != at ) fErr2( at, ok_file_pos( f ) )
}
else if ( lseek( f, at, SEEK_SET ) != at ) fErr1( f )
int geschr = _write( f, from, sL );
if ( sL - geschr )
{
printf( "\nNo space left on devive (?) - check all your drives" );
S_ "%i = errno, %i = geschr <> sL = %i, at = %u, f = %i\n"
, errno, geschr, sL, at, f _fErr
}
LE_
/* public: */ void safe_uts :: ok_getfw
/* -----------------------------------------------------------------------------
file == ( kopf + satz[] ), effect: to = file.satz[ n ]
-----------------------------------------------------------------------------
*/ (
int f // the open file
, long kL // length of kopf
, long n // nr of satz ( 0 <= n )
, uint sL // length of satz
, void * to // destination
)
LB_("safe_uts.ok_getfw")
long at = kL + n * sL ;
if ( lseek( f, at, SEEK_SET ) != at ) fErr
int gel = _read( f, to, sL ); if ( sL - gel )
if ( sL - gel )
{
if ( file_len( f ) <= at ) fErr5( f, at, n, file_len( f )/sL, errno )
}
sf printf( "\ngel.f = %i", f );
LE_
/* public: */ int safe_uts :: ok_get
/* -----------------------------------------------------------------------------
read 'anz' Bytes from file 'f'
-----------------------------------------------------------------------------
*/ (
FILE * f
, void * to
, int anz
)
LB_("safe_uts.ok_get")
if ( ! f ) fErr
if ( anz <= 0 ) fErr
LE_ret( fread( to, 1, anz, f ) )
/* public: */ void safe_uts :: ok_get
/* -----------------------------------------------------------------------------
read exactly 'anz' Bytes from file 'f'
-----------------------------------------------------------------------------
*/ (
int f
, void * to
, int anz
)
LB_("safe_uts.ok_get")
if ( ok_get_more( f, to, anz ) != anz ) fErr
LE_
/* public: */ int safe_uts :: ok_get_more
/* -----------------------------------------------------------------------------
read at most 'anz' Bytes from file 'f'
-----------------------------------------------------------------------------
*/ (
int f
, void * to
, int anz
)
LB_("safe_uts.ok_get_more")
if ( f < 0 ) fErr
if ( anz <= 0 ) { L1_( anz ) if ( anz < 0 ) fErr }
LE_ret( read( f, to, anz ) )
/* public: */ int safe_uts :: ok_get_more
/* -----------------------------------------------------------------------------
read at most 'anz' Bytes from file 'f'
-----------------------------------------------------------------------------
*/ (
FILE * f
, void * to
, int anz
)
LB_("safe_uts.ok_get_more")
if ( ! f ) fErr
if ( anz <= 0 ) { L1_( anz ) if ( anz < 0 ) fErr }
LE_ret( fread( to, 1, anz, f ) )
/* public: */ void safe_uts :: ok_put
/* -----------------------------------------------------------------------------
write 'anz' Bytes to file 'f'
-----------------------------------------------------------------------------
*/ (
FILE * f
, void * from
, int anz
)
LB_("safe_uts.ok_put")
if ( ! f ) fErr else if ( anz <= 0 ) ret_ // nur == tut's nicht
int rc = fwrite( from, 1, anz, f );
if ( rc != anz )
{
show_str( "WRITE", ( char * )from, anz );
S_ "rc = %i <> %i = anz, f = %p \n", rc, anz, f _fErr
}
LE_
/* public: */ void safe_uts :: ok_put
/* -----------------------------------------------------------------------------
write 'anz' Bytes to file 'f'
-----------------------------------------------------------------------------
*/ (
int f
, void * from
, int anz
)
LB_("safe_uts.ok_put")
if ( ! f ) fErr else if ( anz <= 0 ) ret_ // nur == tut's nicht
int rc = write( f, from, anz );
if ( rc != anz )
{
show_str( "WRITE", ( char * )from, anz );
S_ "rc = %i <> %i = anz, f = %i \n", rc, anz, f _fErr
}
LE_
/* public: */ int safe_uts :: ok_clone
/* -----------------------------------------------------------------------------
clone string 'str' to 'destin', return length of string
-----------------------------------------------------------------------------
*/ (
char * & dest
, char * str
)
LB_("safe_uts.ok_clone")
int L = strlen( str ); dest = new char[ L+1 ] ;
memcpy( dest, str, L+1 );
LE_ret( L )
#ifndef __SIMPLE__
/* public: */ void safe_uts :: ok_temp_file
/* -----------------------------------------------------------------------------
Create and open a new temporary file %tmprestN, 1 <= N .
-----------------------------------------------------------------------------
*/ (
FILE * & opn_tf
, path_ref tf // out
, char * rest // in
)
LB_("safe_uts.ok_temp_file")
tf[ L_path - 1 ] = '?' ;
strcpy( tf, getenv( "TMP" ) ); subdir( tf, rest );
if ( ! tf[2] ) { if ( tf[1] == ':' ) memcpy( tf + 2, "/", 2 ); }
dir_exist( tf );
int n = 0 ; opn_tf = 0 ; int e = strlen( tf );
struct stat B ;
while ( ! opn_tf )
{
sprintf( tf + e, "\\%i", ++n ); stat( tf, &B );
if no_such_file
then {
ok ; opn_tf = fopen( tf, "w+" );
if ( ! opn_tf ) create( opn_tf, tf ); // for a fine message
}
esif ( errno ) fErr
}
if ( tf[ L_path - 1 ] != '?' ) { errno = EN_corrupted_data ; fErr }
LE_
/* public: */ void safe_uts :: ok_show_str
/* -----------------------------------------------------------------------------
output to stdout for debugging - use macros Z1_ Z2_
-----------------------------------------------------------------------------
*/ (
char * name // string
, char * a1 // any text, a1 <= a2
, char * a2 //
, int n // n <= 0
)
LB_("safe_uts.ok_show_str")
char sss[ L_sss ] ; int m = a2 - a1 + n + 4 ;
if ( a2 < a1 ) fErr
if ( n < 0 ) fErr
if ( L_sss <= m ) a1 += m - L_sss ;
if ( a1 < a2 ) memcpy( sss , a1 , a2 - a1 );
memcpy( sss + ( a2 - a1 ), "]+[", 3 );
memcpy( sss + ( a2 - a1 + 3 ), a2 , n );
sss[ a2 - a1 + 3 + n ] = 0 ;
printf( "\n%s = ...[%s]... \n", name, sss );
LE_
/* public: */ BOOL safe_uts :: ok_in_name ( uchar c
// -----------------------------------------------------------------------------
)
{
if ( c == '$' ) return( 1 );
if ( c == '_' ) return( 1 ); else return( ok_alphanum( c ) );
}
/* public: */ BOOL safe_uts :: ok_in_nameStr
// -----------------------------------------------------------------------------
(
uchar c
, char * str
)
{
if ( ! str ) ret( in_name( c ) ) else
ret( in_name( c ) || in_str( c, str ) )
}
/* public: */ BOOL safe_uts :: ok_alphanum
// -----------------------------------------------------------------------------
(
uchar c
)
{
if ( isalpha( c ) ) return( 1 );
esif ( isdigit( c ) ) return( 1 ); else return( ok_umlaut( c ) );
}
/* public: */ BOOL safe_uts :: ok_alpha
// -----------------------------------------------------------------------------
(
uchar c
)
{
if ( isalpha( c ) ) return( 1 ); else return( ok_umlaut( c ) );
}
/* public: */ BOOL safe_uts :: ok_XMLName ( uchar c
// -----------------------------------------------------------------------------
)
{
if ( (char) c == ':' ) return( 1 );
if ( ( uchar ) 'a' <= c && c <= ( uchar ) 'z' ) return( 1 );
if ( ( uchar ) 'A' <= c && c <= ( uchar ) 'Z' ) return( 1 );
if ( ( uchar ) '0' <= c && c <= ( uchar ) '9' ) return( 1 );
return( c == '-' );
}
/* public: */ void safe_uts :: to_upper
/* -----------------------------------------------------------------------------
copy thereby transforming to upper
-----------------------------------------------------------------------------
*/ (
char * to
, char * from
)
{
while ( *from ) *to++ = toupper( *from++ ) ; *to = 0 ;
}
/* public: */ char safe_uts :: to_upper
/* -----------------------------------------------------------------------------
Damit man auch ... = toupper( *c++ ) sagen kann
-----------------------------------------------------------------------------
*/ (
char c
)
{
return( toupper( c ) );
}
/* public: */ char * safe_uts :: to_lower
/* -----------------------------------------------------------------------------
copy thereby transforming to lower, return end of 'to'
-----------------------------------------------------------------------------
*/ (
char * to
, char * from
)
{
while ( *from ) *to++ = tolower( *from++ ) ; *to = 0 ;
return( to );
}
/* public: */ void safe_uts :: to_lower
// -----------------------------------------------------------------------------
(
char * c
, int n
)
{
if ( n == -1 ) n = strlen( c );
for ( int i = 0 ; i < n ; i++ ) c[i] = tolower( c[i] );
}
/* public: */ void safe_uts :: to_upper
// -----------------------------------------------------------------------------
(
char * c
, int n
)
{
if ( n == -1 ) n = strlen( c );
for ( int i = 0 ; i < n ; i++ ) c[i] = toupper( c[i] );
}
/* public: */ char safe_uts :: to_lower
/* -----------------------------------------------------------------------------
Damit man auch ... = lower( *c++ ) sagen kann
-----------------------------------------------------------------------------
*/ (
char c
)
{
return( tolower( c ) );
}
/* public: */ char * safe_uts :: to_lower( char * str
// -----------------------------------------------------------------------------
)
LB_("safe_uts.to_lower(")
if ( ! str ) fErr
char * c = str-1 ; while( *( ++c ) ) *c = tolower( *c );
LE_ret( str )
/* public: */ char * safe_uts :: to_upper( char * str
// -----------------------------------------------------------------------------
)
LB_("safe_uts.to_upper(")
if ( ! str ) fErr
char * c = str-1 ; while( *( ++c ) ) *c = toupper( *c );
LE_ret( str )
/* public: */ void safe_uts :: ok_show_ascii
// -----------------------------------------------------------------------------
(
char * str1
, char * str1n // name of str1
, char * str2
, char * str2n // name of str2
, int n
)
{
int i = -1 ;
S_ "\n------------- ascii( %s, %s, %i ): \n", str1n, str2n, n _TR_a
while ( ++i < n )
{
S_ "%5i: .%3u .%3u \n", i, (uchar)str1[i], (uchar)str2[i] _TR_a
}
}
/* public: */ BOOL safe_uts :: ok_reduce_current
/* -----------------------------------------------------------------------------
if ( dir == current_dir ) strcpy( dir, "." )
-----------------------------------------------------------------------------
*/ (
char * dir
)
LB_("safe_uts.ok_reduce_current")
path x ; strcpy( x, dir ); strcat( x, "\\_" );
FILE * f ; create( f, "_" ); close( f );
if ( path_exists( x ) ) strcpy( dir, "." );
Unlink( "_" );
LE_ret( is_( dir, "." ) )
/* public: */ void safe_uts :: ok_subdir
/* -----------------------------------------------------------------------------
add something to the path
-----------------------------------------------------------------------------
*/ (
char * dir
, char * plus
)
LB_("safe_uts.ok_subdir")
if ( ! dir || ! plus ) fErr
char * x = dir ; while ( *x ) x++ ; x-- ;
if ( *x != '/' && *x != '\\' ) *( ++x ) = '\\' ;
char * s = plus ; while ( *s == '/' || *s == '\\' ) s++ ;
memcpy( ++x, s, strlen( s ) + 1 );
LE_
/* public: */ int safe_uts :: ok_get_word
/* -----------------------------------------------------------------------------
get word and its length
-----------------------------------------------------------------------------
*/ (
char * to // path &
, char * from
, char * at
)
LB_("safe_uts.ok_get_word")
int s = strlen( at ); int j = 0 ;
while ( *from )
{
if ( *at == 0 || is( from, at, s ) )
then {
from += s ;
while in_name( *from ) to[ j++ ] = *from++ ;
if ( j == L_path )
{
to[ L_path - 1 ] = 0 ; S_ "to[%s]", to _fErr
}
to[ j ] = 0 ;
ret( j );
}
else from++ ;
}
to[ 0 ] = 0 ;
LE_ret( -1 )
/* public: */ void safe_uts :: ok_add_to_path
/* -----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ (
char * to
, char * add
)
LB_("safe_uts.ok_add_to_path")
if ( ! to ) fErr
if ( ! add ) fErr
if ( *to )
then {
strcat( to, "\\" ); strcat( to, add );
}
else strcpy( to, add );
LE_
/* public: */ char safe_uts :: ok_is_a ( char * atx
/* -----------------------------------------------------------------------------
Return 'd' if directory
Return 'f' if file
Return 'n' if not exists
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_is_a")
if substr( "Sto", atx ) printf( "\nis_file? : %s", atx );
char800 at ; strcpy( at, atx ); dos_me( at );
char * x = eos( at ) - 1 ;
if ( *x == '\\' ) Ret( 0, 'd' ) // muss sein
while ( *x == '\\' ) *x-- = 0 ; // muss sein
if ( ! at ) fErr
if ( ! *at ) ret( 'd' ) // current directory
if ( *at == ':' ) ret( 'n' ) // otherwise NT exception thrown
if ( *at == ' ' ) ret( 'n' ) // otherwise NT exception thrown
struct stat st ; stat( at, &st );
if (0) printf( "\nerrno = %i, mode & S_IFDIR = %i, f = %s"
, errno, st.st_mode & S_IFDIR, at );
int errNr = errno ; ok // _2(errNr,atx)
if ( errNr == 2 ) Ret( 0, 'n' )
if ( no_such_file ) Ret( 0, 'n' )
if ( st.st_mode & S_IFDIR ) Ret( 0, 'd' )
if ( errNr )
{
// if is_( eos( at ) - 4, ".pdf" ) { errno = 0 ; ret( 'f' ) }
// if is_( eos( at ) - 4, ".doc" ) { errno = 0 ; ret( 'f' ) }
// if is_( eos( at ) - 4, ".htm" ) { errno = 0 ; ret( 'f' ) }
printf( "\nACL at %s:\n", at );
// ret( '
fflush( stdout );
S_ "cacls \"%s\"", at _Do // to show access permissions (i.e. ACLs)
printf( "stat( %s ) does not return a result (errno %i):\n"
"currDir = %s\n%s", at, errNr, CWD, eM );
Ret( 0, 'n' )
{
m_errMess "System: stat( %s ) does not return a result (errno %i):\n"
"currDir = %s\n%s" m_
at, errNr, CWD, eM, ret_error
}
;
}
__
LE_ret( 'f' )
/* public: */ void safe_uts :: ok_cp_tree
// -----------------------------------------------------------------------------
(
char * nach
, char * tree
)
LB_("safe_uts.ok_cp_tree")
if ( ! tree || not_is_dir( tree ) )
{
m_errMess "System: no such folder: %s" m_
tree, ret_error
}
if ( ! nach ) fErr1( nach )
char1000 xx ; s_( xx, "\"%s\" \"%s\"/", tree, nach ); dos_me( xx );
char * nt = getenv( "is_NT" );
nt = ( nt && *nt == '1' )? "/S/E/R/K > NUL" : "/S/E/R/K/Y > NUL < NUL" ;
nt = ( 0 )? "/S/E/R/K > NUL" : "/S/E/R/K/Y > NUL < NUL" ;
S_ "-xcopy %s %s", xx, nt _Do
LE_
/* public: */ void safe_uts :: ok_cp_tree
// -----------------------------------------------------------------------------
(
char * to
, char * from
, BOOL create_dirs // as far as path 'to not yet exists
)
LB_("safe_uts.ok_cp_tree")
if ( ! to ) fErr
if ( ! from ) fErr
if ( ! *from ) fErr
if ( ! *to ) fErr
struct stat st ; stat( to, &st ); int attr = st.st_mode ;
BOOL to_is_file, to_is_dir ;
if no_such_file_or_dir
then {
to_is_dir = to_is_file = 0 ;
}
else {
EE to_is_dir = ( attr & S_IFDIR ); to_is_file = ( ! to_is_dir );
}
ok stat( from, &st ); attr = st.st_mode ;
if no_such_file_or_dir
then {
S_ "not found( %s )\n", from _fErr
}
else { EE }
if ( attr & S_IFDIR ) // hier & statt &&
then {
if ( to_is_file && ! create_dirs )
{
S_ "cannot copy dir to file( %s )\n", to _fErr
}
char1000 frmNch ; s_( frmNch, "\"%s\" \"%s/\"", from, to );
char * nt = getenv( "is_NT" );
nt = ( nt && *nt == '1' )? "/S/E/R/K > NUL" : "/S/E/R/K/Y >NUL <NUL" ;
nt = ( 0 )? "/S/E/R/K > NUL" : "/S/E/R/K/Y >NUL <NUL" ;
S_ "-xcopy %s %s", xx, nt _Do
dos_me( frmNch );
S_ "-xcopy %s %s > NUL", frmNch, nt _Do
// /Y unterdrckt Prompting - funktioniert aber nicht unter NT (!)
}
esif ( to_is_dir )
{
S_ "cannot copy file to dir( %s )\n", to _fErr
}
else {
char * c = to + strlen( to );
while ( to < c && *c != '\\' ) c-- ;
if ( to < c )
then {
*c = 0 ; dir_exist( to ); *c = '\\' ;
}
cp_file( to, from );
}
if ( ! path_exists( to ) ) fErr2( from, to )
LE_
#ifdef SYMANTEC
/* public: */ void safe_uts :: ok_see_tree
/* -----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ (
char * from
, FILE * f
, int br
)
LB_("safe_uts.ok_see_tree")
if ( ! f ) fErr
if ( ! from ) fErr
if ( ! path_exists( from ) ) S_ "cannot find %s\n", from _fErr
int e_from = strlen( from ); from[ e_from ] = '\\' ;
memcpy( from + e_from, "\\*.*", 5 );
find_1st( from );
while ( gefunden )
{
FIND gef = *gefunden ;
strcpy( from + e_from + 1, gef.name );
to_lower( gef.name, gef.name );
if ( gef.attribute == FA_DIREC )
then {
if ( not_is_( gef.name, ".." )
&& not_is_( gef.name, "." )
&& not_is_( gef.name, "INDX" )
&& not_is_( gef.name, "indx" )
)
then ok_see_tree( from, f, br );
}
else {
#undef open
#ifndef DOS
int fd = _open( from, O_RDONLY | _O_BINARY );
ftime zp ; getftime( fd, &zp ); EE
fprintf( f, "%12s %8li %4i_%2i_%2i %2i:%2i %*s%s\n"
, gef.name
, file_len( from )
, zp.ft_year + 1980
, zp.ft_month
, zp.ft_day
, zp.ft_hour
, zp.ft_min
, br, "", from
);
#else
ok int fd = _open( from, O_RDONLY | _O_BINARY );
unsigned d, t, tag, monat, jahr, std, min, sec ;
dos_getftime( fd, &d, &t ); close( fd );
tag = ( d ) & 31 ; // Bits 0-4
monat = ( d >> 5 ) & 15 ; // Bits 5-8
jahr = ( d >> 9 ) & 255 ; // Bits 9-15 + Jahr 1980
sec = ( t ) & 31 ;
min = ( t >> 5 ) & 63 ;
std = ( t >> 11 ) & 63 ; path x ;
sprintf( x, "%12s %8li %4i_%2i_%2i %2i:%2i %*s%s\n"
, gef.name
, file_len( from )
, jahr + 1980
, monat
, tag
, std
, min
, br, "", from
);
if ( x[28] == ' ' ) x[28] = '.' ;
if ( x[32] == ' ' ) x[32] = '.' ;
if ( x[34] == ' ' ) x[34] = '.' ;
if ( x[37] == ' ' ) x[37] = '.' ;
fprintf( f, x );
#endif
#define open safe_ut.ok_open
}
find_next
}
ok from[ e_from ] = 0 ;
LE_
/* public: */ void safe_uts :: ok_cp_ms_project
/* -----------------------------------------------------------------------------
copy MS Project (relevant files only) if 'from not 'to
If 'from is 'to, just prune the MS Project.
Der Aufrufer garantiert: Beide Pfade in DOS-Format
-----------------------------------------------------------------------------
*/ (
char * to
, char * from
, BOOL add // additive or deleting old version first
)
LB_("safe_uts.ok_cp_ms_project")
if ( ! to ) fErr
if ( ! from ) fErr
if ( ! path_exists( from ) ) S_ "cannot find %s\n", from _fErr
BOOL prune = is_( to, from );
if ( ! add && ! prune ) dir_exist_empty( to );
int e_from = strlen( from ); from[ e_from ] = '\\' ;
int e_to = strlen( to ); to [ e_to ] = '\\' ;
memcpy( from + e_from, "\\*.*", 5 );
find_1st( from ); int anz = 0 ;
while ( gefunden )
{
FIND gef = *gefunden ;
if ( errno ) S_ "from( %s ), to( %s )", from, to _fErr
char * c = gef.name ; while ( *c && *c != '.' ) c++ ;
path ext ; to_lower( ext, c );
if ( prune )
then {
if ( is_( ext, ".vcw" )
|| is_( ext, ".cvw" )
|| is_( ext, ".aps" )
|| is_( ext, ".wsp" )
|| is_( ext, ".clw" )
|| is_( ext, ".err" )
|| is_( ext, ".tmp" )
|| is_( ext, ".bak" )
|| is_( ext, ".i" )
|| is_( ext, ".sbr" ) // work environment
|| is_( ext, ".bsc" )
|| is_( ext, ".pdb" )
|| is_( ext, ".pch" ) // precompiled header files
|| is_( ext, ".res" )
|| is_( ext, ".obj" )
|| is_( ext, ".lib" )
|| is_( ext, ".exe" )
)
then {
strcpy( from + e_from + 1, gef.name );
Unlink( from );
}
esif ( gef.attribute == FA_DIREC && *gef.name != '.' )
{
gef.name[ 0 ] = lower( gef.name[ 0 ] );
gef.name[ 1 ] = lower( gef.name[ 1 ] );
gef.name[ 2 ] = lower( gef.name[ 2 ] );
if ( not_is_( gef.name, "exe" )
&& not_is_( gef.name, "lib" )
)
then {
strcpy( from + e_from + 1, gef.name );
cp_ms_project( to, from, 1 );
}
}
}
esif ( not_is_( ext, ".vcw" )
&& not_is_( ext, ".cvw" )
&& not_is_( ext, ".aps" )
&& not_is_( ext, ".wsp" )
&& not_is_( ext, ".clw" )
&& not_is_( ext, ".err" )
&& not_is_( ext, ".tmp" )
&& not_is_( ext, ".bak" )
&& not_is_( ext, ".sbr" ) // work environment
&& not_is_( ext, ".bsc" )
&& not_is_( ext, ".pdb" )
&& not_is_( ext, ".pch" ) // precompiled header files
&& not_is_( ext, ".res" )
&& not_is_( ext, ".obj" )
&& not_is_( ext, ".lib" )
&& not_is_( ext, ".exe" )
&& not_is_( ext, "." )
&& not_is_( ext, ".." )
)
then {
strcpy( from + e_from + 1, gef.name );
strcpy( to + e_to + 1, gef.name );
if ( gef.attribute == FA_DIREC )
then {
cp_ms_project( to, from, 1 );
}
esif ( anz ) S_ "copy %s %s > NUL ", from, to _Do
else {
cp_tree( to, from, 0 ); anz = 1 ;
}
}
find_next
}
ok
from[ e_from ] = 0 ;
to [ e_to ] = 0 ;
LE_
/* public: */ void safe_uts :: ok_get_header_files
/* -----------------------------------------------------------------------------
Der Aufrufer garantiert: Pfad 'from' in DOS-Format
-----------------------------------------------------------------------------
*/ (
FILE * hfs
, char * from // tree
)
LB_("safe_uts.ok_get_header_files")
if ( ! hfs ) fErr
if ( ! from ) fErr
if ( ! path_exists( from ) ) S_ "cannot find %s\n", from _fErr
int e_from = strlen( from ); from[ e_from ] = '\\' ;
memcpy( from + e_from, "\\*.*", 5 );
find_1st( from ); int anz = 0 ;
while ( gefunden )
{
FIND gef = *gefunden ;
if ( errno ) S_ "from( %s )\n", from _fErr
char * c = gef.name + strlen( gef.name ) - 1 ;
while ( gef.name < c && *c != '.' ) c-- ;
char ext[ 32 ] ; to_lower( ext, c );
strcpy( from + e_from + 1, gef.name );
if ( not_is_( ext, ".h" )
&& not_is_( ext, ".h2" )
)
then {
if ( gef.attribute == FA_DIREC )
then {
if ( not_is_( ext, "." )
&& not_is_( ext, ".." )
)
then ok_get_header_files( hfs, from );
else ;
}
}
else fprintf( hfs, "\n- %s", from );
find_next
}
ok
from[ e_from ] = 0 ;
LE_
#endif
#ifdef SYMANTEC
/* public: */ void safe_uts :: ok_Do
/* -----------------------------------------------------------------------------
Call '( comm f ) for all files 'f.with_extension in tree 'from
-----------------------------------------------------------------------------
*/ (
char * comm
, char * from
, char * with_extension
, BOOL also_subdirs
)
LB_("safe_uts.ok_Do")
if ( ! from ) fErr
if ( ! path_exists( from ) ) S_ "cannot find %s\n", from _fErr
int e_from = strlen( from );
memcpy( from + e_from, "\\*.*", 5 );
find_1st( from );
while ( gefunden )
{
FIND gef = *gefunden ;
if ( errno ) S_ "from( %s )\n", from _fErr
char * e = gef.name + strlen( gef.name ) - 1 ;
while ( gef.name < e && *e != '.' ) e-- ;
char ext[ 32 ] ; to_lower( ext, e );
if ( gef.attribute == FA_DIREC && also_subdirs
&& *gef.name != '.' )
then {
strcpy( from + e_from + 1, gef.name );
ok_Do( from, comm, with_extension, also_subdirs );
}
esif is_( ext + 1, with_extension )
{
*e = 0 ;
strcpy( from + e_from + 1, gef.name );
S_ "%s %s", comm, from _Do
}
find_next
}
ok
from[ e_from ] = 0 ;
LE_
#endif
#ifdef GNU
#undef find_1st
#undef name
#undef attrib
#endif
/* public: */ void safe_uts :: ok_max_str
/* -----------------------------------------------------------------------------
assert strlen( str ) < max
-----------------------------------------------------------------------------
*/ (
int max
, char * str
, char * file
, int line
)
LB_("safe_uts.ok_max_str")
char * x1 = str ;
char * x2 = str + max ;
while ( *x1 && x1 < x2 ) x1++ ;
if ( x2 == x1 )
{
*x2 = 0 ; S_ "Error in at %i.%s: \n"
"%i < strlen( %s... )\n", line, file, max, str _fErr
}
LE_
/* private: */ void safe_uts :: rm_tree_
/* -----------------------------------------------------------------------------
remove tree (nur aus ok_rm_tree heraus aufgerufen)
-----------------------------------------------------------------------------
*/ (
char * rm
, int e_rm
)
LB_("safe_uts.rm_tree_")
fErr
//
S_ "-echo y | rmdir %s /s > NUL", rm _Do ret_
LE_
/* public: */ void safe_uts :: ok_rm_tree
/* -----------------------------------------------------------------------------
remove tree or file 'rm (if it exists)
-----------------------------------------------------------------------------
*/ (
char * tree
)
LB_("safe_uts.ok_rm_tree")
if ( ! tree ) fErr
if ( ! *tree ) fErr
path rm ; dos_expansion( rm, tree );
struct stat st ;
if ( stat( rm, &st ) )
then {
if ( no_such_file_or_dir ) { ok ret_ } else fErr
}
int attr = st.st_mode ;
if ( attr & S_IFDIR )
then {
S_ "rm -rf \"%s\" 2>&1 > NUL", rm _Do
// S_ "-rmdir /s \"%s\" > NUL", rm _Do /// far too slow !!!
if path_exists( rm )
{
// ?errU "cannot delete folder %s", rm )
printf( "\nW a r n i n g : Cannot delete folder %s\n", rm );
S_ "-rm -rf \"%s/*\" 2>&1 > NUL", rm _Do
S_ "dir %s", rm _Do
}
}
else Unlink( rm )
LE_
/* public: */ void safe_uts :: ok_cp_file
/* -----------------------------------------------------------------------------
cp_file( to + postfix, from + postfix )
-----------------------------------------------------------------------------
*/ (
char * to
, char * from
, char * postfix
)
LB_("safe_uts.ok_cp_file")
if ( ! to ) fErr
if ( ! from ) fErr
if ( ! postfix ) fErr
path t1 ; sprintf( t1, "%s%s", to , postfix );
path f1 ; sprintf( f1, "%s%s", from, postfix );
ok_cp_file( t1, f1 );
LE_
/* public: */ void safe_uts :: ok_cp_file
/* -----------------------------------------------------------------------------
copy file
-----------------------------------------------------------------------------
*/ (
char * to
, char * from
)
LB_("safe_uts.ok_cp_file")
if(1)
{{
// if substr( "Atomare-", to )
// if substr( "01.", to ) fErr2( to, from )
if substr( "assets/pic", from ) printf( "\ncp_file: %s -> %s\n", from, to );
if(0) if substr( "core/Schu", to )
{
printf( "\nfNEU: call_nr %i, %s\n", call_nr, from );
}
// if substr( "177.", to )
}}
if ( ! to ) fErr
if not_is_file( from )
{
{
m_errMess "System: cp_file: from (= %s ) not found, CWD = %s" m_
from, CWD, ret_error
}
}
new_dos_fn( fdos, from );
new_dos_fn( tdos, to );
CopyFile( fdos, tdos, 0 );
if not_is_file( tdos )
{
m_errMess "System: cannot copy: %s --> %s\n" m_
fdos, tdos, ret_error
}
;
path x ; strcpy( x, to ); unix_me( x );
if ( neuNam && substr( neuNam, x ) )
{
printf( "\nNEU: neuNr %i: cp_file %s to: %s", ++neuNrs, from, x );
if ( neuNrs == neuNrMax ) fErr1( x )
}
LE_
/* public: */ void safe_uts :: ok_cp_file
/* -----------------------------------------------------------------------------
copy file + create target dir (if it does not exist)
-----------------------------------------------------------------------------
*/ (
char * to
, char * from
, BOOL force
)
LB_("safe_uts.ok_cp_file")
if ( force )
{
char * e = eos( to ) - 1 ;
while ( to <= e && not_in_str( *e, "/\\" ) ) e-- ;
if ( to < e )
{
char m = *e ; *e = 0 ; dir_exist( to ); *e = m ;
}
}
cp_file( to, from );
LE_
/* public: */ char * safe_uts :: ok_in_str
/* -----------------------------------------------------------------------------
return BOOL( c in string str )
-----------------------------------------------------------------------------
*/ (
char c
, char * str
)
LB_("safe_uts.ok_in_str")
if ( ! str ) fErr
while ( *str ) if ( *str++ == c ) ret( str-1 )
LE_ret( 0 )
/* public: */ BOOL safe_uts :: ok_is_prefix
/* -----------------------------------------------------------------------------
return BOOL( pre is prefix of str )
-----------------------------------------------------------------------------
*/ (
char * pre
, char * str
)
LB_("safe_uts.ok_is_prefix")
if ( ! pre ) fErr
if ( ! str ) fErr
while ( *pre ) if ( *pre++ != *str++ ) ret( 0 )
LE_ret( 1 )
/* public: */ void safe_uts :: ok_f_to_dir
/* -----------------------------------------------------------------------------
copy into directory
-----------------------------------------------------------------------------
*/ (
char * f // copy f to/f
, char * to //
, BOOL exist // create destination dir 'to' if necessary
, BOOL move_it // delete the original file
)
LB_("safe_uts.ok_f_to_dir")
if ( ! f ) fErr
if ( ! to ) fErr
if ( exist ) dir_exist( to );
char * c = to + strlen( to ) - 1 ;
while ( to < c && ! in_str( *c, "/:\\" ) ) c-- ;
path x ; sprintf( x, "%s\\%s", to, c ); cp_file( x, f );
if ( move_it ) Unlink( f )
LE_
/* public: */ void safe_uts :: ok_cp_section
/* -----------------------------------------------------------------------------
copy the specified section of the file
-----------------------------------------------------------------------------
*/ (
char * to
, char * from
, long a
, long e
)
LB_("safe_uts.ok_cp_section")
if ( ! to ) fErr
int f = open( from, 'r', 'B' );
int t = open( from, 'c', 'B' );
seek( f, a, SEEK_SET );
long sum = 0 ;
char * B = ( char * ) malloc( 16400 ); int gel = 16384 ;
while ( gel == 16384 )
{
gel = read( f, B, 16384 ); EE
if ( sum + gel < e ) sum += gel ; else gel = e - sum ;
if ( 0 < gel ) { if ( write( t, B, gel ) != gel ) fErr }
}
close( f );
close( t ); free( B );
LE_
/* public: */ char * safe_uts :: ok_dir_at
/* -----------------------------------------------------------------------------
make 'dir the father node of place 'at
-----------------------------------------------------------------------------
*/ (
char * dir
, char * at
)
LB_("safe_uts.ok_dir_at")
strcpy( dir, at ); char * e = dir + strlen( dir );
while ( dir < e && *e != '/' && *e != '\\' && *e != ':' ) e-- ;
if ( dir == e )
then {
if ( *e != '/' && *e != '\\' && *e != ':' ) *e++ = ' ' ;
}
*e = 0 ;
LE_ret( e )
/* public: */ void safe_uts :: ok_def_subset
/* -----------------------------------------------------------------------------
specify 'cf (= subset of char)
-----------------------------------------------------------------------------
*/ (
char * cf // characteristic function of subset
, char * str // subset charcters up to 'e (so that the NULL
, char e // character may also be element of the set)
)
LB_("safe_uts.ok_def_subset")
if ( ! cf || ! str ) fErr
for ( int r = 0 ; r < 256 ; ) cf[ r++ ] = 0 ;
while ( *str != e ) cf[ ( uchar ) *str++ ] = 1 ;
cf[e] = 1 ;
LE_
/* public: */ void safe_uts :: ok_goto_str
/* -----------------------------------------------------------------------------
while not_is_( c, str ) c++ ; ...
-----------------------------------------------------------------------------
*/ (
char * & c //
, char * str // c to this string
, int n1 // c + n1
, char c1 // and then c to this char
)
LB_("safe_uts.ok_goto_str")
char x = *str ; int n = strlen( str );
while not_is( c, str, n ) { c++ ; while ( *c != x ) c++ ; }
if ( n1 )
then {
c += n1 ; while ( *c != c1 ) c++ ;
}
LE_
/* public: */ BOOL safe_uts :: ok_goto_str
/* -----------------------------------------------------------------------------
while not_is_( c, str ) c++ ; ...
-----------------------------------------------------------------------------
*/ (
char * & c //
, char * str // c to this string
, char * e // end search here at the latest (with fErr)
)
LB_("safe_uts.ok_goto_str")
char x = *str ; int n = strlen( str ); char * a = c ;
while not_is( c, str, n )
{
if ( e <= ++c ) { show_str( "EE", a, e-a ); L1_( str ) ret( 0 ) }
while ( c < e && *c != x ) c++ ;
}
LE_ret( true )
#include rbuffer.h : cpp
/* public: */ void safe_uts :: ok_copy
/* -----------------------------------------------------------------------------
make 'to' a copy of file 'from'
-----------------------------------------------------------------------------
*/ (
char * from
, char * to
)
LB_("safe_uts.ok_copy")
path comm ; sprintf( comm, "copy \"%s\" \"%s\" > NUL", from, to );
dos_me( comm ); S_ comm _Do
LE_
/* public: */ void safe_uts :: ok_copy
/* -----------------------------------------------------------------------------
make 'to' a copy of file 'from'
-----------------------------------------------------------------------------
*/ (
char * from
, FILE * f
)
LB_("safe_uts.ok_copy")
rBuffer B( from, "" ); B.copy_to( f );
LE_
/* public: */ void safe_uts :: ok_move
/* -----------------------------------------------------------------------------
move the file
-----------------------------------------------------------------------------
*/ (
char * from
, char * to
)
LB_("safe_uts.ok_move")
copy( from, to ); Unlink( from )
LE_
/* public: */ void safe_uts :: ok_execute
/* -----------------------------------------------------------------------------
execute file cf containing commands of the following form:
-/cp_into &1 &2
-/cp &1 &2
-/rm &1
-----------------------------------------------------------------------------
*/ (
char * cf
)
LB_("safe_uts.ok_execute")
if ( ! cf ) fErr
rBuffer B( cf, "\n\n" );
while ( B.find( 0, "\n-/", 0 ) )
{
B.a = B.s + 3 ;
char * c = B.z + B.a ;
char * c1 ;
char * c2 ;
char * c3 ;
if is( c, "cp ", 3 )
then {
c += 3 ;
while space( *c ) c++ ; c1 = c ;
while not_space( *c ) c++ ; *c++ = 0 ;
while space( *c ) c++ ; c2 = c ;
while not_space( *c ) c++ ; *c = 0 ;
cp_file( c2, c1 );
}
esif is( c, "cp_into ", 8 )
then {
c += 8 ;
while space( *c ) c++ ; c1 = c ;
while not_space( *c ) c++ ; *c++ = 0 ; c3 = c-1 ;
while space( *c ) c++ ; c2 = c ;
while not_space( *c ) c++ ; *c = 0 ;
while ( ! ( space( *c3 ) || in_str( *c3, "/:\\" ) ) ) c3-- ;
path to ; sprintf( to, "%s\\%s", c2, ++c3 );
cp_file( to, c1 );
}
esif is( c, "rm ", 3 )
then {
c += 3 ;
while space( *c ) c++ ; c1 = c ;
while not_space( *c ) c++ ; *c = 0 ;
rm_tree( c1 );
}
else fErr
*c = '\n' ;
}
LE_
#endif
/* public: */ BOOL safe_uts :: ok_access
/* -----------------------------------------------------------------------------
Return errno that would result, when we try to open the file
in mode O_RDWR
-----------------------------------------------------------------------------
*/ (
char * fn
)
LB_("safe_uts.ok_access")
if ( ! fn ) fErr
path file ; expansion( file, fn ); // S_ "access %s\n", file _TR
#undef open
int f = _open( file, O_RDWR );
#define open safe_ut.ok_open
if ( f == -1 ) ret( errno ) else close( f );
LE_ret( 0 )
/* public: */ long safe_uts :: ok_time_of
/* -----------------------------------------------------------------------------
return time of last update to the file
or 0 if the file not exists
-----------------------------------------------------------------------------
*/ (
char * file // a path into the file system
)
LB_("safe_uts.ok_time_of")
if ( ! file ) fErr
errno = 0 ; struct stat B ; stat( file, &B );
if no_such_file { errno = 0 ; ret( 0L ); }
esif ( errno ) S_ "errno %i: file( %s )", errno, file _fErr
LE_ret( B.st_atime )
/* public: */ void safe_uts :: ok_append
/* -----------------------------------------------------------------------------
write the tail 'fr( offset, whence ) to 'fw
-----------------------------------------------------------------------------
*/ (
FILE * fw
, FILE * fr
, long offset
, int whence
)
LB_("safe_uts.ok_append")
char * B = ( char * ) malloc( 64000 );
if ( ! fseek( fr, offset, whence ) )
{
size_t gel = fread( B, 1, 64000, fr );
while ( 0 < gel )
{
if ( gel != fwrite( B, 1, gel, fw ) ) fErr
gel = fread( B, 64000, 1, fr );
}
}
free( B );
LE_
/* public: */ void safe_uts :: ok_append
/* -----------------------------------------------------------------------------
schreibe den Inhalt der Datei aus nach f
-----------------------------------------------------------------------------
*/ (
FILE * f
, char * aus
)
LB_("safe_uts.ok_append")
if ( ! f || not_is_file( aus ) ) fErr2( f, aus )
rBuffer B( aus, "" );
B.copy_to( f );
LE_
/* public: */ void safe_uts :: ok_endword
/* -----------------------------------------------------------------------------
Macro to find and to mark the end of a word in o n e line of text
-----------------------------------------------------------------------------
*/ (
char * & c
, char e
)
LB_("safe_uts.ok_endword")
while ( *c != e ) c++ ;
*c = 0 ; char * x = --c ; while space( *x ) *x-- = 0 ;
uchar u = *x ;
if ( u < 21 ) S_ "*x = %u\n", u _fErr
LE_
/* public: */ void safe_uts :: ok_checkstr
/* -----------------------------------------------------------------------------
Macro to find characters not allowed in the string
-----------------------------------------------------------------------------
*/ (
uchar a
, uchar e
, char * str
)
LB_("safe_uts.ok_checkstr")
if ( ! str ) fErr else str-- ;
while ( *++str ) if ( ( uchar ) *str < a || e < ( uchar ) *str ) fErr
LE_
#include <stdarg.h>
/* public: */ void safe_uts :: ok_sprintf
// -----------------------------------------------------------------------------
(
char * to
, char * format
, ...
)
LB_("safe_uts.ok_sprintf")
va_list Args ; va_start( Args, to ); // always 1st argument !!!
char * x = va_arg( Args, char * ); // at second argument
// |
// type of argument to skip
// Now Args is the list ... of optional arguments - read them one by one
// using calls va_arg( Args, type_of_argument ):
char * c = format ; while ( *c && *c != '%' ) c++ ; int anr = 2 ;
while ( *c++ == '%' )
{
if ( *c != '%' )
then {
while ( *c && not_alpha( *c )) c++ ;
if ( ! Args ) fErr else ++anr ;
char * nextpar = va_arg( Args, char * );
if ( *c == 's' ) if ( ! nextpar )
{
trace_on
S_ "The %i.th argument of Sprintf() is NULL \n", anr _fErr
}
}
else c++ ;
while ( *c && *c != '%' ) c++ ;
}
// -----------------------------------------------------------------------------
va_start( Args, to ); ::sprintf( to, format, Args );
va_end ( Args );
/* Test, see also perform.exe in tests.ic :
path str ;
sprintf( str, "%i%s","ii","par1", "par2" ); printf( "111\n" );
sprintf( str, "%s%s"," ", 0 , "par2" ); printf( "222\n" );
*/
LE_
/* public: */ int safe_uts :: ok_memcmp
/* -----------------------------------------------------------------------------
because of a BUG in SCC, Version 7.0
-----------------------------------------------------------------------------
*/ (
char * s
, char * t
, int n
)
LB_("safe_uts.ok_memcmp")
if ( n < 0 ) fErr
if ( n == 4 ){
path x1 ; memcpy( x1, s, n );
path x2 ; memcpy( x2, t, n ); printf( "[%s][%s]\n", x1, x2 ); }
while ( n-- ) if ( s[n] != t[n] ) ret( t[n] - s[n] )
LE_ret( 0 )
/* public: */ BOOL safe_uts :: ok_not_text
/* -----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/ (
char * s
)
LB_("safe_uts.ok_not_text")
if ( !s ) fErr
ret( 127 < ( uchar ) *s && 127 < ( uchar ) s[1] )
LE_ret( 0 )
/* public: */ void safe_uts :: ok_see_str
/* -----------------------------------------------------------------------------
for debugging only
-----------------------------------------------------------------------------
*/ (
int see
, char * s
, char * ex
)
LB_("safe_uts.ok_see_str")
if ( !s ) fErr
if ( !ex ) fErr
char str[ 512 ] ;
char * a = str ;
char * e = str + 500 ;
while ( *ex && a < e )
{
if ( *s == *ex ) ex++ ;
if ( *ex ) *a = *s++ ;
if ( ! *a ) *a++ = '?' ; else a++ ;
}
if ( str < a && not_in_name( *a ) ) a-- ; // BUG - in scc
*a = 0 ; printf( "SS%i.[%s]\n", see, str );
LE_
/* public: */ BOOL safe_uts :: ok_assert_in_str
// -----------------------------------------------------------------------------
(
char c
, char * str
, char * at
)
{
if not_in_str( c, str )
{
path x ; char * e = x ;
if ( at ) {
char * a = at ; int z = 0 ;
while ( a < at + 40 && isprint( *a ) ) *e++ = *a++ ;
}
*e = 0 ;
printf( "\nSyntax: char( %c = %u ) not in (%s) at ( %s ... )"
, c, ( uchar )c, str, x );
ret_false
}
ret_true
}
/* public: */ BOOL safe_uts :: ok_assert_at
// -----------------------------------------------------------------------------
(
char * str
, char * at
)
LB_("safe_uts.ok_assert_at")
if ( ! str || ! at ) fErr
if not_is( at, str, strlen( at ) )
{
path x ; char * e = x ;
char * a = at ; int z = 0 ;
while ( a < at + 40 && isprint( *a ) ) *e++ = *a++ ;
*e = 0 ;
printf( "\nSyntax: ( %s ... ) not ( %s ... )", str, x );
ret( false )
}
LE_ret( true )
/* public: */ BOOL safe_uts :: ok_check_str
/* -----------------------------------------------------------------------------
check address and length of string
return 0 iff ok
-----------------------------------------------------------------------------
*/ (
int min_len
, int max_len
, char * str
, char * file
, int line
)
{
if ( str )
then {
if ( max_len < min_len ) max_len = min_len ;
char * x = str ;
char * e = str + max_len ;
while ( *x && x <= e ) x++ ; int L = x - str ;
if ( L < min_len )
then S_ "E r r o r : String too short at %i.%s \n", line, file _TR
esif ( max_len < L )
then S_ "E r r o r : String too long at %i.%s \n", line, file _TR
else ret_false
}
else S_ "E r r o r : NULL adress at %i.%s\n", line, file _TR
ret_true
}
/* public: */ int safe_uts :: ok_open
/* -----------------------------------------------------------------------------
open file 'at, return file handle
-----------------------------------------------------------------------------
*/ (
char * fn
, char opn // 'r' for read
// 'R' for read, but not fErr
// 'a' for append
// 'u' for update
// 'c' for creating (or re-creating) the file
// 'C' for creating, fErr if file exists
, char how // 't' cooked - i.e. as text
// 'B' binary
)
LB_("safe_uts.ok_open")
if ( ! fn ) fErr
if ( ! fn[0] ) fErr
if is_dir( fn )
{
m_errMess "System: Cannot open dir %s as a file.\n" m_
fn, ret_error
}
if ( tr_files ) printf( "\nopen for %c,%c: %s", opn, how, fn );
if ( how != 'B' && how != 't' ) fErr
char noerr = 0 ; if ( opn == 'R' ) { noerr = 'R' ; opn = 'r' ; }
path at ; strcpy( at, fn ); char * x = at-1 ;
#ifdef UNIX
while ( *( ++x ) ) if ( *x == '\\' ) *x = '/' ;
#else
while ( *( ++x ) ) if ( *x == '/' ) *x = '\\' ;
#endif
int f = 0 ; int h = ( how == 'B' )? O_BINARY : O_TEXT ;
#undef open
switch ( opn )
{
case 'r' : f = _open( at, h | O_READ );
Case 'a' : f = _open( at, h | O_APPEND );
Case 'u' : f = _open( at, h | O_RDWR );
Case 'c' : f = _open( at, h | O_RDWR | O_CREAT | O_TRUNC
, S_IREAD | S_IWRITE );
Case 'C' : f = _open( at, h | O_RDWR | O_CREAT | O_EXCL
, S_IREAD | S_IWRITE );
Else : fErr
}
if ( errno )
{
if ( noerr ) { ok ret( -1 ) }
if ( errno == 13 )
{
S_ "\nerror: Cannot open dir %s as a file.\n", fn _fErr
}
char800 xx ; getcwd( xx, 800 );
{
m_errMess "System: currWorkDir = %s,\n"
"cannot open( %s, %c, %c )" m_
xx, at, opn, how, ret_error
}
;
}
#define open safe_ut.ok_open
sf printf( "\n_files.open = %2i, %8i %c %s", ++openfiles, f, opn, fn );
if ( maxopenfiles < openfiles ) fErr2( maxopenfiles, openfiles )
//
LE_ret( f )
/* public: */ void safe_uts :: ok_show_text
/* -----------------------------------------------------------------------------
show to stdout the first n_... characters of txt
-----------------------------------------------------------------------------
*/ (
char * name // any string
, char * txt // any text
, int n_chars //
)
LB_("safe_uts.ok_show_text")
if ( ! n_chars ) n_chars = 11 ;
// if ( a_showStr <= x_showStr + 50 )
{
if ( ! name ) fErr
if ( ! txt ) fErr
if ( 3000 < n_chars ) n_chars = 3000 ;
char sss[ 3100 ] ;
memcpy( sss, txt, n_chars ); sss[ n_chars ] = 0 ;
if ( *name == '?' )
{
printf( "\n?" );
for ( int i = 0 ; i < n_chars ; i++ )
{
printf( "/%u", ( uchar )sss[i] );
}
printf( "\n|" );
}
for ( int i = 0 ; i < n_chars ; i++ ) if ( !sss[i] ) sss[i] = '?' ;
printf( "\n%s = ...[%s]... call_nr %i\n", name, sss, call_nr );
fflush( stdout );
}
if ( x_showStr++ % 32 == 0 )
{
FILE * f = create( f_showStr );
fprintf( f, "showStr %ld", x_showStr );
close( f );
}
LE_
/* public: */ void safe_uts :: ok_show_pos
/* -----------------------------------------------------------------------------
show to stdout position in source code
-----------------------------------------------------------------------------
*/ (
int line
, char * file
)
{
if ( a_otpos <= x_otpos )
{
printf( "\n%i %s\n", line, file );
}
if ( x_otpos++ % 64 == 0 )
{
FILE * f = create( f_otpos ); fprintf( f, "otpos %ld", x_otpos );
close( f );
}
}
/* public: */ char safe_uts :: ok_eoStr
/* -----------------------------------------------------------------------------
NULL( end of string ), return char there (= m)
-----------------------------------------------------------------------------
*/ (
char * & e
, char m
)
{
while ( *( ++e ) != m ){} *e = 0 ; return( m );
}
/* public: */ char safe_uts :: ok_eoStr
/* -----------------------------------------------------------------------------
NULL( end of string ), return char there
-----------------------------------------------------------------------------
*/ (
char * & e
, char * str
)
{
while not_in_str( *e, str ) e++ ; char merke = *e ; *e = 0 ;
return( merke );
}
/* public: */ char safe_uts :: ok_toEndOfStr
// -----------------------------------------------------------------------------
(
char * & c
, char e
)
LB_("safe_uts.ok_toEndOfStr")
while ( *( ++c ) != e ){}
while space( *c ) c-- ; char merke = *( ++c ); *c = 0 ;
LE_ret( merke )
/* public: */ char safe_uts :: ok_toEndOfStr
// -----------------------------------------------------------------------------
(
char * & c
, char e
, char stattBlank
)
LB_("safe_uts.ok_toEndOfStr")
while ( *( ++c ) != e ) if ( *c == ' ' ) *c = stattBlank ;
while space( *c ) c-- ; char merke = *( ++c ); *c = 0 ;
LE_ret( merke )
/* public: */ char safe_uts :: ok_charOf
// -----------------------------------------------------------------------------
(
char * c
, char * str
)
LB_("safe_uts.ok_charOf")
if ( ! str ) fErr
while space( *c ) c++ ;
if ( ! in_str( *c, str ) ) { showStr( "", c, 12 ); fErr }
LE_ret( *c )
/* public: */ char safe_uts :: ok_goto_word
// -----------------------------------------------------------------------------
(
char * & c
, int offset
, int jumps
)
LB_("safe_uts.ok_goto_word")
if ( ! c ) fErr
c += offset ;
while ( jumps-- )
{
while not_space( *( ++c ) ) {}
while space( *( ++c ) ) {}
}
while space( *c ) c++ ; // needed in case of jumps == 0
LE_ret( *c )
/* public: */ char * safe_uts :: ok_currentTime ( int x
// -----------------------------------------------------------------------------
)
{
time_t jetzt ; time( &jetzt );
#define cs(x,w) if ( x == w )
cs(x,2) strftime( str_ct, 32, "%Y.%m.%d %H:%M" , localtime( &jetzt ) );
cs(x,3) strftime( str_ct, 32, "%Y.%m.%d %H:%M:%S" , localtime( &jetzt ) );
if ( x < 2 || x > 3 )
strftime( str_ct, 32, "%Y.%m.%d", localtime( &jetzt ) );
#undef cs
return( str_ct );
}
/* public: */ char * safe_uts :: ok_currentTime_en ( int x
// -----------------------------------------------------------------------------
)
{
time_t jetzt ; time( &jetzt );
#define cs(x,w) if ( x == w )
cs(x,2) strftime( str_ct, 32, "%b %d, %Y - %H:%M" , localtime( &jetzt ) );
cs(x,3) strftime( str_ct, 32, "%b %d, %Y - %H:%M:%S", localtime( &jetzt ) );
if ( x < 2 || x > 3 )
strftime( str_ct, 32, "%b %d, %Y", localtime( &jetzt ) );
#undef cs
return( str_ct );
}
/* public: */ char * safe_uts :: ok_currentTimestamp (
// -----------------------------------------------------------------------------
)
{
time_t jetzt ; time( &jetzt );
time_t xx ;
strftime( str_ct, 80, "%Y.%m.%d_%H.%M", localtime( &jetzt ) );
s_( eos( str_ct ), "_%i", time( &xx ) );
return( str_ct );
}
/* public: */ char * safe_uts :: ok_currentDate (
// -----------------------------------------------------------------------------
)
{
time_t jetzt ; time( &jetzt );
strftime( str_currDate, 32, "%Y.%m.%d", localtime( &jetzt ) );
return( str_currDate );
}
/* public: */ char * safe_uts :: ok_heute (
// -----------------------------------------------------------------------------
)
{
time_t jetzt ; time( &jetzt );
strftime( str_currDate, 32, "%d.%m.%Y", localtime( &jetzt ) );
return( str_currDate );
}
/* public: */ void safe_uts :: ok_test(
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_test")
LE_Ret_( 12 )
/* public: */ char safe_uts :: ok_askChar(
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_askChar")
char c = getch(); printf( "\npress any key [or Ctrl C to exit]" );
if ( ( uchar )c == 3 ) exit( 1 ); // i.e. "ctrl c" means "stop"
LE_ret( c )
/* public: */ void safe_uts :: ok_resInto
/* -----------------------------------------------------------------------------
Create to == toDir/fn aus from = dir/fn
-----------------------------------------------------------------------------
*/ (
path & to
, char * toDir
, char * from
)
LB_("safe_uts.ok_resInto")
if ( ! toDir ) fErr
if ( ! from ) fErr
path frm ; strcpy( frm, from ); unix_me( frm );
char * x = frm + strlen( frm ) - 1 ;
while ( frm < x && *x != '/' ) x-- ;
if ( *x == '/' ) x++ ;
sprintf( to, "%s/%s", toDir, x );
if is_( to, frm ) fErr
LE_
/* public: */ char * safe_uts :: ok_ourHome ( char * fn
/* -----------------------------------------------------------------------------
return the path to the folder containing the file fn
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_ourHome")
s_( ourhome, safe_ut.ok_exePath( fn, 0, 0 ) );
char * x = eos( ourhome );
while ( ourhome < x && not_in_str( *x, "/\\" ) ) x-- ;
if ( ourhome == x ) strcpy( ourhome, "." ); else *x = 0 ;
LE_ret( ourhome )
/* public: */ char * safe_uts :: ok_exePath
// -----------------------------------------------------------------------------
#define ourPath( fn ) safe_ut.ok_exePath( fn, 0, 0 )
// -----------------------------------------------------------------------------
(
char * exe // need not be a *.exe
, BOOL me // must exist
, long L // expected file size
)
LB_("safe_uts.ok_exePath")
if ( ! exe ) fErr
#ifdef MICROSOFT
char p[ 1000 ]; _searchenv( exe, "PATH", p ); ok
#else
char * p = searchpath( exe ); if ( !p ) p = "" ; ok
#endif
if ( !*p )
{
printf( "\nError: Not on PATH: %s\n", exe );
if ( me == 1 ) exit(1);
}
if ( L && L != file_len( p ) )
{
printf( "zError: wrong version: %s\n", p );
if ( me == 1 ) exit(1); else fErr
}
LE_ret( p )
#undef sf
/* public: */ void safe_uts :: Syntax
/* -----------------------------------------------------------------------------
Der Aufrufer sagt:
Zeige die Zeile, die den Syntax Error beinhaltet, dann sage fErr
Die Funktion garantiert: fErr
-----------------------------------------------------------------------------
*/ (
int line
, char * file
, char * c
, char * expected
)
LB_("safe_uts.Syntax")
if not_is( c, expected, strlen( expected ) )
{
char * a = c ; while ( *a && *a != '\n' ) a-- ;
char * e = c+1 ;
while ( *e != '\n' ) e++ ; e++ ;
while ( *e != '\n' ) e++ ; *e = 0 ;
char * x = a ; while ( ++x < e ) if ( ! *x ) *x = '? ' ;
printf( "\n%i.%s"
"\nSyntax Error in Spalte %i:"
"\n expected: [%s]..."
"\n found: [%s]... \n"
, line, file, c-a, expected, c ); exit(1);
}
LE_
/* public: */ void safe_uts :: ok_notAllCapital
/* -----------------------------------------------------------------------------
Transform the string to mixed case letters (no all capital).
-----------------------------------------------------------------------------
*/ (
char * s
)
LB_("safe_uts.ok_notAllCapital")
if ( !s ) fErr
char * a = s ;
while ( *( ++s ) ) if alpha( s[-1] ) *s = tolower( *s );
if is( s-2, "Id" , 2 ) memcpy( s-2, "ID" , 2 );
esif is( s-2, "id" , 2 ) memcpy( s-2, "ID" , 2 );
esif is( s-2, "db" , 2 ) memcpy( s-2, "DB" , 2 );
esif is( s-2, "ja" , 2 ) memcpy( s-2, "Ja" , 2 );
esif is( s-2, "nr" , 2 ) memcpy( s-2, "Nr" , 2 );
esif is( s-2, "kz" , 2 ) memcpy( s-2, "Kz" , 2 );
esif is( s-3, "Blz" , 3 ) memcpy( s-3, "BLZ" , 3 );
esif is( s-3, "blz" , 3 ) memcpy( s-3, "BLZ" , 3 );
esif is( s-3, "Plz" , 3 ) memcpy( s-3, "PLZ" , 3 );
esif is( s-3, "plz" , 3 ) memcpy( s-3, "PLZ" , 3 );
esif is( s-3, "okz" , 3 ) memcpy( s-3, "Okz" , 3 );
esif is( s-4, "nein" , 4 ) memcpy( s-4, "Nein" , 4 );
if is( a, "Last", 4 ) *( a+4 ) = toupper( *( a+4 ) );
LE_
/* public: */ int safe_uts :: ok_common
/* -----------------------------------------------------------------------------
Return length of common prefix
-----------------------------------------------------------------------------
*/ (
char * s1
, char * s2
)
LB_("safe_uts.ok_common")
if ( ! s1 ) fErr
if ( ! s2 ) fErr
int c = 0 ; while ( *s1 && *s1 == *s2 ) { s1++ ; s2++ ; c++ ; }
LE_ret( c )
/* public: */ char * safe_uts :: ok_trimm
/* -----------------------------------------------------------------------------
Trimm at the end of 's all 'c characters
-----------------------------------------------------------------------------
*/ (
char * s
, char c
)
LB_("safe_uts.ok_trimm")
if ( !s ) fErr
char * x = s + strlen( s ) - 1 ;
while ( s < x && *x == c ) *( x-- ) = 0 ;
LE_ret( s )
/* public: */ char * safe_uts :: ok_trimm
/* -----------------------------------------------------------------------------
Trimm at the end of 's all characters found in 'estr
-----------------------------------------------------------------------------
*/ (
char * s
, char * estr
)
LB_("safe_uts.ok_trimm")
if ( !s ) fErr
char * x = s + strlen( s ) - 1 ;
while ( s < x && in_str( *x, estr ) ) *( x-- ) = 0 ;
LE_ret( s )
/* public: */ int safe_uts :: ok_Value
// -----------------------------------------------------------------------------
(
char * s
)
LB_("safe_uts.ok_Value")
int m = 0 ; while ( digit( *s ) ) m = m * 10 + ( *s++ - '0' ) ;
LE_ret( m )
/* public: */ int safe_uts :: ok_anz
// -----------------------------------------------------------------------------
(
char * s
, char c
, char e
)
LB_("safe_uts.ok_anz")
int m = 0 ; while ( *s != e ) if ( *s++ == c ) m++ ;
LE_ret( m )
/* public: */ int safe_uts :: ok_replace
/* -----------------------------------------------------------------------------
In 'file replace 'str1 by 'str2.
Return number of replacements.
-----------------------------------------------------------------------------
*/ (
char * file
, char * str1
, char * str2
)
LB_("safe_uts.ok_replace")
if ( ! file ) fErr
if ( ! str1 ) fErr
if ( ! str2 ) fErr
char * tmp = "xx_rep" ; FILE * f = create( tmp );
rBuffer B( file, "" ); int ers = 0 ;
int L = strlen( str1 ); if ( L <= 0 ) fErr
while ( B.find( 0, str1, f ) )
{
if ( *str2 ) fprintf( f, "%s", str2 );
B.a += L ; ers++ ;
}
close( f );
if ( ers ) copy( tmp, file );
Unlink( tmp )
LE_ret( ers )
/* public: */ BOOL safe_uts :: ok_atComm
// -----------------------------------------------------------------------------
(
int s // Zeile
)
{
printf( "\n.. %i", s ); return( 1 );
}
/* public: */ void safe_uts :: ok_trace_LB
// -----------------------------------------------------------------------------
(
char * enter
)
LB_("safe_uts.ok_trace_LB")
#ifdef LB_tr
int mo = ( LB_tr + 1000 < atLB )? 1000 : 1 ;
if ( atLB % mo == 0 ) printf( "\n%i - %s", atLB , enter );
#endif
}
/* public: */ long safe_uts :: ok_strCode
/* -----------------------------------------------------------------------------
map str to a pseudo-random long number
-----------------------------------------------------------------------------
*/ (
char * str
, char * before
)
LB_("safe_uts.ok_strCode")
long n = 123456777 ;
char * x = str-1 ;
while ( *( ++x ) )
{
if ( before && *before && At( x, before ) ) break ;
n = ( n % 77777777 ) * ( 1 + ( uchar )( *x ) ) + 1234567 ;
}
LE_ret( n )
/* public: */ long safe_uts :: ok_decNr
/* -----------------------------------------------------------------------------
decimal string to int (auch dann, wenn fhrende Nullen)
-----------------------------------------------------------------------------
*/ (
char * str
, char * File
, int Line
)
LB_("safe_uts.ok_decNr")
while ( *str == ' ' || *str == '\t' ) str++ ;
if ( *str == '+' ) str++ ;
if ( *str == '\n' ) ret( 0 )
int minus = 1 ; if ( *str == '-' ) { ++str ; minus = -1 ; }
while ( *str == '0' ) str++ ; // sonst als hexadecimal interpretiert !!!
if not_digit( *str ) ret( 0 ) // Die Zahl kann die 0 gewesen sein
char * x = str ; while digit( *x ) x++ ;
char merke = *x ; *x = 0 ;
if ( x - str > 10 ) fErr4( str, INT_MAX, File, Line )
long anz ; sscanf( str, "%lu", &anz );
*x = merke ;
LE_ret( anz * minus )
/* public: */ float safe_uts :: ok_DECNr
/* -----------------------------------------------------------------------------
Beispiel: str == " -1.455,66 EUR"
-----------------------------------------------------------------------------
*/ (
char * str
, char ko // das Komma als '.' oder ','
, char * File
, int Line
)
LB_("safe_uts.ok_DECNr")
if ( ko != '.' && ko != ',' ) fErr1( ko )
char30 vorko ;
char30 nchko ;
char * z = vorko ;
char * x = str ; skip_space( x );
int VZ = ( *x == '-' )? -1 : 1 ; if in_str( *x, "-+" ) x++ ;
while ( *x != ko && in_str( *x, "0123456789.," ) )
{
if ( *x == ko ) break ;
if in_str( *x, ".," ) x++ ; else *z++ = *x++ ;
}
*z = 0 ; x++ ;
z = nchko ;
int scale = 1 ;
while digit( *x ) { *z++ = *x++ ; scale *= 10 ; }
*z = 0 ;
LE_ret( VZ * ( decNr( vorko ) + ((float) decNr( nchko ))/scale ) )
/* public: */ uchar safe_uts :: ok_zufchar
/* -----------------------------------------------------------------------------
return an random char x out of the range [ from .. to ]
-----------------------------------------------------------------------------
*/ (
uchar from
, uchar to
)
LB_("safe_uts.ok_zufchar")
if ( to <= from ) fErr
uint i = rand() % ( to - from );
LE_ret( from + i )
/* public: */ void safe_uts :: ok_ABC
/* -----------------------------------------------------------------------------
Create ABC navigation record [A] B C ... Z
-----------------------------------------------------------------------------
*/ (
FILE * f
, char * abcName
, char * pre
)
LB_("safe_uts.ok_ABC")
fprintf( f, "<center>%s", pre );
uchar c = 'A' - 1 ;
while ( ++c <= 'Z' ) fprintf( f, "\n<a href=\"#%c%s\">%c </a>", c, abcName, c );
fprintf( f, "</center><br><br>" );
LE_
/* public: */ void safe_uts :: ok_abc
/* -----------------------------------------------------------------------------
Create ABC navigation record [A] B C ... Z
-----------------------------------------------------------------------------
*/ (
FILE * f
, char * abcName
, char * pre
)
LB_("safe_uts.ok_abc")
fprintf( f, "<center>%s", pre );
uchar c = 'a' - 1 ;
while ( ++c <= 'z' ) fprintf( f, "\n<a href=\"#%c%s\">%c </a>", c, abcName, c );
fprintf( f, "</center><br><br>" );
LE_
/* public: */ char safe_uts :: ok_ABC_sec
/* -----------------------------------------------------------------------------
Connect ABC section
-----------------------------------------------------------------------------
*/ (
FILE * f
, char c1
, char c2
, char * abcName
)
LB_("safe_uts.ok_ABC_sec")
if ( upper( c1 ) == upper( c2 ) ) ret( upper( c2 ) )
uchar x1 = max( upper( c1 ) - 1, 'A' );
uchar x2 = min( upper( c2 ) , 'Z' );
while ( ++x1 <= x2 ) fprintf( f, "\n<a name=\"%c%s\"></a>", x1, abcName );
LE_ret( upper( c2 ) )
/* public: */ FILE * safe_uts :: ok_nextf
// -----------------------------------------------------------------------------
(
FILE * f
, char * cr
, char * rm
)
LB_("safe_uts.ok_nextf")
if ( f ) close( f );
if ( cr ) f = create( cr ); else f = 0 ;
if ( rm ) Unlink( rm )
LE_ret( f )
/* public: */ BOOL safe_uts :: ok_in_Range
// -----------------------------------------------------------------------------
(
uchar c
, uchar a
, uchar e
)
LB_("safe_uts.ok_in_Range")
LE_ret( a <= c && c <= e )
/* public: */ char safe_uts :: ok_eoName
// -----------------------------------------------------------------------------
(
char * & e
, char * also
)
LB_("safe_uts.ok_eoName")
while ( in_name( *e ) || in_str( *e, also ) || 127 < (uchar)( *e ) )
{
if ( *e == '_' )
{
if At( e, "_<>_" ){ e += 10 ; continue ; }
if At( e, "_><_" ){ e += 10 ; continue ; }
}
if At( e, "_><_" ) e += 3 ;
if ( *e == '<' || is_tabulator( *e ) ) break ;
if in_str( *e, "" ) break ; // wegen " = in MS's HTML
if ( *e == '(' ) to_( e, ')' )
esif ( *e == '&' )
{
if At( e, "<" ) break ;
if At( e, ">" ) break ;
if ( not_in_str( ' ', also ) && At( e, " " ) ) break ;
to_( e, ';' ) // HTML escape
}
e++ ;
}
if ( e[-1] == '.' && not_is( e-3, "...", 3 ) ) e-- ;
char merke = *e ; *e = 0 ;
LE_ret( merke )
/* public: */ BOOL safe_uts :: ok_not_escaped // obsolete
// -----------------------------------------------------------------------------
(
char * s
)
LB_("safe_uts.ok_not_escaped")
char * x = s-1 ; while ( *x == '\\' ) x-- ;
LE_ret( ( s-x )%2 )
/* public: */ BOOL safe_uts :: ok_escaped ( char * c
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_escaped")
uint anz = 0 ; char * x = c ; while ( *( --x ) == '\\' ) anz++ ;
LE_ret( anz % 2 )
/* public: */ char * safe_uts :: ok_skip_nest
// -----------------------------------------------------------------------------
(
char * & c
, char a // Klammer auf, char z // Klammer zu )
LB_("safe_uts.ok_skip_nest")
if ( a == '\'' ) fErr
int k = 1 ; while ( *c != a ) c++ ; c++ ;
while ( k ) {
if ( *c == '\'' )
then {
if ( c[2] == '\'' ) c += 2 ;
}
esif ( *c == a ) k++ ;
esif ( *c == z ) k-- ;
if ( *c == '"' ) skip_str( c, c+800 ); else
c++ ; // showStr( "xxx", c, 10 ); }
LE_ret( c )
/* public: */ char * safe_uts :: ok_skip_nest_o_str
// -----------------------------------------------------------------------------
(
char * & c
, char a // Klammer auf
, char z // Klammer zu
, char * e // end of range to search
)
LB_("safe_uts.ok_skip_nest_o_str")
char * c1 = c ;
char m = *e ; *e = a ;
int k = 1 ; while ( *c != a ) c++ ; *e = m ;
while ( ++c < e && k ) // des Seiteneffekts wegen in eben dieser Reihenfolge
{
if ( *c == a ) k++ ;
esif ( *c == z ) k-- ;
if ( *c == '"' && not_escaped( c ) )
{
ok_skip_str( c, e ); c-- ;
}
esif ( *c == '\'' )
{
if ( c[3] == '\'' ) c += 3 ; else c += 2 ; // ok so
}
}
if ( e <= c ) { traceStr( "xxn", c1, e-c1 ); fErr }
LE_ret( c )
/* public: */ char * safe_uts :: ok_to_o_str
// -----------------------------------------------------------------------------
(
char * & c
, char z
, char * e // end of range to search
)
LB_("safe_uts.ok_to_o_str")
char * c1 = c-- ;
while ( ++c < e )
{
if ( *c == '"' && not_escaped( c ) ) ok_skip_str( c, e );
if ( *c == z ) break ;
}
if ( e <= c ) { traceStr( "xxo", c1, e-c1 ); fErr }
LE_ret( c )
/* public: */ char * safe_uts :: ok_skip_comment ( char * c
/* -----------------------------------------------------------------------------
Precondition: At( c, "//" ) || At( c, "/*" )
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_skip_comment")
if At( c, "/*" )
then {
while not_At( c, "*/" ) c++ ; c += 2 ;
}
esif At( c, "//" ) to_( c, '\n' )
else fErr
LE_ret( c )
/* public: */ char * safe_uts :: ok_skip_cout_cerr
/* -----------------------------------------------------------------------------
Precondition: At( c, "cout") || At( c, "cerr" )
-----------------------------------------------------------------------------
*/ (
char * c
, char * e
)
LB_("safe_uts.ok_skip_cout_cerr")
if ( not_At( c, "cout" ) && not_At( c, "cerr" ) )
then {
c[11] = 0 ; fErr1( c )
}
while ( *c != ';' )
{
if ( *c == '"' ) skip_str( c, e ); else c++ ;
}
LE_ret( c )
/* public: */ void safe_uts :: ok_skip_space_and_comment ( char *& c
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_skip_space_and_comment")
skip_space( c );
while ( *c == '/' ) { c = skip_comment( c ); skip_space( c ) }
LE_
/* public: */ BOOL safe_uts :: ok_asChar ( char * c
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_asChar")
LE_ret( At( c-1, "'\"'" ) || At( c-2, "'\\\"'" ) || escaped( c ) )
/* public: */ char * safe_uts :: ok_skip_phpstr
/* -----------------------------------------------------------------------------
Note: in PHP, strings may contain \n
skip float quoted string or a " char written as '"' or '\"'
skip single quoted string or a ' char written as ' or '\''
-----------------------------------------------------------------------------
*/ (
char * & c
, char * e
)
LB_("safe_uts.ok_skip_phpstr")
char * c1 = c ;
if ( *c == '\'' ) ret( ok_skip_str1( c,e ) )
if ( *c != '"' ) fErr1( *c )
if escaped( c ) ret( ++c )
if ( At( c-1, "'\"'" ) || At( c-2, "'\\\"" ) ) ret( ++c )
do {
c++ ; while ( c < e && not_in_str( *c, "\"" ) ) c++ ;
if ( *c == '\n' )
{
c = c1+1 ; ret( c ) // da das " hier keinen String beginnt
}
if ( e <= c )
{
traceStr( "XXX", c1, 200 );
fErr2( c-e, e-c1 )
}
}
while escaped( c );
LE_ret( ++c )
/* public: */ char * safe_uts :: ok_skip_str
/* -----------------------------------------------------------------------------
skip float quoted string or a " char written as '"' or '\"'
skip single quoted string or a ' char written as ' or '\''
-----------------------------------------------------------------------------
*/ (
char * & c
, char * e
)
LB_("safe_uts.ok_skip_str")
if ( !e || e < c )
{
char * x = in_str( '\n', c );
if ( x ) e = x ;
}
char * c1 = c ;
if (0)
{
char m = *c1 ;
if ( m != '\'' && m != '"' ) fErr1( c1 )
uint N = 400 ; if ( N < e-c1 ) e = c1 + N ; // robust
c++ ; while ( c < e && *c != m ) c++ ;
while ( c < e && escaped( c ) )
{
c++ ; while ( c < e && *c != m ) c++ ;
}
if ( e <= c )
then {
printf( "\n\nZu langer str[ %s ]?\n", c1 );
fErr
}
else ret( c+1 )
}
// --------------------------- alt, aber Ok:
if ( *c == '\'' ) ret( ok_skip_str1( c,e ) )
if ( *c != '"' ) fErr1( *c )
// if escaped( c ) { c++ ; ret( ok_skip_str( c, e ) ) } // 28.8.2019
// if escaped( c ) ret( ++c )
if ( At( c-1, "'\"'" ) || At( c-2, "'\\\"" ) ) ret( ++c )
do {
c++ ; // while ( c < e && not_in_str( *c, "\"\n" ) ) c++ ;
if ( 200 < e-c1 ) e = c1 + 200 ;
while ( c < e && *c != '"' )
{
if ( !*c ) *c++ == ' ' ; else c++ ; // robust gegen NULL chars
}
ret( c+1 );
if ( *c == '\n' )
{
c = c1+1 ; ret( c ) // da das " hier keinen String beginnt
}
if ( e <= c )
{
traceStr( "XXX", c1, 100 );
c = in_str( '"', c1+1 ); if ( c ) ret( ++c )
fErr4( c1, c-e, e-c1, call_nr )
}
}
while escaped( c );
LE_ret( ++c )
/* public: */ char * safe_uts :: ok_skip_str1
/* -----------------------------------------------------------------------------
skip single quoted string or a ' char written as '\''
-----------------------------------------------------------------------------
*/ (
char * & c
, char * e
)
LB_("safe_uts.ok_skip_str1")
char * c1 = c ;
if ( escaped( c ) ) ret( ++c )
if ( *c != '\'' ) fErr1( c )
if At( c-2, "'\''" ) ret( ++c )
do {
c++ ; while ( c < e && not_in_str( *c, "'\n" ) ) c++ ;
if ( *c == '\n' )
{
c = c1+1 ; ret( c ) // da nur ein can't, don't, ...
}
if ( e <= c )
{
traceStr( "XXX", c1, 200 );
fErr2( c-e, e-c1 )
}
}
while escaped( c );
LE_ret( ++c )
/* public: */ char * safe_uts :: ok_skip_Br
/* -----------------------------------------------------------------------------
skip a bracket such as <... "..." ... '...' ...>
|
return this position
-----------------------------------------------------------------------------
*/ (
char * c
, char * e
, char c1
, char c2
)
LB_("safe_uts.ok_skip_Br")
if ( *c != c1 ) fErr2( *c, c1 )
c++ ; // so dass c1 == c2 sein kann
while ( *c != c2 && c < e )
{
if ( *c == '\"' ) skip_str ( c, e );
if ( *c == '\'' ) skip_str1( c, e ); else c++ ;
}
if ( e <= c ) fErr
if ( *c != c2 ) fErr
LE_ret( ++c )
/* public: */ void safe_uts :: ok_skip_strXXXXXXX
// -----------------------------------------------------------------------------
(
char * & c
, char * e
)
LB_("safe_uts.ok_skip_strXXXXXXX")
if ( *c != '"' ) { traceStr( "ccc", c, 200 ); fErr }
if ( c[-1] == '\\' && c[-2] != '\\' )
{
c++ ; ret_
}
if At( c-1, "'\"'" ) { c++ ; ret_ }
if At( c-2, "'\\\"'" ) { c++ ; ret_ }
char * c1 = c ;
c++ ; while ( *c != '"' && *c != '\n' || escaped( c ) ) c++ ;
if ( *c == '\n' )
then {
traceStr( "xx1: c1-3", c1-3, c-c1 + 30 ); fErr
}
if ( *c != '"' ) fErr // *c = 0 ; _1( c1 ) *c = '"' ;
if ( e <= ++c ) { traceStr( "xx2", c1, e-c1 ); fErr }
LE_
/* public: */ void safe_uts :: ok_extract_sections
/* -----------------------------------------------------------------------------
extract sections [str1 ... str2]
-----------------------------------------------------------------------------
*/ (
char * from // name of input file
, char * str1
, char * str2
, char * into
)
LB_("safe_uts.ok_extract_sections")
if ( ! from ) fErr
if ( ! str1 ) fErr
if ( ! str2 ) fErr
if ( strlen( str2 ) <= 0 ) fErr
FILE * f = is_( into, "-" )? stdout : create( into );
rBuffer B( from, "" );
while ( B.find( 0, str1, 0 ) )
{
rB_( B, 0, str2, f );
fprintf( f, "%s\n\n", str2 ); B.a += strlen( str2 );
}
close( f );
LE_
/* public: */ char safe_uts :: ok_eoStr
// -----------------------------------------------------------------------------
(
char * c
, char * & e
, char m
)
LB_("safe_uts.ok_eoStr")
char merke = *e ; to_( e, m )
char * x = e ; *x-- = 0 ; while ( c <= x && space( *x ) ) *x-- = 0 ;
LE_ret( merke )
/* public: */ char safe_uts :: ok_environment
// -----------------------------------------------------------------------------
(
char * to
, char * from
)
LB_("safe_uts.ok_environment")
if ( ! to || ! from ) fErr
if ( getenv( from ) ) strcpy( to, getenv( from ) ); else *to = 0 ;
LE_ret( *to )
/* public: */ int safe_uts :: ok_max_me
// -----------------------------------------------------------------------------
(
int & M
, int m
)
{
if ( M < m ) M = m ; return( M );
}
/* public: */ int safe_uts :: ok_min_me
// -----------------------------------------------------------------------------
(
int & M
, int m
)
{
if ( m < M ) M = m ; return( M );
}
/* public: */ char * safe_uts :: ok_file_Date // obsolete - use file_Time
/* -----------------------------------------------------------------------------
Return pointer to Last Update Time in format YYYY.MM.DD
-----------------------------------------------------------------------------
*/ (
char * fn
)
LB_("safe_uts.ok_file_Date")
if ( ! fn ) fErr
time_t x = file_Surr( fn );
strftime( xx, 40, "%Y.%m.%d", localtime( &x ) );
LE_ret( xx )
/* public: */ char * safe_uts :: ok_file_Time
/* -----------------------------------------------------------------------------
Write to buffer xx the file's Update Time in format
if ( form == 0 ) then DD.MM.YYYY
if ( form == 1 ) then YYYY.MM.DD
if ( form == 2 ) then YYYY.MM.DD HH:MM
if ( form >= 3 ) then YYYY.MM.DD HH:MM:SS
-----------------------------------------------------------------------------
*/ (
char * fn
, char * xx
, int form
)
LB_("safe_uts.ok_file_Time")
if ( ! fn ) fErr
if ( ! xx ) fErr
time_t x = file_Surr( fn );
strftime( xx, 40, "%Y.%m.%d %H:%M", localtime( &x ) );
if ( form <= 1 ) xx[ 10 ] = 0 ; else
if ( form == 2 ) xx[ 16 ] = 0 ;
if ( form == 0 )
{
char20 zz ; strcpy( zz, ".........." );
zz[0] = xx[8] ;
zz[1] = xx[9] ;
zz[3] = xx[5] ;
zz[4] = xx[6] ; memcpy( zz + 6, xx, 4 );
strcpy( xx, zz );
}
LE_ret( xx )
/* public: */ time_t safe_uts :: ok_file_Surr ( char * fn
/* -----------------------------------------------------------------------------
Return the file's st_mtime value (= Last Update Time)
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_file_Surr")
if ( ! fn ) fErr
char400 xx ; strcpy( xx, fn ); dos_me( fn );
struct stat st ; stat( fn, &st );
if ( errno == 2 ) S_ "not found: %s", fn _fErr
if ( errno ) fErr2( errno, fn )
LE_ret( st.st_mtime )
/* public: */ unsigned long safe_uts :: ok_size_Surr ( char * fn
/* -----------------------------------------------------------------------------
Return the file's st_mtime value (= Last Update Time)
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_size_Surr")
if ( ! fn ) fErr
char400 xx ; strcpy( xx, fn ); dos_me( fn );
struct stat st ;
if ( stat( fn, &st ) ) { if not_is_file( fn ) fErr1( fn ) else fErr }
LE_ret( st.st_size )
/* public: */ char * safe_uts :: ok_MMDD ( char * date // YYYY.MM.DD or YYYY_MM_DD
/* -----------------------------------------------------------------------------
Transform date in place to "MMM DD"
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_MMDD")
char m = date[10] ; date[10] = 0 ;
char * month = date + 5 ;
char * day = date + 8 ; if ( *day == '0' ) day += 1 ;
if At( month, "01" ) month = "Jan" ;
esif At( month, "02" ) month = "Feb" ;
esif At( month, "03" ) month = "Mar" ;
esif At( month, "04" ) month = "Apr" ;
esif At( month, "05" ) month = "May" ;
esif At( month, "06" ) month = "Jun" ;
esif At( month, "07" ) month = "Jul" ;
esif At( month, "08" ) month = "Aug" ;
esif At( month, "09" ) month = "Sep" ;
esif At( month, "10" ) month = "Oct" ;
esif At( month, "11" ) month = "Nov" ;
esif At( month, "12" ) month = "Dec" ; else fErr1( date )
s_( date, "%s %s", month, day );
date[10] = m ;
LE_ret( date )
/* public: */ BOOL safe_uts :: ok_str_in_file
/* -----------------------------------------------------------------------------
return BOOL( string 'str was found in the file 'fn )
-----------------------------------------------------------------------------
*/ (
char * str
, char * fn
)
LB_("safe_uts.ok_str_in_file")
if ( ! str ) fErr
if ( ! fn ) fErr
if not_is_file( fn ) fErr1( fn )
rBuffer B( fn, "" );
// Von Fall zu Fall so schreiben, dass Fehler im File entdeckt werden:
if ( B.find( 0, str, 0 ) )
// if ( B.find( 0, "data exchange.", 0 ) )
{
char100 xx ; s_( xx, "FFF( %s --- %s )", fn, str );
traceStr( xx, B.z + B.a, strlen( str ) + 55 );
ret( 1 )
}
if (0)
{
B.open_rBuffer( fn, "" );
if ( B.find( 0, ">undown<", 0 ) ) fErr2( B.z + B.a, fn )
}
LE_ret( 0 )
/* public: */ BOOL safe_uts :: ok_strchecker ( char * str
// -----------------------------------------------------------------------------
// wird zum Debugging von Fall zu Fall geeignet codiert
// um Trace oder Abbruch zu liefern
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_strchecker")
if substr( ">lass=" , str ) fErr1( str )
LE_ret( 0 )
/* public: */ void safe_uts :: ok_checker
// -----------------------------------------------------------------------------
// wird zum Debugging von Fall zu Fall geeignet codiert
// um Trace oder Abbruch zu liefern
// -----------------------------------------------------------------------------
(
int stNr
, char * fn
)
LB_("safe_uts.ok_checker")
if not_is_file( fn )
{
printf( "\nchecker %i: not found: fn = %s\n", stNr, fn );
ret_
}
// if (100 < stNr || not_is_file( fn ) ) ret_
if ( ! stNr ) { printf( "\nchecker done|\n" ); ret_ }
if ( ! fn ) fErr2( fn, stNr )
char20 st ; s_( st, "st %i", stNr );
printf( "\nchecker check: %i, %s --- cwd = %s\n", stNr, fn, CWD );
if not_is_file( fn ) { _1( CWD ) ret_ }
rBuffer B( fn, "" );
char * e = B.z + B.e ;
char * x = B.z + B.a - 1 ;
// while ( ++x < e ) if ( !*x && x[1] == '/' ) *x = '<' ;
if ( strlen( B.z + B.a ) < B.e - B.a )
{
traceStr( "ZZZ/1", eos( B.z + B.a )-20, 400 );
B.has_NULL(); // zeigt die Stelle um die NULL
{
m_errMess "System: see NULL in ZZZ above ( %i: fn = %s )" m_
stNr, fn, ret_error
}
}
// -----------------------------------------------------------------------------
//
B.open_rBuffer( fn, "" );
// Von Fall zu Fall so schreiben, dass Fehler im File entdeckt werden:
char400 xx ; B.z[ B.e ] = 0 ;
str_set such ; such.insert( "<<" );
such.insert( ">lass=" );
such.insert( ">>" );
such.insert( "PP_" );
such.insert( "ce: <a href=" );
such.insert( "<h5>See:" );
such.insert( ">ans-se<" );
such.insert( "Abbildung \\* ARABIC" );
such.insert( ".htm.htm" );
such.insert( "<span'>" );
such.insert( "</span'>" );
such.insert( "<p <" );
such.insert( ">p class=" );
such.insert( "<span> </o:p>" );
// if ( 1 < stNr ) such.insert( "[endif]" );
// if ( 9 < stNr ) such.insert( "%20" /* checser 81 */ );
match_rec * mr ;
B.open_rBuffer( fn, "" );
if ( mr = B.find( 0, such, 0 ) )
{
char20 cc ; s_( cc, "checker(%i)", stNr );
fErr4( B.z + B.a - 10, fn, mr->str, cc )
}
// -----------------------------------------------------------------------------
uint pAnz = 0 ;
B.open_rBuffer( fn, "" );
while ( B.find( 1, "<p", 0 ) )
{
char * c = B.z + B.a + 1 ;
if ( *c == 'p' || ( *c == 'h' && digit( c[1] ) ) ) ++pAnz ;
}
printf( "\nchecker done( pAnz= %5i ) for %3i = %s\n", pAnz, stNr, fn );
// -----------------------------------------------------------------------------
ret_
if ( stNr == 1 ) checkerNr = decNr( fn );
if ( 0 < stNr && checkerNr == 2 )
{
char20 xfn ; s_( xfn, "xs/%i/x%i.htm", checkerNr, stNr );
cp_file( xfn, fn );
S_ "start %s", xfn _Do
}
LE_
/* public: */ int safe_uts :: ok_trace_strIn
/* -----------------------------------------------------------------------------
trace occurrances of 'str in file 'fn
if 'str found at z[a], show z[ a-n .. a+m ]
-----------------------------------------------------------------------------
*/ (
char * str
, char * fn
, uint m
, int n // n < 0 means: fErr if 'str found // oder: uint
, char * File
, int Line
)
LB_("safe_uts.ok_trace_strIn")
if ( ! str ) fErr
if ( ! str[0] ) fErr
int L = abs( n ); int anz = 0 ; m = abs( m );
rBuffer B( fn, "" );
while ( B.find( 1, str, 0 ) )
{
if ( B.e <= B.a + strlen( str ) ) break ;
if At( B.z + B.a, str )
then {
anz++ ;
B.getmore( L ); if ( B.e <= B.a + L ) L = B.e - B.a ;
if ( n < 0 )
{
printf( "\nstrIn: %i.%s", Line, File );
traceStr( "strIn:", B.z + B.a - m - 4, L + m + 10 );
fErr1( str )
}
}
else {
traceStr( "error in find()", B.z + B.a, strlen(str) + 10 );
fErr2( str, B.e - B.a )
}
}
if ( anz ) printf( "\nstrIn: %3i times [%s] in %s", anz, str, fn );
LE_ret( anz );
/* public: */ BOOL safe_uts :: ok_is_ext
// -----------------------------------------------------------------------------
(
char * fn
, char * ext
)
LB_("safe_uts.ok_is_ext")
if ( ! fn ) fErr
if ( ! ext ) fErr
LE_ret( is_( fn + strlen( fn ) - strlen( ext ), ext ) )
/* public: */ char * safe_uts :: ok_tmp_ ( char * str
/* -----------------------------------------------------------------------------
Return pointer to the tmp fileAt suggested
This function is to ensure that we use our RamDisk for tmp files
if such a RamDisk actually exists
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_tmp_")
if ( ! str ) str = "" ;
char40 zz ; s_( zz, "%s/tmp_%s", tmpsAt, str );
int i = 0 ;
while ( i < e_tmps )
{
if is_( tmps[i], zz ) ret( tmps[i] ) else i += 1 ;
}
e_tmps = i+1 ;
tmps[i] = (( i )? eos( tmps[i-1] ) : eos( tmpsAt )) + 1 ;
strcpy( tmps[i], zz );
if ( 1000 <= eos( tmps[i] ) - tmpsAt )
{
m_errMess "System: too many tmps" m_
ret_error
}
LE_ret( tmps[i] )
/* public: */ uint safe_uts :: ok_tmpName ( char * dir
/* -----------------------------------------------------------------------------
Return a number N such that 'dir/N does not exist
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_tmpName")
if ( ! dir ) fErr else dir_exist( dir );
char800 fn ; s_( fn, "%s/%u_%u", dir, ++nameNr, processNr );
while path_exists( fn ) s_( fn, "%s/%u_%u", dir, ++nameNr, processNr );
LE_ret( nameNr )
/* public: */ uint safe_uts :: ok_wfind
/* -----------------------------------------------------------------------------
ein ufind() ohne Probleme mit Umlauten
return number of files found
-----------------------------------------------------------------------------
*/ (
FILE * f
, char * stru // path to file, char * oftree // path to dir ( -oftree: nur Verzeichnisse sehen ) )
LB_("safe_uts.ok_wfind")
char2000 wc ; uint anz = 0 ;
if ( ! oftree ) fErr
BOOL dateien = true ;
if ( *oftree == '-' )
{
dateien = false ; oftree++ ;
}
if not_is_dir( oftree )
{
m_errMess "System: no such folder: %s" m_
oftree, ret_error
}
char * e = eos( oftree ) - 1 ; if in_str( *e, "/\\" ) *e = 0 ;
BOOL close_f = false ;
if ( ! f )
{
close_f = true ;
strcpy( wc, oftree ); unix_me( wc ); f = create( stru );
fprintf( f, "\n%s", wc );
}
s_( wc, "%s/*", oftree ); dos_me( wc );
_finddata_t dta ; int h = _findfirst( wc, &dta ); ok
e = wc + strlen( wc ) - 2 ; *e = 0 ;
char * e1 = e ;
char1000 xx ; strcpy( xx, wc ); unix_me( xx );
while ( ! errno )
{
if ( not_is_( dta.name, "." )
&& not_is_( dta.name, ".." )
&& not_is_( dta.name, "System Volume Information" )
)
{
s_( e, "/%s", dta.name );
char1000 zz ; strcpy( zz, wc ); unix_me( zz );
if ( dateien || is_dir( zz ) )
{
fprintf( f, "\n%s", zz );
}
if ( dta.attrib & _A_SUBDIR && not_is_( dta.name, "j2h" ) )
then {
anz += ok_wfind( f, 0, wc );
*e = 0 ;
}
else anz++ ;
}
_findnext( h, &dta );
}
if ( errno != ENOENT )
{
m_errMess "System: errno %i: %s" m_
errno, wc, ret_error
}
;
ok _findclose( h ); ok
*e1 = 0 ;
if ( close_f ) close( f );
LE_ret( anz )
/* public: */ uint safe_uts :: ok_do_tree
/* -----------------------------------------------------------------------------
for f in *.ext do: S_ "%s %s %s", co1, f, co2 _Do
-----------------------------------------------------------------------------
*/ (
char * os // dos, unix
, char * oftree
, char * ext
, char * co1
, char * co2
, FILE * f // if ( f == 0 ) execute command, else write it to 'f )
LB_("safe_uts.ok_do_tree")
if ( ! os || not_in_str( *os, "du" ) ) fErr1( os )
if ( * co2 ) co2 = "" ;
char2000 wc ; uint anz = 0 ;
char * e = eos( oftree ) - 1 ; if in_str( *e, "/\\" ) *e = 0 ;
s_( wc, "%s/*", oftree ); dos_me( wc );
_finddata_t dta ; int h = _findfirst( wc, &dta ); ok
e = wc + strlen( wc ) - 2 ; *e = 0 ;
char * e1 = e ;
uint N = strlen( ext );
char1000 xx ; strcpy( xx, wc ); unix_me( xx );
while ( ! errno )
{
if ( not_is_( dta.name, "." )
&& not_is_( dta.name, ".." )
&& not_is_( dta.name, "System Volume Information" )
)
{
s_( e, "/%s", dta.name );
char1000 zz ; strcpy( zz, wc );
if is_( eos( wc ) - N, ext )
then {
if ( *os == 'u' ) unix_me( zz ); else dos_me( zz );
if ( f )
then {
fprintf( f, "\n%s \"%s\" %s", co1, zz, co2 );
}
else S_ "%s \"%s\" %s", co1, zz, co2 _Do
}
if ( dta.attrib & _A_SUBDIR && not_is_( dta.name, "j2h" ) )
then {
anz += ok_do_tree( os, wc, ext, co1, co2, f );
*e = 0 ;
}
else anz++ ;
}
_findnext( h, &dta );
}
if ( errno != ENOENT )
{
m_errMess "System: errno %i: %s" m_
errno, wc, ret_error
}
;
ok _findclose( h ); ok
*e1 = 0 ;
LE_ret( anz )
/* public: */ int safe_uts :: ok_setMx
// -----------------------------------------------------------------------------
(
int & n1
, int n2
)
LB_("safe_uts.ok_setMx")
if ( n1 < n2 ) n1 = n2 ;
LE_ret( n1 )
/* public: */ float safe_uts :: ok_Maxfp
// -----------------------------------------------------------------------------
(
float n1
, float n2
)
LB_("safe_uts.ok_Maxfp")
LE_ret( ( n1 < n2 )? n2 : n1 )
/* public: */ float safe_uts :: ok_Absfp ( float x
// -----------------------------------------------------------------------------
)
{
return( ( x < 0 )? -x : x );
}
/* public: */ float safe_uts :: ok_MaxAbsfp
// -----------------------------------------------------------------------------
(
float n1
, float n2
)
{
float z1 = ( 0 < n1 )? n1 : -n1 ;
float z2 = ( 0 < n2 )? n2 : -n2 ;
//
// muss so kompliziert sein, da abs() nach uint rundet !!!!!!
return( ( n1 < n2 )? n2 : n1 );
}
/* public: */ int safe_uts :: ok_Max
// -----------------------------------------------------------------------------
(
int n1
, int n2
)
{
return( ( n1 < n2 )? n2 : n1 );
}
/* public: */ void safe_uts :: ok_setenv
/* -----------------------------------------------------------------------------
notwendig nur beim MS Compiler
-----------------------------------------------------------------------------
*/ (
char * Var
, char * Value
)
LB_("safe_uts.ok_setenv")
char1000 xx ; s_( xx, "%s=%s", Var, Value ); _putenv( xx );
char * x = getenv( Var );
if ( ! x || not_is_( x, Value ) ) fErr3( x, Var, Value )
LE_
/* public: */ void safe_uts :: ok_setenv ( char * fn
/* -----------------------------------------------------------------------------
executiert alle set Statements im file
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_setenv")
rBuffer B( fn, "\n" );
while ( B.find( 0, "set ", 0 ) ) if space( B.z[ B.a-1 ] )
{
char * V ;
char * n = B.z + B.a + 4 ; skip_space( n );
char * e = n ; to_( e, '=' ) *e++ = 0 ;
if ( *e == '"' )
then {
V = ++e ; to_( e, '"' )
}
else {
V = e ; to_space( e )
}
*e = 0 ; setenv( n, V );
B.a = e - B.z ;
}
LE_
/* public: */ char * safe_uts :: ok_retVar
/* -----------------------------------------------------------------------------
executiert alle set Statements im file
-----------------------------------------------------------------------------
*/ (
char * fn
, char * Var
, str_set & store
)
LB_("safe_uts.ok_retVar")
rBuffer B( fn, "\n" );
char * V = 0 ;
while ( B.find( 1, "set ", 0 ) )
{
char * c = B.z + B.a - 1 ;
if ( *c && not_space( *c ) ) continue ;
char * n = B.z + B.a + 4 ; skip_space( n );
char * e = n ;
while ( *e && *e != '=' ) e++ ; *e++ = 0 ;
//
// Muss so sein, da es Text ... set xxx set Var= ... geben
// kann, so dass in xxx kein '=' ist.
if is_( n, Var )
{
if ( *e == '"' )
then {
V = ++e ; to_( e, '"' )
}
else {
V = e ; to_( e, '\n' )
}
B.a = e - B.z ; *e = 0 ; // muss 0 sein
}
// Note: We need to read the complete file because we have to find
// the last definition for Var.
}
if ( ! V )
{
m_errMess "User: %s not specified in %s" m_
Var, fn, ret_error
}
LE_ret( store.take( V ) )
/* public: */ float safe_uts :: ok_decdecNr ( char * str
/* -----------------------------------------------------------------------------
FEHLER in exec_ut.cpp bei Ausgabe von float-Werten:
Dezimalstellen werden von _1() nicht gezeigt, sind aber dennoch da !!!!
string to float
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_decdecNr")
float x = 0.0 ; char c1 = ',' ;
float k = 1.0 ; char c2 = '.' ;
if ( ! str ) fErr
while ( *str == ' ' || *str == '\t' ) str++ ;
if ( *str == '\n' ) ret( 0.0 )
char * c = str ;
while ( *c && not_space( *c ) && *c != ',' ) c++ ;
if ( *c != ',' ) { c1 = c2 ; c2 = 0 ; }
char * w2 = str ;
char * w1 = str ;
char * w = str ;
if ( *w1 == '"' ) w = w1 = str + 1 ;
if ( *w == '-' ) w++ ;
while ( *w && *w != c1 && not_space( *w ) )
{
if ( *w == c2 ) w++ ;
if not_digit( *w ) break ;
x = x * 10.0 + 1.0 * ( ( uchar )*w - ( uchar )'0' );
w++ ;
}
if ( *w == c1 ) w++ ;
while ( *w && not_space( *w ) )
{
if not_digit( *w ) break ;
k = k/10 ;
x = x + k * ( ( uchar )*w - ( uchar )'0' );
w++ ;
}
LE_ret( ( *w1 == '-' )? -x : x )
/* public: */ void safe_uts :: ok_execAt
/* -----------------------------------------------------------------------------
execute command from a specific folder
-----------------------------------------------------------------------------
*/ (
char * dir
, char * comm
)
LB_("safe_uts.ok_execAt")
if not_is_dir( dir )
{
m_errMess "User: no such folder: %s" m_
dir, ret_error
}
char800 eAt ; strcpy( eAt, dir ); dos_me( eAt );
char800 cwd ; getcwd( cwd, 800 );
if ( ! comm ) fErr
if ( ! comm ) comm = "attrib -r /s" ;
_3( eAt, cwd, comm )
S_ "-cd /d \"%s\"", eAt _Do
S_ "%s" , comm _Do
S_ "-cd /d \"%s\"", cwd _Do
LE_
/* public: */ char * safe_uts :: ok_backto
/* -----------------------------------------------------------------------------
back to character c or str
-----------------------------------------------------------------------------
*/ (
char * str
, char c
)
LB_("safe_uts.ok_backto")
if ( ! str ) fErr
char * x = eos( str ); while ( str < x && *x != c ) x-- ;
LE_ret( x )
/* public: */ char * safe_uts :: ok_backto
/* -----------------------------------------------------------------------------
back to s
-----------------------------------------------------------------------------
*/ (
char * str
, char * sustr
)
LB_("safe_uts.ok_backto")
if ( ! str ) fErr
char * x = eos( str ) - 1 ;
while ( str <= x && not_At( x, sustr ) ) x-- ;
LE_ret( x )
/* public: */ char * safe_uts :: ok_backtoSucc
/* -----------------------------------------------------------------------------
Back to the first char in the longest postfix not containing c
-----------------------------------------------------------------------------
*/ (
char * str
, char * substr
)
LB_("safe_uts.ok_backtoSucc")
if ( ! str ) fErr
char * x = eos( str ); while ( str <= x && not_At( x, substr ) ) x-- ;
if ( x < str ) ret( str )
LE_ret( x + strlen( substr ) )
/* public: */ char * safe_uts :: ok_namAnf ( char * str
/* -----------------------------------------------------------------------------
Back to the first char folowing / or \
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_namAnf")
if ( ! str ) fErr
char * x = eos( str );
while ( str <= x && not_in_str( *x, "/\\" ) ) x-- ;
if ( x < str ) ret( str )
LE_ret( x+1 )
/* public: */ void safe_uts :: ok_rette_fs
/* -----------------------------------------------------------------------------
mache nch/fs zu einer Kopie von aus/fs
Hierbei kann fs auch Wildcards enthalten (etwa * sein).
-----------------------------------------------------------------------------
*/ (
char * aus
, char * nch
, uint dated // BOOL( 0, 5, 8, 9 )
, char * fs
)
LB_("safe_uts.ok_rette_fs")
if ( ! aus || ! nch || ! fs || is_( aus, nch ) ) fErr3( aus, nch, fs )
if not_is_dir( nch )
{
m_errMess "User: not such dir nch = %s" m_
nch, ret_error
}
;
char100 date ; *date = 0 ;
if ( dated )
{
if ( dated < 4 ) dated = 0 ;
esif ( dated == 4 ) dated = 5 ;
esif ( dated == 7 ) dated = 8 ;
esif ( dated > 9 ) dated = 9 ;
s_( date, "/%s", currentDate() + dated );
}
char800 xxA ; s_( xxA, "%s/%s" , aus, fs );
char800 xxN ; s_( xxN, "%s/%s%s", nch, date, fs );
char * xA = backto( xxA, '/' ); *xA = 0 ;
char * xN = backto( xxN, '/' ); *xN = 0 ;
if not_is_dir( xxA )
{
m_errMess "User: no such src folder: %s" m_
xxA, ret_error
}
;
*xA = *xN = '/' ;
if not_is_dir( xxA )
then {
*xN = 0 ; dir_exist( xxN );
S_ "copy %s %s", xxA, xxN _Do
}
else S_ "cptree %s %s", xxA, xxN _Do
printf( "\nsee BackUp = %s", xxN );
LE_
/* public: */ uint safe_uts :: ok_str_match
/* -----------------------------------------------------------------------------
return the length of the longest common prefix
-----------------------------------------------------------------------------
*/ (
char * s1
, char * s2
)
LB_("safe_uts.ok_str_match")
uint m = 0 ;
while ( *s1 && *s2 && *s1 == *s2 )
{
m++ ; s1++ ; s2++ ;
}
LE_ret( m )
/* public: */ uint safe_uts :: ok_prefix_match
/* -----------------------------------------------------------------------------
return the length of the longest prefix of s1 that is substring of s2
-----------------------------------------------------------------------------
*/ (
char * s1
, char * s2
)
LB_("safe_uts.ok_prefix_match")
uint m = 0 ;
char * s = s2-1 ;
char * e = eos( s2 );
while ( ++s+m < e )
{
uint M = str_match( s1, s );
if ( m < M ) then m = M ;
}
LE_ret( m )
/* public: */ uint safe_uts :: ok_substr_match
/* -----------------------------------------------------------------------------
return the length of the 1st longest substr of s1 that is substring of s2
-----------------------------------------------------------------------------
*/ (
char * s1
, char * s2
)
LB_("safe_uts.ok_substr_match")
uint m = 0 ;
while ( *s1 )
{
char * s = s2 ;
while ( *s )
{
uint M = str_match( s1, s );
if ( m < M )
{
m = M ;
}
s++ ;
}
s1++ ;
}
LE_ret( m )
/* public: */ uint safe_uts :: ok_word_match
/* -----------------------------------------------------------------------------
return BOOL( each word in s1 is substring of s2 )
-----------------------------------------------------------------------------
*/ (
BOOL capitalized
, char * s1
, char * s2
)
LB_("safe_uts.ok_word_match")
uint matches = 0 ;
char * ee = eos( s1 );
while ( *s1 && space( *s1) ) s1++ ;
while ( *s1 )
{
char * e = s1 ;
while ( *e && not_space( *e ) ) e++ ;
if ( *e )
then {
*e = 0 ;
if ( ee <= s1 ) ret( matches )
BOOL sub = substr( s1, s2 )? true : false ;
*e = ' ' ;
if ( sub )
then {
matches++ ; s1 = e+1 ;
}
else ret( 0 )
while ( *s1 && space(*s1) ) s1++ ;
if ( capitalized ) while ( *s1 && *s1 != upper( *s1 ) ) s1++ ;
if ( ! *s1 ) ret( matches )
}
esif substr( s1, s2 ) ret( matches + 1 ) else ret( 0 )
}
LE_ret( matches )
/* public: */ char * safe_uts :: ok_thisDir (
/* -----------------------------------------------------------------------------
return absolute path of Current Working Directory (= CWD)
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_thisDir")
getcwd( cwd, 800 ); unix_me( cwd );
LE_ret( cwd )
/* public: */ void safe_uts :: ok_ersChar
/* -----------------------------------------------------------------------------
Ersetze in 'str jedes 'c1 durch ein 'c2
-----------------------------------------------------------------------------
*/ (
char c1
, char c2
, char * str
)
LB_("safe_uts.ok_ersChar")
if ( ! str ) fErr3( c1, c2, str )
char * x = str-1 ;
while ( *( ++x ) ) if ( *x == c1 ) *x = c2 ;
LE_
/* public: */ char * safe_uts :: ok_corrStr
/* -----------------------------------------------------------------------------
Ersetze in 'str jeden substr 'str1 durch 'str2
-----------------------------------------------------------------------------
*/ (
char * str
, char * str1
, char * str2
, char * zstr // destination buffer
, char * estr // end of destination buffer (= 0 if strlen is not to grow)
)
LB_("safe_uts.ok_corrStr")
if ( ! str || ! str1 || ! *str1 || ! str2 ) then fErr3( str, str1, str2 )
if ( ! estr ) estr = zstr + strlen( str );
char * x = str ;
char * z = zstr ;
uint L = strlen( str1 );
uint M = strlen( str2 );
while ( *x )
{
if At( x, str1 )
then {
if ( estr <= z + M ) then fErr
strcpy( z, str2 ); z += M ; x += L ;
}
else {
if ( estr <= z + 1 ) then fErr
*z++ = *x++ ;
}
}
*z = 0 ;
LE_ret( zstr )
/* public: */ char * safe_uts :: ok_normName
/* -----------------------------------------------------------------------------
Ersetze in 'str jeden substr 'str1 durch 'str2
-----------------------------------------------------------------------------
*/ (
char * nch
, char * aus
)
LB_("safe_uts.ok_normName")
if ( ! nch || ! aus ) fErr2( aus, nch )
strcpy( nch, aus ); lower( nch ); *nch = upper( *nch );
char * z = nch ;
while ( *( ++z ) )
{
if not_alpha( z[-1] ) *z = upper( *z );
if not_in_name( *z ) *z = '@' ;
}
LE_ret( nch )
/* public: */ void safe_uts :: ok_upperName ( char * c
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_upperName")
while alphanum( *c ) { *c = upper( *c ); c++ ; }
LE_
/* public: */ BOOL safe_uts :: ok_Identifier ( char * c
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_Identifier")
char * x = c-1 ;
while ( *(++x) ) if not_in_name( *x ) ret( 0 )
LE_ret( 1 )
/* public: */ BOOL safe_uts :: ok_names ( char * c
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_names")
char * x = c-1 ;
while ( *(++x) ) if ( *x != ' ' && not_in_name( *x ) ) ret( 0 )
LE_ret( 1 )
/* public: */ BOOL safe_uts :: ok_quote ( char c
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_quote")
LE_ret( in_str( c, "'`\"" ) != 0 )
/* public: */ void safe_uts :: ok_shrink ( char * str
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_shrink")
char * x = str ;
char * z = str ;
while ( *x )
{
if space( *x )
then {
*z++ = ' ' ; skip_space( x );
}
else *z++ = *x++ ;
}
*z = 0 ;
LE_
/* public: */ char * safe_uts :: ok_eosAt
/* -----------------------------------------------------------------------------
return new eos(str)
-----------------------------------------------------------------------------
*/ (
char * str
, char * endAt
)
LB_("safe_uts.ok_eosAt")
char * x = substr( endAt, str ); if ( x ) *x = 0 ;
LE_ret( eos(str) )
/* public: */ void safe_uts :: ok_strUm
/* -----------------------------------------------------------------------------
trace Zeichenfolge um c herum
-----------------------------------------------------------------------------
*/ (
char * c1
, char * c
, uint n2
, char * e1
, char * e
)
LB_("safe_uts.ok_strUm")
*e = 0 ; _1( e1 )
char20 xx ; s_( xx, "errUm(%i,%i): ", c-c1, n2 );
traceStr( xx, c1, (c-c1) + 1 + n2 );
LE_
/* public: */ BOOL safe_uts :: ok_cp_prefix // return substr( str, aus )
// -----------------------------------------------------------------------------
(
char * nch
, char * aus
, char * str
, BOOL mitstr
)
LB_("safe_uts.ok_cp_prefix")
if ( ! nch ) fErr
if ( ! aus ) fErr
if not_substr( str, aus ) ret( 0 )
char * z = nch ;
char * x = aus ;
while not_At( x, str ) *z++ = *x++ ;
if ( mitstr ) strcpy( z, str ); else *z = 0 ;
LE_ret( 1 )
/* public: */ void safe_uts :: ok_hoAus // hole aus ... bis zu str
// -----------------------------------------------------------------------------
(
char * nch
, char * aus
, char * str
)
LB_("safe_uts.ok_hoAus")
if ( ! ok_cp_prefix( nch, aus, str, 0 ) ) fErr2( str, aus )
LE_
/* public: */ char * safe_uts :: ok_koSEL
// -----------------------------------------------------------------------------
// return TRUE, iff one part x of SEL = x1,x2,x3,..... is substr of str
// -----------------------------------------------------------------------------
(
char * SEL
, char * str
)
LB_("safe_uts.ok_koSEL")
if ( ! SEL || ! str ) fErr2( SEL, str )
char * res = 0 ;
char * k = eos( SEL );
while ( SEL < k && ! res )
{
char * e = k ; char m = *e ; *e = 0 ;
while ( SEL < k && *k != ',' ) k-- ;
if ( *k == ',' ) k++ ;
res = substr( k, str );
*e = m ;
}
LE_ret( res )
/* public: */ BOOL safe_uts :: ok_select_this
// -----------------------------------------------------------------------------
// return TRUE, iff all parts x of SEL = x1~x2~x3~..... are substr of str
// -----------------------------------------------------------------------------
(
char * SEL
, char * str
)
LB_("safe_uts.ok_select_this")
if ( ! SEL || ! str ) fErr2( SEL, str )
if substr( SEL, str ) ret( 1 )
if not_in_str( '~', SEL ) ret( 0 )
char * ss = str ; char * s = SEL ;
while ( s && ss )
{
char * x = in_str( '~', s );
if ( x )
then {
*x = 0 ;
ss = substr( s, str );
*x = '~' ;
if ( ! ss ) ret( 0 ) else s = x+1 ;
}
else {
ss = substr( s, str );
s = 0 ;
}
}
if ( ss ) ret( 1 )
LE_ret( 0 )
/* public: */ char safe_uts :: ok_fastAlphaNum ( char x
// -----------------------------------------------------------------------------
// wandelt Umlaute zum entsprechenden Vokal bzw. zu s
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_fastAlphaNum")
uchar m = ( uchar ) x ;
switch ( m )
{
case 246 : ret( 'o' ) break ; //
case 228 : ret( 'a' ) break ; //
case 252 : ret( 'u' ) break ; // ue
case 214 : ret( 'O' ) break ; //
case 196 : ret( 'A' ) break ; //
case 220 : ret( 'U' ) break ; //
case 223 : ret( 's' ) break ; //
}
LE_ret( alphanum( x )? x : 0 )
/* public: */ char * safe_uts :: ok_mae2win ( char * str
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_mae2win")
char * x = str - 1 ;
while ( *( ++x ) )
{
uchar m = ( uchar ) *x ;
switch ( m )
{
case 148 : *x = ( uchar ) 246 ; break ; //
case 132 : *x = ( uchar ) 228 ; break ; //
case 129 : *x = ( uchar ) 252 ; break ; // ue
case 153 : *x = ( uchar ) 214 ; break ; //
case 142 : *x = ( uchar ) 196 ; break ; //
case 154 : *x = ( uchar ) 220 ; break ; //
case 225 : *x = ( uchar ) 223 ; break ; //
}
}
LE_ret( str )
/* public: */ uint safe_uts :: ok_schmutz ( char * fAt
// -----------------------------------------------------------------------------
// grep "Y =" auf stdout zeigt not-win-character coding (sog. Schmutz)
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_schmutz")
uint Anz = 0 ;
rBuffer B( fAt, "" ); char * x = B.z + B.a ;
while ( *(++x) )
{
if ( ( uchar ) *x > 128 )
{
uchar m = *x ;
if ( m == 246 ) continue ;
esif ( m == 228 ) continue ;
esif ( m == 252 ) continue ;
esif ( m == 214 ) continue ;
esif ( m == 196 ) continue ;
esif ( m == 220 ) continue ;
esif ( m == 223 ) continue ;
Anz++ ;
char * e = x ; while ( *(++e) != '\n' && e-x < 20 ) e++ ;
traceStr( "Y", x, e-x );
printf( "\nY == %u %u %u %u %u ... %s", ( uchar ) x[0]
, ( uchar ) x[1]
, ( uchar ) x[2]
, ( uchar ) x[3]
, ( uchar ) x[4], fAt );
x += 5 ;
}
}
LE_ret( Anz )
/* public: */ char * safe_uts :: ok_utf2win ( char * str
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_utf2win")
char * z = str ;
char * x = str ;
while ( *x )
{
uchar m = ( uchar ) *x ;
if ( m == 195 )
{
m = ( uchar ) x[1] ;
switch ( m )
{
case 182 : x += 2 ; *z++ = ( uchar ) 246 ; break ; //
case 164 : x += 2 ; *z++ = ( uchar ) 228 ; break ; //
case 188 : x += 2 ; *z++ = ( uchar ) 252 ; break ; // ue
case 150 : x += 2 ; *z++ = ( uchar ) 214 ; break ; //
case 132 : x += 2 ; *z++ = ( uchar ) 196 ; break ; //
case 156 : x += 2 ; *z++ = ( uchar ) 220 ; break ; //
case 159 : x += 2 ; *z++ = ( uchar ) 223 ; break ; //
default : *z++ = *x++ ;
}
}
esif ( m == 194 )
{
m = ( uchar ) x[1] ;
switch ( m )
{
case 160 : x += 2 ; *z++ = ' ' ; break ; // space
case 180 : x += 2 ; *z++ = ( uchar ) 39 ; break ; // Apostr
default : *z++ = *x++ ;
}
}
esif ( m == 226 && ( uchar ) x[1] == ( uchar ) 128
&& ( uchar ) x[2] == ( uchar ) 153
)
{
x += 3 ; *z++ = ( uchar ) 39 ; // Apostroph
}
esif ( m == 226 && ( uchar ) x[1] == ( uchar ) 128
&& ( uchar ) x[2] == ( uchar ) 168
)
{
x += 3 ; *z++ = ' ' ;
}
esif ( m == 226 && ( uchar ) x[1] == ( uchar ) 128
&& ( ( uchar ) x[2] == ( uchar ) 158
|| ( uchar ) x[2] == ( uchar ) 156 )
)
{
x += 3 ; *z++ = ( uchar ) 34 ; // Gnsefuesschen
}
else *z++ = *x++ ;
}
*z = 0 ;
LE_ret( str )
/* public: */ char * safe_uts :: ok_norm_date ( char * str
// -----------------------------------------------------------------------------
// DD.MM.YYYY, and also DD-MM-YYYY, become YYYY.MM.DD
//
// Note: YYYY.MM.DD in CSV is presented in EXCEL GUI as DD.MM.YYYY
//
// Code for timestamp to YYYY.MM.DD exists in mantis.ic
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_norm_date")
if not_digit( str[4] ) { str[4] = str[7] = '.' ; ret( str ) }
char20 xx ; strcpy( xx, str );
str[ 0 ] = xx[ 6 ] ;
str[ 1 ] = xx[ 7 ] ;
str[ 2 ] = xx[ 8 ] ;
str[ 3 ] = xx[ 9 ] ;
str[ 4 ] = '.' ;
str[ 5 ] = xx[ 3 ] ;
str[ 6 ] = xx[ 4 ] ;
str[ 7 ] = '.' ;
str[ 8 ] = xx[ 0 ] ;
str[ 9 ] = xx[ 1 ] ;
str[ 10 ] = 0 ;
LE_ret( str )
/* public: */ char * safe_uts :: ok_Appwin_exists ( char * str
// -----------------------------------------------------------------------------
// str muss substr() des Fenstertitels sein
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_Appwin_exists")
if ( !str || !*str ) fErr1( str )
char * tm1 = "tmp_tasks" ;
S_ "-tasklist /V > %s", tm1 _Do
rBuffer B( tm1, "" );
char * res = substr( str, B.z + B.a );
Unlink( tm1 );
LE_ret( 0 )
/* public: */ void safe_uts :: ok_close_Appwins
/* -----------------------------------------------------------------------------
str = win1~win2~win3~win4~...
str = win1/win2/win3/win4/...
str = win1:win2:win3:win4:... via autoIt3
for X = 1, 2, 3, 4, ... do:
close ALL windows with a title containing winX as a substring
WARNING: If more than one such window is open, the function will ask
the user for confirmation.
NOTE: close_Appwins.exe = ntuse_/run/R.exe (dort auch ein *.HLP file)
-----------------------------------------------------------------------------
VBScript:
set wsh = CreateObject( "wscript.shell" )
if wsh.appActivate( "Untitled - Notepad" ) then
wsh.sendkeys "%{F4}"
end If
ODER:
set o = CreateObject("APIWrapperCOM.APIWrapper")
winHandle = o.findWindow("test.txt - Notepad")
o.killWindow( winHandle )
ODER:
tasklist /V > tmp
Dann in tmp alle Window Titles suchen, die betroffen sind, und
dann in jeweils derselben Zeile die Process ID.
Mit der dann pskill aufrufen.
-----------------------------------------------------------------------------
*/ (
BOOL sync // 1 = synchron, 2 = asynchron mit Aufrufer
, char * str
)
LB_("safe_uts.ok_close_Appwins")
char M = in_str( '~', str )? '~' : '/' ;
{
char * tm1 = "tmp_tasks" ;
S_ "-tasklist /V > %s", tm1 _Do
rBuffer B( tm1, "" );
char * x = substr( "===", B.z + B.a ); if ( !x ) fErr
B.a = x - B.z ;
char * x1 = x ;
x = substr( " ===", x+4 ); uint n1 = x + 4 - x1 ;
x = substr( " ===", x+4 );
x = substr( " ===", x+4 );
x = substr( " ===", x+4 );
x = substr( " ===", x+4 );
x = substr( " ===", x+4 );
x = substr( " ===", x+4 );
x = substr( " ===", x+4 ); uint n2 = x + 1 - x1 ;
while ( B.find( 0, "\n", 0 ) )
{
char * c = B.z + B.a + 1 ;
char * p = c + n1 ;
char * w = c + n2 ;
char * e = w ; to_( e, '\n' ) *e = 0 ;
if not_At( w, "Nicht zutreffend" )
{
char * s = str ;
while ( *s )
{
char * x = in_str( M, s ); if ( x ) *x = 0 ;
if ( substr( s, w ) && not_At( c, "cmd.exe" ) )
{
printf( "\npskill Appwin: %s", w );
S_ "taskkill /PID %i /T", decNr( p ) _Do
break ;
}
if ( x ) s = x+1 ; else s = eos(s) ;
}
}
B.a = e - B.z ; *e = '\n' ;
}
unlink( tm1); ok
}
ret_
if in_str( ':', str )
{
// AutoIt3 hat einen exe Compiler - jene exes laufen aber nicht unter
// Vista !!!!
if ( sync )
then S_ "nowin %s", str _Do
else S_ "start nowin %s", str _Do
ret_
}
char1000 comm ; s_( comm, "TASKKILL /F" );
char * eco = eos( comm );
char * wcx = "wcx.cmd" ;
FILE * f = create( wcx );
uint Anz1 = 0 ;
uint Anz2 = 0 ;
char * x = str ;
while ( (x-1) )
{
char * e = in_str( '/', x ); if ( e ) *e = 0 ;
if not_in_str( '*', x )
{
Anz1++ ;
fprintf( f, "\nwin close %s", x );
}
Anz2++ ;
if substr( ".exe", x )
then {
s_( eos( eco ), " /IM \"%s\"", x );
}
else s_( eos( eco ), " /FI \"WINDOWTITLE eq %s*\"", x );
x = e+1 ;
if ( e ) *e = '/' ;
}
close( f );
_1(comm+0)
if ( Anz2 ) S_ "%s", comm _Do
if ( Anz1 ) S_ "rwc %s", wcx _Do
// Microsoft's method seems not work for Wildcards *XXX
unlink( wcx );
LE_
/* public: */ void safe_uts :: ok_close_windows
// -----------------------------------------------------------------------------
// str = str1/str2/.../strN
//
// Close all windows having one such strX as a substring in the title
// -----------------------------------------------------------------------------
(
BOOL sync // 1 = synchron, 2 = asynchron mit Aufrufer
, char * str
)
LB_("safe_uts.ok_close_windows")
close_Appwins( sync, str );
ret_
char * tm1 = "x_wc.bat" ; FILE * f = create( tm1 );
char * x = str ;
while ( x )
{
char * e = in_str( '/', x ); if ( e ) *e = 0 ;
fprintf( f, "\nwin close %s", x );
if ( e ) *e = '/' ;
x = ( e )? e+1 : 0 ;
}
close( f );
S_ "rwc %s", tm1 _Do
unlink( tm1 );
LE_
/* public: */ BOOL safe_uts :: ok_show_or_DEL
// -----------------------------------------------------------------------------
(
long L
, char * fAt
)
LB_("safe_uts.ok_show_or_DEL")
if ( is_file( fAt ) && L < file_len( fAt ) )
then {
S_ "notepad %s", fAt _Do
}
else unlink( fAt );
LE_ret( is_file( fAt ) )
/* public: */ char * safe_uts :: ok_toz
// -----------------------------------------------------------------------------
(
char * z
, char * str
)
LB_("safe_uts.ok_toz")
strcpy( z, str );
LE_ret( eos( z ) )
/* public: */ void safe_uts :: ok_KILL ( char * exe
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_KILL")
if iAt( exe, "pskill" )
{
char * x = in_str( ' ', exe ); while ( *(++x) == ' ' ) {}
char100 xx ; s_( xx, "%s%s", x, isubstr( ".exe", x )? "" : ".exe" );
KILL( xx );
printf( "\nerrno = %i : KILL( %s )", errno, x );
ok ret_
}
#undef system
char100 comm ;
// Mit /F frgt dass Programm nicht nach, ob man noch nicht gespeicherte
// nderungen einer Datei erst noch speichern mchte.
//
// Mit /T werden auch alle Sohnprozesse gekillt:
if in_str( '*', exe )
then {
s_( comm, "taskkill /F /T /FI \"WINDOWTITLE eq %s", exe );
}
else s_( comm, "taskkill /F /T /IM %s", exe );
system( comm ); ok _1(comm)
#define system safe_ut.ok_system
LE_
/* public: */ void safe_uts :: ok_fazit_trace
// -----------------------------------------------------------------------------
(
char * traceAt
, char * nch
)
LB_("safe_uts.ok_fazit_trace")
if ( ! nch || ! *nch ) fErr2( traceAt, nch )
if not_is_file( traceAt )
{
m_errMess "User: no such trace file: %s" m_
traceAt, ret_error
}
rBuffer B( traceAt, "\n" ); FILE * f = create( nch );
while ( B.find( 1, "\n", 0 ) )
{
char * c = B.z + B.a + 1 ;
if At( c, "fatal" )
then {
B.find( 0, "\n]", f );
B.find( 1, "\n" , f );
}
esif At( c, "o k - " )
{
B.find( 1, "\n" , f );
}
}
close( f );
S_ "start notepad %s", nch _Do
LE_
/* public: */ void safe_uts :: ok_EXIT ( int rc
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_EXIT")
fflush( stdout );
fflush( stderr );
#undef exit
char100 zz ; s_( zz, "DONE, exit with rc = %i", rc );
popup( zz );
exit( rc );
# define exit safe_ut.ok_EXIT
LE_
/* public: */ void safe_uts :: ok_DEL ( char * str
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_DEL")
if ( !str || ! *str || *str == '"' ) fErr1( str )
// char800 was ; strcpy( was, str ); dos_me( was );
char800 was ; s_( was, "DEL \"%s\"", str ); dos_me( was );
system_do( was );
LE_
/* public: */ void safe_uts :: ok_popup ( char * str
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_popup")
if ( ! str || ! *str ) ret_
char * tm1 = "doo.vbs" ; FILE * f = create( tm1 );
skip_space( str );
char2000 zz ; char * x = str ; char * z = zz ;
while ( *x )
{
if ( *x == '\n' ) break ; else *z++ = *x++ ;
}
*z = 0 ;
fprintf( f, "\nmsgBox \"%s\"", zz );
printf( "\nmsgBox \"%s\"", zz );
close( f );
S_ "%s", tm1 _Do
Unlink( tm1 )
LE_
/* public: */ void safe_uts :: ok_doAnderswo
// -----------------------------------------------------------------------------
// If ( *comm ) then execute command comm in folder doAt
// else make doAt the current working dir
// -----------------------------------------------------------------------------
(
char * doAt
, char * comm
, char * trace
)
LB_("safe_uts.ok_doAnderswo")
if not_is_dir( doAt )
{
{
m_errMess "System: no such doAt folder: %s\ncurrDir = %s" m_
doAt, ro_currDir, ret_error
}
}
char800 before ; strcpy( before, ro_currDir ); chdir( doAt );
if ( errno ) fErr3( errno, doAt, ( char * ) ro_currDir )
if ( comm && *comm )
{ // _1(comm)
if ( trace && *trace )
then {
S_ "%s > %s", comm, trace _Do
}
else S_ "%s", comm _Do
// _1(errno+1-1) ok
S_ "DEL xNUL_*" _Do
// _1(errno) ok _1(before)
chdir( before );
if ( errno ) fErr3( errno, before, ( char * ) ro_currDir )
}
LE_
/* public: */ char * safe_uts :: ok_memstr
// -----------------------------------------------------------------------------
// Erweitere string c um eine Vorsilbe, die Kopie von str ist.
// -----------------------------------------------------------------------------
(
char * c
, char * str
)
LB_("safe_uts.ok_memstr")
if ( ! c || ! str ) fErr2( c, str )
uint L = strlen( str );
c -= L ; memcpy( c, str, L );
LE_ret( c )
/* public: */ char * safe_uts :: ok_es_
// -----------------------------------------------------------------------------
(
char * e
, char * str
)
LB_("safe_uts.ok_es_")
s_( e, str ); e = eos( e );
LE_ret( e )
/* public: */ void safe_uts :: ok_strTrace
// -----------------------------------------------------------------------------
(
char * Nam
, char * str
)
LB_("safe_uts.ok_strTrace")
char * u = ( iAt( Nam, "err" ) )? "\n|\n" : "" ;
printf( "\n[\n%s:%s%s\n|\n].Len = %i\n", Nam, u, str, strlen( str ) );
if ( *u )
{
m_errMess "System: see %s data above ..." m_
Nam, ret_error
}
LE_
/* public: */ char * safe_uts :: ok_strNorm
// -----------------------------------------------------------------------------
// Strings, die sich nur durch Spaces, Underscores oder gro/klein
// unterscheiden, haben dieselbe Norm
// -----------------------------------------------------------------------------
(
char * nstr // out: der normierte str
, char * str
, uint mxLen
)
LB_("safe_uts.ok_strNorm")
if ( ! str || ! *str ) fErr1( str )
char * e = nstr + mxLen ;
char * z = nstr ;
char * x = str-1 ;
while ( *(++x) ) if alphanum( *x ) *z++ = lower( *x );
if ( e <= z ) fErr1( str ) else *z = 0 ;
LE_ret( nstr )
/* public: */ uint safe_uts :: ok_wait_for
/* -----------------------------------------------------------------------------
Die C++ proc sleep() = Sleep() funktioniert nicht - warum ?????
Sie ist - als Sleep() - definiert in WINBASE.H
-----------------------------------------------------------------------------
*/ (
char * fAt
, uint msec
, BOOL rm
, uint M
)
LB_("safe_uts.ok_wait_for")
uint i = 0 ;
char40 com ; s_( com, "sleep_ms %u", msec );
while not_is_file( fAt )
{
if ( M < ++i ) break ; else system_do( com );
printf( "\nwait %u ms for %s", msec, fAt );
}
if ( rm ) { unlink( fAt ); ok }
LE_ret( i )
/* public: */ void safe_uts :: ok_existiere_Leer ( char * fAt
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_existiere_Leer")
FILE * f = create( fAt ); close( f );
LE_
/* public: */ BOOL safe_uts :: ok_not_htm ( char * fAt
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_not_htm")
int k = 0 ;
if not_is_file( fAt ) fErr1( fAt )
rBuffer B( fAt, "" ); // ( ! B.find( 0, "<body" , 0 ) ) ret( 0 )
char * c ;
char * e ;
Loop {
c = B.z + B.a - 1 ;
e = B.z + B.e ;
while ( ++c < e )
{
if ( *c == '<' )
then {
if ( 1 < ++k ) goto L ;
if(0) if At( c, "<!--" ) { //ret( --k )
B.a = c - B.z ;
traceStr( "ccc",c,100);
if ( ! B.find( 1, "-->", 0 ) ) fErr1( fAt )
c = B.z + B.a ;
e = B.z + B.e ;
traceStr( "ccc",c,e-c );
}
}
esif ( *c == '>' )
{
if ( 0 > --k ) goto L ;
}
}
if ( B.ateof ) break ;
B.a = e - B.z ; B.getmore( 2000 );
}
if ( k ) printf( "\n%i,notHTML.k,f = %i, %s [e-c = %i]", B.ateof, k, fAt, e-c );
ret( k )
char40 xx ; s_( xx, "notHTML( k = %i ): ", k );
L: traceStr( xx, c-8, 40 );
LE_ret( k )
/* public: */ BOOL safe_uts :: ok_rm_unicode
// -----------------------------------------------------------------------------
// unicode to iso
// -----------------------------------------------------------------------------
(
char * x
, uchar c1
, uchar c2
, uchar c3
)
LB_("safe_uts.ok_rm_unicode")
if ( (uchar) *x == c1 && (uchar) x[1] == c2 )
{
*x = c3 ;
strcpy( x+1, x+2 );
ret( 1 )
}
LE_ret( 0 )
/* public: */ char * safe_uts :: ok_werde_fNam ( char * str
// -----------------------------------------------------------------------------
// um UTF chars zu finden ...
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_werde_fNam")
char * z = str ;
char * x = str-1 ;
while ( *(++x) )
{
if alphanum( *x ) *z++ = *x ;
esif ( *x == '&' )
{
if At( x+2, "uml;" ) *z++ = x[1] ;
to_( x, ';' )
}
else {
*z++ = '-' ;
if ( z[-2] == '-' ) z-- ;
}
}
*z = 0 ;
LE_ret( str )
/* public: */ uint safe_uts :: ok_trace_utf ( char * fAt
// -----------------------------------------------------------------------------
// um UTF chars zu finden ...
// -----------------------------------------------------------------------------
)
LB_("safe_uts.ok_trace_utf")
uint found = 0 ;
#ifdef mitBtree
path res ; s_( res, "%s.err.txt", fAt );
FILE * f = create( res );
/* FILE * f = create( "xhtm.htm" );
fprintf( f, "<!DOCTYPE html><html lang=de><head>"
"\n<meta http-equiv='content-type' content='text/html;"
///
"\n charset=iso-8859-1'>"
"\n</head><BODY>" );
***/
rBuffer B( fAt, "" ); B.a += 2 ; // skip utf-Anfangscode
Btree schon ; L1:
while ( B.a < B.e )
{
char * c = B.z + B.a ;
char * e = B.z + B.e ;
while ( ++c < e )
{
uchar c0 = c[0] ;
uchar c1 = c[1] ;
if ( c1 > ( uchar ) 127 )
if ( c0 != ( uchar ) 246 ) //
if ( c0 != ( uchar ) 252 ) // ue
if ( c0 != ( uchar ) 220 ) // Ue
if ( c0 != ( uchar ) 223 ) //
if ( c0 != ( uchar ) 228 ) //
if ( c0 != ( uchar ) 196 ) //
if ( c0 != ( uchar ) 194 ) // '
if ( (uchar) 175 <= (uchar) c[0] )
{
if ( ! found ) fprintf( f, "\nfAt= %s", fAt );
char20 ss ;
char80 zz ; memcpy( zz, c-8, 78 ); zz[70] = 0 ;
uchar c2 = c[2] ;
char * x = substr( "<su", zz ); if ( x ) *x = ' ' ;
// su = sup oder sub (= Exponent oder Index = kleinerer Font)
s_( ss, "%u/%u/%u", c0, c1, c2 );
if ( ! schon.contains( ss ) )
{
found++ ;
char100 uu ; s_( uu,
"\n<BR>%u/%u/%u (%c%c%c): %s", c0, c1, c2, c0, c1, c2, zz );
char1000 xx ; s_( xx, "%s - trace_utf:", fAt );
traceStr( xx, zz, 80 );
traceStr( "trace_utf:", zz, 80 );
schon.StrIns( 'e', ss, uu );
}
c + 10 ;
}
}
B.a = B.e ;
B.getmore( 12000 );
}
KVStore st ; Surr s = schon.GetFirst( st );
while ( s )
{
fprintf( f, "\n%s", st.c );
s = schon.Next( st );
}
close_Appwins( 1, "xhtm.htm" );
close( f );
if ( found )
then {
rBuffer B( res, "" ); B.copy_to( stdout );
ret( found )
}
else unlink( res );
/* if ( found )
{
S_ "xhtm.htm" _Do
exit(0);
} *******/
#else
{
m_errMess "System: define mitBtree (in your main program source)" m_
ret_error
}
#endif
LE_ret( found )
/* public: */ void safe_uts :: ok_XMLUmlaute
/* -----------------------------------------------------------------------------
Was in XML als entity ...; stehen muss:
-----------------------------------------------------------------------------
*/ (
char * aus
, char * nch
)
LB_("safe_uts.ok_XMLUmlaute")
char10 zz ; str_set such ; match_rec * mr ;
zz[2] = 0 ;
zz[0] = ( uchar ) 195 ;
zz[1] = ( uchar ) 164 ; such.insert( zz, "ä" ); //
zz[1] = ( uchar ) 182 ; such.insert( zz, "ö" ); //
zz[1] = ( uchar ) 188 ; such.insert( zz, "ü" ); // ue
zz[1] = ( uchar ) 132 ; such.insert( zz, "Ä" ); //
zz[1] = ( uchar ) 150 ; such.insert( zz, "Ö" ); //
zz[1] = ( uchar ) 156 ; such.insert( zz, "Ü" ); //
zz[1] = ( uchar ) 159 ; such.insert( zz, "β" ); //
such.insert( "&", "&" );
rBuffer B( aus, "" );
FILE * f = create( nch );
while ( mr = B.find( 0, such, f ) )
{
fprintf( f, "%s", mr -> str2 );
B.a += mr -> L ;
}
close( f );
LE_
/* public: */ char * safe_uts :: utf
// -----------------------------------------------------------------------------
(
char * z
, uchar z1
, uchar z2
)
LB_("safe_uts.utf")
z[0] = z1 ;
z[1] = z2 ;
LE_ret( z+2 )
/* public: */ void safe_uts :: ok_win2utf8 ( char * htm
/* -----------------------------------------------------------------------------
... soweit das rBuffer.unicode() NICHT erledigen konnte
-----------------------------------------------------------------------------
*/ )
LB_("safe_uts.ok_win2utf8")
if not_is_file( htm ) fErr1( htm )
char10 Ae ; Ae[0] = 195 ; Ae[1] = 132 ; Ae[2] = Ae[4] = 0 ;
char10 Oe ; Oe[0] = 195 ; Oe[1] = 150 ; Oe[2] = Oe[4] = 0 ;
char10 Ue ; Ue[0] = 195 ; Ue[1] = 156 ; Ue[2] = Ue[4] = 0 ;
char10 Ak ; Ak[0] = 195 ; Ak[1] = 150 ; Ak[2] = Ae[4] = 0 ; // Akzent
char10 ae ; ae[0] = 195 ; ae[1] = 164 ; ae[2] = ae[4] = 0 ;
char10 oe ; oe[0] = 195 ; oe[1] = 182 ; oe[2] = oe[4] = 0 ;
char10 ue ; ue[0] = 195 ; ue[1] = 188 ; ue[2] = ue[4] = 0 ;
char10 ss ; ss[0] = 195 ; ss[1] = 223 ; ss[2] = ss[4] = 0 ; //
char10 cr ; ss[2] = ss[4] = 0 ;
Ae[3] = 132 ;
Oe[3] = 214 ;
Ue[3] = 220 ;
Ak[3] = 210 ;
ae[3] = 228 ;
oe[3] = 246 ;
ue[3] = 252 ;
ss[3] = 223 ;
cr[3] = 169 ; // Copyright Symbol
match_rec * mr ; str_set such ;
such.insert( Ae+3, Ae ); such.insert( ae+3, ae );
such.insert( Oe+3, Oe ); such.insert( oe+3, oe );
such.insert( Ue+3, Ue ); such.insert( ue+3, ue );
such.insert( Ak+3, Ak );
such.insert( ss+3, "ß" );
such.insert( cr+3, "©" );
rBuffer B( htm, "" );
char * tm1 = "2utf8.tmp" ; FILE * f = create( tm1 );
if ( B.find( 0, "iso-8859-1", f ) )
{
B.a += 10 ; fprintf( f, "utf-8" );
while ( mr = B.find( 0, such, f ) )
{
fprintf( f, "%s", mr -> str2 );
B.a += mr -> L ;
}
}
close( f ); cp_file( htm, tm1 ); Unlink( tm1 )
LE_
/* public: */ uint safe_uts :: ok_toUtf8
/* -----------------------------------------------------------------------------
... soweit das rBuffer.unicode() NICHT erledigen konnte
-----------------------------------------------------------------------------
*/ (
char * str
, char * utfstr // der ist zu setzen ...
)
LB_("safe_uts.ok_toUtf8")
uint anzDone = 0 ;
char * x = str-1 ;
char * z = utfstr ;
while ( *(++x) )
{
if ( ( uchar ) *x < 128 ) *z++ = *x ; else
{
uchar u = *x ;
if ( u == 132 ) z = utf( z, 195, 132 ); //
esif ( u == 196 ) z = utf( z, 195, 132 );
esif ( u == 214 ) z = utf( z, 195, 150 ); //
esif ( u == 210 ) z = utf( z, 195, 150 ); // O Akzent
esif ( u == 220 ) z = utf( z, 195, 156 ); //
esif ( u == 228 ) z = utf( z, 195, 164 ); //
esif ( u == 246 ) z = utf( z, 195, 182 ); //
esif ( u == 252 ) z = utf( z, 195, 188 ); // ue
esif ( u == 223 ) z = utf( z, 195, 159 ); //
esif ( u == 946 ) z = utf( z, 195, 159 );
}
}
*z = 0 ;
LE_ret( anzDone )
/* public: */ uint safe_uts :: ok_ersUtf_HTM
/* -----------------------------------------------------------------------------
... soweit das rBuffer.unicode() NICHT erledigen konnte
-----------------------------------------------------------------------------
*/ (
char * aus // fileAt or string
, char * nch // fileAt or string
)
LB_("safe_uts.ok_ersUtf_HTM")
char10 zz ; str_set such ; match_rec * mr ;
zz[3] = 0 ;
zz[0] = ( uchar ) 225 ;
zz[1] = ( uchar ) 190 ;
zz[2] = ( uchar ) 182 ; such.insert( zz, "─" );
zz[0] = ( uchar ) 239 ;
zz[1] = ( uchar ) 187 ;
zz[2] = ( uchar ) 191 ; such.insert( zz, "" );
zz[0] = ( uchar ) 226 ;
zz[1] = ( uchar ) 148 ;
zz[2] = ( uchar ) 128 ; such.insert( zz, "–" );
zz[0] = ( uchar ) 226 ;
zz[1] = ( uchar ) 136 ;
zz[2] = ( uchar ) 146 ; such.insert( zz, "–" );
zz[1] = ( uchar ) 134 ;
zz[2] = ( uchar ) 146 ; such.insert( zz, "→" ); // Pfeil nach rechts
zz[1] = ( uchar ) 128 ;
zz[2] = ( uchar ) 178 ; such.insert( zz, "&prime" ); // Hochkomma
zz[1] = ( uchar ) 128 ;
zz[2] = ( uchar ) 162 ; such.insert( zz, "" ); // Kuller (Bullet)
zz[2] = ( uchar ) 166 ; such.insert( zz, "..." );
zz[2] = ( uchar ) 147 ; such.insert( zz, "–" );
zz[2] = ( uchar ) 148 ; such.insert( zz, "—" );
zz[2] = ( uchar ) 156 ; such.insert( zz, """ );
zz[2] = ( uchar ) 157 ; such.insert( zz, """ );
zz[2] = ( uchar ) 158 ; such.insert( zz, """ );
zz[2] = ( uchar ) 152 ; such.insert( zz, "" ); // Hochkomma
zz[2] = ( uchar ) 153 ; such.insert( zz, "" ); // Hochkomma
zz[1] = ( uchar ) 136 ;
zz[2] = ( uchar ) 158 ; such.insert( zz, "∞" ); // unendlich-Zeichen
zz[2] = ( uchar ) 145 ; such.insert( zz, "Σ" ); // Summenzeichen
zz[2] = ( uchar ) 146 ; such.insert( zz, "−" );
zz[2] = 0 ;
zz[0] = ( uchar ) 206 ;
zz[1] = ( uchar ) 184 ; such.insert( zz, "θ" );
zz[1] = ( uchar ) 189 ; such.insert( zz, "ν" );
zz[1] = ( uchar ) 166 ; such.insert( zz, "φ" );
zz[1] = ( uchar ) 168 ; such.insert( zz, "ψ" );
zz[1] = ( uchar ) 181 ; such.insert( zz, "ε" );
zz[0] = ( uchar ) 207 ;
zz[1] = ( uchar ) 136 ; such.insert( zz, "ψ" ); // Wellenfunktion
zz[1] = ( uchar ) 134 ; such.insert( zz, "φ" ); // Wellenfunktion
zz[0] = ( uchar ) 207 ;
zz[1] = ( uchar ) 128 ; such.insert( zz, "π" );
zz[0] = ( uchar ) 206 ;
zz[1] = ( uchar ) 169 ; such.insert( zz, "Ω" );
zz[0] = ( uchar ) 195 ;
zz[1] = ( uchar ) 163 ; such.insert( zz, "ã" );
zz[1] = ( uchar ) 132 ; such.insert( zz, "Ä" );
zz[1] = ( uchar ) 150 ; such.insert( zz, "Ö" );
zz[1] = ( uchar ) 156 ; such.insert( zz, "Ü" );
zz[1] = ( uchar ) 164 ; such.insert( zz, "ä" );
zz[1] = ( uchar ) 182 ; such.insert( zz, "ö" );
zz[1] = ( uchar ) 188 ; such.insert( zz, "ü" );
// zz[1] = ( uchar ) 159 ; such.insert( zz, "β" );
zz[1] = ( uchar ) 159 ; such.insert( zz, "ß" ); //
zz[1] = ( uchar ) 152 ; such.insert( zz, "∅" ); // leere Menge
zz[0] = ( uchar ) 194 ;
zz[1] = ( uchar ) 178 ; such.insert( zz, "<sup>2</sup>" );
zz[1] = ( uchar ) 181 ; such.insert( zz, "ε" );
// siehe http://danielhuesken.de/html-schreibweise-fuer-aeueoess/ u.A.
uint anzDone = 0 ;
if not_is_file( aus )
{
char * x = aus-1 ;
char * z = nch ;
while ( *(++x) )
{
if ( ( uchar ) *x < 128 ) *z++ = *x ; else
{
if ( *x == ( uchar ) 132 ) strcpy( z, "Ä" );
esif ( *x == ( uchar ) 196 ) strcpy( z, "Ä" );
esif ( *x == ( uchar ) 150 ) strcpy( z, "Ö" );
esif ( *x == ( uchar ) 214 ) strcpy( z, "Ö" );
esif ( *x == ( uchar ) 156 ) strcpy( z, "Ü" );
esif ( *x == ( uchar ) 220 ) strcpy( z, "Ü" );
esif ( *x == ( uchar ) 164 ) strcpy( z, "ä" );
esif ( *x == ( char ) 228 ) strcpy( z, "ä" );
esif ( *x == ( uchar ) 182 ) strcpy( z, "ö" );
esif ( *x == ( uchar ) 246 ) strcpy( z, "ö" );
esif ( *x == ( uchar ) 188 ) strcpy( z, "ü" );
esif ( *x == ( uchar ) 252 ) strcpy( z, "ü" );
esif ( *x == ( uchar ) 159 ) strcpy( z, "ß" );
esif ( *x == ( uchar ) 946 ) strcpy( z, "ß" );
else fErr2( aus, ( char )*x )
z = eos( z );
}
}
*z = 0 ;
ret( anzDone )
}
rBuffer B( aus, "" ); B.unicode();
FILE * f = create( nch );
while ( mr = B.find( 0, such, f ) )
{
anzDone++ ;
fprintf( f, "%s", mr -> str2 );
//
B.a += mr -> L ;
}
close( f );
uint anzDo = trace_utf( nch ); // muss sein
if ( 0 && anzDo )
{
char * use = "\n\nask ntuse_/utf2htm for translations" ;
char * str = "Update safe_uts.ersUtf_HTM() and recompile utfTrace.exe:"
"\nersUtf_HTM() is to know" ;
{
m_errMess "System: %s %i more Utf-8 codes found in\n%s%s" m_
str, anzDo, aus, use, ret_error
}
}
printf( "\nersUtf_HTM( anzDone/Do = %i/%i ): %s\n", anzDone, anzDo, aus );
LE_ret( anzDo )
/* public: */ BOOL safe_uts :: ok_file_substr
/* -----------------------------------------------------------------------------
return TRUE, iff str is substr of text in the file
-----------------------------------------------------------------------------
*/ (
char * fAt // fileAt or string
, char * str // fileAt or string
)
LB_("safe_uts.ok_file_substr")
rBuffer B( fAt, "" );
if ( B.find( 0, str, 0 ) )
{
printf( "\n\nhas substr( %s ): %s\n", str, fAt );
ret( 1 )
}
LE_ret( 0 )
/* public: */ void safe_uts :: ok_escto
// -----------------------------------------------------------------------------
(
char * aus // non-HTML text
, char * nch // mit '<' ersetzt durch <
)
LB_("safe_uts.ok_escto")
rBuffer B( aus, "" ); FILE * f = create( nch );
while ( B.find( 0, "<", f ) )
{
fprintf( f, "<" );
B.a++ ;
}
close( f );
LE_
/* public: */ char * safe_uts :: ok_s2fstr
// -----------------------------------------------------------------------------
// Aus str soll ein Dateine fstr werden
// -----------------------------------------------------------------------------
(
char * str
, char * fstr
, uint L // strlen( fstr ) wir als kleiner L erwartet
)
LB_("safe_uts.ok_s2fstr")
char1000 zz ; s_( zz, utf2win( str ) );
ersUmlaute( zz ); if ( L <= strlen( zz ) ) fErr1( zz )
char * z = fstr ;
char * x = zz-1 ;
while ( *(++x) ) *z++ = alphanum( *x )? *x : '-' ;
*z-- = 0 ;
while ( fstr < z && *z == '-' ) *z-- ;
LE_ret( fstr )
#undef static
#endif