The 42-compliant Kilo Text editor
A simple terminal text editor compliant with 42's standards.
📜 Table of Contents
🧐 About
“Programs do one thing, do it well, and act on files.” Some bearded nerd in the 70's
CLI text editor written in C, following 42's Norminette. Inspired by:
📝 Notes
Compile and Run
Using make
:
$ make && ./kilo
$ make clean
Norminnette
- Install
$ git clone https://github.com/42Paris/norminette.git ~/.norminette/
$ cd ~/.norminette/
$ bundle
$ echo 'alias norminette="~/.norminette/norminette.rb"' >> ~/.bash_profile
$ source ~/.bash_profile
- Run
$ norminette *.c **/*.c **/*.h
Quirks
/*
** This is a proper norminette comment
*/
int main(void)
{
int variable_one;
char variable_two;
variable_one = 42;
return (0);
}
Makefile
$(CC)
is a variable that make expands to cc by default.-Wall
stands for “all Warnings”, and gets the compiler to warn you when it sees code in your program that might not technically be wrong, but is considered bad or questionable usage of the C language, like using variables before initializing them.-Wextra
,-Werror
and-pedantic
turn on even more warnings. For each step in this tutorial, if your program compiles, it shouldn’t produce any warnings except for “unused variable” warnings in some cases. If you get any other warnings, check to make sure your code exactly matches the code in that step.-std=c99
specifies the exact version of the C language standard we’re using, which is C99. C99 allows us to declare variables anywhere within a function, whereas ANSI C requires all variables to be declared at the top of a function or block.
termios.h
Contains the definitions used by the terminal I/O interfaces.
-
IXON
: input bitflag that enablesXOFF
andXON
signal,Ctrl-S
andCtrl-Q
respectively. -
ICRNL
: input bitflag that enables the terminal to interpret a carriage return as a new line. -
BRKINT
: input bitflag sends aSIGINT
signal to the program whenever it reaches a break condition. -
INPCK
: input bitflag that enables parity checking. -
ISTRIP
: input bitflag that "strips" the 8th bit of each input byte, i.e., sets it to 0. -
OPOST
: output bitflag that enables post-processing of output, like\n
into\r\n
. When we disable it, the terminal emulator doesn't input a carriage return after every new line and the output "stairs down" the terminal. -
CS8
: bit mask that sets the character size (CS) to 8 bits per byte. -
ECHO
: local bitflag that causes each key you type to be printed to the terminal. Disabling it no longer prints everything we type on the terminal. -
ICANON
: local bitflag that enables canonical mode, i.e., reads input line-by-line. Disabling it allows us to read input byte-by-byte. -
ISIG
: local bitflag that enablesSIGINT
andSIGTSTP
signal,Ctrl-C
andCtrl-Z
respectively. -
IEXTEN
: local bitflag that enablesCtrl-V
andCtrl-O
signals, that interpret the next character as a literal. -
VMIN
: control character index that represents the minimun number of bytes thatread()
reads before returning. -
VTIME
: control character index that represents the timeout ofread()
in tenths of a second.
sys/ioctl.h
TIOCGWINSZ
: TerminalInputOutputControlGetWINdowSiZe
🛸 42 São Paulo
Part of the larger 42 Network, 42 São Paulo is a software engineering school that offers a healthy alternative to traditional education:
- It doesn't have any teachers and classes.
- Students learn by cooperating and correcting each other's work (peer-to-peer learning).
- Its focus is as much on social skills as it is on technical skills.
- It's completely free to anyone that passes its selection process - The Piscine
It's an amazing school, and I'm grateful for the opportunity.
“I believe 42 will have a rippling effect on the history of the world.” @michaelbrave
The more I study at 42 the more I see the revival of a powerful educational method renewed to a modern discipline. It's not a school in the traditional sense, but more like a Tech Dojo with training and sparring.
Basically the computer nerd version of the Lyceum as opposed to the Apollonian Academy.
📚 Resources
-
https://www.tutorialspoint.com/cprogramming/c_data_types.htm
-
http://check.sourceforge.net/doc/check_html/check_2.html#SEC3
-
https://stackoverflow.com/questions/65820/unit-testing-c-code
-
https://notes.eatonphil.com/unit-testing-c-code-with-gtest.html
-
https://opensource.com/article/19/7/structure-multi-file-c-part-1