interactive testing
[gnucap-felix.git] / src / c_printf.cc
blob34d4bb4e7e879673b6b6bf27a474e60c0c97a5bc
1 /*$Id: c_exp.cc,v 1.4 2010-09-17 12:25:56 felix Exp $ -*- C++ -*-
2 * Copyright (C) 2007 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 *------------------------------------------------------------------
23 //testing=none
24 #include "globals.h"
25 #include "m_expression.h"
26 #include "c_comand.h"
27 /*--------------------------------------------------------------------------*/
28 namespace {
29 /*--------------------------------------------------------------------------*/
30 class CMD_ : public CMD {
31 public:
32 void do_it(CS& cmd, CARD_LIST* Scope)
34 char s1[2048];
35 char* oseek=s1;
36 string s;
37 cmd >> s;
38 OMSTREAM _out = IO::mstdout;
39 char* s0 = strdup(s.c_str());
40 char* iseek = s0;
41 char* percend = strchrnul(iseek, '%');
42 strncpy(s1, s0, unsigned(percend-iseek));
43 oseek+= percend-iseek;
44 iseek = percend;
46 while(cmd.more()){
47 cmd >> ',';
48 char c = cmd.peek();
49 if (c=='>') {
50 _out.outset(cmd);
51 break;
52 } else {
54 Expression e(cmd);
55 Expression r(e, Scope);
56 double d=0.;
57 try{
58 d = r.eval();
59 } catch (Exception& e) { untested();
60 incomplete();
61 throw e;
64 percend = strchrnul(percend+1, '%');
65 *percend = 0;
66 oseek+= sprintf(oseek, iseek, d );
67 *percend = '%';
68 iseek = percend;
70 *oseek = 0;
71 cmd.check(bDANGER, "syntax error parsing expression");
72 trace1("done", s1);
73 _out << string(s1);
74 _out.outreset();
75 free(s0);
77 } p0;
78 DISPATCHER<CMD>::INSTALL d0(&command_dispatcher, "printf", &p0);
79 /*--------------------------------------------------------------------------*/
81 /*--------------------------------------------------------------------------*/
82 /*--------------------------------------------------------------------------*/