1 | /* |
---|
2 | send-sac.c - simple client process to send a big integer. |
---|
3 | If the argument -usesac is given on the commandline, |
---|
4 | SAC big ints will be used, otherwise GMP format is used. |
---|
5 | |
---|
6 | */ |
---|
7 | |
---|
8 | #include <sys/types.h> |
---|
9 | #include <string.h> |
---|
10 | #include <fcntl.h> |
---|
11 | #include "MP.h" |
---|
12 | #include "saclib.h" |
---|
13 | #include "MP_SacBigInt.h" |
---|
14 | |
---|
15 | EXTERN MP_BigIntOps_t imp_sac_bigint_ops; |
---|
16 | |
---|
17 | void main(argc, argv) |
---|
18 | int argc; |
---|
19 | char *argv[]; |
---|
20 | { |
---|
21 | char *ifname = NULL; |
---|
22 | MP_Link_pt link = NULL; |
---|
23 | MP_Env_pt env = NULL; |
---|
24 | int usesac = 0; |
---|
25 | Word sac1, sac2, sac_stack; |
---|
26 | MP_INT gmp; |
---|
27 | |
---|
28 | BEGINSACLIB(&sac_stack); /* initialize SACLIB */ |
---|
29 | env = MP_InitializeEnv(NULL); /* create and initialize an MP environment */ |
---|
30 | if (env == NULL) { |
---|
31 | fprintf(stderr, "%s: MP_InitializeEnv() failed!\n", argv[0]); |
---|
32 | exit(1); |
---|
33 | } |
---|
34 | if(IMP_GetCmdlineArg(argc, argv, "-usesac") != NULL) { |
---|
35 | usesac = 1; |
---|
36 | /* indicate we want SAC ints */ |
---|
37 | MP_SetEnvBigIntFormat(env, &imp_sac_bigint_ops, MP_SAC); |
---|
38 | } |
---|
39 | /* now create the link */ |
---|
40 | if ((link = MP_OpenLink(env, argc, argv)) == NULL) { |
---|
41 | fprintf(stderr, "%s: MP_OpenLink() failed!\n", argv[0]); |
---|
42 | exit(1); |
---|
43 | } |
---|
44 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_INIT_EVENTS); |
---|
45 | MP_SetLinkOption(link, MP_LINK_LOG_MASK_OPT, MP_LOG_WRITE_EVENTS); |
---|
46 | /* MP_SetLinkOption(link, MP_LINK_SEND_MODE_OPT, MP_SEND_WHOLE_MSG);*/ |
---|
47 | |
---|
48 | printf("BETA = %d\n\n", BETA); |
---|
49 | printf("Enter big positive or negative integer: "); |
---|
50 | if (usesac) { |
---|
51 | sac1 = IREAD(); |
---|
52 | printf("the integer just read is "); |
---|
53 | IWRITE(sac1); printf("\n"); fflush(stdout); |
---|
54 | if (!ISATOM(sac1)) LWRITE(sac1); printf("\n"); fflush(stdout); |
---|
55 | IMP_PutApInt(link, (MP_ApInt_t)&sac1); |
---|
56 | MP_PutApIntPacket(link, (MP_ApInt_t)&sac1, 0); |
---|
57 | } |
---|
58 | else { |
---|
59 | mpz_init(&gmp); |
---|
60 | mpz_inp_str(&gmp, stdin, 10); |
---|
61 | IMP_PutApInt(link, (MP_ApInt_t)&gmp); |
---|
62 | MP_PutApIntPacket(link, (MP_ApInt_t)&gmp, 0); |
---|
63 | } |
---|
64 | MP_EndMsg(link); |
---|
65 | |
---|
66 | /* cleanup */ |
---|
67 | MP_CloseLink(link); |
---|
68 | MP_ReleaseEnv(env); |
---|
69 | ENDSACLIB(SAC_FREEMEM); |
---|
70 | } |
---|