File: pcctst.c

package info (click to toggle)
pact 980714-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 13,096 kB
  • ctags: 26,034
  • sloc: ansic: 109,076; lisp: 9,645; csh: 7,147; fortran: 1,050; makefile: 136; lex: 95; sh: 32
file content (111 lines) | stat: -rw-r--r-- 2,861 bytes parent folder | download | duplicates (2)
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
/*
 * PCCTST.C - test connections child side
 *
 * Source Version: 2.0
 * Software Release #92-0043
 *
 */

#include "cpyright.h"

#include "ppc.h"

static void
 SC_DECLARE(send_binary, (long nitems, char *type));

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

/* MAIN - start here */

int main(argc, argv, envp)
   int argc;
   char **argv, **envp;
   {int i, binary;
    char s[MAXLINE+2];

    SC_setbuf(stdout, NULL);

    binary = FALSE;
    for (i = 1; i < argc; i++)
        {if (argv[i][0] == '-')
            {switch (argv[i][1])
                {case 'b' :
                      binary = TRUE;
		      break;
		 case 'h' :
		      printf("\nUsage: pcctst [-b]\n");
                      printf("   Simple program which prints prompts and echos input\n");
                      printf("   In binary mode sends 100 longs and 10 doubles first\n");
		      printf("   Options:\n");
		      printf("      b - run in binary mode\n");
		      break;};};};

    if (binary)
       {send_binary(100, SC_LONG_S);
        send_binary(10,  SC_DOUBLE_S);};

    while (TRUE)
       {PRINT(stdout, "-> ");
        if (fgets(s, MAXLINE, stdin) != NULL)
           PRINT(stdout, "%s", s);

        if (strcmp(s, "end\n") == 0)
           break;};

    return(0);}

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

/* SEND_BINARY - do some binary data exchanges */

static void send_binary(nitems, type)
   long nitems;
   char *type;
   {long i;
    PDBfile *file;
    byte *space;
    double *src;
    PROCESS *pp;

    PRINT(stdout, ":B\n");

    PRINT(stdout, "%s %ld\n", type, nitems);

/* this is a testing mode check */
    if (PC_terminal == NULL)
       {char **argv;

        argv    = FMAKE_N(char *, 2, "SEND_BINARY:argv");
        argv[0] = SC_strsavef("VIF", "char*:SEND_BINARY:argv0");

        PC_terminal      = PC_mk_process(argv, "ab", PC_CHILD);
        PC_terminal->in  = 0;
        PC_terminal->out = 1;};

    pp   = PC_terminal;
    file = pp->vif;

    space = _PD_alloc_entry(file, type, nitems);
    src   = (double *) _PD_alloc_entry(file, SC_DOUBLE_S, nitems);
    for (i = 0L; i < nitems; i++)
        src[i] = (double) i;
    CONVERT(type, &space, SC_DOUBLE_S, src, (int) nitems, TRUE);

    if (PC_write(space, type, nitems, pp))
       printf("Binary data sent: %s %ld\n",
              type, nitems);

    else
       printf("Binary data send failed: %s %ld\n",
              type, nitems);

    PRINT(stdout, ":A\n");

    SFREE(space);

    return;}

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/