hal/tools hal_get_property.c,1.5,1.6 hal_set_property.c,1.5,1.6

David Zeuthen david at pdx.freedesktop.org
Sun Jul 11 13:38:36 PDT 2004


Update of /cvs/hal/hal/tools
In directory pdx:/tmp/cvs-serv13750/tools

Modified Files:
	hal_get_property.c hal_set_property.c 
Log Message:
2004-07-11  David Zeuthen  <david at fubar.dk>

	* tools/hal_get_property.c, tools/hal_set_property.c: Make the
	command line interface a bit nicer.  Patch from Martin Waitz
	<tali at admingilde.org>



Index: hal_get_property.c
===================================================================
RCS file: /cvs/hal/hal/tools/hal_get_property.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- hal_get_property.c	10 Apr 2004 16:51:56 -0000	1.5
+++ hal_get_property.c	11 Jul 2004 20:38:34 -0000	1.6
@@ -56,14 +56,15 @@
 {
 	fprintf (stderr,
  "\n"
- "usage : %s --udi <udi> --key <key> [--hex] [--quiet] [--help]\n",
-		 argv[0]);
+ "usage : hal-get-property --udi <udi> --key <key> \n"
+ "                        [--hex] [--quiet] [--help] [--verbose] [--version]\n");
 	fprintf (stderr,
  "\n"
  "        --udi            Unique Device Id\n"
  "        --key            Key of the property to get\n"
  "        --hex            Show integer values in hex (without leading 0x)\n"
- "        --quiet          Be quiet\n"
+ "        --verbose        Be verbose\n"
+ "        --version        Show version and exit\n"
  "        --help           Show this information and exit\n"
  "\n"
  "This program retrieves a property from a device. If the property exist\n"
@@ -85,7 +86,8 @@
 	char *key = NULL;
 	int type;
 	dbus_bool_t is_hex = FALSE;
-	dbus_bool_t is_quiet = FALSE;
+	dbus_bool_t is_verbose = FALSE;
+	dbus_bool_t is_version = FALSE;
 	char *str;
 
 	if (argc <= 1) {
@@ -101,7 +103,8 @@
 			{"udi", 1, NULL, 0},
 			{"key", 1, NULL, 0},
 			{"hex", 0, NULL, 0},
-			{"quiet", 0, NULL, 0},
+			{"verbose", 0, NULL, 0},
+			{"version", 0, NULL, 0},
 			{"help", 0, NULL, 0},
 			{NULL, 0, NULL, 0}
 		};
@@ -120,8 +123,10 @@
 				return 0;
 			} else if (strcmp (opt, "hex") == 0) {
 				is_hex = TRUE;
-			} else if (strcmp (opt, "quiet") == 0) {
-				is_quiet = TRUE;
+			} else if (strcmp (opt, "verbose") == 0) {
+				is_verbose = TRUE;
+			} else if (strcmp (opt, "version") == 0) {
+				is_version = TRUE;
 			} else if (strcmp (opt, "key") == 0) {
 				key = strdup (optarg);
 			} else if (strcmp (opt, "udi") == 0) {
@@ -136,11 +141,10 @@
 		}
 	}
 
-	if (!is_quiet)
-		fprintf (stderr, "%s " PACKAGE_VERSION "\n", argv[0]);
-
-	if (!is_quiet)
-		fprintf (stderr, "\n");
+	if (is_version) {
+		printf ("hal-get-property " PACKAGE_VERSION "\n");
+		return 0;
+	}
 
 	if (udi == NULL || key == NULL) {
 		usage (argc, argv);
@@ -160,35 +164,35 @@
 	switch (type) {
 	case DBUS_TYPE_STRING:
 		str = hal_device_get_property_string (hal_ctx, udi, key);
-		if (!is_quiet)
-			fprintf (stderr, "Type is string\n");
-		fprintf (stdout, "%s", str);
+		if (is_verbose)
+			printf ("Type is string\n");
+		printf ("%s\n", str);
 		hal_free_string (str);
 		break;
 	case DBUS_TYPE_INT32:
-		if (!is_quiet)
-			fprintf (stderr, "Type is integer (shown in %s)\n",
-				 (is_hex ? "hexadecimal" : "decimal"));
-		fprintf (stdout, (is_hex ? "%x" : "%d"),
-			 hal_device_get_property_int (hal_ctx, udi, key));
+		if (is_verbose)
+			printf ("Type is integer (shown in %s)\n",
+				(is_hex ? "hexadecimal" : "decimal"));
+		printf ((is_hex ? "%x\n" : "%d\n"),
+			hal_device_get_property_int (hal_ctx, udi, key));
 		break;
 	case DBUS_TYPE_DOUBLE:
-		if (!is_quiet)
-			fprintf (stderr, "Type is double\n");
-		fprintf (stdout, "%f",
-			 hal_device_get_property_double (hal_ctx, udi, key));
+		if (is_verbose)
+			printf ("Type is double\n");
+		printf ("%f\n",
+			hal_device_get_property_double (hal_ctx, udi, key));
 		break;
 	case DBUS_TYPE_BOOLEAN:
-		if (!is_quiet)
-			fprintf (stderr, "Type is boolean\n");
-		fprintf (stdout, "%s",
-			 hal_device_get_property_bool (hal_ctx, udi,
-						       key) ? "true" :
-			 "false");
+		if (is_verbose)
+			printf ("Type is boolean\n");
+		printf ("%s\n",
+			hal_device_get_property_bool (hal_ctx, udi,
+						      key) ? "true" :
+			"false");
 		break;
 
 	default:
-		fprintf (stderr, "Unknown type %d='%c'\n", type, type);
+		printf ("Unknown type %d='%c'\n", type, type);
 		return 1;
 		break;
 	}

Index: hal_set_property.c
===================================================================
RCS file: /cvs/hal/hal/tools/hal_set_property.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- hal_set_property.c	10 Apr 2004 16:51:56 -0000	1.5
+++ hal_set_property.c	11 Jul 2004 20:38:34 -0000	1.6
@@ -57,10 +57,9 @@
 {
 	fprintf (stderr,
  "\n"
- "usage : %s --udi <udi> --key <key>\n"
- "           (--int <value> | --string <value> | --bool <value> |"
- "            --double <value> | --remove) [--help]\n",
-		 argv[0]);
+ "usage : hal-set-property --udi <udi> --key <key>\n"
+ "           (--int <value> | --string <value> | --bool <value> |\n"
+ "            --double <value> | --remove) [--help] [--version]\n");
 	fprintf (stderr,
  "\n" "        --udi            Unique Device Id\n"
  "        --key            Key of the property to set\n"
@@ -70,6 +69,8 @@
  "        --double         Set value to a floating point number\n"
  "        --bool           Set value to a boolean, ie. true or false\n"
  "        --remove         Indicates that the property should be removed\n"
+ "        --verbose        Be verbose\n"
+ "        --version        Show version and exit\n"
  "        --help           Show this information and exit\n"
  "\n"
  "This program attempts to set property for a device. Note that, due to\n"
@@ -95,10 +96,9 @@
 	double double_value = 0.0f;
 	dbus_bool_t bool_value = TRUE;
 	dbus_bool_t remove = FALSE;
+	dbus_bool_t is_version = FALSE;
 	int type = DBUS_TYPE_NIL;
 
-	fprintf (stderr, "%s " PACKAGE_VERSION "\n", argv[0]);
-
 	if (argc <= 1) {
 		usage (argc, argv);
 		return 1;
@@ -116,6 +116,7 @@
 			{"double", 1, NULL, 0},
 			{"bool", 1, NULL, 0},
 			{"remove", 0, NULL, 0},
+			{"version", 0, NULL, 0},
 			{"help", 0, NULL, 0},
 			{NULL, 0, NULL, 0}
 		};
@@ -157,6 +158,8 @@
 				remove = TRUE;
 			} else if (strcmp (opt, "udi") == 0) {
 				udi = strdup (optarg);
+			} else if (strcmp (opt, "version") == 0) {
+				is_version = TRUE;
 			}
 			break;
 
@@ -167,6 +170,11 @@
 		}
 	}
 
+	if (is_version) {
+		printf ("hal-set-property " PACKAGE_VERSION "\n");
+		return 0;
+	}
+
 	/* must have at least one, but not neither or both */
 	if ((remove && type != DBUS_TYPE_NIL) ||
 	    ((!remove) && type == DBUS_TYPE_NIL)) {





More information about the hal-commit mailing list