NoodleText
main.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <termios.h>
#include <ctype.h>
#include <errno.h>
#include "args.h"
Include dependency graph for main.c:

Data Structures

struct  erow
 
struct  editorConfig
 
struct  abuf
 Append buffer: dynamic string type struct. More...
 

Macros

#define _DEFAULT_SOURCE
 
#define _BSD_SOURCE
 
#define _GNU_SOURCE
 
#define CTRL_KEY(k)   ((k)&0x1f)
 Value that represents the CTRL key. More...
 
#define NOODLE_VERSION   "0.0.1"
 

Enumerations

enum  editorKey {
  ARROW_LEFT = 1000 , ARROW_RIGHT , ARROW_UP , ARROW_DOWN ,
  DEL_KEY , HOME_KEY , END_KEY , PAGE_UP ,
  PAGE_DOWN
}
 

editorRow : a row of text

Contains the stored text and its size

#define ABUF_INIT   {NULL, 0}
 
typedef struct erow erow
 
struct editorConfig E
 
void kill (const char *s)
 =die. Error handling function using unistd.h More...
 
void disableRawMode ()
 Resets the terminal's attributes with orig_termios. More...
 
void enableRawMode ()
 Sets the terminal's attributes. More...
 
int editorReadKey ()
 
int getCursorPosition (int *rows, int *cols)
 
int getWindowSize (int *rows, int *cols)
 
void editorAppendRow (char *s, size_t len)
 
void editorOpen (char *filename)
 
void abAppend (struct abuf *ab, const char *s, int len)
 
void abFree (struct abuf *ab)
 Deallocates the dynamic memory used by the given. More...
 
void editorScroll ()
 Check if the cursor moved outside the editor window. More...
 
void editorDrawRows (struct abuf *ab)
 Draws the rows on the side of the editor. More...
 
void editorRefreshScreen ()
 Clears the screen of the editor. More...
 
void editorMoveCursor (int key)
 Receives the given WASD keys and moves the cursor accordingly. More...
 
void editorProcessKeypress ()
 
void initEditor ()
 Initialize all the fields in the E struct after enabling raw mode in the editor. More...
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ _BSD_SOURCE

#define _BSD_SOURCE

◆ _DEFAULT_SOURCE

#define _DEFAULT_SOURCE

◆ _GNU_SOURCE

#define _GNU_SOURCE

◆ ABUF_INIT

#define ABUF_INIT   {NULL, 0}

Represents an empty buffer, used as a constructor for the abuf type struct

◆ CTRL_KEY

#define CTRL_KEY (   k)    ((k)&0x1f)

Value that represents the CTRL key.

◆ NOODLE_VERSION

#define NOODLE_VERSION   "0.0.1"

Typedef Documentation

◆ erow

typedef struct erow erow

Enumeration Type Documentation

◆ editorKey

enum editorKey
Enumerator
ARROW_LEFT 
ARROW_RIGHT 
ARROW_UP 
ARROW_DOWN 
DEL_KEY 
HOME_KEY 
END_KEY 
PAGE_UP 
PAGE_DOWN 

Function Documentation

◆ abAppend()

void abAppend ( struct abuf ab,
const char *  s,
int  len 
)

Appends a string

  • s to the a given
  • abuf struct with a
  • len size by allocating enough memory for s

◆ abFree()

void abFree ( struct abuf ab)

Deallocates the dynamic memory used by the given.

  • ab abuf struct

◆ disableRawMode()

void disableRawMode ( )

Resets the terminal's attributes with orig_termios.

◆ editorAppendRow()

void editorAppendRow ( char *  s,
size_t  len 
)

◆ editorDrawRows()

void editorDrawRows ( struct abuf ab)

Draws the rows on the side of the editor.

Number of rows to draw

◆ editorMoveCursor()

void editorMoveCursor ( int  key)

Receives the given WASD keys and moves the cursor accordingly.

Parameters
keyRelates the key with WASD to move the cursor

◆ editorOpen()

void editorOpen ( char *  filename)

◆ editorProcessKeypress()

void editorProcessKeypress ( )

Processes the result/command of each key Calls the editorReadKey() function to receive the user's input

Input holder with stdin

◆ editorReadKey()

int editorReadKey ( )

Handles the reading of STDIN and stores a char at a time in input.

Returns
(char) input: key input from STDIN

◆ editorRefreshScreen()

void editorRefreshScreen ( )

Clears the screen of the editor.

◆ editorScroll()

void editorScroll ( )

Check if the cursor moved outside the editor window.

◆ enableRawMode()

void enableRawMode ( )

Sets the terminal's attributes.

◆ getCursorPosition()

int getCursorPosition ( int *  rows,
int *  cols 
)

◆ getWindowSize()

int getWindowSize ( int *  rows,
int *  cols 
)

Gives the size of the terminal

  • (*int) rows: window rows
  • (*int) cols: window collumns

◆ initEditor()

void initEditor ( )

Initialize all the fields in the E struct after enabling raw mode in the editor.

◆ kill()

void kill ( const char *  s)

=die. Error handling function using unistd.h

  • (string) s: error id name

◆ main()

int main ( int  argc,
char *  argv[] 
)

The Main function.

  • Receives arguments when called, used as options

Variable Documentation

◆ E

struct editorConfig E