Beispiel #1
0
char *
Ptt_prints(char *str, size_t size, int mode)
{
    char           *strbuf = alloca(size);
    int             r, w;
    for( r = w = 0 ; str[r] != 0 && w < ((int)size - 1) ; ++r )
    {
        if( str[r] != ESC_CHR )
        {
            strbuf[w++] = str[r];
            continue;
        }

        if( str[++r] != '*' ){
            if (w+2 >= (int)size-1) break;
            strbuf[w++] = ESC_CHR;
            strbuf[w++] = str[r];
            continue;
        }

        /* Note, w will increased by copied length after */
        expand_esc_star(strbuf+w, &(str[r-1]), size-w);
        r ++;
        w += strlen(strbuf+w);
    }
    strbuf[w] = 0;
    strip_ansi(str, strbuf, mode);
    return str;
}
Beispiel #2
0
/*
 * level defines whether it gets displayed to the screen with printf.
 * (it always logs).
 *   0 = everything, even all the registers
 *   1 = prints syscall count
 *   2 = Just the reseed values
 *
 */
void output(unsigned char level, const char *fmt, ...)
{
	va_list args;
	int n;
	FILE *handle;
	pid_t pid;
	char outputbuf[BUFSIZE];
	char *prefix = NULL;
	char main_prefix[]="[main]";
	char child_prefix[32];

	if (logging == LOGGING_DISABLED && level >= quiet_level)
		return;

	/* prefix preparation */
	pid = getpid();

	if (pid == mainpid)
		prefix = main_prefix;
	else if (prefix == NULL) {
		unsigned int childno;

		childno = find_childno(pid);
		snprintf(child_prefix, sizeof(child_prefix), "[child%u:%u]", childno, pid);
		prefix = child_prefix;
		shm->children[childno]->logdirty = TRUE;
	}

	/* formatting output */
	va_start(args, fmt);
	n = vsnprintf(outputbuf, sizeof(outputbuf), fmt, args);
	va_end(args);
	if (n < 0) {
		outputerr("## Something went wrong in output() [%d]\n", n);
		exit(EXIT_FAILURE);
	}

	/* stdout output if needed */
	if (quiet_level >= level) {
		printf("%s %s", prefix, outputbuf);
		(void)fflush(stdout);
	}

	/* go on with file logs only if enabled */
	if (logging == LOGGING_FILES)
		return;

	handle = find_logfile_handle();
	if (!handle)
		return;

	strip_ansi(outputbuf);

	fprintf(handle, "%s %s", prefix, outputbuf);

	(void)fflush(handle);
}
Beispiel #3
0
// readback
int		
instr(char *str)
{
    register screenline_t *slp = GetCurrentLine();
    *str = 0;
    if (!slp)
	return 0;
    slp->data[slp->len] = 0;
    strip_ansi(str, (char*)slp->data, STRIP_ALL);
    return strlen(str);
}
Beispiel #4
0
int		
innstr(char *str, int n)
{
    register screenline_t *slp = GetCurrentLine();
    char buf[ANSILINELEN];
    *str = 0;
    if (!slp)
	return 0;
    slp->data[slp->len] = 0;
    strip_ansi(buf, (char*)slp->data, STRIP_ALL);
    buf[ANSILINELEN-1] = 0;
    strlcpy(str, buf, n);
    return strlen(str);
}
Beispiel #5
0
void decompile_powers(dbref player, dbref thing, char *thingname)
{
    POWER f1, f2;
    POWERENT *fp;
    char *buf;
    /*
     * Report generic powers
     */
    f1 = Powers(thing);
    f2 = Powers2(thing);

    for (fp = gen_powers; fp->powername; fp++) {
	/*
	 * Skip if we shouldn't decompile this power
	 */
	if (fp->listperm & CA_NO_DECOMP) {
	    continue;
	}

	/*
	 * Skip if this power is not set
	 */

	if (fp->powerpower & POWER_EXT) {
	    if (!(f2 & fp->powervalue)) {
		continue;
	    }
	} else {
	    if (!(f1 & fp->powervalue)) {
		continue;
	    }
	}

	/*
	 * Skip if we can't see this power
	 */

	if (!check_access(player, fp->listperm)) {
	    continue;
	}

	/*
	 * We made it this far, report this power
	 */
	buf = strip_ansi(thingname);
	notify_check(player, player, MSG_PUP_ALWAYS | MSG_ME_ALL | MSG_F_DOWN, "@power %s=%s", buf, fp->powername);
	free_lbuf(buf);
    }
}
Beispiel #6
0
void
interp_err(dbref player, dbref program, struct inst *pc,
		   struct inst *arg, int atop, dbref origprog, const char *msg1, const char *msg2)
{
	char buf[BUFFER_LEN];
	char buf2[BUFFER_LEN];
	char tbuf[40];
	int errcount;
	time_t lt;

