From f9a751917d0dd885ba7ae6047ccf7369512ee5df Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Sun, 31 Aug 2014 08:49:53 +0900 Subject: Case insensitive, syslog support --- .gitignore | 2 ++ Makefile | 3 ++- articles.c | 2 ++ buildinfo.h | 2 +- logs.c | 29 +++++++++++++++++++++++++++++ logs.h | 12 ++++++++++++ microbbs.c | 7 +++++++ 7 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 logs.c create mode 100644 logs.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3789978 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +microbbs diff --git a/Makefile b/Makefile index e8cd73f..ac8cc80 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ make: gcc -c buildinfo.c gcc -c sysinfo.c gcc -c articles.c - gcc buildinfo.o motd.o microbbs.o sysinfo.o articles.o libterm/libterm.o -o microbbs + gcc -c logs.c + gcc buildinfo.o motd.o microbbs.o sysinfo.o articles.o logs.o libterm/libterm.o -o microbbs clean: rm -rf *.o microbbs diff --git a/articles.c b/articles.c index b5c5ea3..db1d16f 100644 --- a/articles.c +++ b/articles.c @@ -56,9 +56,11 @@ int bbs_article( term_screen *ts, const char *fname ) switch( ch ) { case 'q': + case 'Q': quit_loop = 1; break; case 'n': + case 'N': i = 0; break; default: diff --git a/buildinfo.h b/buildinfo.h index d831b5e..1b1041d 100644 --- a/buildinfo.h +++ b/buildinfo.h @@ -4,7 +4,7 @@ #include #include -#define BUILD_VERSION "0.1.4" +#define BUILD_VERSION "0.1.7" #define BUILD_DATE (__DATE__) void print_build_info(); diff --git a/logs.c b/logs.c new file mode 100644 index 0000000..7ec8efe --- /dev/null +++ b/logs.c @@ -0,0 +1,29 @@ +#include "logs.h" + +int bbs_log( const char *syslname ) +{ + int ret; + char *term=NULL; + + setlogmask (LOG_UPTO (LOG_NOTICE)); + + if ( syslname == NULL ) + { + openlog ( BBS_DEFAULT_SYSLOG, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); + } else + { + openlog ( syslname, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1 ); + } + + term = getenv( "TERM" ); + if ( term != NULL ) + syslog (LOG_NOTICE, "BBS visitor with TERM=%s", term); + else + syslog( LOG_NOTICE, "BBS visitor" ); + + closelog (); + + return ret; +} + + diff --git a/logs.h b/logs.h new file mode 100644 index 0000000..f86c0a3 --- /dev/null +++ b/logs.h @@ -0,0 +1,12 @@ +#ifndef __MICROBBS_LOGS_H +#define __MICROBBS_LOGS_H + +#include +#include +#include + +#define BBS_DEFAULT_SYSLOG "microbbs" + +int bbs_log( const char* ); + +#endif diff --git a/microbbs.c b/microbbs.c index af22958..c0d94a3 100644 --- a/microbbs.c +++ b/microbbs.c @@ -1,6 +1,7 @@ #include #include +#include "logs.h" #include "motd.h" #include "libterm/term.h" @@ -15,6 +16,8 @@ int main( int argc, char **argv ) term_init_data( &ts ); //printf("%d %d\n", ts.term_col, ts.term_row); + //write to log that some user have accesed bbs + bbs_log( NULL ); //write to default place bbs_motd( &ts, "art/motd.txt" ); print_build_info(); while ( strncmp( str, "q", 1 ) ) @@ -26,21 +29,25 @@ int main( int argc, char **argv ) switch ( str[0] ) { case 'm': + case 'M': { bbs_motd( &ts, "art/motd.txt" ); } break; case 's': + case 'S': { bbs_sysinfo( &ts ); } break; case 'a': + case 'A': { bbs_article( &ts, "article/post1.txt" ); } break; case 'q': + case 'Q': break; default: printf("Unknow command\n"); -- cgit v1.2.3