Beispiel #1
0
static void recruit_dracoids(unit * dragon, int size)
{
    faction *f = dragon->faction;
    region *r = dragon->region;
    const struct item *weapon = NULL;
    order *new_order = NULL;
    unit *un = create_unit(r, f, size, get_race(RC_DRACOID), 0, NULL, NULL);

    fset(un, UFL_ISNEW | UFL_MOVED);

    name_unit(un);
    change_money(dragon, -un->number * 50);
    equip_unit(un, get_equipment("recruited_dracoid"));

    setstatus(un, ST_FIGHT);
    for (weapon = un->items; weapon; weapon = weapon->next) {
        const weapon_type *wtype = weapon->type->rtype->wtype;
        if (wtype && (wtype->flags & WTF_MISSILE)) {
            setstatus(un, ST_BEHIND);
        }
        new_order = create_order(K_STUDY, f->locale, "'%s'",
            skillname(weapon->type->rtype->wtype->skill, f->locale));
    }

    if (new_order != NULL) {
        addlist(&un->orders, new_order);
    }
}
Beispiel #2
0
void
execshift(void)
{
	int n;
	word *a;
	var *star;
	switch(count(runq->argv->words)){
	default:
		pfmt(err, "Usage: shift [n]\n");
		setstatus("shift usage");
		poplist();
		return;
	case 2:
		n = atoi(runq->argv->words->next->word);
		break;
	case 1:
		n = 1;
		break;
	}
	star = vlook("*");
	for(;n && star->val;--n){
		a = star->val->next;
		efree(star->val->word);
		efree((char *)star->val);
		star->val = a;
		star->changed = 1;
	}
	setstatus("");
	poplist();
}
Beispiel #3
0
static int
noit_snmp_trapvars_to_stats(stats_t *current, netsnmp_variable_list *var) {
  if(isoidprefix(var->name, var->name_length, reconnoiter_check_status_oid,
                 reconnoiter_check_status_oid_len)) {
    if(var->type == ASN_OBJECT_ID) {
      if(isoid(var->name, var->name_length,
               reconnoiter_check_state_oid, reconnoiter_check_state_oid_len)) {
        oid *o = var->val.objid;
        size_t l = var->val_len / sizeof(*o);
        setstatus(state, reconnoiter_check_state_unknown_oid, NP_UNKNOWN);
        else setstatus(state, reconnoiter_check_state_good_oid, NP_GOOD);
        else setstatus(state, reconnoiter_check_state_bad_oid, NP_BAD);
        else return -1;
Beispiel #4
0
void
Xpipewait(void)
{
	char status[NSTATUS+1];
	if(runq->pid==-1)
		setstatus(concstatus(runq->status, getstatus()));
	else{
		strncpy(status, getstatus(), NSTATUS);
		status[NSTATUS]='\0';
		Waitfor(runq->pid, 1);
		runq->pid=-1;
		setstatus(concstatus(getstatus(), status));
	}
}
Beispiel #5
0
void
execnewpgrp(void)
{
	int arg;
	char *s;
	switch(count(runq->argv->words)){
	case 1:
		arg = RFENVG|RFNAMEG|RFNOTEG;
		break;
	case 2:
		arg = 0;
		for(s = runq->argv->words->next->word;*s;s++) switch(*s){
		default:
			goto Usage;
		case 'n':
			arg|=RFNAMEG;  break;
		case 'N':
			arg|=RFCNAMEG;
			break;
		case 'm':
			arg|=RFNOMNT;  break;
		case 'e':
			arg|=RFENVG;   break;
		case 'E':
			arg|=RFCENVG;  break;
		case 's':
			arg|=RFNOTEG;  break;
		case 'f':
			arg|=RFFDG;    break;
		case 'F':
			arg|=RFCFDG;   break;
		}
		break;
	default:
	Usage:
		pfmt(err, "Usage: %s [fnesFNEm]\n", runq->argv->words->word);
		setstatus("rfork usage");
		poplist();
		return;
	}
	if(rfork(arg)==-1){
		pfmt(err, "rc: %s failed\n", runq->argv->words->word);
		setstatus("rfork failed");
	}
	else
		setstatus("");
	poplist();
}
int main(void) {
	char *status;
	float cpu0, cpu1;
	char *datetime;
	int bat0;


	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "Cannot open display.\n");
		return 1;
	}

	if((status = malloc(200)) == NULL)
		exit(1);
	

	for (;;sleep(1)) {
		cpu0 = getfreq("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");
		cpu1 = getfreq("/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq");
		datetime = getdatetime();
		bat0 = getbattery();
		snprintf(status, 200, "%0.2f, %0.2f | %d%% | %s", cpu0, cpu1, bat0, datetime);

		free(datetime);
		setstatus(status);
	}

	free(status);
	XCloseDisplay(dpy);

	return 0;
}
Beispiel #7
0
MyWidget::MyWidget(QGLWidget *parent)
  : QGLWidget(QGLFormat(), parent)
{

  setMouseTracking(true);

  setPaletteBackgroundColor(QColor(255,255,255));

  setstatus();

  menu = new QMenuBar(this, "Menu bar");
  file = new QPopupMenu( this , "file");
  save = new QPopupMenu( this , "save");
  placement = new QPopupMenu( this , "placement");
  options = new QPopupMenu( this , "options");
  view = new QPopupMenu( this , "viewing");
  save->insertItem( "Save &eps file", this, SLOT(savedepsfile()), CTRL+Key_E );
  save->insertItem( "Save &stl file", this, SLOT(savedstlfile()), CTRL+Key_S );
  file->insertItem( "&Load", this, SLOT(openedfile()), CTRL+Key_L );
  generate_id = placement->insertItem( "&Generate", &p, SLOT(generate()), CTRL+Key_G );
  generatefirst_id = placement->insertItem( "Generate &First", &p, SLOT(generateFirst()), CTRL+Key_F );
  generatenext_id = placement->insertItem( "Generate &Next", &p, SLOT(generateNext()), CTRL+Key_N );
  generateten_id = placement->insertItem( "Next &ten streamlines", &p, SLOT(generateTen()), CTRL+Key_T );
  generateresume_id = placement->insertItem( "&Resume the placement", &p, SLOT(generateAll()), CTRL+Key_C );
  clear_id = placement->insertItem( "&Clear", &p, SLOT(purge()), CTRL+Key_M );
  drawstl_id = view->insertItem( "&Draw streamlines", &p, SLOT(draw_stl()), CTRL+Key_D );
  drawpq_id = view->insertItem( "Draw &queue elements", &p, SLOT(draw_pq()), CTRL+Key_Q );
  drawtr_id = view->insertItem( "Draw t&riangulation", &p, SLOT(draw_tr()), CTRL+Key_R );
  drawbc_id = view->insertItem( "Draw &biggest circle", &p, SLOT(draw_bc()), CTRL+Key_B );
  addimage_id = placement->insertItem( "&Image", this, SLOT(openedimage()), CTRL+Key_I );
  options->insertItem( "Density...", &p, SLOT(density()));
  options->insertItem( "Saturation ration...", &p, SLOT(ratio()));
  options->insertItem( "Sampling step...", &p, SLOT(sampling()));
  options->insertItem( "Integrating step...", &p, SLOT(integrating()));
  placement->insertItem( "&Options ", options );
  save_id = file->insertItem( "&Save", save );
  menu->insertItem( "&File", file );
  menu->insertItem( "&Placement", placement );
  view_id = menu->insertItem( "&View ", view );
  file->insertItem( "&Quit", qApp, SLOT(quit()), ALT+Key_F4 );

  // desable all generator menu items
  placement->setItemEnabled(generate_id, false);
  placement->setItemEnabled(generatefirst_id, false);
  placement->setItemEnabled(generatenext_id, false);
  placement->setItemEnabled(generateten_id, false);
  placement->setItemEnabled(generateresume_id, false);
  placement->setItemEnabled(clear_id, false);

  menu->setItemEnabled(view_id, false);

  placement->setItemEnabled(addimage_id, false);
  file->setItemEnabled(save_id, false);


  connect(this, SIGNAL(fileloaded(const QString &)), &p, SLOT(load(const QString &)));
  connect(this, SIGNAL(imageloaded(const QString &)), &p, SLOT(image(const QString &)));
  connect(&p, SIGNAL(optionschanged()), this, SLOT(updatestatus()));

}
Beispiel #8
0
void
Exit(char *stat)
{
	Updenv();
	setstatus(stat);
	exits(truestatus()?"":getstatus());
}
Beispiel #9
0
int
Waitfor(int pid, int n)
{
	thread *p;
	Waitmsg *w;
	char errbuf[ERRMAX];

	if(pid >= 0 && !havewaitpid(pid))
		return 0;

	while((w = wait()) != nil){
		delwaitpid(w->pid);
		if(w->pid==pid){
			setstatus(w->msg);
			free(w);
			return 0;
		}
		for(p = runq->ret;p;p = p->ret)
			if(p->pid==w->pid){
				p->pid=-1;
				strcpy(p->status, w->msg);
			}
		free(w);
	}

	errstr(errbuf, sizeof errbuf);
	if(strcmp(errbuf, "interrupted")==0) return -1;
	return 0;
}
Beispiel #10
0
static fighter *summon_allies(const fighter *fi, const race *rc, int number) {
    attrib *a;
    unit *mage = fi->unit;
    side *si = fi->side;
    battle *b = si->battle;
    region *r = b->region;
    message *msg;
    unit *u =
        create_unit(r, mage->faction, number, rc, 0, NULL, mage);
    leave(u, true);
    setstatus(u, ST_FIGHT);
    
    u->hp = u->number * unit_max_hp(u);
    
    if (mage->flags & UFL_ANON_FACTION) {
        u->flags |= UFL_ANON_FACTION;
    }
    
    a = a_new(&at_unitdissolve);
    a->data.ca[0] = 0;
    a->data.ca[1] = 100;
    a_add(&u->attribs, a);
    
    msg = msg_message("sp_wolfhowl_effect", "mage amount race", mage, u->number, rc);
    message_all(b, msg);
    msg_release(msg);

    return make_fighter(b, u, si, is_attacker(fi));
}
Beispiel #11
0
int sp_shadowcall(struct castorder * co)
{
    fighter * fi = co->magician.fig;
    int level = co->level;
    double power = co->force;
    battle *b = fi->side->battle;
    region *r = b->region;
    unit *mage = fi->unit;
    attrib *a;
    int force = (int)(get_force(power, 3) / 2);
    unit *u;
    const char *races[3] = { "shadowbat", "nightmare", "vampunicorn" };
    const race *rc = rc_find(races[rng_int() % 3]);
    message *msg;

    u = create_unit(r, mage->faction, force, rc, 0, NULL, mage);
    setstatus(u, ST_FIGHT);

    set_level(u, SK_WEAPONLESS, (int)(power / 2));
    set_level(u, SK_STAMINA, (int)(power / 2));
    u->hp = u->number * unit_max_hp(u);

    a = a_new(&at_unitdissolve);
    a->data.ca[0] = 0;
    a->data.ca[1] = 100;
    a_add(&u->attribs, a);

    make_fighter(b, u, fi->side, is_attacker(fi));
    msg =
        msg_message("sp_shadowcall_effect", "mage amount race", mage, u->number,
        u_race(u));
    message_all(b, msg);
    msg_release(msg);
    return level;
}
Beispiel #12
0
void
execflag(void)
{
	char *letter, *val;
	switch(count(runq->argv->words)){
	case 2:
		setstatus(flag[(uchar)runq->argv->words->next->word[0]]?"":"flag not set");
		break;
	case 3:
		letter = runq->argv->words->next->word;
		val = runq->argv->words->next->next->word;
		if(strlen(letter)==1){
			if(strcmp(val, "+")==0){
				flag[(uchar)letter[0]] = flagset;
				break;
			}
			if(strcmp(val, "-")==0){
				flag[(uchar)letter[0]] = 0;
				break;
			}
		}
	default:
		Xerror1("Usage: flag [letter] [+-]");
		return;
	}
	poplist();
}
Beispiel #13
0
int
main(void)
{
        struct items {
                char *up;
                char *load;
                char *fan;
                char *temp;
                char *mem;
                char *swap;
                char *diskio;
                char *fs_root;
                char *fs_home;
                char *fs_storage;
                char *net_speed;
                char *batt;
                char *vol;
                char *time;
                char *status;
        };

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
    }

        struct items *i = malloc(sizeof(struct items));

	while(1) {
		i->up = get_up();
		i->load = get_load();
		i->fan = get_fan();
		i->temp = get_temp();
		i->mem = get_mem();
		i->swap = get_swap();
		i->diskio = get_diskio("sda");
                i->fs_root = get_space("/");
                i->fs_home = get_space("/home");
                i->net_speed = get_net_speed();
		i->batt = get_batt();
		i->vol = get_vol();
		i->time = mktimes("%m/%d/%Y %a %H:%M", tzkiev);

		i->status = smprintf(
                        "up:%s la:%s fan:%s temp:%s m:%s s:%s io:%s /:%s "
                        "~/:%s net:%s bat:%s vol:%s %s",
                        i->up, i->load, i->fan, i->temp, i->mem, i->swap,
                        i->diskio, i->fs_root, i->fs_home, i->net_speed,
                        i->batt, i->vol, i->time);
		setstatus(i->status);

                sleep(INTERVAL);
    }

        free(i);

	XCloseDisplay(dpy);

	return EXIT_SUCCESS;
}
Beispiel #14
0
int main(void) {
    char status[100];
    int l = 0;

    if (!(dpy = XOpenDisplay(NULL))) {
        fprintf(stderr, "Cannot open display.\n");
        return 1;
    }

    for (;;sleep(2)) {

        l = getcpu(status, sizeof(status));
        l += gettemp(status + l, sizeof(status) - l);
        l += getmem(status + l, sizeof(status) - l);
        l += getnetwork(status + l, sizeof(status) - l);
        l += getbattery(status + l, sizeof(status) - l);
        l += getvol(status + l, sizeof(status) - l);
        l += getdatetime(status + l, sizeof(status) - l);

        setstatus(status);
    }

    free(status);
    XCloseDisplay(dpy);

    return 0;
}
Beispiel #15
0
int
main(void)
{
	char *status;
    char *newmails;
    
	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	for (;;sleep(60)) {
        newmails = get_nmail("/home/xavier/Maildir/laposte/new", "Mails:");


		status = smprintf("%s",newmails);
		setstatus(status);
		free(newmails);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
Beispiel #16
0
void
Xmatch(void)
{
	word *p;
	char *subject;
	subject = list2str(runq->argv->words);
	setstatus("no match");
	for(p = runq->argv->next->words;p;p = p->next)
		if(match(subject, p->word, '\0')){
			setstatus("");
			break;
		}
	efree(subject);
	poplist();
	poplist();
}
Beispiel #17
0
int main(void) {
	char *status;
	char *avgs;
	char *tmar;
	char *tmutc;
	char *tmbln;

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	for (;;sleep(3)) {
		avgs = loadavg();
		tmar = mktimes("%H:%M", tzargentina);
		tmutc = mktimes("%H:%M", tzutc);
		tmbln = mktimes("KW %W %a %d %b %H:%M %Z %Y", tzberlin);

		status = smprintf("L:%s A:%s ◷ %s", avgs, tmar, tmutc);
		setstatus(status);
		free(avgs);
		free(tmar);
		free(tmutc);
		free(tmbln);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
Beispiel #18
0
int
main(void)
{
  char tmnyc[128];
  char avgs[128];
  char *status;
  int warn = 0;

  if (!(dpy = XOpenDisplay(NULL))) {
    fprintf(stderr, "dwmstatus: cannot open display.\n");
    return 1;
  }

  for (;;sleep(2)) {
    loadavg(avgs, 128);
    warn = mktimes(tmnyc, 128, "%a, %B %d, %R", tznyc);
    if (warn) {
      status = smprintf("[L: %s | \x04%s\x01]", avgs, tmnyc);
    }
    else {
      status = smprintf("[L: %s | %s]", avgs, tmnyc);      
    }
                      
    setstatus(status);
    free(status);
  }

  XCloseDisplay(dpy);

  return 0;
}
Beispiel #19
0
static void set_err_status(struct request *r, enum http_status_type s)
{
	if (!r)
		return;
	r->in_http_err = 1;
	setstatus(r, s);
}
Beispiel #20
0
int
main(void)
{
	char *status;
	char *avgs;
	char *tmutc;
	char *tmvan;

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	for (;;sleep(5)) {
		avgs = loadavg();
		tmutc = mktimes("%H:%M", tzutc);
		tmvan = mktimes("%a %Y-%m-%d %H:%M:%S %Z", tzvan);

		status = smprintf("LOAD %s  //  %s [%s UTC]",
				avgs, tmvan, tmutc);
		setstatus(status);

		free(avgs);
		free(tmutc);
		free(tmvan);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
Beispiel #21
0
int main(void)
{
	char *status;
        char *batt;
	char *tmmtl;
	char *tmgva;

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	for (;;sleep(1)) {
                batt = battery();
		tmmtl = mktimes(tmfmt, tzmtl);
		tmgva = mktimes(tmfmt, tzgva);

		status = smprintf("%s | mtl: %s gva: %s",
				batt,tmmtl,tmgva);
		setstatus(status);
                free(batt);
		free(tmmtl);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
Beispiel #22
0
int
main(void)
{
	char *status;
	char *avgs;
	char *tmsf;

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}

	for (;;sleep(90)) {
		avgs = loadavg();
		tmsf = mktimes("W:%W %a %d %b %Y %H:%M", tzsofia);

		status = smprintf("L:%s | %s", avgs, tmsf);
		setstatus(status);
		free(avgs);
		free(tmsf);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
Beispiel #23
0
int
main(void) {
	char *status;
	char *tmchicago;
	char *alsavolume;
	char *mpdinfo;
	char *mailinfo;
	char *networkinfo;
	char *layoutinfo;
	static unsigned long long int rec, sent;
	time_t count5min = time(NULL);

	/*
	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}
	*/

	xkblayoutSetup();

	parse_netdev(&rec,&sent);
	mailinfo = getMailCount();
	for (;;sleep(1)) {
		/* Put together the pieces of our status */
		tmchicago = mktimes("%a, %b %d %I:%M", tzchicago);
		alsavolume = get_volume();
		mpdinfo = getmpdstat();
		networkinfo = get_netusage(&rec,&sent);
		layoutinfo = getKeyboardLayout();

		if(runevery(&count5min, 300)) {
			free(mailinfo);
			mailinfo = getMailCount();
		}

		/* Build the status string from our pieces */
		status = smprintf("%s %s %s %s %s[%s%s%%%s] %s[%s%s%s]", mpdinfo, networkinfo, mailinfo, layoutinfo, colcyan, colgreen, alsavolume, colcyan, colcyan, colyellow, tmchicago, colcyan);

		/* Send it to the wm for display */
		setstatus(status);

		/* Clean up our pieces */
		free(layoutinfo);
		free(tmchicago);
		free(alsavolume);
		free(mpdinfo);
		free(networkinfo);
		free(status);
	}

	free(mailinfo);

	xkblayoutCleanup();

	XCloseDisplay(dpy);

	return 0;
}
Beispiel #24
0
void
execcd(void)
{
	word *a = runq->argv->words;
	word *cdpath;
	char dir[512];
	setstatus("can't cd");
	cdpath = vlook("cdpath")->val;
	switch(count(a)){
	default:
		pfmt(err, "Usage: cd [directory]\n");
		break;
	case 2:
		if(a->next->word[0]=='/' || cdpath==0)
			cdpath=&nullpath;
		for(;cdpath;cdpath = cdpath->next){
			strcpy(dir, cdpath->word);
			if(dir[0])
				strcat(dir, "/");
			strcat(dir, a->next->word);
			if(dochdir(dir)>=0){
				if(strlen(cdpath->word)
				&& strcmp(cdpath->word, ".")!=0)
					pfmt(err, "%s\n", dir);
				setstatus("");
				break;
			}
		}
		if(cdpath==0)
			pfmt(err, "Can't cd %s: %r\n", a->next->word);
		break;
	case 1:
		a = vlook("home")->val;
		if(count(a)>=1){
			if(dochdir(a->word)>=0)
				setstatus("");
			else
				pfmt(err, "Can't cd %s: %r\n", a->word);
		}
		else
			pfmt(err, "Can't cd -- $home empty\n");
		break;
	}
	poplist();
}
Beispiel #25
0
int CodesObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = TSqlObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< int*>(_v) = getid(); break;
        case 1: *reinterpret_cast< QString*>(_v) = gettitle(); break;
        case 2: *reinterpret_cast< QString*>(_v) = getcode(); break;
        case 3: *reinterpret_cast< QString*>(_v) = getcode_url(); break;
        case 4: *reinterpret_cast< int*>(_v) = getstatus(); break;
        case 5: *reinterpret_cast< QDateTime*>(_v) = getcreated_at(); break;
        case 6: *reinterpret_cast< QDateTime*>(_v) = getupdated_at(); break;
        case 7: *reinterpret_cast< int*>(_v) = geteditable(); break;
        case 8: *reinterpret_cast< int*>(_v) = getuser_id(); break;
        case 9: *reinterpret_cast< QString*>(_v) = getshow_from(); break;
        }
        _id -= 10;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setid(*reinterpret_cast< int*>(_v)); break;
        case 1: settitle(*reinterpret_cast< QString*>(_v)); break;
        case 2: setcode(*reinterpret_cast< QString*>(_v)); break;
        case 3: setcode_url(*reinterpret_cast< QString*>(_v)); break;
        case 4: setstatus(*reinterpret_cast< int*>(_v)); break;
        case 5: setcreated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 6: setupdated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 7: seteditable(*reinterpret_cast< int*>(_v)); break;
        case 8: setuser_id(*reinterpret_cast< int*>(_v)); break;
        case 9: setshow_from(*reinterpret_cast< QString*>(_v)); break;
        }
        _id -= 10;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 10;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 10;
    } else if (_c == QMetaObject::RegisterPropertyMetaType) {
        if (_id < 10)
            *reinterpret_cast<int*>(_a[0]) = -1;
        _id -= 10;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Beispiel #26
0
SEXP setStatusBar(SEXP text)
{
    if(!isString(text)  || LENGTH(text) != 1 ||
       STRING_ELT(text, 0) == NA_STRING)
	error(_("'text' must be a character string"));
    showstatusbar();
    setstatus(translateChar(STRING_ELT(text, 0)));
    return R_NilValue;
}
Beispiel #27
0
/* 
 * setup the status bar here
 */
int
status(int tostatusbar)
{
    char *status = NULL;
    char *avgs = NULL;
    char *time = NULL;
    char *batt = NULL;
    char *net = NULL;
    char *temp = NULL;
    char *ipaddr = NULL;
    char *net_device_up = NET_DEVICE_PRIMARY;
    time_t count60 = 0;
    time_t count10 = 0;

    if (!(dpy = XOpenDisplay(NULL)) && tostatusbar == 0) {
        fprintf(stderr, "dwmstatus: cannot open display.\n");
        return 1;
    }

    for (;;sleep(0)) {
        /* Update every minute */
        if (runevery(&count60, 60)) {
            free(time);

            time  = mktimes("%Y/%m/%d %H:%M", TIMEZONE);
        }
        /* Update every 10 seconds */
        if (runevery(&count10, 10)) {
            free(avgs);
            free(temp);
            free(batt);

            avgs   = loadavg();
            temp   = gettemperature(TEMP_SENSOR_PATH, TEMP_SENSOR_UNIT);
            batt   = getbattery(BATT_PATH);
            if(!temp) free(temp);
        }
        /* Update every second */
        net    = get_netusage(net_device_up);
        ipaddr = get_ip_addr(net_device_up);

        /* Format of display */
        status = smprintf("%s (%s) | %s [%s] T %s | %s",
                net, ipaddr, batt, avgs, temp, time);
        if(!ipaddr) free(ipaddr);
        free(net);

        if(tostatusbar == 0)
            setstatus(status);
        else
            puts(status);

        free(status);
    }
    return 0;
}
Beispiel #28
0
void
Xsimple(void)
{
	word *a;
	thread *p = runq;
	var *v;
	struct builtin *bp;
	int pid;
	globlist();
	a = runq->argv->words;
	if(a==0){
		Xerror1("empty argument list");
		return;
	}
	if(flag['x'])
		pfmt(err, "%v\n", p->argv->words); /* wrong, should do redirs */
	v = gvlook(a->word);
	if(v->fn)
		execfunc(v);
	else{
		if(strcmp(a->word, "builtin")==0){
			if(count(a)==1){
				pfmt(err, "builtin: empty argument list\n");
				setstatus("empty arg list");
				poplist();
				return;
			}
			a = a->next;
			popword();
		}
		for(bp = Builtin;bp->name;bp++)
			if(strcmp(a->word, bp->name)==0){
				(*bp->fnc)();
				return;
			}
		if(exitnext()){
			/* fork and wait is redundant */
			pushword("exec");
			execexec();
			Xexit();
		}
		else{
			flush(err);
			Updenv();	/* necessary so changes don't go out again */
			if((pid = execforkexec()) < 0){
				Xerror("try again");
				return;
			}

			/* interrupts don't get us out */
			poplist();
			while(Waitfor(pid, 1) < 0)
				;
		}
	}
}
Beispiel #29
0
int
main(void)
{
	char *status;
	char *avgs;
	char *bat;
	char *date;
	char *charge;
	char *tme;
	char* vol;
	char cores[4][5];
	char *mem;
	char *rx_old, *rx_now, *tx_old, *tx_now;
	initcore();
	int rx_rate, tx_rate; //kilo bytes
	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
	}
	rx_old = runcmd(RXCMD);
	tx_old = runcmd(TXCMD);
	for (;;sleep(1)) {
		//avgs = loadavg();
		//bat = getbattery(BATTERY);
		date = mktimes("%a, %d %b", tzpst);
		tme = mktimes("%H:%M", tzpst);
		//charge = chargeStatus(ADAPTER);
		vol = runcmd(VOLCMD);
		mem = runcmd(MEMCMD);
		//get transmitted and recv'd bytes
		rx_now = runcmd(RXCMD);
		tx_now = runcmd(TXCMD);
		rx_rate = (atoi(rx_now) - atoi(rx_old)) / 1024;
		tx_rate = (atoi(tx_now) - atoi(tx_old)) / 1024;
		getcore(cores);
		status = smprintf("\x05[ \x01WLAN0: \x06%dK\x05 / \x06%dK\x05 ][ \x01VOL: \x06%s \x05][\x01 CPU: \x04%s\x05 / \x04%s\x05 / \x04%s\x05 / \x04%s \x05][\x01 RAM: \x04%s\x05 ][ \x03%s\x05 ][ \x03%s\x05 ]",
				  rx_rate, tx_rate, vol, cores[0], cores[1], cores[2], cores[3], mem, date, tme);
		strcpy(rx_old, rx_now);
		strcpy(tx_old, tx_now);
		//printf("%s\n", status);
		setstatus(status);
		//printf("%s\n", status);
		//free(avgs);
		free(rx_now);
		free(tx_now);
		free(bat);
		free(vol);
		free(date);
		free(status);
	}

	XCloseDisplay(dpy);

	return 0;
}
Beispiel #30
0
void
Xerror1(char *s)
{
	if(strcmp(argv0, "rc")==0 || strcmp(argv0, "/bin/rc")==0)
		pfmt(err, "rc: %s\n", s);
	else
		pfmt(err, "rc (%s): %s\n", argv0, s);
	flush(err);
	setstatus("error");
	while(!runq->iflag) Xreturn();
}