resource-fork-types 0.1.1

Support for reading common resource fork types in rust
Documentation
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
use binrw::{BinRead, BinReaderExt};
use fourcc::{fourcc, FourCC};
use macintosh_utils::PascalString;
use resource_fork::Resource;
mod serializer;

use serializer::TemplateSerializer;

pub type TemplateItem = (String, FourCC);

#[derive(Debug, serde::Serialize, Resource)]
#[resource(code = "TMPL", include_size = true, include_name = true)]
pub struct Template(pub FourCC, pub Vec<TemplateItem>);

impl Template {
    pub fn to_struct(&self) -> String {
        let mut serializer = TemplateSerializer::new();
        serializer.serialize(self)
    }
}

impl BinRead for Template {
    type Args<'a> = (usize, &'a str);

    fn read_options<R: std::io::Read + std::io::Seek>(
        reader: &mut R,
        _endian: binrw::Endian,
        args: Self::Args<'_>,
    ) -> binrw::BinResult<Self> {
        let mut items = Vec::new();
        let end = reader.stream_position()? + args.0 as u64;
        while end != reader.stream_position()? {
            let label: PascalString = reader.read_be()?;
            let item_type: FourCC = reader.read_be()?;
            items.push((label.contents(), item_type));
        }

        let Ok(code) = args.1.chars().take(4).collect::<String>().try_into() else {
            return Err(binrw::Error::Custom {
                pos: 0,
                err: Box::new("Could not read FourCC for template item"),
            });
        };

        Ok(Self(code, items))
    }
}

trait TemplateType {
    fn simple_type(&self) -> Option<&'static str>;
    fn is_list(&self) -> bool;
    fn list_count_type(&self) -> Option<&'static str>;
}

impl TemplateType for FourCC {
    fn simple_type(&self) -> Option<&'static str> {
        Some(match *self {
            fourcc!("DBYT") => "i8",
            fourcc!("DWRD") => "i16",
            fourcc!("DLNG") => "i32",

            fourcc!("UBYT") => "u8",
            fourcc!("UWRD") => "u16",
            fourcc!("ULNG") => "u32",

            fourcc!("HBYT") => "u8",
            fourcc!("HWRD") => "u16",
            fourcc!("HLNG") => "u32",

            // filler bytes
            fourcc!("FBYT") => "u8",
            fourcc!("FWRD") => "u16",
            fourcc!("FLNG") => "u32",

            fourcc!("RECT") => "resource_fork_types::common::Rect",
            fourcc!("PNT ") => "resource_fork_types::common::Point",

            _ => return None,
        })
    }

    fn is_list(&self) -> bool {
        matches!(
            *self,
            fourcc!("BCNT")
                | fourcc!("OCNT")
                | fourcc!("WCNT")
                | fourcc!("LCNT")
                | fourcc!("ZCNT")
                | fourcc!("LZCT")
                | fourcc!("FCNT")
        )
    }

    fn list_count_type(&self) -> Option<&'static str> {
        Some(match *self {
            fourcc!("BCNT") => "u8",
            fourcc!("LCNT") => "u32",
            fourcc!("ZCNT") => "u16",
            fourcc!("LCNT") => "u32",

            _ => return None,
        })
    }
}

//decode_TMPL(const void* data, size_t size) {
//StringReader r(data, size);

//using Entry = TemplateEntry;
//using Type = Entry::Type;
//using Format = Entry::Format;

//vector<unique_ptr<Entry>> ret;
//vector<vector<unique_ptr<Entry>>*> write_stack;
//write_stack.emplace_back(&ret);
//bool in_bbit_array = false;
//while (!r.eof()) {
//string name = decode_mac_roman(r.readx(r.get_u8()));
//uint32_t type = r.get_u32b();

//if (write_stack.empty()) {
//throw runtime_error("TMPL ended list with no list open");
//}
//auto* entries = write_stack.back();

//if (in_bbit_array && type != 0x42424954) {
//throw runtime_error("BBIT array length is not a multiple of 8");
//}

