static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { ChatContext* ctx = (ChatContext*) self->x; uint8_t nick[MAX_NAME_LENGTH] = {0}; time_t now; time(&now); struct tm * timeinfo; timeinfo = localtime(&now); if(ctx->friendnum != num) return; getname(num, (uint8_t*) &nick); msg[len-1] = '\0'; nick[MAX_NAME_LENGTH-1] = '\0'; fix_name(msg); fix_name(nick); wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wattroff(ctx->history, COLOR_PAIR(2)); wattron(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s\n", msg); self->blink = true; beep(); flash(); }
/* * Find nvram param name; return pointer which should be treated as const * return NULL if not found. * * NOTE: This routine special-cases the variable wl_bss_enabled. It will * return the normal default value if asked for wl_ or wl0_. But it will * return 0 if asked for a virtual BSS reference like wl0.1_. */ char * nvram_default_get(const char *name) { int idx; char fixed_name[NVRAM_MAX_VALUE_LEN]; fix_name(name, fixed_name); if (strcmp(fixed_name, "wl_bss_enabled") == 0) { if (name[3] == '.' || name[4] == '.') { /* Virtual interface */ return "0"; } } if (!strcmp(nvram_safe_get("devicemode"), "1")) { for (idx = 0; router_defaults_override_type1[idx].name != NULL; idx++) { if (strcmp(router_defaults_override_type1[idx].name, fixed_name) == 0) { return router_defaults_override_type1[idx].value; } } } for (idx = 0; router_defaults[idx].name != NULL; idx++) { if (strcmp(router_defaults[idx].name, fixed_name) == 0) { return router_defaults[idx].value; } } return NULL; }
ToxWindow new_chat(int friendnum) { ToxWindow ret; memset(&ret, 0, sizeof(ret)); ret.onKey = &chat_onKey; ret.onDraw = &chat_onDraw; ret.onInit = &chat_onInit; ret.onMessage = &chat_onMessage; ret.onNickChange = &chat_onNickChange; ret.onStatusChange = &chat_onStatusChange; uint8_t nick[MAX_NAME_LENGTH] = {0}; getname(friendnum, (uint8_t*) &nick); fix_name(nick); snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); ChatContext* x = calloc(1, sizeof(ChatContext)); x->friendnum = friendnum; ret.x = (void*) x; return ret; }
static void fix_action(struct syntax *syn, struct action *a, const char *prefix) { if (a->destination) { const char *name = fix_name(a->destination->name, prefix); a->destination = find_state(syn, name); } if (a->emit_name) a->emit_name = xstrdup(a->emit_name); }
int friendlist_statuschange(int num, uint8_t* str, uint16_t len) { if(len >= MAX_USERSTATUS_LENGTH || num >= num_friends) return -1; memcpy((char*) &friends[num].status, (char*) str, len); friends[num].status[len] = 0; fix_name(friends[num].status); return 0; }
int friendlist_nickchange(int num, uint8_t* str, uint16_t len) { if(len >= MAX_NAME_LENGTH || num >= num_friends) return -1; memcpy((char*) &friends[num].name, (char*) str, len); friends[num].name[len] = 0; fix_name(friends[num].name); return 0; }
std::shared_ptr<const Term> TermFactory::create(const std::string& term_name, std::istream& in) const { auto creator = impl->creators.find(fix_name(term_name)); if (creator == impl->creators.end()) { std::string msg = "TermFactory::create: Unknown Term "; msg += term_name; throw runtime_error(msg.c_str()); } return std::shared_ptr<const Term>(creator->second(in)); }
static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t len) { ChatContext *ctx = (ChatContext*) self->x; if (ctx->friendnum != num) return; nick[len-1] = '\0'; fix_name(nick); snprintf(self->title, sizeof(self->title), "[%s (%d)]", nick, num); wattron(ctx->history, COLOR_PAIR(3)); wprintw(ctx->history, " * Your partner changed nick to '%s'\n", nick); wattroff(ctx->history, COLOR_PAIR(3)); }
void GuiDelimiter::updateTeXCode(int size) { bool const bigsize = size != 0; QString left_str = fix_name(leftLW->currentItem()->toolTip(), bigsize); QString right_str = fix_name(rightLW->currentItem()->toolTip(), bigsize); if (!bigsize) tex_code_ = left_str + ' ' + right_str; else { tex_code_ = bigleft[size] + ' ' + left_str + ' ' + bigright[size] + ' ' + right_str; } // Generate TeX-code for GUI display. // FIXME: Instead of reconstructing the TeX code it would be nice to // FIXME: retrieve the LateX code directly from mathed. // In all cases, we want the '\' prefix if needed, so we pass 'true' // to fix_name. left_str = fix_name(leftLW->currentItem()->toolTip(), true); right_str = fix_name(rightLW->currentItem()->toolTip(), true); QString code_str; if (!bigsize) code_str = "\\left" + left_str + " \\right" + right_str; else { // There should be nothing in the TeX-code when the delimiter is "None". if (left_str != ".") code_str = "\\" + bigleft[size] + left_str + ' '; if (right_str != ".") code_str += "\\" + bigright[size] + right_str; } texCodeL->setText(qt_("TeX Code: ") + code_str); }
struct state *merge_syntax(struct syntax *syn, struct syntax_merge *m) { // NOTE: string_lists is owned by struct syntax so there's no need to // copy it. Freeing struct condition does not free any string lists. const char *prefix = get_prefix(); struct ptr_array *states = &syn->states; int i, old_count = states->count; states->count += m->subsyn->states.count; if (states->count > states->alloc) { states->alloc = states->count; xrenew(states->ptrs, states->alloc); } memcpy(states->ptrs + old_count, m->subsyn->states.ptrs, sizeof(*states->ptrs) * m->subsyn->states.count); for (i = old_count; i < states->count; i++) { struct state *s = xmemdup(states->ptrs[i], sizeof(struct state)); int j; states->ptrs[i] = s; s->name = xstrdup(fix_name(s->name, prefix)); s->emit_name = xstrdup(s->emit_name); s->conds.ptrs = xmemdup(s->conds.ptrs, sizeof(void *) * s->conds.alloc); for (j = 0; j < s->conds.count; j++) s->conds.ptrs[j] = xmemdup(s->conds.ptrs[j], sizeof(struct condition)); // Mark unvisited so that state that is used only as a return state gets visited. s->visited = false; // Don't complain about unvisited copied states. s->copied = true; } for (i = old_count; i < states->count; i++) { fix_conditions(syn, states->ptrs[i], m, prefix); if (m->delim) update_state_colors(syn, states->ptrs[i]); } m->subsyn->used = true; return states->ptrs[old_count]; }
static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint16_t len) { ChatContext *ctx = (ChatContext *) self->x; struct tm *timeinfo = get_time(); if (ctx->friendnum != num) return; wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wattroff(ctx->history, COLOR_PAIR(2)); status[len - 1] = '\0'; fix_name(status); snprintf(self->title, sizeof(self->title), "[%s (%d)]", status, num); wattron(ctx->history, COLOR_PAIR(3)); wprintw(ctx->history, "* Your partner changed status to '%s'\n", status); wattroff(ctx->history, COLOR_PAIR(3)); }
static void chat_onAction(ToxWindow *self, Messenger *m, int num, uint8_t *action, uint16_t len) { ChatContext *ctx = (ChatContext *) self->x; struct tm *timeinfo = get_time(); if (ctx->friendnum != num) return; action[len - 1] = '\0'; fix_name(action); wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wattroff(ctx->history, COLOR_PAIR(2)); wattron(ctx->history, COLOR_PAIR(5)); wprintw(ctx->history, "%s\n", action); wattroff(ctx->history, COLOR_PAIR(5)); self->blink = true; beep(); }
static void chat_onKey(ToxWindow *self, Messenger *m, int key) { ChatContext *ctx = (ChatContext *) self->x; struct tm *timeinfo = get_time(); int x, y, y2, x2; getyx(self->window, y, x); getmaxyx(self->window, y2, x2); /* Add printable chars to buffer and print on input space */ if (isprint(key)) { if (ctx->pos != sizeof(ctx->line) - 1) { mvwaddch(self->window, y, x, key); ctx->line[ctx->pos++] = key; ctx->line[ctx->pos] = '\0'; } } /* BACKSPACE key: Remove one character from line */ else if (key == 0x107 || key == 0x8 || key == 0x7f) { if (ctx->pos > 0) { ctx->line[--ctx->pos] = '\0'; if (x == 0) mvwdelch(self->window, y - 1, x2 - 1); else mvwdelch(self->window, y, x - 1); } } /* RETURN key: Execute command or print line */ else if (key == '\n') { wclear(ctx->linewin); wmove(self->window, y2 - CURS_Y_OFFSET, 0); wclrtobot(self->window); if (ctx->line[0] == '/') execute(self, ctx, m, ctx->line); else { /* make sure the string has at least non-space character */ if (!string_is_empty(ctx->line)) { uint8_t selfname[MAX_NAME_LENGTH]; getself_name(m, selfname, sizeof(selfname)); fix_name(selfname); wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wattroff(ctx->history, COLOR_PAIR(2)); wattron(ctx->history, COLOR_PAIR(1)); wprintw(ctx->history, "%s: ", selfname); wattroff(ctx->history, COLOR_PAIR(1)); wprintw(ctx->history, "%s\n", ctx->line); if (m_sendmessage(m, ctx->friendnum, (uint8_t *) ctx->line, strlen(ctx->line) + 1) == 0) { wattron(ctx->history, COLOR_PAIR(3)); wprintw(ctx->history, " * Failed to send message.\n"); wattroff(ctx->history, COLOR_PAIR(3)); } } } ctx->line[0] = '\0'; ctx->pos = 0; } }
void TermFactory::teach_term(const std::string& term_name, const TermCreator& creator) { impl->creators[fix_name(term_name)] = creator; }