/** * get parent dir name */ char* swoole_dirname(char *file) { char *dirname = sw_strdup(file); if (dirname == NULL) { swWarn("strdup() failed."); return NULL; } int i = strlen(dirname); if (dirname[i - 1] == '/') { i -= 2; } for (; i > 0; i--) { if ('/' == dirname[i]) { dirname[i] = 0; break; } } return dirname; }
/* event_whois_host: 338, 616 Example: :irc.server.com 338 <issuer> <target> <IP> :actually using host :irc.server.com 338 <issuer> <target> :is actually <user@host> [<IP>] :irc.server.com 616 <issuer> <target> :real hostname ... */ void event_whois_host(struct irc_message_compo *compo) { PRINTTEXT_CONTEXT ctx; char *state = ""; char *str, *str_copy, *cp; if (strFeed(compo->params, 2) != 2) { goto bad; } (void) strtok_r(compo->params, "\n", &state); (void) strtok_r(NULL, "\n", &state); if ((str = strtok_r(NULL, "\n", &state)) == NULL) { goto bad; } str_copy = sw_strdup(str); cp = &str_copy[0]; squeeze(str_copy, ":"); printtext_context_init(&ctx, g_active_window, TYPE_SPEC1, true); printtext(&ctx, "%s %s", Theme("whois_host"), cp); free(str_copy); return; bad: printtext_context_init(&ctx, g_status_window, TYPE_SPEC1_WARN, true); printtext(&ctx, "On issuing event %s: An error occurred", compo->command); }
int swProcessPool_create_stream_socket(swProcessPool *pool, char *socket_file, int blacklog) { if (pool->ipc_mode != SW_IPC_SOCKET) { swWarn("ipc_mode is not SW_IPC_SOCKET."); return SW_ERR; } pool->stream->socket_file = sw_strdup(socket_file); if (pool->stream->socket_file == NULL) { return SW_ERR; } pool->stream->socket = swSocket_create_server(SW_SOCK_UNIX_STREAM, pool->stream->socket_file, 0, blacklog); if (pool->stream->socket < 0) { return SW_ERR; } return SW_OK; }
/** * Initiate a new readline session */ static struct readline_session_context * new_session(const char *prompt) { struct readline_session_context *ctx = xcalloc(sizeof *ctx, 1); ctx->buffer = xcalloc(readline_buffersize + 1, sizeof (wchar_t)); ctx->bufpos = 0; ctx->n_insert = 0; ctx->insert_mode = false; ctx->no_bufspc = false; ctx->prompt = sw_strdup(prompt); ctx->prompt_size = (int) strlen(prompt); ctx->act = panel_window(readline_pan1); panel_state = PANEL1_ACTIVE; readline_top_panel(); return ctx; }
/** * Initialize color pairs by calling init_pair() * * @return The no. of pairs that have been initialized. And on error * it returns a negative value. */ static short int init_color_pairs() { short int pair_n = 0; short int colors[] = { COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE }; const size_t numColors = ARRAY_SIZE(colors); short int *fg, *bg; /* Initialize black on black */ if (init_pair(++pair_n, colors[0], colors[0]) == ERR) { err_msg("Could not initialize pair %hd", pair_n); return -1; } /* Initialize a color on the default background of the terminal */ if (theme_bool_unparse("term_use_default_colors", true)) { short int *psi; for (psi = &colors[0]; psi < &colors[numColors]; psi++) { if (init_pair(++pair_n, *psi, -1) == ERR) { err_msg("Could not initialize pair %hd", pair_n); return -1; } } } for (fg = &colors[0]; fg < &colors[numColors]; fg++) { for (bg = &colors[0]; bg < &colors[numColors]; bg++) { if (*fg != *bg && init_pair(++pair_n, *fg, *bg) == ERR) { if (pair_n == 64) { /* The pair number is 64. The terminal that is * being used most likely lack support for pairs * >= 64. However: don't return -1 to indicate an * error. */ return 63; } else { char *fg_name = sw_strdup(strColor(*fg)); char *bg_name = sw_strdup(strColor(*bg)); err_msg("Could not initialize pair %hd (%s, %s)", pair_n, fg_name, bg_name); free(fg_name); free(bg_name); return -1; } } } } return pair_n; }