Esempio n. 1
0
void StdioPuts(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
    dConsolePut(Param[0]->Val->Pointer);
	dConsolePutChar ('\n');

    ReturnValue->Val->Integer = 0;
}
Esempio n. 2
0
void StdioPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
	
    char buf[512];
    GenericPrintf(Parser, ReturnValue, Param, NumArgs,buf);
	dConsolePut (buf);
    ReturnValue->Val->Integer = strlen(buf);
	
}
Esempio n. 3
0
int dPrintf(const char * format,...)
{
        char    buf[256];
        int             length;
        va_list arg_list;

        va_start(arg_list,format);
        length = vsprintf(buf,format,arg_list);
        va_end(arg_list);

        dConsolePut (buf);
        
        return length;
} 
Esempio n. 4
0
void dPuts(const char * s)
{
        dConsolePut(s);
        dConsolePut("\n");
}
Esempio n. 5
0
int dGetLine (char * s,int max) // This function is depended on dConsole
                                                                // And this function is not allowed to abolish
{
        int             pos = strlen(s);
        int             refresh = 1;
        int             x,y,l,width;
        int    key;
        char    c;


        l = strlen (line_buf[line_index]);

        if (l>=LINE_COL_MAX)
        {
                dConsolePut("\n");
                l = 0;
        }
        else
                dConsoleRedraw();

        x = l + 1;
        y = line_count;
        width = LINE_COL_MAX - l;
        
        //LCD_CursorEn(1);

        while (1)
        {
                if (refresh)
                {
                        int i;
                        for (i=x;i<=LINE_COL_MAX;++i)
                        {
                                locate(i,y-line_start);print((uchar*)" ");
                        }
                        if (pos<width-1)
                        {
                                locate(x,y-line_start);            print((uchar*)s);
                                locate(x+pos,y-line_start);        printCursor();
                        }
                        else
                        {
                                locate(x,y-line_start);            print((uchar*)s+pos-width+1);
                                locate(x+width-1,y-line_start);    printCursor(); //cursor
                        }
                        refresh = 0;
                }
                //int keyflag = GetSetupSetting( (unsigned int)0x14);
                key=GetKey();

                if (key==KEY_CHAR_PLUS) {
                  if ((int)strlen(s)>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last+");
                    pos=pos+5; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"+", pos);
                    pos=pos+1; refresh = 1;
                  }
                } else if (key==KEY_CHAR_MINUS) {
                  if ((int)strlen(s)>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last-");
                    pos=pos+5; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"-", pos);
                    pos=pos+1; refresh = 1;
                  }
                } else if (key==KEY_CHAR_MULT) {
                  if ((int)strlen(s)>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last*");
                    pos=pos+5; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"*", pos);
                    pos=pos+1; refresh = 1;
                  }
                } else if (key==KEY_CHAR_DIV) {
                  if ((int)strlen(s)>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last/");
                    pos=pos+5; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"/", pos);
                    pos=pos+1; refresh = 1;
                  }
                } else if (key==KEY_CHAR_POW) {
                  if ((int)strlen(s)>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last^");
                    pos=pos+5; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"^", pos);
                    pos=pos+1; refresh = 1;
                  }
                } else if (key==KEY_CHAR_SQUARE) {
                  if ((int)strlen(s)+1>=max) continue;
                  if(strlen(s)==0) {
                    strcat(s, (char*)"last^2");
                    pos=pos+6; refresh = 1; //start of line, append "last" as we're going to do a calculation on the previous value
                  } else {
                    append(s, (char*)"^2", pos);
                    pos=pos+2; refresh = 1;
                  }
                } else if (key==KEY_CHAR_ROOT) {
                  if ((int)strlen(s)+4>=max) continue;
                  append(s, (char*)"sqrt(", pos);
                  pos=pos+5; refresh = 1;
                }else if (key==KEY_CHAR_H) {
                    if ((int)strlen(s)+4>=max) continue;
                    append(s, (char*)"h", pos);
                    pos=pos+1; refresh = 1;
                  } else if (key==KEY_CHAR_CUBEROOT) {
                  if ((int)strlen(s)+5>=max) continue;
                  append(s, (char*)"^(1/3)", pos); // example: to get cubic root of 27, do 27^(1/3)
                  pos=pos+6; refresh = 1;
                } else if (key==KEY_CHAR_POWROOT) {
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"^(1/", pos); // example: to get cubic root of 27, do 27^(1/3)
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_LN) { // the log() function in eigenmath is the natural log (Casio's ln)
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"log(", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_EXPN) { // the exp() function in eigenmath is the natural expnonent (Casio's e^x)
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"exp(", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_SIN) {
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"sin(", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_ASIN) {
                  if ((int)strlen(s)+6>=max) continue;
                  append(s, (char*)"arcsin(", pos);
                  pos=pos+7; refresh = 1;
                } else if (key==KEY_CHAR_COS) {
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"cos(", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_ACOS) {
                  if ((int)strlen(s)+6>=max) continue;
                  append(s, (char*)"arccos(", pos);
                  pos=pos+7; refresh = 1;
                } else if (key==KEY_CHAR_TAN) {
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"tan(", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_ATAN) {
                  if ((int)strlen(s)+6>=max) continue;
                  append(s, (char*)"arctan(", pos);
                  pos=pos+7; refresh = 1;
                } else if (key==KEY_CHAR_FRAC) {
                  if ((int)strlen(s)>=max) continue;
                  append(s, (char*)"/", pos);
                  pos=pos+1; refresh = 1;
                } else if (key==KEY_CTRL_FD) {
                  if ((int)strlen(s)+4>=max) continue;
                  append(s, (char*)"float", pos); // no ( at the end because this is often used to manipulate the last result
                  pos=pos+5; refresh = 1;
                } else if (key==KEY_CHAR_FACT) {
                  if ((int)strlen(s)>=max) continue;
                  append(s, (char*)"!", pos); 
                  pos=pos+1; refresh = 1;
                } else if (key==KEY_CHAR_IMGNRY) {
                  if ((int)strlen(s)>=max) continue;
                  append(s, (char*)"i", pos);
                  pos=pos+1; refresh = 1;
                } else if (key==KEY_CHAR_PI) {
                  if ((int)strlen(s)+1>=max) continue;
                  append(s, (char*)"pi", pos);
                  pos=pos+2; refresh = 1;
                } else if (key==KEY_CHAR_EXP) {
                  if ((int)strlen(s)+4>=max) continue;
                  append(s, (char*)"*10^(", pos);
                  pos=pos+5; refresh = 1;
                } else if (key==KEY_CHAR_PMINUS) {
                  if ((int)strlen(s)+1>=max) continue;
                  append(s, (char*)"(-", pos);
                  pos=pos+2; refresh = 1;
                } else if (key==KEY_CHAR_ANS) {
                  if ((int)strlen(s)+3>=max) continue;
                  append(s, (char*)"last", pos);
                  pos=pos+4; refresh = 1;
                } else if (key==KEY_CHAR_ENG) {
                  if ((int)strlen(s)+7>=max) continue;
                  append(s, (char*)"selftest", pos);
                  pos=pos+8; refresh = 1;
                } else if (key==KEY_CTRL_MODE) {
                  // open functions catalog
                  /*char text[20] = "";
                  if(showCatalog(text)) {
                    int len = strlen(text);
                    if(pos+len>max) continue;
                    else {
                      append(s, text, pos);
                      pos=pos+len; refresh = 1;
                    }
                  }*/
                  //LCD_CursorEn(0);
                  LCD_SelectFont((u8 *)Font_Ascii_5X7E_Menu);
                  Mode_main();
                  LCD_Clear(0);
                  LCD_SelectFont((u8 *)Font_Ascii_5X7E);
                  dConsoleRedraw();
                  //LCD_CursorEn(1);
                  refresh = 1;
                } else if (key==KEY_CTRL_SETUP) {
                  //LCD_CursorEn(0);
                  LCD_SelectFont((u8 *)Font_Ascii_5X7E_Menu);
                  Setup_main();
                  LCD_Clear(0);
                  LCD_SelectFont((u8 *)Font_Ascii_5X7E);
                  dConsoleRedraw();
                  //LCD_CursorEn(1);
                  refresh = 1;
                } else if (key==KEY_CTRL_UP) {
                  // go up in command history
                  //do_up_arrow();
                  //line_start--;
                  //dConsoleRedraw();
                  //pos=strlen(s);
                  refresh = 1;
                  if (line_start>0)
                    line_start--;
                  dConsoleRedraw();
                } else if (key==KEY_CTRL_DOWN) {
                  // go down in command history
                  //do_down_arrow();
                  //line_start++;
                  //dConsoleRedraw();
                  //pos=strlen(s);
                  refresh = 1;
		  if (line_start<LINE_ROW_MAX-4)
                    line_start++;
                  dConsoleRedraw();
                } else if (key==KEY_CTRL_LEFT) {
                  // move cursor left
                  if(pos<=0) continue;
                  pos--;
                  refresh = 1;
                } else if (key==KEY_CTRL_RIGHT) {
                  // move cursor right
                  if(pos>=(int)strlen(s)) continue;
                  pos++;
                  refresh = 1;
                } else if ((c=dGetKeyChar(key))!=0) {
                        if ((int)strlen(s)>=max) continue;
                        char ns[2] = "";
                        ns[0] = c; ns[1]='\0';
                        append(s, ns, pos);
                        pos++;
                        refresh = 1;
                }
                else if (key==KEY_CTRL_DEL)
                {
                        if (pos<=0) continue;
                        pos--;
                        int i = pos;
                        do {
                                s[i] = s[i+1];
                                i++;
                        } while (s[i] != '\0');
                        refresh = 1;
                }
                else if (key==KEY_CTRL_AC)
                {
                        *s              = 0;
                        pos             = 0;
                        refresh = 1;
                }
                else if (key==KEY_CTRL_EXE) 
                {
                  //LCD_CursorEn(0);
                  return 1;
                }
        }
        return 0;
}
Esempio n. 6
0
void input_eval_loop(int isRecording) {
  char** recHistory = NULL; int curRecHistEntry = 0;
  if(isRecording) recHistory = (char**)alloca(200); // space for 200 pointers to history entries
  while (1) {
    DefineStatusMessage((char*)"", 1, 0, 0);
    strcpy(expr, (char*)"");
    printf("\x1e");
    dConsoleRedraw();
    int res = gets(expr,INPUTBUFLEN);
    if(res == 2) {
      dConsolePut("\n");
      select_script_and_run();
      continue;
    }
    if(res == 4) {
      dConsolePut("\n");
      select_strip_script();
      continue;
    }
    if(res == 3) {
      dConsolePut("\n");
      char buf[100] = "";
      sprintf(buf, "prizmUIkeyHandler(%d,%d)", custom_key_to_handle, custom_key_to_handle_modifier);
      strcpy(expr, (char*)buf);
      execution_in_progress = 1;
      run(buf);
      execution_in_progress = 0;
      check_do_graph();
      if(run_startup_script_again) { run_startup_script_again = 0; run_startup_script(); }
      continue;
    }
    puts(expr);
    update_cmd_history(expr);
    dConsoleRedraw();
    if(strcmp(expr, "testmode") == 0) {
      TestMode(1);
    } else if(strcmp(expr, "meminfo") == 0) {
      print_mem_info();
    } else if(strcmp(expr, "memgc") == 0) {
      gc();
    } else if(strcmp(expr, "record") == 0) {
      if(!isRecording) script_recorder();
      else {
        // create and save a script. this must be done here, because we used alloca
        // the "clean" way would be using malloc&free, but on the Prizm the heap is already being heavily used by the Eigenmath core.
        if(curRecHistEntry == 0) {
          printf("Nothing to record.\n");
          return;
        }
        printf("Recording stopped.\n");
        printf("Type a name for the script, or\n");
        printf("leave empty to discard.\n:");
        char inputname[MAX_FILENAME_SIZE+1] = "";
        gets(inputname,MAX_FILENAME_SIZE-50);
        puts(inputname);
        if(!strlen(inputname)) {
          // user aborted
          printf("Recording discarded.\n");
          return;
        }
        if (aborttimer > 0) {
          Timer_Stop(aborttimer);
          Timer_Deinstall(aborttimer);
        }
        char filename[MAX_FILENAME_SIZE+1] = "";
        sprintf(filename, "\\\\fls0\\%s.txt", inputname);
        unsigned short pFile[MAX_FILENAME_SIZE+1];
        Bfile_StrToName_ncpy(pFile, (unsigned char*)filename, strlen(filename)+1);
        // calculate size
        int size = 0;
        int maxHistory = curRecHistEntry - 1; //because we ++'ed at the end of last addition
        for(int i=0; i <= maxHistory; i++) {
          size = size + strlen(recHistory[i]) + 1; // 1 byte for \n. we will use unix line termination
        }
        int BCEres = Bfile_CreateEntry_OS(pFile, CREATEMODE_FILE, &size);
        if(BCEres >= 0) // Did it create?
        {
          BCEres = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle
          for(int i=0; i <= maxHistory; i++) {
            char* buf = (char*)alloca(strlen(recHistory[i])+5);
            strcpy(buf, recHistory[i]);
            strcat(buf, (char*)"\n");
            Bfile_WriteFile_OS(BCEres, buf, strlen(recHistory[i])+1);
          }
          Bfile_CloseFile_OS(BCEres);
          printf("Script created.\n");
        } else {
          printf("An error occurred when creating the script for recording.\n");
        }
        aborttimer = Timer_Install(0, check_execution_abort, 100);
        if (aborttimer > 0) Timer_Start(aborttimer);
        return;
      }
    } else {
      execution_in_progress = 1;
      has_drawn_graph = 0;
      run(expr);
      // run_startup_script cannot run from inside eval_clear because then it would be a run() inside a run()
      if(run_startup_script_again) { run_startup_script_again = 0; run_startup_script(); }
      execution_in_progress = 0;
      
      // if recording, add input to record
      if(isRecording && curRecHistEntry <= 200) {
        recHistory[curRecHistEntry] = (char*)alloca(strlen(expr)+2); // 2 bytes for security
        strcpy(recHistory[curRecHistEntry], expr);
        curRecHistEntry++;
      }
      check_do_graph();
    }
  }
}
Esempio n. 7
0
int dGetLine (char * s,int max)	// This function is depended on dConsole
								// And this function is not allowed to abolish
{
	int		pos = strlen(s);
	int		refresh = 1;
	int		x,y,l,width;
	uint	key;
	char	c;
	
	
	l = strlen (line_buf[line_index]);
	
	if (l>=LINE_COL_MAX)
	{
		dConsolePut("\n");
		l = 0;
	}
	else
		dConsoleRedraw();

	x = l + 1;
	y = line_count;
	width = LINE_COL_MAX - l;

	while (1)
	{
		if (refresh)
		{
			int i;
			for (i=x;i<=LINE_COL_MAX;++i)
			{
				locate(i,y);Print((uchar*)" ");
			}
			if (pos<width-1)
			{
				locate(x,y);		Print((uchar*)s);
				locate(x+pos,y);	Print((uchar*)"_");
			}
			else
			{
				locate(x,y);			Print((uchar*)s+pos-width+1);
				locate(x+width-1,y);	Print((uchar*)"_");
			}
			refresh = 0;
		}
		GetKey(&key);
		if ((c=dGetKeyChar(key))!=0)
		{
			if (pos>=max) continue;

			s[pos++] = c;s[pos] = '\0';
			refresh = 1;
		}
		else
		{
			if (key==KEY_CTRL_DEL)
			{
				if (pos<=0) continue;
				s[--pos] = '\0';
				refresh  = 1;
			}
			else if (key==KEY_CTRL_AC)
			{
				*s		= 0;
				pos		= 0;
				refresh	= 1;
			}
			else if (key==KEY_CTRL_EXE) return 1;
			
		}
	}
	return 0;
}
Esempio n. 8
0
void dPuts(const char * str)
{
	dConsolePut(str);
	dConsolePut("\n");
}