예제 #1
0
파일: util.c 프로젝트: borlox/kos
int main(int argc, char **argv)
{
	char test1[] = " Hallo  \n";

	printf("Before: '%s'\n", test1);
	char *after = prepare(test1);
	printf("After: '%s'\n", after ? after : "<NULL>");

	char test2[] = "  \t\t \n";
	printf("Before: '%s'\n", test2);
	after = prepare(test2);
	printf("After: '%s'\n", after ? after : "<NULL>");

	struct cmd cmd = {0, 0};
	char line[] = "echo \"test bla\" 'blub\\' diedup'";
	split_cmd(line, &cmd);
	printf("Cmd: \n Argc: %d\n", cmd.argc);

	int i=0;
	for (; i < cmd.argc; ++i) {
		printf(" ->%s\n", cmd.argv[i]);
	}

	char *relined = build_cmd(&cmd);

	printf("Reassembled: '%s'\n", relined);

	free_argv(&cmd);
	free(relined);

	return 0;
}
예제 #2
0
파일: ute.c 프로젝트: hroptatyr/uterus
int
main(int argc, char *argv[])
{
	char *cmd_f = NULL;
	subcmd_f icmd = NULL;
	const char *cmd;
	int res = 0;

	init_cmds();
	if ((cmd = extract_cmd(argc, argv)) == NULL &&
	    /* try the rewriter */
	    (icmd = rewrite_subcmd(argc, argv)) == NULL) {
		ute_cmd_help(argc, argv);
		res = 1;

	} else if (cmd != NULL && (cmd_f = build_cmd(cmd)) != NULL) {
		/* prepare the execve */
		argv[0] = cmd_f;
		res = execv(cmd_f, argv);

	} else if (icmd != NULL || (icmd = get_subcmd(cmd)) != NULL) {
		/* call the internal command */
		res = icmd(argc, argv);

	} else {
		fprintf(stderr, "ute subcommand `%s' invalid\n\n", cmd);
		ute_cmd_help(argc, argv);
		res = 1;
	}
	return res;
}
예제 #3
0
/******************************************************************************
 * This function scores a sequence database using mhmmscan
 *****************************************************************************/
