Пример #1
0
void do_get_string (struct tgl_state *TLS) {
  deactivate_readline ();
  generate_prompt (one_string_type, one_string_num);  
  printf ("%s", one_string_prompt);
  fflush (stdout);
  read_one_string = 1;
  one_string_len = 0;  
}
Пример #2
0
int		vsh(int ac, char **av, char **env)
{
  t_shell	shell;
  char		*str;

  (void)ac;
  (void)av;
  init_program(&shell, env);
  while ((shell.flag & SH_EXIT) &&
	 (str = my_readline(&shell, generate_prompt())))
    {
      lexor_and_parsor(str, &shell);
      main_execution(&shell);
    }
  exit_42sh(&shell);
  return (EXIT_SUCCESS);
}
Пример #3
0
int main() {
    //disable Ctrl+c
    signal(SIGINT,&sigint_handler);
    while (1) {
        if (generate_prompt(prompt)<0) {
            printf("Error in prompt generate!\n");
            exit(1);
        }
        fputs(prompt,stdout);
        if (fgets(cmd,CMD_MAX_LEN,stdin)==NULL) break;
        /*cmd[strlen(cmd)-1]='\0';*/
        background_job=0;
        execute_cmd();
    }
    printf("exit\n");
    return 0;
}
Пример #4
0
/**
 * No need to explain this.
 *
 * @param argc Number of arguments.
 * @param argv Arguments array.
 * @return Return code.
 */
int main(int argc, char **argv) {
	bool running = true;
	char *script_file = NULL;
	char *csv_file = NULL;
	char *ctok = NULL;
	gnuplot_ctrl *gp = gnuplot_init();
	char prompt[64] = "> ";

	if (argc == 2) {
		if (argv[1][strlen(argv[1]) - 3] == '.' &&
				argv[1][strlen(argv[1]) - 2] == 'p' &&
				argv[1][strlen(argv[1]) - 1] == 'c') {
			// Script file.
			script_file = argv[1];
			running = parse_script(script_file, ctok, &csv_file, gp, prompt);
		} else {
			// CSV file.
			csv_file = argv[1];
			generate_prompt(prompt, csv_file);
		}
	}

	while (running) {
		char *buffer = NULL;

		buffer = readline(prompt);
		if (buffer && *buffer) {
			add_history(buffer);
			ctok = strtok(buffer, " ");
		} else {
			continue;
		}

		running = parse_cmd_line(ctok, &csv_file, gp, prompt, false);
	}

	gnuplot_close(gp);
	return EXIT_SUCCESS;
}
Пример #5
0
/**
 * Parses a command.
 *
 * @param ctok Command string in strtok.
 * @param csv_file CSV file location.
 * @param gp gnuplot object.
 * @return True if the program should continue running.
 */
bool parse_cmd_line(char *ctok, char **csv_file, gnuplot_ctrl *gp, char *prompt, bool quiet) {
	// Command.
	if (!strcmp(ctok, "quit") || !strcmp(ctok, "exit")) {
		return false;
	} else if (!strcmp(ctok, "legend")) {
		// Toogle legend.
		if (!strcmp(strtok(NULL, " "), "off")) {
			gnuplot_cmd(gp, "set key off");
			if (!quiet) {
				printf("Legend turned off.\n");
			}
		} else {
			gnuplot_cmd(gp, "set key on");
			if (!quiet) {
				printf("Legend turned on.\n");
			}
		}
	} else if (!strcmp(ctok, "xlabel") || !strcmp(ctok, "ylabel")) {
		// Set xy label.
		char arg[64] = "";
		char xy = ctok[0];

		parse_spaced_arg(arg, ctok);
		if (!quiet) {
			printf("%clabel set to \"%s\"\n", xy, arg);
		}

		switch (xy) {
			case 'x':
				gnuplot_set_xlabel(gp, arg);
				break;
			case 'y':
				gnuplot_set_ylabel(gp, arg);
		}
	} else if (!strcmp(ctok, "plot")) {
		// Plot data.
		char lg_title[64] = "";
		uint8_t col = atoi(strtok(NULL, " "));
		double *items = NULL;
		unsigned int n = 0;

		parse_spaced_arg(lg_title, ctok);
		n = read_csv_col(&items, *csv_file, col);
		gnuplot_setstyle(gp, "lines");
		gnuplot_plot_x(gp, items, n, lg_title);
	} else if (!strcmp(ctok, "gp")) {
		// Execute raw gnuplot command.
		char gp_cmd[1024] = "";

		parse_spaced_arg(gp_cmd, ctok);
		gnuplot_cmd(gp, gp_cmd);
	} else if (!strcmp(ctok, "load")) {
		// Load CSV.
		char filename[2048] = "";
		parse_spaced_arg(filename, ctok);

		*csv_file = malloc(strlen(filename) + 1);
		strcpy(*csv_file, filename);
		generate_prompt(prompt, *csv_file);
	} else {
		printf("Invalid command: %s\n", ctok);
	}

	return true;
}