コード例 #1
0
ファイル: fileutils.c プロジェクト: aharotias2/t-obmenu
str_list* get_file_list(char *dir_name) {
	str_list dir_list = {"  ", NULL}, file_list = {"  ", NULL};
	char *path;

	DIR *dir;
	struct dirent *dp;
	int dir_length = strlen(dir_name);

	if (dir_length <= 0) {
		return NULL;
	}

	dir = opendir(dir_name);
	if (dir == NULL) return NULL;

	for (dp = readdir(dir); dp != NULL; dp = readdir(dir)) {
		if (dp->d_name[0] == '.') {
			continue;
		}
		path = malloc(dir_length + 1 + strlen(dp->d_name) + 1);
		sprintf(path, "%s/%s", dir_name, dp->d_name);
		int file_type = is_reg_file(path);
		if (file_type == 1) {
			strlist_add_sort(&file_list, dp->d_name);
		} else if (file_type == 0) {
			strlist_add_sort(&dir_list, dp->d_name);
		}
		free(path);
	}

	closedir(dir);

	if (strlist_length(dir_list.next) > 0) {
		strlist_last(dir_list.next)->next = file_list.next;
	} else {
		dir_list.next = file_list.next;
	}

	return dir_list.next;
}
コード例 #2
0
ファイル: gpgtar.c プロジェクト: gpg/gnupg
/* Command line parsing.  */
static void
parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
{
    int no_more_options = 0;

    while (!no_more_options && optfile_parse (NULL, NULL, NULL, pargs, popts))
    {
        switch (pargs->r_opt)
        {
        case oOutput:
            opt.outfile = pargs->r.ret_str;
            break;
        case oDirectory:
            opt.directory = pargs->r.ret_str;
            break;
        case oSetFilename:
            opt.filename = pargs->r.ret_str;
            break;
        case oQuiet:
            opt.quiet = 1;
            break;
        case oVerbose:
            opt.verbose++;
            break;
        case oNoVerbose:
            opt.verbose = 0;
            break;
        case oFilesFrom:
            files_from = pargs->r.ret_str;
            break;
        case oNull:
            null_names = 1;
            break;

        case aList:
        case aDecrypt:
        case aEncrypt:
        case aSign:
            set_cmd (&cmd, pargs->r_opt);
            break;

        case oRecipient:
            add_to_strlist (&opt.recipients, pargs->r.ret_str);
            break;

        case oUser:
            opt.user = pargs->r.ret_str;
            break;

        case oSymmetric:
            set_cmd (&cmd, aEncrypt);
            opt.symmetric = 1;
            break;

        case oGpgProgram:
            opt.gpg_program = pargs->r.ret_str;
            break;

        case oSkipCrypto:
            skip_crypto = 1;
            break;

        case oOpenPGP: /* Dummy option for now.  */
            break;
        case oCMS:     /* Dummy option for now.  */
            break;

        case oGpgArgs:
            ;
            {
                strlist_t list;
                if (shell_parse_stringlist (pargs->r.ret_str, &list))
                    log_error ("failed to parse gpg arguments '%s'\n",
                               pargs->r.ret_str);
                else
                {
                    if (opt.gpg_arguments)
                        strlist_last (opt.gpg_arguments)->next = list;
                    else
                        opt.gpg_arguments = list;
                }
            }
            break;

        case oTarArgs:
            ;
            {
                int tar_argc;
                char **tar_argv;

                if (shell_parse_argv (pargs->r.ret_str, &tar_argc, &tar_argv))
                    log_error ("failed to parse tar arguments '%s'\n",
                               pargs->r.ret_str);
                else
                {
                    ARGPARSE_ARGS tar_args;
                    tar_args.argc = &tar_argc;
                    tar_args.argv = &tar_argv;
                    tar_args.flags = ARGPARSE_FLAG_ARG0;
                    parse_arguments (&tar_args, tar_opts);
                    if (tar_args.err)
                        log_error ("unsupported tar arguments '%s'\n",
                                   pargs->r.ret_str);
                    pargs->err = tar_args.err;
                }
            }
            break;

        case oDryRun:
            opt.dry_run = 1;
            break;

        default:
            pargs->err = 2;
            break;
        }
    }
}