Subversion Repositories Kolibri OS

Rev

Rev 8827 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. int executable_run(char cmd[], char args[]) {
  3.     char        exec[FILENAME_MAX];
  4.     int         result;
  5.  
  6.     if ( '/' == cmd[0]) // if path is absolute
  7.     {
  8.         strcpy(exec, cmd);
  9.         if (!file_check(exec) ) // check file existense
  10.         {
  11.             file_not_found(cmd);
  12.             return FALSE;
  13.         }
  14.     } else {
  15.         strcpy(exec, cur_dir); // check file in current directory
  16.         if (exec[strlen(exec)-1] != '/')
  17.             strcat(exec, "/"); // add slash
  18.         strcat(exec, cmd);
  19.        
  20.         if ( !file_check(exec) ) // check file existense
  21.         {
  22.             strcpy(exec, "/sys/"); // check file on virtual disk
  23.             strcat(exec, cmd);
  24.             if ( !file_check(exec) ) // check file existense
  25.             {
  26.                 file_not_found(cmd);
  27.                 return FALSE;
  28.             }
  29.         }
  30.     }
  31.  
  32.     // if file exists:
  33.  
  34.     // try to run as a program
  35.     result = program_run(exec, args);
  36.     if (result > 0) {
  37.         if ( !program_console(result)  ) {
  38.             LAST_PID = result;
  39.             printf (EXEC_STARTED_FMT, cmd, result);
  40.         }
  41.         return TRUE;
  42.     } else      {
  43.         if ( script_check(exec) ) // if file is a valid script
  44.         {
  45.             return script_run(exec, args);
  46.         } else
  47.         {
  48.             printf (EXEC_SCRIPT_ERROR_FMT, cmd);
  49.             return FALSE;
  50.         }
  51.     }
  52.  
  53. }
  54.  
  55.