void doLocalAnsiArgument(int type) { char symbol_name[NAMESIZE]; int identity, address, argptr, ptr; if (match("*")) { identity = POINTER; } else { if (type == STRUCT) { error("cannot pass struct"); return; } identity = VARIABLE; if (type == VOID) return; } if (symname(symbol_name)) { if (find_locale(symbol_name) > -1) { multidef(symbol_name); } else { argptr = add_local (symbol_name, identity, type, 0, AUTO); argstk = argstk + INTSIZE; ptr = local_table_index; while (ptr != NUMBER_OF_GLOBALS) { // modify stack offset as we push more params ptr = ptr - 1; address = symbol_table[ptr].offset; symbol_table[ptr].offset = address + INTSIZE; /* Struct etc FIXME */ } } } else { error("illegal argument name"); junk(); } if (match("[")) { while (inbyte() != ']') { if (endst()) { break; } } identity = POINTER; symbol_table[argptr].identity = identity; } }
TEST_F(SHAPE, Init) { ade::Shape scalar; std::vector<ade::DimT> slist = {12, 43, 56}; ade::Shape vec(slist); uint8_t n = slist.size(); std::vector<ade::DimT> longlist = {4, 23, 44, 52, 19, 92, 12, 2, 5}; ade::Shape lvec(longlist); std::vector<ade::DimT> zerolist = {43, 2, 5, 33, 0, 2, 7}; std::string fatalmsg = "cannot create shape with vector containing zero: " + fmts::to_string(zerolist.begin(), zerolist.end()); EXPECT_FATAL(ade::Shape junk(zerolist), fatalmsg.c_str()); for (uint8_t i = 0; i < ade::rank_cap; ++i) { EXPECT_EQ(1, scalar.at(i)); } for (uint8_t i = 0; i < n; ++i) { EXPECT_EQ(slist[i], vec.at(i)); } for (uint8_t i = n; i < ade::rank_cap; ++i) { EXPECT_EQ(1, vec.at(i)); } for (uint8_t i = 0; i < ade::rank_cap; ++i) { EXPECT_EQ(longlist[i], lvec.at(i)); } EXPECT_FATAL(scalar.at(ade::rank_cap), "cannot access out of bounds index 8"); EXPECT_FATAL(vec.at(ade::rank_cap), "cannot access out of bounds index 8"); }
/** \fn EndAndPaddTilleSizeMatchesAviListAvi \brief Warning we assume everything is even */ bool AviListAvi::EndAndPaddTilleSizeMatches(int sizeFilled) { uint64_t pos=Tell(); // Current position uint64_t start=TellBegin()+8; // Payload start uint64_t end=start+sizeFilled; // Next chunk if(pos&1) ADM_backTrack("[AVI]CHUNK is at a even position",__LINE__,__FILE__); if(pos+8>end) { ADM_error("No space to add junk chunk ( %d, filler=%d)\n",(int)pos-start,sizeFilled); if(end<=pos) { ADM_error("CHUNK OVERFLOW ( %d, filler=%d)\n",(int)pos-start,sizeFilled); ADM_error("CHUNK OVERFLOW ( %d, filler=%d)\n",(int)pos-start,sizeFilled); ADM_error("CHUNK OVERFLOW ( %d, filler=%d)\n",(int)pos-start,sizeFilled); ADM_error("CHUNK OVERFLOW ( %d, filler=%d)\n",(int)pos-start,sizeFilled); ADM_backTrack("CHUNK overflow",__LINE__,__FILE__); return false; } int left=(int)(end-pos); for(int i=0;i<left;i++) Write8(0); // we dont have enough space to put a junk() End(); return true; } End(); uint64_t left=end-8-pos; AviListAvi junk("JUNK",getFile()); junk.Begin(); for(int i=0;i<left;i++) // Inefficient, but can be fairly large junk.Write8(0); junk.End(); return true; }
bool MakeJunction(const string& target, const string& junkpath, mgr_file::Attrs* attrs) { if (mgr_file::Exists(junkpath)) return false; if (!mgr_file::Exists(target)) return false; mgr_file::Info nfo(target); if (!nfo.IsDir()) return false; mgr_file::MkDir(junkpath, attrs); str::u16string tgt(target); str::u16string junk(junkpath); ResHandle hLink(OpenLinkHandle(str::u16string(junkpath).c_str(), GENERIC_WRITE)); if ((bool)hLink) { str::u16string SubstituteName("\\??\\" + target); REPARSE_BUF rdb; rdb->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT; rdb.fill(tgt.c_str(), tgt.size(), SubstituteName.c_str(), SubstituteName.size()); if (rdb.set(junk.c_str())) { return true; } } mgr_file::Remove(junkpath); return false; }
void foo(void) { int a; junk(a = 3); }
void newfunc_typed(int storage, char *n, int type) { int idx; SYMBOL *symbol; char an[NAMESIZE]; fexitlab = getlabel(); if ((idx = find_global(n)) > -1) { symbol = &symbol_table[idx]; if (symbol->identity != FUNCTION) multidef(n); } else { /* extern implies global scope */ idx = add_global(n, FUNCTION, CINT, 0, storage == EXTERN ? PUBLIC : storage); symbol = &symbol_table[idx]; } local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC; argstk = 0; // ANSI style argument declaration if (doAnsiArguments()) { if (storage == EXTERN) { need_semicolon(); return; } /* No body .. just a definition */ if (match(";")) return; } else { // K&R style argument declaration while (!match(")")) { if (symname(an)) { if (find_locale(an) > -1) multidef(an); else { /* FIXME: struct */ add_local(an, 0, 0, argstk, AUTO); argstk = argstk + INTSIZE; } } else { error("illegal argument name"); junk(); } blanks(); if (!streq(line + lptr, ")")) { if (!match(",")) error("expected comma"); } if (endst()) break; } if (storage == EXTERN) { need_semicolon(); return; } /* No body .. just a definition */ if (match(";")) return; stkp = 0; argtop = argstk; while (argstk) { if ((type = get_type()) != -1) { notvoid(type); getarg(type); need_semicolon(); } else { error("wrong number args"); break; } } } if (symbol->offset == FUNCTION) multidef(n); symbol->offset = FUNCTION; output_string(n); output_label_terminator(); newline(); gen_prologue(); statement(YES); print_label(fexitlab); output_label_terminator(); newline(); gen_epilogue(); gen_modify_stack(0); gen_ret(); stkp = 0; local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC; }
/** * nfnl_listen: listen for one or more netlink messages * @nfnhl: libnfnetlink handle * @handler: callback function to be called for every netlink message * - the callback handler should normally return 0 * - but may return a negative error code which will cause * nfnl_listen to return immediately with the same error code * - or return a postivie error code which will cause * nfnl_listen to return after it has finished processing all * the netlink messages in the current packet * Thus a positive error code will terminate nfnl_listen "soon" * without any loss of data, a negative error code will terminate * nfnl_listen "very soon" and throw away data already read from * the netlink socket. * @jarg: opaque argument passed on to callback * * This function is used to receive and process messages coming from an open * nfnetlink handler like events or information request via nfnl_send(). * * On error, -1 is returned, unfortunately errno is not always set * appropiately. For that reason, the use of this function is DEPRECATED. * Please, use nfnl_receive_process() instead. */ int nfnl_listen(struct nfnl_handle *nfnlh, int (*handler)(struct sockaddr_nl *, struct nlmsghdr *n, void *), void *jarg) { struct sockaddr_nl nladdr; char buf[NFNL_BUFFSIZE] __attribute__ ((aligned)); struct iovec iov; int remain; struct nlmsghdr *h; struct nlmsgerr *msgerr; int quit=0; struct msghdr msg = { .msg_name = &nladdr, .msg_namelen = sizeof(nladdr), .msg_iov = &iov, .msg_iovlen = 1, }; memset(&nladdr, 0, sizeof(nladdr)); nladdr.nl_family = AF_NETLINK; iov.iov_base = buf; iov.iov_len = sizeof(buf); while (! quit) { remain = recvmsg(nfnlh->fd, &msg, 0); if (remain < 0) { if (errno == EINTR) continue; /* Bad file descriptor */ else if (errno == EBADF) break; else if (errno == EAGAIN) break; nfnl_error("recvmsg overrun: %s", strerror(errno)); continue; } if (remain == 0) { nfnl_error("EOF on netlink"); return -1; } if (msg.msg_namelen != sizeof(nladdr)) { nfnl_error("Bad sender address len (%d)", msg.msg_namelen); return -1; } for (h = (struct nlmsghdr *)buf; remain >= sizeof(*h);) { int err; int len = h->nlmsg_len; int l = len - sizeof(*h); if (l < 0 || len > remain) { if (msg.msg_flags & MSG_TRUNC) { nfnl_error("MSG_TRUNC"); return -1; } nfnl_error("Malformed msg (len=%d)", len); return -1; } /* end of messages reached, let's return */ if (h->nlmsg_type == NLMSG_DONE) return 0; /* Break the loop if success is explicitely * reported via NLM_F_ACK flag set */ if (h->nlmsg_type == NLMSG_ERROR) { msgerr = NLMSG_DATA(h); return msgerr->error; } err = handler(&nladdr, h, jarg); if (err < 0) return err; quit |= err; /* FIXME: why not _NEXT macros, etc.? */ //h = NLMSG_NEXT(h, remain); remain -= NLMSG_ALIGN(len); h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); } if (msg.msg_flags & MSG_TRUNC) { nfnl_error("MSG_TRUNC"); continue; } if (remain) { nfnl_error("remnant size %d", remain); return -1; } } return quit; } /** * nfnl_talk - send a request and then receive and process messages returned * @nfnlh: nfnetelink handler * @n: netlink message that contains the request * @peer: peer PID * @groups: netlink groups * @junk: callback called if out-of-sequence messages were received * @jarg: data for the junk callback * * This function is used to request an action that does not returns any * information. On error, a negative value is returned, errno could be * set appropiately. For that reason, the use of this function is DEPRECATED. * Please, use nfnl_query() instead. */ int nfnl_talk(struct nfnl_handle *nfnlh, struct nlmsghdr *n, pid_t peer, unsigned groups, struct nlmsghdr *answer, int (*junk)(struct sockaddr_nl *, struct nlmsghdr *n, void *), void *jarg) { char buf[NFNL_BUFFSIZE] __attribute__ ((aligned)); struct sockaddr_nl nladdr; struct nlmsghdr *h; unsigned int seq; int status; struct iovec iov = { n, n->nlmsg_len }; struct msghdr msg = { .msg_name = &nladdr, .msg_namelen = sizeof(nladdr), .msg_iov = &iov, .msg_iovlen = 1, }; memset(&nladdr, 0, sizeof(nladdr)); nladdr.nl_family = AF_NETLINK; nladdr.nl_pid = peer; nladdr.nl_groups = groups; n->nlmsg_seq = seq = ++nfnlh->seq; /* FIXME: why ? */ if (!answer) n->nlmsg_flags |= NLM_F_ACK; status = sendmsg(nfnlh->fd, &msg, 0); if (status < 0) { nfnl_error("sendmsg(netlink) %s", strerror(errno)); return -1; } iov.iov_base = buf; iov.iov_len = sizeof(buf); while (1) { status = recvmsg(nfnlh->fd, &msg, 0); if (status < 0) { if (errno == EINTR) continue; nfnl_error("recvmsg over-run"); continue; } if (status == 0) { nfnl_error("EOF on netlink"); return -1; } if (msg.msg_namelen != sizeof(nladdr)) { nfnl_error("Bad sender address len %d", msg.msg_namelen); return -1; } for (h = (struct nlmsghdr *)buf; status >= sizeof(*h); ) { int len = h->nlmsg_len; int l = len - sizeof(*h); int err; if (l < 0 || len > status) { if (msg.msg_flags & MSG_TRUNC) { nfnl_error("Truncated message\n"); return -1; } nfnl_error("Malformed message: len=%d\n", len); return -1; /* FIXME: libnetlink exits here */ } if (h->nlmsg_pid != nfnlh->local.nl_pid || h->nlmsg_seq != seq) { if (junk) { err = junk(&nladdr, h, jarg); if (err < 0) return err; } goto cont; } if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = NLMSG_DATA(h); if (l < sizeof(struct nlmsgerr)) nfnl_error("ERROR truncated\n"); else { errno = -err->error; if (errno == 0) { if (answer) memcpy(answer, h, h->nlmsg_len); return 0; } perror("NFNETLINK answers"); } return err->error; } if (answer) { memcpy(answer, h, h->nlmsg_len); return 0; } nfnl_error("Unexpected reply!\n"); cont: status -= NLMSG_ALIGN(len); h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); } if (msg.msg_flags & MSG_TRUNC) { nfnl_error("Messages truncated\n"); continue; } if (status) nfnl_error("Remnant of size %d\n", status); } } /** * nfnl_addattr_l - Add variable length attribute to nlmsghdr * @n: netlink message header to which attribute is to be added * @maxlen: maximum length of netlink message header * @type: type of new attribute * @data: content of new attribute * @len: attribute length */ int nfnl_addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen) { int len = NFA_LENGTH(alen); struct nfattr *nfa; assert(n); assert(maxlen > 0); assert(type >= 0); if ((NLMSG_ALIGN(n->nlmsg_len) + len) > maxlen) { errno = ENOSPC; return -1; } nfa = NLMSG_TAIL(n); nfa->nfa_type = type; nfa->nfa_len = len; memcpy(NFA_DATA(nfa), data, alen); memset((uint8_t *)nfa + nfa->nfa_len, 0, NFA_ALIGN(alen) - alen); n->nlmsg_len = (NLMSG_ALIGN(n->nlmsg_len) + NFA_ALIGN(len)); return 0; }
int rtnl_dump_filter(struct rtnl_handle *rth, int (*filter)(struct sockaddr_nl *, struct nlmsghdr *n, void *), void *arg1, int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), void *arg2) { char buf[8192]; struct sockaddr_nl nladdr; struct iovec iov = { buf, sizeof(buf) }; while (1) { int status; struct nlmsghdr *h; struct msghdr msg = { (void*)&nladdr, sizeof(nladdr), &iov, 1, NULL, 0, 0 }; status = recvmsg(rth->fd, &msg, 0); if (status < 0) { if (errno == EINTR) continue; // perror("OVERRUN"); snmp_log(LOG_WARNING,"overrun\n"); continue; } if (status == 0) { // fprintf(stderr, "EOF on netlink\n"); snmp_log(LOG_NOTICE,"EOF on netlink\n"); return -1; } if (msg.msg_namelen != sizeof(nladdr)) { // fprintf(stderr, "sender address length == %d\n", msg.msg_namelen); snmp_log(LOG_NOTICE,"sender address length\n"); return(1); } h = (struct nlmsghdr*)buf; while (NLMSG_OK(h, status)) { int err; if (h->nlmsg_pid != rth->local.nl_pid || h->nlmsg_seq != rth->dump) { if (junk) { err = junk(&nladdr, h, arg2); if (err < 0) return err; } goto skip_it; } if (h->nlmsg_type == NLMSG_DONE) return 0; if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) { // fprintf(stderr, "ERROR truncated\n"); snmp_log(LOG_NOTICE,"error struncated\n"); } else { errno = -err->error; // perror("RTNETLINK answers"); snmp_log(LOG_NOTICE,"rtnetlink failed\n"); } return -1; } err = filter(&nladdr, h, arg1); if (err < 0) return err; skip_it: h = NLMSG_NEXT(h, status); } if (msg.msg_flags & MSG_TRUNC) { // fprintf(stderr, "Message truncated\n"); snmp_log(LOG_NOTICE,"message truncated\n"); continue; } if (status) { // fprintf(stderr, "!!!Remnant of size %d\n", status); snmp_log(LOG_NOTICE,"remnant of size\n"); return(1); } } }
newfunc () { char n[NAMESIZE], *ptr; fexitlab = getlabel(); if (!symname (n) ) { error ("illegal function or declaration"); kill (); return; } if (ptr = findglb (n)) { if (ptr[IDENT] != FUNCTION) multidef (n); else if (ptr[OFFSET] == FUNCTION) multidef (n); else ptr[OFFSET] = FUNCTION; } else addglb (n, FUNCTION, CINT, FUNCTION, PUBLIC); prologue (); if (!match ("(")) error ("missing open paren"); prefix (); outstr (n); col (); nl (); locptr = STARTLOC; argstk = 0; while (!match (")")) { if (symname (n)) { if (findloc (n)) multidef (n); else { addloc (n, 0, 0, argstk, AUTO); argstk = argstk + intsize(); } } else { error ("illegal argument name"); junk (); } blanks (); if (!streq (line + lptr, ")")) { if (!match (",")) error ("expected comma"); } if (endst ()) break; } stkp = 0; argtop = argstk; while (argstk) { if (amatch ("register", 8)) { if (amatch("char", 4)) getarg(CCHAR); else if (amatch ("int", 3)) getarg(CINT); else getarg(CINT); ns(); } else if (amatch ("char", 4)) { getarg (CCHAR); ns (); } else if (amatch ("int", 3)) { getarg (CINT); ns (); } else { error ("wrong number args"); break; } } statement(YES); printlabel(fexitlab); col(); nl(); modstk (0); gret (); stkp = 0; locptr = STARTLOC; }
/* * Get a line into genbuf after gcursor. * Cnt limits the number of input characters * accepted and is used for handling the replace * single character command. Aescaped is the location * where we stick a termination indicator (whether we * ended with an ESCAPE or a newline/return. * * We do erase-kill type processing here and also * are careful about the way we do this so that it is * repeatable. (I.e. so that your kill doesn't happen, * when you repeat an insert if it was escaped with \ the * first time you did it. commch is the command character * involved, including the prompt for readline. */ char * vgetline(int cnt, char *gcursor, bool *aescaped, int commch) { register int c, ch; register char *cp; int x, y, iwhite, backsl=0; cell *iglobp; char cstr[2]; int (*OO)(int) = Outchar; /* * Clear the output state and counters * for autoindent backwards motion (counts of ^D, etc.) * Remember how much white space at beginning of line so * as not to allow backspace over autoindent. */ *aescaped = 0; ogcursor = gcursor; flusho(); CDCNT = 0; HADUP = 0; HADZERO = 0; gobbled = 0; iwhite = whitecnt(genbuf); iglobp = vglobp; /* * Carefully avoid using vinschar in the echo area. */ if (splitw) Outchar = vputchar; else { Outchar = vinschar; vprepins(); } for (;;) { backsl = 0; if (gobblebl) gobblebl--; if (cnt != 0) { cnt--; if (cnt == 0) goto vadone; } c = getkey(); if (c != ATTN) c &= (QUOTE|TRIM); ch = c; maphopcnt = 0; if (vglobp == 0 && Peekkey == 0 && commch != 'r') while ((ch = map(c, immacs)) != c) { c = ch; if (!value(REMAP)) break; if (++maphopcnt > 256) error(catgets(catd, 1, 234, "Infinite macro loop")); } if (!iglobp) { /* * Erase-kill type processing. * Only happens if we were not reading * from untyped input when we started. * Map users erase to ^H, kill to -1 for switch. */ if (c == tty.c_cc[VERASE]) c = CTRL('h'); else if (c == tty.c_cc[VKILL]) c = -1; if (c == ATTN) goto case_ATTN; switch (c) { /* * ^? Interrupt drops you back to visual * command mode with an unread interrupt * still in the input buffer. * * ^\ Quit does the same as interrupt. * If you are a ex command rather than * a vi command this will drop you * back to command mode for sure. */ case QUIT: case_ATTN: ungetkey(c); goto vadone; /* * ^H Backs up a character in the input. * * BUG: Can't back around line boundaries. * This is hard because stuff has * already been saved for repeat. */ case CTRL('h'): bakchar: cp = gcursor + skipleft(ogcursor, gcursor); if (cp < ogcursor) { if (splitw) { /* * Backspacing over readecho * prompt. Pretend delete but * don't beep. */ ungetkey(c); goto vadone; } beep(); continue; } goto vbackup; /* * ^W Back up a white/non-white word. */ case CTRL('w'): wdkind = 1; for (cp = gcursor; cp > ogcursor && isspace(cp[-1]&0377); cp--) continue; for (c = wordch(cp - 1); cp > ogcursor && wordof(c, cp - 1); cp--) continue; goto vbackup; /* * users kill Kill input on this line, back to * the autoindent. */ case -1: cp = ogcursor; vbackup: if (cp == gcursor) { beep(); continue; } endim(); *cp = 0; c = cindent(); vgotoCL(qcolumn(cursor + skipleft(linebuf, cursor), genbuf)); if (doomed >= 0) doomed += c - cindent(); gcursor = cp; continue; /* * \ Followed by erase or kill * maps to just the erase or kill. */ case '\\': x = destcol, y = destline; putchar('\\'); vcsync(); c = getkey(); if (c == tty.c_cc[VERASE] || c == tty.c_cc[VKILL]) { vgoto(y, x); if (doomed >= 0) doomed++; goto def; } ungetkey(c), c = '\\'; backsl = 1; break; /* * ^Q Super quote following character * Only ^@ is verboten (trapped at * a lower level) and \n forces a line * split so doesn't really go in. * * ^V Synonym for ^Q */ case CTRL('q'): case CTRL('v'): x = destcol, y = destline; putchar('^'); vgoto(y, x); c = getkey(); if (c != NL) { if (doomed >= 0) doomed++; goto def; } break; } } /* * If we get a blank not in the echo area * consider splitting the window in the wrapmargin. */ if (c != NL && !splitw) { if (c == ' ' && gobblebl) { gobbled = 1; continue; } if (value(WRAPMARGIN) && (outcol >= OCOLUMNS - value(WRAPMARGIN) || (backsl && outcol == 0)) && commch != 'r') { /* * At end of word and hit wrapmargin. * Move the word to next line and keep going. */ wdkind = 1; gappend(c); if (backsl) gappend(getkey()); *gcursor = 0; /* * Find end of previous word if we are past it. */ for (cp=gcursor; cp>ogcursor && isspace(cp[-1]&0377); cp--) ; if (outcol+(backsl?OCOLUMNS:0) - (gcursor-cp) >= OCOLUMNS - value(WRAPMARGIN)) { /* * Find beginning of previous word. */ for (; cp>ogcursor && !isspace(cp[-1]&0377); cp--) ; if (cp <= ogcursor) { /* * There is a single word that * is too long to fit. Just * let it pass, but beep for * each new letter to warn * the luser. */ c = *--gcursor; *gcursor = 0; beep(); goto dontbreak; } /* * Save it for next line. */ macpush(cp, 0); cp--; } macpush("\n", 0); /* * Erase white space before the word. */ while (cp > ogcursor && isspace(cp[-1]&0377)) cp--; /* skip blank */ gobblebl = 3; goto vbackup; } dontbreak:; } /* * Word abbreviation mode. */ cstr[0] = c; if (anyabbrs && gcursor > ogcursor && !wordch(cstr) && wordch(gcursor-1)) { int wdtype, abno; cstr[1] = 0; wdkind = 1; cp = gcursor + skipleft(ogcursor, gcursor); for (wdtype = wordch(cp - 1); cp > ogcursor && wordof(wdtype, cp - 1); cp--) ; *gcursor = 0; for (abno=0; abbrevs[abno].mapto; abno++) { if (!abbrevs[abno].hadthis && eq(cp, abbrevs[abno].cap)) { abbrevs[abno].hadthis++; macpush(cstr, 0); macpush(abbrevs[abno].mapto, 0); goto vbackup; } } } #ifdef BIT8 if (c == OVERBUF) goto btrp; #endif switch (c) { /* * ^M Except in repeat maps to \n. */ case CR: if (vglobp) goto def; c = '\n'; /* presto chango ... */ /* * \n Start new line. */ case NL: *aescaped = c; goto vadone; /* * escape End insert unless repeat and more to repeat. */ case ESCAPE: if (lastvgk) goto def; goto vadone; /* * ^D Backtab. * ^T Software forward tab. * * Unless in repeat where this means these * were superquoted in. */ case CTRL('d'): case CTRL('t'): if (vglobp) goto def; /* fall into ... */ /* * ^D|QUOTE Is a backtab (in a repeated command). */ #ifndef BIT8 case CTRL('d') | QUOTE: #else btrp: #endif *gcursor = 0; cp = vpastwh(genbuf); c = whitecnt(genbuf); if (ch == CTRL('t')) { /* * ^t just generates new indent replacing * current white space rounded up to soft * tab stop increment. */ if (cp != gcursor) /* * BUG: Don't hack ^T except * right after initial * white space. */ continue; cp = genindent(iwhite = backtab(c + value(SHIFTWIDTH) + 1)); ogcursor = cp; goto vbackup; } /* * ^D works only if we are at the (end of) the * generated autoindent. We count the ^D for repeat * purposes. */ if (c == iwhite && c != 0) { if (cp == gcursor) { iwhite = backtab(c); CDCNT++; ogcursor = cp = genindent(iwhite); goto vbackup; } else if (&cp[1] == gcursor && (*cp == '^' || *cp == '0')) { /* * ^^D moves to margin, then back * to current indent on next line. * * 0^D moves to margin and then * stays there. */ HADZERO = *cp == '0'; ogcursor = cp = genbuf; HADUP = 1 - HADZERO; CDCNT = 1; endim(); back1(); vputchar(' '); goto vbackup; } } if (vglobp && vglobp - iglobp >= 2 && (vglobp[-2] == '^' || vglobp[-2] == '0') && gcursor == ogcursor + 1) goto bakchar; continue; default: /* * Possibly discard control inputs. */ if (!vglobp && junk(c)) { beep(); continue; } def: if (!backsl) { /* int cnt; */ putchar(c); flush(); } if (gcursor > &genbuf[LBSIZE - 2]) error(catgets(catd, 1, 235, "Line too long")); gappend(c & TRIM); vcsync(); if (value(SHOWMATCH) && !iglobp) if (c == ')' || c == '}') lsmatch(gcursor); continue; } } vadone: *gcursor = 0; if (Outchar != termchar) Outchar = OO; endim(); return (gcursor); }
/** * nfnl_talk - send a request and then receive and process messages returned * @nfnlh: nfnetelink handler * @n: netlink message that contains the request * @peer: peer PID * @groups: netlink groups * @junk: callback called if out-of-sequence messages were received * @jarg: data for the junk callback * * This function is used to request an action that does not returns any * information. On error, a negative value is returned, errno could be * set appropiately. For that reason, the use of this function is DEPRECATED. * Please, use nfnl_query() instead. */ int nfnl_talk(struct nfnl_handle *nfnlh, struct nlmsghdr *n, pid_t peer, unsigned groups, struct nlmsghdr *answer, int (*junk)(struct sockaddr_nl *, struct nlmsghdr *n, void *), void *jarg) { char buf[NFNL_BUFFSIZE]; struct sockaddr_nl nladdr; struct nlmsghdr *h; unsigned int seq; int status; struct iovec iov = { (void *)n, n->nlmsg_len }; struct msghdr msg = { (void *)&nladdr, sizeof(nladdr), &iov, 1, NULL, 0, 0 }; memset(&nladdr, 0, sizeof(nladdr)); nladdr.nl_family = AF_NETLINK; nladdr.nl_pid = peer; nladdr.nl_groups = groups; n->nlmsg_seq = seq = ++nfnlh->seq; /* FIXME: why ? */ if (!answer) n->nlmsg_flags |= NLM_F_ACK; status = sendmsg(nfnlh->fd, &msg, 0); if (status < 0) { nfnl_error("sendmsg(netlink) %s", strerror(errno)); return -1; } iov.iov_base = buf; iov.iov_len = sizeof(buf); while (1) { status = recvmsg(nfnlh->fd, &msg, 0); if (status < 0) { if (errno == EINTR) continue; nfnl_error("recvmsg over-run"); continue; } if (status == 0) { nfnl_error("EOF on netlink"); return -1; } if (msg.msg_namelen != sizeof(nladdr)) { nfnl_error("Bad sender address len %d", msg.msg_namelen); return -1; } for (h = (struct nlmsghdr *)buf; status >= sizeof(*h); ) { int len = h->nlmsg_len; int l = len - sizeof(*h); int err; if (l < 0 || len > status) { if (msg.msg_flags & MSG_TRUNC) { nfnl_error("Truncated message\n"); return -1; } nfnl_error("Malformed message: len=%d\n", len); return -1; /* FIXME: libnetlink exits here */ } if (h->nlmsg_pid != nfnlh->local.nl_pid || h->nlmsg_seq != seq) { if (junk) { err = junk(&nladdr, h, jarg); if (err < 0) return err; } goto cont; } if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = NLMSG_DATA(h); if (l < sizeof(struct nlmsgerr)) nfnl_error("ERROR truncated\n"); else { errno = -err->error; if (errno == 0) { if (answer) memcpy(answer, h, h->nlmsg_len); return 0; } perror("NFNETLINK answers"); } return err->error; } if (answer) { memcpy(answer, h, h->nlmsg_len); return 0; } nfnl_error("Unexpected reply!\n"); cont: status -= NLMSG_ALIGN(len); h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); } if (msg.msg_flags & MSG_TRUNC) { nfnl_error("Messages truncated\n"); continue; } if (status) { nfnl_error("Remnant of size %d\n", status); exit(1); } } }
/* * Processes a single man page source by using nroff to create * the preformatted cat page. */ static void process_page(char *mandir, char *src, char *cat, enum Ziptype zipped) { int src_test, cat_test; time_t src_mtime, cat_mtime; char cmd[MAXPATHLEN]; dev_t src_dev; ino_t src_ino; const char *link_name; src_test = test_path(src, &src_mtime); if (!(src_test & (TEST_FILE|TEST_READABLE))) { if (!(src_test & TEST_DIR)) { warnx("%s/%s: unreadable", mandir, src); exit_code = 1; if (rm_junk && is_symlink(src)) junk(mandir, src, "bogus symlink"); } return; } src_dev = test_st.st_dev; src_ino = test_st.st_ino; cat_test = test_path(cat, &cat_mtime); if (cat_test & (TEST_FILE|TEST_READABLE)) { if (!force && cat_mtime >= src_mtime) { if (verbose) { fprintf(stderr, "\t%s/%s: up to date\n", mandir, src); } return; } } /* * Is the man page a link to one we've already processed? */ if ((link_name = find_hashtable(links, src_ino, src_dev)) != NULL) { if (verbose || pretend) { fprintf(stderr, "%slink %s -> %s\n", verbose ? "\t" : "", cat, link_name); } if (!pretend) link(link_name, cat); return; } insert_hashtable(links, src_ino, src_dev, strdup(cat)); if (verbose || pretend) { fprintf(stderr, "%sformat %s -> %s\n", verbose ? "\t" : "", src, cat); if (pretend) return; } snprintf(tmp_file, sizeof tmp_file, "%s.tmp", cat); snprintf(cmd, sizeof cmd, "%scat %s | tbl | nroff -c -T%s -man | %s > %s.tmp", zipped == BZIP ? BZ2CAT_CMD : zipped == GZIP ? GZCAT_CMD : "", src, nroff_device, zipped == BZIP ? BZ2_CMD : zipped == GZIP ? GZ_CMD : "cat", cat); if (system(cmd) != 0) err(1, "formatting pipeline"); if (rename(tmp_file, cat) < 0) warn("%s", cat); tmp_file[0] = '\0'; }
void DoFnKR( SYMBOL *currfn, char simple) { char n[NAMESIZE]; SYMBOL *prevarg; /* ptr to symbol table entry of most recent argument */ SYMBOL *cptr; TAG_SYMBOL *otag ; /* structure tag for structure argument */ struct varid var; prevarg=0; Zsp=0; /* Reset stack pointer */ undeclared=0; infunc=1; while ( !simple && cmatch(')') == 0 ) { /* then count args */ /* any legal name bumps arg count */ if ( symname(n) ) { /* add link to argument chain */ if ( (cptr=addloc(n,0,CINT,0,0)) ) cptr->offset.p = prevarg ; prevarg = cptr ; ++undeclared ; } else { error(E_ARGNAME); junk(); } blanks(); /* if not closing paren, should be comma */ if ( ch() != ')' && cmatch(',') == 0 ) { warning(W_EXPCOM); } if ( endst() ) break ; } Zsp = 0 ; /* preset stack ptr */ while ( undeclared ) { char regit=NO; if (amatch("register") ) regit=YES; /* Auto is be default in function defns, but someone might * try it on... */ if (amatch("auto") ) warning(W_AUTO); otag=GetVarID(&var,STATIK); if (var.type==STRUCT) { getarg(STRUCT, otag,NO,0,0, var.zfar,NO) ; } else if (var.type || regit) { if (regit && var.type == NO ) var.type=CINT; getarg(var.type,NULL_TAG,NO,0,var.sign,var.zfar,NO); } else { error(E_BADARG) ; break ; } } /* Have finished K&R parsing */ setlocvar(prevarg,currfn); }
int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, unsigned groups, struct nlmsghdr *answer, int (*junk)(struct sockaddr_nl *,struct nlmsghdr *n, void *), void *jarg) { int status; unsigned seq; struct nlmsghdr *h; struct sockaddr_nl nladdr; struct iovec iov = { (void*)n, n->nlmsg_len }; char buf[8192]; struct msghdr msg = { (void*)&nladdr, sizeof(nladdr), &iov, 1, NULL, 0, 0 }; memset(&nladdr, 0, sizeof(nladdr)); nladdr.nl_family = AF_NETLINK; nladdr.nl_pid = peer; nladdr.nl_groups = groups; n->nlmsg_seq = seq = ++rtnl->seq; if (answer == NULL) n->nlmsg_flags |= NLM_F_ACK; status = sendmsg(rtnl->fd, &msg, 0); if (status < 0) { perror("Cannot talk to rtnetlink"); return -1; } iov.iov_base = buf; while (1) { iov.iov_len = sizeof(buf); status = recvmsg(rtnl->fd, &msg, 0); if (status < 0) { if (errno == EINTR) continue; perror("OVERRUN"); continue; } if (status == 0) { fprintf(stderr, "EOF on netlink\n"); return -1; } if (msg.msg_namelen != sizeof(nladdr)) { fprintf(stderr, "sender address length == %d\n", msg.msg_namelen); exit(1); } for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) { int err; int len = h->nlmsg_len; int l = len - sizeof(*h); if (l<0 || len>status) { if (msg.msg_flags & MSG_TRUNC) { fprintf(stderr, "Truncated message\n"); return -1; } fprintf(stderr, "!!!malformed message: len=%d\n", len); exit(1); } if (nladdr.nl_pid != peer || h->nlmsg_pid != rtnl->local.nl_pid || h->nlmsg_seq != seq) { if (junk) { err = junk(&nladdr, h, jarg); if (err < 0) return err; } continue; } if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h); if (l < sizeof(struct nlmsgerr)) { fprintf(stderr, "ERROR truncated\n"); } else { errno = -err->error; if (errno == 0) { if (answer) memcpy(answer, h, h->nlmsg_len); return 0; } perror("RTNETLINK answers"); } return -1; } if (answer) { memcpy(answer, h, h->nlmsg_len); return 0; } fprintf(stderr, "Unexpected reply!!!\n"); status -= NLMSG_ALIGN(len); h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len)); } if (msg.msg_flags & MSG_TRUNC) { fprintf(stderr, "Message truncated\n"); continue; } if (status) { fprintf(stderr, "!!!Remnant of size %d\n", status); exit(1); } } }
/** * begin a function * called from "parse", this routine tries to make a function out * of what follows * modified version. p.l. woods */ newfunc() { char n[NAMESIZE]; int idx, type; fexitlab = getlabel(); if (!symname(n)) { error("illegal function or declaration"); kill(); return; } if (idx = findglb(n)) { if (symbol_table[idx].identity != FUNCTION) multidef(n); else if (symbol_table[idx].offset == FUNCTION) multidef(n); else symbol_table[idx].offset = FUNCTION; } else add_global(n, FUNCTION, CINT, FUNCTION, PUBLIC); if (!match("(")) error("missing open paren"); output_string(n); output_label_terminator(); newline(); local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC; argstk = 0; // ANSI style argument declaration if (doAnsiArguments() == 0) { // K&R style argument declaration while (!match(")")) { if (symname(n)) { if (findloc(n)) multidef(n); else { add_local(n, 0, 0, argstk, AUTO); argstk = argstk + INTSIZE; } } else { error("illegal argument name"); junk(); } blanks(); if (!streq(line + lptr, ")")) { if (!match(",")) error("expected comma"); } if (endst()) break; } stkp = 0; argtop = argstk; while (argstk) { if (type = get_type()) { getarg(type); need_semicolon(); } else { error("wrong number args"); break; } } } statement(YES); print_label(fexitlab); output_label_terminator(); newline(); gen_modify_stack(0); gen_ret(); stkp = 0; local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC; }
int primary(LVALUE *lval) { char sname[NAMESIZE]; int num[1], k, symbol_table_idx, offset, reg; SYMBOL *symbol; lval->ptr_type = 0; // clear pointer/array type lval->tagsym = 0; if (match ("(")) { k = hier1 (lval); needbrack (")"); return (k); } if (amatch("sizeof", 6)) { needbrack("("); gen_immediate(); if (amatch("int", 3)) output_number(INTSIZE); else if (amatch("char", 4)) output_number(1); else if (symname(sname)) { if (((symbol_table_idx = find_locale(sname)) > -1) || ((symbol_table_idx = find_global(sname)) > -1)) { symbol = &symbol_table[symbol_table_idx]; if (symbol->storage == LSTATIC) error("sizeof local static"); offset = symbol->offset; if ((symbol->type & CINT) || (symbol->identity == POINTER)) offset *= INTSIZE; else if (symbol->type == STRUCT) offset *= tag_table[symbol->tagidx].size; output_number(offset); } else { error("sizeof undeclared variable"); output_number(0); } } else { error("sizeof only on type or variable"); } needbrack(")"); newline(); lval->symbol = 0; lval->indirect = 0; return(0); } if (symname (sname)) { if ((symbol_table_idx = find_locale(sname)) > -1) { symbol = &symbol_table[symbol_table_idx]; reg = gen_get_locale(symbol); lval->symbol = symbol; lval->indirect = symbol->type; if (symbol->type == STRUCT) { lval->tagsym = &tag_table[symbol->tagidx]; } if (symbol->identity == ARRAY || (symbol->identity == VARIABLE && symbol->type == STRUCT)) { lval->ptr_type = symbol->type; return reg; } if (symbol->identity == POINTER) { lval->indirect = CINT; lval->ptr_type = symbol->type; } return FETCH | reg; } if ((symbol_table_idx = find_global(sname)) > -1) { symbol = &symbol_table[symbol_table_idx]; if (symbol->identity != FUNCTION) { lval->symbol = symbol; lval->indirect = 0; if (symbol->type == STRUCT) { lval->tagsym = &tag_table[symbol->tagidx]; } if (symbol->identity != ARRAY && (symbol->identity != VARIABLE || symbol->type != STRUCT)) { if (symbol->identity == POINTER) { lval->ptr_type = symbol->type; } return FETCH | HL_REG; } gen_immediate(); output_string(symbol->name); newline(); lval->indirect = symbol->type; lval->ptr_type = symbol->type; return 0; } } blanks(); if (ch() != '(') error("undeclared variable"); symbol_table_idx = add_global(sname, FUNCTION, CINT, 0, PUBLIC); symbol = &symbol_table[symbol_table_idx]; lval->symbol = symbol; lval->indirect = 0; return 0; } lval->symbol = 0; lval->indirect = 0; if (constant(num)) return 0; else { error("invalid expression"); gen_immediate(); output_number(0); newline(); junk(); return 0; } }
/* * Get a line into genbuf after gcursor. * Cnt limits the number of input characters * accepted and is used for handling the replace * single character command. Aescaped is the location * where we stick a termination indicator (whether we * ended with an ESCAPE or a newline/return. * * We do erase-kill type processing here and also * are careful about the way we do this so that it is * repeatable. (I.e. so that your kill doesn't happen, * when you repeat an insert if it was escaped with \ the * first time you did it. */ char * vgetline(int cnt, char *gcursor, bool *aescaped) { register int c, ch; register char *cp; int x, y, iwhite; char *iglobp; void (*OO)() = Outchar; /* * Clear the output state and counters * for autoindent backwards motion (counts of ^D, etc.) * Remember how much white space at beginning of line so * as not to allow backspace over autoindent. */ *aescaped = 0; ogcursor = gcursor; flusho(); CDCNT = 0; HADUP = 0; HADZERO = 0; gobbled = 0; iwhite = whitecnt(genbuf); iglobp = vglobp; /* * Carefully avoid using vinschar in the echo area. */ if (splitw) Outchar = vputchar; else { Outchar = vinschar; vprepins(); } for (;;) { if (gobblebl) gobblebl--; if (cnt != 0) { cnt--; if (cnt == 0) goto vadone; } ch = c = getkey() & (QUOTE|TRIM); if (!iglobp) { /* * Erase-kill type processing. * Only happens if we were not reading * from untyped input when we started. * Map users erase to ^H, kill to -1 for switch. */ if (c == tty.c_cc[VERASE]) c = CTRL('h'); else if (c == tty.c_cc[VKILL]) c = -1; switch (c) { /* * ^? Interrupt drops you back to visual * command mode with an unread interrupt * still in the input buffer. * * ^\ Quit does the same as interrupt. * If you are a ex command rather than * a vi command this will drop you * back to command mode for sure. */ case ATTN: case QUIT: ungetkey(c); goto vadone; /* * ^H Backs up a character in the input. * * BUG: Can't back around line boundaries. * This is hard because stuff has * already been saved for repeat. */ case CTRL('h'): bakchar: cp = gcursor - 1; if (cp < ogcursor) { beep(); continue; } goto vbackup; /* * ^W Back up a white/non-white word. */ case CTRL('w'): wdkind = 1; for (cp = gcursor; cp > ogcursor && isspace((int)cp[-1]); cp--) continue; for (c = wordch(cp - 1); cp > ogcursor && wordof(c, cp - 1); cp--) continue; goto vbackup; /* * users kill Kill input on this line, back to * the autoindent. */ case -1: cp = ogcursor; vbackup: if (cp == gcursor) { beep(); continue; } endim(); *cp = 0; c = cindent(); vgotoCL(qcolumn(cursor - 1, genbuf)); if (doomed >= 0) doomed += c - cindent(); gcursor = cp; continue; /* * \ Followed by erase or kill * maps to just the erase or kill. */ case '\\': x = destcol, y = destline; ex_putchar('\\'); vcsync(); c = getkey(); if (c == tty.c_cc[VERASE] || c == tty.c_cc[VKILL]) { vgoto(y, x); if (doomed >= 0) doomed++; goto def; } ungetkey(c), c = '\\'; goto noput; /* * ^Q Super quote following character * Only ^@ is verboten (trapped at * a lower level) and \n forces a line * split so doesn't really go in. * * ^V Synonym for ^Q */ case CTRL('q'): case CTRL('v'): x = destcol, y = destline; ex_putchar('^'); vgoto(y, x); c = getkey(); if (c != NL) { if (doomed >= 0) doomed++; goto def; } break; } } /* * If we get a blank not in the echo area * consider splitting the window in the wrapmargin. */ if (c == ' ' && !splitw) { if (gobblebl) { gobbled = 1; continue; } if (value(WRAPMARGIN) && outcol >= WCOLS - value(WRAPMARGIN)) { c = NL; gobblebl = 2; } } switch (c) { /* * ^M Except in repeat maps to \n. */ case CR: if (vglobp) goto def; c = '\n'; /* presto chango ... */ /* * \n Start new line. */ case NL: *aescaped = c; goto vadone; /* * escape End insert unless repeat and more to repeat. */ case ESCAPE: if (vglobp && *vglobp) goto def; goto vadone; /* * ^D Backtab. * ^T Software forward tab. * * Unless in repeat where this means these * were superquoted in. */ case CTRL('d'): case CTRL('t'): if (vglobp) goto def; /* fall into ... */ /* * ^D|QUOTE Is a backtab (in a repeated command). */ case CTRL('d') | QUOTE: *gcursor = 0; cp = vpastwh(genbuf); c = whitecnt(genbuf); if (ch == CTRL('t')) { /* * ^t just generates new indent replacing * current white space rounded up to soft * tab stop increment. */ if (cp != gcursor) /* * BUG: Don't hack ^T except * right after initial * white space. */ continue; cp = genindent(iwhite = backtab(c + value(SHIFTWIDTH) + 1)); ogcursor = cp; goto vbackup; } /* * ^D works only if we are at the (end of) the * generated autoindent. We count the ^D for repeat * purposes. */ if (c == iwhite && c != 0) { if (cp == gcursor) { iwhite = backtab(c); CDCNT++; ogcursor = cp = genindent(iwhite); goto vbackup; } else if (&cp[1] == gcursor && (*cp == '^' || *cp == '0')) { /* * ^^D moves to margin, then back * to current indent on next line. * * 0^D moves to margin and then * stays there. */ HADZERO = *cp == '0'; ogcursor = cp = genbuf; HADUP = 1 - HADZERO; CDCNT = 1; endim(); back1(); vputc(' '); goto vbackup; } } if (vglobp && vglobp - iglobp >= 2 && (vglobp[-2] == '^' || vglobp[-2] == '0') && gcursor == ogcursor + 1) goto bakchar; continue; default: /* * Possibly discard control inputs. */ if (!vglobp && junk(c)) { beep(); continue; } def: ex_putchar(c); noput: if (gcursor > &genbuf[LBSIZE - 2]) error("Line too long"); *gcursor++ = c & TRIM; vcsync(); #ifdef LISP if (value(SHOWMATCH) && !iglobp) if (c == ')' || c == '}') lsmatch(gcursor); #endif continue; } } vadone: *gcursor = 0; Outchar = OO; endim(); return (gcursor); }
void foo() { junk( &x); //Zortech Error: '::' or '(' expected after class 'x' //Borland raises no errors }
~LockFreeQueue() { NodeIterator junk(*this); // release everything in the queue in ~NodeIterator }
primary (lvalue_t *lval) { char sname[NAMESIZE]; int num[1], k, symbol_table_idx, offset, reg; symbol_t *symbol; lval->ptr_type = 0; /* clear pointer/array type */ if (match ("(")) { k = hier1 (lval); needbrack (")"); return (k); } if (amatch("sizeof", 6)) { needbrack("("); gen_immediate_c(); if (amatch("int", 3)) output_number(INTSIZE); else if (amatch("char", 4)) output_number(1); else if (symname(sname)) { if ((symbol_table_idx = findloc(sname)) || (symbol_table_idx = findglb(sname))) { symbol = &symbol_table[symbol_table_idx]; if (symbol->storage == LSTATIC) error("sizeof local static"); offset = symbol->count; if ((symbol->type & CINT) || (symbol->identity == POINTER)) offset *= INTSIZE; output_number(offset); } else { error("sizeof undeclared variable"); output_number(0); } } else { error("sizeof only on simple type or variable"); } needbrack(")"); newline(); lval->symbol = 0; lval->indirect = 0; return(0); } if (symname (sname)) { if (symbol_table_idx = findloc (sname)) { symbol = &symbol_table[symbol_table_idx]; reg = gen_get_location (symbol); lval->symbol = symbol; lval->indirect = symbol->type; if (symbol->identity == ARRAY) { //lval->ptr_type = symbol->type; lval->ptr_type = 0; return 0; } if (symbol->identity == POINTER) { lval->indirect = UINT; lval->ptr_type = symbol->type; } return reg; } if (symbol_table_idx = findglb (sname)) { symbol = &symbol_table[symbol_table_idx]; lval->symbol = symbol; switch (symbol->identity) { case ARRAY: gen_immediate_a (); output_string (symbol->name); newline (); /* Fall through */ case FUNCTION: lval->indirect = lval->ptr_type = symbol_table[symbol_table_idx].type; lval->ptr_type = 0; return 0; default: lval->indirect = 0; if (symbol->identity == POINTER) { lval->ptr_type = symbol->type; } return 1; } } blanks (); if (ch() != '(') error("undeclared variable"); symbol_table_idx = add_global (sname, FUNCTION, CINT, 0, PUBLIC, 1); symbol = &symbol_table[symbol_table_idx]; lval->symbol = symbol; lval->indirect = 0; return 0; } if (constant (num)) { lval->symbol = 0; lval->indirect = 0; return 0; } error ("invalid expression"); gen_immediate_c (); output_number(0); newline (); junk (); return 0; }
/* * Scan the man section directory for pages and process each one, * then check for junk in the corresponding cat section. */ static void scan_section(char *mandir, char *section, char *cat_section) { struct dirent **entries; char **expected = NULL; int npages; int nexpected = 0; int i, e; enum Ziptype zipped; char *page_name; char page_path[MAXPATHLEN]; char cat_path[MAXPATHLEN]; char zip_path[MAXPATHLEN]; /* * scan the man section directory for pages */ npages = scandir(section, &entries, NULL, alphasort); if (npages < 0) { warn("%s/%s", mandir, section); exit_code = 1; return; } if (verbose || rm_junk) { /* * Maintain a list of all cat pages that should exist, * corresponding to existing man pages. */ expected = (char **) calloc(npages, sizeof(char *)); } for (i = 0; i < npages; free(entries[i++])) { page_name = entries[i]->d_name; snprintf(page_path, sizeof page_path, "%s/%s", section, page_name); if (!is_manpage_name(page_name)) { if (!(test_path(page_path, NULL) & TEST_DIR)) { junk(mandir, page_path, "invalid man page name"); } continue; } zipped = is_bzipped(page_name) ? BZIP : is_gzipped(page_name) ? GZIP : NONE; if (zipped != NONE) { snprintf(cat_path, sizeof cat_path, "%s/%s", cat_section, page_name); if (expected != NULL) expected[nexpected++] = strdup(page_name); process_page(mandir, page_path, cat_path, zipped); } else { /* * We've got an uncompressed man page, * check to see if there's a (preferred) * compressed one. */ snprintf(zip_path, sizeof zip_path, "%s%s", page_path, GZ_EXT); if (test_path(zip_path, NULL) != 0) { junk(mandir, page_path, "man page unused due to existing " GZ_EXT); } else { if (verbose) { fprintf(stderr, "warning, %s is uncompressed\n", page_path); } snprintf(cat_path, sizeof cat_path, "%s/%s", cat_section, page_name); if (expected != NULL) { asprintf(&expected[nexpected++], "%s", page_name); } process_page(mandir, page_path, cat_path, NONE); } } } free(entries); if (expected == NULL) return; /* * scan cat sections for junk */ npages = scandir(cat_section, &entries, NULL, alphasort); e = 0; for (i = 0; i < npages; free(entries[i++])) { const char *junk_reason; int cmp = 1; page_name = entries[i]->d_name; if (strcmp(page_name, ".") == 0 || strcmp(page_name, "..") == 0) continue; /* * Keep the index into the expected cat page list * ahead of the name we've found. */ while (e < nexpected && (cmp = strcmp(page_name, expected[e])) > 0) free(expected[e++]); if (cmp == 0) continue; /* we have an unexpected page */ snprintf(cat_path, sizeof cat_path, "%s/%s", cat_section, page_name); if (!is_manpage_name(page_name)) { if (test_path(cat_path, NULL) & TEST_DIR) continue; junk_reason = "invalid cat page name"; } else if (!is_gzipped(page_name) && e + 1 < nexpected && strncmp(page_name, expected[e + 1], strlen(page_name)) == 0 && strlen(expected[e + 1]) == strlen(page_name) + 3) { junk_reason = "cat page unused due to existing " GZ_EXT; } else junk_reason = "cat page without man page"; junk(mandir, cat_path, junk_reason); } free(entries); while (e < nexpected) free(expected[e++]); free(expected); }
double SlaveBoundaryVertices::loop_over_mesh( Mesh* mesh, MeshDomain* domain, const Settings* settings, MsqError& err ) { if (settings->get_slaved_ho_node_mode() != Settings::SLAVE_CALCULATED) { MSQ_SETERR(err)("Request to calculate higher-order node slaved status " "when Settings::get_get_slaved_ho_node_mode() " "!= SLAVE_CALCUALTED", MsqError::INVALID_STATE); return 0.0; } // If user said that we should treat fixed vertices as the // boundary, but specified that fixed vertices are defined // by the dimension of their geometric domain, then just // do distance from the geometric domain. int dim = this->domainDoF; if (dim >= 4 && settings->get_fixed_vertex_mode() != Settings::FIXED_FLAG) dim = settings->get_fixed_vertex_mode(); // Create a map to contain vertex depth. Intiliaze all to // elemDepth+1. std::vector<Mesh::VertexHandle> vertices; mesh->get_all_vertices( vertices, err ); MSQ_ERRZERO(err); if (vertices.empty()) return 0.0; std::sort( vertices.begin(), vertices.end() ); std::vector<unsigned short> depth( vertices.size(), elemDepth+1 ); BoolArr fixed( vertices.size() ); mesh->vertices_get_fixed_flag( &vertices[0], fixed.mArray, vertices.size(), err ); MSQ_ERRZERO(err); // Initialize map with boundary vertices. if (dim >= 4) { for(size_t i = 0; i < vertices.size(); ++i) if (fixed[i]) depth[i] = 0; } else { if (!domain) { MSQ_SETERR(err)("Request to calculate higher-order node slaved status " "by distance from bounding domain without a domain.", MsqError::INVALID_STATE); return 0.0; } std::vector<unsigned short> dof( vertices.size() ); domain->domain_DoF( &vertices[0], &dof[0], vertices.size(), err ); MSQ_ERRZERO(err); for (size_t i = 0; i < vertices.size(); ++i) if (dof[i] <= dim) depth[i] = 0; } // Now iterate over elements repeatedly until we've found all of the // elements near the boundary. This could be done much more efficiently // using vertex-to-element adjacencies, but it is to common for // applications not to implement that unless doing relaxation smoothing. // This is O(elemDepth * elements.size() * ln(vertices.size())); std::vector<Mesh::ElementHandle> elements; std::vector<Mesh::ElementHandle>::const_iterator j, k; std::vector<Mesh::VertexHandle> conn; std::vector<size_t> junk(2); mesh->get_all_elements( elements, err ); MSQ_ERRZERO(err); if (elements.empty()) return 0.0; bool some_changed; do { some_changed = false; for (j = elements.begin(); j != elements.end(); ++j) { conn.clear(); junk.clear(); mesh->elements_get_attached_vertices( &*j, 1, conn, junk, err ); MSQ_ERRZERO(err); unsigned short elem_depth = elemDepth+1; for (k = conn.begin(); k != conn.end(); ++k) { size_t i = std::lower_bound( vertices.begin(), vertices.end(), *k ) - vertices.begin(); if (i == vertices.size()) { MSQ_SETERR(err)("Invalid vertex handle in element connectivity list.", MsqError::INVALID_MESH); return 0.0; } if (depth[i] < elem_depth) elem_depth = depth[i]; } if (elem_depth == elemDepth+1) continue; ++elem_depth; for (k = conn.begin(); k != conn.end(); ++k) { size_t i = std::lower_bound( vertices.begin(), vertices.end(), *k ) - vertices.begin(); if (depth[i] > elem_depth) { depth[i] = elem_depth; some_changed = true; } } } // for(elements) } while (some_changed); // Now remove any corner vertices from the slaved set std::vector<Mesh::VertexHandle>::iterator p; std::vector<EntityTopology> types(elements.size()); mesh->elements_get_topologies( &elements[0], &types[0], elements.size(), err ); MSQ_ERRZERO(err); for (j = elements.begin(); j != elements.end(); ++j) { const unsigned corners = TopologyInfo::corners(types[j-elements.begin()]); conn.clear(); junk.clear(); mesh->elements_get_attached_vertices( &*j, 1, conn, junk, err ); MSQ_ERRZERO(err); for (unsigned i = 0; i < corners; ++i) { p = std::lower_bound( vertices.begin(), vertices.end(), conn[i] ); depth[p-vertices.begin()] = 0; } } // Now mark all vertices *not* within specified depth as slave vertices. std::vector<unsigned char> bytes( vertices.size() ); mesh->vertices_get_byte( &vertices[0], &bytes[0], vertices.size(), err ); MSQ_ERRZERO(err); for (size_t i = 0; i < vertices.size(); ++i) { if (depth[i] <= elemDepth || fixed[i]) bytes[i] &= ~MsqVertex::MSQ_DEPENDENT; else bytes[i] |= MsqVertex::MSQ_DEPENDENT; } mesh->vertices_set_byte( &vertices[0], &bytes[0], vertices.size(), err ); MSQ_ERRZERO(err); return 0.0; }