	err++;

	if (OWNER(origprog) == OWNER(player)) {
		strcpyn(buf, sizeof(buf), "\033[1;31;40mProgram Error.  Your program just got the following error.\033[0m");
	} else {
		snprintf(buf, sizeof(buf), "\033[1;31;40mProgrammer Error.  Please tell %s what you typed, and the following message.\033[0m",
				NAME(OWNER(origprog)));
	}
	notify_nolisten(player, buf, 1);

	snprintf(buf, sizeof(buf), "\033[1m%s(#%d), line %d; %s: %s\033[0m",
			 NAME(program), program, pc ? pc->line : -1, msg1, msg2);
	notify_nolisten(player, buf, 1);

	lt = time(NULL);
#ifndef WIN32
	format_time(tbuf, 32, "%c", localtime(&lt));
#else
	format_time(tbuf, 32, "%c", uw32localtime(&lt));
#endif

	strip_ansi(buf2, buf);
	errcount = get_property_value(origprog, ".debug/errcount");
	errcount++;
	add_property(origprog, ".debug/errcount", NULL, errcount);
	add_property(origprog, ".debug/lasterr", buf2, 0);
	add_property(origprog, ".debug/lastcrash", NULL, (int)lt);
	add_property(origprog, ".debug/lastcrashtime", tbuf, 0);

	if (origprog != program) {
		errcount = get_property_value(program, ".debug/errcount");
		errcount++;
		add_property(program, ".debug/errcount", NULL, errcount);
		add_property(program, ".debug/lasterr", buf2, 0);
		add_property(program, ".debug/lastcrash", NULL, (int)lt);
		add_property(program, ".debug/lastcrashtime", tbuf, 0);
	}
}
Beispiel #7
0
static void output_rendered_buffer(char *buffer)
{
	/* Output to stdout only if -q param is not specified */
	if (quiet_level == MAX_LOGLEVEL)
		flushbuffer(buffer, stdout);

	/* Exit if should not continue at all. */
	if (logging == TRUE) {
		FILE *log_handle;

		log_handle = find_logfile_handle();
		if (log_handle != NULL) {
			strip_ansi(buffer);
			flushbuffer(buffer, log_handle);
		}
	}
}
Beispiel #8
0
/**
 * 從第 y 列開始 show 出 filename 檔案中的前 lines 行。
 * mode 為 output 的模式,參數同 strip_ansi。
 * @param filename: the file to show
 * @param y:	    starting line on screen
 * @param lines:    max lines to be displayed
 * @param mode:	    SHOWFILE_*, see modes.h
 * @return 失敗傳回 0,否則為 1。
 *         2 表示有 PttPrints 碼
 */
int
show_file(const char *filename, int y, int lines, int mode)
{
    FILE *fp;
    char buf[ANSILINELEN];
    int  ret = 1;
    int  strpmode = STRIP_ALL;

    if (mode & SHOWFILE_ALLOW_COLOR)
	strpmode = ONLY_COLOR;
    if (mode & SHOWFILE_ALLOW_MOVE)
	strpmode = NO_RELOAD;

    if (y >= 0)
	move(y, 0);
    clrtoln(lines + y);
    if ((fp = fopen(filename, "r"))) {
	while (fgets(buf, sizeof(buf), fp) && lines--)
	{
	    move(y++, 0);
	    if (mode == SHOWFILE_RAW)
	    {
		outs(buf);
	    }
	    else if ((mode & SHOWFILE_ALLOW_STAR) && (strstr(buf, ESC_STR "*") != NULL))
	    {
		// because Ptt_prints escapes are not so often,
		// let's try harder to detect it.
		outs(Ptt_prints(buf, sizeof(buf), strpmode));
		ret = 2;
	    } else {
		// ESC is very common...
		strip_ansi(buf, buf, strpmode);
		outs(buf);
	    }
	}
	fclose(fp);
	outs(ANSI_RESET); // prevent some broken Welcome file
    } else
	return 0;
    return ret;
}
Beispiel #9
0
// TODO: combine the below with output()
void output_rendered_buffer(char *buffer)
{
	FILE *log_handle;

	/* Output to stdout only if -q param is not specified */
	if (quiet_level == MAX_LOGLEVEL) {
		fprintf(stdout, "%s", buffer);
		fflush(stdout);
	}

	/* Exit if should not continue at all. */
	if (logging == LOGGING_DISABLED)
		return;

	log_handle = find_logfile_handle();
	if (log_handle != NULL) {
		strip_ansi(buffer);
		fprintf(log_handle, "%s", buffer);
		fflush(log_handle);
	}
}
Beispiel #10
0
BLAPI_PROTO
bl_strip_ansi(lua_State *L)
{
    int n = lua_gettop(L);
    const char *s = NULL;
    char *s2 = NULL;
    size_t os2 = 0;

    if (n < 1 || (s = lua_tostring(L, 1)) == NULL ||
            *s == 0)
    {
        lua_pushstring(L, "");
        return 1;
    }

    os2 = strlen(s)+1;
    s2 = (char*) lua_newuserdata(L, os2);
    strip_ansi(s2, s, STRIP_ALL);
    lua_pushstring(L, s2);
    lua_remove(L, -2);
    return 1;
}
Beispiel #11
0
char *
Ptt_prints(char *str, int mode)
{
  char *po, *px, *ptr, strbuf[40] = "";

  while ((po = strstr(str, "\033[12")) != '\0')
    po[0] = 0;

  while ((po = strstr(str, "\033[10")) != '\0')
    po[0] = 0;

  while ((po = strstr(str, "\033n")) != '\0')
    po[0] = 0;

  while ((po = strstr(str, "\033]")) != '\0')
    po[0] = 0;

  while ((po = strstr(str, "\033[=")) != '\0')
    po[0] = 0;

  while ((po = strstr(str, "\033*")) != '\0')
  {
    switch (*(po + 2))
    {
    case 'S':
      *po = 0;
      px = po + 3;
      sprintf(strbuf, "%s", BOARDNAME);
      break;

    case 's':
      *po = 0;
      px = po + 3;
      sprintf(strbuf, "%s", cuser.userid);
      break;

    case 't':
      {
	time_t now = time(0);
	*po = 0;
	px = po + 3;
	sprintf(strbuf, "%s", Etime(&now));
	break;
      }

    case 'u':
      {
	int attempts;
	extern struct UTMPFILE *utmpshm;
	attempts = utmpshm->number;
	*po = 0;
	px = po + 3;
	sprintf(strbuf, "%d", attempts);
	break;
      }

    case 'z':			/* ·|¦©°£©Ò¦³Áô¨­ªº¤H */
      *po = 0;
      px = po + 3;
      sprintf(strbuf, "%d", guest_count_ulist());
      break;

    case 'b':
      *po = 0;
      px = po + 3;
      sprintf(strbuf, "%d/%d", cuser.month, cuser.day, px);
      break;

    case 'l':
      *po = 0;
      px = po + 3;
      sprintf(strbuf, "%d", cuser.numlogins);
      break;

    case 'p':
      *po = 0;
      px = po + 3;
      sprintf(strbuf, "%d", cuser.numposts);
      break;

    case 'n':
      *po = 0;
      px = po + 3;
      sprintf(strbuf, "%s", cuser.username);
      break;

    case 'm':
      *po = 0;
      px = po + 3;
      sprintf(strbuf, "%d", cuser.silvermoney);
      break;

    default:
      *po = 0;
      px = NULL;
      break;
    }

    if (px)
    {
      /* ©È·¸¦ì */
      ptr = strbuf + strlen(strbuf);
      *(ptr + 1) = '\0';

      while (*po++ = strbuf[0])
      {
	*ptr = *px++;
	strcpy(strbuf, strbuf + 1);
      }
    }
  }

  strip_ansi(str, str, mode);
  return str;
}
Beispiel #12
0
// level: 
// -1 - bold out
//  0 - dark text
//  1 - text
//  2 - no highlight (not implemented)
void
grayout(int y, int end, int level)
{
    register screenline_t *slp = NULL;
    char buf[ANSILINELEN];
    int i = 0;

    if (y < 0) y = 0;
    if (end > b_lines) end = b_lines;

    // TODO change to y <= end someday
    // loop lines
    for (; y <= end; y ++)
    {
	// modify by scroll
	i = y + roll;
	if (i < 0)
	    i += t_lines;
	else if (i >= t_lines)
	    i %= t_lines;

	slp = &big_picture[i];

	if (slp->len < 1)
	    continue;

	if (slp->len >= ANSILINELEN)
	    slp->len = ANSILINELEN -1;

	// tweak slp
	slp->data[slp->len] = 0;
	slp->mode &= ~STANDOUT;
	slp->mode |= MODIFIED;
	slp->oldlen = 0;
	slp->sso = slp->eso = 0;
	slp->smod = 0;

	// make slp->data a pure string
	for (i=0; i<slp->len; i++)
	{
	    if (!slp->data[i])
		slp->data[i] = ' ';
	}

	slp->len = strip_ansi(buf, (char*)slp->data, STRIP_ALL);
	buf[slp->len] = 0;

	switch(level)
	{
	    case GRAYOUT_DARK: // dark text
	    case GRAYOUT_BOLD:// bold text
		// basically, in current system slp->data will
		// not exceed t_columns. buffer overflow is impossible.
		// but to make it more robust, let's quick check here.
		// of course, t_columns should always be far smaller.
		if (strlen((char*)slp->data) > (size_t)t_columns)
		    slp->data[t_columns] = 0;
		strcpy((char*)slp->data, 
			level < 0 ? ANSI_COLOR(1) : ANSI_COLOR(1;30;40));
		strcat((char*)slp->data, buf);
		strcat((char*)slp->data, ANSI_RESET ANSI_CLRTOEND);
		slp->len = strlen((char*)slp->data);
		break;

	    case GRAYOUT_NORM: // Plain text
		memcpy(slp->data, buf, slp->len + 1);
		break;
	}
	slp->emod = slp->len -1;
    }
}
Beispiel #13
0
void decompile_flags( dbref player, dbref thing, char *thingname ) {
    FLAG f1, f2, f3;

    FLAGENT *fp;

    /*
     * Report generic flags
     */

    f1 = Flags( thing );
    f2 = Flags2( thing );
    f3 = Flags3( thing );

    for( fp = gen_flags; fp->flagname; fp++ ) {

        /*
         * Skip if we shouldn't decompile this flag
         */

        if( fp->listperm & CA_NO_DECOMP ) {
            continue;
        }

        /*
         * Skip if this flag is not set
         */

        if( fp->flagflag & FLAG_WORD3 ) {
            if( !( f3 & fp->flagvalue ) ) {
                continue;
            }
        } else if( fp->flagflag & FLAG_WORD2 ) {
            if( !( f2 & fp->flagvalue ) ) {
                continue;
            }
        } else {
            if( !( f1 & fp->flagvalue ) ) {
                continue;
            }
        }

        /*
         * Skip if we can't see this flag
         */

        if( !check_access( player, fp->listperm ) ) {
            continue;
        }

        /*
         * We made it this far, report this flag
         */

        notify_check( player, player, MSG_PUP_ALWAYS|MSG_ME_ALL|MSG_F_DOWN, "@set %s=%s", strip_ansi( thingname ), fp->flagname );
    }
}