commands take buf, bad commmands dont segfault

master
bx 2022-04-02 11:59:31 +00:00
parent 5340cd4ef2
commit 39ab7a9055
5 changed files with 11 additions and 6 deletions

View File

@ -1,4 +1,5 @@
void
c_quit() {
c_quit(char *b) {
exit(0);
}

View File

@ -1,3 +1,3 @@
void (*commands[256])() = {
void (*commands[256])(char *) = {
NULL,
['q'] = c_quit,

7
efn.h
View File

@ -1,4 +1,7 @@
extern void (*commands[256])();
#include <stdlib.h>
#include "globals.h"
void c_quit();
extern void (*commands[256])(char *);
void c_quit(char *);

0
globals.h 100644
View File

3
main.c
View File

@ -4,7 +4,8 @@ main(int argc, char **argv) {
while(1) {
char *com = fgets(buf, sizeof(buf), stdin);
if (com != NULL) {
commands[com[0]]();
if (commands[com[0]] != NULL) commands[com[0]](buf);
else puts("invalid command.");
}
}
return 0;