Hi Hendrik,
On Wed, Jul 27, 2011, Hendrik Sattler wrote:
> ---
> apps/obex_test/obex_test.c | 12 ++++---
> apps/obex_test/obex_test_client.c | 61 ++++++++++++++++++++++--------------
> 2 files changed, 44 insertions(+), 29 deletions(-)
Patches 1-9 have been applied, but this one has issues (though in
general these two c-files are a total mess as far as coding style and
whitespace is concerned).
> 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);
Could you just do
if (fgets(...) == NULL)
break;
to avoid the typecast (and even if there was a typecast there's always a
space before the function/variable name.
> + if (cmd[0] == 0) /* EOF */
> break;
> - switch (cmd[0] | 0x20) {
> + cmd[strlen(cmd)-1] = 0; /* remove trailing newline */
That should be cmd[strlen(cmd) - 1] = '\0'; (0 is for integers, '\0' for
characters. Also not the whitespace change.
> + fprintf(stdout, "PUSH file> ");
> + fflush(stdout);
> + (void)fgets(fname, sizeof(fname), stdin);
The same thing as above.
> + if (fname[0] == 0) /* EOF */
== '\0'
> + fname[strlen(fname)-1] = 0; /* remove trailing newline */
Same thing as earlier.
> + if (strlen(fname) == 0) {
> perror("scanf");
You're not using scanf anymore so this error log isn't correct. Also,
since you're truncating the string this strlen check doesn't guarantee
that errno will be set.
> + (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;
> }
Same issues here as I've already pointed out.
> + 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)
And here.
> + 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;
> }
And here.
> + 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;
> }
And here.
Btw, since the code patterns in all of these places are almost the same
it'd probably make sense to make a helper function for this.
Johan
------------------------------------------------------------------------------
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