Exemple #1
0
void main() {

   byte value,cmd;
   EEPROM_ADDRESS address;

   init_ext_eeprom();

   do {
      do {
         printf("\r\nRead or Write: ");
         cmd=getc();
         cmd=toupper(cmd);
         putc(cmd);
      } while ( (cmd!='R') && (cmd!='W') );

      printf("\n\rLocation: ");

      address = gethex();

      if(cmd=='R')
         printf("\r\nValue: %X\r\n",READ_EXT_EEPROM( address ) );

      if(cmd=='W') {
         printf("\r\nNew value: ");
         value = gethex();
         printf("\n\r");
         WRITE_EXT_EEPROM( address, value );
      }
   } while (TRUE);

}
Exemple #2
0
main()
{
   byte valor, dispositivo, tecla;
   long int endereco;
   do
	{
      do
		{
         printf("\r\nLeitura ou Escrita: ");
         tecla = toupper(getc());
         putc(tecla);
      } while ( (tecla!='L') && (tecla!='E') );

      printf("\n\rDispositivo: ");
		dispositivo = gethex1();
		printf("\n\rEndereco: ");
      endereco = gethex();
      endereco = (endereco<<8)+gethex();
      if(tecla=='L') printf("\r\nValor: %X\r\n",le_eeprom( dispositivo, endereco ) );
      if(tecla=='E')
		{
         printf("\r\nNovo valor: ");
         valor = gethex();
         printf("\n\r");
         escreve_eeprom( dispositivo, endereco, valor );
      }
   } while (TRUE);
}
Exemple #3
0
static void hexcolor2rgb(const char *s, mng_uint16 *r, mng_uint16 *g, mng_uint16 *b)
{
	if(lstrlen(s)!=7) return;
	if(s[0]!='#') return;
	(*r)= gethex(&s[1]); (*r)= ((*r)<<8)|(*r);
	(*g)= gethex(&s[3]); (*g)= ((*g)<<8)|(*g);
	(*b)= gethex(&s[5]); (*b)= ((*b)<<8)|(*b);
}
Exemple #4
0
static void *urldec_str(CxMem *cx, const char **src_p, const char *end, unsigned *len_p)
{
	const char *s;
	char *d, *dst;
	int c, len = 0;

	/* estimate size */
	for (s = *src_p; s < end; s++) {
		if (*s == '%')
			s += 2;
		else if (*s == '&' || *s == '=')
			break;
		len++;
	}

	/* allocate room */
	d = dst = cx_alloc(cx, len + 1);
	if (!dst)
		return NULL;

	/* write out */
	for (s = *src_p; s < end; ) {
		if (*s == '%') {
			if (s + 3 > end)
				goto err;
			c = gethex(s[1]) << 4;
			c |= gethex(s[2]);
			if (c < 0)
				goto err;
			s += 3;
			*d++ = c;
		} else if (*s == '+') {
			*d++ = ' ';
			s++;
		} else if (*s == '&' || *s == '=') {
			break;
		} else {
			*d++ = *s++;
		}
	}
	*d = 0;
	*len_p = d - dst;
	*src_p = s;
	return dst;
err:
	cx_free(cx, dst);
	return NULL;
}
Exemple #5
0
GraphicComp* ImportCmd::PPM_Image (const char* filename) {
    GraphicComp* comp = nil;
    FILE* file = fopen(filename, "r");
    boolean compressed;
    file = CheckCompression(file, filename, compressed);

    if (file != nil) {
        char line[1000];
        do {
            fgets(line, 1000, file);
        } while (strcmp(line, "gsave\n") != 0);

        fgets(line, 1000, file);                    // translate
        fgets(line, 1000, file);                    // scale
        fgets(line, 1000, file);                    // scale
        fgets(line, 1000, file);                    // sizes
        int w, h, d;
        sscanf(line, "%d %d %d", &w, &h, &d);
        fgets(line, 1000, file);                    // [ ... ]
        fgets(line, 1000, file);                    // { ... }
        fgets(line, 1000, file);                    // false 3
        fgets(line, 1000, file);                    // colorimage

        Raster* raster = new Raster(w, h);

        for (int row = h - 1; row >= 0; --row) {
            for (int column = 0; column < w; ++column) {
                int red = gethex(file);
                int green = gethex(file);
                int blue = gethex(file);
                raster->poke(
                    column, row,
                    float(red)/0xff, float(green)/0xff, float(blue)/0xff, 1.0
                );
            }
        }
        raster->flush();
        comp = new RasterComp(new RasterRect(raster), filename);
    }
    
    if (compressed) {
        pclose(file);

    } else {
        fclose(file);
    }
    return comp;
}
Exemple #6
0
main() {
   char house_code;
   byte key_code;

   printf("Online\n\r");

   while (TRUE) {

      if(kbhit()) {
        house_code = getc();
        if((house_code>='A') && (house_code<='P')) {
          putc(house_code);
          key_code=gethex();
          x10_write(house_code,key_code);
          x10_write(house_code,key_code);
        }
      }

      if(x10_data_ready()) {
        putc('>');
        x10_read(&house_code,&key_code);
        printf("%c%2X",house_code,key_code);
      }
   }
}
Exemple #7
0
GraphicComp* ImportCmd::PGM_Image (const char* filename) {
    GraphicComp* comp = nil;
    FILE* file = fopen(filename, "r");

    if (file != nil) {
        char line[1000];
        do {
            fgets(line, 1000, file);
        } while (strcmp(line, "gsave\n") != 0);

        fgets(line, 1000, file);                    // translate
        fgets(line, 1000, file);                    // scale
        fgets(line, 1000, file);                    // sizes
        int w, h, d;
        sscanf(line, "%d %d %d", &w, &h, &d);
        fgets(line, 1000, file);                    // [ ... ]
        fgets(line, 1000, file);                    // { ... }
        fgets(line, 1000, file);                    // image

        Raster* raster = new Raster(w, h);

        for (int row = h - 1; row >= 0; --row) {
            for (int column = 0; column < w; ++column) {
                int byte = gethex(file);
                float g = float(byte) / 0xff;
                raster->poke(column, row, g, g, g, 1.0);
            }
        }
        raster->flush();
        comp = new RasterComp(new RasterRect(raster), filename);
    }
    fclose(file);
    return comp;
}
Exemple #8
0
/* Hexadecimal to integer */
int htoi(char s[], int length)
{
    int i, j, num, result;

    /* Check for a prefix */
    if (contains_prefix(s))
    {
        j = length - 3;
        result = 0;

        /*
         * Completely ignore the prefix
         * and calculate
         */
        for (i = 2; i <= length - 1; ++i)
        {
            num = gethex(s[i]);
            /* valid character? */
            if (num == -1)
                return -1;

            result += num * pow(16, j--);
        }

        return result;
    }

    return -2;
}
Exemple #9
0
static void dcmd (void)
{
    WORD newptr;
    WORD count;
    BYTE c;

    if (gethex((WORD *)&newptr))
	dispptr = newptr;
    else newptr = dispptr;
    for (count = 0; count < 64; count++)
    {
	if ((count & 0xf) == 0)
	{
	    phexw((WORD)dispptr);
	    print(" ");
	}
	print(" ");
	phexb(mem8080[dispptr++]);
	if ((count & 0xf) == 0xf)
	{
	    print("   ");
	    while (newptr < dispptr)
	    {
		c = mem8080[newptr++] & 0x7f;
		if (c < ' ') c = '.';
		write(1,&c,1);
	    }
	    print("\r\n");
	}
    }
}
    GBDisassembleViewer()
        : Viewer(wxT("GBDisassemble"))
    {
        gethex(goto_addr, "GotoAddress", 4);
        goto_addr->SetFocus();
        regctrl(AF);
        regctrl(BC);
        regctrl(DE);
        regctrl(HL);
        regctrl(SP);
        regctrl(PC);
        regctrl(LY);
        regctrl(IFF);
        flagctrl(Z);
        flagctrl(N);
        flagctrl(H);
        flagctrl(C);
        dis = XRCCTRL(*this, "Disassembly", DisList);

        if (!dis)
            baddialog();

        // refit listing for longest line
        dis->Refit(26);
        Fit();
        SetMinSize(GetSize());
        dis->maxaddr = (uint32_t)~0;
        GotoPC();
    }
