/* change data to same dimensions, new samples and type */ int changepic(PICTURE *pic, int samples, int fileid) { int oldsize = sizeofdata(pic); pic->fileid = fileid; pic->samples = samples; if ((pic->data) == NULL) { if (newdata(pic)) return(-1); } else if (sizeofdata(pic) != oldsize) { free(pic->data); if (newdata(pic)) return(-1); /* pic->data = (void *)realloc(pic->data,pic->size); */ } return(0); }
/*DISPATCHER_UIPCALL(smtp_appcall, state)*/ void smtp_appcall(void *state) { if(uip_connected()) { /* senddata();*/ return; } if(uip_acked()) { acked(); } if(uip_newdata()) { newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked()) { senddata(); } else if(uip_poll()) { senddata(); } /* if(uip_closed()) { printf("Dnoe\n"); }*/ }
/* instantiates *(pic->data), swaps as needed, readhead called before */ int readdata(PICTURE *pic, FILE *fp) { int magic = pic->magic; if ((pic->data) == NULL) { if (newdata(pic)) return(-1); } switch (magic) { case PGM_ASCI_MAGIC: case PPM_ASCI_MAGIC: case VISA_MAGIC: case VISA_SWMAGIC: readascidata(pic,fp); break; case VIS_MAGIC: case PGM_MAGIC: case PPM_MAGIC: if ( fread(pic->data,sizeofdata(pic),1,fp) == 0) { (void)fprintf(stderr,"readdata: failed to read binary data\n"); return(-1); } break; case VIS_SWMAGIC: /* now does endian swapping */ { int x, sz = (pic->items)*(pic->samples); switch (pic->fileid) { case IMAGE_ID: break; /* no need to swap individual chars */ case INT_ID: { INT_TYPE *buf = (INT_TYPE *)(pic->data); for (x=0; x<sz; x++) { *buf = swapint(*buf); buf++; } } break; case FIMAGE_ID: { FIMAGE_TYPE *buf = (FIMAGE_TYPE *)(pic->data); for (x=0; x<sz; x++) { *buf = swapfloat(*buf); buf++; } } break; default: (void)fprintf(stderr, "readdata: please recreate the input file on this architecture\n"); return(-1); } } break; default: (void)fprintf(stderr,"readdata: strange magic\n"); return(-1); } return(0); }
TYPED_TEST_P(TcTest, TestHardLinks) { EXPECT_TRUE(tc_rm_recursive("HardLinks")); tc_ensure_dir("HardLinks", 0755, NULL); const int NFILES = 8; std::vector<const char *> files(NFILES); std::vector<const char *> links(NFILES); std::vector<tc_iovec> olddata(NFILES); std::vector<tc_iovec> newdata(NFILES); for (int i = 0; i < NFILES; ++i) { files[i] = new_auto_path("HardLinks/file-%d", i); links[i] = new_auto_path("HardLinks/link-%d", i); olddata[i].file = tc_file_from_path(files[i]); newdata[i].file = tc_file_from_path(links[i]); olddata[i].offset = newdata[i].offset = 0; olddata[i].length = newdata[i].length = 4096; olddata[i].data = (char *)malloc(4096); newdata[i].data = (char *)malloc(4096); } tc_touchv(files.data(), files.size(), false); EXPECT_OK(tc_readv(olddata.data(), olddata.size(), false)); EXPECT_OK(tc_hardlinkv(files.data(), links.data(), files.size(), false)); EXPECT_OK(tc_unlinkv(files.data(), files.size())); EXPECT_OK(tc_readv(newdata.data(), newdata.size(), false)); EXPECT_TRUE(compare_content(olddata.data(), newdata.data(), olddata.size())); for (int i = 0; i < NFILES; ++i) { free((char *)olddata[i].data); free((char *)newdata[i].data); } }
/*---------------------------------------------------------------------------*/ void telnetd_appcall(void *ts) { if(uip_connected()) { tcp_markconn(uip_conn, &s); buf_init(&buf); s.bufptr = 0; s.state = STATE_NORMAL; shell_start(); } if(s.state == STATE_CLOSE) { s.state = STATE_NORMAL; uip_close(); return; } if(uip_closed() || uip_aborted() || uip_timedout()) { closed(); } if(uip_acked()) { acked(); } if(uip_newdata()) { newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll()) { senddata(); } }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_udpsend_process, ev, data) { const char *next, *nextptr; struct shell_input *input; uint16_t port, local_port; PROCESS_BEGIN(); next = strchr(data, ' '); if(next == NULL) { shell_output_str(&udpsend_command, "udpsend <server> <port> [localport]: server as address", ""); PROCESS_EXIT(); } ++next; strncpy(server, data, sizeof(server)); port = shell_strtolong(next, &nextptr); uiplib_ipaddrconv(server, (u8_t *)&serveraddr); udpconn = udp_new(&serveraddr, htons(port), NULL); if(next != nextptr) { local_port = shell_strtolong(nextptr, &nextptr); udp_bind(udpconn, htons(local_port)); } running = 1; while(running) { PROCESS_WAIT_EVENT(); if(ev == shell_event_input) { input = data; if(input->len1 + input->len2 == 0) { PROCESS_EXIT(); } if(input->len1 > 0) { send_line(input->data1, input->len1); } } else if(ev == tcpip_event) { if(uip_newdata()) { newdata(uip_appdata, uip_datalen()); } #if 0 } else if(ev == resolv_event_found) { /* Either found a hostname, or not. */ if((char *)data != NULL && resolv_lookup((char *)data) != NULL) { uip_ipaddr_copy(serveraddr, ipaddr); telnet_connect(&s, server, serveraddr, nick); } else { shell_output_str(&udpsend_command, "Host not found.", ""); } #endif /* 0 */ } } PROCESS_END(); }
/*-----------------------------------------------------------------------------------*/ void webclient_appcall(void) { if(uip_connected()) { s.timer = 0; s.state = WEBCLIENT_STATE_STATUSLINE; senddata(); webclient_connected(); return; } if(s.state == WEBCLIENT_STATE_CLOSE) { webclient_closed(); uip_abort(); return; } if(uip_aborted()) { webclient_aborted(); } if(uip_timedout()) { webclient_timedout(); } if(uip_acked()) { s.timer = 0; acked(); } if(uip_newdata()) { s.timer = 0; newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked()) { senddata(); } else if(uip_poll()) { ++s.timer; if(s.timer == WEBCLIENT_TIMEOUT) { webclient_timedout(); uip_abort(); return; } /* senddata();*/ } if(uip_closed()) { if(s.httpflag != HTTPFLAG_MOVED) { /* Send NULL data to signal EOF. */ webclient_datahandler(NULL, 0); } else { if(resolv_lookup(s.host) == NULL) { resolv_query(s.host); } webclient_get(s.host, s.port, s.file); } } }
PICTURE *makepic(int fileid, int x, int y, float xorig, float yorig, int items, int sampls, char *history) { PICTURE *pic = newpic(); fillhead(pic,fileid,x,y,xorig,yorig,items,sampls,history); if (newdata(pic)) return(NULL); return(pic); }
/*---------------------------------------------------------------------------*/ void telnetd_appcall(void *ts) { if(uip_connected()) { if(!connected) { buf_init(&buf); s.bufptr = 0; s.state = STATE_NORMAL; connected = 1; shell_start(); timer_set(&s.silence_timer, MAX_SILENCE_TIME); ts = (char *)0; } else { uip_send(telnetd_reject_text, strlen(telnetd_reject_text)); ts = (char *)1; } tcp_markconn(uip_conn, ts); } if(!ts) { if(s.state == STATE_CLOSE) { s.state = STATE_NORMAL; uip_close(); return; } if(uip_closed() || uip_aborted() || uip_timedout()) { shell_stop(); connected = 0; } if(uip_acked()) { timer_set(&s.silence_timer, MAX_SILENCE_TIME); acked(); } if(uip_newdata()) { timer_set(&s.silence_timer, MAX_SILENCE_TIME); newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll()) { senddata(); if(s.numsent > 0) { timer_set(&s.silence_timer, MAX_SILENCE_TIME); } } if(uip_poll()) { if(timer_expired(&s.silence_timer)) { uip_close(); tcp_markconn(uip_conn, NULL); } } } }
/* data not copied, samples and fileid can be changed */ PICTURE *copypic(PICTURE *pic, int samples, int fileid) { PICTURE *pic2 = copyhead(pic,samples,fileid); if (pic == NULL) { (void)fprintf(stderr,"copypic given null pic\n"); return(NULL); } if (newdata(pic2)) { (void)fprintf(stderr,"copypic failed to allocate memory\n"); return(NULL); } return(pic2); }
/** test adding a random element */ static void testadd(struct lruhash* table, testdata_t* ref[]) { int numtoadd = random() % HASHTESTMAX; testdata_t* data = newdata(numtoadd); testkey_t* key = newkey(numtoadd); key->entry.data = data; lruhash_insert(table, myhash(numtoadd), &key->entry, data, NULL); ref[numtoadd] = data; }
//test add a random element static void testadd(struct lruhash *table, testdata *ref[]) { int num = random() % MAXHASH; testdata *data = newdata(num); testkey *key = newkey(num); key->entry.data = data; lruhash_insert(table, simplehash(num), &key->entry, data); if(ref) ref[num] = data; }
// Returns a substring. Offset and count are clamped to the size // of `this'. ustring substr(size_t offset, size_t count) const { if (offset > data.size()) offset = data.size(); if (count > data.size() - offset) count = data.size() - offset; std::vector<uchar> newdata(data.begin() + offset, data.begin() + offset + count); return ustring(newdata); }
/** test adding a random element (unlimited range) */ static void testadd_unlim(struct lruhash* table, testdata_t** ref) { int numtoadd = random() % (HASHTESTMAX * 10); testdata_t* data = newdata(numtoadd); testkey_t* key = newkey(numtoadd); key->entry.data = data; lruhash_insert(table, myhash(numtoadd), &key->entry, data, NULL); if(ref) ref[numtoadd] = data; }
QThreadData* QThreadData::current() { static QThreadData *data = 0; // reinterpret_cast<QThreadData *>(pthread_getspecific(current_thread_data_key)); if (!data) { QScopedPointer<QThreadData> newdata(new QThreadData); newdata->thread = new QAdoptedThread(newdata.data()); data = newdata.take(); data->deref(); } return data; }
/*---------------------------------------------------------------------------*/ void resolv_appcall(void) { if(uip_udp_conn->rport == UIP_HTONS(53)) { if(uip_poll()) { check_entries(); } if(uip_newdata()) { newdata(); } } }
/** test hashtable using short sequence */ static void test_short_table(struct lruhash* table) { testkey_t* k = newkey(12); testkey_t* k2 = newkey(14); testdata_t* d = newdata(128); testdata_t* d2 = newdata(129); k->entry.data = d; k2->entry.data = d2; lruhash_insert(table, myhash(12), &k->entry, d, NULL); lruhash_insert(table, myhash(14), &k2->entry, d2, NULL); unit_assert( lruhash_lookup(table, myhash(12), k, 0) == &k->entry); lock_rw_unlock( &k->entry.lock ); unit_assert( lruhash_lookup(table, myhash(14), k2, 0) == &k2->entry); lock_rw_unlock( &k2->entry.lock ); lruhash_remove(table, myhash(12), k); lruhash_remove(table, myhash(14), k2); }
//test lruhash_insert, lruhash_lookup and lruhash_remove static void test_short_table(struct lruhash *table) { testkey *k1 = newkey(12); testkey *k2 = newkey(14); testdata *d1 = newdata(128); testdata *d2 = newdata(129); k1->entry.data = d1; k2->entry.data = d2; lruhash_insert(table, simplehash(12), &k1->entry, d1); lruhash_insert(table, simplehash(14), &k2->entry, d2); unit_assert(lruhash_lookup(table, simplehash(12), k1) == &k1->entry); lock_basic_unlock(&k1->entry.lock); unit_assert(lruhash_lookup(table, simplehash(14), k2) == &k2->entry); lock_basic_unlock(&k2->entry.lock ); lruhash_remove(table, simplehash(12), k1); lruhash_remove(table, simplehash(14), k2); }
/****************************************************************************** * void exosite_appcall(void) * * This function is uIP's application function. It is called whenever a uIP * event occurs (e.g. when a new connection is established, new data arrives, * sent data is acknowledged, data needs to be retransmitted, etc.). * ******************************************************************************/ void exosite_appcall(void) { if(uip_connected()) { s.timer = 0; senddata(); return; } if(s.state == EXO_STATE_CLOSE) { uip_abort(); return; } if(uip_aborted()) { } if(uip_timedout()) { } if(uip_acked()) { s.timer = 0; acked(); } if(uip_newdata()) { s.timer = 0; newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked()) { senddata(); } else if(uip_poll()) { ++s.timer; if(s.timer == EXO_TIMEOUT) { uip_abort(); return; } } #if 0 if(uip_closed()) { if(s.httpflag != HTTPFLAG_MOVED) { memset(s.rxdata,0,sizeof(s.rxdata)); } else { if(resolv_lookup(s.host) == NULL) { resolv_query(s.host); } } } #endif }
void newpacket(u_char *args, const struct pcap_pkthdr *header, const u_char *packet){ struct ether_header *eth; struct iphdr *ip; u_char *payload; unsigned int iplen; printf("Jacked a packet from %s with length of %d, captured %d.\n", args, header->len, header->caplen); eth = (struct ether_header *) packet; ip = (struct iphdr *) ((char *) eth + sizeof(struct ether_header)); if (ntohs(eth->ether_type)!=0x0800 || (ip->version_ihl & 0xF0) != 0x40) return; iplen = ntohs(ip->tot_len); printf("IP: protocol=0x%02x, len=%u\n", ip->protocol, iplen); if (header->caplen < iplen+sizeof(struct ether_header)) return; newdata(ip->protocol, packet + sizeof(struct ether_header) + ((ip->version_ihl & 0x0F)*4), iplen - ((ip->version_ihl & 0x0F)*4)); }
/*---------------------------------------------------------------------------*/ void telnetd_appcall(void) { static unsigned int i; if(uip_connected()) { /* tcp_markconn(uip_conn, &s);*/ for(i = 0; i < TELNETD_CONF_NUMLINES; ++i) { s.lines[i] = NULL; } s.bufptr = 0; s.state = STATE_NORMAL; shell_start(); } if(s.state == STATE_CLOSE) { s.state = STATE_NORMAL; uip_close(); return; } if(uip_closed() || uip_aborted() || uip_timedout()) { closed(); } if(uip_acked()) { acked(); } if(uip_newdata()) { newdata(); } if(uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll()) { senddata(); } }
// define quad-k variable illustrating alt-keybaord layout // type quad with alt-l void init_quad_k(symtab st){ //alt-keyboard // //-> iterate over string char *rows[] = { "~!@#$%^&*()_+", "`1234567890-=", "QWERTYUIOP{}|", "qwertyuiop[]\\", "ASDFGHJKL:\"", "asdfghjkl;'", "ZXCVBNM<>?", "zxcvbnm,./", }; array qk = array_new_dims(8,13); for (int i=0,j; i<8; ++i){ for (j=0; j<13; ++j){ if (!rows[i][j]) break; *elem(qk,i,j) = newdata(PCHAR, inputtobase(rows[i][j],1)); } for (; j<13; ++j){ *elem(qk,i,j) = newdata(PCHAR, inputtobase(' ',0)); } } define_symbol(st,newdata(PCHAR, 0x2395),newdata(PCHAR, 'k'), cache(ARRAY, qk)); //normal keyboard array qa = array_new_dims(8,13); for (int i=0,j; i<8; ++i){ for (j=0; j<13; ++j){ if (!rows[i][j]) break; *elem(qa, i, j) = newdata(PCHAR, inputtobase(rows[i][j],0)); } for (; j<13; ++j){ *elem(qa, i, j) = newdata(PCHAR, inputtobase(' ',0)); } } define_symbol(st,newdata(PCHAR, 0x2395),newdata(PCHAR, 'a'), cache(ARRAY, qa)); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(server_process, ev, data) { PROCESS_BEGIN(); uip_ipaddr_t serveraddr; uip_ipaddr(&serveraddr, 172,16,2,0); serverport = 2222; localport = 3333; udpconn = udp_new(&serveraddr, uip_htons(serverport), NULL); udp_bind(udpconn, uip_htons(localport)); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); if (uip_newdata()) { newdata(uip_appdata, uip_datalen()); } } PROCESS_END(); }
// quad-neg variable controls minus/hi-minus semantics in // the lexical analysis void init_quad_neg(symtab st){ define_symbol(st, newdata(PCHAR, 0x2395),newdata(PCHAR, '-'), 0); }
/** test bin_find_entry function and bin_overflow_remove */ static void test_bin_find_entry(struct lruhash* table) { testkey_t* k = newkey(12); testdata_t* d = newdata(128); testkey_t* k2 = newkey(12 + 1024); testkey_t* k3 = newkey(14); testkey_t* k4 = newkey(12 + 1024*2); hashvalue_t h = myhash(12); struct lruhash_bin bin; memset(&bin, 0, sizeof(bin)); bin_init(&bin, 1); /* remove from empty list */ bin_overflow_remove(&bin, &k->entry); /* find in empty list */ unit_assert( bin_find_entry(table, &bin, h, k) == NULL ); /* insert */ lock_quick_lock(&bin.lock); bin.overflow_list = &k->entry; lock_quick_unlock(&bin.lock); /* find, hash not OK. */ unit_assert( bin_find_entry(table, &bin, myhash(13), k) == NULL ); /* find, hash OK, but cmp not */ unit_assert( k->entry.hash == k2->entry.hash ); unit_assert( bin_find_entry(table, &bin, h, k2) == NULL ); /* find, hash OK, and cmp too */ unit_assert( bin_find_entry(table, &bin, h, k) == &k->entry ); /* remove the element */ lock_quick_lock(&bin.lock); bin_overflow_remove(&bin, &k->entry); lock_quick_unlock(&bin.lock); unit_assert( bin_find_entry(table, &bin, h, k) == NULL ); /* prepend two different elements; so the list is long */ /* one has the same hash, but different cmp */ lock_quick_lock(&bin.lock); unit_assert( k->entry.hash == k4->entry.hash ); k4->entry.overflow_next = &k->entry; k3->entry.overflow_next = &k4->entry; bin.overflow_list = &k3->entry; lock_quick_unlock(&bin.lock); /* find, hash not OK. */ unit_assert( bin_find_entry(table, &bin, myhash(13), k) == NULL ); /* find, hash OK, but cmp not */ unit_assert( k->entry.hash == k2->entry.hash ); unit_assert( bin_find_entry(table, &bin, h, k2) == NULL ); /* find, hash OK, and cmp too */ unit_assert( bin_find_entry(table, &bin, h, k) == &k->entry ); /* remove middle element */ unit_assert( bin_find_entry(table, &bin, k4->entry.hash, k4) == &k4->entry ); lock_quick_lock(&bin.lock); bin_overflow_remove(&bin, &k4->entry); lock_quick_unlock(&bin.lock); unit_assert( bin_find_entry(table, &bin, k4->entry.hash, k4) == NULL); /* remove last element */ lock_quick_lock(&bin.lock); bin_overflow_remove(&bin, &k->entry); lock_quick_unlock(&bin.lock); unit_assert( bin_find_entry(table, &bin, h, k) == NULL ); lock_quick_destroy(&bin.lock); delkey(k); delkey(k2); delkey(k3); delkey(k4); deldata(d); }
std::vector<std::vector<double> > LinearApproximation::findMinimalDifferences( size_t t_numDifferences, const std::vector<std::vector<double> > &t_vals, const std::vector<std::vector<double> > &t_data) const { // t_vals includes the baseline requested value, so we want one more than that if (t_data.empty() || t_numDifferences + 2 == t_vals.size()) { // this is as good as we're going to get / can use right now std::vector<std::vector<double> > retval = t_vals; if (!t_vals.empty()) { retval.erase(retval.begin()); } return retval; } std::vector<std::vector<double> > candidates; std::vector<std::vector<double> > remainder; for (size_t i = 0; i < t_data.size(); ++i) { size_t numDifferences = 0; for (size_t j = 0; j < m_numVars; ++j) { for (size_t i2 = 0; i2 < t_vals.size(); ++i2) { if (t_data[i][j] != t_vals[i2][j]) { ++numDifferences; break; // don't check any further input rows } } if (numDifferences > t_numDifferences) { // don't continue with this data row break; } } if (numDifferences <= t_numDifferences) { candidates.push_back(t_data[i]); } else { remainder.push_back(t_data[i]); } } std::vector<std::vector<double> > keptresult = t_vals; keptresult.erase(keptresult.begin()); for (size_t i = 0; i < candidates.size(); ++i) { std::vector<std::vector<double> > newvals(t_vals); newvals.push_back(candidates[i]); std::vector<std::vector<double> > newdata(t_data); newdata.erase(std::remove(newdata.begin(), newdata.end(), candidates[i]), newdata.end()); std::vector<std::vector<double> > result = findMinimalDifferences(t_numDifferences, newvals, newdata); if (result.size() > keptresult.size()) { keptresult = result; } } return keptresult; }
int main(int argc, char * argv[]) { RWFile file; simplmat <double> data; simplmat <double> q; if( argc < 6) { cerr << "-------------------------------------------------------" << endl << "Multifractal estimation of multispecies 2D distributions" << endl << "Using species rank surface (SRS) see " << endl << "http://f1000research.com/articles/3-14/v2" << endl << "The Dq,F(alpha),Alpha estimation use box counting and the canonical method" << endl << "Chhabra, Meneveau, Jensen & Sreenivasan, Phys.Rev.A 40,5284 (1989)" << endl << endl; cerr << "Usage: mf inputFile qFile minBox maxBox numBoxSizes option" << endl << " option N: Not normalize measure use SRS" << endl << " S: Normalize measure" << endl << " A: Save the reordered distribution" << endl << " E: Use the spatial SAD to compute dimensions" << endl << " This option implies N" << endl; exit(1); } string fname = argv[1]; if( fname.find(".rst") != string::npos ) { if(!file.ReadIdrisi(argv[1], data)) exit(1); } else if( fname.find(".tif")!=string::npos ) { if(!file.ReadTiff(argv[1], data)) exit(1); } else { if(!file.ReadSeed(argv[1], data)) exit(1); } if(!file.ReadSeed(argv[2], q)) exit(1); int minBox = atoi(argv[3]); int maxBox = atoi(argv[4]); int deltaBox = atoi(argv[5]); string opt=argv[6]; simplmat <double> newdata(data); if( toupper(opt[0])!='E') { if(MultispeciesReordering(data,newdata)) MultifractalSBA(newdata, q,argv[1] ,minBox, maxBox, deltaBox, opt[0]); } else MultifractalSBA(data, q,argv[1] ,minBox, maxBox, deltaBox, opt[0]); if(opt[0]=='A') { string::size_type pos=0; if( (pos=fname.find(".")) == string::npos ) { fname += "Reord.sed"; } else { fname = fname.substr(0,pos) + "Reord.sed"; } if(!file.WriteSeed(fname.c_str(),newdata)) exit(1); } return 0; }
/*-----------------------------------------------------------------------------------*/ void webclient_appcall(void *state) { char *dataptr; if(uip_connected()) { s.timer = 0; s.state = WEBCLIENT_STATE_STATUSLINE; senddata(); webclient_connected(); tcp_markconn(uip_conn, &s); return; } if(uip_timedout()) { webclient_timedout(); } if(uip_aborted()) { webclient_aborted(); } if(state == NULL) { uip_abort(); return; } if(s.state == WEBCLIENT_STATE_CLOSE) { webclient_closed(); uip_abort(); return; } /* The acked() and newdata() functions may alter the uip_appdata ptr, so we need to store it in the "dataptr" variable so that we can restore it before the senddata() function is called. */ dataptr = uip_appdata; if(uip_acked()) { s.timer = 0; acked(); } if(uip_newdata()) { s.timer = 0; newdata(); } uip_appdata = dataptr; if(uip_rexmit() || uip_newdata() || uip_acked()) { senddata(); } else if(uip_poll()) { ++s.timer; if(s.timer == WEBCLIENT_TIMEOUT) { webclient_timedout(); uip_abort(); return; } /* senddata();*/ } if(uip_closed()) { tcp_markconn(uip_conn, NULL); if(s.httpflag != HTTPFLAG_MOVED) { /* Send NULL data to signal EOF. */ webclient_datahandler(NULL, 0); } else { /* conn = uip_connect(uip_conn->ripaddr, s.port); if(conn != NULL) { dispatcher_markconn(conn, NULL); init_connection(); }*/ #if UIP_UDP if(resolv_lookup(s.host) == NULL) { resolv_query(s.host); } #endif /* UIP_UDP */ webclient_get(s.host, s.port, s.file); } } }
int main(int argc,char *argv[]) { if (argc != 3) { fprintf(stderr,"usage: %s filein fileout\n",argv[0]); exit(1); } dofiles(argc,argv); if ((fp = fopen(FILEIN,"rb")) == NULL ) { fprintf(stderr,"%s: wrong input file %s\n",PROGNAME,FILEIN); exit(1); } pic = newpic(); while (1) { printf("k keeps the existing header\n"); printf("d deletes the header (translates into raw data format)\n"); printf("p prepends new header (translates from raw data format)\n"); printf("c changes to new header (d+p)\t>"); answer = getchar(); getchar(); printf("%c it is!\n\n",answer); if ((answer == 'd') || (answer == 'k') || (answer == 'c')) { if (readhead(pic,fp) == -1) exit(1); break; } if (answer == 'p') { /* request new header - no header to be read anymore */ printf("Fileid int, as defined in vis.h (0 for unsigned char image): "); scanf("%d",&(pic->fileid)); printf("New image width (x pixels): "); scanf("%d",&(pic->x)); printf("New image height (y pixels): "); scanf("%d",&(pic->y)); printf("Window x origin (float): "); scanf("%f",&(pic->xorigin)); printf("Window y origin (float): "); scanf("%f",&(pic->yorigin)); printf("Number of items (0 for x*y): "); scanf("%d",&(pic->items)); if (pic->items == 0) pic->items = (pic->x)*(pic->y); printf("Number of samples for each item: "); scanf("%d",&(pic->samples)); printf("New image history: "); scanf("%[^\n]",pic->history); getchar(); pic->magic = VIS_MAGIC; break; } printf("Unexpected response, please try again\n"); } while (1) { printf("d for diagonal reflection (rows into columns)\n"); printf("r rotate 90 deg anti-clockwise (diagonal & horizontal reflections)\n"); printf("n for no reflection or endian byte swapping: "); reverse = getchar(); getchar(); printf("%c it is!\n\n",reverse); if ((reverse=='d') || (reverse=='r') || (reverse=='n')) break; printf("Unexpected response - please try again or control-C\n"); } while (1) { printf("v for Libor Spacek's LVL format output\n"); printf("p for Jef Poskanzer's PGM or PPM output \t>"); wout = getchar(); getchar(); printf("%c it is!\n",wout); if (wout == 'v') break; if (wout == 'p') break; (void) printf("Unexpected response - please try again or control-C\n"); } /* no more user input the desired header must be known by now and be in *pic */ if ((reverse == 'd')||(reverse == 'r')) /* swap rows and columns */ { newdata(pic); chbufin = (unsigned char *)pic->data; swapping = pic->y; pic->y = pic->x; pic->x = swapping; sz = (pic->samples)*sizeofidtype(pic->fileid); for (count=0;count<pic->x;count++) if (reverse == 'r') for (county=(pic->y)-1;county>=0;county--) fread(&(chbufin[sz*(county*(pic->x)+count)]),sz,1,fp); else for (county=0;county<pic->y;county++) fread(&(chbufin[sz*(county*pic->x+count)]),sz,1,fp); } else readdata(pic,fp); fclose(fp); if (answer != 'd') switch (wout) { case 'v': writepic(pic,FILEOUT); break; case 'p': writepmpic(pic,FILEOUT); break; default: exit(1); } else { if ((fp = fopen(FILEOUT,"wb")) == NULL ) { fprintf(stderr,"%s: wrong output file %s\n",PROGNAME,FILEOUT); exit(1); } if (fwrite(pic->data,sizeofdata(pic),1,fp) == 0) { fprintf(stderr,"%s: failed to write data\n",PROGNAME); exit(1); } } exit(0); }
/*-----------------------------------------------------------------------------------*/ void websocket_http_client_appcall(void *state) { char *dataptr; struct websocket_http_client_state *s = state; if(uip_connected()) { s->timer = 0; s->outputbufptr = 0; s->outputbuf_sendnext = 0; s->state = WEBSOCKET_HTTP_CLIENT_STATE_STATUSLINE; senddata(s); return; } if(uip_timedout()) { websocket_http_client_timedout(s); } if(uip_aborted()) { /* printf("aborted\n"); */ websocket_http_client_aborted(s); } if(state == NULL) { uip_abort(); return; } if(s->state == WEBSOCKET_HTTP_CLIENT_STATE_CLOSE) { websocket_http_client_closed(s); uip_abort(); return; } /* The acked() and newdata() functions may alter the uip_appdata ptr, so we need to store it in the "dataptr" variable so that we can restore it before the senddata() function is called. */ dataptr = uip_appdata; if(uip_acked()) { s->timer = 0; acked(s); } if(uip_newdata()) { s->timer = 0; newdata(s); } uip_appdata = dataptr; if(uip_rexmit() || uip_newdata() || uip_acked()) { senddata(s); } else if(uip_poll()) { senddata(s); ++s->timer; if(s->timer == WEBSOCKET_HTTP_CLIENT_TIMEOUT) { websocket_http_client_timedout(s); uip_abort(); return; } } if(uip_closed()) { tcp_markconn(uip_conn, NULL); if(s->httpflag != HTTPFLAG_MOVED) { /* Send NULL data to signal EOF. */ websocket_http_client_datahandler(s, NULL, 0); } else { #if UIP_UDP if(mdns_lookup(s->host) == NULL) { mdns_query(s->host); } #endif /* UIP_UDP */ websocket_http_client_get(s, s->host, s->port, s->file, s->subprotocol); } } }