示例#1
0
文件: dwmstatus.c 项目: Mariappan/dwm
char *
get_netusage(unsigned long long int *rec, unsigned long long int *sent)
{
	unsigned long long int newrec, newsent;
	newrec = newsent = 0;
	char downspeedstr[15], upspeedstr[15];
	static char retstr[42];
	int retval;

	retval = parse_netdev(&newrec, &newsent);
	if (retval) {
	    fprintf(stdout, "Error when parsing /proc/net/dev file.\n");
	    exit(1);
	}

	calculate_speed(downspeedstr, newrec, *rec);
	calculate_speed(upspeedstr, newsent, *sent);

	sprintf(retstr, "\x01\uf063 %s  \x02\uf062 %s", downspeedstr, upspeedstr);
	/*sprintf(retstr, "\uf175 %s \uf176 %s", downspeedstr, upspeedstr);*/

	*rec = newrec;
	*sent = newsent;
	return retstr;
}
示例#2
0
char *
get_netusage(unsigned long long int *rec, unsigned long long int *sent) {
	unsigned long long int newrec, newsent;
	newrec = newsent = 0;
	char downspeedstr[15], upspeedstr[15];

	if (parse_netdev(&newrec, &newsent)) {
	    fprintf(stdout, "Error when parsing /proc/net/dev file.\n");
	    exit(1);
	}

	calculate_speed(downspeedstr, newrec, *rec);
	calculate_speed(upspeedstr, newsent, *sent);

	*rec = newrec;
	*sent = newsent;
	
	return smprintf("%s[ %s↓ %s%s %s| %s↑ %s%s%s ]", 
			colcyan, colyellow, colbyellow, downspeedstr, 
			colcyan,
			colyellow, colbyellow, upspeedstr, colcyan);
}
示例#3
0
/// update information at progress bar
extern void progress_update(struct progress_bar *prog, unsigned long long copied, unsigned long long current, int done)
{
    char clear_buf = ' ';
    prog_stat_t prog_stat;

    if (done != 1)
	if ((difftime(time(0), prog->resolution_time) < prog->interval_time) && copied != 0)
	    return;

    memset(&prog_stat, 0, sizeof(prog_stat_t));
    calculate_speed(prog, copied, current, done, &prog_stat);

    if (done != 1){
	prog->resolution_time = time(0);
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	fprintf(stderr, _("\r%80c\rElapsed: %s, Remaining: %s, Completed: %6.2f%%"), clear_buf, prog_stat.Eformated, prog_stat.Rformated, prog_stat.percent);

	if((prog->flag == IO) || (prog->flag == NO_BLOCK_DETAIL))
	    fprintf(stderr, _(", %6.2f%s/min,"), prog_stat.speed, prog_stat.speed_unit);
	if(prog->flag == IO)
	    fprintf(stderr, "\n\r%80c\rcurrent block: %10lld, total block: %10lld, Complete: %6.2f%%%s\r", clear_buf, current, prog->total, prog_stat.total_percent, "\x1b[A");
    } else {
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	fprintf(stderr, _("\r%80c\rElapsed: %s, Remaining: %s, Completed: 100.00%%"), clear_buf, prog_stat.Eformated, prog_stat.Rformated);
	if((prog->flag == IO) || (prog->flag == NO_BLOCK_DETAIL))
	    fprintf(stderr, _(", Rate: %6.2f%s/min,"), prog_stat.speed, prog_stat.speed_unit);
	if(prog->flag == IO)
	    fprintf(stderr, "\n\r%80c\rcurrent block: %10lld, total block: %10lld, Complete: 100.00%%\r", clear_buf, current, prog->total);

        fprintf(stderr, _("\nTotal Time: %s, "), prog_stat.Eformated);
	if(prog->flag == IO)
	    fprintf(stderr, _("Ave. Rate: %6.1f%s/min, "), prog_stat.speed, prog_stat.speed_unit);
        fprintf(stderr, _("%s"), "100.00% completed!\n");
    }
}
示例#4
0
void show_default_screen(msg_t *msg)
{
    LCD_GoTo(8,0);
    get_time_str(string_buff);
    LCD_WriteText(string_buff);
    LCD_GoTo(4, 0);
    LCD_WriteText("k/h \0");
    int offset = 1;
    switch(msg->type) {
    case MSG_SECOND_CHANGE:
        offset = calculate_speed() > 99 ? 0 : 1;
        break;
    }
    if (offset > 0) {
        LCD_GoTo(0,0);
        LCD_WriteText(" \0");
    }
    get_current_speed(string_buff);
    LCD_GoTo(offset, 0);
    LCD_WriteText(string_buff);
}
示例#5
0
/********************** *
 * Event handlers       *
 * *********************/
void event_key_special(int key, int x, int y) {
    if (active_window->state == STATE_LOADING) {
        return;
    }

    int step = 0, i;
    switch (key) {
    case GLUT_KEY_LEFT:
        step = -1;
        break;
    case GLUT_KEY_RIGHT:
        step = 1;
        break;
    case GLUT_KEY_UP:
        step = 10;
        break;
    case GLUT_KEY_DOWN:
        step = -10;
        break;
    case GLUT_KEY_HOME: // Perform match on all frames
        for (i = 1; i <= active_window->nfr; i++) {
            struct frame *fr = get_frame(active_window->frames, i);
            if (fr->flag & HAS_MATCH) {
                continue;
            }
            templateMatch(active_window, i, MARGIN, active_window->tmpl);
            fr->flag |= HAS_MATCH;
            calculate_speed(fr);
        }
        printf("Done matching\n");
    }

    // Update view
    if (active_window->cur+step > 0 && active_window->cur+step <= active_window->nfr) {
        active_window->cur += step;
        glutPostRedisplay();
    }
}
示例#6
0
文件: pc.c 项目: influential/dungeon
uint32_t takeoff(dungeon_t *d, char index)
{
  int i;
  uint32_t spot;
  object_t *temp;
  switch(index) {
    case 'a' :
      spot = 0;
      break;
    case 'b' :
      spot = 1;
      break;
    case 'c' :
      spot = 2;
      break;
    case 'd' :
      spot = 3;
      break;
    case 'e' :
      spot = 4;
      break;
    case 'f' :
      spot = 5;
      break;
    case 'g' :
      spot = 6;
      break;
    case 'h' :
      spot = 7;
      break;
    case 'i' :
      spot = 8;
      break;
    case 'j' :
      spot = 9;
      break;
    case 'k' :
      spot = 10;
      break;
    case 'l' :
      spot = 11;
      break;
    default :
      spot = 12;
      break;
  }
  if(spot < 12) {
    if(d->pc.pc->equipment[spot]) {
      temp = d->pc.pc->equipment[spot];
      d->pc.pc->equipment[spot] = NULL;
      for(i = 0; i < 10; i++) {
        if(!d->pc.pc->carry[i]) {
          d->pc.pc->carry[i] = temp;
          return 1;
        }
      }
      d->object[d->pc.position[dim_y]][d->pc.position[dim_x]] = temp;
      return 2;
    } 
  }
  d->pc.speed = calculate_speed(d, &d->pc);
  return 0;
}
示例#7
0
文件: pc.c 项目: influential/dungeon
uint32_t wear(dungeon_t *d, char index)
{
  uint32_t spot;
  object_t *temp;
  spot = index - '0';
  if(spot < 10) {
    if(d->pc.pc->carry[spot]) {
      temp = d->pc.pc->carry[spot];
      switch(get_type(d->pc.pc->carry[spot])) {
        case objtype_WEAPON :
          if(d->pc.pc->equipment[0]) {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[0];
          } else {
            d->pc.pc->carry[spot] = NULL;
          }
          d->pc.pc->equipment[0] = temp;
          break;
        case objtype_OFFHAND :
          if(d->pc.pc->equipment[1]) {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[1];
          } else {
            d->pc.pc->carry[spot] = NULL;
          }
          d->pc.pc->equipment[1] = temp;
          break;
        case objtype_RANGED :
          if(d->pc.pc->equipment[2]) {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[2];
          } else {
            d->pc.pc->carry[spot] = NULL;
          }
          d->pc.pc->equipment[2] = temp;
          break;
        case objtype_ARMOR :
          if(d->pc.pc->equipment[3]) {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[3];
          } else {
            d->pc.pc->carry[spot] = NULL;
          }
          d->pc.pc->equipment[3] = temp;
          break;
        case objtype_HELMET :
          if(d->pc.pc->equipment[4]) {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[4];
          } else {
            d->pc.pc->carry[spot] = NULL;
          }
          d->pc.pc->equipment[4] = temp;
          break;
        case objtype_CLOAK :
          if(d->pc.pc->equipment[5]) {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[5];
          } else {
            d->pc.pc->carry[spot] = NULL;
          }
          d->pc.pc->equipment[5] = temp;
          break;
        case objtype_GLOVES :
          if(d->pc.pc->equipment[6]) {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[6];
          } else {
            d->pc.pc->carry[spot] = NULL;
          }
          d->pc.pc->equipment[6] = temp;
          break;
        case objtype_BOOTS :
          if(d->pc.pc->equipment[7]) {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[7];
          } else {
            d->pc.pc->carry[spot] = NULL;
          }
          d->pc.pc->equipment[7] = temp;
          break;
        case objtype_AMULET :
          if(d->pc.pc->equipment[8]) {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[8];
          } else {
            d->pc.pc->carry[spot] = NULL;
          }
          d->pc.pc->equipment[8] = temp;
          break;
        case objtype_LIGHT :
          if(d->pc.pc->equipment[9]) {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[9];
          } else {
            d->pc.pc->carry[spot] = NULL;
          }
          d->pc.pc->equipment[9] = temp;
          break;
          case objtype_RING :
          if(!d->pc.pc->equipment[10]) {
            d->pc.pc->carry[spot] = NULL;
            d->pc.pc->equipment[10] = temp;
            break;
          } else if(!d->pc.pc->equipment[11]) {
            d->pc.pc->carry[spot] = NULL;
            d->pc.pc->equipment[11] = temp;
            break;
          } else {
            d->pc.pc->carry[spot] = d->pc.pc->equipment[10];
            d->pc.pc->equipment[10] = temp;
            break;
          }
        default:
          return 1;
      }
    }
  }
  d->pc.speed = calculate_speed(d, &d->pc);
  return 0;
}
示例#8
0
/// update information at ncurses mode
extern void Ncurses_progress_update(struct progress_bar *prog, unsigned long long copied, unsigned long long current, int done)
{
#ifdef HAVE_LIBNCURSESW

    char *p_block, *t_block;
    prog_stat_t prog_stat;

    memset(&prog_stat, 0, sizeof(prog_stat_t));
    calculate_speed(prog, copied, current, done, &prog_stat);

    /// set bar color
    init_pair(4, COLOR_RED, COLOR_RED);
    init_pair(5, COLOR_WHITE, COLOR_BLUE);
    init_pair(6, COLOR_WHITE, COLOR_RED);
    werase(p_win);
    werase(bar_win);

    if (done != 1){
        if (difftime(time(0), prog->resolution_time) < prog->interval_time)
            return;
	prog->resolution_time = time(0);

        mvwprintw(p_win, 0, 0, _("Elapsed: %s Remaining: %s ") , prog_stat.Eformated, prog_stat.Rformated);
	if((prog->flag == IO) || (prog->flag == NO_BLOCK_DETAIL))
	    mvwprintw(p_win, 0, 40, _("Rate: %6.2f%s/min"), prog_stat.speed, prog_stat.speed_unit);
	if (prog->flag == IO)
	    mvwprintw(p_win, 1, 0, _("Current Block: %lld  Total Block: %lld ") , current, prog->total);
        p_block = calloc(sizeof(char), 50);
        t_block = calloc(sizeof(char), 50);
        memset(p_block, ' ', (size_t)(prog_stat.percent*0.5));
        memset(t_block, ' ', (size_t)(prog_stat.total_percent*0.5));
        
	if (prog->flag == IO)
	    mvwprintw(p_win, 3, 0, "Data Block Process:");
	else if (prog->flag == BITMAP)
	    mvwprintw(p_win, 3, 0, "Calculating Bitmap Process:");
	wattrset(bar_win, COLOR_PAIR(4));
        mvwprintw(bar_win, 0, 0, "%s", p_block);
        wattroff(bar_win, COLOR_PAIR(4));
        mvwprintw(p_win, 4, 52, "%6.2f%%", prog_stat.percent);
        
	if (prog->flag == IO) {
	    werase(tbar_win);
	    mvwprintw(p_win, 6, 0, "Total Block Process:");
	    wattrset(tbar_win, COLOR_PAIR(4));
	    mvwprintw(tbar_win, 0, 0, "%s", t_block);
	    wattroff(tbar_win, COLOR_PAIR(4));
	    mvwprintw(p_win, 7, 52, "%6.2f%%", prog_stat.total_percent);
	}

	free(p_block);
	free(t_block);
        
	wrefresh(p_win);
        wrefresh(bar_win);
        wrefresh(tbar_win);
    } else {
        mvwprintw(p_win, 0, 0, _("Total Time: %s Remaining: %s "), prog_stat.Eformated, prog_stat.Rformated);
	if((prog->flag == IO) || (prog->flag == NO_BLOCK_DETAIL))
	    mvwprintw(p_win, 1, 0, _("Ave. Rate: %6.2f%s/min"), prog_stat.speed, prog_stat.speed_unit);

	if (prog->flag == IO)
	    mvwprintw(p_win, 3, 0, "Data Block Process:");
	else if (prog->flag == BITMAP)
	    mvwprintw(p_win, 3, 0, "Calculating Bitmap Process:");
        wattrset(bar_win, COLOR_PAIR(4));
	mvwprintw(bar_win, 0, 0, "%50s", " ");
        wattroff(bar_win, COLOR_PAIR(4));
        mvwprintw(p_win, 4, 52, "100.00%%");

	if (prog->flag == IO) {
	    werase(tbar_win);
	    mvwprintw(p_win, 6, 0, "Total Block Process:");
	    wattrset(tbar_win, COLOR_PAIR(4));
	    mvwprintw(tbar_win, 0, 0, "%50s", " ");
	    wattroff(tbar_win, COLOR_PAIR(4));
	    mvwprintw(p_win, 7, 52, "100.00%%");
	}

        wrefresh(p_win);
        wrefresh(bar_win);
        wrefresh(tbar_win);
        refresh();
	sleep(1);
    }

#endif
}
示例#9
0
/// update information at ncurses mode
extern void Ncurses_progress_update(struct progress_bar *prog, unsigned long long copied, unsigned long long current, int done)
{
#ifdef HAVE_LIBNCURSESW

    char *block = "                                                                    ";
    int x = 0;
    char blockbuf[BUFSIZE];
    prog_stat_t prog_stat;

    memset(&prog_stat, 0, sizeof(prog_stat_t));
    calculate_speed(prog, copied, current, done, &prog_stat);

    /// set bar color
    init_pair(4, COLOR_RED, COLOR_RED);
    init_pair(5, COLOR_WHITE, COLOR_BLUE);
    init_pair(6, COLOR_WHITE, COLOR_RED);
    werase(p_win);
    werase(bar_win);

    if (done != 1){
	prog->resolution_time = time(0);

        mvwprintw(p_win, 0, 0, _("Elapsed: %s Remaining: %s ") , prog_stat.Eformated, prog_stat.Rformated);
	if((prog->flag == IO) || (prog->flag == NO_BLOCK_DETAIL))
	    mvwprintw(p_win, 0, 40, _("Rate: %6.2f%s/min"), prog_stat.speed, prog_stat.speed_unit);
	if (prog->flag == IO)
	    mvwprintw(p_win, 1, 0, _("Current Block: %llu  Total Block: %llu ") , current, prog->total);

	if (prog->flag == IO)
	    mvwprintw(p_win, 3, 0, "Data Block Process:");
	else if (prog->flag == BITMAP)
	    mvwprintw(p_win, 3, 0, "Calculating Bitmap Process:");
	wattrset(bar_win, COLOR_PAIR(4));
	x = snprintf(blockbuf, BUFSIZE, "%.*s",  (unsigned int)(prog_stat.percent*0.5), block);
	if ( x < 0 )
	    fprintf(stderr, "ncurses update error\n");
        mvwprintw(bar_win, 0, 0, "%s", blockbuf);
        wattroff(bar_win, COLOR_PAIR(4));
        mvwprintw(p_win, 4, 52, "%6.2f%%", prog_stat.percent);
        
	if (prog->flag == IO) {
	    werase(tbar_win);
	    mvwprintw(p_win, 6, 0, "Total Block Process:");
	    wattrset(tbar_win, COLOR_PAIR(4));
	    x = snprintf(blockbuf, BUFSIZE, "%.*s",  (unsigned int)(prog_stat.total_percent*0.5), block);
	    if ( x < 0 )
		fprintf(stderr, "ncurses update error\n");
	    mvwprintw(tbar_win, 0, 0, "%s", blockbuf);
	    wattroff(tbar_win, COLOR_PAIR(4));
	    mvwprintw(p_win, 7, 52, "%6.2f%%", prog_stat.total_percent);
	}


	wrefresh(p_win);
        wrefresh(bar_win);
        wrefresh(tbar_win);
    } else {
        mvwprintw(p_win, 0, 0, _("Total Time: %s Remaining: %s "), prog_stat.Eformated, prog_stat.Rformated);
	if((prog->flag == IO) || (prog->flag == NO_BLOCK_DETAIL))
	    mvwprintw(p_win, 1, 0, _("Ave. Rate: %6.2f%s/min"), prog_stat.speed, prog_stat.speed_unit);

	if (prog->flag == IO)
	    mvwprintw(p_win, 3, 0, "Data Block Process:");
	else if (prog->flag == BITMAP)
	    mvwprintw(p_win, 3, 0, "Calculating Bitmap Process:");
        wattrset(bar_win, COLOR_PAIR(4));
	mvwprintw(bar_win, 0, 0, "%50s", " ");
        wattroff(bar_win, COLOR_PAIR(4));
        mvwprintw(p_win, 4, 52, "100.00%%");

	if (prog->flag == IO) {
	    werase(tbar_win);
	    mvwprintw(p_win, 6, 0, "Total Block Process:");
	    wattrset(tbar_win, COLOR_PAIR(4));
	    mvwprintw(tbar_win, 0, 0, "%50s", " ");
	    wattroff(tbar_win, COLOR_PAIR(4));
	    mvwprintw(p_win, 7, 52, "100.00%%");
	}

        wrefresh(p_win);
        wrefresh(bar_win);
        wrefresh(tbar_win);
        refresh();
	sleep(1);
    }

#endif
}