New format; we can also use bison if we want.

This commit is contained in:
dcp1990 2005-06-01 20:31:50 +00:00
parent 9cac8602cd
commit a7848e0855
7 changed files with 115 additions and 17 deletions

View File

@ -1,22 +1,24 @@
# cnd Makefile
# (C)2005, Dan Ponte
# $Amigan: phoned/phoned/Makefile,v 1.3 2005/06/01 01:11:23 dcp1990 Exp $
# $Amigan: phoned/phoned/Makefile,v 1.4 2005/06/01 20:31:50 dcp1990 Exp $
include ../global.mk
# basic stuff. we append for a reason.
CPPFLAGS=-I../include -DDEBUG
CPPFLAGS=-I../include -DDEBUG -DYYERROR_VERBOSE
CFLAGS+=-g -Wall -W -ansi ${CPPFLAGS}
LDFLAGS=
LDFLAGS=-lutil
# keep these up to date.
MAINBIN=phoned
SRCS=main.c init.c log.c cfg.c socket.c y.tab.c lex.yy.c signals.c cid.c
OBJS=main.o init.o log.o cfg.o socket.o y.tab.o lex.yy.o signals.o cid.o
SRCS=main.c init.c log.c cfg.c socket.c y.tab.c lex.yy.c signals.c cid.c modem.c
OBJS=main.o init.o log.o cfg.o socket.o y.tab.o lex.yy.o signals.o cid.o modem.o
OHDRS=y.tab.h
CLEANFILES=y.tab.c y.tab.h lex.yy.c
LEX=lex
YACC=yacc
include ../main.mk
y.tab.h: y.tab.c
y.tab.c: config.y
yacc -d config.y
$(YACC) -d config.y
lex.yy.c: config.l y.tab.c y.tab.h
lex config.l
$(LEX) config.l

View File

@ -1,15 +1,24 @@
/* configuration lexer */
%{
#include <stdio.h>
#include <string.h>
#ifdef BISON
#include "config.tab.h"
#else
#include "y.tab.h"
#endif
#include <phoned.h>
extern int chrcnt, lincnt;
%}
%%
. ++chrcnt; REJECT;
main return MAIN;
notify return NOTIFY;
modemdev return MODDEV;
\" return QUOTE;
\{ return OBRACE;
\} return CBRACE;
\/[a-zA-Z0-9/._-]+ yylval.string = strdup(yytext); return PATH;
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} yylval.string = strdup(yytext); return IPADDR;
; return SCOLON;
\n chrcnt = 0; ++lincnt;/* DONOTHING */

View File

@ -7,15 +7,17 @@
%{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <phoned.h>
int chrcnt = 0;
int lincnt = 0;
int lincnt = 1;
int yylex(void);
extern char* yytext;
void yyerror(str)
char* str;
{
lprintf(fatal, "parser: error: %s at line %d chr %d\n", str, lincnt,
chrcnt);
lprintf(fatal, "parser: error: %s at line %d chr %d (near %s)\n", str,
lincnt, chrcnt, yytext);
exit(-1);
}
int yywrap(void)
@ -23,15 +25,33 @@ int yywrap(void)
return 1;
}
%}
%token NOTIFY OBRACE CBRACE SCOLON
%token <string> IPADDR
%token NOTIFY OBRACE CBRACE SCOLON QUOTE MODDEV MAIN
%token <string> IPADDR PATH
%%
commands:
|
command commands SCOLON
command SCOLON commands
;
command:
notify
|
main
;
main:
MAIN params
{
lprintf(info, "parser: end main\n");
}
;
params:
OBRACE directives CBRACE
;
directives:
|
directives directive SCOLON
;
directive:
modemdev
;
notify:
NOTIFY iplist
@ -52,4 +72,16 @@ ipadr:
lprintf(debug, "Encountered ipaddress %s\n", $1);
}
;
modemdev:
MODDEV devpath
{
lprintf(info, "parser: end modemdev\n");
}
;
devpath:
QUOTE PATH QUOTE
{
lprintf(debug, "Modem dev == %s\n", $2);
}
;
%%

View File

@ -23,10 +23,13 @@ void shutd(void)
void open_logs(void)
{
logf = fopen(difflog ? cf.logfile : LOGFILE, "a");
if(!logf) {
perror("logf open");
exit(-1);
if(strcmp(difflog ? cf.logfile : LOGFILE, "-") == 0) logf = stderr;
else {
logf = fopen(difflog ? cf.logfile : LOGFILE, "a");
if(!logf) {
perror("logf open");
exit(-1);
}
}
lprintf(info, "phoned v" VERSION " starting..\n");
}

View File

@ -28,3 +28,49 @@
* SUCH DAMAGE.
*/
/* system includes */
#include <fcntl.h>
#include <ctype.h>
#include <unistd.h>
#include <signal.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <libutil.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <errno.h>
#include <phoned.h>
#define INITSTRING "ATZ\r\nAT E0 #CID=2 V0\r\n"
/* globals */
FILE* modem;
int modemfd;
void stmod(const char* str)
{
fputs(str, modem);
fflush(modem);
}
int init_modem(char* dev)
{
int lres = 0;
modemfd = open(dev, O_RDWR);
if(!modemfd) {
lprintf(error, "Error opening modem %s: %s\n", dev, strerror(errno));
return -2;
}
lres = uu_lock((dev+(sizeof("/dev/")-1)));
if(lres != 0) {
lprintf(error, "%s\n", uu_lockerr(lres));
return -1;
}
modem = fdopen(modemfd, "w+");
if(!modem) {
lprintf(error, "Error fdopening modemfd %d: %s\n", modemfd, strerror(errno));
return -3;
}
stmod(INITSTRING);
return 1;
}

View File

@ -1,3 +1,6 @@
main {
modemdev "/dev/ttyd0";
};
notify {
10.10.10.13;
10.10.10.1;

View File

@ -45,6 +45,9 @@
#include <phoned.h>
extern int modemfd;
extern FILE* modem;
void handclient(sk)
int sk;
{