Esempio n. 1
0
/* Send ZMODEM binary header hdr of type type */
void zsbhdr(int type, char *hdr)
{


  vfile(F("zsbhdr: %s %lx"), frametypes[type+FTOFFSET], rclhdr(hdr));
/*  if (type == ZDATA)
    for (n = Znulls; --n >=0; )
      xsendline(0);
*/
  xsendline(ZPAD); 
  xsendline(ZDLE);
//Pete (El Supremo) This looks wrong but it is correct - the code fails if == is used
  if ((Crc32t = Txfcs32)) {
    int n;
    UNSL long crc;
  
    xsendline(ZBIN32);  
    zsendline(type);
    crc = 0xFFFFFFFFL; 
    crc = UPDC32(type, crc);
  
    for (n=4; --n >= 0; ++hdr) {
      crc = UPDC32((0377 & *hdr), crc);
      zsendline(*hdr);
    }
    crc = ~crc;
    for (n=4; --n >= 0;) {
      zsendline((int)crc);
      crc >>= 8;
    }
  } else {
Esempio n. 2
0
/* compile shaders and return their ids in a 2-vector */
glm::ivec2 loadShaders(std::string vertFile, std::string fragFile)
{

    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
    GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

    /* read shader files into strings */
    std::ifstream vfile(vertFile.c_str());
    std::ifstream ffile(fragFile.c_str());

    std::ostringstream vbuffer, fbuffer;
    vbuffer << vfile.rdbuf();
    fbuffer << ffile.rdbuf();
    
    std::string vertexString(vbuffer.str());
    std::string fragmentString(fbuffer.str());

    /* convert strings to c_strings and set as shader source */
    char *vertexCString, *fragmentCString;
    vertexCString = new char[vertexString.length() + 1];
    fragmentCString = new char[fragmentString.length() + 1];
    strcpy(vertexCString, vertexString.c_str());
    strcpy(fragmentCString, fragmentString.c_str());

    glShaderSource(vertexShader, 1, (const char**)&vertexCString, 0);
    glShaderSource(fragmentShader, 1, (const char**)&fragmentCString, 0);

    delete vertexCString;
    delete fragmentCString;

    /* compile shaders and check for errors */
    GLint status;
    glCompileShader(vertexShader);
    glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
    if(status != GL_TRUE)
    {
        char log[2048];
        int len;
        glGetShaderInfoLog(vertexShader, 2048, (GLsizei*)&len, log);
        fprintf(stderr, "Vertex Shader: %s", log);
        glDeleteShader(vertexShader);
        glDeleteShader(fragmentShader);
        exit(1);
    }

    glCompileShader(fragmentShader);
    glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &status);
    if(status != GL_TRUE)
    {
        char log[2048];
        int len;
        glGetShaderInfoLog(fragmentShader, 2048, (GLsizei*)&len, log);
        fprintf(stderr, "Fragment Shader: %s", log);
        glDeleteShader(vertexShader);
        glDeleteShader(fragmentShader);
        exit(1);
    }

    return glm::ivec2(vertexShader, fragmentShader);
}
Esempio n. 3
0
bool write_vfile(const char *vfname, const csmp::PropertyDatabase<3> &pdb) {
  ofstream vfile(vfname);
  if (!vfile.is_open())
    return false;
  vfile << pdb;
  vfile.close();
  return true;
}
Esempio n. 4
0
static void FAMGWriteVector(int n, double *vec)
{
    ofstream vfile("vec.dat",ios::out);
    if (!vfile)
		return;
    for(int i = 0; i < n; i++)
    {
        vfile << i << "\t" << vec[i] << endl;
    }

    return;
}
Esempio n. 5
0
	/*virtual*/ U32 get_body(LLChannelDescriptors const& channels, buffer_ptr_t& buffer)
	{
		LLBufferStream ostream(channels, buffer.get());
		
		LLVFile vfile(gVFS, mUUID, mAssetType, LLVFile::READ);
		S32 fileSize = vfile.getSize();
		std::vector<U8> fileBuffer(fileSize);
		vfile.read(&fileBuffer[0], fileSize);
		ostream.write((char*)&fileBuffer[0], fileSize);
		ostream << std::flush;
		
		return fileSize;
	}
Esempio n. 6
0
int wctx(long flen)
{
  int thisblklen;
  int sectnum, attempts, firstch;
  long charssent;
  
//DSERIAL.println("\nwctx");

  charssent = 0;  
  firstsec=TRUE;  
  thisblklen = blklen;
  vfile(F("wctx:file length=%ld"), flen);

  while ((firstch=readline(Rxtimeout))!=NAK && firstch != WANTCRC
    && firstch != WANTG && firstch!=TIMEOUT && firstch!=CAN)
    ;
  if (firstch==CAN) {
    zperr("Receiver CANcelled");
    return ERROR;
  }
  if (firstch==WANTCRC)
    Crcflg=TRUE;
  if (firstch==WANTG)
    Crcflg=TRUE;
  sectnum=0;
  for (;;) {
    if (flen <= (charssent + 896L))
      thisblklen = 128;
    if ( !filbuf(txbuf, thisblklen))
      break;
    if (wcputsec(txbuf, ++sectnum, thisblklen)==ERROR)
      return ERROR;
    charssent += thisblklen;
  }
  //fclose(in);
  fout.close();
  attempts=0;
  do {
    purgeline();
    sendline(EOT);
    //fflush(stdout);
    ++attempts;
  }
  while ((firstch=(readline(Rxtimeout)) != ACK) && attempts < Tx_RETRYMAX);
  if (attempts == Tx_RETRYMAX) {
    zperr("No ACK on EOT");
    return ERROR;
  }
  else
    return OK;
}
Esempio n. 7
0
/*
 * Ack a ZFIN packet, let byegones be byegones
 */
static void ackbibi(void)
{
	int n;

	vfile("ackbibi:");
	Readnum = 1;
	stohdr(0L);
	for (n = 3; --n >= 0;) {
		purgeline();
		zshhdr(ZFIN, Txhdr);
		switch (readline(100)) {
		case 'O':
			readline(1);	/* Discard 2nd 'O' */
			vfile("ackbibi complete");
			return;
		case RCDO:
			return;
		case TIMEOUT:
		default:
			break;
		}
	}
}
Esempio n. 8
0
void LLAssetStorage::downloadEstateAssetCompleteCallback(
	S32 result,
	const LLUUID& file_id,
	LLAssetType::EType file_type,
	void* user_data,
	LLExtStat ext_status)
{
	LLEstateAssetRequest *req = (LLEstateAssetRequest*)user_data;
	if(!req)
	{
		LL_WARNS() << "LLAssetStorage::downloadEstateAssetCompleteCallback called"
			" without a valid request." << LL_ENDL;
		return;
	}
	if (!gAssetStorage)
	{
		LL_WARNS() << "LLAssetStorage::downloadEstateAssetCompleteCallback called"
			" without any asset system, aborting!" << LL_ENDL;
		return;
	}

	req->setUUID(file_id);
	req->setType(file_type);
	if (LL_ERR_NOERR == result)
	{
		// we might have gotten a zero-size file
		LLVFile vfile(gAssetStorage->mVFS, req->getUUID(), req->getAType());
		if (vfile.getSize() <= 0)
		{
			LL_WARNS() << "downloadCompleteCallback has non-existent or zero-size asset!" << LL_ENDL;

			result = LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE;
			vfile.remove();
		}
	}

	if (result != LL_ERR_NOERR)
	{
		add(sFailedDownloadCount, 1);
	}
	req->mDownCallback(gAssetStorage->mVFS, req->getUUID(), req->getAType(), req->mUserData, result, ext_status);
}
Esempio n. 9
0
void LLAssetStorage::downloadEstateAssetCompleteCallback(
	S32 result,
	const LLUUID& file_id,
	LLAssetType::EType file_type,
	void* callback_parm_req,
	LLExtStat ext_status)
{
	LLEstateAssetRequest *req = (LLEstateAssetRequest*)callback_parm_req;
	if(!req)
	{
		llwarns << "LLAssetStorage::downloadEstateAssetCompleteCallback called"
			" without a valid request." << llendl;
		return;
	}
	if (!gAssetStorage)
	{
		llwarns << "LLAssetStorage::downloadEstateAssetCompleteCallback called"
			" without any asset system, aborting!" << llendl;
		return;
	}

	if (LL_ERR_NOERR == result)
	{
		// we might have gotten a zero-size file
		LLVFile vfile(gAssetStorage->mVFS, file_id, file_type);
		if (vfile.getSize() <= 0)
		{
			llwarns << "downloadCompleteCallback has non-existent or zero-size asset!" << llendl;

			result = LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE;
			vfile.remove();
		}
	}

	req->mDownCallback(gAssetStorage->mVFS, file_id, file_type, req->mUserData, result, ext_status);

	delete req;
}
Esempio n. 10
0
/*
 * Receive a file with ZMODEM protocol
 *  Assumes file name frame is in secbuf
 */
static int rzfile(void)
{
	int c, n;
	long last_rxbytes = 0;
	long not_printed = 0;

	last_bps = 0;
	Eofseen = FALSE;

	n = 20;
	rxbytes = 0l;

	if (procheader(secbuf) == ERROR) {
		return (tryzhdrtype = ZSKIP);
	}


	for (;;) {
		stohdr(rxbytes);
		zshhdr(ZRPOS, Txhdr);
	      nxthdr:
		switch (c = zgethdr(Rxhdr, 0)) {
		default:
			vfile("lrzfile: zgethdr returned %d", c);
			return ERROR;
		case ZNAK:
		case TIMEOUT:
			if (--n < 0) {
				vfile("lrzfile: zgethdr returned %d", c);
				return ERROR;
			}
		case ZFILE:
			zrdata(secbuf, MAX_BLOCK);
			continue;
		case ZEOF:
			if (rclhdr(Rxhdr) != rxbytes) {
				/*
				 * Ignore eof if it's at wrong place - force
				 *  a timeout because the eof might have gone
				 *  out before we sent our zrpos.
				 */
				errors = 0;
				goto nxthdr;
			}
			if (Verbose > 1) {
				int minleft = 0;
				int secleft = 0;
				last_bps = (rxbytes / timing(0));
				if (last_bps > 0) {
					minleft =
					    (Bytesleft -
					     rxbytes) / last_bps / 60;
					secleft =
					    ((Bytesleft - rxbytes) /
					     last_bps) % 60;
				}
				fprintf(stderr,
					"\rBytes Received: %7ld/%7ld   BPS:%-6d                   \r\n",
					rxbytes, Bytesleft, last_bps);
			}
			closeok = 1;
			if (closeit()) {
				tryzhdrtype = ZFERR;
				vfile("lrzfile: closeit returned <> 0");
				return ERROR;
			}
			vfile("lrzfile: normal EOF");
			return c;
		case ERROR:	/* Too much garbage in header search error */
			if (--n < 0) {
				vfile("lrzfile: zgethdr returned %d", c);
				return ERROR;
			}
			zmputs(Attn);
			continue;
		case ZSKIP:
			closeit();
			vfile("lrzfile: Sender SKIPPED file");
			return c;
		case ZDATA:
			if (rclhdr(Rxhdr) != rxbytes) {
				if (--n < 0) {
					return ERROR;
				}
				zmputs(Attn);
				continue;
			}
		      moredata:
			if (Verbose > 1
			    && (not_printed > 7
				|| rxbytes >
				last_bps / 2 + last_rxbytes)) {
				int minleft = 0;
				int secleft = 0;
				last_bps = (rxbytes / timing(0));
				if (last_bps > 0) {
					minleft =
					    (Bytesleft -
					     rxbytes) / last_bps / 60;
					secleft =
					    ((Bytesleft - rxbytes) /
					     last_bps) % 60;
				}
				fprintf(stderr,
					"\rBytes Received: %7ld/%7ld   BPS:%-6d ETA %02d:%02d  ",
					rxbytes, Bytesleft, last_bps,
					minleft, secleft);
				last_rxbytes = rxbytes;
				not_printed = 0;
				if (nodeinf != -1 && ((time(0) - lup) > 5)) {
					lseek(nodeinf, 0, SEEK_SET);
					nin.ddn_bpsrate = last_bps;
					sprintf(nin.ddn_activity,
						"UL: %-34.34s", myname);
					write(nodeinf, &nin,
					      sizeof(struct
						     DayDream_NodeInfo));
					lup = time(0);
				}
			} else if (Verbose)
				not_printed++;
			switch (c = zrdata(secbuf, MAX_BLOCK)) {
			case ZCAN:
				vfile("lrzfile: zgethdr returned %d", c);
				return ERROR;
			case ERROR:	/* CRC error */
				if (--n < 0) {
					vfile
					    ("lrzfile: zgethdr returned %d",
					     c);
					return ERROR;
				}
				zmputs(Attn);
				continue;
			case TIMEOUT:
				if (--n < 0) {
					vfile
					    ("lrzfile: zgethdr returned %d",
					     c);
					return ERROR;
				}
				continue;
			case GOTCRCW:
				n = 20;
				putsec(secbuf, Rxcount);
				rxbytes += Rxcount;
				stohdr(rxbytes);
				zshhdr(ZACK, Txhdr);
				xsendline(XON);
				goto nxthdr;
			case GOTCRCQ:
				n = 20;
				putsec(secbuf, Rxcount);
				rxbytes += Rxcount;
				stohdr(rxbytes);
				zshhdr(ZACK, Txhdr);
				goto moredata;
			case GOTCRCG:
				n = 20;
				putsec(secbuf, Rxcount);
				rxbytes += Rxcount;
				goto moredata;
			case GOTCRCE:
				n = 20;
				putsec(secbuf, Rxcount);
				rxbytes += Rxcount;
				goto nxthdr;
			}
		}
	}
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
	char *cp;
	int npats;
	char *virgin, **patts = NULL;
	int exitcode = 0;

	*pathsname = 0;
	*tempsname = 0;
	nodeinf = -1;

	dszlog = -1;

	Rxtimeout = 100;
	setbuf(stderr, NULL);

	chkinvok(virgin = argv[0]);	/* if called as [-]rzCOMMAND set flag */
	npats = 0;
	while (--argc) {
		cp = *++argv;
		if (*cp == '-') {
			while (*++cp) {
				switch (*cp) {
				case '\\':
					cp[1] = toupper(cp[1]);
					continue;
				case '+':
					Lzmanag = ZMAPND;
					break;
				case 'a':
					Rxascii = TRUE;
					break;
				case 'b':
					Rxbinary = TRUE;
					break;
				case 'c':
					Crcflg = TRUE;
					break;
				case 'g':
					if (--argc < 1) {
						usage();
					}

					iofd = open(*++argv, O_RDWR);
					break;
				case 'D':
					Nflag = TRUE;
					break;
				case 'e':
					Zctlesc = 1;
					break;
				case 'h':
					usage();
					break;
				case 'O':
					no_timeout = TRUE;
					break;
				case 'p':
					Lzmanag = ZMPROT;
					break;
				case 'q':
					Quiet = TRUE;
					Verbose = 0;
					break;
				case 'r':
					try_resume = TRUE;
					break;
				case 't':
					if (--argc < 1) {
						usage();
					}
					Rxtimeout = atoi(*++argv);
					if (Rxtimeout < 10
					    || Rxtimeout > 1000) usage();
					break;
				case 'f':
					if (--argc < 1) {
						usage();
					}
					strcpy(pathsname, *++argv);
					break;
				case 'F':
					if (--argc < 1) {
						usage();
					}
					strcpy(tempsname, *++argv);
					break;
				case 'n':
					if (--argc < 1) {
						usage();
					}
					nodeinf = open(*++argv, O_RDWR);
					read(nodeinf, &nin,
					     sizeof(struct
						    DayDream_NodeInfo));
					nin.ddn_flags |= (1L << 1);
					break;
				case 'l':
					if (--argc < 1) {
						usage();
					}
					dszlog =
					    open(*++argv,
						 O_WRONLY | O_CREAT, 0755);
					break;
				case 'w':
					if (--argc < 1) {
						usage();
					}
					Zrwindow = atoi(*++argv);
					break;
				case 'u':
					MakeLCPathname = FALSE;
					break;
				case 'v':
					++Verbose;
					break;
				case 'y':
					Rxclob = TRUE;
					break;
				default:
					usage();
				}
			}
		} else if (!npats && argc > 0) {
			if (argv[0][0]) {
				npats = argc;
				patts = argv;
			}
		}
	}
	if (npats > 1)
		usage();
	if (Batch && npats)
		usage();
	if (Verbose) 
		setbuf(stderr, NULL);
	
	if (!Quiet) {
		if (Verbose == 0)
			Verbose = 2;
	}
	vfile("%s %s\n", Progname, VERSION);
	mode(1);
	signal(SIGTERM, bibi);
	if (wcreceive(npats, patts) == ERROR) {
		exitcode = 0200;
		canit();
	}
	mode(0);
	if (exitcode && !Zmodem)	/* bellow again with all thy might. */
		canit();
	exit(exitcode);

	return 0; /* compilers would complain */
}
Esempio n. 12
0
void LLAssetStorage::downloadCompleteCallback(
	S32 result,
	const LLUUID& file_id,
	LLAssetType::EType file_type,
	void* user_data, LLExtStat ext_status)
{
	lldebugs << "LLAssetStorage::downloadCompleteCallback() for " << file_id
		 << "," << LLAssetType::lookup(file_type) << llendl;
	LLAssetRequest* req = (LLAssetRequest*)user_data;
	if(!req)
	{
		llwarns << "LLAssetStorage::downloadCompleteCallback called without"
			"a valid request." << llendl;
		return;
	}
	if (!gAssetStorage)
	{
		llwarns << "LLAssetStorage::downloadCompleteCallback called without any asset system, aborting!" << llendl;
		return;
	}

	// Inefficient since we're doing a find through a list that may have thousands of elements.
	// This is due for refactoring; we will probably change mPendingDownloads into a set.
	request_list_t::iterator download_iter = std::find(gAssetStorage->mPendingDownloads.begin(), 
													   gAssetStorage->mPendingDownloads.end(),
													   req);
	// If the LLAssetRequest doesn't exist in the downloads queue, then it either has already been deleted
	// by _cleanupRequests, or it's a transfer.
	if (download_iter != gAssetStorage->mPendingDownloads.end())
	{
		req->setUUID(file_id);
		req->setType(file_type);
	}

	if (LL_ERR_NOERR == result)
	{
		// we might have gotten a zero-size file
		LLVFile vfile(gAssetStorage->mVFS, req->getUUID(), req->getType());
		if (vfile.getSize() <= 0)
		{
			llwarns << "downloadCompleteCallback has non-existent or zero-size asset " << req->getUUID() << llendl;
			
			result = LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE;
			vfile.remove();
		}
	}
	
	// find and callback ALL pending requests for this UUID
	// SJB: We process the callbacks in reverse order, I do not know if this is important,
	//      but I didn't want to mess with it.
	request_list_t requests;
	for (request_list_t::iterator iter = gAssetStorage->mPendingDownloads.begin();
		 iter != gAssetStorage->mPendingDownloads.end();  )
	{
		request_list_t::iterator curiter = iter++;
		LLAssetRequest* tmp = *curiter;
		if ((tmp->getUUID() == file_id) && (tmp->getType()== file_type))
		{
			requests.push_front(tmp);
			iter = gAssetStorage->mPendingDownloads.erase(curiter);
		}
	}
	for (request_list_t::iterator iter = requests.begin();
		 iter != requests.end();  )
	{
		request_list_t::iterator curiter = iter++;
		LLAssetRequest* tmp = *curiter;
		if (tmp->mDownCallback)
		{
			tmp->mDownCallback(gAssetStorage->mVFS, req->getUUID(), req->getType(), tmp->mUserData, result, ext_status);
		}
		delete tmp;
	}
}
Esempio n. 13
0
void generate(int dim, char* filename)
{
	int rank=0;
	#ifdef MPI_VERSION
	rank = MPI::COMM_WORLD.Get_rank();
	#endif
	if (rank==0) {
		std::ofstream vfile("v.log",std::ofstream::out);
		vfile.close();
	}


	if (dim == 2)	{
		const int Lx = 768;
		const int Ly = 128;

		grid<2,sparse<phi_type> > initGrid(0, 0,Lx, 0,Ly);

		for (int d=0; d<dim; d++) {
			if (x0(initGrid, d) == g0(initGrid,d))
				b0(initGrid,d) = Dirichlet;
			else if (x1(initGrid,d) == g1(initGrid,d))
				b1(initGrid,d) = Dirichlet;
		}

		for (int n=0; n<nodes(initGrid); n++) {
			vector<int> x = position(initGrid, n);
			if (x[0]>Ly && x[1]>0.25*Ly && x[1]<0.75*Ly)
				set(initGrid(n), 0) = 1.0;
			else if (x[1]<Ly/2)
				set(initGrid(n), 1) = 1.0;
			else
				set(initGrid(n), 2) = 1.0;
		}

		output(initGrid, filename);
	}

	if (dim == 3)	{
		const int Lx = 512;
		const int Ly = 256;
		const int Lz = 64;

		grid<3,sparse<phi_type> > initGrid(0, 0,Lx, 0,Ly, 0,Lz);

		for (int d=0; d<dim; d++) {
			if (x0(initGrid, d) == g0(initGrid,d))
				b0(initGrid,d) = Dirichlet;
			else if (x1(initGrid,d) == g1(initGrid,d))
				b1(initGrid,d) = Dirichlet;
		}

		for (int n=0; n<nodes(initGrid); n++) {
			vector<int> x = position(initGrid, n);
			if (x[0]>Ly && x[1]>0.25*Ly && x[1]<0.75*Ly)
				set(initGrid(n), 0) = 1.0;
			else if (x[1]<Ly/2)
				set(initGrid(n), 1) = 1.0;
			else
				set(initGrid(n), 2) = 1.0;
		}

		output(initGrid, filename);
	}
}
Esempio n. 14
0
GLuint engine::loadshaders(std::string vertfile, std::string fragfile,
        std::vector<std::string> in_attributes,
        std::vector<std::string> out_attributes)
{
    /* init glew and load compiled shaders */
    glewInit();
    if(!glewIsSupported("GL_VERSION_2_0 GL_ARB_multitexture GL_EXT_framebuffer_object")) 
    {
        fprintf(stderr, "Required OpenGL extensions missing\n");
        return -1;
    }

    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
    GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

    /* read shader files into strings */
    std::ifstream vfile(vertfile.c_str());
    std::ifstream ffile(fragfile.c_str());

    if(!vfile)
    {
        std::cout << vertfile << " does not exist!\n";
        exit(1);
    }
    if(!ffile)
    {
        std::cout << fragfile << " does not exist!\n";
        exit(1);
    }

    std::ostringstream vbuffer, fbuffer;
    vbuffer << vfile.rdbuf();
    fbuffer << ffile.rdbuf();
    
    std::string vertexString(vbuffer.str());
    std::string fragmentString(fbuffer.str());

    /* convert strings to c_strings and set as shader source */
    char *vertexCString, *fragmentCString;
    vertexCString = new char[vertexString.length() + 1];
    fragmentCString = new char[fragmentString.length() + 1];
    strcpy(vertexCString, vertexString.c_str());
    strcpy(fragmentCString, fragmentString.c_str());

    glShaderSource(vertexShader, 1, (const char**)&vertexCString, 0);
    glShaderSource(fragmentShader, 1, (const char**)&fragmentCString, 0);

    delete vertexCString;
    delete fragmentCString;

    /* compile shaders and check for errors */
    GLint status;
    glCompileShader(vertexShader);
    glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
    if(status != GL_TRUE)
    {
        char log[2048];
        int len;
        glGetShaderInfoLog(vertexShader, 2048, (GLsizei*)&len, log);
        fprintf(stderr, "Vertex Shader: %s", log);
        glDeleteShader(vertexShader);
        glDeleteShader(fragmentShader);
        exit(1);
    }

    glCompileShader(fragmentShader);
    glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &status);
    if(status != GL_TRUE)
    {
        char log[2048];
        int len;
        glGetShaderInfoLog(fragmentShader, 2048, (GLsizei*)&len, log);
        fprintf(stderr, "Fragment Shader: %s", log);
        glDeleteShader(vertexShader);
        glDeleteShader(fragmentShader);
        exit(1);
    }

    /* create program, bind attributes, and link program */
    int program = glCreateProgram();
    glAttachShader(program, vertexShader);
    glAttachShader(program, fragmentShader);
    int num_in_attributes = in_attributes.size();
    for(int i = 0; i < num_in_attributes; i++)
    {
        glBindAttribLocation(program, i, in_attributes.at(i).c_str());
    }
    int num_out_attributes = out_attributes.size();
    for(int i = 0; i < num_out_attributes; i++)
    {
        glBindFragDataLocation(program, i, out_attributes.at(i).c_str());
    }
    glLinkProgram(program);

    GLint pstatus;
    glGetProgramiv(program, GL_LINK_STATUS, &pstatus);
    if(pstatus != GL_TRUE)
    {
        char log[2048];
        int len;
        glGetProgramInfoLog(program, 2048, (GLsizei*)&len, log);
        fprintf(stderr, "%s", log);
        glDeleteProgram(program);
        return -1;
    }

    return program;
}
Esempio n. 15
0
/*
 * mode(n)
 *  3: save old tty stat, set raw mode with flow control
 *  2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
 *  1: save old tty stat, set raw mode 
 *  0: restore original tty mode
 */
