Patch level : 12.0 no-patch

Files correlati     :
Commento            :

Aggiunto oggetto TURL per verificare e scaricare un URL
Aggiunta funzione get_date delle token string
Aggiunta funzione fmove per spostare un file
Aggiunte funzioni
time_t atime(const char* file) // access time
time_t ctime(const char* file) // creation time
time_t mtime(const char* file) // modification time
struct tm * altime(const char* file)  // access local time
struct tm * cltime(const char* file) // creation local time
struct tm * mltime(const char* file); // creation local time
TDate aldate(const char* file) // creation date
TDate cldate(const char* file) // modification date
TDate mldate(const char* file)// access date

per le varie ddate di un file
This commit is contained in:
Alessandro Bonazzi 2020-09-24 07:19:56 +02:00
parent ae7c61c788
commit 2f86d64529
8 changed files with 175 additions and 12 deletions

View File

@ -1,4 +1,3 @@
#pragma once
#ifndef __DATE_H
#define __DATE_H

View File

@ -145,7 +145,7 @@ public:
TMask_field *get_key(TString & dbfieldname);
// @cmember Ritorna una riga dello spreadsheet
TToken_string& row(int n);
TToken_string& row(int n = -1);
// @cmember Ritorna una riga originale dello spreadsheet
TToken_string& original_row(int n);
// @cmember Ritorna un array con tutte le righe dello spreadsheet
@ -352,11 +352,21 @@ public:
virtual ~TSheet_field();
};
/* FOR_EACH_SHEET_ROW(__sheet, __r, __riga)
/* FOR_EACH_SHEET_ITEM(__sheet, __r)
* __sheet: variabile di tipo TSheet_field& dello sheet
* __r: numero riga
* __riga: variabile TToken_string* contenente la riga
*/
#define FOR_EACH_SHEET_ITEM(__sheet, __r) \
const int sheetof##__items = (__sheet).rows_array().items(); \
int __r; \
\
for (__r = 0; __r < sheetof##__items; __r++)
/* FOR_EACH_SHEET_ROW(__sheet, __r, __riga)
* __sheet: variabile di tipo TSheet_field& dello sheet
* __r: numero riga
* __riga: variabile TToken_string* contenente la riga
*/
#define FOR_EACH_SHEET_ROW(__sheet, __r, __riga) \
TString_array& sheetof##__riga = (__sheet).rows_array(); \
FOR_EACH_ARRAY_ROW(sheetof##__riga, __r, __riga)

View File

@ -1,4 +1,5 @@
#include "netutils.h"
#include <xvt.h>
TLanManager::TLanManager()
{ }
@ -279,3 +280,13 @@ bool TConnection::Request(const char* cmd)
TString_array argv;
return ParseCommand(cmd, argv) > 0;
}
bool TURL::ok(const char * url)
{
return xvt_url_valid(url && *url ? url : _url);
}
bool TURL::get(const char * outfile, const char * path)
{
return xvt_url_get(_url, path == nullptr ? "/" :path, outfile);
}

View File

@ -104,4 +104,15 @@ public:
virtual ~TConnection();
};
class TURL : public TObject
{
TString _url;
public:
bool ok(const char * url = nullptr);
void set_url(const char * url) { if (ok(url)) _url = url; }
bool get(const char * outfile, const char * path = nullptr);
TURL(const char * url = nullptr) { set_url(url); }
};
#endif

View File

