diff options
author | FreeArtMan <dos21h@gmail.com> | 2014-10-31 10:15:31 +0900 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2014-10-31 10:15:31 +0900 |
commit | c84cc88f0b34d8802390e2a7b6dab7f07ba277d1 (patch) | |
tree | f8af1ec8dafd72636eaf320f658c191c47bc1f75 | |
parent | f9a751917d0dd885ba7ae6047ccf7369512ee5df (diff) | |
download | microbbs-c84cc88f0b34d8802390e2a7b6dab7f07ba277d1.tar.gz microbbs-c84cc88f0b34d8802390e2a7b6dab7f07ba277d1.zip |
added article dump, if you whant read it in whole set. hided first log message becouse to many spam from fake visitours
-rw-r--r-- | Makefile | 21 | ||||
-rw-r--r-- | articles.c | 20 | ||||
-rw-r--r-- | articles.h | 1 | ||||
-rw-r--r-- | buildinfo.h | 2 | ||||
-rw-r--r-- | libterm/Makefile | 3 | ||||
-rw-r--r-- | logs.c | 71 | ||||
-rw-r--r-- | logs.h | 4 | ||||
-rw-r--r-- | microbbs.c | 3 | ||||
-rw-r--r-- | motd.h | 2 | ||||
-rw-r--r-- | vote.c | 10 | ||||
-rw-r--r-- | vote.h | 12 |
11 files changed, 136 insertions, 13 deletions
@@ -1,12 +1,17 @@ -make: +PROJECT=microbbs +CC=gcc +CFLAGS= +SOURCES=motd.c buildinfo.c sysinfo.c articles.c logs.c vote.c +OBJECTS=$(SOURCES:.c=.o) + +all: $(OBJECTS) $(PROJECT) + +$(PROJECT): $(SOURCES) cd ./libterm; make - gcc -c motd.c - gcc -c microbbs.c - gcc -c buildinfo.c - gcc -c sysinfo.c - gcc -c articles.c - gcc -c logs.c - gcc buildinfo.o motd.o microbbs.o sysinfo.o articles.o logs.o libterm/libterm.o -o microbbs + $(CC) $(OBJECTS) $(CFLAGS) libterm/libterm.o microbbs.c -o $(PROJECT) + +%.o: %.c + $(CC) $(CFLAGS) -c $< clean: rm -rf *.o microbbs @@ -20,10 +20,13 @@ int bbs_article( term_screen *ts, const char *fname ) max_y = 24; } else { + printf("Unknown mode\n"); max_x = 80; max_y = 24; } + bbs_log_article( NULL ); + if ( fname != NULL ) { f = fopen( fname, "r" ); @@ -48,7 +51,7 @@ int bbs_article( term_screen *ts, const char *fname ) // ((fret > 0) && (i > max_x-1)) ) if ( i >= max_y-1 ) { - printf("(N)ext,(Q)uit:"); + printf("(N)ext,(D)ump,(Q)uit:"); ret_len = getline( &in_buf, &in_size, stdin ); if ( ret_len > 0 ) { @@ -63,6 +66,21 @@ int bbs_article( term_screen *ts, const char *fname ) case 'N': i = 0; break; + //dump whole file to the screen + case 'd': + case 'D': + { + char tmp_buf[81]; + size_t tmp_size; + fseek( f, 0, SEEK_SET ); + while ( (tmp_size = fread( &tmp_buf, 1, 80, f )) > 0 ) + { + tmp_buf[ tmp_size ] = 0; + printf( "%s", tmp_buf ); + } + } + i = 0; + break; default: printf("Try more\n"); } @@ -5,6 +5,7 @@ #include <stdlib.h> #include "libterm/term.h" +#include "logs.h" int bbs_article( term_screen*, const char* ); diff --git a/buildinfo.h b/buildinfo.h index 1b1041d..9dcbb25 100644 --- a/buildinfo.h +++ b/buildinfo.h @@ -4,7 +4,7 @@ #include <stdio.h> #include <stdlib.h> -#define BUILD_VERSION "0.1.7" +#define BUILD_VERSION "0.1.8" #define BUILD_DATE (__DATE__) void print_build_info(); diff --git a/libterm/Makefile b/libterm/Makefile index a592109..5cc090c 100644 --- a/libterm/Makefile +++ b/libterm/Makefile @@ -4,3 +4,6 @@ make: gcc -c screen_modes.c gcc -c print_utils.c ld -r term.o screen_modes.o print_utils.o -o libterm.o + +clean: + rm *.o @@ -2,7 +2,7 @@ int bbs_log( const char *syslname ) { - int ret; + int ret=0; char *term=NULL; setlogmask (LOG_UPTO (LOG_NOTICE)); @@ -15,6 +15,7 @@ int bbs_log( const char *syslname ) openlog ( syslname, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1 ); } + //maybe fake visitor term = getenv( "TERM" ); if ( term != NULL ) syslog (LOG_NOTICE, "BBS visitor with TERM=%s", term); @@ -26,4 +27,72 @@ int bbs_log( const char *syslname ) return ret; } +int bbs_log_article( const char *syslname ) +{ + int ret=0; + + 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 ); + } + + //probably not fake visitor + syslog( LOG_NOTICE, "BBS article" ); + + closelog (); + + + return ret; +} + + +int bbs_log_motd( const char *syslname ) +{ + int ret=0; + + 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 ); + } + + syslog( LOG_NOTICE, "BBS motd" ); + + closelog (); + + + return ret; +} + +int bbs_log_quit( const char *syslname ) +{ + int ret=0; + + 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 ); + } + + syslog( LOG_NOTICE, "BBS quit" ); + + closelog (); + + + return ret; +} + @@ -8,5 +8,7 @@ #define BBS_DEFAULT_SYSLOG "microbbs" int bbs_log( const char* ); - +int bbs_log_article( const char* ); +int bbs_log_motd( const char* ); +int bbs_log_quit( const char* ); #endif @@ -20,7 +20,7 @@ int main( int argc, char **argv ) bbs_log( NULL ); //write to default place bbs_motd( &ts, "art/motd.txt" ); print_build_info(); - while ( strncmp( str, "q", 1 ) ) + while ( strncmp( str, "q", 1 ) && strncmp( str, "Q", 1 ) ) { printf("(M)otd (Q)uit (S)ysinfo (A)rticles: "); ret_len = getline( &str, &str_size, stdin ); @@ -48,6 +48,7 @@ int main( int argc, char **argv ) break; case 'q': case 'Q': + bbs_log_quit( NULL ); break; default: printf("Unknow command\n"); @@ -8,6 +8,8 @@ #include "libterm/print_utils.h" #include "libterm/term.h" +#include "logs.h" + //get file name //calculate current termsize and then print motd in da middle int bbs_motd( term_screen*, const char* ); @@ -0,0 +1,10 @@ +#include "vote.h" + +int bbs_vote( term_screen *ts, const char *s ) +{ + int ret=-1; + + + + return ret; +}
\ No newline at end of file @@ -0,0 +1,12 @@ +#ifndef __MICROBBS_VOTE_H +#define __MICROBBS_VOTE_H + +#include <stdio.h> +#include <stdlib.h> + +#include "libterm/term.h" +#include "logs.h" + +int bbs_vote( term_screen*, const char* ); + +#endif
\ No newline at end of file |