From e8dcb49a760a7dd6581d0cb0190ae81ab00217bc Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 27 Dec 1994 14:59:25 +0000 Subject: [PATCH] Modificato meccanismo richiamo programmi esterni git-svn-id: svn://10.65.10.50/trunk@793 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/applicat.cpp | 28 +- include/applicat.h | 220 +-- include/checks.cpp | 14 +- include/checks.h | 117 +- include/cisam.c | 3378 +++++++++++++++++++++--------------------- include/controls.cpp | 27 +- include/execp.cpp | 36 +- include/execp.h | 68 +- include/form.cpp | 221 +-- include/form.h | 213 +-- include/isam.cpp | 17 +- include/isam.h | 990 ++++++------- include/maskfld.cpp | 65 +- include/maskfld.h | 1135 +++++++------- include/msksheet.cpp | 41 +- include/prassi.ver | 2 +- include/prefix.cpp | 48 +- include/prefix.h | 136 +- include/relapp.cpp | 9 +- include/relation.cpp | 15 +- include/sheet.cpp | 48 +- include/sheet.h | 330 +++-- include/strings.cpp | 21 + include/strings.h | 596 ++++---- include/viswin.cpp | 2 +- include/xvtility.cpp | 18 +- 26 files changed, 3991 insertions(+), 3804 deletions(-) diff --git a/include/applicat.cpp b/include/applicat.cpp index b83a4997f..3f0f1adf9 100755 --- a/include/applicat.cpp +++ b/include/applicat.cpp @@ -301,6 +301,17 @@ void TApplication::terminate() if (_create_ok) { destroy(); // Distruzione files e maschere +#if XVT_OS == XVT_OS_WIN + const word WM_WAKEUP = RegisterWindowMessage("WAKEUP"); + const HTASK ht = GetCurrentTask(); + SendMessage(HWND_BROADCAST, WM_WAKEUP, ht, 0L); + + if (fexist("prassi.hlp")) + { + HWND hwnd = (HWND)get_value(TASK_WIN, ATTR_NATIVE_WINDOW); + WinHelp(hwnd, "prassi.hlp", HELP_QUIT, 0L); + } +#endif do_events(); if (_printer != NULL) // Distruzione dell'eventuale stampante @@ -310,13 +321,6 @@ void TApplication::terminate() delete _printer; _printer = NULL; } -#if XVT_OS == XVT_OS_WIN - if (fexist("prassi.hlp")) - { - HWND hwnd = (HWND)get_value(TASK_WIN, ATTR_NATIVE_WINDOW); - WinHelp(hwnd, "prassi.hlp", HELP_QUIT, 0L); - } -#endif } if (use_files()) @@ -392,17 +396,9 @@ void TApplication::check_parameters(int & argc, char* argv[]) #ifdef DBG else _user = "PRASSI"; #endif - long twin_style = WSF_ICONIZABLE | WSF_SIZE | WSF_CLOSE; - - if (stricmp(argv[argc-1], "-icon") == 0) - { - twin_style |= WSF_ICONIZED; - argc--; - } - else - twin_style |= WSF_MAXIMIZED; #if XVT_OS == XVT_OS_WIN + const long twin_style = WSF_ICONIZABLE | WSF_SIZE | WSF_CLOSE | WSF_MAXIMIZED; set_value(NULL_WIN,ATTR_WIN_PM_TWIN_STARTUP_STYLE, twin_style); #endif } diff --git a/include/applicat.h b/include/applicat.h index c87f00d74..0f9d07cbe 100755 --- a/include/applicat.h +++ b/include/applicat.h @@ -1,107 +1,113 @@ -#ifndef __APPLICATION_H -#define __APPLICATION_H - -#ifndef INCL_XVTH -#include -#endif - -#ifndef __PRINTER_H -#include -#endif - -// @C -// Classe TApplication -// @END - -#define MSG_AI "AI" // message auto_insert (relapp) -#define MSG_FS "FS" // message filtered start (relapp) -#define MSG_LN "LN" // message (printapp -> relapp) -#define CHK_ALL -1 // all authorization checks -#define CHK_DONGLE 0 // dongle authorization checks -#define CHK_USER 1 // user authorization checks - -class TApplication -{ - // @DPRIV - int _bar; - int __argc; - const char** __argv; - TBit_array _dongle_aut; - TBit_array _user_aut; - - TString80 _name, _title; - TPrinter* _printer; - - long _savefirm; - bool _create_ok; - static TString16 _user; - -protected: - const char* get_module_name() const; - static long task_eh(WINDOW win, EVENT* ep); - - virtual long handler(WINDOW win, EVENT* ep); - virtual bool extended_firm() const { return FALSE; } // Extended set_firm dialog box - virtual bool use_files() const { return TRUE; } - - virtual bool create(); // Crea la finestra principale - virtual bool menu(MENU_TAG) { return TRUE; } // Controlla il menu - virtual bool build_firm_data(long cod, bool flagcom = FALSE) { return TRUE;} - virtual bool destroy(); // Rimuove l'applicazione - virtual void print(); - - virtual void on_config_change(); - virtual void on_firm_change(); - - void set_user(const char * user) { _user = user; } - void set_perms(); - - void terminate(); - bool config(); - void about() const; - -public: - // @FPUB - - void setbar(int menubar) { _bar = menubar;} // Modifica la menu-bar - void run(int argc, char* argv[], const char* name); - - // @DES Queste funzioni possono essere ridefinite da ogni applicazione - // @FPUB - virtual word class_id() const { return CLASS_APPLICATION; } - void stop_run(); // Forza chiusura applicazione - - void check_menu_item(MENU_TAG item); // Check menu - void uncheck_menu_item(MENU_TAG item); // Uncheck - void enable_menu_item(MENU_TAG item, bool on = TRUE); - void disable_menu_item(MENU_TAG item) { enable_menu_item(item, FALSE); } - void dispatch_e_menu(MENU_TAG item); - - const TString& name() const { return _name; } - const char** argv() const { return __argv; } - const char* argv(int i) const { return __argv[i]; } - int argc() const { return __argc; } - - void set_title(const char* t) { _title = t; } - const TString& title() const { return _title; } - - TPrinter* set_printer(TPrinter* p); - TPrinter& printer(); - - static void check_parameters(int & argc, char *argv[]); - - const TString& user() const { return _user; } - bool has_module(int module, int checktype = CHK_ALL) const; - bool set_firm(long cod = -1); - long get_firm() const; - const char* get_firm_dir() const; - - TApplication(); - virtual ~TApplication(); -}; - -bool xvt_running(); // xvt is running? -TApplication* MainApp(); // main application (old fashioned: will be removed soon -TApplication& main_app(); - -#endif // __APPLICATION_H +#ifndef __APPLICATION_H +#define __APPLICATION_H + +#ifndef INCL_XVTH +#include +#endif + +#ifndef __PRINTER_H +#include +#endif + +// @C +// Classe TApplication +// @END + +#define MSG_AI "AI" // message auto_insert (relapp) +#define MSG_FS "FS" // message filtered start (relapp) +#define MSG_LN "LN" // message (printapp -> relapp) +#define CHK_ALL -1 // all authorization checks +#define CHK_DONGLE 0 // dongle authorization checks +#define CHK_USER 1 // user authorization checks + +class TApplication +{ + // @DPRIV + int _bar; + int __argc; + const char** __argv; + TBit_array _dongle_aut; + TBit_array _user_aut; + + TString80 _name, _title; + TPrinter* _printer; + + long _savefirm; + bool _create_ok; + word _waiting; + + static TString16 _user; + +protected: + const char* get_module_name() const; + static long task_eh(WINDOW win, EVENT* ep); + + virtual long handler(WINDOW win, EVENT* ep); + virtual bool extended_firm() const { return FALSE; } // Extended set_firm dialog box + virtual bool use_files() const { return TRUE; } + + virtual bool create(); // Crea la finestra principale + virtual bool menu(MENU_TAG) { return TRUE; } // Controlla il menu + virtual bool build_firm_data(long cod, bool flagcom = FALSE) { return TRUE;} + virtual bool destroy(); // Rimuove l'applicazione + virtual void print(); + + virtual void on_config_change(); + virtual void on_firm_change(); + + void set_user(const char * user) { _user = user; } + void set_perms(); + + void terminate(); + bool config(); + void about() const; + +public: + // @FPUB + + void setbar(int menubar) { _bar = menubar;} // Modifica la menu-bar + void run(int argc, char* argv[], const char* name); + + // @DES Queste funzioni possono essere ridefinite da ogni applicazione + // @FPUB + virtual word class_id() const { return CLASS_APPLICATION; } + void stop_run(); // Forza chiusura applicazione + + void check_menu_item(MENU_TAG item); // Check menu + void uncheck_menu_item(MENU_TAG item); // Uncheck + void enable_menu_item(MENU_TAG item, bool on = TRUE); + void disable_menu_item(MENU_TAG item) { enable_menu_item(item, FALSE); } + void dispatch_e_menu(MENU_TAG item); + + const TString& name() const { return _name; } + const char** argv() const { return __argv; } + const char* argv(int i) const { return __argv[i]; } + int argc() const { return __argc; } + + void set_title(const char* t) { _title = t; } + const TString& title() const { return _title; } + + TPrinter* set_printer(TPrinter* p); + TPrinter& printer(); + + static void check_parameters(int & argc, char *argv[]); + + const TString& user() const { return _user; } + bool has_module(int module, int checktype = CHK_ALL) const; + bool set_firm(long cod = -1); + long get_firm() const; + const char* get_firm_dir() const; + + void wait_for(word taskid) { _waiting = taskid; } + void wake_up() { _waiting = 0; } + word waiting() const { return _waiting; } + + TApplication(); + virtual ~TApplication(); +}; + +bool xvt_running(); // xvt is running? +TApplication* MainApp(); // main application (old fashioned: will be removed soon +TApplication& main_app(); + +#endif // __APPLICATION_H diff --git a/include/checks.cpp b/include/checks.cpp index 81ee460db..6c105f73d 100755 --- a/include/checks.cpp +++ b/include/checks.cpp @@ -146,7 +146,6 @@ int yesnofatal_box(const char* fmt, ...) } - int yesnocancel_box(const char* fmt, ...) { buildmsg(); @@ -170,6 +169,19 @@ int yesnocancel_box(const char* fmt, ...) #endif } +int __trace(const char* fmt, ...) +{ + buildmsg(); + FILE* f = fopen("trace.log", "a"); + if (f != NULL) + { + fprintf(f, "%s\n", msg); + fclose(f); + } + + return f != NULL; +} + #endif // XVT_OS diff --git a/include/checks.h b/include/checks.h index bd8f8eb01..62b304a99 100755 --- a/include/checks.h +++ b/include/checks.h @@ -1,58 +1,59 @@ -#ifndef __CHECKS_H -#define __CHECKS_H - -#ifdef __cplusplus -extern "C" { -#endif -/* @FPUB */ -int message_box(const char* fmt, ...); -int warning_box(const char* fmt, ...); -int sorry_box(const char* fmt, ...); -int error_box(const char* fmt, ...); -int fatal_box(const char* fmt, ...); -int yesno_box(const char* fmt, ...); -int yesnocancel_box(const char* fmt, ...); -int yesnofatal_box(const char* fmt, ...); - -/* @END */ -#ifdef __cplusplus -} -#endif - - -/* @M -Utilizzate in fase di debug (definire il simbolo DBG in compilazione) -*/ -#ifdef DBG -#define CHECK(p, m) ( (p) ? (void)0 : (void) fatal_box( \ - "Check failed in %s, line %d:\n\r%s", \ - __FILE__, __LINE__, m) ) - -#define CHECKS(p, m, s0) ( (p) ? (void)0 : (void) fatal_box( \ - "Check failed in %s, line %d:\n\r%s%s", \ - __FILE__, __LINE__, m, s0) ) - -#define CHECKD(p, m, d0) ( (p) ? (void)0 : (void) fatal_box( \ - "Check failed in %s, line %d:\n\r%s%d", \ - __FILE__, __LINE__, m, d0) ) -#else - -#define CHECK(p, m) -#define CHECKS(p, m, s) -#define CHECKD(p, m, d) - -#endif -/* @END */ - - -/* @M -Utilizzata in fase di debug (definire il simbolo TRC in compilazione) -*/ -#ifdef TRC -#define TRACE(m) warning_box(m) -#else -#define TRACE(m) ((void) 0) -#endif -/* @END */ - -#endif // __CHECKS_H +#ifndef __CHECKS_H +#define __CHECKS_H + +#ifdef __cplusplus +extern "C" { +#endif +/* @FPUB */ +int message_box(const char* fmt, ...); +int warning_box(const char* fmt, ...); +int sorry_box(const char* fmt, ...); +int error_box(const char* fmt, ...); +int fatal_box(const char* fmt, ...); +int yesno_box(const char* fmt, ...); +int yesnocancel_box(const char* fmt, ...); +int yesnofatal_box(const char* fmt, ...); +int __trace(const char* fmt, ...); + +/* @END */ +#ifdef __cplusplus +} +#endif + + +/* @M +Utilizzate in fase di debug (definire il simbolo DBG in compilazione) +*/ +#ifdef DBG +#define CHECK(p, m) ( (p) ? (void)0 : (void) fatal_box( \ + "Check failed in %s, line %d:\n\r%s", \ + __FILE__, __LINE__, m) ) + +#define CHECKS(p, m, s0) ( (p) ? (void)0 : (void) fatal_box( \ + "Check failed in %s, line %d:\n\r%s%s", \ + __FILE__, __LINE__, m, s0) ) + +#define CHECKD(p, m, d0) ( (p) ? (void)0 : (void) fatal_box( \ + "Check failed in %s, line %d:\n\r%s%d", \ + __FILE__, __LINE__, m, d0) ) +#else + +#define CHECK(p, m) +#define CHECKS(p, m, s) +#define CHECKD(p, m, d) + +#endif +/* @END */ + + +/* @M +Utilizzata in fase di debug (definire il simbolo TRC in compilazione) +*/ +#ifdef TRC +#define TRACE __trace +#else +#define TRACE 1 ? 0 : __trace +#endif +/* @END */ + +#endif // __CHECKS_H diff --git a/include/cisam.c b/include/cisam.c index 3169ca373..0e7b67559 100755 --- a/include/cisam.c +++ b/include/cisam.c @@ -1,1689 +1,1689 @@ -/* -* -@(SH) Funzioni per la gestione dei file ISAM -@(C$) PRIVATE -logname : nome del file di LOG (GIORNALE) -INTTLOCK : costante che indica alla funzione di lettura che e' stata chaimata dalla funzione di scrittura e quindi deve solo controllare lo stato di lock del record -ISLOCKED : costante che indica che il record e' bloccato -@(VG$) PRIVATE -KSv, PosSv : variabili di lavoro -PagSv, IndSv : variabili di lavoro -IndActive : stato indici - TRUE = Aggiornati ad ogni modifica, FALSE = aggiorna solo i dati -isstate : Stato transazione corrente -win,wisfd : variabili di lavoro -isjournal : TRUE scrive il giornale -openf : array di TUTTI i puntatori ai descrittori dei file ISAM aperti -------------------------------------------------------------------------------- -*/ -#include "cisam.h" -#include "libdefs.h" -#include "checks.h" -#include -#define logname "log.gen" -#define INTTLOCK 0xF000 -#define ISLOCKED 225 -#define NOALLOC (char **) -1 - TKey KSv; - int PosSv; - RecNoType PagSv,IndSv; - BOOLEAN IndActive = TRUE; - int isstate = NOTRANS ; - int wln = -1; - isfdptr wisfd; - extern BOOLEAN isjournal; -/* Guy moved them here from extcdecl.h */ - Str80 cprefix; - isfdptr* openf; - void savekeystat(isdef *); - void restkeystat(isdef *,int ); - int addkeys(isdef *,RecType ,int ,int *); - int delkeys(isdef *,RecType ,int ,int *); - int replkeys(isdef *,RecType ,RecType ,int ,int *); -#ifndef DOS - void writeundo(int ,isdef *,RecType); - void writelog(int ,isdef *,RecType); - char *undoname(void); - void getopenf(int ,RecType *); -#endif -/* -@($) savekeystat ISAM -@(ID) -Salva la chiave corrente. -@(FD) -*/ - void savekeystat(isfd) - isfdptr isfd; /* descrittore del file ISAM */ - { - strcpy(KSv,isfd->i.Key); - IndSv = isfd->i.Ind; - PosSv = isfd->i.Pos; - PagSv = isfd->i.CurPag; - } -/* -@($) restkeystat ISAM -@(ID) -Ripristina la chiave corrente. -@(FD) -*/ - void restkeystat(isfd,knum) - isfdptr isfd; /* descrittore del file ISAM */ - int knum; /* numero della chiave */ - { - isfd->i.PN = knum - 1; - strcpy(isfd->i.Key,KSv); - isfd->i.Ind = IndSv; - isfd->i.Pos = PosSv; - isfd->i.CurPag = PagSv; - } -/* -@($) relisfd ISAM -@(ID) -Vuota il descrittore del file . -@(FD) -*/ - void relisfd(isfd) - isfdptr *isfd; /* descrittore del file ISAM */ - { - free((char *) (*isfd)->d); - free((char *) (*isfd)->r); - free((char *) (*isfd)); - } -/* -@($) getisfd ISAM -@(ID) -Alloca e carica il descrittore del file con numero logico "logicname". -@(FD) -*/ - void getisfd(isfd, logicname) - isdef **isfd; /* descrittore del file ISAM */ - int logicname; /* numero logico del file */ - { - (*isfd) = (isfdptr) malloc(sizeof(**isfd)); - (*isfd)->d = (FileDes *) malloc(sizeof(*((*isfd)->d))); - (*isfd)->r = (RecDes *) malloc(sizeof(*((*isfd)->r))); - COpenDir(ManuLock, NORDIR); - CGetFile(logicname, (*isfd)->d, NoLock, NORDIR); - if ((!(STREMPTY((*isfd)->d->SysName))) && ((*isfd)->d->SysName[0] == '%')) - (*isfd)->ft = COMDIR; - else - (*isfd)->ft = NORDIR; - CCloseDir(NORDIR); - COpenDir(ManuLock, (*isfd)->ft); - COpenFile(logicname, (*isfd)->d, NoLock, (*isfd)->ft); - CCloseDir((*isfd)->ft); - COpenRecDir(ManuLock, (*isfd)->ft); - CGetRec(logicname,(*isfd)->r, (*isfd)->ft); - CCloseRecDir((*isfd)->ft); - } - /*void dump(s,l) - RecType s; - int l; - { - message_box("dump : record: %s ", &s[1]); - }*/ -/* -@(#) cisupdflags ISAM -@(ID) -Aggiorna all'interno del direttorio i campi EOD e Flags. -Ritorna il codice di errore. -@(FD) -@(ISV) -wd = riga relativa al file ISAM in oggetto nel Direttorio. -fdir = identificatore del file direttorio. -- Versione DOS e XENIX -@(FSV) -@(IN) -Il campo Flags viene aggiornato comunque, mentre EOD viene aggiornato solo -se il parametro di input "updateeod" e' TRUE. -@(FN) -*/ - int cisupdflags(isfd,err,updateeod) - isdef *isfd; /* puntatore al descrittore del file ISAM */ - int *err; /* codice di errore */ - BOOLEAN updateeod; /* se TRUE si aggiorna anche EOD */ - - { - FileDes wd; - - *err = NoErr ; - if (isfd->ln <= 0) return(*err) ; - COpenDir( ManuLock, isfd->ft); - COpenFile(isfd->ln, &wd, Lock, isfd->ft); - if ((*err = fdir[isfd->ft].IOR) == NoErr) - { - wd.Flags = isfd->d->Flags; -/* #ifdef DOS - if (updateeod) wd.EOD = isfd->d->EOD; - #else */ - if ((updateeod) && (isfd->f.LockMode == ExclLock)) wd.EOD = isfd->d->EOD; -/* #endif */ - CCloseFile(isfd->ln, &wd, isfd->ft); - } - CCloseDir(isfd->ft); - return(*err); - } - -/* -@(#) cisgeteod ISAM - -@(ID) -Ritorna l' EOD del file. -@(FD) - -@(ISV) - -- Versione DOS e XENIX -@(FSV) - -*/ - - RecNoType cisgeteod(isfd,err) - isfdptr isfd; /* puntatore al descrittore del file ISAM */ - int *err; /* codice di errore */ - - { - - *err = NoErr ; - if (isfd->ln > 0) - { - COpenDir( ManuLock , isfd->ft); - COpenFile(isfd->ln, isfd->d, NoLock, isfd->ft); - CCloseDir(isfd->ft); - } - return(isfd->d->EOD) ; - } - -/* -@(#) cisopen ISAM - -@(ID) -Apre un file ISAM e alloca il buffer per un record a attiva la chiave 1 (uno). -Ritorna il codice di errore. -@(FD) - -@(ISV) -werr = variabile di lavoro che raccoglie il codice errore proveniente dalla CBCloseFile. - -s = stringa di lavoro per messaggi di errore. - -- Versione DOS e XENIX -@(FSV) - -@(IN) -@(FN) -*/ - - int cisopen (isfd,logicname,record,mode,err) - isfdptr *isfd; /* puntatore al descrittore del file */ - int logicname; /* numero logico */ - RecType *record; /* buffer per contenere un record */ - unsigned int mode; /* modo di apertura (lock) */ - int *err; /* codice di errore */ - - { - *err = NoErr; - if (openf[logicname - 1] != NULL) - fatal_box("File n. %d already open", logicname); -#ifndef DOS - if ((excllock(CInsPref(glockname, NORDIR), FALSE) == -1) && (errno == EACCES)) - fatal_box("Can't open directory : Error n. %d ", errno); -#endif - getisfd (isfd,logicname); - COpen(&((*isfd)->f), (*isfd)->d->SysName, (*isfd)->d->LenR, 0, mode); - if (*err = (*isfd)->f.IOR) - { - Str80 name; strcpy(name, (*isfd)->d->SysName); - relisfd(isfd); - fatal_box("Can't open file n. %d (%s): error %d ", - logicname, name, *err); - } - if ((*isfd)->r->NKeys) - { - Str80 name; strcpy(name, CGetIdxName((*isfd)->d->SysName)); - CBOpenFile (&((*isfd)->i), name, mode, err); - if (*err) - { - CClose(&((*isfd)->f)); - relisfd(isfd); - fatal_box("Can't open file n. %d (%s): error %d ", - logicname, name, *err); - } -#ifndef DOS - else - if (mode == ExclLock) - { - CBLockFile(&((*isfd)->i), err); - if (*err) - { - int werr; - CClose(&((*isfd)->f)); - CBCloseFile(&((*isfd)->i), &werr); - relisfd(isfd); - fatal_box("Can't open exclusively file n. %d: error %d ", logicname, *err); - } - } -#endif - } - if (record != NOALLOC) - *record = (RecType) malloc((*isfd)->d->LenR); - (*isfd)->ln = logicname; - openf[logicname - 1] = *isfd; - if ((*isfd)->r->NKeys) (*isfd)->i.PN = 0; - return (*err); - } - -/* -@(#) ciscopyrec ISAM - -@(ID) -Copia un record dati da un record ad un altro. -Ritorna il codice di errore. -@(FD) - -@(ISV) -d = riga del direttorio corrispondente al file in esame. -@(FSV) - -@(IN) -@(FN) -*/ - - int ciscopyrec(logicname,recdest, recsrc ,err) - int logicname; /* numero logico del file ISAM */ - RecType recdest; /* buffer destinazione */ - RecType recsrc; /* buffer sorgente */ - int *err; /* codice di errore */ - - { - FileDes d; - int ft; - - *err = NoErr; - if (logicname < 0) logicname = -logicname; - if (openf[logicname - 1] != NULL) d = *(openf[logicname - 1]->d); - { - COpenDir(ManuLock, NORDIR); - CGetFile(logicname, &d, NoLock, NORDIR); - if ((!(STREMPTY(d.SysName))) && (d.SysName[0] == '%')) ft = COMDIR; - else ft = NORDIR; - CCloseDir(NORDIR); - COpenDir(ManuLock, ft); - COpenFile(logicname, &d, NoLock, ft); - CCloseDir(ft); - } - memcpy(recdest, recsrc, d.LenR); - return(*err); - } - -/* -@(#) cisallocrec ISAM - -@(ID) -Alloca il buffer per un record. -Ritorna il codice di errore. -@(FD) - -@(ISV) -d = riga del direttorio corrispondente al file in esame. -@(FSV) - -@(IN) -@(FN) -*/ - - int cisallocrec(logicname,record,err) - int logicname; /* numero logico del file ISAM */ - RecType *record; /* buffer per il record */ - int *err; /* codice di errore */ - - { - FileDes d; - int ft; - - *err = NoErr; - if (logicname < 0) logicname = -logicname; - if (openf[logicname - 1] != NULL) d = *(openf[logicname - 1]->d); - else - { - COpenDir(ManuLock, NORDIR); - CGetFile(logicname, &d, NoLock, NORDIR); - if ((!(STREMPTY(d.SysName))) && (d.SysName[0] == '%')) ft = COMDIR; - else ft = NORDIR; - CCloseDir(NORDIR); - COpenDir(ManuLock, ft); - COpenFile(logicname, &d, NoLock, ft); - CCloseDir(ft); - } - *record = (RecType) malloc(d.LenR); - if (*record == ((RecType) NULL)) return(ENOMEM); - else return(*err); - } - -/* -@(#) cisclose ISAM - -@(ID) -Chiude un file ISAM e libera il buffer del record. -Ritorna il codice di errore. -@(FD) - -@(ISV) -werr = variabile di lavoro che raccoglie il codice errore proveniente dalla CBCloseFile. - -s[20] = stringa di lavoro per messaggi di errore. - -- Versione DOS e XENIX -@(FSV) - -@(IN) -Restituisce il codice di errore -@(FN) -*/ - - int cisclose(isfd,rec,err) - isdef **isfd; /* puntatore al descrittore del file */ - RecType *rec; /* buffer per il record */ - int *err; /* codice di errore */ - - { - int werr = NoErr; - - *err = NoErr; - if (((*isfd)->ln > 0) && ((*isfd == NULL) || (openf[(*isfd)->ln - 1] == NULL))) - { - if (*isfd != NULL) - error_box("File n. % isclose : Error n. %d ", (*isfd)->ln, IsNotOpen); - else - error_box("isclose : errore n. %d ", IsNotOpen); - } - CClose(&((*isfd)->f)); - *err = ((*isfd)->f.IOR); - if ((*isfd)->r->NKeys) - { - CBCloseFile(&((*isfd)->i), &werr); - if (werr != NoErr ) *err = werr; - } - if ((*isfd)->ln > 0) - openf[(*isfd)->ln - 1] = NULL ; - if ((rec != NULL) && (*rec != NULL)) - free(*rec); - relisfd(isfd); -#ifndef DOS - exclunlock(CInsPref(glockname, NORDIR), FALSE); -#endif - if (*err) - fatal_box("isclose : Error n. %d ", *err); - return (*err); - } - -/* -@(#) cisstart ISAM - -@(ID) -Esegue una lettura cambiando il numero di chiave attiva. -Ritorna il codice di errore. -@(FD) - -@(IN) - La variabile record in input contiene i campi necessari per la ricerca, - in output contiene il record letto. - - La variabile mode e' formata da un comando di lock + comando di posizionamento - . Se non si utilizza ISEQUAL o ISGREAT o ISGTEQ, il valore della variabile - record non ha nessuna importanza. -@(FN) -*/ - - int cisstart(isfd,keynum,record,mode,err) - isfdptr isfd; /* descrittore del file ISAM */ - int keynum; /* numero della chiave */ - RecType record; /* buffer per il record */ - unsigned int mode; /* comando di lettura */ - int *err; /* codice di errore */ - - { - if(isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); - *err = NoErr; - if(!(keynum >= 1) && (keynum <= isfd->r->NKeys)) - return((*err = BTrPathErr)); - isfd->i.PN = keynum - 1; - *err = cisread(isfd,record,mode,err); - return(*err); - } - -/* -@(#) cisread ISAM - -@(ID) -Esegue una lettura utilizzando la chiave attiva. -Ritorna il codice di errore. -@(FD) - -@(ISV) -rmode = variabile che contiene il tipo lettura utilizzato. - -lmode = varibaile dhe contiene il tipo lock utilizzato. - -knum = numero chiave attiva. - -junk = variabile spazzatura per la chiamata alla funzione "sleep". - -times = variabile di lavoro. - -s = stringa contenente messaggio. - -w = descrittore finestra . - -internaltlock = flag che verifica se la isread e' stata chiamata da iswrite per testare l' esistenza di un record. - -@(FSV) - -@(IN) - La variabile record in input contiene i campi necessari per la ricerca, - in output contiene il record letto. - - La variabile mode e' formata da un comando di lock + comando di posizionamento - . Se non si utilizza ISEQUAL o ISGREAT o ISGTEQ, il valore della variabile - record non ha nessuna importanza. -@(FN) -*/ - - int cisread(isfd,record,mode,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record;/* buffer per il record */ - unsigned int mode; /* modo di lettura */ - int *err; /* codice di errore */ - - { - unsigned int rmode = (mode & READTYPES), - lmode = (mode & RecLockTypes), - knum = (isfd->i.PN+1); - int junk,times = 1; - TKey key,key1,key2; -/* char s[120]; */ - BOOLEAN internaltlock = (lmode == INTTLOCK); - - if (internaltlock) lmode = ShareLock; - *err = NoErr ; - if (isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); - if (rmode & (IsPrevN + IsNextN)) - { - times = rmode & BYTEMASK; - if (rmode & IsPrevN) rmode = IsPrev; - else rmode = IsNext; - } - if (rmode == IsCurr) - { - if (!isfd->RecNo) return((*err = IsNotCurr)); - } - else - { - if (rmode == IsNext) - { - while ((times--) && (!*err)) - { - CBNext(&isfd->i,knum,key1,&isfd->RecNo,err); - } - } - else - { - if (rmode == IsPrev) - { - while ((times--) && (!*err)) - { - CBPrev(&isfd->i,knum,key1,&isfd->RecNo,err); - } - } - else - { - if (rmode == IsFirst) MinKey(CCalcLenKey(isfd->r,knum),key); - else - if (rmode == IsLast) MaxKey(CCalcLenKey(isfd->r,knum),key); - else - CBuildKey(isfd->r,knum,record,key); - CBRead(&isfd->i,knum,key,key1,&isfd->RecNo,err); - if ((rmode == IsGreat) && (!*err)) - while ((strcmp(key,key1) == 0) && (!*err)) - CBNext (&isfd->i,knum,key1,&isfd->RecNo,err); - } - } - } - do - { - if (((*err) && (rmode == IsEqual)) || - ((*err == BTrEOF) && (rmode == IsGreat))) - CRead(&isfd->f,record,isfd->RecNo,NoLock); - else - CRead(&isfd->f,record,isfd->RecNo,lmode); - if (TESTLOCK(isfd->f.IOR)) - { - if (lmode == ShareLock) - { - if (!*err) *err = ISLOCKED; - break; - } - message_box("Codice %s in uso da parte\ndi un altro utente.", key1); - if (rmode != IsCurr) - { - CBReRead(&isfd->i,knum,key1,key2,isfd->RecNo,&isfd->RecNo,&junk); - if (junk) strcpy(key1, key2) ; - } - } - else - if (!*err) *err = isfd->f.IOR; - } while (TESTLOCK(isfd->f.IOR)) ; - if (((rmode == IsFirst) || (rmode == IsLast)) && (*err != BTrEmptyTree)) - *err = NoErr; - if ((rmode == IsGtEq) && (*err != BTrEOF) && (*err != BTrEmptyTree)) - *err = NoErr ; - if (DEADLOCK(*err)) return(*err = IsDeadLock); - if (rmode == IsCurr) - { - CBuildKey(isfd->r,knum,record,key); - CBReRead(&isfd->i,knum,key,key1,isfd->RecNo,&isfd->RecNo,&junk); - } - if (*err == BTrEmptyTree) CZeroRec(isfd->r, record); - return(*err); - } - -/* -@($) addkeys ISAM - -@(ID) -Aggiunge all'indice le chiavi contenute nel record. -Ritorna il codice di errore. -@(FD) - -@(ISV) -i,j = contatori. - -werr = codice errore restituito dalla CBDelete. - -key = valore delle chiavi. -@(FSV) - -@(IN) -@(FN) -*/ - - int addkeys (isfd,record,knum,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer per il record */ - int knum; /* numero chiave corrente */ - int *err; /* codice errore */ - - { - int i,j,werr; - TKey key; - - for (i = 1;(i <= isfd->r->NKeys) && (!*err);i++) - { - CBuildKey(isfd->r,i,record,key); - CBWrite(&isfd->i,i,key,isfd->RecNo,err); - if (i == knum) savekeystat(isfd); - } - if (*err) - { - if (i == 2 && *err == BTrDupKeysNotAll) *err = IsReInsert; - for (j = 1; (j < i); j++) - { - CBuildKey(isfd->r,j,record,key); - CBDelete(&isfd->i,j,key,isfd->RecNo,&werr); - } - } - else restkeystat(isfd,knum); - return(*err); - } - -/* -@(#) ciswrite ISAM - -@(ID) -Aggiunge un nuovo record al file ISAM. -Ritorna il codice di errore. -@(FD) - -@(ISV) -werr = codice errore restituito. - -knum = numero chiave attiva. - -junk = variabile di lavoro per la chiamata di varie funzioni. - -wrec = buffer di lavoro. -@(FSV) - -@(IN) - La variabile record in input contiene il record da aggiungere. -@(FN) -*/ - - int ciswrite (isfd,record,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer per il record */ - int *err; /* codice di errore */ - - { - int knum = (isfd->i.PN+1), werr, junk; - RecType wrec; - RecNoType neweox; - - *err = NoErr; - if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); - if (isfd->ln > 0) - { - COpenDir (ManuLock, isfd->ft); - COpenFile(isfd->ln,isfd->d, Lock, isfd->ft); - } - if (isfd->d->EOD == isfd->d->EOX) - { - neweox = isfd->d->EOX / 20 + 1; - if (neweox < 10) neweox = 10; - if (demoflag) - *err = IsFileFull; - else - { - neweox += isfd->d->EOX; - cisextend(isfd, isfd->ln, neweox, err); - } - if (*err == NoErr) - { - if (isfd->ln > 0) - { - COpenFile(isfd->ln,isfd->d, NoLock, isfd->ft); - for (junk = 0; junk < isfd->r->NKeys; junk++) - isfd->i.Base[junk].PEOX = neweox; - } - else - { - isfd->d->EOX = neweox; - if (isfd->f.LockMode == ExclLock) - for (junk = 0; junk < isfd->r->NKeys; junk++) - isfd->i.Base[junk].PEOX = neweox; - } - } - else - { - if (isfd->ln > 0) - { - COpenFile(isfd->ln,isfd->d, UnLock, isfd->ft); - CCloseDir(isfd->ft); - } - isfd->RecNo = 0; - if (DEADLOCK(*err)) *err = IsDeadLock; - return((*err ? *err : (*err = IsFileFull))); - } - } - IRecallRec(record); - if (test_share() && isfd->f.LockMode != ExclLock) - { - wrec = malloc(isfd->d->LenR); - memcpy(wrec, record, isfd->d->LenR); - savekeystat(isfd); - junk = cisstart(isfd, 1, wrec, INTTLOCK+IsEqual, &junk); - restkeystat(isfd, knum); - if ((junk == NoErr) || (junk == ISLOCKED)) - { - *err = IsReInsert; - if (isfd->ln > 0) - { - COpenFile(isfd->ln,isfd->d, UnLock, isfd->ft); - CCloseDir(isfd->ft); - } - isfd->RecNo = 0; - return(*err); - } - free(wrec); - } - isfd->RecNo = (++isfd->d->EOD); - if ((isfd->r->NKeys) && IndActive) - { - if(test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i,err) ; - if (!addkeys(isfd, record, knum, err)) - { - CWrite(&isfd->f,record,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) - { - isfd->RecNo = 0; - junk = delkeys(isfd, record, knum, &werr); - } - else - if (isfd->ln > 0) - CCloseFile(isfd->ln,isfd->d, isfd->ft) ; - } - else isfd->d->EOD-- ; - if(test_share() && isfd->f.LockMode != ExclLock) - CBUnLockFile(&isfd->i, &werr) ; - } - else - { - CWrite(&isfd->f,record,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) isfd->RecNo = 0; - else CCloseFile(isfd->ln,isfd->d, isfd->ft) ; - } - if (!(*err)) - { -#ifndef DOS - if (isstate == NOTRANS) writelog(FNWRITE, isfd, record); - else writeundo(FNWRITE, isfd, record); -#endif - } - if (isfd->ln > 0) - CCloseDir(isfd->ft); - if (test_share()) - { - junk = cisunlock(isfd, &junk); - if (isstate == NOTRANS) - CLockRec(&isfd->f,isfd->RecNo,UnLock); - if (DEADLOCK(*err)) *err = IsDeadLock; - } - return(*err); - } - -/* -@($) delkeys ISAM - -@(ID) -Cancella le chiavi contenute nel record dall'indice. -Ritorna il codice di errore. -@(FD) - -@(ISV) -i,j = contatori. - -werr = codice errore da CBWrite. - -key = valori chiave. -@(FSV) - -@(IN) -@(FN) -*/ - - int delkeys (isfd,record,knum,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer per il record */ - int knum; /* numero della chiave attuale */ - int *err; /* codice di errore */ - - { - int i,j,werr; - TKey key; - - for (i = 1;(i <= isfd->r->NKeys)&&(!*err);i++) - { - CBuildKey(isfd->r,i,record,key); - CBDelete(&isfd->i,i,key,isfd->RecNo,err); - } - if (*err) - { - for (j = 1;(j < i);j++) - { - CBuildKey(isfd->r,j,record,key); - CBWrite(&isfd->i,j,key,isfd->RecNo,&werr); - } - } - else restkeystat(isfd,knum); - return(*err); - } - -/* -@(#) cisdelete ISAM - -@(ID) -Cancella un record da un file ISAM. -Ritorna il codice di errore. -@(FD) - -@(ISV) -knum = numero chiave successiva a quella attiva. - -werr = codice errore da CBUnLockFile. - -key1,key = valori chiave. - -- Versione DOS e XENIX -@(FSV) - -@(IN) - La variabile record in input contiene il record da cancellare. -@(FN) -*/ - - int cisdelete(isfd,record,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer per il record */ - int *err; /* codice di errore */ - - { - int knum = (isfd->i.PN+1), werr; - TKey key,key1; - - if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); - *err = NoErr; - savekeystat(isfd); - CBuildKey(isfd->r,1,record,key); - *err = NoErr ; - CBRead(&isfd->i,1,key,key1,&isfd->RecNo,err); - if (*err) - { - restkeystat(isfd,knum); - return(*err); - } - CRead(&isfd->f, record, isfd->RecNo, NoLock); - if ((*err = isfd->f.IOR)) - { - restkeystat(isfd,knum); - return(*err); - } - if ((isfd->r->NKeys) && IndActive) - { - if(test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i,err) ; - delkeys(isfd, record, knum, err) ; - } - IDeleteRec(record); - CWrite(&isfd->f,record,isfd->RecNo,UnLock); - if((*err = isfd->f.IOR)) - { - IRecallRec(record); - CWrite(&isfd->f,record,isfd->RecNo,NoLock); - if ((isfd->r->NKeys) && IndActive) addkeys(isfd, record, knum, err) ; - restkeystat(isfd,knum); - } -#ifndef DOS - else - { - if (isstate == NOTRANS) - { - writelog(FNDELETE, isfd, NULL); - CRead(&isfd->f,record,isfd->RecNo,UnLock); - } - else writeundo(FNDELETE, isfd, NULL); - } - if (test_share() && (isfd->r->NKeys) && IndActive && - (isfd->f.LockMode != ExclLock)) - CBUnLockFile(&isfd->i, &werr) ; -#else - if (test_share()) - { - CRead(&isfd->f,record,isfd->RecNo,UnLock); - if (isfd->r->NKeys && IndActive && - (isfd->f.LockMode != ExclLock)) - CBUnLockFile(&isfd->i, &werr) ; - } -#endif - return(*err); - } - -/* -@($) replkeys ISAM - -@(ID) -Rimpiazza le chiavi all'interno dell'indice. -Ritorna il codice di errore. -@(FD) - -@(ISV) -i,j = contatori. - -werr = codice errore ritornato da CBDelete e CBWrite. - -key,key1 = valori delle chiavi. -@(FSV) -*/ - - int replkeys (isfd,oldrec,record,knum,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType oldrec; /* buffer contenente il vecchio record */ - RecType record; /* buffer contenente il nuovo record */ - int knum; /* numero della chiave attuale */ - int *err; /* codice di errore */ - - { - int i,j,werr; - TKey key,key1; - - for (i = 1;(i <= isfd->r->NKeys)&&(!*err);i++) - { - CBuildKey(isfd->r,i,record,key); - CBuildKey(isfd->r,i,oldrec,key1); - if (strcmp(key,key1) != 0) - { - CBDelete(&isfd->i,i,key1,isfd->RecNo,err); - if (*err) break; - CBWrite(&isfd->i,i,key,isfd->RecNo,err); - if (*err) CBWrite(&isfd->i,i,key1,isfd->RecNo,err); - if (i == knum) savekeystat(isfd); - } - } - if (*err) - { - for (j = 1;(j < i);j++) - { - CBuildKey(isfd->r,j,record,key); - CBuildKey(isfd->r,j,oldrec,key1); - if (strcmp(key,key1) != 0) - { - CBDelete (&isfd->i,j,key,isfd->RecNo,&werr); - CBWrite(&isfd->i,j,key1,isfd->RecNo,&werr); - } - } - } - else restkeystat(isfd,knum); - return(*err); - } - -/* -@(#) cisrewrite ISAM - -@(ID) -Aggiorna un record nel file ISAM. -Ritorna il codice di errore. -@(FD) - -@(ISV) -knum = numero chiave successiva all'attuale. - -werr = codice errore restituito da CBUnLock. - -key, key1 = valori delle chiavi. - -oldrec = buffer di lavoro. - -- Versione DOS e XENIX -@(FSV) - -@(IN) - La variabile record in input contiene il record da aggiornare. -Utilizza la chiave 1 per ritrovare il record da aggiornare. -@(FN) -*/ - - int cisrewrite(isfd,record,err) - isfdptr isfd; /* descrittore del file isam */ - RecType record; /* buffer contenente i record */ - int *err; /* codice di errore */ - - { - int knum = (isfd->i.PN+1), werr; - TKey key,key1; - RecType oldrec; - - *err = NoErr ; - if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); - oldrec = (RecType) malloc(isfd->d->LenR); - savekeystat(isfd); - IRecallRec(record); - CBuildKey(isfd->r,1,record,key); - CBRead(&isfd->i,1,key,key1,&isfd->RecNo,err); - if(*err) - { - restkeystat(isfd,knum); - return(*err); - } - CRead(&isfd->f,oldrec,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) - { - restkeystat(isfd,knum); - free(oldrec); - return(*err); - } - if (memcmp(oldrec,record,isfd->d->LenR) == 0) - { - *err = NoErr; - restkeystat(isfd,knum); - CLockRec(&isfd->f,isfd->RecNo,UnLock); - free(oldrec); - return(*err); - } - if ((isfd->r->NKeys) && IndActive) - { - if(test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i, err) ; - replkeys(isfd, oldrec, record, knum, err) ; - if(test_share() && isfd->f.LockMode != ExclLock) - CBUnLockFile(&isfd->i, &werr) ; - } - CWrite(&isfd->f,record,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) - { - CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); - replkeys(isfd, record, oldrec, knum, err) ; - restkeystat(isfd,knum); - } - else -#ifndef DOS - { - if (isstate == NOTRANS) - { - writelog(FNREWRITE, isfd, record); - CLockRec(&isfd->f,isfd->RecNo,UnLock); - } - else writeundo(FNREWRITE, isfd, oldrec); - } - -#else - if (test_share()) - CLockRec(&isfd->f,isfd->RecNo,UnLock); -#endif - free(oldrec); - return(*err); - } - -/* -@(#) cisdelcurr ISAM - -@(ID) -Cancella il record corrente. -Ritorna il codice di errore. -@(FD) -*/ - - int cisdelcurr(isfd,err) - isfdptr isfd; /* descrittore del file ISAM */ - int *err; /* codice di errore */ - - { - if(isfd->RecNo) cisdelrec(isfd,isfd->RecNo,err); - else *err = IsNotCurr; - return(*err); - } - -/* -@(#) cisrewcurr ISAM - -@(ID) -Riscrive il record corrente. -Ritorna il codice di errore. -@(FD) - -@(IN) - La variabile record in input contiene il record da aggiornare. -@(FN) -*/ - - int cisrewcurr(isfd,record,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer contenente il record */ - int *err; /* codice di errore */ - - { - if(isfd->RecNo) cisrewrec(isfd,isfd->RecNo,record,err); - else *err = IsNotCurr; - return (*err); - } - -/* -@(#) cisreadrec ISAM - -@(ID) -Legge un record di numero "recnum". -Ritorna il codice di errore. -@(FD) -*/ - - int cisreadrec(isfd,recnum,record,mode,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecNoType recnum; /* numero del record */ - RecType record; /* buffer per il record */ - unsigned int mode; /* modo di lock */ - int *err; /* codice di errore */ - - { - isfd->RecNo = recnum; - return(cisread(isfd,record,IsCurr+(mode & RecLockTypes),err)); - } - -/* -@(#) ciswriterec ISAM - -@(ID) -Riscrive un record di numero "recnum". -@(FD) - -@(IN) - La variabile record in input contiene il record da aggiornare. -@(FN) - -@(ISV) -knum = numero chiave attiva. - -werr = codice errore restituito da CBUnLockFile. - -oldrec = buffer di lavoro. - -- Versione DOS e XENIX -@(FSV) -*/ - - int cisrewrec(isfd,recnum,record,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecNoType recnum; /* numero del record da riscrivere */ - RecType record; /* buffer per il record */ - int *err; /* codice di errore */ - - { - int knum = (isfd->i.PN+1), werr; - RecType oldrec; - - *err = NoErr; - if (isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); - oldrec = (RecType) malloc(isfd->d->LenR); - isfd->RecNo = recnum; - IRecallRec(record); - CRead(&isfd->f,oldrec,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) - { - free(oldrec); - return(*err); - } - if (memcmp(oldrec,record,isfd->d->LenR) == 0) - { - *err = NoErr; - if (test_share()) - CLockRec(&isfd->f,isfd->RecNo,UnLock); - free(oldrec); - return(*err); - } - if ((isfd->r->NKeys) && IndActive) - { - if (test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i, err) ; - replkeys(isfd, oldrec, record, knum, err) ; - if (test_share() && isfd->f.LockMode != ExclLock) - CBUnLockFile(&isfd->i, &werr) ; - } - if (isstate == NOTRANS) CWrite(&isfd->f,record,isfd->RecNo,UnLock); - else CWrite(&isfd->f,record,isfd->RecNo,NoLock); - if ((*err = isfd->f.IOR)) - { - CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); - replkeys(isfd, record, oldrec, knum, err) ; - } -#ifndef DOS - else - { - if (isstate == NOTRANS) - { - writelog(FNREWRITE, isfd, record); - CLockRec(&isfd->f,isfd->RecNo,UnLock); - } - else writeundo(FNREWRITE, isfd, oldrec); - } -#else - if (test_share()) - CLockRec(&isfd->f,isfd->RecNo,UnLock); -#endif - free(oldrec); - return(*err); - } -/* -@(#) cisdelrec ISAM -@(ID) -Cancella un record utilizzando un numero di record. -Ritorna il codice di errore. -@(FD) -@(IN) - La variabile record in input contiene il record da cancellare. -@(FN) -@(ISV) -knum = numero della chiave attiva. -werr = codice di errore restituito da CBUnLockFiles. -oldrec = buffer di lavoro. -key1 = valore della chiave. -- Versione DOS e XENIX -@(FSV) -*/ - int cisdelrec(isfd,recnum,err) - isfdptr isfd; /* descrittore del file ISAM */ - RecNoType recnum; /* numero di record */ - int *err; /* codice di errore */ - { - int knum = (isfd->i.PN+1), werr; - int junk; - RecType oldrec ; - TKey key1 ; - *err = NoErr; - if(isfd == (isfdptr) NULL) return ((*err = IsNotOpen)); - oldrec = (RecType) malloc(isfd->d->LenR); - isfd->RecNo = recnum; - savekeystat(isfd); - CRead(&isfd->f, oldrec, isfd->RecNo, NoLock); - if ((*err = isfd->f.IOR)) - { - free(oldrec); - return(*err); - } - if ((isfd->r->NKeys) && IndActive) - { - if(test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i, err) ; - delkeys(isfd, oldrec, knum, err); - } - IDeleteRec(oldrec); - CWrite(&isfd->f,oldrec,isfd->RecNo,UnLock); - if ((*err = isfd->f.IOR)) - { - IRecallRec(oldrec); - CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); - if ((isfd->r->NKeys) && IndActive) addkeys(isfd, oldrec, knum, err); - } -#ifndef DOS - else - { - if (isstate == NOTRANS) - { - writelog(FNDELETE, isfd, NULL); - CLockRec(&isfd->f,isfd->RecNo,UnLock); - } - else writeundo(FNDELETE, isfd, NULL); - } - if (test_share() && (isfd->r->NKeys) && IndActive && (isfd->f.LockMode != ExclLock)) - CBUnLockFile(&isfd->i, &werr) ; -#else - if (test_share()) - { - CLockRec(&isfd->f,isfd->RecNo,UnLock); - if (isfd->r->NKeys && IndActive && - (isfd->f.LockMode != ExclLock)) - CBUnLockFile(&isfd->i, &werr) ; - } -#endif - free(oldrec); - isfd->RecNo = 0; - return(*err); - } -/* -@(#) cisgetrecno ISAM -@(ID) -Restituisce il numero del record corrente. -@(FD) -*/ - RecNoType cisgetrecno(isfd, err) - isfdptr isfd; /* descrittore del file ISAM */ - int *err; /* codice di errore */ - - { - if (!isfd->RecNo) *err = IsNotCurr; - else *err = NoErr; - return(isfd->RecNo); - } -/* -@(#) cislock ISAM -@(ID) -Blocca il file ISAM. -@(FD) -@(ISV) -junk = variabile spazzatura per la chiamata di sleep. -@(FSV) -*/ - int cislock(isfd,err) - isfdptr isfd; /* descrittore del file ISAM */ - int *err; /* codice di errore */ - { - int junk; - *err = NoErr ; - if (lseek(isfd->f.F, 0L, 0) == -1) return ((*err = CIOResult())); -#ifndef DOS - do - { - if (lockf(isfd->f.F,F_TLOCK,0L) == -1) - { - *err = CIOResult() ; - junk = sleep(1) ; - } - } while (TESTLOCK(*err)) ; -#endif - if(test_share() && isfd->f.LockMode != ExclLock) - CBLockFile(&isfd->i,err); - return(*err); - } -/* -@(#) cisunlock ISAM -@(ID) -Sblocca un file ISAM. -@(FD) -*/ - int cisunlock(isfd,err) - isfdptr isfd; /* descrittore del file */ - int *err; /* codice di errore */ - { - return(cisrelease(isfd,err)); - } -/* -@(#) cisrelease ISAM -@(ID) -Sblocca un file ISAM. -@(FD) -*/ - int cisrelease(isfd,err) - isfdptr isfd; /* descrittore del file ISAM */ - int *err; /* codice di errore */ - { - *err = NoErr ; -#ifndef DOS - if (lseek(isfd->f.F, 0L, 0) == -1) return ((*err = CIOResult())); - do - { - if (lockf(isfd->f.F,F_ULOCK,0L) == -1) *err = CIOResult() ; - } while (TESTLOCK(*err)) ; -#endif - if(test_share() && isfd->f.LockMode != ExclLock) - CBUnLockFile(&isfd->i,err); - return(*err); - } -/* -@(#) IndexOn ISAM -@(ID) -Attiva Aggiornamento Indici. -@(FD) -@(IN) -Di default gli indici sono attivi. -@(FN) -*/ - void IndexOn() - { - IndActive = TRUE ; - } -/* -@(#) IndexOff ISAM -@(ID) -Disattiva l'aggiornamento Indici. -@(FD) -*/ - void IndexOff() - { - IndActive = FALSE ; - } -#ifndef DOS -/* -@($) undoname ISAM -@(ID) -Restituisce il nome del file di Undo. -@(FD) -@(ISV) -path = stringa contenente il nome file. -@(FSV) -*/ - char *undoname() - { - static PathSt path; - TMPFNAME(path, "undo"); - return(path); - } -/* -@($) writeundo ISAM -@(ID) -Scrive una operazione effettuata nel file di Undo. -@(FD) -@(ISV) -fd = puntatore al file. -uname = nome del file di undo. -lgh = variabile di lavoro che contiene l' header del record di undo. -@(FSV) -*/ - void writeundo(fntype,isfd,record) - int fntype; /* operazione da effettuare */ - isfdptr isfd; /* descrittore del file */ - RecType record; /* buffer contenente il record */ - { - int fd; - PathSt uname; - loghead lgh; - - if (isfd->ln <= 0) return ; - strcpy(uname ,undoname()); - if ((fd = open(uname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) - fatal_box("Writeundo : Error n. %d ", errno); - lgh.type = fntype; - lgh.time = time(NULL); - lgh.procid = getpid(); - lgh.userid = getuid(); - lgh.filenum = isfd->ln; - lgh.recnum = isfd->RecNo; - lgh.lenrec = isfd->d->LenR; - if (write(fd, &lgh, sizeof(lgh)) == -1) - fatal_box("Writeundo : Error n. %d ", errno); - if (fntype & (FNREWRITE)) - if (write(fd, record, lgh.lenrec) == -1) - fatal_box("Writeundo : Error n. %d ", errno); - if (close(fd) == -1) - fatal_box("Writeundo : Error n. %d ", errno); - } -/* -@($) writelog ISAM -@(ID) -Scrive sul file Giornale l'operazione effettuata. -@(FD) -@(ISV) -junk = variabile spazzatura per la chiamata di execunlock. -lname = nome del file Giornale (LOG). -fd = puntatore al file giornale. -lgh = testata del file giornale. -@(FSV) -*/ - void writelog(fntype,isfd,record) - int fntype; /* operazione effetuata */ - isfdptr isfd; /* descrittore del file ISAM */ - RecType record; /* buffer per il record */ - { - int fd,junk; - PathSt lname; - loghead lgh; - if (!isjournal) return; - if (isfd->ln <= 0) return ; - strcpy(lname, CInsPref(logname, NORDIR)); - while (excllock(lname,TRUE) == -1) sleep(1); - if ((fd = open(lname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Writelog : Error n. %d ", errno); - } - lgh.type = fntype + FNSTTRANS; - lgh.time = time(NULL); - lgh.procid = getpid(); - lgh.userid = getuid(); - if (fntype & (FNREWRITE + FNWRITE + FNDELETE)) - { - lgh.filenum = isfd->ln; - lgh.recnum = isfd->RecNo; - lgh.lenrec = isfd->d->LenR; - } - else - { - lgh.filenum = 0; - if (fntype == FNREORG) lgh.recnum = *((RecNoType *) record); - else lgh.recnum = 0L; - if (fntype == FNCHGREC) lgh.lenrec = sizeof(RecDes); - else lgh.lenrec = 0; - } - if (write(fd, &lgh, sizeof(lgh)) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Writelog : Error n. %d ", errno); - } - if (fntype & (FNREWRITE + FNWRITE + FNCHGREC)) - if (write(fd, record, lgh.lenrec) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Writelog : Error n. %d ", errno); - } - if (close(fd) == -1) - fatal_box("Writelog : Error n. %d ", errno); - junk = exclunlock(lname,TRUE); - } -#endif -/* -@(#) StTrans ISAM -@(ID) -Inizia una transazione. -@(FD) -*/ - void StTrans() - { -#ifndef DOS - if (isstate == TRANS) EndTrans(); -#endif - isstate = TRANS; - } -#ifndef DOS -/* -@($) getopenf ISAM -@(ID) -Riconfigura il file di lavoro attivo sul file di numero logico "ln". -@(FD) -@(ISV) -junk = variabile spazzatura per la chiamata alla cisclose. -err = codice di errore ritornato dalla cisopen. -@(FSV) -*/ - void getopenf(ln,record) - int ln; /* numero logico del file */ - RecType *record; /* puntatore al buffer per il record */ - { - int err,junk; - if (openf[ln - 1] == NULL) - { - if (wln != ln) - { - if (wln != -1) junk = cisclose(&wisfd ,record ,&err); - cisopen(&wisfd, ln, record, ManuLock, &err); - wln = ln; - } - } - else *record = realloc(*record, openf[ln - 1]->d->LenR); - } -#endif -/* -@(#) EndTrans ISAM -@(ID) -Chiude una transazione. -@(FD) -@(ISV) -fdl, fdu = puntatori ai file di LOG e di Undo. -lname, uname = nomi dei file di LOG e di Undo. -lgh, lgh1 = variabili di lavoro contenenti le testate dei file di log. -nread = variabile di lavoro per la chiamata alla read. -werr = codice di errore ritornato dalla cisclose. -junk = variabile spazzatura per la chiamata di exclunlock. -start = variabile di lavoro. -record = buffer di lavoro. -@(FSV) -*/ - void EndTrans() - { -#ifndef DOS - int fdl, fdu; - PathSt lname, uname; - loghead lgh, lgh1; - int nread, werr, junk, start = FNSTTRANS; - RecType record; - strcpy(lname ,CInsPref(logname, NORDIR)); - while (excllock(lname,TRUE) == -1) sleep(1); - if (((fdl = open(lname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) || - ((fdu = open(uname, O_RDONLY, 0666)) == -1)) - { - junk = exclunlock(lname,TRUE); - fatal_box("Endtrans : Error n. %d ", errno); - } - while ((nread = read(fdu, &lgh, sizeof(lgh))) > 0) - { - lgh.type += start; - start = 0; - if (write(fdl, &lgh, sizeof(lgh)) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Endtrans : Error n. %d ", errno); - } - if (lgh.type == FNREWRITE) - if (lseek(fdu, (long) lgh.lenrec, 1) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Endtrans : Error n. %d ", errno); - } - getopenf(lgh.filenum, &record); - CRead(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); - if (write(fdl, record, lgh.lenrec) == -1) - { - junk = exclunlock(lname,TRUE); - fatal_box("Endtrans : Error n. %d ", errno); - } - } - if ((nread <= 0) || (close(fdu) == -1) || (close(fdl) == -1) || - (unlink(uname) == -1)) - { - junk = exclunlock(lname,TRUE); - fatal_box("Endtrans : Error n. %d ", errno); - } - if (wln != -1) - { - junk = cisclose(&wisfd, &record, &werr); - wln = -1; - } - junk = exclunlock(lname,TRUE); -#endif - } -/* -@(#) AbTrans ISAM -@(ID) -Abortisce una transazione. -@(FD) -*/ - void AbTrans() - { -#ifndef DOS - int fd; - PathSt uname; - loghead lgh; - int nread, werr, junk; - RecType record; - RecType oldrec; - strcpy(uname ,undoname()); - if ((fd = open(uname, O_RDONLY, 0666)) == -1) - fatal_box("Abtrans : Error n. %d ", errno); - while ((nread = read(fd, &lgh, sizeof(lgh))) > 0) - { - getopenf(lgh.filenum, &record); - if (oldrec == NULL) oldrec = malloc(lgh.lenrec); - else oldrec = realloc(oldrec, lgh.lenrec); - if (lgh.type & (FNREWRITE)) - { - if ((nread = read(fd, record, lgh.lenrec)) <= 0) - fatal_box("Abtrans : Error n. %d ", errno); - } - if (lgh.lenrec != openf[lgh.filenum - 1]->d->LenR) - fatal_box("Abtrans : Error n. %d ", IsNoMatch); - CRead(&(openf[lgh.filenum - 1]->f), oldrec, lgh.recnum, NoLock); - switch (lgh.type) - { - case FNREWRITE : - junk = replkeys(openf[lgh.filenum - 1], oldrec, record, - openf[lgh.filenum - 1]->i.PN + 1, &werr); - CWrite(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); - break; - case FNDELETE : - IRecallRec(oldrec); - junk = addkeys(openf[lgh.filenum - 1], oldrec, - openf[lgh.filenum - 1]->i.PN + 1, &werr); - CWrite(&(openf[lgh.filenum - 1]->f), oldrec, lgh.recnum, UnLock); - break; - case FNWRITE : - IDeleteRec(oldrec); - junk = delkeys(openf[lgh.filenum - 1], oldrec, - openf[lgh.filenum - 1]->i.PN + 1, &werr); - CWrite(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); - break; - } - } - if ((nread == -1) || (close(fd) == -1) || (unlink(uname) == -1)) - fatal_box("Abtrans : Error n. %d ", errno); - if (wln != -1) - { - junk = cisclose(&wisfd, &record, &werr); - wln = -1; - } -#endif - } - +/* +* +@(SH) Funzioni per la gestione dei file ISAM +@(C$) PRIVATE +logname : nome del file di LOG (GIORNALE) +INTTLOCK : costante che indica alla funzione di lettura che e' stata chaimata dalla funzione di scrittura e quindi deve solo controllare lo stato di lock del record +ISLOCKED : costante che indica che il record e' bloccato +@(VG$) PRIVATE +KSv, PosSv : variabili di lavoro +PagSv, IndSv : variabili di lavoro +IndActive : stato indici - TRUE = Aggiornati ad ogni modifica, FALSE = aggiorna solo i dati +isstate : Stato transazione corrente +win,wisfd : variabili di lavoro +isjournal : TRUE scrive il giornale +openf : array di TUTTI i puntatori ai descrittori dei file ISAM aperti +------------------------------------------------------------------------------- +*/ +#include "cisam.h" +#include "libdefs.h" +#include "checks.h" +#include +#define logname "log.gen" +#define INTTLOCK 0xF000 +#define ISLOCKED 225 +#define NOALLOC (char **) -1 + TKey KSv; + int PosSv; + RecNoType PagSv,IndSv; + BOOLEAN IndActive = TRUE; + int isstate = NOTRANS ; + int wln = -1; + isfdptr wisfd; + extern BOOLEAN isjournal; +/* Guy moved them here from extcdecl.h */ + Str80 cprefix; + isfdptr* openf; + void savekeystat(isdef *); + void restkeystat(isdef *,int ); + int addkeys(isdef *,RecType ,int ,int *); + int delkeys(isdef *,RecType ,int ,int *); + int replkeys(isdef *,RecType ,RecType ,int ,int *); +#ifndef DOS + void writeundo(int ,isdef *,RecType); + void writelog(int ,isdef *,RecType); + char *undoname(void); + void getopenf(int ,RecType *); +#endif +/* +@($) savekeystat ISAM +@(ID) +Salva la chiave corrente. +@(FD) +*/ + void savekeystat(isfd) + isfdptr isfd; /* descrittore del file ISAM */ + { + strcpy(KSv,isfd->i.Key); + IndSv = isfd->i.Ind; + PosSv = isfd->i.Pos; + PagSv = isfd->i.CurPag; + } +/* +@($) restkeystat ISAM +@(ID) +Ripristina la chiave corrente. +@(FD) +*/ + void restkeystat(isfd,knum) + isfdptr isfd; /* descrittore del file ISAM */ + int knum; /* numero della chiave */ + { + isfd->i.PN = knum - 1; + strcpy(isfd->i.Key,KSv); + isfd->i.Ind = IndSv; + isfd->i.Pos = PosSv; + isfd->i.CurPag = PagSv; + } +/* +@($) relisfd ISAM +@(ID) +Vuota il descrittore del file . +@(FD) +*/ + void relisfd(isfd) + isfdptr *isfd; /* descrittore del file ISAM */ + { + free((char *) (*isfd)->d); + free((char *) (*isfd)->r); + free((char *) (*isfd)); + } +/* +@($) getisfd ISAM +@(ID) +Alloca e carica il descrittore del file con numero logico "logicname". +@(FD) +*/ + void getisfd(isfd, logicname) + isdef **isfd; /* descrittore del file ISAM */ + int logicname; /* numero logico del file */ + { + (*isfd) = (isfdptr) malloc(sizeof(**isfd)); + (*isfd)->d = (FileDes *) malloc(sizeof(*((*isfd)->d))); + (*isfd)->r = (RecDes *) malloc(sizeof(*((*isfd)->r))); + COpenDir(ManuLock, NORDIR); + CGetFile(logicname, (*isfd)->d, NoLock, NORDIR); + if ((!(STREMPTY((*isfd)->d->SysName))) && ((*isfd)->d->SysName[0] == '%')) + (*isfd)->ft = COMDIR; + else + (*isfd)->ft = NORDIR; + CCloseDir(NORDIR); + COpenDir(ManuLock, (*isfd)->ft); + COpenFile(logicname, (*isfd)->d, NoLock, (*isfd)->ft); + CCloseDir((*isfd)->ft); + COpenRecDir(ManuLock, (*isfd)->ft); + CGetRec(logicname,(*isfd)->r, (*isfd)->ft); + CCloseRecDir((*isfd)->ft); + } + /*void dump(s,l) + RecType s; + int l; + { + message_box("dump : record: %s ", &s[1]); + }*/ +/* +@(#) cisupdflags ISAM +@(ID) +Aggiorna all'interno del direttorio i campi EOD e Flags. +Ritorna il codice di errore. +@(FD) +@(ISV) +wd = riga relativa al file ISAM in oggetto nel Direttorio. +fdir = identificatore del file direttorio. +- Versione DOS e XENIX +@(FSV) +@(IN) +Il campo Flags viene aggiornato comunque, mentre EOD viene aggiornato solo +se il parametro di input "updateeod" e' TRUE. +@(FN) +*/ + int cisupdflags(isfd,err,updateeod) + isdef *isfd; /* puntatore al descrittore del file ISAM */ + int *err; /* codice di errore */ + BOOLEAN updateeod; /* se TRUE si aggiorna anche EOD */ + + { + FileDes wd; + + *err = NoErr ; + if (isfd->ln <= 0) return(*err) ; + COpenDir( ManuLock, isfd->ft); + COpenFile(isfd->ln, &wd, Lock, isfd->ft); + if ((*err = fdir[isfd->ft].IOR) == NoErr) + { + wd.Flags = isfd->d->Flags; +/* #ifdef DOS + if (updateeod) wd.EOD = isfd->d->EOD; + #else */ + if ((updateeod) && (isfd->f.LockMode == ExclLock)) wd.EOD = isfd->d->EOD; +/* #endif */ + CCloseFile(isfd->ln, &wd, isfd->ft); + } + CCloseDir(isfd->ft); + return(*err); + } + +/* +@(#) cisgeteod ISAM + +@(ID) +Ritorna l' EOD del file. +@(FD) + +@(ISV) + +- Versione DOS e XENIX +@(FSV) + +*/ + + RecNoType cisgeteod(isfd,err) + isfdptr isfd; /* puntatore al descrittore del file ISAM */ + int *err; /* codice di errore */ + + { + + *err = NoErr ; + if (isfd->ln > 0) + { + COpenDir( ManuLock , isfd->ft); + COpenFile(isfd->ln, isfd->d, NoLock, isfd->ft); + CCloseDir(isfd->ft); + } + return(isfd->d->EOD) ; + } + +/* +@(#) cisopen ISAM + +@(ID) +Apre un file ISAM e alloca il buffer per un record a attiva la chiave 1 (uno). +Ritorna il codice di errore. +@(FD) + +@(ISV) +werr = variabile di lavoro che raccoglie il codice errore proveniente dalla CBCloseFile. + +s = stringa di lavoro per messaggi di errore. + +- Versione DOS e XENIX +@(FSV) + +@(IN) +@(FN) +*/ + + int cisopen (isfd,logicname,record,mode,err) + isfdptr *isfd; /* puntatore al descrittore del file */ + int logicname; /* numero logico */ + RecType *record; /* buffer per contenere un record */ + unsigned int mode; /* modo di apertura (lock) */ + int *err; /* codice di errore */ + + { + *err = NoErr; + if (openf[logicname - 1] != NULL) + fatal_box("File n. %d already open", logicname); +#ifndef DOS + if ((excllock(CInsPref(glockname, NORDIR), FALSE) == -1) && (errno == EACCES)) + fatal_box("Can't open directory : Error n. %d ", errno); +#endif + getisfd (isfd,logicname); + COpen(&((*isfd)->f), (*isfd)->d->SysName, (*isfd)->d->LenR, 0, mode); + if (*err = (*isfd)->f.IOR) + { + Str80 name; strcpy(name, (*isfd)->d->SysName); + relisfd(isfd); + fatal_box("Can't open file n. %d (%s): error %d ", + logicname, name, *err); + } + if ((*isfd)->r->NKeys) + { + Str80 name; strcpy(name, CGetIdxName((*isfd)->d->SysName)); + CBOpenFile (&((*isfd)->i), name, mode, err); + if (*err) + { + CClose(&((*isfd)->f)); + relisfd(isfd); + fatal_box("Can't open file n. %d (%s): error %d ", + logicname, name, *err); + } +#ifndef DOS + else + if (mode == ExclLock) + { + CBLockFile(&((*isfd)->i), err); + if (*err) + { + int werr; + CClose(&((*isfd)->f)); + CBCloseFile(&((*isfd)->i), &werr); + relisfd(isfd); + fatal_box("Can't open exclusively file n. %d: error %d ", logicname, *err); + } + } +#endif + } + if (record != NOALLOC) + *record = (RecType) malloc((*isfd)->d->LenR); + (*isfd)->ln = logicname; + openf[logicname - 1] = *isfd; + if ((*isfd)->r->NKeys) (*isfd)->i.PN = 0; + return (*err); + } + +/* +@(#) ciscopyrec ISAM + +@(ID) +Copia un record dati da un record ad un altro. +Ritorna il codice di errore. +@(FD) + +@(ISV) +d = riga del direttorio corrispondente al file in esame. +@(FSV) + +@(IN) +@(FN) +*/ + + int ciscopyrec(logicname,recdest, recsrc ,err) + int logicname; /* numero logico del file ISAM */ + RecType recdest; /* buffer destinazione */ + RecType recsrc; /* buffer sorgente */ + int *err; /* codice di errore */ + + { + FileDes d; + int ft; + + *err = NoErr; + if (logicname < 0) logicname = -logicname; + if (openf[logicname - 1] != NULL) d = *(openf[logicname - 1]->d); + { + COpenDir(ManuLock, NORDIR); + CGetFile(logicname, &d, NoLock, NORDIR); + if ((!(STREMPTY(d.SysName))) && (d.SysName[0] == '%')) ft = COMDIR; + else ft = NORDIR; + CCloseDir(NORDIR); + COpenDir(ManuLock, ft); + COpenFile(logicname, &d, NoLock, ft); + CCloseDir(ft); + } + memcpy(recdest, recsrc, d.LenR); + return(*err); + } + +/* +@(#) cisallocrec ISAM + +@(ID) +Alloca il buffer per un record. +Ritorna il codice di errore. +@(FD) + +@(ISV) +d = riga del direttorio corrispondente al file in esame. +@(FSV) + +@(IN) +@(FN) +*/ + + int cisallocrec(logicname,record,err) + int logicname; /* numero logico del file ISAM */ + RecType *record; /* buffer per il record */ + int *err; /* codice di errore */ + + { + FileDes d; + int ft; + + *err = NoErr; + if (logicname < 0) logicname = -logicname; + if (openf[logicname - 1] != NULL) d = *(openf[logicname - 1]->d); + else + { + COpenDir(ManuLock, NORDIR); + CGetFile(logicname, &d, NoLock, NORDIR); + if ((!(STREMPTY(d.SysName))) && (d.SysName[0] == '%')) ft = COMDIR; + else ft = NORDIR; + CCloseDir(NORDIR); + COpenDir(ManuLock, ft); + COpenFile(logicname, &d, NoLock, ft); + CCloseDir(ft); + } + *record = (RecType) malloc(d.LenR); + if (*record == ((RecType) NULL)) return(ENOMEM); + else return(*err); + } + +/* +@(#) cisclose ISAM + +@(ID) +Chiude un file ISAM e libera il buffer del record. +Ritorna il codice di errore. +@(FD) + +@(ISV) +werr = variabile di lavoro che raccoglie il codice errore proveniente dalla CBCloseFile. + +s[20] = stringa di lavoro per messaggi di errore. + +- Versione DOS e XENIX +@(FSV) + +@(IN) +Restituisce il codice di errore +@(FN) +*/ + + int cisclose(isfd,rec,err) + isdef **isfd; /* puntatore al descrittore del file */ + RecType *rec; /* buffer per il record */ + int *err; /* codice di errore */ + + { + int werr = NoErr; + + *err = NoErr; + if (((*isfd)->ln > 0) && ((*isfd == NULL) || (openf[(*isfd)->ln - 1] == NULL))) + { + if (*isfd != NULL) + error_box("File n. % isclose : Error n. %d ", (*isfd)->ln, IsNotOpen); + else + error_box("isclose : errore n. %d ", IsNotOpen); + } + CClose(&((*isfd)->f)); + *err = ((*isfd)->f.IOR); + if ((*isfd)->r->NKeys) + { + CBCloseFile(&((*isfd)->i), &werr); + if (werr != NoErr ) *err = werr; + } + if ((*isfd)->ln > 0) + openf[(*isfd)->ln - 1] = NULL ; + if ((rec != NULL) && (*rec != NULL)) + free(*rec); + relisfd(isfd); +#ifndef DOS + exclunlock(CInsPref(glockname, NORDIR), FALSE); +#endif + if (*err) + fatal_box("isclose : Error n. %d ", *err); + return (*err); + } + +/* +@(#) cisstart ISAM + +@(ID) +Esegue una lettura cambiando il numero di chiave attiva. +Ritorna il codice di errore. +@(FD) + +@(IN) + La variabile record in input contiene i campi necessari per la ricerca, + in output contiene il record letto. + + La variabile mode e' formata da un comando di lock + comando di posizionamento + . Se non si utilizza ISEQUAL o ISGREAT o ISGTEQ, il valore della variabile + record non ha nessuna importanza. +@(FN) +*/ + + int cisstart(isfd,keynum,record,mode,err) + isfdptr isfd; /* descrittore del file ISAM */ + int keynum; /* numero della chiave */ + RecType record; /* buffer per il record */ + unsigned int mode; /* comando di lettura */ + int *err; /* codice di errore */ + + { + if(isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); + *err = NoErr; + if(!(keynum >= 1) && (keynum <= isfd->r->NKeys)) + return((*err = BTrPathErr)); + isfd->i.PN = keynum - 1; + *err = cisread(isfd,record,mode,err); + return(*err); + } + +/* +@(#) cisread ISAM + +@(ID) +Esegue una lettura utilizzando la chiave attiva. +Ritorna il codice di errore. +@(FD) + +@(ISV) +rmode = variabile che contiene il tipo lettura utilizzato. + +lmode = varibaile dhe contiene il tipo lock utilizzato. + +knum = numero chiave attiva. + +junk = variabile spazzatura per la chiamata alla funzione "sleep". + +times = variabile di lavoro. + +s = stringa contenente messaggio. + +w = descrittore finestra . + +internaltlock = flag che verifica se la isread e' stata chiamata da iswrite per testare l' esistenza di un record. + +@(FSV) + +@(IN) + La variabile record in input contiene i campi necessari per la ricerca, + in output contiene il record letto. + + La variabile mode e' formata da un comando di lock + comando di posizionamento + . Se non si utilizza ISEQUAL o ISGREAT o ISGTEQ, il valore della variabile + record non ha nessuna importanza. +@(FN) +*/ + + int cisread(isfd,record,mode,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record;/* buffer per il record */ + unsigned int mode; /* modo di lettura */ + int *err; /* codice di errore */ + + { + unsigned int rmode = (mode & READTYPES), + lmode = (mode & RecLockTypes), + knum = (isfd->i.PN+1); + int junk,times = 1; + TKey key,key1,key2; +/* char s[120]; */ + BOOLEAN internaltlock = (lmode == INTTLOCK); + + if (internaltlock) lmode = ShareLock; + *err = NoErr ; + if (isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); + if (rmode & (IsPrevN + IsNextN)) + { + times = rmode & BYTEMASK; + if (rmode & IsPrevN) rmode = IsPrev; + else rmode = IsNext; + } + if (rmode == IsCurr) + { + if (!isfd->RecNo) return((*err = IsNotCurr)); + } + else + { + if (rmode == IsNext) + { + while ((times--) && (!*err)) + { + CBNext(&isfd->i,knum,key1,&isfd->RecNo,err); + } + } + else + { + if (rmode == IsPrev) + { + while ((times--) && (!*err)) + { + CBPrev(&isfd->i,knum,key1,&isfd->RecNo,err); + } + } + else + { + if (rmode == IsFirst) MinKey(CCalcLenKey(isfd->r,knum),key); + else + if (rmode == IsLast) MaxKey(CCalcLenKey(isfd->r,knum),key); + else + CBuildKey(isfd->r,knum,record,key); + CBRead(&isfd->i,knum,key,key1,&isfd->RecNo,err); + if ((rmode == IsGreat) && (!*err)) + while ((strcmp(key,key1) == 0) && (!*err)) + CBNext (&isfd->i,knum,key1,&isfd->RecNo,err); + } + } + } + do + { + if (((*err) && (rmode == IsEqual)) || + ((*err == BTrEOF) && (rmode == IsGreat))) + CRead(&isfd->f,record,isfd->RecNo,NoLock); + else + CRead(&isfd->f,record,isfd->RecNo,lmode); + if (TESTLOCK(isfd->f.IOR)) + { + if (lmode == ShareLock) + { + if (!*err) *err = ISLOCKED; + break; + } + message_box("Codice %s in uso da parte\ndi un altro utente.", key1); + if (rmode != IsCurr) + { + CBReRead(&isfd->i,knum,key1,key2,isfd->RecNo,&isfd->RecNo,&junk); + if (junk) strcpy(key1, key2) ; + } + } + else + if (!*err) *err = isfd->f.IOR; + } while (TESTLOCK(isfd->f.IOR)) ; + if (((rmode == IsFirst) || (rmode == IsLast)) && (*err != BTrEmptyTree)) + *err = NoErr; + if ((rmode == IsGtEq) && (*err != BTrEOF) && (*err != BTrEmptyTree)) + *err = NoErr ; + if (DEADLOCK(*err)) return(*err = IsDeadLock); + if (rmode == IsCurr) + { + CBuildKey(isfd->r,knum,record,key); + CBReRead(&isfd->i,knum,key,key1,isfd->RecNo,&isfd->RecNo,&junk); + } + if (*err == BTrEmptyTree) CZeroRec(isfd->r, record); + return(*err); + } + +/* +@($) addkeys ISAM + +@(ID) +Aggiunge all'indice le chiavi contenute nel record. +Ritorna il codice di errore. +@(FD) + +@(ISV) +i,j = contatori. + +werr = codice errore restituito dalla CBDelete. + +key = valore delle chiavi. +@(FSV) + +@(IN) +@(FN) +*/ + + int addkeys (isfd,record,knum,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer per il record */ + int knum; /* numero chiave corrente */ + int *err; /* codice errore */ + + { + int i,j,werr; + TKey key; + + for (i = 1;(i <= isfd->r->NKeys) && (!*err);i++) + { + CBuildKey(isfd->r,i,record,key); + CBWrite(&isfd->i,i,key,isfd->RecNo,err); + if (i == knum) savekeystat(isfd); + } + if (*err) + { + if (i == 2 && *err == BTrDupKeysNotAll) *err = IsReInsert; + for (j = 1; (j < i); j++) + { + CBuildKey(isfd->r,j,record,key); + CBDelete(&isfd->i,j,key,isfd->RecNo,&werr); + } + } + else restkeystat(isfd,knum); + return(*err); + } + +/* +@(#) ciswrite ISAM + +@(ID) +Aggiunge un nuovo record al file ISAM. +Ritorna il codice di errore. +@(FD) + +@(ISV) +werr = codice errore restituito. + +knum = numero chiave attiva. + +junk = variabile di lavoro per la chiamata di varie funzioni. + +wrec = buffer di lavoro. +@(FSV) + +@(IN) + La variabile record in input contiene il record da aggiungere. +@(FN) +*/ + + int ciswrite (isfd,record,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer per il record */ + int *err; /* codice di errore */ + + { + int knum = (isfd->i.PN+1), werr, junk; + RecNoType neweox; + + *err = NoErr; + if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); + if (isfd->ln > 0) + { + COpenDir (ManuLock, isfd->ft); + COpenFile(isfd->ln,isfd->d, Lock, isfd->ft); + } + if (isfd->d->EOD == isfd->d->EOX) + { + neweox = isfd->d->EOX / 20 + 1; + if (neweox < 10) neweox = 10; + if (demoflag) + *err = IsFileFull; + else + { + neweox += isfd->d->EOX; + cisextend(isfd, isfd->ln, neweox, err); + } + if (*err == NoErr) + { + if (isfd->ln > 0) + { + COpenFile(isfd->ln,isfd->d, NoLock, isfd->ft); + for (junk = 0; junk < isfd->r->NKeys; junk++) + isfd->i.Base[junk].PEOX = neweox; + } + else + { + isfd->d->EOX = neweox; + if (isfd->f.LockMode == ExclLock) + for (junk = 0; junk < isfd->r->NKeys; junk++) + isfd->i.Base[junk].PEOX = neweox; + } + } + else + { + if (isfd->ln > 0) + { + COpenFile(isfd->ln,isfd->d, UnLock, isfd->ft); + CCloseDir(isfd->ft); + } + isfd->RecNo = 0; + if (DEADLOCK(*err)) *err = IsDeadLock; + return((*err ? *err : (*err = IsFileFull))); + } + } + IRecallRec(record); + if (test_share() && isfd->f.LockMode != ExclLock) + { + RecType wrec = malloc(isfd->d->LenR); + memcpy(wrec, record, isfd->d->LenR); + savekeystat(isfd); + junk = cisstart(isfd, 1, wrec, NoLock+IsEqual, &junk); + restkeystat(isfd, knum); + free(wrec); + + if ((junk == NoErr) || (junk == ISLOCKED)) + { + *err = IsReInsert; + if (isfd->ln > 0) + { + COpenFile(isfd->ln,isfd->d, UnLock, isfd->ft); + CCloseDir(isfd->ft); + } + isfd->RecNo = 0; + return(*err); + } + } + isfd->RecNo = (++isfd->d->EOD); + if ((isfd->r->NKeys) && IndActive) + { + if(test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i,err) ; + if (!addkeys(isfd, record, knum, err)) + { + CWrite(&isfd->f,record,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) + { + isfd->RecNo = 0; + junk = delkeys(isfd, record, knum, &werr); + } + else + if (isfd->ln > 0) + CCloseFile(isfd->ln,isfd->d, isfd->ft) ; + } + else isfd->d->EOD-- ; + if(test_share() && isfd->f.LockMode != ExclLock) + CBUnLockFile(&isfd->i, &werr) ; + } + else + { + CWrite(&isfd->f,record,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) isfd->RecNo = 0; + else CCloseFile(isfd->ln,isfd->d, isfd->ft) ; + } + if (!(*err)) + { +#ifndef DOS + if (isstate == NOTRANS) writelog(FNWRITE, isfd, record); + else writeundo(FNWRITE, isfd, record); +#endif + } + if (isfd->ln > 0) + CCloseDir(isfd->ft); + if (test_share()) + { + junk = cisunlock(isfd, &junk); + if (isstate == NOTRANS) + CLockRec(&isfd->f,isfd->RecNo,UnLock); + if (DEADLOCK(*err)) *err = IsDeadLock; + } + return(*err); + } + +/* +@($) delkeys ISAM + +@(ID) +Cancella le chiavi contenute nel record dall'indice. +Ritorna il codice di errore. +@(FD) + +@(ISV) +i,j = contatori. + +werr = codice errore da CBWrite. + +key = valori chiave. +@(FSV) + +@(IN) +@(FN) +*/ + + int delkeys (isfd,record,knum,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer per il record */ + int knum; /* numero della chiave attuale */ + int *err; /* codice di errore */ + + { + int i,j,werr; + TKey key; + + for (i = 1;(i <= isfd->r->NKeys)&&(!*err);i++) + { + CBuildKey(isfd->r,i,record,key); + CBDelete(&isfd->i,i,key,isfd->RecNo,err); + } + if (*err) + { + for (j = 1;(j < i);j++) + { + CBuildKey(isfd->r,j,record,key); + CBWrite(&isfd->i,j,key,isfd->RecNo,&werr); + } + } + else restkeystat(isfd,knum); + return(*err); + } + +/* +@(#) cisdelete ISAM + +@(ID) +Cancella un record da un file ISAM. +Ritorna il codice di errore. +@(FD) + +@(ISV) +knum = numero chiave successiva a quella attiva. + +werr = codice errore da CBUnLockFile. + +key1,key = valori chiave. + +- Versione DOS e XENIX +@(FSV) + +@(IN) + La variabile record in input contiene il record da cancellare. +@(FN) +*/ + + int cisdelete(isfd,record,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer per il record */ + int *err; /* codice di errore */ + + { + int knum = (isfd->i.PN+1), werr; + TKey key,key1; + + if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); + *err = NoErr; + savekeystat(isfd); + CBuildKey(isfd->r,1,record,key); + *err = NoErr ; + CBRead(&isfd->i,1,key,key1,&isfd->RecNo,err); + if (*err) + { + restkeystat(isfd,knum); + return(*err); + } + CRead(&isfd->f, record, isfd->RecNo, NoLock); + if ((*err = isfd->f.IOR)) + { + restkeystat(isfd,knum); + return(*err); + } + if ((isfd->r->NKeys) && IndActive) + { + if(test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i,err) ; + delkeys(isfd, record, knum, err) ; + } + IDeleteRec(record); + CWrite(&isfd->f,record,isfd->RecNo,UnLock); + if((*err = isfd->f.IOR)) + { + IRecallRec(record); + CWrite(&isfd->f,record,isfd->RecNo,NoLock); + if ((isfd->r->NKeys) && IndActive) addkeys(isfd, record, knum, err) ; + restkeystat(isfd,knum); + } +#ifndef DOS + else + { + if (isstate == NOTRANS) + { + writelog(FNDELETE, isfd, NULL); + CRead(&isfd->f,record,isfd->RecNo,UnLock); + } + else writeundo(FNDELETE, isfd, NULL); + } + if (test_share() && (isfd->r->NKeys) && IndActive && + (isfd->f.LockMode != ExclLock)) + CBUnLockFile(&isfd->i, &werr) ; +#else + if (test_share()) + { + CRead(&isfd->f,record,isfd->RecNo,UnLock); + if (isfd->r->NKeys && IndActive && + (isfd->f.LockMode != ExclLock)) + CBUnLockFile(&isfd->i, &werr) ; + } +#endif + return(*err); + } + +/* +@($) replkeys ISAM + +@(ID) +Rimpiazza le chiavi all'interno dell'indice. +Ritorna il codice di errore. +@(FD) + +@(ISV) +i,j = contatori. + +werr = codice errore ritornato da CBDelete e CBWrite. + +key,key1 = valori delle chiavi. +@(FSV) +*/ + + int replkeys (isfd,oldrec,record,knum,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType oldrec; /* buffer contenente il vecchio record */ + RecType record; /* buffer contenente il nuovo record */ + int knum; /* numero della chiave attuale */ + int *err; /* codice di errore */ + + { + int i,j,werr; + TKey key,key1; + + for (i = 1;(i <= isfd->r->NKeys)&&(!*err);i++) + { + CBuildKey(isfd->r,i,record,key); + CBuildKey(isfd->r,i,oldrec,key1); + if (strcmp(key,key1) != 0) + { + CBDelete(&isfd->i,i,key1,isfd->RecNo,err); + if (*err) break; + CBWrite(&isfd->i,i,key,isfd->RecNo,err); + if (*err) CBWrite(&isfd->i,i,key1,isfd->RecNo,err); + if (i == knum) savekeystat(isfd); + } + } + if (*err) + { + for (j = 1;(j < i);j++) + { + CBuildKey(isfd->r,j,record,key); + CBuildKey(isfd->r,j,oldrec,key1); + if (strcmp(key,key1) != 0) + { + CBDelete (&isfd->i,j,key,isfd->RecNo,&werr); + CBWrite(&isfd->i,j,key1,isfd->RecNo,&werr); + } + } + } + else restkeystat(isfd,knum); + return(*err); + } + +/* +@(#) cisrewrite ISAM + +@(ID) +Aggiorna un record nel file ISAM. +Ritorna il codice di errore. +@(FD) + +@(ISV) +knum = numero chiave successiva all'attuale. + +werr = codice errore restituito da CBUnLock. + +key, key1 = valori delle chiavi. + +oldrec = buffer di lavoro. + +- Versione DOS e XENIX +@(FSV) + +@(IN) + La variabile record in input contiene il record da aggiornare. +Utilizza la chiave 1 per ritrovare il record da aggiornare. +@(FN) +*/ + + int cisrewrite(isfd,record,err) + isfdptr isfd; /* descrittore del file isam */ + RecType record; /* buffer contenente i record */ + int *err; /* codice di errore */ + + { + int knum = (isfd->i.PN+1), werr; + TKey key,key1; + RecType oldrec; + + *err = NoErr ; + if(isfd == ((isfdptr) NULL)) return((*err = IsNotOpen)); + oldrec = (RecType) malloc(isfd->d->LenR); + savekeystat(isfd); + IRecallRec(record); + CBuildKey(isfd->r,1,record,key); + CBRead(&isfd->i,1,key,key1,&isfd->RecNo,err); + if(*err) + { + restkeystat(isfd,knum); + return(*err); + } + CRead(&isfd->f,oldrec,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) + { + restkeystat(isfd,knum); + free(oldrec); + return(*err); + } + if (memcmp(oldrec,record,isfd->d->LenR) == 0) + { + *err = NoErr; + restkeystat(isfd,knum); + CLockRec(&isfd->f,isfd->RecNo,UnLock); + free(oldrec); + return(*err); + } + if ((isfd->r->NKeys) && IndActive) + { + if(test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i, err) ; + replkeys(isfd, oldrec, record, knum, err) ; + if(test_share() && isfd->f.LockMode != ExclLock) + CBUnLockFile(&isfd->i, &werr) ; + } + CWrite(&isfd->f,record,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) + { + CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); + replkeys(isfd, record, oldrec, knum, err) ; + restkeystat(isfd,knum); + } + else +#ifndef DOS + { + if (isstate == NOTRANS) + { + writelog(FNREWRITE, isfd, record); + CLockRec(&isfd->f,isfd->RecNo,UnLock); + } + else writeundo(FNREWRITE, isfd, oldrec); + } + +#else + if (test_share()) + CLockRec(&isfd->f,isfd->RecNo,UnLock); +#endif + free(oldrec); + return(*err); + } + +/* +@(#) cisdelcurr ISAM + +@(ID) +Cancella il record corrente. +Ritorna il codice di errore. +@(FD) +*/ + + int cisdelcurr(isfd,err) + isfdptr isfd; /* descrittore del file ISAM */ + int *err; /* codice di errore */ + + { + if(isfd->RecNo) cisdelrec(isfd,isfd->RecNo,err); + else *err = IsNotCurr; + return(*err); + } + +/* +@(#) cisrewcurr ISAM + +@(ID) +Riscrive il record corrente. +Ritorna il codice di errore. +@(FD) + +@(IN) + La variabile record in input contiene il record da aggiornare. +@(FN) +*/ + + int cisrewcurr(isfd,record,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer contenente il record */ + int *err; /* codice di errore */ + + { + if(isfd->RecNo) cisrewrec(isfd,isfd->RecNo,record,err); + else *err = IsNotCurr; + return (*err); + } + +/* +@(#) cisreadrec ISAM + +@(ID) +Legge un record di numero "recnum". +Ritorna il codice di errore. +@(FD) +*/ + + int cisreadrec(isfd,recnum,record,mode,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecNoType recnum; /* numero del record */ + RecType record; /* buffer per il record */ + unsigned int mode; /* modo di lock */ + int *err; /* codice di errore */ + + { + isfd->RecNo = recnum; + return(cisread(isfd,record,IsCurr+(mode & RecLockTypes),err)); + } + +/* +@(#) ciswriterec ISAM + +@(ID) +Riscrive un record di numero "recnum". +@(FD) + +@(IN) + La variabile record in input contiene il record da aggiornare. +@(FN) + +@(ISV) +knum = numero chiave attiva. + +werr = codice errore restituito da CBUnLockFile. + +oldrec = buffer di lavoro. + +- Versione DOS e XENIX +@(FSV) +*/ + + int cisrewrec(isfd,recnum,record,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecNoType recnum; /* numero del record da riscrivere */ + RecType record; /* buffer per il record */ + int *err; /* codice di errore */ + + { + int knum = (isfd->i.PN+1), werr; + RecType oldrec; + + *err = NoErr; + if (isfd == ((isfdptr) NULL)) return ((*err = IsNotOpen)); + oldrec = (RecType) malloc(isfd->d->LenR); + isfd->RecNo = recnum; + IRecallRec(record); + CRead(&isfd->f,oldrec,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) + { + free(oldrec); + return(*err); + } + if (memcmp(oldrec,record,isfd->d->LenR) == 0) + { + *err = NoErr; + if (test_share()) + CLockRec(&isfd->f,isfd->RecNo,UnLock); + free(oldrec); + return(*err); + } + if ((isfd->r->NKeys) && IndActive) + { + if (test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i, err) ; + replkeys(isfd, oldrec, record, knum, err) ; + if (test_share() && isfd->f.LockMode != ExclLock) + CBUnLockFile(&isfd->i, &werr) ; + } + if (isstate == NOTRANS) CWrite(&isfd->f,record,isfd->RecNo,UnLock); + else CWrite(&isfd->f,record,isfd->RecNo,NoLock); + if ((*err = isfd->f.IOR)) + { + CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); + replkeys(isfd, record, oldrec, knum, err) ; + } +#ifndef DOS + else + { + if (isstate == NOTRANS) + { + writelog(FNREWRITE, isfd, record); + CLockRec(&isfd->f,isfd->RecNo,UnLock); + } + else writeundo(FNREWRITE, isfd, oldrec); + } +#else + if (test_share()) + CLockRec(&isfd->f,isfd->RecNo,UnLock); +#endif + free(oldrec); + return(*err); + } +/* +@(#) cisdelrec ISAM +@(ID) +Cancella un record utilizzando un numero di record. +Ritorna il codice di errore. +@(FD) +@(IN) + La variabile record in input contiene il record da cancellare. +@(FN) +@(ISV) +knum = numero della chiave attiva. +werr = codice di errore restituito da CBUnLockFiles. +oldrec = buffer di lavoro. +key1 = valore della chiave. +- Versione DOS e XENIX +@(FSV) +*/ + int cisdelrec(isfd,recnum,err) + isfdptr isfd; /* descrittore del file ISAM */ + RecNoType recnum; /* numero di record */ + int *err; /* codice di errore */ + { + int knum = (isfd->i.PN+1), werr; + int junk; + RecType oldrec ; + TKey key1 ; + *err = NoErr; + if(isfd == (isfdptr) NULL) return ((*err = IsNotOpen)); + oldrec = (RecType) malloc(isfd->d->LenR); + isfd->RecNo = recnum; + savekeystat(isfd); + CRead(&isfd->f, oldrec, isfd->RecNo, NoLock); + if ((*err = isfd->f.IOR)) + { + free(oldrec); + return(*err); + } + if ((isfd->r->NKeys) && IndActive) + { + if(test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i, err) ; + delkeys(isfd, oldrec, knum, err); + } + IDeleteRec(oldrec); + CWrite(&isfd->f,oldrec,isfd->RecNo,UnLock); + if ((*err = isfd->f.IOR)) + { + IRecallRec(oldrec); + CWrite(&isfd->f,oldrec,isfd->RecNo,NoLock); + if ((isfd->r->NKeys) && IndActive) addkeys(isfd, oldrec, knum, err); + } +#ifndef DOS + else + { + if (isstate == NOTRANS) + { + writelog(FNDELETE, isfd, NULL); + CLockRec(&isfd->f,isfd->RecNo,UnLock); + } + else writeundo(FNDELETE, isfd, NULL); + } + if (test_share() && (isfd->r->NKeys) && IndActive && (isfd->f.LockMode != ExclLock)) + CBUnLockFile(&isfd->i, &werr) ; +#else + if (test_share()) + { + CLockRec(&isfd->f,isfd->RecNo,UnLock); + if (isfd->r->NKeys && IndActive && + (isfd->f.LockMode != ExclLock)) + CBUnLockFile(&isfd->i, &werr) ; + } +#endif + free(oldrec); + isfd->RecNo = 0; + return(*err); + } +/* +@(#) cisgetrecno ISAM +@(ID) +Restituisce il numero del record corrente. +@(FD) +*/ + RecNoType cisgetrecno(isfd, err) + isfdptr isfd; /* descrittore del file ISAM */ + int *err; /* codice di errore */ + + { + if (!isfd->RecNo) *err = IsNotCurr; + else *err = NoErr; + return(isfd->RecNo); + } +/* +@(#) cislock ISAM +@(ID) +Blocca il file ISAM. +@(FD) +@(ISV) +junk = variabile spazzatura per la chiamata di sleep. +@(FSV) +*/ + int cislock(isfd,err) + isfdptr isfd; /* descrittore del file ISAM */ + int *err; /* codice di errore */ + { + int junk; + *err = NoErr ; + if (lseek(isfd->f.F, 0L, 0) == -1) return ((*err = CIOResult())); +#ifndef DOS + do + { + if (lockf(isfd->f.F,F_TLOCK,0L) == -1) + { + *err = CIOResult() ; + junk = sleep(1) ; + } + } while (TESTLOCK(*err)) ; +#endif + if(test_share() && isfd->f.LockMode != ExclLock) + CBLockFile(&isfd->i,err); + return(*err); + } +/* +@(#) cisunlock ISAM +@(ID) +Sblocca un file ISAM. +@(FD) +*/ + int cisunlock(isfd,err) + isfdptr isfd; /* descrittore del file */ + int *err; /* codice di errore */ + { + return(cisrelease(isfd,err)); + } +/* +@(#) cisrelease ISAM +@(ID) +Sblocca un file ISAM. +@(FD) +*/ + int cisrelease(isfd,err) + isfdptr isfd; /* descrittore del file ISAM */ + int *err; /* codice di errore */ + { + *err = NoErr ; +#ifndef DOS + if (lseek(isfd->f.F, 0L, 0) == -1) return ((*err = CIOResult())); + do + { + if (lockf(isfd->f.F,F_ULOCK,0L) == -1) *err = CIOResult() ; + } while (TESTLOCK(*err)) ; +#endif + if(test_share() && isfd->f.LockMode != ExclLock) + CBUnLockFile(&isfd->i,err); + return(*err); + } +/* +@(#) IndexOn ISAM +@(ID) +Attiva Aggiornamento Indici. +@(FD) +@(IN) +Di default gli indici sono attivi. +@(FN) +*/ + void IndexOn() + { + IndActive = TRUE ; + } +/* +@(#) IndexOff ISAM +@(ID) +Disattiva l'aggiornamento Indici. +@(FD) +*/ + void IndexOff() + { + IndActive = FALSE ; + } +#ifndef DOS +/* +@($) undoname ISAM +@(ID) +Restituisce il nome del file di Undo. +@(FD) +@(ISV) +path = stringa contenente il nome file. +@(FSV) +*/ + char *undoname() + { + static PathSt path; + TMPFNAME(path, "undo"); + return(path); + } +/* +@($) writeundo ISAM +@(ID) +Scrive una operazione effettuata nel file di Undo. +@(FD) +@(ISV) +fd = puntatore al file. +uname = nome del file di undo. +lgh = variabile di lavoro che contiene l' header del record di undo. +@(FSV) +*/ + void writeundo(fntype,isfd,record) + int fntype; /* operazione da effettuare */ + isfdptr isfd; /* descrittore del file */ + RecType record; /* buffer contenente il record */ + { + int fd; + PathSt uname; + loghead lgh; + + if (isfd->ln <= 0) return ; + strcpy(uname ,undoname()); + if ((fd = open(uname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) + fatal_box("Writeundo : Error n. %d ", errno); + lgh.type = fntype; + lgh.time = time(NULL); + lgh.procid = getpid(); + lgh.userid = getuid(); + lgh.filenum = isfd->ln; + lgh.recnum = isfd->RecNo; + lgh.lenrec = isfd->d->LenR; + if (write(fd, &lgh, sizeof(lgh)) == -1) + fatal_box("Writeundo : Error n. %d ", errno); + if (fntype & (FNREWRITE)) + if (write(fd, record, lgh.lenrec) == -1) + fatal_box("Writeundo : Error n. %d ", errno); + if (close(fd) == -1) + fatal_box("Writeundo : Error n. %d ", errno); + } +/* +@($) writelog ISAM +@(ID) +Scrive sul file Giornale l'operazione effettuata. +@(FD) +@(ISV) +junk = variabile spazzatura per la chiamata di execunlock. +lname = nome del file Giornale (LOG). +fd = puntatore al file giornale. +lgh = testata del file giornale. +@(FSV) +*/ + void writelog(fntype,isfd,record) + int fntype; /* operazione effetuata */ + isfdptr isfd; /* descrittore del file ISAM */ + RecType record; /* buffer per il record */ + { + int fd,junk; + PathSt lname; + loghead lgh; + if (!isjournal) return; + if (isfd->ln <= 0) return ; + strcpy(lname, CInsPref(logname, NORDIR)); + while (excllock(lname,TRUE) == -1) sleep(1); + if ((fd = open(lname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Writelog : Error n. %d ", errno); + } + lgh.type = fntype + FNSTTRANS; + lgh.time = time(NULL); + lgh.procid = getpid(); + lgh.userid = getuid(); + if (fntype & (FNREWRITE + FNWRITE + FNDELETE)) + { + lgh.filenum = isfd->ln; + lgh.recnum = isfd->RecNo; + lgh.lenrec = isfd->d->LenR; + } + else + { + lgh.filenum = 0; + if (fntype == FNREORG) lgh.recnum = *((RecNoType *) record); + else lgh.recnum = 0L; + if (fntype == FNCHGREC) lgh.lenrec = sizeof(RecDes); + else lgh.lenrec = 0; + } + if (write(fd, &lgh, sizeof(lgh)) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Writelog : Error n. %d ", errno); + } + if (fntype & (FNREWRITE + FNWRITE + FNCHGREC)) + if (write(fd, record, lgh.lenrec) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Writelog : Error n. %d ", errno); + } + if (close(fd) == -1) + fatal_box("Writelog : Error n. %d ", errno); + junk = exclunlock(lname,TRUE); + } +#endif +/* +@(#) StTrans ISAM +@(ID) +Inizia una transazione. +@(FD) +*/ + void StTrans() + { +#ifndef DOS + if (isstate == TRANS) EndTrans(); +#endif + isstate = TRANS; + } +#ifndef DOS +/* +@($) getopenf ISAM +@(ID) +Riconfigura il file di lavoro attivo sul file di numero logico "ln". +@(FD) +@(ISV) +junk = variabile spazzatura per la chiamata alla cisclose. +err = codice di errore ritornato dalla cisopen. +@(FSV) +*/ + void getopenf(ln,record) + int ln; /* numero logico del file */ + RecType *record; /* puntatore al buffer per il record */ + { + int err,junk; + if (openf[ln - 1] == NULL) + { + if (wln != ln) + { + if (wln != -1) junk = cisclose(&wisfd ,record ,&err); + cisopen(&wisfd, ln, record, ManuLock, &err); + wln = ln; + } + } + else *record = realloc(*record, openf[ln - 1]->d->LenR); + } +#endif +/* +@(#) EndTrans ISAM +@(ID) +Chiude una transazione. +@(FD) +@(ISV) +fdl, fdu = puntatori ai file di LOG e di Undo. +lname, uname = nomi dei file di LOG e di Undo. +lgh, lgh1 = variabili di lavoro contenenti le testate dei file di log. +nread = variabile di lavoro per la chiamata alla read. +werr = codice di errore ritornato dalla cisclose. +junk = variabile spazzatura per la chiamata di exclunlock. +start = variabile di lavoro. +record = buffer di lavoro. +@(FSV) +*/ + void EndTrans() + { +#ifndef DOS + int fdl, fdu; + PathSt lname, uname; + loghead lgh, lgh1; + int nread, werr, junk, start = FNSTTRANS; + RecType record; + strcpy(lname ,CInsPref(logname, NORDIR)); + while (excllock(lname,TRUE) == -1) sleep(1); + if (((fdl = open(lname, O_WRONLY | O_CREAT | O_APPEND, 0666)) == -1) || + ((fdu = open(uname, O_RDONLY, 0666)) == -1)) + { + junk = exclunlock(lname,TRUE); + fatal_box("Endtrans : Error n. %d ", errno); + } + while ((nread = read(fdu, &lgh, sizeof(lgh))) > 0) + { + lgh.type += start; + start = 0; + if (write(fdl, &lgh, sizeof(lgh)) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Endtrans : Error n. %d ", errno); + } + if (lgh.type == FNREWRITE) + if (lseek(fdu, (long) lgh.lenrec, 1) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Endtrans : Error n. %d ", errno); + } + getopenf(lgh.filenum, &record); + CRead(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); + if (write(fdl, record, lgh.lenrec) == -1) + { + junk = exclunlock(lname,TRUE); + fatal_box("Endtrans : Error n. %d ", errno); + } + } + if ((nread <= 0) || (close(fdu) == -1) || (close(fdl) == -1) || + (unlink(uname) == -1)) + { + junk = exclunlock(lname,TRUE); + fatal_box("Endtrans : Error n. %d ", errno); + } + if (wln != -1) + { + junk = cisclose(&wisfd, &record, &werr); + wln = -1; + } + junk = exclunlock(lname,TRUE); +#endif + } +/* +@(#) AbTrans ISAM +@(ID) +Abortisce una transazione. +@(FD) +*/ + void AbTrans() + { +#ifndef DOS + int fd; + PathSt uname; + loghead lgh; + int nread, werr, junk; + RecType record; + RecType oldrec; + strcpy(uname ,undoname()); + if ((fd = open(uname, O_RDONLY, 0666)) == -1) + fatal_box("Abtrans : Error n. %d ", errno); + while ((nread = read(fd, &lgh, sizeof(lgh))) > 0) + { + getopenf(lgh.filenum, &record); + if (oldrec == NULL) oldrec = malloc(lgh.lenrec); + else oldrec = realloc(oldrec, lgh.lenrec); + if (lgh.type & (FNREWRITE)) + { + if ((nread = read(fd, record, lgh.lenrec)) <= 0) + fatal_box("Abtrans : Error n. %d ", errno); + } + if (lgh.lenrec != openf[lgh.filenum - 1]->d->LenR) + fatal_box("Abtrans : Error n. %d ", IsNoMatch); + CRead(&(openf[lgh.filenum - 1]->f), oldrec, lgh.recnum, NoLock); + switch (lgh.type) + { + case FNREWRITE : + junk = replkeys(openf[lgh.filenum - 1], oldrec, record, + openf[lgh.filenum - 1]->i.PN + 1, &werr); + CWrite(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); + break; + case FNDELETE : + IRecallRec(oldrec); + junk = addkeys(openf[lgh.filenum - 1], oldrec, + openf[lgh.filenum - 1]->i.PN + 1, &werr); + CWrite(&(openf[lgh.filenum - 1]->f), oldrec, lgh.recnum, UnLock); + break; + case FNWRITE : + IDeleteRec(oldrec); + junk = delkeys(openf[lgh.filenum - 1], oldrec, + openf[lgh.filenum - 1]->i.PN + 1, &werr); + CWrite(&(openf[lgh.filenum - 1]->f), record, lgh.recnum, UnLock); + break; + } + } + if ((nread == -1) || (close(fd) == -1) || (unlink(uname) == -1)) + fatal_box("Abtrans : Error n. %d ", errno); + if (wln != -1) + { + junk = cisclose(&wisfd, &record, &werr); + wln = -1; + } +#endif + } + diff --git a/include/controls.cpp b/include/controls.cpp index 7c972a9d8..5d1511858 100755 --- a/include/controls.cpp +++ b/include/controls.cpp @@ -505,6 +505,7 @@ TPush_button::TPush_button(short left, short top, short right, short bottom, { switch(id) { + case DLG_OK: if (strcmp("Conferma", caption()) == 0) capt = format("#%d", BMP_OK); @@ -526,21 +527,23 @@ TPush_button::TPush_button(short left, short top, short right, short bottom, if (strcmp("Nuovo", caption()) == 0) // Puo' essere Gestione capt = format("#%d#%d", BMP_NEWREC, BMP_NEWRECDN); break; - case DLG_FIRSTREC: - capt = format("#%d", BMP_FIRSTREC); - break; - case DLG_PREVREC: - capt = format("#%d", BMP_PREVREC); - break; case DLG_STOPREC: capt = format("#%d", BMP_STOPREC); break; - case DLG_NEXTREC: - capt = format("#%d", BMP_NEXTREC); - break; - case DLG_LASTREC: - capt = format("#%d", BMP_LASTREC); - break; + /* + case DLG_FIRSTREC: + capt = format("#%d", BMP_FIRSTREC); + break; + case DLG_PREVREC: + capt = format("#%d", BMP_PREVREC); + break; + case DLG_NEXTREC: + capt = format("#%d", BMP_NEXTREC); + break; + case DLG_LASTREC: + capt = format("#%d", BMP_LASTREC); + break; + */ case DLG_SAVEREC: capt = format("#%d#%d", BMP_SAVEREC, BMP_SAVERECDN); break; diff --git a/include/execp.cpp b/include/execp.cpp index f8462dc64..068db6ffb 100755 --- a/include/execp.cpp +++ b/include/execp.cpp @@ -30,15 +30,12 @@ bool TExternal_app::can_run() const } -int TExternal_app::run(bool async, bool iconized) +int TExternal_app::run(bool async, bool user) { TString256 path(_path); - if (!async) - { - if (iconized) path << " -icon"; + if (user) path << " -u" << main_app().user(); - } _error = 0; _exitcode = 0; @@ -59,34 +56,32 @@ int TExternal_app::run(bool async, bool iconized) CURSOR oldcur = get_cursor(TASK_WIN); set_cursor(TASK_WIN, CURSOR_WAIT); - const UINT sh = iconized ? SW_SHOWMINIMIZED : SW_SHOW; - _exitcode = WinExec((char*)(const char*)path, sh); + _exitcode = WinExec((char*)(const char*)path, SW_SHOW); if (_exitcode >= 32) { if (!async) - { - if (!iconized) - { - TTemp_window tw(TASK_WIN); - tw.iconize(); - } + { + TTemp_window tw(TASK_WIN); + tw.iconize(); HTASK child = NULL; TASKENTRY te; te.dwSize = sizeof(TASKENTRY); for (bool ok = TaskFirst(&te); ok; ok = TaskNext(&te)) if (te.hInst == (HINSTANCE)_exitcode) child = te.hTask; CHECK(child, "Can't find child task"); - while(TaskFindHandle(&te, child)) - process_events(); - if (!iconized) + main_app().wait_for(child); + for (byte i = 0; main_app().waiting(); i++) { - TTemp_window tw(TASK_WIN); - tw.maximize(); - xvt_statbar_refresh(); - } + if (i == 0 && TaskFindHandle(&te, child) == FALSE) + break; + process_events(); + } + + tw.maximize(); } + xvt_statbar_refresh(); _exitcode = 0; } else @@ -96,7 +91,6 @@ int TExternal_app::run(bool async, bool iconized) else error_box("Impossibile eseguire '%s':\nErrore %d", (const char*)_path, _exitcode); } - set_cursor(TASK_WIN, oldcur); } #else diff --git a/include/execp.h b/include/execp.h index a40d66220..1a7fdcf31 100755 --- a/include/execp.h +++ b/include/execp.h @@ -1,34 +1,34 @@ -// execp.h; trattasi di -*-c++-*- -// fv 6/10/93 - -#ifndef __EXECP_H -#define __EXECP_H - -#ifndef __OBJECT_H -#include -#endif - -// Class for external object execution with optional background -// exec under UNIX and swap on EMS under DOS -// Manages restoring the XVT status -// No command line is implemented; user is supposed to use the -// mailbox for this - -class TExternal_app : public TObject -{ - const char* _path; // app name (must be allocated by user) - int _error; // last error (errno code) - int _exitcode; // last exit code - int _count; // count of calls - -public: - bool can_run() const; - int run(bool async = FALSE, bool iconized = FALSE); - int error() { return _error;}; - int exitcode() { return _exitcode;}; - int count() { return _count; }; - - TExternal_app(const char* p); -}; - -#endif +// execp.h; trattasi di -*-c++-*- +// fv 6/10/93 + +#ifndef __EXECP_H +#define __EXECP_H + +#ifndef __OBJECT_H +#include +#endif + +// Class for external object execution with optional background +// exec under UNIX and swap on EMS under DOS +// Manages restoring the XVT status +// No command line is implemented; user is supposed to use the +// mailbox for this + +class TExternal_app : public TObject +{ + const char* _path; // app name (must be allocated by user) + int _error; // last error (errno code) + int _exitcode; // last exit code + int _count; // count of calls + +public: + bool can_run() const; + int run(bool async = FALSE, bool user = TRUE); + int error() { return _error;}; + int exitcode() { return _exitcode;}; + int count() { return _count; }; + + TExternal_app(const char* p); +}; + +#endif diff --git a/include/form.cpp b/include/form.cpp index b936fb7f7..36617f61e 100755 --- a/include/form.cpp +++ b/include/form.cpp @@ -2,13 +2,13 @@ #include #include -#include #include +#include #include #include #include -#include +#include "..\ba\ba2100.h" static TForm* _form = NULL; @@ -71,7 +71,8 @@ void TForm_flags::print_on(ostream& out) const if (!enabled) s << "D"; if (!shown) s << "H"; - if (s.not_empty()) out << " FLAGS \"" << s << '"' << endl; + if (s.not_empty()) + out << " FLAGS \"" << s << '"' << endl; } @@ -143,7 +144,7 @@ public: bool in_group(byte g) const { return g == 0 || _group[g]; } const TString& key() const { return _desc; } - void to_row(TToken_string& row) const; + void print_on(TToken_string& row) const; void show(bool on = TRUE) { _flag.shown = on; } void hide() { show(FALSE); } @@ -375,11 +376,15 @@ bool TForm_item::update() return TRUE; } -void TForm_item::to_row(TToken_string& row) const -{ +void TForm_item::print_on(TToken_string& row) const +{ row = class_name(); row.add(_y); row.add(_x); + + const long fu = _group.first_one(); + if (fu > 0) row.add(fu); + else row.add(" "); row.add(key()); } @@ -788,10 +793,27 @@ bool TForm_list::update() // TPrint_section /////////////////////////////////////////////////////////// -TPrint_section::TPrint_section(TForm* f) -: _height(0), _form(f) +TMask* TPrint_section::_msk = NULL; + +TPrint_section::TPrint_section(TForm* f) : _height(0), _form(f) {} +TPrint_section::~TPrint_section() +{ + if (_msk) + { + delete _msk; + _msk = NULL; + } +} + +const TPrint_section& TPrint_section::copy(const TPrint_section& ps) +{ + _item = ps._item; + _height = ps._height; + return ps; +} + TPrintrow& TPrint_section::row(int num) { TPrintrow* pr = (TPrintrow*)objptr(num); @@ -815,7 +837,7 @@ TForm_item* TPrint_section::parse_item(const TString& s) if (s == "LI") return new TForm_list(this); - CHECKS(NULL, "Elemento di stampa sconosciuto: ", (const char*)s); + CHECKS(NULL, "Campo di stampa sconosciuto: ", (const char*)s); return NULL; } @@ -868,51 +890,63 @@ bool TPrint_section::update() } -bool TPrint_section::edit() -{ - TMask m("bagn003"); +bool TPrint_section::edit(const char* title) +{ + TMask m("ba2100s"); + m.set_caption(title); + + m.set(F_HEIGHT, _height); + + if (m.run() == K_ESC) + return FALSE; - TString80 title("Campi della sezione"); - - TArray_sheet a(-1, -1, 0, 0, title, "Tipo@8|Riga|Col.|Descrizione@80", 0xE); + bool dirty = m.dirty() != 0; + + if (dirty) + _height = m.get_int(F_HEIGHT); + + TArray_sheet a(-1, -1, 0, 0, title, "Tipo@8|Riga|Col.|Gr.|Descrizione@40", 0xE); for (word i = 0; i < fields(); i++) { TToken_string* s = new TToken_string(128); - field(i).to_row(*s); + field(i).print_on(*s); a.add(s); } - bool dirty = FALSE; KEY k; do { k = a.run(); i = (word)a.selected(); + if (k == K_ENTER || k == K_INS && _msk == NULL) + _msk = new TMask("ba2100f"); + switch(k) { case K_ENTER: - m.set_mode(MODE_MOD); - if (field(i).edit(m)) + _msk->set_mode(MODE_MOD); + if (field(i).edit(*_msk)) { + field(i).print_on(a.row(i)); dirty = TRUE; - field(i).to_row(a.row(i)); } break; case K_INS: { - m.set_mode(MODE_INS); + _msk->set_mode(MODE_INS); TForm_string dummy(this); - if (dummy.edit(m)) + if (dummy.edit(*_msk)) { - const TString& c = m.get(F_CLASS).left(2); + const TString& c = _msk->get(F_CLASS).left(2); TForm_item* item = parse_item(c); - item->read_from(m); + item->read_from(*_msk); _item.insert(item, i); - TToken_string s(128); item->to_row(s); + TToken_string s(128); item->print_on(s); a.insert(s, i); + dirty = TRUE; } } break; @@ -921,19 +955,20 @@ bool TPrint_section::edit() { _item.destroy(i, TRUE); a.destroy(i); + dirty = TRUE; } break; default: break; } - } while (k != K_ESC); + } while (k != K_ESC); return dirty; } void TPrint_section::print_on(ostream& out) const { - out << _height << endl; + out << ' ' << _height << endl; for(word i = 0; i < fields(); i++) out << field(i); } @@ -952,23 +987,14 @@ bool TForm::parse_use(TScanner& scanner) else { tab = scanner.pop(); - if (strlen(tab) > 4) - return error_box("'%s' non e' una tabella valida: %d", tab); _relation = new TRelation(tab); } int key = 1; if (scanner.popkey() == "KE") - { key = scanner.integer(); - if (key < 1) - { - error_box("Chiave non valida '%s': uso 1", - (const char*)scanner.token()); - key = 1; - } - } - else scanner.push(); + else + scanner.push(); _cursor = new TCursor(_relation, "", key); return TRUE; @@ -977,7 +1003,7 @@ bool TForm::parse_use(TScanner& scanner) bool TForm::parse_join(TScanner& scanner) { - TString j(scanner.pop()); // File or table + TString16 j(scanner.pop()); // File or table int to = 0; if (scanner.popkey() == "TO") // TO keyword @@ -1020,13 +1046,16 @@ bool TForm::parse_join(TScanner& scanner) } -TPrint_section& TForm::page2pos(const TArray& s, word p) const +TPrint_section& TForm::section(char s, word p) { pagetype pos = odd_page; - if (p == 0 && s.objptr(last_page)) pos = last_page; - if (p == 1 && s.objptr(first_page)) pos = first_page; - if (pos == 0 && (p & 0x1) == 0 && s.objptr(even_page)) pos = even_page; - return (TPrint_section&)s[pos]; + if (p == 0 && exist(s, last_page)) pos = last_page; + if (p == 1 && exist(s, first_page)) pos = first_page; + if (pos == 0 && (p & 0x1) == 0 && exist(s, even_page)) pos = even_page; + + TPrint_section* sec = exist(s, pos); + CHECKD(sec, "Can't find section for page ", p); + return *sec; } word TForm::set_header(word p, bool u) @@ -1034,10 +1063,14 @@ word TForm::set_header(word p, bool u) TPrinter& printer = main_app().printer(); printer.resetheader(); - TPrint_section& head = page2pos(_head, p); + TPrint_section& head = section('H', p); if (u) head.update(); - else head.reset(); + else + { + head.reset(); + printer.headerlen(head.height()); + } for (word j = 0; j < head.height(); j++) printer.setheaderline(j, head.row(j)); @@ -1047,7 +1080,7 @@ word TForm::set_header(word p, bool u) word TForm::set_body(word p, bool u) { - TPrint_section& body = page2pos(_body, p); + TPrint_section& body = section('B', p); if (u) body.update(); else body.reset(); @@ -1067,10 +1100,14 @@ word TForm::set_footer(word p, bool u) TPrinter& printer = main_app().printer(); printer.resetfooter(); - TPrint_section& foot = page2pos(_foot, p); + TPrint_section& foot = section('F', p); if (u) foot.update(); - else foot.reset(); + else + { + foot.reset(); + printer.footerlen(foot.height()); + } for (word j = 0; j < foot.height(); j++) printer.setfooterline(j, foot.row(j)); @@ -1110,13 +1147,13 @@ long TForm::records() const bool TForm::print(long from, long to) { - CHECK(form == NULL, "Can't print two forms"); - _form = this; + _form = this; // setta il form corrente _lastpage = FALSE; TPrinter& printer = main_app().printer(); printer.setheaderhandler(header_handler); printer.setfooterhandler(footer_handler); + printer.formlen(height()); const bool was_open = printer.isopen(); @@ -1141,7 +1178,7 @@ bool TForm::print(long from, long to) if (i > records()) { - if (_head.objptr(last_page) || _body.objptr(last_page) || _foot.objptr(last_page)) + if (exist('H', last_page) || exist('B', last_page) || exist('F', last_page)) { _lastpage = TRUE; set_header(0, TRUE); @@ -1153,17 +1190,22 @@ bool TForm::print(long from, long to) if (!was_open) printer.close(); - _form = NULL; + _form = NULL; // resetta form return ok; } -void TForm::print_section(ostream& out, const TArray& s, const char* name) const +void TForm::print_section(ostream& out, char s) const { - for (pagetype t = odd_page; t <= last_page; t = pagetype(t+1)) if (s.objptr(t)) + for (pagetype t = odd_page; t <= last_page; t = pagetype(t+1)) { - out << "SECTION " << name << ' ' << int(t); - out << s[t]; - out << "END\n" << endl; + const TPrint_section* sec = ((TForm*)this)->exist(s, t); + if (sec) + { + const char* name = s == 'H' ? "HEADER" : (s == 'F' ? "FOOTER" : "BODY"); + out << "SECTION " << name << ' ' << int(t); + out << *sec; + out << "END\n" << endl; + } } } @@ -1172,14 +1214,15 @@ void TForm::print_on(ostream& out) const if (relation()) out << *relation() << endl; - print_section(out, _head, "HEADER"); - print_section(out, _body, "BODY"); - print_section(out, _foot, "FOOTER"); + print_section(out, 'H'); + print_section(out, 'B'); + print_section(out, 'F'); out << "END" << endl; } -TPrint_section& TForm::section(char s, pagetype t) + +TPrint_section* TForm::exist(char s, pagetype t, bool create) { TArray* a = NULL; switch (s) @@ -1193,33 +1236,29 @@ TPrint_section& TForm::section(char s, pagetype t) } TPrint_section* sec = (TPrint_section*)a->objptr(t); - if (sec == NULL) a->add(sec = new TPrint_section(this)); - return (TPrint_section&)*sec; -} - - -bool TForm::edit(char s, pagetype t) -{ - bool dirty = FALSE; - - section(s, t).edit(); - - if (dirty && yesno_box("Salvare le modifiche?")) + if (sec == NULL && create) { - set_cursor(TASK_WIN, CURSOR_WAIT); - TFilename bak(_name); bak.ext("bak"); - rename(_name, bak); - ofstream out(_name); - print_on(out); - set_cursor(TASK_WIN, CURSOR_ARROW); - } + sec = new TPrint_section(this); + a->add(sec, t); + } + + return sec; +} - return dirty; +word TForm::height() +{ + word h = 0; + if (_head.items()) + h += section('H', 1).height(); + if (_body.items()) + h += section('B', 1).height(); + if (_foot.items()) + h += section('F', 1).height(); + return h; } -TForm::TForm(const char* name) -: _name(name), _relation(NULL), _cursor(NULL) +TForm::TForm(const char* name) : _name(name), _relation(NULL), _cursor(NULL) { const CURSOR oldcur = get_cursor(TASK_WIN); set_cursor(TASK_WIN, CURSOR_WAIT); @@ -1234,14 +1273,16 @@ TForm::TForm(const char* name) while (ok && scanner.popkey() == "JO") ok = parse_join(scanner); } - scanner.push(); - while (scanner.popkey() != "" && ok) - { - const char sec = scanner.key()[0]; + while (ok) + { + scanner.popkey(); + const char sec = toupper(scanner.key()[0]); + if (sec <= ' ' || sec == 'E') + break; const pagetype p = (pagetype)scanner.integer(); - TPrint_section& ps = section(sec, p); - ok = ps.parse(scanner); + TPrint_section* ps = exist(sec, p, TRUE); + ok = ps->parse(scanner); } set_cursor(TASK_WIN, oldcur); diff --git a/include/form.h b/include/form.h index 7513f9250..2609e9ad2 100755 --- a/include/form.h +++ b/include/form.h @@ -1,99 +1,114 @@ -#ifndef __FORM_H -#define __FORM_H - -#ifndef __PRINTER_H -#include -#endif - -#ifndef __SCANNER_H -#include -#endif - -#ifndef __RELATION_H -class TRelation; -class TCursor; -#endif - -enum pagetype { odd_page, even_page, first_page, last_page }; - -class TForm; -class TForm_item; - -class TPrint_section : public TArray -{ - word _height; // Altezza della sezione - - TForm* _form; // Form cui appartiene alla sezione - TArray _item; // Lista dei campi da stampare - -protected: - virtual void print_on(ostream& out) const; - TForm_item* parse_item(const TString& key); - TForm_item* parse_item(TScanner& scanner); - -public: - TPrintrow& row(int num); - TForm* form() const { return _form; } - - TForm_item& field(int n) const { return (TForm_item&)_item[n]; } - word fields() const { return _item.items(); } - word height() const { return _height; } - - void reset(); - bool update(); - bool parse(TScanner& scanner); - - bool edit(); - - TPrint_section(TForm* parent); - virtual ~TPrint_section() {} -}; - - -class TForm : public TObject -{ - TFilename _name; // Profile name - - TRelation* _relation; // Can be NULL - TCursor* _cursor; // Can be NULL - - TArray _head; // Headers - TArray _body; // Bodies - TArray _foot; // Footers - - bool _lastpage; - - TPrint_section& page2pos(const TArray& a, word p) const; - - static void header_handler(TPrinter& p); - static void footer_handler(TPrinter& p); - -protected: - TPrint_section& section(char s, pagetype t); // H = Header, B = Body, F = Footer - - void print_section(ostream& out, const TArray& s, const char* name) const; - virtual void print_on(ostream& out) const; - - bool parse_use(TScanner&); - bool parse_join(TScanner&); - - word page(const TPrinter& p) const; - - virtual long records() const; - virtual word set_header(word p, bool u); - virtual word set_body(word p, bool u); - virtual word set_footer(word p, bool u); - -public: - bool print(long from = 0L, long to = -1L); - - TRelation* relation() const { return _relation; } - TCursor* cursor() const { return _cursor; } - - bool edit(char section, pagetype t); - - TForm(const char* form); - ~TForm(); -}; - -#endif +#ifndef __FORM_H +#define __FORM_H + +#ifndef __PRINTER_H +#include +#endif + +#ifndef __SCANNER_H +#include +#endif + +#ifndef __MASK_H +class TMask; +#endif + +#ifndef __RELATION_H +class TRelation; +class TCursor; +#endif + +enum pagetype { odd_page, even_page, first_page, last_page }; + +class TForm; +class TForm_item; + +class TPrint_section : public TArray +{ + static TMask* _msk; + + word _height; // Altezza della sezione + + TForm* _form; // Form cui appartiene alla sezione + TArray _item; // Lista dei campi da stampare + + const TPrint_section& copy(const TPrint_section& ps); + +protected: + virtual void print_on(ostream& out) const; + TForm_item* parse_item(const TString& key); + TForm_item* parse_item(TScanner& scanner); + +public: + TPrintrow& row(int num); + TForm* form() const { return _form; } + + TForm_item& field(int n) const { return (TForm_item&)_item[n]; } + word fields() const { return _item.items(); } + word height() const { return _height; } + + void reset(); + bool update(); + bool parse(TScanner& scanner); + + bool edit(const char* title); + + const TPrint_section& operator=(const TPrint_section& ps) { return copy(ps); } + TPrint_section(TForm* parent); + TPrint_section(const TPrint_section& ps) { copy(ps); } + virtual ~TPrint_section(); +}; + + +class TForm : public TObject +{ + friend class TForm_editor; + + TFilename _name; // Profile name + + TRelation* _relation; // Can be NULL + TCursor* _cursor; // Can be NULL + + TArray _head; // Headers + TArray _body; // Bodies + TArray _foot; // Footers + + bool _lastpage; // I am about to print the last page + + TPrint_section* exist(char s, pagetype t, bool create = FALSE); // Can be NULL + + static void header_handler(TPrinter& p); + static void footer_handler(TPrinter& p); + +protected: + // H = Header, B = Body, F = Footer, R = Relation + TPrint_section& section(char s = 'B', word page = 1); + word height(); // Height of first page + + void print_section(ostream& out, char s) const; + virtual void print_on(ostream& out) const; + bool edit_relation(); + + bool parse_use(TScanner&); + bool parse_join(TScanner&); + + word page(const TPrinter& p) const; + + virtual long records() const; + virtual word set_header(word p, bool u); + virtual word set_body(word p, bool u); + virtual word set_footer(word p, bool u); + +public: + bool print(long from = 0L, long to = -1L); + + const TFilename& name() const { return _name; } + + TRelation* relation() const { return _relation; } + TCursor* cursor() const { return _cursor; } + + TForm(const char* form); + virtual ~TForm(); +}; + +#endif diff --git a/include/isam.cpp b/include/isam.cpp index cd278cbc0..ddfbdd525 100755 --- a/include/isam.cpp +++ b/include/isam.cpp @@ -28,7 +28,7 @@ #endif #define NOT_LINKED(i,f) CHECKS(i != NULL, "Record senza tracciato: impossibile eseguire ", f) -#define NOT_OPEN(f) CHECKS(_isamfile != NULL, "File chiuso, impossibile eseguire ", f) +#define NOT_OPEN(f) CHECKS(_isamfile != NULL, "File chiuso: ", f) HIDDEN void UNKNOWN_FIELD(int num, const char* name) { yesnofatal_box("Il campo '%s' non appartiene al file %d", name, num); } @@ -38,7 +38,6 @@ HIDDEN void UNKNOWN_FIELD(int num, const char* name) HIDDEN bool __autoload = TRUE; void set_autoload_new_files(bool on) - { __autoload = on; } @@ -193,13 +192,23 @@ const char* TBaseisamfile::name() const const char* TBaseisamfile::filename() const { - NOT_OPEN(name()); + if (_isamfile == NULL) + { + TDir d; + d.get(num()); + return strcpy(__tmp_string, d.name()); + } return _isamfile->d->SysName; } const char* TBaseisamfile::description() const { - NOT_OPEN(name()); + if (_isamfile == NULL) + { + TDir d; + d.get(num()); + return strcpy(__tmp_string, d.des()); + } return _isamfile->d->Des; } diff --git a/include/isam.h b/include/isam.h index 4c2bcd9ed..e24fe74ec 100755 --- a/include/isam.h +++ b/include/isam.h @@ -1,497 +1,493 @@ -#ifndef __ISAM_H -#define __ISAM_H - -#ifndef __ARRAY_H -#include -#endif - -#ifndef __SYSFLD_H -#include -#endif - -#ifndef FOXPRO - -#ifndef __REAL_H -#include -#endif - -#endif - -#ifndef __DATE_H -#include -#endif - -#ifndef __STRINGS_H -#include -#endif - -#ifndef __FILES_H -#include -#endif - -#ifndef __LFFILES_H -#include -#endif - - -// @M -#define FIELDERR -1 - -const int MAX_KEYS = 8; -// @END - -// @C -// Classe TRectype : public TObject -// -// Tipo record -// -// @END - -class TRectype : public TSortable -{ - friend class TExtrectype; - friend class TRecfield; - friend class TBaseisamfile; - friend class TLocalisamfile; - friend class TIsamtempfile; - - // DPRIV - char* _rec; // Puntatore a inizio record - int _logicnum; // Numero logico - int _length; // Lunghezza - isdef* _i; // Puntatore al file isam - bool _isempty; // Se il record e' vuoto - char _tab[5]; // identificatore della tabella - TRecfield * _cod; // campo "COD" della tabella - // @END - -protected: - // FPROT - const char* start(int nf) const; - void setempty(bool val) { _isempty = val;} // Rende vero is_empty - virtual TObject* dup() const; // Duplica record - virtual int compare(const TSortable& s) const; - // @END - -public: - // FPUB - int items() const; - void setdirty() { setempty(FALSE); } - void settab(const char *tab); - char* string() const { return _rec;} // Ritorna il puntatore all'inizio. NON dovrebbe essere usata! - - void discard() { *_rec = char(_deleted);} // Setta il flag di cancellazione - void recall() { *_rec = char(_valid);} // Ripristina il flag di cancellazione - bool isdeleted() const { return *_rec == _deleted;} // Chiede se e' cancellato - int len() const { return _length;} // Ritorna la lunghezza - TFieldtypes type(const char* fieldname) const; // Ritorna il tipo del campo - int length(const char* fieldname) const; // Ritorna lunghezza campo - int ndec(const char* fieldname) const; // Ritorna numero di decimali - bool exist(const char* fieldname) const; // Ritorna l'esistenza del campo - const char* fieldname(int i) const; // Ritorna il nome del campo i - - // @DES Get tipizzata. Ritorna il contenuto del campo nei vari tipi - // @FPUB -#ifndef FOXPRO - int get_int(const char* fieldname) const ; - long get_long(const char* fieldname) const ; - word get_word(const char* fieldname) const ; - char get_char(const char* fieldname) const ; - bool get_bool(const char* fieldname) const ; - real get_real(const char* fieldname) const ; -#endif - TDate get_date(const char* fieldname) const ; - - // @DES Get non tipizzata. Il campo e' ritornato come TString& - // @FPUB - const TString& get(const char* fieldname) const ; - - // @DES Put tipizzata - // @FPUB - -#ifndef FOXPRO - void put(const char* fieldname, int val); - void put(const char* fieldname, long val); - void put(const char* fieldname, word val); - void put(const char* fieldname, const TDate& val); - void put(const char* fieldname, char val); - void put(const char* fieldname, bool val); - void put(const char* fieldname, const real& val); -#endif - - // @DES Put NON tipizzata - // @FPUB - void put(const char* fieldname, const char* val); - // void put(const char* fieldname, TString& val); - - void zero(const char * fieldname); // Vuota campo puntato da fieldname - void zero(); // Vuota tutto il record - void zero(char c); // Vuota tutto il record usando il carattere c - - TRectype& operator =(const TRectype& rec); // assegnazione tra TRectype - TRectype& operator =(const char* rec); // assegnazione tra TRectype - TRectype& operator =(const TBaseisamfile& f); - - const isdef* filehnd() const { return _i; } // Ritorna il file isam associato - int num() const { return _logicnum;} // Ritorna il numero logico - bool empty() const {return _isempty;} // Ritorna se e' vuoto - bool valid() const {return _rec[0] == 0;} // Ritorna se il record non e'cancellato - const char* key(int numkey = 1) const; // Ritorna l'espressione della chiave numero numkey - bool ok() const { return _i != NULL;} - - TRectype(int logicnum); // Costruisce un record staccato da un file. Bisogna poi chiamare linkfile(). Sarebbe meglio utilizzare una delle altre due - TRectype(const TBaseisamfile* i); // Costruisce record e lo associa al file isam i - TRectype(const TRectype& r); // Costruisce il record a partire da r - - virtual ~TRectype(); -}; - -// @C -// Classe TBaseisamfile : public TObject -// -// File isam di base -// -// @END - -class TBaseisamfile : public TObject -{ - // @DPRIV - isdef* _isamfile; // Descrittore file isam - int _logicnum; // Numero logico del record corrente - int _lasterr; // Ultimo errore - bool _delrec; // Per sapere se rimuovere il record alla fine - bool _delopenrec; // Per sapere se rimuovere il record alla fine dalla lista interna di record - TRectype* _current; // Puntatore a record corrente - TFile _hf; - TFile _hfhd; - bool _historicfile; // Vero se il file e' archivio storico - TRecnotype _lasthf; - TRecnotype _recno; - - friend class TRectype; - friend class TLocalisamfile; - friend class TIsamfile; - friend class TIsamtempfile; - friend class TRecfield; - // friend class TCursor; - // @END - // @FPRIV - // friend TRecnotype __buildcursor(TFilecursor* tic, TRecnotype rp); - // friend TRecnotype __filtercursor(TFilecursor* tic); - // friend bool __evalcondition(TBaseisamfile* i,TString& condition); - // friend void __readrec(TFilecursor* tic); - - int gethr(TRectype& rec, TDate& atdate); - int addhr(const TRectype& rec, TDate& atdate); - int rewhr(const TRectype& rec, TDate& atdate); - int delhr(const TRectype& rec, TDate& atdate); - -protected: - // @FPROT - isdef** ptrfilehnd() const { return (isdef**) &_isamfile;} - void clearfilehnd() { _isamfile = NULL;} - - void recover(); - int _open(unsigned int mode = _manulock); // Apre isam file con lock - int _close(); - const char* filename() const; - -public: - // @FPUB - void setkey(int nkey); // Attiva una chiave - int getkey() const; // Ritorna la chiave - void setstatus(int status) { _lasterr = status; } // Setta _lasterr - virtual int first(word lockop = _nolock); - virtual int last(word lockop = _nolock); - virtual int next(word lockop = _nolock); - virtual int next(TDate& atdate); - virtual int prev(word lockop = _nolock); - virtual int prev(TDate& atdate); - virtual int reread(word lockop = _nolock, TDate& atdate = (TDate&)botime); - virtual int reread(TRectype& rec, word lockop = _nolock, TDate& atdate = (TDate&)botime); - virtual int skip(TRecnotype nrec, word lockop = _nolock); - virtual int read(word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime); - virtual int read(TRectype& rec, word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime); - virtual int readat(TRecnotype nrec, word lockop = _nolock); - virtual int readat(TRectype& rec, TRecnotype nrec, word lockop = _nolock); - virtual int write(TDate& atdate = (TDate&)botime); - virtual int write(const TRectype& rec, TDate& atdate = (TDate&)botime); - virtual int rewrite(TDate& atdate = (TDate&)botime); - virtual int rewrite(const TRectype& rec, TDate& atdate = (TDate&)botime); - virtual int rewriteat(TRecnotype nrec); - virtual int rewriteat(const TRectype& rec, TRecnotype nrec); - virtual int remove(TDate& atdate = (TDate&)botime); - virtual int remove(const TRectype& rec, TDate& atdate = (TDate&)botime); - virtual const char* name() const; - - TRecnotype recno() const { return _recno;} - int lock(); // Attiva lock di tutto il file - int unlock(); // Disattiva lock di tutto il file - void indexon(); // Accende gli indici - void indexoff(); // Spegne gli indici - int status() const { return _lasterr; } // Ritorna _lasterr - TRectype& curr() const {return *_current;} // Ritorna puntatore a record corrente - bool eof() const { return status() == _iseof || status() == _isemptyfile;} // Vero se siamo a fine file - bool bof() const { return status() == _isbof || status() == _isemptyfile;} // Vero se siamo a inizio file - bool good() const { return status() == NOERR;} // Vero se _lasterr non contiene codici d'errore - bool bad() const { return status() != NOERR;} // Vero se _lasterr contiene codici d'errore - bool empty(); // Vero se il file e' vuoto - int num() const { return _logicnum;} // Ritorna il numero logico del record corrente - const char* description() const; - TRecnotype eod() const { return filehnd()->d->EOD;} - - isdef* filehnd() const { return (isdef*) _isamfile;} // Ritorna l'handle del file isam nella tabella - - long items() const; // n.o di records nel file - - // @DES Get tipizzata. Ritorna il contenuto del campo nei vari tipi - // @FPUB -#ifndef FOXPRO - int get_int(const char* fieldname) const - { return curr().get_int(fieldname);} - long get_long(const char* fieldname) const - { return curr().get_long(fieldname);} - word get_word(const char* fieldname) const - { return curr().get_word(fieldname);} - char get_char(const char* fieldname) const - { return curr().get_char(fieldname);} - bool get_bool(const char* fieldname) const - { return curr().get_bool(fieldname);} - real get_real(const char* fieldname) const - { return curr().get_real(fieldname);} -#endif - TDate get_date(const char* fieldname) const - { return curr().get_date(fieldname);} - - // @DES Get non tipizzata. Il campo e' ritornato come TString& - // @FPUB - const TString& get(const char* fieldname) const - { return curr().get(fieldname);} - - // @DES Put NON tipizzata - // @FPUB -#ifndef FOXPRO - void put(const char* fieldname, int val) - { curr().put(fieldname, val);} - void put(const char* fieldname, long val) - { curr().put(fieldname, val);} - void put(const char* fieldname, word val) - { curr().put(fieldname, val);} - void put(const char* fieldname, const TDate& val) - { curr().put(fieldname, val);} - void put(const char* fieldname, char val) - { curr().put(fieldname, val);} - void put(const char* fieldname, bool val) - { curr().put(fieldname, val);} - void put(const char* fieldname, const real& val) - { curr().put(fieldname, val);} -#endif - - // @DES Put NON tipizzata - // @FPUB - void put(const char* fieldname, const char* val) - { curr().put(fieldname, val);} - - void zero(const char * fieldname) { curr().zero(fieldname);} - void zero() { curr().zero();} - void zero(char c) { curr().zero(c);} - TRectype& operator =(const TRectype& rec) { return curr() = rec;} - - TBaseisamfile(int logicnum, bool linkrecinst = TRUE); - virtual ~TBaseisamfile(); -}; - -// @C -// Classe TIsamfile : public TBaseisamfile -// -// File isam -// -// @END - -class TIsamfile : public TBaseisamfile -{ -public: - // @FPUB - int flags(bool updateeod = FALSE); - int open(unsigned int mode = _manulock) { return _open(mode);} // Apre isam file con lock - int close() { return _close();} - TIsamfile(int logicnum, bool linkrecinst = TRUE); - virtual ~TIsamfile(); -}; - -// @C -// Classe TIsamtempfile : public TBaseisamfile -// -// File isam temporaneo -// -// @END - -class TIsamtempfile : public TBaseisamfile -{ -public: - // @FPUB - int open(char* radix, bool create = TRUE, TRecnotype eod = 0, - TRecnotype eox = 100); // Apre il file. radix e' la radice del path del file, se create e' falso vuol dire che il file esiste gia', e allora eod dice quanti record ci sono; eox quanti bisogna aggiungerne - - int close(bool flagdel = TRUE); // Chiude il file e se e' vero flagdel lo cancella - - TIsamtempfile(int logicnum, bool linkrecinst = FALSE); - virtual ~TIsamtempfile(); -}; - -// @C -// Classe TSystemisamfile : public TBaseisamfile -// -// @END - -class TSystemisamfile : public TIsamfile -{ - TArray _flds; - TArray _exps; - - bool getlcf(long flev); - bool exec_convapp(long flev, const bool before); - void makelc(TRectype& rec); - -public: - // @FPUB - int build(TRecnotype eox); // Costruisce un file isam - int extend(TRecnotype eox); // Estende un file preesistente - long size(TRecnotype eox); // Calcola lo spazio che il file occuperebbe se venisse esteso a eox - int update(TTrec& newrec, bool vis = TRUE); - - int packfile(bool vis = TRUE); // Rimuove fisicamente i record cancellati - int packindex(bool vis = TRUE); // La stessa cosa sugli indici - - // @DES Importa un file ascii. from e' il nome del file da importare - int load(const char* from, char fs = '|', char fd = '\0', char rs = '\n', bool vis = TRUE, bool extended = FALSE) ; - - // @DES Esporta VERSO un file ascii. - int dump(const char* to, int nkey = 1, char fs = '|', char fd = '\0', char rs = '\n', bool vis = TRUE, bool withdeleted = FALSE); - - TSystemisamfile(int logicnum, bool linkrecinst = TRUE) - : TIsamfile(logicnum, linkrecinst) {} - virtual ~TSystemisamfile() {} -}; - -// @C -// Classe TLocalisamfile : public TBaseisamfile -// -// @END - -class TLocalisamfile : public TBaseisamfile -{ - // @DPRIV - bool _was_open; // Vero se il file e' stato aperto come Localisamfile - bool _isatab; // Vero se il file e' una tabella - -public: - // @FPUB - virtual int operator +=(const TRecnotype npos); // Avanza npos record - virtual int operator -=(const TRecnotype npos); // Sposta indietro di npos - virtual int operator ++(); // record successivo - virtual int operator --(); // record precedente - bool tab() const { return _isatab;} // Ritorna vero se tabella - void settab(bool fl = FALSE) { _isatab = fl;} // Setta il flag _isatab - - int open(unsigned int mode = _manulock); - int close() ; - // Costruttore. linkrecinst dice se il file deve utilizzare un area record separata oppure la stessa. - TLocalisamfile(int logicnum, bool linkrecinst = TRUE); - virtual ~TLocalisamfile(); -}; - -// @C -// Classe TRec_array : public TArray -// -// @END - -class TRec_array : public TArray -{ -public: - // @FPUB - TRec_array(int dimension, TBaseisamfile& i); -}; - -// @C -// Classe TRecfield : public TObject -// -// @END - -class TRecfield : public TObject -{ - // @DPRIV - char _name[12]; // Nome campo - TRectype* _rec; // Puntatore a inizio record - char* _p; // Puntatore a inizio campo - byte _len; // Lunghezza campo - byte _dec; // Numero di decimali - byte _type; // Tipo del campo - // @END - - // @FPRIV - void set(int from, int to); - -public: - // @FPUB - // @DES Operatore di assegnazione (=) per i vari tipi - // @FPUB - - int operator =(int i) ; - long operator =(long l) ; - const TDate& operator =(const TDate& d) ; - const char* operator =(const char* s) ; -#ifndef FOXPRO - const real& operator =(const real& r) ; -#endif // FOXPRO - - // @DES Operatore di estrazione per i vari tipi - // @FPUB - operator int() const ; - operator long() const ; - operator const char*() const ; - operator TDate() const ; -#ifndef FOXPRO - operator const real() const ; -#endif // FOXPRO - - - void setptr(TRecnotype r); // Scrive un campo packed. Sarebbe meglio non usare mai campi packed. - TRecnotype ptr() const; // Legge un campo packed. Sarebbe meglio non usare mai campi packed. - - const char* pos() const { return (const char*) _p;} // Ritorna un puntatore all'inizio del campo nel record. Dovrebbe essere protected! - int len() const { return (int) _len;} // Ritorna la lunghezza - int dec() const { return (int) _dec;} // Ritorna il numero di decimali - TFieldtypes type() const { return (TFieldtypes) _type;} // Ritorna il tipo del campo - TRectype& record() const { return *_rec;} // Ritorna puntatore a inizio record - - TRecfield(TRectype& rec, const char* name, int from = 0, int to = -1); -}; - -// @C -// Classe TTransaction -// -// @END - -class TTransaction -{ -public: - // @FPUB - void begin(); - void end(bool success = TRUE); - void abort() { end(FALSE);} -}; - -#ifdef __ISAM_CPP -#define extern -#endif - -// @DPUB -extern TTransaction transaction; -extern TRectype** openrec; -// @END -#undef extern - -void set_autoload_new_files(bool on); - -#endif // __ISAM_ +#ifndef __ISAM_H +#define __ISAM_H + +#ifndef __SYSFLD_H +#include +#endif + +#ifndef FOXPRO + +#ifndef __REAL_H +#include +#endif + +#endif + +#ifndef __DATE_H +#include +#endif + +#ifndef __STRINGS_H +#include +#endif + +#ifndef __FILES_H +#include +#endif + +#ifndef __LFFILES_H +#include +#endif + + +// @M +#define FIELDERR -1 + +const int MAX_KEYS = 8; +// @END + +// @C +// Classe TRectype : public TObject +// +// Tipo record +// +// @END + +class TRectype : public TSortable +{ + friend class TExtrectype; + friend class TRecfield; + friend class TBaseisamfile; + friend class TLocalisamfile; + friend class TIsamtempfile; + + // DPRIV + char* _rec; // Puntatore a inizio record + int _logicnum; // Numero logico + int _length; // Lunghezza + isdef* _i; // Puntatore al file isam + bool _isempty; // Se il record e' vuoto + char _tab[5]; // identificatore della tabella + TRecfield * _cod; // campo "COD" della tabella + // @END + +protected: + // FPROT + const char* start(int nf) const; + void setempty(bool val) { _isempty = val;} // Rende vero is_empty + virtual TObject* dup() const; // Duplica record + virtual int compare(const TSortable& s) const; + // @END + +public: + // FPUB + int items() const; + void setdirty() { setempty(FALSE); } + void settab(const char *tab); + char* string() const { return _rec;} // Ritorna il puntatore all'inizio. NON dovrebbe essere usata! + + void discard() { *_rec = char(_deleted);} // Setta il flag di cancellazione + void recall() { *_rec = char(_valid);} // Ripristina il flag di cancellazione + bool isdeleted() const { return *_rec == _deleted;} // Chiede se e' cancellato + int len() const { return _length;} // Ritorna la lunghezza + TFieldtypes type(const char* fieldname) const; // Ritorna il tipo del campo + int length(const char* fieldname) const; // Ritorna lunghezza campo + int ndec(const char* fieldname) const; // Ritorna numero di decimali + bool exist(const char* fieldname) const; // Ritorna l'esistenza del campo + const char* fieldname(int i) const; // Ritorna il nome del campo i + + // @DES Get tipizzata. Ritorna il contenuto del campo nei vari tipi + // @FPUB +#ifndef FOXPRO + int get_int(const char* fieldname) const ; + long get_long(const char* fieldname) const ; + word get_word(const char* fieldname) const ; + char get_char(const char* fieldname) const ; + bool get_bool(const char* fieldname) const ; + real get_real(const char* fieldname) const ; +#endif + TDate get_date(const char* fieldname) const ; + + // @DES Get non tipizzata. Il campo e' ritornato come TString& + // @FPUB + const TString& get(const char* fieldname) const ; + + // @DES Put tipizzata + // @FPUB + +#ifndef FOXPRO + void put(const char* fieldname, int val); + void put(const char* fieldname, long val); + void put(const char* fieldname, word val); + void put(const char* fieldname, const TDate& val); + void put(const char* fieldname, char val); + void put(const char* fieldname, bool val); + void put(const char* fieldname, const real& val); +#endif + + // @DES Put NON tipizzata + // @FPUB + void put(const char* fieldname, const char* val); + // void put(const char* fieldname, TString& val); + + void zero(const char * fieldname); // Vuota campo puntato da fieldname + void zero(); // Vuota tutto il record + void zero(char c); // Vuota tutto il record usando il carattere c + + TRectype& operator =(const TRectype& rec); // assegnazione tra TRectype + TRectype& operator =(const char* rec); // assegnazione tra TRectype + TRectype& operator =(const TBaseisamfile& f); + + const isdef* filehnd() const { return _i; } // Ritorna il file isam associato + int num() const { return _logicnum;} // Ritorna il numero logico + bool empty() const {return _isempty;} // Ritorna se e' vuoto + bool valid() const {return _rec[0] == 0;} // Ritorna se il record non e'cancellato + const char* key(int numkey = 1) const; // Ritorna l'espressione della chiave numero numkey + bool ok() const { return _i != NULL;} + + TRectype(int logicnum); // Costruisce un record staccato da un file. Bisogna poi chiamare linkfile(). Sarebbe meglio utilizzare una delle altre due + TRectype(const TBaseisamfile* i); // Costruisce record e lo associa al file isam i + TRectype(const TRectype& r); // Costruisce il record a partire da r + + virtual ~TRectype(); +}; + +// @C +// Classe TBaseisamfile : public TObject +// +// File isam di base +// +// @END + +class TBaseisamfile : public TObject +{ + // @DPRIV + isdef* _isamfile; // Descrittore file isam + int _logicnum; // Numero logico del record corrente + int _lasterr; // Ultimo errore + bool _delrec; // Per sapere se rimuovere il record alla fine + bool _delopenrec; // Per sapere se rimuovere il record alla fine dalla lista interna di record + TRectype* _current; // Puntatore a record corrente + TFile _hf; + TFile _hfhd; + bool _historicfile; // Vero se il file e' archivio storico + TRecnotype _lasthf; + TRecnotype _recno; + + friend class TRectype; + friend class TLocalisamfile; + friend class TIsamfile; + friend class TIsamtempfile; + friend class TRecfield; + // friend class TCursor; + // @END + // @FPRIV + // friend TRecnotype __buildcursor(TFilecursor* tic, TRecnotype rp); + // friend TRecnotype __filtercursor(TFilecursor* tic); + // friend bool __evalcondition(TBaseisamfile* i,TString& condition); + // friend void __readrec(TFilecursor* tic); + + int gethr(TRectype& rec, TDate& atdate); + int addhr(const TRectype& rec, TDate& atdate); + int rewhr(const TRectype& rec, TDate& atdate); + int delhr(const TRectype& rec, TDate& atdate); + +protected: + // @FPROT + isdef** ptrfilehnd() const { return (isdef**) &_isamfile;} + void clearfilehnd() { _isamfile = NULL;} + + void recover(); + int _open(unsigned int mode = _manulock); // Apre isam file con lock + int _close(); + const char* filename() const; + +public: + // @FPUB + void setkey(int nkey); // Attiva una chiave + int getkey() const; // Ritorna la chiave + void setstatus(int status) { _lasterr = status; } // Setta _lasterr + virtual int first(word lockop = _nolock); + virtual int last(word lockop = _nolock); + virtual int next(word lockop = _nolock); + virtual int next(TDate& atdate); + virtual int prev(word lockop = _nolock); + virtual int prev(TDate& atdate); + virtual int reread(word lockop = _nolock, TDate& atdate = (TDate&)botime); + virtual int reread(TRectype& rec, word lockop = _nolock, TDate& atdate = (TDate&)botime); + virtual int skip(TRecnotype nrec, word lockop = _nolock); + virtual int read(word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime); + virtual int read(TRectype& rec, word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime); + virtual int readat(TRecnotype nrec, word lockop = _nolock); + virtual int readat(TRectype& rec, TRecnotype nrec, word lockop = _nolock); + virtual int write(TDate& atdate = (TDate&)botime); + virtual int write(const TRectype& rec, TDate& atdate = (TDate&)botime); + virtual int rewrite(TDate& atdate = (TDate&)botime); + virtual int rewrite(const TRectype& rec, TDate& atdate = (TDate&)botime); + virtual int rewriteat(TRecnotype nrec); + virtual int rewriteat(const TRectype& rec, TRecnotype nrec); + virtual int remove(TDate& atdate = (TDate&)botime); + virtual int remove(const TRectype& rec, TDate& atdate = (TDate&)botime); + virtual const char* name() const; + + TRecnotype recno() const { return _recno;} + int lock(); // Attiva lock di tutto il file + int unlock(); // Disattiva lock di tutto il file + void indexon(); // Accende gli indici + void indexoff(); // Spegne gli indici + int status() const { return _lasterr; } // Ritorna _lasterr + TRectype& curr() const {return *_current;} // Ritorna puntatore a record corrente + bool eof() const { return status() == _iseof || status() == _isemptyfile;} // Vero se siamo a fine file + bool bof() const { return status() == _isbof || status() == _isemptyfile;} // Vero se siamo a inizio file + bool good() const { return status() == NOERR;} // Vero se _lasterr non contiene codici d'errore + bool bad() const { return status() != NOERR;} // Vero se _lasterr contiene codici d'errore + bool empty(); // Vero se il file e' vuoto + int num() const { return _logicnum;} // Ritorna il numero logico del record corrente + const char* description() const; + TRecnotype eod() const { return filehnd()->d->EOD;} + + isdef* filehnd() const { return (isdef*) _isamfile;} // Ritorna l'handle del file isam nella tabella + + long items() const; // n.o di records nel file + + // @DES Get tipizzata. Ritorna il contenuto del campo nei vari tipi + // @FPUB +#ifndef FOXPRO + int get_int(const char* fieldname) const + { return curr().get_int(fieldname);} + long get_long(const char* fieldname) const + { return curr().get_long(fieldname);} + word get_word(const char* fieldname) const + { return curr().get_word(fieldname);} + char get_char(const char* fieldname) const + { return curr().get_char(fieldname);} + bool get_bool(const char* fieldname) const + { return curr().get_bool(fieldname);} + real get_real(const char* fieldname) const + { return curr().get_real(fieldname);} +#endif + TDate get_date(const char* fieldname) const + { return curr().get_date(fieldname);} + + // @DES Get non tipizzata. Il campo e' ritornato come TString& + // @FPUB + const TString& get(const char* fieldname) const + { return curr().get(fieldname);} + + // @DES Put NON tipizzata + // @FPUB +#ifndef FOXPRO + void put(const char* fieldname, int val) + { curr().put(fieldname, val);} + void put(const char* fieldname, long val) + { curr().put(fieldname, val);} + void put(const char* fieldname, word val) + { curr().put(fieldname, val);} + void put(const char* fieldname, const TDate& val) + { curr().put(fieldname, val);} + void put(const char* fieldname, char val) + { curr().put(fieldname, val);} + void put(const char* fieldname, bool val) + { curr().put(fieldname, val);} + void put(const char* fieldname, const real& val) + { curr().put(fieldname, val);} +#endif + + // @DES Put NON tipizzata + // @FPUB + void put(const char* fieldname, const char* val) + { curr().put(fieldname, val);} + + void zero(const char * fieldname) { curr().zero(fieldname);} + void zero() { curr().zero();} + void zero(char c) { curr().zero(c);} + TRectype& operator =(const TRectype& rec) { return curr() = rec;} + + TBaseisamfile(int logicnum, bool linkrecinst = TRUE); + virtual ~TBaseisamfile(); +}; + +// @C +// Classe TIsamfile : public TBaseisamfile +// +// File isam +// +// @END + +class TIsamfile : public TBaseisamfile +{ +public: + // @FPUB + int flags(bool updateeod = FALSE); + int open(unsigned int mode = _manulock) { return _open(mode);} // Apre isam file con lock + int close() { return _close();} + TIsamfile(int logicnum, bool linkrecinst = TRUE); + virtual ~TIsamfile(); +}; + +// @C +// Classe TIsamtempfile : public TBaseisamfile +// +// File isam temporaneo +// +// @END + +class TIsamtempfile : public TBaseisamfile +{ +public: + // @FPUB + int open(char* radix, bool create = TRUE, TRecnotype eod = 0, + TRecnotype eox = 100); // Apre il file. radix e' la radice del path del file, se create e' falso vuol dire che il file esiste gia', e allora eod dice quanti record ci sono; eox quanti bisogna aggiungerne + + int close(bool flagdel = TRUE); // Chiude il file e se e' vero flagdel lo cancella + + TIsamtempfile(int logicnum, bool linkrecinst = FALSE); + virtual ~TIsamtempfile(); +}; + +// @C +// Classe TSystemisamfile : public TBaseisamfile +// +// @END + +class TSystemisamfile : public TIsamfile +{ + TArray _flds; + TArray _exps; + + bool getlcf(long flev); + bool exec_convapp(long flev, const bool before); + void makelc(TRectype& rec); + +public: + // @FPUB + int build(TRecnotype eox); // Costruisce un file isam + int extend(TRecnotype eox); // Estende un file preesistente + long size(TRecnotype eox); // Calcola lo spazio che il file occuperebbe se venisse esteso a eox + int update(TTrec& newrec, bool vis = TRUE); + + int packfile(bool vis = TRUE); // Rimuove fisicamente i record cancellati + int packindex(bool vis = TRUE); // La stessa cosa sugli indici + + // @DES Importa un file ascii. from e' il nome del file da importare + int load(const char* from, char fs = '|', char fd = '\0', char rs = '\n', bool vis = TRUE, bool extended = FALSE) ; + + // @DES Esporta VERSO un file ascii. + int dump(const char* to, int nkey = 1, char fs = '|', char fd = '\0', char rs = '\n', bool vis = TRUE, bool withdeleted = FALSE); + + TSystemisamfile(int logicnum, bool linkrecinst = TRUE) + : TIsamfile(logicnum, linkrecinst) {} + virtual ~TSystemisamfile() {} +}; + +// @C +// Classe TLocalisamfile : public TBaseisamfile +// +// @END + +class TLocalisamfile : public TBaseisamfile +{ + // @DPRIV + bool _was_open; // Vero se il file e' stato aperto come Localisamfile + bool _isatab; // Vero se il file e' una tabella + +public: + // @FPUB + virtual int operator +=(const TRecnotype npos); // Avanza npos record + virtual int operator -=(const TRecnotype npos); // Sposta indietro di npos + virtual int operator ++(); // record successivo + virtual int operator --(); // record precedente + bool tab() const { return _isatab;} // Ritorna vero se tabella + void settab(bool fl = FALSE) { _isatab = fl;} // Setta il flag _isatab + + int open(unsigned int mode = _manulock); + int close() ; + // Costruttore. linkrecinst dice se il file deve utilizzare un area record separata oppure la stessa. + TLocalisamfile(int logicnum, bool linkrecinst = TRUE); + virtual ~TLocalisamfile(); +}; + +// @C +// Classe TRec_array : public TArray +// +// @END + +class TRec_array : public TArray +{ +public: + // @FPUB + TRec_array(int dimension, TBaseisamfile& i); +}; + +// @C +// Classe TRecfield : public TObject +// +// @END + +class TRecfield : public TObject +{ + // @DPRIV + char _name[12]; // Nome campo + TRectype* _rec; // Puntatore a inizio record + char* _p; // Puntatore a inizio campo + byte _len; // Lunghezza campo + byte _dec; // Numero di decimali + byte _type; // Tipo del campo + // @END + + // @FPRIV + void set(int from, int to); + +public: + // @FPUB + // @DES Operatore di assegnazione (=) per i vari tipi + // @FPUB + + int operator =(int i) ; + long operator =(long l) ; + const TDate& operator =(const TDate& d) ; + const char* operator =(const char* s) ; +#ifndef FOXPRO + const real& operator =(const real& r) ; +#endif // FOXPRO + + // @DES Operatore di estrazione per i vari tipi + // @FPUB + operator int() const ; + operator long() const ; + operator const char*() const ; + operator TDate() const ; +#ifndef FOXPRO + operator const real() const ; +#endif // FOXPRO + + + void setptr(TRecnotype r); // Scrive un campo packed. Sarebbe meglio non usare mai campi packed. + TRecnotype ptr() const; // Legge un campo packed. Sarebbe meglio non usare mai campi packed. + + const char* pos() const { return (const char*) _p;} // Ritorna un puntatore all'inizio del campo nel record. Dovrebbe essere protected! + int len() const { return (int) _len;} // Ritorna la lunghezza + int dec() const { return (int) _dec;} // Ritorna il numero di decimali + TFieldtypes type() const { return (TFieldtypes) _type;} // Ritorna il tipo del campo + TRectype& record() const { return *_rec;} // Ritorna puntatore a inizio record + + TRecfield(TRectype& rec, const char* name, int from = 0, int to = -1); +}; + +// @C +// Classe TTransaction +// +// @END + +class TTransaction +{ +public: + // @FPUB + void begin(); + void end(bool success = TRUE); + void abort() { end(FALSE);} +}; + +#ifdef __ISAM_CPP +#define extern +#endif + +// @DPUB +extern TTransaction transaction; +extern TRectype** openrec; +// @END +#undef extern + +void set_autoload_new_files(bool on); + +#endif // __ISAM_ diff --git a/include/maskfld.cpp b/include/maskfld.cpp index 8c27d2aca..1291b1e26 100755 --- a/include/maskfld.cpp +++ b/include/maskfld.cpp @@ -1,4 +1,4 @@ -// $Id: maskfld.cpp,v 1.63 1994-12-20 15:11:11 guy Exp $ +// $Id: maskfld.cpp,v 1.64 1994-12-27 14:58:54 guy Exp $ #include #include @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ TMask_field::TField_Flags::TField_Flags() roman = exchange = FALSE; firm = ghost = FALSE; password = FALSE; + trim = TRUE; } // Certified 100% @@ -47,6 +49,9 @@ char TMask_field::TField_Flags::update(const char* s) for (; *s; s++) switch(toupper(*s)) { + case ' ': + case '_': + trim = FALSE; break; case '*': password = TRUE; break; case 'A': @@ -471,7 +476,8 @@ TString& TMask_field::get() const else gpark = get_field_data(); - return gpark.trim(); + if (_flags.trim) gpark.trim(); + return gpark; } @@ -575,7 +581,7 @@ bool TMask_field::do_message(int num) KEY key = 0; msg = m; value = msg.get(); - value.trim(); + // value.trim(); // TBR const char* dlg = msg.get(); int cmd = -1; @@ -748,8 +754,20 @@ bool TMask_field::on_key(KEY key) #if XVT_OS == XVT_OS_WIN if (fexist("prassi.hlp")) { + struct MULTIGUY + { + UINT mkSize; + BYTE mkKeylist; + char mkKeyphrase[16]; + } mk; + + TFilename topic(mask().source_file()); topic.ext(""); + mk.mkSize = sizeof(MULTIGUY); + mk.mkKeylist = 'M'; + strcpy(mk.mkKeyphrase, topic); + HWND hwnd = (HWND)get_value(TASK_WIN, ATTR_NATIVE_WINDOW); - WinHelp(hwnd, "prassi.hlp", HELP_KEY, (DWORD)(const char*)mask().source_file()); + WinHelp(hwnd, "prassi.hlp", HELP_MULTIKEY, (DWORD)&mk); } else #endif if (_help.not_empty()) @@ -1435,29 +1453,8 @@ KEY TBrowse::run() do_input(TRUE); _cursor->read(_isgteq); - TString80 caption; const TLocalisamfile& f = _cursor->file(); - if (f.tab()) - { - TFilename name("batb"); - name << _cursor->file().name() << ".msk"; - if (fexist(name.lower())) - { - TScanner m(name); - while (m.line().left(2) != "PA"); // Find PAGE - const int apicia = m.token().find('"')+1; - const int apicic = m.token().find('"', apicia); - caption = m.token().sub(apicia, apicic); - } - else - { - caption = name.mid(4); - caption.cut(caption.find('.')); - caption.insert("Tabella ", 0); - } - } - else - caption = f.description(); + TString80 caption(prefhndl->description(f.name())); if (!isalnum(caption[0])) caption = "Selezione"; @@ -1900,7 +1897,7 @@ const char* TEdit_field::get_field_data() const const char* TEdit_field::format(const char* d) { fpark = d; - fpark.trim(); + if (_flags.trim) fpark.trim(); if (fpark.not_empty()) { @@ -1944,7 +1941,8 @@ const char* TEdit_field::picture_data(const char* data, bool video) set_window_data(data); TMask_field::get_window_data(); - fpark.trim(); + + if (_flags.trim) fpark.trim(); return fpark; } @@ -2245,6 +2243,12 @@ void TButton_field::parse_head(TScanner& scanner) bool TButton_field::parse_item(TScanner& scanner) { + if (scanner.key() == "PI") + { + const int bmp = scanner.integer(); + _prompt << '#' << bmp; + return bmp > 0; + } return TMask_field::parse_item(scanner); } @@ -2267,6 +2271,8 @@ void TButton_field::create(WINDOW parent) _virtual_key = _exit_key = K_ESC; break; case DLG_DELREC: + if (_prompt.empty()) + _prompt = "Elimina"; _virtual_key = 'E'; _exit_key = K_DEL; break; @@ -2301,8 +2307,9 @@ void TButton_field::create(WINDOW parent) break; } - #if XWTWS == WMWS + const int diesis = _prompt.find('#'); + if (diesis > 0) _prompt.cut(diesis); _prompt.center_just(_width); #endif diff --git a/include/maskfld.h b/include/maskfld.h index af612e489..2798d255b 100755 --- a/include/maskfld.h +++ b/include/maskfld.h @@ -1,569 +1,566 @@ -/* $Id: maskfld.h,v 1.15 1994-12-15 18:06:30 guy Exp $ */ -#ifndef __MASKFLD_H -#define __MASKFLD_H - -#ifndef __ARRAY_H -#include -#endif - -#ifndef __REAL_H -#include -#endif - -#ifndef __SCANNER_H -#include -#endif - -class TMask_field; - -class TRelation; // __RELATION_H -class TCursor; -class TFieldref; -class TArray_sheet; // __SHEET_H - -// @T -typedef bool (*CONTROL_HANDLER)(TMask_field& field, KEY key); -// @END - -enum CheckType { CHECK_NONE, CHECK_NORMAL, CHECK_REQUIRED }; -enum CheckTime { RUNNING_CHECK, STARTING_CHECK, FINAL_CHECK }; - -// @C -// Classe TMask_field : public TObject -// @END - -class TMask_field : public TObject -{ - // @DPRIV - friend class TMask; - - TMask* _mask; // The mask the control belongs to - - TString _help; // Help message - TFieldref* _field; // Corresponding field on the file - TBit_array _keys; // The keys the field belongs to - TBit_array _groups; // The groups the field belongs to - -protected: - // @DPROT - static int _x, _y; // Coordinate of the control - static int _width; // Size of the control - static TFixed_string _prompt;// Prompt of the field - CONTROL_HANDLER _handler; - - int _size; // Max length of the string - - WINDOW _win; // Window of the control (not its parent!) - WINDOW _promptwin; // Prompt of the control - short _dlg; // Identifier of the control - - int _validate_func; // Number of validation function - TArray _validate_parms; // Parameters for validation function - TArray _message; // Messages to send on modify - - struct TField_Flags - { - bool automagic : 1; - bool dirty : 2; // Modified during run ? - bool enabled : 1; // Is editable - bool enable_default : 1; - bool firm : 1; // Is the current firm ? - bool focusdirty : 1; // Modified during focus ? - bool ghost : 1; - bool password : 1; - bool persistent : 1; - bool rightjust : 1; - bool roman : 1; // Is a Roman number ? - bool shown : 1; // Is visible - bool show_default : 1; - bool uppercase : 1; - bool exchange : 1; // Value exchange - bool zerofilled : 1; - - TField_Flags(); - char update(const char*); - } _flags; - - void construct(TScanner& scanner, WINDOW parent); - void construct(short id, const char* prompt, int x, int y, int len, - WINDOW parent, const char* flags = "", int width = 0); - - virtual WINDOW win() const { return _win; } - - WINDOW wincreate(WIN_TYPE ct, short dx, short dy, - const char* title, WINDOW parent, long flags); - int create_prompt(WINDOW parent, int width = 0, int heigth = 1); - - long default_flags() const; - - virtual void parse_head(TScanner& scanner); - virtual bool parse_item(TScanner& scanner); - - virtual void create(WINDOW parent); - virtual void destroy(); - virtual void highlight() const; - - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); - virtual void set_field_data(const char* data); - virtual const char* get_field_data() const; - virtual void exchange(bool show_value, const real& n) {} - - bool do_message(int n); - -public: - // @FPUB - short atodlg(const char* s) const; - - WINDOW parent() const; - short dlg() const { return _dlg; } - - virtual bool ok() const; - - bool dirty() const { return _flags.dirty; } - bool focusdirty() const { return _flags.focusdirty; } - void set_focusdirty(bool d = TRUE) { _flags.focusdirty = d; } - void set_dirty(bool d = TRUE); - - virtual const char* class_name() const; - virtual word class_id() const; - - int size() const { return _size; } - - bool roman() const { return _flags.roman; } - bool automagic() const { return _flags.automagic; } - bool ghost() const { return _flags.ghost; } - bool exchangeable() const { return _flags.exchange; } - - virtual bool has_check() const { return FALSE;} - virtual bool has_query() const { return FALSE;} - virtual bool has_message() const { return _message.items() > 0; } - - virtual CheckType check_type() const { return CHECK_NONE; } - bool required() const { return check_type() == CHECK_REQUIRED; } - virtual bool check(CheckTime = RUNNING_CHECK) { return TRUE;} - - virtual void reset(); - - virtual void enable(bool on = TRUE); - void disable() { enable(FALSE); } - bool enabled() const { return _flags.enabled; } - void enable_default(); - bool enabled_default() const { return _flags.enable_default; } - - virtual void show(bool on = TRUE); - void hide() { show(FALSE); } - bool shown() const { return _flags.shown; } - void show_default(); - - bool active() const; // Is visible and enabled? - - void set_handler(CONTROL_HANDLER handler) { _handler = handler; } - - bool is_edit() const; - bool to_check(KEY k, bool checkrun = FALSE) const; - - virtual bool on_hit(); - virtual bool on_key(KEY key); - - void set(const char* s); - TString& get() const; - - virtual const char* picture_data(const char* data, bool video); - virtual const char * warning() { return "";} - - bool autoload(const TRelation* r = NULL); - bool autosave(TRelation* r = NULL) const; - - void undo(); - - const char* prompt() const; - void set_prompt(const char* p); - - bool in_key(byte key) const { return _keys[key]; } - void set_key(byte key) { _keys.set(long(key)); _keys.set(0L);} - word last_key() const; - - bool in_group(byte group) const { return _groups[group]; } - void set_group(byte group) { _groups.set(long(group)); _groups.set(0L);} - - const TFieldref* field() const { return _field; } - - void set_focus() const; - void send_key(KEY k, short to); - - // set focus, message-box, set focus - bool message_box(const char* fmt, ...) const; - bool warning_box(const char* fmt, ...) const; - bool error_box(const char* fmt, ...) const; - bool yesno_box(const char* fmt, ...) const; - KEY yesnocancel_box(const char* fmt, ...) const; - - TMask& mask() const { return *_mask; } - TMask_field(TMask* mask); - virtual ~TMask_field(); -}; - - -// @C -// Classe TEdit_field : public TMask_field -// -// @END - -class TEdit_field : public TMask_field -{ - friend class TBrowse; - friend class TList_sheet; - friend class TBrowse_sheet; - -protected: - // @DPROT - TString80 _str; - TString16 _picture; - TString _warning; - CheckType _check; // Accettabilita' di valori nulli - bool _forced; - bool _check_enabled; // Abilitato - - TBrowse* _browse; - TList_sheet* _sheet; - WINDOW _buttonwin; - - const TBrowse* get_browse(TScanner& scanner) const; - - virtual word class_id() const; - virtual void parse_head(TScanner& scanner); - virtual bool parse_item(TScanner& scanner); - - virtual void create(WINDOW parent); - virtual void destroy(); - - bool validate(KEY k); - - virtual void set_window_data(const char* data); - virtual void set_field_data(const char* data); - virtual const char* get_field_data() const; - -public: - // @FPUB - virtual bool on_hit(); - virtual bool on_key(KEY key); - virtual bool has_check() const; - virtual bool has_query() const { return _browse || _sheet;} - virtual const char* picture_data(const char* data, bool video); - virtual const char * warning() { return _warning;} - virtual void show(bool on = TRUE); - virtual void enable(bool on = TRUE); - virtual CheckType check_type() const { return _check; } - void check_type(CheckType c) { _check = c; } - - bool forced() const { return _forced;} - virtual bool check(CheckTime = RUNNING_CHECK); - TBrowse* browse() const { return _browse;} - TList_sheet* sheet() const { return _sheet;} - void enable_check(bool on = TRUE) ; - bool check_enabled() const { return _check_enabled;} - - const char* format(const char* data); - const char* picture() const { return _picture; } - - TEdit_field(TMask* mask); - virtual ~TEdit_field(); -}; - - -/////////////////////////////////////////////////////////// -// TBrowse -/////////////////////////////////////////////////////////// - -class TBrowse -{ - TEdit_field* _fld; // The field owning the sheet - TRelation* _relation; // Main relation - TCursor* _cursor; // Cursor on the relation - TString _insert; - TString _filter; - long _rec; - bool _secondary; - bool _checked; - - TToken_string _head, _items; - TToken_string _inp_id, _inp_fn; - TToken_string _out_id, _out_fn; - -protected: - void do_output(CheckTime = RUNNING_CHECK); - void do_clear(); - bool do_insert(); - - TMask_field& field(short n) const; - TToken_string& create_siblings(TToken_string& siblings); - -public: - int inputs(); - int do_input(bool filter = FALSE); // Serve ai TCursor_sheet - - TBrowse(TEdit_field* f, TRelation* r, int key = 1, const char* filter = ""); - TBrowse(TEdit_field* f, TCursor* c); - ~TBrowse(); - - void parse_join(TScanner& scanner); - void parse_input(TScanner& scanner); - void parse_display(TScanner& scanner); - void parse_output(TScanner& scanner); - void parse_insert(TScanner& scanner); - bool parse_copy(const TString& what, const TBrowse& b); - - void set_insert(const char* s) { _insert = s;} - const TString& get_insert() const { return _insert;} - const TString& get_filter() const { return _filter;} - - TEdit_field& field() const { return *_fld; } - - bool check(CheckTime = RUNNING_CHECK); - bool empty_check(); - const TToken_string& head() const { return _head;} - const TToken_string& items() const { return _items;} - TCursor* cursor() const { return _cursor;} - bool checked() const { return _checked;} - bool secondary() const { return _secondary;} - - KEY run(); -}; - -/////////////////////////////////////////////////////////// -// TList_sheet -/////////////////////////////////////////////////////////// - -class TList_sheet -{ - TEdit_field* _fld; // The field owning the sheet - TArray_sheet* _sheet; // sheet with data; - int _row; - - TToken_string _inp_id; - TToken_string _out_id; - -protected: - int do_input(); - void do_output(CheckTime = RUNNING_CHECK); - bool do_insert(); - TMask_field& field(short id) const; - -public: - TList_sheet(TEdit_field* f, const char* caption, const char* head); - ~TList_sheet(); - - void parse_input(TScanner& scanner); - void read_item(TScanner& scanner); - void parse_output(TScanner& scanner); - TArray_sheet* sheet() { return _sheet; } - TEdit_field& field() const { return *_fld; } - - bool check(CheckTime = RUNNING_CHECK); - - KEY run(); -}; - -// @C -// class TReal_field : public TEdit_field -// @END - -class TReal_field : public TEdit_field -{ - int _decimals; - -protected: - // @FPROT - virtual word class_id() const; - - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); - virtual void exchange(bool show_value, const real& n); - - virtual void create(WINDOW parent); - virtual void parse_head(TScanner& scanner); - virtual bool on_key(KEY key); - -public: - // @FPUB - void set_decimals(int d); // Set precision & picture - int decimals() const { return _decimals; } // Get precision - - TReal_field(TMask* mask); -}; - - -// @C -// class TDate_field : public TEdit_field -//@END - -class TDate_field : public TEdit_field -{ -protected: - // @FPROT - virtual word class_id() const; - virtual void create(WINDOW parent); - virtual bool on_key(KEY key); - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); - -public: - // @FPUB - void parse_head(TScanner& scanner); - TDate_field(TMask* mask); -}; - - -// @C -// class TBoolean_field : public TMask_field -// @END - -class TBoolean_field : public TMask_field -{ -protected: - // @DPROT - bool _on; - - virtual word class_id() const; - - virtual void create(WINDOW parent); - virtual const char* get_window_data() const; - virtual void set_window_data(const char* data); - virtual void set_field_data(const char* data = NULL); - virtual const char* get_field_data() const; - virtual bool parse_item(TScanner& scanner); - virtual void enable(bool on); - virtual bool on_hit(); - virtual bool on_key(KEY key); - -public: - // @FPUB - TBoolean_field(TMask* mask); -}; - - -// @C -// class TList_field : public TMask_field -// @END - -class TList_field : public TMask_field -{ - // @FPRIV - void add_list(); - -protected: - // @FPROT - TToken_string _values; - TToken_string _codes; - TString80 _str; - - virtual word class_id() const; - - virtual void set_window_data(const char* data); - virtual const char* get_window_data() const; - virtual void set_field_data(const char* data = NULL); - virtual const char* get_field_data() const; - - virtual void create(WINDOW parent); - - virtual void current(int n); - virtual int current() const; - - int str2curr(const char* data); - virtual bool on_hit(); - virtual bool on_key(KEY key); - virtual void read_item(TScanner& scanner); - - virtual void parse_head(TScanner& scanner); - virtual bool parse_item(TScanner& scanner); - -public: - // @FPUB - TList_field(TMask* mask); - virtual void replace_items(const char* codes, const char* values); - virtual void add_item(const char* code_value); - virtual void delete_item(const char* code); - int items() const; -}; - - -// @C -// class TRadio_field : public TList_field -// @END - -class TRadio_field : public TList_field -{ - enum { MAX_RADIO = 8 }; - - // @FPRIV - int _nitems; - int _active_item; - WINDOW _radio_ctl_win[MAX_RADIO]; - -protected: - // @FPROT - virtual word class_id() const; - virtual void create(WINDOW parent); - virtual void destroy(); - virtual void enable(bool on); - virtual void show(bool on); - - virtual void current(int n); - virtual int current() const; - WINDOW win() const { return _radio_ctl_win[_active_item]; } - -public: - // @FPUB - TRadio_field(TMask* mask); - - void check_radiobutton(WINDOW checked); - bool move_focus(int d); -}; - - - -// @C -// class TButton_field : public TMask_field -// @END - -class TButton_field : public TMask_field -{ - KEY _virtual_key, _exit_key; - -protected: - // @FPROT - virtual word class_id() const; - virtual void create(WINDOW parent); - - void parse_head(TScanner& scanner); - bool parse_item(TScanner& scanner); - virtual void enable(bool); - virtual void show(bool); - virtual bool on_key(KEY key); - -public: - // @FPUB - TButton_field(TMask* mask); - KEY virtual_key() const { return _virtual_key; } - KEY exit_key() const { return _exit_key; } -}; - - -// @C -// class TGroup_field : public TMask_field -// @END - -class TGroup_field : public TMask_field -{ -protected: - // @DPROT - virtual void parse_head(TScanner& scanner); - virtual void create(WINDOW parent); - -public: - // @FPUB - TGroup_field(TMask* mask); -}; - -#endif // __MASKFLD_H +/* $Id: maskfld.h,v 1.16 1994-12-27 14:58:59 guy Exp $ */ +#ifndef __MASKFLD_H +#define __MASKFLD_H + +#ifndef __REAL_H +#include +#endif + +#ifndef __SCANNER_H +#include +#endif + +class TMask_field; + +class TRelation; // __RELATION_H +class TCursor; +class TFieldref; +class TArray_sheet; // __SHEET_H + +// @T +typedef bool (*CONTROL_HANDLER)(TMask_field& field, KEY key); +// @END + +enum CheckType { CHECK_NONE, CHECK_NORMAL, CHECK_REQUIRED }; +enum CheckTime { RUNNING_CHECK, STARTING_CHECK, FINAL_CHECK }; + +// @C +// Classe TMask_field : public TObject +// @END + +class TMask_field : public TObject +{ + // @DPRIV + friend class TMask; + + TMask* _mask; // The mask the control belongs to + + TString _help; // Help message + TFieldref* _field; // Corresponding field on the file + TBit_array _keys; // The keys the field belongs to + TBit_array _groups; // The groups the field belongs to + +protected: + // @DPROT + static int _x, _y; // Coordinate of the control + static int _width; // Size of the control + static TFixed_string _prompt;// Prompt of the field + CONTROL_HANDLER _handler; + + int _size; // Max length of the string + + WINDOW _win; // Window of the control (not its parent!) + WINDOW _promptwin; // Prompt of the control + short _dlg; // Identifier of the control + + int _validate_func; // Number of validation function + TArray _validate_parms; // Parameters for validation function + TArray _message; // Messages to send on modify + + struct TField_Flags + { + bool automagic : 1; + bool dirty : 2; // Modified during run ? + bool enabled : 1; // Is editable + bool enable_default : 1; + bool firm : 1; // Is the current firm ? + bool focusdirty : 1; // Modified during focus ? + bool ghost : 1; + bool password : 1; + bool persistent : 1; + bool rightjust : 1; + bool roman : 1; // Is a Roman number ? + bool shown : 1; // Is visible + bool show_default : 1; + bool trim : 1; // Trim the string + bool uppercase : 1; + bool exchange : 1; // Value exchange + bool zerofilled : 1; + + TField_Flags(); + char update(const char*); + } _flags; + + void construct(TScanner& scanner, WINDOW parent); + void construct(short id, const char* prompt, int x, int y, int len, + WINDOW parent, const char* flags = "", int width = 0); + + virtual WINDOW win() const { return _win; } + + WINDOW wincreate(WIN_TYPE ct, short dx, short dy, + const char* title, WINDOW parent, long flags); + int create_prompt(WINDOW parent, int width = 0, int heigth = 1); + + long default_flags() const; + + virtual void parse_head(TScanner& scanner); + virtual bool parse_item(TScanner& scanner); + + virtual void create(WINDOW parent); + virtual void destroy(); + virtual void highlight() const; + + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); + virtual void set_field_data(const char* data); + virtual const char* get_field_data() const; + virtual void exchange(bool show_value, const real& n) {} + + bool do_message(int n); + +public: + // @FPUB + short atodlg(const char* s) const; + + WINDOW parent() const; + short dlg() const { return _dlg; } + + virtual bool ok() const; + + bool dirty() const { return _flags.dirty; } + bool focusdirty() const { return _flags.focusdirty; } + void set_focusdirty(bool d = TRUE) { _flags.focusdirty = d; } + void set_dirty(bool d = TRUE); + + virtual const char* class_name() const; + virtual word class_id() const; + + int size() const { return _size; } + + bool roman() const { return _flags.roman; } + bool automagic() const { return _flags.automagic; } + bool ghost() const { return _flags.ghost; } + bool exchangeable() const { return _flags.exchange; } + + virtual bool has_check() const { return FALSE;} + virtual bool has_query() const { return FALSE;} + virtual bool has_message() const { return _message.items() > 0; } + + virtual CheckType check_type() const { return CHECK_NONE; } + bool required() const { return check_type() == CHECK_REQUIRED; } + virtual bool check(CheckTime = RUNNING_CHECK) { return TRUE;} + + virtual void reset(); + + virtual void enable(bool on = TRUE); + void disable() { enable(FALSE); } + bool enabled() const { return _flags.enabled; } + void enable_default(); + bool enabled_default() const { return _flags.enable_default; } + + virtual void show(bool on = TRUE); + void hide() { show(FALSE); } + bool shown() const { return _flags.shown; } + void show_default(); + + bool active() const; // Is visible and enabled? + + void set_handler(CONTROL_HANDLER handler) { _handler = handler; } + + bool is_edit() const; + bool to_check(KEY k, bool checkrun = FALSE) const; + + virtual bool on_hit(); + virtual bool on_key(KEY key); + + void set(const char* s); + TString& get() const; + + virtual const char* picture_data(const char* data, bool video); + virtual const char * warning() { return "";} + + bool autoload(const TRelation* r = NULL); + bool autosave(TRelation* r = NULL) const; + + void undo(); + + const char* prompt() const; + void set_prompt(const char* p); + + bool in_key(byte key) const { return _keys[key]; } + void set_key(byte key) { _keys.set(long(key)); _keys.set(0L);} + word last_key() const; + + bool in_group(byte group) const { return _groups[group]; } + void set_group(byte group) { _groups.set(long(group)); _groups.set(0L);} + + const TFieldref* field() const { return _field; } + + void set_focus() const; + void send_key(KEY k, short to); + + // set focus, message-box, set focus + bool message_box(const char* fmt, ...) const; + bool warning_box(const char* fmt, ...) const; + bool error_box(const char* fmt, ...) const; + bool yesno_box(const char* fmt, ...) const; + KEY yesnocancel_box(const char* fmt, ...) const; + + TMask& mask() const { return *_mask; } + TMask_field(TMask* mask); + virtual ~TMask_field(); +}; + + +// @C +// Classe TEdit_field : public TMask_field +// +// @END + +class TEdit_field : public TMask_field +{ + friend class TBrowse; + friend class TList_sheet; + friend class TBrowse_sheet; + +protected: + // @DPROT + TString80 _str; + TString16 _picture; + TString _warning; + CheckType _check; // Accettabilita' di valori nulli + bool _forced; + bool _check_enabled; // Abilitato + + TBrowse* _browse; + TList_sheet* _sheet; + WINDOW _buttonwin; + + const TBrowse* get_browse(TScanner& scanner) const; + + virtual word class_id() const; + virtual void parse_head(TScanner& scanner); + virtual bool parse_item(TScanner& scanner); + + virtual void create(WINDOW parent); + virtual void destroy(); + + bool validate(KEY k); + + virtual void set_window_data(const char* data); + virtual void set_field_data(const char* data); + virtual const char* get_field_data() const; + +public: + // @FPUB + virtual bool on_hit(); + virtual bool on_key(KEY key); + virtual bool has_check() const; + virtual bool has_query() const { return _browse || _sheet;} + virtual const char* picture_data(const char* data, bool video); + virtual const char * warning() { return _warning;} + virtual void show(bool on = TRUE); + virtual void enable(bool on = TRUE); + virtual CheckType check_type() const { return _check; } + void check_type(CheckType c) { _check = c; } + + bool forced() const { return _forced;} + virtual bool check(CheckTime = RUNNING_CHECK); + TBrowse* browse() const { return _browse;} + TList_sheet* sheet() const { return _sheet;} + void enable_check(bool on = TRUE) ; + bool check_enabled() const { return _check_enabled;} + + const char* format(const char* data); + const char* picture() const { return _picture; } + + TEdit_field(TMask* mask); + virtual ~TEdit_field(); +}; + + +/////////////////////////////////////////////////////////// +// TBrowse +/////////////////////////////////////////////////////////// + +class TBrowse +{ + TEdit_field* _fld; // The field owning the sheet + TRelation* _relation; // Main relation + TCursor* _cursor; // Cursor on the relation + TString _insert; + TString _filter; + long _rec; + bool _secondary; + bool _checked; + + TToken_string _head, _items; + TToken_string _inp_id, _inp_fn; + TToken_string _out_id, _out_fn; + +protected: + void do_output(CheckTime = RUNNING_CHECK); + void do_clear(); + bool do_insert(); + + TMask_field& field(short n) const; + TToken_string& create_siblings(TToken_string& siblings); + +public: + int inputs(); + int do_input(bool filter = FALSE); // Serve ai TCursor_sheet + + TBrowse(TEdit_field* f, TRelation* r, int key = 1, const char* filter = ""); + TBrowse(TEdit_field* f, TCursor* c); + ~TBrowse(); + + void parse_join(TScanner& scanner); + void parse_input(TScanner& scanner); + void parse_display(TScanner& scanner); + void parse_output(TScanner& scanner); + void parse_insert(TScanner& scanner); + bool parse_copy(const TString& what, const TBrowse& b); + + void set_insert(const char* s) { _insert = s;} + const TString& get_insert() const { return _insert;} + const TString& get_filter() const { return _filter;} + + TEdit_field& field() const { return *_fld; } + + bool check(CheckTime = RUNNING_CHECK); + bool empty_check(); + const TToken_string& head() const { return _head;} + const TToken_string& items() const { return _items;} + TCursor* cursor() const { return _cursor;} + bool checked() const { return _checked;} + bool secondary() const { return _secondary;} + + KEY run(); +}; + +/////////////////////////////////////////////////////////// +// TList_sheet +/////////////////////////////////////////////////////////// + +class TList_sheet +{ + TEdit_field* _fld; // The field owning the sheet + TArray_sheet* _sheet; // sheet with data; + int _row; + + TToken_string _inp_id; + TToken_string _out_id; + +protected: + int do_input(); + void do_output(CheckTime = RUNNING_CHECK); + bool do_insert(); + TMask_field& field(short id) const; + +public: + TList_sheet(TEdit_field* f, const char* caption, const char* head); + ~TList_sheet(); + + void parse_input(TScanner& scanner); + void read_item(TScanner& scanner); + void parse_output(TScanner& scanner); + TArray_sheet* sheet() { return _sheet; } + TEdit_field& field() const { return *_fld; } + + bool check(CheckTime = RUNNING_CHECK); + + KEY run(); +}; + +// @C +// class TReal_field : public TEdit_field +// @END + +class TReal_field : public TEdit_field +{ + int _decimals; + +protected: + // @FPROT + virtual word class_id() const; + + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); + virtual void exchange(bool show_value, const real& n); + + virtual void create(WINDOW parent); + virtual void parse_head(TScanner& scanner); + virtual bool on_key(KEY key); + +public: + // @FPUB + void set_decimals(int d); // Set precision & picture + int decimals() const { return _decimals; } // Get precision + + TReal_field(TMask* mask); +}; + + +// @C +// class TDate_field : public TEdit_field +//@END + +class TDate_field : public TEdit_field +{ +protected: + // @FPROT + virtual word class_id() const; + virtual void create(WINDOW parent); + virtual bool on_key(KEY key); + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); + +public: + // @FPUB + void parse_head(TScanner& scanner); + TDate_field(TMask* mask); +}; + + +// @C +// class TBoolean_field : public TMask_field +// @END + +class TBoolean_field : public TMask_field +{ +protected: + // @DPROT + bool _on; + + virtual word class_id() const; + + virtual void create(WINDOW parent); + virtual const char* get_window_data() const; + virtual void set_window_data(const char* data); + virtual void set_field_data(const char* data = NULL); + virtual const char* get_field_data() const; + virtual bool parse_item(TScanner& scanner); + virtual void enable(bool on); + virtual bool on_hit(); + virtual bool on_key(KEY key); + +public: + // @FPUB + TBoolean_field(TMask* mask); +}; + + +// @C +// class TList_field : public TMask_field +// @END + +class TList_field : public TMask_field +{ + // @FPRIV + void add_list(); + +protected: + // @FPROT + TToken_string _values; + TToken_string _codes; + TString80 _str; + + virtual word class_id() const; + + virtual void set_window_data(const char* data); + virtual const char* get_window_data() const; + virtual void set_field_data(const char* data = NULL); + virtual const char* get_field_data() const; + + virtual void create(WINDOW parent); + + virtual void current(int n); + virtual int current() const; + + int str2curr(const char* data); + virtual bool on_hit(); + virtual bool on_key(KEY key); + virtual void read_item(TScanner& scanner); + + virtual void parse_head(TScanner& scanner); + virtual bool parse_item(TScanner& scanner); + +public: + // @FPUB + TList_field(TMask* mask); + virtual void replace_items(const char* codes, const char* values); + virtual void add_item(const char* code_value); + virtual void delete_item(const char* code); + int items() const; +}; + + +// @C +// class TRadio_field : public TList_field +// @END + +class TRadio_field : public TList_field +{ + enum { MAX_RADIO = 8 }; + + // @FPRIV + int _nitems; + int _active_item; + WINDOW _radio_ctl_win[MAX_RADIO]; + +protected: + // @FPROT + virtual word class_id() const; + virtual void create(WINDOW parent); + virtual void destroy(); + virtual void enable(bool on); + virtual void show(bool on); + + virtual void current(int n); + virtual int current() const; + WINDOW win() const { return _radio_ctl_win[_active_item]; } + +public: + // @FPUB + TRadio_field(TMask* mask); + + void check_radiobutton(WINDOW checked); + bool move_focus(int d); +}; + + + +// @C +// class TButton_field : public TMask_field +// @END + +class TButton_field : public TMask_field +{ + KEY _virtual_key, _exit_key; + +protected: + // @FPROT + virtual word class_id() const; + virtual void create(WINDOW parent); + + void parse_head(TScanner& scanner); + bool parse_item(TScanner& scanner); + virtual void enable(bool); + virtual void show(bool); + virtual bool on_key(KEY key); + +public: + // @FPUB + TButton_field(TMask* mask); + KEY virtual_key() const { return _virtual_key; } + KEY exit_key() const { return _exit_key; } +}; + + +// @C +// class TGroup_field : public TMask_field +// @END + +class TGroup_field : public TMask_field +{ +protected: + // @DPROT + virtual void parse_head(TScanner& scanner); + virtual void create(WINDOW parent); + +public: + // @FPUB + TGroup_field(TMask* mask); +}; + +#endif // __MASKFLD_H diff --git a/include/msksheet.cpp b/include/msksheet.cpp index f6ac7556e..37363d2a2 100755 --- a/include/msksheet.cpp +++ b/include/msksheet.cpp @@ -20,15 +20,13 @@ extern "C" // TSpreadsheet /////////////////////////////////////////////////////////// -#define K_PLUS '+' - class TSpreadsheet : public TWindow { friend class TSheet_field; enum { ITF_CID = 0, LIST_CID = 1 }; - TArray _str; // Array di TToken_strings + TString_array _str; // Array di TToken_strings TBit_array _column_disabled; TArray _disabled; // Array di TBit_array @@ -70,11 +68,12 @@ protected: public: void update(int row); - TToken_string& row(int n); - TArray& rows_array() const { return (TArray&)_str; } - int add(TToken_string&); + TToken_string& row(int n) { return _str.row(n); } + int add(const TToken_string& s) { return _str.add(s); } + int add(TToken_string* s) { return _str.add(s); } int insert(int rec); bool destroy(int rec = -1); + TString_array& rows_array() { return _str; } void set_focus_cell(int riga, int colonna); void activate(bool on); @@ -381,7 +380,7 @@ int TSpreadsheet::insert(int rec) const bool ok = notify(rec, K_INS); if (!ok) return -1; - TToken_string s; // Empty row + TToken_string s(80); // Empty row const int r = _str.insert(s, rec); _disabled.insert(NULL, rec); @@ -505,7 +504,7 @@ break; else { src = row(rec).get(col); // Set value for cell - if (src && *src && (acqua == CLASS_REAL_FIELD || acqua == CLASS_DATE_FIELD)) + if (src && *src && f->is_edit()) { src = f->picture_data(src, FALSE); // Get formatted string } @@ -525,11 +524,7 @@ break; if (src) { strncpy(dst, src, len); - if (isspace(*dst)) - { - TFixed_string d(dst); - d.ltrim(); - } + // if (isspace(*dst)) { TFixed_string d(dst); d.ltrim(); } TBR } else *dst = '\0'; @@ -830,16 +825,6 @@ void TSpreadsheet::activate(bool on) } } -int TSpreadsheet::add(TToken_string& t) -{ - return _str.add(t); -} - -TToken_string& TSpreadsheet::row(int n) -{ - return (TToken_string&)_str[n]; -} - #else #include @@ -868,8 +853,6 @@ public: TSpreadsheet(short x, short y, short dx, short dy, const char* maskname, int maskno, const char* head, WINDOW parent, TSheet_field * o); - TArray& rows_array() const { return data(); } - TMask& sheet_mask() { return _mask; } TMask& mask() const; @@ -1218,12 +1201,12 @@ bool TSheet_field::parse_item(TScanner& scanner) void TSheet_field::create(WINDOW parent) { const TMask& m = mask(); - _sheet = new TSpreadsheet(_x, _y, _width, _size, m.source_file(), m.sheets(), - _head, parent, this); + _sheet = new TSpreadsheet(_x, _y, _width, _size, m.source_file(), + m.sheets(), _head, parent, this); _win = _sheet->win(); - enable_window(_win, enabled()); show_window(_win, shown()); + if (!enabled()) disable(); } @@ -1252,7 +1235,7 @@ TToken_string& TSheet_field::row(int n) if (n < 0 || n >= max) { if (n < 0) n = first_empty(); - if (n >= max) n = _sheet->add(TToken_string(80)); + if (n >= max) n = _sheet->add(new TToken_string(80)); } return _sheet->row(n); } diff --git a/include/prassi.ver b/include/prassi.ver index 36d69abf5..93f8e45a8 100755 --- a/include/prassi.ver +++ b/include/prassi.ver @@ -1 +1 @@ -#define VERSION 1.1 +#define VERSION 1.2 diff --git a/include/prefix.cpp b/include/prefix.cpp index cfc7cf397..5926f5cfc 100755 --- a/include/prefix.cpp +++ b/include/prefix.cpp @@ -9,8 +9,8 @@ #include #endif -#include #include +#include #include #include @@ -18,7 +18,7 @@ HIDDEN const char* const glockname = "xx"; -TPrefix::TPrefix() +TPrefix::TPrefix() : _filelevel(0), _items(0) { CHECK(prefhndl == NULL, "Can't create two prefix objects"); @@ -177,6 +177,7 @@ void TPrefix::set(const char* name, bool force, TFilelock mode) CGetFile(LF_DIR, &d, _nolock, NORDIR); _filelevel = d.Flags; + _items = (int)d.EOD; openall(FALSE, excl, max, comfiles); } } @@ -247,6 +248,49 @@ bool TPrefix::set_codditta(long codditta, bool force) return FALSE; } + +const char* TPrefix::description(const char* cod) const +{ + TString80 n(cod); + + if (n[0] == '%') + n.ltrim(1); + + const int logicnum = atoi(n); + if (logicnum == 0) + { + TFilename name("batb"); + name << n << ".msk"; + if (fexist(name.lower())) + { + TScanner m(name); + while (m.line().left(2) != "PA"); // Find PAGE + const int apicia = m.token().find('"')+1; + const int apicic = m.token().find('"', apicia); + n = m.token().sub(apicia, apicic); + } + else n.cut(0); + } + else + { + if (logicnum > 0 && logicnum < items()) + { + const TBaseisamfile f(logicnum); + n = f.description(); + } + else n.cut(0); + } + + return strcpy(__tmp_string, n); +} + +const char* TPrefix::description(int cod) const +{ + TString16 n; n << cod; + return description(n); +} + + // Restituisce il nome di una directory dati // Certified 90% const char* firm2dir(long codditta) diff --git a/include/prefix.h b/include/prefix.h index 72615cc67..4b168cf0b 100755 --- a/include/prefix.h +++ b/include/prefix.h @@ -1,65 +1,71 @@ -#ifndef __PREFIX_H -#define __PREFIX_H - -#ifndef __EXTCTYPE_H -#include -#endif - -#ifndef __FILES_H -#include -#endif - -#ifndef __STRINGS_H -#include -#endif - -// @C -// class TPrefix : public TObject -// @END - -class TPrefix : public TObject -{ - // @DPRIV - TString _prefix; - int* _dirfl; - int* _recfl; - long _filelevel; - SecDef* _fdir; - SecDef* _rdir; - - bool test(const char* s) const ; - void put(); - -public: - // @FPUB - void set(const char* name = NULL, bool force = FALSE, TFilelock mode = _manulock); - bool exist(long codditta) const; - bool test(long codditta) const; - long get_codditta() const ; - bool set_codditta(long codditta, bool force = FALSE); - const char* name() const { return _prefix;} - long filelevel() const {return _filelevel;} - - TPrefix(); - virtual ~TPrefix(); -}; - - -const char* firm2dir(long codditta); - -#ifdef __PREFIX_CPP -#define extern -#endif - -// @DPUB -extern TPrefix* prefhndl -// @END -#ifdef __PREFIX_CPP -= NULL ; -#undef extern -#else -; -#endif - -#endif // __PREFIX_H - +#ifndef __PREFIX_H +#define __PREFIX_H + +#ifndef __EXTCTYPE_H +#include +#endif + +#ifndef __FILES_H +#include +#endif + +#ifndef __STRINGS_H +#include +#endif + +// @C +// class TPrefix : public TObject +// @END + +class TPrefix : public TObject +{ + // @DPRIV + TString _prefix; + int* _dirfl; + int* _recfl; + long _filelevel; + int _items; + + SecDef* _fdir; + SecDef* _rdir; + + bool test(const char* s) const ; + void put(); + +public: + // @FPUB + void set(const char* name = NULL, bool force = FALSE, TFilelock mode = _manulock); + bool exist(long codditta) const; + bool test(long codditta) const; + long get_codditta() const ; + bool set_codditta(long codditta, bool force = FALSE); + const char* name() const { return _prefix;} + long filelevel() const {return _filelevel;} + + int items() const { return _items; } + const char* description(const char* cod) const; + const char* description(int cod) const; + + TPrefix(); + virtual ~TPrefix(); +}; + + +const char* firm2dir(long codditta); + +#ifdef __PREFIX_CPP +#define extern +#endif + +// @DPUB +extern TPrefix* prefhndl +// @END +#ifdef __PREFIX_CPP += NULL ; +#undef extern +#else +; +#endif + +#endif // __PREFIX_H + diff --git a/include/relapp.cpp b/include/relapp.cpp index 9c0f4e0be..148335c78 100755 --- a/include/relapp.cpp +++ b/include/relapp.cpp @@ -1,4 +1,4 @@ -// $Id: relapp.cpp,v 1.40 1994-12-16 15:50:08 guy Exp $ +// $Id: relapp.cpp,v 1.41 1994-12-27 14:59:08 guy Exp $ #include #include #include @@ -465,9 +465,11 @@ bool TRelation_application::modify_mode() } -TMask_field* TRelation_application::get_search_field() const +TMask_field* TRelation_application::get_search_field() const { - if (_search_id > 0) return &_mask->field(_search_id); + if (_search_id > 0) + return &_mask->field(_search_id); + const TChiave& k = _maskeys->key(1); for (int i = 0; i < k.items(); i++) { @@ -624,6 +626,7 @@ bool TRelation_application::save(bool check_dirty) if (mode == MODE_INS) { bool changed = TRUE; + while (changed) { get_relation()->zero(); diff --git a/include/relation.cpp b/include/relation.cpp index 325936a7a..3904a22b6 100755 --- a/include/relation.cpp +++ b/include/relation.cpp @@ -1,4 +1,4 @@ -// $Id: relation.cpp,v 1.27 1994-12-20 15:11:20 guy Exp $ +// $Id: relation.cpp,v 1.28 1994-12-27 14:59:10 guy Exp $ // relation.cpp // fv 12/8/93 // relation class for isam files @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -149,6 +150,7 @@ void TRelationdef::print_on(TToken_string& out) const out = ""; print_name(out, f); + out.add(prefhndl->description(f.name())); out << '|'; if (_numto > 0) @@ -161,7 +163,8 @@ void TRelationdef::print_on(TToken_string& out) const const TLocalisamfile& t = _rel->file(_numto); print_name(out, t); } - } + } else out << ' '; + out.add(_key); out.add(_alias); out << '|'; @@ -213,14 +216,16 @@ void TRelation::print_on(TArray& a) const const TLocalisamfile& f = file(); TToken_string s(128); print_name(s, f); + s.add(prefhndl->description(f.name())); + s.add(""); s.add(f.getkey()); - + s.add(" | "); a.destroy(); - a.add(s, 0); + a.add(s); for (int i = 0; i < _reldefs.items(); i++) { ((TRelationdef&)_reldefs[i]).print_on(s); - a.add(s, i+1); + a.add(s); } } diff --git a/include/sheet.cpp b/include/sheet.cpp index 20cb734f9..155ffd6f4 100755 --- a/include/sheet.cpp +++ b/include/sheet.cpp @@ -6,6 +6,10 @@ #include #include +/////////////////////////////////////////////////////////// +// TSheet +/////////////////////////////////////////////////////////// + TSheet::TSheet(short x, short y, short dx, short dy, const char* title, const char* head, byte buttons, long first, WINDOW parent) @@ -146,13 +150,10 @@ void TSheet::set_first(long n) } -void TSheet::set_row(const TToken_string& row, byte i) +void TSheet::set_row(const TToken_string& r, byte i) { if (i > 64) i = 0; else i++; - if (_page.objptr(i) == NULL) - _page.add(row, i); - else - ((TToken_string&)_page[i]) = row; + _page.add(r, i); } @@ -202,7 +203,7 @@ void TSheet::handler(WINDOW win, EVENT* ep) select(nuo); if (ep->type == E_MOUSE_DBL) dispatch_e_char(win, K_ENTER); - else if (_checkable && _check_enabled && vec == nuo) + else if (_checkable && _check_enabled && vec == nuo) { _checked.not(nuo); force_update(); @@ -270,6 +271,8 @@ bool TSheet::on_key(KEY key) { case K_ENTER: if (items() < 1) key = K_ESC; + if (_disabled[selected()]) + break; case K_ESC: stop_run(key); case K_DEL: @@ -317,8 +320,11 @@ bool TSheet::on_key(KEY key) switch(key) { case K_SPACE: - _checked.not(selected()); - force = TRUE; + if (!_disabled[selected()]) + { + _checked.not(selected()); + force = TRUE; + } break; case K_F2: uncheck(-1); @@ -337,6 +343,23 @@ bool TSheet::on_key(KEY key) } +void TSheet::enable(long n, bool on) +{ + if (n >= 0) + _disabled.set(n, !on); + else + { + if (on) + _disabled.reset(); + else + { + _disabled.set(items()); + _disabled.set(); + } + } +} + + void TSheet::select(long n) { if (n < 0) n = 0; else @@ -436,11 +459,15 @@ bool TSheet::update_row(long n) for (int j = 0; (s = t.get()) != NULL; x += _size[j++]+1) { int x1 = x; + bool dis = FALSE; if (n >= 0) { if (_checkable && j == 0) s = _checked[n] ? "X" : " "; + dis = _disabled[n]; + if (dis) set_color(COLOR_CYAN, COLOR_GRAY); + switch (_type[j]) { case 'R': @@ -457,6 +484,7 @@ bool TSheet::update_row(long n) x1 += (_size[j]-strlen(s)) >> 1; // Centra le testate stringat(x1, y, s); + if (dis) set_color(COLOR_BLACK, COLOR_GRAY); } return TRUE; @@ -578,7 +606,7 @@ long TArray_sheet::add(const TToken_string& s) long TArray_sheet::add(TToken_string* s) { - const long n = _data.add(s, -1); + const long n = _data.add(s); set_scroll_max(-1, n); return n; } @@ -721,7 +749,7 @@ void TBrowse_sheet::repos_buttons() const bool TBrowse_sheet::on_key(KEY k) { const WINDOW ctl = get_ctl_window(win(), 100); - const bool alnum = k >= ' ' && k < 256; + const bool alnum = k >= ' ' && k < K_UP; if (ctl != NULL_WIN && (alnum || k == K_BACKSPACE || k == K_DEL)) { diff --git a/include/sheet.h b/include/sheet.h index f22563e34..f5223b936 100755 --- a/include/sheet.h +++ b/include/sheet.h @@ -1,164 +1,166 @@ -#ifndef __SHEET_H -#define __SHEET_H - -#ifndef __ARRAY_H -#include -#endif - -#ifndef __STRINGS_H -#include -#endif - -#ifndef __WINDOW_H -#include -#endif - -#ifndef __RELATION_H -class TCursor; -#endif - -#ifndef __MASKFLD_H -class TEdit_field; -#endif - -// @C -// class TSheet : public TScroll_window -// @END - -class TSheet : public TScroll_window -{ - // @DPRIV - enum { MAX_BUT = 8, MAX_COL = 128 }; - TArray _page; - - byte _columns; - byte _size[MAX_COL], _type[MAX_COL]; - long _curr, _last_update; - - short _visible_rows; - - bool _checkable; - bool _check_enabled; - TBit_array _checked; - - WINDOW _button[MAX_BUT]; - KEY _key[MAX_BUT]; - byte _buttonmask; - -protected: - // @FPROT - bool head_on() const { return _columns > 1; } - bool buttons_on() const { return *_button != NULL_WIN; } - short visible_rows() const { return _visible_rows; } - virtual short reserved_rows() const; - void build_page(long first = -1); - - PNT log2dev(long x, long y) const; - virtual void handler(WINDOW win, EVENT* ep); - virtual bool on_key(KEY); - virtual void update(); - virtual void open(); - - void set_first(long n); - bool is_visible(long n) const { return n >= first() && n < first()+visible_rows(); } - - int width() const; - int row_to_page(long n) const; - int row_to_win(long n) const; - - long first() const { return origin().y; } - bool update_row(long n); - void invert_row(long n); - - void set_row(const TToken_string& row, byte n); - - virtual void repos_buttons() const; - - virtual void page_build(long first, byte num) pure; - - void print(); -public: - // @FPUB - TSheet(short x, short y, short dx, short dy, - const char* title, const char* head, byte buttons = 0, - long first = 0L, WINDOW parent = NULL_WIN); - void add_button(short id, const char* caption, KEY key = K_ESC); - - virtual long items() const pure; - virtual TToken_string& row(long s = -1); - - long selected() const { return _curr; } - void select(long n); - - bool checked(long n) const { return _checked[n]; } - void check(long n, bool on = TRUE); - void uncheck(long n) { check(n, FALSE); } - void enable_check(bool yn = TRUE) { _check_enabled = yn; } - void disable_check() { enable_check(FALSE); } - bool one_checked() const { return _checked.first_one() != -1; } - long checked() const { return _checked.ones(); } -}; - -class TArray_sheet : public TSheet -{ - TArray _data; - -protected: - - virtual void page_build(long first, byte num); - - TArray& data() const { return (TArray&)_data; } - TToken_string& data(long n) const { return (TToken_string&)_data[(int)n]; } - -public: - TArray_sheet(short x, short y, short dx, short dy, const char* caption, - const char* head, byte buttons = 0, WINDOW parent = NULL_WIN); - virtual long items() const { return _data.items(); } - long add(const TToken_string& s); - long add(TToken_string* s); - long insert(const TToken_string& s, long n); - virtual TToken_string& row(long s = -1) { return (s < 0) ? data(selected()) : data(s); } - bool destroy(int i = -1) { uncheck(-1); return _data.destroy(i, TRUE); } -}; - - -class TCursor_sheet : public TSheet -{ - TArray _fields; // Array of TRecfield - long _records; - -protected: - TCursor* _cursor; - - virtual void page_build(long first, byte rows); - -public: - TCursor_sheet(TCursor* cursor, const char* fields, - const char* title, const char* head, byte buttons = 0); - virtual ~TCursor_sheet() {} - virtual long items() const { return _records; } - virtual KEY run(); -}; - - -class TBrowse_sheet : public TCursor_sheet -{ - TEdit_field* const _field; - -protected: - virtual void handler(WINDOW win, EVENT* ep); - virtual short reserved_rows() const; - virtual void repos_buttons() const; - virtual bool on_key(KEY k); - TEdit_field& field() { return *_field; } - -public: - TBrowse_sheet(TCursor* cursor, const char* fields, - const char* title, const char* head, byte buttons, - TEdit_field* f, TToken_string* siblings = NULL); - virtual ~TBrowse_sheet() {} - virtual KEY run(); -}; - - -#endif +#ifndef __SHEET_H +#define __SHEET_H + +#ifndef __STRINGS_H +#include +#endif + +#ifndef __WINDOW_H +#include +#endif + +#ifndef __RELATION_H +class TCursor; +#endif + +#ifndef __MASKFLD_H +class TEdit_field; +#endif + + +// @C +// class TSheet : public TScroll_window +// @END + +class TSheet : public TScroll_window +{ + // @DPRIV + enum { MAX_BUT = 8, MAX_COL = 128 }; + TString_array _page; + + byte _columns; + byte _size[MAX_COL], _type[MAX_COL]; + long _curr, _last_update; + + short _visible_rows; + + bool _checkable; + bool _check_enabled; + TBit_array _checked, _disabled; + + WINDOW _button[MAX_BUT]; + KEY _key[MAX_BUT]; + byte _buttonmask; + +protected: + // @FPROT + bool head_on() const { return _columns > 1; } + bool buttons_on() const { return *_button != NULL_WIN; } + short visible_rows() const { return _visible_rows; } + virtual short reserved_rows() const; + void build_page(long first = -1); + + PNT log2dev(long x, long y) const; + virtual void handler(WINDOW win, EVENT* ep); + virtual bool on_key(KEY); + virtual void update(); + virtual void open(); + + void set_first(long n); + bool is_visible(long n) const { return n >= first() && n < first()+visible_rows(); } + + int width() const; + int row_to_page(long n) const; + int row_to_win(long n) const; + + long first() const { return origin().y; } + bool update_row(long n); + void invert_row(long n); + + void set_row(const TToken_string& row, byte n); + + virtual void repos_buttons() const; + + virtual void page_build(long first, byte num) pure; + + void print(); +public: + // @FPUB + TSheet(short x, short y, short dx, short dy, + const char* title, const char* head, byte buttons = 0, + long first = 0L, WINDOW parent = NULL_WIN); + void add_button(short id, const char* caption, KEY key = K_ESC); + + virtual long items() const pure; + virtual TToken_string& row(long s = -1); + + long selected() const { return _curr; } + void select(long n); + + bool checked(long n) const { return _checked[n]; } + void check(long n, bool on = TRUE); + void uncheck(long n) { check(n, FALSE); } + void enable_check(bool yn = TRUE) { _check_enabled = yn; } + void disable_check() { enable_check(FALSE); } + + void enable(long n = -1, bool on = TRUE); + void disable(long n = -1) { enable(n, FALSE); } + bool enabled(long n) const { return !_disabled[n]; } + bool disabled(long n) const { return _disabled[n]; } + + bool one_checked() const { return _checked.first_one() != -1; } + long checked() const { return _checked.ones(); } +}; + +class TArray_sheet : public TSheet +{ + TString_array _data; + +protected: + + virtual void page_build(long first, byte num); + TToken_string& data(long n) { return _data.row((int)n); } + TString_array& rows_array() { return _data; } + +public: + TArray_sheet(short x, short y, short dx, short dy, const char* caption, + const char* head, byte buttons = 0, WINDOW parent = NULL_WIN); + virtual long items() const { return _data.items(); } + long add(const TToken_string& s); + long add(TToken_string* s); + long insert(const TToken_string& s, long n); + virtual TToken_string& row(long s = -1) { return (s < 0) ? data(selected()) : data(s); } + bool destroy(int i = -1) { uncheck(-1); return _data.destroy(i, TRUE); } +}; + + +class TCursor_sheet : public TSheet +{ + TArray _fields; // Array of TRecfield + long _records; + +protected: + TCursor* _cursor; + + virtual void page_build(long first, byte rows); + +public: + TCursor_sheet(TCursor* cursor, const char* fields, + const char* title, const char* head, byte buttons = 0); + virtual ~TCursor_sheet() {} + virtual long items() const { return _records; } + virtual KEY run(); +}; + + +class TBrowse_sheet : public TCursor_sheet +{ + TEdit_field* const _field; + +protected: + virtual void handler(WINDOW win, EVENT* ep); + virtual short reserved_rows() const; + virtual void repos_buttons() const; + virtual bool on_key(KEY k); + TEdit_field& field() { return *_field; } + +public: + TBrowse_sheet(TCursor* cursor, const char* fields, + const char* title, const char* head, byte buttons, + TEdit_field* f, TToken_string* siblings = NULL); + virtual ~TBrowse_sheet() {} + virtual KEY run(); +}; + + +#endif diff --git a/include/strings.cpp b/include/strings.cpp index f8f776fae..52c0d95f9 100755 --- a/include/strings.cpp +++ b/include/strings.cpp @@ -1012,3 +1012,24 @@ void TParagraph_string::tokenize() } } } + +/////////////////////////////////////////////////////////// +// TString_array +/////////////////////////////////////////////////////////// + +int TString_array::add(const char* s, int n) +{ + if (objptr(n) == NULL) + n = TArray::add(new TToken_string(s), n); + else row(n) = s; + return n; +} + +int TString_array::add(const TToken_string& s, int n) +{ + if (objptr(n) == NULL) + n = TArray::add(s); + else + row(n) = s; + return n; +} \ No newline at end of file diff --git a/include/strings.h b/include/strings.h index 352a5ccdb..45796b9d1 100755 --- a/include/strings.h +++ b/include/strings.h @@ -1,290 +1,306 @@ -#ifndef __STRINGS_H -#define __STRINGS_H - -#ifndef __STRING_H -#include -#endif - -#ifndef __OBJECT_H -#include -#endif - -// @C -// Classe TString : public TObject -// @END - -class TString : public TObject -{ -protected: - // @DPROT - char* _str; // Puntatore alla stringa - int _size; // Lunghezza - // @END - - // @FPROT - int make_room(int size); // Cerca spazio per altri size caratteri - TString& set(const char*); // Inizializza con la stringa puntata da char* di lunghezza size - - TString(char* str, int size) : _str(str), _size(size) {} - -public: - // @FPUB - virtual void resize(int size, bool cpy); // Ri/alloca la stringa - - TString(); - TString(int size); // Default constructor for a string of given size - TString(const char* s); // Costruttore a partire da una stringa s - TString(const TString& s); // Costruttore da un oggetto TString s - virtual ~TString(); // Deallocates the string - - /////////////////////////////////////////////////////////// - // @DES Methods derived from TObject - /////////////////////////////////////////////////////////// - - // @FPUB - virtual const char* class_name() const; // Ritorna il nome della classe - virtual word class_id() const; // Ritorna l'identificatore della classe - virtual bool ok() const { return _str != NULL; } - virtual TObject* dup() const; - virtual void print_on(ostream& out) const; - virtual void read_from(istream& in); - virtual word hash() const; // Return hash value - - /////////////////////////////////////////////////////////// - // @DES Query methods - /////////////////////////////////////////////////////////// - - // @FPUB - operator const char*() const { return (const char*)_str; } // *(TString) -> _str - char& operator[](int i) // TString[i] -> _str[i] - { - CHECKD(i >= 0 && i <= _size, "Bad string subscript: ", i); - return _str[i]; - } - char operator[](int i) const // TString[i] -> _str[i] - { - CHECKD(i >= 0 && i <= _size, "Bad string subscript: ", i); - return _str[i]; - } - - int size() const { return _size; } - int len() const { return strlen(_str); } - bool empty() const { return *_str == '\0'; } - bool not_empty() const { return *_str != '\0'; } - - int find(char, int from = 0) const; // Ritorna la posizione del carattere char nell'oggetto TString - int find(const char* s, int from = 0) const; // Ritorna la posizione della stringa s nell'oggetto TString - - const TString& left(int count) const; // Ritorna l'oggetto TString composto dai count caratteri da sinistra - const TString& mid(int from, int count = -1) const; // Ritorna l'oggetto TString composto dai count caratteri a partire da from - const TString& sub(int from, int to = -1) const; // Ritorna la stringa da FROM a TO (escluso) - const TString& right(int count) const; // Ritorna l'oggetto TString composto dai count caratteri da destra - - /////////////////////////////////////////////////////////// - // @DES Modifying methods - /////////////////////////////////////////////////////////// - - // @FPUB - - TString& fill(char c, int n = -1); // Riempie con n caratteri c - TString& spaces(int n = -1) { return fill(' ', n); } - TString& overwrite(const char* s, int pos = 0); // Sovrascrive la stringa s dalla posizione pos - TString& insert(const char* s, int pos = 0); // Inserisce la stringa s dalla posizione pos - - TString& strip(const char* k); // Elimina tutti i caratteri contenuti in k - TString& strip_spaces(); // Elimina tutti gli spazi non contenuti tra apici singoli o doppi - TString& ltrim(int n = 0); // Elimina gli spazi da sinistra se n=0 altrimenti elimina i primi n caratteri (da sinistra). - TString& rtrim(int n = 0); // Elimina gli spazi da destra se n=0 altrimenti elimina i primi n caratteri (da destra). - TString& trim(); // ltrim e rtrim - - TString& right_just(int n = -1, char c = ' '); // Giustifica a destra - TString& center_just(int n = -1, char c = ' '); // Centra - TString& left_just(int n = -1, char c = ' '); // Giustifica a sinistra - - TString& picture(const char* pic, const char* s); - virtual TString& format(const char* fmt, ...); - - TString& cut(int n); // Inserisce un '\0' alla posizione n-esima. - - TString& upper(); // Mette la stringa in maiuscolo - TString& lower(); // Mette la stringa in minuscolo - - /////////////////////////////////////////////////////////// - // @DES Standard operators - /////////////////////////////////////////////////////////// - - // @FPUB - - const TString& operator =(const TString& s) { return set(s._str); } - const TString& operator =(const char* s) { return set(s); } - - TString& operator <<(const char*); - TString& operator <<(char); - TString& operator <<(int); - TString& operator <<(long); - TString& operator <<(double); - TString& operator <<(const TObject& obj); - TString& operator <<(const TString& str); // For efficiency only - - bool operator ==(const char* s) const { return strcmp(_str, s) == 0; } - bool operator ==(char* s) const { return strcmp(_str, s) == 0; } - bool operator ==(const TString& s) const { return strcmp(_str, s._str) == 0; } - bool operator !=(const char* s) const { return strcmp(_str, s) != 0; } - bool operator !=(char* s) const { return strcmp(_str, s) != 0; } - bool operator !=(const TString& s) const { return strcmp(_str, s._str) != 0; } - bool operator <(const char* s) const { return strcmp(_str, s) < 0; } - bool operator >(const char* s) const { return strcmp(_str, s) > 0; } - bool operator >=(const char* s) const { return strcmp(_str, s) >= 0; } - bool operator <=(const char* s) const { return strcmp(_str, s) <= 0; } - bool match(const char* s) const; - bool compare(const char* s, int max = -1, bool ignorecase = FALSE) const; -}; - -// @C -// Classe TFixed_string : public TString -// @END - -class TFixed_string : public TString -{ -protected: - virtual void resize(int size, bool cpy); // Causa un errore fatale! - -public: - TFixed_string(const char* str, int size = -1); - virtual ~TFixed_string(); - - virtual TString& format(const char* fmt, ...); - - const TString& operator =(const TString& s) { return set((const char*)s); } - const TString& operator=(const char* str) { return set(str); } - void strncpy(const char* s, int n); -}; - -class TString16 : public TFixed_string -{ - char _str16[17]; - -public: - TString16(const char* s = "") : TFixed_string(_str16, 17) { set(s); } - TString16(const TString& s) : TFixed_string(_str16, 17) { set(s); } - const TString& operator =(const TString& s) { return set((const char*)s); } - const TString& operator =(const char* s) { return set(s); } -}; - -class TString80 : public TFixed_string -{ - char _str80[81]; - -public: - TString80(const char* s = "") : TFixed_string(_str80, 81) { set(s); } - TString80(const TString& s) : TFixed_string(_str80, 81) { set(s); } - const TString& operator =(const char* s) { return set(s); } - const TString& operator =(const TString& s) { return set((const char*)s); } -}; - -class TString256 : public TFixed_string -{ - char _str256[257]; - -public: - TString256(const char* s = "") : TFixed_string(_str256, 257) { set(s); } - TString256(const TString& s) : TFixed_string(_str256, 257) { set(s); } - const TString& operator =(const char* s) { return set(s); } - const TString& operator =(const TString& s) { return set((const char*)s); } -}; - - - -// @C -// Classe TFilename : public TString80 (256 su Windows'95) -// @END - -class TFilename : public TString80 -{ -public: - // @FPUB - - TFilename(const char* n = "") : TString80(n) {} - TFilename(const TString& n) : TString80((const char*)n) {} - TFilename(const TFilename& n) : TString80((const char*)n) {} - - // assegnazione tra TFile e stringa - const TString& operator =(const char* s) { return set(s); } - const TString& operator =(const TString& s) { return set((const char*)s); } - - virtual bool ok() const; // Controlla il formato del nome del file - - const char* ext() const; // Ritorna l'estensione - void ext(const char*); // Imposta come estensione la stringa puntata da char* - - const char* name() const; // Ritorna il nome del file - const char* path() const; // Ritorna il nome del direttorio - const TFilename& temp(const char* prefix = NULL); // Genera il nome di un file temporaneo - const TFilename& tempdir(); // Genera il nome della directory temporanea -}; - -// @C -// Classe TToken_string : public TString -// @END - -class TToken_string : public TString -{ - // @DPRIV - char _separator; // Carattere separatore - int _last; // Puntatore all'ultimo - -protected: - // @FPROT - - virtual TObject* dup() const; // Crea un duplicato della token string - bool set_item(const char* v, int n); - -public: - // @FPUB - TToken_string(const char* = "", char separator = '|'); - TToken_string(int n, char separator = '|'); - TToken_string(const TToken_string& s); - - void separator(char s) { _separator = s; } // Setta il separatore a s - - void restart() { _last = empty() ? -1 : 0; } // Rimette all'inizio il puntatore - const TString& operator =(const char* s) { set(s);restart();return *this; } - const TString& operator =(const TString& s) { set(s);restart();return *this; } - - void add(const char* s, int n = -1); // Aggiunge una stringa - void add(char c, int pos = -1); // Aggiunge un char - void add(long n, int pos = -1); // Aggiunge un intero - void add(int n, int pos = -1); // Aggiunge un intero - void destroy(int pos); // Toglie la stringa pos - const char* get(); // Ritorna il prossimo token - const char* get(int n); // Ritorna un token (-1 = prossimo; -2 = ultimo; n = ennesimo) - char get_char(int n = -1); // Ritorna un carattere - int get_int(int n = -1); // Ritorna un intero - long get_long(int n = -1); // Ritorna un intero esteso - int get_pos(const char* s); // Ritorna la posizione dell'item s - int items() const; // Ritorna il numero di token presenti - bool empty_items() const; // Controlla se tutti i token sono nulli -}; - -/////////////////////////////////////////////////////////// -// @DES Paragraph -/////////////////////////////////////////////////////////// - -class TParagraph_string : public TToken_string -{ - int _width; - bool _fixed; - -protected: - void tokenize(); - -public: - TParagraph_string(const char* s, int width); - const TString& operator =(const char* s); - void set_width(int width) { _width = width; } -}; - -#endif - - - +#ifndef __STRINGS_H +#define __STRINGS_H + +#ifndef __STRING_H +#include +#endif + +#ifndef __ARRAY_H +#include +#endif + +// @C +// Classe TString : public TObject +// @END + +class TString : public TObject +{ +protected: + // @DPROT + char* _str; // Puntatore alla stringa + int _size; // Lunghezza + // @END + + // @FPROT + int make_room(int size); // Cerca spazio per altri size caratteri + TString& set(const char*); // Inizializza con la stringa puntata da char* di lunghezza size + + TString(char* str, int size) : _str(str), _size(size) {} + +public: + // @FPUB + virtual void resize(int size, bool cpy); // Ri/alloca la stringa + + TString(); + TString(int size); // Default constructor for a string of given size + TString(const char* s); // Costruttore a partire da una stringa s + TString(const TString& s); // Costruttore da un oggetto TString s + virtual ~TString(); // Deallocates the string + + /////////////////////////////////////////////////////////// + // @DES Methods derived from TObject + /////////////////////////////////////////////////////////// + + // @FPUB + virtual const char* class_name() const; // Ritorna il nome della classe + virtual word class_id() const; // Ritorna l'identificatore della classe + virtual bool ok() const { return _str != NULL; } + virtual TObject* dup() const; + virtual void print_on(ostream& out) const; + virtual void read_from(istream& in); + virtual word hash() const; // Return hash value + + /////////////////////////////////////////////////////////// + // @DES Query methods + /////////////////////////////////////////////////////////// + + // @FPUB + operator const char*() const { return (const char*)_str; } // *(TString) -> _str + char& operator[](int i) // TString[i] -> _str[i] + { + CHECKD(i >= 0 && i <= _size, "Bad string subscript: ", i); + return _str[i]; + } + char operator[](int i) const // TString[i] -> _str[i] + { + CHECKD(i >= 0 && i <= _size, "Bad string subscript: ", i); + return _str[i]; + } + + int size() const { return _size; } + int len() const { return strlen(_str); } + bool empty() const { return *_str == '\0'; } + bool not_empty() const { return *_str != '\0'; } + + int find(char, int from = 0) const; // Ritorna la posizione del carattere char nell'oggetto TString + int find(const char* s, int from = 0) const; // Ritorna la posizione della stringa s nell'oggetto TString + + const TString& left(int count) const; // Ritorna l'oggetto TString composto dai count caratteri da sinistra + const TString& mid(int from, int count = -1) const; // Ritorna l'oggetto TString composto dai count caratteri a partire da from + const TString& sub(int from, int to = -1) const; // Ritorna la stringa da FROM a TO (escluso) + const TString& right(int count) const; // Ritorna l'oggetto TString composto dai count caratteri da destra + + /////////////////////////////////////////////////////////// + // @DES Modifying methods + /////////////////////////////////////////////////////////// + + // @FPUB + + TString& fill(char c, int n = -1); // Riempie con n caratteri c + TString& spaces(int n = -1) { return fill(' ', n); } + TString& overwrite(const char* s, int pos = 0); // Sovrascrive la stringa s dalla posizione pos + TString& insert(const char* s, int pos = 0); // Inserisce la stringa s dalla posizione pos + + TString& strip(const char* k); // Elimina tutti i caratteri contenuti in k + TString& strip_spaces(); // Elimina tutti gli spazi non contenuti tra apici singoli o doppi + TString& ltrim(int n = 0); // Elimina gli spazi da sinistra se n=0 altrimenti elimina i primi n caratteri (da sinistra). + TString& rtrim(int n = 0); // Elimina gli spazi da destra se n=0 altrimenti elimina i primi n caratteri (da destra). + TString& trim(); // ltrim e rtrim + + TString& right_just(int n = -1, char c = ' '); // Giustifica a destra + TString& center_just(int n = -1, char c = ' '); // Centra + TString& left_just(int n = -1, char c = ' '); // Giustifica a sinistra + + TString& picture(const char* pic, const char* s); + virtual TString& format(const char* fmt, ...); + + TString& cut(int n); // Inserisce un '\0' alla posizione n-esima. + + TString& upper(); // Mette la stringa in maiuscolo + TString& lower(); // Mette la stringa in minuscolo + + /////////////////////////////////////////////////////////// + // @DES Standard operators + /////////////////////////////////////////////////////////// + + // @FPUB + + const TString& operator =(const TString& s) { return set(s._str); } + const TString& operator =(const char* s) { return set(s); } + + TString& operator <<(const char*); + TString& operator <<(char); + TString& operator <<(int); + TString& operator <<(long); + TString& operator <<(double); + TString& operator <<(const TObject& obj); + TString& operator <<(const TString& str); // For efficiency only + + bool operator ==(const char* s) const { return strcmp(_str, s) == 0; } + bool operator ==(char* s) const { return strcmp(_str, s) == 0; } + bool operator ==(const TString& s) const { return strcmp(_str, s._str) == 0; } + bool operator !=(const char* s) const { return strcmp(_str, s) != 0; } + bool operator !=(char* s) const { return strcmp(_str, s) != 0; } + bool operator !=(const TString& s) const { return strcmp(_str, s._str) != 0; } + bool operator <(const char* s) const { return strcmp(_str, s) < 0; } + bool operator >(const char* s) const { return strcmp(_str, s) > 0; } + bool operator >=(const char* s) const { return strcmp(_str, s) >= 0; } + bool operator <=(const char* s) const { return strcmp(_str, s) <= 0; } + bool match(const char* s) const; + bool compare(const char* s, int max = -1, bool ignorecase = FALSE) const; +}; + +// @C +// Classe TFixed_string : public TString +// @END + +class TFixed_string : public TString +{ +protected: + virtual void resize(int size, bool cpy); // Causa un errore fatale! + +public: + TFixed_string(const char* str, int size = -1); + virtual ~TFixed_string(); + + virtual TString& format(const char* fmt, ...); + + const TString& operator =(const TString& s) { return set((const char*)s); } + const TString& operator=(const char* str) { return set(str); } + void strncpy(const char* s, int n); +}; + +class TString16 : public TFixed_string +{ + char _str16[17]; + +public: + TString16(const char* s = "") : TFixed_string(_str16, 17) { set(s); } + TString16(const TString& s) : TFixed_string(_str16, 17) { set(s); } + const TString& operator =(const TString& s) { return set((const char*)s); } + const TString& operator =(const char* s) { return set(s); } +}; + +class TString80 : public TFixed_string +{ + char _str80[81]; + +public: + TString80(const char* s = "") : TFixed_string(_str80, 81) { set(s); } + TString80(const TString& s) : TFixed_string(_str80, 81) { set(s); } + const TString& operator =(const char* s) { return set(s); } + const TString& operator =(const TString& s) { return set((const char*)s); } +}; + +class TString256 : public TFixed_string +{ + char _str256[257]; + +public: + TString256(const char* s = "") : TFixed_string(_str256, 257) { set(s); } + TString256(const TString& s) : TFixed_string(_str256, 257) { set(s); } + const TString& operator =(const char* s) { return set(s); } + const TString& operator =(const TString& s) { return set((const char*)s); } +}; + + + +// @C +// Classe TFilename : public TString80 (256 su Windows'95) +// @END + +class TFilename : public TString80 +{ +public: + // @FPUB + + TFilename(const char* n = "") : TString80(n) {} + TFilename(const TString& n) : TString80((const char*)n) {} + TFilename(const TFilename& n) : TString80((const char*)n) {} + + // assegnazione tra TFile e stringa + const TString& operator =(const char* s) { return set(s); } + const TString& operator =(const TString& s) { return set((const char*)s); } + + virtual bool ok() const; // Controlla il formato del nome del file + + const char* ext() const; // Ritorna l'estensione + void ext(const char*); // Imposta come estensione la stringa puntata da char* + + const char* name() const; // Ritorna il nome del file + const char* path() const; // Ritorna il nome del direttorio + const TFilename& temp(const char* prefix = NULL); // Genera il nome di un file temporaneo + const TFilename& tempdir(); // Genera il nome della directory temporanea +}; + +// @C +// Classe TToken_string : public TString +// @END + +class TToken_string : public TString +{ + // @DPRIV + char _separator; // Carattere separatore + int _last; // Puntatore all'ultimo + +protected: + // @FPROT + + virtual TObject* dup() const; // Crea un duplicato della token string + bool set_item(const char* v, int n); + +public: + // @FPUB + TToken_string(const char* = "", char separator = '|'); + TToken_string(int n, char separator = '|'); + TToken_string(const TToken_string& s); + + void separator(char s) { _separator = s; } // Setta il separatore a s + + void restart() { _last = empty() ? -1 : 0; } // Rimette all'inizio il puntatore + const TString& operator =(const char* s) { set(s);restart();return *this; } + const TString& operator =(const TString& s) { set(s);restart();return *this; } + + void add(const char* s, int n = -1); // Aggiunge una stringa + void add(char c, int pos = -1); // Aggiunge un char + void add(long n, int pos = -1); // Aggiunge un intero + void add(int n, int pos = -1); // Aggiunge un intero + void destroy(int pos); // Toglie la stringa pos + const char* get(); // Ritorna il prossimo token + const char* get(int n); // Ritorna un token (-1 = prossimo; -2 = ultimo; n = ennesimo) + char get_char(int n = -1); // Ritorna un carattere + int get_int(int n = -1); // Ritorna un intero + long get_long(int n = -1); // Ritorna un intero esteso + int get_pos(const char* s); // Ritorna la posizione dell'item s + int items() const; // Ritorna il numero di token presenti + bool empty_items() const; // Controlla se tutti i token sono nulli +}; + +/////////////////////////////////////////////////////////// +// @DES Paragraph +/////////////////////////////////////////////////////////// + +class TParagraph_string : public TToken_string +{ + int _width; + bool _fixed; + +protected: + void tokenize(); + +public: + TParagraph_string(const char* s, int width); + const TString& operator =(const char* s); + void set_width(int width) { _width = width; } +}; + +/////////////////////////////////////////////////////////// +// @DES TString_array +/////////////////////////////////////////////////////////// + +class TString_array : public TArray +{ +public: + TToken_string& row(int n) { return (TToken_string&)operator[](n); } + int add(TToken_string* s, int n = -1) { return TArray::add(s, n); } + int add(const TToken_string& s, int n = -1); + int add(const char* s, int n = -1); + + TString_array(int size = 8) : TArray(size) {} + virtual ~TString_array() {} +}; + +#endif + + + diff --git a/include/viswin.cpp b/include/viswin.cpp index 3dc7eb3f3..04dea832b 100755 --- a/include/viswin.cpp +++ b/include/viswin.cpp @@ -1832,7 +1832,7 @@ bool TViswin::call_editor () newfilename.insert (" ", 0); newfilename.insert (editor, 0); TExternal_app edit (newfilename); - if (edit.run(TRUE)) + if (edit.run(TRUE, FALSE)) beep (); else ok = TRUE; diff --git a/include/xvtility.cpp b/include/xvtility.cpp index 53b09ba9f..63992c7bc 100755 --- a/include/xvtility.cpp +++ b/include/xvtility.cpp @@ -99,6 +99,8 @@ HIDDEN COLORREF NormalForeColor = COLOR2RGB(NORMAL_COLOR); HIDDEN COLORREF NormalBackColor = COLOR2RGB(NORMAL_BACK_COLOR); HIDDEN HBRUSH NormalBrush = CreateSolidBrush(NormalBackColor); +const word WM_WAKEUP = RegisterWindowMessage("WAKEUP"); + static BOOLEAN event_hook(HWND hwnd, UINT msg, UINT wparam, @@ -200,6 +202,9 @@ static BOOLEAN event_hook(HWND hwnd, } break; default: + if (msg == WM_WAKEUP && wparam == main_app().waiting()) + main_app().wake_up(); + break; break; } @@ -393,9 +398,8 @@ KEY e_char_to_key(const EVENT* ep) KEY key = ep->v.chr.ch; if (key < K_INS || key > K_HELP) { - // if (ep->v.chr.shift && !isprint(key)) key += K_SHIFT; - if (ep->v.chr.shift && (key < ' ' || key > 'z')) key += K_SHIFT; - if (key >= ' ' && ep->v.chr.control) key += K_CTRL; + if (ep->v.chr.shift && (key < ' ' || key >= K_UP)) key += K_SHIFT; + if (ep->v.chr.control && key >= ' ') key += K_CTRL; } return key; } @@ -543,9 +547,9 @@ void xvt_init_font() LogFont.lfWidth = (int)font.get_long("Width"); LogFont.lfWeight = FontWeight = (int)font.get_long("Weight"); LogFont.lfCharSet = (int)font.get_long("CharSet"); - LogFont.lfClipPrecision = (int)font.get_long("Clip"); - LogFont.lfOutPrecision = (int)font.get_long("Precision"); - LogFont.lfQuality = (int)font.get_long("Quality");; + // LogFont.lfClipPrecision = (int)font.get_long("Clip"); + // LogFont.lfOutPrecision = (int)font.get_long("Precision"); + // LogFont.lfQuality = (int)font.get_long("Quality");; LogFont.lfPitchAndFamily = (int)font.get_long("Pitch"); strcpy(LogFont.lfFaceName, font.get("Name")); } @@ -581,8 +585,6 @@ void xvt_set_font(WINDOW win, int family, int style, int dim) #if XVT_OS == XVT_OS_WIN if (dim < 1) { - // LogFont.lfWidth = CHARX - (style & FS_BOLD) ? 2 : 1; - // LogFont.lfHeight = CHARY - ((style & FS_BOLD) ? 4 : 2); LogFont.lfWeight = FontWeight + ((style & FS_BOLD) ? 300 : 0); LogFont.lfItalic = (style & FS_ITALIC) ? TRUE : FALSE; set_value(NULL_WIN, ATTR_WIN_PM_LOGFONT, (long)&LogFont);