// //For templates supported by Resorcerer, see http://www.mathemaesthetics.com/ResTemplates.html
//switch (type) {
//case 0x44564452: // DVDR; Resorcerer-only. Divider line with comment (0 bytes)
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::VOID, Format::DECIMAL, 0, 0, 0));
//break;
//case 0x43415345: { // CASE; Resorcerer-only. Symbolic and/or default value (0 bytes)
//         //These appear to be of the format <name>=<value>. <value> is an
// //integer in decimal format or hex (preceded by a $).
//auto tokens = split(name, '=');
//if (tokens.size() != 2) {
//throw runtime_error("CASE entry does not contain exactly one '=' character");
//}
//if (tokens[1].empty()) {
//throw runtime_error("CASE value token is empty");
//}
//name = tokens[0];
//int32_t value = (tokens[1][0] == '$')
//? strtol(&tokens[1][1], nullptr, 16)
//: stol(tokens[1], nullptr, 10);
//entries->back()->case_names.emplace(value, std::move(tokens[0]));
//break;
//}
//case 0x55425954: // UBYT; Resorcerer-only. "unsigned decimal byte"
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::DECIMAL, 1, 0, 0, false));
//break;
//case 0x55575244: // UWRD; Resorcerer-only. "unsigned decimal word"
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::DECIMAL, 2, 0, 0, false));
//break;
//case 0x554C4E47: // ULNG; Resorcerer-only. "unsigned decimal long"
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::DECIMAL, 4, 0, 0, false));
//break;
//case 0x44415445: // DATE; Resorcerer-only. Macintosh System Date/Time (seconds)
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::DATE, 4, 0, 0, false));
//break;
//case 0x44425954: // DBYT; Resorcerer-only. "signed decimal byte"
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::DECIMAL, 1, 0, 0));
//break;
//case 0x44575244: // DWRD; Resorcerer-only. "signed decimal word"
//case 0x52534944: // RSID; Resorcerer-only. "resource ID"
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::DECIMAL, 2, 0, 0));
//break;
//case 0x444C4E47: // DLNG; Resorcerer-only. "signed decimal long"
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::DECIMAL, 4, 0, 0));
//break;
//case 0x48425954: // HBYT; Resorcerer-only. "hex byte"
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::HEX, 1, 0, 0));
//break;
//case 0x48575244: // HWRD; Resorcerer-only. "hex word"
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::HEX, 2, 0, 0));
//break;
//case 0x484C4E47: // HLNG; Resorcerer-only. "hex long"
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::HEX, 4, 0, 0));
//break;
//case 0x46495844: // FIXD; Resorcerer-only. 16:16 Fixed Point Number.
// // .width specifies the width per component (16+16=32)
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::FIXED_POINT, Format::DECIMAL, 2, 0, 0));
//break;
//case 0x504E5420: // PNT ; Resorcerer-only. QuickDraw Point.
// // .width specifies the width per component (16+16=32)
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::POINT_2D, Format::DECIMAL, 2, 0, 0));
//break;
//case 0x41575244: // AWRD; align to 2-byte boundary
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::ALIGNMENT, Format::HEX, 0, 2, 0));
//break;
//case 0x414C4E47: // ALNG; align to 2-byte boundary
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::ALIGNMENT, Format::HEX, 0, 4, 0));
//break;
//case 0x46425954: // FBYT; fill byte
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::ZERO_FILL, Format::HEX, 1, 0, 0));
//break;
//case 0x46575244: // FWRD; fill word
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::ZERO_FILL, Format::HEX, 2, 0, 0));
//break;
//case 0x464C4E47: // FLNG; fill long
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::ZERO_FILL, Format::HEX, 4, 0, 0));
//break;
//case 0x48455844: // HEXD; hex dump
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::EOF_STRING, Format::HEX, 0, 0, 0));
//break;
//case 0x50535452: // PSTR; Pascal string
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::PSTRING, Format::TEXT, 1, 0, 0));
//break;
//case 0x57535452: // WSTR; Pascal string with word-sized length
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::PSTRING, Format::TEXT, 2, 0, 0));
//break;
//case 0x4C535452: // LSTR; Pascal string with long-sized length
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::PSTRING, Format::TEXT, 4, 0, 0));
//break;
//case 0x45535452: // ESTR; even-padded Pascal string
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::PSTRING, Format::TEXT, 1, 2, 0));
//break;
//case 0x4F535452: // OSTR; odd-padded Pascal string
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::PSTRING, Format::TEXT, 1, 2, 1));
//break;
//case 0x43535452: // CSTR; C string (null-terminated)
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::CSTRING, Format::TEXT, 1, 0, 0));
//break;
//case 0x45435354: // ECST; even-padded C string
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::CSTRING, Format::TEXT, 1, 2, 0));
//break;
//case 0x4F435354: // OCST; odd-padded C string
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::CSTRING, Format::TEXT, 1, 2, 1));
//break;
//case 0x424F4F4C: // BOOL; boolean word
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::BOOL, Format::FLAG, 2, 0, 0));
//break;
//case 0x42424954: // BBIT; bit within a word
//if (in_bbit_array) {
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::BOOL, Format::FLAG, 2, 0, 0));
//if (entries->size() == 8) {
//write_stack.pop_back();
//in_bbit_array = false;
//}
//} else {
//entries->emplace_back(make_unique<Entry>("", Type::BITFIELD, Format::FLAG, 1, 0, 0));
//entries = write_stack.emplace_back(&entries->back()->list_entries);
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::BOOL, Format::FLAG, 2, 0, 0));
//in_bbit_array = true;
//}
//break;
//case 0x43484152: // CHAR; ASCII character
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::TEXT, 1, 0, 0));
//break;
//case 0x544E414D: // TNAM; type name
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::INTEGER, Format::TEXT, 4, 0, 0));
//break;
//case 0x52454354: // RECT; QuickDraw Rectangle
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::RECT, Format::DECIMAL, 2, 0, 0));
//break;
//case 0x434F4C52: // COLR; QuickDraw Color RGB Triplet
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::COLOR, Format::HEX, 2, 0, 0, false));
//break;
//case 0x4C53545A: // LSTZ
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::LIST_ZERO_BYTE, Format::FLAG, 0, 0, 0));
//write_stack.emplace_back(&entries->back()->list_entries);
//break;
//case 0x4C535442: // LSTB
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::LIST_EOF, Format::FLAG, 0, 0, 0));
//write_stack.emplace_back(&entries->back()->list_entries);
//break;
//case 0x5A434E54: // ZCNT
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::LIST_ZERO_COUNT, Format::HEX, 2, 0, 0));
//write_stack.emplace_back(&entries->back()->list_entries);
//break;
//case 0x4F434E54: // OCNT
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::LIST_ONE_COUNT, Format::HEX, 2, 0, 0));
//write_stack.emplace_back(&entries->back()->list_entries);
//break;
//case 0x4C434E54: // LCNT; Resorcerer-only. One-based long count of list items
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::LIST_ONE_COUNT, Format::HEX, 4, 0, 0));
//write_stack.emplace_back(&entries->back()->list_entries);
//break;
//case 0x4C535443: { // LSTC
// // ZCNT or OCNT should have already opened the list; make sure that it
// // was the previous command.
//if (write_stack.size() < 2) {
//throw runtime_error("LSTC without preceding ZCNT/OCNT/LCNT in TMPL");
//}
//if (!write_stack.back()->empty()) {
//throw runtime_error("commands between ZCNT/OCNT/LCNT and LSTC");
//}
//auto list_type = write_stack[write_stack.size() - 2]->back()->type;
//if ((list_type != Type::LIST_ZERO_COUNT) && (list_type != Type::LIST_ONE_COUNT)) {
//throw runtime_error("LSTC used for non-ZCNT/OCNT list");
//}
//break;
//}
//case 0x4C535445: // LSTE
//write_stack.pop_back();
//break;
//case 0x50313030: // P100; Pnnn = Pascal string with size 0xnnn / fixed-size Pascal string with NUL-byte padding

