コード例 #1
0
int
cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
{
	struct cmd_buffer_data	*data;
	const struct cmd_entry	*entry = self->entry;
	int			 opt, n;
	const char		*errstr;

	cmd_buffer_init(self, 0);
	data = self->data;

	while ((opt = cmd_getopt(argc, argv, "b:t:", entry->chflags)) != -1) {
		if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
			continue;
		switch (opt) {
		case 'b':
			if (data->buffer == -1) {
				n = strtonum(optarg, 0, INT_MAX, &errstr);
				if (errstr != NULL) {
					xasprintf(cause, "buffer %s", errstr);
					goto error;
				}
				data->buffer = n;
			}
			break;
		case 't':
			if (data->target == NULL)
				data->target = xstrdup(optarg);
			break;
		default:
			goto usage;
		}
	}
	argc -= optind;
	argv += optind;

	if (cmd_fill_argument(
	    self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
		goto usage;
	return (0);

usage:
	xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);

error:
	self->entry->free(self);
	return (-1);
}
コード例 #2
0
/*
 ****************************************************************
 *	Desmonta o dispositivo com o sistema de arquivos DOS	*
 ****************************************************************
 */
void
do_umount (int argc, const char *argv[])
{
	int		opt;

	/*
	 *	Analisa as opções
	 */
	while ((opt = cmd_getopt (argv, "H")) >= 0)
	{
		switch (opt)
		{
		    case 'H':			/* Help */
			do_umount_help ();
			return;

		    default:			/* Erro */
			fprintf (stderr, "\n");
			do_umount_help ();
			return;
		}
	}

	/*
	 *	Pequena consistência
	 */
	argc -= cmd_optind;
	argv += cmd_optind;

	if (argc > 0)
	{
		do_umount_help ();
		return;
	}

	/*
	 *	Processa o dispositivo
	 */
	simple_umount ();

}	/* end do_umount */
コード例 #3
0
int
cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause)
{
	struct cmd_srcdst_data	*data;
	const struct cmd_entry	*entry = self->entry;
	int			 opt;

	cmd_srcdst_init(self, 0);
	data = self->data;

	while ((opt = cmd_getopt(argc, argv, "s:t:", entry->chflags)) != -1) {
		if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
			continue;
		switch (opt) {
		case 's':
			if (data->src == NULL)
				data->src = xstrdup(optarg);
			break;
		case 't':
			if (data->dst == NULL)
				data->dst = xstrdup(optarg);
			break;
		default:
			goto usage;
		}
	}
	argc -= optind;
	argv += optind;

	if (cmd_fill_argument(
	    self->entry->flags, &data->arg, &data->arg2, argc, argv) != 0)
		goto usage;
	return (0);

usage:
	xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);

	self->entry->free(self);
	return (-1);
}
コード例 #4
0
ファイル: do_rm.c プロジェクト: marioaugustorama/tropix-cmd
/*
 ****************************************************************
 *	Remove arquivos						*
 ****************************************************************
 */
void
do_rm (int argc, const char *argv[])
{
	int		opt;

	/*
	 *	Inicializações
	 */
	cmd_iflag = 1;

	/*
	 *	Analisa as opções
	 */
	while ((opt = cmd_getopt (argv, "ifvH")) >= 0)
	{
		switch (opt)
		{
		    case 'i':			/* Interativo */
			cmd_iflag++;
			break;

		    case 'f':			/* Força */
			cmd_iflag = 0;
			break;

		    case 'v':			/* Verboso */
			cmd_vflag++;
			break;

		    case 'H':			/* Help */
			do_rm_help ();
			return;

		    default:			/* Erro */
			fprintf (stderr, "\n");
			do_rm_help ();
			return;
		}
	}

	/*
	 *	Pequena consistência
	 */
	argc -= cmd_optind;
	argv += cmd_optind;

	if (argc == 0)
		{ do_rm_help (); return; }

	/*
	 *	Processa os arquivos
	 */
	for (/* vazio */; *argv; argv++)
	{
		if (received_intr)
			break;

		simple_rm (*argv);
	}

}	/* end do_rm */
コード例 #5
0
ファイル: do_df.c プロジェクト: marioaugustorama/tropix-cmd
/*
 ****************************************************************
 *	Imprime o diretório corrente				*
 ****************************************************************
 */
void
do_df (int argc, const char *argv[])
{
	const UNI	*up = &uni;
	int		livres, total, usados, ruins, index;
	int		end_index;
	short		clusno;
	int		opt;

	/*
	 *	Analisa as opções
	 */
	while ((opt = cmd_getopt (argv, "H")) >= 0)
	{
		switch (opt)
		{
		    case 'H':			/* Help */
			do_df_help ();
			return;

		    default:			/* Erro */
			fprintf (stderr, "\n");
			do_df_help ();
			return;
		}
	}

	/*
	 *	Pequena consistência
	 */
	argc -= cmd_optind;
	argv += cmd_optind;

	if (argc != 0)
		{ do_df_help (); return; }

	/*
	 *	Verifica quantos "clusters" estão livres
	 */
	get_whole_fat ();

	for
	(	livres = 0, ruins = 0,
		index = 2, end_index = 2 + up->u_n_clusters;
		index < end_index;
		index++
	) 
	{
		if   (C_ISFREE (clusno = get_fat_value (index)))
			livres++;
		elif (C_ISBAD (clusno))
			ruins++;
	}

	total  = up->u_n_clusters;
	usados = total - livres - ruins;

	total  = BLTOKB (up->u_sectors_per_cluster * total);
	usados = BLTOKB (up->u_sectors_per_cluster * usados);
	livres = BLTOKB (up->u_sectors_per_cluster * livres);
	ruins  = BLTOKB (up->u_sectors_per_cluster * ruins);

	/*
	 *	Imprime o cabeçalho
	 */
	printf
	(	"RW DISPOSITIVO         SISTEMA    "
		" TOTAL  ALOCADOS  LIVRES  RUINS (KB)   %%\n"
	);

	/*
	 *	Imprime o resultado
	 */
	printf ("%s ", fs_status == FS_MOUNT_RO ? "RO" : "  ");
	printf ("%-20.20s", dev_nm);
	printf ("%-8.8s  ", sb.s_id);
	printf ("%7d   %7d %7d %6d      ", total, usados, livres, ruins);
	printf
	(	"%s %%\n",
		total == 0 ? "?" : editpercent (getpercent (usados, total - ruins))
	);

}	/* end do_df */