File: create_metadata.sh

package info (click to toggle)
darktable 1.0.4-1%2Bdeb7u2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 11,620 kB
  • sloc: ansic: 98,133; cpp: 26,859; xml: 2,202; lisp: 1,940; sh: 720; python: 274; awk: 89; makefile: 83; perl: 57; asm: 46
file content (66 lines) | stat: -rwxr-xr-x 1,227 bytes parent folder | download | duplicates (4)
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
#!/bin/sh

inputfile=$1
outputdir=$2
outputheader=metadata_gen.h
outputbody=metadata_gen.c

headerdefine=__$(printf $outputheader | tr '[:lower:].' '[:upper:]_')__
# header of the .h file
cat > $outputdir/$outputheader << EOF
/** generated file, do not edit! */

#ifndef $headerdefine
#define $headerdefine

typedef enum dt_metadata_t
{
EOF

# header of the .c file
cat > $outputdir/$outputbody << EOF
/** generated file, do not edit! */

#include <string.h>
#include "$outputheader"

dt_metadata_t dt_metadata_get_keyid(const char* key)
{
EOF

# iterate over the input
first=0
for line in $(cat $inputfile | grep -v "^#"); do
    enum=DT_METADATA_$(printf $line | tr '[:lower:].' '[:upper:]_')
    length=$(printf $line | wc -c)
    if [ "$first" -ne 0 ]; then
        printf ",\n" >> $outputdir/$outputheader
    fi
    printf "    $enum" >> $outputdir/$outputheader
    first=1

    cat >> $outputdir/$outputbody << EOF
    if(strncmp(key, "$line", $length) == 0)
        return $enum;
EOF

done

# end of the .h file
cat >> $outputdir/$outputheader << EOF

}
dt_metadata_t;

dt_metadata_t dt_metadata_get_keyid(const char* key);

#endif

EOF

# end of the .c file
cat >> $outputdir/$outputbody << EOF
    return -1;
}

EOF