init
This commit is contained in:
commit
a409fac4e8
19
src/Makefile
Normal file
19
src/Makefile
Normal file
@ -0,0 +1,19 @@
|
||||
CC = /bin/cc
|
||||
LEX = /bin/lex
|
||||
RM = /bin/rm
|
||||
|
||||
all:
|
||||
@echo "Run 'make parser' to build the parser, or 'make lexer' to build the lexer."
|
||||
|
||||
parser:
|
||||
$(CC) parse.c -o parser
|
||||
|
||||
lexer:
|
||||
$(LEX) lexer.l
|
||||
$(CC) lex.yy.c -lfl -o lexer
|
||||
|
||||
clean-parser:
|
||||
$(RM) parser
|
||||
|
||||
clean-lexer:
|
||||
$(RM) lexer lex.yy.c
|
28
src/emk.h
Normal file
28
src/emk.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
emk.h - define functions
|
||||
|
||||
This file is part of emk.
|
||||
|
||||
emk 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.
|
||||
|
||||
emk 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 emk. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EMK_H_
|
||||
#define EMK_H_
|
||||
|
||||
int checkForRoot();
|
||||
char checkForEmkFile();
|
||||
char readEmkFile();
|
||||
char includeFromConfig();
|
||||
|
||||
#endif
|
6
src/examples/config.emk
Normal file
6
src/examples/config.emk
Normal file
@ -0,0 +1,6 @@
|
||||
// config.emk
|
||||
|
||||
declare CC = "/bin/cc"
|
||||
declare AR = "/bin/ar"
|
||||
|
||||
declare PREFIX = "/usr"
|
18
src/examples/emkfile
Normal file
18
src/examples/emkfile
Normal file
@ -0,0 +1,18 @@
|
||||
include ./config.emk;
|
||||
|
||||
declare NCVER = "1.0";
|
||||
declare MKOBJ = "$CC $CFLAGS $LDFLAGS -c";
|
||||
|
||||
function build {
|
||||
echo "Building package";
|
||||
$COMPILE src/main.c -o src/main.o;
|
||||
$COMPILE src/printevents.c -o src/printevents.o;
|
||||
$COMPILE src/mkevent.c -o src/mkevent.o;
|
||||
$CC $CFLAGS $LDFLAGS -o src/nc src/main.o src/printevents.o src/mkevent.o;
|
||||
}
|
||||
|
||||
function install {
|
||||
install src/nc $PREFIX/bin;
|
||||
install man/nc.1 $PREFIX/share/man/man1;
|
||||
gzip $PREFIX/share/man/man1/nc.1;
|
||||
}
|
65
src/include.c
Normal file
65
src/include.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include <libcolor.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "parse.h"
|
||||
|
||||
/* char process-old() {
|
||||
char cwd[PATH_MAX];
|
||||
FILE *emkconfig, *emkfile;
|
||||
char filename[100], contents;
|
||||
|
||||
emkconfig = fopen(EMKCONFIG, "r");
|
||||
if (emkconfig == NULL) {
|
||||
printf(COL_BLUE "INF" COL_RESET " | no config.emk found\n");
|
||||
} else if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
printf(COL_BLUE "INF" COL_RESET " | including config.emk at %s\n", cwd);
|
||||
}
|
||||
|
||||
emkfile = fopen(EMKFILE, "a+");
|
||||
|
||||
contents = fgetc(emkconfig);
|
||||
while (contents != EOF) {
|
||||
fputc(contents, emkfile);
|
||||
contents = fgetc(emkconfig);
|
||||
}
|
||||
|
||||
fclose(emkconfig);
|
||||
fclose(emkfile);
|
||||
} */
|
||||
|
||||
char processFile() {
|
||||
char cwd[PATH_MAX];
|
||||
FILE *emkconfig, *emkfile, *emkfile_new;
|
||||
char filename[100], contents;
|
||||
|
||||
emkconfig = fopen(EMKCONFIG, "r");
|
||||
emkfile = fopen(EMKFILE, "r");
|
||||
|
||||
emkfile_new = fopen(EMKFILE_NEW, "a+");
|
||||
|
||||
/* write contents of emkconfig to new emkfile */
|
||||
contents = fgetc(emkconfig);
|
||||
while (contents != EOF) {
|
||||
fputc(contents, emkfile_new);
|
||||
contents = fgetc(emkconfig);
|
||||
}
|
||||
|
||||
/* write contents of emkfile to new emkfile */
|
||||
contents = fgetc(emkfile);
|
||||
while (contents != EOF) {
|
||||
fputc(contents, emkfile_new);
|
||||
contents = fgetc(emkfile);
|
||||
}
|
||||
|
||||
fclose(emkconfig);
|
||||
fclose(emkfile);
|
||||
}
|
||||
|
||||
int main() {
|
||||
processFile();
|
||||
}
|
||||
|
18
src/lex-tests/lex2.l
Normal file
18
src/lex-tests/lex2.l
Normal file
@ -0,0 +1,18 @@
|
||||
%%
|
||||
"include" { printf("INCLUDE"); }
|
||||
"declare" { printf("DECLARE"); }
|
||||
"function" { printf("FUNCTION"); }
|
||||
%%
|
||||
|
||||
#define EMKFILE "emkfile"
|
||||
|
||||
int yywrap(){}
|
||||
int main() {
|
||||
FILE *fp;
|
||||
char filename[50];
|
||||
fp = fopen(EMKFILE, "r");
|
||||
yyin = fp;
|
||||
|
||||
yylex();
|
||||
return 0;
|
||||
}
|
5
src/lex-tests/lexer.l
Normal file
5
src/lex-tests/lexer.l
Normal file
@ -0,0 +1,5 @@
|
||||
%%
|
||||
"include" { printf("INCLUDE"); }
|
||||
"declare" { printf("DECLARE"); }
|
||||
"function" { printf("FUNCTION"); }
|
||||
%%
|
11
src/lex-tests/lexer.l.old
Normal file
11
src/lex-tests/lexer.l.old
Normal file
@ -0,0 +1,11 @@
|
||||
%%
|
||||
|
||||
"function" { printf("FUNCTION"); }
|
||||
"declare" { printf("DECLARE"); }
|
||||
"include" { printf("INCLUDE"); }
|
||||
|
||||
"""" { printf("STRING %s STRING_END", yytext); }
|
||||
|
||||
. { printf("%s", yytext); }
|
||||
|
||||
%%
|
100
src/parse.c
Normal file
100
src/parse.c
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
parse.c - parse an emkfile
|
||||
|
||||
This file is part of emk.
|
||||
|
||||
emk 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.
|
||||
|
||||
emk 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 emk. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libcolor.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "parse.h"
|
||||
|
||||
struct emkfileData {
|
||||
char cc;
|
||||
char prefix;
|
||||
};
|
||||
|
||||
int checkForRoot() {
|
||||
printf(COL_BLUE "INF" COL_RESET " | checking for root access...\n");
|
||||
if (geteuid() != 0) {
|
||||
printf(COL_BLUE "INF" COL_RESET " | running emk without root\n");
|
||||
} else {
|
||||
printf(COL_BLUE "INF" COL_RESET " | running emk as root\n");
|
||||
}
|
||||
}
|
||||
|
||||
char checkForEmkFile() {
|
||||
char cwd[PATH_MAX];
|
||||
FILE *emkfile;
|
||||
|
||||
emkfile = fopen(EMKFILE, "r");
|
||||
if (emkfile == NULL) {
|
||||
printf(COL_RED "ERR" COL_RESET " | emkfile does not exist\n");
|
||||
exit(1);
|
||||
} else if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
printf(COL_BLUE "INF" COL_RESET " | using emkfile at %s/emkfile\n", cwd);
|
||||
}
|
||||
fclose(emkfile);
|
||||
}
|
||||
|
||||
char readEmkFile() {
|
||||
FILE *emkfile;
|
||||
|
||||
char filename[100], contents;
|
||||
|
||||
emkfile = fopen(EMKFILE, "r");
|
||||
printf(COL_BLUE "INF" COL_RESET " | opening emkfile\n");
|
||||
contents = fgetc(emkfile);
|
||||
while (contents != EOF) {
|
||||
printf ("%c", contents);
|
||||
contents = fgetc(emkfile);
|
||||
}
|
||||
fclose(emkfile);
|
||||
}
|
||||
|
||||
char includeFromConfig() {
|
||||
char cwd[PATH_MAX];
|
||||
FILE *emkconfig, *emkfile;
|
||||
char filename[100], contents;
|
||||
|
||||
emkconfig = fopen(EMKCONFIG, "r");
|
||||
if (emkconfig == NULL) {
|
||||
printf(COL_BLUE "INF" COL_RESET " | no config.emk found\n");
|
||||
} else if (getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
printf(COL_BLUE "INF" COL_RESET " | including config.emk at %s\n", cwd);
|
||||
}
|
||||
|
||||
emkfile = fopen(EMKFILE, "w");
|
||||
|
||||
contents = fgetc(emkconfig);
|
||||
while (contents != EOF) {
|
||||
fputc(contents, emkfile);
|
||||
contents = fgetc(emkconfig);
|
||||
}
|
||||
|
||||
fclose(emkconfig);
|
||||
fclose(emkfile);
|
||||
}
|
||||
|
||||
int main() {
|
||||
checkForEmkFile();
|
||||
readEmkFile();
|
||||
checkForRoot();
|
||||
}
|
27
src/parse.h
Normal file
27
src/parse.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
parse.h - define macros for parse.c
|
||||
|
||||
This file is part of emk.
|
||||
|
||||
emk 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.
|
||||
|
||||
emk 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 emk. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PARSE_H_
|
||||
#define PARSE_H_
|
||||
|
||||
#define EMKFILE "emkfile"
|
||||
#define EMKFILE_NEW "emkfile.new"
|
||||
#define EMKCONFIG "config.emk"
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user