---
apps/obex_test/obex_test.c | 12 ++++---
apps/obex_test/obex_test_client.c | 61 ++++++++++++++++++++++--------------
2 files changed, 44 insertions(+), 29 deletions(-)
diff --git a/apps/obex_test/obex_test.c b/apps/obex_test/obex_test.c
index 4200f9b..350d808 100644
--- a/apps/obex_test/obex_test.c
+++ b/apps/obex_test/obex_test.c
@@ -153,8 +153,8 @@ static int inet_connect(obex_t *handle)
//
int main (int argc, char *argv[])
{
- char cmd[10];
- int num, end = 0;
+ char cmd[3];
+ int end = 0;
int cobex = FALSE, tcpobex = FALSE, btobex = FALSE, r320 = FALSE,
usbobex = FALSE;
obex_t *handle;
#ifdef HAVE_BLUETOOTH
@@ -350,10 +350,12 @@ int main (int argc, char *argv[])
while (!end) {
printf("> ");
- num = scanf("%s", cmd);
- if (num == EOF)
+ fflush(stdout);
+ (void)fgets(cmd, sizeof(cmd), stdin);
+ if (cmd[0] == 0) /* EOF */
break;
- switch (cmd[0] | 0x20) {
+ cmd[strlen(cmd)-1] = 0; /* remove trailing newline */
+ switch(cmd[0]) {
case 'h':
printf("Commands:\n"
" c - connect\n"
diff --git a/apps/obex_test/obex_test_client.c
b/apps/obex_test/obex_test_client.c
index 8f0efc7..d9714b4 100644
--- a/apps/obex_test/obex_test_client.c
+++ b/apps/obex_test/obex_test_client.c
@@ -227,17 +227,19 @@ void push_client(obex_t *handle)
unsigned int uname_size;
char *bfname;
uint8_t *uname;
- int num;
obex_headerdata_t hd;
uint8_t *buf;
int file_size;
- printf("PUSH filename> ");
- memset(fname, 0, sizeof(fname));
- num = scanf("%199c", fname);
- if (num != 1) {
+ fprintf(stdout, "PUSH file> ");
+ fflush(stdout);
+ (void)fgets(fname, sizeof(fname), stdin);
+ if (fname[0] == 0) /* EOF */
+ return;
+ fname[strlen(fname)-1] = 0; /* remove trailing newline */
+ if (strlen(fname) == 0) {
perror("scanf");
return;
}
@@ -294,15 +296,17 @@ void put_client(obex_t *handle)
char rname[200];
unsigned int rname_size;
obex_headerdata_t hd;
- int num;
uint8_t *buf;
int file_size;
- printf("PUT file (local)> ");
- memset(lname, 0, sizeof(lname));
- num = scanf("%199c", lname);
- if (num != 1) {
+ fprintf(stdout, "PUT file (local)> ");
+ fflush(stdout);
+ (void)fgets(lname, sizeof(lname), stdin);
+ if (lname[0] == 0) /* EOF */
+ return;
+ lname[strlen(lname)-1] = 0; /* remove trailing newline */
+ if (strlen(lname) == 0) {
perror("scanf:");
return;
}
@@ -314,10 +318,13 @@ void put_client(obex_t *handle)
return;
}
- printf("PUT remote filename (default: %s)> ", lname);
- memset(rname, 0, sizeof(rname));
- num = scanf("%199c", rname);
- if (num == 0)
+ fprintf(stdout, "PUT remote filename (default: %s)> ", lname);
+ fflush(stdout);
+ (void)fgets(rname, sizeof(rname), stdin);
+ if (rname[0] == 0) /* EOF */
+ return;
+ rname[strlen(rname)-1] = 0; /* remove trailing newline */
+ if (strlen(rname) == 0)
strcpy(rname, lname);
printf("Going to send %d bytes\n", file_size);
@@ -362,13 +369,16 @@ void get_client(obex_t *handle, struct context *gt)
obex_object_t *object;
uint8_t rname[200];
char req_name[200];
- int num, rname_size;
+ int rname_size;
obex_headerdata_t hd;
- printf("GET File> ");
- memset(req_name, 0, sizeof(req_name));
- num = scanf("%199c", req_name);
- if (num != 1) {
+ fprintf(stdout, "GET file> ");
+ fflush(stdout);
+ (void)fgets(req_name, sizeof(req_name), stdin);
+ if (req_name[0] == 0) /* EOF */
+ return;
+ req_name[strlen(req_name)-1] = 0; /* remove trailing newline */
+ if (strlen(req_name) == 0) {
perror("scanf:");
return;
}
@@ -438,13 +448,16 @@ void setpath_client(obex_t *handle)
uint8_t setpath_data[2] = { 0, 0 };
obex_object_t *object;
char path[200];
- int num, path_size;
+ int path_size;
obex_headerdata_t hd;
- printf("SETPATH> ");
- memset(path, 0, sizeof(path));
- num = scanf("%199c", path);
- if (num != 1) {
+ fprintf(stdout, "SETPATH> ");
+ fflush(stdout);
+ (void)fgets(path, sizeof(path), stdin);
+ if (path[0] == 0) /* EOF */
+ return;
+ path[strlen(path)-1] = 0; /* remove trailing newline */
+ if (strlen(path) == 0) {
perror("scanf:");
return;
}
--
1.7.5.4
------------------------------------------------------------------------------
Got Input? Slashdot Needs You.
Take our quick survey online. Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Openobex-users mailing list
[email protected]
http://lists.sourceforge.net/lists/listinfo/openobex-users