summaryrefslogtreecommitdiff
path: root/support/dktools/test-dk4tsp08.c
blob: 3dec48053f580daad3852b4292f78307f144ceba (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
	WARNING: This file was generated by dkct.
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: test-dk4tsp08.ctr
*/

/**	@file test-dk4tsp08.c The test-dk4tsp08 module.
*/


#line 1 "test-dk4tsp08.ctr"

#include "dk4conf.h"
#include "dk4enc.h"
#include "dk4tsp08.h"
#include "dk4strm.h"
#include "dk4strmf.h"
#include "dk4strmo32.h"
#include "dk4ansi.h"
#include <string.h>




#line 13 "test-dk4tsp08.ctr"



#define	LINE_VERSION	1


/**	Buffer for input from file.
*/
static char fbuf[4096];


#if LINE_VERSION
static char lbuf[4096];
#endif


#if LINE_VERSION
int
line_handler(void *obj, char *line, dk4_um_t lineno, dk4_er_t *erp)
{
  size_t	 sz;
  int		 back = DK4_TSP_RES_ERROR;
  sz = strlen(line);
  if (0 < sz) {
    if (0 != dk4stream_write( (dk4_stream_t *)obj, line, sz, erp)) {
      back = DK4_TSP_RES_OK;
    }
  } else {
    back = DK4_TSP_RES_OK;
  }
  return back;
}
#else
int
char_handler(void *obj, char c, dk4_text_stream_position_t *pos, dk4_er_t *erp)
{
  dk4_c32_t	 c32;
  int		 back = DK4_TSP_RES_ERROR;
  if (dk4ansi_decode(&c32, (unsigned char)c)) {
    if (dk4stream_c32_putc((dk4_stream_t *)obj, c32, erp)) {
      back = DK4_TSP_RES_OK;
    }
  }
  return back;
}
#endif



int main(void)
{
  dk4_tsp08_t	 tsp;		/* Text stream processor. */
  dk4_er_t	 er;		/* Error report */
  dk4_stream_t	*outstream;	/* Output stream */
  size_t	 nread;		/* Number of bytes read */
#if DK4_ON_WINDOWS
  int		 oldmode;	/* Output text or binary mode */
  int		 oldinmode;	/* Input text or binary mode */
#endif
  int		 res;		/* Result for text stream processing */
  int		 oldres;	/* Previous result */
  int		 cc;		/* Flag: Can continue */
  

#line 76 "test-dk4tsp08.ctr"
  

#line 77 "test-dk4tsp08.ctr"
#if DK4_ON_WINDOWS
  oldmode = _setmode(_fileno(stdout), _O_BINARY);
  oldinmode = _setmode(_fileno(stdin), _O_BINARY);
#endif
  dk4error_init(&er);
  outstream = dk4stream_open_for_file( stdout, DK4_STREAM_WRITE, 0, 0, &er);
  if (NULL != outstream) {
    dk4stream_set_output_encoding(outstream, DK4_FILE_ENCODING_ASCII);
#if 1
    (void)dk4stream_write_bom_if_necessary(outstream, NULL);
#endif
#if LINE_VERSION
    res = dk4tsp08_setup_line(
      &tsp, (void *)outstream, line_handler, lbuf, sizeof(lbuf),
      DK4_ENCODING_ASCII, DK4_ENCODING_UTF8, &er
    );
#else
    res = dk4tsp08_setup_char(
      &tsp, (void *)outstream, char_handler,
      DK4_ENCODING_UTF8, DK4_ENCODING_UTF8, &er
    );
#endif
    if (DK4_TSP_RES_OK == res) {
      oldres = DK4_TSP_RES_OK;
      cc = 1;
      while (1 == cc) {
	nread = fread(fbuf, 1, sizeof(fbuf), stdin);
	if (0 < nread) {
	  res = dk4tsp08_add_bytes(&tsp, (unsigned char *)fbuf, nread);
	  switch (res) {
	    case DK4_TSP_RES_OK: {
	    } break;
	    case DK4_TSP_RES_ERROR: {
	      if (DK4_TSP_RES_OK == oldres) {
	        oldres = DK4_TSP_RES_ERROR;
		

#line 113 "test-dk4tsp08.ctr"
	      }
	    } break;
	    case DK4_TSP_RES_FATAL: {
	      if (DK4_TSP_RES_FATAL != oldres) {
	        oldres = DK4_TSP_RES_FATAL;
		

#line 119 "test-dk4tsp08.ctr"
	      }
	    } break;
	  }
	} else {
	  cc = 0;
	}
      }
      res = dk4tsp08_finish(&tsp);
      switch (res) {
        case DK4_TSP_RES_OK: {
        } break;
        case DK4_TSP_RES_ERROR: {
          if (DK4_TSP_RES_OK == oldres) {
            oldres = DK4_TSP_RES_ERROR;
    	

#line 134 "test-dk4tsp08.ctr"
          }
        } break;
        case DK4_TSP_RES_FATAL: {
          if (DK4_TSP_RES_FATAL != oldres) {
            oldres = DK4_TSP_RES_FATAL;
    	

#line 140 "test-dk4tsp08.ctr"
          }
        } break;
      }
    } else {			

#line 144 "test-dk4tsp08.ctr"
    }
    dk4stream_close(outstream, NULL);
  } else {			

#line 147 "test-dk4tsp08.ctr"
  }
  fflush(stdout);
#if DK4_ON_WINDOWS
  _setmode(_fileno(stdin), oldinmode);
  _setmode(_fileno(stdout), oldmode);
#endif
  

#line 154 "test-dk4tsp08.ctr"
  

#line 155 "test-dk4tsp08.ctr"
  return 0;
}