1*c42dbd0eSchristos /* Copyright (C) 2021 Free Software Foundation, Inc.
2*c42dbd0eSchristos Contributed by Oracle.
3*c42dbd0eSchristos
4*c42dbd0eSchristos This file is part of GNU Binutils.
5*c42dbd0eSchristos
6*c42dbd0eSchristos This program is free software; you can redistribute it and/or modify
7*c42dbd0eSchristos it under the terms of the GNU General Public License as published by
8*c42dbd0eSchristos the Free Software Foundation; either version 3, or (at your option)
9*c42dbd0eSchristos any later version.
10*c42dbd0eSchristos
11*c42dbd0eSchristos This program is distributed in the hope that it will be useful,
12*c42dbd0eSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of
13*c42dbd0eSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*c42dbd0eSchristos GNU General Public License for more details.
15*c42dbd0eSchristos
16*c42dbd0eSchristos You should have received a copy of the GNU General Public License
17*c42dbd0eSchristos along with this program; if not, write to the Free Software
18*c42dbd0eSchristos Foundation, 51 Franklin Street - Fifth Floor, Boston,
19*c42dbd0eSchristos MA 02110-1301, USA. */
20*c42dbd0eSchristos
21*c42dbd0eSchristos #include "config.h"
22*c42dbd0eSchristos #include <stdio.h>
23*c42dbd0eSchristos
24*c42dbd0eSchristos #include "PreviewExp.h"
25*c42dbd0eSchristos #include "Data_window.h"
26*c42dbd0eSchristos #include "DbeSession.h"
27*c42dbd0eSchristos #include "Emsg.h"
28*c42dbd0eSchristos #include "Print.h"
29*c42dbd0eSchristos #include "i18n.h"
30*c42dbd0eSchristos
PreviewExp()31*c42dbd0eSchristos PreviewExp::PreviewExp (): Experiment () { }
32*c42dbd0eSchristos
~PreviewExp()33*c42dbd0eSchristos PreviewExp::~PreviewExp () { }//~PreviewExp
34*c42dbd0eSchristos
35*c42dbd0eSchristos Experiment::Exp_status
experiment_open(char * path)36*c42dbd0eSchristos PreviewExp::experiment_open (char *path)
37*c42dbd0eSchristos {
38*c42dbd0eSchristos // Find experiment directory
39*c42dbd0eSchristos if ((status = find_expdir (path)) != SUCCESS)
40*c42dbd0eSchristos {
41*c42dbd0eSchristos size_t len = strlen (path);
42*c42dbd0eSchristos is_group = ((len > 4) && !strcmp (&path[len - 4], NTXT (".erg")));
43*c42dbd0eSchristos return status;
44*c42dbd0eSchristos }
45*c42dbd0eSchristos else
46*c42dbd0eSchristos is_group = 0;
47*c42dbd0eSchristos
48*c42dbd0eSchristos read_log_file ();
49*c42dbd0eSchristos if (status == FAILURE)
50*c42dbd0eSchristos return status;
51*c42dbd0eSchristos
52*c42dbd0eSchristos if (status == INCOMPLETE && resume_ts != MAX_TIME)
53*c42dbd0eSchristos // experiment is incomplete and "resumed" (non-paused)
54*c42dbd0eSchristos // PreviewExp does not process all the packets, therefore...
55*c42dbd0eSchristos // ... last_event does not reflect reality
56*c42dbd0eSchristos // ... we don't know the duration or the end.
57*c42dbd0eSchristos last_event = ZERO_TIME; // mark last_event as uninitialized
58*c42dbd0eSchristos
59*c42dbd0eSchristos read_notes_file ();
60*c42dbd0eSchristos return status;
61*c42dbd0eSchristos }
62*c42dbd0eSchristos
63*c42dbd0eSchristos Vector<char*> *
preview_info()64*c42dbd0eSchristos PreviewExp::preview_info ()
65*c42dbd0eSchristos {
66*c42dbd0eSchristos Vector<char*> *info = new Vector<char*>;
67*c42dbd0eSchristos if (is_group)
68*c42dbd0eSchristos info->append (GTXT ("Experiment Group"));
69*c42dbd0eSchristos else
70*c42dbd0eSchristos info->append (GTXT ("Experiment"));
71*c42dbd0eSchristos info->append (expt_name);
72*c42dbd0eSchristos
73*c42dbd0eSchristos if (status == FAILURE /* != SUCCESS */)
74*c42dbd0eSchristos {
75*c42dbd0eSchristos if (is_group)
76*c42dbd0eSchristos {
77*c42dbd0eSchristos Vector<char*> *grp_list = dbeSession->get_group_or_expt (expt_name);
78*c42dbd0eSchristos for (int i = 0, grp_sz = grp_list->size (); i < grp_sz; i++)
79*c42dbd0eSchristos {
80*c42dbd0eSchristos char *nm = grp_list->fetch (i);
81*c42dbd0eSchristos char *str = dbe_sprintf (GTXT ("Exp.#%d"), i + 1);
82*c42dbd0eSchristos info->append (str);
83*c42dbd0eSchristos info->append (nm);
84*c42dbd0eSchristos }
85*c42dbd0eSchristos delete grp_list;
86*c42dbd0eSchristos }
87*c42dbd0eSchristos else
88*c42dbd0eSchristos {
89*c42dbd0eSchristos info->append (GTXT ("Error message"));
90*c42dbd0eSchristos info->append (mqueue_str (errorq, GTXT ("No errors\n")));
91*c42dbd0eSchristos }
92*c42dbd0eSchristos return info;
93*c42dbd0eSchristos }
94*c42dbd0eSchristos info->append (GTXT ("Experiment header"));
95*c42dbd0eSchristos info->append (mqueue_str (commentq, GTXT ("Empty header\n")));
96*c42dbd0eSchristos info->append (GTXT ("Error message"));
97*c42dbd0eSchristos info->append (mqueue_str (errorq, GTXT ("No errors\n")));
98*c42dbd0eSchristos info->append (GTXT ("Warning message"));
99*c42dbd0eSchristos info->append (mqueue_str (warnq, GTXT ("No warnings\n")));
100*c42dbd0eSchristos info->append (GTXT ("Notes"));
101*c42dbd0eSchristos info->append (mqueue_str (notesq, GTXT ("\n")));
102*c42dbd0eSchristos return info;
103*c42dbd0eSchristos }
104*c42dbd0eSchristos
105*c42dbd0eSchristos char *
mqueue_str(Emsgqueue * msgqueue,char * null_str)106*c42dbd0eSchristos PreviewExp::mqueue_str (Emsgqueue *msgqueue, char *null_str)
107*c42dbd0eSchristos {
108*c42dbd0eSchristos char *mesgs = pr_mesgs (msgqueue->fetch (), null_str, "");
109*c42dbd0eSchristos char *last = mesgs + strlen (mesgs) - 1;
110*c42dbd0eSchristos if (*last == '\n')
111*c42dbd0eSchristos *last = '\0';
112*c42dbd0eSchristos return mesgs;
113*c42dbd0eSchristos }
114