PUBLIC void mprWriteToOsLog(cchar *message, int level) { HKEY hkey; void *event; long errorType; ulong exists; char buf[ME_MAX_BUFFER], logName[ME_MAX_BUFFER], *cp, *value; wchar *lines[9]; int type; static int once = 0; scopy(buf, sizeof(buf), message); cp = &buf[slen(buf) - 1]; while (*cp == '\n' && cp > buf) { *cp-- = '\0'; } type = EVENTLOG_ERROR_TYPE; lines[0] = wide(buf); lines[1] = 0; lines[2] = lines[3] = lines[4] = lines[5] = 0; lines[6] = lines[7] = lines[8] = 0; if (once == 0) { /* Initialize the registry */ once = 1; fmt(logName, sizeof(logName), "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s", mprGetAppName()); hkey = 0; if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, wide(logName), 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, &exists) == ERROR_SUCCESS) { value = "%SystemRoot%\\System32\\netmsg.dll"; if (RegSetValueEx(hkey, UT("EventMessageFile"), 0, REG_EXPAND_SZ, (uchar*) value, (int) slen(value) + 1) != ERROR_SUCCESS) { RegCloseKey(hkey); return; } errorType = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; if (RegSetValueEx(hkey, UT("TypesSupported"), 0, REG_DWORD, (uchar*) &errorType, sizeof(DWORD)) != ERROR_SUCCESS) { RegCloseKey(hkey); return; } RegCloseKey(hkey); } } event = RegisterEventSource(0, wide(mprGetAppName())); if (event) { /* 3299 is the event number for the generic message in netmsg.dll. "%1 %2 %3 %4 %5 %6 %7 %8 %9" -- thanks Apache for the tip */ ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, 3299, NULL, sizeof(lines) / sizeof(wchar*), 0, lines, 0); DeregisterEventSource(event); } }
static int startProcess(MprCmd *cmd) { PROCESS_INFORMATION procInfo; STARTUPINFO startInfo; cchar *envBlock; int err; memset(&startInfo, 0, sizeof(startInfo)); startInfo.cb = sizeof(startInfo); startInfo.dwFlags = STARTF_USESHOWWINDOW; if (cmd->flags & MPR_CMD_SHOW) { startInfo.wShowWindow = SW_SHOW; } else { startInfo.wShowWindow = SW_HIDE; } startInfo.dwFlags |= STARTF_USESTDHANDLES; if (cmd->flags & MPR_CMD_IN) { if (cmd->files[MPR_CMD_STDIN].clientFd > 0) { startInfo.hStdInput = (HANDLE) _get_osfhandle(cmd->files[MPR_CMD_STDIN].clientFd); } } else { startInfo.hStdInput = (HANDLE) _get_osfhandle((int) fileno(stdin)); } if (cmd->flags & MPR_CMD_OUT) { if (cmd->files[MPR_CMD_STDOUT].clientFd > 0) { startInfo.hStdOutput = (HANDLE) _get_osfhandle(cmd->files[MPR_CMD_STDOUT].clientFd); } } else { startInfo.hStdOutput = (HANDLE) _get_osfhandle((int) fileno(stdout)); } if (cmd->flags & MPR_CMD_ERR) { if (cmd->files[MPR_CMD_STDERR].clientFd > 0) { startInfo.hStdError = (HANDLE) _get_osfhandle(cmd->files[MPR_CMD_STDERR].clientFd); } } else { startInfo.hStdError = (HANDLE) _get_osfhandle((int) fileno(stderr)); } envBlock = makeWinEnvBlock(cmd); if (! CreateProcess(0, wide(cmd->command), 0, 0, 1, 0, (char*) envBlock, wide(cmd->dir), &startInfo, &procInfo)) { err = mprGetOsError(); if (err == ERROR_DIRECTORY) { mprLog("error mpr cmd", 0, "Cannot create process: %s, directory %s is invalid", cmd->program, cmd->dir); } else { mprLog("error mpr cmd", 0, "Cannot create process: %s, %d", cmd->program, err); } return MPR_ERR_CANT_CREATE; } cmd->thread = procInfo.hThread; cmd->process = procInfo.hProcess; cmd->pid = procInfo.dwProcessId; return 0; }
NS_IMETHODIMP sbDatetimePropertyInfo::MakeSearchable(const nsAString & aValue, nsAString & _retval) { nsresult rv; PRInt64 value = 0; NS_ConvertUTF16toUTF8 narrow(aValue); _retval = aValue; _retval.StripWhitespace(); sbSimpleAutoLock lock(mMinMaxDateTimeLock); if(PR_sscanf(narrow.get(), gsFmtRadix10, &value) != 1) { _retval = EmptyString(); return NS_ERROR_INVALID_ARG; } char out[32] = {0}; if(PR_snprintf(out, 32, gsSortFmtRadix10, value) == (PRUint32)-1) { rv = NS_ERROR_FAILURE; _retval = EmptyString(); } else { NS_ConvertUTF8toUTF16 wide(out); rv = NS_OK; _retval = wide; } return rv; }
/// Conserts string ti it's lower presentation. REMutableString & REMutableString::toLower() { if (_p.isNotEmpty()) { if (this->isContainsNonASCII()) { REWideString wide(*this); const REUInt32 len = wide.length(); if (len > 0) { wchar_t * s = (wchar_t *)wide.wideChars(); while (*s) { *s = (wchar_t)towlower(*s); s++; } this->setFromWideString(s, len, REStringTypeUTF8); } } else { char * s = (char *)this->UTF8String(); while (*s) { *s = (char)tolower(*s); s++; } } } return (*this); }
std::wstring getWide(const std::string& text) { std::wstring wide(text.length(), L' '); std::copy(text.begin(), text.end(), wide.begin()); return wide; }
PUBLIC MprList *mprListRegistry(cchar *key) { HKEY top, h; wchar name[ME_MAX_PATH]; MprList *list; int index, size; assert(key && *key); /* Get the registry hive */ if ((key = getHive(key, &top)) == 0) { return 0; } if (RegOpenKeyEx(top, wide(key), 0, KEY_READ, &h) != ERROR_SUCCESS) { return 0; } list = mprCreateList(0, 0); index = 0; while (1) { size = sizeof(name) / sizeof(wchar); if (RegEnumValue(h, index, name, &size, 0, NULL, NULL, NULL) != ERROR_SUCCESS) { break; } mprAddItem(list, sclone(multi(name))); index++; } RegCloseKey(h); return list; }
void update(team *overall, batsman *team1, bowler *team2, matchinfo *info) { /*it is main updater function*/ char a[4]; char *e = "%s"; int v, x; system("clear"); start(overall); in_the_ground(team1); warming_up(team2); move(10, 11); printf("\e[1menter name of batsman on stike: " ANSI_COLOR_RESET); move(45, 11); scanf(e, name); onstrike = send_batsman(team1, name); move(10, 12); printf("\e[1menter name of batsman off strike:" ANSI_COLOR_RESET); move(45, 12); scanf(e, name); offstrike = send_batsman(team1, name); taking_guard(onstrike); taking_guard(offstrike); move(10, 13); printf("\e[1menter name of bowler: " ANSI_COLOR_RESET); move(35, 13); scanf(e, name); bowling = give_bowl(team2, name); shining_bowl(bowling); x = 27; while((overall->balls != (info->overs * 6)) && (overall->wickets != 10)) { move(0, 26); printf("\e[1menter runs made , wicket(w), wide(y), noball(n), extra(e) end inning(esc)" ANSI_COLOR_RESET); move(0, x); scanf("%s", a); x = 27; if(a[0] == 27) break; input(a); if(wrong) { move(0, 28); printf("\e[1mINVALIND INPUT:" ANSI_COLOR_RESET); x = 29; wrong = 0; continue; } else if(ab[0] == '\0') add_runs_with_no_extra(team1, team2, overall, info); else { if(ab[0] == 'y' || ab[0] == 'n' || ab[0] == 'e') { add_runs_with_extra(team1, team2, overall, info); } else { move(0,28); printf("\e[1mbowled(b), caught(c), lbw(l), run out(r), retired hurt(h), heatwicket(t), time out(o)" ANSI_COLOR_RESET); move(0, 29); wicket(team1, team2, overall, info); } } if((overall->innings == 2) && overall->target <= 0) break; }
HBufC8* QNFCNdefUtility::QString2HBufC8L(const QString& qstring) { TPtrC wide(static_cast<const TUint16*>(qstring.utf16()),qstring.length()); HBufC8* newBuf = HBufC8::NewL(wide.Length()); TPtr8 des = newBuf->Des(); des.Copy(wide); return newBuf; }
YBUTIL_DECL const std::wstring fast_widen(const std::string &narrow) { if (narrow.empty()) return std::wstring(); std::wstring wide(narrow.size(), L'\0'); size_t processed = do_fast_widen(narrow, wide); if (processed == narrow.size()) return wide; throw std::runtime_error("non ascii detected, fast_widen failed"); }
PUBLIC int mprWriteRegistry(cchar *key, cchar *name, cchar *value) { HKEY top, h, subHandle; ulong disposition; assert(key && *key); assert(value && *value); /* Get the registry hive */ if ((key = getHive(key, &top)) == 0) { return MPR_ERR_CANT_ACCESS; } if (name && *name) { /* Write a registry string value */ if (RegOpenKeyEx(top, wide(key), 0, KEY_ALL_ACCESS, &h) != ERROR_SUCCESS) { return MPR_ERR_CANT_ACCESS; } if (RegSetValueEx(h, wide(name), 0, REG_SZ, (uchar*) value, (int) slen(value) + 1) != ERROR_SUCCESS) { RegCloseKey(h); return MPR_ERR_CANT_READ; } } else { /* Create a new sub key */ if (RegOpenKeyEx(top, wide(key), 0, KEY_CREATE_SUB_KEY, &h) != ERROR_SUCCESS){ return MPR_ERR_CANT_ACCESS; } if (RegCreateKeyEx(h, wide(value), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &subHandle, &disposition) != ERROR_SUCCESS) { return MPR_ERR_CANT_ACCESS; } RegCloseKey(subHandle); } RegCloseKey(h); return 0; }
static void writetiff_(const char * fname, int sx, int sy, int sz, uint8_t * img, int Bpp, WICPixelFormatGUID pixfmt, enum WICTiffCompressionOption compression) { IWICBitmapEncoder *encoder; IWICBitmapFrameEncode *frame; IWICStream *stream; IPropertyBag2 *props; const unsigned plane_stride_bytes = Bpp*sx*sy; init(); CALL(factory,CreateEncoder,&GUID_ContainerFormatTiff,NULL,&encoder); CALL(factory,CreateStream,&stream); //CopyFileA(fname,"backup.tmp",FALSE); CALL(stream,InitializeFromFilename,wide(fname),GENERIC_WRITE); CALL(encoder,Initialize,(IStream*)stream,WICBitmapEncoderNoCache); { for(int z=0;z<sz;++z,img+=plane_stride_bytes){ CALL(encoder,CreateNewFrame,&frame,&props); { /* Set properties: See Note (1) below */ PROPBAG2 option={0}; VARIANT v; VariantInit(&v); v.vt = VT_UI1; v.bVal = compression; option.pstrName=L"TiffCompressionMethod"; CALL(props,Write,1,&option,&v); } CALL(frame,Initialize,props); CALL(frame,SetSize,sx,sy); { /* Some pixel formats don't work. */ WICPixelFormatGUID fmt = pixfmt; CALL(frame, SetPixelFormat, &fmt); /* might coerce the requested pixel format */ WARN(IsEqualGUID(&fmt,&pixfmt)); } CALL(frame,WritePixels,sy,sx*Bpp,plane_stride_bytes,(BYTE*)img); CALL0(frame,Commit); }} CALL0(encoder,Commit); RELEASE(frame); RELEASE(stream); RELEASE(encoder); //DeleteFileA("backup.tmp"); Error:; //CopyFileA("backup.tmp",fname,FALSE); //DeleteFileA("backup.tmp"); exit(-1); }
PUBLIC char *mprReadRegistry(cchar *key, cchar *name) { HKEY top, h; char *value; ulong type, size; assert(key && *key); /* Get the registry hive */ if ((key = getHive(key, &top)) == 0) { return 0; } if (RegOpenKeyEx(top, wide(key), 0, KEY_READ, &h) != ERROR_SUCCESS) { return 0; } /* Get the type */ if (RegQueryValueEx(h, wide(name), 0, &type, 0, &size) != ERROR_SUCCESS) { RegCloseKey(h); return 0; } if (type != REG_SZ && type != REG_EXPAND_SZ) { RegCloseKey(h); return 0; } if ((value = mprAlloc(size + 1)) == 0) { return 0; } if (RegQueryValueEx(h, wide(name), 0, &type, (uchar*) value, &size) != ERROR_SUCCESS) { RegCloseKey(h); return 0; } RegCloseKey(h); value[size] = '\0'; return value; }
static const std::wstring do_widen( const std::string &narrow, const std::locale &loc) { if (narrow.empty()) return std::wstring(); std::wstring wide(narrow.size(), L'\0'); size_t processed = do_fast_widen(narrow, wide); if (processed == narrow.size()) return wide; typedef std::string::traits_type::state_type state_type; typedef std::codecvt<wchar_t, char, state_type> CVT; const CVT& cvt = std::use_facet<CVT>(loc); state_type state = state_type(); const char* from_beg = &narrow[0]; const char* from_end = from_beg + narrow.size(); const char* from_nxt; wchar_t* to_beg = &wide[0]; wchar_t* to_end = to_beg + wide.size(); wchar_t* to_nxt; std::wstring::size_type sz = 0; std::codecvt_base::result r; do { r = cvt.in(state, from_beg, from_end, from_nxt, to_beg, to_end, to_nxt); switch (r) { case std::codecvt_base::error: throw std::runtime_error("error converting string to wstring"); case std::codecvt_base::partial: sz += to_nxt - to_beg; wide.resize(2*wide.size()); to_beg = &wide[sz]; to_end = &wide[0] + wide.size(); break; case std::codecvt_base::noconv: wide.resize(sz + (from_end-from_beg)); std::memcpy(&wide[sz], from_beg, (std::size_t)(from_end-from_beg)); r = std::codecvt_base::ok; break; case std::codecvt_base::ok: sz += to_nxt - to_beg; wide.resize(sz); break; } } while (r != std::codecvt_base::ok); return wide; }
PUBLIC int mprLoadNativeModule(MprModule *mp) { MprModuleEntry fn; void *handle; assert(mp); if ((handle = (HANDLE) MPR->appInstance) == 0) { handle = GetModuleHandle(NULL); } if (!handle || !mp->entry || !GetProcAddress(handle, mp->entry)) { #if ME_STATIC mprLog("error mpr", 0, "Cannot load module %s, product built static", mp->name); return MPR_ERR_BAD_STATE; #else MprPath info; char *at, *baseName; if ((at = mprSearchForModule(mp->path)) == 0) { mprLog("error mpr", 0, "Cannot find module \"%s\", cwd=\"%s\", search=\"%s\"", mp->path, mprGetCurrentPath(), mprGetModuleSearchPath()); return MPR_ERR_CANT_ACCESS; } mp->path = at; mprGetPathInfo(mp->path, &info); mp->modified = info.mtime; baseName = mprGetPathBase(mp->path); mprLog("info mpr", 4, "Loading native module %s", baseName); if ((handle = LoadLibrary(wide(mp->path))) == 0) { mprLog("error mpr", 0, "Cannot load module %s, errno=\"%d\"", mp->path, mprGetOsError()); return MPR_ERR_CANT_READ; } mp->handle = handle; #endif /* !ME_STATIC */ } else if (mp->entry) { mprLog("info mpr", 4, "Activating native module %s", mp->name); } if (mp->entry) { if ((fn = (MprModuleEntry) GetProcAddress((HINSTANCE) handle, mp->entry)) == 0) { mprLog("error mpr", 0, "Cannot load module %s, cannot find function \"%s\"", mp->name, mp->entry); FreeLibrary((HINSTANCE) handle); return MPR_ERR_CANT_ACCESS; } if ((fn)(mp->moduleData, mp) < 0) { mprLog("error mpr", 0, "Initialization for module %s failed", mp->name); FreeLibrary((HINSTANCE) handle); return MPR_ERR_CANT_INITIALIZE; } } return 0; }
/* Create a default window if the application has not already created one. */ PUBLIC int mprInitWindow() { MprWaitService *ws; WNDCLASS wc; HWND hwnd; wchar *name, *title; int rc; ws = MPR->waitService; if (ws->hwnd) { return 0; } name = (wchar*) wide(mprGetAppName()); title = (wchar*) wide(mprGetAppTitle()); wc.style = CS_HREDRAW | CS_VREDRAW; wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = 0; wc.hIcon = NULL; wc.lpfnWndProc = (WNDPROC) msgProc; wc.lpszMenuName = wc.lpszClassName = name; rc = RegisterClass(&wc); if (rc == 0) { mprError("Cannot register windows class"); return MPR_ERR_CANT_INITIALIZE; } hwnd = CreateWindow(name, title, WS_OVERLAPPED, CW_USEDEFAULT, 0, 0, 0, NULL, NULL, 0, NULL); if (!hwnd) { mprError("Cannot create window"); return -1; } ws->hwnd = hwnd; ws->socketMessage = MPR_SOCKET_MESSAGE; return 0; }
int add(DeviceList* const list, Element e) { if(++list->current < list->size) { chprintf((BaseSequentialStream *)&itm_port, "list->current: %i\n", list->current); chprintf((BaseSequentialStream *)&itm_port, "e.data: %i\n", e.data); list->elements[list->current] = e; chprintf((BaseSequentialStream *)&itm_port, "list->elements[list->current]: %i\n", list->elements[list->current]); return 1; }else { wide(list); list->elements[list->current] = e; return 1; } return 0; }
static int do_test (void) { char *path; { int fd = create_temp_file ("tst-bz24153-", &path); TEST_VERIFY_EXIT (fd >= 0); xwrite (fd, "abcdef", strlen ("abcdef")); xclose (fd); } narrow (path); wide (path); free (path); return 0; }
std::string get_exe_path() { TCHAR exepath[MAX_PATH+1]; GetModuleFileName(0, exepath, MAX_PATH+1); //TCHAR* qwe = exepath; //std::basic_string<TCHAR> path = qwe; //TODO Fix failure on accented chars in path #ifdef UNICODE std::wstring wide( exepath ); std::string path( wide.begin(), wide.end() ); #else std::string path = exepath; #endif return path; };
// Return current ByteCode and increment PC to next bytecode, skipping all // intermediate constants. Returns EOBC at end. // Expected usage: // while( (bc = iter.next()) != EOBC() ) { ... } Bytecodes::Code next() { _bc_start = _pc; // Capture start of bc if( _pc >= _end ) return EOBC(); // End-Of-Bytecodes // Fetch Java bytecode // All rewritten bytecodes maintain the size of original bytecode. _bc = Bytecodes::java_code((Bytecodes::Code)*_pc); int csize = Bytecodes::length_for(_bc); // Expected size if( _bc == Bytecodes::_wide ) { _bc=wide(); // Handle wide bytecode } else if( csize == 0 ) { _bc=table(_bc); // Handle inline tables } else { _pc += csize; // Bump PC past bytecode } return check_java(_bc); }
void ApplicationContextImpl::initialise(int argc, char* argv[]) { initArgs(argc, argv); // Get application data directory from environment std::string appData = getenv("APPDATA"); if (appData.empty()) { throw std::runtime_error( "Critical: cannot find APPDATA environment variable." ); } // Construct DarkRadiant home directory _homePath = appData + "\\DarkRadiant"; if (!os::makeDirectory(_homePath)) { std::cerr << "ApplicationContextImpl: could not create home directory " << "'" << _homePath << "'" << std::endl; } { // get path to the editor wchar_t filename[MAX_PATH+1]; GetModuleFileName(0, filename, MAX_PATH); wchar_t* last_separator = wcsrchr(filename, '\\'); if (last_separator != 0) { *(last_separator+1) = '\0'; } else { filename[0] = '\0'; } // convert to std::string std::wstring wide(filename); std::string appPathNarrow(wide.begin(), wide.end()); // Make sure we have forward slashes _appPath = os::standardPath(appPathNarrow); } // Initialise the relative paths initPaths(); }
void AppManagerPrivate::handleCommandLineArgsW(int argc, wchar_t** argv) { std::vector<std::string> utf8Args; if (argv) { for (int i = 0; i < argc; ++i) { std::wstring wide(argv[i]); std::string str = StrUtils::utf16_to_utf8(wide); assert(StrUtils::is_utf8(str.c_str())); utf8Args.push_back(str); } } else { // If the user didn't specify launch arguments (e.g unit testing), // At least append the binary path std::string path = ProcInfo::applicationDirPath(0); utf8Args.push_back(path); } copyUtf8ArgsToMembers(utf8Args); }
bool FlarmDevice::GetConfig(const char *setting, TCHAR *buffer, size_t length, OperationEnvironment &env) { char narrow_buffer[length * 2]; if (!GetConfig(setting, narrow_buffer, length * 2, env)) return false; if (StringIsEmpty(narrow_buffer)) { *buffer = _T('\0'); return true; } UTF8ToWideConverter wide(narrow_buffer); if (!wide.IsValid()) return false; CopyString(buffer, wide, length); return true; }
static void* readtiff_(const char * fname, int * sx_, int * sy_, int * sz_, int Bpp, WICPixelFormatGUID pixfmt) { unsigned sx,sy,sz; uint8_t* buf=0,*img; IWICBitmapDecoder *decoder=0; init(); CALL(factory,CreateDecoderFromFilename, wide(fname),0,GENERIC_READ, WICDecodeMetadataCacheOnDemand,&decoder); CALL(decoder,GetFrameCount,&sz); { for(unsigned iframe=0;iframe<sz;++iframe,img+=sx*sy*Bpp) { IWICBitmapFrameDecode *frame; IWICFormatConverter *converter; CALL(factory,CreateFormatConverter,&converter); CALL(decoder,GetFrame,iframe,&frame); // the frame is an IWICBitmapSource if(buf==0) { CALL(frame,GetSize,&sx,&sy); ERR(buf=brecs_alloc(sx*sy*sz*Bpp)); img=buf; } CALL(converter,Initialize,(IWICBitmapSource*)frame, &pixfmt, WICBitmapDitherTypeNone, 0, 0.0f, WICBitmapPaletteTypeCustom); CALL(converter,CopyPixels,0,sx*Bpp,sx*sy*Bpp,(BYTE*)img); RELEASE(converter); RELEASE(frame); }} RELEASE(decoder); *sx_=sx; *sy_=sy; *sz_=sz; return buf; Error:; return 0; }
const std::wstring StringUtil::AnsiToWide(const std::string& str) { ATL::CA2W ca2w(str.data()); std::wstring wide(ca2w); return wide; }
static int makeChannel(MprCmd *cmd, int index) { SECURITY_ATTRIBUTES clientAtt, serverAtt, *att; HANDLE readHandle, writeHandle; MprCmdFile *file; MprTicks now; char *pipeName; int openMode, pipeMode, readFd, writeFd; static int tempSeed = 0; memset(&clientAtt, 0, sizeof(clientAtt)); clientAtt.nLength = sizeof(SECURITY_ATTRIBUTES); clientAtt.bInheritHandle = 1; /* Server fds are not inherited by the child */ memset(&serverAtt, 0, sizeof(serverAtt)); serverAtt.nLength = sizeof(SECURITY_ATTRIBUTES); serverAtt.bInheritHandle = 0; file = &cmd->files[index]; now = ((int) mprGetTicks() & 0xFFFF) % 64000; lock(MPR->cmdService); pipeName = sfmt("\\\\.\\pipe\\MPR_%d_%d_%d.tmp", getpid(), (int) now, ++tempSeed); unlock(MPR->cmdService); /* Pipes are always inbound. The file below is outbound. we swap whether the client or server inherits the pipe or file. MPR_CMD_STDIN is the clients input pipe. Pipes are blocking since both ends share the same blocking mode. Client must be blocking. */ openMode = PIPE_ACCESS_INBOUND; pipeMode = 0; att = (index == MPR_CMD_STDIN) ? &clientAtt : &serverAtt; readHandle = CreateNamedPipe(wide(pipeName), openMode, pipeMode, 1, 0, 256 * 1024, 1, att); if (readHandle == INVALID_HANDLE_VALUE) { mprLog("error mpr cmd", 0, "Cannot create stdio pipes %s. Err %d", pipeName, mprGetOsError()); return MPR_ERR_CANT_CREATE; } readFd = _open_osfhandle((intptr_t) readHandle, 0); att = (index == MPR_CMD_STDIN) ? &serverAtt: &clientAtt; writeHandle = CreateFile(wide(pipeName), GENERIC_WRITE, 0, att, OPEN_EXISTING, openMode, 0); writeFd = _open_osfhandle((intptr_t) writeHandle, 0); if (readFd < 0 || writeFd < 0) { mprLog("error mpr cmd", 0, "Cannot create stdio pipes %s. Err %d", pipeName, mprGetOsError()); return MPR_ERR_CANT_CREATE; } if (index == MPR_CMD_STDIN) { file->clientFd = readFd; file->fd = writeFd; file->handle = writeHandle; } else { file->clientFd = writeFd; file->fd = readFd; file->handle = readHandle; } return 0; }
LRESULT ListView_InsertItemText(HWND wnd_lv, UINT item, UINT subitem, const char * text, bool b_set, LPARAM lp, int image_index) { pfc::stringcvt::string_os_from_utf8 wide(text); return ListView_InsertItemText(wnd_lv, item, subitem, const_cast<TCHAR*>(wide.get_ptr()), b_set, lp, image_index); }
void maktab(void) { # define FN(i,c) font[stynum[i]][c] # define SZ(i,c) csize[stynum[i]][c] /* define the tab stops of the table */ int icol, ilin, tsep, k, ik, vforml, il, text; int doubled[MAXCOL], acase[MAXCOL]; char *s; char space[40]; for(icol=0; icol <ncol; icol++) { doubled[icol] = acase[icol] = 0; fprintf(tabout, ".nr %d 0\n", icol+CRIGHT); for(text=0; text<2; text++) { if (text) { warnoff(); fprintf(tabout, ".%02d\n.rm %02d\n", icol+80, icol+80); warnon(); } for(ilin=0; ilin<nlin; ilin++) { if (instead[ilin]|| fullbot[ilin]) continue; vforml=ilin; for(il=prev(ilin); il>=0 && vspen(table[il][icol].col); il=prev(il)) vforml=il; if (fspan(vforml,icol)) continue; if (filler(table[ilin][icol].col)) continue; switch(ctype(vforml,icol)) { case 'a': acase[icol]=1; s = table[ilin][icol].col; if (tx(s) && text) { if (doubled[icol]==0) fprintf(tabout, ".nr %d 0\n.nr %d 0\n",S1,S2); doubled[icol]=1; nreg(space, sizeof(space), s, '-'); fprintf(tabout, ".if %s>\\n(%d .nr %d %s\n",space,S2,S2,space); } case 'n': if (table[ilin][icol].rcol!=0) { if (doubled[icol]==0 && text==0) fprintf(tabout, ".nr %d 0\n.nr %d 0\n", S1, S2); doubled[icol]=1; if (real(s=table[ilin][icol].col) && !vspen(s)) { if (tx(s) != text) continue; fprintf(tabout, ".nr %d ", TMP); wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n"); fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1, TMP, S1, TMP); } if (text==0 && real(s=table[ilin][icol].rcol) && !vspen(s) && !barent(s)) { fprintf(tabout, ".nr %d \\w%c%s%c\n",TMP, F1, s, F1); fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",S2,TMP,S2,TMP); } continue; } case 'r': case 'c': case 'l': if (real(s=table[ilin][icol].col) && !vspen(s)) { if (tx(s) != text) continue; fprintf(tabout, ".nr %d ", TMP); wide(s, FN(vforml,icol), SZ(vforml,icol)); fprintf(tabout, "\n"); fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", icol+CRIGHT, TMP, icol+CRIGHT, TMP); } } } } if (acase[icol]) { fprintf(tabout, ".if \\n(%d>=\\n(%d .nr %d \\n(%du+2n\n",S2,icol+CRIGHT,icol+CRIGHT,S2); } if (doubled[icol]) { fprintf(tabout, ".nr %d \\n(%d\n", icol+CMID, S1); fprintf(tabout, ".nr %d \\n(%d+\\n(%d\n",TMP,icol+CMID,S2); fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n",TMP,icol+CRIGHT,icol+CRIGHT,TMP); fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d +(\\n(%d-\\n(%d)/2\n",TMP,icol+CRIGHT,icol+CMID,icol+CRIGHT,TMP); } if (cll[icol][0]) { fprintf(tabout, ".nr %d %sn\n", TMP, cll[icol]); fprintf(tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n",icol+CRIGHT, TMP, icol+CRIGHT, TMP); } for(ilin=0; ilin<nlin; ilin++) if ((k=lspan(ilin, icol))) { s=table[ilin][icol-k].col; if (!real(s) || barent(s) || vspen(s) ) continue; fprintf(tabout, ".nr %d ", TMP); wide(table[ilin][icol-k].col, FN(ilin,icol-k), SZ(ilin,icol-k)); for(ik=k; ik>=0; ik--) { fprintf(tabout, "-\\n(%d",CRIGHT+icol-ik); if (!expflg && ik>0) fprintf(tabout, "-%dn", sep[icol-ik]); } fprintf(tabout, "\n"); fprintf(tabout, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP, TMP, TMP, k); fprintf(tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP); for(ik=0; ik<k; ik++) { if (doubled[icol-k+ik]) fprintf(tabout, ".nr %d +\\n(%d/2\n", icol-k+ik+CMID, TMP); fprintf(tabout, ".nr %d +\\n(%d\n", icol-k+ik+CRIGHT, TMP); } } } if (textflg) untext(); /* if even requested, make all columns widest width */ # define TMP1 S1 # define TMP2 S2 if (evenflg) { fprintf(tabout, ".nr %d 0\n", TMP); for(icol=0; icol<ncol; icol++) { if (evenup[icol]==0) continue; fprintf(tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n", icol+CRIGHT, TMP, TMP, icol+CRIGHT); } for(icol=0; icol<ncol; icol++) { if (evenup[icol]==0) /* if column not evened just retain old interval */ continue; if (doubled[icol]) fprintf(tabout, ".nr %d (100*\\n(%d/\\n(%d)*\\n(%d/100\n", icol+CMID, icol+CMID, icol+CRIGHT, TMP); /* that nonsense with the 100's and parens tries to avoid overflow while proportionally shifting the middle of the number */ fprintf(tabout, ".nr %d \\n(%d\n", icol+CRIGHT, TMP); } } /* now adjust for total table width */ for(tsep=icol=0; icol<ncol; icol++) tsep+= sep[icol]; if (expflg) { fprintf(tabout, ".nr %d 0", TMP); for(icol=0; icol<ncol; icol++) fprintf(tabout, "+\\n(%d", icol+CRIGHT); fprintf(tabout, "\n"); fprintf(tabout, ".nr %d \\n(.l-\\n(.i-\\n(%d%s\n", TMP, TMP, (utf8 || tlp) && (boxflg || dboxflg || allflg) ? "-1n" : ""); if (boxflg || dboxflg || allflg) tsep += 1; else tsep -= sep[ncol-1]; fprintf(tabout, ".nr %d \\n(%d/%d\n", TMP, TMP, tsep); fprintf(tabout, ".if \\n(%d<1n .nr %d 1n\n", TMP, TMP); } else if (xcolflg) { fprintf(tabout, ".nr %d 0", TMP); for(icol=0; icol<ncol; icol++) fprintf(tabout, "+\\n(%d", icol+CRIGHT); fprintf(tabout, "\n"); fprintf(tabout, ".nr %d \\n(.l-\\n(.i-\\n(%d-%dn/%d\n", TMP, TMP, tsep + ((boxflg || dboxflg || allflg) ? (utf8 || tlp) ? 2 : 1 : -1), xcolflg); for(icol=0; icol<ncol; icol++) { if (!xcol[icol]) continue; fprintf(tabout, ".nr %d +\\n(%d\n", icol+CRIGHT, TMP); } fprintf(tabout, ".nr %d 1n\n", TMP); } else fprintf(tabout, ".nr %d 1n\n", TMP); fprintf(tabout, ".nr %d 0\n",CRIGHT-1); tsep= (boxflg || allflg || dboxflg || left1flg) ? 1 : 0; for(icol=0; icol<ncol; icol++) { fprintf(tabout, ".nr %d \\n(%d+(%d*\\n(%d)\n",icol+CLEFT, icol+CRIGHT-1, tsep, TMP); fprintf(tabout, ".nr %d +\\n(%d\n",icol+CRIGHT, icol+CLEFT); if (doubled[icol]) { /* the next line is last-ditch effort to avoid zero field width */ /*fprintf(tabout, ".if \\n(%d=0 .nr %d 1\n",icol+CMID, icol+CMID);*/ fprintf(tabout, ".nr %d +\\n(%d\n", icol+CMID, icol+CLEFT); /* fprintf(tabout, ".if n .if \\n(%d%%24>0 .nr %d +12u\n",icol+CMID, icol+CMID); */ } tsep=sep[icol]; } if (rightl) fprintf(tabout, ".nr %d (\\n(%d+\\n(%d)/2\n",ncol+CRIGHT-1, ncol+CLEFT-1, ncol+CRIGHT-2); fprintf(tabout, ".nr TW \\n(%d\n", ncol+CRIGHT-1); if (boxflg || allflg || dboxflg) fprintf(tabout, ".nr TW +%d*\\n(%d\n", sep[ncol-1], TMP); fprintf(tabout, ".if t .if \\n(TW>\\n(.l .tm Table at line %d file %s is too wide - \\n(TW units\n", iline-1, ifile); return; }
void maktab(void) /* define the tab stops of the table */ { int icol, ilin, tsep, k, ik, vforml, il, s, text; char *ss; for (icol = 0; icol < ncol; icol++) { doubled[icol] = acase[icol] = 0; Bprint(&tabout, ".nr %2s 0\n", reg(icol, CRIGHT)); for (text = 0; text < 2; text++) { if (text) Bprint(&tabout, ".%2s\n.rm %2s\n", reg(icol, CRIGHT), reg(icol, CRIGHT)); for (ilin = 0; ilin < nlin; ilin++) { if (instead[ilin] || fullbot[ilin]) continue; vforml = ilin; for (il = prev(ilin); il >= 0 && vspen(table[il][icol].col); il = prev(il)) vforml = il; if (fspan(vforml, icol)) continue; if (filler(table[ilin][icol].col)) continue; if ((flags[icol][stynum[ilin]] & ZEROW) != 0) continue; switch (ctype(vforml, icol)) { case 'a': acase[icol] = 1; ss = table[ilin][icol].col; s = (int)(uintptr)ss; if (s > 0 && s < 128 && text) { if (doubled[icol] == 0) Bprint(&tabout, ".nr %d 0\n.nr %d 0\n", S1, S2); doubled[icol] = 1; Bprint(&tabout, ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n", s, S2, S2, (int)s); } case 'n': if (table[ilin][icol].rcol != 0) { if (doubled[icol] == 0 && text == 0) Bprint(&tabout, ".nr %d 0\n.nr %d 0\n", S1, S2); doubled[icol] = 1; if (real(ss = table[ilin][icol].col) && !vspen(ss)) { s = (int)(uintptr)ss; if (tx(s) != text) continue; Bprint(&tabout, ".nr %d ", TMP); wide(ss, FN(vforml, icol), SZ(vforml, icol)); Bprint(&tabout, "\n"); Bprint(&tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1, TMP, S1, TMP); } if (text == 0 && real(ss = table[ilin][icol].rcol) && !vspen(ss) && !barent(ss)) { Bprint(&tabout, ".nr %d \\w%c%s%c\n", TMP, F1, ss, F1); Bprint(&tabout, ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S2, TMP, S2, TMP); } continue; } case 'r': case 'c': case 'l': if (real(ss = table[ilin][icol].col) && !vspen(ss)) { s = (int)(uintptr)ss; if (tx(s) != text) continue; Bprint(&tabout, ".nr %d ", TMP); wide(ss, FN(vforml, icol), SZ(vforml, icol)); Bprint(&tabout, "\n"); Bprint(&tabout, ".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n", reg(icol, CRIGHT), TMP, reg(icol, CRIGHT), TMP); } } } } if (acase[icol]) { Bprint(&tabout, ".if \\n(%d>=\\n(%2s .nr %2s \\n(%du+2n\n", S2, reg(icol, CRIGHT), reg(icol, CRIGHT), S2); } if (doubled[icol]) { Bprint(&tabout, ".nr %2s \\n(%d\n", reg(icol, CMID), S1); Bprint(&tabout, ".nr %d \\n(%2s+\\n(%d\n", TMP, reg(icol, CMID), S2); Bprint(&tabout, ".if \\n(%d>\\n(%2s .nr %2s \\n(%d\n", TMP, reg(icol, CRIGHT), reg(icol, CRIGHT), TMP); Bprint(&tabout, ".if \\n(%d<\\n(%2s .nr %2s +(\\n(%2s-\\n(%d)/2\n", TMP, reg(icol, CRIGHT), reg(icol, CMID), reg(icol, CRIGHT), TMP); } if (cll[icol][0]) { Bprint(&tabout, ".nr %d %sn\n", TMP, cll[icol]); Bprint(&tabout, ".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n", reg(icol, CRIGHT), TMP, reg(icol, CRIGHT), TMP); } for (ilin = 0; ilin < nlin; ilin++) if (k = lspan(ilin, icol)) { ss = table[ilin][icol-k].col; if (!real(ss) || barent(ss) || vspen(ss) ) continue; Bprint(&tabout, ".nr %d ", TMP); wide(table[ilin][icol-k].col, FN(ilin, icol - k), SZ(ilin, icol - k)); for (ik = k; ik >= 0; ik--) { Bprint(&tabout, "-\\n(%2s", reg(icol - ik, CRIGHT)); if (!expflg && ik > 0) Bprint(&tabout, "-%dn", sep[icol-ik]); } Bprint(&tabout, "\n"); Bprint(&tabout, ".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP, TMP, TMP, k); Bprint(&tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP); for (ik = 1; ik <= k; ik++) { if (doubled[icol-k+ik]) Bprint(&tabout, ".nr %2s +\\n(%d/2\n", reg(icol - k + ik, CMID), TMP); Bprint(&tabout, ".nr %2s +\\n(%d\n", reg(icol - k + ik, CRIGHT), TMP); } } } if (textflg) untext(); /* if even requested, make all columns widest width */ if (evenflg) { Bprint(&tabout, ".nr %d 0\n", TMP); for (icol = 0; icol < ncol; icol++) { if (evenup[icol] == 0) continue; Bprint(&tabout, ".if \\n(%2s>\\n(%d .nr %d \\n(%2s\n", reg(icol, CRIGHT), TMP, TMP, reg(icol, CRIGHT)); } for (icol = 0; icol < ncol; icol++) { if (evenup[icol] == 0) /* if column not evened just retain old interval */ continue; if (doubled[icol]) Bprint(&tabout, ".nr %2s (100*\\n(%2s/\\n(%2s)*\\n(%d/100\n", reg(icol, CMID), reg(icol, CMID), reg(icol, CRIGHT), TMP); /* that nonsense with the 100's and parens tries to avoid overflow while proportionally shifting the middle of the number */ Bprint(&tabout, ".nr %2s \\n(%d\n", reg(icol, CRIGHT), TMP); } } /* now adjust for total table width */ for (tsep = icol = 0; icol < ncol; icol++) tsep += sep[icol]; if (expflg) { Bprint(&tabout, ".nr %d 0", TMP); for (icol = 0; icol < ncol; icol++) Bprint(&tabout, "+\\n(%2s", reg(icol, CRIGHT)); Bprint(&tabout, "\n"); Bprint(&tabout, ".nr %d \\n(.l-\\n(%d\n", TMP, TMP); if (boxflg || dboxflg || allflg) /* tsep += 1; */ {} else tsep -= sep[ncol-1]; Bprint(&tabout, ".nr %d \\n(%d/%d\n", TMP, TMP, tsep); Bprint(&tabout, ".if \\n(%d<0 .nr %d 0\n", TMP, TMP); } else Bprint(&tabout, ".nr %d 1n\n", TMP); Bprint(&tabout, ".nr %2s 0\n", reg(-1, CRIGHT)); tsep = (boxflg || allflg || dboxflg || left1flg) ? 2 : 0; if (sep[-1] >= 0) tsep = sep[-1]; for (icol = 0; icol < ncol; icol++) { Bprint(&tabout, ".nr %2s \\n(%2s+((%d*\\n(%d)/2)\n", reg(icol, CLEFT), reg(icol - 1, CRIGHT), tsep, TMP); Bprint(&tabout, ".nr %2s +\\n(%2s\n", reg(icol, CRIGHT), reg(icol, CLEFT)); if (doubled[icol]) { /* the next line is last-ditch effort to avoid zero field width */ /*Bprint(&tabout, ".if \\n(%2s=0 .nr %2s 1\n",reg(icol,CMID), reg(icol,CMID));*/ Bprint(&tabout, ".nr %2s +\\n(%2s\n", reg(icol, CMID), reg(icol, CLEFT)); /* Bprint(&tabout, ".if n .if \\n(%s%%24>0 .nr %s +12u\n",reg(icol,CMID), reg(icol,CMID)); */ } tsep = sep[icol] * 2; } if (rightl) Bprint(&tabout, ".nr %s (\\n(%s+\\n(%s)/2\n", reg(ncol - 1, CRIGHT), reg(ncol - 1, CLEFT), reg(ncol - 2, CRIGHT)); Bprint(&tabout, ".nr TW \\n(%2s\n", reg(ncol - 1, CRIGHT)); tsep = sep[ncol-1]; if (boxflg || allflg || dboxflg) Bprint(&tabout, ".nr TW +((%d*\\n(%d)/2)\n", tsep, TMP); Bprint(&tabout, ".if t .if (\\n(TW>\\n(.l .tm Table at line %d file %s is too wide - \\n(TW units\n", iline - 1, ifile); /* * Used to be: ".if t .if (\\n(TW+\\n(.o)>7.65i .tm Table at line %d file %s is too wide - \\n(TW units\n", iline - 1, ifile); * but that gives warnings where none are necessary (or desired) [sape] */ }
/* * define the tab stops of the table */ maktab() { int icol, ilin, tsep, k, ik, vforml, il, text; int doubled[MAXCOL], acase[MAXCOL]; char *s; for(icol = 0; icol < ncol; icol++){ doubled[icol] = acase[icol] = 0; printf(".nr %2s 0\n", reg(icol, CRIGHT)); for(text = 0; text < 2; text++){ if(text) printf(".%2s\n.rm %2s\n", reg(icol, CRIGHT), reg(icol, CRIGHT)); for(ilin = 0; ilin < nlin; ilin++){ if(instead[ilin] || fullbot[ilin]){ continue; } vforml = ilin; for(il = prev(ilin); il >= 0 && vspen(table[il][icol].col); il = prev(il)) vforml = il; if(fspan(vforml, icol)){ continue; } if(filler(table[ilin][icol].col)){ continue; } if((ctop[stynum[ilin]][icol] & ZEROW) != 0){ continue; } switch(ctype(vforml, icol)){ case 'a': acase[icol] = 1; s = table[ilin][icol].col; if(s > 0 && s < (char *)128 && text){ if(doubled[icol] == 0) printf( ".nr %d 0\n.nr %d 0\n", S1, S2); doubled[icol] = 1; printf( ".if \\n(%c->\\n(%d .nr %d \\n(%c-\n", s, S2, S2, s); } case 'n': if(table[ilin][icol].rcol != 0){ if(doubled[icol] == 0 && text == 0) printf( ".nr %d 0\n.nr %d 0\n", S1, S2); doubled[icol] = 1; if(real(s=table[ilin][icol].col) && !vspen(s)){ if(tx((int)s) != text) continue; printf(".nr %d ", TMP); wide(s, FN(vforml, icol), SZ(vforml, icol)); printf("\n"); printf( ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S1, TMP, S1, TMP); } if(text == 0 && real(s=table[ilin][icol].rcol) && !vspen(s) && !barent(s)){ printf( ".nr %d \\w%c%s%c\n", TMP, F1, s, F1); printf( ".if \\n(%d<\\n(%d .nr %d \\n(%d\n", S2, TMP, S2, TMP); } continue; } case 'r': case 'c': case 'l': if(real(s = table[ilin][icol].col) && !vspen(s)){ if(tx((int)s) != text) continue; printf(".nr %d ", TMP); wide(s, FN(vforml, icol), SZ(vforml, icol)); printf("\n"); printf( ".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n", reg(icol, CRIGHT), TMP, reg(icol, CRIGHT), TMP); } } } } if(acase[icol]){ printf(".if \\n(%d>=\\n(%2s .nr %2s \\n(%du+2n\n", S2, reg(icol, CRIGHT), reg(icol, CRIGHT), S2); } if(doubled[icol]){ printf(".nr %2s \\n(%d\n", reg(icol, CMID), S1); printf(".nr %d \\n(%2s+\\n(%d\n", TMP, reg(icol, CMID), S2); printf(".if \\n(%d>\\n(%2s .nr %2s \\n(%d\n", TMP, reg(icol, CRIGHT), reg(icol, CRIGHT), TMP); printf( ".if \\n(%d<\\n(%2s .nr %2s +(\\n(%2s-\\n(%d)/2\n", TMP, reg(icol, CRIGHT), reg(icol, CMID), reg(icol, CRIGHT), TMP); } if(cll[icol][0]){ printf(".nr %d %sn\n", TMP, cll[icol]); printf(".if \\n(%2s<\\n(%d .nr %2s \\n(%d\n", reg(icol, CRIGHT), TMP, reg(icol, CRIGHT), TMP); } for(ilin = 0; ilin < nlin; ilin++) if(k = lspan(ilin, icol)){ s = table[ilin][icol - k].col; if(!real(s) || barent(s) || vspen(s)) continue; printf(".nr %d ", TMP); wide(table[ilin][icol - k].col, FN(ilin, icol - k), SZ(ilin, icol - k)); for(ik = k; ik >= 0; ik--){ printf("-\\n(%2s", reg(icol-ik,CRIGHT)); if(!expflg && ik > 0) printf( "-%dn", sep[icol - ik]); } printf("\n"); printf(".if \\n(%d>0 .nr %d \\n(%d/%d\n", TMP, TMP, TMP, k); printf(".if \\n(%d<0 .nr %d 0\n", TMP, TMP); for(ik = 1; ik <= k; ik++){ if(doubled[icol - k + ik]){ printf(".nr %2s +\\n(%d/2\n", reg(icol - k + ik,CMID), TMP); } printf(".nr %2s +\\n(%d\n", reg(icol - k + ik, CRIGHT),TMP); } } } if(textflg) untext(); /* * if even requested, make all columns widest width */ #define TMP1 S1 #define TMP2 S2 if(evenflg){ printf(".nr %d 0\n", TMP); for(icol = 0; icol < ncol; icol++){ if(evenup[icol] == 0) continue; printf(".if \\n(%2s>\\n(%d .nr %d \\n(%2s\n", reg(icol, CRIGHT), TMP, TMP, reg(icol, CRIGHT)); } for(icol = 0; icol < ncol; icol++){ /* * if column not evened just retain old interval */ if(evenup[icol] == 0) continue; if(doubled[icol]) printf( ".nr %2s (100*\\n(%2s/\\n(%2s)*\\n(%d/100\n", reg(icol, CMID), reg(icol, CMID), reg(icol, CRIGHT), TMP); /* * that nonsense with the 100's and parens tries to avoid * overflow while proportionally shifting the middle of * the number */ printf(".nr %2s \\n(%d\n", reg(icol, CRIGHT), TMP); } } /* * now adjust for total table width */ for(tsep = icol = 0; icol < ncol; icol++) tsep += sep[icol]; if(expflg){ printf(".nr %d 0", TMP); for(icol = 0; icol < ncol; icol++) printf("+\\n(%2s", reg(icol, CRIGHT)); printf("\n"); /* * Bug fix: Most users expect the expand to take place * over the line length minus the current indentation * (I do as well, a bit ugly to see the table creeping * in the right margin (jna)) */ printf(".nr %d \\n(.l-\\n(.i-\\n(%d\n", TMP, TMP); if(boxflg || dboxflg || allflg) tsep += 1; else tsep -= sep[ncol - 1]; printf(".nr %d \\n(%d/%d\n", TMP, TMP, tsep); printf(".if \\n(%d<0 .nr %d 0\n", TMP, TMP); } else printf(".nr %d 1n\n", TMP); printf(".nr %2s 0\n", reg(-1,CRIGHT)); tsep = (boxflg || allflg || dboxflg || left1flg) ? 1 : 0; for(icol = 0; icol < ncol; icol++){ printf(".nr %2s \\n(%2s+(%d*\\n(%d)\n", reg(icol, CLEFT), reg(icol -1, CRIGHT), tsep, TMP); printf(".nr %2s +\\n(%2s\n",reg(icol, CRIGHT),reg(icol, CLEFT)); if(doubled[icol]){ /* * the next line is last-ditch effort to avoid * zero field width */ /* printf(".if \\n(%2s=0 .nr %2s 1\n", reg(icol,CMID), reg(icol,CMID)); */ printf(".nr %2s +\\n(%2s\n", reg(icol, CMID), reg(icol, CLEFT)); /* printf(".if n .if \\n(%2s%%24>0 .nr %2s +12u\n", reg(icol, CMID), reg(icol, CMID)); */ } tsep = sep[icol]; } if(rightl) printf(".nr %2s (\\n(%2s+\\n(%2s)/2\n", reg(ncol-1, CRIGHT), reg(ncol-1, CLEFT), reg(ncol-2, CRIGHT)); printf(".nr TW \\n(%2s\n", reg(ncol-1, CRIGHT)); if(boxflg || allflg || dboxflg) printf(".nr TW +%d*\\n(%d\n", sep[ncol - 1], TMP); printf( ".if t .if\\n(TW>\\n(.lu .tm Table at line %d file %s is too wide - \\n(TW units\n", iline - 1, strlen(oldname) ? oldname : ifile); return; }
uint8_t XR21B1411::Init(uint8_t parent, uint8_t port, bool lowspeed) { const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); uint8_t buf[constBufSize]; USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf); uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; uint8_t num_of_conf; // number of configurations AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("XR Init\r\n"); if(bAddress) return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; if(!p->epinfo) { USBTRACE("epinfo\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Restore p->epinfo p->epinfo = oldep_ptr; if(rcode) goto FailGetDevDescr; // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if(!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr(0, 0, bAddress); if(rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:", rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; num_of_conf = udd->bNumConfigurations; if((((udd->idVendor != 0x2890U) || (udd->idProduct != 0x0201U)) && ((udd->idVendor != 0x04e2U) || (udd->idProduct != 0x1411U)))) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if(rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for(uint8_t i = 0; i < num_of_conf; i++) { ConfigDescParser< USB_CLASS_COM_AND_CDC_CTRL, CDC_SUBCLASS_ACM, CDC_PROTOCOL_ITU_T_V_250, CP_MASK_COMPARE_CLASS | CP_MASK_COMPARE_SUBCLASS | CP_MASK_COMPARE_PROTOCOL > CdcControlParser(this); ConfigDescParser<USB_CLASS_CDC_DATA, 0, 0, CP_MASK_COMPARE_CLASS> CdcDataParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &CdcControlParser); if(rcode) goto FailGetConfDescr; rcode = pUsb->getConfDescr(bAddress, 0, i, &CdcDataParser); if(rcode) goto FailGetConfDescr; if(bNumEP > 1) break; } // for if(bNumEP < 4) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Conf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if(rcode) goto FailSetConfDescr; // Set up features status _enhanced_status = enhanced_features(); half_duplex(false); autoflowRTS(false); autoflowDSR(false); autoflowXON(false); wide(false); // Always false, because this is only available in custom mode. rcode = pAsync->OnInit(this); if(rcode) goto FailOnInit; USBTRACE("XR configured\r\n"); ready = true; //bPollEnable = true; //USBTRACE("Poll enabled\r\n"); return 0; FailGetDevDescr: #ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: #ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); #endif #ifdef DEBUG_USB_HOST Fail: NotifyFail(rcode); #endif Release(); return rcode; }