string finger_user(string who) { object link, body; mixed tmp1, tmp2, tmp3, tmp4, tmp5; string msg; mapping mail_stat; int hibernate; link = restore_data(who); if (link) body = restore_body(who); if (!link || !body) { if (sscanf(who, "(%s)", who)) return finger_group(who); return "Finger: There is no such user.\n"; } msg = LINE1; // Line 1: Fingerguy the Utter Novice (Chaotic Neutral) if (link->query("wizard")) { string al, title = body->getenv( "TITLE" ); al = body->query("al_title"); if (!al || al=="") { msg += body->query_title() + "\n"; } else { if (!title) title = "$N the New Wizard ($A)"; title = replace_string(title, "$N", body->query("cap_name")); title = replace_string(title, "$A", al); msg += title + "\n"; } } else msg += body->query_title() + "\n"; // Line 2: Male Human Mage [Level 5] // or: Male Human Necromancer [Lesser Power of Prime] msg += capitalize(body->query("gender")); msg += " "+capitalize(body->query("race")); mail_stat = link->query("Class"); if (mail_stat) { tmp1 = (values(mail_stat))[0]; msg += ( " " + capitalize(tmp1) ); } if (wizardp(TP)) { if (link->query("wizard")) { if (member_group(body->query("name"), "ambassador")) { tmp1 = "Ambassador"; tmp2 = body->query("ambassador"); if ((tmp2 != 0) && (tmp2 != "")) tmp1 = tmp1 + " of " + capitalize(tmp2); } else { tmp1 = DOMAIN_D->query_domain(link); tmp2 = DOMAIN_D->query_domain_level(link); if ((tmp1 == 0) || (tmp1 == "")) tmp1 = "Domainless "+tmp2; else tmp1 = tmp2 + " of " + tmp1 + " Domain"; } } else { tmp1 = "Level " + link->query("level"); } tmp1 = " [" + tmp1 + "]\n"; msg += tmp1; } else msg += "\n"; // Line 3: Gang allegience: The Machiavellian Menagerie // or: The Admin (Leader) tmp1 = "Gang allegience: "; tmp2 = body->query("gang"); if (tmp2) { mail_stat = GANG_D->get_list_map(); if (mail_stat[tmp2] == body->query("name")) tmp1 += "Leader of "+cap_all_words(tmp2); else tmp1 += "Member of "+cap_all_words(tmp2); } else { tmp1 += "none"; } msg += tmp1 + "\n"; // Line 4 : Married to Whoever tmp1 = body->query("spouse"); if (tmp1) { tmp1 = capitalize(tmp1); msg += "Married to "+tmp1+"\n"; } // Line 5 : A cool line to make it all very pretty. msg += LINE2; // Line 6: In Real Life: Matthew A. Titmus // or: In Real Life: ? tmp2 = "In Real Life: "; if (tmp3 = (string)link->RNAME) tmp2 += extract(tmp3, 0, 22); else tmp2 += "?"; msg += "Status: "; if (member_group(body->query("name"), "root")) msg += "Administrator\n"; else if (member_group(body->query("name"), "adminaccess")) msg += "Elder\n"; else if (member_group(body->query("name"), "ambassador")) msg += "Ambassador\n"; else if (link->query("wizard")) msg += "Immortal\n"; else msg += "Player\n"; if (body->query("email_visible")) tmp1 = "[Public]"; else tmp1 = "[Private]"; if (adminp(TP) || body->query("name")==TP->query("name")) { tmp1 = (string)link->query("email")+" "+tmp1; } else { if (body->query("email_visible")) { tmp1 = (string)link->query("email"); } else { tmp1 = "[Private]"; } } if (tmp1) msg += "Email address: " + tmp1 + "\n"; tmp1 = (string)link->query("URL"); if (tmp1) msg += "URL: " + tmp1 + "\n"; hibernate = (int)link->query("hibernate"); if (hibernate && time() < hibernate) msg += "\n\t[In hibernation until " + ctime(hibernate) + "]\n\n"; tmp1 = find_player(who); if (tmp1) { if (!filter_users(tmp1)) tmp1 = 0; } if (!link->query("last_on")) msg += (tmp1 ? "On since: " : "Last on: ") + "Unavailable"; else msg += ((tmp1 && !tmp1->query("npc")) ? "On since: " : "Last on: ") + ctime((int)link->query("last_on")) ; if (wizardp(TP)) msg += ( " from " + (string)link->query("ip") + " \n" ); else msg += "\n"; if (tmp1) { tmp1 = query_idle_string(tmp1, 1); if (strlen(tmp1) > 0) msg += tmp1 + "\n"; } mail_stat = (mapping)MAILBOX_D->mail_status(who); if (mail_stat["unread"]) msg += sprintf("%s has not read %d of their %d piece%s of mail.\n", capitalize(who), mail_stat["unread"], mail_stat["total"], (mail_stat["total"] == 1 ? "" : "s")); else { msg += "No unread mail" ; if(this_player()) { if (adminp(getuid(this_player()))) { // msg += " ("+mail_stat["total"]+" pieces)" ; msg += sprintf(" (%d piece%s)", mail_stat["total"], (mail_stat["total"] == 1 ? "" : "s")); } } msg += ".\n" ; } if (link->query("wizard")) { tmp1 = user_path(who) + ".project"; if (file_size(tmp1) >= 0) msg += "Project: " + read_file(tmp1); tmp1 = user_path(who) + ".plan"; if (file_size(tmp1) >= 0) { msg += "Plan:\n" + read_file(tmp1); } else { msg += "No Plan.\n"; } } else { if (body->query("session")) tmp1 = iwrap("Session: "+body->query("session")); else tmp1 = "No Session.\n"; msg += tmp1; } msg += LINE1; if (!find_player(who) || !interactive(find_player(who))) { link->remove(); // Some names like .foo weren't getting away. if(link) destruct(link); if(link) log_file("fingerdest",sprintf("Connection of %s not "+ "dested by finger daemon, on %s.\n", link->query("name"), ctime(time()))); if(body) destruct(body); if(body) log_file("fingerdest",sprintf("Connection of %s not "+ "dested by finger daemon, on %s.\n", body->query("name"), ctime(time()))); } return "\n" + msg + "\n"; }
void network_thread () { /* * We loop forever waiting on either data from the ppp drivers or from * our network socket. Control handling is no longer done here. */ struct sockaddr_in from; struct in_pktinfo to; unsigned int fromlen; int tunnel, call; /* Tunnel and call */ int recvsize; /* Length of data received */ struct buffer *buf; /* Payload buffer */ struct call *c, *sc; /* Call to send this off to */ struct tunnel *st; /* Tunnel */ fd_set readfds; /* Descriptors to watch for reading */ int max; /* Highest fd */ struct timeval tv, *ptv; /* Timeout for select */ struct msghdr msgh; struct iovec iov; char cbuf[256]; unsigned int refme, refhim; int * currentfd; int server_socket_processed; /* This one buffer can be recycled for everything except control packets */ buf = new_buf (MAX_RECV_SIZE); tunnel = 0; call = 0; for (;;) { int ret; process_signal(); max = build_fdset (&readfds); ptv = process_schedule(&tv); ret = select (max + 1, &readfds, NULL, NULL, ptv); if (ret <= 0) { if (ret == 0) { if (gconfig.debug_network) { l2tp_log (LOG_DEBUG, "%s: select timeout\n", __FUNCTION__); } } else { if (gconfig.debug_network) { l2tp_log (LOG_DEBUG, "%s: select returned error %d (%s)\n", __FUNCTION__, errno, strerror (errno)); } } continue; } if (FD_ISSET (control_fd, &readfds)) { do_control (); } server_socket_processed = 0; currentfd = NULL; st = tunnels.head; while (st || !server_socket_processed) { if (st && (st->udp_fd == -1)) { st=st->next; continue; } if (st) { currentfd = &st->udp_fd; } else { currentfd = &server_socket; server_socket_processed = 1; } if (FD_ISSET (*currentfd, &readfds)) { /* * Okay, now we're ready for reading and processing new data. */ recycle_buf (buf); /* Reserve space for expanding payload packet headers */ buf->start += PAYLOAD_BUF; buf->len -= PAYLOAD_BUF; memset(&from, 0, sizeof(from)); memset(&to, 0, sizeof(to)); fromlen = sizeof(from); memset(&msgh, 0, sizeof(struct msghdr)); iov.iov_base = buf->start; iov.iov_len = buf->len; msgh.msg_control = cbuf; msgh.msg_controllen = sizeof(cbuf); msgh.msg_name = &from; msgh.msg_namelen = fromlen; msgh.msg_iov = &iov; msgh.msg_iovlen = 1; msgh.msg_flags = 0; /* Receive one packet. */ recvsize = recvmsg(*currentfd, &msgh, 0); if (recvsize < MIN_PAYLOAD_HDR_LEN) { if (recvsize < 0) { if (errno == ECONNREFUSED) { close(*currentfd); } if ((errno == ECONNREFUSED) || (errno == EBADF)) { *currentfd = -1; } if (errno != EAGAIN) l2tp_log (LOG_WARNING, "%s: recvfrom returned error %d (%s)\n", __FUNCTION__, errno, strerror (errno)); } else { l2tp_log (LOG_WARNING, "%s: received too small a packet\n", __FUNCTION__); } continue; } refme=refhim=0; struct cmsghdr *cmsg; /* Process auxiliary received data in msgh */ for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL; cmsg = CMSG_NXTHDR(&msgh,cmsg)) { /* extract destination(our) addr */ if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_PKTINFO) { struct in_pktinfo* pktInfo = ((struct in_pktinfo*)CMSG_DATA(cmsg)); to = *pktInfo; } /* extract IPsec info out */ else if (gconfig.ipsecsaref && cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == gconfig.sarefnum) { unsigned int *refp; refp = (unsigned int *)CMSG_DATA(cmsg); refme =refp[0]; refhim=refp[1]; } } /* * some logic could be added here to verify that we only * get L2TP packets inside of IPsec, or to provide different * classes of service to packets not inside of IPsec. */ buf->len = recvsize; fix_hdr (buf->start); extract (buf->start, &tunnel, &call); if (gconfig.debug_network) { l2tp_log(LOG_DEBUG, "%s: recv packet from %s, size = %d, " "tunnel = %d, call = %d ref=%u refhim=%u\n", __FUNCTION__, inet_ntoa (from.sin_addr), recvsize, tunnel, call, refme, refhim); } if (gconfig.packet_dump) { do_packet_dump (buf); } if (! (c = get_call (tunnel, call, from.sin_addr, from.sin_port, refme, refhim))) { if ((c = get_tunnel (tunnel, from.sin_addr.s_addr, from.sin_port))) { /* * It is theoretically possible that we could be sent * a control message (say a StopCCN) on a call that we * have already closed or some such nonsense. To * prevent this from closing the tunnel, if we get a * call on a valid tunnel, but not with a valid CID, * we'll just send a ZLB to ack receiving the packet. */ if (gconfig.debug_tunnel) l2tp_log (LOG_DEBUG, "%s: no such call %d on tunnel %d. Sending special ZLB\n", __FUNCTION__); handle_special (buf, c, call); /* get a new buffer */ buf = new_buf (MAX_RECV_SIZE); } else l2tp_log (LOG_DEBUG, "%s: unable to find call or tunnel to handle packet. call = %d, tunnel = %d Dumping.\n", __FUNCTION__, call, tunnel); } else { if (c->container) { c->container->my_addr = to; } buf->peer = from; /* Handle the packet */ c->container->chal_us.vector = NULL; if (handle_packet (buf, c->container, c)) { if (gconfig.debug_tunnel) l2tp_log (LOG_DEBUG, "%s: bad packet\n", __FUNCTION__); }; if (c->cnu) { /* Send Zero Byte Packet */ control_zlb (buf, c->container, c); c->cnu = 0; } }; } if (st) st=st->next; } /* * finished obvious sources, look for data from PPP connections. */ st = tunnels.head; while (st) { sc = st->call_head; while (sc) { if ((sc->fd >= 0) && FD_ISSET (sc->fd, &readfds)) { /* Got some payload to send */ int result; recycle_payload (buf, sc->container->peer); /* #ifdef DEBUG_FLOW_MORE l2tp_log (LOG_DEBUG, "%s: rws = %d, pSs = %d, pLr = %d\n", __FUNCTION__, sc->rws, sc->pSs, sc->pLr); #endif if ((sc->rws>0) && (sc->pSs > sc->pLr + sc->rws) && !sc->rbit) { #ifdef DEBUG_FLOW log(LOG_DEBUG, "%s: throttling payload (call = %d, tunnel = %d, Lr = %d, Ss = %d, rws = %d)!\n",__FUNCTION__, sc->cid, sc->container->tid, sc->pLr, sc->pSs, sc->rws); #endif sc->throttle = -1; We unthrottle in handle_packet if we get a payload packet, valid or ZLB, but we also schedule a dethrottle in which case the R-bit will be set FIXME: Rate Adaptive timeout? tv.tv_sec = 2; tv.tv_usec = 0; sc->dethrottle = schedule(tv, dethrottle, sc); } else */ /* while ((result=read_packet(buf,sc->fd,sc->frame & SYNC_FRAMING))>0) { */ while ((result = read_packet (buf, sc->fd, SYNC_FRAMING)) > 0) { add_payload_hdr (sc->container, sc, buf); if (gconfig.packet_dump) { do_packet_dump (buf); } sc->prx = sc->data_rec_seq_num; if (sc->zlb_xmit) { deschedule (sc->zlb_xmit); sc->zlb_xmit = NULL; } sc->tx_bytes += buf->len; sc->tx_pkts++; udp_xmit (buf, st); recycle_payload (buf, sc->container->peer); } if (result != 0) { l2tp_log (LOG_WARNING, "%s: tossing read packet, error = %s (%d). Closing call.\n", __FUNCTION__, strerror (-result), -result); strcpy (sc->errormsg, strerror (-result)); sc->needclose = -1; } } sc = sc->next; } st = st->next; } } }
JViewObj* JFocusSet::operator[](JViewObj& obj) { return extract(children[obj]);}
/* * Main loop: open the zipfile, iterate over its contents and decide what * to do with each entry. */ static void unzip(const char *fn) { struct archive *a; struct archive_entry *e; int fd, ret; uintmax_t total_size, file_count, error_count; if (strcmp(fn, "-") == 0) fd = STDIN_FILENO; else if ((fd = open(fn, O_RDONLY)) < 0) error("%s", fn); if ((a = archive_read_new()) == NULL) error("archive_read_new failed"); ac(archive_read_support_format_zip(a)); ac(archive_read_open_fd(a, fd, 8192)); if (!zipinfo_mode) { if (!p_opt && !q_opt) printf("Archive: %s\n", fn); if (v_opt == 1) { printf(" Length Date Time Name\n"); printf(" -------- ---- ---- ----\n"); } else if (v_opt == 2) { printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); printf("-------- ------ ------- ----- ---- ---- ------ ----\n"); } } total_size = 0; file_count = 0; error_count = 0; for (;;) { ret = archive_read_next_header(a, &e); if (ret == ARCHIVE_EOF) break; ac(ret); if (!zipinfo_mode) { if (t_opt) error_count += test(a, e); else if (v_opt) list(a, e); else if (p_opt || c_opt) extract_stdout(a, e); else extract(a, e); } else { if (Z1_opt) list(a, e); } total_size += archive_entry_size(e); ++file_count; } if (zipinfo_mode) { if (v_opt == 1) { printf(" -------- -------\n"); printf(" %8ju %ju file%s\n", total_size, file_count, file_count != 1 ? "s" : ""); } else if (v_opt == 2) { printf("-------- ------- --- -------\n"); printf("%8ju %7ju 0%% %ju file%s\n", total_size, total_size, file_count, file_count != 1 ? "s" : ""); } } ac(archive_read_close(a)); (void)archive_read_finish(a); if (fd != STDIN_FILENO && close(fd) != 0) error("%s", fn); if (t_opt) { if (error_count > 0) { errorx("%d checksum error(s) found.", error_count); } else { printf("No errors detected in compressed data of %s.\n", fn); } } }
int GzippedFileReader::_ReadSync(void* pBuffer, PX_off_t offset, uint bytesToRead) { if (!OkIndex()) return -1; // Without all the caching, chunking and states, this would be enough: // return extract(m_src, m_pIndex, offset, (unsigned char*)pBuffer, bytesToRead); // Split request to GZFILE_READ_CHUNK_SIZE chunks at GZFILE_READ_CHUNK_SIZE boundaries uint maxInChunk = GZFILE_READ_CHUNK_SIZE - offset % GZFILE_READ_CHUNK_SIZE; if (bytesToRead > maxInChunk) { int first = _ReadSync(pBuffer, offset, maxInChunk); if (first != maxInChunk) return first; // EOF or failure int rest = _ReadSync((char*)pBuffer + maxInChunk, offset + maxInChunk, bytesToRead - maxInChunk); if (rest < 0) return rest; return first + rest; } // From here onwards it's guarenteed that the request is inside a single GZFILE_READ_CHUNK_SIZE boundaries int res = m_cache.Read(pBuffer, offset, bytesToRead); if (res >= 0) return res; // Not available from cache. Decompress from optimal starting // point in GZFILE_READ_CHUNK_SIZE chunks and cache each chunk. PTT s = NOW(); PX_off_t extractOffset = GetOptimalExtractionStart(offset); // guaranteed in GZFILE_READ_CHUNK_SIZE boundaries int size = offset + maxInChunk - extractOffset; unsigned char* extracted = (unsigned char*)malloc(size); int span = m_pIndex->span; int spanix = extractOffset / span; AsyncPrefetchCancel(); res = extract(m_src, m_pIndex, extractOffset, extracted, size, &(m_zstates[spanix].state)); if (res < 0) { free(extracted); return res; } AsyncPrefetchChunk(getInOffset(&(m_zstates[spanix].state))); int copied = ChunksCache::CopyAvailable(extracted, extractOffset, res, pBuffer, offset, bytesToRead); if (m_zstates[spanix].state.isValid && (extractOffset + res) / span != offset / span) { // The state no longer matches this span. // move the state to the appropriate span because it will be faster than using the index int targetix = (extractOffset + res) / span; m_zstates[targetix].Kill(); m_zstates[targetix] = m_zstates[spanix]; // We have elements for the entire file, and another one. m_zstates[spanix].state.isValid = 0; // Not killing because we need the state. } if (size <= GZFILE_READ_CHUNK_SIZE) m_cache.Take(extracted, extractOffset, res, size); else { // split into cacheable chunks for (int i = 0; i < size; i += GZFILE_READ_CHUNK_SIZE) { int available = CLAMP(res - i, 0, GZFILE_READ_CHUNK_SIZE); void* chunk = available ? malloc(available) : 0; if (available) memcpy(chunk, extracted + i, available); m_cache.Take(chunk, extractOffset + i, available, std::min(size - i, GZFILE_READ_CHUNK_SIZE)); } free(extracted); } int duration = NOW() - s; if (duration > 10) Console.WriteLn(Color_Gray, L"gunzip: chunk #%5d-%2d : %1.2f MB - %d ms", (int)(offset / 4 / 1024 / 1024), (int)(offset % (4 * 1024 * 1024) / GZFILE_READ_CHUNK_SIZE), (float)size / 1024 / 1024, duration); return copied; }
GT PFC::multi_miller(int n,G2** QQ,G1** PP) { GT z; ZZn *Px,*Py; int i,j,*k,nb; ECn3 *Q,*A; ECn P; ZZn6 res; Big X=*x; Px=new ZZn[n]; Py=new ZZn[n]; Q=new ECn3[n]; A=new ECn3[n]; k=new int[n]; nb=bits(X); res=1; for (j=0;j<n;j++) { k[j]=0; P=PP[j]->g; normalise(P); Q[j]=QQ[j]->g; extract(P,Px[j],Py[j]); Px[j]+=Px[j]; Py[j]+=Py[j]; } for (j=0;j<n;j++) { #ifdef MR_ECN3_PROJECTIVE Q[j].norm(); #endif A[j]=Q[j]; } for (i=nb-2;i>=0;i--) { res*=res; for (j=0;j<n;j++) { if (QQ[j]->ptable==NULL) res*=g(A[j],A[j],Px[j],Py[j]); else res*=gp(QQ[j]->ptable,k[j],Px[j],Py[j]); } if (bit(X,i)==1) for (j=0;j<n;j++) { if (QQ[j]->ptable==NULL) res*=g(A[j],Q[j],Px[j],Py[j]); else res*=gp(QQ[j]->ptable,k[j],Px[j],Py[j]); } if (res.iszero()) return 0; } delete [] k; delete [] A; delete [] Q; delete [] Py; delete [] Px; z.g=res; return z; }
int ag_extract(unsigned dbh, int attr, int val, char *buf, int maxsz) { return extract(h2p(dbh),attr,val,buf,maxsz); }
/** * get_health function * @param *data Pointer of the 1st subframe * @return Value of the SV Health, no units */ unsigned short get_health(char * data) { char tmp[7]; extract(data,76,81,tmp); return bin2dec(tmp); }
/** * get_toc function * @param *data Pointer of the 1st subframe * @return Value of the Reference time clock, seconds */ double get_toc(char * data) { char tmp[17]; extract(data,218,233,tmp); return bin2dec(tmp) * 16; // scale factor }
/** * get_cl2 function * @param *data Pointer of the 1st subframe * @return Value of the code on L2, no units */ unsigned short get_cl2(char * data) { char tmp[3]; extract(data,70,71,tmp); return bin2dec(tmp); }
/** * get_ura function * @param *data Pointer of the 1st subframe * @return Value of the SV range accuracy, in week */ unsigned short get_ura(char * data) { char tmp[5]; extract(data,72,75,tmp); return bin2dec(tmp); }
/** * get_subfrID function * @param *data Pointer of the navigation data * @return ID of the subframe */ unsigned short get_subfrID(char * data) { char tmp[4]; extract(data,49,51,tmp); return bin2dec(tmp); }
/** * get_tow function * @param *data Pointer of the 1st subframe * @return Value of the Time of week, in seconds */ int get_tow(char * data) { char tmp[18]; extract(data,30,46,tmp); return bin2dec(tmp)*6; // *4*1.5 IS-GPS-200E : Figure 3-16. Time Line Relationship of HOW Message }
string finger_group(string group) { int i, j; string msg; object link; mixed tmp1, tmp2, tmp3, tmp4, tmp5; string *group2; groups = master()->query_groups(); if (!group || undefinedp(groups[group])) return "Finger: There is no such group.\n"; /* * special case: filter root members out of admin group */ // if (group == "admin") // groups["admin"] = filter_array(groups["admin"], "filter_root", this_object()); group2 = groups[group]; j = group2 ? sizeof(group2) : 0; msg = LINE1; if (j == 0) { msg += "[" + capitalize(mud_name()) + "] No members of " + capitalize(group) + " group (" + ctime(time()) + ").\n"; } else { msg += "[" + capitalize(mud_name()) + "] " + j + (j == 1 ? " user" : " users") + " " + "in " + capitalize(group) + " group (" + ctime(time()) + ").\n"; msg += LINE2; msg += sprintf("%-12s%-20s%-14s%-28s", "Login", "Real Name", "Domain", "On\n"); msg += LINE2; group2 = sort_array(group2, "do_alpha", this_object()); for (i = 0; i < j; i++) { tmp1 = group2[i]; /* logid id */ link = find_player(tmp1); if (link) link = link->query_link(); else link = restore_data(tmp1); if (!link) continue; /* no such user */ tmp2 = (string)link->RNAME; /* real name */ tmp3 = DOMAIN_D->query_domain(link); if ((tmp3 == 0) || (tmp3 == "")) tmp3 = "None"; tmp4 = find_player(tmp1); if (!tmp4 || !filter_users(tmp4)) tmp5 = "Last "; else tmp5 = "Since "; if (!link->query("last_on")) tmp5 += "(Unavailable)"; else tmp5 += ctime((int)link->query("last_on")); msg += sprintf("%-12s%-20s%-14s%28s", capitalize((string)tmp1), capitalize(extract((string)tmp2, 0, 18)), capitalize((string)tmp3), (string)tmp5 + "\n"); if (!find_player(tmp1)) { link->remove(); } } } return msg + LINE1; }
inline Try<Nothing> FlagsBase::load(const std::string& prefix) { return load(extract(prefix)); }
/** * get_iode_s2 function * @param *data Pointer of the 2nd subframe * @return Value of the Issue of Data, Ephemeris -on subframe 2, no units */ unsigned short get_iode_s2(char * data) { char tmp[9]; extract(data,60,67,tmp); return bin2dec(tmp); }
inline Try<Nothing> FlagsBase::load( const Option<std::string>& prefix, int* argc, char*** argv, bool unknowns, bool duplicates) { std::map<std::string, Option<std::string> > values; if (prefix.isSome()) { values = extract(prefix.get()); } // Keep the arguments that are not being processed as flags. std::vector<char*> args; // Read flags from the command line. for (int i = 1; i < *argc; i++) { const std::string arg(strings::trim((*argv)[i])); // Stop parsing flags after '--' is encountered. if (arg == "--") { // Save the rest of the arguments. for (int j = i + 1; j < *argc; j++) { args.push_back((*argv)[j]); } break; } // Skip anything that doesn't look like a flag. if (arg.find("--") != 0) { args.push_back((*argv)[i]); continue; } std::string name; Option<std::string> value = None(); size_t eq = arg.find_first_of("="); if (eq == std::string::npos && arg.find("--no-") == 0) { // --no-name name = arg.substr(2); } else if (eq == std::string::npos) { // --name name = arg.substr(2); } else { // --name=value name = arg.substr(2, eq - 2); value = arg.substr(eq + 1); } name = strings::lower(name); if (!duplicates) { if (values.count(name) > 0 || (name.find("no-") == 0 && values.count(name.substr(3)) > 0)) { return Error("Duplicate flag '" + name + "' on command line"); } } values[name] = value; } Try<Nothing> result = load(values, unknowns); // Update 'argc' and 'argv' if we successfully loaded the flags. if (!result.isError()) { CHECK_LE(args.size(), (size_t) *argc); size_t i = 1; // Start at '1' to skip argv[0]. foreach (char* arg, args) { (*argv)[i++] = arg; } *argc = i; // Now null terminate the array. Note that we'll "leak" the // arguments that were processed here but it's not like they would // have gotten deleted in normal operations anyway. (*argv)[i++] = NULL; }
/** * get_toe function * @param *data Pointer of the 2nd subframe * @return Value of the Reference time ephemeris, seconds */ int get_toe(char * data) { char tmp[17]; extract(data,270,285,tmp); return bin2dec(tmp) * 16; // scale factor }
GT PFC::multi_miller(int n,G2** QQ,G1** PP) { GT z; ZZn *Px,*Py; int i,j,*k,nb; ECn2 *Q,*A; ECn P; ZZn12 res; Big m; Big X=*x; Px=new ZZn[n]; Py=new ZZn[n]; Q=new ECn2[n]; A=new ECn2[n]; k=new int[n]; if (X<0) m=-(6*X+2); else m=6*X+2; nb=bits(m); res=1; for (j=0;j<n;j++) { k[j]=0; P=PP[j]->g; normalise(P); Q[j]=QQ[j]->g; Q[j].norm(); extract(P,Px[j],Py[j]); } for (j=0;j<n;j++) A[j]=Q[j]; for (i=nb-2;i>=0;i--) { res*=res; for (j=0;j<n;j++) { if (QQ[j]->ptable==NULL) res*=g(A[j],A[j],Px[j],Py[j]); else res*=gp(QQ[j]->ptable,k[j],Px[j],Py[j]); } if (bit(m,i)==1) for (j=0;j<n;j++) { if (QQ[j]->ptable==NULL) res*=g(A[j],Q[j],Px[j],Py[j]); else res*=gp(QQ[j]->ptable,k[j],Px[j],Py[j]); } if (res.iszero()) return 0; } if (X<0) res.conj(); for (j=0;j<n;j++) { q_power_frobenius(Q[j],*frob); if (QQ[j]->ptable==NULL) { if (X<0) A[j]=-A[j]; res*=g(A[j],Q[j],Px[j],Py[j]); } else res*=gp(QQ[j]->ptable,k[j],Px[j],Py[j]); q_power_frobenius(Q[j],*frob); if (QQ[j]->ptable==NULL) { Q[j]=-Q[j]; res*=g(A[j],Q[j],Px[j],Py[j]); } else res*=gp(QQ[j]->ptable,k[j],Px[j],Py[j]); } delete [] k; delete [] A; delete [] Q; delete [] Py; delete [] Px; z.g=res; return z; }
/** * get_ado function * @param *data Pointer of the 2nd subframe * @return Value of the Age of data offset, seconds */ unsigned short get_ado(char * data) { char tmp[6]; extract(data,287,291,tmp); return bin2dec(tmp) * 900; // scale factor }
void string_next_page(string str) { int num, noargs, i,j,k, redraw; string s1, s2, *s3, s4, s5; if (!str) str = ""; if (sscanf(str,"%d%s", num, str)!=2) noargs = 1; s1 = extract(str,1); str = extract(str,0,1); /* case statements WEEEEEE */ switch(str) { case "q" : if (finish_func) call_other(finish_ob, finish_func); finish_func = 0; return; case "" : case "f" : /* go on a number of pages... */ topl += ROWS; redraw = 1; break; case "/" : /* sigh */ i = topl+4; if (s1=="") s1 = last_search; if (!s1 || s1 == "") s1 = "bing!"; for (i=topl+4;i<fsize;i++) if (sscanf(the_bit[k],"%s"+s1+"%s",s4,s5)==2) if (num--<=0) break; if (i==fsize) write("Sorry "+s1+" not found.\n"); else topl = i-3; redraw = 1; break; case "?" : if (s1=="") s1 = last_search; if (!s1 || s1 == "") s1 = "bing!"; for (i=topl+2;i>0;i--) if (sscanf(the_bit[k],"%s"+s1+"%s",s4,s5)==2) if (num--<=0) break; if (i==fsize) write("Sorry "+s1+" not found.\n"); else topl = i-3; redraw = 1; break; case "b" : if (topl>0) { topl -= ROWS; redraw = 1; if (topl<0) topl = 0; } break; case "g" : topl = num; if (topl>=fsize) topl = fsize-2; redraw = 1; break; case "G" : redraw = 1; if (noargs) topl = fsize - ROWS; else topl = num; if (topl>fsize) topl = fsize-2; break; } if (redraw) string_display_file(); if (topl<fsize) { more_string_status_line(); input_to("string_next_page"); } else if (finish_func) { call_other(finish_ob, finish_func); finish_func = 0; } }
/** * get_iode_s3 function * @param *data Pointer of the 3rd subframe * @return Value of the Issue of Data, Ephemeris -on subframe 3, no units */ unsigned short get_iode_s3(char * data) { char tmp[9]; extract(data,270,277,tmp); return bin2dec(tmp); }
FILE * collect(struct header *hp, int printheaders) { FILE *fbuf; int lc, cc, escape, eofcount, fd, c, t; char linebuf[LINESIZE], tempname[PATHSIZE], *cp, getsub; sigset_t nset; int longline, lastlong, rc; /* So we don't make 2 or more lines out of a long input line. */ collf = NULL; /* * Start catching signals from here, but we're still die on interrupts * until we're in the main loop. */ sigemptyset(&nset); sigaddset(&nset, SIGINT); sigaddset(&nset, SIGHUP); sigprocmask(SIG_BLOCK, &nset, NULL); if ((saveint = signal(SIGINT, SIG_IGN)) != SIG_IGN) signal(SIGINT, collint); if ((savehup = signal(SIGHUP, SIG_IGN)) != SIG_IGN) signal(SIGHUP, collhup); savetstp = signal(SIGTSTP, collstop); savettou = signal(SIGTTOU, collstop); savettin = signal(SIGTTIN, collstop); if (setjmp(collabort) || setjmp(colljmp)) { rm(tempname); goto err; } sigprocmask(SIG_UNBLOCK, &nset, NULL); noreset++; snprintf(tempname, sizeof(tempname), "%s/mail.RsXXXXXXXXXX", tmpdir); if ((fd = mkstemp(tempname)) == -1 || (collf = Fdopen(fd, "w+")) == NULL) { warn("%s", tempname); goto err; } rm(tempname); /* * If we are going to prompt for a subject, * refrain from printing a newline after * the headers (since some people mind). */ t = GTO|GSUBJECT|GCC|GNL; getsub = 0; if (hp->h_subject == NULL && value("interactive") != NULL && (value("ask") != NULL || value("asksub") != NULL)) t &= ~GNL, getsub++; if (printheaders) { puthead(hp, stdout, t); fflush(stdout); } if ((cp = value("escape")) != NULL) escape = *cp; else escape = ESCAPE; eofcount = 0; hadintr = 0; lastlong = 0; longline = 0; if (!setjmp(colljmp)) { if (getsub) grabh(hp, GSUBJECT); } else { /* * Come here for printing the after-signal message. * Duplicate messages won't be printed because * the write is aborted if we get a SIGTTOU. */ cont: if (hadintr) { fflush(stdout); fprintf(stderr, "\n(Interrupt -- one more to kill letter)\n"); } else { printf("(continue)\n"); fflush(stdout); } } for (;;) { colljmp_p = 1; c = readline(stdin, linebuf, LINESIZE); colljmp_p = 0; if (c < 0) { if (value("interactive") != NULL && value("ignoreeof") != NULL && ++eofcount < 25) { printf("Use \".\" to terminate letter\n"); continue; } break; } lastlong = longline; longline = c == LINESIZE - 1; eofcount = 0; hadintr = 0; if (linebuf[0] == '.' && linebuf[1] == '\0' && value("interactive") != NULL && !lastlong && (value("dot") != NULL || value("ignoreeof") != NULL)) break; if (linebuf[0] != escape || value("interactive") == NULL || lastlong) { if (putline(collf, linebuf, !longline) < 0) goto err; continue; } c = linebuf[1]; switch (c) { default: /* * On double escape, just send the single one. * Otherwise, it's an error. */ if (c == escape) { if (putline(collf, &linebuf[1], !longline) < 0) goto err; else break; } printf("Unknown tilde escape.\n"); break; case 'C': /* * Dump core. */ core(); break; case '!': /* * Shell escape, send the balance of the * line to sh -c. */ shell(&linebuf[2]); break; case ':': case '_': /* * Escape to command mode, but be nice! */ execute(&linebuf[2], 1); goto cont; case '.': /* * Simulate end of file on input. */ goto out; case 'q': /* * Force a quit of sending mail. * Act like an interrupt happened. */ hadintr++; collint(SIGINT); exit(1); case 'x': /* * Exit, do not save in dead.letter. */ goto err; case 'h': /* * Grab a bunch of headers. */ grabh(hp, GTO|GSUBJECT|GCC|GBCC); goto cont; case 't': /* * Add to the To list. */ hp->h_to = cat(hp->h_to, extract(&linebuf[2], GTO)); break; case 's': /* * Set the Subject line. */ cp = &linebuf[2]; while (isspace((unsigned char)*cp)) cp++; hp->h_subject = savestr(cp); break; case 'R': /* * Set the Reply-To line. */ cp = &linebuf[2]; while (isspace((unsigned char)*cp)) cp++; hp->h_replyto = savestr(cp); break; case 'c': /* * Add to the CC list. */ hp->h_cc = cat(hp->h_cc, extract(&linebuf[2], GCC)); break; case 'b': /* * Add to the BCC list. */ hp->h_bcc = cat(hp->h_bcc, extract(&linebuf[2], GBCC)); break; case 'i': case 'A': case 'a': /* * Insert named variable in message. */ switch(c) { case 'i': cp = &linebuf[2]; while(isspace((unsigned char)*cp)) cp++; break; case 'a': cp = "sign"; break; case 'A': cp = "Sign"; break; default: goto err; } if(*cp != '\0' && (cp = value(cp)) != NULL) { printf("%s\n", cp); if(putline(collf, cp, 1) < 0) goto err; } break; case 'd': /* * Read in the dead letter file. */ if (strlcpy(linebuf + 2, getdeadletter(), sizeof(linebuf) - 2) >= sizeof(linebuf) - 2) { printf("Line buffer overflow\n"); break; } /* FALLTHROUGH */ case 'r': case '<': /* * Invoke a file: * Search for the file name, * then open it and copy the contents to collf. */ cp = &linebuf[2]; while (isspace((unsigned char)*cp)) cp++; if (*cp == '\0') { printf("Interpolate what file?\n"); break; } cp = expand(cp); if (cp == NULL) break; if (*cp == '!') { /* * Insert stdout of command. */ char *sh; int nullfd, tempfd, rc; char tempname2[PATHSIZE]; if ((nullfd = open("/dev/null", O_RDONLY, 0)) == -1) { warn("/dev/null"); break; } snprintf(tempname2, sizeof(tempname2), "%s/mail.ReXXXXXXXXXX", tmpdir); if ((tempfd = mkstemp(tempname2)) == -1 || (fbuf = Fdopen(tempfd, "w+")) == NULL) { warn("%s", tempname2); break; } unlink(tempname2); if ((sh = value("SHELL")) == NULL) sh = _PATH_CSHELL; rc = run_command(sh, 0, nullfd, fileno(fbuf), "-c", cp+1, NULL); close(nullfd); if (rc < 0) { Fclose(fbuf); break; } if (fsize(fbuf) == 0) { fprintf(stderr, "No bytes from command \"%s\"\n", cp+1); Fclose(fbuf); break; } rewind(fbuf); } else if (isdir(cp)) { printf("%s: Directory\n", cp); break; } else if ((fbuf = Fopen(cp, "r")) == NULL) { warn("%s", cp); break; } printf("\"%s\" ", cp); fflush(stdout); lc = 0; cc = 0; while ((rc = readline(fbuf, linebuf, LINESIZE)) >= 0) { if (rc != LINESIZE - 1) lc++; if ((t = putline(collf, linebuf, rc != LINESIZE - 1)) < 0) { Fclose(fbuf); goto err; } cc += t; } Fclose(fbuf); printf("%d/%d\n", lc, cc); break; case 'w': /* * Write the message on a file. */ cp = &linebuf[2]; while (*cp == ' ' || *cp == '\t') cp++; if (*cp == '\0') { fprintf(stderr, "Write what file!?\n"); break; } if ((cp = expand(cp)) == NULL) break; rewind(collf); exwrite(cp, collf, 1); break; case 'm': case 'M': case 'f': case 'F': /* * Interpolate the named messages, if we * are in receiving mail mode. Does the * standard list processing garbage. * If ~f is given, we don't shift over. */ if (forward(linebuf + 2, collf, tempname, c) < 0) goto err; goto cont; case '?': if ((fbuf = Fopen(_PATH_TILDE, "r")) == NULL) { warn("%s", _PATH_TILDE); break; } while ((t = getc(fbuf)) != EOF) putchar(t); Fclose(fbuf); break; case 'p': /* * Print out the current state of the * message without altering anything. */ rewind(collf); printf("-------\nMessage contains:\n"); puthead(hp, stdout, GTO|GSUBJECT|GCC|GBCC|GNL); while ((t = getc(collf)) != EOF) putchar(t); goto cont; case '|': /* * Pipe message through command. * Collect output as new message. */ rewind(collf); mespipe(collf, &linebuf[2]); goto cont; case 'v': case 'e': /* * Edit the current message. * 'e' means to use EDITOR * 'v' means to use VISUAL */ rewind(collf); mesedit(collf, c); goto cont; } } goto out; err: if (collf != NULL) { Fclose(collf); collf = NULL; } out: if (collf != NULL) rewind(collf); noreset--; sigprocmask(SIG_BLOCK, &nset, NULL); signal(SIGINT, saveint); signal(SIGHUP, savehup); signal(SIGTSTP, savetstp); signal(SIGTTOU, savettou); signal(SIGTTIN, savettin); sigprocmask(SIG_UNBLOCK, &nset, NULL); return (collf); }
void DrawFace(TopoDS_Face face,void(*callbackfunc)(const double* x, const double* n), bool just_one_average_normal) { double x[9], n[9]; StdPrs_ToolShadedShape SST; // Get triangulation TopLoc_Location L; Handle_Poly_Triangulation facing = BRep_Tool::Triangulation(face,L); gp_Trsf tr = L; if(facing.IsNull()){ #if 0 BRepAdaptor_Surface surface(face, Standard_True); double u0 = surface.FirstUParameter(); double u1 = surface.LastUParameter(); double v0 = surface.FirstVParameter(); double v1 = surface.LastVParameter(); const int numi = 10; const int numj = 10; for(int i = 0; i<numi; i++) { for(int j = 0; j<numj; j++) { double uA = -1.2 + 2.5 *(double)i / numi; double uB = -1.2 + 2.5 *(double)(i+1) / numi; double vA = 10* (double)j / numj; double vB = 10*(double)(j+1) / numj; gp_Pnt p0, p1, p2, p3; gp_Dir n0 = GetFaceNormalAtUV(face, uA, vA, &p0); gp_Dir n1 = GetFaceNormalAtUV(face, uB, vA, &p1); gp_Dir n2 = GetFaceNormalAtUV(face, uB, vB, &p2); gp_Dir n3 = GetFaceNormalAtUV(face, uA, vB, &p3); x[0] = p0.X(); x[1] = p0.Y(); x[2] = p0.Z(); x[3] = p1.X(); x[4] = p1.Y(); x[5] = p1.Z(); x[6] = p2.X(); x[7] = p2.Y(); x[8] = p2.Z(); n[0] = n0.X(); n[1] = n0.Y(); n[2] = n0.Z(); n[3] = n1.X(); n[4] = n1.Y(); n[5] = n1.Z(); n[6] = n2.X(); n[7] = n2.Y(); n[8] = n2.Z(); (*callbackfunc)(x, n); x[0] = p0.X(); x[1] = p0.Y(); x[2] = p0.Z(); x[3] = p2.X(); x[4] = p2.Y(); x[5] = p2.Z(); x[6] = p3.X(); x[7] = p3.Y(); x[8] = p3.Z(); n[0] = n0.X(); n[1] = n0.Y(); n[2] = n0.Z(); n[3] = n2.X(); n[4] = n2.Y(); n[5] = n2.Z(); n[6] = n3.X(); n[7] = n3.Y(); n[8] = n3.Z(); (*callbackfunc)(x, n); } } #endif } else { Poly_Connect pc(facing); const TColgp_Array1OfPnt& Nodes = facing->Nodes(); const Poly_Array1OfTriangle& triangles = facing->Triangles(); TColgp_Array1OfDir myNormal(Nodes.Lower(), Nodes.Upper()); SST.Normal(face, pc, myNormal); Standard_Integer nnn = facing->NbTriangles(); // nnn : nombre de triangles Standard_Integer nt, n1, n2, n3 = 0; // nt : triangle courant // ni : sommet i du triangle courant for (nt = 1; nt <= nnn; nt++) { if (SST.Orientation(face) == TopAbs_REVERSED) // si la face est "reversed" triangles(nt).Get(n1,n3,n2); // le triangle est n1,n3,n2 else triangles(nt).Get(n1,n2,n3); // le triangle est n1,n2,n3 if (TriangleIsValid (Nodes(n1),Nodes(n2),Nodes(n3)) ) { gp_Pnt v1 = Nodes(n1).Transformed(tr); gp_Pnt v2 = Nodes(n2).Transformed(tr); gp_Pnt v3 = Nodes(n3).Transformed(tr); x[0] = v1.X(); x[1] = v1.Y(); x[2] = v1.Z(); x[3] = v2.X(); x[4] = v2.Y(); x[5] = v2.Z(); x[6] = v3.X(); x[7] = v3.Y(); x[8] = v3.Z(); if(just_one_average_normal) { gp_Vec V1(v1, v2); gp_Vec V2(v1, v3); extract((V1 ^ V2).Normalized(), n); } else { n[0] = myNormal(n1).X(); n[1] = myNormal(n1).Y(); n[2] = myNormal(n1).Z(); n[3] = myNormal(n2).X(); n[4] = myNormal(n2).Y(); n[5] = myNormal(n2).Z(); n[6] = myNormal(n3).X(); n[7] = myNormal(n3).Y(); n[8] = myNormal(n3).Z(); } (*callbackfunc)(x, n); } } } }
void speechCallback( const speech_msgs::SpeechConstPtr& speech ) { cout << "speech callback" << endl; //1.開始 //2.okao内のトラッキングIDと結びついた名前(OKAO_ID)を調べる //3.もし、主人の名前があったら、4へ。なければ1へ(ループ) //4.speech内のトラッキングIDを取得 //5.トラッキングIDとOKAO_IDを照合する //6.OKAO_IDに発言を記録する //8.主人以外の人物の記録が終わったら、1へ。終わってなければ6へ。 //人物を検出しているかどうか cout << "human size: "<< human_last.size() <<endl; if(human_last.size()) { bool master_is_looking = false; map<long long, int> tracking_to_okao; //発見した人物を記録し、主人を探す for(int i = 0; i<human_last.size(); ++i) { tracking_to_okao[ human_last[i].body.tracking_id ] = human_last[i].max_okao_id; cout << "now looking okao_id: " << human_last[i].max_okao_id << endl; if( human_last[i].max_okao_id == MASTER ) master_is_looking = true; } //主人がいるなら記録開始 // if( master_is_looking ) //{ speech_msgs::Speech sp_msg; float point_p = 0; cout<< "now looking master!" <<endl; int speech_okao_id; //string to long long long long speech_tracking_id = boost::lexical_cast< long long>(speech->TrackingID); cout << "now speech tracking_id: " << speech_tracking_id << endl; map< long long, int >::iterator tracking_id_find = tracking_to_okao.find( speech_tracking_id ); speech_okao_id = tracking_id_find->second; sp_msg.okao_id = speech_okao_id; if(speech->positive_point == 1){ point_p = 40; } else if(speech->positive_point == -1){ point_p = -40; } //speech->positive_point = -20; cout << "point: " << speech->positive_point << endl; if(mood.count(TIDtoName(speech_okao_id)) == 0){ mood[TIDtoName(speech_okao_id)] = point_p; } else{ float point = mood[TIDtoName(speech_okao_id)]; point += point_p; mood[TIDtoName(speech_okao_id)] = point; } window_mood[speech->hour][speech->minute][speech->second][TIDtoName(speech_okao_id)] = point_p; zmq_positive(speech_tracking_id,mood[TIDtoName(speech_okao_id)]); browser(speech,speech_okao_id); if(speech->sentence == "おしゃべりしよう" || speech->sentence == "お話ししよう"){ if(conv == 0){ conv = 1; conversation("start"); //cout << "お話開始" << endl; //robot_browser("いいですよ",1); } } else if(speech->sentence == "おしゃべり終わり" || speech->sentence == "おしゃべり終了"){ if(conv == 1){ conv = 0; conversation("end"); //robot_browser("終了しますね",1); } } else if(conv == 1){ conversation(speech->sentence); } else extract(speech,speech_okao_id); cout << "now speech okao_id: " << speech_okao_id << endl; cout << "all words: "<< speech->sentence <<endl; for( int w_id = 0 ; w_id < speech->word_num ; ++w_id ) { if(wordcheck(speech->words[w_id].word,speech->words[w_id].part[0])){ WordProp wp_tmp; wp_tmp.freq = 0; wp_tmp.num = 0; map< string, WordProp >::iterator it_words_wp = words_wp.find( speech->words[ w_id ].word ); if( it_words_wp != words_wp.end() ) { wp_tmp = it_words_wp->second; } ++wp_tmp.freq; wp_tmp.num = speech->word_num; Situation st_tmp; st_tmp.okao_id = speech_okao_id; sp_msg.words.push_back( speech->words[w_id] ); //すべての人物をpush_backする map< long long, int >::iterator it_okao = tracking_to_okao.begin(); while(it_okao != tracking_to_okao.end() ) { st_tmp.people.push_back( it_okao->second ); ++it_okao; } wp_tmp.situations.push_back( st_tmp ); words_wp[ speech->words[ w_id ].word ] = wp_tmp; } } //} } }
/// Master config parser. This handles 'import' and 'version-ge' etc. /// Then it defers to the inferior parser for a line it does not understand. /// /// Note: old-style 'version-ge: 1.2.3' etc apply to the rest of the file, but /// new-style 'version: >= 1.2.3' apply only up to the next 'version:' bool load_config_file(ZString filename, ConfigItemParser slave) { io::LineReader in(filename); if (!in.is_open()) { PRINTF("Unable to open file: %s\n"_fmt, filename); return false; } io::Line line_; bool rv = true; bool good_version = true; while (in.read_line(line_)) { if (is_comment(line_.text)) continue; auto line = io::respan(line_.to_span(), ZString(line_.text)); io::Spanned<XString> key; io::Spanned<ZString> value; if (!config_split(line, &key, &value)) { line.span.error("Bad config line"_s); rv = false; continue; } if (key.data == "version"_s) { if (value.data == "all"_s) { good_version = true; } else { good_version = true; while (good_version && value.data) { ZString::iterator it = std::find(value.data.begin(), value.data.end(), ' '); io::Spanned<XString> value_head; value_head.data = value.data.xislice_h(it); value_head.span = value.span; value.data = value.data.xislice_t(it).lstrip(); value_head.span.end.column = value_head.span.begin.column + value_head.data.size() - 1; value.span.begin.column = value.span.end.column - value.data.size() + 1; good_version &= check_version(value_head, borrow(rv)); } } continue; } if (!good_version) { continue; } if (key.data == "import"_s) { if (!load_config_file(value.data, slave)) { value.span.error("Failed to include file"_s); rv = false; } continue; } else if (key.data == "version-lt"_s) { Version vers; if (!extract(value.data, &vers)) { value.span.error("Bad value"_s); rv = false; continue; } if (CURRENT_VERSION < vers) continue; break; } else if (key.data == "version-le"_s) { Version vers; if (!extract(value.data, &vers)) { rv = false; value.span.error("Bad value"_s); continue; } if (CURRENT_VERSION <= vers) continue; break; } else if (key.data == "version-gt"_s) { Version vers; if (!extract(value.data, &vers)) { rv = false; value.span.error("Bad value"_s); continue; } if (CURRENT_VERSION > vers) continue; break; } else if (key.data == "version-ge"_s) { Version vers; if (!extract(value.data, &vers)) { rv = false; value.span.error("Bad value"_s); continue; } if (CURRENT_VERSION >= vers) continue; break; } else { rv &= slave(key, value); } // nothing to see here, move along } return rv; }
void main(int argc, char *argv[]) { int errflg = 0; char *ret = nil; fmtinstall('M', dirmodefmt); TARGBEGIN { case 'c': docreate++; verb = Replace; break; case 'f': usefile = arname = EARGF(usage()); break; case 'g': argid = strtoul(EARGF(usage()), 0, 0); break; case 'i': ignerrs = 1; break; case 'k': keepexisting++; break; case 'm': /* compatibility */ settime = 0; break; case 'p': posix++; break; case 'P': posix = 0; break; case 'r': verb = Replace; break; case 'R': relative = 0; break; case 's': resync++; break; case 't': verb = Toc; break; case 'T': settime++; break; case 'u': aruid = strtoul(EARGF(usage()), 0, 0); break; case 'v': verbose++; break; case 'x': verb = Xtract; break; case 'z': docompress++; break; case '-': break; default: fprint(2, "tar: unknown letter %C\n", TARGC()); errflg++; break; } TARGEND if (argc < 0 || errflg) usage(); initblks(); switch (verb) { case Toc: case Xtract: ret = extract(argv); break; case Replace: if (getwd(origdir, sizeof origdir) == nil) strcpy(origdir, "/tmp"); ret = replace(argv); break; default: usage(); break; } exits(ret); }
TSoundTrackP TSoundTrack::extract(double t0, double t1) { return extract(secondsToSamples(t0), secondsToSamples(t1)); }
JViewObj* JFocusSet::operator[](int index) { return extract(children[index]);}
int main(int argc, char **argv) { char *tmpdir; size_t tdlen; /* * Keep a reference to cwd, so we can always come back home. */ cwdfd = open(".", O_RDONLY | O_CLOEXEC); if (cwdfd < 0) { syswarn(1, errno, "Can't open current working directory."); return(exit_val); } /* * Where should we put temporary files? */ if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') tmpdir = _PATH_TMP; tdlen = strlen(tmpdir); while (tdlen > 0 && tmpdir[tdlen - 1] == '/') tdlen--; tempfile = malloc(tdlen + 1 + sizeof(_TFILE_BASE)); if (tempfile == NULL) { paxwarn(1, "Cannot allocate memory for temp file name."); return(exit_val); } if (tdlen) memcpy(tempfile, tmpdir, tdlen); tempbase = tempfile + tdlen; *tempbase++ = '/'; /* * parse options, determine operational mode, general init */ options(argc, argv); if ((gen_init() < 0) || (tty_init() < 0)) return(exit_val); /* * pmode needs to restore setugid bits when extracting or copying, * so can't pledge at all then. */ if (pmode == 0 || (act != EXTRACT && act != COPY)) { if (pledge("stdio rpath wpath cpath fattr dpath getpw proc exec tape", NULL) == -1) err(1, "pledge"); /* Copy mode, or no gzip -- don't need to fork/exec. */ if (gzip_program == NULL || act == COPY) { if (pledge("stdio rpath wpath cpath fattr dpath getpw tape", NULL) == -1) err(1, "pledge"); } } /* * select a primary operation mode */ switch (act) { case EXTRACT: extract(); break; case ARCHIVE: archive(); break; case APPND: if (gzip_program != NULL) errx(1, "can not gzip while appending"); append(); break; case COPY: copy(); break; default: case LIST: list(); break; } return(exit_val); }