File: keybinding2docbook.awk

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 (91 lines) | stat: -rw-r--r-- 2,837 bytes parent folder | download | duplicates (8)
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
BEGIN {
  FS = ";"
  print "#include <stdlib.h>"
  print "#include <string.h>"
  print "#include <stdio.h>"
  print "#include <gtk/gtk.h>"
  print "#include <gdk/gdkkeysyms.h>"
  print "struct accel{ char *path; char *key; };"
  print "gint compare(gconstpointer a, gconstpointer b){"
  print "  const char *sa = ((struct accel*)a)->path;"
  print "  const char *sb = ((struct accel*)b)->path;"
  print "  return strcasecmp(sa, sb);"
  print "}"
  print "int main(int argc, char *argv[])"
  print "{"
  print "  GSList *accels = NULL;"
  print "  struct accel *acc;"
  print "  char buffer[1024];"
  print "  char *s, *d, *temp;"
}

/^"[^"]+";[^;]+;/{
  print "  acc = (struct accel*)malloc(sizeof(struct accel));"
  print "  s = temp = strdup(" $1 ");"
  print "  d = buffer;"
  print "  while(*s != '\\0')"
  print "  {"
  print "    if(*s == '<')"
  print "    {"
  print "      *d = '&';d++;*d = 'l';d++;*d = 't';d++;*d = ';';"
  print "    }"
  print "    else if(*s == '>')"
  print "    {"
  print "      *d = '&';d++;*d = 'g';d++;*d = 't';d++;*d = ';';"
  print "    }"
  print "    else"
  print "    {"
  print "      *d = *s;"
  print "    }"
  print "    d++; s++;"
  print "  }"
  print "  *d = '\\0';"
  print "  acc->path = strdup(buffer);"
  print "  free(temp);"
  print "  s = temp = strdup(gtk_accelerator_name(" $2 "," $3 "));"
  print "  d = buffer;"
  print "  while(*s != '\\0')"
  print "  {"
  print "    if(*s == '<')"
  print "    {"
  print "      *d = '&';d++;*d = 'l';d++;*d = 't';d++;*d = ';';"
  print "    }"
  print "    else if(*s == '>')"
  print "    {"
  print "      *d = '&';d++;*d = 'g';d++;*d = 't';d++;*d = ';';"
  print "    }"
  print "    else"
  print "    {"
  print "      *d = *s;"
  print "    }"
  print "    d++; s++;"
  print "  }"
  print "  *d = '\\0';"
  print "  acc->key = strdup(buffer);"
  print "  free(temp);"
  print "  accels = g_slist_insert_sorted(accels, acc, compare);"
}

END {
  print "  printf(\"<informaltable frame=\\\"none\\\"><tgroup cols=\\\"2\\\" colsep=\\\"0\\\" rowsep=\\\"0\\\">\\n\");"
  print "  printf(\"%s\\n\",\"<colspec colwidth=\\\"100%\\\"/>\");"
  print "  printf(\"<colspec colwidth=\\\"5cm\\\"/>\\n\");"
  print "  printf(\"<tbody>\\n\");"
  print "  while(accels){"
  print "    acc = (struct accel*)accels->data;"
  print "    printf(\"<row>\\n\");"
  print "    printf(\"<entry>\\n\");"
  print "    printf(\"%s\\n\", acc->path);"
  print "    printf(\"</entry>\\n\");"
  print "    printf(\"<entry>\\n\");"
  print "    printf(\"%s\\n\", acc->key);"
  print "    printf(\"</entry>\\n\");"
  print "    printf(\"</row>\\n\");"
  print "    accels = g_slist_next(accels);"
  print "  }"
  print "  printf(\"</tbody>\\n\");"
  print "  printf(\"</tgroup>\\n\");"
  print "  printf(\"</informaltable>\\n\");"
  print "  return 0;"
  print "}"
}