Subversion Repositories Kolibri OS

Rev

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. void get_file_dir_loc(char *filepath, char *dir_path)
  47. {
  48.         char *res = strrchr(filepath, '/');
  49.         if (res == 0)
  50.         {
  51.                 dir_path = '\0';
  52.                 return;
  53.         }
  54.         size_t pos = res - filepath;
  55.         strncpy(dir_path, filepath, pos);
  56.         dir_path[pos] = '\0';
  57. }
  58.  
  59. /// ===========================================================
  60.  
  61. int file_check(char file[])
  62. {
  63. kol_struct70    k70;
  64. int             result;
  65.  
  66. k70.p00 = 0;
  67. k70.p04 = 0;
  68. //k70.p08 = 0;
  69. k70.p12 = 0;
  70. k70.p16 = 0;
  71. k70.p20 = 0;
  72. k70.p21 = file;
  73.  
  74. result = kol_file_70(&k70);
  75.  
  76. if (0 == result)
  77.         return TRUE;
  78. else
  79.         return FALSE;
  80. }
  81.  
  82. /// ===========================================================
  83.  
  84. void file_not_found(char file[])
  85. {
  86. #if LANG_ENG
  87.         printf ("  File '%s' not found.\n\r", file);
  88. #elif LANG_RUS
  89.         printf ("  ” ©« '%s' ­¥ ­ ©¤¥­.\n\r", file);
  90. #endif
  91. }
  92.  
  93. /// ===========================================================
  94.  
  95. int iswhite(char c)
  96. {
  97. return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c));
  98. }
  99.  
  100. /// ===========================================================
  101.  
  102. void trim(char string[])
  103. {
  104. int i, j;
  105.  
  106. for (i=0; ;i++)
  107.         if ( !iswhite(string[i]) )
  108.                 break;
  109. j = 0;
  110. for (;;i++, j++)
  111.         {
  112.         string[j] = string[i];
  113.         if ('\0' == string[i] )
  114.                 break;
  115.         }
  116.  
  117. for (i=0; ;i++)
  118.         if ('\0' == string[i])
  119.                 break;
  120. i--;
  121. for (;i>0;--i)
  122.         if ( iswhite(string[i]) )
  123.                 string[i] = '\0';
  124.         else
  125.                 break;
  126. }
  127.  
  128. /// ===========================================================
  129.  
  130. void kol_main()
  131. {
  132.  
  133. NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]);
  134.  
  135. strcpy(title, "SHELL ");
  136. strcat(title, SHELL_VERSION);
  137. CONSOLE_INIT(title);
  138.  
  139. if (sizeof (kol_struct70) != 25)
  140. {
  141.         printf("Invalid struct align kol_struct70, need to fix compile options\n\r");
  142.         kol_exit();
  143. }
  144.  
  145.  
  146. //strcpy(cur_dir, PATH);
  147. //dir_truncate(cur_dir);
  148. getcwd(cur_dir, sizeof cur_dir);
  149. //printf("curdir %s\n", cur_dir);
  150.  
  151. con_set_cursor_height(con_get_font_height()-1);
  152.  
  153. ALIASES = malloc(128*1024);
  154.  
  155. if (!PARAM || PARAM[0] == 0)
  156. {
  157.    strcpy(CMD, PATH);
  158.    dir_truncate(CMD);
  159.    strcat(CMD, ".shell");
  160.    if ( !file_check(CMD) )
  161.        strcpy(CMD, "/sys/settings/.shell");
  162. }
  163. else
  164. {
  165.         if (PARAM[0] == '/')
  166.         {
  167.                 strcpy(cur_dir, PARAM);
  168.                 *(strrchr(cur_dir, '/')+1)=0;
  169.         }
  170.         strcpy(CMD, PARAM);
  171. }
  172.  
  173. command_execute();
  174.  
  175. for (;;)
  176.         {
  177.         //printf("\033[32;1m");
  178.         printf ("# ");
  179.         //printf("\033[0m");
  180.         command_get();
  181.         command_execute();
  182.         }
  183.  
  184. _exit(0);
  185. kol_exit();
  186. }
  187.  
  188. /// ===========================================================
  189.