]> pd.if.org Git - zpackage/blob - zpm-contents
fix printf format string
[zpackage] / zpm-contents
1 #!/bin/sh
2
3 pkgfile=${ZPMDB:-/var/lib/zpm/db.zpm}
4
5 long=0
6 pkgonly=0
7 quiet=0
8 config=include
9
10 while getopts f:qlncC opt; do
11         case $opt in
12                 f) pkgfile="$OPTARG" ;;
13                 l) long=1 ;;
14                 n) pkgonly=1 ;;
15                 q) quiet=1 ;;
16                 c) config=only ;;
17                 C) config=exclude ;;
18         esac
19 done
20 shift $((OPTIND - 1))
21
22 if [ ! -f $pkgfile ]; then
23         echo cannot find $pkgfile
24         exit 1
25 fi
26
27 if [ $long -gt 0 ]; then
28         cols="filetype,printf('%.4s', mode) as mode,username,groupname,"
29 fi
30
31 if [ $pkgonly -eq 1 ]; then
32         cols="pkgid"
33 elif [ $quiet -eq 0 ]; then
34         cols="pkgid,$cols"
35 fi
36
37 pkglist=
38 while [ $# -gt 0 ]; do
39         pkg=$1
40         shift
41         if [ "$pkg" = '--' ]; then
42                 break;
43         fi
44
45         pkgid=$(zpm findpkg -f $pkgfile "$pkg")
46         if [ -n "$pkgid" ]; then
47                 q=$(zpm quote -q "$pkgid")
48                 pkglist=",$q"
49         else
50                 warn "package $pkg not found, ignoring"
51         fi
52 done
53 pkglist=${pkglist#,}
54
55 globlist=
56 for glob in "$@"; do
57         q=$(zpm quote -q "$glob")
58         globlist="or path glob $q"
59 done
60 globlist=${globlist#'or '}
61
62 cols=${cols%,}
63
64 {
65         printf '.separator " "\n'
66         printf 'select %s\n' "$cols"
67
68         if [ $pkgonly -eq 0 ]; then
69                 if [ -n "$cols" ]; then
70                         printf ', '
71                 fi
72
73                 printf "case\n";
74                 printf "when filetype = 'd' then rtrim(path,'/') || '/'\n"
75                 printf "when filetype = 'l' then printf('%%s -> %%s', path, target)\n"
76                 printf "else path end as path\n"
77         fi
78         printf 'from packagefiles_pkgid\nwhere true\n'
79         if [ -n "$globlist" ]; then
80                 printf "and (%s)\n" "$globlist"
81         fi
82         if [ -n "$pkglist" ]; then
83                 printf "and pkgid in (%s)\n" "$pkglist"
84         fi
85         case $config in
86                 only) printf "and configuration = 1\n" ;;
87                 exclude) printf "and configuration = 0\n" ;;
88         esac
89         printf 'order by pkgid,path\n'
90         printf ';\n'
91 } | zpm shell $pkgfile
92 #} | cat