// //According to an alert in Resorcerer when editing a resource that uses a template with an odd Pnnn in it,
// //this can either be:
// //- a Pascal string of "0xnnn" characters, prefixed with the length byte (ResEdit)
// //- a Pascal string of "0xnnn - 1" characters, prefixed with the length byte (Resorcerer)

// //As a Pascal string can be at most 255 (0xFF) characters long, if "nnn" is > 0xFF, the remaining bytes are
// //filled with NUL-bytes.

// //This appears to be a bug. Stuffit Expander has a TMPL with a P100
// //field in it, but P100 isn't valid - a 1-byte pstring can only be 0xFF
// //bytes long. It looks like whoever wrote the TMPL mistakely included
// //the length byte here... reading some of the resources that would
// //match the relevant TMPL makes it look like we should treat P100 as if
// //it were P0FF, so that's what we'll do.
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::FIXED_PSTRING, Format::TEXT, 0xFF, 0, 0));
//break;
//default:
//try {
//if ((type & 0xFF000000) == 0x48000000) {
// //             Hnnn (fixed-length hex dump)
//uint16_t width =
//value_for_hex_char(type & 0xFF) |
//(value_for_hex_char((type >> 8) & 0xFF) << 4) |
//(value_for_hex_char((type >> 16) & 0xFF) << 8);
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::STRING, Format::HEX, width, 0, 0));
//} else if ((type & 0xFF000000) == 0x43000000) {
// //         Cnnn (C string with fixed NUL-byte padding)
//uint16_t width =
//value_for_hex_char(type & 0xFF) |
//(value_for_hex_char((type >> 8) & 0xFF) << 4) |
//(value_for_hex_char((type >> 16) & 0xFF) << 8);
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::FIXED_CSTRING, Format::TEXT, width, 0, 0));
//} else if ((type & 0xFFFF0000) == 0x50300000) {
// //     P0nn (Pascal string with fixed NUL-byte padding)
//uint16_t width =
//value_for_hex_char(type & 0xFF) |
//(value_for_hex_char((type >> 8) & 0xFF) << 4);
//entries->emplace_back(make_unique<Entry>(std::move(name), Type::FIXED_PSTRING, Format::TEXT, width, 0, 0));
//} else {
//throw runtime_error("unknown field type: " + string_for_resource_type(type));
//}
//} catch (const out_of_range&) {
//throw runtime_error("unknown field type: " + string_for_resource_type(type));
//}
//}
//}

