summaryrefslogtreecommitdiff
path: root/awk/index_positions.awk
blob: 36e9cbe662d0ec9c6c76c99b6c66b9f10dc74a12 (about) (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
BEGIN {
    FS="|";

    fc_tag = ":" or_default(fc_tag, "fc") ":";
    suspended_tag = ":" or_default(suspended_tag, "suspended") ":";
    review_data_drawer = ":" or_default(review_data_drawer, "REVIEW_DATA") ":";
    type_property = or_default(type_property, "FC_TYPE");
    created_property = or_default(created_property, "FC_CREATED");
}

## Heading Parsing

/^\*+[ \t]+.*$/ {
    # tag re based on org-tag-re
    match($0, /^\*+[ \t]+.*[ \t]+(:([a-zA-Z0-9_@#%]+:)+)$/, a)
    tags = a[1]

    id = "none";

    if (tags ~ fc_tag) {
        in_card = 1;
        suspended = (tags ~ suspended_tag);
    } else {
        in_card = 0;
    }
    next
}

## Property parsing

in_card && /:PROPERTIES:/ {
    in_properties = 1;
    delete properties;
}

in_properties && match($0, /^[ \t]*:([a-zA-Z0-9_]+):[ \t]*(.+)$/, a)  {
    properties[a[1]] = trim_surrounding(a[2]);
}

in_properties && /:END:/ {
    in_properties = 0;
}

## Review data parsing

in_card && $0 ~ review_data_drawer {
    in_data = 1;
}

in_data && /:END:/ {
    in_data = 0;
}

in_data && /^\|.*\|$/ {
    # Make sure we're inside a data block,
    # check NF to skip the |--+--| table separator
    # match on $2 to skip the table header
    if (in_data == 1 && NF == 7 && $2 !~ "position") {
        id = properties["ID"];
        type = properties[type_property];

        position = trim($2);
        ease = trim($3);
        box = trim($4);
        interval = trim($5);
        due      = trim_surrounding($6);
        print FILENAME "\t" id "\t" type "\t" suspended "\t" position "\t" ease "\t" box "\t" interval "\t" due;
    }
}