~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/erl_interface/test/erl_eterm_SUITE_data/print_term.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * %CopyrightBegin%
 
3
 * 
 
4
 * Copyright Ericsson AB 1997-2009. All Rights Reserved.
 
5
 * 
 
6
 * The contents of this file are subject to the Erlang Public License,
 
7
 * Version 1.1, (the "License"); you may not use this file except in
 
8
 * compliance with the License. You should have received a copy of the
 
9
 * Erlang Public License along with this software. If not, it can be
 
10
 * retrieved online at http://www.erlang.org/.
 
11
 * 
 
12
 * Software distributed under the License is distributed on an "AS IS"
 
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
 * the License for the specific language governing rights and limitations
 
15
 * under the License.
 
16
 * 
 
17
 * %CopyrightEnd%
 
18
 */
 
19
 
 
20
/*
 
21
 * Purpose: Test the erl_print_term() function.
 
22
 * Author:  Bjorn Gustavsson
 
23
 */
 
24
 
 
25
#include <stdio.h>
 
26
#include <errno.h>
 
27
#include <sys/types.h>
 
28
#include <sys/stat.h>
 
29
#include <fcntl.h>
 
30
#ifndef __WIN32__
 
31
#include <unistd.h>
 
32
#endif
 
33
 
 
34
#include "erl_interface.h"
 
35
 
 
36
#ifndef __WIN32__
 
37
#define _O_BINARY 0
 
38
#define _setmode(fd, mode)
 
39
#endif
 
40
 
 
41
#define HEADER_SIZE 2
 
42
 
 
43
static int readn(int, unsigned char*, int);
 
44
 
 
45
/*
 
46
 * This program doesn't use the runner, because it needs a packet
 
47
 * on input, but the result will be as a stream of bytes (since
 
48
 * erl_print_term() prints directly on a file).
 
49
 *
 
50
 * Input is a package of with a packet header size of two bytes.
 
51
 *
 
52
 *  +------------------------------------------------------------+
 
53
 *  | length    | Encoded term...                                |
 
54
 *  | (2 bytes) | (as given by "length")                         |
 
55
 *  +------------------------------------------------------------+
 
56
 *
 
57
 *              <------------------- length --------------------->
 
58
 *
 
59
 * This program decodes the encoded terms and passes it to
 
60
 * erl_print_term().  Then this program prints
 
61
 *
 
62
 *    CR <result> LF
 
63
 *
 
64
 * and waits for a new package.  <result> is the return value from
 
65
 * erl_print_term(), formatted as an ASCII string.
 
66
 */
 
67
 
 
68
#ifdef VXWORKS
 
69
int print_term()
 
70
#else
 
71
int main()
 
72
#endif
 
73
{
 
74
    _setmode(0, _O_BINARY);
 
75
    _setmode(1, _O_BINARY);
 
76
 
 
77
    erl_init(NULL, 0);
 
78
 
 
79
    for (;;) {
 
80
        char buf[4*1024];
 
81
        ETERM* term;
 
82
        char* message;
 
83
        int n;
 
84
 
 
85
        if (readn(0, buf, 2) <= 0) {
 
86
          /* fprintf(stderr, "error reading message header\n"); */
 
87
          /* actually this is where we leave the infinite loop */
 
88
          exit(1);
 
89
        }
 
90
        n = buf[0] * 256 + buf[1];
 
91
        if (readn(0, buf, n) < 0) {
 
92
          fprintf(stderr, "error reading message contents\n");
 
93
          exit(1);
 
94
        }
 
95
 
 
96
        term = erl_decode(buf);
 
97
        if (term == NULL) {
 
98
            fprintf(stderr, "erl_decode() failed\n");
 
99
            exit(1);
 
100
        }
 
101
        n = erl_print_term(stdout, term);
 
102
        erl_free_compound(term);
 
103
        fprintf(stdout,"\r%d\n", n);
 
104
        fflush(stdout);
 
105
    }
 
106
}
 
107
 
 
108
/*
 
109
 * Reads len number of bytes.
 
110
 */
 
111
 
 
112
static int
 
113
readn(fd, buf, len)
 
114
     int fd;                    /* File descriptor to read from. */
 
115
     unsigned char *buf;        /* Store in this buffer. */
 
116
     int len;                   /* Number of bytes to read. */
 
117
{
 
118
    int n;                      /* Byte count in last read call. */
 
119
    int sofar = 0;              /* Bytes read so far. */
 
120
 
 
121
    do {
 
122
        if ((n = read(fd, buf+sofar, len-sofar)) <= 0)
 
123
            /* error or EOF in read */
 
124
            return(n);
 
125
        sofar += n;
 
126
    } while (sofar < len);
 
127
    return sofar;
 
128
}
 
129