/* * Author: jmc * Look for the first occurrence of needle in haystack * Return the substring starting with needle */ char *strstr(const char *haystack, const char *needle) { size_t length = strlen(needle); size_t last = strlen(haystack) - length; size_t x; for (x = 0; x <= last; x++) if (_kstrncmp(&haystack[x], needle, length) == 0) return (char *) &haystack[x]; return NULL; }
void drv_load(void) { if (argc < 2) printf("No driver inserted or bad usage! Type %s --help for the usage.\n", argv[0]); else { if ( (_kstrncmp (argv[1], "-r", 2) == 0) ) { if ( ( argv[2] != NULL ) ) { if (_kstrncmp (argv[2], "mouse", 5) == 0) { printf("Disattivamento %s in corso..\n", argv[2]); mouse_dead(); } else printf("FATAL: Driver %s not found.\n", argv[2]); } else printf("Warning, no driver name inserted!\n"); } // per ora lo impostiamo così, static, // tanto non abbiamo nessun altro modulo, per ora.. else if (_kstrncmp (argv[1], "mouse", 5) == 0) { // enabling mouse mouse_init(); } else if ( (_kstrncmp (argv[1], "--help", 6) == 0) || (_kstrncmp (argv[1], "-h", 2) == 0) ) { printf("---------------------------------------------------\n" "Driver tool to load and kill driver\n" "Simple to use, just type:\n" "\n" "Usage: %s -<options> driver_name\n" "\t-> %s module_name - to load driver\n" "\t-> %s -r module_name - to kill driver\n" "---------------------------------------------------\n" , argv[0], argv[0], argv[0]); } else { if ( (_kstrncmp (argv[1], "-r", 2) == 0) && (_kstrncmp (argv[2], "mouse", 5) == -1) ) printf("FATAL: Driver %s not found.\n", argv[2]); else printf("FATAL: Driver %s not found.\n", argv[1]); } } }
int get_mountpoint_id(char *path) { int i = 0; int last=-1; while(i<MAX_MOUNTPOINT ) { if(!_kstrncmp(path, mountpoint_list[i].mountpoint, strlen(mountpoint_list[i].mountpoint))) { if(strlen(mountpoint_list[i].mountpoint) > strlen(mountpoint_list[last].mountpoint) && i>0) last = i; else if(i==0) last = i; } i++; } //if(last!=-1) printf("Changing dir %s\n", mountpoint_list[last].mountpoint, last); return last; }
void shell() { char cmd[256]; char string[256]; char *user = kmalloc(24); memset(user, 0, strlen(user)); printf(LNG_USER); scanf ("%23s",user); while (!strlen(user)) { printf(LNG_USER); scanf ("%s",user); printf(LNG_USER_R); } _kclear(); aalogo(); printf("\n\n\n\n"); shell_mess = strlen (user) + 3; argc=1; for (;;) { printf("%s~# ",user); scanf("%254s",cmd); options (cmd); if (strcmp(argv[0], "help") == 0) { printf("Available commands:\n"); help(); } else if (strcmp(argv[0], "echo") == 0) { int c; for (c=1; c<argc; c++) printf ("%s ", argv[c]); printf ("\n"); } else if (strcmp(argv[0], "poweroff") == 0) { printf("Poweroff..\n"); poweroff(); } else if (strcmp(argv[0], "clear") == 0) { _kclear(); } else if (strcmp (argv[0], "uname") == 0) { /*if (argv[2] != " ") { memmove(argv[2], argv[2]+6, strlen(argv[2])); }*/ if (!(_kstrncmp(argv[1], "-a", 2)) || !(_kstrncmp(argv[1], "--all", 5))) { printf("%s %s.%s%s #1 CEST 2009 %s\n",NAME,VERSION,PATCHLEVEL,EXTRAVERSION,cpu_vendor); } else if (!(_kstrncmp(argv[1], "-r", 2)) || !(_kstrncmp(argv[1], "--rev", 5))) { printf("%s.%s%s\n",VERSION,PATCHLEVEL,EXTRAVERSION); } else if (!(_kstrncmp(argv[1], "-h", 2) ) || !(_kstrncmp(argv[1], "--help", 6))) { uname_help(); } else if (!(_kstrncmp(argv[1], "-i", 2)) || !(_kstrncmp(argv[1], "--info", 6))) { info(); } if (!(_kstrncmp(argv[1], '\0', 1))) { printf("%s\n" "For more info about this tool, please do 'uname --help'\n",NAME); } } else if (strcmp(argv[0], "cpuid") == 0) { struct cpuinfo_generic *sinfo = get_cpuid(); printf ("----- CPUID Information -----\n"); printf ("Vendor: %s\n", sinfo->cpu_vendor); printf ("Type: %s\n", sinfo->cpu_type); free (sinfo); } else if (strcmp(argv[0], "answer") == 0) { printf("42\n"); outportb('4',0xe9); } else if (strcmp(argv[0], "sleep") == 0) { int s; if (argv[1]) { s = atoi(argv[1]); if (s != -1) sleep (s); } else printf ("Missing operand\n"); } else if (strcmp(argv[0], "kmalloc") == 0) { printf("kmalloc try: ...\n"); int *b; b = (int*) kmalloc(10*sizeof(int)); printf("Address obtained: %d\n", b); int i = 0; while(i<10){ b[i] = i*2; i++; } i=0; while(i<10) { printf("b[%d] = %d\n",i, b[i]); i++; } printf("Address of a: %d\n", b); printf("Navigating used list...\n"); print_heap_list (kheap->used_list); free (b); } else if (strcmp(argv[0], "do_fault") == 0) { printf ("Genero un pagefault scrivendo 10 nella locazione 0xa0000000...\n"); int *prova; prova = (int*)0xa0000000; *prova = 10; printf ("Contenuto della locazione 0xa0000000 dopo l'intervento dell'handler: %d\n", *prova); } /*else if (!(_kstrncmp(cmd,"try_heap",8))){ try_alloc(); } else if (!(_kstrncmp(cmd,"free",4))) { unsigned int ptr = 425548; free((unsigned int*)ptr); ptr = 437836; free((unsigned int*)ptr); ptr=446028; free((unsigned int*)ptr); printf("Navigating used list...\n"); print_heap_list (kheap->used_list); printf("Navigating free list...\n"); print_heap_list (kheap->free_list); printf("Navigating free nodes...\n"); print_heap_list (kheap->free_nodes); }*/ else if (strcmp(argv[0], "printmem") == 0) print_heap_list(kheap->used_list); else if (strcmp(argv[0], "date") == 0) date(); else if (strcmp(argv[0], "aalogo") == 0) aalogo(); else if (strcmp(argv[0], "credits") == 0) { _kcolor('\011'); _kputs("DreamOS Credits\n\n"); _kputs("Main Developers:\n"); _kcolor('\012'); printf("Shainer - Lisa\n" "Finarfin - Ivan\n\n\n" ); _kcolor('\011'); _kputs("Contributors:\n"); _kcolor('\012'); _kputs("Osiris\n" "Celeron\n" "Hamcha\n" "m0nt0\n" "and many others (3 or 4 :P)\n\n"); _kcolor('\007'); } else if (strlen(cmd)>0) { printf(LNG_UNKNOWN_CMD " %s\n", argv[0]); } memset(string+5, 0, strlen(string)); memset(cmd, 0, strlen(cmd)); for (--argc; argc>=0; argc--) { free (argv[argc]); } } }
int strncmp(const char *s1, const char *s2, int n){ return _kstrncmp(s1,s2,n); }