/* * This is the heart of the multiplexer. All inputs add to the tail of the * Engine's queue. The engine takes from the head of its queue and copies * to all outputs on its output list. * Args: Pointer to information structure (iface_t, cast to void) * Returns: Nothing */ void *run_engine(void *info) { senblk_t *sptr; iface_t *optr; iface_t *eptr = (iface_t *)info; int retval=0; (void) pthread_detach(pthread_self()); for (;;) { sptr = next_senblk(eptr->q); if (isactive(eptr->ofilter,sptr)) { pthread_mutex_lock(&eptr->lists->io_mutex); /* Traverse list of outputs and push a copy of senblk to each */ for (optr=eptr->lists->outputs;optr;optr=optr->next) { if ((optr->q) && ((!sptr) || ((sptr->src != optr->id) || (flag_test(optr,F_LOOPBACK))))) { push_senblk(sptr,optr->q); } } pthread_mutex_unlock(&eptr->lists->io_mutex); } if (sptr==NULL) /* Queue has been marked inactive */ break; senblk_free(sptr,eptr->q); } pthread_exit(&retval); }
int setactive(struct protstream *conn, mystring_t *name) { int result; char filename[1024]; /* if string name is empty, disable active script */ if (!strlen(string_DATAPTR(name))) { if (deleteactive(conn) != TIMSIEVE_OK) return TIMSIEVE_FAIL; prot_printf(conn,"OK\r\n"); return TIMSIEVE_OK; } result = scriptname_valid(name); if (result!=TIMSIEVE_OK) { prot_printf(conn,"NO \"Invalid script name\"\r\n"); return result; } if (exists(string_DATAPTR(name))==FALSE) { prot_printf(conn,"NO \"Script does not exist\"\r\n"); return TIMSIEVE_NOEXIST; } /* if script already is the active one just say ok */ if (isactive(string_DATAPTR(name))==TRUE) { prot_printf(conn,"OK\r\n"); return TIMSIEVE_OK; } /* get the name of the active sieve script */ snprintf(filename, sizeof(filename), "%s.bc", string_DATAPTR(name)); /* ok we want to do this atomically so let's - make <activesieve>.NEW as a hard link - rename it to <activesieve> */ result = symlink(filename, "defaultbc.NEW"); if (result) { syslog(LOG_ERR, "symlink(%s, defaultbc.NEW): %m", filename); prot_printf(conn, "NO \"Can't make link\"\r\n"); return TIMSIEVE_FAIL; } result = rename("defaultbc.NEW", "defaultbc"); if (result) { unlink("defaultbc.NEW"); syslog(LOG_ERR, "rename(defaultbc.NEW, defaultbc): %m"); prot_printf(conn,"NO \"Error renaming\"\r\n"); return TIMSIEVE_FAIL; } sync_log_sieve(sieved_userid); prot_printf(conn,"OK\r\n"); return TIMSIEVE_OK; }
int ORects :: truncate(void){ int newcounts; int rid; for ( rid=newcounts=0 ; rid<counts ; rid++ ){ if ( isactive(rid) ){ rectlist[newcounts++] = rectlist[rid]; } } return( counts = newcounts ); }
const char *get_shimname(int index) { if ((index < MAX_SHIMS) && (index >= 0) && isactive(index)) { return( sh_names[index]); } else { return(NULL); } }
int get_shimindex(char *shimname) { int index; for (index = 0; index < MAX_SHIMS; index++) { if ( (strcmp(shimname,sh_names[index]) == 0) && isactive(index)) return(index); } return(-1); }
void MapObjects::draw(int8_t layer, double viewx, double viewy, float alpha) const { for (auto& oid : layers[layer]) { auto mmo = get(oid); if (mmo && mmo->isactive()) { mmo->draw(viewx, viewy, alpha); } } }
/* * Count the number of active sets in graph gno */ int nactive(int gno) { int i, cnt = 0; for (i = 0; i < g[gno].maxplot; i++) { if (isactive(gno, i)) { cnt++; } } return cnt; }
Srv::~Srv() { kLogPrintf("+Srv::~Srv() host=%s:%s\n",shost,sport); if (isactive()) { setactive(false); //завершаем опросный тред (если он есть) kLogPrintf("waiting stop...\n"); pthread_join(thread, NULL); //ждем пока тред остановится } if (allprojectsdom != NULL) delete allprojectsdom; if (pwd != NULL) delete pwd; pthread_mutex_destroy(&mutex); kLogPrintf("-Srv::~Srv()\n"); }
void Srv::setactive(bool b) //включить/выключить тред обновления данных { if (isactive() != b) if (b) { active = true; if ( 0 != pthread_create(&thread, NULL, updatethread, this)) kLogPrintf("pthread_create() error\n"); } else { active = false; //сигнализирует треду остановиться } }
void copy_graph_sets_only(int from, int to) { int i, j; kill_graph(to); set_graph_active(to); /* TODO compare maxplots */ for (i = 0; i < g[from].maxplot; i++) { for (j = 0; j < MAX_SET_COLS; j++) { g[to].p[i].ex[j] = NULL; } g[to].p[i].active = OFF; if (isactive(from, i)) { do_copyset(from, i, to, i); } } }
/* list the scripts user has available */ int listscripts(struct protstream *conn) { DIR *dp; struct dirent *dir; size_t length; /* open the directory */ dp=opendir("."); if (dp==NULL) { prot_printf(conn,"NO \"Error opening directory\"\r\n"); return TIMSIEVE_FAIL; } while ((dir=readdir(dp)) != NULL) /* while there are files here */ { length=strlen(dir->d_name); if (length >= strlen(".script")) /* if ends in .script */ { if (strcmp(dir->d_name + (length - 7), ".script")==0) { char *namewo=(char *) xmalloc(length-6); memcpy(namewo, dir->d_name, length-7); namewo[length-7]='\0'; if (isactive(namewo)==TRUE) prot_printf(conn,"\"%s\" ACTIVE\r\n", namewo); else prot_printf(conn,"\"%s\"\r\n", namewo); free(namewo); } } } closedir(dp); prot_printf(conn,"OK\r\n"); return TIMSIEVE_OK; }
void autoscale_set(int gno, int setno, int axis) { if (isactive(gno, setno)) { switch (axis) { case -3: defaultsetgraph(gno, setno); default_axis(gno, g[gno].auto_type, X_AXIS); default_axis(gno, g[gno].auto_type, ZX_AXIS); default_axis(gno, g[gno].auto_type, Y_AXIS); default_axis(gno, g[gno].auto_type, ZY_AXIS); break; case -2: defaultx(gno, setno); default_axis(gno, g[gno].auto_type, X_AXIS); default_axis(gno, g[gno].auto_type, ZX_AXIS); break; case -1: defaulty(gno, setno); default_axis(gno, g[gno].auto_type, Y_AXIS); default_axis(gno, g[gno].auto_type, ZY_AXIS); break; default: if (axis % 2) { defaulty(gno, setno); } else { defaultx(gno, setno); } default_axis(gno, g[gno].auto_type, axis); break; } update_all(gno); } else { errwin("Set not active!"); } }
/* delete a sieve script */ int deletescript(struct protstream *conn, const struct buf *name) { int result; char path[1024]; result = scriptname_valid(name); if (result!=TIMSIEVE_OK) { prot_printf(conn,"NO \"Invalid script name\"\r\n"); return result; } snprintf(path, 1023, "%s.script", name->s); if (isactive(name->s)) { prot_printf(conn, "NO (ACTIVE) \"Active script cannot be deleted\"\r\n"); return TIMSIEVE_FAIL; } result = unlink(path); if (result != 0) { if (result == ENOENT) prot_printf(conn, "NO (NONEXISTENT) \"Script %s does not exist.\"\r\n", name->s); else prot_printf(conn,"NO \"Error deleting script\"\r\n"); return TIMSIEVE_FAIL; } snprintf(path, 1023, "%s.bc", name->s); result = unlink(path); if (result != 0) { prot_printf(conn,"NO \"Error deleting bytecode\"\r\n"); return TIMSIEVE_FAIL; } sync_log_sieve(sieved_userid); prot_printf(conn,"OK\r\n"); return TIMSIEVE_OK; }
void copy_graph(int from, int to) { int i, j; plotarr *p; kill_graph(to); p = g[to].p; memcpy(&g[to], &g[from], sizeof(graph)); g[to].p = p; set_graph_active(to); /* TODO compare maxplots */ for (i = 0; i < g[from].maxplot; i++) { for (j = 0; j < MAX_SET_COLS; j++) { g[to].p[i].ex[j] = NULL; } g[to].p[i].active = OFF; if (isactive(from, i)) { do_copyset(from, i, to, i); } } }
/* delete a sieve script */ int deletescript(struct protstream *conn, mystring_t *name) { int result; char path[1024]; result = scriptname_valid(name); if (result!=TIMSIEVE_OK) { prot_printf(conn,"NO \"Invalid script name\"\r\n"); return result; } snprintf(path, 1023, "%s.script", string_DATAPTR(name)); if (isactive(string_DATAPTR(name)) && (deleteactive(conn)!=TIMSIEVE_OK)) { return TIMSIEVE_FAIL; } result = unlink(path); if (result != 0) { prot_printf(conn,"NO \"Error deleting script\"\r\n"); return TIMSIEVE_FAIL; } snprintf(path, 1023, "%s.bc", string_DATAPTR(name)); result = unlink(path); if (result != 0) { prot_printf(conn,"NO \"Error deleting bytecode\"\r\n"); return TIMSIEVE_FAIL; } sync_log_sieve(sieved_userid); prot_printf(conn,"OK\r\n"); return TIMSIEVE_OK; }
/*DRAFT IF IN A CITY*/ void draft(void) { short armynum, x, y, i; long men = 0, mercs; short army = (-1), isgod = FALSE, newtype = 0; long i_cost, e_cost; char ch; clear_bottom(0); if (country == 0) { isgod = TRUE; country = sct[XREAL][YREAL].owner; curntn = &ntn[country]; } else if (sct[XREAL][YREAL].owner != country) { errormsg("You do not own"); return; } if ((sct[XREAL][YREAL].designation != DTOWN) && (sct[XREAL][YREAL].designation != DCAPITOL) && (sct[XREAL][YREAL].designation != DCITY)) { errormsg("must raise in towns/cities/capitols"); if (isgod == TRUE) reset_god(); return; } if (curntn->tgold <= 0) { errormsg("You are broke"); if (isgod == TRUE) reset_god(); return; } if (ISCITY(sct[XREAL][YREAL].designation) && (sct[XREAL][YREAL].people * (3 * CITYLIMIT + (curntn->tsctrs / 2)) < curntn->tciv)) { mvprintw(LINES - 1, 0, "Need %d people in sector: hit any key", curntn->tciv / (3 * CITYLIMIT + (curntn->tsctrs / 2))); refresh(); getch(); if (isgod == TRUE) reset_god(); return; } /* ask what type of unit */ y = LINES - 2; mvaddstr(y, 0, "options: 1) spy 2) scout"); clrtoeol(); x = 25; for (i = 0; i <= NOUNITTYPES; i++) { if (unitvalid(i) == TRUE) { mvprintw(y, x + 2, "%s", *(shunittype + i)); mvprintw(y, x, "(%c)", *(shunittype + i)[0]); x += strlen(*(shunittype + i)) + 3; if (x > COLS - 10) { x = 0; y++; } } } move(y, x); clrtoeol(); if ((magic(country, WARRIOR) == TRUE) || (magic(country, WARLORD) == TRUE) || (magic(country, CAPTAIN) == TRUE)) mvaddstr(LINES - 3, 0, "(Warrior = 1/2 enlist cost) what type of unit do you want:"); else mvaddstr(LINES - 3, 0, "what type of unit do you want to raise:"); clrtoeol(); refresh(); ch = getch(); for (newtype = 0; newtype <= NOUNITTYPES; newtype++) if (ch == *(shunittype + newtype)[0]) break; if ((newtype == NOUNITTYPES + 1) || (unitvalid(newtype) == FALSE)) { if (ch == '1') newtype = A_SPY; else if (ch == '2') newtype = A_SCOUT; else { errormsg("Invalid type"); if (isgod == TRUE) reset_god(); return; } } clear_bottom(0); /* marines and sailors may only be drafted in harbors */ if (newtype == A_MARINES || newtype == A_SAILOR) { i = FALSE; for (x = XREAL - 1; x <= XREAL + 1; x++) for (y = YREAL - 1; y <= YREAL + 1; y++) if (sct[x][y].altitude == WATER) i = TRUE; /* not a harbor */ if (i == FALSE) { if (newtype == A_MARINES) errormsg("Huh? What would marines do without the water?"); else errormsg("You gotta be kinding!? Sailors on land?"); if (isgod == TRUE) reset_god(); return; } } /* raise an untrained army */ i = FALSE; if (newtype == A_SPY || newtype == A_SCOUT) { men = 1; } else { mvprintw(LINES - 3, 0, "how many %s do you wish to raise:", unittype[newtype]); clrtoeol(); refresh(); men = get_number(); if (men <= 0) { if (isgod == TRUE) reset_god(); return; } } /* i_people*256 is initial people -> can draft up to following */ /* draftable = max_draft - already drafted */ /* = imen/4 - ( imen - people) */ /* = -3/4 * imen + people) */ /* 192 comes from 3*256/4 */ if ((newtype != A_MERCENARY && (men > sct[XREAL][YREAL].people - (sct[XREAL][YREAL].i_people * 192))) || (sct[XREAL][YREAL].i_people < 0)) { if (sct[XREAL][YREAL].i_people < 0) errormsg("error: sector wasn't city at beginning of turn"); else errormsg("error: raising too many soldiers"); if (isgod == TRUE) reset_god(); return; } /* check that you dont have too many mercenaries */ mercs = 0; if (newtype == A_MERCENARY) { int totalsolds = 0; for (armynum = 0; armynum < MAXARM; armynum++) { if (P_ATYPE < MINLEADER) { if (P_ATYPE == A_MERCENARY) mercs += P_ASOLD; totalsolds += P_ASOLD; } } if (men + mercs > (totalsolds + men) / 2) { errormsg("you would then have more than 50%% mercenaries"); if (isgod == TRUE) reset_god(); return; } if (mercgot + men > MERCMEN / NTOTAL) { errormsg("there are not that many mercanaries available"); if (isgod == TRUE) reset_god(); return; } } e_cost = (long) * (u_encost + newtype) * men; i_cost = (long) * (u_enmetal + newtype) * men; /* magiced get 1/2 enlistment costs */ if ((magic(country, WARRIOR) == TRUE) || (magic(country, WARLORD) == TRUE) || (magic(country, CAPTAIN) == TRUE)) e_cost /= 2; if ((magic(country, SAPPER) == TRUE) && ((newtype == A_SIEGE) || (newtype == A_CATAPULT))) { e_cost /= 2; i_cost /= 2; } /* check to see if enough gold */ if (e_cost > curntn->tgold) { errormsg("You don't have enough talons"); if (isgod == TRUE) reset_god(); return; } else if (i_cost > curntn->metals) { mvprintw(LINES - 1, 0, "You don't have %ld metal", i_cost); mvaddstr(LINES - 1, COLS - 20, "PRESS ANY KEY"); clrtoeol(); refresh(); getch(); if (isgod == TRUE) reset_god(); return; } else { move(LINES - 2, 0); clrtoeol(); } /* count is order of that army in sector */ /* armynum is number of that army */ if ((armynum = getselunit()) >= 0) { if (armynum >= MAXARM || newtype == A_SPY || newtype == A_SCOUT) { army = -1; } else { /* if different types, must raise new army */ if ((newtype == P_ATYPE) && (P_ASTAT != ONBOARD)) { mvaddstr(LINES - 1, 0, "Do you wish to raise a new army:"); clrtoeol(); refresh(); if (getch() != 'y') army = armynum; else army = -1; } else army = (-1); } } if (army == (-1)) { mvprintw(LINES - 2, 0, "(%s, gold talons=%ld, metal=%ld) raising a new army", *(unittype + newtype), e_cost, i_cost); clrtoeol(); refresh(); sleep(1); armynum = 0; while ((army == (-1)) && (armynum < MAXARM)) { if (P_ASOLD <= 0) { army = armynum; P_ASOLD = 0; if (newtype == A_MILITIA) P_ASTAT = MILITIA; /* new militia units=MILITIA */ else P_ASTAT = DEFEND; /* set new armies to DEFEND */ AADJSTAT; AADJMEN; } armynum++; } if (army == (-1)) { errormsg("NO FREE ARMIES"); if (isgod == TRUE) reset_god(); return; } armynum = army; } else { mvprintw(LINES - 2, 0, "(%s, gold talons=%ld, metal=%ld) adding to existing army", *(unittype + newtype), e_cost, i_cost); clrtoeol(); refresh(); sleep(2); } if (newtype == A_SPY) { while (TRUE) { clear_bottom(0); mvaddstr(LINES - 3, 0, "Spy Against What Nation: "); refresh(); if ((i = get_country()) == (-1)) { if (isgod == TRUE) reset_god(); return; } if (i == country) { errormsg("What? You don't even trust yourself?"); i = NTOTAL; } if (!(isntn(ntn[i].active))) { errormsg("You can't spy against them"); i = NTOTAL; } if (i < NTOTAL && isactive(i)) break; } if (curntn->dstatus[i] != UNMET) { P_AYLOC = ntn[i].capy; P_AXLOC = ntn[i].capx; mvprintw(LINES - 2, 0, "The Spy Starts in %s's Capitol (%d,%d)", ntn[i].name, rel_x((int) P_AXLOC), rel_y((int) P_AYLOC)); clrtoeol(); } else { clear_bottom(0); mvprintw(LINES - 4, 0, "You do not yet know where %s is", ntn[i].name); mvaddstr(LINES - 3, 0, "Have the Spy start from this sector? [y or n]"); refresh(); if (getch() != 'y') { if (isgod == TRUE) reset_god(); return; } P_AYLOC = YREAL; P_AXLOC = XREAL; mvprintw(LINES - 2, 0, "Intelligence indicates that %s lies to the %s", ntn[i].name, *(directions + compass((int) P_AXLOC, (int) P_AYLOC, (int) ntn[i].capx, (int) ntn[i].capy))); clrtoeol(); } errormsg(""); redraw = PART; } else { P_AYLOC = YREAL; P_AXLOC = XREAL; } if (newtype == A_SPY || newtype == A_SCOUT) { P_ASTAT = SCOUT; AADJSTAT; } P_ATYPE = newtype; if (P_ATYPE != A_MERCENARY) { sct[XREAL][YREAL].people -= men; SADJCIV; } else { mercgot += men; AADJMERC; } AADJLOC; P_AMOVE = 0; AADJMOV; P_ASOLD += men; AADJMEN; if (P_ASTAT >= NUMSTATUS) { P_ASTAT = ATTACK; AADJSTAT; } curntn->metals -= i_cost; curntn->tgold -= e_cost; makemap(); /* if display 'y' is set, this will show new * army */ if (isgod == TRUE) reset_god(); }
Bool XineramaIsActive(Display *dpy) { init(); return isactive(dpy); }
void flipxy(int gno) { int i, j; tickmarks t; double *x, *y; for (i = 0; i < MAXAXES; i += 2) { memcpy(&t, &g[gno].t[i], sizeof(tickmarks)); memcpy(&g[gno].t[i], &g[gno].t[i + 1], sizeof(tickmarks)); memcpy(&g[gno].t[i + 1], &t, sizeof(tickmarks)); if (g[gno].t[i].t_op == RIGHT) { g[gno].t[i].t_op = TOP; } else if (g[gno].t[i].t_op == LEFT) { g[gno].t[i].t_op = BOTTOM; } if (g[gno].t[i].tl_op == RIGHT) { g[gno].t[i].tl_op = TOP; } else if (g[gno].t[i].tl_op == LEFT) { g[gno].t[i].tl_op = BOTTOM; } if (g[gno].t[i + 1].t_op == TOP) { g[gno].t[i + 1].t_op = RIGHT; } else if (g[gno].t[i + 1].t_op == BOTTOM) { g[gno].t[i + 1].t_op = LEFT; } if (g[gno].t[i + 1].tl_op == TOP) { g[gno].t[i + 1].tl_op = RIGHT; } else if (g[gno].t[i + 1].tl_op == BOTTOM) { g[gno].t[i + 1].tl_op = LEFT; } } if (g[gno].type == LOGX) { g[gno].type = LOGY; } else if (g[gno].type == LOGY) { g[gno].type = LOGX; } fswap(&g[gno].w.xg1, &g[gno].w.yg1); fswap(&g[gno].w.xg2, &g[gno].w.yg2); fswap(&g[gno].dsx, &g[gno].dsy); iswap(&g[gno].fx, &g[gno].fy); iswap(&g[gno].px, &g[gno].py); for (i = 0; i < g[gno].maxplot; i++) { if (isactive(gno, i)) { x = getx(gno, i); /* TODO really need to just swap pointers */ y = gety(gno, i); for (j = 0; j < getsetlength(gno, i); j++) { fswap(&x[j], &y[j]); } updatesetminmax(gno, i); } } update_all(gno); }
/* * Apply changed from configuration dialog. */ static void configure_apply_cb (gpointer data) { ConfigFile *cfgfile; show_volume=isactive(vol_on); show_balance=isactive(bal_on); show_pause=isactive(pause_on); show_trackname=isactive(trackname_on); show_stop=isactive(stop_on); show_repeat=isactive(repeat_on); show_shuffle=isactive(shuffle_on); if (colour) g_free (colour); if (font) g_free (font); colour = g_strdup (gtk_entry_get_text (GTK_ENTRY (colour_entry))); font = g_strdup (gtk_entry_get_text (GTK_ENTRY (font_entry))); timeout = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (timeout_spin)); offset = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (offset_spin)); shadow_offset = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (shadow_spin)); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pos_top))) pos = XOSD_top; else pos = XOSD_bottom; if (osd) { xosd_set_colour (osd, colour); if (xosd_set_font (osd, font) == -1) { DEBUG("invalid font"); DEBUG(font); } xosd_set_timeout (osd, timeout); xosd_set_offset (osd, offset); xosd_set_shadow_offset (osd, shadow_offset); xosd_set_pos (osd, pos); } cfgfile = xmms_cfg_open_default_file(); xmms_cfg_write_string(cfgfile, "osd", "colour", colour); xmms_cfg_write_string(cfgfile, "osd", "font", font); xmms_cfg_write_int(cfgfile, "osd", "timeout", timeout); xmms_cfg_write_int(cfgfile, "osd", "offset", offset); xmms_cfg_write_int(cfgfile, "osd", "shadow_offset", shadow_offset); xmms_cfg_write_int(cfgfile, "osd", "pos", pos); xmms_cfg_write_int (cfgfile, "osd", "show_volume", show_volume ); xmms_cfg_write_int (cfgfile, "osd", "show_balance", show_balance ); xmms_cfg_write_int (cfgfile, "osd", "show_pause", show_pause ); xmms_cfg_write_int (cfgfile, "osd", "show_trackname", show_trackname ); xmms_cfg_write_int (cfgfile, "osd", "show_stop", show_stop ); xmms_cfg_write_int (cfgfile, "osd", "show_repeat", show_repeat ); xmms_cfg_write_int (cfgfile, "osd", "show_shuffle", show_shuffle ); xmms_cfg_write_default_file(cfgfile); xmms_cfg_free(cfgfile); }