summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile15
-rw-r--r--articles.c28
-rw-r--r--articles.h3
-rw-r--r--buildinfo.h2
-rw-r--r--debug.h65
-rw-r--r--list.c142
-rw-r--r--list.h69
-rw-r--r--logs.c24
-rw-r--r--logs.h1
-rw-r--r--microbbs.c2
-rw-r--r--mmm.c26
-rw-r--r--mmm.h50
-rw-r--r--mmm_config.h18
-rw-r--r--sysinfo.c5
-rw-r--r--sysinfo.h3
15 files changed, 445 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 443b8ca..0d61766 100644
--- a/Makefile
+++ b/Makefile
@@ -1,18 +1,23 @@
PROJECT=microbbs
CC=gcc
CFLAGS=
-SOURCES=motd.c buildinfo.c sysinfo.c articles.c logs.c vote.c
+SOURCES=motd.c buildinfo.c sysinfo.c articles.c logs.c vote.c list.c mmm.c
OBJECTS=$(SOURCES:.c=.o)
-
-all: $(OBJECTS) $(PROJECT)
+BUILD_DIR=build_dir
+
+all: mkdir $(OBJECTS) $(PROJECT)
+
+mkdir:
+ mkdir -p $(BUILD_DIR)
$(PROJECT): $(SOURCES)
cd ./libterm; make
- $(CC) $(OBJECTS) $(CFLAGS) libterm/libterm.o microbbs.c -o $(PROJECT)
+ $(CC) $(addprefix $(BUILD_DIR)/,$(OBJECTS)) $(CFLAGS) libterm/libterm.o microbbs.c -o $(PROJECT)
%.o: %.c
- $(CC) $(CFLAGS) -c $<
+ $(CC) $(CFLAGS) -c $< -o $(BUILD_DIR)/$@
clean:
rm -rf *.o microbbs
+ cd ./$(BUILD_DIR); rm -rf *.o
cd ./libterm; make clean
diff --git a/articles.c b/articles.c
index b3553c0..c071bf1 100644
--- a/articles.c
+++ b/articles.c
@@ -98,3 +98,31 @@ int bbs_article( term_screen *ts, const char *fname )
return ret;
}
+
+int bbs_article_list( term_screen *ts, const char *dir_name )
+{
+ int ret=-1;
+ int max_x=-1, max_y=-1;
+
+ if ( ts->mode == SCREEN_MODE_80x24 )
+ {
+ max_x = 80;
+ max_y = 24;
+ } else
+ {
+ printf("Unknown mode\n");
+ max_x = 80;
+ max_y = 24;
+ }
+
+ bbs_log_article_list( NULL );
+
+ if ( dir_name != NULL )
+ {
+ //should have some bugs be carefull
+
+ ret = 0;
+ }
+
+ return ret;
+}
diff --git a/articles.h b/articles.h
index 25977b9..0282386 100644
--- a/articles.h
+++ b/articles.h
@@ -7,6 +7,9 @@
#include "libterm/term.h"
#include "logs.h"
+#define WORKING_DIR "article"
+
int bbs_article( term_screen*, const char* );
+int bbs_article_list( term_screen*, const char* );
#endif
diff --git a/buildinfo.h b/buildinfo.h
index 9dcbb25..3b5964d 100644
--- a/buildinfo.h
+++ b/buildinfo.h
@@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
-#define BUILD_VERSION "0.1.8"
+#define BUILD_VERSION "0.1.9"
#define BUILD_DATE (__DATE__)
void print_build_info();
diff --git a/debug.h b/debug.h
new file mode 100644
index 0000000..78e42f4
--- /dev/null
+++ b/debug.h
@@ -0,0 +1,65 @@
+#ifndef __RB_DEBUG_UTILS_H
+#define __RB_DEBUG_UTILS_H
+
+//what about kprintf?
+
+//config options
+#define PRINTF printf
+#define COLORIZE
+#define PRINT_LINENUM
+#define PRINT_FILENAME
+#define PRINT_DEBUG
+
+
+//use color
+#ifdef COLORIZE
+ #define D_COLOR "1;32m"
+ #define D_COLOR_S "\033[" D_COLOR
+ #define D_COLOR_E "\033[0m"
+ #define E_COLOR "1;31m"
+ #define E_COLOR_S "\033[" E_COLOR
+ #define E_COLOR_E "\033[0m"
+#else
+ #define D_COLOR
+ #define D_COLOR_S
+ #define D_COLOR_E
+ #define E_COLOR
+ #define E_COLOR_S
+ #define E_COLOR_E
+#endif
+
+//print debug line
+#ifdef PRINT_LINENUM
+ #define PRINT_LINE_F "LINE:%d "
+ #define PRINT_LINE_D __LINE__
+#else
+ #define PRINT_LINE_F ""
+ #define PRINT_LINE_D ""
+#endif
+
+//print
+#ifdef PRINT_FILENAME
+ #define PRINT_FILE_F "FILE:%s "
+ #define PRINT_FILE_D __FILE__
+#else
+ #define PRINT_FILE_F ""
+ #define PRINT_FILE_D ""
+#endif
+
+//print debug string
+#ifdef PRINT_DEBUG
+ #define PRINT_DEBUG_F "Debug: "
+#else
+ #define PRINT_DEBUG_F ""
+#endif
+
+#define PRINT( format, args ... ) PRINTF( D_COLOR_S PRINT_DEBUG_F \
+ PRINT_FILE_F PRINT_LINE_F format D_COLOR_E, PRINT_FILE_D, \
+ PRINT_LINE_D, ##args);
+
+#define ERROR( format, args ... ) PRINTF( E_COLOR_S PRINT_DEBUG_F \
+ PRINT_FILE_F PRINT_LINE_F format E_COLOR_E, PRINT_FILE_D, \
+ PRINT_LINE_D, ##args);
+
+
+#endif
diff --git a/list.c b/list.c
new file mode 100644
index 0000000..83655cd
--- /dev/null
+++ b/list.c
@@ -0,0 +1,142 @@
+#include "list.h"
+
+struct List* llist_new()
+{
+ struct List *list=MALLOC( sizeof(struct List) );
+ list->first = NULL;
+ list->last = NULL;
+ list->count = 0;
+ return list;
+}
+
+
+struct ListNode* llist_newn( void *ptr )
+{
+ struct ListNode *node = MALLOC( sizeof( struct ListNode ) );
+ node->next = NULL;
+ node->val = ptr;
+ return node;
+}
+
+
+int llist_length( struct List *list )
+{
+ int len;
+ struct ListNode *node=list->first;
+ for ( len=0; node; node=node->next,len++);
+ return len;
+}
+
+
+int llist_index( struct List *list, void *ptr )
+{
+ int index;
+ struct ListNode *node = list->first;
+ for ( index=0; node; node=node->next, index++)
+ if ( node->val == ptr )
+ return index;
+ return -1;
+}
+
+
+void llist_reverse( struct List **list )
+{
+ //abort(0);
+}
+
+
+void llist_append( struct List *list, void *ptr )
+{
+ //abort(0);
+}
+
+
+void llist_appendn( struct List **list, void *ptr, struct ListNode *node )
+{
+ //abort(0);
+}
+
+
+void* llist_pop( struct List *list )
+{
+ struct ListNode *node = list->last;
+ struct ListNode *iter = list->first;
+ if ( node )
+ {
+ /*
+ if ( node->prev != NULL )
+ {
+ void *ptr = node->val;
+ //node = node->prev;
+ //FREE( node->next );
+ //node->next = NULL;
+ //list->last = node;
+ return ptr;
+ }
+ */
+
+ while (iter->next != node)
+ {
+ iter = iter->next;
+ }
+ void *ptr = node->val;
+ FREE(iter->next);
+ iter->next = NULL;
+ list->last = iter;
+ return ptr;
+
+ }
+ return NULL;
+}
+
+
+void llist_push( struct List *list, void *ptr )
+{
+ struct ListNode *node = MALLOC( sizeof(struct ListNode) );
+ node->val = ptr;
+ node->next = NULL;
+ if ( list->last )
+ {
+ list->last->next = node;
+ list->last = node;
+ }
+ else
+ {
+ list->first = node;
+ list->last = node;
+ }
+}
+
+
+
+void llist_free( struct List *list )
+{
+ struct ListNode *node = list->first, *prev;
+
+ while ( node != list->last )
+ {
+ prev = node;
+ node = node->next;
+ if (prev != NULL)
+ {
+ FREE( prev->val );
+ FREE( prev );
+ }
+ }
+ if ( node )
+ {
+ if ( node->val )
+ FREE( node->val );
+ FREE( node );
+ }
+ list->first = NULL;
+ list->last = NULL;
+ FREE( list );
+ list = NULL;
+}
+
+void llist_freen( struct ListNode *node )
+{
+}
+
+
diff --git a/list.h b/list.h
new file mode 100644
index 0000000..c443430
--- /dev/null
+++ b/list.h
@@ -0,0 +1,69 @@
+#ifndef __LIBADT_SLIST_H
+#define __LIBADT_SLIST_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#include "debug.h"
+#include "mmm.h"
+
+//use stack memallocation features. need to make some changes in api
+
+
+typedef struct ListNode
+{
+ struct ListNode *next;
+ void *val;
+} ListNode;
+
+typedef struct List
+{
+ int count;
+ ListNode *first;
+ ListNode *last;
+} List;
+
+struct List* llist_new();
+struct ListNode* llist_newn( void* );
+//#define __LLIST_NEW()
+//#define __LLIST_NEWN()
+
+int llist_length( struct List* );
+int llist_index( struct List*, void* );
+//llist_find( struct List );
+//find by pointer
+//find by value
+void llist_reverse( struct List** );
+
+void llist_append( struct List*, void* );
+void llist_appendn( struct List**, void*, struct ListNode* );
+//#define __LIST_APPEND()
+
+void* llist_pop( struct List* );
+void llist_push( struct List*, void* );
+
+void llist_free( struct List* );
+void llist_freen( struct ListNode* );
+
+//void llist_merge( struct List**, struct List* );
+//void llist_compare( struct List
+//void llist_split( struct List*,
+//void llist_splitn( struct List*, struct ListNode*
+//void llist_splitp( struct List*, void*
+//void llist_splitc( struct List*, void (*)(void*)
+//void llist_sort(
+//sort by pointer
+//sort by value
+
+#define llist_first(A) ((A)->first)
+#define llist_last(A) ((A)->last)
+
+//#define LLIST_FOREACH()
+//#define LLIST_FOREACH_PREV()
+
+//#define llist_islastn(A) ()
+//#define llist_isfirstn(A) ()
+//#define llist_getfirstn(A) ((A))
+//#define llist_getlastn(A) ()
+#endif
diff --git a/logs.c b/logs.c
index 697693c..0feebf7 100644
--- a/logs.c
+++ b/logs.c
@@ -51,6 +51,30 @@ int bbs_log_article( const char *syslname )
}
+int bbs_log_article_list( 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 list" );
+
+ closelog ();
+
+
+ return ret;
+}
+
+
int bbs_log_motd( const char *syslname )
{
int ret=0;
diff --git a/logs.h b/logs.h
index 9247ba6..ed1595e 100644
--- a/logs.h
+++ b/logs.h
@@ -9,6 +9,7 @@
int bbs_log( const char* );
int bbs_log_article( const char* );
+int bbs_log_article_list( const char* );
int bbs_log_motd( const char* );
int bbs_log_quit( const char* );
#endif
diff --git a/microbbs.c b/microbbs.c
index 3624671..77ac92b 100644
--- a/microbbs.c
+++ b/microbbs.c
@@ -17,7 +17,7 @@ int main( int argc, char **argv )
//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_log( NULL ); //write to default place
bbs_motd( &ts, "art/motd.txt" );
print_build_info();
while ( strncmp( str, "q", 1 ) && strncmp( str, "Q", 1 ) )
diff --git a/mmm.c b/mmm.c
new file mode 100644
index 0000000..4dc9a04
--- /dev/null
+++ b/mmm.c
@@ -0,0 +1,26 @@
+#include "mmm.h"
+
+#ifdef MMM_PLAIN
+#endif
+
+#ifdef MMM_RECORD
+
+
+void* mmm_malloc(size_t size, const char *fname, int line )
+{
+ void *ret=NULL;
+ ret = malloc( size );
+ printf("alloc,0x%8p,%zu,%s,%d\n",(void *)ret,size,fname,line);
+ return ret;
+}
+
+
+void mmm_free( void *ptr, const char *fname, int line )
+{
+ printf("free,0x%8p,%s,%d\n",(void *)ptr,fname,line);
+ free( ptr );
+}
+
+#endif
+
+
diff --git a/mmm.h b/mmm.h
new file mode 100644
index 0000000..4b1c368
--- /dev/null
+++ b/mmm.h
@@ -0,0 +1,50 @@
+#ifndef __LIBMM_MMM_H
+#define __LIBMM_MMM_H
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <dlfcn.h>
+
+#include "mmm_config.h"
+
+//----------------------------------------------------------------------
+#ifdef MMM_PLAIN
+
+#define MALLOC(SIZE) malloc(SIZE);
+#define FREE(PTR) free(PTR);
+#define CALLOC(NMEMB,SIZE) calloc(NMEMB, SIZE);
+#define REALLOC(PTR,SIZE) realloc(PTR,SIZE);
+
+#endif
+
+//----------------------------------------------------------------------
+#ifdef MMM_PLAIN_SAFE
+
+#define MALLOC(SIZE) malloc(SIZE);
+#define FREE(PTR) if (PTR!=NULL){free(PTR);PTR=NULL;};
+#define CALLOC(NMEMB,SIZE) calloc(NMEMB, SIZE);
+#define REALLOC(PTR,SIZE) realloc(PTR,SIZE);
+
+#endif
+
+//----------------------------------------------------------------------
+#ifdef MMM_RECORD
+
+#define MALLOC(SIZE) mmm_malloc(SIZE,__FILE__,__LINE__);
+#define FREE(PTR) mmm_free((PTR),__FILE__,__LINE__);
+#define CALLOC(NMEMB,SIZE) calloc(NMEMB,SIZE);
+#define REALLOC(PTR,SIZE) realloc(PTR,SIZE);
+
+void* mmm_malloc(size_t, const char *, int );
+void mmm_free( void *, const char *, int );
+
+#endif
+
+
+
+
+#endif
diff --git a/mmm_config.h b/mmm_config.h
new file mode 100644
index 0000000..cca4f6a
--- /dev/null
+++ b/mmm_config.h
@@ -0,0 +1,18 @@
+#ifndef __LIBMMM_CONFIG_H
+#define __LIBMMM_CONFIG_H
+
+//---------------------------------------------------------------------
+//ONLY ONE OF OPTION CAN BE USED
+
+//noting is done with memory. only plain wrappers is usded.
+#define MMM_PLAIN
+
+//cleans free after free if free is not NULL
+//#define MMM_PLAIN_SAFE
+
+//show in terminal some data about used malocc and free
+//#define MMM_RECORD
+//---------------------------------------------------------------------
+
+
+#endif
diff --git a/sysinfo.c b/sysinfo.c
index 7b12e2f..5d1eacb 100644
--- a/sysinfo.c
+++ b/sysinfo.c
@@ -4,7 +4,10 @@ int bbs_sysinfo( term_screen *ts )
{
int ret=0;
- printf("BBS:MicroBBS\n");
+ printf("BBS:MicroBBS %s (%s)\n", BUILD_VERSION, BUILD_DATE);
+ printf("Author: FreeArtMan\n");
+ printf("Contributor: epoch\n");
+ printf("Ideological support: irc://hacking.allowed.org#default\n");
return ret;
}
diff --git a/sysinfo.h b/sysinfo.h
index adbdec4..30d9f64 100644
--- a/sysinfo.h
+++ b/sysinfo.h
@@ -1,8 +1,11 @@
#ifndef __MICROBBS_SYSINFO_H
#define __MICROBBS_SYSINFO_H
+#include "buildinfo.h"
+
#include "libterm/term.h"
+
int bbs_sysinfo( term_screen* );
#endif