Exemple #1
0
void F64ReadLine::open(const wchar_t* fn)
{
    hFile = CreateFileW(fn, GENERIC_READ, FILE_SHARE_READ, 
        NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
    if(hFile == INVALID_HANDLE_VALUE) {
        is_good = false;
        return;
    }
    GetFileSizeEx(hFile, &filesz);
    setpointer(0);
    blocksz = filesz.QuadPart > ringsz ? ringsz : filesz.QuadPart;
}
Exemple #2
0
 virtual void visit(TypeStruct *t)
 {
     d_uns64 structoff = offset;
     for (size_t i = 0; i < t->sym->fields.dim; i++)
     {
         VarDeclaration *v = t->sym->fields[i];
         offset = structoff + v->offset;
         if (v->type->ty == Tclass)
             setpointer(offset);
         else
             v->type->accept(this);
     }
     offset = structoff;
 }
Exemple #3
0
void F64ReadLine::TestEnc(void)
{
    if(Args.getSourceCodepage() != NO_CODEPAGE) return;

    char* buf = new char[MEMPROTECT(32768)];
    int size = 0;
    setpointer(0);
    ReadFile(hFile, buf, 32768, (LPDWORD)&size, NULL);
    do {
        if(size > 2) { // 逆天等级的 bug 发现! 非 unsigned 情况下, 0xFF 和 '\xFF' 不同!
            if(buf[0] == '\xEF' && buf[1] == '\xBB' && buf[2] == '\xBF') {
                Args.setSourceCodepage(codepage = 65001);
                setpointer(3);
                break;
            }
        }
        if(size > 1) {
            if(buf[0] == '\xFF' && buf[1] == '\xFE') {
                Args.setSourceCodepage(codepage = 1200);
                setpointer(2);
                break;
            }
            if(buf[0] == '\xFE' && buf[1] == '\xFF') {
                Args.setSourceCodepage(codepage = 1201);
                setpointer(2);
                break;
            }
            if(TRUE == IsTextUnicode(buf, 32768, NULL)) {
                Args.setSourceCodepage(codepage = 1200);
                setpointer(2);
                break;
            }
        }
        if(isutf8(buf, 32768)) {
            Args.setSourceCodepage(codepage = 65001);
            setpointer(0);
            break;
        }
        Args.setSourceCodepage(codepage = GetACP());
        setpointer(0);
        break;
    } while(0);
    delete [] buf;
}
Exemple #4
0
static void do_gotopt_proc(void *data)
{
    int ind;
    WPoint wp;
    VPoint vp;
    int cg = get_cg();

    if (set_is_dataless(cg, track_setno)) {
        errmsg("No or inactive set selected");
        return;
    }

    xv_evalexpri(goto_index_item, &ind);
    if (get_point(cg, track_setno, ind, &wp) == RETURN_SUCCESS) {
        vp = Wpoint2Vpoint(wp);
        setpointer(vp);
    } else {
        errmsg("Point index out of range");
    }
}
int main (int argc, char * const argv[])
{

	int red[2], green[2], blue[2], ret[2];
	int id, leido, opcion, channel = NOSET; 
	int inputfd = STDIN_FILENO, outfd = STDOUT_FILENO;
	u_char buff[768] = {};
	char * inputfile = NULL;
	char * outputfile = NULL;
	char * header = NULL;
	
	extern char * optarg;
	extern int optind, opterr, optopt;

	while ((opcion = getopt(argc, argv, "hc:a:o:") ) >= 0)
	{
		switch(opcion)
		{
			case 'h':
				write(STDOUT_FILENO, "Usage: hist [OPTION...]\n  -h, 			     show this help and exit\n  -a <ppm-file>,	     use ppm-file file\n  -c <rojo/verde/azul>,	     show only the result for selected colour\n  -o <file-name>,	     create a file named file-name and stores the results\n", 249);
				return 0;

				break;

			case 'o':
				if ((outfd = open(optarg, O_CREAT | O_RDWR | O_TRUNC, 0640)) == -1)
				{
					perror("open");
					return -3;
				}

				outputfile = malloc(sizeof (char) * strlen(optarg));
				strcpy(outputfile, optarg);

				break;

			case 'a':
				if ((inputfd = open(optarg, O_RDONLY)) == -1)
				{
					perror("open");
					return -3;
				}

				inputfd = setpointer(inputfd, optarg);
				inputfile = malloc(sizeof (char) * strlen(optarg));
				strcpy(inputfile, optarg);

				break;

			case 'c':
				if (!strcmp("rojo", optarg)) 
					channel = RED;
				else if (!strcmp("verde", optarg)) 
					channel = GREEN;
				else if (!strcmp("azul", optarg)) 
					channel = BLUE;
				else
				{
					write(STDERR_FILENO, "Wrong argument\n", 15);
					return -3;
				}
				break;

			case '?':
				write(STDERR_FILENO, "Missing argument\n", 17);
				return -2;
				
				break;
		}
	}



	if (inputfd == STDIN_FILENO)
	{
		write(STDERR_FILENO, "No input file\n", 14);
		return -4;
	}

	header = malloc(sizeof (char) * 256);

	sprintf(header, "File read: %s\n", inputfile);
	if (outputfile != NULL)
		sprintf(header, "%sOutput file: %s\n", header, outputfile);
	if (channel == NOSET)
		sprintf(header, "%sChannels analized: all\n\n", header);
	if (channel == RED)
		sprintf(header, "%sChannel analized: red\n\n", header);
	if (channel == GREEN)
		sprintf(header, "%sChannel analized: green\n\n", header);
	if (channel == BLUE)
		sprintf(header, "%sChannel analized: blue\n\n", header);

	write(outfd,header,strlen(header));
	id = inic(red, green, blue, ret, channel);

	switch(id)
	{
		case RED: 
			while ((leido = read(red[0], buff, 768)) > 0)
			{
				if (analize(RED, ret[1], leido, buff) != 0)
					return -1;
			}

			return 0;
			break;

		case GREEN: 
			while ((leido = read(green[0], buff, 768)) > 0)
			{
				if (analize(GREEN, ret[1], leido, buff) != 0)
					return -1;
			}

			return 0;
			break;

		case BLUE: 
			while ((leido = read(blue[0], buff, 768)) > 0)
			{
				if (analize(BLUE, ret[1], leido, buff) != 0)
					return -1;
			}

			return 0;
			break;

	}

	u_char r[257];
	char outTxt[50];
	int pix[3][256], i, j, status;


	for(i = 0 ; i < 3  ; i++  )
		for(j = 0; j < 256; j++ )
			pix[i][j] = 0;

	while ((leido = read(inputfd, buff, 768)) > 0)
	{
		if (leido == -1)
		{
			perror("read");
			return -9;
		}
		if (channel == RED || channel == NOSET) 
			write(red[1], buff, leido); 
		if (channel == GREEN || channel == NOSET) 
			write(green[1], buff, leido);
		if (channel == BLUE || channel == NOSET) 
			write(blue[1], buff, leido);

		for(j = 0 ; j < 3 ; j++)
		{
			if (channel != NOSET) j += 2;
			leido = read(ret[0],r,257);
			for (i=1; i<257; i++)
			{
				pix [ r[0] ] [i-1] += (int) r[i];
			}
		}
	}


	if (channel == RED || channel == NOSET) 
		close(red[1]);
	if (channel == GREEN || channel == NOSET) 
		close(green[1]);
	if (channel == BLUE || channel == NOSET) 
		close(blue[1]);

	for(i = 0 ; i < 2 ; i++  )
	{
		if (channel != NOSET) 
			i += 2;

		wait(&status);

		if (WIFEXITED(status))
		{
			if (WEXITSTATUS(status) != 0)
				write(STDERR_FILENO, "Child ended with error\n", 23);
		}
		else
			write(STDERR_FILENO, "Child ended signalized\n", 17);
	}

	switch (channel)
	{
		case NOSET:
			for (i = 0 ; i < 256 ; i++) 
			{
				sprintf(outTxt, "red[%3d]=%d\t\tgreen[%3d]=%d\t\tblue[%3d]=%d\n", i, pix[0][i], i, pix[1][i], i, pix[2][i]);
				write(outfd, outTxt, strlen(outTxt));
			}
			break;
		case RED:
			for (i = 0 ; i < 256 ; i++) 
			{
				sprintf(outTxt, "red[%3d]=%d\n", i, pix[0][i]);
				write(outfd, outTxt, strlen(outTxt));
			}
			break;
		case GREEN:
			for (i = 0 ; i < 256 ; i++) 
			{
				sprintf(outTxt, "green[%3d]=%d\n", i, pix[1][i]);
				write(outfd, outTxt, strlen(outTxt));
			}
			break;
		case BLUE:
			for (i = 0 ; i < 256 ; i++) 
			{
				sprintf(outTxt, "blue[%3d]=%d\n", i, pix[2][i]);
				write(outfd, outTxt, strlen(outTxt));
			}
			break;
	
			
	}

	return 0;
}
Exemple #6
0
 virtual void visit(TypeDelegate *t) { setpointer(offset); } // delegate is {context, function}
Exemple #7
0
 virtual void visit(TypeClass *t) { setpointer(offset); }
Exemple #8
0
 virtual void visit(TypeReference *t) { setpointer(offset); }
Exemple #9
0
 virtual void visit(TypePointer *t) 
 {
     if (t->nextOf()->ty != Tfunction) // don't mark function pointers
         setpointer(offset);
 }
Exemple #10
0
 virtual void visit(TypeAArray *t) { setpointer(offset); }
Exemple #11
0
 virtual void visit(TypeDArray *t) { setpointer(offset + sz_size_t); } // dynamic array is {length,ptr}
Exemple #12
0
 virtual void visit(TypeBasic *t)
 {
     if (t->ty == Tvoid)
         setpointer(offset);
 }
Exemple #13
0
long
conswrite(Chan *c, void *va, long count, vlong offset)
{
	char buf[128], *p;
	int x, y;

	USED(offset);

	if(c->qid.type & QTDIR)
		error(Eperm);

	switch((ulong)c->qid.path) {
	default:
		error(Egreg);
	case Qcons:
		if(canrlock(&kprintq.l)){
			if(kprintq.q != nil){
				if(waserror()){
					runlock(&kprintq.l);
					nexterror();
				}
				qwrite(kprintq.q, va, count);
				poperror();
				runlock(&kprintq.l);
				return count;
			}
			runlock(&kprintq.l);
		}
		return write(1, va, count);
	case Qsysctl:
		return sysconwrite(va, count);
	case Qconsctl:
		if(count >= sizeof(buf))
			count = sizeof(buf)-1;
		strncpy(buf, va, count);
		buf[count] = 0;
		if(strncmp(buf, "rawon", 5) == 0) {
			kbd.raw = 1;
			return count;
		}
		else
		if(strncmp(buf, "rawoff", 6) == 0) {
			kbd.raw = 0;
			return count;
		}
		error(Ebadctl);
	case Qkeyboard:
		for(x=0; x<count; ) {
			Rune r;
			x += chartorune(&r, &((char*)va)[x]);
			gkbdputc(gkbdq, r);
		}
		return count;
	case Qpointer:
		if(count > sizeof buf-1)
			count = sizeof buf -1;
		memmove(buf, va, count);
		buf[count] = 0;
		p = nil;
		x = strtoul(buf+1, &p, 0);
		if(p == nil || p == buf+1)
			error(Eshort);
		y = strtoul(p, 0, 0);
		setpointer(x, y);
		return count;
	case Qnull:
		return count;
	case Qpin:
		if(up->env->pgrp->pin != Nopin)
			error("pin already set");
		if(count >= sizeof(buf))
			count = sizeof(buf)-1;
		strncpy(buf, va, count);
		buf[count] = '\0';
		up->env->pgrp->pin = atoi(buf);
		return count;
	case Qtime:
		if(count >= sizeof(buf))
			count = sizeof(buf)-1;
		strncpy(buf, va, count);
		buf[count] = '\0';
		timeoffset = strtoll(buf, 0, 0)-osusectime();
		return count;
	case Quser:
		if(count >= sizeof(buf))
			error(Ebadarg);
		strncpy(buf, va, count);
		buf[count] = '\0';
		if(count > 0 && buf[count-1] == '\n')
			buf[--count] = '\0';
		if(count == 0)
			error(Ebadarg);
		if(strcmp(up->env->user, eve) != 0)
			error(Eperm);
		setid(buf, 0);
		return count;
	case Qhostowner:
		if(count >= sizeof(buf))
			error(Ebadarg);
		strncpy(buf, va, count);
		buf[count] = '\0';
		if(count > 0 && buf[count-1] == '\n')
			buf[--count] = '\0';
		if(count == 0)
			error(Ebadarg);
		if(strcmp(up->env->user, eve) != 0)
			error(Eperm);
		kstrdup(&eve, buf);
		return count;
	case Qhoststdout:
		return write(1, va, count);
	case Qhoststderr:
		return write(2, va, count);
	case Qjit:
		if(count >= sizeof(buf))
			count = sizeof(buf)-1;
		strncpy(buf, va, count);
		buf[count] = '\0';
		x = atoi(buf);
		if (x < 0 || x > 9)
			error(Ebadarg);
		cflag = x;
		return count;
	case Qsysname:
		if(count >= sizeof(buf))
			count = sizeof(buf)-1;
		strncpy(buf, va, count);
		buf[count] = '\0';
		kstrdup(&ossysname, buf);
		return count;
	case Qsnarf:
		if(offset+count >= SnarfSize)
			error(Etoobig);
		snarftab->qid.vers++;
		memmove((uchar*)(c->aux)+offset, va, count);
		return count;
	}
	return 0;
}