/** * int_set_format - format an &set for printing * @set: set attribute to be formatted * @way: style of format (0 for router ID list, 1 for community list) * @from: starting position in set * @buf: destination buffer * @size: size of buffer * * This function takes a set attribute and formats it. @way specifies * the style of format (router ID / community). @from argument can be * used to specify the first printed value for the purpose of printing * untruncated sets even with smaller buffers. If the output fits in * the buffer, 0 is returned, otherwise the position of the first not * printed item is returned. This value can be used as @from argument * in subsequent calls. If truncated output suffices, -1 can be * instead used as @from, in that case " ..." is eventually added at * the struct buffer to indicate truncation. */ int int_set_format(struct adata *set, int way, int from, byte *buf, uint size) { u32 *z = (u32 *) set->data; byte *end = buf + size - 24; int from2 = MAX(from, 0); int to = set->length / 4; int i; for (i = from2; i < to; i++) { if (buf > end) { if (from < 0) strcpy(buf, " ..."); else *buf = 0; return i; } if (i > from2) *buf++ = ' '; if (way) buf += bsprintf(buf, "(%d,%d)", z[i] >> 16, z[i] & 0xffff); else buf += bsprintf(buf, "%R", z[i]); }
/** * cli_printf - send reply to a CLI connection * @c: CLI connection * @code: numeric code of the reply, negative for continuation lines * @msg: a printf()-like formatting string. * * This function send a single line of reply to a given CLI connection. * In works in all aspects like bsprintf() except that it automatically * prepends the reply line prefix. * * Please note that if the connection can be already busy sending some * data in which case cli_printf() stores the output to a temporary buffer, * so please avoid sending a large batch of replies without waiting * for the buffers to be flushed. * * If you want to write to the current CLI output, you can use the cli_msg() * macro instead. */ void cli_printf(struct cli *c, int code, char *msg, ...) { va_list args; byte buf[CLI_LINE_SIZE]; int cd = code; int errcode; int size, cnt; if (cd < 0) { cd = -cd; if (cd == c->last_reply) size = bsprintf(buf, " "); else size = bsprintf(buf, "%04d-", cd); errcode = -8000; } else if (cd == CLI_ASYNC_CODE) { size = 1; buf[0] = '+'; errcode = cd; } else { size = bsprintf(buf, "%04d ", cd); errcode = 8000; } c->last_reply = cd; va_start(args, msg); cnt = bvsnprintf(buf+size, sizeof(buf)-size-1, msg, args); va_end(args); if (cnt < 0) { cli_printf(c, errcode, "<line overflow>"); return; } size += cnt; buf[size++] = '\n'; memcpy(cli_alloc_out(c, size), buf, size); }
void bprintf ( cstr_type format , TArgs && ...args ) { auto & chars = details::get_thread_local_chars (); bsprintf (chars, format, std::forward<TArgs> (args)...); details::write_to_cout (chars); }
void as_path_format(struct adata *path, byte *buf, unsigned int size) { byte *p = path->data; byte *e = p + path->length; byte *end = buf + size - 16; int sp = 1; int l, isset; while (p < e) { if (buf > end) { strcpy(buf, " ..."); return; } isset = (*p++ == AS_PATH_SET); l = *p++; if (isset) { if (!sp) *buf++ = ' '; *buf++ = '{'; sp = 0; } while (l-- && buf <= end) { if (!sp) *buf++ = ' '; buf += bsprintf(buf, "%u", get_as(p)); p += BS; sp = 0; } if (isset) { *buf++ = ' '; *buf++ = '}'; sp = 0; } } *buf = 0; }
static void cli_copy_message(struct cli *c) { byte *p, *q; uint cnt = 2; if (c->ring_overflow) { byte buf[64]; int n = bsprintf(buf, "<%d messages lost>\n", c->ring_overflow); c->ring_overflow = 0; memcpy(cli_alloc_out(c, n), buf, n); } p = c->ring_read; while (*p) { cnt++; p++; if (p == c->ring_end) p = c->ring_buf; ASSERT(p != c->ring_write); } c->async_msg_size += cnt; q = cli_alloc_out(c, cnt); *q++ = '+'; p = c->ring_read; do { *q = *p++; if (p == c->ring_end) p = c->ring_buf; } while (*q++); c->ring_read = p; q[-1] = '\n'; }
/** * Invoked from Total Commander's command line - or by pressing enter. */ int __stdcall FsExecuteFile(HWND MainWin, bchar * fullRemoteName, bchar * verb) { gMainWin = MainWin; WLock wlock; if (!verb || !*verb) return FS_EXEC_ERROR; // disable automatic reloads lastServer = 0; bstring cmd = verb; bstring fullRemotePath; if (fullRemoteName && *fullRemoteName) fullRemotePath = fullRemoteName + 1; // set the global mode!? -- ignore, since SFTP does not support it. if (cmd.length() > 5 && cmd.substr(0, 4) == TEXT("MODE")) { if (cmd[5] == 'A') transferAscii = true; else { modeExtensions.clear(); transferAscii = false; if (cmd[5] == 'X') { size_t start = (size_t)-1; for (size_t i = 6; i < cmd.size(); ++i) { if (cmd[i] == '.') start = i; else if (cmd[i] <= 32) { size_t len = i - start; bstring x = cmd.substr(start, len); modeExtensions.insert(std::make_pair(x, x)); start = (size_t)-1; } } if (start != (size_t)-1) { bstring x = cmd.substr(start); modeExtensions.insert(std::make_pair(x, x)); } } } return FS_EXEC_OK; } bstring remotePath; if (cmd == TEXT("open")) { size_t slash = fullRemotePath.find_first_of('\\'); if (slash != (size_t)-1) return FS_EXEC_YOURSELF; // it's a server name if (fullRemotePath != EDIT_CONNECTIONS) { // get or create the server Server * server = Server::findServer(remotePath, fullRemotePath.c_str()); if (!server) return FS_EXEC_ERROR; if (!server->connect()) { Server::removeServer(server->getName().c_str()); return FS_EXEC_ERROR; } // simply get the home folder and append. Otherwise the progress bar hides // connect and get the home folder bstring response; if (!server->getHomeDir(response)) return FS_EXEC_ERROR; // return the full remote path and force reload of dir fullRemoteName[0] = '/'; bstrcpy(fullRemoteName + 1, server->getName().c_str()); bstrcat(fullRemoteName, response.c_str()); toDos(fullRemoteName); return FS_EXEC_SYMLINK; } // It's edit connections. Create a temp server - maybe we keep it. Server server(TEXT("~")); // popup config dialog config_tag const * const cfg = server.doConfig(); if (!cfg) { fullRemoteName[1] = 0; return FS_EXEC_SYMLINK; } Sftp4tc const * const session = &cfg->sftp4tc; // is there a session? bstring sessionName; #ifdef UNICODE BCONVERT(wchar_t, 256, sessionName, session->selectedSession) #else sessionName = session->selectedSession; #endif bchar buf[16]; if (sessionName.length() == 0) { // no create a name from host sessionName = TEXT("quick connection ("); bsprintf(buf, TEXT("%d) "), ++quickConnectionCount); bchar const * host; #ifdef UNICODE BCONVERT(wchar_t, 256, host, cfg->host) #else host = cfg->host; #endif sessionName = sessionName + buf + host; } else