Subversion Repositories Kolibri OS

Rev

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

  1.  
  2.  
  3. int script_check(char file[]) {
  4.     kol_struct70        k70;
  5.     char                buf[4];
  6.  
  7.     k70.p00 = 0;
  8.     k70.p04 = 0;
  9.     //k70.p08 = 0;
  10.     k70.p12 = 4; // read 4 bytes
  11.     k70.p16 = (unsigned) buf;
  12.     k70.p20 = 0;
  13.     k70.p21 = file;
  14.  
  15.     kol_file_70(&k70);
  16.  
  17.     if ( !strcmp(buf, script_sign) ) // if we found the script signature
  18.         return TRUE;
  19.     else
  20.         return FALSE;
  21. }
  22.  
  23.  
  24. int script_run(char exec[], char args[]) {
  25.     kol_struct70        k70;
  26.     kol_struct_BDVK     bdvk;
  27.     unsigned    result, i;
  28.     unsigned    long long filesize, pos;
  29.     char                *buf; // buffer, where script is copied
  30.  
  31.     k70.p00 = 5;
  32.     k70.p04 = k70.p12 = 0;
  33.     //k70.p08 = 0;
  34.     k70.p16 = (unsigned) &bdvk;
  35.     k70.p20 = 0;
  36.     k70.p21 = exec;
  37.  
  38.     result = kol_file_70(&k70); // get file info
  39.     if ( 0 != result )
  40.         return FALSE;
  41.  
  42.     filesize = bdvk.p32; // get file size
  43.  
  44.     buf = malloc(filesize+256); // may fail for over 4Gb file, but impossible case
  45.     if (NULL == buf)
  46.         return FALSE;
  47.  
  48.     buf[filesize]=0;
  49.  
  50.     k70.p00 = 0;
  51.     k70.p04 = 0;
  52.     //k70.p08 = 0;
  53.     k70.p12 = filesize;
  54.     k70.p16 = (unsigned) buf;
  55.     k70.p20 = 0;
  56.     k70.p21 = exec;
  57.  
  58.     result = kol_file_70(&k70); // read file to the buffer
  59.     if ( 0 != result )
  60.         {
  61.         free(buf);
  62.         return FALSE;
  63.         }
  64.  
  65.     pos = 0;
  66.  
  67.     for (;;) // script processing
  68.     {
  69.         if (pos > filesize)
  70.             break;
  71.  
  72.         for (i=0;;i++) // reading a string
  73.             {
  74.             if ((0x0A == buf[pos])||(0x0D == buf[pos])||(0 == buf[pos]))
  75.                 {
  76.                 pos++;
  77.                 CMD[i] = '\0';
  78.                 break;
  79.                 }
  80.             CMD[i] = buf[pos];
  81.             pos++;
  82.             }
  83.  
  84.         if ( 0 == strlen(CMD) ) // empty string
  85.             continue;
  86.  
  87.         if ('#' == CMD[0]) // comment
  88.             continue;
  89.  
  90.         command_execute();
  91.  
  92.     }
  93.  
  94.     free(buf);
  95.     return TRUE;
  96. }
  97.