42sh Wiki

SCL structure

  • Shell introduction
  • Quoting
    • Escape Character (Backslash) \
    • Single-Quotes '
    • Double-Quotes "
  • Token Recognition
    • Alias Substitution
  • Reserved Words
  • Parameters and Variables
    • Positional Parameters
    • Special Parameters
    • Shell Variables
  • Word Expansions
    • Tilde Expansion
    • Parameter Expansion
    • Command Substitution
    • Arithmetic Expansion
    • Field Splitting
    • Pathname Expansion
    • Quote Removal
  • Redirection
    • Redirecting Input
    • Redirecting Output
    • Appending Redirected Output
    • Here-Document
    • Duplicating an Output File Descriptor
    • Open File Descriptors for Reading and Writing
  • Exit Status and Errors
    • Consequences of Shell Errors
    • Exit Status for Commands
  • Shell Commands
    • Simple Commands
    • Pipelines
    • Lists
    • Compound Commands
    • Function Definition Command
  • Shell Grammar
    • Shell Grammar Lexical Conventions
    • Shell Grammar Rules
  • Signals and Error Handling
  • Shell Execution Environment
  • Pattern Matching Notation
    • Patterns Matching a Single Character
    • Patterns Matching Multiple Characters
    • Patterns Used for Filename Expansion
  • Special Built-In Utilities

Tips

1) Utilities

  • tree -I 'venv|build': display all directories execpt venv and build.
  • alias ccg="gcc -Wall -Wextra -Werror -pedantic -std=c99 -g -fsanitize=address -o out"

2) Shell

A) To check if command is POSIX-compliant

  • run bash --posix in terminal.
  • run your command

3) Cmake

A) General

B) Run Pytest

  • First time:
    • Download conftest.py (Renamed if needed) and move it to test folder. (not needed as pierre did it for us)
    • Run python -m venv venv to create env. ( in root of dir)
    • To activate env, run source venv/bin/activate
    • Run pip install pytest pyyaml
    • Run pip install cmake-format (cmake-format -i CMakeLists.txt)
    • To run tests, type pytest
    • Tests are written in a .yaml file (see conftest.py for syntax).
    • To deactivate env, run deactivate
  • Other:
    • To activate env, run source venv/bin/activate
    • To run tests, type pytest
    • To deactivate env, run deactivate

C) Run criterion tests

To run criterion testsuite: ctest --verbose or make check (if implemented).

  • Suppose the following architecture:
├── CMakeLists.txt  (1)
├── src
│   ├── CMakeLists.txt (2)
│   ├── lexer
│   │   ├── CMakeLists.txt (3)
│   │   ├── lexer.c
│   │   ├── lexer.h
│   │   ├── token.c
│   │   └── token.h
└── tests
    └── utests
        ├── CMakeLists.txt (4)
        ├── lexer
        │   └── lexer_1.c
  • In CMakeLists.txt (1), make sure to have:
    • add_subdirectory(src/lexer)
  • In CMakeLists.txt (2), make sure to have:
    • target_link_libraries(42sh PRIVATE ${READLINE_LIB} common_options lexer)
  • In CMakeLists.txt (3), make sure to have:
add_library(lexer STATIC <--- THIS
 lexer.c
 lexer.h
 token.c
 token.h
)

target_include_directories(lexer PUBLIC .) <--- THIS

target_link_libraries(lexer PRIVATE common_options) <--- THIS
  • In CMakeLists.txt (4), make sure to have:
find_library(CRITERION_LIB criterion)

add_executable(test_criterion utests_1.c lexer/lexer_1.c)
                                            ^
                                            `--- THIS
target_link_libraries(test_criterion PRIVATE
    ${CRITERION_LIB}
    common_options
    lexer <-- THIS
)
  • In lexer/lexer_1.c, only need to include #include "token.h"

4) Git

A) .git/config

[core] pager = less -S [alias] tree = log --graph --decorate --pretty=oneline --abbrev-commit
  • git tree: view commit in tree-like view.
  • git config --global pull.rebase true: Enable pull rebase.

B) branching

  • git branch: Display all existing branches.
  • git checkout <branch>: switch branch
  • git checkout -b <branch>: create branch + switch branch
  • git push --set-upstream origin <branch>: Tells git to push to <branch> and not master.

C) Merge

  • git checkout master
  • git pull
  • git merge <name_branch>

5) Debugging

  • In your file test, replace Test(....) by int main(void)
  • Run make debug, an executable named utest_criterion will be created.
  • Run gdb utest_criterion.
  • ALWAYS make clean + rm utest_criterion
    • because the utest_criterion at the root is a copy from the one in test. Thus make clean won't see it.

Valgrind

  • At root, mkdir build/
  • cd build
  • cmake .. -DCMAKE_BUILD_TYPE=Release (This should run version without fsanitize=address)

fsanitize=address

  • At root, mkdir debug/
  • cd debug
  • cmake .. -DCMAKE_BUILD_TYPE=Debug (This should run version with fsanitize=address)

6) Static library linking

  • Use -Wl,--start-group and -Wl,--end-group to stop worrying about libraries ordering.
target_link_libraries(
  utest_criterion
  PRIVATE ${CRITERION_LIB}
          common_options
          "-Wl,--start-group"
          ast
          execution
          option_parser
          parser
          lexer
          data-structure
          utils
          "-Wl,--end-group")

7) Doxygen (manpage)

  • if you want to have acces to manpage from root, use the command : groff -man -Tascii doc/42sh.man | less
  • Updates can and MUST be done, it can be manipulated like a .txt document in vim/emacs.

Miscellaneous

Conferences