+ // SIGINT
+ ctrl_c_action.sa_handler = ctrl_c_handler;
+ sigemptyset (&ctrl_c_action.sa_mask);
+ ctrl_c_action.sa_flags = 0;
+
+ sigaction (SIGINT, &ctrl_c_action, NULL);
+
+ // SIGALRM
+ if (pid != 0) {
+ child_dies_action.sa_handler = child_dies_handler;
+ sigemptyset (&child_dies_action.sa_mask);
+ child_dies_action.sa_flags = 0;
+
+ sigaction (SIGALRM, &child_dies_action, NULL);
+ }
+
+}
+
+int
+opened_parens (char *line, int k)
+{
+ int i;
+ int opened = 0;
+ char c = 0;
+
+ // Choose the corresponding opening bracket
+ if (k == ')') c = '(';
+ else if (k == ']') c = '[';
+ else if (k == '}') c = '{';
+
+ for (i = 0; i < strlen (line); i++) {
+ // Is the current character part of a character literal?
+ if (i + 2 >= strlen (line)
+ && line[i] == '#'
+ && line[i + 1] == '\\')
+ i = i + 2;
+ else if (line[i] == '"') {
+ // Skip over a string literal
+ for (i++; i < strlen (line); i++)
+ if (line[i] == '"'
+ && line[i - 1] != '\\')
+ break;
+ }
+ else if (line[i] == ';') {
+ // Comment until endline
+ break;
+ }
+ else if (line[i] == c)
+ opened++;
+ else if (line[i] == k)
+ opened--;
+ }