本文整理匯總了C++中ARRAY_ITEM函數的典型用法代碼示例。如果您正苦於以下問題:C++ ARRAY_ITEM函數的具體用法?C++ ARRAY_ITEM怎麽用?C++ ARRAY_ITEM使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ARRAY_ITEM函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: server_lock
void
server_lock(void)
{
struct client *c;
static struct passwd *pw, pwstore;
static char pwbuf[_PW_BUF_LEN];
u_int i;
if (server_locked)
return;
if (getpwuid_r(getuid(), &pwstore, pwbuf, sizeof pwbuf, &pw) != 0) {
server_locked_pw = NULL;
return;
}
server_locked_pw = pw;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue;
status_prompt_clear(c);
status_prompt_set(c,
"Password:", server_lock_callback, NULL, c, PROMPT_HIDDEN);
server_redraw_client(c);
}
server_locked = 1;
}
示例2: tty_write
void
tty_write(void (*cmdfn)(
struct tty *, const struct tty_ctx *), const struct tty_ctx *ctx)
{
struct window_pane *wp = ctx->wp;
struct client *c;
u_int i;
/* wp can be NULL if updating the screen but not the terminal. */
if (wp == NULL)
return;
if (wp->window->flags & WINDOW_REDRAW || wp->flags & PANE_REDRAW)
return;
if (wp->window->flags & WINDOW_HIDDEN || !window_pane_visible(wp))
return;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue;
if (c->flags & CLIENT_SUSPENDED)
continue;
if (c->session->curw->window == wp->window) {
if (c->tty.flags & TTY_FREEZE || c->tty.term == NULL)
continue;
cmdfn(&c->tty, ctx);
}
}
}
示例3: cmd_list_sessions_exec
int
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{
struct session *s;
struct session_group *sg;
char *tim, tmp[64];
u_int i, idx;
time_t t;
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
s = ARRAY_ITEM(&sessions, i);
if (s == NULL)
continue;
sg = session_group_find(s);
if (sg == NULL)
*tmp = '\0';
else {
idx = session_group_index(sg);
xsnprintf(tmp, sizeof tmp, " (group %u)", idx);
}
t = s->creation_time.tv_sec;
tim = ctime(&t);
*strchr(tim, '\n') = '\0';
ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s",
s->name, winlink_count(&s->windows), tim, s->sx, s->sy,
tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
}
return (0);
}
示例4: ci_alist_hash
/*
* Returns an entry that has been displaced, if any.
*/
array_item *add_to_array (array *a, array_item *item)
{
int count;
int location = 0;
array_item * ret = NULL;
u_32int_t mask; /* Dummy var */
if (a->hash == HASH_INSENSITIVE)
item->hash = ci_alist_hash(item->name, &mask);
else
item->hash = cs_alist_hash(item->name, &mask);
check_array_size(a);
if (a->max)
{
find_array_item(a, item->name, &count, &location);
if (count < 0)
{
ret = ARRAY_ITEM(a, location);
a->max--;
}
else
move_array_items(a, location, a->max, 1);
}
a->list[location] = item;
a->max++;
return ret;
}
示例5: control_notify_window_layout_changed
void
control_notify_window_layout_changed(struct window *w)
{
struct client *c;
struct session *s;
struct format_tree *ft;
struct winlink *wl;
u_int i;
const char *template;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
continue;
s = c->session;
if (winlink_find_by_window_id(&s->windows, w->id) == NULL)
continue;
#ifndef TMATE_SLAVE
/*
* When the last pane in a window is closed it won't have a
* layout root and we don't need to inform the client about the
* layout change because the whole window will go away soon.
*/
if (w->layout_root == NULL)
continue;
示例6: cmd_list_clients_exec
/* ARGSUSED */
int
cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct client *c;
struct session *s;
u_int i;
const char *s_utf8;
if (args_has(args, 't')) {
s = cmd_find_session(ctx, args_get(args, 't'), 0);
if (s == NULL)
return (-1);
} else
s = NULL;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue;
if (c->tty.flags & TTY_UTF8)
s_utf8 = " (utf8)";
else
s_utf8 = "";
if (s != NULL && s != c->session)
continue;
ctx->print(ctx, "%s: %s [%ux%u %s]%s", c->tty.path,
c->session->name, c->tty.sx, c->tty.sy,
c->tty.termname, s_utf8);
}
return (0);
}
示例7: server_unlock
int
server_unlock(const char *s)
{
struct client *c;
u_int i;
char *out;
if (!server_locked)
return (0);
if (server_password != NULL) {
if (s == NULL)
return (-1);
out = crypt(s, server_password);
if (strcmp(out, server_password) != 0)
return (-1);
}
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL)
continue;
status_prompt_clear(c);
server_redraw_client(c);
}
server_locked = 0;
return (0);
}
示例8: paste_get_index
/* Get an item by its index. */
struct paste_buffer *
paste_get_index(struct paste_stack *ps, u_int idx)
{
if (idx >= ARRAY_LENGTH(ps))
return (NULL);
return (ARRAY_ITEM(ps, idx));
}
示例9: fetch_mbox_make
/* Make an array of all the mboxes to visit. */
int
fetch_mbox_make(struct account *a)
{
struct fetch_mbox_data *data = a->data;
struct fetch_mbox_mbox *fmbox;
char *path;
u_int i, j;
glob_t g;
ARRAY_INIT(&data->fmboxes);
for (i = 0; i < ARRAY_LENGTH(data->mboxes); i++) {
path = ARRAY_ITEM(data->mboxes, i);
if (glob(path, GLOB_BRACE|GLOB_NOCHECK, NULL, &g) != 0) {
log_warn("%s: glob(\"%s\")", a->name, path);
goto error;
}
if (g.gl_pathc < 1)
fatalx("glob returned garbage");
for (j = 0; j < (u_int) g.gl_pathc; j++) {
fmbox = xcalloc(1, sizeof *fmbox);
fmbox->path = xstrdup(g.gl_pathv[j]);
fmbox->fd = -1;
fmbox->base = NULL;
ARRAY_ADD(&data->fmboxes, fmbox);
}
globfree(&g);
}
return (0);
error:
for (i = 0; i < ARRAY_LENGTH(&data->fmboxes); i++) {
fmbox = ARRAY_ITEM(&data->fmboxes, i);
xfree(fmbox->path);
xfree(fmbox);
}
ARRAY_FREE(&data->fmboxes);
return (-1);
}
示例10: move_array_items
/*
* Move ``start'' through ``end'' array elements ``dir'' places up
* in the array. If ``dir'' is negative, move them down in the array.
* Fill in the vacated spots with NULLs.
*/
void move_array_items (array *a, int start, int end, int dir)
{
int i;
if (dir > 0)
{
for (i = end; i >= start; i--)
LARRAY_ITEM(a, i + dir) = ARRAY_ITEM(a, i);
for (i = dir; i > 0; i--)
LARRAY_ITEM(a, start + i - 1) = NULL;
}
else if (dir < 0)
{
for (i = start; i <= end; i++)
LARRAY_ITEM(a, i + dir) = ARRAY_ITEM(a, i);
for (i = end - dir + 1; i <= end; i++)
LARRAY_ITEM(a, i) = NULL;
}
}
示例11: keywords_clear
void
keywords_clear()
{
int i;
for (i = 0; i < ARRAY_LENGTH(&keywords); i++)
xfree(ARRAY_ITEM(&keywords, i));
ARRAY_CLEAR(&keywords);
}
示例12: imap_state_select1
/* Select state 1. */
int
imap_state_select1(struct account *a, struct fetch_ctx *fctx)
{
struct fetch_imap_data *data = a->data;
if (imap_putln(a, "%u SELECT {%zu}",
++data->tag, strlen(ARRAY_ITEM(data->folders, data->folder))) != 0)
return (FETCH_ERROR);
fctx->state = imap_state_select2;
return (FETCH_BLOCK);
}
示例13: num_clients
static int num_clients(void)
{
unsigned int i, count = 0;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
if (ARRAY_ITEM(&clients, i))
count++;
}
return count;
}
示例14: print_results
void
print_results()
{
int i;
struct result *result;
for (i = 0; i < ARRAY_LENGTH(&results); i++) {
result = ARRAY_ITEM(&results, i);
if (result->status == RESULT_SHOW)
printf("%ls\n", result->value);
}
}
示例15: imap_state_body
/* Body state. */
int
imap_state_body(struct account *a, struct fetch_ctx *fctx)
{
struct fetch_imap_data *data = a->data;
struct mail *m = fctx->mail;
struct fetch_imap_mail *aux;
char *line, *ptr;
u_int n;
if (imap_getln(a, fctx, IMAP_UNTAGGED, &line) != 0)
return (FETCH_ERROR);
if (line == NULL)
return (FETCH_BLOCK);
if (sscanf(line, "* %u FETCH (", &n) != 1)
return (imap_invalid(a, line));
if ((ptr = strstr(line, "BODY[] {")) == NULL)
return (imap_invalid(a, line));
if (sscanf(ptr, "BODY[] {%zu}", &data->size) != 1)
return (imap_invalid(a, line));
data->lines = 0;
/* Fill in local data. */
aux = xcalloc(1, sizeof *aux);
aux->uid = ARRAY_FIRST(&data->wanted);
m->auxdata = aux;
m->auxfree = imap_free;
ARRAY_REMOVE(&data->wanted, 0);
/* Open the mail. */
if (mail_open(m, data->size) != 0) {
log_warnx("%s: failed to create mail", a->name);
return (FETCH_ERROR);
}
m->size = 0;
/* Tag mail. */
default_tags(&m->tags, data->src);
if (data->server.host != NULL) {
add_tag(&m->tags, "server", "%s", data->server.host);
add_tag(&m->tags, "port", "%s", data->server.port);
}
add_tag(&m->tags, "server_uid", "%u", aux->uid);
add_tag(&m->tags,
"folder", "%s", ARRAY_ITEM(data->folders, data->folder));
/* If we already know the mail is oversize, start off flushing it. */
data->flushing = data->size > conf.max_size;
fctx->state = imap_state_line;
return (FETCH_AGAIN);
}