getting started
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -52,3 +52,6 @@ Module.symvers
|
|||||||
Mkfile.old
|
Mkfile.old
|
||||||
dkms.conf
|
dkms.conf
|
||||||
|
|
||||||
|
|
||||||
|
# Directories
|
||||||
|
build/
|
||||||
|
|||||||
33
Makefile
Normal file
33
Makefile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
NAME=calculator-c-ncurses
|
||||||
|
VERSION=0.0.1
|
||||||
|
|
||||||
|
CC=gcc
|
||||||
|
AR=ar
|
||||||
|
RM=rm -f
|
||||||
|
CFLAGS=-Wall -Wextra -Wmissing-declarations -Wshadow -O2
|
||||||
|
INC=-I./include
|
||||||
|
LIBS=-lncurses
|
||||||
|
|
||||||
|
CALC_S=./src/main.c ./src/calculate.c
|
||||||
|
CALC_O=$(CALC_S:%.c=%.o)
|
||||||
|
CALC_T=calculator-c-ncurses
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
|
||||||
|
all: prepare $(CALC_T)
|
||||||
|
|
||||||
|
$(CALC_T): $(CALC_O)
|
||||||
|
$(CC) $(INC) $(LIBS) -o ./build/$@ $^
|
||||||
|
.c.o:
|
||||||
|
@echo $<
|
||||||
|
$(CC) $(CFLAGS) $(LIBS) $(INC) -c $< -o $@
|
||||||
|
|
||||||
|
$(CALC_O): $(CALC_S)
|
||||||
|
|
||||||
|
prepare:
|
||||||
|
mkdir -p ./build/
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) ./src/*.o
|
||||||
12
include/calculate.h
Normal file
12
include/calculate.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef CALCULATE_H_
|
||||||
|
#define CALCULATE_H_
|
||||||
|
|
||||||
|
int strlen(char* str);
|
||||||
|
|
||||||
|
void strrev(char* str);
|
||||||
|
|
||||||
|
int atoi(char* src, int target);
|
||||||
|
|
||||||
|
float atof(char* src, float target);
|
||||||
|
|
||||||
|
#endif
|
||||||
8
include/main.h
Normal file
8
include/main.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef MAIN_H_
|
||||||
|
#define MAIN_H_
|
||||||
|
|
||||||
|
#include <ncurses.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv);
|
||||||
|
|
||||||
|
#endif
|
||||||
23
src/calculate.c
Normal file
23
src/calculate.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include <calculate.h>
|
||||||
|
|
||||||
|
int strlen(char* str) {
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
while (str[res] != '\0') {
|
||||||
|
res += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void strrev(char* str) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int atoi(char* src, int target) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float atof(char* src, float target) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
31
src/main.c
Normal file
31
src/main.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include <main.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
int scrHeight, scrWidth;
|
||||||
|
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
initscr();
|
||||||
|
noecho();
|
||||||
|
keypad(stdscr, TRUE);
|
||||||
|
start_color();
|
||||||
|
init_pair(1, COLOR_RED, COLOR_BLUE);
|
||||||
|
wbkgd(stdscr, COLOR_PAIR(1));
|
||||||
|
|
||||||
|
getmaxyx(stdscr, scrHeight, scrWidth);
|
||||||
|
|
||||||
|
printw("Width: %d, Height: %d", scrWidth, scrHeight);
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
ch = getch();
|
||||||
|
|
||||||
|
if (ch == 'q') break;
|
||||||
|
}
|
||||||
|
|
||||||
|
attrset(0);
|
||||||
|
endwin();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user