@ -1681,13 +1681,21 @@ long TToken_string::get_long(int n)
}
// Certified 99%
real TToken_string::get_real(int n)
const real TToken_string::get_real(int n)
{
const char* const r = get(n);
return r ? real(r) : ZERO;
}
// Certified 99%
const TDate TToken_string::get_date(int n)
{
const char* const d = get(n);
return d ? TDate(d) : botime;
}
bool TToken_string::get_bool(int n)
{
const TString & s = get(n);

View File

@ -695,7 +695,9 @@ public:
// @cmember Ritorna un intero esteso (chiama <mf TToken_string::get>)
long get_long(int n = -1);
// @cmember Ritorna un real (chiama <mf TToken_string::get>)
real get_real(int n = -1);
const real get_real(int n = -1);
// @cmember Ritorna una data (chiama <mf TToken_string::get>)
const TDate get_date(int n);
// @cmember Ritorna un booleano (chiama <mf TToken_string::get>)
bool get_bool(int n = -1);

View File

@ -144,6 +144,34 @@ bool fcopy(
return xvt_fsys_fcopy(orig, dest) != 0 ;
}
// @func Permette di spostare un file
//
// @rdesc Ritorna il risultato dell'operazione:
//
// @flag TRUE | Se l'operazione e' stata effettuata con successo
// @flag FALSE | Se l'operazione non e' stata effettuata con successo
bool fmove(
const char* orig, // @parm Nome del file di origine
const char* dest, // @parm Nome del file di destinazione
bool append, // @parm Controllo per aggiungere il contenuto del
bool advanced) // @parm Controllo per utilizzare la xvt_fsys_fcopy
// file <p dest> in coda al file <p orig> (default FALSE)
// @comm Nel caso vengano ravvisati degli errori durante l'operazione vengono
// creati dei box di comunicazione che indicano la causa del problema
{
CHECK(orig && *orig && dest && *dest, "fcopy: Invalid file name");
// Muove il file su se stesso?
if (xvt_str_same(orig, dest))
return true; // Or FALSE?
const bool ok = fcopy(orig, dest, append, advanced);
if (ok)
remove_file(orig);
return ok;
}
// @doc EXTERNAL
// @func Controlla l'esistenza di un file
@ -153,13 +181,13 @@ bool fcopy(
// @flag TRUE | Se il file esiste
// @flag FALSE | Se il file non esiste
bool fexist(
const char* file) // @parm Nome del file di cui contrallare l'esistenza
const char* file) // @parm Nome del file di cui controllare l'esistenza
{
return file && *file && xvt_fsys_file_exists(file) != 0;
}
bool dexist(
const char* file) // @parm Nome del file di cui contrallare l'esistenza
const char* file) // @parm Nome del direttorio di cui controllare l'esistenza
{
return file && *file && xvt_fsys_dir_exists(file) != 0;
}
@ -169,6 +197,66 @@ long fsize(const char* name)
return (name && *name) ? xvt_fsys_file_attr(name, XVT_FILE_ATTR_SIZE) : 0L;
}
time_t atime(const char* file)
{
return xvt_fsys_file_attr(file, XVT_FILE_ATTR_ATIME);
}
time_t ctime(const char* file)
{
return xvt_fsys_file_attr(file, XVT_FILE_ATTR_CTIME);
}
time_t mtime(const char* file)
{
return xvt_fsys_file_attr(file, XVT_FILE_ATTR_MTIME);
}
struct tm * altime(const char* file)
{
time_t t = atime(file);
return localtime(&t);
}
struct tm * cltime(const char* file)
{
time_t t = ctime(file);
return localtime(&t);
}
struct tm * mltime(const char* file)
{
time_t t = mtime(file);
return localtime(&t);
}
TDate aldate(const char* file)
{
struct tm * t = altime(file);
TDate d(t->tm_mday, t->tm_mon + 1, t->tm_year + 1900);
return d;
}
TDate cldate(const char* file)
{
struct tm * t = cltime(file);
TDate d(t->tm_mday, t->tm_mon + 1, t->tm_year + 1900);
return d;
}
TDate mldate(const char* file)
{
struct tm * t = mltime(file);
TDate d(t->tm_mday, t->tm_mon + 1, t->tm_year + 1900);
return d;
}
// @doc EXTERNAL
// @func Permette di creare una directory
@ -735,3 +823,17 @@ TString& to_tstring(int n)
{
return to_tstring(static_cast<long>(n));
}
const TString & mod2name(word module)
{
return dongle().module_code2name(module);
}
const TString & mod2tabname(word module)
{
TString & mod = get_tmp_string(4);
mod = dongle().module_code2name(module);
mod.upper();
return mod;
}

View File

@ -1,14 +1,19 @@
#ifndef __UTILITY_H
#define __UTILITY_H
#ifndef __STRINGS_H
#include <strings.h>
#endif
#ifndef __ARRAY_H
#include <array.h>
#endif
#ifndef __DATE_H
#include <date.h>
#endif
#ifndef __STRINGS_H
#include <strings.h>
#endif
#ifndef __VARIANT_H
#include <variant.h>
#endif
@ -48,10 +53,22 @@ const char* cmd2name(const char* argv0, const char* argv1 = "");
int rtoi(const char * roman);
const char* itor(int i);
bool fcopy(const char* orig, const char* dest, bool append = false, bool advanced = false);
bool fmove(const char* orig, const char* dest, bool append = false, bool advanced = false);
bool fexist(const char* file);
long fsize(const char* file);
bool dexist(const char* file);
void log_message(const char* fmt, ...);
time_t atime(const char* file); // access time
time_t ctime(const char* file); // creation time
time_t mtime(const char* file); // modification time
struct tm * altime(const char* file); // access local time
struct tm * cltime(const char* file); // creation local time
struct tm * mltime(const char* file); // creation local time
TDate aldate(const char* file); // creation date
TDate cldate(const char* file);// modification date
TDate mldate(const char* file);// access date
inline struct tm modificationlocaltime(const char* file); void log_message(const char* fmt, ...);
bool make_dir(const char* dir);
bool remove_file(const char* file);
@ -88,6 +105,9 @@ inline const char* get_iva_sirio() // Ritorna la partita IVA della Sirio
TString& to_tstring(long n);
TString& to_tstring(int n);
const TString & mod2name(word module);
const TString & mod2tabname(word module);
inline bool is_multi_table(const int file) { return file == LF_TAB || file == LF_TABGEN || file == LF_TABCOM || file == LF_TABMOD; }
#endif /* __UTILITY_H */