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
|
/*$Id: c_list.cc 2016/09/11 $ -*- 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.
*------------------------------------------------------------------
* list and save commands.
* save is list with direction to file
*/
//testing=script 2006.07.17
#include "e_cardlist.h"
#include "u_lang.h"
#include "c_comand.h"
#include "globals.h"
/*--------------------------------------------------------------------------*/
namespace {
/*--------------------------------------------------------------------------*/
void list_save(CS& cmd, OMSTREAM out, CARD_LIST* scope)
{
assert(scope);
if (scope == &CARD_LIST::card_list) {
}else{untested();
}
scope->precalc_first();
//out.setfloatwidth(7);
switch (ENV::run_mode) {
case rPRE_MAIN:
unreachable();
return;
case rPRESET:
/* do nothing */
return;
case rBATCH:
case rINTERACTIVE:
case rSCRIPT:
/* keep going */
break;
}
if (!OPT::language) {
throw Exception("no language");
}else{
}
(out - IO::mstdout) << head << '\n';
if (cmd.is_end()) { /* no args: list all */
for (CARD_LIST::const_iterator ci=scope->begin();ci!=scope->end();++ci) {
OPT::language->print_item(out, *ci);
}
}else{ /* some args: be selective */
size_t arg1 = cmd.cursor();
CARD_LIST::fat_iterator ci = (cmd.match1('-'))
? CARD_LIST::fat_iterator(scope, scope->begin())
: findbranch(cmd, scope);
if (ci.is_end()) {itested();
throw Exception_CS("can't find", cmd);
}else{
}
if (cmd.match1('-')) { /* there is a dash: a range */
cmd.skip();
if (cmd.is_end()) { /* line ends with dash: all to end */
do {
OPT::language->print_item(out, *ci);
} while (++ci, !ci.is_end());
}else{
CARD_LIST::fat_iterator stop = ci;
stop = findbranch(cmd, ++stop);
if (stop.is_end()) {itested();
throw Exception_CS("can't find", cmd);
}else{
do {
OPT::language->print_item(out, *ci);
} while (ci++ != stop); // note subtle difference
}
}
}else{ /* no dash: a list */
do { /* each arg */
size_t next = cmd.cursor();
do { /* all that match this arg */
OPT::language->print_item(out, *ci);
cmd.reset(arg1);
assert(!ci.is_end());
ci = findbranch(cmd, ++ci); // next match
} while (!ci.is_end());
cmd.reset(arg1 = next);
ci = findbranch(cmd, scope); // next arg
} while (!ci.is_end());
}
}
}
/*--------------------------------------------------------------------------*/
class CMD_LIST : public CMD {
public:
void do_it(CS& cmd, CARD_LIST* Scope)override {
assert(Scope);
if (Scope == &CARD_LIST::card_list) {
}else{untested();
}
list_save(cmd, IO::mstdout, Scope);
}
} p1;
DISPATCHER<CMD>::INSTALL d1(&command_dispatcher, "list", &p1);
/*--------------------------------------------------------------------------*/
class CMD_SAVE : public CMD {
public:
void do_it(CS& cmd, CARD_LIST* Scope)override {itested();
assert(Scope);
if (Scope == &CARD_LIST::card_list) {untested();
}else{untested();
}
cmd.reset(); /* back up to beginning of input line */
OMSTREAM out; // = IO::mstdout;
list_save(cmd, *outset(cmd,&out), Scope);
}
} p2;
DISPATCHER<CMD>::INSTALL d2(&command_dispatcher, "save", &p2);
/*--------------------------------------------------------------------------*/
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// vim:ts=8:sw=2:noet:
|