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