• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Test of sentence handling.
2    Copyright (C) 2015-2016 Free Software Foundation, Inc.
3    Written by Daiki Ueno <ueno@gnu.org>, 2015.
4 
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
17 
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21 
22 #include "sentence.h"
23 
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 
28 int
main(int argc,char ** argv)29 main (int argc, char **argv)
30 {
31   while (1)
32     {
33       char buffer[1024];
34       const char *result;
35       ucs4_t ending_char;
36       char *p, *newline;
37 
38       memset (buffer, 0, sizeof buffer);
39 
40       /* Read REQUIRED_SPACES parameter.  */
41       if (!fgets (buffer, sizeof (buffer) - 1, stdin))
42         break;
43 
44       newline = strchr (buffer, '\n');
45       if (!newline)
46         return 1;
47       *newline = '\0';
48 
49       sentence_end_required_spaces = atoi (buffer);
50 
51       /* Collect lines until an empty line is read.  */
52       p = buffer;
53       while (1)
54         {
55           p = fgets (p, sizeof (buffer) - (p - buffer) - 1, stdin);
56           if (!p)
57             break;
58 
59           if (*p == '\n')
60             break;
61 
62           newline = strchr (p, '\n');
63           if (!newline)
64             return 1;
65 
66           p = newline + 1;
67           *p = '\0';
68         }
69 
70       if (p == NULL)
71         break;
72 
73       *newline = '\0';
74       result = sentence_end (buffer, &ending_char);
75       printf ("%X\n%s\n\n", ending_char, result);
76     }
77 
78   return 0;
79 }
80