aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--README.md7
-rw-r--r--include/all.h13
-rw-r--r--include/handler.h5
-rw-r--r--include/init.h11
-rw-r--r--include/util/io.h4
-rw-r--r--src/handler.cc23
-rw-r--r--src/init.cc22
-rw-r--r--src/main.cc102
-rw-r--r--src/util/io.cc30
10 files changed, 124 insertions, 103 deletions
diff --git a/Makefile b/Makefile
index 66092f8..a81885e 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,10 @@ INCLUDE_DIR = include
BUILD = build
TARGET = $(BUILD)/ccshell
-CPPFLAGS = -I$(INCLUDE_DIR) -MMD -MP
-CXXFLAGS = -std=c++23 -Wall -Wextra -O2
+MAKEFLAGS += -j8
+
+CPPFLAGS = -I$(INCLUDE_DIR) -MMD -MP -flto
+CXXFLAGS = -std=c++23 -Wall -Wextra -O3 -flto
# static
LDFLAGS += -static -static-libgcc -static-libstdc++
@@ -27,4 +29,8 @@ $(BUILD)/%.cc.o: %.cc
clean:
rm -rf $(BUILD)
+fresh:
+ rm -rf $(BUILD)
+ make
+
.PHONY: clean
diff --git a/README.md b/README.md
index fe888a0..f71144e 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,6 @@
-# ccshell \ No newline at end of file
+# ccshell
+
+ignore this test
+```sh
+git update-index --skip-worktree src/test.cc
+```
diff --git a/include/all.h b/include/all.h
new file mode 100644
index 0000000..266735b
--- /dev/null
+++ b/include/all.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "command/builtin.h"
+#include "util/io.h"
+#include "util/string.h"
+#include "eval.h"
+#include "global.h"
+#include "ground.h"
+#include "handler.h"
+#include "init.h"
+#include "job.h"
+#include "parse.h"
+#include "path.h"
diff --git a/include/handler.h b/include/handler.h
index f226387..225fc93 100644
--- a/include/handler.h
+++ b/include/handler.h
@@ -18,7 +18,10 @@
namespace ov4
{
-void init();
+typedef void handler_t(int);
+
+void signal_init();
+handler_t *Signal(int signum, handler_t *handler);
void sigchld_handler(int sig);
void sigint_handler(int sig);
void sigtstp_handler(int sig);
diff --git a/include/init.h b/include/init.h
new file mode 100644
index 0000000..9222a4c
--- /dev/null
+++ b/include/init.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include <iostream>
+#include "all.h"
+
+namespace ov4
+{
+
+void init();
+
+}
diff --git a/include/util/io.h b/include/util/io.h
index 5bdbcbd..22199f3 100644
--- a/include/util/io.h
+++ b/include/util/io.h
@@ -33,4 +33,8 @@ bool isnum(char *s);
void reverse(char str[], int length);
char *itoa(int num, char* str, int base);
+void usage(void);
+void unix_error(char *msg);
+void app_error(char *msg);
+
}
diff --git a/src/handler.cc b/src/handler.cc
index afc1fc1..5356d47 100644
--- a/src/handler.cc
+++ b/src/handler.cc
@@ -6,12 +6,33 @@ namespace ov4
extern char **environ;
sigset_t BLOCK_HANDLER;
-void init()
+void signal_init()
{
sigemptyset(&BLOCK_HANDLER);
sigaddset(&BLOCK_HANDLER, SIGINT);
sigaddset(&BLOCK_HANDLER, SIGTSTP);
sigaddset(&BLOCK_HANDLER, SIGCHLD);
+
+ Signal(SIGINT, sigint_handler); /* ctrl-c */
+ Signal(SIGTSTP, sigtstp_handler); /* ctrl-z */
+ Signal(SIGCHLD, sigchld_handler); /* Terminated or stopped child */
+}
+
+/*
+ * Signal - wrapper for the sigaction function
+ */
+
+handler_t *Signal(int signum, handler_t *handler)
+{
+ struct sigaction action, old_action;
+
+ action.sa_handler = handler;
+ sigemptyset(&action.sa_mask); /* block sigs of type being handled */
+ action.sa_flags = SA_RESTART; /* restart syscalls if possible */
+
+ if (sigaction(signum, &action, &old_action) < 0)
+ unix_error("Signal error");
+ return (old_action.sa_handler);
}
/*
diff --git a/src/init.cc b/src/init.cc
new file mode 100644
index 0000000..06b66e1
--- /dev/null
+++ b/src/init.cc
@@ -0,0 +1,22 @@
+#include "init.h"
+
+namespace ov4
+{
+
+using namespace std;
+
+void init()
+{
+ cout << "\
+You are using ccshell. \n\
+This is free software; see the source for copying conditions. \
+There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n\
+Published under GNU AFFERO GENERAL PUBLIC LICENSE (AGPL) Version 3." << endl;
+
+ signal_init();
+
+
+
+}
+
+}
diff --git a/src/main.cc b/src/main.cc
index d7719b2..f983590 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -11,52 +11,24 @@
#include <vector>
#include <string>
-#include "util/io.h"
-#include "job.h"
-#include "parse.h"
-#include "handler.h"
-#include "ground.h"
-#include "eval.h"
-#include "path.h"
-#include "util/string.h"
+#include "all.h"
#include "test.h"
using namespace std;
using namespace ov4;
-
-
/* Global variables */
char prompt[] = "$ "; /* command line prompt (DO NOT CHANGE) */
char sbuf[MAXLINE]; /* for composing sprintf messages */
-
-
-int builtin_cmd(char *c_str);
-
-
-
-void usage(void);
-void unix_error(char *msg);
-void app_error(char *msg);
-typedef void handler_t(int);
-handler_t *Signal(int signum, handler_t *handler);
-
-// built-in commands
-void builtin_command_quit();
-
/*
* main - The shell's main routine
*/
int main(int argc, char **argv)
{
- cout << "\
-You are using ccshell. \n\
-This is free software; see the source for copying conditions. \
-There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n\
-Published under GNU AFFERO GENERAL PUBLIC LICENSE (AGPL) Version 3." << endl;
+ init();
//test(argv);
- init();
+
char c;
char cmdline[MAXLINE];
int emit_prompt = 1; /* emit prompt (default) */
@@ -84,10 +56,7 @@ Published under GNU AFFERO GENERAL PUBLIC LICENSE (AGPL) Version 3." << endl;
/* Install the signal handlers */
- /* These are the ones you will need to implement */
- Signal(SIGINT, sigint_handler); /* ctrl-c */
- Signal(SIGTSTP, sigtstp_handler); /* ctrl-z */
- Signal(SIGCHLD, sigchld_handler); /* Terminated or stopped child */
+
/* This one provides a clean way to kill the shell */
Signal(SIGQUIT, sigquit_handler);
@@ -119,66 +88,3 @@ Published under GNU AFFERO GENERAL PUBLIC LICENSE (AGPL) Version 3." << endl;
exit(0); /* control never reaches here */
}
-
-
-
-
-
-
-
-
-
-/***********************
- * Other helper routines
- ***********************/
-
-/*
- * usage - print a help message
- */
-void usage(void)
-{
- printf("Usage: shell [-hvp]\n");
- printf(" -h print this message\n");
- printf(" -v print additional diagnostic information\n");
- printf(" -p do not emit a command prompt\n");
- exit(1);
-}
-
-/*
- * unix_error - unix-style error routine
- */
-void unix_error(char *msg)
-{
- fprintf(stdout, "%s: %s\n", msg, strerror(errno));
- exit(1);
-}
-
-/*
- * app_error - application-style error routine
- */
-void app_error(char *msg)
-{
- fprintf(stdout, "%s\n", msg);
- exit(1);
-}
-
-/*
- * Signal - wrapper for the sigaction function
- */
-handler_t *Signal(int signum, handler_t *handler)
-{
- struct sigaction action, old_action;
-
- action.sa_handler = handler;
- sigemptyset(&action.sa_mask); /* block sigs of type being handled */
- action.sa_flags = SA_RESTART; /* restart syscalls if possible */
-
- if (sigaction(signum, &action, &old_action) < 0)
- unix_error("Signal error");
- return (old_action.sa_handler);
-}
-
-
-
-
-
diff --git a/src/util/io.cc b/src/util/io.cc
index 531bd47..1261684 100644
--- a/src/util/io.cc
+++ b/src/util/io.cc
@@ -96,4 +96,34 @@ char *itoa(int num, char* str, int base)
return str;
}
+/*
+ * usage - print a help message
+ */
+void usage(void)
+{
+ printf("Usage: shell [-hvp]\n");
+ printf(" -h print this message\n");
+ printf(" -v print additional diagnostic information\n");
+ printf(" -p do not emit a command prompt\n");
+ exit(1);
+}
+
+/*
+ * unix_error - unix-style error routine
+ */
+void unix_error(char *msg)
+{
+ fprintf(stdout, "%s: %s\n", msg, strerror(errno));
+ exit(1);
+}
+
+/*
+ * app_error - application-style error routine
+ */
+void app_error(char *msg)
+{
+ fprintf(stdout, "%s\n", msg);
+ exit(1);
+}
+
}