* [Bluez-devel] hcitool and argv syntax
@ 2007-12-28 19:23 Perki Pat
2007-12-28 22:39 ` Marcel Holtmann
0 siblings, 1 reply; 5+ messages in thread
From: Perki Pat @ 2007-12-28 19:23 UTC (permalink / raw)
To: bluez-devel
Hi! If I want to scan on hci0 the next sintax is bad, but hcitool
doesn't complain:
pablo@golgi:~$ hcitool hci0 scan
pablo@golgi:~$
(I better should use hcitool -i hci0 scan)
I've written a little patch to warn when an unrecognised command is given:
pablo@golgi:~/work/hcitool-patch1/utils/tools$ diff -u hcitool.c.orig
hcitool.c
--- hcitool.c.orig 2007-12-28 20:06:58.000000000 +0100
+++ hcitool.c 2007-12-28 20:04:11.000000000 +0100
@@ -2291,6 +2291,7 @@
{
int opt, i, dev_id =3D -1;
bdaddr_t ba;
+ int unk_cmd=3D1;
while ((opt=3Dgetopt_long(argc, argv, "+i:h", main_options, NULL)) !=3D -=
1) {
switch (opt) {
@@ -2326,8 +2327,15 @@
for (i =3D 0; command[i].cmd; i++) {
if (strncmp(command[i].cmd, argv[0], 3))
continue;
+ unk_cmd=3D0;
command[i].func(dev_id, argc, argv);
break;
}
- return 0;
+
+ if(unk_cmd) {
+ fprintf(stderr,"\"%s\" isn't a valid command. Try --help for a list
of commands.\n",argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ exit(EXIT_SUCCESS);
}
Now, when I ask for an inexistent command it complains:
pablo@golgi:~$ ./hcitool nop scan
"nop" isn't a valid command. Try --help for a list of commands.
pablo@golgi:~$
If you find it useful, feel free to commit it.
Bye.
=
______________________________________________ =
LLama Gratis a cualquier PC del Mundo. =
Llamadas a fijos y m=F3viles desde 1 c=E9ntimo por minuto. =
http://es.voice.yahoo.com
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [Bluez-devel] hcitool and argv syntax
2007-12-28 19:23 [Bluez-devel] hcitool and argv syntax Perki Pat
@ 2007-12-28 22:39 ` Marcel Holtmann
2007-12-28 23:30 ` Perki Pat
0 siblings, 1 reply; 5+ messages in thread
From: Marcel Holtmann @ 2007-12-28 22:39 UTC (permalink / raw)
To: BlueZ development
Hi Perki,
> If I want to scan on hci0 the next sintax is bad, but hcitool
> doesn't complain:
> pablo@golgi:~$ hcitool hci0 scan
> pablo@golgi:~$
> (I better should use hcitool -i hci0 scan)
>
> I've written a little patch to warn when an unrecognised command is given:
>
> pablo@golgi:~/work/hcitool-patch1/utils/tools$ diff -u hcitool.c.orig
> hcitool.c
> --- hcitool.c.orig 2007-12-28 20:06:58.000000000 +0100
> +++ hcitool.c 2007-12-28 20:04:11.000000000 +0100
> @@ -2291,6 +2291,7 @@
> {
> int opt, i, dev_id = -1;
> bdaddr_t ba;
> + int unk_cmd=1;
>
> while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
> switch (opt) {
> @@ -2326,8 +2327,15 @@
> for (i = 0; command[i].cmd; i++) {
> if (strncmp(command[i].cmd, argv[0], 3))
> continue;
> + unk_cmd=0;
> command[i].func(dev_id, argc, argv);
> break;
> }
> - return 0;
> +
> + if(unk_cmd) {
> + fprintf(stderr,"\"%s\" isn't a valid command. Try --help for a list
> of commands.\n",argv[0]);
> + exit(EXIT_FAILURE);
> + }
> +
> + exit(EXIT_SUCCESS);
> }
>
>
> Now, when I ask for an inexistent command it complains:
> pablo@golgi:~$ ./hcitool nop scan
> "nop" isn't a valid command. Try --help for a list of commands.
> pablo@golgi:~$
>
> If you find it useful, feel free to commit it.
your patch is way too complicated. You can simply check for
command[i].cmd == NULL to print the error.
And of course you have to follow the coding style. I am not joking with
this one. It is the main reason for me to reject patches.
Regards
Marcel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [Bluez-devel] hcitool and argv syntax
2007-12-28 22:39 ` Marcel Holtmann
@ 2007-12-28 23:30 ` Perki Pat
2007-12-29 5:00 ` Marcel Holtmann
0 siblings, 1 reply; 5+ messages in thread
From: Perki Pat @ 2007-12-28 23:30 UTC (permalink / raw)
To: BlueZ development
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 904 bytes --]
> your patch is way too complicated. You can simply check for
> command[i].cmd == NULL to print the error.
You're completely right. I don't know what I was thinking on.
>
> And of course you have to follow the coding style. I am not joking with
> this one. It is the main reason for me to reject patches.
I've replaced 3-space-tabs with real tabs.
--- hcitool.c.orig 2007-12-28 20:06:58.000000000 +0100
+++ hcitool.c 2007-12-29 00:09:03.000000000 +0100
@@ -2329,5 +2329,11 @@
command[i].func(dev_id, argc, argv);
break;
}
- return 0;
+
+ if(!command[i].cmd) {
+ fprintf(stderr, "\"%s\" isn't a valid command. Try --help for a list
of commands.\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ exit(EXIT_SUCCESS);
}
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
[-- Attachment #2: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #3: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [Bluez-devel] hcitool and argv syntax
2007-12-28 23:30 ` Perki Pat
@ 2007-12-29 5:00 ` Marcel Holtmann
2007-12-29 10:38 ` Perki Pat
0 siblings, 1 reply; 5+ messages in thread
From: Marcel Holtmann @ 2007-12-29 5:00 UTC (permalink / raw)
To: BlueZ development
Hi Perki,
> > your patch is way too complicated. You can simply check for
> > command[i].cmd == NULL to print the error.
> You're completely right. I don't know what I was thinking on.
> >
> > And of course you have to follow the coding style. I am not joking with
> > this one. It is the main reason for me to reject patches.
> I've replaced 3-space-tabs with real tabs.
>
> --- hcitool.c.orig 2007-12-28 20:06:58.000000000 +0100
> +++ hcitool.c 2007-12-29 00:09:03.000000000 +0100
> @@ -2329,5 +2329,11 @@
> command[i].func(dev_id, argc, argv);
> break;
> }
> - return 0;
> +
> + if(!command[i].cmd) {
put a space between "if" and "("
> + fprintf(stderr, "\"%s\" isn't a valid command. Try --help for a list
> of commands.\n", argv[0]);
A line should not exceed 78 characters. So either shorten it or break it
up.
> + exit(EXIT_FAILURE);
> + }
> +
> + exit(EXIT_SUCCESS);
You have to use "return 0". Otherwise you get a compiler warning.
Regards
Marcel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [Bluez-devel] hcitool and argv syntax
2007-12-29 5:00 ` Marcel Holtmann
@ 2007-12-29 10:38 ` Perki Pat
0 siblings, 0 replies; 5+ messages in thread
From: Perki Pat @ 2007-12-29 10:38 UTC (permalink / raw)
To: BlueZ development
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 653 bytes --]
>
> You have to use "return 0". Otherwise you get a compiler warning.
I got no warning with GCC 4.1.3. Anyways, here is the new patch:
--- hcitool.c.orig 2007-12-28 20:06:58.000000000 +0100
+++ hcitool.c 2007-12-29 11:35:00.000000000 +0100
@@ -2329,5 +2329,11 @@
command[i].func(dev_id, argc, argv);
break;
}
+
+ if(!command[i].cmd) {
+ fprintf(stderr, "\"%s\" isn't a valid command. Try --help for a list
of commands.\n", argv[0]);
+ exit(1);
+ }
+
return 0;
}
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com
[-- Attachment #2: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #3: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-12-29 10:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-28 19:23 [Bluez-devel] hcitool and argv syntax Perki Pat
2007-12-28 22:39 ` Marcel Holtmann
2007-12-28 23:30 ` Perki Pat
2007-12-29 5:00 ` Marcel Holtmann
2007-12-29 10:38 ` Perki Pat
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox