void for_each_in_search_path(bool (*callback)(const char *, size_t, void *), void *callback_data) { const char *search_path = get_search_path(); for_each_colon_separated(search_path, callback, callback_data); }
void test_plat_get_search_path() { int ret; char output[PATH_MAX]; putenv("CHEWING_PATH=" CHEWING_DATA_PREFIX); ret = get_search_path( output, sizeof(output) ); ok (ret == 0, "get_search_path return 0"); ok (!strcmp(output, CHEWING_DATA_PREFIX), "get_search_path succes"); // TODO plat specific test }
CHEWING_API ChewingContext *chewing_new() { ChewingContext *ctx; int ret; char search_path[PATH_MAX]; char path[PATH_MAX]; ctx = ALC( ChewingContext, 1 ); if ( !ctx ) goto error; ctx->output = ALC ( ChewingOutput, 1 ); if ( !ctx->output ) goto error; ctx->data = allocate_ChewingData(); if ( !ctx->data ) goto error; chewing_Reset( ctx ); ret = get_search_path( search_path, sizeof( search_path ) ); if ( ret ) goto error; ret = find_path_by_files( search_path, DICT_FILES, path, sizeof( path ) ); if ( ret ) goto error; ret = InitDict( ctx->data, path ); if ( ret ) goto error; ret = InitTree( ctx->data, path ); if ( ret ) goto error; ret = InitHash( ctx->data ); if ( !ret ) goto error; ctx->cand_no = 0; ret = find_path_by_files( search_path, SYMBOL_TABLE_FILES, path, sizeof( path ) ); if ( ret ) goto error; ret = InitSymbolTable( ctx->data, path ); if ( ret ) goto error; ret = find_path_by_files( search_path, EASY_SYMBOL_FILES, path, sizeof( path ) ); if ( ret ) goto error; ret = InitEasySymbolInput( ctx->data, path ); if ( ret ) goto error; ret = find_path_by_files( search_path, PINYIN_FILES, path, sizeof( path ) ); if ( ret ) goto error; ret = InitPinyin( ctx->data, path ); if ( !ret ) goto error; return ctx; error: chewing_delete( ctx ); return NULL; }
PyObject * option(PyObject *self, PyObject *args) { long option; int error; PyObject *py_option; py_option = PyTuple_GetItem(args, 0); if (!py_option) return NULL; if (!PyLong_Check(py_option)) goto on_non_integer; option = PyLong_AsLong(py_option); switch (option) { case GIT_OPT_GET_SEARCH_PATH: { PyObject *py_level; py_level = PyTuple_GetItem(args, 1); if (!py_level) return NULL; if (!PyLong_Check(py_level)) goto on_non_integer; return get_search_path(PyLong_AsLong(py_level)); break; } case GIT_OPT_SET_SEARCH_PATH: { PyObject *py_level, *py_path, *tpath; const char *path; int err; py_level = PyTuple_GetItem(args, 1); if (!py_level) return NULL; py_path = PyTuple_GetItem(args, 2); if (!py_path) return NULL; if (!PyLong_Check(py_level)) goto on_non_integer; path = py_str_borrow_c_str(&tpath, py_path, NULL); if (!path) return NULL; err = git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, PyLong_AsLong(py_level), path); Py_DECREF(tpath); if (err < 0) { Error_set(err); return NULL; } Py_RETURN_NONE; break; } case GIT_OPT_GET_MWINDOW_SIZE: { size_t size; error = git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &size); if (error < 0) { Error_set(error); return NULL; } return PyLong_FromSize_t(size); break; } case GIT_OPT_SET_MWINDOW_SIZE: { size_t size; PyObject *py_size; py_size = PyTuple_GetItem(args, 1); if (!py_size) return NULL; if (!PyLong_Check(py_size)) goto on_non_integer; size = PyLong_AsSize_t(py_size); error = git_libgit2_opts(GIT_OPT_SET_MWINDOW_SIZE, size); if (error < 0) { Error_set(error); return NULL; } Py_RETURN_NONE; break; } case GIT_OPT_GET_MWINDOW_MAPPED_LIMIT: { size_t limit; error = git_libgit2_opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, &limit); if (error < 0) { Error_set(error); return NULL; } return PyLong_FromSize_t(limit); break; } case GIT_OPT_SET_MWINDOW_MAPPED_LIMIT: { size_t limit; PyObject *py_limit; py_limit = PyTuple_GetItem(args, 1); if (!py_limit) return NULL; if (!PyLong_Check(py_limit)) goto on_non_integer; limit = PyLong_AsSize_t(py_limit); error = git_libgit2_opts(GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, limit); if (error < 0) { Error_set(error); return NULL; } Py_RETURN_NONE; break; } case GIT_OPT_SET_CACHE_OBJECT_LIMIT: { size_t limit; int object_type; PyObject *py_object_type, *py_limit; py_object_type = PyTuple_GetItem(args, 1); if (!py_object_type) return NULL; py_limit = PyTuple_GetItem(args, 2); if (!py_limit) return NULL; if (!PyLong_Check(py_limit)) goto on_non_integer; object_type = PyLong_AsLong(py_object_type); limit = PyLong_AsSize_t(py_limit); error = git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, object_type, limit); if (error < 0) { Error_set(error); return NULL; } Py_RETURN_NONE; break; } case GIT_OPT_SET_CACHE_MAX_SIZE: { size_t max_size; PyObject *py_max_size; py_max_size = PyTuple_GetItem(args, 1); if (!py_max_size) return NULL; if (!PyLong_Check(py_max_size)) goto on_non_integer; max_size = PyLong_AsSize_t(py_max_size); error = git_libgit2_opts(GIT_OPT_SET_CACHE_MAX_SIZE, max_size); if (error < 0) { Error_set(error); return NULL; } Py_RETURN_NONE; break; } case GIT_OPT_ENABLE_CACHING: { int flag; PyObject *py_flag; py_flag = PyTuple_GetItem(args, 1); if (!PyLong_Check(py_flag)) goto on_non_integer; flag = PyLong_AsSize_t(py_flag); error = git_libgit2_opts(GIT_OPT_ENABLE_CACHING, flag); if (error < 0) { Error_set(error); return NULL; } Py_RETURN_NONE; break; } case GIT_OPT_GET_CACHED_MEMORY: { size_t current; size_t allowed; PyObject* tup = PyTuple_New(2); error = git_libgit2_opts(GIT_OPT_GET_CACHED_MEMORY, ¤t, &allowed); if (error < 0) { Error_set(error); return NULL; } PyTuple_SetItem(tup, 0, PyLong_FromLong(current)); PyTuple_SetItem(tup, 1, PyLong_FromLong(allowed)); return tup; break; } } PyErr_SetString(PyExc_ValueError, "unknown/unsupported option value"); return NULL; on_non_integer: PyErr_SetString(PyExc_TypeError, "option is not an integer"); return NULL; }
/*********************************************************************** * OpenFile (KERNEL.74) * OpenFileEx (KERNEL.360) */ HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode ) { HFILE hFileRet; HANDLE handle; FILETIME filetime; WORD filedatetime[2]; const char *p, *filename; if (!ofs) return HFILE_ERROR; TRACE("%s %s %s %s%s%s%s%s%s%s%s%s\n",debugstr_a(name), ((mode & 0x3 )==OF_READ)?"OF_READ": ((mode & 0x3 )==OF_WRITE)?"OF_WRITE": ((mode & 0x3 )==OF_READWRITE)?"OF_READWRITE":"unknown", ((mode & 0x70 )==OF_SHARE_COMPAT)?"OF_SHARE_COMPAT": ((mode & 0x70 )==OF_SHARE_DENY_NONE)?"OF_SHARE_DENY_NONE": ((mode & 0x70 )==OF_SHARE_DENY_READ)?"OF_SHARE_DENY_READ": ((mode & 0x70 )==OF_SHARE_DENY_WRITE)?"OF_SHARE_DENY_WRITE": ((mode & 0x70 )==OF_SHARE_EXCLUSIVE)?"OF_SHARE_EXCLUSIVE":"unknown", ((mode & OF_PARSE )==OF_PARSE)?"OF_PARSE ":"", ((mode & OF_DELETE )==OF_DELETE)?"OF_DELETE ":"", ((mode & OF_VERIFY )==OF_VERIFY)?"OF_VERIFY ":"", ((mode & OF_SEARCH )==OF_SEARCH)?"OF_SEARCH ":"", ((mode & OF_CANCEL )==OF_CANCEL)?"OF_CANCEL ":"", ((mode & OF_CREATE )==OF_CREATE)?"OF_CREATE ":"", ((mode & OF_PROMPT )==OF_PROMPT)?"OF_PROMPT ":"", ((mode & OF_EXIST )==OF_EXIST)?"OF_EXIST ":"", ((mode & OF_REOPEN )==OF_REOPEN)?"OF_REOPEN ":"" ); if (mode & OF_PARSE) { OpenFile( name, ofs, mode ); return 0; } if (mode & OF_CREATE) { handle = (HANDLE)OpenFile( name, ofs, mode ); if (handle == (HANDLE)HFILE_ERROR) goto error; } else { ofs->cBytes = sizeof(OFSTRUCT); ofs->nErrCode = 0; if (mode & OF_REOPEN) name = ofs->szPathName; if (!name) return HFILE_ERROR; /* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName Are there any cases where getting the path here is wrong? Uwe Bonnes 1997 Apr 2 */ if (!GetFullPathNameA( name, sizeof(ofs->szPathName), ofs->szPathName, NULL )) goto error; /* If OF_SEARCH is set, ignore the given path */ filename = name; if ((mode & OF_SEARCH) && !(mode & OF_REOPEN)) { /* First try the file name as is */ if (GetFileAttributesA( filename ) != INVALID_FILE_ATTRIBUTES) filename = NULL; else { /* Now remove the path */ if (filename[0] && (filename[1] == ':')) filename += 2; if ((p = strrchr( filename, '\\' ))) filename = p + 1; if ((p = strrchr( filename, '/' ))) filename = p + 1; if (!filename[0]) { SetLastError( ERROR_FILE_NOT_FOUND ); goto error; } } } /* Now look for the file */ if (filename) { BOOL found; char *path = get_search_path(); if (!path) goto error; found = SearchPathA( path, filename, NULL, sizeof(ofs->szPathName), ofs->szPathName, NULL ); HeapFree( GetProcessHeap(), 0, path ); if (!found) goto error; } TRACE("found %s\n", debugstr_a(ofs->szPathName) ); if (mode & OF_DELETE) { if (!DeleteFileA( ofs->szPathName )) goto error; TRACE("(%s): OF_DELETE return = OK\n", name); return 1; } handle = (HANDLE)_lopen( ofs->szPathName, mode ); if (handle == INVALID_HANDLE_VALUE) goto error; GetFileTime( handle, NULL, NULL, &filetime ); FileTimeToDosDateTime( &filetime, &filedatetime[0], &filedatetime[1] ); if ((mode & OF_VERIFY) && (mode & OF_REOPEN)) { if (ofs->Reserved1 != filedatetime[0] || ofs->Reserved2 != filedatetime[1] ) { CloseHandle( handle ); WARN("(%s): OF_VERIFY failed\n", name ); /* FIXME: what error here? */ SetLastError( ERROR_FILE_NOT_FOUND ); goto error; } } ofs->Reserved1 = filedatetime[0]; ofs->Reserved2 = filedatetime[1]; } TRACE("(%s): OK, return = %p\n", name, handle ); hFileRet = Win32HandleToDosFileHandle( handle ); if (hFileRet == HFILE_ERROR16) goto error; if (mode & OF_EXIST) _lclose16( hFileRet ); /* Return the handle, but close it first */ return hFileRet; error: /* We get here if there was an error opening the file */ ofs->nErrCode = GetLastError(); WARN("(%s): return = HFILE_ERROR error= %d\n", name,ofs->nErrCode ); return HFILE_ERROR16; }
PyObject * option(PyObject *self, PyObject *args) { long option; int error; PyObject *py_option; py_option = PyTuple_GetItem(args, 0); if (!py_option) return NULL; if (!PyLong_Check(py_option)) goto on_non_integer; option = PyLong_AsLong(py_option); switch (option) { case GIT_OPT_GET_SEARCH_PATH: { PyObject *py_level; py_level = PyTuple_GetItem(args, 1); if (!py_level) return NULL; if (!PyLong_Check(py_level)) goto on_non_integer; return get_search_path(PyLong_AsLong(py_level)); break; } case GIT_OPT_SET_SEARCH_PATH: { PyObject *py_level, *py_path, *tpath; const char *path; int err; py_level = PyTuple_GetItem(args, 1); if (!py_level) return NULL; py_path = PyTuple_GetItem(args, 2); if (!py_path) return NULL; if (!PyLong_Check(py_level)) goto on_non_integer; path = py_str_borrow_c_str(&tpath, py_path, NULL); if (!path) return NULL; err = git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, PyLong_AsLong(py_level), path); Py_DECREF(tpath); if (err < 0) { Error_set(err); return NULL; } Py_RETURN_NONE; break; } case GIT_OPT_GET_MWINDOW_SIZE: { size_t size; error = git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &size); if (error < 0) { Error_set(error); return NULL; } return PyLong_FromSize_t(size); break; } case GIT_OPT_SET_MWINDOW_SIZE: { size_t size; PyObject *py_size; py_size = PyTuple_GetItem(args, 1); if (!py_size) return NULL; if (!PyLong_Check(py_size)) goto on_non_integer; size = PyLong_AsSize_t(py_size); error = git_libgit2_opts(GIT_OPT_SET_MWINDOW_SIZE, size); if (error < 0) { Error_set(error); return NULL; } Py_RETURN_NONE; break; } } PyErr_SetString(PyExc_ValueError, "unknown/unsupported option value"); return NULL; on_non_integer: PyErr_SetString(PyExc_TypeError, "option is not an integer"); return NULL; }
PyObject * option(PyObject *self, PyObject *args) { long option; int error; PyObject *py_option; py_option = PyTuple_GetItem(args, 0); if (!py_option) return NULL; if (!PyInt_Check(py_option)) return Error_type_error( "option should be an integer, got %.200s", py_option); option = PyInt_AsLong(py_option); switch (option) { case GIT_OPT_GET_MWINDOW_SIZE: { size_t size; error = git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &size); if (error < 0) return Error_set(error); return PyInt_FromSize_t(size); } case GIT_OPT_SET_MWINDOW_SIZE: { size_t size; PyObject *py_size; py_size = PyTuple_GetItem(args, 1); if (!py_size) return NULL; if (!PyInt_Check(py_size)) return Error_type_error( "size should be an integer, got %.200s", py_size); size = PyInt_AsSize_t(py_size); error = git_libgit2_opts(GIT_OPT_SET_MWINDOW_SIZE, size); if (error < 0) return Error_set(error); Py_RETURN_NONE; } case GIT_OPT_GET_MWINDOW_MAPPED_LIMIT: { size_t limit; error = git_libgit2_opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, &limit); if (error < 0) return Error_set(error); return PyInt_FromSize_t(limit); } case GIT_OPT_SET_MWINDOW_MAPPED_LIMIT: { size_t limit; PyObject *py_limit; py_limit = PyTuple_GetItem(args, 1); if (!py_limit) return NULL; if (PyInt_Check(py_limit)) { limit = PyInt_AsSize_t(py_limit); } else if (PyLong_Check(py_limit)) { limit = PyLong_AsSize_t(py_limit); } else { return Error_type_error( "limit should be an integer, got %.200s", py_limit); } error = git_libgit2_opts(GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, limit); if (error < 0) return Error_set(error); Py_RETURN_NONE; } case GIT_OPT_GET_SEARCH_PATH: { PyObject *py_level; py_level = PyTuple_GetItem(args, 1); if (!py_level) return NULL; if (!PyInt_Check(py_level)) return Error_type_error( "level should be an integer, got %.200s", py_level); return get_search_path(PyInt_AsLong(py_level)); } case GIT_OPT_SET_SEARCH_PATH: { PyObject *py_level, *py_path, *tpath; const char *path; int err; py_level = PyTuple_GetItem(args, 1); if (!py_level) return NULL; py_path = PyTuple_GetItem(args, 2); if (!py_path) return NULL; if (!PyInt_Check(py_level)) return Error_type_error( "level should be an integer, got %.200s", py_level); path = py_str_borrow_c_str(&tpath, py_path, NULL); if (!path) return NULL; err = git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, PyInt_AsLong(py_level), path); Py_DECREF(tpath); if (err < 0) return Error_set(err); Py_RETURN_NONE; } case GIT_OPT_SET_CACHE_OBJECT_LIMIT: { size_t limit; int object_type; PyObject *py_object_type, *py_limit; py_object_type = PyTuple_GetItem(args, 1); if (!py_object_type) return NULL; py_limit = PyTuple_GetItem(args, 2); if (!py_limit) return NULL; if (!PyInt_Check(py_limit)) return Error_type_error( "limit should be an integer, got %.200s", py_limit); object_type = PyInt_AsLong(py_object_type); limit = PyInt_AsSize_t(py_limit); error = git_libgit2_opts( GIT_OPT_SET_CACHE_OBJECT_LIMIT, object_type, limit); if (error < 0) return Error_set(error); Py_RETURN_NONE; } case GIT_OPT_SET_CACHE_MAX_SIZE: { size_t max_size; PyObject *py_max_size; py_max_size = PyTuple_GetItem(args, 1); if (!py_max_size) return NULL; if (!PyInt_Check(py_max_size)) return Error_type_error( "max_size should be an integer, got %.200s", py_max_size); max_size = PyInt_AsSize_t(py_max_size); error = git_libgit2_opts(GIT_OPT_SET_CACHE_MAX_SIZE, max_size); if (error < 0) return Error_set(error); Py_RETURN_NONE; } case GIT_OPT_GET_CACHED_MEMORY: { size_t current; size_t allowed; PyObject* tup = PyTuple_New(2); error = git_libgit2_opts(GIT_OPT_GET_CACHED_MEMORY, ¤t, &allowed); if (error < 0) return Error_set(error); PyTuple_SetItem(tup, 0, PyInt_FromLong(current)); PyTuple_SetItem(tup, 1, PyInt_FromLong(allowed)); return tup; } case GIT_OPT_SET_SSL_CERT_LOCATIONS: { PyObject *py_file, *py_dir; const char *file_path, *dir_path; int err; py_file = PyTuple_GetItem(args, 1); py_dir = PyTuple_GetItem(args, 2); /* py_file and py_dir are only valid if they are strings */ if (PyUnicode_Check(py_file) || PyBytes_Check(py_file)) { file_path = py_str_to_c_str(py_file, Py_FileSystemDefaultEncoding); } else { file_path = NULL; } if (PyUnicode_Check(py_dir) || PyBytes_Check(py_dir)) { dir_path = py_str_to_c_str(py_dir, Py_FileSystemDefaultEncoding); } else { dir_path = NULL; } err = git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, file_path, dir_path); if (err < 0) return Error_set(err); Py_RETURN_NONE; } // int enabled case GIT_OPT_ENABLE_CACHING: case GIT_OPT_ENABLE_STRICT_OBJECT_CREATION: case GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION: case GIT_OPT_ENABLE_OFS_DELTA: case GIT_OPT_ENABLE_FSYNC_GITDIR: case GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION: case GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY: { PyObject *py_enabled; int enabled; py_enabled = PyTuple_GetItem(args, 1); if (!py_enabled) return NULL; if (!PyInt_Check(py_enabled)) return Error_type_error("expected integer, got %.200s", py_enabled); enabled = PyInt_AsSize_t(py_enabled); error = git_libgit2_opts(option, enabled); if (error < 0) return Error_set(error); Py_RETURN_NONE; } // Not implemented case GIT_OPT_GET_TEMPLATE_PATH: case GIT_OPT_SET_TEMPLATE_PATH: case GIT_OPT_SET_USER_AGENT: case GIT_OPT_SET_SSL_CIPHERS: case GIT_OPT_GET_USER_AGENT: case GIT_OPT_GET_WINDOWS_SHAREMODE: case GIT_OPT_SET_WINDOWS_SHAREMODE: case GIT_OPT_SET_ALLOCATOR: case GIT_OPT_GET_PACK_MAX_OBJECTS: case GIT_OPT_SET_PACK_MAX_OBJECTS: { Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } } PyErr_SetString(PyExc_ValueError, "unknown/unsupported option value"); return NULL; }