Ejemplo n.º 1
0
static void gui_level(int id, int i)
{
    struct level *l = get_level(i);

    const GLubyte *fore = 0;
    const GLubyte *back = 0;

    int jd;

    if (!l)
    {
        gui_label(id, " ", GUI_SML, gui_blk, gui_blk);
        return;
    }

    if (level_opened(l))
    {
        fore = level_bonus(l)     ? gui_grn : gui_wht;
        back = level_completed(l) ? fore    : gui_yel;
    }

    jd = gui_label(id, level_name(l), GUI_SML, back, fore);

    if (level_opened(l) || config_cheat())
        gui_set_state(jd, START_LEVEL, i);
}
display_options()
{
	/** Display all the available options.. **/

	char *sort_name();

	ClearScreen();
	Centerline(0,"-- ELM Options Editor --");

#ifdef ENABLE_CALENDAR
	PutLine1(2, 0, "C)alendar file       : %s", raw_calendar_file);
#endif
	PutLine1(3, 0, "D)isplay mail using  : %s", raw_pager);
	PutLine1(4, 0, "E)ditor              : %s", raw_editor);
	PutLine1(5, 0, "F)older directory    : %s", raw_folders);
	PutLine1(6, 0, "S)orting criteria    : %s", sort_name(FULL));
	PutLine1(7, 0, "O)utbound mail saved : %s", raw_sentmail);
	PutLine1(8, 0, "P)rint mail using    : %s", raw_printout);
	PutLine1(9, 0, "Y)our full name      : %s", full_username);

	PutLine1(12,0, "A)rrow cursor        : %s", onoff(arrow_cursor));
	PutLine1(13,0, "M)enu display        : %s", onoff(mini_menu));

	PutLine1(15,0, "U)ser level          : %s", level_name(user_level));
	PutLine1(16,0, "N)ames only          : %s", onoff(names_only));
}
Ejemplo n.º 3
0
/// Return the log buffer up to limit as a python list. Called by management agent.
PyObject *qd_log_recent_py(long limit) {
    if (PyErr_Occurred()) return NULL;
    PyObject *list = PyList_New(0);
    PyObject *py_entry = NULL;
    if (!list) goto error;
    qd_log_entry_t *entry = DEQ_TAIL(entries);
    while (entry && limit) {
        const int ENTRY_SIZE=6;
        py_entry = PyList_New(ENTRY_SIZE);
        if (!py_entry) goto error;
        int i = 0;
        // NOTE: PyList_SetItem steals a reference so no leak here.
        PyList_SetItem(py_entry, i++, PyString_FromString(entry->module));
        const char* level = level_name(entry->level);
        PyList_SetItem(py_entry, i++, level ? PyString_FromString(level) : inc_none());
        PyList_SetItem(py_entry, i++, PyString_FromString(entry->text));
        PyList_SetItem(py_entry, i++, entry->file ? PyString_FromString(entry->file) : inc_none());
        PyList_SetItem(py_entry, i++, entry->file ? PyLong_FromLong(entry->line) : inc_none());
        PyList_SetItem(py_entry, i++, PyLong_FromLongLong((PY_LONG_LONG)entry->time));
        assert(i == ENTRY_SIZE);
        if (PyErr_Occurred()) goto error;
        PyList_Insert(list, 0, py_entry);
        Py_DECREF(py_entry);
        if (limit > 0) --limit;
        entry = DEQ_PREV(entry);
    }
    return list;
 error:
    Py_XDECREF(list);
    Py_XDECREF(py_entry);
    return NULL;
}
Ejemplo n.º 4
0
static int logv(int level, const char *fmt, va_list ap)
{
    if (g_log_context.level < level) {
        return 0;
    }

    char buf[LOG_BUF_LEN];
    int len;
    char *ptr = buf;

    time_t time;
    struct timeval tv;
    struct tm *tm;
    gettimeofday(&tv, NULL);
    time = tv.tv_sec;
    tm = localtime(&time);
    /* %3ld 在数值位数超过3位的时候不起作用, 所以这里转成int */
    len = sprintf(ptr, "%04d-%02d-%02d %02d:%02d:%02d.%03d ", tm->tm_year + 1900,
            tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
            (int) (tv.tv_usec / 1000));
    if (len < 0) {
        return -1;
    }
    ptr += len;

    memcpy(ptr, level_name(level), LEVEL_NAME_LEN);
    ptr += LEVEL_NAME_LEN;

    int space = sizeof(buf) - (ptr - buf) - 10;
    len = vsnprintf(ptr, space, fmt, ap);
    if (len < 0) {
        return -1;
    }
    ptr += len > space ? space : len;
    *ptr++ = '\n';
    *ptr = '\0';

    len = ptr - buf;
    // change to write(), without locking?
    if (g_log_context.mutex) {
        pthread_mutex_lock(g_log_context.mutex);
    }
    fwrite(buf, len, 1, g_log_context.fp);
    fflush(g_log_context.fp);

    g_log_context.stats.w_curr += len;
    g_log_context.stats.w_total += len;
    if (g_log_context.rotate_size > 0 && g_log_context.stats.w_curr > g_log_context.rotate_size) {
        rotate();
    }
    if (g_log_context.mutex) {
        pthread_mutex_unlock(g_log_context.mutex);
    }

    return len;
}
Ejemplo n.º 5
0
int Logger::logv(int level, const char *fmt, va_list ap)
{
    if (logger.level_ < level) {	//未设置日志级别
        return 0;
    }

    char buf[LOG_BUF_LEN];	//缓冲区大小为4KB
    int len;
    char *ptr = buf;	//指向日志缓冲区的指针

    time_t time;
    struct timeval tv;
    struct tm *tm;
    gettimeofday(&tv, NULL);	//获取当前时间(自1970年1月1日以来的秒数)
    time = tv.tv_sec;
    tm = localtime(&time);	//转换时间格式
    /* %3ld 在数值位数超过3位的时候不起作用, 所以这里转成int */
    len = sprintf(ptr, "%04d-%02d-%02d %02d:%02d:%02d.%03d ", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000));	//写入日志消息之前,先写入消息产生的时间
    if (len < 0) {
        return -1;
    }
    ptr += len;		//指针往后偏移

    memcpy(ptr, level_name(level), LEVEL_NAME_LEN);	//时间之后写入的是日志的级别(8字节的长度,计算过的,可以容纳最长的那个)
    ptr += LEVEL_NAME_LEN;	//指针往后偏移8字节

    int space = sizeof(buf) - (ptr - buf) - 10;	//缓冲区剩余的空间大小
    len = vsnprintf(ptr, space, fmt, ap);	//将可变参数写入日志级别之后
    if (len < 0) {
        return -1;
    }
    ptr += len > space ? space : len;	//最多偏移到文件末端
    *ptr++ = '\n';		//字符串尾字符是换行
    *ptr = '\0';		//字符串以null字节终止

    len = ptr - buf;	//计算写入消息后的偏移量
    // change to write(), without locking?
    if (this->mutex) {
        pthread_mutex_lock(this->mutex);	//如果是线程安全的,那么加锁
    }
    fwrite(buf, len, 1, this->fp);	//将之前写入缓冲区的数据写入到日志文件中去
    fflush(this->fp);	//强制冲洗数据进入日志文件

    stats.w_curr += len;	//设置对于当前文件的偏移量
    stats.w_total += len;	//设置对于所有文件总和的偏移量
    if (rotate_size > 0 && stats.w_curr > rotate_size) {	//如果当前日志文件的长度超出了单个日志文件的长度,那么再次调用此函数进行日志的交替
        this->rotate();
    }
    if (this->mutex) {
        pthread_mutex_unlock(this->mutex);	//写操作结束后解锁
    }

    return len;		//返回此次写入的消息字节数
}
Ejemplo n.º 6
0
wrapped_stream logger::log(level l, std::string str)
{
    wrapped_stream stream((l >= level_  ? sink_ : 0));
    stream << std::dec << "[" << pid_ << "][" << level_name(l) << "]";
    if (name_ != "") stream << "[" << name_ << "]";
    if (str != "")
    {
        stream << "[" << str << "]";
    }
    stream << std::boolalpha << " ";

    return stream;
}
Ejemplo n.º 7
0
static int save_enter(struct state *st, struct state *prev)
{
    const char *name;

    name = demo_format_name(config_get_s(CONFIG_REPLAY_NAME),
                            set_id(curr_set()),
                            level_name(curr_level()));

    text_input_start(on_text_input);
    text_input_str(name);

    return save_gui();
}
Ejemplo n.º 8
0
void log_string(unsigned short l, const char *s)
{
    time_t now;
    time(&now);
    struct tm *tm = localtime(&now);
    string m;
    format(m, "%02u:%02u:%02u [%s] ", tm->tm_hour, tm->tm_min, tm->tm_sec, level_name(l));
    m += s;
    LogInfo li;
    li.log_level = l;
    li.log_info = (void*)m.c_str();
    li.packet_id = 0;
    li.add_info  = NULL;
    Event e(EventLog, &li);
    e.process();
}
Ejemplo n.º 9
0
static int goal_gui(void)
{
    const char *s1 = _("New Record");
    const char *s2 = _("GOAL");

    int id, jd, kd, ld, md;

    int high = progress_lvl_high();

    if ((id = gui_vstack(0)))
    {
        int gid = 0;

        if (curr_mode() == MODE_CHALLENGE)
        {
            int coins, score, balls;
            int i;

            /* Reverse-engineer initial score and balls. */

            if (resume)
            {
                coins = 0;
                score = curr_score();
                balls = curr_balls();
            }
            else
            {
                coins = curr_coins();
                score = curr_score() - coins;
                balls = curr_balls();

                for (i = curr_score(); i > score; i--)
                    if (progress_reward_ball(i))
                        balls--;
            }

            /*if ((jd = gui_hstack(id)))
            {
                gui_filler(jd);*/

                if ((kd = gui_vstack(id)))
                {
                    if ((ld = video.device_w < video.device_h ? gui_vstack(kd) : gui_hstack(kd)))
                    {
                        if ((md = gui_harray(ld)))
                        {
                            balls_id = gui_count(md, 100, GUI_MED);
                            gui_label(md, _("Balls"), GUI_MED,
                                      gui_wht, gui_wht);
                        }
                        if ((md = gui_harray(ld)))
                        {
                            score_id = gui_count(md, 1000, GUI_MED);
                            gui_label(md, _("Score"), GUI_MED,
                                      gui_wht, gui_wht);
                        }
                        if ((md = gui_harray(ld)))
                        {
                            coins_id = gui_count(md, 100, GUI_MED);
                            gui_label(md, _("Coins"), GUI_MED,
                                      gui_wht, gui_wht);
                        }

                        gui_set_count(balls_id, balls);
                        gui_set_count(score_id, score);
                        gui_set_count(coins_id, coins);
                    }

                    if ((ld = gui_harray(kd)))
                    {
                        const struct level *l;

                        gui_label(ld, "", GUI_SML, 0, 0);

                        for (i = MAXLVL - 1; i >= 0; i--)
                            if ((l = get_level(i)) && level_bonus(l))
                            {
                                const GLubyte *c = (level_opened(l) ?
                                                    gui_grn : gui_gry);

                                gui_label(ld, level_name(l), GUI_SML, c, c);
                            }

                        gui_label(ld, "", GUI_SML, 0, 0);
                    }

                    gui_set_rect(kd, GUI_ALL);
                }

                /*gui_filler(jd);
            }*/

            gui_space(id);
        }
        else
        {
            gid = gui_label(id, high ? s1 : s2, GUI_LRG, gui_blu, gui_grn);
            gui_space(id);

            balls_id = score_id = coins_id = 0;
        }

        gui_score_board(id, (GUI_SCORE_COIN |
                             GUI_SCORE_TIME |
                             GUI_SCORE_GOAL |
                             GUI_SCORE_SAVE), 1, high);

        gui_space(id);

        if ((jd = gui_harray(id)))
        {
            if      (progress_done())
                gui_start(jd, _("Finish"), GUI_MED, GOAL_DONE, 0);
            else if (progress_last())
                gui_start(jd, _("Finish"), GUI_MED, GOAL_LAST, 0);

            if (progress_next_avail())
                gui_start(jd, _("Next"),  GUI_MED, GOAL_NEXT, 0);

            if (progress_same_avail())
                gui_start(jd, _("Retry"), GUI_MED, GOAL_SAME, 0);

            if (!progress_done() && !progress_last())
                gui_start(jd, _("Quit"), GUI_MED, GOAL_DONE, 0);
            //if (demo_saved())
            //    gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
        }

        if (!resume && gid)
            gui_pulse(gid, 1.2f);

        gui_layout(id, 0, 0);

    }

    set_score_board(level_score(curr_level(), SCORE_COIN), progress_coin_rank(),
                    level_score(curr_level(), SCORE_TIME), progress_time_rank(),
                    level_score(curr_level(), SCORE_GOAL), progress_goal_rank());

    return id;
}
Ejemplo n.º 10
0
std::string logger::get_level_name()
{
    return level_name(get_level());
}
Ejemplo n.º 11
0
int
jklog_log_ml (jklog * logger, const char *message, const char *marker,
	      unsigned level)
{
#if defined(HAVE_FLOCKFILE) && defined(HAVE_FUNLOCKFILE)
  flockfile (logger->stream);
#endif
#ifdef HAVE_ANSI_COLORS
  if (logger->display & JKLOG_DISPLAY_COLORS)
    fputs (level_color (level), logger->stream);
#endif
  if (logger->display & JKLOG_DISPLAY_SHOW_NAME
      || logger->display & JKLOG_DISPLAY_SHOW_LEVEL)
    {
      putc_unlocked ('[', logger->stream);
    }
  if (logger->display & JKLOG_DISPLAY_SHOW_NAME)
    {
      if (fprintf (logger->stream, "%s", logger->name) < 0)
	{
	  return -1;
	}
    }
  if (logger->display & JKLOG_DISPLAY_SHOW_NAME
      && logger->display & JKLOG_DISPLAY_SHOW_LEVEL)
    {
      fputs (" :: ", logger->stream);
    }
  if (logger->display & JKLOG_DISPLAY_SHOW_NAME
      && !(logger->display & JKLOG_DISPLAY_SHOW_LEVEL))
    {
      fputs ("] ", logger->stream);
    }
  else if (logger->display & JKLOG_DISPLAY_SHOW_LEVEL)
    {
      char buf[7];
      snprintf (buf, 7, "%s]", level_name (level));
      if (fprintf (logger->stream, "%-6s ", buf) < 0)
	{
	  return -1;
	}
    }
  if ((logger->display & JKLOG_DISPLAY_SHOW_MARKER) && (marker != NULL))
    {
      if (fprintf (logger->stream, "%s: ", marker) < 0)
	{
	  return -1;
	}
    }
  if (logger->display & JKLOG_DISPLAY_SHOW_TIME)
    {
      time_t clocktime;
      time (&clocktime);
      struct tm *tm = localtime (&clocktime);
      char datebuf[strlen (logger->datetime_format) * 5];
      if (strftime (datebuf, 512, logger->datetime_format, tm) == 0)
	{
	  return -1;
	}
      if (fprintf (logger->stream, "%s: ", datebuf) < 0)
	{
	  return -1;
	}
    }
  fprintf (logger->stream, "%s\n", message);
#ifdef HAVE_ANSI_COLORS
  if (logger->display & JKLOG_DISPLAY_COLORS)
    fputs ("\033[0m", logger->stream);
#endif
#if defined(HAVE_FLOCKFILE) && defined(HAVE_FUNLOCKFILE)
  funlockfile (logger->stream);
#endif
  return 0;
}