Exemplo n.º 1
0
/* Like shell_parse_stringlist, but returns an argv vector
   instead of a strlist.  */
static int
shell_parse_argv (const char *s, int *r_argc, char ***r_argv)
{
  int i;
  strlist_t list;

  if (shell_parse_stringlist (s, &list))
    return 1;

  *r_argc = strlist_length (list);
  *r_argv = xtrycalloc (*r_argc, sizeof **r_argv);
  if (*r_argv == NULL)
    return 1;

  for (i = 0; list; i++)
    (*r_argv)[i] = list->d, list = list->next;
  return 0;
}
Exemplo n.º 2
0
Arquivo: gpgtar.c Projeto: 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;
        }
    }
}