~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to routines/comm/messages.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright INRIA */
2
 
 
3
 
#ifdef __STDC__
4
 
#include <stdlib.h>
5
 
#else
6
 
#include <malloc.h>
7
 
#endif
8
 
#include <stdio.h>
9
 
#include <string.h>
10
 
 
11
 
#include "../machine.h"
12
 
#include "../intersci/cerro.h"
13
 
#include "../libcomm/libCalCom.h"
14
 
#include "../libcomm/libCom.h"
15
 
 
16
 
static char *TheAppli;
17
 
static char *TheType;
18
 
static char *TheMsg;
19
 
 
20
 
/* Called when a message comes: see initcom.c */
21
 
void ParseMessage(message)
22
 
Message message;
23
 
{
24
 
  int lappli, ltype, lmsg;
25
 
 
26
 
  lappli = strlen(message.tableau[0]);
27
 
  if ((TheAppli = (char *)malloc((unsigned)sizeof(char)*(lappli + 1)))
28
 
      == NULL) {
29
 
    cerro("Running out of memory");
30
 
    return;
31
 
  }
32
 
  strcpy(TheAppli,message.tableau[0]);
33
 
 
34
 
  ltype = strlen(message.tableau[3]);
35
 
  if ((TheType = (char *)malloc((unsigned)sizeof(char)*(ltype + 1)))
36
 
      == NULL) {
37
 
    cerro("Running out of memory");
38
 
    return;
39
 
  }
40
 
  strcpy(TheType,message.tableau[3]);
41
 
 
42
 
  lmsg = strlen(message.tableau[4]);
43
 
  if ((TheMsg = (char *)malloc((unsigned)sizeof(char)*(lmsg + 1)))
44
 
      == NULL) {
45
 
    cerro("Running out of memory");
46
 
    return;
47
 
  }
48
 
  strcpy(TheMsg,message.tableau[4]);
49
 
}
50
 
 
51
 
/* Communication functions for Scilab toplevel */
52
 
 
53
 
/* sends a message "msg" of type "type" */
54
 
void C2F(sendmsg)(type,ltype,msg,lmsg)
55
 
     char *type; int *ltype;
56
 
     char *msg; int *lmsg;
57
 
{
58
 
  type[*ltype] = '\0';
59
 
  msg[*lmsg] = '\0';
60
 
  envoyer_message_parametres_var(ID_GeCI,MSG_POSTER_LISTE_ELMNT,
61
 
                                 type,msg,NULL);
62
 
}
63
 
 
64
 
/* gets a message "msg" of type "type" from the application "appli" */
65
 
void C2F(getmsg)(appli,lappli,type,ltype,msg,lmsg)
66
 
     char **appli; int *lappli;
67
 
     char **type; int *ltype;
68
 
     char ** msg; int *lmsg;
69
 
{
70
 
  TheAppli = ""; TheType = ""; TheMsg = "";
71
 
  scanner_messages();
72
 
  
73
 
  *lappli = strlen(TheAppli);
74
 
  *appli = TheAppli;
75
 
  *ltype = strlen(TheType);
76
 
  *type = TheType;
77
 
  *lmsg = strlen(TheMsg);
78
 
  *msg = TheMsg;
79
 
}
80
 
 
81
 
#define MAXNAM 126
82
 
#define MAXARGS 11
83
 
 
84
 
/* executes the application "appli" on host "host" 
85
 
   the command line is "command" */
86
 
void C2F(execappli)(command,lcommand,host,lhost,appli,lappli)
87
 
     char *command; int *lcommand;
88
 
     char *host; int *lhost;
89
 
     char *appli; int *lappli;
90
 
{
91
 
  int nargs = 0;
92
 
  char w[MAXNAM];
93
 
  int inword = 1;
94
 
  int i = 0;
95
 
  char *args[MAXARGS];
96
 
  
97
 
  command[*lcommand] = '\0';
98
 
  host[*lhost] = '\0';
99
 
  appli[*lappli] = '\0';
100
 
 
101
 
  /* cut the string "command" into "nargs" "args" */
102
 
  if (*command == ' ' || *command == '\t') inword = 0;
103
 
  while (*command) {
104
 
    if (inword) {
105
 
      w[i++] = *command++;
106
 
      if (*command == ' ' || *command == '\t' || *command == '\0') {
107
 
        w[i] = '\0';
108
 
        args[nargs] = (char *)malloc((unsigned)(i+1));
109
 
        strcpy(args[nargs],w);
110
 
        nargs++;
111
 
        inword = 0;
112
 
      }
113
 
    }
114
 
    else {
115
 
      command++; /** jpc : I remove * in  *command++ cause it's unused **/
116
 
      if (*command != ' ' && *command != '\t') {
117
 
        i = 0;
118
 
        inword = 1;
119
 
      }
120
 
    }
121
 
  }
122
 
  
123
 
  switch (nargs) {
124
 
  case 0:
125
 
    return;
126
 
  case 1:
127
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
128
 
                                   appli,host,args[0],
129
 
                                   INS_ID_PIPES,
130
 
                                   NULL);
131
 
    break;
132
 
  case 2:
133
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
134
 
                                   appli,host,args[0],
135
 
                                   INS_ID_PIPES,
136
 
                                   args[1],
137
 
                                   NULL);
138
 
    break;
139
 
  case 3:
140
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
141
 
                                   appli,host,args[0],
142
 
                                   INS_ID_PIPES,
143
 
                                   args[1],args[2],
144
 
                                   NULL);
145
 
    break;
146
 
  case 4:
147
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
148
 
                                   appli,host,args[0],
149
 
                                   INS_ID_PIPES,
