9 main (int argc, char **argv)
17 Mutf_8 = msymbol ("utf-8");
18 for (i = 1; i < argc; i++)
20 if (strcmp (argv[i], "--sp-cm") == 0)
21 option |= MTEXT_LBO_SP_CM;
22 else if (strcmp (argv[i], "--korean-sp") == 0)
23 option |= MTEXT_LBO_KOREAN_SP;
24 else if (strcmp (argv[i], "--ai-as-id") == 0)
25 option |= MTEXT_LBO_AI_AS_ID;
28 printf ("Usage: linebreak [--sp-cm] [--korean-sp] [--ai-as-id]\n");
33 while (fgets (buf, 256, stdin) != NULL)
35 int len = strlen (buf);
37 int pos, last_pos = -1;
39 if (buf[len - 1] == '\n')
42 mt1 = mconv_decode_buffer (msymbol ("utf-8"), (unsigned char *) buf, len);
43 pos = mtext_len (mt1) - 1;
44 while ((pos = mtext_character (mt1, pos, 0, '\\')) >= 0)
46 if (mtext_ref_char (mt1, pos + 1) == 'n')
48 mtext_del (mt1, pos + 1, pos + 2);
49 mtext_set_char (mt1, pos, '\n');
52 pos = mtext_len (mt1);
53 mt2 = mtext_dup (mt1);
56 int break_pos = mtext_line_break (mt1, pos, option, NULL);
60 if (break_pos != last_pos)
62 mtext_ins_char (mt2, break_pos, '|', 1);
68 pos = mtext_len (mt2) - 1;
69 while ((pos = mtext_character (mt2, pos, 0, '\n')) >= 0)
71 mtext_set_char (mt2, pos, '\\');
72 mtext_ins_char (mt2, pos + 1, 'n', 1);
75 mconv_encode_stream (Mutf_8, mt2, stdout);
77 m17n_object_unref (mt1);
78 m17n_object_unref (mt2);