From 6042c9f07fe79651893953e1f3f69528806a8a5d Mon Sep 17 00:00:00 2001 From: Quentin Rameau Date: Mon, 5 Aug 2019 00:53:35 +0200 Subject: Makefile: take advantage of having separate build units --- Makefile | 14 +++-- gramscii.c | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 182 ------------------------------------------------------------- 3 files changed, 190 insertions(+), 188 deletions(-) create mode 100644 gramscii.c delete mode 100644 main.c diff --git a/Makefile b/Makefile index 24aa1d3..71887b1 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,9 @@ include config.mk -SRC = main.c draw.c screen.c files.c lineset.c +SRC = gramscii.c draw.c screen.c files.c lineset.c INC = config.h gramscii.h arg.h +OBJ = ${SRC:.c=.o} DISTFILES = ${SRC} ${INC} Makefile config.mk README.md Changelog all: options gramscii @@ -16,14 +17,15 @@ options: @echo "LDFLAGS = ${LDFLAGS}" @echo "CC = ${CC}" @echo "-+-+-+-+-+-+-+-+-+-+-" - -gramscii: ${SRC} ${INC} - ${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${SRC} - + +gramscii: ${OBJ} + +${OBJ}: ${INC} + clean: @echo cleaning - @rm -f gramscii + @rm -f gramscii ${OBJ} install: all @echo installing executable to ${DESTDIR}${BINDIR} diff --git a/gramscii.c b/gramscii.c new file mode 100644 index 0000000..9a6ef59 --- /dev/null +++ b/gramscii.c @@ -0,0 +1,182 @@ +/* +* +* gramscii: a simple editor for ASCII box-and-arrow charts +* +* Copyright (c) 2019 Vincenzo "KatolaZ" Nicosia +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. Please see the attached file COPYING. +* Otherwise, please visit . +* +*/ + +#include +#include +#include + +#include "arg.h" +#include "gramscii.h" + + +char *argv0; + + +void cleanup(int s){ + + if (!silent) + printf("\033[;H\033[2J"); + else + dump_lines(screen, stdout); + tcsetattr(0, TCSANOW, &t1); + fflush(stdout); + exit(0); +} + +void exit_cleanup(void){ + cleanup(0); +} + +/*** Initialisation ***/ + +void init(){ + + signal(SIGHUP, cleanup); + signal(SIGINT, cleanup); + signal(SIGTERM, cleanup); + signal(SIGQUIT, cleanup); + atexit(exit_cleanup); + + tcgetattr(0, &t1); + t2 = t1; + t2.c_lflag &= ~(ICANON | ECHO); + tcsetattr(0, TCSANOW, &t2); + + init_screen(); + x = 0; + y = 0; + step = 1; + modified = 0; + fname[0] = '\0'; + redraw(); +} + + +/*** Commands ***/ + +void commands(FILE *fc){ + + char c; + while((c=fgetc(fc))!=EOF){ + if (!change_style(c) && !move_around(c, fc)){ + switch(c){ + case 'i': + mode = TEXT; + get_text(fc); + break; + case 'R': + redraw(); + break; + case 'b': + mode = BOX; + get_box(fc); + break; + case 'A': autoend=1; + case 'a': + mode = ARROW; + get_arrow(fc); + autoend = 0; + break; + case 'W': + force_new = 1;/** FALLTHROUGH **/ + case 'w': + write_file(fc); + break; + case 'e': + check_modified(fc);/** FALLTHROUGH **/ + case 'E': + load_file(fc); + break; + case 'N': + new_file(fc); + break; + case 'x': + mode = DEL; + erase(fc); + break; + case 'v': + mode = VIS; + visual_box(fc); + break; + case 'C': + crop_to_nonblank(); + break; + case 'p': + paste(); + break; + case 'u': + undo_change(); + break; + case 'U': + redo_change(); + break; + case 'q': + check_modified(fc);/** FALLTHROUGH **/ + case 'Q': + exit(0); + break; + } + } + check_bound(&x, &y); + status_bar(); + show_cursor(); + step = 1; + force_new = 0; + } + +} + +void usage(){ + fprintf(stderr, "Usage: %s [-s] [-h] [file ...]\n", argv0); + exit(1); +} + + +int main(int argc, char *argv[]){ + FILE *fc; + + ARGBEGIN { + case 's': + silent = 1; + break; + case 'h': /* FALLTHROUGH */ + default: + usage(); + } ARGEND; + + init(); + while (argc){ + fc = fopen(argv[0], "r"); + if (fc == NULL){ + fprintf(stderr, "Error opening file %s\n", argv[0]); + } + else { + commands(fc); + fclose(fc); + redraw(); + } + argv++; + argc--; + } + commands(stdin); + return 0; +} diff --git a/main.c b/main.c deleted file mode 100644 index 9a6ef59..0000000 --- a/main.c +++ /dev/null @@ -1,182 +0,0 @@ -/* -* -* gramscii: a simple editor for ASCII box-and-arrow charts -* -* Copyright (c) 2019 Vincenzo "KatolaZ" Nicosia -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. Please see the attached file COPYING. -* Otherwise, please visit . -* -*/ - -#include -#include -#include - -#include "arg.h" -#include "gramscii.h" - - -char *argv0; - - -void cleanup(int s){ - - if (!silent) - printf("\033[;H\033[2J"); - else - dump_lines(screen, stdout); - tcsetattr(0, TCSANOW, &t1); - fflush(stdout); - exit(0); -} - -void exit_cleanup(void){ - cleanup(0); -} - -/*** Initialisation ***/ - -void init(){ - - signal(SIGHUP, cleanup); - signal(SIGINT, cleanup); - signal(SIGTERM, cleanup); - signal(SIGQUIT, cleanup); - atexit(exit_cleanup); - - tcgetattr(0, &t1); - t2 = t1; - t2.c_lflag &= ~(ICANON | ECHO); - tcsetattr(0, TCSANOW, &t2); - - init_screen(); - x = 0; - y = 0; - step = 1; - modified = 0; - fname[0] = '\0'; - redraw(); -} - - -/*** Commands ***/ - -void commands(FILE *fc){ - - char c; - while((c=fgetc(fc))!=EOF){ - if (!change_style(c) && !move_around(c, fc)){ - switch(c){ - case 'i': - mode = TEXT; - get_text(fc); - break; - case 'R': - redraw(); - break; - case 'b': - mode = BOX; - get_box(fc); - break; - case 'A': autoend=1; - case 'a': - mode = ARROW; - get_arrow(fc); - autoend = 0; - break; - case 'W': - force_new = 1;/** FALLTHROUGH **/ - case 'w': - write_file(fc); - break; - case 'e': - check_modified(fc);/** FALLTHROUGH **/ - case 'E': - load_file(fc); - break; - case 'N': - new_file(fc); - break; - case 'x': - mode = DEL; - erase(fc); - break; - case 'v': - mode = VIS; - visual_box(fc); - break; - case 'C': - crop_to_nonblank(); - break; - case 'p': - paste(); - break; - case 'u': - undo_change(); - break; - case 'U': - redo_change(); - break; - case 'q': - check_modified(fc);/** FALLTHROUGH **/ - case 'Q': - exit(0); - break; - } - } - check_bound(&x, &y); - status_bar(); - show_cursor(); - step = 1; - force_new = 0; - } - -} - -void usage(){ - fprintf(stderr, "Usage: %s [-s] [-h] [file ...]\n", argv0); - exit(1); -} - - -int main(int argc, char *argv[]){ - FILE *fc; - - ARGBEGIN { - case 's': - silent = 1; - break; - case 'h': /* FALLTHROUGH */ - default: - usage(); - } ARGEND; - - init(); - while (argc){ - fc = fopen(argv[0], "r"); - if (fc == NULL){ - fprintf(stderr, "Error opening file %s\n", argv[0]); - } - else { - commands(fc); - fclose(fc); - redraw(); - } - argv++; - argc--; - } - commands(stdin); - return 0; -} -- cgit v1.2.3