File: lln.c

package info (click to toggle)
lletters 0.1.95-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,152 kB
  • ctags: 502
  • sloc: sh: 9,985; ansic: 3,225; makefile: 230; sed: 93; perl: 50
file content (279 lines) | stat: -rw-r--r-- 7,962 bytes parent folder | download
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/* 
 *  Linux Letters and Numbers
 *  By Kirk Ismay, <captain@netidea.com> 
 * 
 *  Based on my daughters favorite game, Larry's Letters and Numbers.
 *  This is a Linux replacement, as the original was written for Windows. 
 *  I have made several improvements too.*/

#include "lletters.h"
#include <string.h>

char * lln_sound_dir;
/* Change by Lalo Martins, Feb 27 1999: */
char * lln_image_dir;
/* end change by Lalo Martins, Feb 27 1999 */

int lln_ignore = FALSE; /* Paul Keinzle */
/* Change by Gopal Narayanan, Apr. 6, 2001 */
int ll_sound = 1;
/* end change by Gopal Narayanan */

void
delete_event (GtkWidget * widget, GdkEvent * event, gpointer * data)
{
  gdk_key_repeat_restore ();
  gtk_main_quit ();
}

int
retransmit_press (GtkWidget * widget, GdkEventButton * event, gpointer * data)
{
  if ((event->button == 2) || (event->button == 3)) {
     /* retransmit as if button 1 did it */
    gtk_button_pressed(GTK_BUTTON(widget));
    return TRUE; /* We're done, don't do any more */
  } else {
    return FALSE; /* Don't retransmit button 1 messages */
  }
}

int
retransmit_release (GtkWidget * widget, GdkEventButton * event, gpointer * data)
{
  if ( (event->button == 2) || (event->button == 3)) {
     /* retransmit as if button 1 did it */
    gtk_button_released(GTK_BUTTON(widget));
    return TRUE; /* We're done, don't do any more */
  } else {
    return FALSE; /* Don't retransmit button 1  messages */
  }
}

int
get_keystroke (GtkWidget * widget, GdkEventKey * event, gpointer * data)
{
  gint key = event->keyval;
  gint esc_key = 65307;
  gint enter_key = 65293;

  if (lln_ignore) return TRUE;

  if ((int) data == 1)
    {//Close popup window first if any key is pressed
      lln_ignore = FALSE;
      gtk_widget_destroy (widget);
    }

  if (key == esc_key) { 
    gdk_key_repeat_restore ();
    gtk_main_quit();
  }
  if (isascii(key)) {
    if (isalpha(key)) {
      lln_show_letter (widget, (gpointer) toupper(key));
    }
    else if (isdigit(key) && key != '0') { 
      lln_show_number (widget, (gpointer) (key-48));
    }
  }

  return TRUE;
}

