4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
14 * Neither the name of the NXP Semiconductor nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
46 #include "buildincmd.h"
48 #include "../libuuu/libuuu.h"
59 void linux_auto_arg(const char *space
= " ", const char * filter
= "")
63 const char *param
[] = { "-b", "-d", "-v", "-V", "-s", NULL
};
66 for (int i
= 0; param
[i
]; i
++)
68 if (str
.find(param
[i
]) == string::npos
)
69 cout
<< param
[i
] << space
<< endl
;
73 int linux_autocomplete_ls(const char *path
, void *p
)
75 cout
<< path
+ 2 << endl
;
79 void linux_autocomplete(int argc
, char **argv
)
98 cout
<< cur
<< " " << endl
;
105 if (last
.substr(last
.size() - 3) == "uuu" &&(cur
.empty() || cur
[0] == '-'))
111 }else if(last
.empty())
115 else if (last
== "-b")
117 return g_BuildScripts
.PrintAutoComplete(cur
);
119 }else if(last
[0] == '-')
124 uuu_for_each_ls_file(linux_autocomplete_ls
, cur
.c_str(), NULL
);
127 string
get_next_word(string str
, size_t &pos
)
130 start
= str
.find(' ', pos
);
131 string sub
= str
.substr(pos
, start
- pos
);
132 pos
= start
== string::npos
? start
: start
+ 1;
136 void power_shell_autocomplete(const char *p
)
143 vector
<string
> argv
; string params
;
144 while (pos
!= string::npos
&& pos
< pstr
.size())
146 file
= get_next_word(pstr
, pos
);
147 argv
.push_back(file
);
149 if (file
.size() && file
[0] == '-')
150 params
+= " " + file
;
153 string last
= argv
[argv
.size() - 1];
154 string prev
= argv
.size() > 1 ? argv
[argv
.size() - 2] : "";
155 if (last
== "-b" || prev
== "-b")
161 if (g_BuildScripts
.find(cur
) == g_BuildScripts
.end())
162 g_BuildScripts
.PrintAutoComplete(cur
, "");
168 if (last
[0] == '-' || argv
.size() == 1)
169 linux_auto_arg("", params
.c_str());
172 if (argv
.size() == 1)
175 uuu_for_each_ls_file(linux_autocomplete_ls
, last
.c_str(), NULL
);
178 int auto_complete(int argc
, char**argv
)
180 if (argc
== 4 || argc
== 3)
182 string str
= argv
[1];
184 if (str
.substr(str
.size() - 3) == "uuu")
186 linux_autocomplete(argc
, argv
);
193 string str
= argv
[1];
194 if (str
== "-autocomplete")
196 power_shell_autocomplete(argc
== 2 ? "" : argv
[2]);
204 void print_autocomplete_help()
209 cout
<< "Enjoy auto [tab] command complete by put below script into /etc/bash_completion.d/uuu" << endl
;
211 cout
<< " _uuu_autocomplete()" <<endl
;
212 cout
<< " {" << endl
;
213 cout
<< " COMPREPLY=($(" << TARGET_PATH
<< " $1 $2 $3))" << endl
;
214 cout
<< " }" << endl
;
215 cout
<< " complete -o nospace -F _uuu_autocomplete uuu" << g_vt_default
<< endl
<< endl
;
219 printf("Powershell: Enjoy auto [tab] command complete by run below command or put into Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1\n");
221 HMODULE hModule
= GetModuleHandleA(NULL
);
223 GetModuleFileNameA(hModule
, path
, MAX_PATH
);
225 printf(" Register-ArgumentCompleter -CommandName uuu -ScriptBlock {param($commandName,$parameterName,$wordToComplete,$commandAst,$fakeBoundParameter); %s -autocomplete $parameterName }\n\n",