1 ### vim:ft=zsh:foldmethod=marker
2 ## koders.com source code search backend for lookup
3 ## Copyright: 2009, Frank Terbeck <ft@bewatermyfriend.org>
5 LOOKUP_guard || return 1
6 [[ -n ${lookup_describe} ]] &&
7 printf '%s' 'source code search via koders.com' &&
11 local -a comp_args known_langs
12 local -A known_licences
14 lookup_context="$(LOOKUP_context)"
57 AFL 'Academic Free Licence'
58 AGPLv3 'Affero General Public Licence v3'
59 AL20 'Apache Licence, Version 2.0'
60 ASL 'Apache Software Licence'
61 APSL 'Apple Public Source Licence'
62 BSD 'Berkeley Software Distribution Licence'
63 CPL 'Common Public Licence'
64 EPL10 'Eclipse Public Licence v1.0'
65 GTPL 'Globus Toolkit Public Licence'
66 GPL 'GNU General Public Licence v1 v2 v3'
67 LGPL 'GNU Lesser General Public Licence'
68 IBMPL 'IBM Public Licence'
69 IBMILA 'International Licence Agreement for Non-Warranted Programs'
70 IOSL 'Intel Open Source Licence'
71 MSCL 'Microsoft Community Licence'
72 MSLCL 'Microsoft Limited Community Licence'
73 MSPL 'Microsoft Permissive Licence'
74 MSLPL 'Microsoft Limited Permissive Licence'
75 MSRL 'Microsoft Reference Licence'
76 MSVSSDK 'Microsoft Visual Studio SDK Licence'
77 MITD 'MIT Derived Licence'
78 MPL10 'Mozilla Public Licence Version 1.0'
79 MPL11 'Mozilla Public Licence Version 1.1'
80 NPL10 'Netscape Public Licence, Version 1.0'
81 NPL11 'Netscape Public Licence, Version 1.1'
82 OSL 'Open Software Licence'
84 CNRIPL 'Python Licence'
85 PSFL 'Python Software Foundation Licence'
86 SL 'Sleepycat Software Product Licence'
87 SISSL 'Sun Industry Standards Source Licence'
88 SPL 'Sun Public Licence'
89 W3C 'W3C Software Licence'
90 WXWLL 'wxWindows Library Licence'
91 ZLL 'zlib/libpng Licence'
92 ZPL 'Zope Public Licence'
93 "*" 'Match all licences'
97 LOOKUP_guard -fd LOOKUP_help_${backend} ||
98 function LOOKUP_help_${backend}() {
99 LOOKUP_guard || return 1
105 ls=(${(on)known_langs})
107 printf 'usage: %s <query>\n' ${backend}
108 printf ' -l <lang> limit search to specific language\n'
109 printf ' -L <licence> limit search to specific licence\n'
110 printf '\n Search source code via koders.com\n'
111 printf '\nKnown languages:\n'
112 while (( ${#ls} > 0 )) ; do
113 if (( ${#ls} > i )) ; then
114 print ' ' ${ls[1,$i]}
121 printf '\nKnown licences:\n'
122 for l in ${(kon)known_licences} ; do
123 printf '%8s - %s\n' $l ${known_licences[$l]}
125 printf '\n Per default this backend makes unlimited searches.\n'
126 printf ' Results include code from all languages in all licences.\n'
127 printf '\n You may specify a default language and a default licence via\n'
128 printf ' the default-lang and default-licence styles (both default to '\''*'\''\n'
129 printf ' which means unlimited) in this context: %s\n' ${lookup_context}
130 printf '\nExamples:\n'
131 printf ' %% zstyle '\'':lookup:*:%s:*'\'' default-lang C\n' ${backend}
132 printf ' %% zstyle '\'':lookup:*:%s:*'\'' default-licence BSD\n\n' ${backend}
133 printf ' %% lookup %s strlcpy\n' ${backend}
134 printf ' %% lookup %s -l C handle_keys\n' ${backend}
135 printf ' %% lookup %s -L GPL -l C strlcpy\n\n' ${backend}
137 LOOKUP_help && return 0
139 if [[ -n ${lookup_complete} ]] ; then
141 LOOKUP_guard -fd __lookup_${backend}_langs ||
142 function __lookup_${backend}_langs() {
143 _describe -t koders_langs 'known languages' known_langs
146 LOOKUP_guard -fd __lookup_${backend}_licences ||
147 function __lookup_${backend}_licences() {
152 for l in ${(k)known_licences}; do
153 ls+=("$l:${known_licences[$l]}")
155 _describe -t koders_licences 'known licences' ls
159 '-l[limit search to specific language]:language:__lookup_'${backend}'_langs'
160 '-L[limit search to specific licence]:licence:__lookup_'${backend}'_licences'
161 '*:source code search string:true'
164 _arguments -s -w -A '-*' ${comp_args} && return 0
165 _message 'source code search string'
172 zstyle -s "${lookup_context}" default-lang lang || lang='*'
173 zstyle -s "${lookup_context}" default-licence licence || licence='*'
175 lu_parseopts_args=( l string L string )
176 LOOKUP_parseopts "$@" || return 1
177 [[ -n ${opts[-l]} ]] && lang="${opts[-l]}"
178 [[ -n ${opts[-L]} ]] && licence="${opts[-L]}"
181 LOOKUP_query_handler || return 1
182 if [[ -z ${QUERY} ]] ; then
188 LOOKUP_browser "http://koders.com/default.aspx?s=${QUERY}&la=${lang}&li=${licence}"