Lines Matching defs:search
436 // if set, limits search to registry keys with the specified Company
445 allocSearchInfoBuffer(SearchInfo *search, int wcharCount)
454 buffer->next = search->_buffer;
455 search->_buffer = buffer;
461 freeSearchInfo(SearchInfo *search)
463 struct _SearchInfoBuffer *b = search->_buffer;
464 search->_buffer = NULL;
489 dumpSearchInfo(SearchInfo *search)
496 #define DEBUG(s) debug(DEBUGNAME(#s) L": %s\n", (search->s) ? (search->s) : L"(null)")
497 #define DEBUG_2(s, sl) _debugStringAndLength((search->s), (search->sl), DEBUGNAME(#s))
498 #define DEBUG_BOOL(s) debug(DEBUGNAME(#s) L": %s\n", (search->s) ? L"True" : L"False")
566 parseCommandLine(SearchInfo *search)
568 if (!search || !search->originalCmdLine) {
572 const wchar_t *argv0End = findArgv0End(search->originalCmdLine, -1);
575 search->restOfCmdLine = argv0End; // will be first space after argv0
576 while (--tail != search->originalCmdLine) {
588 if (tail == search->originalCmdLine && tail[0] == L'"') {
591 // Without special cases, we can now fill in the search struct
593 search->executableLength = -1;
599 search->executable = L"python.exe";
600 search->allowExecutableOverride = true;
601 search->allowDefaults = true;
603 search->executable = L"pythonw.exe";
604 search->allowExecutableOverride = true;
605 search->allowDefaults = true;
606 search->windowed = true;
608 search->executable = L"python_d.exe";
609 search->allowExecutableOverride = true;
610 search->allowDefaults = true;
612 search->executable = L"pythonw_d.exe";
613 search->allowExecutableOverride = true;
614 search->allowDefaults = true;
615 search->windowed = true;
617 search->executable = L"python.exe";
618 search->tag = &tail[6];
619 search->tagLength = tailLen - 6;
620 search->allowExecutableOverride = true;
621 search->oldStyleTag = true;
622 search->allowPyvenvCfg = true;
624 search->executable = L"pythonw.exe";
625 search->tag = &tail[7];
626 search->tagLength = tailLen - 7;
627 search->allowExecutableOverride = true;
628 search->oldStyleTag = true;
629 search->allowPyvenvCfg = true;
630 search->windowed = true;
632 search->executable = tail;
633 search->executableLength = tailLen;
634 search->allowPyvenvCfg = true;
641 const wchar_t *arg = search->restOfCmdLine;
652 search->tag = arg;
653 search->tagLength = argLen;
654 search->oldStyleTag = true;
655 search->restOfCmdLine = tail;
661 search->company = argStart;
662 search->companyLength = (int)(tagStart - argStart);
663 search->tag = tagStart + 1;
665 search->tag = argStart;
667 search->tagLength = (int)(tail - search->tag);
668 search->allowDefaults = false;
669 search->restOfCmdLine = tail;
671 search->list = true;
672 search->restOfCmdLine = tail;
674 search->listPaths = true;
675 search->restOfCmdLine = tail;
677 search->help = true;
688 arg = search->restOfCmdLine;
691 search->scriptFile = arg;
693 ++search->scriptFile;
698 search->scriptFileLength = (int)(arg - search->scriptFile);
706 _decodeShebang(SearchInfo *search, const char *buffer, int bufferLength, bool onlyUtf8, wchar_t **decoded, int *decodedLength)
718 wchar_t *b = allocSearchInfoBuffer(search, wideLen + 1);
756 searchPath(SearchInfo *search, const wchar_t *shebang, int shebangLength)
824 wchar_t *buf = allocSearchInfoBuffer(search, n + 1);
829 search->executablePath = buf;
830 search->executableArgs = &command[commandLength];
831 search->executableArgsLength = shebangLength - commandLength;
875 _findCommand(SearchInfo *search, const wchar_t *command, int commandLength)
884 wchar_t *path = allocSearchInfoBuffer(search, n + 1);
889 search->executablePath = path;
895 _useShebangAsExecutable(SearchInfo *search, const wchar_t *shebang, int shebangLength)
925 wcsncpy_s(script, MAXLEN, search->scriptFile, search->scriptFileLength) ||
936 wchar_t *path = allocSearchInfoBuffer(search, n + 1);
941 search->executablePath = path;
943 search->executableArgs = &shebang[commandLength];
944 search->executableArgsLength = shebangLength - commandLength;
951 checkShebang(SearchInfo *search)
955 if (search->tag || !search->scriptFile) {
959 if (search->scriptFileLength < 0) {
960 search->scriptFileLength = (int)wcsnlen_s(search->scriptFile, MAXLEN);
963 wchar_t *scriptFile = (wchar_t*)malloc(sizeof(wchar_t) * (search->scriptFileLength + 1));
968 wcsncpy_s(scriptFile, search->scriptFileLength + 1,
969 search->scriptFile, search->scriptFileLength);
1023 int exitCode = _decodeShebang(search, start, (int)(b - start + (bytesRead == 0)), onlyUtf8, &shebang, &shebangLength);
1029 // Handle shebangs that we should search PATH for
1030 exitCode = searchPath(search, shebang, shebangLength);
1054 if (_findCommand(search, &command[-6], commandLength + 6)) {
1055 search->executableArgs = &command[commandLength];
1056 search->executableArgsLength = shebangLength - commandLength;
1058 commandLength + 6, &command[-6], search->executablePath);
1062 search->tag = command;
1063 search->tagLength = commandLength;
1066 if (search->tagLength > 4) {
1067 const wchar_t *suffix = &search->tag[search->tagLength - 4];
1069 search->tagLength -= 4;
1074 if (search->tagLength > 2) {
1075 const wchar_t *suffix = &search->tag[search->tagLength - 2];
1077 search->tagLength -= 2;
1080 search->oldStyleTag = true;
1081 search->executableArgs = &command[commandLength];
1082 search->executableArgsLength = shebangLength - commandLength;
1083 if (search->tag && search->tagLength) {
1085 commandLength, command, search->tagLength, search->tag);
1099 if (_findCommand(search, shebang, commandLength)) {
1100 search->executableArgs = &shebang[commandLength];
1101 search->executableArgsLength = shebangLength - commandLength;
1103 commandLength, shebang, search->executablePath);
1109 return _useShebangAsExecutable(search, shebang, shebangLength);
1114 checkDefaults(SearchInfo *search)
1116 if (!search->allowDefaults) {
1121 if (search->tag && search->tagLength && !search->oldStyleTag) {
1129 if (!search->tag || !search->tagLength) {
1132 } else if (0 == wcsncmp(search->tag, L"3", search->tagLength)) {
1135 } else if (0 == wcsncmp(search->tag, L"2", search->tagLength)) {
1139 debug(L"# Cannot select defaults for tag '%.*s'\n", search->tagLength, search->tag);
1153 wchar_t *tag = allocSearchInfoBuffer(search, n + 1);
1160 search->tag = tag;
1161 search->tagLength = n;
1162 search->oldStyleTag = true;
1164 search->company = tag;
1165 search->companyLength = (int)(slash - tag);
1166 search->tag = slash + 1;
1167 search->tagLength = n - (search->companyLength + 1);
1168 search->oldStyleTag = false;
1172 search->lowPriorityTag = true;
1451 _registryReadLegacyEnvironment(const SearchInfo *search, HKEY root, EnvironmentInfo *env, const wchar_t *fallbackArch)
1457 search->executable,
1458 search->executableLength
1464 if (search->windowed) {
1525 _registryReadEnvironment(const SearchInfo *search, HKEY root, EnvironmentInfo *env, const wchar_t *fallbackArch)
1536 return _registryReadLegacyEnvironment(search, root, env, fallbackArch);
1540 if (search->windowed) {
1580 _registrySearchTags(const SearchInfo *search, EnvironmentInfo **result, HKEY root, int sortKey, const wchar_t *company, const wchar_t *fallbackArch)
1598 exitCode = _registryReadEnvironment(search, subkey, env, fallbackArch);
1619 registrySearch(const SearchInfo *search, EnvironmentInfo **result, HKEY root, int sortKey, const wchar_t *fallbackArch)
1633 if (search->limitToCompany && 0 != _compare(search->limitToCompany, -1, buffer, cchBuffer)) {
1639 exitCode = _registrySearchTags(search, result, subkey, sortKey, buffer, fallbackArch);
1652 appxSearch(const SearchInfo *search, EnvironmentInfo **result, const wchar_t *packageFamilyName, const wchar_t *tag, int sortKey)
1656 const wchar_t *exeName = search->executable;
1657 if (!exeName || search->allowExecutableOverride) {
1658 exeName = search->windowed ? L"pythonw.exe" : L"python.exe";
1715 explicitOverrideSearch(const SearchInfo *search, EnvironmentInfo **result)
1717 if (!search->executablePath) {
1726 int exitCode = copyWstr(&env->executablePath, search->executablePath);
1754 virtualenvSearch(const SearchInfo *search, EnvironmentInfo **result)
1760 if (!n || !join(buffer, MAXLEN, L"Scripts") || !join(buffer, MAXLEN, search->executable)) {
1803 // Registry subkey to search
1805 // Registry hive to search
1879 collectEnvironments(const SearchInfo *search, EnvironmentInfo **result)
1890 exitCode = explicitOverrideSearch(search, result);
1895 exitCode = virtualenvSearch(search, result);
1901 if (env && !(search->list || search->listPaths)) {
1907 exitCode = registrySearch(search, result, root, info->sortKey, info->fallbackArch);
1915 if (search->limitToCompany) {
1916 debug(L"# Skipping APPX search due to PYLAUNCHER_LIMIT_TO_COMPANY\n");
1921 exitCode = appxSearch(search, result, info->familyName, info->tag, info->sortKey);
2007 installEnvironment(const SearchInfo *search)
2010 if (!search->tag || !search->tagLength) {
2016 if (!search->oldStyleTag &&
2017 search->company && search->companyLength &&
2018 0 != _compare(search->company, search->companyLength, L"PythonCore", -1)) {
2019 debug(L"# Cannot install for company %.*s\n", search->companyLength, search->company);
2025 if (0 == _compare(search->tag, search->tagLength, info->tag, -1)) {
2079 _companyMatches(const SearchInfo *search, const EnvironmentInfo *env)
2081 if (!search->company || !search->companyLength) {
2084 return 0 == _compare(env->company, -1, search->company, search->companyLength);
2089 _tagMatches(const SearchInfo *search, const EnvironmentInfo *env, int searchTagLength)
2092 searchTagLength = search->tagLength;
2094 if (!search->tag || !searchTagLength) {
2097 return _startsWithSeparated(env->tag, -1, search->tag, searchTagLength, L".-");
2112 _selectEnvironment(const SearchInfo *search, EnvironmentInfo *env, EnvironmentInfo **best)
2116 exitCode = _selectEnvironment(search, env->prev, best);
2124 if (env->highPriority && search->lowPriorityTag) {
2125 // This environment is marked high priority, and the search allows
2133 if (!search->oldStyleTag) {
2134 if (_companyMatches(search, env) && _tagMatches(search, env, -1)) {
2147 int tagLength = search->tagLength;
2150 if (0 == _compareArgument(&search->tag[tagLength - 3], 3, L"-64", 3)) {
2153 } else if (0 == _compareArgument(&search->tag[tagLength - 3], 3, L"-32", 3)) {
2159 if (_tagMatches(search, env, tagLength)) {
2177 selectEnvironment(const SearchInfo *search, EnvironmentInfo *root, EnvironmentInfo **best)
2188 int exitCode = _selectEnvironment(search, root, &result);
2322 calculateCommandLine(const SearchInfo *search, const EnvironmentInfo *launch, wchar_t *buffer, int bufferLength)
2327 // Construct command line from a search override, or else the selected
2329 if (search->executablePath) {
2330 executablePath = search->executablePath;
2336 // only if the search allowed an override.
2337 // Otherwise, use the environment's installDir and the search's default
2339 if (executablePath && search->allowExecutableOverride) {
2354 } else if (!search->executable || !search->executableLength) {
2360 wcsncpy_s(executable, 256, search->executable, search->executableLength);
2389 if (!exitCode && search->executableArgs) {
2390 if (search->executableArgsLength < 0) {
2391 exitCode = wcscat_s(buffer, bufferLength, search->executableArgs);
2392 } else if (search->executableArgsLength > 0) {
2394 if (end < bufferLength - (search->executableArgsLength + 1)) {
2396 search->executableArgs, search->executableArgsLength);
2401 if (!exitCode && search->restOfCmdLine) {
2402 exitCode = wcscat_s(buffer, bufferLength, search->restOfCmdLine);
2441 launchEnvironment(const SearchInfo *search, const EnvironmentInfo *launch, wchar_t *launchCommand)
2537 performSearch(SearchInfo *search, EnvironmentInfo **envs)
2540 int exitCode = parseCommandLine(search);
2547 exitCode = checkShebang(search);
2559 exitCode = checkDefaults(search);
2564 // If debugging is enabled, list our search criteria
2565 dumpSearchInfo(search);
2568 exitCode = collectEnvironments(search, envs);
2582 SearchInfo search = {0};
2597 wchar_t *limitToCompany = allocSearchInfoBuffer(&search, len);
2598 search.limitToCompany = limitToCompany;
2606 search.originalCmdLine = GetCommandLineW();
2608 exitCode = performSearch(&search, &envs);
2614 if (search.help) {
2624 searchExitCode = selectEnvironment(&search, envs, &env);
2627 if (search.list || search.listPaths) {
2628 exitCode = listEnvironments(envs, stdout, search.listPaths, env);
2645 exitCode = installEnvironment(&search);
2649 exitCode = performSearch(&search, &envs);
2653 exitCode = selectEnvironment(&search, envs, &env);
2659 if (!isEnvVarSet(L"PYLAUNCHER_ALLOW_INSTALL") && search.oldStyleTag) {
2679 exitCode = calculateCommandLine(&search, env, launchCommand, sizeof(launchCommand) / sizeof(launchCommand[0]));
2685 exitCode = launchEnvironment(&search, env, launchCommand);
2688 freeSearchInfo(&search);