8 changed files with 197 additions and 27 deletions
-
2src/spicelib/.cvsignore
-
12src/spicelib/devices/ChangeLog
-
11src/spicelib/devices/Makefile.am
-
25src/spicelib/devices/dev.c
-
2src/spicelib/devices/dev.h
-
64src/spicelib/devices/devlist.c
-
35src/spicelib/devices/devlist.h
-
73src/spicelib/devices/test_devlist.c
@ -1,3 +1,5 @@ |
|||||
Makefile.in |
Makefile.in |
||||
Makefile |
Makefile |
||||
.deps |
.deps |
||||
|
.libs |
||||
|
test_devlist |
||||
@ -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 <config.h> |
||||
|
|
||||
|
#include <devdefs.h> |
||||
|
#include <ifsim.h> |
||||
|
|
||||
|
#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; |
||||
|
} |
||||
@ -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 |
||||
@ -0,0 +1,73 @@ |
|||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
#include <ifsim.h> |
||||
|
#include <devdefs.h> |
||||
|
|
||||
|
#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; |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue