Advertisement
0Nera

string problems

Jul 27th, 2021
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1.  
  2. //Код в обработчике клавиатуры:
  3. if(keycode == ENTER_KEY_CODE) {
  4.     tty_putchar('\n');
  5.     shell_exec(string_mem);
  6.     string_mem_counter = 0;
  7.     memset(string_mem, 0, STRING_MEM_MAX);
  8.     tty_setcolor(VGA_COLOR_LIGHT_GREEN);
  9.     tty_printf("\n $");
  10.     tty_setcolor(VGA_COLOR_LIGHT_CYAN);  
  11.     return;  
  12. }
  13.  
  14. //Вот код функции shell_exec:
  15.  
  16. void shell_exec(char *input_command){
  17.     char *help= "help";
  18.     if(strcmp(input_command, help)==0){
  19.         tty_printf("\nSynapseOS is a free and open source 64x operating system written in FASM and C.\nCommands:\n help - info about commands\n sysinfo - system information");
  20.      } else{
  21.         tty_printf("\n[");
  22.         tty_printf(input_command);
  23.         tty_printf("]");
  24.     }
  25. }
  26.  
  27. //Вот моя реализация strcmp:
  28. int strcmp(char *str1, char *str2) {
  29.     return memcmp(str1, str2, strlen(str1) + 1);
  30. }
  31.  
  32. //memcmp:
  33.  
  34. int memcmp(void *mem1, void *mem2, size_t count) {
  35.     char above, below;
  36.     asm("movl %0, %%esi \n movl %1, %%edi \n movl %2, %%ecx \n repe cmpsb"::"a"(mem1),"b"(mem2),"c"(count));
  37.     asm("seta %0 \n setb %1":"=a"(above),"=b"(below));
  38.     return above - below;
  39. }
  40.  
  41. /*
  42. В репозитории много мусора, но я его оставлю на всякий случай
  43. Репозиторий:
  44. https://github.com/Synapse-OS/SynapseOS
  45.  
  46. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement