summaryrefslogtreecommitdiff
path: root/todo.c
diff options
context:
space:
mode:
Diffstat (limited to 'todo.c')
-rw-r--r--todo.c116
1 files changed, 78 insertions, 38 deletions
diff --git a/todo.c b/todo.c
index 8e293d9..d3d1464 100644
--- a/todo.c
+++ b/todo.c
@@ -24,30 +24,8 @@ int bbs_todo( term_screen *ts, const char *fname)
todo_fname = fname;
}
- //LOAD DATA FROM FILE TO LINKED LIST
List *todo_list = llist_new();
- f_file *file = f_file_open( todo_fname, F_FILE_READ );
- if ( file != NULL )
- {
- const int l_s = 128;
- int r_v;
- {
- cycle0:;
- char *l = malloc( l_s );
- r_v = f_file_readl( file, l_s, l );
- if ( r_v < 0 ) goto exit_cycle0;
- l[r_v] = '\0';
- llist_push( todo_list, l );
- goto cycle0;
- exit_cycle0:;
- if ( l != NULL ) free( l );
- }
-
- }
- f_file_close( file );
- //LOAD DATA FROM FILE TO LINKED LIST
- //END
-
+ bbs_todo_load( todo_fname, todo_list );
//log that someone use todo
bbs_log( NULL, "visited TODO" );
@@ -183,35 +161,97 @@ int bbs_todo_remove( term_screen *ts, List *todo, const char *fname )
term_cur_set_r( ts, 0 );
term_printf( ts, "Remove entry from todo:\n");
-
-
-
return ret;
}
int bbs_todo_save( const char *fname, List *todo )
{
- int ret=-1;
-
- f_file *f=NULL;
+ FILE *f;
struct ListNode *iter=todo->first;
+ int count_max = 0;
+
+ f = fopen( fname, "w" );
+
+ if ( f == NULL )
+ {
+ return -1;
+ }
- f = f_file_open( fname, F_FILE_WRITE );
while ( iter != NULL )
{
- size_t str_size=strlen( iter->val )+2;
+
+ netbyte_store nb;
+ nb_u8arr td;
+ int er=0;
+ uint8_t *res=NULL;
+
+ size_t str_size = strlen( iter->val );
char *str = malloc( str_size );
- memcpy( str, iter->val, str_size-2);
- str[str_size-1] = '\0';
- str[str_size-2] = '\n';
- f_file_write( f, strlen(str), str );
- printf( "%s\n", str ); fflush( stdout );
+
+ memcpy( str, iter->val, str_size );
+
+ nb_init( &nb );
+ er = nb_u8arr_create( &td, str_size, (uint8_t *)str );
+ if (er)
+ printf("er create u8arr: %d\n",er);
+
+ er = nb_add_u8arr( &nb, &td );
+ if (er)
+ printf("er add u8arr: %d\n",er);
+
+ res = nb_create( &nb );
+
+
+
+ fwrite( res, 1, nb.size, f );
+
free( str );
+ free( res );
+
iter = iter->next;
+ if ( count_max > 128 )
+ break;
+ count_max += 1;
}
- f_file_close( f );
- return ret;
+ fclose( f );
+
+ return 0;
+}
+
+int bbs_todo_load( const char *fname, List *todo )
+{
+ FILE *f;
+ int i;
+ __nb_type t;
+
+ netbyte_store nb;
+
+ nb_init( &nb );
+
+ f = fopen( fname, "r" );
+ if ( f == NULL )
+ {
+ return -1;
+ }
+
+ while (nb_fread( &nb, fileno(f) ) == 0)
+ {
+ for ( i=0; i<nb_count(&nb); i++ )
+ {
+ t = nb.types[i];
+ if (t.type == NBT_U8ARRAY)
+ {
+ nb_u8arr *l = (nb_u8arr *)t.nb_val;
+ char *u = malloc( l->len );
+ memcpy( u, l->val, l->len );
+ llist_push( todo, u );
+ }
+ }
+ }
+ fclose( f );
+
+ return 0;
}
#endif \ No newline at end of file