├── .github
└── workflows
│ ├── myed.yml
│ ├── mytar.yml
│ ├── pages.yml
│ ├── src.yml
│ └── unused.yml
├── .gitignore
├── README.md
├── dev
├── README.md
├── check-unused-modules.sh
├── compile_src.sh
├── expand.js
├── expand.sh
├── gitconfig.sh
├── html.sh
├── myed.sh
├── mytar.sh
└── push_md.sh
├── docs
├── index.html
└── vim-tips.html
├── getting-credits
├── 2019
│ ├── assignment-2019-phase-1.txt
│ ├── assignment-2019-phase-2.txt
│ └── tests
│ │ ├── README
│ │ ├── phase-1
│ │ ├── inputfile
│ │ ├── stef-config
│ │ ├── test-001.sh
│ │ ├── test-002.sh
│ │ ├── test-003.sh
│ │ ├── test-004.sh
│ │ ├── test-005.sh
│ │ ├── test-006.sh
│ │ ├── test-007.sh
│ │ ├── test-008.sh
│ │ ├── test-009.sh
│ │ ├── test-010.sh
│ │ ├── test-011.sh
│ │ ├── test-012.sh
│ │ ├── test-013.sh
│ │ ├── test-014.sh
│ │ ├── test-015.sh
│ │ ├── test-016.sh
│ │ ├── test-017.sh
│ │ ├── test-018.sh
│ │ ├── test-019.sh
│ │ ├── test-020.sh
│ │ ├── test-021.sh
│ │ ├── test-022.sh
│ │ ├── test-023.sh
│ │ ├── test-024.sh
│ │ ├── test-025.sh
│ │ ├── test-026.sh
│ │ ├── test-output-001.txt
│ │ ├── test-output-002.txt
│ │ ├── test-output-003.txt
│ │ ├── test-output-004.txt
│ │ ├── test-output-005.txt
│ │ ├── test-output-006.txt
│ │ ├── test-output-007.txt
│ │ ├── test-output-008.txt
│ │ ├── test-output-009.txt
│ │ ├── test-output-010.txt
│ │ ├── test-output-011.txt
│ │ ├── test-output-012.txt
│ │ ├── test-output-013.txt
│ │ ├── test-output-014.txt
│ │ ├── test-output-015.txt
│ │ ├── test-output-016.txt
│ │ ├── test-output-017.txt
│ │ ├── test-output-018.txt
│ │ ├── test-output-019.txt
│ │ ├── test-output-020.txt
│ │ ├── test-output-021.txt
│ │ ├── test-output-022.txt
│ │ ├── test-output-023.txt
│ │ ├── test-output-025.txt
│ │ └── test-output-026.txt
│ │ └── phase-2
│ │ ├── README
│ │ ├── inputfile
│ │ ├── stef-config
│ │ ├── test-009.sh
│ │ ├── test-010.sh
│ │ ├── test-017.sh
│ │ ├── test-024.sh
│ │ ├── test-026.sh
│ │ ├── test-027.sh
│ │ ├── test-028.sh
│ │ ├── test-029.sh
│ │ ├── test-030.sh
│ │ ├── test-031.sh
│ │ ├── test-032.sh
│ │ ├── test-output-009.txt
│ │ ├── test-output-010.txt
│ │ ├── test-output-017.txt
│ │ ├── test-output-024.txt
│ │ ├── test-output-026.txt
│ │ ├── test-output-027.txt
│ │ ├── test-output-028.txt
│ │ ├── test-output-029.txt
│ │ ├── test-output-030.txt
│ │ ├── test-output-031.txt
│ │ └── test-output-032.txt
├── 2020
│ ├── assignment.txt
│ └── tests
│ │ ├── .gitignore
│ │ ├── README
│ │ ├── configure.sh
│ │ ├── phase-1.tests
│ │ ├── run-tests.sh
│ │ ├── stef-config
│ │ ├── test-001.sh
│ │ ├── test-002.sh
│ │ ├── test-003.sh
│ │ ├── test-004.sh
│ │ ├── test-005.sh
│ │ ├── test-006.sh
│ │ ├── test-007.sh
│ │ ├── test-008.sh
│ │ ├── test-009.sh
│ │ ├── test-011.sh
│ │ ├── test-012.sh
│ │ ├── test-013.sh
│ │ ├── test-014.sh
│ │ ├── test-015.sh
│ │ ├── test-016.sh
│ │ ├── test-017.sh
│ │ ├── test-018.sh
│ │ ├── test-019.sh
│ │ ├── test-020.sh
│ │ ├── test-021.sh
│ │ ├── test-022.sh
│ │ ├── test-023.sh
│ │ ├── test-024.sh
│ │ ├── test-025.sh
│ │ ├── test-026.sh
│ │ ├── test-027.sh
│ │ ├── test-028.sh
│ │ ├── test-029.sh
│ │ ├── test-030.sh
│ │ ├── test-031.sh
│ │ ├── test-output-002.txt
│ │ ├── test-output-003.txt
│ │ ├── test-output-004.txt
│ │ ├── test-output-005.txt
│ │ ├── test-output-006.txt
│ │ ├── test-output-007.txt
│ │ ├── test-output-011.txt
│ │ ├── test-output-013.txt
│ │ ├── test-output-014.txt
│ │ ├── test-output-015.txt
│ │ ├── test-output-016.txt
│ │ ├── test-output-017.txt
│ │ ├── test-output-018.txt
│ │ ├── test-output-019.txt
│ │ ├── test-output-021.txt
│ │ ├── test-output-022.txt
│ │ ├── test-output-024.txt
│ │ ├── test-output-025.txt
│ │ ├── test-output-027.txt
│ │ ├── test-output-028.txt
│ │ ├── test-output-029.txt
│ │ └── unconfigure.sh
├── 2021
│ ├── assignment.txt
│ └── tests
│ │ ├── README
│ │ ├── configure.sh
│ │ ├── phase-1.tests
│ │ ├── run-tests.sh
│ │ ├── stef-config
│ │ ├── test-001.sh
│ │ ├── test-002.sh
│ │ ├── test-003.sh
│ │ ├── test-004.sh
│ │ ├── test-005.sh
│ │ ├── test-006.sh
│ │ ├── test-007.sh
│ │ ├── test-008.sh
│ │ ├── test-009.sh
│ │ ├── test-011.sh
│ │ ├── test-012.sh
│ │ ├── test-013.sh
│ │ ├── test-014.sh
│ │ ├── test-015.sh
│ │ ├── test-016.sh
│ │ ├── test-017.sh
│ │ ├── test-018.sh
│ │ ├── test-019.sh
│ │ ├── test-020.sh
│ │ ├── test-021.sh
│ │ ├── test-022.sh
│ │ ├── test-023.sh
│ │ ├── test-024.sh
│ │ ├── test-025.sh
│ │ ├── test-026.sh
│ │ ├── test-027.sh
│ │ ├── test-028.sh
│ │ ├── test-029.sh
│ │ ├── test-030.sh
│ │ ├── test-031.sh
│ │ ├── test-output-002.txt
│ │ ├── test-output-003.txt
│ │ ├── test-output-004.txt
│ │ ├── test-output-005.txt
│ │ ├── test-output-006.txt
│ │ ├── test-output-007.txt
│ │ ├── test-output-011.txt
│ │ ├── test-output-013.txt
│ │ ├── test-output-014.txt
│ │ ├── test-output-015.txt
│ │ ├── test-output-016.txt
│ │ ├── test-output-017.txt
│ │ ├── test-output-018.txt
│ │ ├── test-output-019.txt
│ │ ├── test-output-021.txt
│ │ ├── test-output-022.txt
│ │ ├── test-output-024.txt
│ │ ├── test-output-025.txt
│ │ ├── test-output-027.txt
│ │ ├── test-output-028.txt
│ │ ├── test-output-029.txt
│ │ └── unconfigure.sh
├── 2022
│ ├── assignment.txt
│ └── tests
│ │ ├── README
│ │ ├── config.var
│ │ ├── configure.sh
│ │ ├── phase-1.tests
│ │ ├── run-tests.sh
│ │ ├── stef-config
│ │ ├── test-001.sh
│ │ ├── test-002.sh
│ │ ├── test-003.sh
│ │ ├── test-004.sh
│ │ ├── test-005.sh
│ │ ├── test-006.sh
│ │ ├── test-007.sh
│ │ ├── test-008.sh
│ │ ├── test-009.sh
│ │ ├── test-011.sh
│ │ ├── test-012.sh
│ │ ├── test-013.sh
│ │ ├── test-014.sh
│ │ ├── test-015.sh
│ │ ├── test-016.sh
│ │ ├── test-017.sh
│ │ ├── test-018.sh
│ │ ├── test-019.sh
│ │ ├── test-020.sh
│ │ ├── test-021.sh
│ │ ├── test-022.sh
│ │ ├── test-023.sh
│ │ ├── test-024.sh
│ │ ├── test-025.sh
│ │ ├── test-026.sh
│ │ ├── test-027.sh
│ │ ├── test-028.sh
│ │ ├── test-029.sh
│ │ ├── test-030.sh
│ │ ├── test-031.sh
│ │ ├── test-output-002.txt
│ │ ├── test-output-003.txt
│ │ ├── test-output-004.txt
│ │ ├── test-output-005.txt
│ │ ├── test-output-006.txt
│ │ ├── test-output-007.txt
│ │ ├── test-output-011.txt
│ │ ├── test-output-013.txt
│ │ ├── test-output-014.txt
│ │ ├── test-output-015.txt
│ │ ├── test-output-016.txt
│ │ ├── test-output-017.txt
│ │ ├── test-output-018.txt
│ │ ├── test-output-019.txt
│ │ ├── test-output-021.txt
│ │ ├── test-output-022.txt
│ │ ├── test-output-024.txt
│ │ ├── test-output-025.txt
│ │ ├── test-output-027.txt
│ │ ├── test-output-028.txt
│ │ ├── test-output-029.txt
│ │ └── unconfigure.sh
├── 2023
│ ├── assignment.txt
│ └── tests
│ │ ├── README
│ │ ├── config.var
│ │ ├── configure.sh
│ │ ├── phase-1.tests
│ │ ├── run-tests.sh
│ │ ├── stef-config
│ │ ├── test-001.sh
│ │ ├── test-002.sh
│ │ ├── test-003.sh
│ │ ├── test-004.sh
│ │ ├── test-005.sh
│ │ ├── test-006.sh
│ │ ├── test-007.sh
│ │ ├── test-008.sh
│ │ ├── test-009.sh
│ │ ├── test-011.sh
│ │ ├── test-012.sh
│ │ ├── test-013.sh
│ │ ├── test-014.sh
│ │ ├── test-015.sh
│ │ ├── test-016.sh
│ │ ├── test-017.sh
│ │ ├── test-018.sh
│ │ ├── test-019.sh
│ │ ├── test-020.sh
│ │ ├── test-021.sh
│ │ ├── test-022.sh
│ │ ├── test-023.sh
│ │ ├── test-024.sh
│ │ ├── test-025.sh
│ │ ├── test-026.sh
│ │ ├── test-027.sh
│ │ ├── test-028.sh
│ │ ├── test-029.sh
│ │ ├── test-030.sh
│ │ ├── test-031.sh
│ │ ├── test-output-002.txt
│ │ ├── test-output-003.txt
│ │ ├── test-output-004.txt
│ │ ├── test-output-005.txt
│ │ ├── test-output-006.txt
│ │ ├── test-output-007.txt
│ │ ├── test-output-011.txt
│ │ ├── test-output-013.txt
│ │ ├── test-output-014.txt
│ │ ├── test-output-015.txt
│ │ ├── test-output-016.txt
│ │ ├── test-output-017.txt
│ │ ├── test-output-018.txt
│ │ ├── test-output-019.txt
│ │ ├── test-output-021.txt
│ │ ├── test-output-022.txt
│ │ ├── test-output-024.txt
│ │ ├── test-output-025.txt
│ │ ├── test-output-027.txt
│ │ ├── test-output-028.txt
│ │ ├── test-output-029.txt
│ │ └── unconfigure.sh
├── 2024
│ ├── assignment.txt
│ └── tests
│ │ ├── README
│ │ ├── configure.sh
│ │ ├── phase-1.tests
│ │ ├── run-tests.sh
│ │ ├── stef-config
│ │ ├── test-001.sh
│ │ ├── test-002.sh
│ │ ├── test-003.sh
│ │ ├── test-004.sh
│ │ ├── test-005.sh
│ │ ├── test-006.sh
│ │ ├── test-007.sh
│ │ ├── test-008.sh
│ │ ├── test-009.sh
│ │ ├── test-011.sh
│ │ ├── test-012.sh
│ │ ├── test-013.sh
│ │ ├── test-014.sh
│ │ ├── test-015.sh
│ │ ├── test-016.sh
│ │ ├── test-017.sh
│ │ ├── test-018.sh
│ │ ├── test-019.sh
│ │ ├── test-020.sh
│ │ ├── test-021.sh
│ │ ├── test-022.sh
│ │ ├── test-023.sh
│ │ ├── test-024.sh
│ │ ├── test-025.sh
│ │ ├── test-026.sh
│ │ ├── test-027.sh
│ │ ├── test-028.sh
│ │ ├── test-029.sh
│ │ ├── test-030.sh
│ │ ├── test-031.sh
│ │ ├── test-output-002.txt
│ │ ├── test-output-003.txt
│ │ ├── test-output-004.txt
│ │ ├── test-output-005.txt
│ │ ├── test-output-006.txt
│ │ ├── test-output-007.txt
│ │ ├── test-output-011.txt
│ │ ├── test-output-013.txt
│ │ ├── test-output-014.txt
│ │ ├── test-output-015.txt
│ │ ├── test-output-016.txt
│ │ ├── test-output-017.txt
│ │ ├── test-output-018.txt
│ │ ├── test-output-019.txt
│ │ ├── test-output-021.txt
│ │ ├── test-output-022.txt
│ │ ├── test-output-024.txt
│ │ ├── test-output-025.txt
│ │ ├── test-output-027.txt
│ │ ├── test-output-028.txt
│ │ ├── test-output-029.txt
│ │ └── unconfigure.sh
└── 2025
│ ├── assignment.txt
│ └── tests
│ ├── README
│ ├── configure.sh
│ ├── phase-1.tests
│ ├── run-tests.sh
│ ├── stef-config
│ ├── test-001.sh
│ ├── test-002.sh
│ ├── test-003.sh
│ ├── test-004.sh
│ ├── test-005.sh
│ ├── test-006.sh
│ ├── test-007.sh
│ ├── test-008.sh
│ ├── test-009.sh
│ ├── test-011.sh
│ ├── test-012.sh
│ ├── test-013.sh
│ ├── test-014.sh
│ ├── test-015.sh
│ ├── test-016.sh
│ ├── test-017.sh
│ ├── test-018.sh
│ ├── test-019.sh
│ ├── test-020.sh
│ ├── test-021.sh
│ ├── test-022.sh
│ ├── test-023.sh
│ ├── test-024.sh
│ ├── test-025.sh
│ ├── test-026.sh
│ ├── test-027.sh
│ ├── test-028.sh
│ ├── test-029.sh
│ ├── test-030.sh
│ ├── test-031.sh
│ ├── test-032.sh
│ ├── test-output-002.txt
│ ├── test-output-003.txt
│ ├── test-output-004.txt
│ ├── test-output-005.txt
│ ├── test-output-006.txt
│ ├── test-output-007.txt
│ ├── test-output-011.txt
│ ├── test-output-013.txt
│ ├── test-output-014.txt
│ ├── test-output-015.txt
│ ├── test-output-016.txt
│ ├── test-output-017.txt
│ ├── test-output-018.txt
│ ├── test-output-019.txt
│ ├── test-output-021.txt
│ ├── test-output-022.txt
│ ├── test-output-024.txt
│ ├── test-output-025.txt
│ ├── test-output-027.txt
│ ├── test-output-028.txt
│ ├── test-output-029.txt
│ └── unconfigure.sh
├── input
├── 2020
│ ├── 01.json
│ ├── 01.md
│ ├── 02.json
│ ├── 02.md
│ ├── 03.json
│ ├── 03.md
│ ├── 04.json
│ ├── 04.md
│ ├── 05.json
│ ├── 05.md
│ ├── 06.json
│ ├── 06.md
│ ├── 07.json
│ ├── 07.md
│ ├── 08.json
│ ├── 08.md
│ ├── 09.json
│ ├── 09.md
│ ├── 10.json
│ ├── 10.md
│ ├── 11.json
│ ├── 11.md
│ ├── 12.json
│ ├── 12.md
│ ├── 13.json
│ └── 13.md
├── 2021
│ ├── 01.json
│ ├── 01.md
│ ├── 02.json
│ ├── 02.md
│ ├── 03.json
│ ├── 03.md
│ ├── 04.json
│ ├── 04.md
│ ├── 05.json
│ ├── 05.md
│ ├── 06.json
│ ├── 06.md
│ ├── 07.json
│ ├── 07.md
│ ├── 08.json
│ ├── 08.md
│ ├── 09.json
│ ├── 09.md
│ ├── 10.json
│ ├── 10.md
│ ├── 11.json
│ ├── 11.md
│ ├── 12.json
│ ├── 12.md
│ ├── 13.json
│ ├── 13.md
│ └── overflow.md
├── 2022
│ ├── 01.json
│ ├── 01.md
│ ├── 02.json
│ ├── 02.md
│ ├── 03.json
│ ├── 03.md
│ ├── 04.json
│ ├── 04.md
│ ├── 05.json
│ ├── 05.md
│ ├── 06.json
│ ├── 06.md
│ ├── 07.json
│ ├── 07.md
│ ├── 08.json
│ ├── 08.md
│ ├── 09.json
│ ├── 09.md
│ ├── 10.json
│ ├── 10.md
│ ├── 11.json
│ ├── 11.md
│ ├── 12.json
│ ├── 12.md
│ ├── 13.json
│ ├── 13.md
│ ├── debugging.json
│ └── debugging.md
├── 2023
│ ├── 01.json
│ ├── 01.md
│ ├── 02.json
│ ├── 02.md
│ ├── 03.json
│ ├── 03.md
│ ├── 04.json
│ ├── 04.md
│ ├── 05.json
│ ├── 05.md
│ ├── 06.json
│ ├── 06.md
│ ├── 07.json
│ ├── 07.md
│ ├── 08.json
│ ├── 08.md
│ ├── 09.json
│ ├── 09.md
│ ├── 10.json
│ ├── 10.md
│ ├── 11.json
│ ├── 11.md
│ ├── 12.json
│ └── 12.md
├── 2024
│ ├── 01.json
│ ├── 01.md
│ ├── 02.json
│ ├── 02.md
│ ├── 03.json
│ ├── 03.md
│ ├── 04.json
│ ├── 04.md
│ ├── 05.json
│ ├── 05.md
│ ├── 06.json
│ ├── 06.md
│ ├── 07.json
│ ├── 07.md
│ ├── 08.json
│ ├── 08.md
│ ├── 09.json
│ ├── 09.md
│ ├── 10.json
│ ├── 10.md
│ ├── 11.json
│ ├── 11.md
│ ├── 12.json
│ └── 12.md
└── 2025
│ ├── 01.json
│ ├── 01.md
│ ├── 02.json
│ ├── 02.md
│ ├── 03.json
│ ├── 03.md
│ ├── 04.json
│ ├── 04.md
│ ├── 05.json
│ ├── 05.md
│ ├── 06.json
│ ├── 06.md
│ ├── 07.json
│ ├── 07.md
│ ├── 08.json
│ ├── 08.md
│ ├── 09.json
│ ├── 09.md
│ ├── 10.json
│ ├── 10.md
│ ├── 11.json
│ ├── 11.md
│ ├── 12.json
│ ├── 12.md
│ ├── 13.json
│ └── 13.md
├── modules
├── 2d-array-init.md
├── arithmetic-promotion-and-conversions.md
├── arithmetic-type-conversions.md
├── array-intro.md
├── array-of-pointers.md
├── arrays-and-functions-2.md
├── arrays-and-functions.md
├── arrays-and-pointers.md
├── arrays-as-function-arguments.md
├── assert.md
├── basics.md
├── bintree.md
├── bitwise-operations.md
├── bitwise-vs-logical.md
├── boolean.md
├── break.md
├── building-with-specific-c-ver.md
├── c99-standard.md
├── calling-by-value-and-reference.md
├── changing-pointers-in-fn.md
├── comma-operator.md
├── comments.md
├── common-mistakes-defines.md
├── compiler-warnings.md
├── compound-statement-within-expression.md
├── const.md
├── debug-prints.md
├── debugger.md
├── dynamic-allocation.md
├── dynamic-analysis.md
├── dynamic-tracing.md
├── enum.md
├── err.md
├── explicit-type-conversion.md
├── expressions-intro.md
├── expressions.md
├── file-API.md
├── first-class-objective.md
├── flexible-array-member.md
├── for-loop.md
├── freestanding-environment.md
├── function-arguments.md
├── function-intro.md
├── function-pointers.md
├── function-retval-vs-ABI.md
├── getchar.md
├── goto.md
├── heap-memory-woes.md
├── hello-world.md
├── home-assignments
│ ├── animal-sorting.md
│ ├── animals.md
│ ├── bytecnt2str.md
│ ├── conway-1d.md
│ ├── count-digit-occurence.md
│ ├── count-digit-occurence2.md
│ ├── count-digits-whitespace-and-the-rest.md
│ ├── count-letter-occurence.md
│ ├── dirtree.md
│ ├── file-of-ints.md
│ ├── file-read.md
│ ├── get-bits.md
│ ├── home-assignment-section.md
│ ├── linked-list2.md
│ ├── mountain-generator.md
│ ├── mygetopt.md
│ ├── offset-checker.md
│ ├── pointers.md
│ ├── string-to-array-copy.md
│ └── toupper.md
├── incomplete-type.md
├── integer-literals.md
├── integer-overflow.md
├── integer-to-unsigned-integer-c89.md
├── intro.md
├── library-tracing.md
├── linkage.md
├── linked-list.md
├── linking.md
├── moving-star.md
├── multi-dimensional-arrays.md
├── namespace.md
├── negative-numbers.md
├── numbers.md
├── opaque-structures.md
├── operator-precedence.md
├── operators.md
├── pointer-addressing.md
├── pointer-size.md
├── pointer-to-pointer.md
├── pointers.md
├── preprocessor.md
├── program-arguments.md
├── rank.md
├── reading-complex-declarations.md
├── scm.md
├── scope.md
├── side-effect.md
├── sizeof.md
├── statements.md
├── static-analysis.md
├── static-functions-and-variables.md
├── storage-classes.md
├── string-length.md
├── string.md
├── strings-and-arrays.md
├── strings-and-string-constants.md
├── structure-bit-fields.md
├── structure-casting.md
├── structures.md
├── switch.md
├── syscall-tracing.md
├── ternary-operator-quiz.md
├── ternary-operator.md
├── the-last-comma.md
├── transparent-handles.md
├── typedef.md
├── types-of-behavior.md
├── undefined-behavior.md
├── unions.md
├── valid-pointer-operations.md
├── variable-argument-functions.md
└── warm-up
│ ├── 3d-as-1d.md
│ ├── altbits.md
│ ├── binary-numbits.md
│ ├── binary-tree
│ └── basis.md
│ ├── bitdiff.md
│ ├── circle.md
│ ├── count-words.md
│ ├── dragon.md
│ ├── ell-in-cm.md
│ ├── grep.md
│ ├── print-binary.md
│ ├── strcmp.md
│ ├── string.md
│ ├── strsepc.md
│ ├── toupper-redux.md
│ ├── tr-redux.md
│ └── tr.md
├── posters
├── c-prog-lang--poster-CR-2023.pdf
├── c-prog-lang--poster-CR-2023.roff
├── c-prog-lang--poster-CR-2024.pdf
├── c-prog-lang--poster-CR-2024.roff
├── c-prog-lang--poster-CR-2025.pdf
└── c-prog-lang--poster-CR-2025.roff
├── src
├── 2d-static-array-initialization.c
├── 3d-array.c
├── Makefile
├── allocate-2d-array.c
├── argv-as-2d-array.c
├── argv-concat-nofree.c
├── arithmetics.c
├── arithmetics2.c
├── array-as-argument.c
├── array-char-nozero.c
├── array-designated-initializers.c
├── array-fill.c
├── array-fill2.c
├── array-init-func.c
├── array-literal.c
├── array-notation-with-ptr.c
├── array-of-ptrs.c
├── array-out-of-bounds.c
├── array-partial-init.c
├── array-var-not-modifiable.c
├── array-variable-length.c
├── assert.c
├── bitfield-bitwise-ops.c
├── bitfield-wraparound.c
├── bitfield.c
├── bitwise-vs-logical.c
├── block-static-object.c
├── bool.c
├── buf-overflow-func.c
├── buf-overflow.c
├── bus-error.c
├── bytecnt2str.c
├── cast-double.c
├── cast-intptr.c
├── char.c
├── check-c-version.c
├── circle-simplified.c
├── circle.c
├── comma.c
├── common-mistake-with-define.c
├── complex-declaration.c
├── compound-statement-invalid.c
├── compound-statement.c
├── const-and-pointers.c
├── const-not-really-a-const.c
├── const.c
├── conv-and-prom-with-bitwise-ops.c
├── conway-1d-30.c
├── count-numbers-array.c
├── count-numbers.c
├── crashme.c
├── declaration.c
├── derived-types.c
├── divbyzero.c
├── divminus.c
├── ell-in-cm.c
├── empty-array.c
├── enum-values.c
├── enums.c
├── err.c
├── errx.c
├── expression-statement.c
├── ext.c
├── fahr-to-cent.c
├── fear-of-goto.c
├── file-open.c
├── flexible-array-member.c
├── float-precision.c
├── float.c
├── fmt-string-invalid.c
├── fn-ptr.c
├── fn-static-object.c
├── fopen-binary.c
├── for.c
├── fscanf.c
├── func-implicit.c
├── func-large-array.c
├── hello-world1.c
├── hello-world2.c
├── identifier-namespace.c
├── if.c
├── inches-to-cm.c
├── inches-to-cm2.c
├── init-array-from-string.c
├── int-overflow.c
├── int-to-ptr.c
├── int-uint-cast.c
├── integer-conversion-assignment.c
├── integer-conversion.c
├── left-right-shift.c
├── lgamma.c
├── linkage.c
├── linked-list.c
├── math.c
├── missing-comma-in-initializer.c
├── mountain-generator.c
├── moving-star.c
├── mul.c
├── mult.c
├── my-assert.c
├── no-return.c
├── not-one.c
├── null-statement.c
├── objs
│ ├── .ignore
│ ├── solutions
│ │ └── .ignore
│ └── tasks
│ │ └── .ignore
├── opaque-consumer.c
├── opaque.c
├── opaque.h
├── opaque_impl.h
├── operator.c
├── passing-arrays.c
├── plus-deref-plus-argv.c
├── plus-deref-plus-deref-argv.c
├── pointer-to-array-type-difference.c
├── print-argv.c
├── print-int-as-double.c
├── printf-format.c
├── printf-width-and-precision.c
├── printf.c
├── printf2.c
├── ptr-cast.c
├── ptr-change.c
├── ptr-inc.c
├── ptr-lvalue.c
├── ptr-ptr-array.c
├── ptr-recap.c
├── ptr-to-array-of-ptrs.c
├── ptr-with-array-notation.c
├── ptr_plus_plus.c
├── random.c
├── range-check.c
├── read-binary.c
├── read-file.c
├── read-file2.c
├── recurs.c
├── recursive-fn.c
├── recursive-fn2.c
├── request-c99.c
├── return-1.c
├── return.c
├── sequence-point-violation.c
├── shadow-block.c
├── shadow.c
├── shell.c
├── signed-plus-unsigned.c
├── signed-to-unsigned.c
├── solutions
│ ├── 2d-array-max.c
│ ├── 2d-array.c
│ ├── 2d-static-array-as-1d.c
│ ├── 2darray-min-avg.c
│ ├── 3max.c
│ ├── allocate-and-fill-out-array.c
│ ├── altbits.c
│ ├── animal-sort.c
│ ├── animal.h
│ ├── animal_maxlegs.c
│ ├── animal_maxlegs.h
│ ├── animal_minlegs.c
│ ├── animal_minlegs.h
│ ├── animals.h
│ ├── argv-char-dist.c
│ ├── argv-concat.c
│ ├── argv-do-while.c
│ ├── argv-for-v2.c
│ ├── argv-for.c
│ ├── argv-nodash.c
│ ├── argv-nr.c
│ ├── argv-sort.c
│ ├── argv-while-v2.c
│ ├── argv-while.c
│ ├── ascii-hex.c
│ ├── bitdiff.c
│ ├── count-1-bits.c
│ ├── create-string.c
│ ├── dirtree.c
│ ├── fahr-to-cent_defines.c
│ ├── file-AZ.c
│ ├── file-copy.c
│ ├── fopen-leak.c
│ ├── getchar.c
│ ├── int-promotion.c
│ ├── linked-list-free.c
│ ├── maxlegs.c
│ ├── null-ptr.c
│ ├── numchars-for-binary.c
│ ├── offsetof.c
│ ├── print-argv-recursively.c
│ ├── print-ascii-table-subset.c
│ ├── print-in-binary.c
│ ├── ptr-basics.c
│ ├── ptr-diff.c
│ ├── stdarg.c
│ ├── strcmp.c
│ ├── struct-access-ptr.c
│ ├── struct-access.c
│ ├── struct-animals.c
│ ├── struct-op-precedence.c
│ ├── swap-by-reference.c
│ ├── toupper-ternary.c
│ ├── tr.c
│ ├── union-lowhigh.c
│ └── usage.c
├── static_assert.c
├── string-format.c
├── string-isempty.c
├── string-literal-address.c
├── string-literal-write.c
├── string.c
├── strsep.c
├── strsepc.c
├── struct-X.c
├── struct-anon.c
├── struct-common.c
├── struct-decl.c
├── struct-designated-init.c
├── struct-foo.c
├── struct-in-union.c
├── struct-init.c
├── struct-reference.c
├── struct-unnamed.c
├── swap-by-value.c
├── switch.c
├── tasks
│ ├── string-to-array-copy-solution.c
│ └── string-to-array-copy.c
├── ternary-assign.c
├── ternary.c
├── to-upper.c
├── toupper-table.c
├── toupper.c
├── tr-d-chars.c
├── typedef.c
├── uintptr.c
├── union-in-struct.c
├── unsigned-overflow.c
├── use-after-free.c
├── while.c
├── whole-array.c
├── why-it-works.c
├── words.c
├── words2.c
├── wrong-modifier.c
└── x86-ABI.c
└── style.md
/.github/workflows/unused.yml:
--------------------------------------------------------------------------------
1 | name: Check unused modules
2 | on:
3 | push:
4 | branches:
5 | - master
6 | paths:
7 | - modules/**
8 | - input/**
9 | - dev/check-unused-modules.sh
10 | - .github/workflows/unused.yml
11 | jobs:
12 | job1:
13 | name: unused module check
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout master branch
17 | uses: actions/checkout@v4
18 | - name: Check unused modules
19 | run: ./dev/check-unused-modules.sh
20 |
--------------------------------------------------------------------------------
/dev/compile_src.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | cd src
6 | make
7 |
--------------------------------------------------------------------------------
/dev/gitconfig.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -ex
4 |
5 | git config --global user.email "vlada@kotalovi.cz"
6 | git config --global user.name "Vladimir Kotal"
7 |
--------------------------------------------------------------------------------
/dev/myed.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | export STEF="$GITHUB_WORKSPACE/stef/stef.sh"
6 | export ED=/bin/ed
7 |
8 | cd getting-credits/2019/tests
9 | for phase in phase-1 phase-2; do
10 | cd $phase
11 | $STEF
12 | cd -
13 | done
14 |
--------------------------------------------------------------------------------
/dev/mytar.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 |
5 | export STEF="$GITHUB_WORKSPACE/stef/stef.sh"
6 |
7 | export GNUTAR=/bin/tar
8 | export MYGNUTAR=$GNUTAR
9 |
10 | cd getting-credits/2020/tests
11 | ./run-tests.sh
12 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/stef-config:
--------------------------------------------------------------------------------
1 | export STEF_TESTSUITE_NAME="NPRG099 ed tests"
2 | export ED=${ED:-/Volumes/crypto/hg/maied/ed}
3 | #export ED=/bin/ed
4 | # This is on u-pl machines.
5 | #export ED=/afs/ms/u/p/pechanec/maied/ed
6 | export INPUTFILE=inputfile
7 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-001.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo '1,$p' | $ED $INPUTFILE
4 |
5 | (( $? == 0 )) || exit 1
6 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-002.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo '1,2p' | $ED $INPUTFILE
4 |
5 | (( $? == 0 )) || exit 1
6 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-003.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo '5,10p' | $ED $INPUTFILE
4 |
5 | (( $? == 0 )) || exit 1
6 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-004.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo '1,100p' | $ED $INPUTFILE
4 |
5 | (( $? == 1 )) || exit 1
6 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-005.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cat <&1
4 | h
5 | q
6 | INPUT
7 |
8 | (( $? == 0 )) || exit 1
9 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-026.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cat << "INPUT" | $ED $INPUTFILE
4 | H
5 | 1q
6 | 2H
7 | INPUT
8 |
9 | (( $? == 1 )) || exit 1
10 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-002.txt:
--------------------------------------------------------------------------------
1 | 802
2 | # Input file for tests. Do not change without changing the tests.
3 |
4 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-003.txt:
--------------------------------------------------------------------------------
1 | 802
2 | Since C is relatively small, it can be described in a small space, and learned quickly. A programmer can reasonable expect to know and understand and indeed regularly use the entire language."
3 |
4 | Syllabus
5 |
6 | C history, standards, motivation
7 | coding style, basic language primitives
8 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-004.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-005.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 | Invalid address
4 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-006.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-007.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 | Invalid address
4 | Invalid address
5 | ?
6 | Invalid address
7 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-008.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 | Unexpected address
4 | ?
5 | Unexpected address
6 | Unexpected address
7 | ?
8 | Unexpected address
9 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-009.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 | Unexpected address
4 | ?
5 | Unexpected address
6 | Unexpected address
7 | ?
8 | Unexpected address
9 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-012.txt:
--------------------------------------------------------------------------------
1 | 802
2 | # Input file for tests. Do not change without changing the tests.
3 |
4 | Hello, world.
5 |
6 | Since C is relatively small, it can be described in a small space, and learned quickly. A programmer can reasonable expect to know and understand and indeed regularly use the entire language."
7 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-013.txt:
--------------------------------------------------------------------------------
1 | 802
2 | debugging tools and techniques
3 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-014.txt:
--------------------------------------------------------------------------------
1 | 802
2 | debugging tools and techniques
3 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-015.txt:
--------------------------------------------------------------------------------
1 | 802
2 | # Input file for tests. Do not change without changing the tests.
3 | # Input file for tests. Do not change without changing the tests.
4 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-016.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 | Unknown command
4 | ?
5 | Unknown command
6 | ?
7 | Unknown command
8 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-017.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 | Invalid command suffix
4 | ?
5 | Invalid command suffix
6 | ?
7 | Invalid command suffix
8 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-018.txt:
--------------------------------------------------------------------------------
1 | 802
2 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-019.txt:
--------------------------------------------------------------------------------
1 | 802
2 | # Input file for tests. Do not change without changing the tests.
3 | ?
4 | Unexpected address
5 | 1 # Input file for tests. Do not change without changing the tests.
6 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-020.txt:
--------------------------------------------------------------------------------
1 | 802
2 | # Input file for tests. Do not change without changing the tests.
3 | ?
4 | Unexpected address
5 | 1 # Input file for tests. Do not change without changing the tests.
6 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-021.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 | Invalid address
4 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-022.txt:
--------------------------------------------------------------------------------
1 | 802
2 | 5 Since C is relatively small, it can be described in a small space, and learned quickly. A programmer can reasonable expect to know and understand and indeed regularly use the entire language."
3 | 2
4 | 3 Hello, world.
5 | 4
6 | 1 # Input file for tests. Do not change without changing the tests.
7 | 2
8 | 3 Hello, world.
9 | Hello, world.
10 | 3 Hello, world.
11 | ?
12 | 3 Hello, world.
13 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-023.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 | Unknown command
4 | ?
5 | Invalid command suffix
6 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-025.txt:
--------------------------------------------------------------------------------
1 | /totallynonexistentfile: No such file or directory
2 | Cannot open input file
3 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-1/test-output-026.txt:
--------------------------------------------------------------------------------
1 | 802
2 | ?
3 | Unexpected address
4 | ?
5 | Unexpected address
6 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-2/README:
--------------------------------------------------------------------------------
1 | Tests
2 |
3 | 009-010, 016-017 command 'd'
4 | 024 modified buffer error message, q+q quits
5 | 026-029 command 'i'
6 | 030 w with empty argv1
7 | 031 w with non-empty argv1
8 | 032 w triggers correct error
9 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-2/stef-config:
--------------------------------------------------------------------------------
1 | export STEF_TESTSUITE_NAME="NPRG099 ed tests, Part 2"
2 | # You MUST set this one to your ed implementation or export ED before you run
3 | # the tests.
4 | #export ED=/bin/false
5 | export INPUTFILE=inputfile
6 | export TMPINPUTFILE=inputfile.tmp
7 | export OUTPUTFILE=outputfile.tmp
8 | # Avoid common aliases whose colored output, for example, could break a
9 | # subsequent grep use.
10 | export LS=/bin/ls
11 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-2/test-009.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Delete multiple lines at once.
4 |
5 | cp $INPUTFILE $TMPINPUTFILE || exit 2
6 |
7 | cat <" with empty argv1.
4 |
5 | cat << INPUT | $ED
6 | 0i
7 | hi
8 | hello
9 | .
10 | w $OUTPUTFILE
11 | 2i
12 | middle line
13 | .
14 | w
15 | q
16 | INPUT
17 |
18 | (( $? == 0 )) || exit 1
19 |
20 | cat $OUTPUTFILE
21 | rm -f $OUTPUTFILE
22 |
23 | exit 0
24 |
--------------------------------------------------------------------------------
/getting-credits/2019/tests/phase-2/test-031.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | #
3 | # Test "w " with non-empty argv1.
4 |
5 | cp $INPUTFILE $TMPINPUTFILE || exit 2
6 |
7 | cat <", i.e. a missing space after 'w'.
4 |
5 | cat <&2 && exit 1; }
7 | [[ -x $STEF ]] || { echo "STEF variable value '$STEF' not an executable" \
8 | "script." >&2 && exit 1; }
9 |
10 | $STEF $*
11 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-001.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Make sure tar with no arguments exits with 2.
4 |
5 | $MYTAR
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-002.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple listing test.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $tarfile
9 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-003.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing test with specific file arguments. Follow the same ordering in argv
4 | # as in the archive.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | first=$(echo "$inputfiles" | head -1)
10 | third=$(echo "$inputfiles" | head -3 | tail -1)
11 | seventh=$(echo "$inputfiles" | head -7 | tail -1)
12 | last=$(echo "$inputfiles" | tail -1)
13 |
14 | $MYTAR -t -f $tarfile $first $third $seventh $last
15 | (($? == 0)) || exit 1
16 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-008.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Wrong option.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -Z
9 | (($? == 2)) || exit 1
10 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-009.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Check test of non-existing file.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | base=$(basename $MYTAR)
9 |
10 | # The warning messages start with "$argv0: ". In case $MYTAR is not
11 | # "mytar", fix the output.
12 | output=$($MYTAR -t -f /totally/nonexistent.tar 2>&1)
13 | typeset -i ret=$?
14 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
15 |
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 | exit 0
18 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-011.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing truncated archive reports an error.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $partial 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-012.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Make sure tar with no options but an argument exits with 2.
4 |
5 | $MYTAR anything
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-013.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $onezeroblockmissing 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-014.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Two zero block missing is accepted without any warning.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $twozeroblocksmissing
9 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
10 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-015.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # No warnings when building the mytar binary.
4 |
5 | # When verifying the testing environment, we need to exit right now.
6 | [[ -n $MYGNUTAR ]] && exit 0
7 |
8 | source $configvar
9 | cd $tmpdir
10 |
11 | $GCC -Wall -Wextra $MYTAR_C
12 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-017.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple listing test, -v is ignored
4 |
5 | source $configvar
6 | # The -tv options with GNU tar prints long file listing which we do not support
7 | # so just emulate the simple listing and exit.
8 | [[ -n $MYGNUTAR ]] && echo "$inputfiles" && exit 0
9 |
10 | cd $tmpdir
11 |
12 | $MYTAR -t -v -f $tarfile
13 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-018.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Refuse anything that does not look like a tar archive.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | skipping="Skipping to next header"
9 |
10 | output=$($MYTAR -t -f $MYTAR 2>&1)
11 | typeset -i ret=$?
12 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
13 | echo "$output" | grep -v "$skipping" | \
14 | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
15 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-019.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple extra test. Will only test the extraction created the right files,
4 | # does not diff the contents - that is another unit test.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | $MYTAR -x -f ../$tarfile
14 | LC_ALL=C /bin/ls -1 *
15 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-021.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple extra test, see test-019.sh. Use the -v option now.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | tmp2=tmp-$(basename $0)
9 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
10 | cd $tmp2
11 |
12 | $MYTAR -x -v -f ../$tarfile
13 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-028.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0. Be verbose
4 | # here.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | output=$($MYTAR -x -f ../$onezeroblockmissing 2>&1)
14 | typeset -i ret=$?
15 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-002.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-003.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-004.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-005.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-006.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-007.txt:
--------------------------------------------------------------------------------
1 | mytar: Unsupported header type: 53
2 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-011.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-013.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: A lone zero block at 22
3 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-014.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-015.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2020/tests/test-output-015.txt
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-016.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2020/tests/test-output-016.txt
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-017.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-018.txt:
--------------------------------------------------------------------------------
1 | mytar: This does not look like a tar archive
2 | mytar: Exiting with failure status due to previous errors
3 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-019.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-021.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-022.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-024.txt:
--------------------------------------------------------------------------------
1 | mytar: Unexpected EOF in archive
2 | mytar: Error is not recoverable: exiting now
3 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-025.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-027.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-028.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2020/tests/test-output-029.txt:
--------------------------------------------------------------------------------
1 | gig-file
2 | gig-file
3 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/phase-1.tests:
--------------------------------------------------------------------------------
1 | 001
2 | 002
3 | 003
4 | 004
5 | 005
6 | 006
7 | 007
8 | 008
9 | 009
10 | 011
11 | 012
12 | 013
13 | 014
14 | 015
15 | 016
16 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/run-tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | [[ -n $MYGNUTAR ]] && export STEF_REGFILE_LOCAL_VARS=" "
4 |
5 | [[ -n $STEF ]] || { echo "STEF variable must be set first. See README." \
6 | >&2 && exit 1; }
7 | [[ -x $STEF ]] || { echo "STEF variable value '$STEF' not an executable" \
8 | "script." >&2 && exit 1; }
9 |
10 | $STEF $*
11 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-001.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Make sure tar with no arguments exits with 2.
4 |
5 | $MYTAR
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-002.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple listing test.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $tarfile
9 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-003.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing test with specific file arguments. Follow the same ordering in argv
4 | # as in the archive.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | first=$(echo "$inputfiles" | head -1)
10 | third=$(echo "$inputfiles" | head -3 | tail -1)
11 | seventh=$(echo "$inputfiles" | head -7 | tail -1)
12 | last=$(echo "$inputfiles" | tail -1)
13 |
14 | $MYTAR -t -f $tarfile $first $third $seventh $last
15 | (($? == 0)) || exit 1
16 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-008.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Wrong option.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -Z
9 | (($? == 2)) || exit 1
10 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-009.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Check test of non-existing file.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | base=$(basename $MYTAR)
9 |
10 | # The warning messages start with "$argv0: ". In case $MYTAR is not
11 | # "mytar", fix the output.
12 | output=$($MYTAR -t -f /totally/nonexistent.tar 2>&1)
13 | typeset -i ret=$?
14 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
15 |
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 | exit 0
18 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-011.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing truncated archive reports an error.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $partial 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-012.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Make sure tar with no options but an argument exits with 2.
4 |
5 | $MYTAR anything
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-013.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $onezeroblockmissing 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-014.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Two zero block missing is accepted without any warning.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $twozeroblocksmissing
9 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
10 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-015.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # No warnings when building the mytar binary.
4 |
5 | # When verifying the testing environment, we need to exit right now.
6 | [[ -n $MYGNUTAR ]] && exit 0
7 |
8 | source $configvar
9 | cd $tmpdir
10 |
11 | $GCC -Wall -Wextra $MYTAR_C
12 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-017.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple listing test, -v is ignored
4 |
5 | source $configvar
6 | # The -tv options with GNU tar prints long file listing which we do not support
7 | # so just emulate the simple listing and exit.
8 | [[ -n $MYGNUTAR ]] && echo "$inputfiles" && exit 0
9 |
10 | cd $tmpdir
11 |
12 | $MYTAR -t -v -f $tarfile
13 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-018.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Refuse anything that does not look like a tar archive.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | skipping="Skipping to next header"
9 |
10 | output=$($MYTAR -t -f $MYTAR 2>&1)
11 | typeset -i ret=$?
12 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
13 | echo "$output" | grep -v "$skipping" | \
14 | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
15 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-019.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple extra test. Will only test the extraction created the right files,
4 | # does not diff the contents - that is another unit test.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | $MYTAR -x -f ../$tarfile
14 | LC_ALL=C /bin/ls -1 *
15 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-021.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple extra test, see test-019.sh. Use the -v option now.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | tmp2=tmp-$(basename $0)
9 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
10 | cd $tmp2
11 |
12 | $MYTAR -x -v -f ../$tarfile
13 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-028.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0. Be verbose
4 | # here.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | output=$($MYTAR -x -f ../$onezeroblockmissing 2>&1)
14 | typeset -i ret=$?
15 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-002.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-003.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-004.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-005.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-006.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-007.txt:
--------------------------------------------------------------------------------
1 | mytar: Unsupported header type: 53
2 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-011.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-013.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: A lone zero block at 22
3 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-014.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-015.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2021/tests/test-output-015.txt
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-016.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2021/tests/test-output-016.txt
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-017.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-018.txt:
--------------------------------------------------------------------------------
1 | mytar: This does not look like a tar archive
2 | mytar: Exiting with failure status due to previous errors
3 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-019.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-021.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-022.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-024.txt:
--------------------------------------------------------------------------------
1 | mytar: Unexpected EOF in archive
2 | mytar: Error is not recoverable: exiting now
3 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-025.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-027.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-028.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2021/tests/test-output-029.txt:
--------------------------------------------------------------------------------
1 | gig-file
2 | gig-file
3 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/config.var:
--------------------------------------------------------------------------------
1 | export tmpdir=dir.0REI8
2 |
3 | export tarfile=archive.tar
4 |
5 | export inputfiles="aaa-file
6 | another-file2
7 | empty.data
8 | file.zero
9 | file1.random
10 | file2.zero
11 | file3.zero
12 | hello-world
13 | small-file"
14 |
15 | export aaafile=aaa-file
16 |
17 | export aaa1stblocks=aaa-file-1st-blocks
18 |
19 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/phase-1.tests:
--------------------------------------------------------------------------------
1 | 001
2 | 002
3 | 003
4 | 004
5 | 005
6 | 006
7 | 007
8 | 008
9 | 009
10 | 011
11 | 012
12 | 013
13 | 014
14 | 015
15 | 016
16 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/run-tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | [[ -n $MYGNUTAR ]] && export STEF_REGFILE_LOCAL_VARS=" "
4 |
5 | [[ -n $STEF ]] || { echo "STEF variable must be set first. See README." \
6 | >&2 && exit 1; }
7 | [[ -x $STEF ]] || { echo "STEF variable value '$STEF' not an executable" \
8 | "script." >&2 && exit 1; }
9 |
10 | $STEF $*
11 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-001.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Make sure tar with no arguments exits with 2.
4 |
5 | $MYTAR
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-002.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple listing test.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $tarfile
9 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-003.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing test with specific file arguments. Follow the same ordering in argv
4 | # as in the archive.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | first=$(echo "$inputfiles" | head -1)
10 | third=$(echo "$inputfiles" | head -3 | tail -1)
11 | seventh=$(echo "$inputfiles" | head -7 | tail -1)
12 | last=$(echo "$inputfiles" | tail -1)
13 |
14 | $MYTAR -t -f $tarfile $first $third $seventh $last
15 | (($? == 0)) || exit 1
16 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-008.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Wrong option.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -Z
9 | (($? == 2)) || exit 1
10 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-009.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Check test of non-existing file.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | base=$(basename $MYTAR)
9 |
10 | # The warning messages start with "$argv0: ". In case $MYTAR is not
11 | # "mytar", fix the output.
12 | output=$($MYTAR -t -f /totally/nonexistent.tar 2>&1)
13 | typeset -i ret=$?
14 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
15 |
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 | exit 0
18 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-011.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing truncated archive reports an error.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $partial 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-012.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Make sure tar with no options but an argument exits with 2.
4 |
5 | $MYTAR anything
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-013.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $onezeroblockmissing 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-014.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Two zero block missing is accepted without any warning.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $twozeroblocksmissing
9 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
10 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-015.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # No warnings when building the mytar binary.
4 |
5 | # When verifying the testing environment, we need to exit right now.
6 | [[ -n $MYGNUTAR ]] && exit 0
7 |
8 | source $configvar
9 | cd $tmpdir
10 |
11 | $GCC -Wall -Wextra $MYTAR_C
12 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-017.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple listing test, -v is ignored
4 |
5 | source $configvar
6 | # The -tv options with GNU tar prints long file listing which we do not support
7 | # so just emulate the simple listing and exit.
8 | [[ -n $MYGNUTAR ]] && echo "$inputfiles" && exit 0
9 |
10 | cd $tmpdir
11 |
12 | $MYTAR -t -v -f $tarfile
13 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-018.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Refuse anything that does not look like a tar archive.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | skipping="Skipping to next header"
9 |
10 | output=$($MYTAR -t -f $MYTAR 2>&1)
11 | typeset -i ret=$?
12 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
13 | echo "$output" | grep -v "$skipping" | \
14 | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
15 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-019.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple extra test. Will only test the extraction created the right files,
4 | # does not diff the contents - that is another unit test.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | $MYTAR -x -f ../$tarfile
14 | LC_ALL=C /bin/ls -1 *
15 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-021.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple extra test, see test-019.sh. Use the -v option now.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | tmp2=tmp-$(basename $0)
9 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
10 | cd $tmp2
11 |
12 | $MYTAR -x -v -f ../$tarfile
13 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-028.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0. Be verbose
4 | # here.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | output=$($MYTAR -x -f ../$onezeroblockmissing 2>&1)
14 | typeset -i ret=$?
15 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-002.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-003.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-004.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-005.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-006.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-007.txt:
--------------------------------------------------------------------------------
1 | mytar: Unsupported header type: 53
2 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-011.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-013.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: A lone zero block at 22
3 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-014.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-015.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2022/tests/test-output-015.txt
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-016.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2022/tests/test-output-016.txt
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-017.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-018.txt:
--------------------------------------------------------------------------------
1 | mytar: This does not look like a tar archive
2 | mytar: Exiting with failure status due to previous errors
3 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-019.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-021.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-022.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-024.txt:
--------------------------------------------------------------------------------
1 | mytar: Unexpected EOF in archive
2 | mytar: Error is not recoverable: exiting now
3 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-025.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-027.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-028.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2022/tests/test-output-029.txt:
--------------------------------------------------------------------------------
1 | gig-file
2 | gig-file
3 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/config.var:
--------------------------------------------------------------------------------
1 | export tmpdir=dir.NphXC
2 |
3 | export tarfile=archive.tar
4 |
5 | export inputfiles="aaa-file
6 | another-file2
7 | empty.data
8 | file.zero
9 | file1.random
10 | file2.zero
11 | file3.zero
12 | hello-world
13 | small-file"
14 |
15 | export aaafile=aaa-file
16 |
17 | export aaa1stblocks=aaa-file-1st-blocks
18 |
19 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/phase-1.tests:
--------------------------------------------------------------------------------
1 | 001
2 | 002
3 | 003
4 | 004
5 | 005
6 | 006
7 | 007
8 | 008
9 | 009
10 | 011
11 | 012
12 | 013
13 | 014
14 | 015
15 | 016
16 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/run-tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | [[ -n $MYGNUTAR ]] && export STEF_REGFILE_LOCAL_VARS=" "
4 |
5 | [[ -n $STEF ]] || { echo "STEF variable must be set first. See README." \
6 | >&2 && exit 1; }
7 | [[ -x $STEF ]] || { echo "STEF variable value '$STEF' not an executable" \
8 | "script." >&2 && exit 1; }
9 |
10 | $STEF $*
11 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-001.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Make sure tar with no arguments exits with 2.
4 |
5 | $MYTAR
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-002.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple listing test.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $tarfile
9 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-003.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing test with specific file arguments. Follow the same ordering in argv
4 | # as in the archive.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | first=$(echo "$inputfiles" | head -1)
10 | third=$(echo "$inputfiles" | head -3 | tail -1)
11 | seventh=$(echo "$inputfiles" | head -7 | tail -1)
12 | last=$(echo "$inputfiles" | tail -1)
13 |
14 | $MYTAR -t -f $tarfile $first $third $seventh $last
15 | (($? == 0)) || exit 1
16 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-008.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Wrong option.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -Z
9 | (($? == 2)) || exit 1
10 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-009.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Check test of non-existing file.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | base=$(basename $MYTAR)
9 |
10 | # The warning messages start with "$argv0: ". In case $MYTAR is not
11 | # "mytar", fix the output.
12 | output=$($MYTAR -t -f /totally/nonexistent.tar 2>&1)
13 | typeset -i ret=$?
14 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
15 |
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 | exit 0
18 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-011.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing truncated archive reports an error.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $partial 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-012.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Make sure tar with no options but an argument exits with 2.
4 |
5 | $MYTAR anything
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-013.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $onezeroblockmissing 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-014.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Two zero block missing is accepted without any warning.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $twozeroblocksmissing
9 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
10 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-015.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # No warnings when building the mytar binary.
4 |
5 | # When verifying the testing environment, we need to exit right now.
6 | [[ -n $MYGNUTAR ]] && exit 0
7 |
8 | source $configvar
9 | cd $tmpdir
10 |
11 | $GCC -Wall -Wextra $MYTAR_C
12 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-017.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple listing test, -v is ignored
4 |
5 | source $configvar
6 | # The -tv options with GNU tar prints long file listing which we do not support
7 | # so just emulate the simple listing and exit.
8 | [[ -n $MYGNUTAR ]] && echo "$inputfiles" && exit 0
9 |
10 | cd $tmpdir
11 |
12 | $MYTAR -t -v -f $tarfile
13 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-018.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Refuse anything that does not look like a tar archive.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | skipping="Skipping to next header"
9 |
10 | output=$($MYTAR -t -f $MYTAR 2>&1)
11 | typeset -i ret=$?
12 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
13 | echo "$output" | grep -v "$skipping" | \
14 | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
15 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-019.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple extra test. Will only test the extraction created the right files,
4 | # does not diff the contents - that is another unit test.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | $MYTAR -x -f ../$tarfile
14 | LC_ALL=C /bin/ls -1 *
15 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-021.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple extra test, see test-019.sh. Use the -v option now.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | tmp2=tmp-$(basename $0)
9 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
10 | cd $tmp2
11 |
12 | $MYTAR -x -v -f ../$tarfile
13 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-028.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0. Be verbose
4 | # here.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | output=$($MYTAR -x -f ../$onezeroblockmissing 2>&1)
14 | typeset -i ret=$?
15 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-002.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-003.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-004.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-005.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-006.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-007.txt:
--------------------------------------------------------------------------------
1 | mytar: Unsupported header type: 53
2 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-011.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-013.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: A lone zero block at 22
3 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-014.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-015.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2023/tests/test-output-015.txt
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-016.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2023/tests/test-output-016.txt
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-017.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-018.txt:
--------------------------------------------------------------------------------
1 | mytar: This does not look like a tar archive
2 | mytar: Exiting with failure status due to previous errors
3 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-019.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-021.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-022.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-024.txt:
--------------------------------------------------------------------------------
1 | mytar: Unexpected EOF in archive
2 | mytar: Error is not recoverable: exiting now
3 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-025.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-027.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-028.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2023/tests/test-output-029.txt:
--------------------------------------------------------------------------------
1 | gig-file
2 | gig-file
3 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/phase-1.tests:
--------------------------------------------------------------------------------
1 | 001
2 | 002
3 | 003
4 | 004
5 | 005
6 | 006
7 | 007
8 | 008
9 | 009
10 | 011
11 | 012
12 | 013
13 | 014
14 | 015
15 | 016
16 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/run-tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | [[ -n $MYGNUTAR ]] && export STEF_REGFILE_LOCAL_VARS=" "
4 |
5 | [[ -n $STEF ]] || { echo "STEF variable must be set first. See README." \
6 | >&2 && exit 1; }
7 | [[ -x $STEF ]] || { echo "STEF variable value '$STEF' not an executable" \
8 | "script." >&2 && exit 1; }
9 |
10 | command -v stdbuf >/dev/null && prefix="stdbuf -o0"
11 | $prefix $STEF ${@}
12 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-001.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Make sure tar with no arguments exits with 2.
4 |
5 | $MYTAR
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-002.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple listing test.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $tarfile
9 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-003.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing test with specific file arguments. Follow the same ordering in argv
4 | # as in the archive.
5 | #
6 |
7 | source $configvar
8 | cd $tmpdir
9 |
10 | typeset -i last=${#inputfiles[@]}
11 |
12 | $MYTAR -t -f "$tarfile" \
13 | ${inputfiles[0]} ${inputfiles[2]} ${inputfiles[6]} ${inputfiles[$last - 1]}
14 | (($? == 0)) || exit 1
15 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-004.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing test with specific file arguments. Use different ordering in argv
4 | # from the ordering in the archive. However, the files should still be listed
5 | # in the ordering of the archive.
6 |
7 | source $configvar
8 | cd $tmpdir
9 |
10 | typeset -i last=${#inputfiles[@]}
11 |
12 | $MYTAR -t -f "$tarfile" \
13 | ${inputfiles[6]} ${inputfiles[$last - 1]} ${inputfiles[2]} ${inputfiles[0]}
14 | (($? == 0)) || exit 1
15 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-008.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Wrong option.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -Z
9 | (($? == 2)) || exit 1
10 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-009.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Check test of non-existing file.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | base=$(basename $MYTAR)
9 |
10 | # The warning messages start with "$argv0: ". In case $MYTAR is not
11 | # "mytar", fix the output.
12 | output=$($MYTAR -t -f /totally/nonexistent.tar 2>&1)
13 | typeset -i ret=$?
14 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
15 |
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 | exit 0
18 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-011.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Listing truncated archive reports an error.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $partial 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-012.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Make sure tar with no options but an argument exits with 2.
4 |
5 | $MYTAR anything
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-013.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $onezeroblockmissing 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-014.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Two zero block missing is accepted without any warning.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $twozeroblocksmissing
9 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
10 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-015.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # No warnings when building the mytar binary.
4 |
5 | # When verifying the testing environment, we need to exit right now.
6 | [[ -n $MYGNUTAR ]] && exit 0
7 |
8 | source $configvar
9 | cd $tmpdir
10 |
11 | $GCC -Wall -Wextra $MYTAR_C
12 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-017.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple listing test, -v is ignored
4 |
5 | source $configvar
6 |
7 | # The -tv options with GNU tar prints long file listing which we do not support
8 | # so just emulate the simple listing and exit.
9 | if [[ -n $MYGNUTAR ]]; then
10 | for i in "${inputfiles[@]}"; do
11 | echo $i
12 | done
13 | exit 0
14 | fi
15 |
16 | cd $tmpdir
17 |
18 | $MYTAR -t -v -f "$tarfile"
19 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-018.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Refuse anything that does not look like a tar archive.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | skipping="Skipping to next header"
9 |
10 | output=$($MYTAR -t -f $MYTAR 2>&1)
11 | typeset -i ret=$?
12 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
13 | echo "$output" | grep -v "$skipping" | \
14 | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
15 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-019.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple extra test. Will only test the extraction created the right files,
4 | # does not diff the contents - that is another unit test.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | $MYTAR -x -f ../$tarfile
14 | LC_ALL=C /bin/ls -1 *
15 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-021.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # Simple extra test, see test-019.sh. Use the -v option now.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | tmp2=tmp-$(basename $0)
9 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
10 | cd $tmp2
11 |
12 | $MYTAR -x -v -f ../$tarfile
13 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-028.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0. Be verbose
4 | # here.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | output=$($MYTAR -x -f ../$onezeroblockmissing 2>&1)
14 | typeset -i ret=$?
15 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-002.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-003.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-004.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-005.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-006.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-007.txt:
--------------------------------------------------------------------------------
1 | mytar: Unsupported header type: 53
2 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-011.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-013.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: A lone zero block at 22
3 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-014.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-015.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2024/tests/test-output-015.txt
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-016.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2024/tests/test-output-016.txt
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-017.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-018.txt:
--------------------------------------------------------------------------------
1 | mytar: This does not look like a tar archive
2 | mytar: Exiting with failure status due to previous errors
3 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-019.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-021.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-022.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-024.txt:
--------------------------------------------------------------------------------
1 | mytar: Unexpected EOF in archive
2 | mytar: Error is not recoverable: exiting now
3 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-025.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-027.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-028.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2024/tests/test-output-029.txt:
--------------------------------------------------------------------------------
1 | gig-file
2 | gig-file
3 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/phase-1.tests:
--------------------------------------------------------------------------------
1 | 001
2 | 002
3 | 003
4 | 004
5 | 005
6 | 006
7 | 007
8 | 008
9 | 009
10 | 011
11 | 012
12 | 013
13 | 014
14 | 015
15 | 016
16 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/run-tests.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | [[ -n $MYGNUTAR ]] && export STEF_REGFILE_LOCAL_VARS=" "
4 |
5 | [[ -n $STEF ]] || { echo "STEF variable must be set first. See README." \
6 | >&2 && exit 1; }
7 | [[ -x $STEF ]] || { echo "STEF variable value '$STEF' not an executable" \
8 | "script." >&2 && exit 1; }
9 |
10 | command -v stdbuf >/dev/null && prefix="stdbuf -o0"
11 | $prefix $STEF ${@}
12 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-001.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Make sure tar with no arguments exits with 2.
4 |
5 | $MYTAR
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-002.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Simple listing test.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $tarfile
9 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-003.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Listing test with specific file arguments. Follow the same ordering in argv
4 | # as in the archive.
5 | #
6 |
7 | source $configvar
8 | cd $tmpdir
9 |
10 | typeset -i last=${#inputfiles[@]}
11 |
12 | $MYTAR -t -f "$tarfile" \
13 | ${inputfiles[0]} ${inputfiles[2]} ${inputfiles[6]} ${inputfiles[$last - 1]}
14 | (($? == 0)) || exit 1
15 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-004.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Listing test with specific file arguments. Use different ordering in argv
4 | # from the ordering in the archive. However, the files should still be listed
5 | # in the ordering of the archive.
6 |
7 | source $configvar
8 | cd $tmpdir
9 |
10 | typeset -i last=${#inputfiles[@]}
11 |
12 | $MYTAR -t -f "$tarfile" \
13 | ${inputfiles[6]} ${inputfiles[$last - 1]} ${inputfiles[2]} ${inputfiles[0]}
14 | (($? == 0)) || exit 1
15 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-008.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Wrong option.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -Z
9 | (($? == 2)) || exit 1
10 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-009.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Check test of non-existing file.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | base=$(basename $MYTAR)
9 |
10 | # The warning messages start with "$argv0: ". In case $MYTAR is not
11 | # "mytar", fix the output.
12 | output=$($MYTAR -t -f /totally/nonexistent.tar 2>&1)
13 | typeset -i ret=$?
14 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
15 |
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 | exit 0
18 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-011.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Listing truncated archive reports an error.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $partial 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-012.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Make sure tar with no options but an argument exits with 2.
4 |
5 | $MYTAR anything
6 | (($? == 2)) && exit 0
7 | exit 1
8 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-013.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | output=$($MYTAR -t -f $onezeroblockmissing 2>&1)
9 | typeset -i ret=$?
10 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
11 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
12 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-014.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Two zero block missing is accepted without any warning.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | $MYTAR -t -f $twozeroblocksmissing
9 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
10 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-015.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # No warnings when building the mytar binary.
4 |
5 | # When verifying the testing environment, we need to exit right now.
6 | [[ -n $MYGNUTAR ]] && exit 0
7 |
8 | source $configvar
9 | cd $tmpdir
10 |
11 | $GCC -Wall -Wextra $MYTAR_C
12 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-017.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Simple listing test, -v is ignored
4 |
5 | source $configvar
6 |
7 | # The -tv options with GNU tar prints long file listing which we do not support
8 | # so just emulate the simple listing and exit.
9 | if [[ -n $MYGNUTAR ]]; then
10 | for i in "${inputfiles[@]}"; do
11 | echo $i
12 | done
13 | exit 0
14 | fi
15 |
16 | cd $tmpdir
17 |
18 | $MYTAR -t -v -f "$tarfile"
19 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-018.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Refuse anything that does not look like a tar archive.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | skipping="Skipping to next header"
9 |
10 | output=$($MYTAR -t -f $MYTAR 2>&1)
11 | typeset -i ret=$?
12 | ((ret == 2)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
13 | echo "$output" | grep -v "$skipping" | \
14 | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
15 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-019.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Simple extra test. Will only test the extraction created the right files,
4 | # does not diff the contents - that is another unit test.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | $MYTAR -x -f ../$tarfile
14 | LC_ALL=C /bin/ls -1 *
15 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-021.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # Simple extra test, see test-019.sh. Use the -v option now.
4 |
5 | source $configvar
6 | cd $tmpdir
7 |
8 | tmp2=tmp-$(basename $0)
9 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
10 | cd $tmp2
11 |
12 | $MYTAR -x -v -f ../$tarfile
13 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-028.sh:
--------------------------------------------------------------------------------
1 | #/usr/bin/env bash
2 | #
3 | # One zero block missing triggers a warning but exit is still 0. Be verbose
4 | # here.
5 |
6 | source $configvar
7 | cd $tmpdir
8 |
9 | tmp2=tmp-$(basename $0)
10 | mkdir $tmp2 || { echo "mkdir failed" && exit 1; }
11 | cd $tmp2
12 |
13 | output=$($MYTAR -x -f ../$onezeroblockmissing 2>&1)
14 | typeset -i ret=$?
15 | ((ret == 0)) || { echo "Wrong tar return value $ret." >&2 && exit 1; }
16 | echo "$output" | sed -e "s/^[a-zA-Z0-9/.]*$base: /mytar: /"
17 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-002.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-003.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-004.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-005.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-006.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 | mytar: nonexistent1: Not found in archive
6 | mytar: nonexistent2: Not found in archive
7 | mytar: nonexistent3: Not found in archive
8 | mytar: Exiting with failure status due to previous errors
9 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-007.txt:
--------------------------------------------------------------------------------
1 | mytar: Unsupported header type: 53
2 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-011.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-013.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: A lone zero block at 22
3 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-014.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-015.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2025/tests/test-output-015.txt
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-016.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/getting-credits/2025/tests/test-output-016.txt
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-017.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-018.txt:
--------------------------------------------------------------------------------
1 | mytar: This does not look like a tar archive
2 | mytar: Exiting with failure status due to previous errors
3 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-019.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-021.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | another-file2
3 | empty.data
4 | file.zero
5 | file1.random
6 | file2.zero
7 | file3.zero
8 | hello-world
9 | small-file
10 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-022.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | empty.data
3 | file3.zero
4 | small-file
5 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-024.txt:
--------------------------------------------------------------------------------
1 | mytar: Unexpected EOF in archive
2 | mytar: Error is not recoverable: exiting now
3 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-025.txt:
--------------------------------------------------------------------------------
1 | aaa-file
2 | mytar: Unexpected EOF in archive
3 | mytar: Error is not recoverable: exiting now
4 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-027.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-028.txt:
--------------------------------------------------------------------------------
1 | mytar: A lone zero block at 22
2 |
--------------------------------------------------------------------------------
/getting-credits/2025/tests/test-output-029.txt:
--------------------------------------------------------------------------------
1 | gig-file
2 | gig-file
3 |
--------------------------------------------------------------------------------
/input/2020/01.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/01.md",
3 | "files" : ["input/2020/01.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/01.md:
--------------------------------------------------------------------------------
1 | #include "modules/intro.md"
2 | #include "modules/hello-world.md"
3 | #include "modules/first-class-objective.md"
4 | #include "modules/basics.md"
5 | #include "modules/moving-star.md"
6 |
--------------------------------------------------------------------------------
/input/2020/02.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/02.md",
3 | "files" : ["input/2020/02.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/03.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/03.md",
3 | "files" : ["input/2020/03.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/04.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/04.md",
3 | "files" : ["input/2020/04.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/05.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/05.md",
3 | "files" : ["input/2020/05.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/06.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/06.md",
3 | "files" : ["input/2020/06.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/06.md:
--------------------------------------------------------------------------------
1 | #include "modules/array-of-characters.md"
2 | #include "modules/strings.md"
3 | #include "modules/for-loop.md"
4 | #include "modules/expressions-intro.md"
5 | #include "modules/statements.md"
6 | #include "modules/err.md"
7 | #include "modules/file-API.md"
8 | #include "modules/pointers.md"
9 | #include "modules/home-assignment-section.md"
10 | #include "modules/pointer-difference.md"
11 |
--------------------------------------------------------------------------------
/input/2020/07.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/07.md",
3 | "files" : ["input/2020/07.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/07.md:
--------------------------------------------------------------------------------
1 | #include "modules/warm-up/circle.md"
2 | #include "modules/pointer-size.md"
3 | #include "modules/arrays-and-pointers.md"
4 | #include "modules/strings-and-arrays.md"
5 | #include "modules/valid-pointer-operations.md"
6 | #include "modules/arrays-as-function-arguments.md"
7 | #include "modules/calling-by-value-and-reference.md"
8 | #include "modules/home-assignment-section.md"
9 | #include "modules/home-assignments/implement-function.md"
10 |
--------------------------------------------------------------------------------
/input/2020/08.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/08.md",
3 | "files" : ["input/2020/08.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/09.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/09.md",
3 | "files" : ["input/2020/09.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/10.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/10.md",
3 | "files" : ["input/2020/10.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/11.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/11.md",
3 | "files" : ["input/2020/11.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/11.md:
--------------------------------------------------------------------------------
1 | #include "modules/warm-up/3d-as-1d.md"
2 | #include "modules/the-last-comma.md"
3 | #include "modules/enum.md"
4 | #include "modules/const.md"
5 | #include "modules/typedef.md"
6 | #include "modules/name-space.md"
7 | #include "modules/reading-complex-declarations.md"
8 | #include "modules/bitwise-operations.md"
9 | #include "modules/home-assignment-section.md"
10 | #include "modules/home-assignments/linked-list2.md"
11 | #include "modules/home-assignments/get-bits.md"
12 |
--------------------------------------------------------------------------------
/input/2020/12.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/12.md",
3 | "files" : ["input/2020/12.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/13.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/13.md",
3 | "files" : ["input/2020/13.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2020/13.md:
--------------------------------------------------------------------------------
1 | #include "modules/building-with-specific-c-ver.md"
2 | #include "modules/flexible-array-member.md"
3 | #include "modules/structure-bit-fields.md"
4 | #include "modules/non-transparent-handles.md"
5 | #include "modules/incomplete-type.md"
6 | #include "modules/opaque-structures.md"
7 |
--------------------------------------------------------------------------------
/input/2021/01.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/01.md",
3 | "files" : ["input/2021/01.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/01.md:
--------------------------------------------------------------------------------
1 | #include "modules/intro.md"
2 | #include "modules/first-class-objective.md"
3 | #include "modules/hello-world.md"
4 | #include "modules/basics.md"
5 | #include "modules/moving-star.md"
6 |
--------------------------------------------------------------------------------
/input/2021/02.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/02.md",
3 | "files" : ["input/2021/02.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/03.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/03.md",
3 | "files" : ["input/2021/03.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/04.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/04.md",
3 | "files" : ["input/2021/04.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/05.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/05.md",
3 | "files" : ["input/2021/05.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/05.md:
--------------------------------------------------------------------------------
1 | # Topics
2 |
3 | Warm-up, common mistakes, multi-dimensional arrays, home assignment, integer
4 | promotion and conversions.
5 |
6 | #include "modules/warm-up/tr.md"
7 |
8 | #include "modules/common-mistakes-1.md"
9 |
10 | #include "modules/multi-dimensional-arrays.md"
11 |
12 | #include "modules/home-assignments/home-assignment-section.md"
13 | #include "modules/home-assignments/mountain-generator.md"
14 |
15 | #include "modules/arithmetic-promotion-and-conversions.md"
16 |
--------------------------------------------------------------------------------
/input/2021/06.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/06.md",
3 | "files" : ["input/2021/06.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/06.md:
--------------------------------------------------------------------------------
1 | #include "modules/strings-and-string-constants.md"
2 | #include "modules/warm-up/tr-redux.md"
3 | #include "modules/for-loop.md"
4 | #include "modules/expressions-intro.md"
5 | #include "modules/statements.md"
6 | #include "modules/pointers.md"
7 | #include "modules/file-API.md"
8 | #include "modules/err.md"
9 |
10 | #include "modules/home-assignments/home-assignment-section.md"
11 | #include "modules/home-assignments/file-of-ints.md"
12 | #include "modules/home-assignments/file-read.md"
13 |
--------------------------------------------------------------------------------
/input/2021/07.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/07.md",
3 | "files" : ["input/2021/07.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/07.md:
--------------------------------------------------------------------------------
1 | #include "modules/warm-up/circle.md"
2 | #include "modules/pointer-size.md"
3 | #include "modules/arrays-and-pointers.md"
4 | #include "modules/strings-and-arrays.md"
5 | #include "modules/valid-pointer-operations.md"
6 | #include "modules/arrays-as-function-arguments.md"
7 | #include "modules/calling-by-value-and-reference.md"
8 | #include "modules/home-assignments/home-assignment-section.md"
9 | #include "modules/home-assignments/implement-function.md"
10 |
--------------------------------------------------------------------------------
/input/2021/08.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/08.md",
3 | "files" : ["input/2021/08.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/08.md:
--------------------------------------------------------------------------------
1 | #include "modules/warm-up/strcmp.md"
2 | #include "modules/program-arguments.md"
3 | #include "modules/structures.md"
4 |
5 | #include "modules/home-assignments/home-assignment-section.md"
6 | #include "modules/home-assignments/animals.md"
7 |
--------------------------------------------------------------------------------
/input/2021/09.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/09.md",
3 | "files" : ["input/2021/09.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/09.md:
--------------------------------------------------------------------------------
1 | #include "modules/operator-precedence.md"
2 |
3 | #include "modules/pointer-addressing.md"
4 | #include "modules/array-of-pointers.md"
5 | #include "modules/warm-up/dragon.md"
6 |
7 | #include "modules/home-assignments/home-assignment-section.md"
8 | #include "modules/home-assignments/pointers.md"
9 |
10 | #include "modules/pointer-to-pointer.md"
11 | #include "modules/changing-pointers-in-fn.md"
12 |
13 | #include "modules/explicit-type-conversion.md"
14 |
--------------------------------------------------------------------------------
/input/2021/10.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/10.md",
3 | "files" : ["input/2021/10.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/10.md:
--------------------------------------------------------------------------------
1 | #include "modules/warm-up/strsepc.md"
2 |
3 | #include "modules/dynamic-allocation.md"
4 | #include "modules/memory-leaks.md"
5 |
6 | #include "modules/structure-casting.md"
7 |
8 | #include "modules/home-assignments/home-assignment-section.md"
9 | #include "modules/home-assignments/linked-list.md"
10 | #include "modules/home-assignments/mygetopt.md"
11 |
--------------------------------------------------------------------------------
/input/2021/11.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/11.md",
3 | "files" : ["input/2021/11.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/12.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/12.md",
3 | "files" : ["input/2021/12.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/12.md:
--------------------------------------------------------------------------------
1 | Lecture on May 26 2021
2 |
3 | #include "modules/bitwise-operations.md"
4 | #include "modules/warm-up/bitdiff.md"
5 |
6 | #include "modules/namespace.md"
7 |
8 | #include "modules/reading-complex-declarations.md"
9 |
10 | #include "modules/linking.md"
11 |
12 | #include "modules/home-assignments/home-assignment-section.md"
13 | #include "modules/home-assignments/get-bits.md"
14 | #include "modules/home-assignments/dirtree.md"
15 |
--------------------------------------------------------------------------------
/input/2021/13.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/13.md",
3 | "files" : ["input/2021/13.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2021/overflow.md:
--------------------------------------------------------------------------------
1 | #include "modules/building-with-specific-c-ver.md"
2 | #include "modules/flexible-array-member.md"
3 | #include "modules/structure-bit-fields.md"
4 | #include "modules/non-transparent-handles.md"
5 | #include "modules/incomplete-type.md"
6 | #include "modules/opaque-structures.md"
7 | #include "modules/goto.md"
8 |
--------------------------------------------------------------------------------
/input/2022/01.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/01.md",
3 | "files" : ["input/2022/01.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/01.md:
--------------------------------------------------------------------------------
1 | #include "modules/intro.md"
2 | #include "modules/first-class-objective.md"
3 | #include "modules/hello-world.md"
4 | #include "modules/basics.md"
5 | #include "modules/moving-star.md"
6 |
--------------------------------------------------------------------------------
/input/2022/02.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/02.md",
3 | "files" : ["input/2022/02.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/03.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/03.md",
3 | "files" : ["input/2022/03.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/04.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/04.md",
3 | "files" : ["input/2022/04.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/05.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/05.md",
3 | "files" : ["input/2022/05.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/05.md:
--------------------------------------------------------------------------------
1 | # Topics
2 |
3 | Warm-up, common mistakes, multi-dimensional arrays,
4 | integer promotion and conversions.
5 |
6 | # Warm-up
7 | #include "modules/warm-up/tr.md"
8 |
9 | #include "modules/common-mistakes-defines.md"
10 |
11 | #include "modules/multi-dimensional-arrays.md"
12 |
13 | #include "modules/arithmetic-promotion-and-conversions.md"
14 |
15 | #include "modules/home-assignments/home-assignment-section.md"
16 | #include "modules/home-assignments/mountain-generator.md"
17 |
--------------------------------------------------------------------------------
/input/2022/06.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/06.md",
3 | "files" : ["input/2022/06.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/06.md:
--------------------------------------------------------------------------------
1 | #include "modules/strings-and-string-constants.md"
2 |
3 | # Warm-up
4 | #include "modules/warm-up/string.md"
5 |
6 | #include "modules/for-loop.md"
7 | #include "modules/expressions-intro.md"
8 | #include "modules/statements.md"
9 | #include "modules/pointers.md"
10 |
11 | #include "modules/err.md"
12 |
13 | #include "modules/home-assignments/home-assignment-section.md"
14 | #include "modules/warm-up/tr-redux.md"
15 |
--------------------------------------------------------------------------------
/input/2022/07.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/07.md",
3 | "files" : ["input/2022/07.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/08.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/08.md",
3 | "files" : ["input/2022/08.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/08.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/strcmp.md"
3 |
4 | #include "modules/program-arguments.md"
5 | #include "modules/structures.md"
6 |
7 | #include "modules/home-assignments/home-assignment-section.md"
8 | #include "modules/home-assignments/animals.md"
9 |
--------------------------------------------------------------------------------
/input/2022/09.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/09.md",
3 | "files" : ["input/2022/09.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/09.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/dragon.md"
3 |
4 | #include "modules/operator-precedence.md"
5 |
6 | #include "modules/pointer-addressing.md"
7 | #include "modules/array-of-pointers.md"
8 | #include "modules/pointer-to-pointer.md"
9 | #include "modules/changing-pointers-in-fn.md"
10 |
11 | #include "modules/explicit-type-conversion.md"
12 |
13 | #include "modules/home-assignments/home-assignment-section.md"
14 | #include "modules/home-assignments/pointers.md"
15 |
--------------------------------------------------------------------------------
/input/2022/10.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/10.md",
3 | "files" : ["input/2022/10.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/10.md:
--------------------------------------------------------------------------------
1 | #include "modules/warm-up/strsepc.md"
2 |
3 | #include "modules/dynamic-allocation.md"
4 | #include "modules/memory-leaks.md"
5 |
6 | #include "modules/structure-casting.md"
7 |
8 | #include "modules/home-assignments/home-assignment-section.md"
9 | #include "modules/home-assignments/linked-list.md"
10 | #include "modules/home-assignments/mygetopt.md"
11 |
--------------------------------------------------------------------------------
/input/2022/11.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/11.md",
3 | "files" : ["input/2022/11.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/12.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/12.md",
3 | "files" : ["input/2022/12.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/12.md:
--------------------------------------------------------------------------------
1 | #include "modules/bitwise-operations.md"
2 | #include "modules/warm-up/bitdiff.md"
3 |
4 | #include "modules/namespace.md"
5 |
6 | #include "modules/reading-complex-declarations.md"
7 |
8 | #include "modules/linking.md"
9 |
10 | #include "modules/home-assignments/home-assignment-section.md"
11 | #include "modules/home-assignments/get-bits.md"
12 | #include "modules/home-assignments/dirtree.md"
13 |
--------------------------------------------------------------------------------
/input/2022/13.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/13.md",
3 | "files" : ["input/2022/13.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/13.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/altbits.md"
3 | #include "modules/warm-up/binary-numbits.md"
4 |
5 | #include "modules/goto.md"
6 | #include "modules/switch.md"
7 |
8 | #include "modules/building-with-specific-c-ver.md"
9 | #include "modules/flexible-array-member.md"
10 | #include "modules/structure-bit-fields.md"
11 | #include "modules/transparent-handles.md"
12 | #include "modules/incomplete-type.md"
13 | #include "modules/opaque-structures.md"
14 |
--------------------------------------------------------------------------------
/input/2022/debugging.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/debugging.md",
3 | "files" : ["input/2022/debugging.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2022/debugging.md:
--------------------------------------------------------------------------------
1 | # Debugging
2 | #include "modules/debug-prints.md"
3 | #include "modules/assert.md"
4 | #include "modules/syscall-tracing.md"
5 | #include "modules/static-analysis.md"
6 | #include "modules/library-tracing.md"
7 | #include "modules/dynamic-analysis.md"
8 | #include "modules/dynamic-tracing.md"
9 | #include "modules/debugger.md"
10 |
--------------------------------------------------------------------------------
/input/2023/01.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/01.md",
3 | "files" : ["input/2023/01.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/01.md:
--------------------------------------------------------------------------------
1 | #include "modules/intro.md"
2 | #include "modules/first-class-objective.md"
3 | #include "modules/hello-world.md"
4 | #include "modules/basics.md"
5 | #include "modules/moving-star.md"
6 |
--------------------------------------------------------------------------------
/input/2023/02.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/02.md",
3 | "files" : ["input/2023/02.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/03.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/03.md",
3 | "files" : ["input/2023/03.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/04.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/04.md",
3 | "files" : ["input/2023/04.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/05.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/05.md",
3 | "files" : ["input/2023/05.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/05.md:
--------------------------------------------------------------------------------
1 | # Topics
2 |
3 | Warm-up, common mistakes, multi-dimensional arrays,
4 | integer promotion and conversions.
5 |
6 | # Warm-up
7 | #include "modules/warm-up/tr.md"
8 |
9 | #include "modules/common-mistakes-defines.md"
10 |
11 | #include "modules/multi-dimensional-arrays.md"
12 |
13 | #include "modules/arithmetic-promotion-and-conversions.md"
14 |
15 | #include "modules/home-assignments/home-assignment-section.md"
16 | #include "modules/home-assignments/mountain-generator.md"
17 |
--------------------------------------------------------------------------------
/input/2023/06.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/06.md",
3 | "files" : ["input/2023/06.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/06.md:
--------------------------------------------------------------------------------
1 | #include "modules/strings-and-string-constants.md"
2 |
3 | # Warm-up
4 | #include "modules/warm-up/string.md"
5 |
6 | #include "modules/for-loop.md"
7 | #include "modules/expressions-intro.md"
8 | #include "modules/statements.md"
9 | #include "modules/pointers.md"
10 |
11 | #include "modules/err.md"
12 |
13 | #include "modules/home-assignments/home-assignment-section.md"
14 | #include "modules/warm-up/tr-redux.md"
15 |
--------------------------------------------------------------------------------
/input/2023/07.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/07.md",
3 | "files" : ["input/2023/07.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/08.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/08.md",
3 | "files" : ["input/2023/08.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/08.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/strcmp.md"
3 |
4 | #include "modules/program-arguments.md"
5 | #include "modules/structures.md"
6 |
7 | #include "modules/home-assignments/home-assignment-section.md"
8 | #include "modules/home-assignments/animals.md"
9 |
--------------------------------------------------------------------------------
/input/2023/09.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/09.md",
3 | "files" : ["input/2023/09.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/09.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/dragon.md"
3 |
4 | #include "modules/operator-precedence.md"
5 |
6 | #include "modules/pointer-addressing.md"
7 | #include "modules/array-of-pointers.md"
8 | #include "modules/pointer-to-pointer.md"
9 | #include "modules/changing-pointers-in-fn.md"
10 |
11 | #include "modules/explicit-type-conversion.md"
12 |
13 | #include "modules/home-assignments/home-assignment-section.md"
14 | #include "modules/home-assignments/pointers.md"
15 |
--------------------------------------------------------------------------------
/input/2023/10.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/10.md",
3 | "files" : ["input/2023/10.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/10.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/strsepc.md"
3 |
4 | #include "modules/dynamic-allocation.md"
5 | #include "modules/memory-leaks.md"
6 |
7 | #include "modules/structure-casting.md"
8 |
9 | #include "modules/home-assignments/linked-list.md"
10 | #include "modules/bintree.md"
11 |
12 | #include "modules/home-assignments/home-assignment-section.md"
13 | #include "modules/home-assignments/mygetopt.md"
14 |
--------------------------------------------------------------------------------
/input/2023/11.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/11.md",
3 | "files" : ["input/2023/11.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2023/12.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/12.md",
3 | "files" : ["input/2023/12.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/01.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/01.md",
3 | "files" : ["input/2024/01.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/01.md:
--------------------------------------------------------------------------------
1 | #include "modules/intro.md"
2 | #include "modules/first-class-objective.md"
3 | #include "modules/hello-world.md"
4 | #include "modules/basics.md"
5 | #include "modules/moving-star.md"
6 |
--------------------------------------------------------------------------------
/input/2024/02.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/02.md",
3 | "files" : ["input/2024/02.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/03.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/03.md",
3 | "files" : ["input/2024/03.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/04.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/04.md",
3 | "files" : ["input/2024/04.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/05.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/05.md",
3 | "files" : ["input/2024/05.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/05.md:
--------------------------------------------------------------------------------
1 | # Topics
2 |
3 | Warm-up, common mistakes, multi-dimensional arrays,
4 | integer promotion and conversions.
5 |
6 | # Warm-up
7 | #include "modules/warm-up/tr.md"
8 |
9 | #include "modules/common-mistakes-defines.md"
10 |
11 | #include "modules/multi-dimensional-arrays.md"
12 |
13 | #include "modules/arithmetic-promotion-and-conversions.md"
14 |
15 | #include "modules/home-assignments/home-assignment-section.md"
16 | #include "modules/home-assignments/mountain-generator.md"
17 |
--------------------------------------------------------------------------------
/input/2024/06.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/06.md",
3 | "files" : ["input/2024/06.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/06.md:
--------------------------------------------------------------------------------
1 | #include "modules/strings-and-string-constants.md"
2 |
3 | # Warm-up
4 | #include "modules/warm-up/string.md"
5 |
6 | #include "modules/for-loop.md"
7 | #include "modules/expressions-intro.md"
8 | #include "modules/statements.md"
9 | #include "modules/pointers.md"
10 |
11 | #include "modules/err.md"
12 |
13 | #include "modules/home-assignments/home-assignment-section.md"
14 | #include "modules/warm-up/tr-redux.md"
15 |
--------------------------------------------------------------------------------
/input/2024/07.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/07.md",
3 | "files" : ["input/2024/07.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/08.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/08.md",
3 | "files" : ["input/2024/08.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/08.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/strcmp.md"
3 |
4 | #include "modules/program-arguments.md"
5 | #include "modules/structures.md"
6 |
7 | #include "modules/home-assignments/home-assignment-section.md"
8 | #include "modules/home-assignments/animals.md"
9 |
--------------------------------------------------------------------------------
/input/2024/09.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/09.md",
3 | "files" : ["input/2024/09.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/09.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/dragon.md"
3 |
4 | #include "modules/operator-precedence.md"
5 |
6 | #include "modules/pointer-addressing.md"
7 | #include "modules/array-of-pointers.md"
8 | #include "modules/pointer-to-pointer.md"
9 | #include "modules/changing-pointers-in-fn.md"
10 |
11 | #include "modules/explicit-type-conversion.md"
12 |
13 | #include "modules/home-assignments/home-assignment-section.md"
14 | #include "modules/home-assignments/pointers.md"
15 |
--------------------------------------------------------------------------------
/input/2024/10.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/10.md",
3 | "files" : ["input/2024/10.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/10.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/strsepc.md"
3 |
4 | #include "modules/dynamic-allocation.md"
5 | #include "modules/heap-memory-woes.md"
6 |
7 | #include "modules/structure-casting.md"
8 |
9 | #include "modules/linked-list.md"
10 | #include "modules/bintree.md"
11 |
12 | #include "modules/home-assignments/home-assignment-section.md"
13 | #include "modules/home-assignments/mygetopt.md"
14 | #include "modules/home-assignments/dirtree.md"
15 |
--------------------------------------------------------------------------------
/input/2024/11.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/11.md",
3 | "files" : ["input/2024/11.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2024/12.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/12.md",
3 | "files" : ["input/2024/12.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/01.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/01.md",
3 | "files" : ["input/2025/01.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/01.md:
--------------------------------------------------------------------------------
1 | #include "modules/intro.md"
2 | #include "modules/c99-standard.md"
3 | #include "modules/first-class-objective.md"
4 | #include "modules/hello-world.md"
5 | #include "modules/basics.md"
6 | #include "modules/moving-star.md"
7 |
--------------------------------------------------------------------------------
/input/2025/02.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/02.md",
3 | "files" : ["input/2025/02.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/03.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/03.md",
3 | "files" : ["input/2025/03.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/04.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/04.md",
3 | "files" : ["input/2025/04.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/05.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/05.md",
3 | "files" : ["input/2025/05.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/06.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/06.md",
3 | "files" : ["input/2024/06.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/07.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/07.md",
3 | "files" : ["input/2025/07.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/08.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/08.md",
3 | "files" : ["input/2025/08.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/08.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/strcmp.md"
3 |
4 | #include "modules/program-arguments.md"
5 | #include "modules/structures.md"
6 |
7 | #include "modules/home-assignments/home-assignment-section.md"
8 | #include "modules/home-assignments/animals.md"
9 |
--------------------------------------------------------------------------------
/input/2025/09.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/09.md",
3 | "files" : ["input/2025/09.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/09.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/dragon.md"
3 |
4 | #include "modules/operator-precedence.md"
5 |
6 | #include "modules/pointer-addressing.md"
7 | #include "modules/array-of-pointers.md"
8 | #include "modules/pointer-to-pointer.md"
9 | #include "modules/changing-pointers-in-fn.md"
10 |
11 | #include "modules/explicit-type-conversion.md"
12 |
13 | #include "modules/home-assignments/home-assignment-section.md"
14 | #include "modules/home-assignments/pointers.md"
15 |
--------------------------------------------------------------------------------
/input/2025/10.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/10.md",
3 | "files" : ["input/2024/10.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/10.md:
--------------------------------------------------------------------------------
1 | # Warm-up
2 | #include "modules/warm-up/strsepc.md"
3 |
4 | #include "modules/dynamic-allocation.md"
5 | #include "modules/heap-memory-woes.md"
6 |
7 | #include "modules/structure-casting.md"
8 |
9 | #include "modules/linked-list.md"
10 | #include "modules/bintree.md"
11 |
12 | #include "modules/home-assignments/home-assignment-section.md"
13 | #include "modules/home-assignments/mygetopt.md"
14 | #include "modules/home-assignments/dirtree.md"
15 |
--------------------------------------------------------------------------------
/input/2025/11.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/11.md",
3 | "files" : ["input/2025/11.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/12.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/12.md",
3 | "files" : ["input/2025/12.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/13.json:
--------------------------------------------------------------------------------
1 | {
2 | "build" : "lecture-notes/13.md",
3 | "files" : ["input/2025/13.md"]
4 | }
5 |
--------------------------------------------------------------------------------
/input/2025/13.md:
--------------------------------------------------------------------------------
1 | # Overflow content
2 |
3 | #include "modules/transparent-handles.md"
4 | #include "modules/incomplete-type.md"
5 | #include "modules/opaque-structures.md"
6 |
7 | #include "modules/home-assignments/home-assignment-section.md"
8 | #include "modules/home-assignments/get-bits.md"
9 | #include "modules/home-assignments/dirtree.md"
10 |
--------------------------------------------------------------------------------
/modules/bitwise-vs-logical.md:
--------------------------------------------------------------------------------
1 | # bitwise operators vs. logical operators vs. comparison
2 |
3 | Bit operators have lower precedence than comparison. As a consequence the
4 | evaluation of expressions such as `(a & b == c & d)` is counter intuitive.
5 |
6 | #source bitwise-vs-logical.c
7 |
8 | In this case modern compilers (clang) will actually warn about missing
9 | parentheses.
10 |
11 | You can read the explanation by Dennis Ritchie here:
12 | http://www.lysator.liu.se/c/dmr-on-or.html
13 |
--------------------------------------------------------------------------------
/modules/c99-standard.md:
--------------------------------------------------------------------------------
1 | # C standards
2 |
3 | C standards are not free but the drafts are. The latest draft can be used as
4 | the standard since the only change from the draft is that the latest draft is
5 | labeled as the standard. The latest C99 draft:
6 | http://www.open-std.org/JTC1/sc22/wg14/www/docs/n1256.pdf
7 |
8 | There is also a [txt only version](http://port70.net/~nsz/c/c99/n1256.txt).
9 |
--------------------------------------------------------------------------------
/modules/changing-pointers-in-fn.md:
--------------------------------------------------------------------------------
1 | # Changing pointers
2 |
3 | - In order to change the value of a pointer in a function, it has to be passed
4 | as a pointer to a pointer.
5 | - This makes sense, because the storage address of a plain pointer is
6 | not known to the function, and therefore we must pass in its address
7 | so that we can change the object the address points to by
8 | dereferencing the address.
9 |
10 | #source ptr-change.c
11 |
--------------------------------------------------------------------------------
/modules/home-assignments/count-digit-occurence2.md:
--------------------------------------------------------------------------------
1 | ## :wrench: Count digit occurrence (use arrays)
2 |
3 | Write a simple program on counting
4 | #module count-digit-occurence.md the digit occurence
5 | as in one of the previous classes but now use an array for counting the figures.
6 |
--------------------------------------------------------------------------------
/modules/home-assignments/file-read.md:
--------------------------------------------------------------------------------
1 | ## File read
2 |
3 | :wrench: create a text file where each line begins with integer followed
4 | by space and a string, e.g.:
5 | ```
6 | 42 towel
7 | 13 dwarfs and Snow White
8 | ```
9 | Read the file using `fscanf()` and print the values (i.e. integer and a string)
10 | from each line to standard output.
11 |
--------------------------------------------------------------------------------
/modules/home-assignments/home-assignment-section.md:
--------------------------------------------------------------------------------
1 | # :wrench: Home assignment
2 |
3 | Note that home assignments are entirely voluntary but writing code is the only
4 | way to learn a programming language.
5 |
--------------------------------------------------------------------------------
/modules/static-functions-and-variables.md:
--------------------------------------------------------------------------------
1 | # Static variables and functions
2 |
3 | If a function is declared `static`, it is visible only from the same source code
4 | file.
5 |
6 | Static variables: they retain value across function calls. That is, the
7 | initialization of a static variable within a function is done only once.
8 |
9 | Yes, the word `static` is overloaded in C.
10 |
11 | :wrench: Take the binary tree implementation and use the `static` keyword where
12 | it makes sense.
13 |
--------------------------------------------------------------------------------
/modules/ternary-operator-quiz.md:
--------------------------------------------------------------------------------
1 | ## :wrench: Ternary operator: quiz
2 |
3 | See the code in #source ternary.c
4 |
5 | - is this possible to do with ternary operator ?
6 | - how would you fix it ?
7 | - the usual solution is to put this into macro. many libraries/programs
8 | define their own `MAX`/`MIN` macros.
9 |
--------------------------------------------------------------------------------
/modules/the-last-comma.md:
--------------------------------------------------------------------------------
1 | # The last initializer and a comma
2 |
3 | In C89, having a comma after the last initializer was a syntax error. Since
4 | C99, it is allowed and optional.
5 |
6 | ```C
7 | struct s {
8 | int a;
9 | int b;
10 | } s = { 1, 2, }; // ',' after 2 is optional
11 | ```
12 |
13 | See why keeping the last comma always there might be a very good idea:
14 |
15 | #source missing-comma-in-initializer.c
16 |
--------------------------------------------------------------------------------
/modules/warm-up/3d-as-1d.md:
--------------------------------------------------------------------------------
1 | ## Work with 3-d array
2 |
3 | Declare a 3-d array of 1x2x3 `int`s and statically initialize it with numbers
4 | 1..6. Retype the array as 1-d and print all elements. You should get then:
5 |
6 | ```
7 | $ ./a.out
8 | 1 2 3 4 5 6
9 | ```
10 |
11 | No compilation warnings with `gcc -Wall -Wextra` allowed!
12 |
--------------------------------------------------------------------------------
/modules/warm-up/binary-numbits.md:
--------------------------------------------------------------------------------
1 | ## :wrench: Number of bits for binary representation
2 |
3 | Given an `int` (assume 4 bytes) with a positive value, use bit operators to find
4 | out how many bits (and bytes) will be needed to represent the number in binary.
5 | Then rewrite
6 | #source print-in-binary.c
7 | using the acquired number.
8 |
9 | Note: be careful about little vs big endian
10 |
11 | #solution numchars-for-binary.c
12 |
--------------------------------------------------------------------------------
/modules/warm-up/strsepc.md:
--------------------------------------------------------------------------------
1 | # :wrench: `strsepc`
2 |
3 | Implement:
4 |
5 | ```C
6 | char *strsepc(char **stringp, int c);
7 | ```
8 |
9 | which behaves like strsep(3) except that it searches only for the first
10 | occurence of a single character.
11 |
12 | Try to use `strsep`() first to properly understand how it works.
13 |
14 | #source strsep.c
15 |
16 | #solution strsepc.c
17 |
--------------------------------------------------------------------------------
/posters/c-prog-lang--poster-CR-2023.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/posters/c-prog-lang--poster-CR-2023.pdf
--------------------------------------------------------------------------------
/posters/c-prog-lang--poster-CR-2024.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/posters/c-prog-lang--poster-CR-2024.pdf
--------------------------------------------------------------------------------
/posters/c-prog-lang--poster-CR-2025.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/posters/c-prog-lang--poster-CR-2025.pdf
--------------------------------------------------------------------------------
/src/2d-static-array-initialization.c:
--------------------------------------------------------------------------------
1 | /*
2 | * 2d array static initialization.
3 | */
4 | #include
5 |
6 | #define MYSIZE 4
7 |
8 | int
9 | main(void)
10 | {
11 | int i, j;
12 | int a[MYSIZE][MYSIZE] = {
13 | { 0, 1, 2, 3 },
14 | { 4, 5, 6, 7 },
15 | { 8, 9, 10, 11 },
16 | { 12, 13, 14, 15 }
17 | };
18 |
19 | /* Print the array. */
20 | for (i = 0; i < MYSIZE; ++i)
21 | for (j = 0; j < MYSIZE; ++j)
22 | printf("%d ", a[i][j]);
23 |
24 | putchar('\n');
25 | }
26 |
--------------------------------------------------------------------------------
/src/arithmetics2.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | printf("%d %d\n", 1);
7 | }
8 |
--------------------------------------------------------------------------------
/src/array-char-nozero.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | char s[] = { 'f', 'o', 'o' };
7 | /*
8 | * Note the continuation line. Indent such a line by 4 characters
9 | * instead of a tabulator. Always stick to 80 columns.
10 | */
11 | char s2[] = { 'f', 'o', 'o', 'f', 'o', 'o', 'f', 'o', 'o', 'f', 'o',
12 | 'o', 'f', 'o', 'o', 'f', 'o', 'o' };
13 |
14 | printf("%s\n", s);
15 | printf("%s\n", s2);
16 | }
17 |
--------------------------------------------------------------------------------
/src/array-fill.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | char s[8] = { 'h' }; // The rest will be initialized with zeroes
7 |
8 | /* sizeof returns the size of the whole array in bytes. */
9 | printf("size = %zu\n", sizeof (s));
10 | for (size_t i = 0; i < sizeof (s); i++)
11 | printf("'%c' (0x%x)\n", s[i], s[i]);
12 | printf("%s\n", s);
13 | }
14 |
--------------------------------------------------------------------------------
/src/array-init-func.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | func(void)
5 | {
6 | static int val = 1;
7 |
8 | return (val++);
9 | }
10 |
11 | int
12 | main(void)
13 | {
14 | int a[3] = { func(), func(), func() };
15 |
16 | for (size_t i = 0; i < sizeof (a) / sizeof (a[0]); i++)
17 | printf("%d\n", a[i]);
18 | }
19 |
--------------------------------------------------------------------------------
/src/array-literal.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void
4 | func(int array[], size_t len)
5 | {
6 | for (int i = 0; i < len; i++)
7 | printf("%d\n", array[i]);
8 | }
9 |
10 | int
11 | main(void)
12 | {
13 | func((int []){ 0, 1, 2}, 3);
14 | }
15 |
--------------------------------------------------------------------------------
/src/array-notation-with-ptr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | char *p = "hello";
7 |
8 | /* Will print 'e' */
9 | printf("%c\n", p[1]);
10 | }
11 |
--------------------------------------------------------------------------------
/src/array-of-ptrs.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | char *a[] = { "hello", ",", " world", "!" };
7 |
8 | printf("size = %zu\n", sizeof (a));
9 | printf("%s%s%s%s\n", a[0], a[1], a[2], a[3]);
10 | }
11 |
--------------------------------------------------------------------------------
/src/array-partial-init.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | char array[80] = { [0] = 'A', [2] = 'f', [4] = 'o', [6] = 'o' };
4 |
5 | int
6 | main(void)
7 | {
8 | size_t i;
9 |
10 | for (i = 0; i < sizeof (array) / sizeof (array[0]); i++) {
11 | if (array[i] != 0)
12 | printf("%c", array[i]);
13 | else
14 | printf("_");
15 | }
16 | printf("\n");
17 | }
18 |
--------------------------------------------------------------------------------
/src/array-var-not-modifiable.c:
--------------------------------------------------------------------------------
1 | int
2 | main(void)
3 | {
4 | int a[1];
5 | int aa[1];
6 |
7 | /* The compiler fails on both. */
8 | ++a;
9 | a = aa;
10 | }
11 |
--------------------------------------------------------------------------------
/src/array-variable-length.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | static size_t
4 | VLA(int n)
5 | {
6 | int a[n + 1]; // can use an expression
7 |
8 | return (sizeof(a));
9 | }
10 |
11 | int
12 | main(void)
13 | {
14 | printf("%zu\n", VLA(4));
15 | }
16 |
--------------------------------------------------------------------------------
/src/assert.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int
6 | main(int argc, char *argv[])
7 | {
8 | assert(argc == 2);
9 | }
10 |
--------------------------------------------------------------------------------
/src/bitfield-bitwise-ops.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | struct foo_s {
4 | unsigned int a : 3;
5 | unsigned int b : 5;
6 | } foo;
7 |
8 | int
9 | main(void)
10 | {
11 | foo.a = 5; /* 101 */
12 | foo.b = 16; /* 10000 */
13 |
14 | foo.a = foo.a ^ foo.b;
15 | unsigned int xor = foo.a ^ foo.b;
16 |
17 | printf("%u vs %u\n", foo.a, xor);
18 | }
19 |
--------------------------------------------------------------------------------
/src/bitfield-wraparound.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | struct foo_s {
4 | unsigned int a : 3;
5 | } foo;
6 |
7 | int
8 | main(void)
9 | {
10 | foo.a = 7;
11 | foo.a++;
12 |
13 | /* Will print 0. */
14 | printf("%u\n", foo.a);
15 | }
16 |
--------------------------------------------------------------------------------
/src/bitfield.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | struct foo {
5 | unsigned short a : 15;
6 | short b : 2;
7 | };
8 |
9 | int
10 | main(void)
11 | {
12 | printf("%zu\n", sizeof (struct foo));
13 |
14 | int a = 65534;
15 | int b = -5;
16 | struct foo foo = { .a = 0, .b = 0 };
17 |
18 | foo.a = a;
19 | foo.b = b;
20 |
21 | printf("%x -> %x (%d)\n", a, foo.a, foo.a);
22 | printf("%x -> %x (%d)\n", b, foo.b, foo.b);
23 | }
24 |
--------------------------------------------------------------------------------
/src/bitwise-vs-logical.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | if (5 & 3 == 1)
7 | printf("yes\n");
8 | }
9 |
--------------------------------------------------------------------------------
/src/block-static-object.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | /* There can be some code here. */
7 | again:
8 | {
9 | static int i = 0;
10 |
11 | if (i == 3)
12 | return (0);
13 |
14 | ++i;
15 | printf("%d\n", i);
16 | }
17 |
18 | goto again;
19 | }
20 |
--------------------------------------------------------------------------------
/src/buf-overflow.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | char foo[4] = "foo";
7 | char bar[5] = "barr";
8 |
9 | /* BUG: will always overflow destination buffer! */
10 | strncpy(foo, bar, sizeof (bar));
11 | }
12 |
--------------------------------------------------------------------------------
/src/bus-error.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This may result with a bus error on some architectures when running (it will
3 | * compile fine). E.g., SPARC.
4 | *
5 | * $ ./a.out
6 | * Bus Error (core dumped)
7 | *
8 | * $ echo $?
9 | * 138
10 | *
11 | * $ isainfo
12 | * sparcv9 sparc
13 | */
14 | #include
15 |
16 | int
17 | main(void)
18 | {
19 | char *s = "hello, world, hello, world";
20 | long long int *p = (long long int *)(s + 1);
21 |
22 | printf("%lld\n", *p);
23 | }
24 |
--------------------------------------------------------------------------------
/src/char.c:
--------------------------------------------------------------------------------
1 | /*
2 | * See if char is signed or unsigned.
3 | *
4 | * Compile with -fsigned-char -fwrapv and then with -funsigned-char and see the
5 | * difference.
6 | *
7 | * Note: signed overflow behavior is undefined. That's why -fwrapv is used in
8 | * the signed case.
9 | */
10 |
11 | #include
12 |
13 | int
14 | main(void)
15 | {
16 | char c = (char) 128;
17 |
18 | printf("%d\n", c);
19 | }
20 |
--------------------------------------------------------------------------------
/src/check-c-version.c:
--------------------------------------------------------------------------------
1 | #ifndef __STDC_VERSION__
2 | #error "__STDC_VERSION__ not defined. C99 compiler or greater required."
3 | #else
4 | #if __STDC_VERSION__ < 199901L
5 | #error "C99 compiler or greater required."
6 | #endif
7 | #endif
8 |
9 | int
10 | main(void)
11 | {
12 | }
13 |
--------------------------------------------------------------------------------
/src/circle-simplified.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a simplified version of circle.c
3 | */
4 | #include
5 | #include
6 | #include
7 |
8 | #define MYRAD 15
9 |
10 | int
11 | main(void)
12 | {
13 | char a[2 * MYRAD + 2];
14 |
15 | a[2 * MYRAD + 1] = '\0';
16 | for (int i = -MYRAD; i <= MYRAD; ++i) {
17 | int y = sqrt(MYRAD * MYRAD - i * i);
18 |
19 | memset(a, ' ', sizeof (a) - 1);
20 | a[y + MYRAD] = '*';
21 | a[-y + MYRAD] = '*';
22 | printf("%s\n", a);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/comma.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int x, i = 4; // not comma operator !
7 |
8 | while (x = 1, printf("foo\n"), i < 6) {
9 | i += x;
10 | }
11 |
12 | return (++i, i); // the parens are there just for style
13 | // what if you change ++i to i++ ?
14 | // what if you change this to (x, ++i, i) ?
15 | }
16 |
--------------------------------------------------------------------------------
/src/complex-declaration.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* foo and foo2 are compatible types */
4 | typedef char *(*(**foo[][8])(void))[];
5 |
6 | typedef char *a_of_p[];
7 | typedef a_of_p *(**foo2[][8])(void);
8 |
9 | int
10 | main(void)
11 | {
12 | foo x = { NULL };
13 | foo2 y = { NULL };
14 |
15 | /*
16 | * The compiler may warn that x and y may never be equal but it accepts
17 | * they are of the same type.
18 | */
19 | if (y == x)
20 | return (1);
21 | }
22 |
--------------------------------------------------------------------------------
/src/compound-statement-invalid.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int i = 2;
7 |
8 | if (({ i *= 2; puts("doubled");}), i % 2 == 0) {
9 | puts("even");
10 | } else {
11 | puts("odd");
12 | }
13 | printf("%d\n", i);
14 | }
15 |
--------------------------------------------------------------------------------
/src/const-not-really-a-const.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int i = 'c';
7 | int *p1 = &i;
8 | int const *p2 = &i;
9 |
10 | // Illegal. I cannot change 'i' through *p2.
11 | *p2 = 'x';
12 | // However, I can change it through *p1.
13 | *p1 = 'x';
14 | }
15 |
--------------------------------------------------------------------------------
/src/const.c:
--------------------------------------------------------------------------------
1 | int
2 | main(void)
3 | {
4 | const int a[3] = { 1, 2, 3 };
5 | int const b[3] = { 1, 2, 3 };
6 |
7 | /* The compiler prints an error for the next line. */
8 | a[0] = 4;
9 | }
10 |
--------------------------------------------------------------------------------
/src/conv-and-prom-with-bitwise-ops.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | /* -1 is promoted to an unsigned int first. */
7 | printf("%u\n", 13U & -1);
8 | }
9 |
--------------------------------------------------------------------------------
/src/crashme.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Note that this involves signed overflow which is undefined behavior in the
3 | * spec.
4 | *
5 | * $ ./a.out 2147483648 -1
6 | * -2147483648 -1
7 | * Floating point exception: 8
8 | */
9 | #include
10 | #include
11 | #include
12 |
13 | int
14 | main(int argc, char **argv)
15 | {
16 | int a, b;
17 |
18 | assert(argc == 3);
19 |
20 | a = atoi(argv[1]);
21 | b = atoi(argv[2]);
22 |
23 | printf("%d %d\n", a, b);
24 |
25 | return (b ? a / b : 0);
26 | }
27 |
--------------------------------------------------------------------------------
/src/declaration.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | /*
7 | * int is usually 4 bytes. It does not have to be but on 32 and 64 bit
8 | * CPUs it is 4 bytes.
9 | */
10 | int i;
11 |
12 | /* Assignment */
13 | i = 0;
14 |
15 | /* % starts a conversion specification. 'd' is for an int (decimal). */
16 | printf("%d\n", i);
17 |
18 | /* No need to use return, C99 will make sure 0 is returned here. */
19 | }
20 |
--------------------------------------------------------------------------------
/src/derived-types.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Type of "myarray" is "an array of 10 pointers to a pointer to char". It is
3 | * called a derived type.
4 | */
5 | typedef char **myarray[10];
6 | myarray a;
7 |
8 | int
9 | main(void)
10 | {
11 | char c;
12 | char *p = &c;
13 |
14 | /* OK */
15 | a[0] = &p;
16 | /* Assigning an incompatible pointer, your compiler should complain. */
17 | a[1] = p;
18 | }
19 |
--------------------------------------------------------------------------------
/src/divbyzero.c:
--------------------------------------------------------------------------------
1 | int
2 | main(void)
3 | {
4 | int a = 42, b = 0;
5 |
6 | a /= b;
7 | }
8 |
--------------------------------------------------------------------------------
/src/divminus.c:
--------------------------------------------------------------------------------
1 | int
2 | main(void)
3 | {
4 | int a = 0, b = -1;
5 |
6 | a /= b;
7 | }
8 |
--------------------------------------------------------------------------------
/src/ell-in-cm.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int
5 | main(void)
6 | {
7 | int i = 1, n = 30;
8 |
9 | printf("Ell\tInches\tCentimeters\n");
10 | while (i <= n) {
11 | float cm;
12 | int in;
13 |
14 | if ((i - 1) % 10 == 0) {
15 | int j = 0;
16 | while (j++ < 20)
17 | printf("-");
18 | printf("\n");
19 | }
20 |
21 | in = i * 45;
22 | cm = in * 2.54;
23 | printf("%d\t%d\t%.2f\n", i, in, cm);
24 | ++i;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/enum-values.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | enum foo {
4 | FOO = 42,
5 | X,
6 | Y = 2,
7 | Z,
8 | BAR
9 | };
10 |
11 | int
12 | main(void)
13 | {
14 | printf("%d\n", FOO);
15 | printf("%d\n", BAR);
16 | }
17 |
--------------------------------------------------------------------------------
/src/enums.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /*
4 | * As with structures, you may or may not use a comma after the last enumerator.
5 | */
6 | enum white_space { NL = '\n', SP = ' ', TAB = '\t', };
7 |
8 | int
9 | main(void)
10 | {
11 | printf("%d\n", SP);
12 | printf("'%c'\n", SP);
13 | }
14 |
--------------------------------------------------------------------------------
/src/err.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int
5 | main(void)
6 | {
7 | errno = 3;
8 | if (errno)
9 | err(1, "ERROR: ");
10 | }
11 |
--------------------------------------------------------------------------------
/src/errx.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int some_error = 3;
7 |
8 | if (some_error)
9 | errx(1, "ERROR: %d", some_error);
10 | }
11 |
--------------------------------------------------------------------------------
/src/expression-statement.c:
--------------------------------------------------------------------------------
1 | int
2 | main(void)
3 | {
4 | int c = 4;
5 |
6 | c + 1;
7 | "foo";
8 |
9 | return (c);
10 | }
11 |
--------------------------------------------------------------------------------
/src/ext.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Use as:
3 | *
4 | * $ cc linkage.c ext.c
5 | */
6 | int i;
7 | static int si;
8 |
--------------------------------------------------------------------------------
/src/fear-of-goto.c:
--------------------------------------------------------------------------------
1 | /*
2 | * As seen in the source of an UNIX operating system. The author chose not to
3 | * use goto however needed to jump out of block of code so he used do/while.
4 | */
5 |
6 | #include
7 |
8 | int
9 | main(void)
10 | {
11 | do {
12 |
13 | printf("foo\n");
14 |
15 | break;
16 |
17 | printf("bar\n");
18 |
19 | } while (0);
20 |
21 | printf("finish\n");
22 | }
23 |
--------------------------------------------------------------------------------
/src/float-precision.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Compile and run the program, observe what happens.
3 | * Then recompile it with the -DADDTWO and observe once again.
4 | * Why is that ?
5 | */
6 |
7 | #include
8 |
9 | int
10 | main(void)
11 | {
12 | float f = 1 << 23;
13 | size_t cnt = 0;
14 |
15 | printf("%zu\n", sizeof (f));
16 |
17 | while (1) {
18 | printf("%16.2f %zu\n", f, cnt++);
19 | #if ADDTWO
20 | if (f >= 16777216.0)
21 | f += 2;
22 | else
23 | #endif
24 | f += 1;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/float.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | float f = 13.12345678;
7 |
8 | printf("%f\n", f);
9 | /* Will this print exactly 13.12345678? If not, why? */
10 | printf("%.8f\n", f);
11 | printf("%.2f\n", f);
12 | printf("%10.2f\n", f);
13 | printf("%010.2f\n", f);
14 | }
15 |
--------------------------------------------------------------------------------
/src/fmt-string-invalid.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | printf("%ld\n", 1ULL);
7 | }
8 |
--------------------------------------------------------------------------------
/src/fn-ptr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | myadd(int a, int b)
5 | {
6 | return (a + b);
7 | }
8 |
9 | int
10 | mymultiply(int a, int b)
11 | {
12 | return (a * b);
13 | }
14 |
15 | int
16 | process_numbers(int a, int b, int (*f)(int, int))
17 | {
18 | return ((*f)(a, b));
19 | }
20 |
21 | int
22 | main(void)
23 | {
24 | printf("%d\n", process_numbers(13, 7, myadd));
25 | printf("%d\n", process_numbers(13, 7, mymultiply));
26 | }
27 |
--------------------------------------------------------------------------------
/src/fn-static-object.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void
4 | fn(void)
5 | {
6 | static int i = 0;
7 |
8 | printf("%d\n", ++i);
9 | }
10 |
11 | int
12 | main(void)
13 | {
14 | fn();
15 | fn();
16 | fn();
17 | fn();
18 | }
19 |
--------------------------------------------------------------------------------
/src/for.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | for (int i = 0, j = 10; i < 10; i++, j--) {
7 | printf("%d %d\n", i, j);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/fscanf.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int
6 | main(int argc, char *argv[])
7 | {
8 | if (argc != 2)
9 | errx(1, "usage: %s ", argv[0]);
10 |
11 | FILE *fp;
12 | if ((fp = fopen(argv[1], "r")) == NULL)
13 | err(1, "fopen");
14 |
15 | int num;
16 | char str[BUFSIZ]; // might not be enough
17 | while (fscanf(fp, "%d %s\n", &num, str) > 0)
18 | printf("%d '%s'\n", num, str);
19 |
20 | fclose(fp);
21 | }
22 |
--------------------------------------------------------------------------------
/src/func-implicit.c:
--------------------------------------------------------------------------------
1 | // gcc -std=c11 -pedantic-errors -Wall -Wextra
2 |
3 | #include
4 |
5 | // implicit function definitions should not be possible in C99+
6 | bool
7 | fce()
8 | {
9 | return (1);
10 | }
11 |
12 | int
13 | main(void)
14 | {
15 | return (fce());
16 | }
17 |
--------------------------------------------------------------------------------
/src/hello-world1.c:
--------------------------------------------------------------------------------
1 | /* missing include file, see the error message */
2 |
3 | int
4 | main(void)
5 | {
6 | printf("hello, world\n");
7 | }
8 |
--------------------------------------------------------------------------------
/src/hello-world2.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | printf("hello, world\n");
7 | }
8 |
--------------------------------------------------------------------------------
/src/if.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Modify 'i'. Compile, run, and check with "echo $?" on the command line.
3 | */
4 | int
5 | main(void)
6 | {
7 | int i = 13;
8 |
9 | if (i > 10)
10 | return (1);
11 | }
12 |
--------------------------------------------------------------------------------
/src/inches-to-cm.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int
5 | main(void)
6 | {
7 | int i = 1;
8 | int cm;
9 |
10 | printf("Inches\tCentimeters\n");
11 | while (i < 10) {
12 | cm = i * 2.54;
13 | /*
14 | * You can try to replace 'cm' directly with "i * 2.54" to see
15 | * what happens. I.e.:
16 | */
17 | //printf("%d\t%d\n", i, i * 2.54);
18 | printf("%d\t%d\n", i, cm);
19 | ++i;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/inches-to-cm2.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int
5 | main(void)
6 | {
7 | int i = 1;
8 |
9 | printf("Inches\tCentimeters\n");
10 | while (i < 10) {
11 | printf("%d\t%5.2f\n", i, i * 2.54);
12 | #if 0
13 | /* Try also these. */
14 | printf("%d\t%f\n", i, i * 2.54);
15 | printf("%d\t%.2f\n", i, i * 2.54);
16 | #endif
17 | ++i;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/init-array-from-string.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | char array[] = "foobar";
4 |
5 | int
6 | main(void)
7 | {
8 | printf("Array size: %zu\n", sizeof (array));
9 | printf("Array as string: '%s'\n", array);
10 | }
11 |
--------------------------------------------------------------------------------
/src/int-to-ptr.c:
--------------------------------------------------------------------------------
1 | int
2 | main(void)
3 | {
4 | int *p = 0x1234; // is not a valid behavior
5 | }
6 |
--------------------------------------------------------------------------------
/src/int-uint-cast.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int a = -42;
7 | unsigned int b;
8 |
9 | b = a;
10 |
11 | printf("%u\n", b);
12 |
13 | return (b);
14 | }
15 |
--------------------------------------------------------------------------------
/src/left-right-shift.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int shift = sizeof (int) * 8 - 4;
7 | printf("%u\n", (255 << shift) >> shift);
8 | printf("%u\n", (255U << shift) >> shift);
9 | }
10 |
--------------------------------------------------------------------------------
/src/linkage.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Use as:
3 | *
4 | * $ cc linkage.c ext.c
5 | */
6 | #include
7 |
8 | extern int i;
9 | /*
10 | * This will generate an error as the 'si' object is only visible within the
11 | * ext.c file.
12 | */
13 | extern int si;
14 |
15 | int
16 | main(void)
17 | {
18 | printf("%d\n", i);
19 | printf("%d\n", si);
20 | }
21 |
--------------------------------------------------------------------------------
/src/math.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int
5 | main(void)
6 | {
7 | printf("%f\n", lgamma(10.0));
8 | }
9 |
--------------------------------------------------------------------------------
/src/mul.c:
--------------------------------------------------------------------------------
1 | /*
2 | * compile with and without -DPARENS and see the difference.
3 | */
4 |
5 | #include
6 |
7 | #ifdef PARENS
8 | #define MUL(a, b) ((a) * (b))
9 | #else
10 | #define MUL(a, b) (a * b)
11 | #endif
12 |
13 | int
14 | main(void)
15 | {
16 | int i = 2, j = 3;
17 | printf("%d\n", MUL(i + j, 3));
18 | }
19 |
--------------------------------------------------------------------------------
/src/mult.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int a = INT_MAX, b = INT_MAX;
7 |
8 | return (a * b);
9 | }
10 |
--------------------------------------------------------------------------------
/src/my-assert.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | /* Custom assert macro, overrides the library function assert(3). */
6 | #ifdef assert
7 | #undef assert
8 | #endif
9 |
10 | #define assert(p) if (!(p)) { \
11 | fprintf(stderr, "assert failed at %d in %s\n", __LINE__, __FILE__); \
12 | exit(1); }
13 |
14 | int
15 | main(int argc, char *argv[])
16 | {
17 | assert(argc == 2);
18 | }
19 |
--------------------------------------------------------------------------------
/src/no-return.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | foo(int a)
5 | {
6 | if (a > 0)
7 | return (1);
8 |
9 | printf("foo!\n");
10 | }
11 |
12 | int
13 | main(void)
14 | {
15 | foo(0);
16 | }
17 |
--------------------------------------------------------------------------------
/src/not-one.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | /* Also try with '-10 + 1U + 10U' */
7 | printf("%ld\n", -10 + 1U + 10L);
8 | }
9 |
--------------------------------------------------------------------------------
/src/null-statement.c:
--------------------------------------------------------------------------------
1 | int
2 | main(void)
3 | {
4 | int i = 42;
5 |
6 | while (i-- > 0)
7 | ; // null statement
8 |
9 | ;;; // more null statements
10 |
11 | return (i);
12 | }
13 |
--------------------------------------------------------------------------------
/src/objs/.ignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/src/objs/.ignore
--------------------------------------------------------------------------------
/src/objs/solutions/.ignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/src/objs/solutions/.ignore
--------------------------------------------------------------------------------
/src/objs/tasks/.ignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devnull-cz/c-prog-lang/9e5f7df0e250638797eb3a30b8112d60296c563d/src/objs/tasks/.ignore
--------------------------------------------------------------------------------
/src/opaque-consumer.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "opaque.h"
4 |
5 | int
6 | main(void)
7 | {
8 | opaque_t h; // has to be a pointer
9 |
10 | // will not compile:
11 | // printf("%zu\n", sizeof (struct opaque));
12 |
13 | h = getOpaque();
14 | doStuff(h);
15 | }
16 |
--------------------------------------------------------------------------------
/src/opaque.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "opaque_impl.h"
4 |
5 | struct opaque *
6 | getOpaque(void)
7 | {
8 | return (malloc(sizeof (struct opaque)));
9 | }
10 |
11 | void
12 | doStuff(struct opaque *f)
13 | {
14 | f->x = 1;
15 | f->y = 2;
16 | }
17 |
--------------------------------------------------------------------------------
/src/opaque.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This is public header file, to be distributed with the library built
3 | * from opaque.c
4 | */
5 |
6 | struct opaque;
7 |
8 | typedef struct opaque *opaque_t;
9 |
10 | void doStuff(opaque_t f);
11 | opaque_t getOpaque(void);
12 |
--------------------------------------------------------------------------------
/src/opaque_impl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This is supposed to be a private header file, not shipped with the library
3 | * built from opaque.c.
4 | */
5 |
6 | struct opaque {
7 | int x;
8 | int y;
9 | };
10 |
--------------------------------------------------------------------------------
/src/operator.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int i = 1, j = 0;
7 |
8 | /*
9 | * Demonstrate both operator precedence (i+++j) and modification of
10 | * variable (j) between sequencing points.
11 | */
12 | if (((i+++j) > 1) || (++j)) {
13 | printf("yep\n");
14 | }
15 |
16 | printf("j = %d\n", j);
17 | }
18 |
--------------------------------------------------------------------------------
/src/plus-deref-plus-argv.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(int argc, char **argv)
5 | {
6 | /*
7 | * Assuming we run this as:
8 | *
9 | * $ ./a.out hello dear friend
10 | *
11 | * What will be printed?
12 | */
13 | printf("%s\n", argv[1]);
14 | printf("%s\n", ++*++argv);
15 | printf("%s\n", argv[0]);
16 | printf("%s\n", ++*++argv);
17 | printf("%s\n", argv[0]);
18 | }
19 |
--------------------------------------------------------------------------------
/src/plus-deref-plus-deref-argv.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(int argc, char **argv)
5 | {
6 | printf("%s\n", *++*++argv);
7 | }
8 |
--------------------------------------------------------------------------------
/src/print-int-as-double.c:
--------------------------------------------------------------------------------
1 | /*
2 | * There is no implicit type conversion for variadic function arguments aside
3 | * from the integeter promotion (which does no apply here).
4 | */
5 | #include
6 |
7 | int
8 | main(void)
9 | {
10 | /* Will not print 1.0 */
11 | printf("%.8f\n", 1);
12 |
13 | /* This is correct and will print 1.0000000 */
14 | printf("%.8f\n", (double)1);
15 | }
16 |
--------------------------------------------------------------------------------
/src/printf-format.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | printf("%lld", 1);
7 | }
8 |
--------------------------------------------------------------------------------
/src/printf.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | printf("hello, world\n");
7 | printf("hello, world\n");
8 | /* Strings are concatenated automatically (in C99, not in C89). */
9 | printf("hello, world\n"
10 | "hello, world\n");
11 | #if 0
12 | /*
13 | * This will return an error as a new line must not be part of a string
14 | * literal.
15 | */
16 | printf("hello, world
17 | hello world\n");
18 | #endif
19 | }
20 |
--------------------------------------------------------------------------------
/src/printf2.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | printf("%d %d\n", 1);
7 | }
8 |
--------------------------------------------------------------------------------
/src/ptr-change.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void
4 | change_ptr(int **p, int *val)
5 | {
6 | *p = val;
7 | }
8 |
9 | int
10 | main(void)
11 | {
12 | int i, j;
13 | int *p = &i;
14 |
15 | printf("&i = %p, &j = %p\n", &i, &j);
16 |
17 | printf("p = %p\n", p);
18 | change_ptr(&p, &j);
19 | printf("p = %p\n", p);
20 | }
21 |
--------------------------------------------------------------------------------
/src/ptr-inc.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int a[] = { 0, 1, 2 };
7 | int *p = a;
8 |
9 | printf("%d\n", *(p + 2)); // will print 2
10 |
11 | /* Note the increment is by sizeof (int) */
12 | printf("Size of int: %zu\n", sizeof (int));
13 | printf("%p\n%p\n%p\n", p, p + 1, p + 2);
14 | }
15 |
--------------------------------------------------------------------------------
/src/ptr-lvalue.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int i = 5;
7 | int *p = &(i + 1);
8 |
9 | printf("%d\n", *p);
10 | }
11 |
--------------------------------------------------------------------------------
/src/ptr-recap.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int n = 13;
7 | int *p = &n;
8 | int i = *p; // i will be 13
9 |
10 | printf("%d\n", i);
11 | }
12 |
--------------------------------------------------------------------------------
/src/ptr-with-array-notation.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | char a[] = "hello";
7 |
8 | /* Will print 'e' */
9 | printf("%c\n", *(a + 1));
10 | }
11 |
--------------------------------------------------------------------------------
/src/ptr_plus_plus.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int n = 5;
7 | int *p = &n;
8 |
9 | printf("%p %d\n", p, *p);
10 | (*p)++;
11 | printf("%p %d\n", p, *p);
12 | *p++;
13 | printf("%p %d\n", p, *p);
14 | }
15 |
--------------------------------------------------------------------------------
/src/random.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define SIZE 8
5 |
6 | void
7 | run(void)
8 | {
9 | char *p[SIZE] = { 0 };
10 |
11 | long int idx = random() % SIZE;
12 |
13 | for (size_t i = 0; i < SIZE; i++) {
14 | if (i == idx) {
15 | **(p + idx) = 'a';
16 | }
17 | }
18 | }
19 |
20 | int
21 | main(void)
22 | {
23 | srandom(time(NULL));
24 | run();
25 | }
26 |
--------------------------------------------------------------------------------
/src/range-check.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | bool
6 | check(long off, size_t size, size_t limit)
7 | {
8 | /* The last portion of the check is overflow avoidance. */
9 | if (off < 0 || off > limit || size > limit || limit - off < size) {
10 | warnx("not valid input");
11 | return (false);
12 | }
13 |
14 | return (true);
15 | }
16 |
17 | int
18 | main(void)
19 | {
20 | printf("%d\n", check(-1, 1, 255));
21 | }
22 |
--------------------------------------------------------------------------------
/src/recurs.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | static void
6 | foo(int n)
7 | {
8 | if (n == 0)
9 | return;
10 |
11 | sleep(1);
12 | foo(--n);
13 | }
14 |
15 | int
16 | main(int argc, char *argv[])
17 | {
18 | if (argc != 2)
19 | errx(1, "usage: %s ", argv[0]);
20 |
21 | foo(atoi(argv[1]));
22 | }
23 |
--------------------------------------------------------------------------------
/src/recursive-fn.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Print 0..9 recursively using a function call fn(9).
3 | */
4 | #include
5 |
6 | void
7 | myfn(int depth)
8 | {
9 | if (depth != 0)
10 | myfn(depth - 1);
11 | printf("%d\n", depth);
12 | }
13 |
14 | int
15 | main(void)
16 | {
17 | myfn(9);
18 | }
19 |
--------------------------------------------------------------------------------
/src/recursive-fn2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Print 9..0 recursively using a function call fn(9).
3 | */
4 | #include
5 |
6 | void
7 | myfn(int depth)
8 | {
9 | printf("%d\n", depth);
10 | /*
11 | * Also try to remove ';' after the return operator (do not change
12 | * anything else), then compile, execute, and explain what you see.
13 | */
14 | if (depth == 0)
15 | return;
16 | myfn(depth - 1);
17 | }
18 |
19 | int
20 | main(void)
21 | {
22 | myfn(9);
23 | }
24 |
--------------------------------------------------------------------------------
/src/request-c99.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Build with:
3 | *
4 | * gcc -std=c99 request-c99.c
5 | *
6 | * and also without it.
7 | */
8 | #if __STDC_VERSION__ != 199901L
9 | #error "C99 (and not greater) compiler required."
10 | #endif
11 |
12 | int
13 | main(void)
14 | {
15 | }
16 |
--------------------------------------------------------------------------------
/src/return-1.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int i = -1;
7 | unsigned int u = i;
8 |
9 | printf("0x%x\n", i);
10 | printf("%u\n", u);
11 | printf("%u\n", (u << 24) >> 24);
12 |
13 | return (i);
14 | }
15 |
--------------------------------------------------------------------------------
/src/return.c:
--------------------------------------------------------------------------------
1 | int
2 | main(void)
3 | {
4 | /*
5 | * See what "echo $?" prints out in the shell.
6 | *
7 | * Then also try "return (-1)" and "return (1000)" and check $? again.
8 | * You will NOT get -1 and 1000. See the lecture notes for explanation.
9 | */
10 | return (13);
11 | }
12 |
--------------------------------------------------------------------------------
/src/shadow-block.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Compile with -Wshadow (GCC) to see the warning about having the variable 'c'
3 | * shadowing the other one of the same name, but representing different objects.
4 | */
5 |
6 | #include
7 |
8 | int
9 | foo(void)
10 | {
11 | int c = 4;
12 |
13 | {
14 | int c = 1;
15 | c++;
16 | }
17 |
18 | return (++c);
19 | }
20 |
21 | int
22 | main(void)
23 | {
24 | /* Will print 5. */
25 | printf("%d\n", foo());
26 | }
27 |
--------------------------------------------------------------------------------
/src/shadow.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Compile with -Wshadow (GCC). Also see "./shadow-block.c" for more
3 | * information.
4 | */
5 |
6 | #include
7 |
8 | int c = 3;
9 |
10 | int
11 | foo(void)
12 | {
13 | int c = 4;
14 |
15 | return (++c);
16 | }
17 |
18 | int
19 | main(void)
20 | {
21 | /* Will print 5. */
22 | printf("%d\n", foo());
23 | }
24 |
--------------------------------------------------------------------------------
/src/solutions/3max.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int i = 1, j = 2, k = 3;
7 | int max;
8 |
9 | max = k > ((i > j) ? i : j) ? k : ((i > j) ? i : j);
10 |
11 | printf("max = %d\n", max);
12 | }
13 |
--------------------------------------------------------------------------------
/src/solutions/animal.h:
--------------------------------------------------------------------------------
1 | #ifndef _ANIMAL_H_
2 | #define _ANIMAL_H_
3 |
4 | #include // for size_t
5 | #include
6 |
7 | #ifndef NAME_MAX
8 | #define NAME_MAX 128
9 | #endif
10 |
11 | struct animal {
12 | char name[NAME_MAX]; // filename should be sufficient even
13 | // for these long Latin names
14 | size_t legs; // can have many legs
15 | };
16 |
17 | #endif /* _ANIMAL_H_ */
18 |
--------------------------------------------------------------------------------
/src/solutions/animal_maxlegs.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #include "animals.h"
4 | #include "animal_maxlegs.h"
5 |
6 | int
7 | main(void)
8 | {
9 | printf("%s\n",
10 | maxlegs(animals, sizeof (animals) / sizeof (animals[0]))->name);
11 | }
12 |
--------------------------------------------------------------------------------
/src/solutions/animal_maxlegs.h:
--------------------------------------------------------------------------------
1 | #include "animal.h"
2 |
3 | extern struct animal *maxlegs(struct animal *, size_t len);
4 |
--------------------------------------------------------------------------------
/src/solutions/animal_minlegs.h:
--------------------------------------------------------------------------------
1 | #include "animal.h"
2 |
3 | extern size_t count_minlegs(struct animal *animals, size_t len, size_t min);
4 |
--------------------------------------------------------------------------------
/src/solutions/animals.h:
--------------------------------------------------------------------------------
1 | #ifndef _ANIMALS_H_
2 | #define _ANIMALS_H
3 |
4 | #include "animal.h"
5 |
6 | struct animal animals[] = {
7 | { "human", 2 },
8 | { "frog", 4 },
9 | { "snail", 1 },
10 | { "snake", 0 },
11 | { "dog", 4 },
12 | { "spider", 8 },
13 | { "ant", 6 },
14 | { "centipede", 100 }
15 | };
16 | #else
17 | /* because this file contains definition of array we want to be extra careful */
18 | #error "multiple includes of animal definitions !"
19 | #endif /* _ANIMALS_H_ */
20 |
--------------------------------------------------------------------------------
/src/solutions/argv-do-while.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(int argc, char *argv[])
5 | {
6 | (void)argc;
7 |
8 | do {
9 | printf("%p '%s'\n", (void *)*argv, *argv);
10 | } while (*++argv != NULL);
11 | }
12 |
--------------------------------------------------------------------------------
/src/solutions/argv-for-v2.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(int argc, char **argv)
5 | {
6 | (void)argc;
7 |
8 | /* Not a nice way of doing things but shown as possible. */
9 | for ( ; *argv != NULL; printf("'%s'\n", *argv++))
10 | ;
11 | }
12 |
--------------------------------------------------------------------------------
/src/solutions/argv-for.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(int argc, char *argv[])
5 | {
6 | for (int i = 0; i < argc; i++)
7 | printf("%p '%s'\n", argv[i], argv[i]);
8 | }
9 |
--------------------------------------------------------------------------------
/src/solutions/argv-nodash.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(int argc, char *argv[])
5 | {
6 | for (int i = 0; i < argc; i++) {
7 | if (argv[i][0] != '-')
8 | printf("%p %s\n", argv[i], argv[i]);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/solutions/argv-while-v2.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(int argc, char **argv)
5 | {
6 | (void)argc;
7 |
8 | while (*argv++ != NULL) {
9 | printf("'%s'\n", *(argv - 1));
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/solutions/argv-while.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(int argc, char **argv)
5 | {
6 | while (*argv != NULL) {
7 | printf("'%s'\n", *argv++);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/solutions/ascii-hex.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int
5 | main(void)
6 | {
7 | unsigned char c = 0;
8 |
9 | while (c < 128) {
10 | if (isprint(c))
11 | printf("%02x %c\t", c, c);
12 | if (!isprint(c))
13 | printf("%02x NP\t", c);
14 |
15 | if ((c + 1) % 8 == 0)
16 | printf("\n");
17 |
18 | /*
19 | * NEVER do "if ((c++ + 1) % 8 == 0)" above as that is hard to
20 | * read and such code is prone to errors.
21 | */
22 | c++;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/solutions/create-string.c:
--------------------------------------------------------------------------------
1 | /*
2 | * See ../modules/warm-up/string.md
3 | */
4 | #include
5 |
6 | char str[] = { 'h', 'e', 'l', 'l', 'o', '\n', 'w', 'o', 'r', 'l', 'd', '\n',
7 | '\t', '\170' /* or: 'y' - 1 */, '\n', '\'' };
8 |
9 | int
10 | main(void)
11 | {
12 | printf("%s\n", str);
13 | }
14 |
--------------------------------------------------------------------------------
/src/solutions/fopen-leak.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | int
7 | main(int argc, char *argv[])
8 | {
9 | if (argc != 2)
10 | errx(1, "usage: %s ", argv[0]);
11 |
12 | for (size_t i = 1; i < UINT_MAX; i++) {
13 | FILE *f = fopen(argv[1], "r");
14 | if (f == NULL)
15 | err(1, "fopen [%zu]", i);
16 | printf("%zu\n", i);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/solutions/getchar.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Read characters from the standard input and print them out.
3 | */
4 | #include
5 |
6 | int
7 | main(void)
8 | {
9 | int c;
10 |
11 | while (1) {
12 | c = getchar();
13 | if (c == EOF)
14 | return (0);
15 | printf("%c", c);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/solutions/maxlegs.c:
--------------------------------------------------------------------------------
1 | #include "animal_maxlegs.h"
2 |
3 | static size_t
4 | getlegs(struct animal *a)
5 | {
6 | return (a->legs);
7 | }
8 |
9 | struct animal *
10 | maxlegs(struct animal *a, size_t len)
11 | {
12 | struct animal *p = a, *max = a;
13 |
14 | for (size_t i = 0; i < len; i++) {
15 | if (getlegs(p + i) >= getlegs(max))
16 | max = p + i;
17 | }
18 |
19 | return (max);
20 | }
21 |
--------------------------------------------------------------------------------
/src/solutions/null-ptr.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int *p = NULL;
7 |
8 | printf("%p\n", p); // This might print '(nil)' on some systems.
9 | // Use newline to flush the buffer.
10 | *p = 1;
11 | printf("%d", *p);
12 | }
13 |
--------------------------------------------------------------------------------
/src/solutions/offsetof.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define MYOFFSETOF(s, m) (size_t)(&((s *)0)->m)
4 |
5 | int
6 | main(void)
7 | {
8 | struct X { char a; int b; char c; };
9 |
10 | printf("%zu\n", MYOFFSETOF(struct X, c));
11 | }
12 |
--------------------------------------------------------------------------------
/src/solutions/print-ascii-table-subset.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | printf("Dec\tOct\tChar\n");
7 | for (int i = 'a'; i <= 'z'; ++i)
8 | printf("%d\t%o\t%c\n", i, i, i);
9 | }
10 |
--------------------------------------------------------------------------------
/src/solutions/ptr-basics.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int i = 5;
7 | int *p = &i;
8 |
9 | printf("pointer lives at %p\n", &p);
10 | printf("pointer points to %p\n", p);
11 | printf("value of the pointed address: %d\n", *p);
12 | }
13 |
--------------------------------------------------------------------------------
/src/solutions/ptr-diff.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int i = 1;
7 | int *p = &i;
8 | int *q = p + 1;
9 |
10 | printf("%p\n", p);
11 | printf("%p\n", q);
12 | /*
13 | * The different of two pointers is of ptrdiff_t type. It is defined as
14 | * a signed integer. You do not need to know what is the exact size on
15 | * your architecture if you use the 't' printf modifier (remember we use
16 | * 'z' modified for sizeof values).
17 | */
18 | printf("%td\n", q - p);
19 | }
20 |
--------------------------------------------------------------------------------
/src/solutions/struct-access-ptr.c:
--------------------------------------------------------------------------------
1 | struct foo_s {
2 | int *a;
3 | char b;
4 | };
5 |
6 | int
7 | main(void)
8 | {
9 | struct foo_s foo;
10 | struct foo_s *p_foo = &foo;
11 |
12 | /* first dereference and then access */
13 | int i = 42;
14 | foo.a = &i;
15 | *(*p_foo).a = 1; // eq. *(p_foo->a) = 1;
16 | (*p_foo).b = 'C'; // ditto
17 | }
18 |
--------------------------------------------------------------------------------
/src/solutions/struct-access.c:
--------------------------------------------------------------------------------
1 | struct foo_s {
2 | int a;
3 | char b;
4 | };
5 |
6 | int
7 | main(void)
8 | {
9 | struct foo_s foo;
10 | struct foo_s *p_foo = &foo;
11 |
12 | /* first dereference and then access */
13 | (*p_foo).a = 1; // eq. p_foo->a = 1;
14 | (*p_foo).b = 'C'; // ditto
15 | }
16 |
--------------------------------------------------------------------------------
/src/solutions/struct-animals.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #include "animals.h"
7 | #include "animal_minlegs.h"
8 |
9 | int
10 | main(int argc, char *argv[])
11 | {
12 | if (argc != 2)
13 | errx(1, "usage: %s ", argv[0]);
14 |
15 | printf("count: %zu\n",
16 | count_minlegs(animals, sizeof (animals) / sizeof (animals[0]),
17 | atoi(argv[1])));
18 | }
19 |
--------------------------------------------------------------------------------
/src/solutions/swap-by-reference.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /*
4 | * This function is actually useful in contrast to swap-by-value.c.
5 | */
6 | void
7 | swap(int *a, int *b)
8 | {
9 | int n = *a;
10 |
11 | *a = *b;
12 | *b = n;
13 | }
14 |
15 | int
16 | main(void)
17 | {
18 | int i = 1;
19 | int j = 2;
20 |
21 | swap(&i, &j);
22 | /* Will print 2 1 */
23 | printf("%d %d\n", i, j);
24 | }
25 |
--------------------------------------------------------------------------------
/src/solutions/toupper-ternary.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | mytoupper(int c)
5 | {
6 | return (c >= 'a' && c <= 'z' ? c - ('a' - 'A') : c);
7 | }
8 |
9 | int
10 | main(void)
11 | {
12 | int c;
13 |
14 | while ((c = getchar()) != EOF)
15 | printf("%c", mytoupper(c));
16 | }
17 |
--------------------------------------------------------------------------------
/src/solutions/union-lowhigh.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | union bar_u {
4 | unsigned short i; // 2 bytes
5 | struct {
6 | unsigned char low;
7 | unsigned char high;
8 | } bytes;
9 | };
10 |
11 | int
12 | main(void)
13 | {
14 | union bar_u bar = { .i = 256 };
15 |
16 | printf("size = %zu bytes\n", sizeof (bar));
17 | printf("low: %x high: %x\n", bar.bytes.low, bar.bytes.high);
18 |
19 | if (bar.bytes.low == 1)
20 | printf("big endian\n");
21 | else
22 | printf("little endian\n");
23 | }
24 |
--------------------------------------------------------------------------------
/src/solutions/usage.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int
5 | main(int argc, char *argv[])
6 | {
7 | if ((argc != 3) && (argc != 2))
8 | errx(1, "usage: %s [arg2]", argv[0]);
9 | }
10 |
--------------------------------------------------------------------------------
/src/static_assert.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define static_assert(p, cnt) \
4 | typedef int __assert ## cnt[(p) ? 1 : -1]
5 |
6 | static void
7 | foo(void *x)
8 | {
9 | printf("%p\n", x);
10 | }
11 |
12 | int
13 | main(void)
14 | {
15 | int i = 0xff;
16 |
17 | static_assert(sizeof(void *) >= sizeof i, 1);
18 | foo((void *) i);
19 | }
20 |
--------------------------------------------------------------------------------
/src/string-format.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | /* See printf(3) for more information. */
7 | printf("%5s\n", "foo");
8 | printf("%5s\n", "foobar");
9 | printf("%.5s\n", "foo");
10 | printf("%.5s\n", "foobar");
11 |
12 | /*
13 | * We can also align a string to the left, print it with a greater
14 | * width, and not print all of it. We will get the following:
15 | *
16 | * :hello, wor :
17 | */
18 | (void) printf(":%-15.10s:\n", "hello, world");
19 | }
20 |
--------------------------------------------------------------------------------
/src/string-isempty.c:
--------------------------------------------------------------------------------
1 | _Bool
2 | isempty(char s[])
3 | {
4 | return (s[0] == '\0');
5 | }
6 |
7 | int
8 | main(void)
9 | {
10 | return (isempty(""));
11 | }
12 |
--------------------------------------------------------------------------------
/src/string-literal-address.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | char *s;
7 |
8 | printf("%p\n", s = "hello world");
9 | printf("%s\n", s);
10 | /*
11 | * This probably prints the same address as the first printf() as only
12 | * one copy of the string is usually stored (usually in a read-only
13 | * segment).
14 | */
15 | printf("%p\n", "hello world");
16 | }
17 |
--------------------------------------------------------------------------------
/src/string-literal-write.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | char *s = "foo";
4 | char a[] = "bar";
5 |
6 | int
7 | main(void)
8 | {
9 | a[0] = 'B';
10 | printf("%s\n", a);
11 |
12 | /* causes segmentation failure (with GCC) */
13 | s[1] = 'A';
14 | printf("%s\n", s);
15 | }
16 |
--------------------------------------------------------------------------------
/src/string.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | char *string = "foo";
4 | char array[] = "bar";
5 |
6 | int
7 | main(void)
8 | {
9 | printf("modifying string\n");
10 | string[0] = 'A';
11 |
12 | printf("modifying array\n");
13 | array[0] = 'A';
14 | }
15 |
--------------------------------------------------------------------------------
/src/struct-X.c:
--------------------------------------------------------------------------------
1 | /* compile with and without -fpack-struct (GCC / Clang) and observe the difference */
2 |
3 | #include
4 |
5 | struct X { int a; char b; int c; };
6 | struct Y { int a; char b; int c; char d; };
7 | struct Z { int a; char b; int c; char *d; };
8 |
9 | int
10 | main(void)
11 | {
12 | printf("%zu\n", sizeof (struct X));
13 | printf("%zu\n", sizeof (struct Y));
14 | printf("%zu\n", sizeof (struct Z));
15 | }
16 |
--------------------------------------------------------------------------------
/src/struct-anon.c:
--------------------------------------------------------------------------------
1 | // compile with: -Wall -pedantic -std=c99
2 |
3 | #include
4 |
5 | int
6 | main(void)
7 | {
8 | struct {
9 | struct {
10 | int a;
11 | char b;
12 | };
13 | } foo;
14 |
15 | foo.a = 42;
16 | printf("%d\n", foo.a);
17 | }
18 |
--------------------------------------------------------------------------------
/src/struct-decl.c:
--------------------------------------------------------------------------------
1 | struct foo_s {
2 | int a;
3 | char b;
4 | };
5 |
6 | struct foo_s foo;
7 |
8 | int
9 | main(void)
10 | {
11 | }
12 |
--------------------------------------------------------------------------------
/src/struct-designated-init.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | struct foo_s {
4 | char a;
5 | int b;
6 | short c;
7 | void *p;
8 | };
9 |
10 | int
11 | main(void)
12 | {
13 | /* define a structure using 'designated initializers' from C99 */
14 | struct foo_s foo = {
15 | .b = 'C',
16 | .a = 1
17 | };
18 |
19 | printf("foo bar %p\n", &foo);
20 | /* Will be implicitly 0 */
21 | printf("%d\n", foo.c);
22 | /* Will be implicitly NULL (0) */
23 | printf("%p\n", foo.p);
24 | }
25 |
--------------------------------------------------------------------------------
/src/struct-foo.c:
--------------------------------------------------------------------------------
1 | struct foo {
2 | int a;
3 | } foo;
4 |
5 | int
6 | main(void)
7 | {
8 | }
9 |
--------------------------------------------------------------------------------
/src/struct-in-union.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | union foo {
7 | struct { // anonymous struct
8 | int a;
9 | int b;
10 | } s1;
11 | struct { // ditto
12 | short sa_1;
13 | short sa_2;
14 | short sb_1;
15 | short sb_2;
16 | } s2;
17 | } foo;
18 |
19 | foo.s1.a = 42;
20 | printf("%d %d\n", foo.s2.sa_1, foo.s2.sa_2);
21 | }
22 |
--------------------------------------------------------------------------------
/src/struct-init.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | struct foo_s {
4 | char a;
5 | int b;
6 | };
7 |
8 | int
9 | main(void)
10 | {
11 | struct foo_s foo = { 1, 'C' };
12 |
13 | /* Remember, char is promoted to int if passed to printf */
14 | printf("%d\n", foo.a);
15 | printf("%c\n", foo.b);
16 | }
17 |
--------------------------------------------------------------------------------
/src/struct-reference.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | struct foo_s {
4 | int a;
5 | char b;
6 | };
7 |
8 | int
9 | main(void)
10 | {
11 | struct foo_s foo;
12 | struct foo_s *p = &foo;
13 |
14 | printf("%p\n", &foo);
15 | printf("%p\n", &foo.b);
16 | /* Will print the same address as &foo */
17 | printf("%p\n", p);
18 | /* Will print the same address as &foo.b */
19 | printf("%p\n", &p->b);
20 | }
21 |
--------------------------------------------------------------------------------
/src/struct-unnamed.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | struct {
7 | int a;
8 | char b;
9 | } foo;
10 |
11 | foo.a = 42;
12 | printf("%d\n", foo.a);
13 | }
14 |
--------------------------------------------------------------------------------
/src/swap-by-value.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /*
4 | * This function is essentially useless.
5 | */
6 | void
7 | swap(int a, int b)
8 | {
9 | int n = a;
10 |
11 | a = b;
12 | b = n;
13 | }
14 |
15 | int
16 | main(void)
17 | {
18 | int i = 1;
19 | int j = 2;
20 |
21 | swap(i, j);
22 | /* Will print 1 2 */
23 | printf("%d %d\n", i, j);
24 | }
25 |
--------------------------------------------------------------------------------
/src/ternary-assign.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int i = 42, j = 43, max;
7 |
8 | /*
9 | * Note: the ternary conditional ?: has higher precedence than simple
10 | * assignment. If not using parens, it would try to assigng the
11 | * expression '(i > j) ? max = i : max' to j.
12 | */
13 |
14 | /*
15 | * (i > j) ? max = i : max = j;
16 | * (i > j) ? (max = i) : max = j;
17 | */
18 | (i > j) ? (max = i) : (max = j);
19 |
20 | printf("max = %d\n", max);
21 | }
22 |
--------------------------------------------------------------------------------
/src/ternary.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define PrintInt(expr) printf("%s : %d\n", #expr, (expr))
4 |
5 | int
6 | max(int x, int y)
7 | {
8 | (x > y) ? return x : return y;
9 | }
10 |
11 | int main()
12 | {
13 | int a = 10, b = 20;
14 |
15 | PrintInt(a);
16 | PrintInt(b);
17 | PrintInt(max(a,b));
18 | }
19 |
--------------------------------------------------------------------------------
/src/to-upper.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Convert all input to upper characters. Test with:
3 | *
4 | * $ cat /etc/passwd | ./a.out
5 | */
6 | #include
7 |
8 | int
9 | main(void)
10 | {
11 | int c;
12 |
13 | while (1) {
14 | c = getchar();
15 |
16 | if (c == EOF)
17 | break;
18 |
19 | if (c >= 'a' && c <= 'z')
20 | printf("%c", 'A' + c - 'a');
21 | else
22 | printf("%c", c);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/typedef.c:
--------------------------------------------------------------------------------
1 | typedef struct mystruct_s {
2 | int a;
3 | char c;
4 | } mystruct_t;
5 |
6 | int
7 | main(void)
8 | {
9 | struct mystruct_s s;
10 | struct mystruct_s *p = &s;
11 | mystruct_t *p2;
12 |
13 | /* No error or warning. The pointers are of the same type. */
14 | p2 = p;
15 | }
16 |
--------------------------------------------------------------------------------
/src/uintptr.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int
5 | main(void)
6 | {
7 | uintptr_t uptr;
8 | char *ptr = "foo";
9 |
10 | uptr = (uintptr_t)ptr;
11 |
12 | printf("%p\n", ptr);
13 | printf("0x%lx\n", uptr);
14 | }
15 |
--------------------------------------------------------------------------------
/src/union-in-struct.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | struct foo {
7 | union {
8 | int a;
9 | int b;
10 | } u;
11 | } foo;
12 |
13 | foo.u.a = 42;
14 | printf("%d\n", foo.u.b);
15 | }
16 |
--------------------------------------------------------------------------------
/src/unsigned-overflow.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | int
6 | main(void)
7 | {
8 | unsigned int a = UINT_MAX;
9 |
10 | printf("%u\n", ++a);
11 | }
12 |
--------------------------------------------------------------------------------
/src/use-after-free.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | static char *
4 | foo(size_t len)
5 | {
6 | return ((char *)malloc(len));
7 | }
8 |
9 | int
10 | main(void)
11 | {
12 | char *p = malloc(128);
13 |
14 | *p = 'A';
15 | free(p);
16 | *p = 'B';
17 |
18 | char *q = foo(16);
19 | *q = 'X';
20 | free(q);
21 | *q = 'Y';
22 | }
23 |
--------------------------------------------------------------------------------
/src/while.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int i = 0;
7 |
8 | while (i < 10) {
9 | printf("%d\n", i);
10 | ++i;
11 | }
12 | printf("--\n");
13 |
14 | /*
15 | * No need for {} for a single line body but some people would still
16 | * prefer using {}s.
17 | */
18 | i = 0;
19 | while (i < 10)
20 | printf("%d\n", i++);
21 | }
22 |
--------------------------------------------------------------------------------
/src/whole-array.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define TOTAL_ELEMENTS (sizeof (array) / sizeof (array[0]))
4 |
5 | int array[] = {23, 34, 12, 17, 204, 99, 16};
6 |
7 | int
8 | main(void)
9 | {
10 | int d = -1;
11 |
12 | while (d <= (TOTAL_ELEMENTS - 2)) {
13 | printf("%d\n", array[d + 1]);
14 | d++;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/why-it-works.c:
--------------------------------------------------------------------------------
1 | /*
2 | * This code may actually "work" by accident and print 100. Why is that?
3 | */
4 |
5 | #include
6 |
7 | int
8 | addnum(int n1, int n2)
9 | {
10 | int n = n1 + n2;
11 | }
12 |
13 | int
14 | main(void)
15 | {
16 | printf("%d\n", addnum(1, 99));
17 | }
18 |
--------------------------------------------------------------------------------
/src/words2.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | int c, inword = 0, words = 0;
7 |
8 | while ((c = getchar()) != EOF) {
9 | if (c == ' ' || c == '\t' || c == '\n') {
10 | words = words + inword;
11 | inword = 0;
12 | continue;
13 | }
14 | inword = 1;
15 | }
16 |
17 | if (inword == 1)
18 | ++words;
19 |
20 | printf("%d\n", words);
21 | }
22 |
--------------------------------------------------------------------------------
/src/wrong-modifier.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int
4 | main(void)
5 | {
6 | /*
7 | * This is NOT OK. Very probably will print some random number if
8 | * compiled with "-m 32". If compiled in 64 bits, it will probably work
9 | * fine but the compile should warn you anyway as it is still incorrect
10 | * code.
11 | */
12 | printf("%lld\n", 13);
13 |
14 | /* The following is always correct. Why? */
15 | char c = 13;
16 | printf("%d\n", c);
17 | }
18 |
--------------------------------------------------------------------------------
/src/x86-ABI.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void
4 | func(int a)
5 | {
6 | printf("%d\n", a);
7 | }
8 |
9 | int
10 | main(void)
11 | {
12 | unsigned char c = 'A';
13 |
14 | /* not an integral promotion but an x86 API manifestation */
15 | func(c);
16 | }
17 |
--------------------------------------------------------------------------------