Advertisement
Shiny_

Untitled

Jan 25th, 2021
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include "stdio.h"
  2.  
  3. #define LS 5863588
  4. #define CD 5863276
  5. #define MKDIR 210720772860
  6. #define PWD 193502992
  7.  
  8. const unsigned long hash(const char *str) {
  9.     unsigned long hash = 5381;  
  10.     int c;
  11.  
  12.     while ((c = *str++))
  13.         hash = ((hash << 5) + hash) + c;
  14.     return hash;
  15. }
  16.  
  17. int main(int argc, char *argv[]) {
  18.     char *p_command = argv[1];
  19.     switch(hash(p_command)) {
  20.     case LS:
  21.         printf("Running ls...\n");
  22.         break;
  23.     case CD:
  24.         printf("Running cd...\n");
  25.         break;
  26.     case MKDIR:
  27.         printf("Running mkdir...\n");
  28.         break;
  29.     case PWD:
  30.         printf("Running pwd...\n");
  31.         break;
  32.     default:
  33.         printf("[ERROR] '%s' is not a valid command.\n", p_command);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement