/***************************************************************************
* CVSID: $Id$
*
* hal-device.c : add devices HAL
*
* Copyright (C) 2005 SuSE Linux Gmbh
*
* Authors:
* Steffen Winterfeldt <snwint@suse.de>
*
* Licensed under the Academic Free License version 2.1
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#define _GNU_SOURCE
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <inttypes.h>
#include <getopt.h>
#ifndef DBUS_API_SUBJECT_TO_CHANGE
#endif
#include <libhal.h>
typedef struct {
char *udi;
char *real_udi;
} new_dev_t;
typedef struct lh_prop_s {
char *key;
union {
char *str_value;
double double_value;
char **strlist_value;
} v;
} lh_prop_t;
void help(void);
static char *skip_space(char *s);
static char *skip_non_eq_or_space(char *s);
static char *skip_number(char *s);
static char *skip_nonquote(char *s);
struct {
char *udi;
} opt;
{ 0, 0, 0, 0 }
};
{
int i, err;
opterr = 0;
switch (i) {
case 'a':
break;
case 'r':
break;
case 'h':
help();
return 0;
default:
help();
return 1;
}
}
return 2;
}
/* fprintf(stderr, "connected to: %s\n", dbus_bus_get_unique_name(conn)); */
if (dbus_error_is_set(&error)) {
}
"Normally this means the HAL daemon (hald) is not running or not ready.\n");
return 5;
}
err = 0;
else
err = 6;
return err;
}
void help()
{
"usage: hal-device [--help] [--add udi] [--remove udi] [udi]\n"
"Create, remove, or show HAL device. If no udi is given, shows all devices.\n"
"If udi doesn't start with a '/', '/org/freedesktop/Hal/devices/' is prepended.\n"
" -a, --add udi\t\tAdd new device.\n"
" \t\t\tReads property list in 'lshal' syntax from stdin.\n"
" -r, --remove udi\tRemove device.\n"
" -h, --help\t\tShow this text.\n"
);
}
/*
* Dump all devices.
*/
{
int i;
int num_devices;
char **device_names;
if (arg) {
if (*arg == '/') {
} else {
#ifdef HAVE_ASPRINTF
#else
#endif
}
}
if (!udi) {
return 31;
}
} else {
num_devices = 1;
}
for(i = 0; i < num_devices; i++) {
int type;
continue;
}
if (!udi)
printf("%d: ", i);
switch (type) {
printf(" %s = '%s' (string)\n",
);
break;
printf(" %s = %d (0x%x) (int)\n",
);
break;
printf(" %s = %lld (0x%llx) (uint64)\n",
(long long) libhal_psi_get_uint64(&it),
(long long) libhal_psi_get_uint64(&it)
);
break;
printf(" %s = %g (double)\n",
);
break;
printf(" %s = %s (bool)\n",
);
break;
{
char **strlist;
while (*strlist) {
strlist++;
}
printf(" } (string list)\n");
}
break;
default:
break;
}
}
printf("\n");
}
return 0;
}
{
char *udi;
if (!arg) return 11;
if (*arg == '/') {
} else {
#ifdef HAVE_ASPRINTF
#else
#endif
}
return 12;
}
return 13;
}
return 0;
}
{
int err;
if (!arg)
return 21;
if (*arg == '/') {
} else {
#ifdef HAVE_ASPRINTF
#else
#endif
}
if (udi)
if (udi)
if (dev_exists) {
} else {
return 22;
}
}
}
if (!dev_exists) {
}
}
return err;
}
char *skip_space(char *s)
{
while (isspace(*s)) s++;
return s;
}
char *skip_non_eq_or_space(char *s)
{
while (*s && *s != '=' && !isspace(*s))
s++;
return s;
}
char *skip_number(char *s)
{
s++;
return s;
}
char *skip_nonquote(char *s)
{
while (*s && *s != '\'')
s++;
return s;
}
{
char *s, *s1;
lh_prop_t *p;
unsigned len;
int remove = 0;
s = skip_space(buf);
if (*s == '-') {
remove = 1;
s = skip_space(s + 1);
}
s = skip_non_eq_or_space(key = s);
*s++ = 0;
if (!*key)
return;
if (*key == '#')
return;
if (*s == '=')
s++;
s = skip_space(s);
if (!*s)
remove = 1;
p = calloc(1, sizeof *p);
if (remove) {
*prop = p;
return;
}
if (*s == '\'') {
s_val = s + 1;
*(s ? s : s_val) = 0;
} else if (*s == '{') {
s_val = s + 1;
len = 0;
while (*s_val++ == '\'') {
s = skip_nonquote(s_val);
if (*s) *s++ = 0;
s_val = skip_nonquote(s);
}
s += 4;
p->v.bool_value = TRUE;
s += 5;
p->v.bool_value = FALSE;
} else if ((s1 = skip_number(s)) != s) {
*s1++ = 0;
*s1++ = 0;
}
s = s1;
}
if (p->type == LIBHAL_PROPERTY_TYPE_INVALID) {
free(p);
} else {
*prop = p;
}
}
{
lh_prop_t *p;
continue;
}
if (old_type != LIBHAL_PROPERTY_TYPE_INVALID &&
return 41;
}
}
switch (p->type) {
break;
return 42;
}
break;
return 42;
}
break;
return 42;
}
break;
return 42;
}
break;
return 42;
}
break;
for(s = p->v.strlist_value; *s; s++) {
return 42;
}
}
break;
}
}
return 0;
}
{
char **s;
}
}
return NULL;
}