execp.* Tolte funzioni sugli url e spostate nei golem
golem.cpp Potenziata la gestione delle icone isam.cpp Modificata la creazione dei file temporanei progind.cpp Cambiati i colori della barra strings.* Potenziata la generazione dei file temporanei git-svn-id: svn://10.65.10.50/trunk@5339 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
		
							parent
							
								
									ab3cf55295
								
							
						
					
					
						commit
						f955b1a48e
					
				@ -5,7 +5,6 @@
 | 
			
		||||
#include <xvt.h>
 | 
			
		||||
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN
 | 
			
		||||
#include <shellapi.h>
 | 
			
		||||
#include <toolhelp.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
@ -362,79 +361,3 @@ TExternal_app::TExternal_app(const char* p)
 | 
			
		||||
  _exitcode =  0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// GotoURL 
 | 
			
		||||
// Liberamente tradotto da Windows Developer Journal August 1997
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
static long get_reg_key(HKEY key, const char* subkey, TString& retdata)
 | 
			
		||||
{                                            
 | 
			
		||||
  HKEY hkey;
 | 
			
		||||
  long retval = RegOpenKey(key, subkey, &hkey);
 | 
			
		||||
  if (retval == ERROR_SUCCESS)
 | 
			
		||||
  {
 | 
			
		||||
    long datasize = retdata.size();
 | 
			
		||||
    RegQueryValue(hkey, NULL, retdata.get_buffer(), &datasize);
 | 
			
		||||
    RegCloseKey(hkey);
 | 
			
		||||
  }
 | 
			
		||||
  return retval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ext2app(const char* ext, TString& app)
 | 
			
		||||
{                               
 | 
			
		||||
  bool ok = FALSE;
 | 
			
		||||
  TString key(_MAX_PATH);
 | 
			
		||||
 | 
			
		||||
  key = ext;
 | 
			
		||||
  if (key[0] != '.')
 | 
			
		||||
    key.insert(".", 0);
 | 
			
		||||
  
 | 
			
		||||
  if (get_reg_key(HKEY_CLASSES_ROOT, key, key) == ERROR_SUCCESS)
 | 
			
		||||
  {
 | 
			
		||||
    key << "\\shell\\open\\command";
 | 
			
		||||
    if (get_reg_key(HKEY_CLASSES_ROOT, key, key) == ERROR_SUCCESS)
 | 
			
		||||
    {
 | 
			
		||||
      key.strip("\"");
 | 
			
		||||
      int pos = key.find("%1");
 | 
			
		||||
      if (pos > 0)
 | 
			
		||||
        key.cut(pos);
 | 
			
		||||
      key.trim();
 | 
			
		||||
      app = key;  
 | 
			
		||||
      ok = TRUE;  
 | 
			
		||||
    }
 | 
			
		||||
  }      
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool goto_url(const char* url)
 | 
			
		||||
{
 | 
			
		||||
  bool retflag = FALSE;
 | 
			
		||||
  
 | 
			
		||||
  HINSTANCE hinst = ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
 | 
			
		||||
  DWORD winst = DWORD((DWORD*)hinst);
 | 
			
		||||
  UINT error = UINT(winst);  // Tutto 'sto giro per evitare un warning
 | 
			
		||||
  if (error <= 32)
 | 
			
		||||
  {    
 | 
			
		||||
    TString app(_MAX_PATH);
 | 
			
		||||
    if (ext2app(".htm", app))
 | 
			
		||||
    {
 | 
			
		||||
      app << ' ' << url;
 | 
			
		||||
      error = WinExec(app, SW_SHOWNORMAL);
 | 
			
		||||
      if (error > 32)
 | 
			
		||||
        retflag = TRUE;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
    retflag = TRUE;
 | 
			
		||||
  
 | 
			
		||||
  return retflag;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool print_url(const char* url)
 | 
			
		||||
{
 | 
			
		||||
  HINSTANCE hinst = ShellExecute(NULL, "print", url, NULL, NULL, SW_SHOWNORMAL);
 | 
			
		||||
  DWORD winst = DWORD((DWORD*)hinst);
 | 
			
		||||
  UINT error = UINT(winst);  // Tutto 'sto giro per evitare un warning
 | 
			
		||||
  return error >= 32;
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
@ -51,11 +51,4 @@ public:
 | 
			
		||||
  TExternal_app(const char* p);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Estrae lapplicazione associata all'estensione
 | 
			
		||||
bool ext2app(const char* ext, TString& app);
 | 
			
		||||
// Va ad un URl qualsiasi
 | 
			
		||||
bool goto_url(const char* url);
 | 
			
		||||
// Stampa un URl qualsiasi
 | 
			
		||||
bool print_url(const char* url);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -13,6 +13,174 @@
 | 
			
		||||
 | 
			
		||||
#include "bagn006.h"
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// GotoURL 
 | 
			
		||||
// Liberamente tradotto da Windows Developer Journal August 1997
 | 
			
		||||
///////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
HIDDEN long get_reg_key(HKEY key, const char* subkey, TString& retdata)
 | 
			
		||||
{                                            
 | 
			
		||||
  HKEY hkey;
 | 
			
		||||
  long retval = RegOpenKey(key, subkey, &hkey);
 | 
			
		||||
  if (retval == ERROR_SUCCESS)
 | 
			
		||||
  {
 | 
			
		||||
    long datasize = retdata.size();
 | 
			
		||||
    RegQueryValue(hkey, NULL, retdata.get_buffer(), &datasize);
 | 
			
		||||
    RegCloseKey(hkey);
 | 
			
		||||
  }
 | 
			
		||||
  return retval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
HIDDEN bool file2app(const char* filename, TString& app)
 | 
			
		||||
{                               
 | 
			
		||||
  bool ok = FALSE;
 | 
			
		||||
  
 | 
			
		||||
  if (*filename != '.')
 | 
			
		||||
  {
 | 
			
		||||
    HINSTANCE hinst = FindExecutable(filename, ".", app.get_buffer());
 | 
			
		||||
    DWORD* pinst = (DWORD*)hinst;
 | 
			
		||||
    UINT err = LOWORD(pinst);
 | 
			
		||||
    ok = err > 32;
 | 
			
		||||
  }
 | 
			
		||||
    
 | 
			
		||||
  if (!ok)
 | 
			
		||||
  {                         
 | 
			
		||||
    char ext[_MAX_EXT];
 | 
			
		||||
    if (*filename == '.')
 | 
			
		||||
      strncpy(ext, filename, _MAX_EXT);
 | 
			
		||||
    else  
 | 
			
		||||
      _splitpath(filename, NULL, NULL, NULL, ext);
 | 
			
		||||
 | 
			
		||||
    TFilename key;
 | 
			
		||||
    if (get_reg_key(HKEY_CLASSES_ROOT, ext, key) == ERROR_SUCCESS)
 | 
			
		||||
    {
 | 
			
		||||
      key << "\\shell\\open\\command";
 | 
			
		||||
      if (get_reg_key(HKEY_CLASSES_ROOT, key, key) == ERROR_SUCCESS)
 | 
			
		||||
      {
 | 
			
		||||
        key.strip("\"");
 | 
			
		||||
        int pos = key.find("%1");
 | 
			
		||||
        if (pos > 0)
 | 
			
		||||
          key.cut(pos);
 | 
			
		||||
        key.trim();
 | 
			
		||||
        app = key;  
 | 
			
		||||
        ok = TRUE;  
 | 
			
		||||
      }
 | 
			
		||||
    }      
 | 
			
		||||
  }  
 | 
			
		||||
  
 | 
			
		||||
  if (ok && !fexist(app))
 | 
			
		||||
    ok = warning_box("Il programma %s e' stato rimosso!", app.get_buffer());
 | 
			
		||||
  
 | 
			
		||||
  return ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
HIDDEN bool internet_address(const char* filename)
 | 
			
		||||
{           
 | 
			
		||||
  const TFilename url(filename);
 | 
			
		||||
  if (url.find("://") > 0)
 | 
			
		||||
    return TRUE;
 | 
			
		||||
  if (url.find("www.") >= 0)
 | 
			
		||||
    return TRUE;                                
 | 
			
		||||
  
 | 
			
		||||
  const char* extensions[] = { "com","edu","gov","it","mil","net","org", NULL };
 | 
			
		||||
  const char* ext = url.ext();
 | 
			
		||||
  for (int e = 0; extensions[e]; e++)
 | 
			
		||||
    if (stricmp(ext, extensions[e]) == 0)
 | 
			
		||||
      return TRUE;
 | 
			
		||||
  
 | 
			
		||||
  return FALSE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
HIDDEN word file2icon(const char* filename)
 | 
			
		||||
{
 | 
			
		||||
  word icon = 0;
 | 
			
		||||
 | 
			
		||||
  char ext[_MAX_EXT];
 | 
			
		||||
  if (*filename == '.')
 | 
			
		||||
    strncpy(ext, filename, _MAX_EXT);
 | 
			
		||||
  else                   
 | 
			
		||||
  {         
 | 
			
		||||
    if (internet_address(filename))
 | 
			
		||||
      strcpy(ext, ".htm");                      
 | 
			
		||||
    else  
 | 
			
		||||
      _splitpath(filename, NULL, NULL, NULL, ext);
 | 
			
		||||
  }  
 | 
			
		||||
  
 | 
			
		||||
  int icon_number = 0;
 | 
			
		||||
  TFilename key;
 | 
			
		||||
 | 
			
		||||
  if (stricmp(ext, ".exe") != 0)
 | 
			
		||||
  {
 | 
			
		||||
    if (get_reg_key(HKEY_CLASSES_ROOT, ext, key) == ERROR_SUCCESS)
 | 
			
		||||
    {                     
 | 
			
		||||
      key << "\\DefaultIcon";                                     
 | 
			
		||||
      if (get_reg_key(HKEY_CLASSES_ROOT, key, key) == ERROR_SUCCESS)  // Windows 95 only
 | 
			
		||||
      {
 | 
			
		||||
        const int comma = key.find(',');
 | 
			
		||||
        if (comma > 0)
 | 
			
		||||
        {
 | 
			
		||||
          icon_number = atoi(key.mid(comma+1));
 | 
			
		||||
          key.cut(comma);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        if (!file2app(filename, key))
 | 
			
		||||
          file2app(".htm", key);
 | 
			
		||||
      }  
 | 
			
		||||
    }
 | 
			
		||||
  }  
 | 
			
		||||
  else
 | 
			
		||||
    key = filename;
 | 
			
		||||
  
 | 
			
		||||
  if (fexist(key))
 | 
			
		||||
  {
 | 
			
		||||
    HINSTANCE hInst = (HINSTANCE)xvt_vobj_get_attr(NULL_WIN, ATTR_WIN_INSTANCE);
 | 
			
		||||
    HICON hicon = ExtractIcon(hInst, key, icon_number);
 | 
			
		||||
    if (hicon == NULL) 
 | 
			
		||||
      ExtractIcon(hInst, key, 0);
 | 
			
		||||
    if (hicon == NULL)
 | 
			
		||||
      warning_box("Impossibile accedere alll'icona del programma %s", key.get_buffer());
 | 
			
		||||
    DWORD dwicon = DWORD((DWORD*)hicon);
 | 
			
		||||
    icon = LOWORD(dwicon);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  return icon;  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
HIDDEN bool goto_url(const char* url)
 | 
			
		||||
{
 | 
			
		||||
  bool retflag = FALSE;
 | 
			
		||||
  
 | 
			
		||||
  HINSTANCE hinst = ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
 | 
			
		||||
  DWORD winst = DWORD((DWORD*)hinst);
 | 
			
		||||
  UINT error = UINT(winst);  // Tutto 'sto giro per evitare un warning
 | 
			
		||||
  if (error <= 32)
 | 
			
		||||
  {    
 | 
			
		||||
    TFilename app(_MAX_PATH);
 | 
			
		||||
    if (file2app(".htm", app))
 | 
			
		||||
    {
 | 
			
		||||
      app << ' ' << url;
 | 
			
		||||
      error = WinExec(app, SW_SHOWNORMAL);
 | 
			
		||||
      if (error > 32)
 | 
			
		||||
        retflag = TRUE;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
    retflag = TRUE;
 | 
			
		||||
  
 | 
			
		||||
  return retflag;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
HIDDEN bool print_url(const char* url)
 | 
			
		||||
{
 | 
			
		||||
  HINSTANCE hinst = ShellExecute(NULL, "print", url, NULL, NULL, SW_SHOWNORMAL);
 | 
			
		||||
  DWORD winst = DWORD((DWORD*)hinst);
 | 
			
		||||
  UINT error = UINT(winst);  // Tutto 'sto giro per evitare un warning
 | 
			
		||||
  return error >= 32;
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
// Campi GOLEM
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
@ -24,46 +192,21 @@ TString& TGolem_field::get_window_data()
 | 
			
		||||
 | 
			
		||||
void TGolem_field::set_window_data(const char* data)
 | 
			
		||||
{ 
 | 
			
		||||
  TFilename app(_MAX_PATH);
 | 
			
		||||
  if (*data > ' ')
 | 
			
		||||
  {
 | 
			
		||||
    TFilename file(data);
 | 
			
		||||
    const int pipe = file.find('|');
 | 
			
		||||
    if (pipe > 0) file.cut(pipe);  
 | 
			
		||||
  WORD icon = 0;         
 | 
			
		||||
  
 | 
			
		||||
    HINSTANCE hinst = FindExecutable(file, ".", app.get_buffer());
 | 
			
		||||
    DWORD* pinst = (DWORD*)hinst;
 | 
			
		||||
    UINT err = LOWORD(pinst);
 | 
			
		||||
    if (err <= 32)
 | 
			
		||||
      ext2app(".htm", app);
 | 
			
		||||
    if (err > 32 && !fexist(app))
 | 
			
		||||
  char* pipe = strchr(data, '|');
 | 
			
		||||
  if (pipe)
 | 
			
		||||
  {
 | 
			
		||||
      warning_box("Il file %s e' associato all'applicazione\n"
 | 
			
		||||
                  "%s, che non e' presente sul sistema", 
 | 
			
		||||
                  file.get_buffer(), app.get_buffer());
 | 
			
		||||
    }
 | 
			
		||||
    *pipe = '\0';
 | 
			
		||||
    icon = file2icon(data);
 | 
			
		||||
    *pipe = '|';
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  TPushbutton_control* btn = (TPushbutton_control*)_ctl;
 | 
			
		||||
  if (app.not_empty())
 | 
			
		||||
  {
 | 
			
		||||
    HINSTANCE hInst = (HINSTANCE)xvt_vobj_get_attr(NULL_WIN, ATTR_WIN_INSTANCE);
 | 
			
		||||
    HICON hicon = ExtractIcon(hInst, app, 0);
 | 
			
		||||
    DWORD dwicon = DWORD((DWORD*)hicon);
 | 
			
		||||
    WORD icon = LOWORD(dwicon);
 | 
			
		||||
  if (icon)
 | 
			
		||||
    btn->set_icon(icon);
 | 
			
		||||
  else  
 | 
			
		||||
    {
 | 
			
		||||
#ifdef DBG
 | 
			
		||||
      warning_box("Can't extract %s icon!", app.get_buffer());
 | 
			
		||||
#endif    
 | 
			
		||||
    btn->set_bmp(BMP_OLE, 0);
 | 
			
		||||
    }  
 | 
			
		||||
  }
 | 
			
		||||
  else            
 | 
			
		||||
  {
 | 
			
		||||
    btn->set_bmp(BMP_OLE, 0);
 | 
			
		||||
  }  
 | 
			
		||||
 | 
			
		||||
  RCT rct; btn->get_rect(rct);
 | 
			
		||||
  xi_invalidate_rect(btn->parent(), &rct);
 | 
			
		||||
@ -139,16 +282,8 @@ bool TGolem_field::autosave(TRelation& r)
 | 
			
		||||
          {                
 | 
			
		||||
            char ext[_MAX_EXT];
 | 
			
		||||
            _splitpath(new_file, NULL, NULL, NULL, ext);
 | 
			
		||||
             old_file.temp(golem_path, ext);
 | 
			
		||||
 | 
			
		||||
            // Very childish! I can do much better
 | 
			
		||||
            for (long n = 1; ; n++)
 | 
			
		||||
            {  
 | 
			
		||||
              TString16 name; name.format("%08ld%s", n, ext);
 | 
			
		||||
              old_file = golem_path; 
 | 
			
		||||
              old_file.add(name);
 | 
			
		||||
              if (!fexist(old_file))
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            fcopy(new_file, old_file);
 | 
			
		||||
            new_row.add(old_file, 0);
 | 
			
		||||
            new_value.add(new_row, i);
 | 
			
		||||
 | 
			
		||||
@ -1604,25 +1604,22 @@ TIsamtempfile::TIsamtempfile(int logicnum, const char* radix, bool create)
 | 
			
		||||
  if (radix && *radix)
 | 
			
		||||
  {
 | 
			
		||||
    if (*radix == '%') 
 | 
			
		||||
      n = radix;
 | 
			
		||||
      n = radix + 1;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      n.tempdir(); 
 | 
			
		||||
      n << '/' << radix; 
 | 
			
		||||
      n << SLASH << radix; 
 | 
			
		||||
    }
 | 
			
		||||
  }  
 | 
			
		||||
  
 | 
			
		||||
    n.ext("dbf");
 | 
			
		||||
  }  
 | 
			
		||||
  else
 | 
			
		||||
    n.temp(NULL, "dbf");
 | 
			
		||||
  
 | 
			
		||||
  if (!create)
 | 
			
		||||
  {      
 | 
			
		||||
    TDir dir; dir.get(logicnum);
 | 
			
		||||
    const word& len = dir.len();  
 | 
			
		||||
 | 
			
		||||
    // Tolgo il % senno' che fa la fopen ?
 | 
			
		||||
    if (n[0] == '%') 
 | 
			
		||||
      n = n.sub(1);
 | 
			
		||||
    
 | 
			
		||||
    FILE* f = fopen(n, "r");
 | 
			
		||||
 | 
			
		||||
    TString err;
 | 
			
		||||
@ -1635,13 +1632,6 @@ TIsamtempfile::TIsamtempfile(int logicnum, const char* radix, bool create)
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  _autodel = create > TRUE;
 | 
			
		||||
 | 
			
		||||
  n.ext("");        
 | 
			
		||||
 | 
			
		||||
  // Ci rimetto il % se prima l'avevo tolto, senno' che fa la open ?
 | 
			
		||||
  if (n[0] != '%')
 | 
			
		||||
    n.insert("%", 0);
 | 
			
		||||
  
 | 
			
		||||
  open(n, create, eod, eox);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1676,6 +1666,8 @@ int TIsamtempfile::open(
 | 
			
		||||
    tmpname << &radix[1] ;
 | 
			
		||||
  else
 | 
			
		||||
    tmpname.temp(radix);
 | 
			
		||||
  tmpname.ext("");  
 | 
			
		||||
    
 | 
			
		||||
  getisfd (_isamfile, num());
 | 
			
		||||
  strcpy(filehnd()->d->SysName, (const char*)tmpname);
 | 
			
		||||
  filehnd()->d->EOX = eox;
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
#include <math.h>
 | 
			
		||||
 | 
			
		||||
#include <colors.h>
 | 
			
		||||
#include <defmask.h>
 | 
			
		||||
#include <progind.h>  
 | 
			
		||||
#include <controls.h>
 | 
			
		||||
@ -112,17 +113,21 @@ void TIndwin::update_bar()
 | 
			
		||||
  RCT r; xvt_vobj_get_client_rect(w, &r);
 | 
			
		||||
  
 | 
			
		||||
  // Rettangolo contenente l'intera barra
 | 
			
		||||
  r.left = CHARX; r.right -= CHARX;
 | 
			
		||||
  r.left += CHARX; r.right -= CHARX;
 | 
			
		||||
  r.top = (int)_bar; 
 | 
			
		||||
  r.bottom = r.top + 2*CHARY;
 | 
			
		||||
 | 
			
		||||
  RCT b = r;
 | 
			
		||||
  // Rettangolo in rilievo
 | 
			
		||||
  b.right = b.left + int((r.right-r.left)*prc);
 | 
			
		||||
  xi_draw_3d_rect(w, &b, FALSE, 2, 0, 0, 0);
 | 
			
		||||
//  xi_draw_3d_rect(w, &b, FALSE, 2, 0, 0, 0);
 | 
			
		||||
  xi_draw_3d_rect(w, &b, FALSE, 2, 
 | 
			
		||||
                  BTN_LIGHT_COLOR, BTN_BACK_COLOR, BTN_DARK_COLOR);
 | 
			
		||||
  // Rettangolo scavato
 | 
			
		||||
  b.left = b.right; b.right = r.right;
 | 
			
		||||
  xi_draw_3d_rect(w, &b, TRUE, 2, 0, 0, 0);
 | 
			
		||||
//  xi_draw_3d_rect(w, &b, TRUE, 2, 0, 0, 0);
 | 
			
		||||
  xi_draw_3d_rect(w, &b, TRUE, 2, 
 | 
			
		||||
                  BTN_LIGHT_COLOR, BTN_BACK_COLOR, BTN_DARK_COLOR);
 | 
			
		||||
  
 | 
			
		||||
  char n[8]; sprintf(n, "%d%%", (int)floor(prc * 100.0 + 0.5));
 | 
			
		||||
  xvt_dwin_draw_text(w, r.left+r.right/2-CHARX, (r.bottom+r.top+CHARY)/2-3, n, -1);
 | 
			
		||||
 | 
			
		||||
@ -26,8 +26,7 @@ class TString512 : public TFixed_string
 | 
			
		||||
  char _str512[513];
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  TString512(const char* s = "") : TFixed_string(_str512, 513) { set(s); }
 | 
			
		||||
  TString512(const TString& s) : TFixed_string(_str512, 513) { set(s); }
 | 
			
		||||
  TString512() : TFixed_string(_str512, 513) { }
 | 
			
		||||
  const TString& operator =(const char* s);
 | 
			
		||||
  const TString& operator =(const TString& s) { return operator =((const char*)s); }
 | 
			
		||||
  void strncpy(const char* s, int n);
 | 
			
		||||
@ -92,6 +91,7 @@ void TString::resize(
 | 
			
		||||
 | 
			
		||||
  // @comm Non funziona con le stringhe static e per valori negativi di <p size>
 | 
			
		||||
{                     
 | 
			
		||||
  CHECKD(size >= 0, "Invalid string resize ", size);
 | 
			
		||||
  char* s = new char[size+1];
 | 
			
		||||
  if (cpy && _str) strcpy(s, _str);
 | 
			
		||||
  else *s = '\0';
 | 
			
		||||
@ -114,7 +114,7 @@ TString& TString::set(
 | 
			
		||||
  // @rdesc Ritorna l'indirizzo della stringa inizializzata
 | 
			
		||||
{
 | 
			
		||||
  if (s == NULL) s = "";
 | 
			
		||||
  const int sz = *s ? strlen(s) : 7;
 | 
			
		||||
  const int sz = *s ? strlen(s) : 15;
 | 
			
		||||
  if (sz > size()) resize(sz, FALSE);
 | 
			
		||||
  strcpy(_str, s);
 | 
			
		||||
 | 
			
		||||
@ -134,7 +134,7 @@ int TString::make_room(
 | 
			
		||||
  const int lun = len();
 | 
			
		||||
  const int spare = size() - lun;
 | 
			
		||||
  if (spare < s)
 | 
			
		||||
    resize(size() + 2*s, TRUE);
 | 
			
		||||
    resize(3 * (size() + s) / 2, TRUE);
 | 
			
		||||
  return lun;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -146,15 +146,20 @@ TString::TString(const TString& s) : _str(NULL), _size(0)
 | 
			
		||||
 | 
			
		||||
TString::TString(int size, char c) : _str(NULL), _size(0)
 | 
			
		||||
{ 
 | 
			
		||||
/*
 | 
			
		||||
  resize(size, FALSE); 
 | 
			
		||||
  *(_str+size--)='\0';
 | 
			
		||||
  for (;c && size>=0; size--)
 | 
			
		||||
    *(_str+size)=c;
 | 
			
		||||
  
 | 
			
		||||
*/    
 | 
			
		||||
  if (size > 0)
 | 
			
		||||
    fill(c, size);   // Guy: Much simpler and faster (uses memset)
 | 
			
		||||
  else
 | 
			
		||||
    resize(15, FALSE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TString::TString() : _str(NULL), _size(0)
 | 
			
		||||
{ resize(7, FALSE); }
 | 
			
		||||
{ resize(15, FALSE); }
 | 
			
		||||
 | 
			
		||||
TString::~TString()
 | 
			
		||||
{
 | 
			
		||||
@ -964,13 +969,6 @@ TString& TFixed_string::format(
 | 
			
		||||
// Filename
 | 
			
		||||
///////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
const char SLASH =
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_WIN32
 | 
			
		||||
'\\';
 | 
			
		||||
#else                   
 | 
			
		||||
'/';
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// Certified 90%
 | 
			
		||||
const char* TFilename::ext() const
 | 
			
		||||
{
 | 
			
		||||
@ -983,11 +981,15 @@ const char* TFilename::ext() const
 | 
			
		||||
void TFilename::ext(const char* e)
 | 
			
		||||
{
 | 
			
		||||
  char* d = strrchr(name(), '.');
 | 
			
		||||
  if (d && is_not_slash(*(d+1))) *d = '\0';
 | 
			
		||||
 | 
			
		||||
  if (*e && *e != '.') *this << ".";
 | 
			
		||||
  if (d && is_not_slash(*(d+1))) 
 | 
			
		||||
    *d = '\0';
 | 
			
		||||
  if (*e)
 | 
			
		||||
  {
 | 
			
		||||
    if (*e != '.') 
 | 
			
		||||
      *this << ".";
 | 
			
		||||
    *this << e;
 | 
			
		||||
  }  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Certified 90%
 | 
			
		||||
@ -1134,13 +1136,32 @@ const TFilename& TFilename::tempdir()
 | 
			
		||||
 | 
			
		||||
// @mfunc Genera il nome di un file temporaneo
 | 
			
		||||
const TFilename& TFilename::temp(
 | 
			
		||||
  const char* prefix) // @parm Eventuale prefisso da assegnare al file temporaneo
 | 
			
		||||
  const char* prefix,      // @parm Eventuale prefisso da assegnare al file temporaneo
 | 
			
		||||
  const char* extension)   // @parm Eventuale estensione da assegnare al file temporaneo
 | 
			
		||||
 | 
			
		||||
  // @comm Nel generare il nome del file controlla se esistone dei caratteri jolly
 | 
			
		||||
  //       e li elimina.
 | 
			
		||||
{ 
 | 
			
		||||
  tempdir();
 | 
			
		||||
  if (extension && *extension)
 | 
			
		||||
  {   
 | 
			
		||||
    static unsigned long numero = 0;  
 | 
			
		||||
    
 | 
			
		||||
    TFilename prefisso(prefix);
 | 
			
		||||
    if (prefisso.empty())
 | 
			
		||||
      prefisso.tempdir();
 | 
			
		||||
    if (is_not_slash(prefisso.right(1)[0]))  
 | 
			
		||||
      prefisso << SLASH;
 | 
			
		||||
 | 
			
		||||
    // Childish: You could use findfirst!
 | 
			
		||||
    do
 | 
			
		||||
    {
 | 
			
		||||
      format("%s%ld", prefisso.get_buffer(), ++numero);
 | 
			
		||||
      ext(extension);
 | 
			
		||||
    } while (fexist(_str));
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    tempdir();
 | 
			
		||||
    if (prefix && *prefix)
 | 
			
		||||
    {
 | 
			
		||||
      set(prefix);      // Copia prefisso e ...
 | 
			
		||||
@ -1160,13 +1181,14 @@ const TFilename& TFilename::temp(
 | 
			
		||||
      if (f.find("##") != -1) *this << getuid();
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
  else cut(0);
 | 
			
		||||
    else 
 | 
			
		||||
      cut(0);
 | 
			
		||||
  
 | 
			
		||||
    char* t = tempnam(NULL, (char*)_str);
 | 
			
		||||
 | 
			
		||||
    CHECK(t != NULL, "Can't execute tempnam");
 | 
			
		||||
    set(t);
 | 
			
		||||
    free(t);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
#ifdef DBG
 | 
			
		||||
  if (fexist(_str)) 
 | 
			
		||||
 | 
			
		||||
@ -421,7 +421,7 @@ public:
 | 
			
		||||
  // @cmember Ritorna il nome del direttorio
 | 
			
		||||
  const char* path() const;
 | 
			
		||||
  // @cmember Genera il nome di un file temporaneo
 | 
			
		||||
  const TFilename& temp(const char* prefix = NULL);
 | 
			
		||||
  const TFilename& temp(const char* prefix = NULL, const char* extension = NULL);
 | 
			
		||||
  // @cmember Genera il nome della directory temporanea
 | 
			
		||||
  const TFilename& tempdir();
 | 
			
		||||
};
 | 
			
		||||
@ -590,4 +590,11 @@ public:
 | 
			
		||||
  {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const char SLASH =
 | 
			
		||||
#if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_WIN32
 | 
			
		||||
'\\';
 | 
			
		||||
#else                   
 | 
			
		||||
'/';
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user