int 
io_mode(int fd, int n)
{
	static int did0 = FALSE;

	vfile("Setting iode:%d", n);

/*	fprintf(stderr,"TEST BUILD: ignoring all terminal mode changes");
	return 0 ;
*/



	switch(n) {

#ifdef USE_TERMIOS

	case 2:		/* Un-raw mode used by sz, sb when -g detected */
		if(!did0) {
			did0 = TRUE;
			tcgetattr(fd,&oldtty);
		}
		tty = oldtty;

		tty.c_iflag = BRKINT|IXON;

		tty.c_oflag = 0;	/* Transparent output */

		tty.c_cflag &= ~PARENB;	/* Disable parity */
		tty.c_cflag |= CS8;	/* Set character size = 8 */
		if (Twostop)
			tty.c_cflag |= CSTOPB;	/* Set two stop bits */

#ifdef READCHECK
		tty.c_lflag = protocol==ZM_ZMODEM ? 0 : ISIG;
		tty.c_cc[VINTR] = protocol==ZM_ZMODEM ? -1 : 030;	/* Interrupt char */
#else
		tty.c_lflag = 0;
		tty.c_cc[VINTR] = protocol==ZM_ZMODEM ? 03 : 030;	/* Interrupt char */
#endif
#ifdef _POSIX_VDISABLE
		if (((int) _POSIX_VDISABLE)!=(-1)) {
			tty.c_cc[VQUIT] = _POSIX_VDISABLE;		/* Quit char */
		} else {
			tty.c_cc[VQUIT] = -1;			/* Quit char */
		}
#else
		tty.c_cc[VQUIT] = -1;			/* Quit char */
#endif
#ifdef NFGVMIN
		tty.c_cc[VMIN] = 1;
#else
		tty.c_cc[VMIN] = 3;	 /* This many chars satisfies reads */
#endif
		tty.c_cc[VTIME] = 1;	/* or in this many tenths of seconds */

		tcsetattr(fd,TCSADRAIN,&tty);

		return OK;
	case 1:
	case 3:
		if(!did0) {
			did0 = TRUE;
			tcgetattr(fd,&oldtty);
		}
		tty = oldtty;

		tty.c_iflag = IGNBRK;
		if (n==3) /* with flow control */
			tty.c_iflag |= IXOFF;

		 /* No echo, crlf mapping, INTR, QUIT, delays, no erase/kill */
		tty.c_lflag &= ~(ECHO | ICANON | ISIG);
		tty.c_oflag = 0;	/* Transparent output */

		tty.c_cflag &= ~(PARENB);	/* Same baud rate, disable parity */
		/* Set character size = 8 */
		tty.c_cflag &= ~(CSIZE);
		tty.c_cflag |= CS8;	
		if (Twostop)
			tty.c_cflag |= CSTOPB;	/* Set two stop bits */
#ifdef NFGVMIN
		tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */
#else
		tty.c_cc[VMIN] = HOWMANY; /* This many chars satisfies reads */
#endif
		tty.c_cc[VTIME] = 1;	/* or in this many tenths of seconds */
		tcsetattr(fd,TCSADRAIN,&tty);
		Baudrate = getspeed(cfgetospeed(&tty));
		return OK;
	case 0:
		if(!did0)
			return ERROR;
		tcdrain (fd); /* wait until everything is sent */
		tcflush (fd,TCIOFLUSH); /* flush input queue */
		tcsetattr (fd,TCSADRAIN,&oldtty);
		tcflow (fd,TCOON); /* restart output */

		return OK;
#endif

#ifdef USE_TERMIO
	case 2:		/* Un-raw mode used by sz, sb when -g detected */
		if(!did0)
			(void) ioctl(fd, TCGETA, &oldtty);
		tty = oldtty;

		tty.c_iflag = BRKINT|IXON;

		tty.c_oflag = 0;	/* Transparent output */

		tty.c_cflag &= ~PARENB;	/* Disable parity */
		tty.c_cflag |= CS8;	/* Set character size = 8 */
		if (Twostop)
			tty.c_cflag |= CSTOPB;	/* Set two stop bits */


#ifdef READCHECK
		tty.c_lflag = protocol==ZM_ZMODEM ? 0 : ISIG;
		tty.c_cc[VINTR] = protocol==ZM_ZMODEM ? -1 : 030;	/* Interrupt char */
#else
		tty.c_lflag = 0;
		tty.c_cc[VINTR] = protocol==ZM_ZMODEM ? 03 : 030;	/* Interrupt char */
#endif
		tty.c_cc[VQUIT] = -1;			/* Quit char */
#ifdef NFGVMIN
		tty.c_cc[VMIN] = 1;
#else
		tty.c_cc[VMIN] = 3;	 /* This many chars satisfies reads */
#endif
		tty.c_cc[VTIME] = 1;	/* or in this many tenths of seconds */

		(void) ioctl(fd, TCSETAW, &tty);
		did0 = TRUE;
		return OK;
	case 1:
	case 3:
		if(!did0)
			(void) ioctl(fd, TCGETA, &oldtty);
		tty = oldtty;

		tty.c_iflag = n==3 ? (IGNBRK|IXOFF) : IGNBRK;

		 /* No echo, crlf mapping, delays, no erase/kill */
		tty.c_lflag &= ~(ECHO | ICANON | ISIG);

		tty.c_oflag = 0;	/* Transparent output */

		tty.c_cflag &= ~PARENB;	/* Same baud rate, disable parity */
		tty.c_cflag |= CS8;	/* Set character size = 8 */
		if (Twostop)
			tty.c_cflag |= CSTOPB;	/* Set two stop bits */
#ifdef NFGVMIN
		tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */
#else
		tty.c_cc[VMIN] = HOWMANY; /* This many chars satisfies reads */
#endif
		tty.c_cc[VTIME] = 1;	/* or in this many tenths of seconds */
		(void) ioctl(fd, TCSETAW, &tty);
		did0 = TRUE;
		Baudrate = getspeed(tty.c_cflag & CBAUD);
		return OK;
	case 0:
		if(!did0)
			return ERROR;
		(void) ioctl(fd, TCSBRK, 1);	/* Wait for output to drain */
		(void) ioctl(fd, TCFLSH, 0);	/* Flush input queue */
		(void) ioctl(fd, TCSETAW, &oldtty);	/* Restore modes */
		(void) ioctl(fd, TCXONC,1);	/* Restart output */
		return OK;
#endif


#ifdef USE_SGTTY
	/*
	 *  NOTE: this should transmit all 8 bits and at the same time
	 *   respond to XOFF/XON flow control.  If no FIONREAD or other
	 *   READCHECK alternative, also must respond to INTRRUPT char
	 *   This doesn't work with V7.  It should work with LLITOUT,
	 *   but LLITOUT was broken on the machine I tried it on.
	 */
	case 2:		/* Un-raw mode used by sz, sb when -g detected */
		if(!did0) {
			ioctl(fd, TIOCEXCL, 0);
			ioctl(fd, TIOCGETP, &oldtty);
			ioctl(fd, TIOCGETC, &oldtch);
#ifdef LLITOUT
			ioctl(fd, TIOCLGET, &Locmode);
#endif
		}
		tty = oldtty;
		tch = oldtch;
#ifdef READCHECK
		tch.t_intrc = Zmodem ? -1:030;	/* Interrupt char */
#else
		tch.t_intrc = Zmodem ? 03:030;	/* Interrupt char */
#endif
		tty.sg_flags |= (ODDP|EVENP|CBREAK);
		tty.sg_flags &= ~(ALLDELAY|CRMOD|ECHO|LCASE);
		ioctl(fd, TIOCSETP, &tty);
		ioctl(fd, TIOCSETC, &tch);
#ifdef LLITOUT
		ioctl(fd, TIOCLBIS, &Locbit);
#else
		bibi(99);	/* un-raw doesn't work w/o lit out */
#endif
		did0 = TRUE;
		return OK;
	case 1:
	case 3:
		if(!did0) {
			ioctl(fd, TIOCEXCL, 0);
			ioctl(fd, TIOCGETP, &oldtty);
			ioctl(fd, TIOCGETC, &oldtch);
#ifdef LLITOUT
			ioctl(fd, TIOCLGET, &Locmode);
#endif
		}
		tty = oldtty;
		tty.sg_flags |= RAW;
		tty.sg_flags &= ~ECHO;
		ioctl(fd, TIOCSETP, &tty);
		did0 = TRUE;
		Baudrate = getspeed(tty.sg_ospeed);
		return OK;
	case 0:
		if(!did0)
			return ERROR;
		ioctl(fd, TIOCSETP, &oldtty);
		ioctl(fd, TIOCSETC, &oldtch);
		ioctl(fd, TIOCNXCL, 0);
#ifdef LLITOUT
		ioctl(fd, TIOCLSET, &Locmode);
#endif
#ifdef TIOCFLUSH
		{ int x=1; ioctl(fd,TIOCFLUSH,&x); }
#endif
#endif

		return OK;
	default:
		return ERROR;
	}
}
Esempio n. 16
0
// virtual 
void LLViewerAssetStorage::storeAssetData(
	const LLTransactionID& tid,
	LLAssetType::EType asset_type,
	LLStoreAssetCallback callback,
	void* user_data,
	bool temp_file,
	bool is_priority,
	bool store_local,
	bool user_waiting,
	F64 timeout)
{
	LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID());
	llinfos << "LLViewerAssetStorage::storeAssetData (legacy) " << tid << ":" << LLAssetType::lookup(asset_type)
			<< " ASSET_ID: " << asset_id << llendl;
	
	if (mUpstreamHost.isOk())
	{
		if (mVFS->getExists(asset_id, asset_type))
		{
			// Pack data into this packet if we can fit it.
			U8 buffer[MTUBYTES];
			buffer[0] = 0;

			LLVFile vfile(mVFS, asset_id, asset_type, LLVFile::READ);
			S32 asset_size = vfile.getSize();

			LLAssetRequest *req = new LLAssetRequest(asset_id, asset_type);
			req->mUpCallback = callback;
			req->mUserData = user_data;

			if (asset_size < 1)
			{
				// This can happen if there's a bug in our code or if the VFS has been corrupted.
				llwarns << "LLViewerAssetStorage::storeAssetData()  Data _should_ already be in the VFS, but it's not! " << asset_id << llendl;
				// LLAssetStorage metric: Zero size VFS
				reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, 0, MR_ZERO_SIZE, __FILE__, __LINE__, "The file didn't exist or was zero length (VFS - can't tell which)" );

				delete req;
				if (callback)
				{
					callback(asset_id, user_data, LL_ERR_ASSET_REQUEST_FAILED, LL_EXSTAT_VFS_CORRUPT);
				}
				return;
			}
			else
			{
				// LLAssetStorage metric: Successful Request
				S32 size = mVFS->getSize(asset_id, asset_type);
				const char *message = "Added to upload queue";
				reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, size, MR_OKAY, __FILE__, __LINE__, message );

				if(is_priority)
				{
					mPendingUploads.push_front(req);
				}
				else
				{
					mPendingUploads.push_back(req);
				}
			}

			// Read the data from the VFS if it'll fit in this packet.
			if (asset_size + 100 < MTUBYTES)
			{
				BOOL res = vfile.read(buffer, asset_size);		/* Flawfinder: ignore */
				S32 bytes_read = res ? vfile.getLastBytesRead() : 0;
				
				if( bytes_read == asset_size )
				{
					req->mDataSentInFirstPacket = TRUE;
					//llinfos << "LLViewerAssetStorage::createAsset sending data in first packet" << llendl;
				}
				else
				{
					llwarns << "Probable corruption in VFS file, aborting store asset data" << llendl;

					// LLAssetStorage metric: VFS corrupt - bogus size
					reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, asset_size, MR_VFS_CORRUPTION, __FILE__, __LINE__, "VFS corruption" );

					if (callback)
					{
						callback(asset_id, user_data, LL_ERR_ASSET_REQUEST_NONEXISTENT_FILE, LL_EXSTAT_VFS_CORRUPT);
					}
					return;
				}
			}
			else
			{
				// Too big, do an xfer
				buffer[0] = 0;
				asset_size = 0;
			}
			mMessageSys->newMessageFast(_PREHASH_AssetUploadRequest);
			mMessageSys->nextBlockFast(_PREHASH_AssetBlock);
			mMessageSys->addUUIDFast(_PREHASH_TransactionID, tid);
			mMessageSys->addS8Fast(_PREHASH_Type, (S8)asset_type);
			mMessageSys->addBOOLFast(_PREHASH_Tempfile, temp_file);
			mMessageSys->addBOOLFast(_PREHASH_StoreLocal, store_local);
			mMessageSys->addBinaryDataFast( _PREHASH_AssetData, buffer, asset_size );
			mMessageSys->sendReliable(mUpstreamHost);
		}
		else
		{
			llwarns << "AssetStorage: attempt to upload non-existent vfile " << asset_id << ":" << LLAssetType::lookup(asset_type) << llendl;
			// LLAssetStorage metric: Zero size VFS
			reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, 0, MR_ZERO_SIZE, __FILE__, __LINE__, "The file didn't exist or was zero length (VFS - can't tell which)" );
			if (callback)
			{
				callback(asset_id, user_data,  LL_ERR_ASSET_REQUEST_NONEXISTENT_FILE, LL_EXSTAT_NONEXISTENT_FILE);
			}
		}
	}
	else
	{
		llwarns << "Attempt to move asset store request upstream w/o valid upstream provider" << llendl;
		// LLAssetStorage metric: Upstream provider dead
		reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, 0, MR_NO_UPSTREAM, __FILE__, __LINE__, "No upstream provider" );
		if (callback)
		{
			callback(asset_id, user_data, LL_ERR_CIRCUIT_GONE, LL_EXSTAT_NO_UPSTREAM);
		}
	}
}
Esempio n. 17
0
void LLAssetStorage::downloadCompleteCallback(
	S32 result,
	const LLUUID& file_id,
	LLAssetType::EType file_type,
	void* user_data, LLExtStat ext_status)
{
	lldebugs << "LLAssetStorage::downloadCompleteCallback() for " << file_id
		 << "," << LLAssetType::lookup(file_type) << llendl;
	LLAssetRequest* req = (LLAssetRequest*)user_data;
	if(!req)
	{
		llwarns << "LLAssetStorage::downloadCompleteCallback called without"
			"a valid request." << llendl;
		return;
	}
	if (!gAssetStorage)
	{
		llwarns << "LLAssetStorage::downloadCompleteCallback called without any asset system, aborting!" << llendl;
		return;
	}

	req->setUUID(file_id);
	req->setType(file_type);
	if (LL_ERR_NOERR == result)
	{
		// we might have gotten a zero-size file
		LLVFile vfile(gAssetStorage->mVFS, req->getUUID(), req->getType());
		if (vfile.getSize() <= 0)
		{
			llwarns << "downloadCompleteCallback has non-existent or zero-size asset " << req->getUUID() << llendl;
			
			result = LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE;
			vfile.remove();
		}
	}
	
	// find and callback ALL pending requests for this UUID
	// SJB: We process the callbacks in reverse order, I do not know if this is important,
	//      but I didn't want to mess with it.
	request_list_t requests;
	for (request_list_t::iterator iter = gAssetStorage->mPendingDownloads.begin();
		 iter != gAssetStorage->mPendingDownloads.end();  )
	{
		request_list_t::iterator curiter = iter++;
		LLAssetRequest* tmp = *curiter;
		if ((tmp->getUUID() == req->getUUID()) && (tmp->getType()== req->getType()))
		{
			requests.push_front(tmp);
			iter = gAssetStorage->mPendingDownloads.erase(curiter);
		}
	}
	for (request_list_t::iterator iter = requests.begin();
		 iter != requests.end();  )
	{
		request_list_t::iterator curiter = iter++;
		LLAssetRequest* tmp = *curiter;
		if (tmp->mDownCallback)
		{
			tmp->mDownCallback(gAssetStorage->mVFS, req->getUUID(), req->getType(), tmp->mUserData, result, ext_status);
		}
		delete tmp;
	}
}
bool B9UpdateManager::CopyFromTemp()
{
    qDebug() << "UpdateManager: Copying downloaded files from temp into actuall locations...";
    waitingbar->setDescription("Copying...");
    waitingbar->setMax(updateEntries.size());

    for(int i = 0; i < updateEntries.size(); i++)
    {

        QString src = CROSS_OS_GetDirectoryFromLocationTag("TEMP_DIR") + "/" + updateEntries[i].fileName;
        QString dest = CROSS_OS_GetDirectoryFromLocationTag(updateEntries[i].localLocationTag) + "/"
                + updateEntries[i].fileName;


        qDebug() << "from: " << src;
        qDebug() << "to: " << dest;

        if(QFile::exists(dest))
        {   //if were updating the executable - we must rename the old one instead of removing it..

            #ifdef Q_OS_WIN
            if(updateEntries[i].fileName == "B9Creator.exe")
            {
            #endif
            #ifdef Q_OS_MAC
            if(updateEntries[i].fileName == "B9Creator")
            {
            #endif
            #ifdef Q_OS_LINUX
            if(updateEntries[i].fileName == "B9Creator")
            {
            #endif

                //remove any old b9creator.exe.old files
                if(QFile::exists(QString(dest).append(".old")))
                    QFile::remove(QString(dest).append(".old"));

                //rename the executable we are running. to the .old
                if(rename(dest.toAscii(),
                           QString(dest).append(".old").toAscii()))
                    return false;
            }
            else
                QFile::remove(dest);
        }

        //were about to copy so we need to make any sub directories needed.
         QDir().mkpath(QFileInfo(dest).absolutePath());

        if(!QFile::copy(src,dest))
            return false;
        else
        {
            //at this point we have copied the file.
            //on unix - we have to mark the files as executable files.
            if(updateEntries[i].fileName == "B9Creator")
            {
                #ifdef Q_OS_MAC
                system(QString("chmod +x " + dest).toAscii());
                #endif
                #ifdef Q_OS_LINUX
                    system(QString("chmod +x \"" + dest + "\"").toAscii());
                #endif
            }
            if(updateEntries[i].fileName == "avrdude")
            {
                qDebug() << "APPLYING EXECUTABLNESS TO AVRDUDE!";
                #ifdef Q_OS_MAC
                    system(QString("chmod +x \"" + dest + "\"").toAscii());
                #endif
                #ifdef Q_OS_LINUX
                    system(QString("chmod +x \"" +  dest + "\"").toAscii());
                #endif
            }
            if(updateEntries[i].fileName == "avrdude.conf")
            {
                #ifdef Q_OS_MAC
                system(QString("chmod +x \"" + dest + "\"").toAscii());
                #endif
                #ifdef Q_OS_LINUX
                system(QString("chmod +x \"" + dest + "\"").toAscii());
                #endif
            }
        }

        waitingbar->setValue(i);

    }

    return true;
}


bool B9UpdateManager::UpdateLocalFileVersionList()
{
    int i;
    qDebug() << "UpdateManager: Updating Local File Versions List...";

    QFile vfile(CROSS_OS_GetDirectoryFromLocationTag("APPLICATION_DIR") + "/FileVersions.txt");
    if(!vfile.open(QIODevice::WriteOnly | QIODevice::Truncate))
    {
        return false;
    }
    QTextStream outStream(&vfile);

    for(i = 0; i < remoteEntries.size(); i++)
    {
        outStream << remoteEntries[i].localLocationTag;
        outStream << " ";
        outStream << "\"" << remoteEntries[i].fileName << "\"";
        outStream << " ";
        outStream << remoteEntries[i].version;
        if(i != remoteEntries.size() - 1)
            outStream << "\n";

    }

    vfile.close();
    return true;
}


//move files to proper locations or delete depreciated stuff.
void B9UpdateManager::TransitionFromPreviousVersions()
{
#ifndef Q_OS_LINUX
    //old 1.4 files in the wrong location
    QFile::remove(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/B9Creator_LOG.txt");
    QFile::remove(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/B9Firmware_1_0_9.hex");
    QFile::remove(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/avrdude.exe");
    QFile::remove(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/avrdude");
    QFile::remove(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/avrdude.conf");
#endif
    //OLD Material file sould be salvaged by b9matcat and removed.

    //check for old executables and delete them
    QFile(CROSS_OS_GetDirectoryFromLocationTag("EXECUTABLE_DIR") + "/B9Creator.exe.old").remove();
}