9 #define _(String) gettext(String)
10 #define gettext_noop(String) String
11 #define N_(String) gettext_noop (String)
13 Messages::Messages(int input_flag, int output_flag, int id)
17 msgid = msgget(IPC_PRIVATE, IPC_CREAT | 0777);
26 this->input_flag = input_flag;
27 this->output_flag = output_flag;
28 bc_enter_msg_id(msgid);
35 msgctl(msgid, IPC_RMID, NULL);
36 bc_remove_msg_id(msgid);
40 char* Messages::get_message_buffer()
45 int Messages::read_message(char *text)
47 buffer.mtype = input_flag;
49 if((msgrcv(msgid, (struct msgbuf*)&buffer, MESSAGESIZE, input_flag, 0)) < 0)
51 printf(_("recieve message failed\n"));
52 sleep(1); // don't flood the screen during the loop
56 //printf("%d %d\n", buffer.text[0], buffer.mtype);
57 strcpy(text, buffer.text);
61 long Messages::read_message()
63 buffer.mtype = input_flag;
65 if((msgrcv(msgid, (struct msgbuf*)&buffer, MESSAGESIZE, input_flag, 0)) < 0)
67 printf(_("recieve message failed\n"));
71 return atol(buffer.text);
74 float Messages::read_message_f()
77 char *data = read_message_raw();
78 sscanf(data, "%f", &value);
82 char* Messages::read_message_raw()
84 buffer.mtype = input_flag;
86 if((msgrcv(msgid, (struct msgbuf*)&buffer, MESSAGESIZE, input_flag, 0)) < 0)
88 printf(_("recieve message failed\n"));
90 return "RECIEVE MESSAGE FAILED";
96 int Messages::read_message(long *value1, long *value2)
98 char *data = read_message_raw();
99 sscanf(data, "%ld %ld", value1, value2);
103 int Messages::read_message_f(float *value1, float *value2)
105 char *data = read_message_raw();
106 sscanf(data, "%f %f", value1, value2);
110 int Messages::read_message(long *command, long *value1, long *value2)
112 char *data = read_message_raw();
113 sscanf(data, "%ld %ld %ld", command, value1, value2);
117 int Messages::read_message(long *command, long *value1, long *value2, long *value3)
119 char *data = read_message_raw();
120 sscanf(data, "%ld %ld %ld %ld", command, value1, value2, value3);
124 int Messages::read_message_f(float *value1, float *value2, float *value3)
126 char *data = read_message_raw();
127 sscanf(data, "%f %f %f", value1, value2, value3);
131 int Messages::read_message_f(float *value1, float *value2, float *value3, float *value4)
133 char *data = read_message_raw();
134 sscanf(data, "%f %f %f %f", value1, value2, value3, value4);
138 int Messages::read_message(int *command, char *text)
142 char *data = read_message_raw();
143 sscanf(data, "%d", command);
144 // find the start of the text
145 for(i = 0; i < MESSAGESIZE && data[i] != ' '; i++) { ; }
148 // copy the text part
149 for(j = 0; (text[j] = data[i]) != 0; i++, j++) { ; }
154 int Messages::write_message(char *text)
156 buffer.mtype = output_flag;
157 strcpy(buffer.text, text);
159 if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(text) + 1, 0)) < 0) printf(_("send message failed\n"));
163 int Messages::write_message_raw()
165 buffer.mtype = output_flag;
167 if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(buffer.text) + 1, 0)) < 0) printf(_("send message failed\n"));
171 int Messages::write_message_flagged(int output_flag, int command)
173 buffer.mtype = output_flag;
174 sprintf(buffer.text, "%d", command);
176 if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(buffer.text) + 1, 0)) < 0) printf(_("send message failed\n"));
180 int Messages::write_message(int number)
182 sprintf(buffer.text, "%d", number);
183 buffer.mtype = output_flag;
184 if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(buffer.text) + 1, 0)) < 0) perror(_("Messages::write_message"));
188 int Messages::write_message_f(float number)
190 sprintf(buffer.text, "%f", number);
191 buffer.mtype = output_flag;
192 if((msgsnd(msgid, (struct msgbuf*)&buffer, strlen(buffer.text) + 1, 0)) < 0) perror(_("Messages::write_message"));
196 int Messages::write_message(int command, char *text)
198 sprintf(buffer.text, "%d %s", command, text);
199 return write_message_raw();
202 int Messages::write_message(long command, long value)
204 sprintf(buffer.text, "%ld %ld", command, value);
205 return write_message_raw();
208 int Messages::write_message_f(float value1, float value2)
210 sprintf(buffer.text, "%f %f", value1, value2);
211 return write_message_raw();
214 int Messages::write_message(long command, long value1, long value2)
216 sprintf(buffer.text, "%ld %ld %ld", command, value1, value2);
217 return write_message_raw();
220 int Messages::write_message(long command, long value1, long value2, long value3)
222 sprintf(buffer.text, "%ld %ld %ld %ld", command, value1, value2, value3);
223 return write_message_raw();
226 int Messages::write_message_f(float value1, float value2, float value3, float value4)
228 sprintf(buffer.text, "%f %f %f %f", value1, value2, value3, value4);
229 return write_message_raw();
232 int Messages::write_message_f(float value1, float value2, float value3)
234 sprintf(buffer.text, "%f %f %f", value1, value2, value3);
235 return write_message_raw();
238 int Messages::get_id()