YASH 0.1
CLI written in C
Loading...
Searching...
No Matches
yash.h File Reference

Core data structures and constants. More...

#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>

Go to the source code of this file.

Classes

struct  Command
 Represents one command with arguments and redirections. More...
 
struct  Line
 Represents a full line of user input. More...
 

Macros

#define MAX_CMDLINE   2001
 Maximum command line length including null terminator.
 
#define MAX_TOKENS   2000
 Upper bound on number of tokens from max line length.
 
#define MAX_TOKEN_LEN   30
 Maximum length of a single token.
 
#define MAX_ARGS   64
 Reasonable cap on arguments per command.
 
#define MAX_JOBS   20
 Maximum number of jobs to track.
 
#define FILE_CREATE_MODE   (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
 File creation mode.
 

Typedefs

typedef struct Command Command
 Represents one command with arguments and redirections.
 
typedef struct Line Line
 Represents a full line of user input.
 

Enumerations

enum  TokenKind {
  TK_WORD , TK_REDIR_IN , TK_REDIR_OUT , TK_REDIR_ERR ,
  TK_PIPE , TK_AMP
}
 Token kinds. More...
 

Functions

void init_command (Command *cmd)
 Initialize a Command structure to NULL/0 values.
 

Variables

volatile sig_atomic_t child_status_changed
 Flag indicating that a child process status has changed.
 
pid_t foreground_pgid
 Process group ID of the current foreground process.
 

Detailed Description

Core data structures and constants.

Author
Nathan Lemma
Date
09-15-2025

This file contains the core data structures and constants used throughout the YASH shell implementation.

Typedef Documentation

◆ Command

typedef struct Command Command

Represents one command with arguments and redirections.

Invariants:

  • argv is always NULL-terminated.
  • argv[0] must exist for a valid command (cannot be empty).
  • At most one of each redirection (in_file, out_file, err_file) may be set.
  • Redirection fields are either a filename string or NULL.
  • background == 1 is only valid if the containing Line.is_pipeline == 0.
  • argv pointers reference the tokenized input buffer, which must outlive parsing and execution.

◆ Line

typedef struct Line Line

Represents a full line of user input.

Invariants:

  • If is_pipeline == 0: left is valid, right is unused.
  • If is_pipeline == 1: both left and right must have argv[0].
  • Background execution (&) is invalid when is_pipeline == 1.
  • original always contains the raw command line string as typed, including & if present.

Enumeration Type Documentation

◆ TokenKind

enum TokenKind

Token kinds.

Enumerator
TK_WORD 

Identifies = Regular text

TK_REDIR_IN 

Identifies = <

TK_REDIR_OUT 

Identifies = >

TK_REDIR_ERR 

Identifies = 2>

TK_PIPE 

Identifies = |

TK_AMP 

Identifies = &

Function Documentation

◆ init_command()

void init_command ( Command * cmd)

Initialize a Command structure to NULL/0 values.

Parameters
cmdPointer to Command structure to initialize