void run_mhmmscan(
  MCAST_OPTIONS_T *options,
  char *hmm_filename,
  char *seq_filename,
  char *scores_filename
) {

  if (verbosity >= NORMAL_VERBOSE) {
    fprintf(stderr, "%s", "Creating HMM from motif file.\n");
  }

  // Build the command line for mhmmscan
  const char *bin_dir = get_meme_bin_dir();
  char *cmd;
  cmd = build_cmd(
             "mhmmscan", 
             "%s/mhmmscan %s %s %s --fancy --allow-weak-motifs %s --p-thresh %s "
             "--max-gap %s --e-thresh %s --eg-cost 1 --pseudo-weight %s %s "
             "%s %s > %s", 
             bin_dir,
             options->bg_filename != NULL ? "--bg-file" : "",
             options->bg_filename != NULL ? options->bg_filename : "",
             options->text_only ? "--text" : "",
             options->use_synth ? "--synth" : "",
             options->p_thresh,
             options->max_gap,
             options->e_thresh,
             options->pseudo_weight,
             options->quiet ? "--quiet" : "",
             hmm_filename,
             seq_filename,
             scores_filename
           );

  // Execute mhmmscan
  if (verbosity >= NORMAL_VERBOSE) {
    fprintf(stderr, "Executing %s\n", cmd);
  }
  int status = system(cmd);
  // Check for interrupts
  if (WIFSIGNALED(status) && 
     (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGQUIT)) {
       die("Interrupted while running mhmmscan");
  }
  if (status == -1) {
    // Unable to start mhmmscan
    perror("Error starting mhmmscan command");
    die("Unable to start mhmmscan command (%s)", cmd);
  }

  // Check result of running mhmmscan
  int result = WEXITSTATUS(status);
  if (result != 0) {
    die("mhmmscan failed with exit status %d, command run was: %s", result, cmd);
  }
  free(cmd);
}
예제 #4
0
파일: upsclient.c 프로젝트: ThomasKurz/nut
int upscli_list_start(UPSCONN_t *ups, unsigned int numq, const char **query)
{
	char	cmd[UPSCLI_NETBUF_LEN], tmp[UPSCLI_NETBUF_LEN];

	if (!ups) {
		return -1;
	}

	if (numq < 1) {
		ups->upserror = UPSCLI_ERR_INVALIDARG;
		return -1;
	}

	/* create the string to send to upsd */
	build_cmd(cmd, sizeof(cmd), "LIST", numq, query);

	if (upscli_sendline(ups, cmd, strlen(cmd)) != 0) {
		return -1;
	}

	if (upscli_readline(ups, tmp, sizeof(tmp)) != 0) {
		return -1;
	}

	if (upscli_errcheck(ups, tmp) != 0) {
		return -1;
	}

	if (!pconf_line(&ups->pc_ctx, tmp)) {
		ups->upserror = UPSCLI_ERR_PARSE;
		return -1;
	}

	if (ups->pc_ctx.numargs < 2) {
		ups->upserror = UPSCLI_ERR_PROTOCOL;
		return -1;
	}

	/* the response must start with BEGIN LIST */
	if ((strcasecmp(ups->pc_ctx.arglist[0], "BEGIN") != 0) ||
		(strcasecmp(ups->pc_ctx.arglist[1], "LIST") != 0)) {
		ups->upserror = UPSCLI_ERR_PROTOCOL;
		return -1;
	}

	/* q: [LIST] VAR <ups>       *
	 * a: [BEGIN LIST] VAR <ups> */

	/* compare q[0]... to a[2]... */

	if (!verify_resp(numq, query, &ups->pc_ctx.arglist[2])) {
		ups->upserror = UPSCLI_ERR_PROTOCOL;
		return -1;
	}

	return 0;
}
예제 #5
0
파일: upsclient.c 프로젝트: ThomasKurz/nut
int upscli_get(UPSCONN_t *ups, unsigned int numq, const char **query, 
		unsigned int *numa, char ***answer)
{
	char	cmd[UPSCLI_NETBUF_LEN], tmp[UPSCLI_NETBUF_LEN];
	
	if (!ups) {
		return -1;
	}

	if (numq < 1) {
		ups->upserror = UPSCLI_ERR_INVALIDARG;
		return -1;
	}

	/* create the string to send to upsd */
	build_cmd(cmd, sizeof(cmd), "GET", numq, query);

	if (upscli_sendline(ups, cmd, strlen(cmd)) != 0) {
		return -1;
	}

	if (upscli_readline(ups, tmp, sizeof(tmp)) != 0) {
		return -1;
	}

	if (upscli_errcheck(ups, tmp) != 0) {
		return -1;
	}

	if (!pconf_line(&ups->pc_ctx, tmp)) {
		ups->upserror = UPSCLI_ERR_PARSE;
		return -1;
	}

	/* q: [GET] VAR <ups> <var>   *
	 * a: VAR <ups> <var> <val> */

	if (ups->pc_ctx.numargs < numq) {
		ups->upserror = UPSCLI_ERR_PROTOCOL;
		return -1;
	}

	if (!verify_resp(numq, query, ups->pc_ctx.arglist)) {
		ups->upserror = UPSCLI_ERR_PROTOCOL;
		return -1;
	}

	*numa = ups->pc_ctx.numargs;
	*answer = ups->pc_ctx.arglist;

	return 0;
}
예제 #6
0
/******************************************************************************
 * This function builds a star topology HMM from a MEME format motif file.
 * The HMM is stored in a text file in the output directory.
 *****************************************************************************/
