diff options
| author | Douglas B. Rumbaugh <doug@douglasrumbaugh.com> | 2025-11-02 21:56:58 -0500 |
|---|---|---|
| committer | Douglas B. Rumbaugh <doug@douglasrumbaugh.com> | 2025-11-02 21:56:58 -0500 |
| commit | 26da453832ca90ce22415a59a2aab57ab16cba66 (patch) | |
| tree | f773bf84632158537fc72a9b869cd87066d73946 | |
| parent | f84e64b593c6e6fda9e2a907d25ed99d8742d619 (diff) | |
| download | hush-26da453832ca90ce22415a59a2aab57ab16cba66.tar.gz | |
Comment header + clang tidy
| -rw-r--r-- | include/builtin.h | 8 | ||||
| -rw-r--r-- | include/command.h | 9 | ||||
| -rw-r--r-- | include/config.h | 8 | ||||
| -rw-r--r-- | include/lexer.h | 21 | ||||
| -rw-r--r-- | include/variables.h | 8 | ||||
| -rw-r--r-- | src/builtin.c | 8 | ||||
| -rw-r--r-- | src/command.c | 38 | ||||
| -rw-r--r-- | src/hush.c | 10 | ||||
| -rw-r--r-- | src/lexer.c | 9 | ||||
| -rw-r--r-- | src/variables.c | 11 |
10 files changed, 102 insertions, 28 deletions
diff --git a/include/builtin.h b/include/builtin.h index 1c99ef5..1b6baf2 100644 --- a/include/builtin.h +++ b/include/builtin.h @@ -1,4 +1,12 @@ /* + * include/builtin.h + * + * HUSH builtin commands module + * CISC 301 -- Operating Systems, Project 2 + * + * Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu> + * + * Distributed under the Modified BSD License * */ #ifndef H_HUSH_BUILTIN diff --git a/include/command.h b/include/command.h index 2948aca..502e7e1 100644 --- a/include/command.h +++ b/include/command.h @@ -1,7 +1,14 @@ /* + * include/command.h + * + * Abstractions for parsing commands from tokens and executing them + * CISC 301 -- Operating Systems, Project 2 + * + * Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu> + * + * Distributed under the Modified BSD License * */ - #ifndef H_HUSH_COMMAND #define H_HUSH_COMMAND diff --git a/include/config.h b/include/config.h index 789a1bb..caa5187 100644 --- a/include/config.h +++ b/include/config.h @@ -1,4 +1,12 @@ /* + * include/config.h + * + * Configuration parameters and constants for HUSH + * CISC 301 -- Operating Systems, Project 2 + * + * Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu> + * + * Distributed under the Modified BSD License * */ #ifndef H_HUSH_CONFIG diff --git a/include/lexer.h b/include/lexer.h index bec44a9..cf4cf98 100644 --- a/include/lexer.h +++ b/include/lexer.h @@ -1,15 +1,22 @@ /* - * Header file for the HUSH lexical analysis - * module + * include/lexer.h + * + * HUSH lexical analysis module + * CISC 301 -- Operating Systems, Project 2 + * + * Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu> + * + * Distributed under the Modified BSD License + * */ #ifndef H_HUSH_LEXER #define H_HUSH_LEXER #include <ctype.h> -#include <stdlib.h> -#include <string.h> #include <stdbool.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include "config.h" @@ -31,7 +38,7 @@ typedef struct token { struct token *next; } token; -/* +/* * Accepts a null-terminate string representing * a full command and returns the pointer to the * head of a list of parsed tokens. The provided @@ -47,7 +54,7 @@ typedef struct token { * input string is *not* null-terminated, or if * it has leading or trailing whitespace. */ - + token *parse_command(char *cmdstr); /* @@ -55,7 +62,7 @@ token *parse_command(char *cmdstr); * of parsed tokens and validates that the * tokens are syntactically valid. If the * sequence is valid, NULL will be returned. - * If the sequence is invalid, a pointer to + * If the sequence is invalid, a pointer to * the first invalid token will be returned. */ token *validate_command(token *cmd); diff --git a/include/variables.h b/include/variables.h index 7511690..0df2b65 100644 --- a/include/variables.h +++ b/include/variables.h @@ -1,4 +1,12 @@ /* + * include/variables.h + * + * Local variable storage and access + * CISC 301 -- Operating Systems, Project 2 + * + * Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu> + * + * Distributed under the Modified BSD License * */ #ifndef H_HUSH_VARIABLES diff --git a/src/builtin.c b/src/builtin.c index f22ce33..a357788 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -1,4 +1,12 @@ /* + * src/builtin.c + * + * HUSH builtin commands module + * CISC 301 -- Operating Systems, Project 2 + * + * Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu> + * + * Distributed under the Modified BSD License * */ #include "builtin.h" diff --git a/src/command.c b/src/command.c index 3d63121..34cdf89 100644 --- a/src/command.c +++ b/src/command.c @@ -1,7 +1,14 @@ /* - * + * src/command.c + * + * Abstractions for parsing commands from tokens and executing them + * CISC 301 -- Operating Systems, Project 2 + * + * Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu> + * + * Distributed under the Modified BSD License + * */ - #include "command.h" #include "config.h" #include "lexer.h" @@ -15,7 +22,7 @@ command *create_command() { } cmd->command = NULL; - memset(cmd->args, 0, sizeof(char*)); + memset(cmd->args, 0, sizeof(char *)); cmd->pipe[0] = -1; cmd->pipe[1] = -1; cmd->infile = NULL; @@ -23,7 +30,7 @@ command *create_command() { cmd->pid = -1; cmd->next = NULL; - cmd->prev= NULL; + cmd->prev = NULL; return cmd; } @@ -56,21 +63,22 @@ command *commands_from_tokens(token *parsed_cmdstr, size_t *cnt) { cmd->next->prev = cmd; cmd = cmd->next; } - } return cmd_head; } void print_commands(FILE *file, command *cmds) { - for (command *cmd=cmds; cmd; cmd = cmd->next) { + for (command *cmd = cmds; cmd; cmd = cmd->next) { fprintf(file, "Command: %s\n", cmd->command); fprintf(file, "\t"); - for (size_t i=0; i<MAX_ARGUMENT_CNT; i++) { + for (size_t i = 0; i < MAX_ARGUMENT_CNT; i++) { fprintf(file, "%s ", cmd->args[i]); } - fprintf(file, "\n\tInfile: %s\n\tOutfile: %s\\n\tPid:%d\n", cmd->infile, cmd->outfile, cmd->pid); - fprintf(file, "\tRead Pipe: %d\tWrite Pipe: %d\n", cmd->pipe[0], cmd->pipe[1]); + fprintf(file, "\n\tInfile: %s\n\tOutfile: %s\\n\tPid:%d\n", cmd->infile, + cmd->outfile, cmd->pid); + fprintf(file, "\tRead Pipe: %d\tWrite Pipe: %d\n", cmd->pipe[0], + cmd->pipe[1]); } } @@ -108,8 +116,8 @@ pid_t execute_command(command *cmd) { } if (cmd->outfile && !freopen(cmd->outfile, "w", stdout)) { - perror("Could not open output file"); - exit(EXIT_FAILURE); + perror("Could not open output file"); + exit(EXIT_FAILURE); } else if (cmd->next) { close(cmd->pipe[0]); if (dup2(cmd->pipe[1], STDOUT_FILENO) == -1) { @@ -118,19 +126,19 @@ pid_t execute_command(command *cmd) { } close(cmd->pipe[1]); } - - /* + + /* * NOTE: discarding the const qualifier here is okay because either * 1) exec fails, in which case the process is aborted immediately * 2) exec succeeds, in which case the memory is released immediately * * In either case, the args won't be accessed again. */ - execvp(cmd->command, (char**)cmd->args); + execvp(cmd->command, (char **)cmd->args); perror("Could not run command"); exit(EXIT_FAILURE); - } else if (res < 0) { + } else if (res < 0) { perror("Could not run command"); return -1; } @@ -1,10 +1,16 @@ /* - * hush -- the HU Shell + * src/hush.c * + * HUSH -- The HU Shell * A minimal shell for CISC 301, Operating Systems * + * CISC 301 -- Operating Systems, Project 2 + * + * Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu> + * + * Distributed under the Modified BSD License + * */ - #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/src/lexer.c b/src/lexer.c index 38ae558..86ed597 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1,7 +1,14 @@ /* + * src/lexer.c + * + * HUSH lexical analysis module + * CISC 301 -- Operating Systems, Project 2 + * + * Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu> + * + * Distributed under the Modified BSD License * */ - #include "lexer.h" #include "config.h" diff --git a/src/variables.c b/src/variables.c index c478d9d..b852a11 100644 --- a/src/variables.c +++ b/src/variables.c @@ -1,7 +1,14 @@ -/* +/* + * src/variables.c + * + * Local variable storage and access + * CISC 301 -- Operating Systems, Project 2 + * + * Copyright (C) 2025 Douglas B. Rumbaugh <dbrumbaugh@harrisburgu.edu> + * + * Distributed under the Modified BSD License * */ - #include "variables.h" #include "strmap.h" |