Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #define LS 5863588
- #define CD 5863276
- #define MKDIR 210720772860
- #define PWD 193502992
- const unsigned long hash(const char *str) {
- unsigned long hash = 5381;
- int c;
- while ((c = *str++))
- hash = ((hash << 5) + hash) + c;
- return hash;
- }
- int main(int argc, char *argv[]) {
- char *p_command = argv[1];
- switch(hash(p_command)) {
- case LS:
- printf("Running ls...\n");
- break;
- case CD:
- printf("Running cd...\n");
- break;
- case MKDIR:
- printf("Running mkdir...\n");
- break;
- case PWD:
- printf("Running pwd...\n");
- break;
- default:
- printf("[ERROR] '%s' is not a valid command.\n", p_command);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement