hoa.cc 24.2 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
// Copyright (C) 2011, 2012, 2014, 2015, 2016, 2017 Laboratoire de Recherche et
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Developpement de l'Epita (LRDE).
// Copyright (C) 2003, 2004  Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot 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 of the License, or
// (at your option) any later version.
//
// Spot 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, see <http://www.gnu.org/licenses/>.

#include <ostream>
#include <sstream>
25
#include <cstring>
26
#include <map>
27
28
29
30
31
32
33
34
35
#include <spot/twa/twa.hh>
#include <spot/twa/twagraph.hh>
#include <spot/twaalgos/hoa.hh>
#include <spot/twaalgos/reachiter.hh>
#include <spot/misc/escape.hh>
#include <spot/misc/bddlt.hh>
#include <spot/misc/minato.hh>
#include <spot/twa/formula2bdd.hh>
#include <spot/tl/formula.hh>
36
#include <spot/kripke/fairkripke.hh>
37
38
39
40
41

namespace spot
{
  namespace
  {
42
    struct metadata final
43
44
45
46
47
48
49
50
    {
      // Assign a number to each atomic proposition.
      typedef std::map<int, unsigned> ap_map;
      ap_map ap;
      typedef std::vector<int> vap_t;
      vap_t vap;

      std::vector<bool> common_acc;
51
      bool has_state_acc;
52
      bool is_complete;
53
      bool is_universal;
54
      bool is_colored;
55
      bool use_implicit_labels;
56
      bool use_state_labels = true;
57
      bdd all_ap;
58
59
60
61
62
63

      // Label support: the set of all conditions occurring in the
      // automaton.
      typedef std::map<bdd, std::string, bdd_less_than> sup_map;
      sup_map sup;

64
      metadata(const const_twa_graph_ptr& aut, bool implicit,
65
               bool state_labels)
66
      {
67
        check_det_and_comp(aut);
68
        use_implicit_labels = implicit && is_universal && is_complete;
69
        use_state_labels &= state_labels;
70
        number_all_ap(aut);
71
72
73
      }

      std::ostream&
74
      emit_acc(std::ostream& os, acc_cond::mark_t b)
75
      {
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
        // FIXME: We could use a cache for this.
        if (b == 0U)
          return os;
        os << " {";
        bool notfirst = false;
        for (auto v: b.sets())
          {
            if (notfirst)
              os << ' ';
            else
              notfirst = true;
            os << v;
          }
        os << '}';
        return os;
91
92
      }

93
      void check_det_and_comp(const const_twa_graph_ptr& aut)
94
      {
95
96
97
        std::string empty;

        unsigned ns = aut->num_states();
98
        bool universal = true;
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
        bool complete = true;
        bool state_acc = true;
        bool nodeadend = true;
        bool colored = aut->num_sets() >= 1;
        for (unsigned src = 0; src < ns; ++src)
          {
            bdd sum = bddfalse;
            bdd available = bddtrue;
            bool st_acc = true;
            bool notfirst = false;
            acc_cond::mark_t prev = 0U;
            bool has_succ = false;
            bdd lastcond = bddfalse;
            for (auto& t: aut->out(src))
              {
                if (has_succ)
                  use_state_labels &= lastcond == t.cond;
                else
                  lastcond = t.cond;
                if (complete)
                  sum |= t.cond;
120
                if (universal)
121
122
                  {
                    if (!bdd_implies(t.cond, available))
123
                      universal = false;
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
151
152
153
                    else
                      available -= t.cond;
                  }
                sup.insert(std::make_pair(t.cond, empty));
                if (st_acc)
                  {
                    if (notfirst && prev != t.acc)
                      {
                        st_acc = false;
                      }
                    else
                      {
                        notfirst = true;
                        prev = t.acc;
                      }
                  }
                if (colored)
                  {
                    auto a = t.acc;
                    if (!a || a.remove_some(1))
                      colored = false;
                  }
                has_succ = true;
              }
            nodeadend &= has_succ;
            if (complete)
              complete &= sum == bddtrue;
            common_acc.push_back(st_acc);
            state_acc &= st_acc;
          }
154
        is_universal = universal;
155
156
157
158
159
160
        is_complete = complete;
        has_state_acc = state_acc;
        // If the automaton has state-based acceptance and contain
        // some states without successors do not declare it as
        // colored.
        is_colored = colored && (!has_state_acc || nodeadend);
161
        // If the automaton declares that it is universal or
162
        // state-based, make sure that it really is.
163
        if (aut->prop_universal().is_true() && !universal)
164
165
          throw std::runtime_error("print_hoa(): automaton is not universal"
                                   " but prop_universal()==true");
166
        if (aut->prop_universal().is_false() && universal)
167
168
169
170
171
172
173
174
175
176
177
178
          throw std::runtime_error("print_hoa(): automaton is universal"
                                   " despite prop_universal()==false");
        if (aut->prop_complete().is_true() && !complete)
          throw std::runtime_error("print_hoa(): automaton is not complete"
                                   " but prop_complete()==true");
        if (aut->prop_complete().is_false() && complete)
          throw std::runtime_error("print_hoa(): automaton is complete"
                                   " but prop_complete()==false");
        if (aut->prop_state_acc() && !state_acc)
          throw std::runtime_error("print_hoa(): automaton has "
                                   "transition-based acceptance despite"
                                   " prop_state_acc()==true");
179
180
      }

181
      void number_all_ap(const const_twa_graph_ptr& aut)
182
      {
183
184
185
186
187
188
        // Make sure that the automaton uses only atomic propositions
        // that have been registered via twa::register_ap() or some
        // variant.  If that is not the case, it is a bug that should
        // be fixed in the function creating the automaton.  Since
        // that function could be written by the user, throw an
        // exception rather than using an assert().
189
190
191
        bdd all = bddtrue;
        for (auto& i: sup)
          all &= bdd_support(i.first);
192
193
194
195
196
        all_ap = aut->ap_vars();
        if (bdd_exist(all, all_ap) != bddtrue)
          throw std::runtime_error("print_hoa(): automaton uses "
                                   "unregistered atomic propositions");
        all = all_ap;
197
198
199
200
201
202

        while (all != bddtrue)
          {
            int v = bdd_var(all);
            all = bdd_high(all);
            ap.insert(std::make_pair(v, vap.size()));
203
            vap.emplace_back(v);
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
          }

        if (use_implicit_labels)
          return;

        for (auto& i: sup)
          {
            bdd cond = i.first;
            if (cond == bddtrue)
              {
                i.second = "t";
                continue;
              }
            if (cond == bddfalse)
              {
                i.second = "f";
                continue;
              }
            std::ostringstream s;
            bool notfirstor = false;

            minato_isop isop(cond);
            bdd cube;
            while ((cube = isop.next()) != bddfalse)
              {
                if (notfirstor)
                  s << " | ";
                bool notfirstand = false;
                while (cube != bddtrue)
                  {
                    if (notfirstand)
                      s << '&';
                    else
                      notfirstand = true;
                    bdd h = bdd_high(cube);
                    if (h == bddfalse)
                      {
                        s << '!' << ap[bdd_var(cube)];
                        cube = bdd_low(cube);
                      }
                    else
                      {
                        s << ap[bdd_var(cube)];
                        cube = h;
                      }
                  }
                notfirstor = true;
              }
            i.second = s.str();
          }
254
255
256
257
258
      }
    };

  }

259
260
  enum hoa_acceptance
    {
261
262
263
264
      Hoa_Acceptance_States,        /// state-based acceptance if
                                /// (globally) possible
                                /// transition-based acceptance
                                /// otherwise.
265
266
267
      Hoa_Acceptance_Transitions, /// transition-based acceptance globally
      Hoa_Acceptance_Mixed    /// mix state-based and transition-based
    };
268

269
  static std::ostream&
270
  print_hoa(std::ostream& os,
271
272
                const const_twa_graph_ptr& aut,
                const char* opt)
273
  {
274
275
276
    bool newline = true;
    hoa_acceptance acceptance = Hoa_Acceptance_States;
    bool implicit_labels = false;
277
    bool verbose = false;
278
    bool state_labels = false;
279
    bool v1_1 = false;
280
281
282

    if (opt)
      while (*opt)
283
284
285
        {
          switch (char c = *opt++)
            {
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
            case '1':
              if (opt[0] == '.' && opt[1] == '1')
                {
                  v1_1 = true;
                  opt += 2;
                }
              else if (opt[0] == '.' && opt[1] == '0')
                {
                  v1_1 = false;
                  opt += 2;
                }
              else
                {
                  v1_1 = false;
                }
              break;
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
            case 'i':
              implicit_labels = true;
              break;
            case 'k':
              state_labels = true;
              break;
            case 'l':
              newline = false;
              break;
            case 'm':
              acceptance = Hoa_Acceptance_Mixed;
              break;
            case 's':
              acceptance = Hoa_Acceptance_States;
              break;
            case 't':
              acceptance = Hoa_Acceptance_Transitions;
              break;
            case 'v':
              verbose = true;
              break;
            default:
              throw std::runtime_error
                (std::string("unknown option for print_hoa(): ") + c);
            }
        }
328

329
    metadata md(aut, implicit_labels, state_labels);
330

331
    if (acceptance == Hoa_Acceptance_States && !md.has_state_acc)
332
      acceptance = Hoa_Acceptance_Transitions;
333

334
335
336
337
338
339
340
341
342
343
344
345
346
    auto print_dst = [&os, &aut](unsigned dst)
      {
        bool notfirst = false;
        for (unsigned d: aut->univ_dests(dst))
          {
            if (notfirst)
              os << '&';
            else
              notfirst = true;
            os << d;
          }
      };

347
    unsigned num_states = aut->num_states();
348
    unsigned init = aut->get_init_state_number();
349
350

    const char nl = newline ? '\n' : ' ';
351
    os << (v1_1 ? "HOA: v1.1" : "HOA: v1") << nl;
352
    auto n = aut->get_named_prop<std::string>("automaton-name");
353
    if (n)
354
      escape_str(os << "name: \"", *n) << '"' << nl;
355
    unsigned nap = md.vap.size();
356
    os << "States: " << num_states << nl
357
358
359
       << "Start: ";
    print_dst(init);
    os << nl
360
       << "AP: " << nap;
361
    auto d = aut->get_dict();
362
    for (auto& i: md.vap)
363
      escape_str(os << " \"", d->bdd_map[i].f.ap_name()) << '"';
364
    os << nl;
365

366
    unsigned num_acc = aut->num_sets();
367
    acc_cond::acc_code acc_c = aut->acc().get_acceptance();
368
    if (aut->acc().is_generalized_buchi())
369
      {
370
371
372
373
374
375
376
        if (aut->acc().is_all())
          os << "acc-name: all";
        else if (aut->acc().is_buchi())
          os << "acc-name: Buchi";
        else
          os << "acc-name: generalized-Buchi " << num_acc;
        os << nl;
377
      }
378
379
    else if (aut->acc().is_generalized_co_buchi())
      {
380
381
382
383
384
385
386
        if (aut->acc().is_none())
          os << "acc-name: none";
        else if (aut->acc().is_co_buchi())
          os << "acc-name: co-Buchi";
        else
          os << "acc-name: generalized-co-Buchi " << num_acc;
        os << nl;
387
388
389
      }
    else
      {
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
        int r = aut->acc().is_rabin();
        assert(r != 0);
        if (r > 0)
          {
            os << "acc-name: Rabin " << r << nl;
            // Force the acceptance to remove any duplicate sets, and
            // make sure it is correctly ordered.
            acc_c = acc_cond::acc_code::rabin(r);
          }
        else
          {
            r = aut->acc().is_streett();
            assert(r != 0);
            if (r > 0)
              {
                os << "acc-name: Streett " << r << nl;
                // Force the acceptance to remove any duplicate sets, and
                // make sure it is correctly ordered.
                acc_c = acc_cond::acc_code::streett(r);
              }
            else
              {
                std::vector<unsigned> pairs;
                if (aut->acc().is_generalized_rabin(pairs))
                  {
                    os << "acc-name: generalized-Rabin " << pairs.size();
                    for (auto p: pairs)
                      os << ' ' << p;
                    os << nl;
                    // Force the acceptance to remove any duplicate
                    // sets, and make sure it is correctly ordered.
                    acc_c = acc_cond::acc_code::generalized_rabin(pairs.begin(),
                                                                  pairs.end());
                  }
                else
                  {
                    bool max = false;
                    bool odd = false;
                    if (aut->acc().is_parity(max, odd))
                      os << "acc-name: parity "
                         << (max ? "max " : "min ")
                         << (odd ? "odd " : "even ")
                         << num_acc << nl;
                  }
              }
          }
436
      }
437
    os << "Acceptance: " << num_acc << ' ';
438
    os << acc_c;
439
    os << nl;
440
    os << "properties:";
441
442
443
444
445
    // Make sure the property line is not too large,
    // otherwise our test cases do not fit in 80 columns...
    unsigned prop_len = 60;
    auto prop = [&](const char* str)
      {
446
447
448
449
450
451
452
453
454
455
456
        if (newline)
          {
            auto l = strlen(str);
            if (prop_len < l)
              {
                prop_len = 60;
                os << "\nproperties:";
              }
            prop_len -= l;
          }
        os << str;
457
      };
458
    implicit_labels = md.use_implicit_labels;
459
    state_labels = md.use_state_labels;
460
    if (implicit_labels)
461
      prop(" implicit-labels");
462
463
    else if (state_labels)
      prop(" state-labels explicit-labels");
464
    else
465
      prop(" trans-labels explicit-labels");
466
    if (acceptance == Hoa_Acceptance_States)
467
      prop(" state-acc");
468
    else if (acceptance == Hoa_Acceptance_Transitions)
469
      prop(" trans-acc");
470
471
    if (md.is_colored)
      prop(" colored");
472
473
    else if (verbose && v1_1)
      prop(" !colored");
474
    if (md.is_complete)
475
      prop(" complete");
476
477
    else if (v1_1)
      prop(" !complete");
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
    // The definition of "deterministic" was changed between HOA v1
    // (were it meant "universal") and HOA v1.1 were it means
    // ("universal" and "existential").
    if (!v1_1)
      {
        if (md.is_universal)
          prop(" deterministic");
        // It's probable that nobody cares about the "no-univ-branch"
        // property.  The "univ-branch" property seems more important to
        // announce that the automaton might not be parsable by tools that
        // do not support alternating automata.
        if (!aut->is_existential())
          {
            prop(" univ-branch");
          }
        else if (verbose)
          {
            if (v1_1)
              prop(" !univ-branch");
            else
              prop(" no-univ-branch");
          }
      }
    else
      {
        if (md.is_universal && aut->is_existential())
          {
            prop(" deterministic");
            if (verbose)
              prop(" !univ-branch !exist-branch");
          }
        else
          {
            prop(" !deterministic");
            if (!aut->is_existential())
              prop(" univ-branch");
            else if (verbose)
              prop(" !univ-branch");
            if (!md.is_universal)
              prop(" exist-branch");
            else if (verbose)
              prop(" !exist-branch");
          }
      }
522
523
524
525
526
    // Deterministic automata are also unambiguous, so writing both
    // properties seems redundant.  People working on unambiguous
    // automata are usually concerned about non-deterministic
    // unambiguous automata.  So do not mention "unambiguous"
    // in the case of deterministic automata.
527
    if (aut->prop_unambiguous() && (verbose || !md.is_universal))
528
      prop(" unambiguous");
529
530
    else if (v1_1 && !aut->prop_unambiguous())
      prop(" !unambiguous");
531
    if (aut->prop_semi_deterministic() && (verbose || !md.is_universal))
532
533
534
      prop(" semi-deterministic");
    else if (v1_1 && !aut->prop_semi_deterministic())
      prop(" !semi-deterministic");
535
    if (aut->prop_stutter_invariant())
536
      prop(" stutter-invariant");
537
    if (!aut->prop_stutter_invariant())
538
539
540
541
542
543
      {
        if (v1_1)
          prop(" !stutter-invariant");
        else
          prop(" stutter-sensitive");
      }
544
545
    if (aut->prop_terminal())
      prop(" terminal");
546
547
548
549
    if (aut->prop_very_weak() && (verbose || aut->prop_terminal() != true))
      prop(" very-weak");
    if (aut->prop_weak() && (verbose || (aut->prop_terminal() != true &&
                                         aut->prop_very_weak() != true)))
550
      prop(" weak");
551
    if (aut->prop_inherently_weak() && (verbose || aut->prop_weak() != true))
552
      prop(" inherently-weak");
553
    if (v1_1 && !aut->prop_terminal() && (verbose || aut->prop_weak() != false))
554
      prop(" !terminal");
555
556
557
    if (v1_1 && !aut->prop_very_weak() && (verbose
                                           || aut->prop_weak() != false))
      prop(" !very-weak");
558
559
    if (v1_1 && !aut->prop_weak() && (verbose ||
                                      aut->prop_inherently_weak() != false))
560
561
562
      prop(" !weak");
    if (v1_1 && !aut->prop_inherently_weak())
      prop(" !inherently-weak");
563
    os << nl;
564

565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
    // highlighted states and edges are only output in the 1.1 format,
    // because we use a dot in the header name.
    if (v1_1)
      {
        if (auto hstates = aut->get_named_prop
            <std::map<unsigned, unsigned>>("highlight-states"))
          {
            os << "spot.highlight.states:";
            for (auto& p: *hstates)
              os << ' ' << p.first << ' ' << p.second;
            os << nl;
          }
        if (auto hedges = aut->get_named_prop
            <std::map<unsigned, unsigned>>("highlight-edges"))
          {
580
581
582
583
584
585
586
587
588
589
590
591
592
593
            // Numbering edges is a delicate process.  The
            // "highlight-edges" property uses edges numbers that are
            // indices in the "edges" vector.  However these edges
            // need not be sorted.  When edges are output in HOA, they
            // are output with increasing source state number, and the
            // edges number expected in the HOA file should use that
            // order.  So we need to make a first pass on the
            // automaton to number all edges as they will be output.
            unsigned maxedge = aut->edge_vector().size();
            std::vector<unsigned> renum(maxedge);
            unsigned edge = 0;
            for (unsigned i = 0; i < num_states; ++i)
              for (auto& t: aut->out(i))
                renum[aut->get_graph().index_of_edge(t)] = ++edge;
594
595
            os << "spot.highlight.edges:";
            for (auto& p: *hedges)
596
597
              if (p.first < maxedge) // highlighted edges could come from user
                os << ' ' << renum[p.first] << ' ' << p.second;
598
599
600
601
            os << nl;
          }
      }

602
603
604
605
606
607
    // If we want to output implicit labels, we have to
    // fill a vector with all destinations in order.
    std::vector<unsigned> out;
    std::vector<acc_cond::mark_t> outm;
    if (implicit_labels)
      {
608
609
610
        out.resize(1UL << nap);
        if (acceptance != Hoa_Acceptance_States)
          outm.resize(1UL << nap);
611
612
      }

613
    os << "--BODY--" << nl;
614

615
    auto sn = aut->get_named_prop<std::vector<std::string>>("state-names");
616
617
    for (unsigned i = 0; i < num_states; ++i)
      {
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
        hoa_acceptance this_acc = acceptance;
        if (this_acc == Hoa_Acceptance_Mixed)
          this_acc = (md.common_acc[i] ?
                      Hoa_Acceptance_States : Hoa_Acceptance_Transitions);

        os << "State: ";
        if (state_labels)
          {
            bool output = false;
            for (auto& t: aut->out(i))
              {
                os << '[' << md.sup[t.cond] << "] ";
                output = true;
                break;
              }
            if (!output)
              os << "[f] ";
          }
        os << i;
        if (sn && i < sn->size() && !(*sn)[i].empty())
          os << " \"" << (*sn)[i] << '"';
        if (this_acc == Hoa_Acceptance_States)
          {
            acc_cond::mark_t acc = 0U;
            for (auto& t: aut->out(i))
              {
                acc = t.acc;
                break;
              }
            md.emit_acc(os, acc);
          }
        os << nl;

        if (!implicit_labels && !state_labels)
          {

            for (auto& t: aut->out(i))
              {
656
657
                os << '[' << md.sup[t.cond] << "] ";
                print_dst(t.dst);
658
659
660
661
662
663
664
665
666
667
                if (this_acc == Hoa_Acceptance_Transitions)
                  md.emit_acc(os, t.acc);
                os << nl;
              }
          }
        else if (state_labels)
          {
            unsigned n = 0;
            for (auto& t: aut->out(i))
              {
668
                print_dst(t.dst);
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
                if (this_acc == Hoa_Acceptance_Transitions)
                  {
                    md.emit_acc(os, t.acc);
                    os << nl;
                  }
                else
                  {
                    ++n;
                    os << (((n & 15) && t.next_succ) ? ' ' : nl);
                  }
              }
          }
        else
          {
            for (auto& t: aut->out(i))
              {
                bdd cond = t.cond;
                while (cond != bddfalse)
                  {
                    bdd one = bdd_satoneset(cond, md.all_ap, bddfalse);
                    cond -= one;
                    unsigned level = 1;
                    unsigned pos = 0U;
                    while (one != bddtrue)
                      {
                        bdd h = bdd_high(one);
                        if (h == bddfalse)
                          {
                            one = bdd_low(one);
                          }
                        else
                          {
                            pos |= level;
                            one = h;
                          }
                        level <<= 1;
                      }
                    out[pos] = t.dst;
                    if (this_acc != Hoa_Acceptance_States)
                      outm[pos] = t.acc;
                  }
              }
            unsigned n = out.size();
            for (unsigned i = 0; i < n;)
              {
714
                print_dst(out[i]);
715
716
717
718
719
720
721
722
723
724
725
726
                if (this_acc != Hoa_Acceptance_States)
                  {
                    md.emit_acc(os, outm[i]) << nl;
                    ++i;
                  }
                else
                  {
                    ++i;
                    os << (((i & 15) && i < n) ? ' ' : nl);
                  }
              }
          }
727
      }
728
    os << "--END--";                // No newline.  Let the caller decide.
729
730
731
732
    return os;
  }

  std::ostream&
733
  print_hoa(std::ostream& os,
734
735
            const const_twa_ptr& aut,
            const char* opt)
736
  {
737

738
    auto a = std::dynamic_pointer_cast<const twa_graph>(aut);
739
    if (!a)
740
      a = make_twa_graph(aut, twa::prop_set::all());
741

742
743
    // for Kripke structures, automatically append "k" to the options.
    char* tmpopt = nullptr;
744
    if (std::dynamic_pointer_cast<const fair_kripke>(aut))
745
      {
746
747
748
749
750
751
        unsigned n = opt ? strlen(opt) : 0;
        tmpopt = new char[n + 2];
        if (opt)
          strcpy(tmpopt, opt);
        tmpopt[n] = 'k';
        tmpopt[n + 1] = 0;
752
753
754
755
      }
    print_hoa(os, a, tmpopt ? tmpopt : opt);
    delete[] tmpopt;
    return os;
756
757
758
  }

}