summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cmd_blk.c2
-rw-r--r--cmd/cmd_cd.c2
-rw-r--r--cmd/cmd_close.c10
-rw-r--r--cmd/cmd_dump.c10
-rw-r--r--cmd/cmd_dumps.c10
-rw-r--r--cmd/cmd_dumpx.c21
-rw-r--r--cmd/cmd_flags.c2
-rw-r--r--cmd/cmd_info.c2
-rw-r--r--cmd/cmd_ls.c2
-rw-r--r--cmd/cmd_open.c2
-rw-r--r--cmd/cmd_pos.c2
-rw-r--r--cmd/cmd_pwd.c2
-rw-r--r--cmd/cmd_read.c17
-rw-r--r--cmd/cmd_resize.c2
-rw-r--r--cmd/cmd_seek.c2
-rw-r--r--cmd/cmd_size.c2
-rw-r--r--cmd/cmd_write.c24
-rw-r--r--cmd/cmd_writes.c18
18 files changed, 80 insertions, 52 deletions
diff --git a/cmd/cmd_blk.c b/cmd/cmd_blk.c
index 07f27f8..a568f98 100644
--- a/cmd/cmd_blk.c
+++ b/cmd/cmd_blk.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
/*
diff --git a/cmd/cmd_cd.c b/cmd/cmd_cd.c
index 92c22b2..a24768c 100644
--- a/cmd/cmd_cd.c
+++ b/cmd/cmd_cd.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_cd( cmd_arg_t *arg )
diff --git a/cmd/cmd_close.c b/cmd/cmd_close.c
index d5a03b3..3db6a70 100644
--- a/cmd/cmd_close.c
+++ b/cmd/cmd_close.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
/*
@@ -23,10 +23,12 @@ int c_close( cmd_arg_t *arg )
}
// clean buf
- if ( g_buf->buf != NULL )
+ if ( !g_buf->isempty() )
{
- buf_zero( g_buf );
- buf_free( g_buf );
+ //buf_zero( g_buf );
+ g_buf->zero();
+ //buf_free( g_buf );
+ g_buf->empty();
}
return 0;
diff --git a/cmd/cmd_dump.c b/cmd/cmd_dump.c
index bf2e5d1..999822e 100644
--- a/cmd/cmd_dump.c
+++ b/cmd/cmd_dump.c
@@ -5,22 +5,24 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_dump( cmd_arg_t *arg )
{
int i;
- if ( g_buf->buf == NULL)
+ if ( g_buf->isempty())
{
printf("Buffer to print empty\n");
return -1;
}
- for (i=0; i<g_buf->size; i++)
+ for (i=0; i<g_buf->size(); i++)
{
- printf("%02x",(unsigned char)g_buf->buf[i]);
+ char c;
+ g_buf->getc(i,&c);
+ printf("%02x",(unsigned char)c);
}
printf("\n");
diff --git a/cmd/cmd_dumps.c b/cmd/cmd_dumps.c
index ecc5143..61d4c84 100644
--- a/cmd/cmd_dumps.c
+++ b/cmd/cmd_dumps.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_dumps( cmd_arg_t *arg )
@@ -20,11 +20,13 @@ int c_dumps( cmd_arg_t *arg )
return -1;
}
- for (i=0; i<g_buf->size; i++)
+ for (i=0; i<g_buf->size(); i++)
{
- if (isprint(g_buf->buf[i]))
+ char c;
+ g_buf->getc(i,&c);
+ if (isprint(c))
{
- printf("%c", g_buf->buf[i]);
+ printf("%c", c);
} else
{
printf("\e[7m.\e[0m");
diff --git a/cmd/cmd_dumpx.c b/cmd/cmd_dumpx.c
index 3e6cdf1..ecca20c 100644
--- a/cmd/cmd_dumpx.c
+++ b/cmd/cmd_dumpx.c
@@ -8,26 +8,28 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_dumpx( cmd_arg_t *arg )
{
int i,j;
- if ( g_buf->buf == NULL)
+ if ( g_buf->isempty() )
{
printf("Buffer to print empty\n");
return -1;
}
- for (i=0; i<g_buf->size; i+=16)
+ for (i=0; i<g_buf->size(); i+=16)
{
for (j=i; j<i+16; j++)
{
- if ( j<g_buf->size )
+ if ( j<g_buf->size() )
{
- printf("%02x ",(unsigned char)g_buf->buf[j]);
+ char c;
+ g_buf->getc(j,&c);
+ printf("%02x ",(unsigned char)c);
} else
{
printf(" ");
@@ -36,11 +38,14 @@ int c_dumpx( cmd_arg_t *arg )
for (j=i; j<i+16; j++)
{
- if ( j<g_buf->size ) //wrong place move to cycle?
+ if ( j<g_buf->size() ) //wrong place move to cycle?
{
- if ( isprint(g_buf->buf[j]) )
+ char c;
+ g_buf->getc(j,&c);
+ if ( isprint(c) )
{
- printf("%c",(unsigned char)g_buf->buf[j]);
+
+ printf("%c",(unsigned char)c);
} else
{
printf("\e[7m.\e[0m");
diff --git a/cmd/cmd_flags.c b/cmd/cmd_flags.c
index 03f6b81..5e96651 100644
--- a/cmd/cmd_flags.c
+++ b/cmd/cmd_flags.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_flags( cmd_arg_t *arg )
diff --git a/cmd/cmd_info.c b/cmd/cmd_info.c
index 74324f6..01f58f6 100644
--- a/cmd/cmd_info.c
+++ b/cmd/cmd_info.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
/*
diff --git a/cmd/cmd_ls.c b/cmd/cmd_ls.c
index 7e92db6..bb7781c 100644
--- a/cmd/cmd_ls.c
+++ b/cmd/cmd_ls.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_ls( cmd_arg_t *arg )
diff --git a/cmd/cmd_open.c b/cmd/cmd_open.c
index a4740c6..b7ea4f7 100644
--- a/cmd/cmd_open.c
+++ b/cmd/cmd_open.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
/*
diff --git a/cmd/cmd_pos.c b/cmd/cmd_pos.c
index 05264d4..b040511 100644
--- a/cmd/cmd_pos.c
+++ b/cmd/cmd_pos.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_pos( cmd_arg_t *arg )
diff --git a/cmd/cmd_pwd.c b/cmd/cmd_pwd.c
index 4e21721..d35478d 100644
--- a/cmd/cmd_pwd.c
+++ b/cmd/cmd_pwd.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_pwd( cmd_arg_t *arg )
diff --git a/cmd/cmd_read.c b/cmd/cmd_read.c
index 68dab14..da1988c 100644
--- a/cmd/cmd_read.c
+++ b/cmd/cmd_read.c
@@ -5,23 +5,28 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_read( cmd_arg_t *arg )
{
int ret;
- if ( g_buf->buf == NULL )
+ //if ( g_buf->buf == NULL )
+ if (g_buf->isempty())
{
- buf_resize( g_buf, g_file->blk_size );
+ //buf_resize( g_buf, g_file->blk_size );
+ g_buf->realloc(g_file->blk_size);
}
- ret = file_read_blk( g_file, g_buf->buf );
+ char *buf_ptr;
+ int sz;
+ g_buf->get_ptr(&buf_ptr,&sz);
+ ret = file_read_blk( g_file, (uint8_t *)buf_ptr, sz );
printf("Readed %d bytes\n", ret);
- if ( (ret >= 0) && (ret <= g_buf->buf_size) )
+ if ( (ret >= 0) && (ret <= g_buf->size()) )
{
- g_buf->size = ret;
+ g_buf->set_size(ret);
}
return 0;
diff --git a/cmd/cmd_resize.c b/cmd/cmd_resize.c
index 1e723cf..2b7fbd5 100644
--- a/cmd/cmd_resize.c
+++ b/cmd/cmd_resize.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_resize( cmd_arg_t *arg )
diff --git a/cmd/cmd_seek.c b/cmd/cmd_seek.c
index 7516811..d8bb768 100644
--- a/cmd/cmd_seek.c
+++ b/cmd/cmd_seek.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_seek( cmd_arg_t *arg )
diff --git a/cmd/cmd_size.c b/cmd/cmd_size.c
index 12723ef..3823923 100644
--- a/cmd/cmd_size.c
+++ b/cmd/cmd_size.c
@@ -5,7 +5,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
int c_size( cmd_arg_t *arg )
diff --git a/cmd/cmd_write.c b/cmd/cmd_write.c
index d54c0b5..978e244 100644
--- a/cmd/cmd_write.c
+++ b/cmd/cmd_write.c
@@ -5,13 +5,10 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
-//support masks
-int c_write( cmd_arg_t *arg)
-{
- /*
+/*
anonymous function
*/
uint8_t hex2u8( uint8_t *buf )
@@ -30,6 +27,11 @@ int c_write( cmd_arg_t *arg)
return ret;
}
+//support masks
+int c_write( cmd_arg_t *arg)
+{
+
+
int argc = arg->argc;
char **argv = arg->argv;
int i;
@@ -57,7 +59,7 @@ int c_write( cmd_arg_t *arg)
}
}
- if (strlen(argv[0]) > g_buf->size*2)
+ if (strlen(argv[0]) > g_buf->size()*2)
{
printf("Input param bigger then buffer\n");
return -1;
@@ -70,14 +72,18 @@ int c_write( cmd_arg_t *arg)
printf("\n");
- buf = malloc(strlen(argv[0])/2);
+ buf = (uint8_t *)malloc(strlen(argv[0])/2);
for (i=0; i<(strlen(argv[0])/2); i++)
{
buf[i] = hex2u8((unsigned char*)&argv[0][i*2]);
}
- memcpy( g_buf->buf, buf, strlen(argv[0])/2 );
- fret = file_write_blk( g_file, g_buf->buf );
+ char *buf_ptr;
+ int sz;
+ //memcpy( buf_ptr, buf, strlen(argv[0])/2 );
+ g_buf->set((char *)buf,strlen(argv[0])/2);
+ g_buf->get_ptr(&buf_ptr,&sz);
+ fret = file_write_blk( g_file, (uint8_t *)buf_ptr, sz );
free( buf );
if ( fret < 0)
diff --git a/cmd/cmd_writes.c b/cmd/cmd_writes.c
index 7d7eeed..0b555be 100644
--- a/cmd/cmd_writes.c
+++ b/cmd/cmd_writes.c
@@ -7,7 +7,7 @@
#include "libcmd/cmd_parse.h"
extern file_t *g_file;
-extern buf_t *g_buf;
+extern Buf *g_buf;
extern int g_flags;
//white spaces should be supported
@@ -23,16 +23,22 @@ int c_writes( cmd_arg_t *arg )
return -1;
}
- if (((g_buf == NULL) || (g_file == NULL)) || (g_buf->buf == NULL))
+ if (((g_buf == NULL) || (g_file == NULL)))
{
printf("Buffer or file not initialised");
return -1;
}
- if ( strlen(argv[0]) <= g_buf->size )
+ if ( strlen(argv[0]) <= g_buf->size() )
{
- memcpy( g_buf->buf, argv[0], strlen(argv[0]) );
- fret = file_write_blk( g_file, g_buf->buf );
+ //memcpy( g_buf->buf, argv[0], strlen(argv[0]) );
+ //check if can save all string in dat buffer
+ g_buf->set(argv[0],strlen(argv[0]));
+
+ char *buf_ptr;
+ int sz;
+ g_buf->get_ptr(&buf_ptr,&sz);
+ fret = file_write_blk( g_file, (uint8_t *)buf_ptr, sz );
if ( fret < 0 )
{
printf("Couldnt write block to file\n");
@@ -40,7 +46,7 @@ int c_writes( cmd_arg_t *arg )
}
} else
{
- printf("Input bigger then buffer buf %d input %zu\n", g_buf->size, strlen(argv[0]));
+ printf("Input bigger then buffer buf %d input %zu\n", g_buf->size(), strlen(argv[0]));
return -1;
}