PyMODINIT_FUNC initCfilters(void) { SC_OFF_LEN = strlen(SC_OFF); SC_OFF_U = to_unicode(SC_OFF, SC_OFF_LEN); SC_ON_LEN = strlen(SC_ON); SC_ON_U = to_unicode(SC_ON, SC_ON_LEN); (void) Py_InitModule("Cfilters", FilterMethods); }
PyObject * DiffStats_format(DiffStats *self, PyObject *args, PyObject *kwds) { int err, format; git_buf buf = { 0 }; Py_ssize_t width; PyObject *str; char *keywords[] = {"format", "width", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "in", keywords, &format, &width)) return NULL; if (width <= 0) { PyErr_SetString(PyExc_ValueError, "width must be positive"); return NULL; } err = git_diff_stats_to_buf(&buf, self->stats, format, width); if (err < 0) return Error_set(err); str = to_unicode(buf.ptr, NULL, NULL); git_buf_free(&buf); return str; }
PyObject * Refspec_rtransform(Refspec *self, PyObject *py_str) { char *str, *trans; int err, len, alen; PyObject *py_trans; str = py_str_to_c_str(py_str, NULL); alen = len = strlen(str); do { alen *= alen; trans = malloc(alen); if (!trans) { free(str); return PyErr_NoMemory(); } err = git_refspec_rtransform(trans, alen, self->refspec, str); } while(err == GIT_EBUFS); free(str); if (err < 0) { free(trans); Error_set(err); return NULL; } py_trans = to_unicode(trans, NULL, NULL); free(trans); return py_trans; }
PyObject * Branch_upstream_name__get__(Branch *self) { int err; const char *branch_name; char *c_name = NULL; PyObject *py_name; CHECK_REFERENCE(self); branch_name = git_reference_name(self->reference); /* Get the length of the upstream name */ err = git_branch_upstream_name(NULL, 0, self->repo->repo, branch_name); if (err < GIT_OK) return Error_set(err); /* Get the actual upstream name */ c_name = calloc(err, sizeof(char)); if (c_name == NULL) return PyErr_NoMemory(); err = git_branch_upstream_name(c_name, err * sizeof(char), self->repo->repo, branch_name); if (err < GIT_OK) { free(c_name); return Error_set(err); } py_name = to_unicode(c_name, NULL, NULL); free(c_name); return py_name; }
PyObject * Diff_patch__get__(Diff *self) { git_patch* patch; git_buf buf = {NULL}; int err = GIT_ERROR; size_t i, len, num; PyObject *py_patch = NULL; num = git_diff_num_deltas(self->list); if (num == 0) Py_RETURN_NONE; for (i = 0, len = 1; i < num ; ++i) { err = git_patch_from_diff(&patch, self->list, i); if (err < 0) goto cleanup; /* This appends to the current buf, so we can simply keep passing it */ err = git_patch_to_buf(&buf, patch); if (err < 0) goto cleanup; git_patch_free(patch); } py_patch = to_unicode(buf.ptr, NULL, NULL); git_buf_free(&buf); cleanup: git_buf_free(&buf); return (err < 0) ? Error_set(err) : py_patch; }
static int foreach_path_cb(git_submodule *submodule, const char *name, void *payload) { PyObject *list = (PyObject *)payload; PyObject *path = to_unicode(git_submodule_path(submodule), NULL, NULL); return PyList_Append(list, path); }
/* Reads file from MS-Word 97 and above file. Takes in account strange* * situation that unicode and non-unicode 256-byte blocks could be * * intermixed in word file * * * * Parameters: * * * * f - file to read * * offset - position of the character inside file (to determine * * possible block boundaries * **********************************************************************/ int get_word8_char(FILE *f,long *offset,long fileend) { int count,i,u; char c; if ((i=(*offset)%256) ==0) { count=catdoc_read(read_buf,1,256,f); memset(read_buf+count,0,256-count); buf_is_unicode=0; if (*offset+(long)count>fileend) { count=fileend-*offset; } while (i<count) { c=read_buf[i++]; if ((c==0x20|| c==0x0D||ispunct(c))&&i<count&&read_buf[i]==0) { buf_is_unicode=1; break; } i++; } i=0; } if (buf_is_unicode) { u=read_buf[i] | read_buf[i+1]<<8; (*offset)+=2; } else { u=to_unicode(source_charset,read_buf[i]); (*offset)++; } return u; }
/* Reads file from MS-Word 97 and above file. Takes in account strange* * situation that unicode and non-unicode 256-byte blocks could be * * intermixed in word file * * * * Parameters: * * * * f - file to read * * offset - position of the character inside file (to determine * * possible block boundaries * **********************************************************************/ int get_word8_char(FILE *f,long *offset,long fileend, struct ole_params_t *ole_params, unsigned char read_buf[256], int *buf_is_unicode, struct io_funcs_t *io_funcs) { int count,i,u; char c; if ((i=(*offset)%256) ==0) { count=io_funcs->catdoc_read(read_buf,1,256,f, ole_params); memset(read_buf+count,0,256-count); *buf_is_unicode=0; if (*offset+(long)count>fileend) { count=fileend-*offset; } while (i<count) { c=read_buf[i++]; if ((c==0x20|| c==0x0D||ispunct(c))&&i<count&&read_buf[i]==0) { *buf_is_unicode=1; break; } i++; } i=0; } if (*buf_is_unicode) { u=read_buf[i] | read_buf[i+1]<<8; (*offset)+=2; } else { u=to_unicode(source_charset,read_buf[i]); (*offset)++; } return u; }
PyObject * Commit_message__get__(Commit *commit) { const char *message, *encoding; message = git_commit_message(commit->commit); encoding = git_commit_message_encoding(commit->commit); return to_unicode(message, encoding, "strict"); }
char Square::ToPlain(const string_t & str) { if (str.empty()) return ToPlain(Blank); char ch = ToPlain(to_unicode(str).at(0)); if (ch == 0) return ToPlain(Blank); return ch; }
PyObject * Tag_name__get__(Tag *self) { const char *name; name = git_tag_name(self->tag); if (!name) Py_RETURN_NONE; return to_unicode(name, "utf-8", "strict"); }
PyObject * Tag_message__get__(Tag *self) { const char *message; message = git_tag_message(self->tag); if (!message) Py_RETURN_NONE; return to_unicode(message, "utf-8", "strict"); }
void mg_fopen(const char *path, const char *mode, struct file *filep) { #ifdef _WIN32 wchar_t wbuf[PATH_MAX], wmode[20]; to_unicode(path, wbuf, ARRAY_SIZE(wbuf)); MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, ARRAY_SIZE(wmode)); filep->fp = _wfopen(wbuf, wmode); #else filep->fp = fopen(path, mode); #endif }
PyObject * Remote_push_url__get__(Remote *self) { const char *url; url = git_remote_pushurl(self->remote); if (!url) Py_RETURN_NONE; return to_unicode(url, NULL, NULL); }
PyObject* Branch_branch_name__get__(Branch *self) { int err; const char *c_name; CHECK_REFERENCE(self); err = git_branch_name(&c_name, self->reference); if (err == GIT_OK) return to_unicode(c_name, NULL, NULL); else return Error_set(err); }
int Config_get_multivar_fn_wrapper(const git_config_entry *value, void *data) { PyObject *item = NULL; if (!(item = to_unicode(value->value, NULL, NULL))) return -2; PyList_Append((PyObject *)data, item); Py_CLEAR(item); return 0; }
PyObject * get_pylist_from_git_strarray(git_strarray *strarray) { int index; PyObject *new_list; new_list = PyList_New(strarray->count); if (new_list == NULL) return NULL; for (index = 0; index < strarray->count; index++) PyList_SET_ITEM(new_list, index, to_unicode(strarray->strings[index], NULL, NULL)); return new_list; }
static PyObject * get_search_path(long level) { git_buf buf = {NULL}; PyObject *py_path; int err; err = git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, level, &buf); if (err < 0) return Error_set(err); py_path = to_unicode(buf.ptr, NULL, NULL); git_buf_free(&buf); if (!py_path) return NULL; return py_path; }
bool Square::IsValidString(const string_t & str) { if (str == Black) return true; #if PUZ_UNICODE std::wstring::const_iterator begin = str.begin(); std::wstring::const_iterator end = str.end(); #else std::wstring unicode = to_unicode(str); std::wstring::const_iterator begin = unicode.begin(); std::wstring::const_iterator end = unicode.end(); #endif // PUZ_UNICODE std::wstring::const_iterator it; for (it = begin; it != end; ++it) if (! IsValidChar(*it)) return false; return true; }
PyObject * Branch_remote_name__get__(Branch *self) { int err; git_buf name = {NULL}; const char *branch_name; PyObject *py_name; CHECK_REFERENCE(self); branch_name = git_reference_name(self->reference); err = git_branch_remote_name(&name, self->repo->repo, branch_name); if (err < GIT_OK) return Error_set(err); py_name = to_unicode(name.ptr, NULL, NULL); git_buf_free(&name); return py_name; }
static lstring from_utf8(const char *text, size_t size) { namespace lb = boost::locale::boundary; std::string::const_iterator begin(text); std::string::const_iterator end(text + size); lb::ssegment_index wmap(lb::character, begin, end, __fuzzy_locale); wmap.rule(lb::character_any); lstring ret; for (auto it = wmap.begin(), e = wmap.end(); it != e; ++it) { std::string str = it->str(); const char *ptr = str.c_str(); auto code = __fuzzy_utf8_converter->to_unicode(ptr, ptr + str.size()); letter<unsigned int> l(code); ret.append(&l, 1); } return ret; }
PyObject * Diff_patch__get__(Diff *self) { const git_diff_delta* delta; git_diff_patch* patch; char **strings = NULL; char *buffer = NULL; int err = GIT_ERROR; size_t i, len, num; PyObject *py_patch = NULL; num = git_diff_num_deltas(self->list); MALLOC(strings, num * sizeof(char*), cleanup); for (i = 0, len = 1; i < num ; ++i) { err = git_diff_get_patch(&patch, &delta, self->list, i); if (err < 0) goto cleanup; err = git_diff_patch_to_str(&(strings[i]), patch); if (err < 0) goto cleanup; len += strlen(strings[i]); git_diff_patch_free(patch); } CALLOC(buffer, (len + 1), sizeof(char), cleanup); for (i = 0; i < num; ++i) { strcat(buffer, strings[i]); free(strings[i]); } free(strings); py_patch = to_unicode(buffer, NULL, NULL); free(buffer); cleanup: return (err < 0) ? Error_set(err) : py_patch; }
PyObject * Config_get_multivar(Config *self, PyObject *args) { int err; PyObject *list; const char *name = NULL; const char *regex = NULL; git_config_iterator *iter; git_config_entry *entry; if (!PyArg_ParseTuple(args, "s|s", &name, ®ex)) return NULL; list = PyList_New(0); err = git_config_multivar_iterator_new(&iter, self->config, name, regex); if (err < 0) return Error_set(err); while ((err = git_config_next(&entry, iter)) == 0) { PyObject *item; item = to_unicode(entry->value, NULL, NULL); if (item == NULL) { git_config_iterator_free(iter); return NULL; } PyList_Append(list, item); Py_CLEAR(item); } git_config_iterator_free(iter); if (err == GIT_ITEROVER) err = 0; if (err < 0) return Error_set(err); return list; }
PyObject * Config_getitem(Config *self, PyObject *py_key) { int64_t value_int; int err, value_bool; const char *value_str; char *key; PyObject* py_value; key = py_str_to_c_str(py_key, NULL); if (key == NULL) return NULL; err = git_config_get_string(&value_str, self->config, key); if (err < 0) goto cleanup; if (git_config_parse_int64(&value_int, value_str) == 0) py_value = PyLong_FromLongLong(value_int); else if(git_config_parse_bool(&value_bool, value_str) == 0) py_value = PyBool_FromLong(value_bool); else py_value = to_unicode(value_str, NULL, NULL); cleanup: free(key); if (err < 0) { if (err == GIT_ENOTFOUND) { PyErr_SetObject(PyExc_KeyError, py_key); return NULL; } return Error_set(err); } return py_value; }
static void create_directory(const char *root, const char *dir) throw (CargoException) { const char *separator = dir; while (true) { /* find separator */ bool found = false; while (separator) { separator++; if (*separator == 0) { break; } if (*separator == '/' || *separator == '\\') { found = true; break; } } if (!found) { break; } /* create directory */ std::string new_dir(root); new_dir += "/"; new_dir.append(dir, separator - dir); #ifndef _WIN32 struct stat st; if (stat(new_dir.c_str(), &st) == -1) { mkdir(new_dir.c_str(), 0700); } #else modify_directory_separator(new_dir); wchar_t wdir[MaxPathLength]; to_unicode(new_dir.c_str(), wdir, MaxPathLength); int rv = CreateDirectoryW(wdir, 0); #endif } }
PyObject * Signature_name__get__(Signature *self) { return to_unicode(self->signature->name, self->encoding, "strict"); }
PyObject * Signature_email__get__(Signature *self) { return to_unicode(self->signature->email, self->encoding, "strict"); }
PyObject * Remote_name__get__(Remote *self) { return to_unicode(git_remote_name(self->remote), NULL, NULL); }
int copy_out (FILE *f,char *header, FILE *out, get_unicode_char_t get_unicode_char, struct ole_params_t *ole_params, struct io_funcs_t *io_funcs) { char *buf= NULL; int count,i; long offset; unsigned short int *buffer = NULL; unsigned char read_buf[256]; int buf_is_unicode = 0; if (get_unicode_char == get_word8_char) { /* non-word file and -u specified. Trying to guess which kind of * unicode is used */ if ((unsigned char)header[0]==0xFE && (unsigned char)header[1]==0xFF) { get_unicode_char = get_utf16msb; fputs(convert_char(header[2]<<8|header[3]),out); fputs(convert_char(header[4]<<8|header[5]),out); fputs(convert_char(header[6]<<8|header[7]),out); } else if ((unsigned char)header[0]!=0xFF || (unsigned char)header[1]!=0xFE) { int c,j,d; /* if it is not utf16, assume it is UTF8. We are told -u, * aren't we */ get_unicode_char = get_utf8; i=0; while (i<8) { c=(unsigned char)header[i++]; if (c >=0x80) { if ( c<0xE0) { c=(c & 0x1F); count =1; } else { c=(c & 0xF); count = 2; } for (j=0;j<count;j++) { if (i<7) { d=(unsigned char) header[i++]; } else { d=fgetc(f); } c=c<<6 | (d & 0x3F); } } fputs (convert_char(c),out); } } else { get_unicode_char = get_utf16lsb; fputs(convert_char(header[3]<<8|header[2]),out); fputs(convert_char(header[5]<<8|header[4]),out); fputs(convert_char(header[7]<<8|header[6]),out); } while (!io_funcs->catdoc_eof(f)) { i=get_unicode_char(f,&offset,0x7FFFFFFF, ole_params, read_buf, &buf_is_unicode, io_funcs); if (i!=EOF) fputs(convert_char(i),out); } } else { for (i=0;i<8;i++) { fputs(convert_char(to_unicode(source_charset,(unsigned char)header[i])),out); } buffer = (unsigned short int*) malloc(PARAGRAPH_BUFFER * sizeof(unsigned short int)); if (!buffer) return -1; buf = (char*)buffer; /* Assuming 8-bit input text */ while ((count = io_funcs->catdoc_read(buf,1,PARAGRAPH_BUFFER,f, ole_params))) { for (i=0;i<count;i++) { fputs(convert_char(to_unicode(source_charset, (unsigned char)buf[i])),out); } } free(buffer); } return 0; }
PyObject * Refspec_string__get__(Refspec *self) { return to_unicode(git_refspec_string(self->refspec), NULL, NULL); }