//if (write_stack.size() != 1) {
//throw runtime_error("unterminated list in TMPL");
//}
//return ret;
//}

pub enum BaseType {
    /// Signed Decimal Byte
    DBYT,
    /// Signed Decimal Word
    DWRD,
    /// Signed Decimal Long
    DLNG,

    /// Unsigned Decimal Byte
    UBYT,
    /// Unsigned Decimal Word
    UWRD,
    /// Unsigned Decimal Long
    ULNG,

    /// Unsigned Hex Byte
    HBYT,
    /// Unsigned Hex Word
    HWRD,
    /// Unsigned Hex Long
    HLNG,

    /// Byte Boolean Flag (low-order bit)
    BFLG,
    /// Word Boolean Flag (low-order bit)
    WFLG,
    /// Long Boolean Flag (low-order bit)
    LFLG,

    /// __Signed__ Resource ID Integer
    RSID,
    /// Boolean Word
    BOOL,
    /// ASCII Character
    CHAR,
    /// Type Name
    TNAM,
    /// Macintosh System Date/Time (seconds)
    DATE,
    /// Modification Date/Time (seconds)
    MDAT,
    /// MacOS System Script Code
    SCPC,
    /// MacOS System Language Code
    LNGC,
    /// MacOS System Region Code/
    RGNC,
    /// QuickDraw Point
    PNT,
    /// QuickDraw Rectangle
    RECT,
    /// QuickDraw Color RGB Triplet
    COLR,
    /// Color Lookup Table Hex Dump
    CLUT,
    /// Single Precision Float
    REAL,
    /// Double Precision Float
    DOUB,
    /// Extended 80-bit SANE Float
    EXTN,
    /// Extended 96-bit SANE Float
    XT96,
    /// THINK C Universal 96-bit Float
    UNIV,
    // 16:16 Fixed Point Number
    FIXD,
    /// 16:16 Fixed Point Number
    FRAC,
    /// 0:16 Fixed Point Small Fraction
    SFRC,
    /// 4:12 Fixed Point Font Width
    FWID,
    /// 1:15 Fixed Point Color Component
    FXYZ,
    /// Pascal String
    PSTR,
    /// Even-Padded Pascal String
    ESTR,
    /// Even Pascal String (pad included)
    PPST,
    /// Pascal String Odd-Padded
    OSTR,
    /// Null-Terminated C String
    CSTR,
    /// Even-Padded C String
    ECST,
    /// C String Odd-Padded
    OCST,
    /// Byte Length String (same as PSTR)
    BSTR,
    /// Word Length String
    WSTR,
    /// Long Length String
    LSTR,
    /// Sized Text Dump
    TXTS,
    /// Pascal String with Fixed Padding
    PVar(usize),
    /// C String with Fixed Padding
    CVar(usize),
    /// Text with Fixed Padding
    TVar(usize),
    /// Byte Length Hex Dump)
    BHEX,
    /// Word Length Hex Dump
    WHEX,
    /// Long Length Hex Dump
    LHEX,
    /// Byte Length - 1 Hex Dump
    BSHX,
    /// Word Length - 2 Hex Dump
    WSHX,
    /// Long Length - 4 Hex Dump
    LSHX,
    /// Fixed-Length Hex Dump
    HVar,
    /// Sized Hex Dump
    HEXS,
    /// Hex Dump
    HEXD,
    /// Offset to SKPE in Byte, inclusive| 1 byte
    BSKP,
    /// Offset to SKPE in Word, inclusive| 2 bytes
    WSKP,
    /// Offset to SKPE in Long, inclusive| 4 bytes
    LSKP,
    /// Offset to SKPE in Byte, exclusive| 1 byte
    BSIZ,
    /// Offset to SKPE in Word, exclusive| 2 bytes
    WSIZ,
    /// Offset to SKPE in Long, exclusive| 4 bytes
    LSIZ,
    /// Symbolic and/or Default Value
    CASE,
    /// Divider Line with Comment
    DVDR,
}

