📄 device.c
字号:
/**********Copyright 1990 Regents of the University of California. All rights reserved.Author: 1986 Wayne A. Christopher, U. C. Berkeley CAD GroupModified: 2000 AlansFixes**********//* * Routines to query and alter devices. */#include "ngspice.h"#include "gendefs.h"#include "cktdefs.h"#include "cpdefs.h"#include "ftedefs.h"#include "dgen.h"#include "circuits.h"#include "device.h"#include "variable.h"#include "gens.h" /* wl_forall */static wordlist *devexpand(char *name);static void all_show(wordlist *wl, int mode);/* * show: list device operating point info * show * show devs : params * show devs : params ; devs : params * show dev dev dev : param param param , dev dev : param param * show t : param param param, t : param param * */static int count;voidcom_showmod(wordlist *wl){ all_show(wl, 1);}voidcom_show(wordlist *wl){ all_show(wl, 0);}static voidall_show(wordlist *wl, int mode){ wordlist *params, *nextgroup, *thisgroup; wordlist *prev, *next, *w; int screen_width; dgen *dg, *listdg; int instances; int i, j, n; int param_flag, dev_flag; if (!ft_curckt) { fprintf(cp_err, "Error: no circuit loaded\n"); return; } if (wl && wl->wl_word && eq(wl->wl_word, "-v")) { old_show(wl->wl_next); return; } if (!cp_getvar("width", VT_NUM, (char *) &screen_width)) screen_width = DEF_WIDTH; count = (screen_width - LEFT_WIDTH) / (DEV_WIDTH + 1); n = 0; do { prev = NULL; params = NULL; nextgroup = NULL; thisgroup = wl; param_flag = 0; dev_flag = 0; /* find the parameter list and the nextgroup */ for (w = wl; w && !nextgroup; w = next) { next = w->wl_next; if (eq(w->wl_word, "++") || eq(w->wl_word, "all")) { if (params) { param_flag = DGEN_ALLPARAMS; if (prev) prev->wl_next = w->wl_next; else params = next; } else { dev_flag = DGEN_ALLDEVS; if (prev) prev->wl_next = w->wl_next; else thisgroup = next; } /* w must not be freed here */ w = NULL; } else if (eq(w->wl_word, "+")) { if (params) { param_flag = DGEN_DEFPARAMS; if (prev) prev->wl_next = w->wl_next; else params = next; } else { dev_flag = DGEN_DEFDEVS; if (prev) prev->wl_next = w->wl_next; else thisgroup = next; } /* w must not be freed here */ w = NULL; } else if (eq(w->wl_word, ":")) { /* w must not be freed here */ w = NULL; if (!params) { params = next; if (prev) prev->wl_next = NULL; else thisgroup = NULL; } else { if (prev) prev->wl_next = next; else params = next; } } else if (eq(w->wl_word, ";") || eq(w->wl_word, ",")) { nextgroup = next; /* w must not be freed here */ w = NULL; if (prev) prev->wl_next = NULL; break; } prev = w; } instances = 0; for (dg = dgen_init(ft_curckt->ci_ckt, thisgroup, 1, dev_flag, mode); dg; dgen_nth_next(&dg, count)) { instances = 1; if (dg->flags & DGEN_INSTANCE) { instances = 2; printf(" %s: %s\n", ft_sim->devices[dg->dev_type_no]->name, ft_sim->devices[dg->dev_type_no]->description); n += 1; i = 0; do { printf("%*s", LEFT_WIDTH, "device"); j = dgen_for_n(dg, count, printstr, "n", i); i += 1; printf("\n"); } while (j); if (ft_sim->devices[dg->dev_type_no]->numModelParms) { i = 0; do { printf("%*s", LEFT_WIDTH, "model"); j = dgen_for_n(dg, count, printstr, "m", i); i += 1; printf("\n"); } while (j); } listdg = dg; if (param_flag) param_forall(dg, param_flag); else if (!params) param_forall(dg, DGEN_DEFPARAMS); if (params) wl_forall(params, listparam, dg); printf("\n"); } else if (ft_sim->devices[dg->dev_type_no]->numModelParms) { printf(" %s models (%s)\n", ft_sim->devices[dg->dev_type_no]->name, ft_sim->devices[dg->dev_type_no]->description); n += 1; i = 0; do { printf("%*s", LEFT_WIDTH, "model"); j = dgen_for_n(dg, count, printstr, "m", i); i += 1; printf("\n"); } while (j); printf("\n"); if (param_flag) param_forall(dg, param_flag); else if (!params) param_forall(dg, DGEN_DEFPARAMS); if (params) wl_forall(params, listparam, dg); printf("\n"); } } wl = nextgroup; } while (wl); if (!n) { if (instances == 0) printf("No matching instances or models\n"); else if (instances == 1) printf("No matching models\n"); else printf("No matching elements\n"); }}intprintstr(dgen *dg, char *name){ /* va: ' ' is no flag for %s; \? avoids trigraph warning */ if (*name == 'n') { if (dg->instance) printf(" %*.*s", DEV_WIDTH, DEV_WIDTH, dg->instance->GENname); else printf(" %*s", DEV_WIDTH, "<\?\?\?\?\?\?\?>"); } else if (*name == 'm') { if (dg->model) printf(" %*.*s", DEV_WIDTH, DEV_WIDTH, dg->model->GENmodName); else printf(" %*s", DEV_WIDTH, "<\?\?\?\?\?\?\?>"); } else printf(" %*s", DEV_WIDTH, "<error>"); return 0;}voidparam_forall(dgen *dg, int flags){ int i, j, k, found; int xcount; IFparm *plist; found = 0; if (dg->flags & DGEN_INSTANCE) { xcount = *ft_sim->devices[dg->dev_type_no]->numInstanceParms; plist = ft_sim->devices[dg->dev_type_no]->instanceParms; } else { xcount = *ft_sim->devices[dg->dev_type_no]->numModelParms; plist = ft_sim->devices[dg->dev_type_no]->modelParms; } for (i = 0; i < xcount; i++) { if (plist[i].dataType & IF_ASK) { if ((((CKTcircuit *) (dg->ckt))->CKTrhsOld || (plist[i].dataType & IF_SET)) && (!(plist[i].dataType & (IF_REDUNDANT | IF_UNINTERESTING)) || (flags == DGEN_ALLPARAMS && !(plist[i].dataType & IF_REDUNDANT)))) { j = 0; do { if (!j) printf("%*.*s", LEFT_WIDTH, LEFT_WIDTH, plist[i].keyword); else printf("%*.*s", LEFT_WIDTH, LEFT_WIDTH, " "); k = dgen_for_n(dg, count, printvals, (plist + i), j); printf("\n"); j += 1; } while (k); } } }}voidlistparam(wordlist *p, dgen *dg){ int i, j, k, found; int xcount; IFparm *plist; found = 0; if (dg->flags & DGEN_INSTANCE) { xcount = *ft_sim->devices[dg->dev_type_no]->numInstanceParms; plist = ft_sim->devices[dg->dev_type_no]->instanceParms; } else { xcount = *ft_sim->devices[dg->dev_type_no]->numModelParms; plist = ft_sim->devices[dg->dev_type_no]->modelParms; } for (i = 0; i < xcount; i++) { if (eqc(p->wl_word, plist[i].keyword) && (plist[i].dataType & IF_ASK)) { found = 1; break; } } if (found) { if ((((CKTcircuit *) (dg->ckt))->CKTrhsOld || (plist[i].dataType & IF_SET))) { j = 0; do { if (!j) printf("%*.*s", LEFT_WIDTH, LEFT_WIDTH, p->wl_word); else printf("%*.*s", LEFT_WIDTH, LEFT_WIDTH, " "); k = dgen_for_n(dg, count, printvals, (plist + i), j); printf("\n"); j += 1; } while (k > 0); } else { j = 0; do { if (!j) printf("%*.*s", LEFT_WIDTH, LEFT_WIDTH, p->wl_word); else printf("%*s", LEFT_WIDTH, " "); k = dgen_for_n(dg, count, bogus1, 0, j); printf("\n"); j += 1; } while (k > 0); } } else { j = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -