Example #1
0
int main( void ) {
	int i, j, ch;

	c_puts( "User A running\n" );
	ch = writech( 'A' );
	if( ch != 'A' ) {
		c_printf( "User A, write 1 char '%c'\n", ch );
	}
	for( i = 0; i < 30; ++i ) {
		for( j = 0; j < DELAY_STD; ++j )
			continue;
		ch = writech( 'A' );
		if( ch != 'A' ) {
			c_printf( "User A, write 2 char '%c'\n", ch );
		}
	}

	c_puts( "User A exiting\n" );
	exit();

	ch = writech( 'a' );	/* shouldn't happen! */
	if( ch != 'a' ) {
		c_printf( "User A, write 3 char '%c'\n", ch );
	}
}
Example #2
0
static void cmd_version (void)
{
  writestr (cur_slot, VERSION);
  writech (cur_slot, '\n');
  writestr (cur_slot, COPYRIGHT);
  writech (cur_slot, '\n');
}
Example #3
0
static void help_summary (CMD *cmdset, int cmdnum, char *header)
{
  int i;
  int pos = 0, next_pos;
  int col_width = 40;           /* Constant */

  writestr (cur_slot, header);
  for (i=0; i < cmdnum; i++) {
    if (cmdset[i].level > cur_slot->acct.level)
      continue;

    /* Don't list functions disabled by run-time configuration */
    if (cmdset[i].func == cmd_room_typing && !roomtyping_f)
      continue;
    if (cmdset[i].func == change_pw && !chpasswd_f)
      continue;

    next_pos = (pos / col_width + 1) * col_width;
    if (next_pos + col_width > cur_slot->acct.width) {
      writech (cur_slot, '\n');
      pos = 0;
    } else if (pos) {
      while (pos++ < next_pos)
        writech (cur_slot, ' ');
    }
    pos += sprintf (msg_buf, "/%c  %.*s",
                    cmdset[i].ch, col_width - 6, cmdset[i].anno);
    writestr (cur_slot, msg_buf);
  }
  writech (cur_slot, '\n');
}
Example #4
0
void writetime (SLOT * sp, long t)
{
  writetwodig (sp, (int) (t / 3600));
  writech (sp, ':');
  writetwodig (sp, (int) (t / 60 % 60));
  writech (sp, ':');
  writetwodig (sp, (int) (t % 60));
}
Example #5
0
void writetwodig (SLOT *sp, int i)
{
  if (i >= 100)
    writeint (sp, i);
  else {
    writech (sp, i / 10 + '0');
    writech (sp, i % 10 + '0');
  }
}
Example #6
0
int main( void ) {
	int i;
	pid_t pid;

	pid = getpid();
	c_printf( "User G (%d) running\n", pid );
	writech( 'G' );
	for( i = 0; i < 5; ++i ) {
		sleep( seconds_to_ms(15) );
		writech( 'G' );
	}

	c_puts( "User G exiting\n" );
	exit();
}
Example #7
0
static void completion_print( int cols,
			      int *width,
			      int row_start,
			      int row_stop,
			      wchar_t *prefix,
			      int is_quoted,
			      const std::vector<comp_t *> &lst )
{

	size_t rows = (lst.size()-1)/cols+1;
	size_t i, j;

	for( i = row_start; i<row_stop; i++ )
	{
		for( j = 0; j < cols; j++ )
		{
			comp_t *el;

			int is_last = (j==(cols-1));
			
			if( lst.size() <= j*rows + i )
				continue;

			el = lst.at(j*rows + i );
			
			completion_print_item( prefix, el, width[j] - (is_last?0:2), i%2 );
			
			if( !is_last)
				writestr( L"  " );
		}
		writech( L'\n' );
	}
}
Example #8
0
/* Given a string and list of colors of the same size, return the string with ANSI escape sequences representing the colors. */
static std::string ansi_colorize(const wcstring &text, const std::vector<highlight_spec_t> &colors)
{
    assert(colors.size() == text.size());
    assert(output_receiver.empty());

    int (*saved)(char) = output_get_writer();
    output_set_writer(write_to_output_receiver);

    highlight_spec_t last_color = highlight_spec_normal;
    for (size_t i=0; i < text.size(); i++)
    {
        highlight_spec_t color = colors.at(i);
        if (color != last_color)
        {
            set_color(highlight_get_color(color, false), rgb_color_t::normal());
            last_color = color;
        }
        writech(text.at(i));
    }

    output_set_writer(saved);
    std::string result;
    result.swap(output_receiver);
    return result;
}
Example #9
0
int writeline(char *line)
{
while (*line) /* TODO: should this have a check of some sort, != \n or something? */
	{
	writech(*line);
	line++;
	}

return 1;
}
Example #10
0
void paabout (SLOT *sl, char *msg)
{
  SLOT *sp;
  SLOT_LIST *slist;

  write_log_paabout (sl, msg);

  slist = channels[MAINLIST].members;
  while (slist) {
    sp = slist->slot;

    if (sp && (sp->acct.pa_notify || 
               (sl->acct.chan == sp->acct.chan))) {
      select_stop (sp);
      select_wrap (sp);
      begin_color (sp, sl->acct.msgcolor);
      if (slots_f) {
        writestr (sp, "-- #");
        writeint (sp, sl->nslot);
      } else {
        writestr (sp, "--");
      }
      writech (sp, ' ');
      writestr (sp, msg);
      writestr (sp, " channel ");
      if (sl->acct.chan == sp->acct.chan || 
          sl->flags.listed || sl->acct.chan == 1 ||
          sp->acct.level > 2)
        writetwodig (sp, sl->acct.chan);
      else
        writestr (sp, "**");
      writestr (sp, ": ");
      writestr (sp, sl->acct.id);
      writech (sp, '/');
      writestr (sp, sl->acct.handle);
      reset_attr (sp);
      writech (sp, '\n');
      clear_stop (sp);
      clear_wrap (sp);
    }
    slist = slist->next;
  }
}
Example #11
0
void writemsg_raw (char *msg, int color, char nlchar)
{

  select_wrap (cur_slot);
  writestr (cur_slot, "     ");
  begin_color (cur_slot, color);

  while (*msg) {
    if (*msg == nlchar)
      writestr (cur_slot, "\n  ");
    else
      writech (cur_slot, *msg);
    msg++;
  }

  reset_attr (cur_slot);
  writech (cur_slot, '\n');
  clear_wrap (cur_slot);
}
Example #12
0
int main( void ) {
	prio_t prio1, prio2;
	int i, j;
	pid_t pid;

	pid = getpid();
	prio1 = getprio();
	c_printf( "User T (%d) running, initial prio %d\n", pid, prio1 );
	
	writech( 'T' );
	for( i = 0; i < 20; ++i ) {
		for( j = 0; j < DELAY_STD; ++j )
			continue;
		writech( 'T' );
	}

	prio2 = setprio( PRIO_HIGH );
	prio1 = getprio();
	c_printf( "User T, set prio #1 old %d new %d\n", prio2, prio1 );
	
	writech( 'T' );
	for( i = 0; i < 20; ++i ) {
		for( j = 0; j < DELAY_STD; ++j )
			continue;
		writech( 'T' );
	}

	prio2 = setprio( PRIO_LOW );
	prio1 = getprio();
	c_printf( "User T, set prio #2 old %d new %d\n", prio2, prio1 );

	writech( 'T' );
	for( i = 0; i < 20; ++i ) {
		for( j = 0; j < DELAY_STD; ++j )
			continue;
		writech( 'T' );
	}

	prio2 = setprio( PRIO_STD );
	prio1 = getprio();
	c_printf( "User T, set prio #3 old %d new %d\n", prio2, prio1 );
	
	writech( 'T' );
	for( i = 0; i < 30; ++i ) {
		for( j = 0; j < DELAY_STD; ++j )
			continue;
		writech( 'T' );
	}

	c_puts( "User T exiting\n" );
	exit();
}
Example #13
0
static void print_time (void)
{
  time_t secs;
  
  secs = time (NULL);
  writestr (cur_slot, "Current time: ");
  writestr (cur_slot, ctime (&secs));
  writestr (cur_slot, "Time on: ");
  writetime (cur_slot, secs - cur_slot->login_time);
  writech (cur_slot, '\n');
}
Example #14
0
void writeaction (SLOT *sp, char *msg)
{
  select_stop (sp);
  select_wrap (sp);
  begin_attr (sp, 1);
  begin_color (sp, cur_slot->acct.msgcolor);
  writestr (sp, msg);
  reset_attr (sp);
  writech (sp, '\n');
  clear_stop (sp);
  clear_wrap (sp);
}
Example #15
0
int main( void ) {
	int i;
	char ch = '&';

	c_puts( "User R running\n" );
	sleep( seconds_to_ms(10) );
	for( i = 0; i < 3; ++i ) {
		do {
			writech( 'R' );
			ch = readch();
			if( ch == -1 ) {	/* wait a bit */
				sleep( seconds_to_ms(1) );
			}
		} while( ch == -1 );
		writech( ch );
		c_printf("%c is %d\n", ch, ch);
	}

	c_puts( "User R exiting\n" );
	exit();
}
Example #16
0
/**
   Print the specified string, but use at most the specified amount of
   space. If the whole string can't be fitted, ellipsize it.

   \param str the string to print
   \param max the maximum space that may be used for printing
   \param has_more if this flag is true, this is not the entire string, and the string should be ellisiszed even if the string fits but takes up the whole space.
*/
static int print_max(const wchar_t *str, int max, int has_more)
{
    int i;
    int written = 0;
    for (i=0; str[i]; i++)
    {

        if (written + wcwidth(str[i]) > max)
            break;
        if ((written + wcwidth(str[i]) == max) && (has_more || str[i+1]))
        {
            writech(ellipsis_char);
            written += wcwidth(ellipsis_char);
            break;
        }

        writech(str[i]);
        written+= wcwidth(str[i]);
    }
    return written;
}
Example #17
0
void dump_userinfoshort (ACCOUNT *acct, int logged_in)
{
  ACCOUNT *cur_acct;
  long idle, hours, mins, secs;

  cur_acct = &cur_slot->acct;

  writestr (cur_slot, "Login/Handle: ");
  begin_color (cur_slot, acct->msgcolor);
  writestr (cur_slot, acct->id);
  writech (cur_slot, '/');
  writestr (cur_slot, acct->handle);
  reset_attr (cur_slot);

  writestr (cur_slot, "\nChannel: ");
  if (cur_acct->level == TOPLEVEL  ||
      channels[acct->chan].name    ||
      acct->chan == cur_acct->chan ||
      !strcmp(acct->id, cur_acct->id)) {
    writeint (cur_slot, acct->chan);
    writestr (cur_slot, "\n");
  } else
    writestr (cur_slot, "**\n");

  if (cur_acct->level >= 2 ||
      acct->email_public   ||
      !strcmp(acct->id, cur_acct->id)) {
    writestr (cur_slot, "Email address is ");
    writestr (cur_slot, acct->email_address);
    writestr (cur_slot, acct->email_public ? " [public]\n" : " [private]\n");
  } else
    writestr (cur_slot, "Email address is *PRIVATE*\n");

  writestr (cur_slot, "Last logout: ");
  writestr (cur_slot, ctime(&acct->last_logout));

  if (logged_in) {
    /* calculate idle time if the user is logged in */
    idle = time (NULL) - acct->last_typed;
    hours = idle / 3600;
    idle -= hours * 3600;
    mins = idle / 60;
    secs = idle - (mins * 60);
    sprintf (msg_buf, "Last typed: %.24s (idle: %dh %02dm %02ds)\n",
             ctime(&acct->last_typed), hours, mins, secs);
    writestr (cur_slot, msg_buf);
  } else {
    writestr (cur_slot, "Last typed: ");
    writestr (cur_slot, ctime(&acct->last_typed));
  }
}
Example #18
0
/// Convert a wide character to a multibyte string and append it to the buffer.
static void s_write_char(screen_t *s, data_buffer_t *b, wchar_t c) {
    scoped_buffer_t scoped_buffer(b);  //!OCLINT(has side effects)
    s->actual.cursor.x += fish_wcwidth_min_0(c);
    writech(c);
    if (s->actual.cursor.x == s->actual_width && allow_soft_wrap()) {
        s->soft_wrap_location.x = 0;
        s->soft_wrap_location.y = s->actual.cursor.y + 1;

        // Note that our cursor position may be a lie: Apple Terminal makes the right cursor stick
        // to the margin, while Ubuntu makes it "go off the end" (but still doesn't wrap). We rely
        // on s_move to fix this up.
    } else {
        invalidate_soft_wrap(s);
    }
}
Example #19
0
int main( void ) {
	int i;
	int pid;
	time_t time;

	time = gettime();
	c_printf( "User L running, initial time %u\n", time );
	writech( 'L' );

	for( i = 0; i < 3 ; ++i ) {
		time = gettime();
		pid = spawn( "/USER_X.B" );
		if( pid < 0 ) {
			c_printf( "User L spawn() #%d failed @%08u\n", i, time );
		} else {
			sleep( 0 );
			writech( 'L' );
		}
	}

	time = gettime();
	c_printf( "User L exiting at time %u\n", time );
	exit();
}
Example #20
0
void operact (SLOT *from, SLOT *to, char * msg)
{
  SLOT *sp;
  SLOT_LIST *sl;
  
  sl = channels[MAINLIST].members;
  while(sl) {
    sp = sl->slot;
    if (sp && sp != from && sp->acct.level > 3) {
      select_stop (sp);
      select_wrap (sp);
      if (from)
        begin_color (sp, from->acct.msgcolor);
      writestr (sp, "** ");
      if (from) {
        writestr (sp, from->acct.id);
        writech (sp, '/');
        writestr (sp, from->acct.handle);
        writech (sp, ' ');
      }
      writestr (sp, msg);
      if (to != NULL) {
        writech (sp, ' ');
        writestr (sp, to->acct.id);
        writech (sp, '/');
        writestr (sp, to->acct.handle);
      }
      if (from)
        reset_attr (sp);
      writech (sp, '\n');
      clear_stop (sp);
      clear_wrap (sp);
    }
    sl = sl->next;
  }
}
Example #21
0
File: FED.C Project: MegaGod/TW
void print_page( int pageno, int char_per_page ) {
	int x, y, z = _ceil( ( Y ), 4 );

	pageno *= char_per_page;

	for ( x = 0; x < 79; x += BYTE ) {
		for ( y = 0; y<( lower_limit / 4 - 10 ); y += z ) {
			if ( pageno>255 )  return;
			/*
			writech( x, y + 10, pageno++ );
			*/
			writech( x + 2, y + 10, pageno++ );
		}
	}
}
Example #22
0
void terminal(void)
{
    clrscr();
    cout << "Terminal ready... hit Alt-X to exit.\n";
    char modem=0,key=0;
    int done=0;
    do {
        key=readch();
        switch(key) {
            case -1: // exit terminal
                done=1;
                break;
            default:
                break;
        }
        com2 << key;
        com2 >> modem;
        writech(modem);
    } while (!done);
}
Example #23
0
/**
   Print the specified item using at the specified amount of space
*/
static void completion_print_item( const wchar_t *prefix, comp_t *c, int width, bool secondary )
{
	int comp_width=0, desc_width=0;
	int written=0;
	
	if( c->pref_width <= width )
	{
		/*
		  The entry fits, we give it as much space as it wants
		*/
		comp_width = c->comp_width;
		desc_width = c->desc_width;
	}
	else
	{
		/*
		  The completion and description won't fit on the
		  allocated space. Give a maximum of 2/3 of the
		  space to the completion, and whatever is left to
		  the description.
		*/
		int desc_all = c->desc_width?c->desc_width+4:0;
		
		comp_width = maxi( mini( c->comp_width,
					 2*(width-4)/3 ),
				   width - desc_all );
		if( c->desc_width )
			desc_width = width-comp_width-4;
		else
			c->desc_width=0;
		
	}
	
    rgb_color_t bg = secondary ? get_color(HIGHLIGHT_PAGER_SECONDARY) : rgb_color_t::normal();
	for( size_t i=0; i<c->comp.size(); i++ )
	{
        const wcstring &comp = c->comp.at(i);
		if( i != 0 )
			written += print_max( L"  ", comp_width - written, 2 );
		set_color( get_color(HIGHLIGHT_PAGER_PREFIX), bg );
		written += print_max( prefix, comp_width - written, comp.empty()?0:1 );
		set_color( get_color(HIGHLIGHT_PAGER_COMPLETION), bg);
		written += print_max( comp.c_str(), comp_width - written, i!=(c->comp.size()-1) );
	}


	if( desc_width )
	{
		while( written < (width-desc_width-2))
		{
			written++;
			writech( L' ');
		}
		set_color( get_color( HIGHLIGHT_PAGER_DESCRIPTION ), bg);
		written += print_max( L"(", 1, 0 );
		written += print_max( c->desc.c_str(), desc_width, 0 );
		written += print_max( L")", 1, 0 );
	}
	else
	{
		while( written < width )
		{
			written++;
			writech( L' ');
		}
	}
	if ( secondary )
		set_color( rgb_color_t::normal(), rgb_color_t::normal() );
}
Example #24
0
void dump_userinfo (SLOT *sp)
{
  ACCOUNT *acct;
  SLOT *sq;
  int i;

  acct = &sp->acct;

  dump_userinfoshort (acct, 1);

  writestr (cur_slot, "Account created from: ");
  writestr (cur_slot, acct->created_from);
  writestr (cur_slot, "\nMessage format: ");
  writestr (cur_slot, acct->msgfmt);
  writestr (cur_slot, "\nActive format: ");
  writestr (cur_slot, acct->activefmt);
  writestr (cur_slot, "\nNewline character: ");
  writech (cur_slot, acct->nlchar);
  writestr (cur_slot, "\nNewlines ");
  writestr (cur_slot, acct->newlines ? "on" : "off");
  writestr (cur_slot, "\nBeeping ");
  writestr (cur_slot, acct->beeping ? "on" : "off");
#ifndef NOBROADCAST
  writestr (cur_slot, "\nBroadcast messages ");
  writestr (cur_slot, acct->nostat ? "off" : "on");
#endif
  writestr (cur_slot, "\nPA messages ");
  writestr (cur_slot, acct->pa_notify ? "off" : "on");
  writestr (cur_slot, "\nANSI colors ");
  writestr (cur_slot, acct->usecolor ? "on" : "off");
  writestr (cur_slot, "\nEmail status: ");
  writestr (cur_slot, acct->email_verified ? "verified" : "new");

  writestr (cur_slot, "\nUser has squelched:");
  for (i = 1; i <= slots_used; i++) {
    sq = slotbase[i];
    if (sq && squelched (sp, sq)) {
      writestr (cur_slot, " ");
      writestr (cur_slot, sq->acct.id);
    }
  }
  writestr (cur_slot, "\nUser has reversed:");
  for (i = 1; i <= slots_used; i++) {
    sq = slotbase[i];
    if (sq && reversed (sp, sq)) {
      writestr (cur_slot, " ");
      writestr (cur_slot, sq->acct.id);
    }
  }
  writestr (cur_slot, "\nUser is being squelched by:");
  for (i = 1; i <= slots_used; i++) {
    sq = slotbase[i];
    if (sq && squelched (sq, sp)) {
      writestr (cur_slot, " ");
      writestr (cur_slot, sq->acct.id);
    }
  }
  writestr (cur_slot, "\nUser is being reversed by:");
  for (i = 1; i <= slots_used; i++) {
    sq = slotbase[i];
    if (sq && reversed (sq, sp)) {
      writestr (cur_slot, " ");
      writestr (cur_slot, sq->acct.id);
    }
  }
  writech (cur_slot, '\n');
}
Example #25
0
/**
   Convert a wide character to a multibyte string and append it to the
   buffer.
*/
static void s_write_char( screen_t *s, data_buffer_t *b, wchar_t c )
{
	scoped_buffer_t scoped_buffer(b);
	s->actual.cursor.x+=fish_wcwidth( c );
	writech( c );
}
Example #26
0
void writestr (SLOT *sp, char *s)
{
  while (s && *s)
    writech (sp, *s++);
}
Example #27
0
void writeint (SLOT *sp, int i)
{
  if (i >= 10)
    writeint (sp, i / 10);
  writech (sp, i % 10 + '0');
}
Example #28
0
void printf(const char *fmt, ...) {
unsigned char *pos;
unsigned long num = 0;
int print_int = 0;
va_list args;
va_start(args, fmt);

while (*fmt) {

int radix = 10; // default to base decimal, hex = 16
print_int = 0;
/* This is done to prevent some pretty crazy errors:
1. running "printf("%d %s",int a, char[10] b); leads to
printf("%d %s",int a, char[10] b); AND strncat(b,last-digit-of-a);
2. keyboard stops responding.
So, while we have no idea what it does, we'll use pos = something
in here as a workaround
*/

if (*fmt != '%') 	/* not a control char, print it straight away */
	writech(*fmt);
else {
	fmt++; /* fmt == %, skip to the next one */
	switch (*fmt) {
		case 'x': // hex, change the base
			radix = 16;
		case 'd':
			num = va_arg(args, unsigned long);
			print_int = 1;
			break;

		case 's':
			pos = va_arg(args, unsigned char * );
			while (*pos != '\0') {
				writech(*pos);
				pos++;
				}
			break;

		case 'c': /* TODO: should s and c be similar? should s use writeline? */
			{
			unsigned char  writec = va_arg(args, unsigned char);
			writech(writec);
			break;
			}

		case '%':
			writech('%');
			break;
		}
}

if (print_int == 1) {
// a simple writech(num) would print the number corresponding to the hex ascii value
/* This is basically a bad itoa function */

/* get the numbers in reverse order */
int help = 0, help2 = 0, help3 = 0;
// an unsigned long takes 4 bytes - 32 bits. This is the biggest number our printf can handle
//unsigned char *helpstring = 0;
unsigned char helpstring[32] = "";

// this loops through numbers higher than 10
while (num / radix > 0) {
	help3 = num % radix + '0';
	if (help3 > '9') // it's a hex!
		help3 = help3 + 7; // make it a number, '9' + 7 = 'A' (10 in hex)
	helpstring[help++] = help3;
	num = num / radix;
	help2++;
	}

// the last one aka the first digit ( number < 10)
help3 = num % radix + '0';
if (help3 > '9') // it's a hex!
	help3 = help3 + 7; // make it a number
helpstring[help++] = help3;

/* reverse to original order */
int temp = 0, first = 0;
int last = help2;


while (first < last) {
	temp = helpstring[first];
	helpstring[first] = helpstring[last];
	helpstring[last] = temp;
	last--;
	first++;
	}

/* now, print*/
help = 0;
last = help2;
pos = helpstring;
while (*pos != '\0' && help <= last) {
	*pos = helpstring[help++]; // help++ means use help, only then ++!
	writech(*pos);
	}

}
fmt++;

}
va_end(args);
/* don't return anything, be a sucker */
}
Example #29
0
void writemsg (SLOT *sp, char *msg, int typ)
{
  char *s;
  char *t;
  
  select_stop (sp);
  select_wrap (sp);
  begin_color (sp, cur_slot->acct.msgcolor);

  /* Emphasize personal messages */
  if (typ == 1)
    begin_attr (sp, 1);

  s = sp->acct.msgfmt;
  while (*s) {
    if (*s == '%') {
      switch (*++s) {
      case '\\': 
        writech (sp, '\\');
        break;

      case '_': 
        writech (sp, '_');
        break;

      case 'm': 
        while (*msg) {
          if (*msg == cur_slot->acct.nlchar && sp->acct.newlines)
            writestr (sp, "\n  ");
          else
            writech (sp, *msg);
          msg++;
        }
        break;
	    
      default: 
        if (shared_spec (sp, cur_slot, *s))
          break;
        writech (sp, '%');
        if (!*s)
          s--;
        else
          writech (sp, *s);
      }
    } else if (*s == '_') {
      t = (char *)index (++s, '_');
      if (typ == 2) {
        if (t != NULL)
          *t = '\0';
        writestr (sp, s);
        if (t != NULL)
          *t = '_';
      }
      if (t == NULL)
        break;
      else
        s = t;
    } else if (*s == '\\') {
      t = (char *)index (++s, '\\');
      if (typ == 1) {
        if (t != NULL)
          *t = '\0';
        writestr (sp, s);
        if (t != NULL)
          *t = '\\';
      }
      if (t == NULL)
        break;
      else
        s = t;
    } else
      writech (sp, *s);
    s++;
  }

  reset_attr (sp);
  writech (sp, '\n');
  clear_stop (sp);
  clear_wrap (sp);
}