pub enum Marker {
    /// End of Skip or Sizeof
    SKPE,
    /// Begin Counted List Item
    LSTC,
    /// Begin Non-Counted List Item
    LSTB,
    /// Begin Sized List Item
    LSTS,
    /// Begin List Item, Ending in Zero Byte
    LSTZ,
    /// End of any List Item
    LSTE,
    /// List Item is Entire TMPL
    SELF,
    /// Key on Resource ID, Not Data| 0 bytes
    KRID,
    /// Begin Keyed Item for Previous CASE |0 bytes
    KEYB,
    /// End of Keyed Item |0 bytes
    KEYE,
    /// Use Big-Endian Data Parsing
    BDND,
    /// Use Little-Endian Data Parsing
    LNDN,
    /// Declare Filtered Template (with comment)
    FLTR,
}

pub enum List {
    /// Byte Count of List Items
    BCNT(Vec<TemplateItem>),
    /// One-Based Count of List Items
    OCNT(Vec<TemplateItem>),
    /// Word Count of List Items (same as OCNT)
    WCNT(Vec<TemplateItem>),
    /// Long Count of List Items
    LCNT(Vec<TemplateItem>),
    /// Zero-Based Count of List Items
    ZCNT(Vec<TemplateItem>),
    /// Zero-Based Count of List Items
    LZCT(Vec<TemplateItem>),
    /// Fixed Count of List Items
    FCNT(Vec<TemplateItem>),
}

pub enum Key {
    /// Signed Decimal Byte Key| 1 byte
    KBYT,
    /// Signed Decimal Word Key| 2 bytes
    KWRD,
    /// Signed Decimal Long Key| 4 bytes
    KLNG,
    /// Unsigned Decimal Byte Key| 1 byte
    KUBT,
    /// Unsigned Decimal Word Key| 2 bytes
    KUWD,
    /// Unsigned Decimal Long Key| 4 bytes
    KULG,
    /// Unsigned Hex Byte Key| 1 byte
    KHBT,
    /// Unsigned Hex Word Key| 2 bytes
    KHWD,
    /// Unsigned Hex Long Key| 4 bytes
    KHLG,
    /// Single ASCII Character Key| 1 byte
    KCHR,
    /// Four-Character Type Key| 4 bytes
    KTYP,
}

pub enum Alignment {
    /// Align to 2-byte boundary
    AWRD,
    /// Align to 4-byte boundary
    ALNG,
    /// Align to 8-byte boundary
    AL08,
    /// Align to 16-byte boundary
    AL16,
}

pub enum FillerFieldTypes {
    /// Fill Byte
    FBYT,
    /// Fill Word
    FWRD,
    /// Fill Long
    FLNG,
    /// Fill Bytes
    FVar(usize),
}

pub enum BitWise {
    /// Bit Within a Byte
    BBIT,
    /// Bit Field Within a Byte
    BBVar(usize),
    /// Bit Within a Word
    WBIT,
    /// Bit Field Within a Word
    WBVar(usize),
    /// Bit Within a Long
    LBIT,
    /// Bit Field Within a Long
    LBnn(usize),
}

pub enum Modifiers {
    /// Insert a Byte When Opening
    PlusBYT,
    /// Insert a Word When Opening
    PlusWRD,
    /// Insert a Long When Opening
    PlusLNG,
    /// Insert Bytes When Opening
    PlusVar,
    /// Insert a Pascal String When Opening
    PlusPST,
    /// Insert an Even Pascal String When Opening
    PlusEST,
    /// Insert a C String When Opening
    PlusCST,
    /// Delete a Byte When Opening
    MinusBYT,
    /// Delete a Word When Opening
    MinusWRD,
    /// Delete a Long When Opening
    MinusLNG,
    /// Delete Bytes When Opening
    MinusVar,
    /// Delete a Pascal String When Opening
    MinusPST,
    /// Delete an Even Pascal String When Opening
    MinusEST,
    /// Delete a C String When Opening
    MinusCST,
}