Remove unused fields
[scilab.git] / scilab_doc / comm / alpha.c
1 /* Copyright INRIA */
2 /***************************************************************************/
3 #include <stdio.h>
4 #include <string.h>
5
6 /* Communications headers */
7 #include "/usr/local/lib/scilab-2.3/routines/libcomm/libCalCom.h"
8 #include "/usr/local/lib/scilab-2.3/routines/libcomm/libCom.h"
9
10 static void QuitAppli();  
11 static void EndAppli();
12 static void ParseMessage();
13 static void MsgError();
14
15 /* Known messages */
16 static actions_messages tb_messages[]={
17   {ID_GeCI,MSG_QUITTER_APPLI,NBP_QUITTER_APPLI,QuitAppli},
18   {ID_GeCI,MSG_FIN_APPLI,NBP_FIN_APPLI,EndAppli},
19   {NULL,MSG_DISTRIB_LISTE_ELMNT,NBP_DISTRIB_LISTE_ELMNT,ParseMessage},
20   {NULL,NULL,0,MsgError}};
21
22 static void QuitAppli(message)
23      Message message;
24 {  
25   printf("Quit application\n");
26   exit(0);
27 }
28
29 static void EndAppli(message) 
30      Message message;
31 {
32   printf("End application\n");
33 }
34
35 static void MsgError(message)
36      Message message;
37 {
38   printf("Bad received message\n");
39 }
40
41 static char *TheAppli;
42 static char *TheType;
43 static char *TheMsg;
44
45 /* ParseMessage is executed when a message is received */
46 static void ParseMessage(message)
47      Message message;
48 {
49   int lappli, ltype, lmsg;
50
51   lappli = strlen(message.tableau[0]);
52   if ((TheAppli = (char *)malloc((unsigned)sizeof(char)*(lappli + 1)))
53       == NULL) {
54     return;
55   }
56   strcpy(TheAppli,message.tableau[0]);
57
58   ltype = strlen(message.tableau[3]);
59   if ((TheType = (char *)malloc((unsigned)sizeof(char)*(ltype + 1)))
60       == NULL) {
61     return;
62   }
63   strcpy(TheType,message.tableau[3]);
64
65   lmsg = strlen(message.tableau[4]);
66   if ((TheMsg = (char *)malloc((unsigned)sizeof(char)*(lmsg + 1)))
67       == NULL) {
68     return;
69   }
70   strcpy(TheMsg,message.tableau[4]);
71 }
72
73 static int find(s,n,t)
74      char *s;
75      int n;
76      char **t;
77 {
78   int i;
79   for (i=0; i<n; i++)
80     if (!strcmp(s,t[i])) return(i);
81   return(-1);
82 }
83
84 int main(argc, argv)
85      unsigned int argc;
86      char **argv;
87 {
88   int igeci;
89   int p1, p2;
90   char myhost[128];
91   /* Scilab application to execute */
92   char *scilex = "/usr/local/lib/scilab-2.3/bin/scilex";
93
94   igeci = find("-pipes",argc,argv);
95   if (igeci == -1) exit(1);
96
97   p1 = atoi(argv[igeci+1]); p2 = atoi(argv[igeci+2]);
98
99   /* Intialization of communications */
100   init_messages(tb_messages,p1,p2);
101
102   /* Get the name of my computer */
103   gethostname(myhost,128);
104
105   /* Execute Scilab with name "Scilab" on my local host */
106   envoyer_message_parametres_var(ID_GeCI,
107                                  MSG_LANCER_APPLI,
108                                  "Scilab",
109                                  myhost,
110                                  scilex,
111                                  INS_ID_PIPES,
112                                  NULL);
113
114   /* Link THIS application with "Scilab" */
115   envoyer_message_parametres_var(ID_GeCI,
116                                  MSG_CREER_LIAISON, 
117                                  identificateur_appli(),
118                                  "Scilab",NULL);
119   
120   /* Link "Scilab" with THIS application  */
121   envoyer_message_parametres_var(ID_GeCI,
122                                  MSG_CREER_LIAISON, 
123                                  "Scilab",
124                                  identificateur_appli(),NULL);
125
126   /* Loop waiting for messages */
127   while (1) {
128     scanner_messages();
129     if (TheType != NULL) {
130       printf("Message received from %s\n",TheAppli);
131       printf("    type: %s\n",TheType);
132       printf("    message: %s\n",TheMsg);
133       TheAppli = NULL; TheType = NULL; TheMsg = NULL;
134     }
135   }
136 }
137 /***************************************************************************/