File: process_input.c

package info (click to toggle)
grpn 1.4.1-1.1
  • links: PTS
  • area: main
  • in suites: bookworm, sid
  • size: 2,020 kB
  • sloc: ansic: 6,616; makefile: 74
file content (221 lines) | stat: -rw-r--r-- 5,251 bytes parent folder | download | duplicates (2)
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
/*

Copyright (C) 2002  Paul Wilkins

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.

*/
/* process_input.c  by Paul Wilkins 3/21/97 */

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>

#include "process_input.h"
#include "funcs.h"
#include "lcd.h"
#include "editor.h"
#include "error.h"
#include "number.h"
#include <locale.h>



void processInput(int ksym, int isCtrl, char bb, char chr){
   int keysym;
   char c;

   gchar* cliptext; 
   GtkClipboard* clipboard;
   Number *num;
   


   if(ksym == 0){
      switch(chr){
         case ' ':
         case '\n':
         case '\t':
	    keysym = GDK_space;
	    break;
         case '+':
	    keysym = GDK_plus;
	    break;
         case '-':
	    keysym = GDK_minus;
	    break;
         case '/':
	    keysym = GDK_slash;
	    break;
         case '*':
	    keysym = GDK_asterisk;
	    break;
         case '^':
	    keysym = GDK_asciicircum;
	    break;
         default:
            keysym = GDK_4;  /* just pick one */
            break;
      }
   } else {
      keysym = ksym;
   }

   if(isCtrl){
      switch(keysym){
         case GDK_c:      /*copy to clipboard*/
                if(NULL == (num = getStackEle(0))) break;
                if(NULL == (cliptext = printNumber(num))) break;

             	clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
             	gtk_clipboard_set_text (clipboard, cliptext, -1);
             	gtk_clipboard_store(clipboard);
                free(cliptext);
            break;
      }

      /* ignore the ctrl key */
      return;
   }


   /* this will clear any error string */
   resetError();

   /* process the line */
   switch(keysym){

      case GDK_space:     /* if there is something in the buffer, then */
      case GDK_KP_Space:  /* push it onto the stack, else duplicate the */
      case GDK_Return:    /* element on the bottom of the stack */
      case GDK_Tab:
      case GDK_KP_Tab:
      case GDK_KP_Enter:
      case GDK_KP_Insert:
      case GDK_Linefeed:
         PushStack();
         break;

      case GDK_Begin:      /* used when editing the entry buffer */
      case GDK_Home:
      case GDK_Up:
      case GDK_KP_Home:
      case GDK_KP_Up:
         homeEditor();
         break;

      case GDK_End:      /* used when editing the entry buffer */
      case GDK_Down:
      case GDK_KP_End:
      case GDK_KP_Down:
         endEditor();
         break;

      case GDK_Right:      /* used when editing the entry buffer */
      case GDK_KP_Right:
         rightEditor();
         break;

      case GDK_Left:      /* used when editing the entry buffer */
      case GDK_KP_Left:
         leftEditor();
         break;

      case GDK_BackSpace:  /* delete the last entry in the stack */
      case GDK_Delete:     /* OR backspace over the last char typed */
      case GDK_KP_Delete:
         if(isEditingEditor()){
            deleteEditor();
         } else {
            PopStack();
         }
         break;

      case GDK_Escape:  /* clear the entry buffer */
         cancelEditor();
         break;

      case GDK_plus: 
      case GDK_KP_Add:
         c = getPrevEditor();
         if(c == 'e' || c == 'E'){
            insertEditor(bb);
         } else {
	    AddStack();
         }
         break;

      case GDK_minus: 
      case GDK_KP_Subtract:
         c = getPrevEditor();
         if(c == 'e' || c == 'E'){
            insertEditor(bb);
         } else {
	    SubStack();
         }
         break;

      case GDK_asterisk: 
      case GDK_KP_Multiply:
         MulStack();
         break;

      case GDK_slash: 
      case GDK_KP_Divide:
         DivStack();
         break;

      case GDK_asciicircum:
         PowStack();
         break;

      default:  /* catch everything that's left over */

         /* ascii characters */
         
         if (bb == '.') {
      		//is the locale decimal seperator a comma?
      		struct lconv * lc;
      		lc=localeconv();
      		if  (strcmp(lc->decimal_point,",")==0)
      		{
         		// then replace . by ,
                	bb=',';
      		}
         } else if (bb == ',') {
      		//is the locale decimal seperator a comma?
      		struct lconv * lc;
      		lc=localeconv();
      		if  (strcmp(lc->decimal_point,".")==0)
      		{
         		// then replace , by .
                	bb='.';
      		}
         }

         if((keysym >= GDK_KP_Space && keysym <= GDK_KP_9) ||
            (keysym >= GDK_space && keysym <= GDK_asciitilde)){
            insertEditor(bb);
         }

         
         break;
   }

   /* repaint the screen */
   redrawLCD();

}