summaryrefslogtreecommitdiffhomepage
path: root/mixgtk/mixgtk_mixal.c
blob: d3ce72be6d7e73ad6ca8b8bcf4b72084942f61b0 (plain)
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
/* -*-c-*- -------------- mixgtk_mixal.c :
 * Implementation of the functions declared in mixgtk_mixal.h
 * ------------------------------------------------------------------
 *  Last change: Time-stamp: "01/03/10 02:27:52 jose"
 * ------------------------------------------------------------------
 * Copyright (C) 2001 Free Software Foundation, Inc.
 *  
 * 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 2 of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *  
 */


#include <stdlib.h>
#include "mixgtk_widgets.h"
#include "mixgtk_mixal.h"

static const mix_vm_t *vm_;
static GtkCList *clist_;
static gulong lineno_;


/* initialise the mixal widgets */
gboolean
mixgtk_mixal_init (const mix_vm_t *vm)
{
  g_return_val_if_fail (vm != NULL, FALSE);
  vm_ = vm;
  clist_ = GTK_CLIST (mixgtk_widget_factory_get (MIXGTK_WIDGET_MIXAL));
  g_return_val_if_fail (clist_ != NULL, FALSE);
  return TRUE;
}

/* load the corresponding mixal file */
void
mixgtk_mixal_load_file (void)
{
  enum {ADDR_SIZE = 10, CONT_SIZE = 20};
  static gchar ADDR[ADDR_SIZE], CONT[CONT_SIZE];
  static const gchar *TEXT[3];
  
  const mix_src_file_t *file;
  
  g_assert (vm_);
  g_assert (clist_);
  
  gtk_clist_clear (clist_);
  
  file = mix_vm_get_src_file (vm_);
  if (file != NULL)
    {
      gint k;
      mix_address_t addr;

      lineno_ = mix_src_file_get_line_no (file);

      gtk_clist_freeze (clist_);
      for (k = 0; k < lineno_; ++k)
	{
	  TEXT[0] = TEXT[1] = "";
	  TEXT[2] = mix_src_file_get_line (file, k + 1);
	  addr = mix_vm_get_lineno_address (vm_, k + 1);
	  if (addr != MIX_VM_CELL_NO)
	    {
	      snprintf (ADDR, ADDR_SIZE, "%04d", mix_short_magnitude (addr));
	      mix_word_print_to_buffer (mix_vm_get_addr_contents (vm_, addr),
					CONT);
	      TEXT[0] = ADDR;
	      TEXT[1] = CONT;
	    }
	  gtk_clist_append (clist_, (gchar **)TEXT);
	}
      TEXT[0] = TEXT[1] = TEXT[2] = NULL;
      gtk_clist_append (clist_, (gchar **)TEXT);
      
      gtk_clist_thaw (clist_);
    }
  else
    lineno_ = 0;
}


/* update the widgets */
void
mixgtk_mixal_update (void)
{
  gint addr = 0;
  gint k = 0;
  gchar *addrval = NULL;
  
  g_assert (vm_);
  g_assert (clist_);
  
  addr = mix_short_magnitude (mix_vm_get_prog_count (vm_));
  while (k < lineno_)
    {
      gtk_clist_get_text (clist_, k, 0, &addrval);
      if (addrval && atoi(addrval) == addr)  break;
      ++k;
    }
  gtk_clist_select_row (clist_, k, 0);
  if (gtk_clist_row_is_visible (clist_, k) != GTK_VISIBILITY_FULL)
    gtk_clist_moveto (clist_, k, 0, 0.25, 0);
}