Pages

Overview of Unix Commands for C Development

This document provides an explanation of various Unix commands used in the management and development of C software projects, highlighting their purposes and usage contexts.

File Formatting and Conversion

Convert spaces to tabs in C and header files:

sed -i 's/^[ ]\{4\}/\t/' *.c *.h

^[ \t]+

This command uses 'sed' to replace the first four spaces at the beginning of each line with a tab in all .c and .h files, modifying files in-place.

Convert DOS to Unix line endings in C and header files:

dos2unix *.c *.h

Applies the 'dos2unix' utility to convert line endings from CRLF (Carriage Return + Line Feed) to LF (Line Feed), which is standard in Unix/Linux environments.

Apply global DOS to Unix conversion and space-to-tab replacement:

find . -type f -exec dos2unix {} +
find . -type f -exec sed -i 's/^[ ]\{4\}/\t/' {} +

Runs 'dos2unix' and 'sed' on every file in the directory and subdirectories, converting line endings and replacing leading spaces with tabs, respectively.

Exclude .git directory during formatting:

find . -path './.git' -prune -o -type f -exec sed -i 's/^[ ]\{4\}/\t/' {} +
find . -path './.git' -prune -o -type f -exec dos2unix {} +

Specifically avoids modifying files within the '.git' directory while performing the same operations as above.

Code Style Enforcement

Check coding style of all C and header files:

betty *.c *.h

Applies 'Betty' style checks to all .c and .h files in the directory, enforcing consistency and standards across the project.

Compilation and Debugging

Compile all C files into an executable:

gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o shell

Compiles all .c files with strict compiler warnings and standards enforced, creating an executable named 'shell'.

Memory leak check with Valgrind:

valgrind --leak-check=full ./shell

Runs the compiled 'shell' executable through 'Valgrind' with a full leak check enabled, identifying any memory management issues.

No comments:

Post a Comment