-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagenda_client.c
114 lines (104 loc) · 3.4 KB
/
agenda_client.c
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
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use them
* as a guideline for developing your own functions.
*/
#include "agenda.h"
#include <stdio.h>
void
agenda_1(char *host)
{
CLIENT *clnt;
int *result_1;
struct contact insertcontact_1_arg;
struct contact *result_2;
char * searchcontact_1_arg;
int *result_3;
char * removecontact_1_arg;
void *result_4;
char * setfile_1_arg;
#ifndef DEBUG
clnt = clnt_create (host, agenda, agenda, "udp");
if (clnt == NULL) {
clnt_pcreateerror (host);
exit (1);
}
#endif /* DEBUG */
setfile_1_arg = (char *) malloc(100*sizeof(char));
printf("Enter agenda name: ");
scanf("%s",setfile_1_arg);
int input;
printf("Press:\n1: Insert\n2: Search\n3: Remove\n0: Exit\n");
scanf("%d",&input);
while(input != 0){
if(input == 1){
printf("Name: ");
scanf("%s",insertcontact_1_arg.name);
printf("Fone: ");
scanf("%s",insertcontact_1_arg.fone);
printf("Address: ");
scanf("%s",insertcontact_1_arg.address);
result_4 = setfile_1(&setfile_1_arg, clnt);
if (result_4 == (void *) NULL) {
clnt_perror (clnt, "call failed");
}
result_1 = insertcontact_1(&insertcontact_1_arg, clnt);
if (result_1 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
if (*result_1)
printf("%s included successfully.\n\n",insertcontact_1_arg.name);
else printf("%s already exists.\n\n",insertcontact_1_arg.name);
}
else if(input == 2){
searchcontact_1_arg = (char *)malloc(50*sizeof(char));
printf("Name: ");
scanf("%s",searchcontact_1_arg);
result_4 = setfile_1(&setfile_1_arg, clnt);
if (result_4 == (void *) NULL) {
clnt_perror (clnt, "call failed");
}
result_2 = searchcontact_1(&searchcontact_1_arg, clnt);
if (result_2 == (struct contact *) NULL) {
clnt_perror (clnt, "call failed");
}
if(strcmp(result_2->name,""))
printf("Name: %s\nFone: %s\nAddress: %s\n\n",
result_2->name, result_2->fone, result_2->address);
else printf("Contact not found.\n\n");
}
else if(input == 3){
removecontact_1_arg = (char *)malloc(50*sizeof(char));
printf("Name: ");
scanf("%s",removecontact_1_arg);
result_4 = setfile_1(&setfile_1_arg, clnt);
if (result_4 == (void *) NULL) {
clnt_perror (clnt, "call failed");
}
result_3 = removecontact_1(&removecontact_1_arg, clnt);
if (result_3 == (int *) NULL) {
clnt_perror (clnt, "call failed");
}
if(*result_3)
printf("%s removed successfully.\n\n",removecontact_1_arg);
else printf("%s does not exist.\n\n",removecontact_1_arg);
}
printf("Press:\n1: Insert\n2: Search\n3: Remove\n0: Exit\n");
scanf("%d",&input);
}
#ifndef DEBUG
clnt_destroy (clnt);
#endif /* DEBUG */
}
int
main (int argc, char *argv[])
{
char *host;
if (argc < 2) {
printf ("usage: %s server_host\n", argv[0]);
exit (1);
}
host = argv[1];
agenda_1 (host);
exit (0);
}