Ejemplo n.º 1
0
void
do_down_arrow(void)
{
	char *s;

	// save curr cmd if new input or change to historical input

	s = get_curr_cmd();

	if (*s) {
		if (k == i || strcmp(s, buf[k]) != 0) {
			update_cmd_history(s);
			k = (i + N - 1) % N;
		}
	}

	free(s);

	// advance history pointer

	if (k != i)
		k = (k + 1) % N;

	if (buf[k])
		update_curr_cmd(buf[k]);
	else
		update_curr_cmd("");
}
Ejemplo n.º 2
0
void input_eval_loop() {
  char** recHistory = NULL; int curRecHistEntry = 0;
  while (1) {
    dPrintf(">");
    dConsoleRedraw();
    int res = dGetLine(expr,INPUTBUFLEN);
    dPuts(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 {
      execution_in_progress = 1;
      PM_SetCPUFreq(152);
      run(expr);
      PM_SetCPUFreq(16);
      execution_in_progress = 0;     
    }
  }
}
Ejemplo n.º 3
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();
    }
  }
}
Ejemplo n.º 4
0
int escore_slim_cmd(struct escore_priv *escore, u32 cmd, u32 *resp)
{
	int err = 0;
	int sr = cmd & BIT(28);
	u32 rv;
	int retry = ES_MAX_RETRIES + 1;
	struct slim_device *sbdev = escore->gen0_client;

	dev_dbg(&sbdev->dev,
			"%s: cmd=0x%08x  sr=0x%08x\n", __func__, cmd, sr);

	*resp = 0;
	cmd = cpu_to_le32(cmd);
	err = escore_slim_write(escore, &cmd, sizeof(cmd));
	dev_dbg(&sbdev->dev, "%s: err=%d, cmd_cmpl_mode=%d\n",
		 __func__, err, escore->cmd_compl_mode);
	if (err || sr)
		goto cmd_exit;

	do {
		if (escore->cmd_compl_mode == ES_CMD_COMP_INTR) {
			pr_debug("%s(): Waiting for API interrupt. Jiffies:%lu",
					__func__, jiffies);
			err = wait_for_completion_timeout(&escore->rising_edge,
					msecs_to_jiffies(ES_RESP_TOUT_MSEC));
			if (!err) {
				pr_debug("%s(): API Interrupt wait timeout\n",
						__func__);
				err = -ETIMEDOUT;
				break;
			}
		} else {
			pr_debug("%s(): Polling method\n", __func__);
			usleep_range(ES_RESP_POLL_TOUT,
					ES_RESP_POLL_TOUT + 500);
		}
		err = escore_slim_read(escore, &rv, sizeof(rv));
		dev_dbg(&sbdev->dev, "%s: err=%d\n", __func__, err);
		*resp = le32_to_cpu(rv);
		dev_dbg(&sbdev->dev, "%s: *resp=0x%08x\n", __func__, *resp);
		if (err) {
			dev_dbg(&sbdev->dev,
				"%s: escore_slim_read() failure\n", __func__);
		} else if ((*resp & ES_ILLEGAL_CMD) == ES_ILLEGAL_CMD) {
			dev_err(&sbdev->dev, "%s: illegal command 0x%08x\n",
				__func__, cmd);
			err = -EINVAL;
			goto cmd_exit;
		} else if (*resp == ES_NOT_READY) {
			dev_dbg(&sbdev->dev,
				"%s: escore_slim_read() not ready\n", __func__);
			err = -ETIMEDOUT;
		} else {
			goto cmd_exit;
		}

		--retry;
	} while (retry != 0 && escore->cmd_compl_mode != ES_CMD_COMP_INTR);

cmd_exit:
	update_cmd_history(le32_to_cpu(cmd), *resp);
	return err;
}