File: c_sweep.cc

package info (click to toggle)
gnucap 1%3A20230520-dev-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 9,836 kB
  • sloc: cpp: 29,956; sh: 352; makefile: 139
file content (150 lines) | stat: -rw-r--r-- 4,442 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*$Id: c_sweep.cc,v 26.83 2008/06/05 04:46:59 al Exp $ -*- C++ -*-
 * Copyright (C) 2001 Albert Davis
 * Author: Albert Davis <aldavis@gnu.org>
 *
 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
 *
 * 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; either version 3, 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 Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *------------------------------------------------------------------
 * Step a parameter and repeat a group of commands
 */
//testing=none 2006.07.17
#include "c_comand.h"
#include "globals.h"
extern int swp_count[], swp_steps[];
extern int swp_type[];
extern int swp_nest;
/*--------------------------------------------------------------------------*/
namespace {
  static std::string tempfile = STEPFILE;
/*--------------------------------------------------------------------------*/
static void setup(CS& cmd)
{
  for (;;) {
    if (cmd.is_digit()) {
      swp_steps[swp_nest] = cmd.ctoi() ;
      swp_steps[swp_nest] = (swp_steps[swp_nest]) 
	? swp_steps[swp_nest]-1
	: 0;
    }else if (cmd.umatch("li{near} ")) {
      swp_type[swp_nest] = 0;
    }else if (cmd.umatch("lo{g} ")) {
      swp_type[swp_nest] = 'L';
    }else{
      break;
    }
  }
}
/*--------------------------------------------------------------------------*/
static void buildfile(CS& cmd)
{
  static FILE *fptr;
  
  setup(cmd);
  if (fptr) {
    fclose(fptr);
  }else{
  }
  fptr = fopen(tempfile.c_str(), "w");
  if (!fptr) {
    throw Exception_File_Open("can't open temporary file:" + tempfile);
  }else{
  }
  fprintf(fptr, "%s\n", cmd.fullstring().c_str());
  
  for (;;) {
    char buffer[BUFLEN];
    getcmd(">>>", buffer, BUFLEN);
    if (Umatch(buffer,"go ")) {
      break;
    }else{
    }
    fprintf(fptr, "%s\n", buffer);
  }
  fclose(fptr);
  fptr = NULL;
}
/*--------------------------------------------------------------------------*/
static void doit(CARD_LIST* scope)
{
  static FILE *fptr;
  
  for (swp_count[swp_nest]=0; swp_count[swp_nest]<=swp_steps[swp_nest];
       ++swp_count[swp_nest]) {
    if (fptr) {
      fclose(fptr);
    }else{
    }
    fptr = fopen(tempfile.c_str(), "r");
    if (!fptr) {
      throw Exception_File_Open("can't open " + tempfile);
    }else{
    }
    char buffer[BUFLEN];
    fgets(buffer,BUFLEN,fptr);
    {
      CS cmd(CS::_STRING, buffer); //fgets from local file, obsolete
      if (cmd.umatch("sw{eep} ")) {
	setup(cmd);
      }else{
	throw Exception("bad file format: " + tempfile);
      }
      size_t ind = cmd.cursor();
      strncpy(buffer, "fault                              ", ind);
      buffer[ind-1] = ' ';		/* make sure there is a delimiter   */
    }					/* in case the words run together   */
    for (;;) {				/* may wipe out one letter of fault */
      {
	CS cmd(CS::_STRING, buffer); //fgets from local file, obsolete
	CMD::cmdproc(cmd, scope);
      }
      if (!fgets(buffer,BUFLEN,fptr)) {
	break;
      }else{
      }
      {
	CS cmd(CS::_STRING, buffer); //fgets from local file, obsolete
	if (cmd.umatch("sw{eep} ")) {
	  cmd.warn(bDANGER, "command not allowed in sweep");
	  buffer[0] = '\'';
	}else{
	}
      }
      IO::mstdout << swp_count[swp_nest]+1 << "> " << buffer;
    }
  }
  fclose(fptr);
  fptr = NULL;
  swp_count[swp_nest] = 0;
}
/*--------------------------------------------------------------------------*/
class CMD_SWEEP : public CMD {
public:
  void do_it(CS& cmd, CARD_LIST* Scope)override {
    if (cmd.more()) {
      buildfile(cmd);
    }else{
    }
    doit(Scope);
    command("unfault", Scope);
  }
} p;
DISPATCHER<CMD>::INSTALL d(&command_dispatcher, "sweep", &p);
/*--------------------------------------------------------------------------*/
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// vim:ts=8:sw=2:noet: