/* Return a case-INsensitive hash of buf. */ unsigned int tm_ihash(str_char *buf, unsigned int table_size) { unsigned int result = 0; unsigned int word; int done; str_char *rest_of_buf; ASSERT(buf); ASSERT(table_size > 0); rest_of_buf = buf; do { next_word(&rest_of_buf, &word, &done); convert_to_lower(&word); result += word; } while(!done); return(result % table_size); }
/** * parse_default_source_metric - Parse default_source_metric option * @s: String token * * Reads and assigns the default source metric, if no reliable * unicast routing information available. * * Syntax: * default_source_metric <number> * * Default pref and metric statements should precede all phyint * statements in the config file. * * Returns: * When parsing @s is successful this function returns %TRUE, otherwise %FALSE. */ int parse_default_source_metric(char *s) { char *w; u_int value; vifi_t vifi; struct uvif *v; value = UCAST_DEFAULT_SOURCE_METRIC; if (EQUAL((w = next_word(&s)), "")) { WARN("Missing default source metric; defaulting to %u", UCAST_DEFAULT_SOURCE_METRIC); } else if (sscanf(w, "%u", &value) != 1) { WARN("Invalid default source metric; defaulting to %u", UCAST_DEFAULT_SOURCE_METRIC); value = UCAST_DEFAULT_SOURCE_METRIC; } default_source_metric = value; logit(LOG_INFO, 0, "default_source_metric is %u", value); for (vifi = 0, v = uvifs; vifi < MAXVIFS; ++vifi, ++v) v->uv_local_metric = default_source_metric; return TRUE; }
cons_t *parse(FILE *fd, dict_t **scope, int break_on_newline) { char word[256]; cons_t *prog = NULL; dict_t *entry; value_t val; while (next_word(fd, word, break_on_newline)) { entry = dict_get(*scope, word); if (entry != NULL) { list_push(&prog, wrap_symbol(entry)); } else { val = number(word); if (!null_p(val)) { list_push(&prog, val); } else { *scope = dict_add(*scope, word, null()); list_push(&prog, wrap_symbol(*scope)); } } } return prog; }
static int get_ifname(char **cpp, char **ifnamep) { char w[MAX_WORD], *ocp; struct if_nameindex *ifnp; ocp = *cpp; if (next_word(&ocp, w) && if_namelist != NULL) for (ifnp = if_namelist; ifnp->if_name != NULL; ifnp++) if (strcmp(w, ifnp->if_name) == 0) { /* if_name found. advance the word pointer */ *cpp = ocp; strlcpy(curifname, w, sizeof(curifname)); *ifnamep = curifname; return (1); } /* this is not interface name. use one in the context. */ if (curifname[0] == '\0') return (0); *ifnamep = curifname; return (1); }
static int ctl_parser(char *cmdbuf) { char w[MAX_WORD], *cp = cmdbuf; char *ifname; int state; int rval; if (!get_ifname(&cp, &ifname)) { printf("missing interface name in %s, line %d", altqconfigfile, line_no); return (0); } if (!next_word(&cp, w)) { state = is_q_enabled(ifname); printf("altq %s on %s\n", state ? "enabled" : "disabled", ifname); return (1); } if (EQUAL(w, "enable")) { rval = qcmd_enable(ifname); printf("altq %s on %s\n", (rval == 0) ? "enabled" : "enable failed!", ifname); } else if (EQUAL(w, "disable")) { rval = qcmd_disable(ifname); printf("altq %s on %s\n", (rval == 0) ? "disabled" : "disable failed!", ifname); } else if (EQUAL(w, "reload")) { printf("reinitializing altq...\n"); qcmd_destroyall(); qcmd_init(); } else return (0); return (1); }
/** * parse_default_igmp_querier_timeout - Parse default_igmp_querier_timeout option * @s: String token * * Reads and assigns default querier timeout for an active IGMP querier. * This is the time it takes before pimd tries to take over as the * active querier. If the argument is missing or invalid the system * will calculate a fallback based on the query interval. * * Syntax: * default_igmp_querier_timeout <SEC> * * Returns: * When parsing @s is successful this function returns %TRUE, otherwise %FALSE. */ static int parse_default_igmp_querier_timeout(char *s) { char *w; uint32_t value = 0; uint32_t recommended = QUERIER_TIMEOUT(default_igmp_query_interval); if (EQUAL((w = next_word(&s)), "")) { WARN("Missing argument to default_igmp_querier_timeout!"); } else if (sscanf(w, "%u", &value) != 1) { WARN("Invalid default default_igmp_querier_timeout!"); value = 0; } /* Do some sanity checks to prevent invalid configuration and to recommend * better settings, see GitHub issue troglobit/pimd#31 for details. */ if (value != 0) { /* 1) Prevent invalid configuration */ if (value <= default_igmp_query_interval) { WARN("IGMP querier timeout %d must be larger than the query interval %d, forcing default!", value, default_igmp_query_interval); value = recommended; } /* 2) Warn power user of potentially too low setting. */ if (value < recommended) WARN("The IGMP querier timeout %d is smaller than the recommended value %d, allowing ...", value, recommended); logit(LOG_WARNING, 0, "Recommended querier timeout = Robustness x query-interval + response-time / 2 = %d x %d + %d / 2 = %d", IGMP_ROBUSTNESS_VARIABLE, default_igmp_query_interval, IGMP_QUERY_RESPONSE_INTERVAL, recommended); } default_igmp_querier_timeout = value; return TRUE; }
/* * Read in the information about files used in making the system. * Store it in the ftab linked list. */ void read_files(void) { FILE *fp; register struct file_list *tp, *pf; register struct device *dp; register struct opt *op; const char *wd; char *this, *needs; const char *devorprof; int options; int not_option; char pname[BUFSIZ]; char fname[1024]; char *rest = (char *) 0; int nreqs, first = 1, isdup; ftab = 0; (void) sprintf(fname, "%s/files", config_directory); openit: fp = fopenp(VPATH, fname, pname, "r"); if (fp == 0) { perror(fname); exit(1); } next: options = 0; rest = (char *) 0; /* * filename [ standard | optional ] * [ dev* | profiling-routine ] [ device-driver] */ wd = get_word(fp); if (wd == (char *)EOF) { (void) fclose(fp); if (first == 1) { (void) sprintf(fname, "%s/files.%s", config_directory, machinename); first++; goto openit; } return; } if (wd == 0) goto next; /* * Allow comment lines beginning witha '#' character. */ if (*wd == '#') { while ((wd=get_word(fp)) && wd != (char *)EOF) ; goto next; } this = ns(wd); next_word(fp, wd); if (wd == 0) { printf("%s: No type for %s.\n", fname, this); exit(1); } if ((pf = fl_lookup(this)) && (pf->f_type != INVISIBLE || pf->f_flags)) isdup = 1; else isdup = 0; tp = 0; nreqs = 0; devorprof = ""; needs = 0; if (eq(wd, "standard")) goto checkdev; if (!eq(wd, "optional")) { printf("%s: %s must be optional or standard\n", fname, this); exit(1); } if (strncmp(this, "OPTIONS/", 8) == 0) options++; not_option = 0; nextopt: next_word(fp, wd); if (wd == 0) goto doneopt; if (eq(wd, "not")) { not_option = !not_option; goto nextopt; } devorprof = wd; if (eq(wd, "device-driver") || eq(wd, "profiling-routine")) { next_word(fp, wd); goto save; } nreqs++; if (needs == 0 && nreqs == 1) needs = ns(wd); if (isdup) goto invis; if (options) { struct opt *lop = 0; struct device tdev; /* * Allocate a pseudo-device entry which we will insert into * the device list below. The flags field is set non-zero to * indicate an internal entry rather than one generated from * the configuration file. The slave field is set to define * the corresponding symbol as 0 should we fail to find the * option in the option list. */ init_dev(&tdev); tdev.d_name = ns(wd); tdev.d_type = PSEUDO_DEVICE; tdev.d_flags++; tdev.d_slave = 0; for (op=opt; op; lop=op, op=op->op_next) { char *od = allCaps(ns(wd)); /* * Found an option which matches the current device * dependency identifier. Set the slave field to * define the option in the header file. */ if (strcmp(op->op_name, od) == 0) { tdev.d_slave = 1; if (lop == 0) opt = op->op_next; else lop->op_next = op->op_next; free(op); op = 0; } free(od); if (op == 0) break; } newdev(&tdev); } for (dp = dtab; dp != 0; dp = dp->d_next) { if (eq(dp->d_name, wd) && (dp->d_type != PSEUDO_DEVICE || dp->d_slave)) { if (not_option) goto invis; /* dont want file if option present */ else goto nextopt; } } if (not_option) goto nextopt; /* want file if option missing */ for (op = opt; op != 0; op = op->op_next) if (op->op_value == 0 && opteq(op->op_name, wd)) { if (nreqs == 1) { free(needs); needs = 0; } goto nextopt; } invis: while ((wd = get_word(fp)) != 0) ; if (tp == 0) tp = new_fent(); tp->f_fn = this; tp->f_type = INVISIBLE; tp->f_needs = needs; tp->f_flags = isdup; goto next; doneopt: if (nreqs == 0) { printf("%s: what is %s optional on?\n", fname, this); exit(1); } checkdev: if (wd) { if (*wd == '|') goto getrest; next_word(fp, wd); if (wd) { devorprof = wd; next_word(fp, wd); } } save: getrest: if (wd) { if (*wd == '|') { rest = ns(get_rest(fp)); } else { printf("%s: syntax error describing %s\n", fname, this); exit(1); } } if (eq(devorprof, "profiling-routine") && profiling == 0) goto next; if (tp == 0) tp = new_fent(); tp->f_fn = this; tp->f_extra = rest; if (options) tp->f_type = INVISIBLE; else if (eq(devorprof, "device-driver")) tp->f_type = DRIVER; else if (eq(devorprof, "profiling-routine")) tp->f_type = PROFILING; else tp->f_type = NORMAL; tp->f_flags = 0; tp->f_needs = needs; if (pf && pf->f_type == INVISIBLE) pf->f_flags = 1; /* mark as duplicate */ goto next; }
/** * parse_candidateRP - Parse candidate Rendez-Vous Point information. * @s: String token * * Syntax: * cand_rp [address | ifname] [priority <0-255>] [time <10-16383>] * * Returns: * %TRUE if the parsing was successful, o.w. %FALSE */ int parse_candidateRP(char *s) { u_int time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; u_int priority = PIM_DEFAULT_CAND_RP_PRIORITY; char *w; uint32_t local = INADDR_ANY_N; cand_rp_flag = FALSE; my_cand_rp_adv_period = PIM_DEFAULT_CAND_RP_ADV_PERIOD; while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "priority")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing priority, defaulting to %u", w, PIM_DEFAULT_CAND_RP_PRIORITY); priority = PIM_DEFAULT_CAND_RP_PRIORITY; continue; } if (sscanf(w, "%u", &priority) != 1) { WARN("Invalid priority %s, defaulting to %u", w, PIM_DEFAULT_CAND_RP_PRIORITY); priority = PIM_DEFAULT_CAND_RP_PRIORITY; } if (priority > PIM_MAX_CAND_RP_PRIORITY) { WARN("Too high Cand-RP priority %u, defaulting to %d", priority, PIM_MAX_CAND_RP_PRIORITY); priority = PIM_MAX_CAND_RP_PRIORITY; } continue; } if (EQUAL(w, "time")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing Cand-RP announce interval, defaulting to %u", PIM_DEFAULT_CAND_RP_ADV_PERIOD); time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; continue; } if (sscanf(w, "%u", &time) != 1) { WARN("Invalid Cand-RP announce interval, defaulting to %u", PIM_DEFAULT_CAND_RP_ADV_PERIOD); time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; continue; } if (time < PIM_MIN_CAND_RP_ADV_PERIOD) time = PIM_MIN_CAND_RP_ADV_PERIOD; if (time > PIM_MAX_CAND_RP_ADV_PERIOD) time = PIM_MAX_CAND_RP_ADV_PERIOD; my_cand_rp_adv_period = time; continue; } /* Cand-RP interface or address */ local = ifname2addr(w); if (!local) local = inet_parse(w, 4); if (!inet_valid_host(local)) { local = max_local_address(); WARN("Invalid Cand-RP address '%s', defaulting to %s", w, inet_fmt(local, s1, sizeof(s1))); } else if (local_address(local) == NO_VIF) { local = max_local_address(); WARN("Cand-RP address '%s' is not local, defaulting to %s", w, inet_fmt(local, s1, sizeof(s1))); } } if (local == INADDR_ANY_N) { /* If address not provided, use the max. local */ local = max_local_address(); } my_cand_rp_address = local; my_cand_rp_priority = priority; my_cand_rp_adv_period = time; cand_rp_flag = TRUE; logit(LOG_INFO, 0, "Local Cand-RP address %s, priority %u, interval %u sec", inet_fmt(local, s1, sizeof(s1)), priority, time); return TRUE; }
/** * parse_rp_address - Parse rp_address config option. * @s: String token. * * This is an extension to the original pimd to add pimd.conf support for static * Rendez-Vous Point addresses. * * The function has been extended by [email protected], of Lintrack, to allow specifying * multicast group addresses as well. * * Syntax: * rp_address <ADDRESS> [<GROUP>[</LENGTH> masklen <LENGTH>] * * Returns: * When parsing @s is successful this function returns %TRUE, otherwise %FALSE. */ int parse_rp_address(char *s) { char *w; uint32_t local = 0xffffff; uint32_t group_addr = htonl(INADDR_UNSPEC_GROUP); uint32_t masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN; u_int dummy; struct rp_hold *rph; /* next is RP addr */ w = next_word(&s); if (EQUAL(w, "")) { logit(LOG_WARNING, 0, "Missing rp_address argument"); return FALSE; } local = inet_parse(w, 4); if (local == 0xffffff) { WARN("Invalid rp_address %s", w); return FALSE; } /* next is group addr if exist */ w = next_word(&s); if (!EQUAL(w, "")) { parse_prefix_len (w, &masklen); group_addr = inet_parse(w, 4); if (!IN_MULTICAST(ntohl(group_addr))) { WARN("%s is not a valid multicast address", inet_fmt(group_addr, s1, sizeof(s1))); return FALSE; } /* next is prefix or priority if exist */ while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "masklen")) { w = next_word(&s); if (!sscanf(w, "%u", &masklen)) { WARN("Invalid masklen %s. Defaulting to %d)", w, PIM_GROUP_PREFIX_DEFAULT_MASKLEN); masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN; } } /* Unused, but keeping for backwards compatibility for people who * may still have this option in their pimd.conf * The priority of a static RP is hardcoded to always be 1, see Juniper's * configuration or similar sources for reference. */ if (EQUAL(w, "priority")) { w = next_word(&s); sscanf(w, "%u", &dummy); WARN("The priority of static RP's is, as of pimd 2.2.0, always 1."); } } } else { group_addr = htonl(INADDR_UNSPEC_GROUP); masklen = PIM_GROUP_PREFIX_MIN_MASKLEN; } validate_prefix_len(&masklen); rph = calloc(1, sizeof(*rph)); if (!rph) { logit(LOG_WARNING, 0, "Out of memory when parsing rp-address %s", inet_fmt(local, s1, sizeof(s1))); return FALSE; } rph->address = local; rph->group = group_addr; VAL_TO_MASK(rph->mask, masklen); /* attach at the beginning */ rph->next = g_rp_hold; g_rp_hold = rph; logit(LOG_INFO, 0, "Local static RP: %s, group %s/%d", inet_fmt(local, s1, sizeof(s1)), inet_fmt(group_addr, s2, sizeof(s2)), masklen); return TRUE; }
/* * Extracts given chains from a policy file. */ static int openpam_read_chain(pam_handle_t *pamh, const char *service, pam_facility_t facility, const char *filename, openpam_style_t style) { pam_chain_t *this, **next; const char *p, *q; int count, i, lineno, ret; pam_facility_t fclt; pam_control_t ctlf; char *line, *name; FILE *f; if ((f = fopen(filename, "r")) == NULL) { openpam_log(errno == ENOENT ? PAM_LOG_LIBDEBUG : PAM_LOG_NOTICE, "%s: %m", filename); return (0); } this = NULL; count = lineno = 0; while ((line = openpam_readline(f, &lineno, NULL)) != NULL) { p = line; /* match service name */ if (style == pam_conf_style) { if (!match_word(p, service)) { FREE(line); continue; } p = next_word(p); } /* match facility name */ for (fclt = 0; fclt < PAM_NUM_FACILITIES; ++fclt) if (match_word(p, _pam_facility_name[fclt])) break; if (fclt == PAM_NUM_FACILITIES) { openpam_log(PAM_LOG_NOTICE, "%s(%d): invalid facility '%.*s' (ignored)", filename, lineno, wordlen(p), p); goto fail; } if (facility != fclt && facility != PAM_FACILITY_ANY) { FREE(line); continue; } p = next_word(p); /* include other chain */ if (match_word(p, "include")) { p = next_word(p); if (*next_word(p) != '\0') openpam_log(PAM_LOG_NOTICE, "%s(%d): garbage at end of 'include' line", filename, lineno); if ((name = dup_word(p)) == NULL) goto syserr; ret = openpam_load_chain(pamh, name, fclt); FREE(name); if (ret < 0) goto fail; count += ret; FREE(line); continue; } /* allocate new entry */ if ((this = calloc(1, sizeof *this)) == NULL) goto syserr; /* control flag */ for (ctlf = 0; ctlf < PAM_NUM_CONTROL_FLAGS; ++ctlf) if (match_word(p, _pam_control_flag_name[ctlf])) break; if (ctlf == PAM_NUM_CONTROL_FLAGS) { openpam_log(PAM_LOG_ERROR, "%s(%d): invalid control flag '%.*s'", filename, lineno, wordlen(p), p); goto fail; } this->flag = ctlf; /* module name */ p = next_word(p); if (*p == '\0') { openpam_log(PAM_LOG_ERROR, "%s(%d): missing module name", filename, lineno); goto fail; } if ((name = dup_word(p)) == NULL) goto syserr; this->module = openpam_load_module(name); FREE(name); if (this->module == NULL) goto fail; /* module options */ p = q = next_word(p); while (*q != '\0') { ++this->optc; q = next_word(q); } this->optv = calloc(this->optc + 1, sizeof(char *)); if (this->optv == NULL) goto syserr; for (i = 0; i < this->optc; ++i) { if ((this->optv[i] = dup_word(p)) == NULL) goto syserr; p = next_word(p); } /* hook it up */ for (next = &pamh->chains[fclt]; *next != NULL; next = &(*next)->next) /* nothing */ ; *next = this; this = NULL; ++count; /* next please... */ FREE(line); } if (!feof(f)) goto syserr; fclose(f); return (count); syserr: openpam_log(PAM_LOG_ERROR, "%s: %m", filename); fail: FREE(this); FREE(line); fclose(f); return (-1); }
int is_from (const char *s, char *path, size_t pathlen, time_t *tp) { struct tm tm; int yr; if (path) *path = 0; if (mutt_strncmp ("From ", s, 5) != 0) return 0; s = next_word (s); /* skip over the From part. */ if (!*s) return 0; dprint (3, (debugfile, "\nis_from(): parsing: %s", s)); if (!is_day_name (s)) { const char *p; size_t len; short q = 0; for (p = s; *p && (q || !ISSPACE (*p)); p++) { if (*p == '\\') { if (*++p == '\0') return 0; } else if (*p == '"') { q = !q; } } if (q || !*p) return 0; /* pipermail archives have the return_path obscured such as "me at mutt.org" */ if (ascii_strncasecmp(p, " at ", 4) == 0) { p = strchr(p + 4, ' '); if (!p) { dprint (1, (debugfile, "is_from(): error parsing what appears to be a pipermail-style obscured return_path: %s\n", s)); return 0; } } if (path) { len = (size_t) (p - s); if (len + 1 > pathlen) len = pathlen - 1; memcpy (path, s, len); path[len] = 0; dprint (3, (debugfile, "is_from(): got return path: %s\n", path)); } s = p + 1; SKIPWS (s); if (!*s) return 0; if (!is_day_name (s)) { dprint(1, (debugfile, "is_from(): expected weekday, got: %s\n", s)); return 0; } } s = next_word (s); if (!*s) return 0; /* do a quick check to make sure that this isn't really the day of the week. * this could happen when receiving mail from a local user whose login name * is the same as a three-letter abbreviation of the day of the week. */ if (is_day_name (s)) { s = next_word (s); if (!*s) return 0; } /* now we should be on the month. */ if ((tm.tm_mon = mutt_check_month (s)) < 0) return 0; /* day */ s = next_word (s); if (!*s) return 0; if (sscanf (s, "%d", &tm.tm_mday) != 1) return 0; /* time */ s = next_word (s); if (!*s) return 0; /* Accept either HH:MM or HH:MM:SS */ if (sscanf (s, "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec) == 3); else if (sscanf (s, "%d:%d", &tm.tm_hour, &tm.tm_min) == 2) tm.tm_sec = 0; else return 0; s = next_word (s); if (!*s) return 0; /* timezone? */ if (isalpha ((unsigned char) *s) || *s == '+' || *s == '-') { s = next_word (s); if (!*s) return 0; /* * some places have two timezone fields after the time, e.g. * From [email protected] Wed Aug 2 00:39:12 MET DST 1995 */ if (isalpha ((unsigned char) *s)) { s = next_word (s); if (!*s) return 0; } } /* year */ if (sscanf (s, "%d", &yr) != 1) return 0; tm.tm_year = yr > 1900 ? yr - 1900 : (yr < 70 ? yr + 100 : yr); dprint (3,(debugfile, "is_from(): month=%d, day=%d, hr=%d, min=%d, sec=%d, yr=%d.\n", tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_year)); tm.tm_isdst = -1; if (tp) *tp = mutt_mktime (&tm, 0); return 1; }
void send_rc5(void) { /* load pwm timing, retransmit and retransmit timeout */ struct params_t params; params.raw = next_word(); uint16_t retransmit_delay = next_word(); /* load data */ struct params_t dataparam; dataparam.raw = next_word(); /* remember positing in timing table */ uint16_t pos = 0; /* calculate retransmit timeout */ uint16_t retransmit = retransmit_delay; for (uint8_t i = 0; i <= params.repeat; i++) { retransmit = retransmit_delay -= 3*RC5_TIME; uint16_t data = dataparam.raw; timing[pos++] = RC5_TIME; /* on */ timing[pos++] = RC5_TIME; /* off */ timing[pos++] = RC5_TIME; /* on */ if (toggle_bit) { /* insert off-on */ timing[pos] = RC5_TIME; /* off */ timing[pos+1] = RC5_TIME; /* on */ pos+=2; } else { /* insert on-off */ timing[pos-1] += RC5_TIME; /* double on time */ timing[pos] = RC5_TIME; /* off */ pos++; } uint8_t old_bit = toggle_bit; /* insert data into timing array */ for (uint8_t b = 0; b < 11; b++) { uint8_t bit = data & 1; if ( bit ^ old_bit) { /* if old bit and current bit are different, increase last timing */ timing[pos-1] += RC5_TIME; timing[pos] = RC5_TIME; pos++; old_bit = bit; } else { /* else if both bits are the same, insert normal cycles */ timing[pos++] = RC5_TIME; timing[pos++] = RC5_TIME; } /* subtract cycle length from retransmit */ retransmit -= 2*RC5_TIME; data >>= 1; } /* if pos is even, the last period is off, insert repeat delay there */ if (pos % 2 == 0) { timing[pos-1] = retransmit; /* else the last period is on, add repeat delay as new timing */ } else { timing[pos++] = retransmit; } /* reset retransmit delay */ retransmit = retransmit_delay; } /* now timing[] is an array of on-off times. iterate over it, and * correct the off times */ for (uint8_t j = 0; j < pos; j+=2) { timing[j+1] += timing[j]; } /* flip toggle bit */ toggle_bit = !toggle_bit; /* mark end of code */ timing[pos-1] = 0; /* set loaded pwm value */ pwm_set(params.pwm); }
/* update returns false if enter has been pressed, true otherwise */ bool TCOD_text_update (TCOD_text_t txt, TCOD_key_t key) { int cx,cy,oldpos; text_t * data = (text_t*)txt; TCOD_IFNOT(data && data->con ) return false; oldpos = data->cursor_pos; /* for real-time keyboard : only on key release */ if ( key.pressed ) { /* process keyboard input */ switch (key.vk) { case TCODK_BACKSPACE: /* get rid of the last character */ if ( data->sel_start != MAX_INT ) { deleteSelection(data); } else { deleteChar(data); } break; case TCODK_DELETE: if ( key.shift ) { /* SHIFT-DELETE : cut to clipboard */ cut(data); } else { if ( data->sel_start != MAX_INT ) { deleteSelection(data); } else if ( data->text[data->cursor_pos] ) { data->cursor_pos++; deleteChar(data); } } break; /* shift + arrow / home / end = selection */ /* ctrl + arrow = word skipping. ctrl + shift + arrow = word selection */ case TCODK_LEFT: if ( data->multiline && key.shift && data->sel_end == -1) { data->sel_end = data->cursor_pos; } if ( data->cursor_pos > 0 ) { if ( key.lctrl || key.rctrl ) { previous_word(data); } else data->cursor_pos--; selectStart(data,oldpos,key); } break; case TCODK_RIGHT: if ( data->multiline && key.shift && data->sel_start == MAX_INT ) { data->sel_start = data->cursor_pos; } if ( data->text[data->cursor_pos] ) { if ( key.lctrl || key.rctrl ) { next_word(data); } else data->cursor_pos++; selectEnd(data,oldpos,key); } break; case TCODK_UP : get_cursor_coords(data,&cx,&cy); if ( data->multiline && key.shift && data->sel_end == -1) { data->sel_end = data->cursor_pos; } set_cursor_pos(data,cx,cy-1,false); selectStart(data,oldpos,key); break; case TCODK_DOWN : get_cursor_coords(data,&cx,&cy); if ( data->multiline && key.shift && data->sel_start == MAX_INT ) { data->sel_start = data->cursor_pos; } set_cursor_pos(data,cx,cy+1,false); selectEnd(data,oldpos,key); break; case TCODK_HOME: get_cursor_coords(data,&cx,&cy); if ( data->multiline && key.shift && data->sel_end == -1) { data->sel_end = data->cursor_pos; } if ( key.lctrl || key.rctrl ) { set_cursor_pos(data,0,0,true); } else { set_cursor_pos(data,0,cy,true); } selectStart(data,oldpos,key); break; case TCODK_END: get_cursor_coords(data,&cx,&cy); if ( data->multiline && key.shift && data->sel_start == MAX_INT ) { data->sel_start = data->cursor_pos; } if ( key.lctrl || key.rctrl ) { set_cursor_pos(data,data->w,data->h,true); } else { set_cursor_pos(data,data->w-1,cy,true); } selectEnd(data,oldpos,key); break; case TCODK_ENTER: /* validate input */ case TCODK_KPENTER: if ( data->sel_start != MAX_INT ) { deleteSelection(data); } if ( data->multiline ) { get_cursor_coords(data,&cx,&cy); if ( cy < data->h-1 ) insertChar(data,'\n'); } else { data->input_continue = false; } break; case TCODK_TAB : if (data->tab_size ) { int count=data->tab_size; if ( data->sel_start != MAX_INT ) { deleteSelection(data); } while ( count > 0 ) { insertChar(data,' '); count--; } } break; default: { /* append a new character */ if ( (key.c == 'c' || key.c=='C' || key.vk == TCODK_INSERT) && (key.lctrl || key.rctrl) ) { /* CTRL-C or CTRL-INSERT : copy to clipboard */ copy(data); } else if ( (key.c == 'x' || key.c=='X') && (key.lctrl || key.rctrl) ) { /* CTRL-X : cut to clipboard */ cut(data); } else if ( ((key.c == 'v' || key.c=='V') && (key.lctrl || key.rctrl)) || ( key.vk == TCODK_INSERT && key.shift ) ) { /* CTRL-V or SHIFT-INSERT : paste from clipboard */ paste(data); } else if (key.c > 31) { if ( data->sel_start != MAX_INT ) { deleteSelection(data); } insertChar(data,(char)(key.c)); } break; } } } return data->input_continue; }
/* * Read in the information about files used in making the system. * Store it in the ftab linked list. */ static void read_files(void) { FILE *fp; struct file_list *tp, *pf; struct device *dp; struct device *save_dp; struct opt *op; char *wd, *this, *needs, *special, *depends, *clean, *warning; char fname[MAXPATHLEN]; int nonoptional; int nreqs, first = 1, configdep, isdup, std, filetype, imp_rule, no_obj, before_depend, nowerror, mandatory; ftab = 0; save_dp = NULL; if (ident == NULL) { printf("no ident line specified\n"); exit(1); } snprintf(fname, sizeof(fname), "../conf/files"); openit: fp = fopen(fname, "r"); if (fp == NULL) err(1, "%s", fname); next: /* * filename [ standard | mandatory | optional ] [ config-dependent ] * [ dev* | profiling-routine ] [ no-obj ] * [ compile-with "compile rule" [no-implicit-rule] ] * [ dependency "dependency-list"] [ before-depend ] * [ clean "file-list"] [ warning "text warning" ] */ wd = get_word(fp); if (wd == (char *)EOF) { fclose(fp); if (first == 1) { first++; snprintf(fname, sizeof(fname), "../platform/%s/conf/files", platformname); fp = fopen(fname, "r"); if (fp != NULL) goto next; snprintf(fname, sizeof(fname), "files.%s", platformname); goto openit; } if (first == 2) { first++; snprintf(fname, sizeof(fname), "files.%s", raisestr(ident)); fp = fopen(fname, "r"); if (fp != NULL) goto next; } return; } if (wd == 0) goto next; if (wd[0] == '#') { while (((wd = get_word(fp)) != (char *)EOF) && wd) ; goto next; } this = strdup(wd); next_word(fp, wd); if (wd == 0) { printf("%s: No type for %s.\n", fname, this); exit(1); } if ((pf = fl_lookup(this)) && (pf->f_type != INVISIBLE || pf->f_flags)) isdup = 1; else isdup = 0; tp = 0; if (first == 3 && pf == NULL && (tp = fltail_lookup(this)) != NULL) { if (tp->f_type != INVISIBLE || tp->f_flags) printf("%s: Local file %s overrides %s.\n", fname, this, tp->f_fn); else printf("%s: Local file %s could override %s" " with a different kernel configuration.\n", fname, this, tp->f_fn); } nreqs = 0; special = NULL; depends = NULL; clean = NULL; warning = NULL; configdep = 0; needs = NULL; std = mandatory = nonoptional = 0; imp_rule = 0; no_obj = 0; before_depend = 0; nowerror = 0; filetype = NORMAL; if (strcmp(wd, "standard") == 0) { std = 1; } else if (strcmp(wd, "mandatory") == 0) { /* * If an entry is marked "mandatory", config will abort if * it's not called by a configuration line in the config * file. Apart from this, the device is handled like one * marked "optional". */ mandatory = 1; } else if (strcmp(wd, "nonoptional") == 0) { nonoptional = 1; } else if (strcmp(wd, "optional") == 0) { /* don't need to do anything */ } else { printf("%s: %s must be optional, mandatory or standard\n", fname, this); printf("Alternatively, your version of config(8) may be out of sync with your\nkernel source.\n"); exit(1); } nextparam: next_word(fp, wd); if (wd == NULL) goto doneparam; if (strcmp(wd, "config-dependent") == 0) { configdep++; goto nextparam; } if (strcmp(wd, "no-obj") == 0) { no_obj++; goto nextparam; } if (strcmp(wd, "no-implicit-rule") == 0) { if (special == NULL) { printf("%s: alternate rule required when " "\"no-implicit-rule\" is specified.\n", fname); } imp_rule++; goto nextparam; } if (strcmp(wd, "before-depend") == 0) { before_depend++; goto nextparam; } if (strcmp(wd, "dependency") == 0) { next_quoted_word(fp, wd); if (wd == NULL) { printf("%s: %s missing compile command string.\n", fname, this); exit(1); } depends = strdup(wd); goto nextparam; } if (strcmp(wd, "clean") == 0) { next_quoted_word(fp, wd); if (wd == NULL) { printf("%s: %s missing clean file list.\n", fname, this); exit(1); } clean = strdup(wd); goto nextparam; } if (strcmp(wd, "compile-with") == 0) { next_quoted_word(fp, wd); if (wd == NULL) { printf("%s: %s missing compile command string.\n", fname, this); exit(1); } special = strdup(wd); goto nextparam; } if (strcmp(wd, "nowerror") == 0) { nowerror++; goto nextparam; } if (strcmp(wd, "warning") == 0) { next_quoted_word(fp, wd); if (wd == NULL) { printf("%s: %s missing warning text string.\n", fname, this); exit(1); } warning = strdup(wd); goto nextparam; } nreqs++; if (strcmp(wd, "local") == 0) { filetype = LOCAL; goto nextparam; } if (strcmp(wd, "no-depend") == 0) { filetype = NODEPEND; goto nextparam; } if (strcmp(wd, "device-driver") == 0) { printf("%s: `device-driver' flag obsolete.\n", fname); exit(1); } if (strcmp(wd, "profiling-routine") == 0) { filetype = PROFILING; goto nextparam; } if (needs == 0 && nreqs == 1) needs = strdup(wd); if (isdup) goto invis; for (dp = dtab; dp != NULL; save_dp = dp, dp = dp->d_next) if (strcmp(dp->d_name, wd) == 0) { if (std && dp->d_type == PSEUDO_DEVICE && dp->d_count <= 0) dp->d_count = 1; goto nextparam; } if (mandatory) { printf("%s: mandatory device \"%s\" not found\n", fname, wd); exit(1); } if (std) { dp = malloc(sizeof(*dp)); bzero(dp, sizeof(*dp)); init_dev(dp); dp->d_name = strdup(wd); dp->d_type = PSEUDO_DEVICE; dp->d_count = 1; save_dp->d_next = dp; goto nextparam; } for (op = opt; op != NULL; op = op->op_next) { if (op->op_value == 0 && opteq(op->op_name, wd)) { if (nreqs == 1) { free(needs); needs = NULL; } goto nextparam; } } if (nonoptional) { printf("%s: the option \"%s\" MUST be specified\n", fname, wd); exit(1); } invis: while ((wd = get_word(fp)) != 0) ; if (tp == NULL) tp = new_fent(); tp->f_fn = this; tp->f_type = INVISIBLE; tp->f_needs = needs; tp->f_flags = isdup; tp->f_special = special; tp->f_depends = depends; tp->f_clean = clean; tp->f_warn = warning; goto next; doneparam: if (std == 0 && nreqs == 0) { printf("%s: what is %s optional on?\n", fname, this); exit(1); } if (wd != NULL) { printf("%s: syntax error describing %s\n", fname, this); exit(1); } if (filetype == PROFILING && profiling == 0) goto next; if (tp == NULL) tp = new_fent(); tp->f_fn = this; tp->f_type = filetype; tp->f_flags = 0; if (configdep) tp->f_flags |= CONFIGDEP; if (imp_rule) tp->f_flags |= NO_IMPLCT_RULE; if (no_obj) tp->f_flags |= NO_OBJ; if (before_depend) tp->f_flags |= BEFORE_DEPEND; if (nowerror) tp->f_flags |= NOWERROR; if (imp_rule) tp->f_flags |= NO_IMPLCT_RULE; if (no_obj) tp->f_flags |= NO_OBJ; tp->f_needs = needs; tp->f_special = special; tp->f_depends = depends; tp->f_clean = clean; tp->f_warn = warning; if (pf && pf->f_type == INVISIBLE) pf->f_flags = 1; /* mark as duplicate */ goto next; }
/** * parse_spt_threshold - Parse spt_threshold option * @s: String token * * This configuration setting replaces the switch_register_threshold and * switch_data_threshold. It is more intuitive and more in line with * what major vendors are also using. * * Note that the rate is in kbps instead of bps, compared to the old * syntax. Both the above parse_compat_threshold() and this function * target the same backend. * * Syntax: * spt_threshold [rate <KBPS> | packets <NUM> | infinity] [interval <SEC>] * * Returns: * When parsing @s is successful this function returns %TRUE, otherwise %FALSE. */ static int parse_spt_threshold(char *s) { char *w; u_int32 rate = SPT_THRESHOLD_DEFAULT_RATE; u_int32 packets = SPT_THRESHOLD_DEFAULT_PACKETS; u_int32 interval = SPT_THRESHOLD_DEFAULT_INTERVAL; spt_mode_t mode = SPT_THRESHOLD_DEFAULT_MODE; while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "rate")) { mode = SPT_RATE; if (EQUAL((w = next_word(&s)), "")) { WARN("Missing spt-threshold rate argument, defaulting to %u", SPT_THRESHOLD_DEFAULT_RATE); rate = SPT_THRESHOLD_DEFAULT_RATE; continue; } /* 10 --> 1,000,000,000 == 100 Gbps */ if (sscanf(w, "%10u", &rate) != 1) { WARN("Invalid spt-threshold rate %s, defaulting to %u", w, SPT_THRESHOLD_DEFAULT_RATE); rate = SPT_THRESHOLD_DEFAULT_RATE; } continue; } if (EQUAL(w, "interval")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing spt-threshold interval; defaulting to %u sec", SPT_THRESHOLD_DEFAULT_INTERVAL); interval = SPT_THRESHOLD_DEFAULT_INTERVAL; continue; } /* 5 --> 99,999 ~= 27h */ if (sscanf(w, "%5u", &interval) != 1) { WARN("Invalid spt-threshold interval %s; defaulting to %u sec", w, SPT_THRESHOLD_DEFAULT_INTERVAL); interval = SPT_THRESHOLD_DEFAULT_INTERVAL; } if (interval < TIMER_INTERVAL) { WARN("Too low spt-threshold interval %s; defaulting to %u sec", w, TIMER_INTERVAL); interval = TIMER_INTERVAL; } continue; } if (EQUAL(w, "packets")) { mode = SPT_PACKETS; if (EQUAL((w = next_word(&s)), "")) { WARN("Missing spt-threshold number of packets; defaulting to %u", SPT_THRESHOLD_DEFAULT_PACKETS); packets = SPT_THRESHOLD_DEFAULT_PACKETS; continue; } /* 10 --> 4294967295, which is max of uint32_t */ if (sscanf(w, "%10u", &packets) != 1) { WARN("Invalid spt-threshold packets %s; defaulting to %u", w, SPT_THRESHOLD_DEFAULT_PACKETS); packets = SPT_THRESHOLD_DEFAULT_INTERVAL; } continue; } if (EQUAL(w, "infinity")) { mode = SPT_INF; continue; } WARN("Invalid spt-threshold parameter %s; reverting to defaults.", w); mode = SPT_THRESHOLD_DEFAULT_MODE; rate = SPT_THRESHOLD_DEFAULT_RATE; packets = SPT_THRESHOLD_DEFAULT_PACKETS; interval = SPT_THRESHOLD_DEFAULT_INTERVAL; break; } spt_threshold.mode = mode; switch (mode) { case SPT_INF: logit(LOG_INFO, 0, "spt-threshold infinity => RP and lasthop router will never switch to SPT."); break; case SPT_RATE: /* Accounting for headers we can approximate 1 byte/s == 10 bits/s (bps) * Note, in the new spt_threshold setting the rate is in kbps as well! */ spt_threshold.bytes = rate * interval / 10 * 1000; spt_threshold.interval = interval; logit(LOG_INFO, 0, "spt-threshold rate %u interval %u", rate, interval); break; case SPT_PACKETS: spt_threshold.packets = packets; spt_threshold.interval = interval; logit(LOG_INFO, 0, "spt-threshold packets %u interval %u", packets, interval); break; } return TRUE; }
/** * parse_rp_address - Parse rp_address config option. * @s: String token. * * This is an extension to the original pimd to add pimd.conf support for static * Rendez-Vous Point addresses. * * The function has been extended by [email protected], of Lintrack, to allow specifying * multicast group addresses as well. * * Format: * rp_address <rp-address> * * Returns: * When parsing @s is successful this function returns %TRUE, otherwise %FALSE. */ int parse_rp_address(char *s) { char *w; u_int32 local = 0xffffff; u_int32 group_addr; u_int32 masklen; struct rp_hold * rph; w = next_word(&s); if (EQUAL(w, "")) { logit(LOG_WARNING, 0, "'rp_address' in %s: no <rp-addr> - ignoring", configfilename); return FALSE; } local = inet_parse(w, 4); if (local == 0xffffff) { logit(LOG_WARNING, 0, "'rp_address' in %s: invalid <rp-addr> provided: '%s'", configfilename, w); return FALSE; } w = next_word(&s); if (!EQUAL(w, "")) { group_addr = inet_parse(w, 4); if (!IN_MULTICAST(ntohl(group_addr))) { logit(LOG_WARNING, 0, "'rp_address' in %s: %s is not a multicast addr", configfilename, inet_fmt(group_addr, s1, sizeof(s1))); return FALSE; } if (EQUAL((w = next_word(&s)), "masklen")) { w = next_word(&s); if (sscanf(w, "%u", &masklen) == 1) { if (masklen > (sizeof(group_addr) * 8)) masklen = (sizeof(group_addr) * 8); else if (masklen < 4) masklen = 4; } else masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN; } else masklen = PIM_GROUP_PREFIX_DEFAULT_MASKLEN; } else { group_addr = htonl(224 << 24); masklen = 4; } /* save */ rph = malloc(sizeof(*rph)); rph->address = local; rph->group = group_addr; VAL_TO_MASK(rph->mask, masklen); /* attach at the beginning */ rph->next = g_rp_hold; g_rp_hold = rph; logit(LOG_INFO, 0, "Added static RP: %s, group %s/%d", inet_fmt(local, s1, sizeof(s1)), inet_fmt(group_addr, s2, sizeof(s2)), masklen); return TRUE; }
/* * function name: parse_data_threshold * input: char *s * output: int * operation: reads and assigns the switch to the spt threshold * due to data packets, if used as DR. * General form: * 'switch_data_threshold [rate <number> interval <number>]'. */ int parse_data_threshold(char *s) { char *w; u_int rate; u_int interval; rate = PIM_DEFAULT_DATA_RATE; interval = PIM_DEFAULT_DATA_RATE_INTERVAL; pim_data_rate_bytes = (rate * interval) / 10; pim_data_rate_check_interval = interval; while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "rate")) { if (EQUAL((w = next_word(&s)), "")) { logit(LOG_WARNING, 0, "Missing data_rate value; set to default %u (bits/s)\n", PIM_DEFAULT_DATA_RATE); rate = PIM_DEFAULT_DATA_RATE; continue; } if (sscanf(w, "%u", &rate) != 1) { logit(LOG_WARNING, 0, "Invalid data_rate value %s; set to default %u (bits/s)", w, PIM_DEFAULT_DATA_RATE); rate = PIM_DEFAULT_DATA_RATE; } continue; } /* if rate */ if (EQUAL(w, "interval")) { if (EQUAL((w = next_word(&s)), "")) { logit(LOG_WARNING, 0, "Missing data_rate interval; set to default %u seconds", PIM_DEFAULT_DATA_RATE_INTERVAL); interval = PIM_DEFAULT_DATA_RATE_INTERVAL; continue; } if (sscanf(w, "%u", &interval) != 1) { logit(LOG_WARNING, 0, "Invalid data_rate interval %s; set to default %u seconds" , w, PIM_DEFAULT_DATA_RATE_INTERVAL); interval = PIM_DEFAULT_DATA_RATE_INTERVAL; } continue; } /* if interval */ logit(LOG_WARNING, 0, "Invalid parameter %s; setting rate and interval to default", w); rate = PIM_DEFAULT_DATA_RATE; interval = PIM_DEFAULT_DATA_RATE_INTERVAL; break; } /* while not empty */ if (interval < TIMER_INTERVAL) { logit(LOG_WARNING, 0, "data_rate interval too short; set to default %u seconds", PIM_DEFAULT_DATA_RATE_INTERVAL); interval = PIM_DEFAULT_DATA_RATE_INTERVAL; } logit(LOG_INFO, 0, "data_rate_limit is %u (bits/s)", rate); logit(LOG_INFO, 0, "data_rate_interval is %u (seconds)", interval); pim_data_rate_bytes = (rate * interval) / 10; pim_data_rate_check_interval = interval; return TRUE; }
/* * function name: parse_candidateRP * input: char *s * output: int (TRUE if the parsing was successful, o.w. FALSE) * operation: parses the candidate RP information. * The general form is: * 'cand_rp <local-addr> [priority <number>] [time <number>]'. */ int parse_candidateRP(char *s) { u_int time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; u_int priority = PIM_DEFAULT_CAND_RP_PRIORITY; char *w; u_int32 local = INADDR_ANY_N; cand_rp_flag = FALSE; my_cand_rp_adv_period = PIM_DEFAULT_CAND_RP_ADV_PERIOD; while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "priority")) { if (EQUAL((w = next_word(&s)), "")) { logit(LOG_WARNING, 0, "Missing priority; set to default %u (0 is highest)", PIM_DEFAULT_CAND_RP_PRIORITY); priority = PIM_DEFAULT_CAND_RP_PRIORITY; continue; } if (sscanf(w, "%u", &priority) != 1) { logit(LOG_WARNING, 0, "invalid priority %s; set to default %u (0 is highest)", PIM_DEFAULT_CAND_RP_PRIORITY); priority = PIM_DEFAULT_CAND_RP_PRIORITY; } continue; } if (EQUAL(w, "time")) { if (EQUAL((w = next_word(&s)), "")) { logit(LOG_WARNING, 0, "Missing cand_rp_adv_period value; set to default %u", PIM_DEFAULT_CAND_RP_ADV_PERIOD); time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; continue; } if (sscanf(w, "%u", &time) != 1) { logit(LOG_WARNING, 0, "Invalid cand_rp_adv_period value; set to default %u", PIM_DEFAULT_CAND_RP_ADV_PERIOD); time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; continue; } if (time > (my_cand_rp_adv_period = ~0)) time = my_cand_rp_adv_period; /* TODO: XXX: cannot be shorter than 10 seconds (not in the spec)*/ if (time < 10) time = 10; #if 0 if (time > PIM_DEFAULT_CAND_RP_ADV_PERIOD) time = PIM_DEFAULT_CAND_RP_ADV_PERIOD; #endif /* 0 */ my_cand_rp_adv_period = time; continue; } /* Cand-RP address */ local = inet_parse(w, 4); if (!inet_valid_host(local)) { local = max_local_address(); logit(LOG_WARNING, 0, "Invalid Cand-RP address provided '%s' in %s. Will use the largest enabled local address.", w, configfilename); } else if (local_address(local) == NO_VIF) { local = max_local_address(); logit(LOG_WARNING, 0, "Cand-RP address is not local '%s' in %s. Will use the largest enabled local address.", w, configfilename); } } /* while not empty */ if (local == INADDR_ANY_N) { /* If address not provided, use the max. local */ local = max_local_address(); } my_cand_rp_address = local; my_cand_rp_priority = priority; my_cand_rp_adv_period = time; cand_rp_flag = TRUE; logit(LOG_INFO, 0, "Local Cand-RP address is %s", inet_fmt(local, s1, sizeof(s1))); logit(LOG_INFO, 0, "Local Cand-RP priority is %u", priority); logit(LOG_INFO, 0, "Local Cand-RP advertisement period is %u sec.", time); return TRUE; }
void config_vifs_from_file(void) { FILE *f; char linebuf[LINE_BUFSIZ]; char *w, *s; struct ifconf ifc; int option; char ifbuf[BUFSIZ]; u_int8 *data_ptr; int error_flag; int line_num; error_flag = FALSE; line_num = 0; if ((f = fopen(configfilename, "r")) == NULL) { if (errno != ENOENT) logit(LOG_WARNING, errno, "can't open %s", configfilename); return; } /* TODO: HARDCODING!!! */ cand_rp_adv_message.buffer = (u_int8 *)malloc(4 + sizeof(pim_encod_uni_addr_t) + 255*sizeof(pim_encod_grp_addr_t)); cand_rp_adv_message.prefix_cnt_ptr = cand_rp_adv_message.buffer; /* By default, if no group_prefix configured, then prefix_cnt == 0 * implies group_prefix = 224.0.0.0 and masklen = 4. */ *cand_rp_adv_message.prefix_cnt_ptr = 0; cand_rp_adv_message.insert_data_ptr = cand_rp_adv_message.buffer; /* TODO: XXX: HARDCODING!!! */ cand_rp_adv_message.insert_data_ptr += (4 + 6); ifc.ifc_buf = ifbuf; ifc.ifc_len = sizeof(ifbuf); if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0) logit(LOG_ERR, errno, "ioctl SIOCGIFCONF"); while (fgets(linebuf, sizeof(linebuf), f) != NULL) { if (strlen(linebuf) >= (LINE_BUFSIZ - 1)) { logit(LOG_WARNING, 0, "line length must be shorter than %d in %s:%d", LINE_BUFSIZ, configfilename, line_num); error_flag = TRUE; } else { line_num++; } s = linebuf; w = next_word(&s); option = wordToOption(w); switch(option) { case EMPTY: continue; break; case PHYINT: parse_phyint(s); break; case CANDIDATE_RP: parse_candidateRP(s); break; case RP_ADDRESS: parse_rp_address(s); break; case GROUP_PREFIX: parse_group_prefix(s); break; case BOOTSTRAP_RP: parseBSR(s); break; case REG_THRESHOLD: parse_reg_threshold(s); break; case DATA_THRESHOLD: parse_data_threshold(s); break; case DEFAULT_SOURCE_METRIC: parse_default_source_metric(s); break; case DEFAULT_SOURCE_PREFERENCE: parse_default_source_preference(s); break; default: logit(LOG_WARNING, 0, "unknown command '%s' in %s:%d", w, configfilename, line_num); error_flag = TRUE; } } if (error_flag) { /* * XXX: let's be pedantic even about warnings. If this is a problem, * comment out this logit(LOG_ERR). */ logit(LOG_ERR, 0, "Syntax Error in %s", configfilename); } cand_rp_adv_message.message_size = cand_rp_adv_message.insert_data_ptr - cand_rp_adv_message.buffer; if (cand_rp_flag != FALSE) { /* Prepare the RP info */ my_cand_rp_holdtime = 2.5 * my_cand_rp_adv_period; /* TODO: HARDCODING! */ data_ptr = cand_rp_adv_message.buffer + 1; PUT_BYTE(my_cand_rp_priority, data_ptr); PUT_HOSTSHORT(my_cand_rp_holdtime, data_ptr); PUT_EUADDR(my_cand_rp_address, data_ptr); } fclose(f); }
Instruction CPU::next_instruction() { char off; Instruction next; next.opcode = next_byte(); int extra_cycles = 0; next.op = ops[next.opcode]; switch (next.op.addr_mode) { case IMM: next.operand = next_byte(); next.args[0] = next.operand; next.arglen = 1; break; case ZP: next.addr = next_byte(); next.operand = get_mem(next.addr); next.args[0] = next.addr; next.arglen = 1; break; case ZP_ST: next.addr = next_byte(); next.args[0] = next.addr; next.arglen = 1; break; case ABS: next.addr = next_word(); next.operand = get_mem(next.addr); next.args[0] = next.addr & 0xff; next.args[1] = (next.addr & 0xff00) >> 8; next.arglen = 2; break; case ABS_ST: next.addr = next_word(); next.args[0] = next.addr & 0xff; next.args[1] = (next.addr & 0xff00) >> 8; next.arglen = 2; break; case ABSI: next.i_addr = next_word(); next.addr = get_mem(next.i_addr) + (get_mem(((next.i_addr+1) & 0xff) | (next.i_addr & 0xff00)) << 8); next.args[0] = next.i_addr & 0xff; next.args[1] = (next.i_addr & 0xff00) >> 8; next.arglen = 2; break; case ABSY: next.i_addr = next_word(); next.addr = (next.i_addr + y) & 0xffff; next.operand = get_mem((next.i_addr&0xff00)|(next.addr&0xff)); if(!next.op.store) { if((next.i_addr & 0xff00) != (next.addr & 0xff00) || next.op.extra_page_cross == 0) { next.operand = get_mem(next.addr); extra_cycles += next.op.extra_page_cross; } } next.args[0] = next.i_addr & 0xff; next.args[1] = (next.i_addr & 0xff00) >> 8; next.arglen = 2; break; case ABSX: next.i_addr = next_word(); next.addr = (next.i_addr + x) & 0xffff; next.operand = get_mem((next.i_addr&0xff00)|(next.addr&0xff)); if(!next.op.store) { if((next.i_addr & 0xff00) != (next.addr & 0xff00) || next.op.extra_page_cross == 0) { next.operand = get_mem(next.addr); extra_cycles += next.op.extra_page_cross; } } next.args[0] = next.i_addr & 0xff; next.args[1] = (next.i_addr & 0xff00) >> 8; next.arglen = 2; break; case REL: off = next_byte(); next.addr = off + pc; next.args[0] = off; next.arglen = 1; break; case IXID: next.args[0] = next_byte(); get_mem(next.args[0]); //dummy next.i_addr = (next.args[0] + x) & 0xff; next.addr = (get_mem(next.i_addr) + (get_mem((next.i_addr+1) & 0xff) << 8)); if(!next.op.store) { next.operand = get_mem(next.addr); } next.arglen = 1; break; case IDIX: next.i_addr = next_byte(); next.addr = (get_mem(next.i_addr) + (get_mem((next.i_addr+1)&0xff)<<8)) + y; next.addr &= 0xffff; //fetch from same page next.operand = get_mem(((next.addr-y)&0xff00)|(next.addr&0xff)); if(((next.addr & 0xff00) != ((next.addr - y) & 0xff00) || next.op.extra_page_cross == 0) && !next.op.store) { //fetch correct address next.operand = get_mem(next.addr); extra_cycles += next.op.extra_page_cross; } next.args[0] = next.i_addr; next.arglen = 1; break; case ZPX: next.i_addr = next_byte(); get_mem(next.i_addr); //dummy next.addr = (next.i_addr + x) & 0xff; if(!next.op.store) { next.operand = get_mem(next.addr); } next.args[0] = next.i_addr; next.arglen = 1; break; case ZPY: next.i_addr = next_byte(); get_mem(next.i_addr); //dummy next.addr = (next.i_addr + y) & 0xff; if(!next.op.store) { next.operand = get_mem(next.addr); } next.args[0] = next.i_addr; next.arglen = 1; break; case IMP: case A: get_mem(pc+1); //dummy read break; default: next.arglen = 0; break; } next.extra_cycles = extra_cycles; return next; }
int main(int argc, char *argv[]) { const struct parsed_proto *pp; FILE *fout, *fhdr; char basename[256] = { 0, }; char line[256]; char fmt[256]; char word[256]; int noname = 0; const char *p2; char *p; int arg; int ret, ord; int l; for (arg = 1; arg < argc; arg++) { if (IS(argv[arg], "-n")) noname = 1; else if (IS(argv[arg], "-b") && arg < argc - 1) snprintf(basename, sizeof(basename), "%s", argv[++arg]); else break; } if (argc != arg + 2) { printf("usage:\n%s [-n] [-b <basename>] <.h> <.def>\n", argv[0]); return 1; } hdrfn = argv[arg++]; fhdr = fopen(hdrfn, "r"); my_assert_not(fhdr, NULL); fout = fopen(argv[arg++], "w"); my_assert_not(fout, NULL); if (basename[0] == 0) { p = strrchr(hdrfn, '.'); my_assert_not(p, NULL); p2 = strrchr(hdrfn, '/'); if (p2++ == NULL) p2 = hdrfn; l = p - p2; my_assert((unsigned int)l < 256, 1); memcpy(basename, p2, l); basename[l] = 0; } snprintf(fmt, sizeof(fmt), "%s_%%d", basename); fprintf(fout, "LIBRARY %s\n", basename); fprintf(fout, "EXPORTS\n"); while (fgets(line, sizeof(line), fhdr)) { p = sskip(line); if (*p == 0) continue; if (IS_START(p, "//")) continue; ret = 0; while (p != NULL && *p != 0) { p = next_word(word, sizeof(word), p); ret = sscanf(word, fmt, &ord); if (ret == 1) break; } if (ret != 1) { printf("scan for '%s' failed for '%s'\n", fmt, line); return 1; } snprintf(word, sizeof(word), fmt, ord); pp = proto_parse(fhdr, word, 0); if (pp == NULL) return 1; fputc(' ', fout); fputc(pp->is_fastcall ? '@' : ' ', fout); fprintf(fout, "%s", word); if (pp->is_stdcall) fprintf(fout, "@%-2d", pp->argc * 4); else fprintf(fout, " "); fprintf(fout, " @%d", ord); if (noname) fprintf(fout, " NONAME"); fprintf(fout, "\n"); } fclose(fhdr); fclose(fout); return 0; }
void config_vifs_from_file(void) { FILE *fp; char linebuf[LINE_BUFSIZ]; char *w, *s; int option; uint8_t *data_ptr; int error_flag; error_flag = FALSE; lineno = 0; /* TODO: HARDCODING!!! */ cand_rp_adv_message.buffer = calloc(1, 4 + sizeof(pim_encod_uni_addr_t) + 255 * sizeof(pim_encod_grp_addr_t)); if (!cand_rp_adv_message.buffer) logit(LOG_ERR, errno, "Ran out of memory in config_vifs_from_file()"); cand_rp_adv_message.prefix_cnt_ptr = cand_rp_adv_message.buffer; /* By default, if no group-prefix configured, then prefix_cnt == 0 * implies group-prefix = 224.0.0.0 and masklen = 4. */ *cand_rp_adv_message.prefix_cnt_ptr = 0; cand_rp_adv_message.insert_data_ptr = cand_rp_adv_message.buffer; /* TODO: XXX: HARDCODING!!! */ cand_rp_adv_message.insert_data_ptr += (4 + 6); fp = fopen(config_file, "r"); if (!fp) { logit(LOG_WARNING, errno, "Cannot open configuration file %s", config_file); fallback_config(); goto nofile; } while (fgets(linebuf, sizeof(linebuf), fp)) { if (strlen(linebuf) >= (LINE_BUFSIZ - 1)) { WARN("Line length must be shorter than %d", LINE_BUFSIZ); error_flag = TRUE; } lineno++; s = linebuf; w = next_word(&s); option = parse_option(w); switch (option) { case CONF_EMPTY: continue; break; case CONF_PHYINT: parse_phyint(s); break; case CONF_CANDIDATE_RP: parse_rp_candidate(s); break; case CONF_RP_ADDRESS: parse_rp_address(s); break; case CONF_GROUP_PREFIX: parse_group_prefix(s); break; case CONF_BOOTSTRAP_RP: parse_bsr_candidate(s); break; case CONF_COMPAT_THRESHOLD: parse_compat_threshold(s); break; case CONF_SPT_THRESHOLD: parse_spt_threshold(s); break; case CONF_DEFAULT_ROUTE_METRIC: parse_default_route_metric(s); break; case CONF_DEFAULT_ROUTE_DISTANCE: parse_default_route_distance(s); break; case CONF_IGMP_QUERY_INTERVAL: parse_igmp_query_interval(s); break; case CONF_IGMP_QUERIER_TIMEOUT: parse_igmp_querier_timeout(s); break; case CONF_HELLO_INTERVAL: parse_hello_interval(s); break; default: logit(LOG_WARNING, 0, "%s:%u - Unknown command '%s'", config_file, lineno, w); error_flag = TRUE; } } fclose(fp); nofile: /* A static RP address is needed for SSM. We use a link-local * address. It is not required to be configured on any interface. */ strncpy(linebuf, "169.254.0.1 232.0.0.0/8\n", sizeof(linebuf)); s = linebuf; parse_rp_address(s); if (error_flag) logit(LOG_ERR, 0, "%s:%u - Syntax error", config_file, lineno); cand_rp_adv_message.message_size = cand_rp_adv_message.insert_data_ptr - cand_rp_adv_message.buffer; if (cand_rp_flag != FALSE) { /* Prepare the RP info */ my_cand_rp_holdtime = 2.5 * my_cand_rp_adv_period; /* TODO: HARDCODING! */ data_ptr = cand_rp_adv_message.buffer + 1; PUT_BYTE(my_cand_rp_priority, data_ptr); PUT_HOSTSHORT(my_cand_rp_holdtime, data_ptr); PUT_EUADDR(my_cand_rp_address, data_ptr); } /* If no IGMP querier timeout was set, calculate from query interval */ if (!igmp_querier_timeout) igmp_querier_timeout = QUERIER_TIMEOUT(igmp_query_interval); IF_DEBUG(DEBUG_IGMP) { logit(LOG_INFO, 0, "IGMP query interval : %u sec", igmp_query_interval); logit(LOG_INFO, 0, "IGMP querier timeout : %u sec", igmp_querier_timeout); } }
void send_pause(void) { /* load pwm timing, retransmit and retransmit timeout */ struct params_t params; params.raw = next_word(); uint16_t retransmit_delay = next_word(); /* load header */ uint16_t header_on = next_word(); uint16_t header_len = next_word(); /* load timing values */ uint16_t on = next_word(); uint16_t one = next_word(); uint16_t zero = next_word(); /* load data */ struct params_t params2; params2.raw = next_word(); /* remember positing in timing table */ uint16_t pos = 0; /* calculate retransmit timeout */ uint16_t retransmit; uint16_t *dataptr; for (uint8_t i = 0; i <= params.repeat; i++) { dataptr = (uint16_t *)current_code; retransmit = retransmit_delay; if (header_on != 0) { if (i == 0 || (params2.flags & REPEAT_HEADER)) { /* add header */ timing[pos] = header_on; timing[pos+1] = header_len; pos += 2; } if (i == 0 || (params2.flags & REPEAT_SUBTRACT_HEADER)) { /* calculate retransmit timeout */ retransmit -= header_len; } } uint16_t data = 0; /* insert data into timing array */ for (uint8_t b = 0; b < params2.bits; b++) { if (b % 16 == 0) { /* load data */ data = pgm_read_word(dataptr++); } /* on timing */ timing[pos++] = on; if (data & 1) { /* one */ timing[pos++] = one; /* subtract cycle length from retransmit */ retransmit -= one; } else { /* zero */ timing[pos++] = zero; /* subtract cycle length from retransmit */ retransmit -= zero; } data >>= 1; } /* insert last on pulse and retransmit delay */ timing[pos++] = on; timing[pos++] = retransmit+on; /* reset retransmit delay */ retransmit = retransmit_delay; } /* remember positing in code table */ current_code = dataptr; /* mark end of code */ timing[pos-1] = 0; /* set loaded pwm value */ pwm_set(params.pwm); }
static int parse_entry(FILE *fp, pf_spec *spec, char *store) { int eoe = 0; int eof = 0; int i; char *valp = NULL; int type = 0; int side = 0; /* 0 == left, 1 == right */ int done_rhs = 0; while (!eoe) { switch(next_word(fp)) { case TOK_END: eof = 1; case TOK_NL: eoe = 1; break; case TOK_EQ: side = 1; break; case TOK_SEPARATOR: side = 0; valp = NULL; done_rhs = 0; break; case TOK_ID: /* printf("\tident%d=\"%s\"\n", side, word); */ if (side == 0) { for (i = 0; spec[i].name; i++) { if (word[0] == spec[i].name[0] && strcmp(word, spec[i].name) == 0) { valp = &store[spec[i].offset]; type = spec[i].type; break; } } if (!spec[i].name) { char buf[MAXWORD]; sprintf(buf, "Warning - unknown identifier \"%s\"\n",word); parse_error(buf); } } else { /* side == right */ if (done_rhs) { parse_error("Syntax error"); break; } done_rhs = 1; if (valp) { switch(type) { case PF_STR: *((char **)valp) = strdup(word); break; case PF_INT: *((int *)valp) = atoi(word); break; default: { char buf[MAXWORD]; sprintf(buf, "Unknown type %d\n", type); parse_error(buf); } break; } } } break; } } return eof; }
/* * main function */ int main(void) { /* hardware on port D: * PD0: RX * PD1: TX * PD2: D+ * PD3: INT1/IR_IN * PD4: D- * PD5: IR_OUT * PD7: DF_CS */ DDRD = _BV(PD5) | _BV(PD7); PORTD = _BV(PD7); /* configure pin change interrupt for button 1 and 2, * for waking up from sleep mode... */ PCMSK1 = _BV(PCINT12) | _BV(PCINT13); /* hardware on port B: * PB0: PUD * PB1: /LED2 * PB2: /LED1 * PB3: MOSI * PB4: MISO * PB5: SCK */ DDRB = _BV(PB0) | _BV(PB1) | _BV(PB2) | _BV(PB3) | _BV(PB5); PORTB = _BV(PB1) | _BV(PB2); /* hardware on port C: * PC0: IR_IN2 * PC1: POWER * PC2: BTN4 * PC3: BTN3 * PC4: BTN2 * PC5: BTN1 */ DDRC = 0; PORTC = _BV(PC2) | _BV(PC3) | _BV(PC4) | _BV(PC5); /* init analog to digital converter, * convert on PC1(ADC1) * prescaler 64 => 250khz frequency */ ADMUX = _BV(REFS0) | _BV(ADLAR) | _BV(ADIF) | _BV(MUX0); ADCSRA = _BV(ADEN) | _BV(ADPS1); /* init spi */ SPCR = _BV(SPE) | _BV(MSTR); SPSR |= _BV(SPI2X); /* init timer2 for key debouncing, CTC, prescaler 1024, * timeout after 10ms */ TCCR2A = _BV(WGM21); TCCR2B = _BV(CS22) | _BV(CS21) | _BV(CS20); TIMSK2 = _BV(OCIE2A); OCR2A = F_CPU/100/1024; /* configure sleep mode */ set_sleep_mode(SLEEP_MODE_STANDBY); #ifdef DEBUG_UART /* uart */ UBRR0H = 0; UBRR0L = 8; UCSR0C = _BV(UCSZ00) | _BV(UCSZ01); UCSR0B = _BV(TXEN0); UDR0 = 'b'; while(!(UCSR0A & _BV(UDRE0))); #endif /* read dataflash status */ df_select(); SPDR = 0xd7; while(!(SPSR & _BV(SPIF))); SPDR = 0; while(!(SPSR & _BV(SPIF))); uint8_t df_status = SPDR; /* read battery voltage */ uint8_t bat = battery_voltage(); #ifdef DEBUG_UART UDR0 = 'D'; while(!(UCSR0A & _BV(UDRE0))); UDR0 = df_status; while(!(UCSR0A & _BV(UDRE0))); UDR0 = 'V'; while(!(UCSR0A & _BV(UDRE0))); UDR0 = bat; while(!(UCSR0A & _BV(UDRE0))); #endif df_release(); sei(); #ifdef BLINK_START /* blink start sequence */ blink(BLINK_START); #endif if (df_status == DF_STATUS_IDLE) blink(BLINK_DF_SEEN); else blink(BLINK_DF_ERROR); if (bat >= MIN_BAT_VOLTAGE) blink(BLINK_BAT_OK); else blink(BLINK_BAT_FAIL); uint8_t pos; uint8_t button_sum = 0; while (1) { /* if a button has been pressed and we're idle, wait some more time to determine mode */ if (state == IDLE && (button_press[0] > 0 || button_press[1] > 0)) { /* wait one second via timer1, using prescaler 1024 */ TIFR1 = TIFR1; OCR1A = F_CPU/1024/2; TCCR1B = _BV(CS12) | _BV(CS10); button_sum = 0; state = READ_COMMAND; } /* if we're waiting for a command, and some button has been pressed, reset timeout */ uint8_t sum = button_press[0] + button_press[1]; if (state == READ_COMMAND && sum != button_sum) { TCNT1 = 0; button_sum = sum; } /* if we're waiting for a command, check if the timer expired */ if (state == READ_COMMAND && (TIFR1 & _BV(OCF1A))) { /* disable timer1 */ TCCR1B = 0; TCNT1 = 0; /* parse button presses */ if (button_press[0] == 1 && button_press[1] == 0) { if (battery_voltage() < MIN_BAT_VOLTAGE && !options.ignore_bat) { blink(BLINK_VOLTAGE); } else { /* start transmitting */ pos = 0; current_code = &codes[0]; single_code = &codes[0]; state = LOAD_CODE; #ifdef BLINK_MODE1 /* blink mode 1 */ blink(BLINK_MODE1); #endif if (!options.silent) PORTB &= ~_BV(PB1); } } else if (button_press[0] == 0) { if (button_press[1] == 1) { options.silent = !options.silent; /* blink for silent toggle */ if (options.silent) blink(BLINK_SILENT); else blink(BLINK_NONSILENT); } else if (button_press[1] == 2) { options.single_step = !options.single_step; /* blink for single step toggle */ if (options.single_step) blink(BLINK_STEP); else blink(BLINK_NOSTEP); } else if (button_press[1] == 3) { options.ignore_bat = !options.ignore_bat; /* blink for ignore battery toggle */ if (options.ignore_bat) blink(BLINK_BAT_IGNORE); else blink(BLINK_BAT_HONOR); } else blink(BLINK_INVALID); } else blink(BLINK_INVALID); /* reset state, if not yet done */ if (state == READ_COMMAND) state = IDLE; /* reset buttons */ button_press[0] = 0; button_press[1] = 0; button_press[2] = 0; } if (state == LOAD_CODE) { /* if we're in single-step mode, wait for a keypress */ if (options.single_step) { while (button_press[0] == 0 && button_press[1] == 0 && button_press[2] == 0); /* send next code if button1 has been pressed, stop if button2 * has been pressed, resend code if button3 has been pressed */ if (button_press[2]) { current_code = single_code; button_press[1] = 0; } else if (!button_press[1]) { button_press[1] = 0; } /* reset buttons */ button_press[0] = 0; button_press[2] = 0; } /* stop sending if button2 has been pressed */ if (button_press[1] > 0) { button_press[0] = 0; button_press[1] = 0; PORTB |= _BV(PB1); #ifdef BLINK_MODE1_END blink(BLINK_MODE1_END); #endif state = IDLE; } else { #ifdef DEBUG_UART UDR0 = 'L'; while(!(UCSR0A & _BV(UDRE0))); #endif /* if we're in single step mode, remember code address for single-retransmit */ single_code = current_code; /* load next generating function and generate timing table */ void (*func)(void); uint16_t ptr = next_word(); func = (void *)ptr; if (func != NULL) { #ifdef DEBUG_UART UDR0 = 'p'; while(!(UCSR0A & _BV(UDRE0))); UDR0 = pos++; while(!(UCSR0A & _BV(UDRE0))); #endif /* call generating function */ func(); #ifdef DEBUG_UART UDR0 = 'f'; while(!(UCSR0A & _BV(UDRE0))); #endif /* reset timing pointer */ current_timing = &timing[0]; /* update state */ state = TRANSMIT_CODE; /* init timer1 for initial delay before sending: * prescaler 256, CTC mode (TOP == OCR1A) * enable compare interrupts */ OCR1A = DELAY_NEXT_CODE; OCR1B = 0xffff; TIFR1 = TIFR1; TIMSK1 = _BV(OCIE1A) | _BV(OCIE1B); TCCR1B = _BV(CS12) | _BV(WGM12); } else { #ifdef DEBUG_UART UDR0 = 'E'; while(!(UCSR0A & _BV(UDRE0))); #endif PORTB |= _BV(PB1); #ifdef BLINK_MODE1_END blink(BLINK_MODE1_END); #endif state = IDLE; } sleep_counter = 0; } } if (state == SLEEP) { /* enable pin change interrupt for button 1 and 2, * for waking up from sleep mode... */ PCICR = _BV(PCIE1); /* set and enter sleep mode */ sleep_mode(); sleep_counter = SLEEP_COUNTER_VALUE; state = IDLE; /* disable pin change interrupt for button 1 and 2, * for waking up from sleep mode... */ PCICR = 0; } } }
void config_vifs_from_file(void) { FILE *f; char linebuf[LINE_BUFSIZ]; char *w, *s; struct ifconf ifc; int option; char ifbuf[BUFSIZ]; u_int8 *data_ptr; int error_flag; error_flag = FALSE; lineno = 0; if ((f = fopen(config_file, "r")) == NULL) { if (errno != ENOENT) logit(LOG_WARNING, errno, "Cannot open %s", config_file); return; } /* TODO: HARDCODING!!! */ cand_rp_adv_message.buffer = calloc(1, 4 + sizeof(pim_encod_uni_addr_t) + 255 * sizeof(pim_encod_grp_addr_t)); if (!cand_rp_adv_message.buffer) logit(LOG_ERR, errno, "Ran out of memory in config_vifs_from_file()"); cand_rp_adv_message.prefix_cnt_ptr = cand_rp_adv_message.buffer; /* By default, if no group_prefix configured, then prefix_cnt == 0 * implies group_prefix = 224.0.0.0 and masklen = 4. */ *cand_rp_adv_message.prefix_cnt_ptr = 0; cand_rp_adv_message.insert_data_ptr = cand_rp_adv_message.buffer; /* TODO: XXX: HARDCODING!!! */ cand_rp_adv_message.insert_data_ptr += (4 + 6); ifc.ifc_buf = ifbuf; ifc.ifc_len = sizeof(ifbuf); if (ioctl(udp_socket, SIOCGIFCONF, (char *)&ifc) < 0) logit(LOG_ERR, errno, "Failed querying kernel network interfaces"); while (fgets(linebuf, sizeof(linebuf), f) != NULL) { if (strlen(linebuf) >= (LINE_BUFSIZ - 1)) { WARN("Line length must be shorter than %d", LINE_BUFSIZ); error_flag = TRUE; } lineno++; s = linebuf; w = next_word(&s); option = parse_option(w); switch (option) { case CONF_EMPTY: continue; break; case CONF_PHYINT: parse_phyint(s); break; case CONF_CANDIDATE_RP: parse_candidateRP(s); break; case CONF_RP_ADDRESS: parse_rp_address(s); break; case CONF_GROUP_PREFIX: parse_group_prefix(s); break; case CONF_BOOTSTRAP_RP: parseBSR(s); break; case CONF_COMPAT_THRESHOLD: parse_compat_threshold(s); break; case CONF_SPT_THRESHOLD: parse_spt_threshold(s); break; case CONF_DEFAULT_SOURCE_METRIC: parse_default_source_metric(s); break; case CONF_DEFAULT_SOURCE_PREFERENCE: parse_default_source_preference(s); break; case CONF_DEFAULT_IGMP_QUERY_INTERVAL: parse_default_igmp_query_interval(s); break; case CONF_DEFAULT_IGMP_QUERIER_TIMEOUT: parse_default_igmp_querier_timeout(s); break; default: logit(LOG_WARNING, 0, "%s:%u - Unknown command '%s'", config_file, lineno, w); error_flag = TRUE; } } if (error_flag) logit(LOG_ERR, 0, "%s:%u - Syntax error", config_file, lineno); cand_rp_adv_message.message_size = cand_rp_adv_message.insert_data_ptr - cand_rp_adv_message.buffer; if (cand_rp_flag != FALSE) { /* Prepare the RP info */ my_cand_rp_holdtime = 2.5 * my_cand_rp_adv_period; /* TODO: HARDCODING! */ data_ptr = cand_rp_adv_message.buffer + 1; PUT_BYTE(my_cand_rp_priority, data_ptr); PUT_HOSTSHORT(my_cand_rp_holdtime, data_ptr); PUT_EUADDR(my_cand_rp_address, data_ptr); } /* If no IGMP querier timeout was set, calculate from query interval */ if (!default_igmp_querier_timeout) default_igmp_querier_timeout = QUERIER_TIMEOUT(default_igmp_query_interval); IF_DEBUG(DEBUG_IGMP) { logit(LOG_INFO, 0, "IGMP query interval : %u sec", default_igmp_query_interval); logit(LOG_INFO, 0, "IGMP querier timeout : %u sec", default_igmp_querier_timeout); } fclose(f); }
int input_line(char *string, int length) { char curline[2000]; /* edit buffer */ int noline; unsigned c; int more; int i; if (first) { poolinit(); /* build line pool */ first = 0; } noline = 1; /* no line fetched yet */ for (cl=cp=0; cl<length && cl<(int)sizeof(curline); ) { if (usrbrk()) { clrbrk(); break; } switch (c=input_char()) { case F_RETURN: /* CR */ t_sendl("\r\n", 2); /* yes, print it and */ goto done; /* get out */ case F_CLRSCRN: /* clear screen */ asclrs(); t_sendl(curline, cl); ascurs(0, cp); break; case F_CSRUP: if (noline) { /* no line fetched yet */ getnext(); /* getnext so getprev gets current */ noline = 0; /* we now have line */ } bstrncpy(curline, getprev(), sizeof(curline)); prtcur(curline); break; case F_CSRDWN: noline = 0; /* mark line fetched */ bstrncpy(curline, getnext(), sizeof(curline)); prtcur(curline); break; case F_INSCHR: insert_space(curline, sizeof(curline)); break; case F_DELCHR: delchr(1, curline, sizeof(curline)); /* delete one character */ break; case F_CSRLFT: /* Backspace */ backup(curline); break; case F_CSRRGT: forward(curline, sizeof(curline)); break; case F_ERSCHR: /* Rubout */ backup(curline); delchr(1, curline, sizeof(curline)); if (cp == 0) { t_char(' '); t_char(0x8); } break; case F_DELEOL: t_clrline(0, t_width); if (cl > cp) cl = cp; break; case F_NXTWRD: i = next_word(curline); while (i--) { forward(curline, sizeof(curline)); } break; case F_PRVWRD: i = prev_word(curline); while (i--) { backup(curline); } break; case F_DELWRD: delchr(next_word(curline), curline, sizeof(curline)); /* delete word */ break; case F_NXTMCH: /* Ctl-X */ if (cl==0) { *string = EOS; /* terminate string */ return(c); /* give it to him */ } /* Note fall through */ case F_DELLIN: case F_ERSLIN: while (cp > 0) { backup(curline); /* backup to beginning of line */ } t_clrline(0, t_width); /* erase line */ cp = 0; cl = 0; /* reset cursor counter */ t_char(' '); t_char(0x8); break; case F_SOL: while (cp > 0) { backup(curline); } break; case F_EOL: while (cp < cl) { forward(curline, sizeof(curline)); } while (cp > cl) { backup(curline); } break; case F_TINS: /* toggle insert mode */ mode_insert = !mode_insert; /* flip bit */ break; default: if (c > 255) { /* function key hit */ if (cl==0) { /* if first character then */ *string = EOS; /* terminate string */ return c; /* return it */ } t_honk_horn(); /* complain */ } else { if ((c & 0xC0) == 0xC0) { if ((c & 0xFC) == 0xFC) { more = 5; } else if ((c & 0xF8) == 0xF8) { more = 4; } else if ((c & 0xF0) == 0xF0) { more = 3; } else if ((c & 0xE0) == 0xE0) { more = 2; } else { more = 1; } } else { more = 0; } if (mode_insert) { insert_space(curline, sizeof(curline)); } curline[cp++] = c; /* store character in line being built */ t_char(c); /* echo character to terminal */ while (more--) { c= input_char(); insert_hole(curline, sizeof(curline)); curline[cp++] = c; /* store character in line being built */ t_char(c); /* echo character to terminal */ } if (cp > cl) { cl = cp; /* keep current length */ curline[cp] = 0; } } break; } /* end switch */ } /* If we fall through here rather than goto done, the line is too long simply return what we have now. */ done: curline[cl++] = EOS; /* terminate */ bstrncpy(string,curline,length); /* return line to caller */ /* Save non-blank lines. Note, put line zaps curline */ if (curline[0] != EOS) { putline(curline,cl); /* save line for posterity */ } return 0; /* give it to him/her */ }
/** * parse_phyint - Parse physical interface configuration, if any. * @s: String token * * Syntax: * phyint <local-addr | ifname> [disable|enable] * [threshold <t>] [preference <p>] [metric <m>] * [altnet <net-addr>/<masklen>] * [altnet <net-addr> masklen <masklen>] * [scoped <net-addr>/<masklen>] * [scoped <net-addr> masklen <masklen>] * * Returns: * %TRUE if the parsing was successful, o.w. %FALSE */ static int parse_phyint(char *s) { char *w, c; uint32_t local, altnet_addr, scoped_addr; vifi_t vifi; struct uvif *v; u_int n, altnet_masklen = 0, scoped_masklen = 0; struct phaddr *ph; struct vif_acl *v_acl; if (EQUAL((w = next_word(&s)), "")) { WARN("Missing phyint address"); return FALSE; } local = ifname2addr(w); if (!local) { local = inet_parse(w, 4); if (!inet_valid_host(local)) { WARN("Invalid phyint address '%s'", w); return FALSE; } } for (vifi = 0, v = uvifs; vifi < numvifs; ++vifi, ++v) { if (vifi == numvifs) { WARN("phyint %s is not a valid interface", inet_fmt(local, s1, sizeof(s1))); return FALSE; } if (local != v->uv_lcl_addr) continue; while (!EQUAL((w = next_word(&s)), "")) { if (EQUAL(w, "disable")) { v->uv_flags |= VIFF_DISABLED; continue; } if (EQUAL(w, "enable")) { v->uv_flags &= ~VIFF_DISABLED; continue; } if (EQUAL(w, "altnet")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing ALTNET for phyint %s", inet_fmt(local, s1, sizeof(s1))); continue; } parse_prefix_len (w, &altnet_masklen); altnet_addr = ifname2addr(w); if (!altnet_addr) { altnet_addr = inet_parse(w, 4); if (!inet_valid_host(altnet_addr)) { WARN("Invalid altnet address '%s'", w); return FALSE; } } if (EQUAL((w = next_word(&s)), "masklen")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing ALTNET masklen for phyint %s", inet_fmt(local, s1, sizeof (s1))); continue; } if (!sscanf(w, "%u", &altnet_masklen)) { WARN("Invalid altnet masklen '%s' for phyint %s", w, inet_fmt(local, s1, sizeof(s1))); continue; } } ph = (struct phaddr *)calloc(1, sizeof(struct phaddr)); if (!ph) return FALSE; if (altnet_masklen) { VAL_TO_MASK(ph->pa_subnetmask, altnet_masklen); } else { ph->pa_subnetmask = v->uv_subnetmask; } ph->pa_subnet = altnet_addr & ph->pa_subnetmask; ph->pa_subnetbcast = ph->pa_subnet | ~ph->pa_subnetmask; if (altnet_addr & ~ph->pa_subnetmask) WARN("Extra subnet %s/%d has host bits set", inet_fmt(altnet_addr, s1, sizeof(s1)), altnet_masklen); ph->pa_next = v->uv_addrs; v->uv_addrs = ph; logit(LOG_DEBUG, 0, "ALTNET: %s/%d", inet_fmt(altnet_addr, s1, sizeof(s1)), altnet_masklen); } /* altnet */ /* scoped mcast groups/masklen */ if (EQUAL(w, "scoped")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing SCOPED for phyint %s", inet_fmt(local, s1, sizeof(s1))); continue; } parse_prefix_len (w, &scoped_masklen); scoped_addr = ifname2addr(w); if (!scoped_addr) { scoped_addr = inet_parse(w, 4); if (!IN_MULTICAST(ntohl(scoped_addr))) { WARN("Invalid scoped address '%s'", w); return FALSE; } } if (EQUAL((w = next_word(&s)), "masklen")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing SCOPED masklen for phyint %s", inet_fmt(local, s1, sizeof(s1))); continue; } if (sscanf(w, "%u", &scoped_masklen) != 1) { WARN("Invalid scoped masklen '%s' for phyint %s", w, inet_fmt(local, s1, sizeof(s1))); continue; } } v_acl = (struct vif_acl *)calloc(1, sizeof(struct vif_acl)); if (!v_acl) return FALSE; VAL_TO_MASK(v_acl->acl_mask, scoped_masklen); v_acl->acl_addr = scoped_addr & v_acl->acl_mask; if (scoped_addr & ~v_acl->acl_mask) WARN("Boundary spec %s/%d has host bits set", inet_fmt(scoped_addr, s1, sizeof(s1)),scoped_masklen); v_acl->acl_next = v->uv_acl; v->uv_acl = v_acl; logit(LOG_DEBUG, 0, "SCOPED %s/%x", inet_fmt(v_acl->acl_addr, s1, sizeof(s1)), v_acl->acl_mask); } /* scoped */ if (EQUAL(w, "threshold")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing threshold for phyint %s", inet_fmt(local, s1, sizeof(s1))); continue; } if (sscanf(w, "%u%c", &n, &c) != 1 || n < 1 || n > 255 ) { WARN("Invalid threshold '%s' for phyint %s", w, inet_fmt(local, s1, sizeof(s1))); continue; } v->uv_threshold = n; continue; } /* threshold */ if (EQUAL(w, "preference")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing preference for phyint %s", inet_fmt(local, s1, sizeof(s1))); continue; } if (sscanf(w, "%u%c", &n, &c) != 1 || n < 1 || n > 255 ) { WARN("Invalid preference '%s' for phyint %s", w, inet_fmt(local, s1, sizeof(s1))); continue; } IF_DEBUG(DEBUG_ASSERT) { logit(LOG_DEBUG, 0, "Config setting default local preference on %s to %d", inet_fmt(local, s1, sizeof(s1)), n); } v->uv_local_pref = n; continue; } if (EQUAL(w, "metric")) { if (EQUAL((w = next_word(&s)), "")) { WARN("Missing metric for phyint %s", inet_fmt(local, s1, sizeof(s1))); continue; } if (sscanf(w, "%u%c", &n, &c) != 1 || n < 1 || n > 1024 ) { WARN("Invalid metric '%s' for phyint %s", w, inet_fmt(local, s1, sizeof(s1))); continue; } IF_DEBUG(DEBUG_ASSERT) { logit(LOG_DEBUG, 0, "Setting default local metric on %s to %d", inet_fmt(local, s1, sizeof(s1)), n); } v->uv_local_metric = n; continue; } } /* if not empty */ break; } return TRUE; }
static int ui_input_key(struct input *input) { switch (ui.key) { case KEY_LEFT: if (ui.mod == GLFW_MOD_CONTROL + GLFW_MOD_SHIFT) { input->q = prev_word(input->q, input->text); } else if (ui.mod == GLFW_MOD_CONTROL) { if (input->p != input->q) input->p = input->q = input->p < input->q ? input->p : input->q; else input->p = input->q = prev_word(input->q, input->text); } else if (ui.mod == GLFW_MOD_SHIFT) { if (input->q > input->text) input->q = prev_char(input->q, input->text); } else if (ui.mod == 0) { if (input->p != input->q) input->p = input->q = input->p < input->q ? input->p : input->q; else if (input->q > input->text) input->p = input->q = prev_char(input->q, input->text); } break; case KEY_RIGHT: if (ui.mod == GLFW_MOD_CONTROL + GLFW_MOD_SHIFT) { input->q = next_word(input->q, input->end); } else if (ui.mod == GLFW_MOD_CONTROL) { if (input->p != input->q) input->p = input->q = input->p > input->q ? input->p : input->q; else input->p = input->q = next_word(input->q, input->end); } else if (ui.mod == GLFW_MOD_SHIFT) { if (input->q < input->end) input->q = next_char(input->q); } else if (ui.mod == 0) { if (input->p != input->q) input->p = input->q = input->p > input->q ? input->p : input->q; else if (input->q < input->end) input->p = input->q = next_char(input->q); } break; case KEY_UP: case KEY_HOME: if (ui.mod == GLFW_MOD_CONTROL + GLFW_MOD_SHIFT) { input->q = input->text; } else if (ui.mod == GLFW_MOD_CONTROL) { input->p = input->q = input->text; } else if (ui.mod == GLFW_MOD_SHIFT) { input->q = input->text; } else if (ui.mod == 0) { input->p = input->q = input->text; } break; case KEY_DOWN: case KEY_END: if (ui.mod == GLFW_MOD_CONTROL + GLFW_MOD_SHIFT) { input->q = input->end; } else if (ui.mod == GLFW_MOD_CONTROL) { input->p = input->q = input->end; } else if (ui.mod == GLFW_MOD_SHIFT) { input->q = input->end; } else if (ui.mod == 0) { input->p = input->q = input->end; } break; case KEY_DELETE: if (input->p != input->q) ui_input_delete_selection(input); else if (input->p < input->end) { char *np = next_char(input->p); memmove(input->p, np, input->end - np); input->end -= np - input->p; *input->end = 0; input->q = input->p; } break; case KEY_ESCAPE: return -1; case KEY_ENTER: return 1; case KEY_BACKSPACE: if (input->p != input->q) ui_input_delete_selection(input); else if (input->p > input->text) { char *pp = prev_char(input->p, input->text); memmove(pp, input->p, input->end - input->p); input->end -= input->p - pp; *input->end = 0; input->q = input->p = pp; } break; case KEY_CTL_A: input->p = input->q = input->text; break; case KEY_CTL_E: input->p = input->q = input->end; break; case KEY_CTL_W: if (input->p != input->q) ui_input_delete_selection(input); else { input->p = prev_word(input->p, input->text); ui_input_delete_selection(input); } break; case KEY_CTL_U: input->p = input->q = input->end = input->text; break; case KEY_CTL_C: case KEY_CTL_X: if (input->p != input->q) { char buf[sizeof input->text]; char *p = input->p < input->q ? input->p : input->q; char *q = input->p > input->q ? input->p : input->q; memmove(buf, p, q - p); buf[q-p] = 0; glfwSetClipboardString(window, buf); if (ui.key == KEY_CTL_X) ui_input_delete_selection(input); } break; case KEY_CTL_V: { const char *buf = glfwGetClipboardString(window); if (buf) ui_input_paste(input, buf, (int)strlen(buf)); } break; default: if (ui.key >= 32) { int cat = ucdn_get_general_category(ui.key); if (ui.key == ' ' || (cat >= UCDN_GENERAL_CATEGORY_LL && cat < UCDN_GENERAL_CATEGORY_ZL)) { char buf[8]; int n = fz_runetochar(buf, ui.key); ui_input_paste(input, buf, n); } } break; } return 0; }
bool VSFMergeTest::read_test_case(OsFile_Handle file, MergeTestCase * const test_case) { enum { BUFFER_SIZE = 256 }; char read_buffer[BUFFER_SIZE]; enum { FIRST_STATE = 0, LOCATION_COUNT = FIRST_STATE, TYPE, SRC_STATUS, DST_STATUS, SRC_WHERE, DST_WHERE, SRC_VALUE, DST_VALUE, LAST_STATE = DST_VALUE, STATE_COUNT }; int parse_state = FIRST_STATE; static const char * const end_of_suite_marker = "VSF_MERGE_SUITE_END"; static const char * const keywords[STATE_COUNT] = { "Location_count", "Types", "Source_status", "Target_status", "Source_where", "Target_where", "Source_value", "Target_value" }; const int TYPE_COUNT = 2; static const char * const type_names[TYPE_COUNT] = { "int", "long" }; static const BasicType types[TYPE_COUNT] = { T_INT, T_LONG }; static const char * const status_names[] = { "flushed", "cached", "changed" }; static const char * const where_names[] = { "nowhere", "immediate", "register" }; unsigned int location_count = 0; unsigned int index = 0; int value = 0; VSFMergeTest::initialize(); while (true) { const int bytes_read = CompilerTest::read_line(file, read_buffer, BUFFER_SIZE); if (bytes_read == 0) { // End-of-file. break; } if (bytes_read == BUFFER_SIZE) { tty->print_cr("Line too long"); break; } if (read_buffer[0] == '#') { continue; } char buffer[BUFFER_SIZE]; const char * p = read_buffer; // Read the first word to the buffer. if (jvm_sscanf(p, "%255s", buffer) != 1) { break; } // Check for the end of suite marker. if (parse_state == FIRST_STATE) { if (jvm_strcmp(buffer, end_of_suite_marker) == 0) { break; } } if (jvm_strcmp(buffer, keywords[parse_state]) != 0) { tty->print_cr("Unexpected keyword: %s", buffer); break; } switch (parse_state) { case LOCATION_COUNT: p = next_word(p); if (jvm_sscanf(p, "%d", &location_count) != 1) { tty->print_cr("Cannot read location count"); return false; } if (location_count > MAX_TEST_LOCATION_COUNT) { tty->print_cr("Too many locations %d > %d", location_count, MAX_TEST_LOCATION_COUNT); return false; } test_case->location_count = location_count; break; case TYPE: for (index = 0; index < location_count; index++) { p = next_word(p); if (jvm_sscanf(p, "%255s", buffer) != 1) { tty->print_cr("Cannot read type for location %d", index); return false; } value = CompilerTest::get_keyword_index(type_names, ARRAY_SIZE(type_names), buffer); if (value < 0 || value >= TYPE_COUNT) { tty->print_cr("Invalid type \"%s\" for location %d", buffer, index); return false; } BasicType type = types[value]; // For two-word types the type of the second location must be T_ILLEGAL. if (type == T_LONG) { if (index > 0 && test_case->types[index - 1] == T_LONG) { type = T_ILLEGAL; } } test_case->types[index] = type; } break; case SRC_STATUS: case DST_STATUS: { const bool is_source = parse_state == SRC_STATUS; const char * const frame_name = is_source ? "source" : "target"; for (index = 0; index < location_count; index++) { p = next_word(p); if (jvm_sscanf(p, "%255s", buffer) != 1) { tty->print_cr("Cannot read status for %s location %d", frame_name, index); return false; } value = CompilerTest::get_keyword_index(status_names, ARRAY_SIZE(status_names), buffer); if (value == -1) { tty->print_cr("Invalid status \"%s\" for %s location %d", buffer, frame_name, index); return false; } if (is_source) { test_case->src_status[index] = (RawLocation::Status)value; } else { test_case->dst_status[index] = (RawLocation::Status)value; } } break; } case SRC_WHERE: case DST_WHERE: { const bool is_source = parse_state == SRC_WHERE; const char * const frame_name = is_source ? "source" : "target"; for (index = 0; index < location_count; index++) { p = next_word(p); if (jvm_sscanf(p, "%255s", buffer) != 1) { tty->print_cr("Cannot read where for %s location %d", frame_name, index); return false; } value = CompilerTest::get_keyword_index(where_names, ARRAY_SIZE(where_names), buffer); if (value == -1) { tty->print_cr("Invalid where \"%s\" for %s location %d", buffer, frame_name, index); return false; } if (is_source) { test_case->src_where[index] = (Value::ValueLocation)value; } else { test_case->dst_where[index] = (Value::ValueLocation)value; } } break; } case SRC_VALUE: case DST_VALUE: { const bool is_source = parse_state == SRC_VALUE; const char * const frame_name = is_source ? "source" : "target"; for (index = 0; index < location_count; index++) { p = next_word(p); if (jvm_sscanf(p, "%d", &value) != 1) { tty->print_cr("Cannot read value for %s location %d", frame_name, index); return false; } const Value::ValueLocation where = is_source ? test_case->src_where[index] : test_case->dst_where[index]; int location_value = value; if (where == Value::T_REGISTER) { if (!is_valid_register(value)) { tty->print_cr("Invalid int register %d for %s location %d", value, frame_name, index); return false; } location_value = VSFMergeTest::available_int_register(value); } if (is_source) { test_case->src_value[index] = location_value; } else { test_case->dst_value[index] = location_value; } } break; } } if (parse_state == LAST_STATE) { return true; } parse_state++; } return false; }