NO_TRACE static cmd_info_t *parse_cmd(const wchar_t *cmdline) { size_t start = 0; size_t end; char *tmp; while (isspace(cmdline[start])) start++; end = start + 1; while (!isspace(cmdline[end])) end++; tmp = malloc(STR_BOUNDS(end - start + 1), 0); wstr_to_str(tmp, end - start + 1, &cmdline[start]); spinlock_lock(&cmd_lock); list_foreach(cmd_list, link, cmd_info_t, hlp) { spinlock_lock(&hlp->lock); if (str_cmp(hlp->name, tmp) == 0) { spinlock_unlock(&hlp->lock); spinlock_unlock(&cmd_lock); free(tmp); return hlp; } spinlock_unlock(&hlp->lock); }
void slog_wstr(const WCHAR *txt) { char *txt_copy; txt_copy = wstr_to_str(txt); if (!txt_copy) return; slog_str(txt_copy); free(txt_copy); }
void conversion_big_s(t_printf *t) { wchar_t *sw; sw = arg_get_wstring(t); if (sw == NULL) to_string(t, ft_strdup("(null)")); else to_string(t, wstr_to_str(t, sw)); }
wstring_ty * sub_date(sub_context_ty *scp, wstring_list_ty *arg) { wstring_ty *result; time_t now; trace(("sub_date()\n{\n")); time(&now); if (arg->nitems < 2) { char *time_string; time_string = ctime(&now); result = wstr_n_from_c(time_string, 24); } else { struct tm *tm; char buf[1000]; size_t nbytes; wstring_ty *wfmt; string_ty *fmt; wfmt = wstring_list_to_wstring(arg, 1, 32767, (char *)0); fmt = wstr_to_str(wfmt); wstr_free(wfmt); tm = localtime(&now); /* * The strftime is locale dependent. */ language_human(); nbytes = strftime(buf, sizeof(buf) - 1, fmt->str_text, tm); language_C(); if (!nbytes && fmt->str_length) { sub_context_error_set(scp, i18n("strftime output too large")); result = 0; } else result = wstr_n_from_c(buf, nbytes); str_free(fmt); } trace(("return %8.8lX;\n", (long)result)); trace(("}\n")); return result; }
static VALUE win32_readlink(const char* file) { VALUE error = Qnil; VALUE target = Qnil; HANDLE h = INVALID_HANDLE_VALUE; bool ok = true; REPARSE_DATA_BUFFER* buf = NULL; const size_t buf_size = MAXIMUM_REPARSE_DATA_BUFFER_SIZE; buf = (REPARSE_DATA_BUFFER*)xmalloc(buf_size); if(ok) { const DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; const DWORD access_mode = FILE_READ_EA; const DWORD attributes = FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_REPARSE_POINT | FILE_FLAG_OPEN_REPARSE_POINT; h = CreateFile( file, access_mode, share_mode, 0, OPEN_EXISTING, attributes, NULL); if(!(ok = (h != INVALID_HANDLE_VALUE))) { error = make_api_error(file); } } if(ok) { DWORD returned_size; ok = 0 != DeviceIoControl (h, FSCTL_GET_REPARSE_POINT, NULL, 0, buf, buf_size, &returned_size, NULL); if(!ok) { error = make_api_error(file); } } if(ok) { wchar_t* raw_target = NULL; long target_len = 0; switch (buf->ReparseTag) { case IO_REPARSE_TAG_MOUNT_POINT: { raw_target = &buf->MountPointReparseBuffer.PathBuffer[ buf->MountPointReparseBuffer.SubstituteNameOffset / sizeof(wchar_t)]; target_len = buf->MountPointReparseBuffer.SubstituteNameLength / sizeof(wchar_t); break; } case IO_REPARSE_TAG_SYMLINK: { raw_target = &buf->SymbolicLinkReparseBuffer.PathBuffer[ buf->SymbolicLinkReparseBuffer.SubstituteNameOffset / sizeof(wchar_t)]; target_len = buf->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(wchar_t); break; } default: ok = false; error = make_error_str(rb_eIOError, "file %s is not a symlink", file); } if(ok) { wchar_t* resolved; resolved = resolve_api_path(raw_target); target_len -= resolved - raw_target; target = wstr_to_str(filecp(), resolved, target_len); } } if( h != INVALID_HANDLE_VALUE ) { CloseHandle(h); } xfree(buf); if( !NIL_P(error) ) { rb_exc_raise(error); } return target; }
hany hjson_decode(hjson_t * json,hcchar * str,InvokeTickDeclare){ hany data = NULL; hchar * p=(hchar *)str; hlist_t data_stack = list_alloc(20,20); hlist_t state_stack =list_alloc(20,20); hbuffer_t value_buffer = buffer_alloc(128, 256); hbuffer_t name_buffer = buffer_alloc(128, 256); hbuffer_t base64_buffer= buffer_alloc(1024,1024); hintptr s; hwchar wchar; hint32 iwchar; hchar wchbuf[8]; //hint32 object_level=0; //hint32 array_level =0; list_add(state_stack, (hany) 0); while (p && *p != '\0') { s = (hintptr)list_last(state_stack); if(s == 0x00){ if(SPACE_CHAR(*p)){ } else if( *p == '{'){ list_add(state_stack, (hany)0x10); data = (*json->object_new)(json,InvokeTickArg); list_add(data_stack, data); list_add(data_stack, data); //hlog("object begin %ld\n",object_level++); } else if( *p == '['){ list_add(state_stack, (hany)0x20); data = (*json->array_new)(json,InvokeTickArg); list_add(data_stack, data); list_add(data_stack, data); //hlog("array begin %ld\n",array_level++); } else if( *p == '\"'){ list_add(state_stack, (hany)0x01); list_add(state_stack, (hany)0x30); } else if( TRUE_EQUAL(p)){ data = (*json->booleanValue)(json,hbool_true,InvokeTickArg); list_add(data_stack, data); break; } else if( FALSE_EQUAL(p)){ data = (*json->booleanValue)(json,hbool_false,InvokeTickArg); list_add(data_stack, data); break; } else if( NULL_EQUAL(p)){ data = (*json->nullValue)(json,InvokeTickArg); list_add(data_stack, data); break; } else{ list_add(state_stack, (hany)0x02); list_add(state_stack, (hany)0x40); continue; } } else if(s == 0x01){ // string value end data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg); list_add(data_stack, data); break; } else if(s == 0x02){ // number value end data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg); list_add(data_stack, data); break; } else if(s ==0x10) { // object if(SPACE_CHAR(*p) || *p ==','){ } else if(*p == '\"'){ list_add(state_stack, (hany)0x11); } else if(*p == ':'){ list_add(state_stack, (hany)0x12); } else if(*p == '}'){ list_pop(state_stack); list_pop(data_stack); buffer_clear(name_buffer); buffer_clear(value_buffer); //hlog("object end %ld\n",--object_level); } else{ buffer_append(name_buffer,p,1); list_add(state_stack, (hany)0x11); } } else if(s == 0x11){ // object value key if(*p == '\\' && p[1] == '"'){ p++; buffer_append(name_buffer, p, 1); } else if( *p == '"'){ list_pop(state_stack); } else if( *p == ':'){ list_pop(state_stack); list_add(state_stack, (hany)0x12); } else{ buffer_append(name_buffer, p, 1); } } else if(s == 0x12){ // object value if(SPACE_CHAR(*p)){ } else if( *p == '{'){ list_pop(state_stack); list_add(state_stack, (hany)0x10); data = (*json->object_new)(json,InvokeTickArg); (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg); list_add(data_stack, data); buffer_clear(name_buffer); buffer_clear(value_buffer); //hlog("object begin %ld\n",object_level++); } else if( *p == '['){ list_pop(state_stack); list_add(state_stack, (hany)0x20); data = (*json->array_new)(json,InvokeTickArg); (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg); list_add(data_stack, data); buffer_clear(name_buffer); buffer_clear(value_buffer); //hlog("array begin %ld\n",array_level++); } else if( *p =='"'){ // string value list_pop(state_stack); list_add(state_stack, (hany)0x13); list_add(state_stack, (hany)0x30); } else if( TRUE_EQUAL(p)){ list_pop(state_stack); data = (*json->booleanValue)(json,hbool_true,InvokeTickArg); (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg); buffer_clear(name_buffer); buffer_clear(value_buffer); p += 3; } else if( FALSE_EQUAL(p)){ list_pop(state_stack); data = (*json->booleanValue)(json,hbool_false,InvokeTickArg); (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg); buffer_clear(name_buffer); buffer_clear(value_buffer); p += 4; } else if( NULL_EQUAL(p)){ list_pop(state_stack); data = (*json->nullValue)(json,InvokeTickArg); (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg); buffer_clear(name_buffer); buffer_clear(value_buffer); p += 3; } else { list_pop(state_stack); list_add(state_stack, (hany)0x14); list_add(state_stack, (hany)0x40); continue; } } else if(s == 0x13){ // string value end data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg); (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg); buffer_clear(name_buffer); buffer_clear(value_buffer); list_pop(state_stack); continue; } else if(s == 0x14){ // number value end data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg); (*json->object_put)(json,list_last(data_stack),buffer_to_str(name_buffer),data,InvokeTickArg); buffer_clear(name_buffer); buffer_clear(value_buffer); list_pop(state_stack); continue; } else if(s ==0x20){ // array value if(SPACE_CHAR(*p) || *p ==','){ } else if( *p ==']'){ list_pop(state_stack); list_pop(data_stack); buffer_clear(name_buffer); buffer_clear(value_buffer); //hlog("array end %ld\n",--array_level); } else if( *p == '{'){ list_add(state_stack, (hany)0x23); list_add(state_stack, (hany)0x10); data = (*json->object_new)(json,InvokeTickArg); (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg); list_add(data_stack, data); //hlog("object begin %ld\n",object_level++); } else if( *p == '['){ list_add(state_stack, (hany)0x23); list_add(state_stack, (hany)0x20); data = (*json->array_new)(json,InvokeTickArg); (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg); list_add(data_stack, data); //hlog("array begin %ld\n",array_level++); } else if( *p =='"'){ // string value list_add(state_stack, (hany)0x21); list_add(state_stack, (hany)0x30); } else if( TRUE_EQUAL(p)){ data = (*json->booleanValue)(json,hbool_true,InvokeTickArg); (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg); p += 3; } else if( FALSE_EQUAL(p)){ data = (*json->booleanValue)(json,hbool_false,InvokeTickArg); (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg); p += 4; } else if( NULL_EQUAL(p)){ data = (*json->nullValue)(json,InvokeTickArg); (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg); p += 3; } else { list_add(state_stack, (hany)0x22); list_add(state_stack, (hany)0x40); continue; } } else if(s == 0x21){ // string value end data = (*json->stringValue)(json,buffer_to_str(value_buffer),base64_buffer,InvokeTickArg); (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg); buffer_clear(name_buffer); buffer_clear(value_buffer); list_pop(state_stack); continue; } else if(s == 0x22){ // number value end data = (*json->numberValue)(json,buffer_to_str(value_buffer),InvokeTickArg); (*json->array_add)(json,list_last(data_stack),data,InvokeTickArg); buffer_clear(name_buffer); buffer_clear(value_buffer); list_pop(state_stack); continue; } else if(s == 0x23){ // object || array value end /* data = list_pop(data_stack); if(data ){ hdata_array_add((hdata_t)list_last(data_stack), data); } */ buffer_clear(name_buffer); buffer_clear(value_buffer); list_pop(state_stack); continue; } else if(s ==0x30){ // string value if( *p == '\\'){ if( p[1] == 'n'){ buffer_append_str(value_buffer,"\n"); } else if( p[1] == 'r'){ buffer_append_str(value_buffer,"\r"); } else if( p[1] == 't'){ buffer_append_str(value_buffer,"\t"); } else if( p[1] == '\\'){ buffer_append_str(value_buffer,"\\"); } else if( p[1] == '\"'){ buffer_append_str(value_buffer,"\""); } else if( p[1] == '\''){ buffer_append_str(value_buffer,"\'"); } else if( p[1] == 'u' || p[1] == 'U'){ iwchar = 0; sscanf(p + 2, "%04x",&iwchar); wchar = iwchar; strcpy(wchbuf, ""); buffer_append(value_buffer, wchbuf,wstr_to_str(&wchar, 1, wchbuf)); p+= 4; } else{ buffer_append(value_buffer,p+1,1); } p++; } else if( *p == '\"'){ list_pop(state_stack); } else{ buffer_append(value_buffer,p,1); } } else if(s == 0x40){ // number value if(NUMBER_CHAR(*p)){ buffer_append(value_buffer, p, 1); } else{ list_pop(state_stack); continue; } } p++; } while((data = list_pop(data_stack))){ if(list_count(data_stack) ==0){ break; } (*json->object_dealloc)(json,data,InvokeTickArg); } buffer_dealloc(value_buffer); buffer_dealloc(name_buffer); buffer_dealloc(base64_buffer); list_dealloc(data_stack); list_dealloc(state_stack); return data; }