• R/O
  • SSH
  • HTTPS

hamigaki: コミット


コミットメタ情報

リビジョン1778 (tree)
日時2010-10-23 11:19:59
作者hamigaki

ログメッセージ

added some builtin rules
-FILE_OPEN
-HDRMACRO
-IMPORTED_MODULES
-MD5
-NEAREST_USER_LOCATION
-PAD
-PRECIOUS
-SEARCH_FOR_TARGET
-SELF_PATH
-UPDATE_NOW
-USER_MODULE
-W32_GETREGNAMES

変更サマリ

差分

--- hamigaki/trunk/libs/bjam/test/builtin_rules_test.cpp (revision 1777)
+++ hamigaki/trunk/libs/bjam/test/builtin_rules_test.cpp (revision 1778)
@@ -16,6 +16,11 @@
1616 #include <boost/none.hpp>
1717 #include <cstdlib>
1818
19+#if defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
20+ #include <io.h>
21+#endif
22+#include <fcntl.h>
23+
1924 namespace bjam = hamigaki::bjam;
2025 namespace ut = boost::unit_test;
2126
@@ -366,10 +371,13 @@
366371 ("EXIT")
367372 ("EXPORT")
368373 ("FAIL_EXPECTED")
374+ ("FILE_OPEN")
369375 ("GLOB")
370376 ("GLOB-RECURSIVELY")
371377 ("HAS_NATIVE_RULE")
378+ ("HDRMACRO")
372379 ("IMPORT")
380+ ("IMPORTED_MODULES")
373381 ("IMPORT_MODULE")
374382 ("INCLUDES")
375383 ("INSTANCE")
@@ -376,23 +384,32 @@
376384 ("ISFILE")
377385 ("LEAVES")
378386 ("MATCH")
387+ ("MD5")
379388 ("NATIVE_RULE")
389+ ("NEAREST_USER_LOCATION")
380390 ("NOCARE")
381391 ("NORMALIZE_PATH")
382392 ("NOTFILE")
383393 ("NOUPDATE")
394+ ("PAD")
395+ ("PRECIOUS")
384396 ("PWD")
385397 ("REBUILDS")
386398 ("RMOLD")
387399 ("RULENAMES")
400+ ("SEARCH_FOR_TARGET")
401+ ("SELF_PATH")
388402 ("SHELL")
389403 ("SORT")
390404 ("SUBST")
391405 ("TEMPORARY")
392406 ("UPDATE")
407+ ("UPDATE_NOW")
408+ ("USER_MODULE")
393409 ("VARNAMES")
394410 #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
395411 ("W32_GETREG")
412+ ("W32_GETREGNAMES")
396413 #endif
397414 ;
398415 result = ctx.invoke_rule("RULENAMES", args);
@@ -569,6 +586,25 @@
569586 result.begin(), result.end(), expect.begin(), expect.end());
570587 }
571588
589+void imported_modules_test()
590+{
591+ bjam::context ctx;
592+ bjam::list_of_list args;
593+
594+ args.push_back(boost::assign::list_of("m1")("m2"));
595+ args.push_back(boost::assign::list_of("m3"));
596+ ctx.invoke_rule("IMPORT_MODULE", args);
597+
598+ args.clear();
599+ args.push_back(boost::assign::list_of("m3"));
600+
601+ bjam::string_list expect = boost::assign::list_of("m1")("m2");
602+ const bjam::string_list& result = ctx.invoke_rule("IMPORTED_MODULES", args);
603+
604+ BOOST_CHECK_EQUAL_COLLECTIONS(
605+ result.begin(), result.end(), expect.begin(), expect.end());
606+}
607+
572608 void instance_test()
573609 {
574610 bjam::context ctx;
@@ -657,6 +693,21 @@
657693 // TODO: add the positive tests
658694 }
659695
696+void user_module_test()
697+{
698+ bjam::context ctx;
699+ bjam::list_of_list args;
700+
701+ const std::string m1("m1");
702+
703+ BOOST_CHECK(!ctx.get_module(m1).user_module);
704+
705+ args.push_back(boost::assign::list_of(m1));
706+ BOOST_CHECK(ctx.invoke_rule("USER_MODULE", args).empty());
707+
708+ BOOST_CHECK(ctx.get_module(m1).user_module);
709+}
710+
660711 void check_if_file_test()
661712 {
662713 bjam::context ctx;
@@ -698,8 +749,10 @@
698749 // should use SHGetSpecialFolderPath()
699750 std::string prog_dir(win_dir, 0, 3);
700751 prog_dir += "Program Files";
752+#if !defined(_WIN64)
701753 if (get_native_system_arch() != 0)
702754 prog_dir += " (x86)";
755+#endif
703756
704757 ::OSVERSIONINFOA info;
705758 std::memset(&info, 0, sizeof(info));
@@ -714,8 +767,8 @@
714767
715768 args.push_back(boost::assign::list_of
716769 ("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion")
717- ("ProgramFilesDir")
718770 );
771+ args.push_back(boost::assign::list_of("ProgramFilesDir"));
719772 result = ctx.invoke_rule("W32_GETREG", args);
720773 BOOST_CHECK_EQUAL(result.size(), 1u);
721774 if (!result.empty())
@@ -729,8 +782,8 @@
729782 args.clear();
730783 args.push_back(boost::assign::list_of
731784 ("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion")
732- ("ProgramFilesPath")
733785 );
786+ args.push_back(boost::assign::list_of("ProgramFilesPath"));
734787 result = ctx.invoke_rule("W32_GETREG", args);
735788 BOOST_CHECK_EQUAL(result.size(), 1u);
736789 if (!result.empty())
@@ -751,8 +804,8 @@
751804 args.clear();
752805 args.push_back(boost::assign::list_of
753806 ("HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon")
754- ("BuildNumber")
755807 );
808+ args.push_back(boost::assign::list_of("BuildNumber"));
756809 result = ctx.invoke_rule("W32_GETREG", args);
757810 BOOST_CHECK_EQUAL(result.size(), 1u);
758811 if (!result.empty())
@@ -762,11 +815,37 @@
762815 args.clear();
763816 args.push_back(boost::assign::list_of
764817 ("HKLM\\HARDWARE\\DESCRIPTION\\System")
765- ("SystemBiosVersion")
766818 );
819+ args.push_back(boost::assign::list_of("SystemBiosVersion"));
767820 result = ctx.invoke_rule("W32_GETREG", args);
768821 BOOST_CHECK(result.size() >= 1);
769822 }
823+
824+void w32_getregnames_test()
825+{
826+ bjam::context ctx;
827+ bjam::list_of_list args;
828+ bjam::string_list result;
829+
830+ args.push_back(boost::assign::list_of
831+ ("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion")
832+ );
833+ args.push_back(boost::assign::list_of("subkeys"));
834+ result = ctx.invoke_rule("W32_GETREGNAMES", args);
835+ BOOST_CHECK(
836+ std::find(result.begin(), result.end(), "Control Panel") != result.end()
837+ );
838+
839+ args.clear();
840+ args.push_back(boost::assign::list_of
841+ ("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion")
842+ );
843+ args.push_back(boost::assign::list_of("values"));
844+ result = ctx.invoke_rule("W32_GETREGNAMES", args);
845+ BOOST_CHECK(
846+ std::find(result.begin(), result.end(), "DevicePath") != result.end()
847+ );
848+}
770849 #endif
771850
772851 void shell_test()
@@ -788,6 +867,84 @@
788867 }
789868 }
790869
870+void md5_test()
871+{
872+ bjam::context ctx;
873+ bjam::list_of_list args;
874+ bjam::string_list result;
875+
876+ args.push_back(boost::assign::list_of("abc"));
877+ result = ctx.invoke_rule("MD5", args);
878+ BOOST_CHECK_EQUAL(result.size(), 1u);
879+ if (!result.empty())
880+ BOOST_CHECK_EQUAL(result[0], "900150983cd24fb0d6963f7d28e17f72");
881+}
882+
883+void file_open_test()
884+{
885+ bjam::context ctx;
886+ bjam::list_of_list args;
887+ bjam::string_list result;
888+
889+ args.push_back(boost::assign::list_of("file_open.txt"));
890+ args.push_back(boost::assign::list_of("w"));
891+ result = ctx.invoke_rule("FILE_OPEN", args);
892+ BOOST_REQUIRE_EQUAL(result.size(), 1u);
893+
894+ int fd = std::atoi(result[0].c_str());
895+ BOOST_REQUIRE_NE(fd, -1);
896+
897+ static const char msg[] = "file_open_test\n";
898+ int n = ::write(fd, msg, sizeof(msg)-1);
899+ BOOST_CHECK_EQUAL(n, static_cast<int>(sizeof(msg)-1));
900+
901+ ::close(fd);
902+
903+
904+ args.clear();
905+ args.push_back(boost::assign::list_of("file_open.txt"));
906+ args.push_back(boost::assign::list_of("r"));
907+ result = ctx.invoke_rule("FILE_OPEN", args);
908+ BOOST_REQUIRE_EQUAL(result.size(), 1u);
909+
910+ fd = std::atoi(result[0].c_str());
911+ BOOST_REQUIRE_NE(fd, -1);
912+
913+ char buf[64];
914+ n = ::read(fd, buf, sizeof(buf));
915+
916+ BOOST_CHECK_EQUAL(n, static_cast<int>(sizeof(msg)-1));
917+ if (n != -1)
918+ BOOST_CHECK_EQUAL(std::string(buf, n), std::string(msg));
919+
920+ ::close(fd);
921+ std::remove("file_open.txt");
922+}
923+
924+void pad_test()
925+{
926+ bjam::context ctx;
927+ bjam::list_of_list args;
928+ bjam::string_list result;
929+
930+ args.push_back(boost::assign::list_of("abc"));
931+ args.push_back(boost::assign::list_of("8"));
932+ result = ctx.invoke_rule("PAD", args);
933+ BOOST_CHECK_EQUAL(result.size(), 1u);
934+ if (!result.empty())
935+ BOOST_CHECK_EQUAL(result[0], "abc ");
936+}
937+
938+void precious_test()
939+{
940+ bjam::context ctx;
941+ bjam::list_of_list args;
942+
943+ args.push_back(boost::assign::list_of("t1"));
944+ BOOST_CHECK(ctx.invoke_rule("PRECIOUS", args).empty());
945+ BOOST_CHECK(ctx.get_target("t1").flags & bjam::target::precious);
946+}
947+
791948 ut::test_suite* init_unit_test_suite(int, char* [])
792949 {
793950 ut::test_suite* test = BOOST_TEST_SUITE("builtin rules test");
@@ -819,6 +976,7 @@
819976 test->add(BOOST_TEST_CASE(&back_trace_test));
820977 test->add(BOOST_TEST_CASE(&pwd_test));
821978 test->add(BOOST_TEST_CASE(&import_module_test));
979+ test->add(BOOST_TEST_CASE(&imported_modules_test));
822980 test->add(BOOST_TEST_CASE(&instance_test));
823981 test->add(BOOST_TEST_CASE(&sort_test));
824982 test->add(BOOST_TEST_CASE(&normalize_path_test));
@@ -825,10 +983,16 @@
825983 test->add(BOOST_TEST_CASE(&calc_test));
826984 test->add(BOOST_TEST_CASE(&native_rule_test));
827985 test->add(BOOST_TEST_CASE(&has_native_rule_test));
986+ test->add(BOOST_TEST_CASE(&user_module_test));
828987 test->add(BOOST_TEST_CASE(&check_if_file_test));
829988 #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
830989 test->add(BOOST_TEST_CASE(&w32_getreg_test));
990+ test->add(BOOST_TEST_CASE(&w32_getregnames_test));
831991 #endif
832992 test->add(BOOST_TEST_CASE(&shell_test));
993+ test->add(BOOST_TEST_CASE(&md5_test));
994+ test->add(BOOST_TEST_CASE(&file_open_test));
995+ test->add(BOOST_TEST_CASE(&pad_test));
996+ test->add(BOOST_TEST_CASE(&precious_test));
833997 return test;
834998 }
--- hamigaki/trunk/libs/bjam/src/registry.cpp (revision 1777)
+++ hamigaki/trunk/libs/bjam/src/registry.cpp (revision 1778)
@@ -1,6 +1,6 @@
11 // registry.cpp: Win32 registry utilities
22
3-// Copyright Takeshi Mouri 2007.
3+// Copyright Takeshi Mouri 2007-2010.
44 // Distributed under the Boost Software License, Version 1.0.
55 // (See accompanying file LICENSE_1_0.txt or copy at
66 // http://www.boost.org/LICENSE_1_0.txt)
@@ -154,6 +154,68 @@
154154 return string_list();
155155 }
156156
157+ std::string get_subkey_name(std::size_t i) const
158+ {
159+ char name[256];
160+ DWORD name_size = sizeof(name);
161+
162+ int err = ::RegEnumKeyExA(
163+ handle_, static_cast<DWORD>(i), name, &name_size, 0, 0, 0, 0);
164+
165+ if (err == ERROR_SUCCESS)
166+ return std::string(name);
167+ else
168+ return std::string();
169+ }
170+
171+ string_list get_subkey_names() const
172+ {
173+ if (handle_ == 0)
174+ return string_list();
175+
176+ string_list result;
177+ for (std::size_t i = 0; ; ++i)
178+ {
179+ const std::string& name = get_subkey_name(i);
180+ if (name.empty())
181+ break;
182+ result.push_back(name);
183+ }
184+
185+ return result;
186+ }
187+
188+ std::string get_value_name(std::size_t i) const
189+ {
190+ char name[16384];
191+ DWORD name_size = sizeof(name);
192+
193+ int err = ::RegEnumValueA(
194+ handle_, static_cast<DWORD>(i), name, &name_size, 0, 0, 0, 0);
195+
196+ if (err == ERROR_SUCCESS)
197+ return std::string(name);
198+ else
199+ return std::string();
200+ }
201+
202+ string_list get_value_names() const
203+ {
204+ if (handle_ == 0)
205+ return string_list();
206+
207+ string_list result;
208+ for (std::size_t i = 0; ; ++i)
209+ {
210+ const std::string& name = get_value_name(i);
211+ if (name.empty())
212+ break;
213+ result.push_back(name);
214+ }
215+
216+ return result;
217+ }
218+
157219 private:
158220 ::HKEY handle_;
159221 };
@@ -178,4 +240,38 @@
178240 return reg.get_values(name);
179241 }
180242
243+HAMIGAKI_BJAM_DECL
244+string_list registry_subkey_names(const std::string& key)
245+{
246+ std::string::size_type delim = key.find("\\");
247+
248+ ::HKEY parent = root_key(key.substr(0, delim));
249+ if (parent == 0)
250+ return string_list();
251+
252+ std::string::size_type start = delim;
253+ if (start != std::string::npos)
254+ ++start;
255+
256+ registry_key reg(parent, key.substr(start), KEY_ENUMERATE_SUB_KEYS);
257+ return reg.get_subkey_names();
258+}
259+
260+HAMIGAKI_BJAM_DECL
261+string_list registry_value_names(const std::string& key)
262+{
263+ std::string::size_type delim = key.find("\\");
264+
265+ ::HKEY parent = root_key(key.substr(0, delim));
266+ if (parent == 0)
267+ return string_list();
268+
269+ std::string::size_type start = delim;
270+ if (start != std::string::npos)
271+ ++start;
272+
273+ registry_key reg(parent, key.substr(start), KEY_QUERY_VALUE);
274+ return reg.get_value_names();
275+}
276+
181277 } } } // End namespaces win32, bjam, hamigaki.
--- hamigaki/trunk/libs/bjam/src/bjam_context.cpp (revision 1777)
+++ hamigaki/trunk/libs/bjam/src/bjam_context.cpp (revision 1778)
@@ -1,6 +1,6 @@
11 // bjam_context.cpp: the context information for bjam
22
3-// Copyright Takeshi Mouri 2007, 2008.
3+// Copyright Takeshi Mouri 2007-2010.
44 // Distributed under the Boost Software License, Version 1.0.
55 // (See accompanying file LICENSE_1_0.txt or copy at
66 // http://www.boost.org/LICENSE_1_0.txt)
@@ -316,6 +316,7 @@
316316 f.arguments() = args;
317317 f.filename(rule.filename);
318318 f.line(rule.line);
319+ f.prev_user_frame(old.prev_user_frame());
319320
320321 scoped_push_frame guard(*this, f);
321322 this->change_module(rule.module_name);
--- hamigaki/trunk/libs/bjam/src/builtin_rules.cpp (revision 1777)
+++ hamigaki/trunk/libs/bjam/src/builtin_rules.cpp (revision 1778)
@@ -1,6 +1,6 @@
11 // builtin_rules.cpp: bjam builtin rules
22
3-// Copyright Takeshi Mouri 2007, 2008.
3+// Copyright Takeshi Mouri 2007-2010.
44 // Distributed under the Boost Software License, Version 1.0.
55 // (See accompanying file LICENSE_1_0.txt or copy at
66 // http://www.boost.org/LICENSE_1_0.txt)
@@ -12,10 +12,12 @@
1212 #include <hamigaki/bjam/util/glob.hpp>
1313 #include <hamigaki/bjam/util/path.hpp>
1414 #include <hamigaki/bjam/util/regex.hpp>
15+#include <hamigaki/bjam/util/search.hpp>
1516 #include <hamigaki/bjam/util/shell.hpp>
1617 #include <hamigaki/bjam/bjam_context.hpp>
1718 #include <hamigaki/bjam/builtin_rules.hpp>
1819 #include <hamigaki/bjam/bjam_exceptions.hpp>
20+#include <hamigaki/checksum/md5.hpp>
1921 #include <hamigaki/iterator/first_iterator.hpp>
2022 #include <hamigaki/iterator/ostream_iterator.hpp>
2123 #include <boost/assign/list_of.hpp>
@@ -26,6 +28,7 @@
2628 #include <boost/next_prior.hpp>
2729 #include <boost/regex.hpp>
2830 #include <cstdlib>
31+#include <iomanip>
2932 #include <locale>
3033 #include <sstream>
3134
@@ -33,6 +36,11 @@
3336 #include <hamigaki/bjam/util/win32/registry.hpp>
3437 #endif
3538
39+#if defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
40+ #include <io.h>
41+#endif
42+#include <fcntl.h>
43+
3644 namespace fs = boost::filesystem;
3745
3846 namespace hamigaki { namespace bjam {
@@ -268,6 +276,12 @@
268276 return string_list();
269277 }
270278
279+HAMIGAKI_BJAM_DECL string_list hdr_macro(context& ctx)
280+{
281+ // TODO: not implemented
282+ return string_list();
283+}
284+
271285 HAMIGAKI_BJAM_DECL string_list fail_expected(context& ctx)
272286 {
273287 set_target_flags(ctx, target::fail_expected);
@@ -290,6 +304,22 @@
290304 return old;
291305 }
292306
307+HAMIGAKI_BJAM_DECL string_list update_now(context& ctx)
308+{
309+ frame& f = ctx.current_frame();
310+ const list_of_list& args = f.arguments();
311+ const string_list& arg2 = args[1];
312+ const string_list& arg3 = args[2];
313+
314+ const string_list& targets = args[0];
315+ const boost::optional<std::string>& log = arg2.try_front();
316+ const boost::optional<std::string>& force = arg3.try_front();
317+
318+ // TODO: not implemented
319+
320+ return string_list(std::string("ok"));
321+}
322+
293323 HAMIGAKI_BJAM_DECL string_list subst(context& ctx)
294324 {
295325 frame& f = ctx.current_frame();
@@ -463,6 +493,49 @@
463493 return string_list(ctx.working_directory());
464494 }
465495
496+HAMIGAKI_BJAM_DECL string_list search_for_target(context& ctx)
497+{
498+ frame& f = ctx.current_frame();
499+ const list_of_list& args = f.arguments();
500+
501+ const string_list& targets = args[0];
502+ const string_list& path = args[1];
503+
504+ const std::string& name = targets[0];
505+
506+ path_components compo;
507+ split_path(compo, name);
508+ compo.grist.clear();
509+ compo.member.clear();
510+
511+ bool found = false;
512+ std::string filename;
513+
514+ for (std::size_t i = 0, size = path.size(); i < size; ++i)
515+ {
516+ compo.root = path[i];
517+ filename = make_path(compo);
518+
519+ if (fs::exists(fs::path(filename)))
520+ {
521+ found = true;
522+ break;
523+ }
524+ }
525+
526+ if (!found)
527+ {
528+ compo.root.clear();
529+ fs::path ph(make_path(compo));
530+ fs::path work(ctx.working_directory());
531+ filename = fs::complete(ph, work).file_string();
532+ }
533+
534+ call_bind_rule(ctx, name, filename);
535+
536+ return string_list(name);
537+}
538+
466539 HAMIGAKI_BJAM_DECL string_list import_module(context& ctx)
467540 {
468541 frame& f = ctx.current_frame();
@@ -476,6 +549,19 @@
476549 return string_list();
477550 }
478551
552+HAMIGAKI_BJAM_DECL string_list imported_modules(context& ctx)
553+{
554+ frame& f = ctx.current_frame();
555+ const list_of_list& args = f.arguments();
556+
557+ module& m = ctx.get_module(args[0].try_front());
558+
559+ return string_list(
560+ m.imported_modules.begin(),
561+ m.imported_modules.end()
562+ );
563+}
564+
479565 HAMIGAKI_BJAM_DECL string_list instance(context& ctx)
480566 {
481567 frame& f = ctx.current_frame();
@@ -583,6 +669,44 @@
583669 return string_list();
584670 }
585671
672+HAMIGAKI_BJAM_DECL string_list user_module(context& ctx)
673+{
674+ frame& f = ctx.current_frame();
675+ const list_of_list& args = f.arguments();
676+
677+ const string_list& modules = args[0];
678+ module& m = ctx.get_module(args[0].try_front());
679+
680+ for (std::size_t i = 0, size = modules.size(); i < size; ++i)
681+ {
682+ module& m = ctx.get_module(modules[i]);
683+ m.user_module = true;
684+ }
685+
686+ return string_list();
687+}
688+
689+HAMIGAKI_BJAM_DECL string_list nearest_user_location(context& ctx)
690+{
691+ frame& f = ctx.current_frame();
692+
693+ frame* user_frame =
694+ f.current_module().user_module ? &f : f.prev_user_frame();
695+ if (!user_frame)
696+ return string_list();
697+
698+ string_list result;
699+ result.push_back(user_frame->filename());
700+ {
701+ std::ostringstream os;
702+ os.imbue(std::locale::classic());
703+ os << user_frame->line();
704+ result.push_back(os.str());
705+ }
706+
707+ return result;
708+}
709+
586710 HAMIGAKI_BJAM_DECL string_list check_if_file(context& ctx)
587711 {
588712 frame& f = ctx.current_frame();
@@ -606,13 +730,32 @@
606730 const list_of_list& args = f.arguments();
607731
608732 const string_list& arg1 = args[0];
733+ const string_list& arg2 = args[1];
609734
610- boost::optional<std::string> name;
611- if (arg1.size() >= 2)
612- name = arg1[1];
735+ const std::string& path = arg1[0];
736+ boost::optional<std::string> name = arg2.try_front();
613737
614- return win32::registry_values(arg1[0], name);
738+ return win32::registry_values(path, name);
615739 }
740+
741+HAMIGAKI_BJAM_DECL string_list w32_getregnames(context& ctx)
742+{
743+ frame& f = ctx.current_frame();
744+ const list_of_list& args = f.arguments();
745+
746+ const string_list& arg1 = args[0];
747+ const string_list& arg2 = args[1];
748+
749+ const std::string& path = arg1[0];
750+ const std::string& result_type = arg2[0];
751+
752+ if (result_type == "subkeys")
753+ return win32::registry_subkey_names(path);
754+ else if (result_type == "values")
755+ return win32::registry_value_names(path);
756+ else
757+ return string_list();
758+}
616759 #endif
617760
618761 HAMIGAKI_BJAM_DECL string_list shell(context& ctx)
@@ -636,6 +779,77 @@
636779 return bjam::shell(cmd, need_status, need_capture);
637780 }
638781
782+HAMIGAKI_BJAM_DECL string_list md5(context& ctx)
783+{
784+ frame& f = ctx.current_frame();
785+ const list_of_list& args = f.arguments();
786+
787+ const std::string& s = args[0][0];
788+
789+ checksum::md5 md5;
790+ md5.process_bytes(s.c_str(), s.size());
791+
792+ typedef checksum::md5::value_type value_type;
793+ const value_type& v = md5.checksum();
794+
795+ std::ostringstream os;
796+ os.imbue(std::locale::classic());
797+ os << std::hex << std::setfill('0');
798+ for (std::size_t i = 0; i < value_type::static_size; ++i)
799+ os << std::setw(2) << static_cast<unsigned>(v[i]);
800+
801+ return string_list(os.str());
802+}
803+
804+HAMIGAKI_BJAM_DECL string_list file_open(context& ctx)
805+{
806+ frame& f = ctx.current_frame();
807+ const list_of_list& args = f.arguments();
808+
809+ const std::string& name = args[0][0];
810+ const std::string& mode = args[1][0];
811+
812+ int fd;
813+ if (mode == "w")
814+ fd = ::open(name.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0666);
815+ else
816+ fd = ::open(name.c_str(), O_RDONLY);
817+
818+ if (fd == -1)
819+ return string_list();
820+
821+ std::ostringstream os;
822+ os.imbue(std::locale::classic());
823+ os << fd;
824+ return string_list(os.str());
825+}
826+
827+HAMIGAKI_BJAM_DECL string_list pad(context& ctx)
828+{
829+ frame& f = ctx.current_frame();
830+ const list_of_list& args = f.arguments();
831+
832+ std::string str = args[0][0];
833+ std::size_t width = static_cast<std::size_t>(std::atoi(args[1][0].c_str()));
834+
835+ if (str.size() < width)
836+ str.resize(width, ' ');
837+
838+ return string_list(str);
839+}
840+
841+HAMIGAKI_BJAM_DECL string_list precious(context& ctx)
842+{
843+ set_target_flags(ctx, target::precious);
844+ return string_list();
845+}
846+
847+HAMIGAKI_BJAM_DECL string_list self_path(context& ctx)
848+{
849+ // FIXME
850+ return string_list("bjam");
851+}
852+
639853 } // namespace builtins
640854
641855 HAMIGAKI_BJAM_DECL void set_builtin_rules(context& ctx)
@@ -711,6 +925,10 @@
711925 ctx.set_builtin_rule("ISFILE", params, &builtins::is_file);
712926
713927 params.clear();
928+ ctx.set_builtin_rule("HDRMACRO", params, &builtins::hdr_macro);
929+ ctx.set_builtin_rule("HdrMacro", params, &builtins::hdr_macro, false);
930+
931+ params.clear();
714932 ctx.set_builtin_rule("FAIL_EXPECTED", params, &builtins::fail_expected);
715933
716934 params.clear();
@@ -722,6 +940,12 @@
722940 ctx.set_builtin_rule("UPDATE", params, &builtins::update);
723941
724942 params.clear();
943+ params.push_back(boost::assign::list_of("targets")("*"));
944+ params.push_back(boost::assign::list_of("log")("?"));
945+ params.push_back(boost::assign::list_of("ignore-minus-n")("?"));
946+ ctx.set_builtin_rule("UPDATE_NOW", params, &builtins::update_now);
947+
948+ params.clear();
725949 params.push_back(
726950 boost::assign::list_of("string")("pattern")("replacements")("+"));
727951 ctx.set_builtin_rule("SUBST", params, &builtins::subst);
@@ -755,11 +979,22 @@
755979 ctx.set_builtin_rule("PWD", params, &builtins::pwd);
756980
757981 params.clear();
982+ params.push_back(boost::assign::list_of("target")("*"));
983+ params.push_back(boost::assign::list_of("path")("*"));
984+ ctx.set_builtin_rule(
985+ "SEARCH_FOR_TARGET", params, &builtins::search_for_target);
986+
987+ params.clear();
758988 params.push_back(boost::assign::list_of("modules_to_import")("+"));
759989 params.push_back(boost::assign::list_of("target_module")("?"));
760990 ctx.set_builtin_rule("IMPORT_MODULE", params, &builtins::import_module);
761991
762992 params.clear();
993+ params.push_back(boost::assign::list_of("module")("?"));
994+ ctx.set_builtin_rule(
995+ "IMPORTED_MODULES", params, &builtins::imported_modules);
996+
997+ params.clear();
763998 params.push_back(boost::assign::list_of("instance_module"));
764999 params.push_back(boost::assign::list_of("class_module"));
7651000 ctx.set_builtin_rule("INSTANCE", params, &builtins::instance);
@@ -784,13 +1019,27 @@
7841019 ctx.set_builtin_rule("HAS_NATIVE_RULE", params, &builtins::has_native_rule);
7851020
7861021 params.clear();
1022+ params.push_back(boost::assign::list_of("module")("*"));
1023+ ctx.set_builtin_rule("USER_MODULE", params, &builtins::user_module);
1024+
1025+ params.clear();
1026+ ctx.set_builtin_rule(
1027+ "NEAREST_USER_LOCATION", params, &builtins::nearest_user_location);
1028+
1029+ params.clear();
7871030 params.push_back(boost::assign::list_of("file"));
7881031 ctx.set_builtin_rule("CHECK_IF_FILE", params, &builtins::check_if_file);
7891032
7901033 #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
7911034 params.clear();
792- params.push_back(boost::assign::list_of("key_path")("data")("?"));
1035+ params.push_back(boost::assign::list_of("key_path"));
1036+ params.push_back(boost::assign::list_of("data")("?"));
7931037 ctx.set_builtin_rule("W32_GETREG", params, &builtins::w32_getreg);
1038+
1039+ params.clear();
1040+ params.push_back(boost::assign::list_of("key_path"));
1041+ params.push_back(boost::assign::list_of("result-type"));
1042+ ctx.set_builtin_rule("W32_GETREGNAMES", params, &builtins::w32_getregnames);
7941043 #endif
7951044
7961045 params.clear();
@@ -798,6 +1047,27 @@
7981047 params.push_back(boost::assign::list_of("*"));
7991048 ctx.set_builtin_rule("SHELL", params, &builtins::shell);
8001049 ctx.set_builtin_rule("COMMAND", params, &builtins::shell);
1050+
1051+ params.clear();
1052+ params.push_back(boost::assign::list_of("string"));
1053+ ctx.set_builtin_rule("MD5", params, &builtins::md5);
1054+
1055+ params.clear();
1056+ params.push_back(boost::assign::list_of("name"));
1057+ params.push_back(boost::assign::list_of("mode"));
1058+ ctx.set_builtin_rule("FILE_OPEN", params, &builtins::file_open);
1059+
1060+ params.clear();
1061+ params.push_back(boost::assign::list_of("string"));
1062+ params.push_back(boost::assign::list_of("width"));
1063+ ctx.set_builtin_rule("PAD", params, &builtins::pad);
1064+
1065+ params.clear();
1066+ params.push_back(boost::assign::list_of("targets")("*"));
1067+ ctx.set_builtin_rule("PRECIOUS", params, &builtins::precious);
1068+
1069+ params.clear();
1070+ ctx.set_builtin_rule("SELF_PATH", params, &builtins::self_path);
8011071 }
8021072
8031073 } } // End namespaces bjam, hamigaki.
--- hamigaki/trunk/libs/bjam/src/modules/order.cpp (revision 1777)
+++ hamigaki/trunk/libs/bjam/src/modules/order.cpp (revision 1778)
@@ -1,6 +1,6 @@
11 // order.cpp: bjam order module
22
3-// Copyright Takeshi Mouri 2007.
3+// Copyright Takeshi Mouri 2007-2010.
44 // Distributed under the Boost Software License, Version 1.0.
55 // (See accompanying file LICENSE_1_0.txt or copy at
66 // http://www.boost.org/LICENSE_1_0.txt)
@@ -34,7 +34,7 @@
3434 typedef string_list::const_iterator iter_type;
3535 iter_type it = std::find(objects.begin(), objects.end(), name);
3636 if (it != objects.end())
37- return std::distance(objects.begin(), it);
37+ return static_cast<int>(std::distance(objects.begin(), it));
3838 else
3939 return -1;
4040 }
--- hamigaki/trunk/hamigaki/bjam/builtin_rules.hpp (revision 1777)
+++ hamigaki/trunk/hamigaki/bjam/builtin_rules.hpp (revision 1778)
@@ -1,6 +1,6 @@
11 // builtin_rules.hpp: bjam builtin rules
22
3-// Copyright Takeshi Mouri 2007.
3+// Copyright Takeshi Mouri 2007-2010.
44 // Distributed under the Boost Software License, Version 1.0.
55 // (See accompanying file LICENSE_1_0.txt or copy at
66 // http://www.boost.org/LICENSE_1_0.txt)
@@ -39,10 +39,11 @@
3939 HAMIGAKI_BJAM_DECL string_list no_update(context& ctx);
4040 HAMIGAKI_BJAM_DECL string_list temporary(context& ctx);
4141 HAMIGAKI_BJAM_DECL string_list is_file(context& ctx);
42-
42+HAMIGAKI_BJAM_DECL string_list hdr_macro(context& ctx);
4343 HAMIGAKI_BJAM_DECL string_list fail_expected(context& ctx);
4444 HAMIGAKI_BJAM_DECL string_list rm_old(context& ctx);
4545 HAMIGAKI_BJAM_DECL string_list update(context& ctx);
46+HAMIGAKI_BJAM_DECL string_list update_now(context& ctx);
4647 HAMIGAKI_BJAM_DECL string_list subst(context& ctx);
4748 HAMIGAKI_BJAM_DECL string_list rule_names(context& ctx);
4849 HAMIGAKI_BJAM_DECL string_list var_names(context& ctx);
@@ -52,9 +53,9 @@
5253 HAMIGAKI_BJAM_DECL string_list caller_module(context& ctx);
5354 HAMIGAKI_BJAM_DECL string_list back_trace(context& ctx);
5455 HAMIGAKI_BJAM_DECL string_list pwd(context& ctx);
55-
56+HAMIGAKI_BJAM_DECL string_list search_for_target(context& ctx);
5657 HAMIGAKI_BJAM_DECL string_list import_module(context& ctx);
57-
58+HAMIGAKI_BJAM_DECL string_list imported_modules(context& ctx);
5859 HAMIGAKI_BJAM_DECL string_list instance(context& ctx);
5960 HAMIGAKI_BJAM_DECL string_list sort(context& ctx);
6061 HAMIGAKI_BJAM_DECL string_list normalize_path(context& ctx);
@@ -61,13 +62,22 @@
6162 HAMIGAKI_BJAM_DECL string_list calc(context& ctx);
6263 HAMIGAKI_BJAM_DECL string_list native_rule(context& ctx);
6364 HAMIGAKI_BJAM_DECL string_list has_native_rule(context& ctx);
64-
65+HAMIGAKI_BJAM_DECL string_list user_module(context& ctx);
66+HAMIGAKI_BJAM_DECL string_list nearest_user_location(context& ctx);
6567 HAMIGAKI_BJAM_DECL string_list check_if_file(context& ctx);
6668
6769 #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
6870 HAMIGAKI_BJAM_DECL string_list w32_getreg(context& ctx);
71+HAMIGAKI_BJAM_DECL string_list w32_getregnames(context& ctx);
6972 #endif
7073
74+HAMIGAKI_BJAM_DECL string_list shell(context& ctx);
75+HAMIGAKI_BJAM_DECL string_list md5(context& ctx);
76+HAMIGAKI_BJAM_DECL string_list file_open(context& ctx);
77+HAMIGAKI_BJAM_DECL string_list pad(context& ctx);
78+HAMIGAKI_BJAM_DECL string_list precious(context& ctx);
79+HAMIGAKI_BJAM_DECL string_list self_path(context& ctx);
80+
7181 } // namespace builtins
7282
7383 } } // End namespaces bjam, hamigaki.
--- hamigaki/trunk/hamigaki/bjam/util/win32/registry.hpp (revision 1777)
+++ hamigaki/trunk/hamigaki/bjam/util/win32/registry.hpp (revision 1778)
@@ -1,6 +1,6 @@
11 // registry.hpp: Win32 registry utility
22
3-// Copyright Takeshi Mouri 2007.
3+// Copyright Takeshi Mouri 2007-2010.
44 // Distributed under the Boost Software License, Version 1.0.
55 // (See accompanying file LICENSE_1_0.txt or copy at
66 // http://www.boost.org/LICENSE_1_0.txt)
@@ -24,6 +24,12 @@
2424 string_list registry_values(
2525 const std::string& key, const boost::optional<std::string>& name);
2626
27+HAMIGAKI_BJAM_DECL
28+string_list registry_subkey_names(const std::string& key);
29+
30+HAMIGAKI_BJAM_DECL
31+string_list registry_value_names(const std::string& key);
32+
2733 } } } // End namespaces win32, bjam, hamigaki.
2834
2935 #ifdef BOOST_HAS_ABI_HEADERS
--- hamigaki/trunk/hamigaki/bjam/util/module.hpp (revision 1777)
+++ hamigaki/trunk/hamigaki/bjam/util/module.hpp (revision 1778)
@@ -1,6 +1,6 @@
11 // module.hpp: bjam module
22
3-// Copyright Takeshi Mouri 2007.
3+// Copyright Takeshi Mouri 2007-2010.
44 // Distributed under the Boost Software License, Version 1.0.
55 // (See accompanying file LICENSE_1_0.txt or copy at
66 // http://www.boost.org/LICENSE_1_0.txt)
@@ -25,6 +25,11 @@
2525 boost::optional<std::string> class_module;
2626 std::set<std::string> imported_modules;
2727 std::map<std::string,native_rule> native_rules;
28+ bool user_module;
29+
30+ module() : user_module(false)
31+ {
32+ }
2833 };
2934
3035 } } // End namespaces bjam, hamigaki.
--- hamigaki/trunk/hamigaki/bjam/util/target.hpp (revision 1777)
+++ hamigaki/trunk/hamigaki/bjam/util/target.hpp (revision 1778)
@@ -1,6 +1,6 @@
11 // target.hpp: bjam target
22
3-// Copyright Takeshi Mouri 2007.
3+// Copyright Takeshi Mouri 2007-2010.
44 // Distributed under the Boost Software License, Version 1.0.
55 // (See accompanying file LICENSE_1_0.txt or copy at
66 // http://www.boost.org/LICENSE_1_0.txt)
@@ -26,6 +26,7 @@
2626 static const unsigned rm_old = 0x0040;
2727 static const unsigned fail_expected = 0x0080;
2828 static const unsigned is_file = 0x0100;
29+ static const unsigned precious = 0x0200;
2930
3031 variable_table variables;
3132 std::set<std::string> depended_targets;
--- hamigaki/trunk/hamigaki/bjam/util/frame.hpp (revision 1777)
+++ hamigaki/trunk/hamigaki/bjam/util/frame.hpp (revision 1778)
@@ -1,6 +1,6 @@
11 // frame.hpp: bjam frame
22
3-// Copyright Takeshi Mouri 2007.
3+// Copyright Takeshi Mouri 2007-2010.
44 // Distributed under the Boost Software License, Version 1.0.
55 // (See accompanying file LICENSE_1_0.txt or copy at
66 // http://www.boost.org/LICENSE_1_0.txt)
@@ -18,12 +18,12 @@
1818 struct frame
1919 {
2020 public:
21- explicit frame(module& m) : module_(&m), line_(1)
21+ explicit frame(module& m) : module_(&m), line_(1), prev_user_(0)
2222 {
2323 }
2424
2525 frame(module& m, const boost::optional<std::string>& name)
26- : module_(&m), module_name_(name)
26+ : module_(&m), module_name_(name), prev_user_(0)
2727 {
2828 }
2929
@@ -88,6 +88,21 @@
8888 line_ = n;
8989 }
9090
91+ frame* prev_user_frame()
92+ {
93+ return prev_user_;
94+ }
95+
96+ const frame* prev_user_frame() const
97+ {
98+ return prev_user_;
99+ }
100+
101+ void prev_user_frame(frame* f)
102+ {
103+ prev_user_ = f;
104+ }
105+
91106 private:
92107 module* module_;
93108 boost::optional<std::string> module_name_;
@@ -95,6 +110,7 @@
95110 list_of_list arguments_;
96111 std::string filename_;
97112 int line_;
113+ frame* prev_user_;
98114 };
99115
100116 class scoped_change_filename : private boost::noncopyable
旧リポジトリブラウザで表示