Exemple #11
0
main() {
   long int value;

   do {
      printf("\r\n\nHex value: ");
      value=gethex();
      value=value<<8|gethex();

      printf("\r\nAs dollers:  ");
      print_fp_2(value);

      printf("\r\nAs Volts:  ");
      print_as_volts(value);

   } while (TRUE);

}
Exemple #12
0
static int charliteral(int c)
{
	if(!bCanInsertSymbol)
	{
		//maks: solve the error when colorize "oi/oi"
		WASLITERAL = 0;
		return c;
	}

    if (c == '\\') {
	switch ((c = EiC_nextchar())) {
	case 'n': c = '\n'; break;     /* newline */
	case 't': c = '\t'; break;     /* tabspace */
	case 'v': c = '\v'; break;     /* vertical tab */
	case 'b': c = '\b'; break;     /* backspace */
	case 'r': c = '\r'; break;     /* carriage return */
	case 'f': c = '\f'; break;     /* formfeed */
	case 'a': c = '\a'; break;     /* bell */
	case '\\': c = '\\'; break;    /* backslash */
	case '\'': c = '\''; break;    /* single quote */
	case '"': c = '\"'; break;     /* double quote */
        case '?': c = '\?'; break;     /* question mark */
	case 'x':		       /* string of hex characters */
	case 'X':{
	    int i, val = 0;
	    while ((i = gethex((c = EiC_nextchar()))) > -1) {
		val = val * 16 + i;
	    }
	    retract(c);
	    if (val > 255)
		EiC_error("Illegal character hex value");
	    c = val;
	}
	break;
	default:
	    if (getoct(c) > -1) {		/* octal characters */
		int i, val = 0;
		while ((i = getoct(c)) > -1) {
		    val = val * 8 + i;
		    c = EiC_nextchar();
		}
		retract(c);
		if (val > 255)
		    EiC_error("Illegal character octal value");
		c = val;
	    } else
		EiC_error("Illegal character escape sequence `\\%c'", c);
	    break;
	}
	WASLITERAL = 1;
    } else
	WASLITERAL = 0;
    return ((signed char )c);
}
Exemple #13
0
main() {

   byte value,cmd;
   EEPROM_ADDRESS address;

   init_ext_eeprom();

   do {
      do {
         printf("\r\nRead or Write: ");
         cmd=getc();
         cmd=toupper(cmd);
         putc(cmd);
      } while ( (cmd!='R') && (cmd!='W') );

      printf("\n\rLocation: ");

#if sizeof(EEPROM_ADDRESS)==1
      address = gethex();
#else
#if EEPROM_SIZE>0xfff
      address = gethex();
#else
      address = gethex1();
#endif
      address = (address<<8)+gethex();
#endif

      if(cmd=='R')
         printf("\r\nValue: %X\r\n",READ_EXT_EEPROM( address ) );

      if(cmd=='W') {
         printf("\r\nNew value: ");
         value = gethex();
         printf("\n\r");
         WRITE_EXT_EEPROM( address, value );
      }
   } while (TRUE);

}
Exemple #14
0
static int gcmd (void)
{
    WORD newpc, newbrk;
    WORD gotpc;

    gotpc = gethex((WORD *)&newpc);

    // Handle breakpoint 1

    if (*cptr++ == ',')
    {
	if (!gethex((WORD *)&newbrk))
	{
	    print("Illegal breakpoint\n");
	    return (FALSE);
	}
	breakpt1 = newbrk;
	brkdata1 = mem8080[breakpt1];
	mem8080[breakpt1] = 8;
    }

    // Handle breakpoint 2

    if (*cptr++ == ',')
    {
	if (!gethex((WORD *)&newbrk))
	{
	    print("Illegal breakpoint\n");
	    mem8080[breakpt1] = brkdata1;
	    breakpt1 = 0;
	    return (FALSE);
	}
	breakpt2 = newbrk;
	brkdata2 = mem8080[breakpt2];
	mem8080[breakpt2] = 8;
    }

    if (gotpc) savepc = newpc;
    return (TRUE);
}
Exemple #15
0
static void lcmd (void)
{
    WORD newptr;
    WORD count;

    if (gethex((WORD *)&newptr))
	listptr = newptr;
    for (count = 0; count < 12; count++)
    {
	printf ("%X: ", listptr);
	listptr += disassemble (listptr);
    }
}
Exemple #16
0
BINARY  * converthexbytes( unsigned char * s)
{
   int      val, k=0, m;
   BINARY * p;
   int      len = strlen(s);

   printf("--input hex: %s\n",s);   

   p = malloc( sizeof(BINARY) );

   p->b   = malloc( len / 2 );
   p->blen= len / 2;

   while( *s )
   {
      val   = gethex(*s);
      s++;
      val <<= 4;

      if( !*s ) break; // check that we have 2 digits for hex, else ignore the 1st

      val |= gethex(*s);
      s++;

      p->b[k++] = val;
   }

   if( k != p->blen )
   {
      printf("hex length mismatch\n");
   }

   printf("--output hex[%d]: ",p->blen); for(m=0;m<p->blen;m++) printf("%2.2x", p->b[m]);

   printf(" \n");

   return p;
}
Exemple #17
0
int main(int argc, char **argv)
{
	FILE *pfp, *fp;
	unsigned addr, patch;
	char line[256];
	char *s;


	if (argc != 3 || (pfp = fopen(argv[1], "rt")) == NULL || (fp = fopen(argv[2], "r+b")) == NULL) {
		fprintf(stderr, "usage: patchbin patchfile filetopatch\n");
		exit(1);
	}


	while (fgets(line, 256, pfp)) {
		for (s = line; *s && (*s == ' ' || *s == '\t' || *s == '\n'); s++)
			;
		if (!*s)
			continue;

		if ((s = gethex(s, &addr)) == NULL || addr < 0x100 || fseek(fp, addr - 0x100, 0) != 0)
			fprintf(stderr, "bad address: %s", line);
		else
			while ((s = gethex(s, &patch))) {
				if (patch < 0 || patch >= 0x100) {
					fprintf(stderr, "bad patch (%04X) in line %s", patch, line);
					break;
				}
				else
					putc(patch, fp);
			}
	}
	fclose(pfp);
	fclose(fp);
	return 0;
}
/* Encode string to UTF-8 : OpenPegasus doesn't support non UTF-8 Characters */
std::string CIMHelper::encode(std::string str)
{
	static std::string unreserved = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.,;:~+'`><}{|][!@#$%^&*()?\"/\\\t\n\r";
	std::string r;
	size_t neg = -1;
    for (size_t i = 0; i < str.length(); i++ )
    {
      	char c = str.at(i);
      	if (unreserved.find(c) != neg)
        	r+=c;
    	else
        	r+=gethex(c);
    }

	return r;
}
Exemple #19
0
GraphicComp* ImportCmd::PGM_Image (const char* filename) {
    GraphicComp* comp = nil;
    FILE* file = fopen(filename, "r");

    if (file != nil) {
        char line[1000];
        do {
            Fgets(line, 1000, file);
        } while (strcmp(line, "gsave\n") != 0);

        Fgets(line, 1000, file);                    // translate
        Fgets(line, 1000, file);                    // scale
        Fgets(line, 1000, file);                    // sizes
        int w, h, d;
        sscanf(line, "%d %d %d", &w, &h, &d);
        Fgets(line, 1000, file);                    // [ ... ]
        Fgets(line, 1000, file);                    // { ... }
        Fgets(line, 1000, file);                    // image

	if (d == 1) {
	    Bitmap* bm = new Bitmap((void*)nil, w, h);

	    for (int row = h - 1; row >= 0; --row) {
		for (int column = 0; column < w; column += 8) {
		    int byte = gethex(file);
		    int bit = 0x80;
		    int limit = column + 8;

		    for (int pos = column; pos < limit; ++pos, bit >>= 1) {
			bool value = !(byte & bit);
			bm->poke(value, pos, row);
		    }
		}
	    }
	    bm->flush();
	    comp = new StencilComp(new UStencil(bm, bm, stdgraphic));

	} else {
// Get a statement
numvar getstatement(void) {
numvar retval = 0;
//char *fetchmark;
numvar fetchmark;

	chkbreak();

	if (sym == s_while) {
		// at this point sym is pointing at s_while, before the conditional expression
		// save fetchptr so we can restart parsing from here as the while iterates
		//fetchmark = fetchptr;
		fetchmark = markparsepoint();
		for (;;) {
			//fetchptr = fetchmark;			// restore to mark
			//primec();						// set up for mr. getsym()
			returntoparsepoint(fetchmark, 0);
			getsym(); 						// fetch the start of the conditional
			if (getnum()) {
				retval = getstatement();
				if (sym == s_returning) break;	// exit if we caught a return
			}
			else {
				skipstatement();
				break;
			}
		}
	}
	
	else if (sym == s_if) {
		getsym();			// eat "if"
		if (getnum()) {
			retval = getstatement();
			if (sym == s_else) {
				getsym();	// eat "else"
				skipstatement();
			}
		} else {
			skipstatement();
			if (sym == s_else) {
				getsym();	// eat "else"
				retval = getstatement();
			}
		}
	}
	else if (sym == s_lcurly) {
		getsym(); 	// eat "{"
		while ((sym != s_eof) && (sym != s_returning) && (sym != s_rcurly)) retval = getstatement();
		if (sym == s_rcurly) getsym();	// eat "}"
	}
	else if (sym == s_return) {
		getsym();	// eat "return"
		if ((sym != s_eof) && (sym != s_semi)) retval = getnum();
		sym = s_returning;		// signal we're returning up the line
	}
	else if (sym == s_switch) retval = getswitchstatement();

	else if (sym == s_function) cmd_function();

	else if (sym == s_run) {	// run macroname
		getsym();
		if ((sym != s_script_eeprom) && (sym != s_script_progmem) &&
			(sym != s_script_file)) unexpected(M_id);

		// address of macroid is in symval via parseid
		// check for [,snoozeintervalms]
		getsym();	// eat macroid to check for comma; symval untouched
		if (sym == s_comma) {
			vpush(symval);
			getsym();			// eat the comma
			getnum();			// get a number or else
			startTask(vpop(), expval);
		}
		else startTask(symval, 0);
	}

	else if (sym == s_stop) {
		getsym();
		if (sym == s_mul) {						// stop * stops all tasks
			initTaskList();
			getsym();
		}
		else if ((sym == s_semi) || (sym == s_eof)) {
			if (background) stopTask(curtask);	// stop with no args stops the current task IF we're in back
			else initTaskList();				// in foreground, stop all
		}
		else stopTask(getnum());
	}

	else if (sym == s_boot) reboot();
	else if (sym == s_rm) {		// rm "sym" or rm *
		getsym();
		if (sym == s_script_eeprom) {
			eraseentry(idbuf);
		} 
		else if (sym == s_mul) nukeeeprom();
		else if (sym != s_undef) expected(M_id);
		getsym();
	}
	else if (sym == s_ps) 		{ getsym();	showTaskList(); }
	else if (sym == s_peep) 	{ getsym(); cmd_peep(); }
	else if (sym == s_ls) 		{ getsym(); cmd_ls(); }
	else if (sym == s_help) 	{ getsym(); cmd_help(); }
	else if (sym == s_print) 	{ getsym(); cmd_print(); }
	else if (sym == s_semi)		{ ; }	// ;)

#ifdef HEX_UPLOAD
	// a line beginning with a colon is treated as a hex record
	// containing data to upload to eeprom
	//
	// TODO: verify checksum
	//
	else if (sym == s_colon) {
		// fetchptr points at the byte count
		byte byteCount = gethex(2);		// 2 bytes byte count
		int addr = gethex(4);			// 4 bytes address
		byte recordType = gethex(2);	// 2 bytes record type; now fetchptr -> data
		if (recordType == 1) reboot();	// reboot on EOF record (01)
		if (recordType != 0) return;	// we only handle the data record (00)
		if (addr == 0) nukeeeprom();	// auto-clear eeprom on write to 0000
		while (byteCount--) eewrite(addr++, gethex(2));		// update the eeprom
		gethex(2);						// discard the checksum
		getsym();						// and re-prime the parser
	}
#endif

	else getexpression();

	if (sym == s_semi) getsym();		// eat trailing ';'
	return retval;
}
Exemple #21
0
void yy_str_deescape(const char *str, struct astr *astr) {
	int rlen = 0;
	int i;
	for (i = 0; str[i]; i++) {
		if (str[i] == '\\') {
			i++;
			rlen++;
			if (str[i] == 'x')
				i += 2;
		} else if (str[i] != '"') {
			rlen++;
		}
	}
	char *res = malloc (rlen + 1);
	int j;
	for (i = 0, j = 0; str[i]; i++) {
		if (str[i] == '\\') {
			i++;
			switch (str[i]) {
				case '\\':
				case '\'':
				case '\"':
				case '\?':
					res[j++] = str[i];
					break;
				case 'n':
					res[j++] = '\n';
					break;
				case 'f':
					res[j++] = '\f';
					break;
				case 't':
					res[j++] = '\t';
					break;
				case 'a':
					res[j++] = '\a';
					break;
				case 'v':
					res[j++] = '\v';
					break;
				case 'r':
					res[j++] = '\r';
					break;
				case 'x':
					res[j++] = gethex(str[i+1]) << 4 | gethex(str[i+2]);
					i += 2;
					break;
				default:
					assert(0);
			}
			if (str[i] == 'x')
				i += 2;
		} else if (str[i] != '"') {
			res[j++] = str[i];
		}
	}
	res[j] = 0;
	assert(j == rlen);
	astr->len = rlen;
	astr->str = res;
}
Exemple #22
0
int main()
{
    printf("This works %d%%\n", 100);
    printf("Hello World!\n");
    printf("Norm  nums: %d %u %x %c %s%s", -1, -2, 0xabcdefab, 'X', "x", "\n");

    // Note: these don't work with __simple_printf!
    printf("BFill nums: %4d %12u %10x %3c %3s%s", -1, -2, 0xabcdefab, 'X', "x", "\n");
    printf("LFill nums: %04d %012u %010x %3c %3s%s", -1, -2, 0xabcdefab, 'X', "x", "\n");
#pragma GCC diagnostic ignored "-Wformat"
    // The underlying library actively ignores the zeros -- we want to test it!
    printf("RFill nums: %-04d %-012u %-010x %-3c %-3s%s", -1, -2, 0xabcdefab, 'X', "x", "\n");
    // The underlying library detects and handles this error - we want to test it!
    printf("%");
#pragma GCC diagnostic warning "-Wformat"

#ifdef __TINY_IO_H
    putstr("Put*  nums: ");
    putdec(-1);
    putchar(' ');
    putudec(-1);
    putchar(' ');
    puthex(0xabcdefab);
    putchar(' ');
    putchar('X');
    putchar(' ');
    putstr("x");
    putchar(' ');
    putfnum(0xabcdefab, 16, 0, 10, '0');
    putchar('\n');

    putlhex(-10000000000L);
    putchar(' ');
    putldec(-10000000000L);
    putchar(' ');
    putlfnum(0xabcdefabcdef, 16, 0, 16, '0');
    putchar('\n');
#endif

    char buf[80];
    sprintf(buf, "Norm  nums: %d %u %x %c %s", -1, -2, 0xabcdefab, 'X', "x");
    puts(buf);
    int d;
    unsigned u, x;
    char c;
    char s[20];
    int n = sscanf(buf, "Norm  nums: %d %u %x %c %s\n", &d, &u, &x, &c, s);
    printf("Scan  nums: %d %u %x %c %s (%d scanned)\n", d, u, x, c, s, n);

    printf("\nGimme a character: ");
    char ch = getchar();
    printf("\nYou typed: ");
    putchar(ch);
    putchar('\n');

    int age;
    do {
        printf("\nHow old are you? ");
        scanf("%u", &age);
    } while (!age);
    printf("In ten years, you'll be: %d\n\n", age + 10);

    sprintf(buf, "BFill nums: %4d %12u %10x %3c %3s", -1, -2, 0xabcdefab, 'X', "x");
    puts(buf);
    n = sscanf(buf, "BFill nums: %4d %12u %10x %3c %3s\n",&d, &u, &x, &c, s);
    printf("Scan  nums: %d %u %x %c %s (%d scanned)\n", d, u, x, c, s, n);

    sprintf(buf, "LFill nums: %04d %012u %010x %3c %3s", -1, -2, 0xabcdefab, 'X', "x");
    puts(buf);
    n = sscanf(buf, "LFill nums: %04d %012u %010x %3c %3s\n",&d, &u, &x, &c, s);
    printf("Scan  nums: %d %u %x %c %s (%d scanned)\n", d, u, x, c, s, n);

#ifdef __TINY_IO_H
    printf("\nEnter a string up to 4 characters: ");
    safe_gets(s, 5);
    printf("You entered: %s\n", s);

    printf("\nEnter a decimal: ");
    d = getdec();
    printf("You entered: %d\n", d);

    printf("\nEnter an unsigned decimal: ");
    u = getudec();
    printf("You entered: %d\n", u);

    printf("\nEnter a hex number: ");
    u = gethex();
    printf("You entered: %x\n", u);

    printf("\nEnter a 1-4 digit number: ");
    d = getfnum(10, 1, 4);
    printf("You entered: %d\n", (int)d);

    long long ld;
    unsigned long long lu, lx;

    printf("\nEnter a long long decimal: ");
    ld = getldec();
    printf("You entered: "); putldec(ld); putchar('\n');

    printf("\nEnter an unsigned long long decimal: ");
    lu = getludec();
    printf("You entered: "); putludec(lu); putchar('\n');

    printf("\nEnter a long long hex number: ");
    lx = getlhex();
    printf("You entered: "); putlhex(lx); putchar('\n');

    printf("\nEnter a 1-12 digit long long number: ");
    ld = getlfnum(10, 1, 12);
    printf("You entered: "); putldec(ld); putchar('\n');
#endif

    _serialLock = 1;
    printf("\n\nMultithreaded tests.\n"
           "Note this will be quite messed up because multiple cogs\n"
           "will be doing I/O on a character-by-character basis...\n");
    _start_cog_thread(threadStack(0), &testThread, (void*)1, &tls[0]);
    _start_cog_thread(threadStack(1), &testThread, (void*)2, &tls[1]);
    testThread(0);

    printf("\nBye!\n");

    return 0;
}
Exemple #23
0
void lclcmd(int ch)
{
 if (ch == 'd')			/* dump memory */
 {
  putx(' ');
  if (gethex())
  {
   unsigned char *p;

   p = (unsigned char *) (int) val;
   if (gethex())
   {
    newline();
    prtbuf(p,val);
   }
  }
 }
#if DBGMSG
 else if (ch == 'D')		/* dump dbg buffer */
 {
  newline();
  int empty = dbgemp;
  for (int i = 0; i < dbgcnt; i++)
  {
   P_DBGMSG p = &dbgdata[empty];
   float t = (float) p->time / 1000;
   printf("%8.3f %8s %8x %12d\n", t, p->str,
	  (unsigned int) p->val, (int) p->val);
   empty++;
   if (empty >= MAXDBGMSG)
    empty = 0;
   while (1)
   {
    if (pollBufChar() == 0)
     break;
   }
  }
  printf("z %d x %d\n", zLoc, xLoc);
 }
 else if (ch == 'E')		/* clear debug buffer */
 {
  clrDbgBuf();
 }
#endif
#if ENCTEST
 else if (ch == 'e')
 {
  printf(" counts ");
  fflush(stdout);
  if (getnum())
  {
   encInit();
   encRunCount = val;
   encStart(true);
  }
  else
  {
   printf(" stop[y] ");
   fflush(stdout);
   ch = getx();
   if (ch == 'y')
   {
    encStop();
   }
  }
 }
#endif
 else if (ch == 't')
 {
  putx(' ');
  if (getnum())
  {
   newline();
   int i;
   int j = 0;
   for (i = 0; i < val; i++)
   {
    LOAD(XLDZCTL, j);
    read1(XRDZCTL);
    int testVal = j & ((1 << (zCtl_size)) - 1);
    if (readval.i != testVal)
    {
     setSync();
     printf("%4d z testVal %8x readVal %8x\n",
	    i, (unsigned int) testVal, (unsigned int) readval.i);
     clrSync();
    }

    LOAD(XLDXCTL, j);
    read1(XRDXCTL);
    testVal = j & ((1 << (xCtl_size)) - 1);
    if (readval.i != testVal)
    {
     setSync();
     printf("%4d x testVal %8x readVal %8x\n",
	    i, (unsigned int) testVal, (unsigned int) readval.i);
     clrSync();
    }
    j += 1;
    while (pollBufChar() != 0)
     ;
   }
  }
 }
 else if (ch == 'q')
 {
  gpioInfo(GPIOA);
  usartInfo(USART1);
  usartInfo(USART2);
  usartInfo(USART6);
  putstr1("start remcmd\n");
 }
 else if (ch == 'r')		/* read memory */
 {
  putx(' ');
  if (gethex())
  {
   printf("%x",*(int16_t *) (int) val);
  }
 }
 else if (ch == 'w')		/* write memory */
 {
  putx(' ');
  if (gethex())
  {
   int16_t *p;
   p = (int16_t *) (int) val;
   printf(" %x ",*p);
   if (gethex())
   {
    *p = val;
   }
  }
 }
 else if (ch == 'a')		/* set command address */
 {
  putx(' ');
  if (getnum())
   addr = val;
 }
 else if (ch == 'g')		/* read spi data */
 {
  putx(' ');
  if (getnum())
  {
   addr = val;			/* save address */
   read1(addr);			/* read from device */
   printf("\nread addr %x val %8lx %10ld",addr,readval.i,readval.i);
  }
 }
 else if (ch == 'G')		/* read spi repeatedly */
 {
  putx(' ');
  if (getnum())			/* enter address */
  {
   addr = val;			/* save address */
   putx(' ');
   if (getnum())		/* enter number of tries */
   {
    newline();
    int16_t i = (int16_t) val;
    while (1)
    {
     read1(addr);		/* read from device */
     if (chRdy())		/* if character available */
     {
      ch = chRead();
      break;
     }
     if ((i != 0)
     &&  (--i <= 0))
      break;
    }
    printf("spiw0 %d spiw1 %d",spiw0,spiw1);
   }
  }
 }
 else if (ch == 's')		/* send val to address a */
 {
  printf(" addr ");
  fflush(stdout);
  if (getnum())			/* read address */
  {
   addr = val;
   printf(" data ");
   fflush(stdout);
   if (getnum())		/* read data */
   {
    printf("\nsending addr %x %10ld val %8lx",addr,val,val);
    LOAD(addr,val);
   }
  }
 }
 else if (ch == 'p')		/* set print flag */
 {
  putx(' ');
  if (getnum())
  {
   print = val;
  }
 }
 else if (ch == 'r')		/* reset */
 {
  LOAD(XLDZCTL,0);
  LOAD(XLDXCTL,0);
  LOAD(XLDTCTL,0);
  LOAD(XLDDCTL,0);
 }
 else if (ch == 'x')		/* move x rel */
 {
  putx(' ');
  if (getnum())
  {
   xMoveRel(val, XMOV);
  }
 }
 else if (ch == 'z')		/* move z rel */
 {
  putx(' ');
  if (getnum())
  {
   zMoveRel(val, XMOV);
  }
 }
 else if (ch == 'u')		/* send debug message */
 {
  putx(' ');
  if (getnum())
  {
   dbgmsg("test",val);
  }
 }
}
Exemple #24
0
static void success(int ival)
{
    int i, size;
	
    size = (int) (lex_curpos - lex_lastpos);
    memcpy(EiC_LEXEM, &lex_buff[lex_lastpos], size);
    EiC_LEXEM[size] = '\0';
    if (Lseen) size--;
    if (Useen) size--;
    if (Fseen) size--;

    Hseen = 0;
    switch (ival) {
	case ID:
	    if ((token->Tok = EiC_iskeyword(cwords, EiC_LEXEM,
 					sizeof(cwords) / sizeof(keyword_t))) == 0) 
		{
			if(size > 64) //maks: avoid crash when enter a very long identifier
			{
				EiC_error("Identifier is too large");
				return;
			}

			token->Tok = ID;
			/* search for id in various name spaces */
			if ((token->Val.sym = EiC_lookup(EiC_work_tab, EiC_LEXEM)) == NULL)
				if(bCanInsertSymbol) token->Val.sym = EiC_insertLUT(EiC_work_tab, EiC_LEXEM, ID); //maks
				
				if (token->Val.sym)
					if (token->Val.sym->sclass == c_typedef)
						token->Tok = TYPENAME;
		}
	    break;
	case OCTAL:
	    if (Fseen)
		EiC_error("Declaration syntax error");
	    for (lexival = 0, i = 0; i < size; i++)
		lexival = lexival * 8 + getoct(EiC_LEXEM[i]);
	    Hseen = 1;
	    setintval();
	    break;
	case HEX:
	    for (lexival = 0, i = 2; i < size; i++)
		lexival = lexival * 16 + gethex(EiC_LEXEM[i]);
	    Hseen = 1;
	    setintval();
	    break;
	case TOKEN_INT:
	    for (lexival = 0, i = 0; i < size; i++)
		lexival = lexival * 10 + EiC_LEXEM[i] - '0';
	    setintval();
	    break;
	case TOKEN_FLOAT:
	    if (Useen)
		EiC_error("Declaration syntax error");
	    lexfval = atof(EiC_LEXEM);
	    setfloatval();
	    break;
	case RELOP:
	case MISC:
	    break;
    }
}
// Get a statement
numvar getstatement(void) {
numvar retval = 0;
char *fetchmark;

	chkbreak();

//#define LINEMODE
#ifdef LINEMODE
	if (sym == s_while) {
		// at this point sym is pointing at s_while, before the conditional expression
		// save fetchptr so we can restart parsing from here as the while iterates
		char *fetchmark = fetchptr;
		for (;;) {
			fetchptr = fetchmark;			// restore to mark
			primec();						// set up for mr. getsym()
			getsym(); 						// fetch the start of the conditional
			if (!getnum()) {					
				//longjmp(env, X_EXIT);		// get the conditional; exit on false
				sym = s_eof;				// we're finished here.  move along.
				return;
			}
			if (sym != s_colon) expectedchar(':');
			getsym();	// eat :
			getstatementlist();
		}
	}
	else if (sym == s_if) {
		getsym(); 								// fetch the start of the conditional
		if (!getnum()) {
			//longjmp(env, X_EXIT);	// get the conditional; exit on false
			sym = s_eof;
			return;
		}
		if (sym != s_colon) expectedchar(':');
		getsym();	// eat :
		getstatementlist();
	}

	// The switch statement: call one of N macros based on a selector value
	// switch <numval>: macroid1, macroid2,.., macroidN
	// numval < 0: numval = 0
	// numval > N: numval = N

	else if (sym == s_switch) {
		getsym();	// eat "switch"
		numvar selector = getnum();	// evaluate the switch value
		if (selector < 0) selector = 0;
		if (sym != s_colon) expectedchar(':');

		// we sit before the first macroid
		// scan and discard the <selector>'s worth of macro ids 
		// that sit before the one we want
		for (;;) {
			getsym();	// get an id, sets symval to its eeprom addr as a side effect
			if (sym != s_macro) expected (6);		// TODO: define M_macro instead of 6
			getsym();	// eat id, get separator; assume symval is untouched
			if ((sym == s_semi) || (sym == s_eof)) break;	// last case is default so we exit always
			if (sym != s_comma) expectedchar(',');
			if (!selector) break;		// ok, this is the one we want to execute
			selector--;					// one down...
		}

		// call the macro whose addr is squirreled in symval all this time
		// on return, the parser is ready to pick up where we left off
		domacrocall(symval);

		// scan past the rest of the unused switch options, if any
		// TODO: syntax checking for non-chosen options could be made much tighter at the cost of some space
		while ((sym != s_semi) && (sym != s_eof)) getsym();		// scan to end of statement without executing
	}

#else
	// new statement handling
	if (sym == s_while) {
		// at this point sym is pointing at s_while, before the conditional expression
		// save fetchptr so we can restart parsing from here as the while iterates
		fetchmark = fetchptr;
		for (;;) {
			fetchptr = fetchmark;			// restore to mark
			primec();						// set up for mr. getsym()
			getsym(); 						// fetch the start of the conditional
			if (getnum()) {
				retval = getstatement();
				if (sym == s_returning) break;	// exit if we caught a return
			}
			else {
				skipstatement();
				break;
			}
		}
	}
	
	else if (sym == s_if) {
		getsym();			// eat "if"
		if (getnum()) {
			retval = getstatement();
			if (sym == s_else) {
				getsym();	// eat "else"
				skipstatement();
			}
		} else {
			skipstatement();
			if (sym == s_else) {
				getsym();	// eat "else"
				retval = getstatement();
			}
		}
	}
	else if (sym == s_lcurly) {
		getsym(); 	// eat "{"
		while ((sym != s_eof) && (sym != s_returning) && (sym != s_rcurly)) retval = getstatement();
		if (sym == s_rcurly) getsym();	// eat "}"
	}
	else if (sym == s_return) {
		getsym();	// eat "return"
		if ((sym != s_eof) && (sym != s_semi)) retval = getnum();
		sym = s_returning;		// signal we're returning up the line
	}
	else if (sym == s_switch) retval = getswitchstatement();

	else if (sym == s_function) cmd_function();

#endif


	else if (sym == s_run) {	// run macroname
		getsym();
		if (sym != s_macro) unexpected(M_id);

		// address of macroid is in symval via parseid
		// check for [,snoozeintervalms]
		getsym();	// eat macroid to check for comma; symval untouched
		if (sym == s_comma) {
			vpush(symval);
			getsym();			// eat the comma
			getnum();			// get a number or else
			startTask(kludge(vpop()), expval);
		}
		else startTask(kludge(symval), 0);
	}

	else if (sym == s_stop) {
		getsym();
		if (sym == s_mul) {						// stop * stops all tasks
			initTaskList();
			getsym();
		}
		else if ((sym == s_semi) || (sym == s_eof)) {
			if (background) stopTask(curtask);	// stop with no args stops the current task IF we're in back
			else initTaskList();				// in foreground, stop all
		}
		else stopTask(getnum());
	}

	else if (sym == s_boot) reboot();

#if !defined(TINY85)
	else if (sym == s_rm) {		// rm "sym" or rm *
		getsym();
		if (sym == s_macro) {
			eraseentry(idbuf);
		} 
		else if (sym == s_mul) nukeeeprom();
		else if (sym != s_undef) expected(M_id);
		getsym();
	}
	else if (sym == s_ps) 		{ getsym();	showTaskList(); }
	else if (sym == s_peep) 	{ getsym(); cmd_peep(); }
	else if (sym == s_ls) 		{ getsym(); cmd_ls(); }
	else if (sym == s_help) 	{ getsym(); cmd_help(); }
	else if (sym == s_print) 	{ getsym(); cmd_print(); }
	else if (sym == s_semi)		{ ; }	// ;)
#endif

#ifdef HEX_UPLOAD
	// a line beginning with a colon is treated as a hex record
	// containing data to upload to eeprom
	//
	// TODO: verify checksum
	//
	else if (sym == s_colon) {
		// fetchptr points at the byte count
		byte byteCount = gethex(2);		// 2 bytes byte count
		int addr = gethex(4);			// 4 bytes address
		byte recordType = gethex(2);	// 2 bytes record type; now fetchptr -> data
		if (recordType == 1) reboot();	// reboot on EOF record (01)
		if (recordType != 0) return;	// we only handle the data record (00)
		if (addr == 0) nukeeeprom();	// auto-clear eeprom on write to 0000
		while (byteCount--) eewrite(addr++, gethex(2));		// update the eeprom
		gethex(2);						// discard the checksum
		getsym();						// and re-prime the parser
	}
#endif

	else getexpression();

	if (sym == s_semi) getsym();		// eat trailing ';'
	return retval;
}
void monitor(void)
{
        ch = bootldrgetch();
        if(ch=='!') {
          ch = bootldrgetch();
          if(ch=='!') {

#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
            uint16_t extaddr;
#endif
            int i;
            uint8_t addrl, addrh;

#ifdef CRUMB128
            PGM_P welcome = {"ATmegaBOOT / Crumb128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
#elif defined PROBOMEGA128
            PGM_P welcome = {"ATmegaBOOT / PROBOmega128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
#elif defined SAVVY128
            PGM_P welcome = {"ATmegaBOOT / Savvy128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
#elif defined __AVR_ATmega1280__ 
            PGM_P welcome = {"ATmegaBOOT / Arduino Mega - (C) Arduino LLC - 090930\n\r" };
#endif

            /* turn on LED */
            LED_DDR |= _BV(LED);
            LED_PORT &= ~_BV(LED);

            /* print a welcome message and command overview */
            for(i=0; welcome[i] != '\0'; ++i) {
              myputch(welcome[i]);
            }

            /* test for valid commands */
            for(;;) {
              myputch('\n');
              myputch('\r');
              myputch(':');
              myputch(' ');

              ch = bootldrgetch();
              myputch(ch);

              /* toggle LED */
              if(ch == 't') {
                if(bit_is_set(LED_PIN,LED)) {
                  LED_PORT &= ~_BV(LED);
                  myputch('1');
                } else {
                  LED_PORT |= _BV(LED);
                  myputch('0');
                }
              } 

              /* read byte from address */
              else if(ch == 'r') {
                ch = bootldrgetch(); myputch(ch);
                addrh = gethex();
                addrl = gethex();
                myputch('=');
                ch = *(uint8_t *)((addrh << 8) + addrl);
                puthex(ch);
              }

              /* write a byte to address  */
              else if(ch == 'w') {
                ch = bootldrgetch(); myputch(ch);
                addrh = gethex();
                addrl = gethex();
                ch = bootldrgetch(); myputch(ch);
                ch = gethex();
                *(uint8_t *)((addrh << 8) + addrl) = ch;
              }

              /* read from uart and echo back */
              else if(ch == 'u') {
                for(;;) {
                  myputch(bootldrgetch());
                }
              }
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
              /* external bus loop  */
              else if(ch == 'b') {
                myputch('b');
                myputch('u');
                myputch('s');
                MCUCR = 0x80;
                XMCRA = 0;
                XMCRB = 0;
                extaddr = 0x1100;
                for(;;) {
                  ch = *(volatile uint8_t *)extaddr;
                  if(++extaddr == 0) {
                    extaddr = 0x1100;
                  }
                }
              }
#endif

              else if(ch == 'j') {
                app_start();
              }

            } /* end of monitor functions */

          }
        }
      }
Exemple #27
0
int yylex(void)
{
    char errmsg[80];
    int keyword, c;

loop:
    skipws();

    xline = line;
    xcolumn = column;
    if (ch == '/')
    {
        getch();
        if (ch == '/')
        {
            skipcom();
            goto loop;
        }

        return '/';
    }

    if (ch == EOF)
        return EOF;

    if (isalpha(ch))
    {
        getword();
        keyword = lookup(wbuf);
        wpos = 0;

        if (keyword >= 0)
            return keyword;

        snprintf(yylval.name, BUFSIZ, "%s", wbuf);
        return LIDENT;
    }

    if (isdigit(ch))
    {
        getnum();
        yylval.val = atoi(wbuf);
        wpos = 0;
        return LNUMBER;
    }

    c = ch;
    getch();

    if (c == '#')
    {
        gethex();
        yylval.val = hex(wbuf+1);
        wpos = 0;
        return LHEX;
    }

    switch (c)
    {
        case '+':
        case '-':
        case '{':
        case '}':
        case ',':
        case '*':
        case '%':
        case '|':
        case '&':
        case '^':
        case '~':
        case '(':
        case ')':
            return c;
    }

    snprintf(errmsg, sizeof(errmsg), "unknown symbol: %c", c);
    yyerror(errmsg);
    return 0;
}
/*
================
DrawTris

Draws triangle outlines for debugging
================
*/
static void DrawTris( shaderCommands_t *input ) {
	char            *s = r_trisColor->string;
	vec4_t trisColor = { 1, 1, 1, 1 };
	unsigned int stateBits = 0;

	GL_Bind( tr.whiteImage );

	if ( *s == '0' && ( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) ) {
		s += 2;
		if ( Q_IsHexColorString( s ) ) {
			trisColor[0] = ( (float)( gethex( *( s ) ) * 16 + gethex( *( s + 1 ) ) ) ) / 255.00;
			trisColor[1] = ( (float)( gethex( *( s + 2 ) ) * 16 + gethex( *( s + 3 ) ) ) ) / 255.00;
			trisColor[2] = ( (float)( gethex( *( s + 4 ) ) * 16 + gethex( *( s + 5 ) ) ) ) / 255.00;

			if ( Q_HexColorStringHasAlpha( s ) ) {
				trisColor[3] = ( (float)( gethex( *( s + 6 ) ) * 16 + gethex( *( s + 7 ) ) ) ) / 255.00;
			}
		}
	} else {
		int i;
		char    *token;

		for ( i = 0 ; i < 4 ; i++ ) {
			token = COM_Parse( &s );
			if ( token ) {
				trisColor[i] = atof( token );
			} else {
				trisColor[i] = 1.f;
			}
		}

		if ( !trisColor[3] ) {
			trisColor[3] = 1.f;
		}
	}

	if ( trisColor[3] < 1.f ) {
		stateBits |= ( GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );
	}

	qglColor4fv( trisColor );

	// ydnar r_showtris 2
	if ( r_showtris->integer == 2 ) {
		stateBits |= ( GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE );
		GL_State( stateBits );
		qglDepthRange( 0, 0 );
	}
	#ifdef CELSHADING_HACK
	else if ( r_showtris->integer == 3 ) {
		stateBits |= ( GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE );
		GL_State( stateBits );
		qglEnable( GL_POLYGON_OFFSET_LINE );
		qglPolygonOffset( 4.0, 0.5 );
		qglLineWidth( 5.0 );
	}
	#endif
	else
	{
		stateBits |= ( GLS_POLYMODE_LINE );
		GL_State( stateBits );
		qglEnable( GL_POLYGON_OFFSET_LINE );
		qglPolygonOffset( r_offsetFactor->value, r_offsetUnits->value );
	}

	qglDisableClientState( GL_COLOR_ARRAY );
	qglDisableClientState( GL_TEXTURE_COORD_ARRAY );

	qglVertexPointer( 3, GL_FLOAT, 16, input->xyz ); // padded for SIMD

	if ( qglLockArraysEXT ) {
		qglLockArraysEXT( 0, input->numVertexes );
		GLimp_LogComment( "glLockArraysEXT\n" );
	}

	R_DrawElements( input->numIndexes, input->indexes );

	if ( qglUnlockArraysEXT ) {
		qglUnlockArraysEXT();
		GLimp_LogComment( "glUnlockArraysEXT\n" );
	}
	qglDepthRange( 0, 1 );
	qglDisable( GL_POLYGON_OFFSET_LINE );
}
// Get a statement
void getstatement(void) {

#if !defined(TINY85)
	chkbreak();
#endif

	if (sym == s_while) {
		// at this point sym is pointing at s_while, before the conditional expression
		// save fetchptr so we can restart parsing from here as the while iterates
		char *fetchmark = fetchptr;
		for (;;) {
			fetchptr = fetchmark;			// restore to mark
			primec();						// set up for mr. getsym()
			getsym(); 						// fetch the start of the conditional
			if (!getnum()) {					
				//longjmp(env, X_EXIT);		// get the conditional; exit on false
				sym = s_eof;				// we're finished here.  move along.
				return;
			}
			if (sym != s_colon) expectedchar(':');
			getsym();	// eat :
			getstatementlist();
		}
	}
	
	else if (sym == s_if) {
		getsym(); 								// fetch the start of the conditional
		if (!getnum()) {
			//longjmp(env, X_EXIT);	// get the conditional; exit on false
			sym = s_eof;
			return;
		}
		if (sym != s_colon) expectedchar(':');
		getsym();	// eat :
		getstatementlist();
	}


#if SKETCH
	// The switch statement: call one of N macros based on a selector value
	// switch <numval>: macroid1, macroid2,.., macroidN
	// numval < 0: numval = 0
	// numval > N: numval = N

	else if (sym == s_switch) {
		getsym();	// eat "switch"
		numvar selector = getnum();	// evaluate the switch value
		if (selector < 0) selector = 0;
		if (sym != s_colon) expectedchar(':');

		// we sit before the first macroid
		// scan and discard the <selector>'s worth of macro ids 
		// that sit before the one we want
		for (;;) {
			getsym();	// get an id, sets symval to its eeprom addr as a side effect
			if (sym != s_macro) expected (6);		// TODO: define M_macro instead of 6
			getsym();	// eat id, get separator; assume symval is untouched
			if ((sym == s_semi) || (sym == s_eof)) break;	// last case is default so we exit always
			if (sym != s_comma) expectedchar(',');
			if (!selector) break;		// ok, this is the one we want to execute
			selector--;					// one down...
		}

		// call the macro whose addr is squirreled in symval all this time
		// on return, the parser is ready to pick up where we left off
		doMacroCall(symval);

		// scan past the rest of the unused switch options, if any
		// TODO: syntax checking for non-chosen options could be made much tighter at the cost of some space
		while ((sym != s_semi) && (sym != s_eof)) getsym();		// scan to end of statement without executing
	}
#endif


	else if ((sym == s_macro) || (sym == s_undef)) {		// macro def or ref
		getsym();						// scan past macro name to next symbol: ; or :=
		if (sym == s_define) {			// macro definition: macroid := strvalue
			// to define the macro, we need to copy the id somewhere on the stack
			// to avoid having this local buffer in every getstatement stack frame,
			// we break out defineMacro here to a separate function that only eats that
			// stack in the case that a macro is being defined
#ifdef TINY85
			unexpected(M_defmacro);
#else
			defineMacro();
#endif
		}
		else if ((sym == s_semi) || (sym == s_eof)) {	// valid macro reference: let's call it
#if SKETCH
			doMacroCall(symval);			// parseid stashes the macro address in symval
#else
			char op = sym;					// save sym for restore
			expval = findKey(idbuf);		// assumes id in idbuf isn't clobbered since getsym() above
			if (expval >= 0) {
				char *fetchmark = fetchptr;			// save the current parse pointer

				// call the macro
				calleeprommacro(findend(expval));	// register the macro into the parser stream
				getsym();
				getstatementlist();		// parse and execute the macro code here
				if (sym != s_eof) expected(M_eof);

				// restore parsing context so we can resume cleanly
				fetchptr = fetchmark;	// restore pointer
				primec();				// and inchar
				sym = op;				// restore saved sym: s_semi or s_eof
			} else unexpected(M_id);
#endif
		}
		else expectedchar(';');
		//else getexpression();		// assume it was macro1+32+macro2...
	}
	
	else if (sym == s_run) {	// run macroname
		getsym();
		if (sym != s_macro) unexpected(M_id);

#if 0
		// address of macroid is in symval via parseid
		startTask(kludge(symval));
		getsym();
#else
		// address of macroid is in symval via parseid
		// check for [,snoozeintervalms]
		getsym();	// eat macroid to check for comma; symval untouched
		if (sym == s_comma) {
			vpush(symval);
			getsym();			// eat the comma
			getnum();			// get a number or else
			startTask(kludge(vpop()), expval);
		}
		else startTask(kludge(symval), 0);
#endif
	}
	else if (sym == s_stop) {
		getsym();
		if (sym == s_mul) {						// stop * stops all tasks
			initTaskList();
			getsym();
		}
		else if ((sym == s_semi) || (sym == s_eof)) {
			if (background) stopTask(curtask);	// stop with no args stops the current task IF we're in back
			else initTaskList();				// in foreground, stop all
		}
		else stopTask(getnum());
	}

	else if (sym == s_boot) reboot();

#if !defined(TINY85)
	else if (sym == s_rm) {		// rm "sym" or rm *
		getsym();
		if (sym == s_macro) {
			eraseentry(idbuf);
		} 
		else if (sym == s_mul) nukeeeprom();
		else expected(M_id);
		getsym();
	}
	else if (sym == s_ps) showTaskList();
	else if (sym == s_peep) 	{ getsym(); cmd_peep(); }
	else if (sym == s_ls) 		{ getsym(); cmd_ls(); }
	else if (sym == s_help) 	{ getsym(); cmd_help(); }
	else if (sym == s_print) 	{ getsym(); cmd_print(); }
#endif

#ifdef HEX_UPLOAD
	// a line beginning with a colon is treated as a hex record
	// containing data to upload to eeprom
	//
	// TODO: verify checksum
	//
	else if (sym == s_colon) {
		// fetchptr points at the byte count
		byte byteCount = gethex(2);		// 2 bytes byte count
		int addr = gethex(4);			// 4 bytes address
		byte recordType = gethex(2);	// 2 bytes record type; now fetchptr -> data
		if (recordType == 1) reboot();	// reboot on EOF record (01)
		if (recordType != 0) return;	// we only handle the data record (00)
		if (addr == 0) nukeeeprom();	// auto-clear eeprom on write to 0000
		while (byteCount--) eewrite(addr++, gethex(2));		// update the eeprom
		gethex(2);						// discard the checksum
		getsym();						// and re-prime the parser
	}
#endif

	else  {
		getexpression();
	}
}
Exemple #30
0
extern int EiC_lexan(void)
{
    int t=0, loop; char c=0, EiC_nextchar();

#ifdef ILOOKAHEAD

    token = &EiC_TokenArray[EiC_TokenP];

    if(EiC_TokenR > 0) {
	EiC_TokenR--;
	EiC_TokenI++;
	EiC_TokenP=(EiC_TokenP+1)%MAX_TOKENS;
	return token->Tok;
    }


#else

    if (STOKEN != NOTOKEN) {
	STOKEN = NOTOKEN;
	return token->Tok;
    }

#endif
    
    loop  = 1;
    state = 0;
    while (loop) {
	switch (state) {
	  case 0: lex_lastpos = lex_curpos; c = EiC_nextchar();
	    state = (WHITE(c) ? 0 :
		    (c == '\n' ? lex_lineno++, 0 :
		    (c == '<' ? t = LT, 1 :
		    (c == '>' ? t = GT, 2 :
		    (c == '+' ? t = '+', 3 :
		    (c == '-' ? t = '-', 4 :
		    (c == '|' ? t = BOR, 5 :
		    (c == '&' ? t = AND, 6 :
		    (c == '\''? 7 :
		    (c == '"' ? 8 :
		    (c == '.' ? 9 :  
		    (c == '/' ? t = '/', c = EiC_nextchar(), 50 :
		    (c == '%' ? t = '%', c = EiC_nextchar(), 50 :
		    (c == '*' ? t = '*', c = EiC_nextchar(), 50 :
		    (c == '=' ? t = ASS, c = EiC_nextchar(), 50 :
		    (c == '!' ? t = NOT, c = EiC_nextchar(), 50 :
		    (c == '^' ? t = XOR, c = EiC_nextchar(), 50 :
			//(c == '~' ? t = NOTB, c = EiC_nextchar(), 50 : //maks: ~
		     fail(RELOP, c))))))))))))))))));
	    break;
	  case 1: /* get <,  <= and << */
	    if ((c = EiC_nextchar()) == '<') t = LSHT;
	    else state = 50;
	    break;
	  case 2: /* get >, >= and >> */
	    if ((c = EiC_nextchar()) == '>') t = RSHT;
	    else state = 50;
	    break;
	  case 3: c = EiC_nextchar();                         /* get +, += or ++ */
	    if (c == '+') t = INC, state = 60;
	    else state = 50;
	    break;
	  case 4: c = EiC_nextchar();                            /* get -, -= -- */
	    state = 60;
	    if (c == '-') t = DEC;
	    else if (c == '>') t = RARROW;
	    else state = 50;
	    break;
	  case 5: c = EiC_nextchar();                         /* get |, |= or || */
	    if (c == '|') t = LOR, state = 60;
	    else state = 50;
	    break;
	  case 6: c = EiC_nextchar();                         /* get &, &= or && */
	    if (c == '&') t = LAND, state = 60;
	    else state = 50;
	    break;
	  case 7:token->Val.ival = charliteral(EiC_nextchar()); /* char_constants */
	    t = TOKEN_CHAR;
	    if (EiC_nextchar() != '\'')
		EiC_error("Missing single quote '");
	    state = 60;
	    break;
	  case 8: EiC_stringliteral();                        /* string literals */
	    token->Tok = STR;
	    /*return STR;*/ loop = 0; break;
	  case 9: c = EiC_nextchar();
	    t = '.';
	    if(DIGIT(c)) 
		state = 22;
	    else
		state = 60;
	    retract(c);
	    break;
	  case 10: c = EiC_nextchar();              /* identifiers and  keywords */
	    state = (LETTER(c) ? 11 :
		    (c == '_' ? 11 : fail(ID, c)));
	    break;
	  case 11: c = EiC_nextchar();
	    state = (LETTER(c) ? 11 :
		    (DIGIT(c) ? 11 :
		    (c == '_' ? 11 : 12)));
	    break;
	  case 12: retract(c); success(ID); /*return (token->Tok);*/ loop = 0; break;

	  case 20: c = EiC_nextchar();                     /* integers and reals */
	    state = (c == '0' ? 30 :
		    (DIGIT(c) ? 21 : fail(TOKEN_INT, c)));
	    break;
	  case 21: c = EiC_nextchar();
	    state = (DIGIT(c) ? 21 :
		    (c == '.' ? 22 :
		    (c == 'e' ? 23 :
		    (c == 'E' ? 23 : 25))));
	    break;
	  case 22: c = EiC_nextchar();
	    state = (DIGIT(c) ? 22 :
		    (c == 'e' ? 23 :
		    (c == 'E' ? 23 : 26)));
	    break;
	  case 23: c = EiC_nextchar();
	    state = (c == '+' ? 24 :
		    (c == '-' ? 24 :
		    (DIGIT(c) ? 24 : fail(TOKEN_FLOAT, c) /* ??? */ )));
	    break;
	  case 24: c = EiC_nextchar();
	    state = (DIGIT(c) ? 24 : 26);
	    break;
	  case 25: checkExt(c); success(TOKEN_INT); /*return (token->Tok);*/ loop = 0; break;
	  case 26: checkExt(c); success(TOKEN_FLOAT); /*return (token->Tok);*/ loop = 0; break;
	  case 27: checkExt(c); success(HEX);   /*return (token->Tok);*/ loop = 0; break;
	  case 28: checkExt(c); success(OCTAL); /*return (token->Tok);*/ loop = 0; break;
	  case 30:			  /* check for octal and hex numbers */
	    if ((c = EiC_nextchar()) == 'x' || c == 'X') {
		while (gethex((c = EiC_nextchar())) > -1);
		state = 27;
		break;
	    }
	    if (c != '.' && c != 'e' && c != 'E') {
		while (getoct(c) > -1)
		    c = EiC_nextchar();
		state = 28;
		break;
	    }
	    retract(c); state = 21; break;
	  case 50:                                      /* mix with equal's  */
	    if (c == '=')
		switch (t) {
		  case '+': t = ADDEQ;  break;		/* += */
		  case '-': t = SUBEQ;  break;		/* -= */
		  case '/': t = DIVEQ;  break;		/* /= */
		  case '*': t = MULEQ;  break;		/* *= */
		  case '%': t = MODEQ;  break;		/* %= */
		  case ASS: t = EQ;     break;		/* == */
		  case GT:  t = GE;     break;		/* >= */
		  case LT:  t = LE;     break;		/* <= */
		  case NOT: t = NE;     break;		/* != */
		  case RSHT:t = RSHTEQ; break;		/* >>= */
		  case LSHT:t = LSHTEQ; break;		/* <<= */
		  case AND: t = ANDEQ;  break;		/* &= */
		  case BOR: t = BOREQ;  break;		/* |= */
		  case XOR: t = XOREQ;  break;		/* ^= */
		  //case NOTB: t = NOTBEQ;  break;		/* maks ~= */
		  default: retract(c);
	    }
		else if(c == '/' && t == '/') //maks
		{
			//C++ comment
			//Only for colorize
			//Comments are removed by preprocessor before parser

			do 
			{
				c = EiC_nextchar();
				
			} while(c && c != '\n');

			retract(c);

			success(MISC); 
			token->Tok = TOKEN_COMMENT;
			loop = 0;
			break;
		}
		else retract(c);
	    state = 60;
	    break;
	  case 60: success(MISC); token->Tok = t; /*return (token->Tok);*/ loop = 0; break;
	  case 100: token->Tok = EiC_nextchar(); /*return (token->Tok);*/ loop = 0; break;
	}
    }

#ifdef ILOOKAHEAD

    if(EiC_TokenI<MAX_TOKENS)
	EiC_TokenI++;

    EiC_TokenP = (EiC_TokenP +1)%MAX_TOKENS;

#endif

    return token->Tok;


}