Changeset 22a2bb0 in tol


Ignore:
Timestamp:
Mar 20, 2009, 5:00:58 PM (18 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
d9a156c
Parents:
338cca0
Message:

Using TolAppData() as base of TmpNam() in order to centralize all TOL related directories

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@791 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/bbasic/sys.cpp

    r338cca0 r22a2bb0  
    4545//--------------------------------------------------------------------
    4646BTraceInit("sys.cpp");
    47 #ifdef  UNIX
     47#ifdef  UNIX
    4848  BBool BSys::unix_=BTRUE;
    4949  BText BSys::editor_("emacs ");
    … …  
    8080    BSys::MkDir(tolAppData_+"OIS",          true);
    8181    BSys::MkDir(tolAppData_+"tests_results",true);
     82    tolAppData_ = GetStandardAbsolutePath(tolAppData_);
    8283  }
    8384  return(tolAppData_);
    … …  
    226227      if(!prefix.HasName() || fName.BeginWith(prefix))
    227228      {
    228         path = dir.Name()+"/"+fName;
    229   //    Std(BText("\n") + n + ") " + dir.FileName(n) + msg);
    230         remove(path.String());
     229  path = dir.Name()+"/"+fName;
     230  //  Std(BText("\n") + n + ") " + dir.FileName(n) + msg);
     231  remove(path.String());
    231232      }
    232233    }
    … …  
    238239//--------------------------------------------------------------------
    239240BText BSys::TempNam(const BText& outputDir,
    240                     const BText& prefix,
    241                     const BText& ext,
    242                           BInt   len)
     241        const BText& prefix,
     242        const BText& ext,
     243              BInt   len)
    243244
    244245/*! Creates a unique temporal file name in specific directory.
    … …  
    260261{
    261262//InitTotalTime("BSys::TempNam");
    262     static BInt fileNumber_ = -1;
    263     BText fileName;
    264     BText dir = outputDir;
     263  static BInt fileNumber_ = -1;
     264  BText fileName;
     265  BText dir = outputDir;
     266//Std(BText("\nBSys::TempNam 1 dir = ")+dir);
     267  if(!dir.HasName()) { dir= TolAppData()+"tmp/"; }
     268//Std(BText("\nBSys::TempNam 2 dir = ")+dir);
     269
    265270//Std("\nBSys::TempNam("); Std(outputDir+", "+prefix+", "+ext+", "+len+")");
    266     if(!(BDir::CheckIsDir(dir)) || (!dir.HasName()) )
    267     {
    268 #     ifdef UNIX
    269 /* tempnam function was deprecated:
    270  *      dir = GetFilePath(tempnam("","")); */
    271         dir = "/tmp";
    272 #     else
    273         BText tmp = getenv("TMP");
    274         if(!tmp.HasName()) { tmp = getenv("TEMP"); }
    275         dir = tmp;
    276         BText dirTOL = dir+"/TOL";
    277         if(!BDir::CheckIsDir(dirTOL))
    278         {
    279       system(BText("mkdir \"")+dirTOL+"\"");
    280         //MkDir(dirTOL,true);
    281         }
    282         dir = dirTOL;
    283 #     endif
    284     }
    285     BInt attempts = 0;
    286     BText pathFile;
    287     do
    288     {
    289         attempts ++;
    290         if(len<4) { len=4; }
    291        
    292         BInt base = (BInt)pow(10.0,(double)len); //(BInt)(BDat(10)^BDat(len)).Value();
    293         BInt r = LongRandom(base-1);
    294         BText number = BText("")+r;
    295         if(len<number.Length()) { number = number.SubString(0,len-1); }
    296         fileName = prefix+number+"."+ext;
    297         pathFile = dir+"/"+fileName;
     271  if(!BDir::CheckIsDir(dir))
     272  {
     273  //Std(BText("\nBSys::TempNam 4 dir = ")+dir);
     274    mkdir(dir);
     275  }
     276//Std(BText("\nBSys::TempNam 5 dir = ")+dir);
     277  BInt attempts = 0;
     278  BText pathFile;
     279  do
     280  {
     281    attempts ++;
     282    if(len<4) { len=4; }
     283    BInt base = (BInt)pow(10.0,(double)len); //(BInt)(BDat(10)^BDat(len)).Value();
     284    BInt r = LongRandom(base-1);
     285    BText number = BText("")+r;
     286    if(len<number.Length()) { number = number.SubString(0,len-1); }
     287    fileName = prefix+number+"."+ext;
     288    pathFile = dir+fileName;
    298289//  Std(pathFile + " is File " + CheckIsFile(pathFile));
    299     }
    300     while(CheckIsFile(pathFile));
     290  }
     291  while(CheckIsFile(pathFile));
    301292//Std(BText("\nTempNam = ") + fileName + " after " + attempts+ " attempts.");
    302293//SumPartialTime;
    303     return(pathFile);
     294  return(pathFile);
    304295}
    305296
    … …  
    316307{
    317308  BChar* aux=getenv(envVar.String());
    318   BText  tmpName=aux;
     309  BText  tmpName=aux;
    319310  return(tmpName);
    320311}
    … …  
    336327  {
    337328    Error(BText("\n[")+errno+"]=" + strerror(errno) + "\n" +
    338           I2("Cannot execute the command: ",
    339              "No se pudo ejecutar el mandato: ") + "\n" + command);
     329    I2("Cannot execute the command: ",
     330       "No se pudo ejecutar el mandato: ") + "\n" + command);
    340331  }
    341332  return(!err);
    … …  
    415406
    416407  if (!CreateProcess(NULL, cmd, NULL, NULL,
    417             FALSE, 0, NULL, NULL, &startupInfo,
    418             &piProcInfo))
     408       FALSE, 0, NULL, NULL, &startupInfo,
     409       &piProcInfo))
    419410  {
    420411    ShowLastError(I2("Creating process \n",
    … …  
    529520/*! Prints a file in the default printer. Operating systems:<ul>
    530521 *      <li>UNIX: print the file with lp command, options:<ul>
    531  *      <li>-onb: option no banner (don't work).
    532  *      <li>-s: suppress messages from lp such as: request ID is...
    533  *      <li>-c: Make copies of the files to be printed immediately when
    534  *              lp is invoked (and then can be deleted).</ul>
     522 *  <li>-onb: option no banner (don't work).
     523 *  <li>-s: suppress messages from lp such as: request ID is...
     524 *  <li>-c: Make copies of the files to be printed immediately when
     525 *            lp is invoked (and then can be deleted).</ul>
    535526 *      <li>WINDOWS: .</ul>
    536527 * \param fileName Name of file to be printed
    … …  
    539530//--------------------------------------------------------------------
    540531{
    541 #ifdef  UNIX
     532#ifdef  UNIX
    542533  BText command("lp -c ");
    543534  return(BSys::System(command+fileName));
    544535#else // WINDOWS
    545536  ShellExecute(
    546     0,                 // handle to parent window
     537    0,                 // handle to parent window
    547538    "print",           // string that specifies operation to perform
    548539    fileName.String(), // filename string
    … …  
    582573//--------------------------------------------------------------------
    583574{
    584 #ifdef  UNIX
     575#ifdef  UNIX
    585576  BText copyCom("cp ");
    586577#else // WINDOWS
    … …  
    679670{
    680671  if(!BSys::Editor().HasName()) { return(BFALSE); }
    681 #ifdef  UNIX
     672#ifdef  UNIX
    682673  return(BSys::System(BSys::Editor()+" "+fileName+" &"));
    683674#else // WINDOWS
    … …  
    715706{
    716707  if(!BSys::Editor().HasName()) { return(BFALSE); }
    717 #ifdef  UNIX
     708#ifdef  UNIX
    718709  return(Edit(fileName,0));
    719710#else // WINDOWS
    … …  
    740731{
    741732  if(!BSys::Editor().HasName()) { return(BFALSE); }
    742 #ifdef  UNIX
     733#ifdef  UNIX
    743734  return(Edit(fileName,0));
    744735#else // WINDOWS
    … …  
    780771//--------------------------------------------------------------------
    781772{
    782 #ifdef  UNIX
     773#ifdef  UNIX
    783774  return(BSys::System(BSys::Editor()+fileName));
    784775#else // WINDOWS
    … …  
    889880  (
    890881    GetCurrentThread(), // handle to the thread
    891     &lpExitCode               // address to receive termination status
     882    &lpExitCode          // address to receive termination status
    892883  );
    893884  ExitThread(lpExitCode);
    … …  
    901892//--------------------------------------------------------------------
    902893{
    903 #ifndef   UNIX
     894#ifndef    UNIX
    904895
    905896//Std(BText("\nClient Question : \n")+command+"\n");
    906897
    907   SECURITY_ATTRIBUTES     sa =
     898  SECURITY_ATTRIBUTES    sa =
    908899  {
    909900    sizeof(SECURITY_ATTRIBUTES),   // structure size
    910     0,                             // No security descriptor
     901    0,                             // No security descriptor
    911902    TRUE,                          // Thread handle is inheritable
    912903  };
    913904  char* arg = new char[command.Length()+1];
    914905  strncpy(arg, command.String(), command.Length()+1);
    915   DWORD   threadId;
     906  DWORD    threadId;
    916907  HANDLE hThread = (HANDLE)CreateThread
    917908  (
    918909    &sa,                    // Thread security
    919910    4096,                   // Thread stack size
    920     threadMain,             // Thread starting address
     911    threadMain,              // Thread starting address
    921912    (void *)arg,            // Thread start argument
    922913    CREATE_SUSPENDED,       // Create in suspended state
    … …  
    927918  {
    928919    //MessageBox(0, "Thread Creation Failed", "Error", MB_OK);
    929         Error("Thread Creation Failed");
     920  Error("Thread Creation Failed");
    930921    return(BFALSE);
    931922  }
Note: See TracChangeset for help on using the changeset viewer.