RPM: store libs in %{_libdir}
[idzebra-moved-to-github.git] / util / charmap.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2011 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20
21 /**
22  * \file charmap.c
23  * \brief character conversions (.chr)
24  *  
25  * Support module to handle character-conversions into and out of the
26  * Zebra dictionary.
27  */
28
29 #if HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32 #include <ctype.h>
33 #include <string.h>
34 #include <stdlib.h>
35 #include <assert.h>
36
37 typedef unsigned ucs4_t;
38
39 #include <charmap.h>
40
41 #include <yaz/yaz-util.h>
42
43 #define CHR_MAXSTR 1024
44 #define CHR_MAXEQUIV 32
45
46 const unsigned char CHR_FIELD_BEGIN = '^';
47
48 const char *CHR_UNKNOWN = "\001";
49 const char *CHR_SPACE   = "\002";
50 const char *CHR_CUT     = "\003";
51 const char *CHR_BASE    = "\005"; /* CHECK CHR_BASE_CHAR as well */
52
53 struct chrmaptab_info
54 {
55     chr_t_entry *input;         /* mapping table for input data */
56     chr_t_entry *q_input;       /* mapping table for queries */
57     unsigned char *output[256]; /* return mapping - for display of registers */
58     int base_uppercase;         /* Start of upper-case ordinals */
59     NMEM nmem;
60 };
61
62 /*
63  * Character map trie node.
64  */
65 struct chr_t_entry
66 {
67     chr_t_entry **children;  /* array of children */
68     unsigned char **target;  /* target for this node, if any */
69 };
70
71 /*
72  * General argument structure for callback functions (internal use only)
73  */
74 typedef struct chrwork 
75 {
76     chrmaptab map;
77     char string[CHR_MAXSTR+1];
78 } chrwork;
79
80 /*
81  * Callback for equivalent stuff
82  */
83 typedef struct
84 {
85     NMEM nmem;
86     int no_eq;
87     char *eq[CHR_MAXEQUIV];
88 } chr_equiv_work;
89 /*
90  * Add an entry to the character map.
91  */
92 static chr_t_entry *set_map_string(chr_t_entry *root, NMEM nmem,
93                                    const char *from, int len, char *to,
94                                    const char *from_0)
95 {
96     if (!from_0)
97         from_0 = from;
98     if (!root)
99     {
100         root = (chr_t_entry *) nmem_malloc(nmem, sizeof(*root));
101         root->children = 0;
102         root->target = 0;
103     }
104     if (!len)
105     {
106         if (!root->target || !root->target[0] || 
107             strcmp((const char *) root->target[0], to))
108         {
109             if (from_0 && 
110                 root->target && root->target[0] && root->target[0][0] &&
111                 strcmp((const char *) root->target[0], CHR_UNKNOWN))
112             {
113                 yaz_log(YLOG_WARN, "duplicate entry for charmap from '%s'",
114                         from_0);
115             }
116             root->target = (unsigned char **)
117                 nmem_malloc(nmem, sizeof(*root->target)*2);
118             root->target[0] = (unsigned char *) nmem_strdup(nmem, to);
119             root->target[1] = 0;
120         }
121     }
122     else
123     {
124         if (!root->children)
125         {
126             int i;
127
128             root->children = (chr_t_entry **)
129                 nmem_malloc(nmem, sizeof(chr_t_entry*) * 256);
130             for (i = 0; i < 256; i++)
131                 root->children[i] = 0;
132         }
133         if (!(root->children[(unsigned char) *from] =
134               set_map_string(root->children[(unsigned char) *from], nmem,
135                              from + 1, len - 1, to, from_0)))
136             return 0;
137     }
138     return root;
139 }
140
141 static chr_t_entry *find_entry_x(chr_t_entry *t, const char **from, int *len, int first)
142 {
143     chr_t_entry *res;
144
145     while (*len <= 0)
146     {   /* switch to next buffer */
147         if (*len < 0)
148             break;
149         from++;
150         len++;
151     }
152     if (*len > 0 && t->children)
153     {
154         const char *old_from = *from;
155         int old_len = *len;
156
157         res = 0;
158
159         if (first && t->children[CHR_FIELD_BEGIN])
160         {
161             if ((res = find_entry_x(t->children[CHR_FIELD_BEGIN], from, len, 0)) && res != t->children[CHR_FIELD_BEGIN])
162                 return res;
163             else
164                 res = 0;
165             /* otherwhise there was no match on beginning of field, move on */
166         } 
167         
168         if (!res && t->children[(unsigned char) **from])
169         {
170             (*len)--;
171             (*from)++;
172             if ((res = find_entry_x(t->children[(unsigned char) *old_from],
173                                     from, len, 0)))
174                 return res;
175             /* no match */
176             *len = old_len;
177             *from = old_from;
178         }
179     }
180     /* no children match. use ourselves, if we have a target */
181     return t->target ? t : 0;
182 }
183
184 const char **chr_map_input_x(chrmaptab maptab, const char **from, int *len, int first)
185 {
186     chr_t_entry *t = maptab->input;
187     chr_t_entry *res;
188
189     if (!(res = find_entry_x(t, from, len, first)))
190         abort();
191     return (const char **) (res->target);
192 }
193
194 const char **chr_map_input(chrmaptab maptab, const char **from, int len, int first)
195 {
196     chr_t_entry *t = maptab->input;
197     chr_t_entry *res;
198     int len_tmp[2];
199
200     len_tmp[0] = len;
201     len_tmp[1] = -1;
202     if (!(res = find_entry_x(t, from, len_tmp, first)))
203         abort();
204     return (const char **) (res->target);
205 }
206
207 const char **chr_map_q_input(chrmaptab maptab,
208                              const char **from, int len, int first)
209 {
210     chr_t_entry *t = maptab->q_input;
211     chr_t_entry *res;
212     int len_tmp[2];
213     
214     len_tmp[0] = len;
215     len_tmp[1] = -1;
216     if (!(res = find_entry_x(t, from, len_tmp, first)))
217         return 0;
218     return (const char **) (res->target);
219 }
220
221 const char *chr_map_output(chrmaptab maptab, const char **from, int len)
222 {
223     unsigned char c = ** (unsigned char **) from;
224     const char *out = (const char*) maptab->output[c];
225
226     if (out)
227         (*from)++;
228     return out;
229 }
230
231 static int zebra_ucs4_strlen(ucs4_t *s)
232 {
233     int i = 0;
234     while (*s++)
235         i++;
236     return i;
237 }
238
239 ucs4_t zebra_prim_w(ucs4_t **s)
240 {
241     ucs4_t c;
242     ucs4_t i = 0;
243     char fmtstr[8];
244
245     yaz_log(YLOG_DEBUG, "prim_w %.3s", (char *) *s);
246     if (**s == '\\' && 1[*s])
247     {
248         (*s)++;
249         c = **s;
250         switch (c)
251         {
252         case '\\': c = '\\'; (*s)++; break;
253         case 'r': c = '\r'; (*s)++; break;
254         case 'n': c = '\n'; (*s)++; break;
255         case 't': c = '\t'; (*s)++; break;
256         case 's': c = ' '; (*s)++; break;
257         case 'x': 
258             if (zebra_ucs4_strlen(*s) >= 3)
259             {
260                 fmtstr[0] = (*s)[1];
261                 fmtstr[1] = (*s)[2];
262                 fmtstr[2] = 0;
263                 sscanf(fmtstr, "%x", &i);
264                 c = i;
265                 *s += 3;
266             }
267             break;
268         case '0':
269         case '1':
270         case '2':
271         case '3':
272         case '4':
273         case '5':
274         case '6':
275         case '7':
276         case '8':
277         case '9':
278             if (zebra_ucs4_strlen(*s) >= 3)
279             {
280                 fmtstr[0] = (*s)[0];
281                 fmtstr[1] = (*s)[1];
282                 fmtstr[2] = (*s)[2];
283                 fmtstr[3] = 0;
284                 sscanf(fmtstr, "%o", &i);
285                 c = i;
286                 *s += 3;
287             }
288             break;
289         case 'L':
290             if (zebra_ucs4_strlen(*s) >= 5)
291             {
292                 fmtstr[0] = (*s)[1];
293                 fmtstr[1] = (*s)[2];
294                 fmtstr[2] = (*s)[3];
295                 fmtstr[3] = (*s)[4];
296                 fmtstr[4] = 0;
297                 sscanf(fmtstr, "%x", &i);
298                 c = i;
299                 *s += 5;
300             }
301             break;
302         default:
303             (*s)++;
304         }
305     }
306     else
307     {
308         c = **s;
309         ++(*s);
310     }
311     yaz_log(YLOG_DEBUG, "out %d", c);
312     return c;
313 }
314
315 /*
316  * Callback function.
317  * Add an entry to the value space.
318  */
319 static void fun_addentry(const char *s, void *data, int num)
320 {
321     chrmaptab tab = (chrmaptab) data;
322     char tmp[2];
323     
324     tmp[0] = num; tmp[1] = '\0';
325     tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s), tmp, 0);
326     tab->output[num + tab->base_uppercase] =
327         (unsigned char *) nmem_strdup(tab->nmem, s);
328 }
329
330 /* 
331  * Callback function.
332  * Add a space-entry to the value space.
333  */
334 static void fun_addspace(const char *s, void *data, int num)
335 {
336     chrmaptab tab = (chrmaptab) data;
337     tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s),
338                                 (char*) CHR_SPACE, 0);
339 }
340
341 /* 
342  * Callback function.
343  * Add a space-entry to the value space.
344  */
345 static void fun_addcut(const char *s, void *data, int num)
346 {
347     chrmaptab tab = (chrmaptab) data;
348     tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s),
349                                 (char*) CHR_CUT, 0);
350 }
351
352 /*
353  * Create a string containing the mapped characters provided.
354  */
355 static void fun_mkstring(const char *s, void *data, int num)
356 {
357     chrwork *arg = (chrwork *) data;
358     const char **res, *p = s;
359
360     res = chr_map_input(arg->map, &s, strlen(s), 0);
361     if (*res == (char*) CHR_UNKNOWN)
362         yaz_log(YLOG_WARN, "Map: '%s' has no mapping", p);
363     strncat(arg->string, *res, CHR_MAXSTR - strlen(arg->string));
364     arg->string[CHR_MAXSTR] = '\0';
365 }
366
367 /*
368  * Create an unmodified string (scan_string handler).
369  */
370 static void fun_add_equivalent_string(const char *s, void *data, int num)
371 {
372     chr_equiv_work *arg = (chr_equiv_work *) data;
373     
374     if (arg->no_eq == CHR_MAXEQUIV)
375         return;
376     arg->eq[arg->no_eq++] = nmem_strdup(arg->nmem, s);
377 }
378
379 /*
380  * Add a map to the string contained in the argument.
381  */
382 static void fun_add_map(const char *s, void *data, int num)
383 {
384     chrwork *arg = (chrwork *) data;
385
386     assert(arg->map->input);
387     yaz_log(YLOG_DEBUG, "set map %.*s", (int) strlen(s), s);
388     set_map_string(arg->map->input, arg->map->nmem, s, strlen(s), arg->string,
389                    0);
390     for (s = arg->string; *s; s++)
391         yaz_log(YLOG_DEBUG, " %3d", (unsigned char) *s);
392 }
393
394 static int scan_to_utf8(yaz_iconv_t t, ucs4_t *from, size_t inlen,
395                         char *outbuf, size_t outbytesleft)
396 {
397     size_t inbytesleft = inlen * sizeof(ucs4_t);
398     char *inbuf = (char*) from;
399     size_t ret;
400    
401     if (t == 0)
402         *outbuf++ = *from;  /* ISO-8859-1 is OK here */
403     else
404     {
405         ret = yaz_iconv(t, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
406         if (ret != (size_t) (-1))
407             ret = yaz_iconv(t, 0, 0, &outbuf, &outbytesleft);
408         
409             
410         if (ret == (size_t) (-1))
411         {
412             yaz_log(YLOG_LOG, "from: %2X %2X %2X %2X",
413                     from[0], from[1], from[2], from[3]);
414             yaz_log(YLOG_WARN|YLOG_ERRNO, "bad unicode sequence");
415             return -1;
416         }
417     }
418     *outbuf = '\0';
419     return 0;
420 }
421
422 static int scan_string(char *s_native,
423                        yaz_iconv_t t_unicode, yaz_iconv_t t_utf8,
424                        void (*fun)(const char *c, void *data, int num),
425                        void *data, int *num)
426 {
427     char str[1024];
428
429     ucs4_t arg[512];
430     ucs4_t arg_prim[512];
431     ucs4_t *s0, *s = arg;
432     ucs4_t c, begin, end;
433     size_t i;
434
435     if (t_unicode != 0)
436     {
437         char *outbuf = (char *) arg;
438         char *inbuf = s_native;
439         size_t outbytesleft = sizeof(arg)-4;
440         size_t inbytesleft = strlen(s_native);
441         size_t ret;             
442         ret = yaz_iconv(t_unicode, &inbuf, &inbytesleft,
443                         &outbuf, &outbytesleft);
444         if (ret != (size_t)(-1))
445             ret = yaz_iconv(t_unicode, 0, 0, &outbuf, &outbytesleft);
446             
447         if (ret == (size_t)(-1))
448             return -1;
449         i = (outbuf - (char*) arg)/sizeof(ucs4_t);
450     }
451     else
452     { 
453         for (i = 0; s_native[i]; i++)
454             arg[i] = s_native[i] & 255; /* ISO-8859-1 conversion */
455     }
456     arg[i] = 0;      /* terminate */
457     if (s[0] == 0xfeff || s[0] == 0xfeff)  /* skip byte Order Mark */
458         s++;
459     while (*s)
460     {
461         switch (*s)
462         {
463         case '{':
464             s++;
465             begin = zebra_prim_w(&s);
466             if (*s != '-')
467             {
468                 yaz_log(YLOG_FATAL, "Bad range in char-map");
469                 return -1;
470             }
471             s++;
472             end = zebra_prim_w(&s);
473             if (end <= begin)
474             {
475                 yaz_log(YLOG_FATAL, "Bad range in char-map");
476                 return -1;
477             }
478             s++;
479             for (c = begin; c <= end; c++)
480             {
481                 if (scan_to_utf8(t_utf8, &c, 1, str, sizeof(str)-1))
482                     return -1;
483                 (*fun)(str, data, num ? (*num)++ : 0);
484             }
485             break;
486         case '(':
487             ++s;
488             s0 = s; i = 0;
489             while (*s != ')' || s[-1] == '\\')
490                 arg_prim[i++] = zebra_prim_w(&s);
491             arg_prim[i] = 0;
492             if (scan_to_utf8(t_utf8, arg_prim, zebra_ucs4_strlen(arg_prim), str, sizeof(str)-1))
493                 return -1;
494             (*fun)(str, data, num ? (*num)++ : 0);
495             s++;
496             break;
497         default:
498             c = zebra_prim_w(&s);
499             if (scan_to_utf8(t_utf8, &c, 1, str, sizeof(str)-1))
500                 return -1;
501             (*fun)(str, data, num ? (*num)++ : 0);
502         }
503     }
504     return 0;
505 }
506
507 chrmaptab chrmaptab_create(const char *tabpath, const char *name,
508                            const char *tabroot)
509 {
510     FILE *f;
511     char line[512], *argv[50];
512     chrmaptab res;
513     int lineno = 0;
514     int no_directives = 0;
515     int errors = 0;
516     int argc, num = (int) *CHR_BASE, i;
517     NMEM nmem;
518     yaz_iconv_t t_unicode = 0;
519     yaz_iconv_t t_utf8 = 0;
520     unsigned endian = 31;
521     const char *ucs4_native = "UCS-4";
522
523     yaz_log(YLOG_DEBUG, "maptab %s open", name);
524     if (!(f = yaz_fopen(tabpath, name, "r", tabroot)))
525     {
526         yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", name);
527         return 0;
528     }
529
530     if (*(char*) &endian == 31)      /* little endian? */
531         ucs4_native = "UCS-4LE";
532
533     t_utf8 = yaz_iconv_open("UTF-8", ucs4_native);
534
535     nmem = nmem_create();
536     res = (chrmaptab) nmem_malloc(nmem, sizeof(*res));
537     res->nmem = nmem;
538     res->input = (chr_t_entry *) nmem_malloc(res->nmem, sizeof(*res->input));
539     res->input->target = (unsigned char **)
540         nmem_malloc(res->nmem, sizeof(*res->input->target) * 2);
541     res->input->target[0] = (unsigned char*) CHR_UNKNOWN;
542     res->input->target[1] = 0;
543     res->input->children = (chr_t_entry **)
544         nmem_malloc(res->nmem, sizeof(res->input) * 256);
545     for (i = 0; i < 256; i++)
546     {
547         res->input->children[i] = (chr_t_entry *)
548             nmem_malloc(res->nmem, sizeof(*res->input));
549         res->input->children[i]->children = 0;
550         res->input->children[i]->target = (unsigned char **)
551             nmem_malloc(res->nmem, 2 * sizeof(unsigned char *));
552         res->input->children[i]->target[1] = 0;
553         res->input->children[i]->target[0] = (unsigned char*) CHR_UNKNOWN;
554     }
555     res->q_input = (chr_t_entry *)
556         nmem_malloc(res->nmem, sizeof(*res->q_input));
557     res->q_input->target = 0;
558     res->q_input->children = 0;
559
560     for (i = *CHR_BASE; i < 256; i++)
561         res->output[i] = 0;
562     res->output[(int) *CHR_SPACE] = (unsigned char *) " ";
563     res->output[(int) *CHR_UNKNOWN] = (unsigned char*) "@";
564     res->base_uppercase = 0;
565
566     while (!errors && (argc = readconf_line(f, &lineno, line, 512, argv, 50)))
567     {
568         no_directives++;
569         if (!yaz_matchstr(argv[0], "lowercase"))
570         {
571             if (argc != 2)
572             {
573                 yaz_log(YLOG_FATAL, "Syntax error in charmap");
574                 ++errors;
575             }
576             if (scan_string(argv[1], t_unicode, t_utf8, fun_addentry,
577                             res, &num) < 0)
578             {
579                 yaz_log(YLOG_FATAL, "Bad value-set specification");
580                 ++errors;
581             }
582             res->base_uppercase = num;
583             res->output[(int) *CHR_SPACE + num] = (unsigned char *) " ";
584             res->output[(int) *CHR_UNKNOWN + num] = (unsigned char*) "@";
585             num = (int) *CHR_BASE;
586         }
587         else if (!yaz_matchstr(argv[0], "uppercase"))
588         {
589             if (!res->base_uppercase)
590             {
591                 yaz_log(YLOG_FATAL, "Uppercase directive with no lowercase set");
592                 ++errors;
593             }
594             if (argc != 2)
595             {
596                 yaz_log(YLOG_FATAL, "Missing arg for uppercase directive");
597                 ++errors;
598             }
599             if (scan_string(argv[1], t_unicode, t_utf8, fun_addentry,
600                             res, &num) < 0)
601             {
602                 yaz_log(YLOG_FATAL, "Bad value-set specification");
603                 ++errors;
604             }
605         }
606         else if (!yaz_matchstr(argv[0], "space"))
607         {
608             if (argc != 2)
609             {
610                 yaz_log(YLOG_FATAL, "Syntax error in charmap for space");
611                 ++errors;
612             }
613             if (scan_string(argv[1], t_unicode, t_utf8,
614                             fun_addspace, res, 0) < 0)
615             {
616                 yaz_log(YLOG_FATAL, "Bad space specification");
617                 ++errors;
618             }
619         }
620         else if (!yaz_matchstr(argv[0], "cut"))
621         {
622             if (argc != 2)
623             {
624                 yaz_log(YLOG_FATAL, "Syntax error in charmap for cut");
625                 ++errors;
626             }
627             if (scan_string(argv[1], t_unicode, t_utf8,
628                             fun_addcut, res, 0) < 0)
629             {
630                 yaz_log(YLOG_FATAL, "Bad cut specification");
631                 ++errors;
632             }
633         }
634         else if (!yaz_matchstr(argv[0], "map"))
635         {
636             chrwork buf;
637
638             if (argc != 3)
639             {
640                 yaz_log(YLOG_FATAL, "charmap directive map requires 2 args");
641                 ++errors;
642             }
643             buf.map = res;
644             buf.string[0] = '\0';
645             if (scan_string(argv[2], t_unicode, t_utf8,
646                             fun_mkstring, &buf, 0) < 0)
647             {
648                 yaz_log(YLOG_FATAL, "Bad map target");
649                 ++errors;
650             }
651             if (scan_string(argv[1], t_unicode, t_utf8,
652                             fun_add_map, &buf, 0) < 0)
653             {
654                 yaz_log(YLOG_FATAL, "Bad map source");
655                 ++errors;
656             }
657         }
658         else if (!yaz_matchstr(argv[0], "equivalent"))
659         {
660             chr_equiv_work w;
661
662             if (argc != 2)
663             {
664                 yaz_log(YLOG_FATAL, "equivalent requires 1 argument");
665                 ++errors;
666             }
667             w.nmem = res->nmem;
668             w.no_eq = 0;
669             if (scan_string(argv[1], t_unicode, t_utf8, 
670                             fun_add_equivalent_string, &w, 0) < 0)
671             {
672                 yaz_log(YLOG_FATAL, "equivalent: invalid string");
673                 ++errors;
674             }
675             else if (w.no_eq == 0)
676             {
677                 yaz_log(YLOG_FATAL, "equivalent: no strings");
678                 ++errors;
679             }
680             else
681             {
682                 char *result_str;
683                 int i, slen = 5;
684
685                 /* determine length of regular expression */
686                 for (i = 0; i<w.no_eq; i++)
687                     slen += strlen(w.eq[i]) + 1;
688                 result_str = nmem_malloc(res->nmem, slen + 5);
689
690                 /* build the regular expression */
691                 *result_str = '\0';
692                 slen = 0;
693                 for (i = 0; i<w.no_eq; i++)
694                 {
695                     result_str[slen++]  = i ? '|' : '(';
696                     strcpy(result_str + slen, w.eq[i]);
697                     slen += strlen(w.eq[i]);
698                 }
699                 result_str[slen++] = ')';
700                 result_str[slen] = '\0';
701
702                 /* each eq will map to this regular expression */
703                 for (i = 0; i<w.no_eq; i++)
704                 {
705                     set_map_string(res->q_input, res->nmem,
706                                    w.eq[i], strlen(w.eq[i]),
707                                    result_str, 0);
708                 }
709             }
710         }
711         else if (!yaz_matchstr(argv[0], "encoding"))
712         {
713             if (t_unicode != 0)
714                 yaz_iconv_close(t_unicode);
715             t_unicode = yaz_iconv_open(ucs4_native, argv[1]);
716         }
717         else
718         {
719             yaz_log(YLOG_WARN, "Syntax error at '%s' in %s", line, name);
720             errors++;
721         }
722     }   
723     yaz_fclose(f);
724     if (no_directives == 0)
725     {
726         yaz_log(YLOG_WARN, "No directives in '%s'", name);
727         errors++;
728     }
729     if (errors)
730     {
731         chrmaptab_destroy(res);
732         res = 0;
733     }
734     yaz_log(YLOG_DEBUG, "maptab %s close %d errors", name, errors);
735     if (t_utf8 != 0)
736         yaz_iconv_close(t_utf8);
737     if (t_unicode != 0)
738         yaz_iconv_close(t_unicode);
739     return res;
740 }
741
742 void chrmaptab_destroy(chrmaptab tab)
743 {
744     if (tab)
745         nmem_destroy(tab->nmem);
746 }
747
748
749 /*
750  * Local variables:
751  * c-basic-offset: 4
752  * c-file-style: "Stroustrup"
753  * indent-tabs-mode: nil
754  * End:
755  * vim: shiftwidth=4 tabstop=8 expandtab
756  */
757