Subversion Repositories Kolibri OS

Rev

Rev 6857 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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