Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #include "all.h"
  3.  
  4. /// ===========================================================
  5.  
  6. int dir_check(char dir[])
  7. /// just checks, if dir[] is really a directory
  8. {
  9. kol_struct70    k70;
  10. int             result;
  11.  
  12. k70.p00 = 1;
  13. k70.p04 = 0;
  14. //k70.p08 = 0;
  15. k70.p12 = 2; // enough to read . & ..
  16. k70.p16 = (unsigned)malloc(32+k70.p12*560);
  17. k70.p20 = 0;
  18. k70.p21 = dir;
  19.  
  20. result = kol_file_70(&k70);
  21.  
  22. free((void*)k70.p16);
  23.  
  24. if ( (0 == result)||(6 == result) )  // 6 is possible ???
  25.         return TRUE;
  26. else
  27.         return FALSE;
  28.  
  29. }
  30.  
  31. /// ===========================================================
  32.  
  33. void dir_truncate(char dir[])
  34. {
  35. int i;
  36. i = strlen(dir)-1;
  37. for (;;i--)
  38.         if ('/' == dir[i])
  39.                 {
  40.                 dir[i+1] = 0;
  41.                 break;
  42.                 }
  43. }
  44.  
  45. /// ===========================================================
  46.  
  47. int file_check(char file[])
  48. {
  49. kol_struct70    k70;
  50. int             result;
  51.  
  52. k70.p00 = 0;
  53. k70.p04 = 0;
  54. //k70.p08 = 0;
  55. k70.p12 = 0;
  56. k70.p16 = 0;
  57. k70.p20 = 0;
  58. k70.p21 = file;
  59.  
  60. result = kol_file_70(&k70);
  61.  
  62. if (0 == result)
  63.         return TRUE;
  64. else
  65.         return FALSE;
  66. }
  67.  
  68. /// ===========================================================
  69.  
  70. void file_not_found(char file[])
  71. {
  72. #if LANG_ENG
  73.         printf ("  File '%s' not found.\n\r", file);
  74. #elif LANG_RUS
  75.         printf ("  ” ©« '%s' ­¥ ­ ©¤¥­.\n\r", file);
  76. #endif
  77. }
  78.  
  79. /// ===========================================================
  80.  
  81. int iswhite(char c)
  82. {
  83. return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c));
  84. }
  85.  
  86. /// ===========================================================
  87.  
  88. void trim(char string[])
  89. {
  90. int i, j;
  91.  
  92. for (i=0; ;i++)
  93.         if ( !iswhite(string[i]) )
  94.                 break;
  95. j = 0;
  96. for (;;i++, j++)
  97.         {
  98.         string[j] = string[i];
  99.         if ('\0' == string[i] )
  100.                 break;
  101.         }
  102.  
  103. for (i=0; ;i++)
  104.         if ('\0' == string[i])
  105.                 break;
  106. i--;
  107. for (;i>0;--i)
  108.         if ( iswhite(string[i]) )
  109.                 string[i] = '\0';
  110.         else
  111.                 break;
  112. }
  113.  
  114. /// ===========================================================
  115.  
  116. void kol_main()
  117. {
  118.  
  119. NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]);
  120.  
  121. strcpy(title, "SHELL ");
  122. strcat(title, SHELL_VERSION);
  123. CONSOLE_INIT(title);
  124.  
  125. if (sizeof (kol_struct70) != 25)
  126. {
  127.         printf("Invalid struct align kol_struct70, need to fix compile options\n\r");
  128.         kol_exit();
  129. }
  130.  
  131.  
  132. strcpy(cur_dir, PATH);
  133. dir_truncate(cur_dir);
  134.  
  135. con_set_cursor_height(con_get_font_height()-1);
  136.  
  137. ALIASES = malloc(128*1024);
  138.  
  139. if (PARAM[0] == 0)
  140. {
  141.    strcpy(CMD, cur_dir);
  142.    strcat(CMD, ".shell");
  143.    if ( !file_check(CMD) )
  144.        strcpy(CMD, "/sys/settings/.shell");
  145. }
  146. else
  147. {
  148.         if (PARAM[0] == '/')
  149.         {
  150.                 strcpy(cur_dir, PARAM);
  151.                 *(strrchr(cur_dir, '/')+1)=0;
  152.         }
  153.         strcpy(CMD, PARAM);
  154. }
  155.  
  156. command_execute();
  157.  
  158. for (;;)
  159.         {
  160.         printf ("# ");
  161.         command_get();
  162.         command_execute();
  163.         }
  164.  
  165. _exit(0);
  166. kol_exit();
  167. }
  168.  
  169. /// ===========================================================
  170.