Simplify vflist_get_formatted()
[geeqie.git] / scripts / template-desktop.sh
1 #! /bin/bash
2
3 # Insert updated menu "Valid sections" list into the desktop template file.
4 # This needs to be run only when the menus have changed.
5
6 tmp_file=$(mktemp)
7 path=$(dirname $(realpath $0))
8 srcpath=$(dirname $path)"/src/layout_util.c"
9 templatepath=$(dirname $path)"/plugins/template.desktop.in"
10
11 awk -v src_path=$srcpath 'BEGIN {
12 menu_flag = 0
13 template_flag = 0
14 i = 0
15 }
16
17 function get_menus()
18 {
19         {while ((getline line < src_path) > 0 )
20                 {
21                 if (line == "\"<ui>\"")
22                         {
23                         menu_flag = 1
24                         }
25                 if (line == "\"<\057ui>\";")
26                         {
27                         menu_flag = 0
28                         }
29                 if (menu_flag >= 1)
30                         {
31                         gsub(/\047|"|\/|<|>/, "", line)
32                         split(line, lineArr, "=")
33
34                         if (index(lineArr[1], "menu action") > 0)
35                                 {
36                                 i = i + 1
37                                 menu[i] = lineArr[2]
38                                 if ( i == 3)
39                                         {
40                                         print "#    " menu[1] "/" menu[2] "/"  lineArr[2]
41                                         }
42                                 if ( i == 2)
43                                         {
44                                         print "#    " menu[1] "/"  lineArr[2]
45                                         }
46                                 if (i == 1)
47                                         {
48                                         print "#    " lineArr[2]
49                                         }
50                                 }
51                         if (index(lineArr[1], "placeholder name"))
52                                 {
53                                 if ( i == 2)
54                                         {
55                                         print "#    " menu[1] "/" menu[2] "/" lineArr[2]
56                                         }
57                                 else
58                                         {
59                                         print "#    "   menu[1] "/" lineArr[2]
60                                         }
61                                 }
62                         gsub(" ", "", line)
63                         if (line == "menu")
64                                 {
65                                 i = i - 1
66                                 }
67                         }
68                 }
69         }
70 }
71
72 /Valid sections/ {template_flag = 1; print; get_menus()}
73 /This is a filter/ {template_flag = 0; print ""}
74 (template_flag == 0) {print}
75 '  $templatepath > $tmp_file
76
77 zenity --text-info < $tmp_file
78 if [ $? == 0 ]
79 then
80         mv $tmp_file  $templatepath
81 else
82         rm $tmp_file
83 fi