void run_mhmm(
  char *motif_filename,
  char *hmm_filename
) {

  if (verbosity >= NORMAL_VERBOSE) {
    fprintf(stderr, "%s", "Creating HMM from motif file.\n");
  }

  // Build the command line for mhmm
  const char *bin_dir = get_meme_bin_dir();
  char *cmd;
  cmd = build_cmd(
             "mhmm", 
             "%s/mhmm --type star --keep-unused --verbosity %d %s > %s", 
             bin_dir,
             verbosity,
             motif_filename,
             hmm_filename
           );

  // Execute mhmm
  if (verbosity >= NORMAL_VERBOSE) {
    fprintf(stderr, "Executing %s\n", cmd);
  }
  int status = system(cmd);
  // Check for interrupts
  if (WIFSIGNALED(status) && 
     (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGQUIT)) {
       die("Interrupted while running mhmm");
  }
  if (status == -1) {
    // Unable to start mhmm
    perror("Error starting mhmm command");
    die("Unable to start mhmm command (%s)", cmd);
  }

  // Check result of running mhmm
  int result = WEXITSTATUS(status);
  if (result != 0) {
    die("mhmm failed with exit status %d, command run was: %s", result, cmd);
  }
  free(cmd);
}
예제 #7
0
파일: rcsprog.c 프로젝트: mosconi/openbsd
int
main(int argc, char **argv)
{
	u_int i;
	char **cmd_argv;
	int ret, cmd_argc;

	if (pledge("stdio rpath wpath cpath fattr flock getpw", NULL) == -1)
		err(2, "pledge");

	ret = -1;
	rcs_optind = 1;
	SLIST_INIT(&temp_files);

	cmd_argc = build_cmd(&cmd_argv, argv, argc);

	if ((rcs_tmpdir = getenv("TMPDIR")) == NULL)
		rcs_tmpdir = RCS_TMPDIR_DEFAULT;

	signal(SIGHUP, sighdlr);
	signal(SIGINT, sighdlr);
	signal(SIGQUIT, sighdlr);
	signal(SIGABRT, sighdlr);
	signal(SIGALRM, sighdlr);
	signal(SIGTERM, sighdlr);

	for (i = 0; i < (sizeof(programs)/sizeof(programs[0])); i++)
		if (strcmp(__progname, programs[i].prog_name) == 0) {
			usage = programs[i].prog_usage;
			ret = programs[i].prog_hdlr(cmd_argc, cmd_argv);
			break;
		}

	/* clean up temporary files */
	worklist_run(&temp_files, worklist_unlink);

	exit(ret);
}
예제 #8
0
파일: Terminal.c 프로젝트: alex262/MB96F330
void Terminal (void)
{
	U8 c;
	
	if (GetRxByte(&c) == FIFO_ERROR_UNDERFLOW)
		return;
	// While a usable user command on RS232 isn't received, build it
	if (!cmd)
	{
		build_cmd(c);
	}
	// perform the command
	if (cmd)
	{
		switch (cmd_type)
		{
			case CMD_UART:
				DrawUartReg(par_str1[0]-0x30);
				break;
			case CMD_RESET:
				RESET;
				break;
			case CMD_DMA:
				DrawDMAStatus();
				break;
			case CMD_CAN0:
				DrawCanStatus(0);
				break;
			case CMD_CAN1:
				DrawCanStatus(1);
				break;
			case CMD_CAN2:
				DrawCanStatus(2);
				break;
	
			
			#ifdef EN_SR_ZN_CYKL
				case CMD_CYKLE:
					puts((BYTE *)" Среднее время цикла - ");
					putdec(program.SrCikl_mks);
					puts((BYTE *)" мкс \n\r");
					break;
			#endif
		
			case CMD_ADDR:
				puts((BYTE *)" Адрес блока - ");
				putdec(ADDR,3);
				puts((BYTE *)"\n\r");
				
				break;
			case CMD_TIMERS:
				PrintTimerService();
				break;
			//=============================================
			case CMD_HELP:
				// Display help on USART
				puts((BYTE *)MSG_HELP);
				break;
			// Unknown command.
			default:
				// Display error message.
				puts((BYTE *)MSG_ER_CMD_NOT_FOUND);
				break;
		}
		// Reset vars.
		cmd_type = CMD_NONE;
		cmd = false;
		// Display prompt.
		puts((BYTE *)MSG_PROMPT);
	}
}