From 0c771d999914f9d17c723900f2987acc45fd0fbb Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 4 Sep 2009 13:00:02 -0700 Subject: [PATCH] Move usb scanning code to ao-tools library This will allow the scanning code to be used by the command line tools as well as the ao-view GUI. Now that ao-view depends on the ao-tools library, it has been moved to the ao-tools directory as well. Signed-off-by: Keith Packard --- INSTALL | 17 +++- Makefile.am | 2 +- ao-tools/Makefile.am | 2 +- {ao-view => ao-tools/ao-view}/.gitignore | 0 {ao-view => ao-tools/ao-view}/Makefile.am | 8 +- {ao-view => ao-tools/ao-view}/ao-view.1 | 0 {ao-view => ao-tools/ao-view}/aoview.glade | 0 {ao-view => ao-tools/ao-view}/aoview.h | 18 +---- .../ao-view}/aoview_convert.c | 0 .../ao-view}/aoview_dev_dialog.c | 23 +++--- {ao-view => ao-tools/ao-view}/aoview_eeprom.c | 0 {ao-view => ao-tools/ao-view}/aoview_file.c | 0 {ao-view => ao-tools/ao-view}/aoview_flite.c | 0 {ao-view => ao-tools/ao-view}/aoview_label.c | 0 {ao-view => ao-tools/ao-view}/aoview_log.c | 0 {ao-view => ao-tools/ao-view}/aoview_main.c | 0 .../ao-view}/aoview_monitor.c | 0 {ao-view => ao-tools/ao-view}/aoview_replay.c | 0 {ao-view => ao-tools/ao-view}/aoview_serial.c | 0 {ao-view => ao-tools/ao-view}/aoview_state.c | 0 {ao-view => ao-tools/ao-view}/aoview_table.c | 0 {ao-view => ao-tools/ao-view}/aoview_util.c | 0 {ao-view => ao-tools/ao-view}/aoview_voice.c | 0 {ao-view => ao-tools/ao-view}/design | 0 ao-tools/lib/Makefile.am | 3 + .../aoview_dev.c => ao-tools/lib/cc-usbdev.c | 78 +++++++++++------- ao-tools/lib/cc-util.c | 80 +++++++++++++++++++ ao-tools/lib/cc.h | 51 ++++++++++++ configure.ac | 2 +- 29 files changed, 221 insertions(+), 63 deletions(-) rename {ao-view => ao-tools/ao-view}/.gitignore (100%) rename {ao-view => ao-tools/ao-view}/Makefile.am (60%) rename {ao-view => ao-tools/ao-view}/ao-view.1 (100%) rename {ao-view => ao-tools/ao-view}/aoview.glade (100%) rename {ao-view => ao-tools/ao-view}/aoview.h (96%) rename {ao-view => ao-tools/ao-view}/aoview_convert.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_dev_dialog.c (92%) rename {ao-view => ao-tools/ao-view}/aoview_eeprom.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_file.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_flite.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_label.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_log.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_main.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_monitor.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_replay.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_serial.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_state.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_table.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_util.c (100%) rename {ao-view => ao-tools/ao-view}/aoview_voice.c (100%) rename {ao-view => ao-tools/ao-view}/design (100%) rename ao-view/aoview_dev.c => ao-tools/lib/cc-usbdev.c (73%) create mode 100644 ao-tools/lib/cc-util.c create mode 100644 ao-tools/lib/cc.h diff --git a/INSTALL b/INSTALL index 8b82ade0..2550dab7 100644 --- a/INSTALL +++ b/INSTALL @@ -2,7 +2,7 @@ Installation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, -2006, 2007, 2008 Free Software Foundation, Inc. +2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is free documentation; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. @@ -159,7 +159,7 @@ Particular systems CC is not installed, it is recommended to use the following options in order to use an ANSI C compiler: - ./configure CC="cc -Ae" + ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. @@ -174,6 +174,16 @@ and if that doesn't work, try ./configure CC="cc -nodtk" + On Solaris, don't put `/usr/ucb' early in your `PATH'. This +directory contains several dysfunctional programs; working variants of +these programs are available in `/usr/bin'. So, if you need `/usr/ucb' +in your `PATH', put it _after_ `/usr/bin'. + + On Haiku, software installed for all users goes in `/boot/common', +not `/usr/local'. It is recommended to use the following options: + + ./configure --prefix=/boot/common + Specifying the System Type ========================== @@ -189,7 +199,8 @@ type, such as `sun4', or a canonical name which has the form: where SYSTEM can have one of these forms: - OS KERNEL-OS + OS + KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't diff --git a/Makefile.am b/Makefile.am index 96b9dea9..39e7c244 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=src ao-view ao-tools ao-utils +SUBDIRS=src ao-tools ao-utils EXTRA_DIST = ChangeLog diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 98b88f38..02b4785e 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -1 +1 @@ -SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-load +SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-load ao-view diff --git a/ao-view/.gitignore b/ao-tools/ao-view/.gitignore similarity index 100% rename from ao-view/.gitignore rename to ao-tools/ao-view/.gitignore diff --git a/ao-view/Makefile.am b/ao-tools/ao-view/Makefile.am similarity index 60% rename from ao-view/Makefile.am rename to ao-tools/ao-view/Makefile.am index 17661c8e..7b274a40 100644 --- a/ao-view/Makefile.am +++ b/ao-tools/ao-view/Makefile.am @@ -1,14 +1,16 @@ VERSION=$(shell git describe) -AM_CFLAGS=$(GNOME_CFLAGS) $(ALSA_CFLAGS) -I$(top_srcdir)/src -DAOVIEW_VERSION=\"$(VERSION)\" @FLITE_INCS@ +AO_VIEW_CFLAGS=-I$(top_srcdir)/ao-tools/lib +AO_VIEW_LIBS=$(top_builddir)/ao-tools/lib/libao-tools.a +AM_CFLAGS=$(AO_VIEW_CFLAGS) $(GNOME_CFLAGS) $(ALSA_CFLAGS) -I$(top_srcdir)/src -DAOVIEW_VERSION=\"$(VERSION)\" @FLITE_INCS@ bin_PROGRAMS=ao-view -ao_view_LDADD=$(GNOME_LIBS) $(FLITE_LIBS) $(ALSA_LIBS) +ao_view_DEPENDENCIES=$(AO_VIEW_LIBS) +ao_view_LDADD=$(GNOME_LIBS) $(FLITE_LIBS) $(ALSA_LIBS) $(AO_VIEW_LIBS) $(LIBUSB_LIBS) ao_view_SOURCES = \ aoview_main.c \ - aoview_dev.c \ aoview_dev_dialog.c \ aoview_serial.c \ aoview_monitor.c \ diff --git a/ao-view/ao-view.1 b/ao-tools/ao-view/ao-view.1 similarity index 100% rename from ao-view/ao-view.1 rename to ao-tools/ao-view/ao-view.1 diff --git a/ao-view/aoview.glade b/ao-tools/ao-view/aoview.glade similarity index 100% rename from ao-view/aoview.glade rename to ao-tools/ao-view/aoview.glade diff --git a/ao-view/aoview.h b/ao-tools/ao-view/aoview.h similarity index 96% rename from ao-view/aoview.h rename to ao-tools/ao-view/aoview.h index 9ca65298..6a4753ac 100644 --- a/ao-view/aoview.h +++ b/ao-tools/ao-view/aoview.h @@ -37,20 +37,12 @@ #include #include +#include "cc.h" + #include #include #include -struct usbdev { - char *sys; - char *tty; - char *manufacturer; - char *product; - char *serial; - int idProduct; - int idVendor; -}; - struct aogps_time { int hour; int minute; @@ -203,12 +195,6 @@ aoview_serial_getc(struct aoview_serial *serial); void aoview_dev_dialog_init(GladeXML *xml); -int -aoview_usb_scan(struct usbdev ***devs_ret); - -void -aoview_usbdev_free(struct usbdev *usbdev); - void aoview_state_notify(struct aodata *data); diff --git a/ao-view/aoview_convert.c b/ao-tools/ao-view/aoview_convert.c similarity index 100% rename from ao-view/aoview_convert.c rename to ao-tools/ao-view/aoview_convert.c diff --git a/ao-view/aoview_dev_dialog.c b/ao-tools/ao-view/aoview_dev_dialog.c similarity index 92% rename from ao-view/aoview_dev_dialog.c rename to ao-tools/ao-view/aoview_dev_dialog.c index 3f92085c..87396c1f 100644 --- a/ao-view/aoview_dev_dialog.c +++ b/ao-tools/ao-view/aoview_dev_dialog.c @@ -24,25 +24,30 @@ aoview_dev_dialog_map(GtkWidget *widget, gpointer data) GtkListStore *list_store; GtkTreeIter iter; int ndev, n; - struct usbdev **devs; + struct cc_usbdevs *devs; + struct cc_usbdev *dev; list_store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - ndev = aoview_usb_scan(&devs); - for (n = 0; n < ndev; n++) { - gtk_list_store_append(list_store, &iter); - gtk_list_store_set(list_store, &iter, - 0, devs[n]->product, - 1, devs[n]->serial, - 2, devs[n]->tty, - -1); + devs = cc_usbdevs_scan(); + if (devs) { + for (n = 0; n < devs->ndev; n++) { + dev = devs->dev[n]; + gtk_list_store_append(list_store, &iter); + gtk_list_store_set(list_store, &iter, + 0, dev->product, + 1, dev->serial, + 2, dev->tty, + -1); + } } gtk_tree_view_set_model (dev_list, GTK_TREE_MODEL(list_store)); g_object_unref(G_OBJECT(list_store)); gtk_tree_view_columns_autosize(dev_list); + cc_usbdevs_free(devs); } static GtkMessageDialog *dev_open_fail_dialog; diff --git a/ao-view/aoview_eeprom.c b/ao-tools/ao-view/aoview_eeprom.c similarity index 100% rename from ao-view/aoview_eeprom.c rename to ao-tools/ao-view/aoview_eeprom.c diff --git a/ao-view/aoview_file.c b/ao-tools/ao-view/aoview_file.c similarity index 100% rename from ao-view/aoview_file.c rename to ao-tools/ao-view/aoview_file.c diff --git a/ao-view/aoview_flite.c b/ao-tools/ao-view/aoview_flite.c similarity index 100% rename from ao-view/aoview_flite.c rename to ao-tools/ao-view/aoview_flite.c diff --git a/ao-view/aoview_label.c b/ao-tools/ao-view/aoview_label.c similarity index 100% rename from ao-view/aoview_label.c rename to ao-tools/ao-view/aoview_label.c diff --git a/ao-view/aoview_log.c b/ao-tools/ao-view/aoview_log.c similarity index 100% rename from ao-view/aoview_log.c rename to ao-tools/ao-view/aoview_log.c diff --git a/ao-view/aoview_main.c b/ao-tools/ao-view/aoview_main.c similarity index 100% rename from ao-view/aoview_main.c rename to ao-tools/ao-view/aoview_main.c diff --git a/ao-view/aoview_monitor.c b/ao-tools/ao-view/aoview_monitor.c similarity index 100% rename from ao-view/aoview_monitor.c rename to ao-tools/ao-view/aoview_monitor.c diff --git a/ao-view/aoview_replay.c b/ao-tools/ao-view/aoview_replay.c similarity index 100% rename from ao-view/aoview_replay.c rename to ao-tools/ao-view/aoview_replay.c diff --git a/ao-view/aoview_serial.c b/ao-tools/ao-view/aoview_serial.c similarity index 100% rename from ao-view/aoview_serial.c rename to ao-tools/ao-view/aoview_serial.c diff --git a/ao-view/aoview_state.c b/ao-tools/ao-view/aoview_state.c similarity index 100% rename from ao-view/aoview_state.c rename to ao-tools/ao-view/aoview_state.c diff --git a/ao-view/aoview_table.c b/ao-tools/ao-view/aoview_table.c similarity index 100% rename from ao-view/aoview_table.c rename to ao-tools/ao-view/aoview_table.c diff --git a/ao-view/aoview_util.c b/ao-tools/ao-view/aoview_util.c similarity index 100% rename from ao-view/aoview_util.c rename to ao-tools/ao-view/aoview_util.c diff --git a/ao-view/aoview_voice.c b/ao-tools/ao-view/aoview_voice.c similarity index 100% rename from ao-view/aoview_voice.c rename to ao-tools/ao-view/aoview_voice.c diff --git a/ao-view/design b/ao-tools/ao-view/design similarity index 100% rename from ao-view/design rename to ao-tools/ao-view/design diff --git a/ao-tools/lib/Makefile.am b/ao-tools/lib/Makefile.am index 9584e216..f66ee0a9 100644 --- a/ao-tools/lib/Makefile.am +++ b/ao-tools/lib/Makefile.am @@ -16,6 +16,9 @@ libao_tools_a_SOURCES = \ ccdbg-state.c \ cc-usb.c \ cc-usb.h \ + cc.h \ + cc-usbdev.c \ + cc-util.c \ cc-bitbang.c \ cc-bitbang.h \ cp-usb-async.c \ diff --git a/ao-view/aoview_dev.c b/ao-tools/lib/cc-usbdev.c similarity index 73% rename from ao-view/aoview_dev.c rename to ao-tools/lib/cc-usbdev.c index 9b8cc19e..d8bb8b11 100644 --- a/ao-view/aoview_dev.c +++ b/ao-tools/lib/cc-usbdev.c @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * 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 @@ -15,14 +16,18 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include "aoview.h" +#include "cc.h" + #include #include +#include +#include +#include static char * load_string(char *dir, char *file) { - char *full = aoview_fullname(dir, file); + char *full = cc_fullname(dir, file); char line[4096]; char *r; FILE *f; @@ -86,14 +91,14 @@ usb_tty(char *sys) int ntty; char *tty; - base = aoview_basename(sys); + base = cc_basename(sys); num_configs = load_hex(sys, "bNumConfigurations"); num_interfaces = load_hex(sys, "bNumInterfaces"); for (config = 1; config <= num_configs; config++) { for (interface = 0; interface < num_interfaces; interface++) { sprintf(endpoint_base, "%s:%d.%d", base, config, interface); - endpoint_full = aoview_fullname(sys, endpoint_base); + endpoint_full = cc_fullname(sys, endpoint_base); /* Check for tty:ttyACMx style names */ @@ -102,21 +107,21 @@ usb_tty(char *sys) alphasort); if (ntty > 0) { free(endpoint_full); - tty = aoview_fullname("/dev", namelist[0]->d_name + 4); + tty = cc_fullname("/dev", namelist[0]->d_name + 4); free(namelist); return tty; } /* Check for tty/ttyACMx style names */ - tty_dir = aoview_fullname(endpoint_full, "tty"); + tty_dir = cc_fullname(endpoint_full, "tty"); free(endpoint_full); ntty = scandir(tty_dir, &namelist, dir_filter_tty, alphasort); free (tty_dir); if (ntty > 0) { - tty = aoview_fullname("/dev", namelist[0]->d_name); + tty = cc_fullname("/dev", namelist[0]->d_name); free(namelist); return tty; } @@ -125,12 +130,12 @@ usb_tty(char *sys) return NULL; } -static struct usbdev * +static struct cc_usbdev * usb_scan_device(char *sys) { - struct usbdev *usbdev; + struct cc_usbdev *usbdev; - usbdev = calloc(1, sizeof (struct usbdev)); + usbdev = calloc(1, sizeof (struct cc_usbdev)); if (!usbdev) return NULL; usbdev->sys = strdup(sys); @@ -143,8 +148,8 @@ usb_scan_device(char *sys) return usbdev; } -void -aoview_usbdev_free(struct usbdev *usbdev) +static void +usbdev_free(struct cc_usbdev *usbdev) { free(usbdev->sys); free(usbdev->manufacturer); @@ -174,16 +179,19 @@ dir_filter_dev(const struct dirent *d) return 1; } -int -aoview_usb_scan(struct usbdev ***devs_ret) +struct cc_usbdevs * +cc_usbdevs_scan(void) { - int n; - int ndev = 0; - int e; - struct dirent **ents; - char *dir; - struct usbdev **devs = NULL; - struct usbdev *dev; + int e; + struct dirent **ents; + char *dir; + struct cc_usbdev *dev; + struct cc_usbdevs *devs; + int n; + + devs = calloc(1, sizeof (struct cc_usbdevs)); + if (!devs) + return NULL; n = scandir (USB_DEVICES, &ents, dir_filter_dev, @@ -191,18 +199,30 @@ aoview_usb_scan(struct usbdev ***devs_ret) if (!n) return 0; for (e = 0; e < n; e++) { - dir = aoview_fullname(USB_DEVICES, ents[e]->d_name); + dir = cc_fullname(USB_DEVICES, ents[e]->d_name); dev = usb_scan_device(dir); free(dir); if (dev->idVendor == 0xfffe && dev->tty) { - if (devs) - devs = realloc(devs, ndev + 1 * sizeof (struct usbdev *)); + if (devs->dev) + devs->dev = realloc(devs->dev, + devs->ndev + 1 * sizeof (struct usbdev *)); else - devs = malloc (sizeof (struct usbdev *)); - devs[ndev++] = dev; + devs->dev = malloc (sizeof (struct usbdev *)); + devs->dev[devs->ndev++] = dev; } } free(ents); - *devs_ret = devs; - return ndev; + return devs; +} + +void +cc_usbdevs_free(struct cc_usbdevs *usbdevs) +{ + int i; + + if (!usbdevs) + return; + for (i = 0; i < usbdevs->ndev; i++) + usbdev_free(usbdevs->dev[i]); + free(usbdevs); } diff --git a/ao-tools/lib/cc-util.c b/ao-tools/lib/cc-util.c new file mode 100644 index 00000000..7104470c --- /dev/null +++ b/ao-tools/lib/cc-util.c @@ -0,0 +1,80 @@ +/* + * Copyright © 2009 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "cc.h" +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +char * +cc_fullname (char *dir, char *file) +{ + char *new; + int dlen = strlen (dir); + int flen = strlen (file); + int slen = 0; + + if (dir[dlen-1] != '/') + slen = 1; + new = malloc (dlen + slen + flen + 1); + if (!new) + return 0; + strcpy(new, dir); + if (slen) + strcat (new, "/"); + strcat(new, file); + return new; +} + +char * +cc_basename(char *file) +{ + char *b; + + b = strrchr(file, '/'); + if (!b) + return file; + return b + 1; +} + +int +cc_mkdir(char *dir) +{ + char *slash; + char *d; + char *part; + + d = dir; + for (;;) { + slash = strchr (d, '/'); + if (!slash) + slash = d + strlen(d); + if (!*slash) + break; + part = strndup(dir, slash - dir); + if (!access(part, F_OK)) + if (mkdir(part, 0777) < 0) + return -errno; + free(part); + d = slash + 1; + } + return 0; +} diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h new file mode 100644 index 00000000..dad11bf3 --- /dev/null +++ b/ao-tools/lib/cc.h @@ -0,0 +1,51 @@ +/* + * Copyright © 2009 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef _CC_H_ +#define _CC_H_ + +char * +cc_fullname (char *dir, char *file); + +char * +cc_basename(char *file); + +int +cc_mkdir(char *dir); + +struct cc_usbdev { + char *sys; + char *tty; + char *manufacturer; + char *product; + char *serial; + int idProduct; + int idVendor; +}; + +struct cc_usbdevs { + struct cc_usbdev **dev; + int ndev; +}; + +void +cc_usbdevs_free(struct cc_usbdevs *usbdevs); + +struct cc_usbdevs * +cc_usbdevs_scan(void); + +#endif /* _CC_H_ */ diff --git a/configure.ac b/configure.ac index b52bb6e9..dfbae71d 100644 --- a/configure.ac +++ b/configure.ac @@ -73,7 +73,6 @@ PKG_CHECK_MODULES([ALSA], [alsa]) AC_OUTPUT([ Makefile -ao-view/Makefile ao-tools/Makefile ao-tools/lib/Makefile ao-tools/ao-rawload/Makefile @@ -81,5 +80,6 @@ ao-tools/ao-dbg/Makefile ao-tools/ao-bitbang/Makefile ao-tools/ao-eeprom/Makefile ao-tools/ao-load/Makefile +ao-tools/ao-view/Makefile ao-utils/Makefile ]) -- 2.30.2