From 14acefd9690f6b9475b10fa28aeaebf6c91fada5 Mon Sep 17 00:00:00 2001 From: arno Date: Fri, 7 Jul 2000 12:33:24 +0000 Subject: [PATCH] * dev.c dev.h: Moved defunct first_device() and next_device() to devlist.c * devlist.c, devlist.h: Another step towards dynamically loadable devices. The first_device() and next_device() functions abstract away the actual implementation of the devices list. Currently it is a fixed length array, when we start supporting dynamically loaded devices, this is no longer true. * test_devlist.c: Checks the implementation of first_device() and next_device(). * Makefile.am, .cvsignore: Updates for new files. --- src/spicelib/.cvsignore | 2 + src/spicelib/devices/ChangeLog | 12 +++++ src/spicelib/devices/Makefile.am | 11 +++++ src/spicelib/devices/dev.c | 25 ---------- src/spicelib/devices/dev.h | 2 - src/spicelib/devices/devlist.c | 64 +++++++++++++++++++++++++ src/spicelib/devices/devlist.h | 35 ++++++++++++++ src/spicelib/devices/test_devlist.c | 73 +++++++++++++++++++++++++++++ 8 files changed, 197 insertions(+), 27 deletions(-) create mode 100644 src/spicelib/devices/devlist.c create mode 100644 src/spicelib/devices/devlist.h create mode 100644 src/spicelib/devices/test_devlist.c diff --git a/src/spicelib/.cvsignore b/src/spicelib/.cvsignore index e440fafda..c9b9f5e4f 100644 --- a/src/spicelib/.cvsignore +++ b/src/spicelib/.cvsignore @@ -1,3 +1,5 @@ Makefile.in Makefile .deps +.libs +test_devlist diff --git a/src/spicelib/devices/ChangeLog b/src/spicelib/devices/ChangeLog index 566a103f8..eb703a6fb 100644 --- a/src/spicelib/devices/ChangeLog +++ b/src/spicelib/devices/ChangeLog @@ -1,3 +1,15 @@ +2000-07-07 Arno W. Peters + + * devlist.c, devlist.h: Another step towards + dynamically loadable devices. The first_device() and + next_device() functions abstract away the actual + implementation of the devices list. Currently it is a fixed + length array, when we start supporting dynamically loaded devices, + this is no longer true. + + * test_devlist.c: Checks the implementation of first_device() + and next_device(). + 2000-04-04 Paolo Nenzi * Makefile.am: Added support for BSIM4 diff --git a/src/spicelib/devices/Makefile.am b/src/spicelib/devices/Makefile.am index 3e6c6c143..c11cd6711 100644 --- a/src/spicelib/devices/Makefile.am +++ b/src/spicelib/devices/Makefile.am @@ -37,6 +37,8 @@ lib_LIBRARIES = libdev.a libdev_a_SOURCES = \ dev.c \ dev.h \ + devlist.c \ + devlist.h \ devsup.c \ cktaccept.c \ cktaccept.h \ @@ -46,6 +48,15 @@ libdev_a_SOURCES = \ cktfinddev.c \ cktinit.c +bin_PROGRAMS = test_devlist + +test_devlist_SOURCES = \ + devlist.c \ + devlist.h \ + test_devlist.c + +TESTS = test_devlist + EXTRA_DIST = README INCLUDES = -I$(top_srcdir)/src/include diff --git a/src/spicelib/devices/dev.c b/src/spicelib/devices/dev.c index 722a3d63d..028443b97 100644 --- a/src/spicelib/devices/dev.c +++ b/src/spicelib/devices/dev.c @@ -173,28 +173,3 @@ devices(void) } -/* Returns the first device in the list, or NULL if the list is empty */ -SPICEdev * -first_device(void) -{ - return DEVices[0]; -} - - -/* Returns the next device on the list, or NULL if no more devices - left. */ -SPICEdev * -next_device(SPICEdev *current) -{ - SPICEdev *ret; - int index; - - index = (current - first_device()) / sizeof(SPICEdev *); - if (index < num_devices()) { - ret = DEVices[index + 1]; - } else { - ret = NULL; - } - - return ret; -} diff --git a/src/spicelib/devices/dev.h b/src/spicelib/devices/dev.h index a49c3ca2a..cb1ee02ec 100644 --- a/src/spicelib/devices/dev.h +++ b/src/spicelib/devices/dev.h @@ -5,8 +5,6 @@ int num_devices(void); IFdevice **devices_ptr(void); SPICEdev **devices(void); -SPICEdev *first_device(void); -SPICEdev *next_device(SPICEdev *current); #endif diff --git a/src/spicelib/devices/devlist.c b/src/spicelib/devices/devlist.c new file mode 100644 index 000000000..a140a65a1 --- /dev/null +++ b/src/spicelib/devices/devlist.c @@ -0,0 +1,64 @@ +/* NG-SPICE -- An electrical circuit simulator + * + * Copyright (c) 1990 University of California + * Copyright (c) 2000 Arno W. Peters + * + * Permission to use, copy, modify, and distribute this software and + * its documentation without fee, and without a written agreement is + * hereby granted, provided that the above copyright notice, this + * paragraph and the following three paragraphs appear in all copies. + * + * This software program and documentation are copyrighted by their + * authors. The software program and documentation are supplied "as + * is", without any accompanying services from the authors. The + * authors do not warrant that the operation of the program will be + * uninterrupted or error-free. The end-user understands that the + * program was developed for research purposes and is advised not to + * rely exclusively on the program for any reason. + * + * IN NO EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, + * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING + * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS + * DOCUMENTATION, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. THE AUTHORS SPECIFICALLY DISCLAIMS ANY + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE + * SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE AUTHORS + * HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, + * ENHANCEMENTS, OR MODIFICATIONS. */ + +#include + +#include +#include + +#include "dev.h" + + + +/* Returns the first device in the list, or NULL if the list is empty */ +SPICEdev ** +first_device(void) +{ + return devices(); +} + + +/* Returns the next device on the list, or NULL if no more devices + left. */ +SPICEdev ** +next_device(SPICEdev **current) +{ + int index; + SPICEdev **ret; + + index = (current - devices())/sizeof(SPICEdev *); + printf("index: %d\n", index); + if (index < num_devices()) { + ret = current + sizeof(SPICEdev *); + } else { + ret = NULL; + } + + return ret; +} diff --git a/src/spicelib/devices/devlist.h b/src/spicelib/devices/devlist.h new file mode 100644 index 000000000..25d660786 --- /dev/null +++ b/src/spicelib/devices/devlist.h @@ -0,0 +1,35 @@ +/* NG-SPICE -- An electrical circuit simulator + * + * Copyright (c) 2000 Arno W. Peters + * + * Permission to use, copy, modify, and distribute this software and + * its documentation without fee, and without a written agreement is + * hereby granted, provided that the above copyright notice, this + * paragraph and the following three paragraphs appear in all copies. + * + * This software program and documentation are copyrighted by their + * authors. The software program and documentation are supplied "as + * is", without any accompanying services from the authors. The + * authors do not warrant that the operation of the program will be + * uninterrupted or error-free. The end-user understands that the + * program was developed for research purposes and is advised not to + * rely exclusively on the program for any reason. + * + * IN NO EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, + * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING + * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS + * DOCUMENTATION, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. THE AUTHORS SPECIFICALLY DISCLAIMS ANY + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE + * SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE AUTHORS + * HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, + * ENHANCEMENTS, OR MODIFICATIONS. */ + +#ifndef _DEVLIST_H +#define _DEVLIST_H + +SPICEdev **first_device(void); +SPICEdev **next_device(SPICEdev **current); + +#endif diff --git a/src/spicelib/devices/test_devlist.c b/src/spicelib/devices/test_devlist.c new file mode 100644 index 000000000..99c7866d8 --- /dev/null +++ b/src/spicelib/devices/test_devlist.c @@ -0,0 +1,73 @@ +#include +#include + +#include +#include + +#include "devlist.h" + + +SPICEdev dummy = { + { + "Dummy", + "A dummy element", + + NULL, + NULL, + NULL, + + NULL, + NULL, + + NULL, + NULL, + 0 + }, + + NULL, +}; + + +SPICEdev *DEVices[] = { + &dummy, + &dummy, + &dummy, + &dummy +}; + + +int +num_devices(void) +{ + return sizeof(DEVices)/sizeof(SPICEdev *); +} + +SPICEdev ** +devices(void) +{ + return DEVices; +} + + +int +main(void) +{ + SPICEdev **dev; + int count = 0; + int ret; + + for (dev = first_device(); dev != NULL; dev = next_device(dev)) { + printf("count: %d\n", count); + count++; + } + + if (count == num_devices() + 1) { + printf("PASSED"); + ret = EXIT_SUCCESS; + } else { + printf("FAILED"); + ret = EXIT_FAILURE; + } + printf(": test_dev\n"); + return ret; +}