int
main (int argc, char *argv[])
{
  gint x, z, i;
  gchar buf[40];
  /* Change by Lalo Martins, Feb 27 1999: */
  gchar *lang, *rc_file;
  struct stat statbuf;
  /* end change by Lalo Martins, Feb 27 1999 */
  GtkWidget *window;
  GtkWidget *button;
  GtkWidget *label;
  GtkWidget *box1, *box2, *box3, *box4;
  GtkWidget *vbox;

/* Changes by Rudy Godoy, Jul 20 2004 */
  setlocale(LC_MESSAGES, "");
  textdomain("lletters");
  bind_textdomain_codeset ("lletters", "ISO-8859-1");
/* End changes Rudy Godoy, Jul 20 2004 */

/* Begin change JPV - 1999/03/06 */
//  textdomain("linux-letters-and-numbers");
/* End change JPV - 1999/03/06 */

  gtk_init (&argc, &argv);
  gdk_imlib_init(); 
  gdk_key_repeat_disable ();

  /* Begin change Gopal Narayanan Apr 6 2001; */
  if (argc > 2) {
    fprintf(stderr, _("Usage: %s [-d]\n"), argv[0]);
    return 1;
  }
  if (argc == 2) {
    if (strcmp(argv[1],"-d") == 0) {
      ll_sound = 0;
      printf(_("Disabling sound\n"));
    }
  }

  /* End change by Gopal Narayanan */

  /* Change by Lalo Martins, Feb 27 1999: */
  lang = strtok(getenv ("LANG"), "_");
//  lang = strtok(lang, "_");
  if (lang)
  {
/* Begin change JPV - 1999/03/06 */
    printf (_("Found LANG=`%s'\n"), lang);
/* End change JPV - 1999/03/06 */
    asprintf (&lln_image_dir, "%s/lletters/%s/images/", DATADIR, lang);
    /* Set soundfile directory. Kirk Ismay */
    asprintf (&lln_sound_dir, "%s/lletters/%s/sounds/", DATADIR, lang);
    if (stat (lln_image_dir, &statbuf)) {
      /* if $LANG-specific dir doesn't exist... */
      asprintf (&lln_image_dir, "%s/lletters/images/", DATADIR);
      /* Set soundfile directory. Kirk Ismay */
      asprintf (&lln_sound_dir, "%s/lletters/sounds/", DATADIR);
    }
  }
  else {
    asprintf (&lln_image_dir, "%s/lletters/images/", DATADIR);
    /* Set soundfile directory. Kirk Ismay */
    asprintf (&lln_sound_dir, "%s/lletters/sounds/", DATADIR);
  }
  /* Begin change JPV - 1999/03/06 */
  printf (_("Using `%s' for image dir\n"), lln_image_dir);
  /* End change JPV - 1999/03/06 */
  /* end change by Lalo Martins, Feb 27 1999 */
#ifdef SOUND
  if (ll_sound) {
    printf (_("Using `%s' for sound dir\n"), lln_sound_dir);
  }
#else
  printf (_("Sound disabled"));
#endif

  /* Load and parse the Global RC file */
  asprintf (&rc_file, "%s/lletters/lln.rc", DATADIR);
  gtk_rc_parse (rc_file);

  /* Load and parse the user's RC file */
  asprintf (&rc_file, "%s/.llnrc", g_get_home_dir());

  if (lln_check_file (rc_file) == TRUE) {
    gtk_rc_parse (rc_file);
  }

  /* create a new window */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_name (window, "main_window");
  gtk_window_set_default_size (GTK_WINDOW (window), MAIN_X, MAIN_Y);

/* Begin change JPV - 1999/03/06 */
  gtk_window_set_title (GTK_WINDOW (window), _("Linux Letters and Numbers"));
/* End change JPV - 1999/03/06 */
  gtk_window_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);

  gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
		      GTK_SIGNAL_FUNC (get_keystroke), (gpointer) 0);
  gtk_signal_connect (GTK_OBJECT (window), "key_release_event",
		      GTK_SIGNAL_FUNC (get_keystroke), (gpointer) 0);
  gtk_signal_connect (GTK_OBJECT (window), "delete_event",
		      GTK_SIGNAL_FUNC (delete_event), NULL);

  /* sets the border width of the window. */
  gtk_container_border_width (GTK_CONTAINER (window), 25);

  /* we create boxes to pack widgets into */
  vbox = gtk_vbox_new (FALSE, 0);
  box1 = gtk_hbox_new (TRUE, 0);
  box2 = gtk_hbox_new (TRUE, 0);
  box3 = gtk_hbox_new (TRUE, 0);
  box4 = gtk_hbox_new (TRUE, 0);

  /* put the box into the main window. */
  gtk_container_add (GTK_CONTAINER (window), vbox);
  /* put the horizontal boxes into the vertical one */
  gtk_box_pack_start (GTK_BOX (vbox), box1, TRUE, TRUE, 5);
  gtk_box_pack_start (GTK_BOX (vbox), box2, TRUE, TRUE, 5);
  gtk_box_pack_start (GTK_BOX (vbox), box3, TRUE, TRUE, 5);
  gtk_box_pack_start (GTK_BOX (vbox), box4, TRUE, TRUE, 5);
  /* Make a row of numbers */
  i = 1;
  while (i <= 9)
    {
      button = gtk_button_new ();
 
      sprintf (buf, "%d", i);
      label = gtk_label_new (buf);
      gtk_widget_set_name (label, "main_label");

      gtk_container_add (GTK_CONTAINER (button), label);
 
      gtk_box_pack_start (GTK_BOX (box1), button, TRUE, TRUE, 5);

      /* Now when the button is clicked, we call the "show_number" function
       *        * with a pointer to the letter as it's argument */
      gtk_signal_connect (GTK_OBJECT (button), "button_press_event",
			  GTK_SIGNAL_FUNC (retransmit_press), button);
      gtk_signal_connect (GTK_OBJECT (button), "button_release_event",
			  GTK_SIGNAL_FUNC (retransmit_release), button);
      gtk_signal_connect (GTK_OBJECT (button), "clicked",
			  GTK_SIGNAL_FUNC (lln_show_number), (gpointer) i);
      i++;
    }

  /* Make 3 rows of letters */
  x = 'A';
  z = 'Z';
  while (x <= z)
    {
      sprintf (buf, "%c", x);


      /* creates a new button with a label. */
      button = gtk_button_new ();

      label = gtk_label_new (buf);
      gtk_widget_set_name  (label, "main_label");


      gtk_container_add (GTK_CONTAINER (button), label);
      gtk_signal_connect (GTK_OBJECT (button), "button_press_event",
			  GTK_SIGNAL_FUNC (retransmit_press), button);
      gtk_signal_connect (GTK_OBJECT (button), "button_release_event",
			  GTK_SIGNAL_FUNC (retransmit_release), button);
      gtk_signal_connect (GTK_OBJECT (button), "clicked",
			  GTK_SIGNAL_FUNC (lln_show_letter), (gpointer) x);

      if (x <= 'I')
	gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 5);
      else if (x <= 'Q')
	gtk_box_pack_start (GTK_BOX (box3), button, TRUE, TRUE, 5);
      else
	gtk_box_pack_start (GTK_BOX (box4), button, TRUE, TRUE, 5);

      x++;
    }

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}