1 #!/usr/local/bin/gawk -f
3 # This script creates an .xml file from a .txt file
4 # The .txt file should come from an MS-Word .doc file
5 # The .txt file must be saved with the 'LF only' option
6 # (Even with this option, ^M may remain in the .txt file. In this case,
7 # it is necessary to remove them manually).
8 # The .doc file must be well-formed
18 filexml =
"YAG_introduction.xml";
21 printf ("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n") > filexml
;
24 if ((int
($
1) >=
1) && (int
($
1) <=
9)) {
27 level =
split ($
1, word
, ".");
31 while (section_opened
> 0) {
32 printf ("</section>\n\n") > filexml
;
35 if (chapter_opened ==
1) {
36 printf ("</chapter>\n\n\n") > filexml
;
39 printf ("<chapter>\n") > filexml
;
44 if (list_opened ==
1) {
45 printf ("</list>\n") > filexml
;
48 while (section_opened
> level
- 1) {
49 printf ("</section>\n\n") > filexml
;
52 printf ("<section niv='%d'><title>", level
) > filexml
;
53 for (i =
2; i
< NF; i
++) printf ("%s ", $i
) > filexml
;
54 printf ("%s</title>\n", $
NF) > filexml
;
60 if (length ($
0) > 0) {
64 if (list_opened ==
0) {
65 printf ("<list>\n") > filexml
;
68 printf ("<item>", level
) > filexml
;
69 for (i =
2; i
< NF; i
++) printf ("%s ", $i
) > filexml
;
70 printf ("%s</item>\n", $
NF) > filexml
;
75 if (list_opened ==
1) {
76 printf ("</list>\n") > filexml
;
79 printf ("<p>%s</p>\n", $
0) > filexml
;
89 while (section_opened
> 0) {
90 printf ("</section>\n\n") > filexml
;
93 if (chapter_opened ==
1) {
94 printf ("</chapter>\n\n\n") > filexml
;