static void ramcloudSet(struct ramcloudData *d, wstr key, struct array *vals, uint32_t vlen, uint16_t flag, struct RejectRules *rule) { wheatLog(WHEAT_DEBUG, "%s set key %s", __func__, key); uint64_t version; int i = 0; struct slice *slice; wstr val = wstrNewLen(NULL, vlen+sizeof(flag)); while (i < narray(vals)) { slice = arrayIndex(vals, i); val = wstrCatLen(val, (char*)slice->data, slice->len); ++i; } val = wstrCatLen(val, (char*)&flag, FLAG_SIZE); Status s = rc_write(global.client, d->table_id, key, wstrlen(key), val, wstrlen(val), rule, &version); wstrFree(val); if (s != STATUS_OK) { // cas command if (rule->versionNeGiven) { if (s == STATUS_WRONG_VERSION) sliceTo(&d->storage_response, (uint8_t*)EXISTS, sizeof(EXISTS)-1); else if (s == STATUS_OBJECT_DOESNT_EXIST) sliceTo(&d->storage_response, (uint8_t*)NOT_FOUND, sizeof(NOT_FOUND)-1); } else if ((rule->doesntExist && s == STATUS_OBJECT_DOESNT_EXIST) || (rule->exists && s == STATUS_OBJECT_EXISTS)) { sliceTo(&d->storage_response, (uint8_t*)NOT_STORED, sizeof(NOT_STORED)-1); } else { wheatLog(WHEAT_WARNING, "%s failed to set %s: %s", __func__, key, statusToString(s)); sliceTo(&d->storage_response, (uint8_t*)SERVER_ERROR, sizeof(SERVER_ERROR)-1); } } else { sliceTo(&d->storage_response, (uint8_t*)STORED, sizeof(STORED)-1); } }
int newtListboxAppendEntry(newtComponent co, const char * text, const void * data) { struct listbox * li = co->data; struct items *item; if(li->boxItems) { for (item = li->boxItems; item->next != NULL; item = item->next); item = item->next = malloc(sizeof(struct items)); } else { item = li->boxItems = malloc(sizeof(struct items)); } if (!li->userHasSetWidth && text && (wstrlen(text,-1) > li->curWidth)) updateWidth(co, li, wstrlen(text,-1)); item->text = strdup(text); item->data = data; item->next = NULL; item->isSelected = 0; if (li->grow) co->height++, li->curHeight++; li->numItems++; return 0; }
bool CClassManager::LoadNewLibrary(const wchar* szLibraryName) { if (!szLibraryName || !*szLibraryName) return false; wchar BinPath[MAX_PATH]; bool bAbsolutePath = false; for(unsigned int i = wstrlen(szLibraryName); i>0; i--) { if (szLibraryName[i]=='\\' || szLibraryName[i]=='/') { bAbsolutePath = true; break; } } if (bAbsolutePath) { // check extension and copy if (wstrlen(szLibraryName)<5 || szLibraryName[wstrlen(szLibraryName)-5]!='.') #if defined(WIN32) wsprintf(BinPath, 259, _W("%s.wp3d"), szLibraryName); #elif defined (LINUX) wsprintf(BinPath, 259, _W("%s.lp3d"), szLibraryName); #endif else wstrcpy(BinPath, szLibraryName); // copy abspath with extension }
Bool wsubstr(char *s1, char *s2) { int i, len1 = wstrlen(s1), len2 = wstrlen(s2); for (i = 0; i <= len1 - len2; ++i) { if (wstrncasecmp(s1+i, s2, len2) == 0) return yes; } return no; }
static void ramcloudRead(void *item, void *data) { wstr i = *(wstr*)item; struct ramcloudData *d = data; uint32_t actual_len; uint64_t version; uint64_t len = RAMCLOUD_DEFAULT_VALUE_LEN; wheatLog(WHEAT_DEBUG, "%s read key %s", __func__, i); wstr val = wstrNewLen(NULL, len); Status s = rc_read(global.client, d->table_id, i, wstrlen(i), NULL, &version, val, len, &actual_len); if (s != STATUS_OK) { if (s != STATUS_OBJECT_DOESNT_EXIST) { wheatLog(WHEAT_WARNING, " failed to read %s: %s", i, statusToString(s)); } wstrFree(val); return ; } while (actual_len > len) { wstrFree(val); len = actual_len; val = wstrNewLen(NULL, actual_len); if (val == NULL) { wheatLog(WHEAT_WARNING, " failed to alloc memory"); return ; } s = rc_read(global.client, d->table_id, i, wstrlen(i), NULL, &version, val, len, &actual_len); if (s != STATUS_OK) { if (s != STATUS_OBJECT_DOESNT_EXIST) { wheatLog(WHEAT_WARNING, " failed to read %s: %s", i, statusToString(s)); } wstrFree(val); return ; } } d->retrieval_len += actual_len; arrayPush(d->retrievals, &val); struct slice ss = {(uint8_t*)(i), wstrlen(i)}; arrayPush(d->retrievals_keys, &ss); ss.data = (uint8_t*)val; ss.len = actual_len - FLAG_SIZE; arrayPush(d->retrievals_vals, &ss); arrayPush(d->retrievals_flags, &val[actual_len-FLAG_SIZE]); arrayPush(d->retrievals_versions, &version); }
NAMESPACE_UPP void DrawTextEllipsis(Draw& w, int x, int y, int cx, const wchar *text, const char *ellipsis, Font font, Color ink, int n) { if(n < 0) n = wstrlen(text); FontInfo f = font.Info(); const char *s; int dtl = 0; int el = 0; for(s = ellipsis; *s; s++) { dtl += f[(byte)*s]; el++; } int l = 0; int i; for(i = 0; i < n; i++) { l += f[(byte) text[i]]; if(l > cx) { while(l + dtl > cx && i > 0) { l -= f[(byte) text[i]]; i--; } i++; break; } } w.DrawText(x, y, text, font, ink, i); if(i < n) w.DrawText(x + l, y, ellipsis, font, ink, el); }
acr_index* TextParser::Parse() { fseek(fin, 2, SEEK_SET); //pass BOM ulong offset; ulong num; char *str; static wchar_t text[512] = {0}; acr_index cur; ulong pos = 0; //重写此处以适应不同格式文本 while (fwscanf(fin, L"○%08X○%08d●\r\n%s\r\n\r\n", &offset, &num, text) == 3) { int len = wstrlen(text); memcpy(real_data + pos, text, len); memset(real_data + pos + len, 0, 2); //其他游戏需要根据情况适当修改 cur.hash = offset; cur.new_str_len = len; cur.new_str_off = (ulong)real_data + pos; cur.old_str_len = len; //这两个暂时先这样 cur.old_str_off = (ulong)real_data + pos; //这两个暂时先这样 index.push_back(cur); pos += (len+2); } return (acr_index*)&index[0]; }
void newtRedrawHelpLine(void) { char * buf; SLsmg_set_color(NEWT_COLORSET_HELPLINE); if (currentHelpline) { /* buffer size needs to be wide enough to hold all the multibyte currentHelpline + all the single byte ' ' to fill the line */ int wlen = wstrlen(*currentHelpline, -1); int len; if (wlen > SLtt_Screen_Cols) wlen = SLtt_Screen_Cols; len = strlen(*currentHelpline) + (SLtt_Screen_Cols - wlen); buf = alloca(len + 1); memset(buf, ' ', len); memcpy(buf, *currentHelpline, strlen(*currentHelpline)); buf[len] = '\0'; } else { buf = alloca(SLtt_Screen_Cols + 1); memset(buf, ' ', SLtt_Screen_Cols); buf[SLtt_Screen_Cols] = '\0'; } SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); SLsmg_write_string(buf); }
Vector<WString> Split(int maxcount, const wchar *s, const wchar *text, bool ignoreempty) { SplitDelimWText delim; delim.ds = text; delim.l = wstrlen(text); return delim.l ? SplitGeneric<WString>(maxcount, delim, s, ignoreempty) : Vector<WString>(); }
const wchar_t* wcopy (const wchar_t* str) { int l = wstrlen(str); wchar_t* c = malloc(sizeof(wchar_t)*(l+1)); memcpy(c,str,sizeof(wchar_t)*(l+1)); c[l]=0; return c; }
int APIENTRY WinMain(HINSTANCE x, HINSTANCE y, LPSTR z, int w) { int argc, n; char *arg, *p, **argv; Rune *warg; if(0 && win_hasunicode()){ warg = GetCommandLineW(); n = (wstrlen(warg)+1)*UTFmax; arg = malloc(n); wstrtoutf(arg, warg, n); }else arg = GetCommandLineA(); /* conservative guess at the number of args */ for(argc=4,p=arg; *p; p++) if(*p == ' ' || *p == '\t') argc++; argv = malloc(argc*sizeof(char*)); argc = args(argv, argc, arg); mymain(argc, argv); ExitThread(0); return 0; }
newtComponent newtCheckbox(int left, int top, const char * text, char defValue, const char * seq, char * result) { newtComponent co; struct checkbox * cb; if (!seq) seq = " *"; co = malloc(sizeof(*co)); cb = malloc(sizeof(struct checkbox)); co->data = cb; cb->flags = 0; if (result) cb->result = result; else cb->result = &cb->value; cb->text = strdup(text); cb->seq = strdup(seq); cb->type = CHECK; cb->hasFocus = 0; cb->inactive = COLORSET_CHECKBOX; cb->active = COLORSET_ACTCHECKBOX; defValue ? (*cb->result = defValue) : (*cb->result = cb->seq[0]); co->ops = &cbOps; co->callback = NULL; co->height = 1; co->width = wstrlen(text, -1) + 4; co->top = top; co->left = left; co->takesFocus = 1; return co; }
//------------------------------------------ size_t CFS_Sqlite::WriteUTF8(const wchar* string, FSFILE *fp) { if (!string || !*string) return 0; // if not unicode #ifndef UNICODE return Write(string, 1, strlen(string), fp); #else unsigned int inputLen = wstrlen(string); unsigned char *target; target = new unsigned char[inputLen*4+1]; // make buffer long enough UErrorCode status = U_ZERO_ERROR; int32_t len; //// set up the converter UConverter *conv = ucnv_open("utf-8", &status); assertd(U_SUCCESS(status)!=0, "Failed to open utf-8 converter!"); //// convert len = ucnv_fromUChars(conv, (char*)target, inputLen*4, string, -1, &status); assertd(U_SUCCESS(status)!=0, "Failed to convert string to utf-8!"); //// write to file size_t wrlen = Write(target, 1, len, fp); //// close and clean delete[] target; ucnv_close(conv); return wrlen; #endif }
int main() { printf("=== Pointer basic\n"); int *ip; int h = 5; ip = &h; *ip = 10; printf("ip pointed to %d\nh is %d\n", *ip, h); printf("=== Difference between c++ and ++c\n"); int a = 8, d = 8; int b, c; b = a++; c = ++d; printf("b = a++, %d\nc = ++d, %d\n", b, c); printf("=== Function with pointers\n"); swap(&b, &c); printf("after swap, b = %d, c = %d\n", b, c); printf("Pointer and array\n"); int arr[5] = {1, 2, 3, 4, 5}; int *ap = &(arr[0]); int *bp = arr; printf("the first element of array is %d\n", *ap); printf("the second element of array is %d\n", *(ap+1)); printf("the first element of array is %d\n", *bp); printf("the first element of array is %d\n", *arr); // Test string len printf("len of hello is %d\n", wstrlen("hello")); return 1; }
const WCHAR* cursor_window_get_string_16_coerce(CursorWindow* thiz,INT32 row,INT32 col) { CursorWindowFieldSlot* field = NULL; CursorWindowRowChunk* chunk=NULL; INT32 row_in_chunk=0; return_val_if_fail(thiz , NULL); return_val_if_fail(_cursor_window_locate_field(thiz,row,col,&row_in_chunk,&chunk,&field),NULL); if (field->type==FIELD_TYPE_STRING_16||field->type==FIELD_TYPE_NULL) return (const WCHAR*)field->data.buffer.buf; else if (field->type==FIELD_TYPE_STRING) { INT32 len = strlen((const CHAR*)field->data.buffer.buf); WCHAR* utf16_str = TG_CALLOC_V2(len*2+2); return_val_if_fail(utf16_str , NULL); tg_UTF8ToUCS2(( CHAR*)field->data.buffer.buf,utf16_str); TG_FREE(field->data.buffer.buf); field->data.buffer.buf= (UINT8*)utf16_str; field->data.buffer.size = wstrlen((const WCHAR*)field->data.buffer.buf)*2+2; field->type=FIELD_TYPE_STRING_16; return (const WCHAR*)field->data.buffer.buf; } else return NULL; }
BOOL cursor_window_put_string_16(CursorWindow* thiz,INT32 col,const WCHAR* value) { INT32 len = 0; if (value) len = 2*wstrlen(value)+2; return _cursor_window_put_buffer_field(thiz,col,FIELD_TYPE_STRING_16,(const void*)value,len); }
/* * This function returns the length in bytes for C and Unicode strings. * Note that unlike strlen() it returns the length _including_ the * terminator, which may be one or two null bytes. */ size_t pdf_strlen(const char *text) { if (pdf_is_unicode(text)) return wstrlen(text) + 2; else return strlen(text) + 1; }
INT32 tg_shared_preferences_put_string_16(SharedPreferences* thiz,const CHAR* key_path,const WCHAR* value) { INT32 len = 0; return_val_if_fail((value),SharedPreferences_ERROR); len= wstrlen(value)*2+2; return tg_shared_preferences_put_serialization(thiz,key_path,value,len); }
void renderString(int x, int y, string glstring){ UnicodeChar c; int uc; int span = 0; double wid = pow(2, ceil(log2(32 * stretch))); wchar_t* wstr = nullptr; MBToWC(glstring.c_str(), wstr, glstring.length()+128); glEnable(GL_TEXTURE_2D); for (unsigned int k = 0; k < wstrlen(wstr); k++) { uc = wstr[k]; c = chars[uc]; if (uc == (int)'\n') { UITrans(0, 20); span = 0; continue; } if (!c.aval) { loadchar(uc); c = chars[uc]; } glBindTexture(GL_TEXTURE_2D, c.tex); UITrans(x + 1 + span, y + 1); glColor4f(0.5, 0.5, 0.5, a); glBegin(GL_QUADS); glTexCoord2d(0.0, 0.0); UIVertex(c.xpos / stretch, 15 - c.ypos / stretch); glTexCoord2d(c.width / wid, 0.0); UIVertex(c.xpos / stretch + c.width / stretch, 15- c.ypos / stretch); glTexCoord2d(c.width / wid, c.height / wid); UIVertex(c.xpos / stretch + c.width / stretch, 15 + c.height / stretch - c.ypos / stretch); glTexCoord2d(0.0, c.height / wid); UIVertex(c.xpos / stretch, 15 + c.height / stretch - c.ypos / stretch); glEnd(); UITrans(-1, -1); glColor4f(r, g, b, a); glBegin(GL_QUADS); glTexCoord2d(0.0, 0.0); UIVertex(c.xpos / stretch, 15 - c.ypos / stretch); glTexCoord2d(c.width / wid, 0.0); UIVertex(c.xpos / stretch + c.width / stretch, 15 - c.ypos / stretch); glTexCoord2d(c.width / wid, c.height / wid); UIVertex(c.xpos / stretch + c.width / stretch, 15 + c.height / stretch - c.ypos / stretch); glTexCoord2d(0.0, c.height / wid); UIVertex(c.xpos / stretch, 15 + c.height / stretch - c.ypos / stretch); glEnd(); UITrans(-x - span, -y); span += c.advance / stretch; } glColor4f(1.0, 1.0, 1.0, 1.0); free(wstr); }
/* This assumes the buffer is allocated properly! */ static void addLine(newtComponent co, const char * s, int len) { struct textbox * tb = co->data; while (wstrlen(s,len) > tb->textWidth) { len--; } tb->lines[tb->numLines] = malloc(len + 1); memcpy(tb->lines[tb->numLines], s, len); tb->lines[tb->numLines++][len] = '\0'; }
String GetString(PasteClip& clip) { GuiLock __; if(clip.Accept("wtext")) { String s = ~clip; return WString((const wchar *)~s, wstrlen((const wchar *)~s)).ToString(); } if(clip.IsAvailable("text")) return ~clip; return Null; }
WString GetWString(PasteClip& clip) { GuiLock __; if(clip.Accept("wtext")) { String s = ~clip; return WString((const wchar *)~s, wstrlen((const wchar *)~s)); } if(clip.Accept("text")) return (~clip).ToWString(); return Null; }
Parser* ModuleTable::NewModule(Parser & moduleAST ) { std::pair<wchar_t*,Parser*> newmod(moduleAST.modulePtr->moduleName, &moduleAST); typedef TModuleTable::iterator hmit; typedef std::pair<hmit, bool> retcode; //insert unique retcode insertResult = moduleName2parser.insert(newmod); if(insertResult.second)return &moduleAST; //output an error const wchar_t *fmt=L"name declared twice: %ls"; size_t len=wstrlen(fmt)-3+wstrlen(moduleAST.modulePtr->moduleName)+1; wchar_t *msg=new wchar_t[len];abortIfNull(msg); (void)wsprintf(msg, len, fmt, moduleAST.modulePtr->moduleName); Err(msg); delete[] msg; return 0; }
int newtListboxInsertEntry(newtComponent co, const char * text, const void * data, void * key) { struct listbox * li = co->data; struct items *item, *t; if (li->boxItems) { if (key) { item = li->boxItems; while (item && item->data != key) item = item->next; if (!item) return 1; t = item->next; item = item->next = malloc(sizeof(struct items)); item->next = t; } else { t = li->boxItems; item = li->boxItems = malloc(sizeof(struct items)); item->next = t; } } else if (key) { return 1; } else { item = li->boxItems = malloc(sizeof(struct items)); item->next = NULL; } if (!li->userHasSetWidth && text && (wstrlen(text,-1) > li->curWidth)) updateWidth(co, li, wstrlen(text,-1)); item->text = strdup(text?text:"(null)"); item->data = data; item->isSelected = 0; if (li->sb) li->sb->left = co->left + co->width - li->bdxAdjust - 1; li->numItems++; listboxDraw(co); return 0; }
void newtGridWrappedWindow(newtGrid grid, char * title) { int w, width, height, offset = 0; newtGridGetSize(grid, &width, &height); w = wstrlen(title,-1); if (width < w + 2) { offset = ((w + 2) - width) / 2; width = w + 2; } newtCenteredWindow(width + 2, height + 2, title); newtGridPlace(grid, 1 + offset, 1); }
void newtListboxSetEntry(newtComponent co, int num, const char * text) { struct listbox * li = co->data; int i; struct items *item; for(i = 0, item = li->boxItems; item != NULL && i < num; i++, item = item->next); if(!item) return; else { free(item->text); item->text = strdup(text); } if (li->userHasSetWidth == 0 && wstrlen(text,-1) > li->curWidth) { updateWidth(co, li, wstrlen(text,-1)); } if (num >= li->startShowItem && num <= li->startShowItem + co->height) listboxDraw(co); }
WCHAR *c2wstrcat(WCHAR *ws1, char *s2) { int ix = wstrlen(ws1); int iy = 0; while (s2[iy]) { ws1[ix] = (WCHAR)s2[iy]; ix++; iy++; } ws1[ix] = 0; return ws1; }
WCHAR *wstrcat(WCHAR *ws1, WCHAR *ws2) { int ix = wstrlen(ws1); int iy = 0; while (ws2[iy]) { ws1[ix] = ws2[iy]; ix++; iy++; } ws1[ix] = 0; return ws1; }
virtual wchar *duplicateStringValue( const wchar *value, unsigned int length = unknown ) { //@todo invesgate this old optimization //if ( !value || value[0] == 0 ) // return 0; if ( length == unknown ) length = (unsigned int)wstrlen(value); wchar *newString = static_cast<wchar *>( malloc( sizeof(wchar) * (length + 1) ) ); memcpy( newString, value, sizeof(wchar) * length ); newString[length] = 0; return newString; }
BOOL cursor_window_update_string_16(CursorWindow* thiz,INT32 row,INT32 col,const WCHAR* value) { CursorWindowFieldSlot* field = NULL; CursorWindowRowChunk* chunk=NULL; INT32 row_in_chunk=0; INT32 len = 0; return_val_if_fail(thiz , FALSE); return_val_if_fail(_cursor_window_locate_field(thiz,row,col,&row_in_chunk,&chunk,&field),FALSE); return_val_if_fail(field->type==FIELD_TYPE_STRING_16||field->type==FIELD_TYPE_NULL,FALSE); _cursor_window_destroy_field(field); field->type=FIELD_TYPE_STRING_16; if (value) len = 2*wstrlen(value)+2; return _cursor_window_buffer_field_set_value(field,(const void*)value,len); }