150
 
                                   args[1],args[2],args[3],
151
 
                                   NULL);
152
 
    break;
153
 
  case 5:
154
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
155
 
                                   appli,host,args[0],
156
 
                                   INS_ID_PIPES,
157
 
                                   args[1],args[2],args[3],args[4],
158
 
                                   NULL);
159
 
    break;
160
 
  case 6:
161
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
162
 
                                   appli,host,args[0],
163
 
                                   INS_ID_PIPES,
164
 
                                   args[1],args[2],args[3],args[4],args[5],
165
 
                                   NULL);
166
 
    break;
167
 
  case 7:
168
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
169
 
                                   appli,host,args[0],
170
 
                                   INS_ID_PIPES,
171
 
                                   args[1],args[2],args[3],args[4],args[5],
172
 
                                   args[6],
173
 
                                   NULL);
174
 
    break;
175
 
  case 8:
176
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
177
 
                                   appli,host,args[0],
178
 
                                   INS_ID_PIPES,
179
 
                                   args[1],args[2],args[3],args[4],args[5],
180
 
                                   args[6],args[7],
181
 
                                   NULL);
182
 
    break;
183
 
  case 9:
184
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
185
 
                                   appli,host,args[0],
186
 
                                   INS_ID_PIPES,
187
 
                                   args[1],args[2],args[3],args[4],args[5],
188
 
                                   args[6],args[7],args[8],
189
 
                                   NULL);
190
 
    break;
191
 
  case 10:
192
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
193
 
                                   appli,host,args[0],
194
 
                                   INS_ID_PIPES,
195
 
                                   args[1],args[2],args[3],args[4],args[5],
196
 
                                   args[6],args[7],args[8],args[9],
197
 
                                   NULL);
198
 
    break;
199
 
  default:
200
 
    /* if more than MAXARGS arguments, discard them! */
201
 
    envoyer_message_parametres_var(ID_GeCI,MSG_LANCER_APPLI,
202
 
                                   appli,host,args[0],
203
 
                                   INS_ID_PIPES,
204
 
                                   args[1],args[2],args[3],args[4],args[5],
205
 
                                   args[6],args[7],args[8],args[9],args[10],
206
 
                                   NULL);
207
 
    break;
208
 
  }
209
 
}
210
 
 
211
 
/* creates a link from application "appli1" to application "appli2" */
212
 
void C2F(createlink)(appli1,lappli1,appli2,lappli2)
213
 
     char *appli1; int *lappli1;
214
 
     char *appli2; int *lappli2;
215
 
{
216
 
  appli1[*lappli1] = '\0';
217
 
  appli2[*lappli2] = '\0';
218
 
  if (!strcmp(appli1,"SELF"))
219
 
    envoyer_message_parametres_var(ID_GeCI,
220
 
                                   MSG_CREER_LIAISON, 
221
 
                                   identificateur_appli(),
222
 
                                   appli2,
223
 
                                   NULL);
224
 
  else if (!strcmp(appli2,"SELF"))
225
 
    envoyer_message_parametres_var(ID_GeCI,
226
 
                                   MSG_CREER_LIAISON, 
227
 
                                   appli1,
228
 
                                   identificateur_appli(),
229
 
                                   NULL);
230
 
 
231
 
  else
232
 
    envoyer_message_parametres_var(ID_GeCI,
233
 
                                   MSG_CREER_LIAISON, 
234
 
                                   appli1,
235
 
                                   appli2,
236
 
                                   NULL);
237
 
}
238
 
 
239
 
/* destroys a link from application "appli1" to application "appli2" */
240
 
void C2F(destroylink)(appli1,lappli1,appli2,lappli2)
241
 
     char *appli1; int *lappli1;
242
 
     char *appli2; int *lappli2;
243
 
{
244
 
  appli1[*lappli1] = '\0';
245
 
  appli2[*lappli2] = '\0';
246
 
  if (!strcmp(appli1,"SELF"))
247
 
    envoyer_message_parametres_var(ID_GeCI,
248
 
                                   MSG_DETRUIRE_LIAISON, 
249
 
                                   identificateur_appli(),
250
 
                                   appli2,
251
 
                                   NULL);
252
 
  else if (!strcmp(appli2,"SELF"))
253
 
    envoyer_message_parametres_var(ID_GeCI,
254
 
                                   MSG_DETRUIRE_LIAISON, 
255
 
                                   appli1,
256
 
                                   identificateur_appli(),
257
 
                                   NULL);
258
 
 
259
 
  else
260
 
    envoyer_message_parametres_var(ID_GeCI,
261
 
                                   MSG_DETRUIRE_LIAISON, 
262
 
                                   appli1,
263
 
                                   appli2,
264
 
                                   NULL);
265
 
}
266
 
 
267
 
/* waits for a message coming from the application "appli" 
268
 
     this message is "msg" with type "type" */
269
 
void C2F(waitmsg)(appli,lappli,type,ltype,msg,lmsg)
270
 
     char *appli; int *lappli;
271
 
     char **type; int *ltype;
272
 
     char ** msg; int *lmsg;
273
 
{
274
 
  Message message;
275
 
 
276
 
  appli[*lappli] = '\0';
277
 
  message = attendre_reponse(appli,
278
 
                             MSG_DISTRIB_LISTE_ELMNT,
279
 
                             NBP_DISTRIB_LISTE_ELMNT);
280
 
  TheAppli = ""; TheType = ""; TheMsg = "";
281
 
  ParseMessage(message);
282
 
  *ltype = strlen(TheType);
283
 
  *type = TheType;
284
 
  *lmsg = strlen(TheMsg);
285
 
  *msg = TheMsg;
286
 
}