aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sdp/ao_scan_inserts.d
blob: 9111076785b3ae68567949a4aea506e4f16818d2 (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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
#+OPTIONS: ^:nil _:nil#+OPTIONS: ^:nil _:nil
* sisu_scan_inserts.d
*/
mixin template SiSUdocInserts() {
  class Inserts {
    auto scan_subdoc_source(
      char[][] markup_sourcefile_insert_content, string fn_src, int add
    ) {
      char[][100000] cont_arbitrary_max_length_set_;
      auto ft0 = flag_type.dup;
      auto ft1 = flag_type.dup;
      string[string] processing;
      uint[string] line_occur;
      auto obj_im = new ObjInlineMarkup();
      auto obj_att = new ObjAttrib();
      int[string] counter; counter["add"]=0;
      mixin ScreenTxtColors;
      auto rgx = new Rgx();
      int tell_l(string color, in char[] line) {
        writeln(scr_txt_marker[color], line);
        return 0;
      }
      auto fn_pth_full = match(fn_src, rgx.src_pth);
      auto markup_src_file_path = fn_pth_full.captures[1];
      foreach (line; markup_sourcefile_insert_content) {
        if (ft1["curly_code"] == 1) {
          ft1["header_make"] = 0;
          ft1["header_metadata"] = 0;
          if (auto m = match(line, rgx.block_curly_code_close)) {
            ft1["curly_code"] = 0;
          }
          cont_arbitrary_max_length_set_[counter["add"]] = line;
          ++counter["add"]; ++add;
        } else if (auto m = match(line, rgx.block_curly_code_open)) {
          ft1["curly_code"] = 1;
          ft1["header_make"] = 0;
          ft1["header_metadata"] = 0;
          cont_arbitrary_max_length_set_[counter["add"]] = line;
          ++counter["add"]; ++add;
        } else if (ft1["tic_code"] == 1) {
          ft1["header_make"] = 0;
          ft1["header_metadata"] = 0;
          if (auto m = match(line, rgx.block_tic_close)) {
            ft1["tic_code"] = 0;
          }
          cont_arbitrary_max_length_set_[counter["add"]] = line;
          ++counter["add"]; ++add;
        } else if (auto m = match(line, rgx.block_tic_code_open)) {
          ft1["tic_code"] = 1;
          ft1["header_make"] = 0;
          ft1["header_metadata"] = 0;
          cont_arbitrary_max_length_set_[counter["add"]] = line;
          ++counter["add"]; ++add;
        } else if (
          (ft1["header_make"] == 1) && (line_occur["header_make"] > 0)
          && match(line, rgx.header_sub)
        ) {
            ft1["header_make"] = 1;
            ft1["header_metadata"] = 0;
            ++line_occur["header_make"];
            ++counter["add"];
        } else if (
          (ft1["header_metadata"] == 1) && (line_occur["header_metadata"] > 0)
          && match(line, rgx.header_sub)
        ) {
            ft1["header_metadata"] = 1;
            ft1["header_make"] = 0;
            ++line_occur["header_metadata"];
            ++counter["add"];
        } else if (auto m = match(line, rgx.insert_src_fn_ssi_or_sst)) {
          ft1["header_make"] = 0;
          ft1["header_metadata"] = 0;
          auto insert_fn = m.captures[2];
          auto insert_sub_pth = m.captures[1];
          auto fn_src_insert =
            (markup_src_file_path ~ insert_sub_pth ~ insert_fn);
          auto raw = new MarkupInsertRaw();
          auto markup_sourcesubfile_insert_content =
            raw.markupSourceContentRawLineArray(fn_src_insert);
          debug(insert) {                              // insert file
            tell_l("red", line);
            tell_l("red", fn_src_insert);
            tell_l("fuchsia", "ERROR");
            writeln(
              "  length contents insert array: ",
              markup_sourcesubfile_insert_content.length
            );
          }
            auto ins = new Inserts();
          /*
            1. load file,
            2. read lines;
            3. scan lines,
            4. if filename insert, and insert filename
            5.   repeat 1
            6. else
            7.   add line to new array;
          */
        } else {
          ft1["header_make"] = 0;
          ft1["header_metadata"] = 0;
          cont_arbitrary_max_length_set_[counter["add"]] = line;
          ++counter["add"]; ++add;
        }
      }
      auto contents_ = cont_arbitrary_max_length_set_[0 .. counter["add"]].dup;
      auto t = tuple(contents_, add);
      return t;
    }
    auto scan_doc_source(char[][] markup_sourcefile_content, string fn_src) {
      char[][100000] cont_arbitrary_max_length_set; // 2000 pg * 50 lines
      string[string] processing;
      uint[string] line_occur;
      auto obj_im = new ObjInlineMarkup();
      auto obj_att = new ObjAttrib();
      auto ft = flag_type.dup;
      int add;
      mixin ScreenTxtColors;
      auto rgx = new Rgx();
      int tell_l(string color, in char[] line) {
        writeln(scr_txt_marker[color], line);
        return 0;
      }
      auto fn_pth_full = match(fn_src, rgx.src_pth);
      auto markup_src_file_path = fn_pth_full.captures[1];
      foreach (line; markup_sourcefile_content) {
        if (ft["curly_code"] == 1) {
          ft["header_make"] = 0;
          ft["header_metadata"] = 0;
          if (auto m = match(line, rgx.block_curly_code_close)) {
            ft["curly_code"] = 0;
          }
          cont_arbitrary_max_length_set[add] = line;
          ++add;
        } else if (auto m = match(line, rgx.block_curly_code_open)) {
          ft["curly_code"] = 1;
          ft["header_make"] = 0;
          ft["header_metadata"] = 0;
          cont_arbitrary_max_length_set[add] = line;
          ++add;
        } else if (ft["tic_code"] == 1) {
          ft["header_make"] = 0;
          ft["header_metadata"] = 0;
          if (auto m = match(line, rgx.block_tic_close)) {
            ft["tic_code"] = 0;
          }
          cont_arbitrary_max_length_set[add] = line;
          ++add;
        } else if (auto m = match(line, rgx.block_tic_code_open)) {
          ft["tic_code"] = 1;
          ft["header_make"] = 0;
          ft["header_metadata"] = 0;
          cont_arbitrary_max_length_set[add] = line;
        } else if ((ft["header_make"] == 1)
        && (line_occur["header_make"] > 0)
        && match(line, rgx.header_sub)) {
          ++line_occur["header_make"];
          cont_arbitrary_max_length_set[add] = line;
          ++add;
        } else if ((ft["header_metadata"] == 1)
        && (line_occur["header_metadata"] > 0)
        && match(line, rgx.header_sub)) {
          ++line_occur["header_metadata"];
          cont_arbitrary_max_length_set[add] = line;
          ++add;
        } else if (auto m = match(line, rgx.header_make)) {
          ft["header_make"] = 1;
          ++line_occur["header_make"];
          cont_arbitrary_max_length_set[add] = line;
          ++add;
        } else if (auto m = match(line, rgx.header_metadata)) {
          ft["header_metadata"] = 1;
          ++line_occur["header_metadata"];
          cont_arbitrary_max_length_set[add] = line;
          ++add;
        } else if (auto m = match(line, rgx.insert_src_fn_ssi_or_sst)) {
          ft["header_make"] = 0;
          ft["header_metadata"] = 0;
          auto insert_fn = m.captures[2];
          auto insert_sub_pth = m.captures[1];
          auto fn_src_insert =
            (markup_src_file_path ~ insert_sub_pth ~ insert_fn);
          auto raw = new MarkupInsertRaw();
          auto markup_sourcefile_insert_content =
            raw.markupSourceContentRawLineArray(fn_src_insert);
          debug(insert) {                              // insert file
            tell_l("red", line);
            tell_l("red", fn_src_insert);
            writeln(
              "  length contents insert array: ",
              markup_sourcefile_insert_content.length
            );
          }
            auto ins = new Inserts();
            auto t = ins.scan_subdoc_source(
              markup_sourcefile_insert_content, to!string(fn_src_insert), add
            );
            static assert(!isTypeTuple!(t));
            auto tmparr = t[0];
            auto addsub = t[1];
            cont_arbitrary_max_length_set[add .. addsub-1] = tmparr[0 .. $-1];
            add=addsub;
          /*
            1. load file,
            2. read lines;
            3. scan lines,
            4. if filename insert, and insert filename
            5.   repeat 1
            6. else
            7.   add line to new array;
          */
        } else {
          ft["header_make"] = 0;
          ft["header_metadata"] = 0;
          cont_arbitrary_max_length_set[add] = line;
          ++add;
        }
      }
      auto contents = cont_arbitrary_max_length_set[0..add].dup;
      debug(insert) {                              // insert file
        writeln(__LINE__);
        writeln(contents.length);
        writeln(add);
      }
      return contents;
    }
  }
}