FACT++  1.0
dim_send_command.c
Go to the documentation of this file.
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <dic.h>
6 
7 int received = 0;
8 char str[132] = {'\0'};
9 
10 void rout(tag, code)
11 int *tag;
12 int *code;
13 {
14  int silent;
15 
16  silent = *tag;
17  if(!silent)
19  if(*code)
20  {
21  if(!silent)
22  printf(" Command %s Successfully Sent\n", str);
23  }
24  else
25  {
26  if(!silent)
27  printf(" Command %s Unsuccessfull\n", str);
28  }
29  received = 1;
30 #ifdef WIN32
31  wake_up();
32 #endif
33 }
34 /*
35 main(argc,argv)
36 int argc;
37 char **argv;
38 {
39  char data[1024] = {'\0'};
40  int silent = 0;
41 
42  if(argc < 2)
43  {
44  printf("Command Name > ");
45  fflush(stdout);
46  scanf("%s", str);
47  printf("Command String > ");
48  fflush(stdout);
49  scanf("%s", data);
50  }
51  else
52  {
53  sprintf(str,argv[1]);
54  if(argc < 3)
55  data[0] = '\0';
56  else
57  {
58  sprintf(data,argv[2]);
59  if(argc > 3)
60  silent = 1;
61  }
62  }
63  dic_cmnd_callback(str,data,(int)strlen(data)+1, rout, silent);
64  while(!received)
65  dim_wait();
66  sleep(1);
67 }
68 */
69 int main(argc,argv)
70 int argc;
71 char **argv;
72 {
73 int i;
74 int silent = 0;
75 char data[1024] = {'\0'};
76 int data_int, data_int_flag = 0;
77 char dns_node[128], *ptr;
78 int dns_port = 0;
79 
80  dns_node[0] = '\0';
81  for(i = 1; i < argc; i++)
82  {
83  if(!strcmp(argv[i],"-dns"))
84  {
85  strcpy(dns_node,argv[i+1]);
86  if((ptr = strchr(dns_node,':')))
87  {
88  *ptr = '\0';
89  ptr++;
90  sscanf(ptr,"%d",&dns_port);
91  }
92  i++;
93  }
94  else if(!strcmp(argv[i],"-s"))
95  {
96  silent = 1;
97  }
98  else if(!strcmp(argv[i],"-i"))
99  {
100  data_int_flag = 1;
101  }
102  else
103  {
104  if(!str[0])
105  {
106  strcpy(str, argv[i]);
107  }
108  else if(!data[0])
109  {
110  strcpy(data,argv[i]);
111  }
112  }
113  }
114  if(dns_node[0])
115  {
116  dic_set_dns_node(dns_node);
117  }
118  if(dns_port)
119  {
120  dic_set_dns_port(dns_port);
121  }
122  if(!str[0])
123  {
124  printf("dim_send_command: Insufficient parameters\n");
125  printf("usage: dim_send_command <cmnd_name> [<data>] [-dns <dns_node>] [-s] [-i]\n");
126  exit(0);
127  }
128  if(!data[0])
129  data[0] = '\0';
130  if(data_int_flag)
131  {
132  sscanf(data,"%d",&data_int);
133  dic_cmnd_callback(str,&data_int,sizeof(int), rout, silent);
134  }
135  else
136  {
137  dic_cmnd_callback(str,data,(int)strlen(data)+1, rout, silent);
138  }
139  while(!received)
140  dim_wait();
141  sleep(1);
142  return(1);
143 }
static int wake_up
Definition: dns.c:81
int dim_wait(void)
Definition: dim_thr.c:409
int i
Definition: db_dim_client.c:21
int received
int dic_set_dns_node(char *node)
Definition: open_dns.c:58
int dic_set_dns_port(int port)
Definition: open_dns.c:107
void rout(int *tag, int *code)
float data[4 *1440]
int main(int argc, char **argv)
void dim_print_date_time()
Definition: utilities.c:134
char str[132]
int dic_cmnd_callback(char *serv_name, void *serv_address, int serv_size, void(*usr_routine)(), dim_long tag)
Definition: dic.c:716