//static void print_statement(void) void print_statement(void) { char buf[20]; accept(TOKENIZER_PRINT); do { if(tokenizer_token() == TOKENIZER_STRING) { tokenizer_string(strings[MAX_STRINGNUM], sizeof(strings[MAX_STRINGNUM])); glcd_PutsA(strings[MAX_STRINGNUM]); tokenizer_next(); } else if(tokenizer_token() == TOKENIZER_COMMA) { glcd_PutsA(" "); tokenizer_next(); } else if(tokenizer_token() == TOKENIZER_SEMICOLON) { tokenizer_next(); } else if(tokenizer_token() == TOKENIZER_VARIABLE || tokenizer_token() == TOKENIZER_NUMBER) { glcd_PutsA(ltodeci(expr(),buf,6)); } else { break; } } while(tokenizer_token() != TOKENIZER_CR && tokenizer_token() != TOKENIZER_ENDOFINPUT); glcd_PutsA("\n"); // cputs_p(6,"Print"); tokenizer_next(); }
/*---------------------------------------------------------------------------*/ static void print_statement(void) { accept(TOKENIZER_PRINT); do { DEBUG_PRINTF("Print loop\n"); if(tokenizer_token() == TOKENIZER_STRING) { tokenizer_string(string, sizeof(string)); printf("%s", string); tokenizer_next(); } else if(tokenizer_token() == TOKENIZER_COMMA) { printf(" "); tokenizer_next(); } else if(tokenizer_token() == TOKENIZER_SEMICOLON) { tokenizer_next(); } else if(tokenizer_token() == TOKENIZER_VARIABLE || tokenizer_token() == TOKENIZER_NUMBER) { printf("%d", expr()); } else { break; } } while(tokenizer_token() != TOKENIZER_CR && tokenizer_token() != TOKENIZER_ENDOFINPUT); printf("\n"); DEBUG_PRINTF("End of print\n"); tokenizer_next(); }
static void print_statement (void) { accept(T_PRINT); do { /* Print a string literal. */ if (tokenizer_token() == T_STRING) { printf("%s", tokenizer_string()); tokenizer_next(); } /* A seperator, send a space. */ else if (tokenizer_token() == T_SEPERATOR) { printf(" "); tokenizer_next(); } /* Evaluate and print an expression. */ else if (tokenizer_token() == T_LETTER || tokenizer_token() == T_NUMBER || tokenizer_token() == T_LEFT_PAREN) printf("%d", expression()); else { break; } /* This additionally ensures a new-line character is present at the end of the line-statement. */ if (tokenizer_finished()) accept(T_EOL); } while (tokenizer_token() != T_EOL && tokenizer_token() != T_EOF); printf("\n"); tokenizer_next(); }
/*---------------------------------------------------------------------------*/ static void factor(struct typevalue *v) { uint8_t t = current_token; int len; struct typevalue arg[3]; DEBUG_PRINTF("factor: token %d\n", current_token); switch(t) { case TOKENIZER_STRING: v->type = TYPE_STRING; len = tokenizer_string_len(); v->d.p = string_temp(len); memcpy(v->d.p + 1, tokenizer_string(), len); DEBUG_PRINTF("factor: string %p\n", v->d.p); accept_tok(TOKENIZER_STRING); break; case TOKENIZER_NUMBER: v->d.i = tokenizer_num(); v->type = TYPE_INTEGER; DEBUG_PRINTF("factor: number %d\n", v->d.i); accept_tok(TOKENIZER_NUMBER); break; case TOKENIZER_LEFTPAREN: accept_tok(TOKENIZER_LEFTPAREN); expr(v); accept_tok(TOKENIZER_RIGHTPAREN); break; case TOKENIZER_INTVAR: case TOKENIZER_STRINGVAR: varfactor(v); break; default: if (TOKENIZER_NUMEXP(t)) { accept_tok(t); switch(t) { case TOKENIZER_PEEK: funcexpr(arg,"I"); v->d.i = peek_function(arg[0].d.i); break; case TOKENIZER_ABS: funcexpr(arg,"I"); v->d.i = arg[0].d.i; if (v->d.i < 0) v->d.i = -v->d.i; break; case TOKENIZER_INT: funcexpr(arg,"I"); v->d.i = arg[0].d.i; break; case TOKENIZER_SGN: funcexpr(arg,"I"); v->d.i = arg[0].d.i; if (v->d.i > 1 ) v->d.i = 1; if (v->d.i < 0) v->d.i = -1; break; case TOKENIZER_LEN: funcexpr(arg,"S"); v->d.i = *arg[0].d.p; break; case TOKENIZER_CODE: funcexpr(arg,"S"); if (*arg[0].d.p) v->d.i = arg[0].d.p[1]; else v->d.i = 0; break; case TOKENIZER_VAL: funcexpr(arg,"S"); v->d.i = string_val(&arg[0]); break; default: syntax_error(); } v->type = TYPE_INTEGER; } else if (TOKENIZER_STRINGEXP(t)) { accept_tok(t); switch(t) { case TOKENIZER_LEFTSTR: funcexpr(arg, "SI"); string_cut(v, &arg[0], 1, arg[1].d.i); break; case TOKENIZER_RIGHTSTR: funcexpr(arg, "SI"); string_cut_r(v, &arg[0], arg[1].d.i); break; case TOKENIZER_MIDSTR: funcexpr(arg, "SII"); string_cut(v, &arg[0], arg[1].d.i, arg[2].d.i); break; case TOKENIZER_CHRSTR: funcexpr(arg, "I"); v->d.p = string_temp(2); v->d.p[1] = arg[0].d.i; v->type = TYPE_STRING; break; default: syntax_error(); } } else syntax_error(); } }
//static void save_statement(void) void save_statement(void) { BYTE res; // long p2; // FILINFO Finfo; char filename[20]; unsigned char tmp[2]; // UINT BytesRead; UINT BytesWrite; int i; tmp[0] = 0x00; tmp[1] = 0x00; accept(TOKENIZER_SAVE); tokenizer_string(filename, 20); accept(TOKENIZER_STRING); accept(TOKENIZER_CR); // res = f_getfree("", (DWORD*)&p2, &Bfs);// testcode #if TEST res = 0; #else res = f_opendir(& Bdir, ""); #endif if (res) { glcd_PutsD("Error: NO SD Card!!\n"); } else { if(strlen(filename)!=0){ if ((isEx(filename,"BAS"))||(isEx(filename,"bas"))){ #if TEST printf(filename); printf(" = BASIC filename\n"); #else if(f_open(&BfileR,filename,FA_CREATE_ALWAYS | FA_WRITE) == FR_OK){ f_write(&BfileR,BASICBUF,strlen(BASICBUF),&BytesWrite); f_close(&BfileR); }else{ glcd_PutsD("Error: Can not Write file!!\n"); } #endif } if ((isEx(filename,"TXT"))||(isEx(filename,"txt"))){ #if TEST printf(filename); printf(" = TXT filename\n"); #else if(f_open(&BfileR,filename,FA_CREATE_ALWAYS | FA_WRITE) == FR_OK){ f_write(&BfileR,strings[3],strlen(strings[3]),&BytesWrite); f_close(&BfileR); }else{ glcd_PutsD("Error: Can not Write file!!\n"); } #endif } if ((isEx(filename,"DAT"))||(isEx(filename,"dat"))){ #if TEST printf(filename); printf(" = DAT filename\n"); #else if(f_open(&BfileR,filename,FA_CREATE_ALWAYS | FA_WRITE) == FR_OK){ f_write(&BfileR,arrays[3],4096,&BytesWrite); f_close(&BfileR); }else{ glcd_PutsD("Error: Can not Write file!!\n"); } #endif } if ((isEx(filename,"BMP"))||(isEx(filename,"bmp"))){ #if TEST printf(filename); printf(" = BMP filename\n"); #else if(f_open(&BfileR,filename,FA_CREATE_ALWAYS | FA_WRITE) == FR_OK){ f_write(&BfileR, bmpheader, 62, &BytesWrite); for(i=0;i<240;i++){ f_write(&BfileR, glcd_buf+(50*(240-i)), 50, &BytesWrite); f_write(&BfileR, tmp, 2, &BytesWrite); } f_close(&BfileR); }else{ glcd_PutsD("Error: Can not Write file!!\n"); } #endif } } } }
//static void load_statement(void) void load_statement(void) { BYTE res; long p2; FILINFO Finfo; char filename[20]; UINT BytesRead; char tmp[62]; int i; accept(TOKENIZER_LOAD); tokenizer_string(filename, 20); accept(TOKENIZER_STRING); accept(TOKENIZER_CR); res = f_getfree("", (DWORD*)&p2, &Bfs);// testcode res = f_opendir(& Bdir, ""); if (res) { glcd_PutsD("Error: NO SD Card!!\n"); } else { for(;;) { res = f_readdir(& Bdir, &Finfo); if ((res != FR_OK) || !Finfo.fname[0]){ glcd_PutsD("Error: File not Found\n"); break; } if(strncmp(&(Finfo.fname[0]), filename, strlen(filename)) == 0) { if (isEx(&(Finfo.fname[0]),"BAS")){ for(i=0;i<MAX_BASICBUF;i++)BASICBUF[i] = 0; if (f_open(&BfileR, filename , FA_READ) == FR_OK) { f_read (&BfileR, BASICBUF, 256, &BytesRead); f_close(&BfileR); }else{ glcd_PutsD("Error: Can not Read file!!\n"); } ErrLine = 0; break; } if (isEx(&(Finfo.fname[0]),"TXT")){ for(i=0;i<MAX_STRINGLEN;i++)strings[3][i] = 0; if (f_open(&BfileR, filename , FA_READ) == FR_OK) { f_read (&BfileR, strings[3], 4096, &BytesRead); f_close(&BfileR); }else{ glcd_PutsD("Error: Can not Read file!!\n"); } break; } if (isEx(&(Finfo.fname[0]),"DAT")){ for(i=0;i<MAX_ARRYLEN;i++)arrays[3][i] = 0; if (f_open(&BfileR, filename , FA_READ) == FR_OK) { f_read (&BfileR, arrays[3], 4096, &BytesRead); f_close(&BfileR); }else{ glcd_PutsD("Error: Can not Read file!!\n"); } break; } if (isEx(&(Finfo.fname[0]),"BMP")){ for (i = 0;i < (50*240);i++)glcd_buf[i] = 0x00; for(i=0;i<31;i++)glcd_check[i] = 0xff; if (f_open(&BfileR, filename , FA_READ) == FR_OK) { f_read (&BfileR, tmp, 62, &BytesRead); for(i=0;i<240;i++){ f_read (&BfileR, glcd_buf+(50*(240-i)), 50, &BytesRead); f_read (&BfileR, tmp, 2, &BytesRead); } f_close(&BfileR); glcd_posClear(); glcd_TransFromBuf(); }else{ glcd_PutsD("Error: Can not Read file!!\n"); } break; } } } } }