示例#1
0
/* Append a directory to the end of the list of directories.  */
void
dir_list_append (const char *s)
{
  if (directory == NULL)
    directory = string_list_alloc ();
  string_list_append_unique (directory, s);
}
示例#2
0
文件: main.c 项目: cglinden/autocook
int
main(int argc, char **argv)
{
    string_ty       *s;
    string_list_ty  sl;
    size_t          j;

    arglex_init(argc, argv, argtab);
    str_initialize();
    switch (arglex())
    {
    case arglex_token_help:
        help((char *)0, usage);
        exit(0);

    case arglex_token_version:
        version();
        exit(0);

    default:
        break;
    }

    string_list_constructor(&sl);
    while (arglex_token != arglex_token_eoln)
    {
        switch (arglex_token)
        {
        default:
            generic_argument(usage);
            continue;

        case arglex_token_warning:
            warning++;
            break;

        case arglex_token_string:
            s = str_from_c(arglex_value.alv_string);
            string_list_append_unique(&sl, s);
            str_free(s);
            break;
        }
        arglex();
    }

    if (!sl.nstrings)
    {
        error_intl(0, i18n("no files named"));
        usage();
    }

    for (j = 0; j < sl.nstrings; ++j)
        file_check(sl.string[j]);
    exit(0);
    return 0;
}
/* Read list of filenames from a file.  */
string_list_ty *
read_names_from_file (const char *file_name)
{
  size_t line_len = 0;
  char *line_buf = NULL;
  FILE *fp;
  string_list_ty *result;

  if (strcmp (file_name, "-") == 0)
    fp = stdin;
  else
    {
      fp = fopen (file_name, "r");
      if (fp == NULL)
	error (EXIT_FAILURE, errno,
	       _("error while opening \"%s\" for reading"), file_name);
    }

  result = string_list_alloc ();

  while (!feof (fp))
    {
      /* Read next line from file.  */
      int len = getline (&line_buf, &line_len, fp);

      /* In case of an error leave loop.  */
      if (len < 0)
	break;

      /* Remove trailing '\n' and trailing whitespace.  */
      if (len > 0 && line_buf[len - 1] == '\n')
	line_buf[--len] = '\0';
      while (len > 0
	     && (line_buf[len - 1] == ' '
		 || line_buf[len - 1] == '\t'
		 || line_buf[len - 1] == '\r'))
	line_buf[--len] = '\0';

      /* Test if we have to ignore the line.  */
      if (*line_buf == '\0' || *line_buf == '#')
	continue;

      string_list_append_unique (result, line_buf);
    }

  /* Free buffer allocated through getline.  */
  if (line_buf != NULL)
    free (line_buf);

  /* Close input stream.  */
  if (fp != stdin)
    fclose (fp);

  return result;
}
示例#4
0
文件: cook.c 项目: cglinden/autocook
void
cook_implicit_append( recipe_ty *rp)
{
    string_ty       *base;
    string_list_ty  base_list;
    recipe_list_ty  *rlp;
    size_t          j;
    match_ty        *mp;

    /*
     * Create a suitable matching object.  We need to set the recipe
     * flags, to know which matching flavour.
     */
    mp = match_new_by_recipe(rp);

    string_list_constructor(&base_list);
    for (j = 0; j < rp->target->nstrings; ++j)
    {
        base = os_entryname(rp->target->string[j]);
        if (match_usage_mask(mp, base, &rp->pos) != 0)
        {
            match_delete(mp);
            str_free(base);
            string_list_destructor(&base_list);
            recipe_list_append(&implicit, rp);
            return;
        }
        string_list_append_unique(&base_list, base);
        str_free(base);
    }
    match_delete(mp);
    for (j = 0; j < base_list.nstrings; ++j)
    {
        base = base_list.string[j];
        rlp = cook_implicit_find(base);
        recipe_list_append(rlp, rp);
    }
    string_list_destructor(&base_list);
}
示例#5
0
文件: main.c 项目: cglinden/autocook
static void
argparse(option_level_ty level)
{
    option_number_ty type;
    string_ty       *s;
    sub_context_ty  *scp;
    int             fingerprint_update;

    type = -1;
    fingerprint_update = 0;
    switch (arglex())
    {
    case arglex_token_help:
        if (level != OPTION_LEVEL_COMMAND_LINE)
        {
          not_in_env:
            scp = sub_context_new();
            sub_var_set(scp, "Name", "%s", arglex_value.alv_string);
            fatal_intl(scp, i18n("may not use $name in environment variable"));
            /* NOTREACHED */
        }
        help((char *)0, usage);
        quit(0);

    case arglex_token_version:
        if (level != OPTION_LEVEL_COMMAND_LINE)
            goto not_in_env;
        version();
        quit(0);

    default:
        break;
    }
    while (arglex_token != arglex_token_eoln)
    {
        switch (arglex_token)
        {
        default:
            generic_argument(usage);
            continue;

        case arglex_token_include:
            if (arglex() != arglex_token_string)
            {
                arg_needs_string(arglex_token_include, usage);
                /* NOTREACHED */
            }
            s = str_from_c(arglex_value.alv_string);
            string_list_append_unique(&option.o_search_path, s);
            str_free(s);
            break;

        case arglex_token_reason:
            type = OPTION_REASON;
          normal_on:
            if (option_already(type, level))
            {
              too_many:
                arg_duplicate_cur(usage);
                /* NOTREACHED */
            }
            option_set(type, level, 1);
            break;

        case arglex_token_reason_not:
            type = OPTION_REASON;
          normal_off:
            if (option_already(type, level))
                goto too_many;
            option_set(type, level, 0);
            break;

        case arglex_token_cascade:
            type = OPTION_CASCADE;
            goto normal_on;

        case arglex_token_cascade_not:
            type = OPTION_CASCADE;
            goto normal_off;

        case arglex_token_disassemble:
            type = OPTION_DISASSEMBLE;
            goto normal_on;

        case arglex_token_disassemble_not:
            type = OPTION_DISASSEMBLE;
            goto normal_off;

        case arglex_token_tty:
            type = OPTION_TERMINAL;
            goto normal_on;

        case arglex_token_tty_not:
            type = OPTION_TERMINAL;
            goto normal_off;

        case arglex_token_precious:
            type = OPTION_PRECIOUS;
            goto normal_on;

        case arglex_token_precious_not:
            type = OPTION_PRECIOUS;
            goto normal_off;

        case arglex_token_log:
            if (option_already(OPTION_LOGGING, level))
                goto too_many;
            option_set(OPTION_LOGGING, level, 1);
            if (arglex() != arglex_token_string)
                continue;
            if (option.o_logfile)
                str_free(option.o_logfile);
            option.o_logfile = str_from_c(arglex_value.alv_string);
            break;

        case arglex_token_log_not:
            type = OPTION_LOGGING;
            goto normal_off;

        case arglex_token_book:
            if (option_already(OPTION_BOOK, level))
                goto too_many;
            option_set(OPTION_BOOK, level, 1);
            if (arglex() != arglex_token_string)
                continue;
            if (option.o_book)
                str_free(option.o_book);
            option.o_book = str_from_c(arglex_value.alv_string);
            break;

        case arglex_token_book_not:
            type = OPTION_BOOK;
            goto normal_off;

        case arglex_token_include_cooked:
            type = OPTION_INCLUDE_COOKED;
            goto normal_on;

        case arglex_token_include_cooked_not:
            type = OPTION_INCLUDE_COOKED;
            goto normal_off;

        case arglex_token_include_cooked_warning:
            type = OPTION_INCLUDE_COOKED_WARNING;
            goto normal_on;

        case arglex_token_include_cooked_warning_not:
            type = OPTION_INCLUDE_COOKED_WARNING;
            goto normal_off;

        case arglex_token_silent:
            type = OPTION_SILENT;
            goto normal_on;

        case arglex_token_silent_not:
            type = OPTION_SILENT;
            goto normal_off;

        case arglex_token_tell_position:
            type = OPTION_TELL_POSITION;
            goto normal_on;

        case arglex_token_tell_position_not:
            type = OPTION_TELL_POSITION;
            goto normal_off;

        case arglex_token_metering:
            type = OPTION_METER;
            goto normal_on;

        case arglex_token_metering_not:
            type = OPTION_METER;
            goto normal_off;

        case arglex_token_touch:
            type = OPTION_TOUCH;
            goto normal_on;

        case arglex_token_touch_not:
            type = OPTION_TOUCH;
            goto normal_off;

        case arglex_token_action:
            type = OPTION_ACTION;
            goto normal_on;

        case arglex_token_action_not:
            type = OPTION_ACTION;
            goto normal_off;

        case arglex_token_persevere:
            type = OPTION_PERSEVERE;
            goto normal_on;

        case arglex_token_persevere_not:
            type = OPTION_PERSEVERE;
            goto normal_off;

        case arglex_token_errok:
            type = OPTION_ERROK;
            goto normal_on;

        case arglex_token_errok_not:
            type = OPTION_ERROK;
            goto normal_off;

        case arglex_token_force:
            type = OPTION_FORCE;
            goto normal_on;

        case arglex_token_force_not:
            type = OPTION_FORCE;
            goto normal_off;

        case arglex_token_fingerprint:
            type = OPTION_FINGERPRINT;
            goto normal_on;

        case arglex_token_fingerprint_not:
            type = OPTION_FINGERPRINT;
            goto normal_off;

        case arglex_token_fingerprint_update:
            if (level != OPTION_LEVEL_COMMAND_LINE)
                goto not_in_env;
            if (option.fingerprint_update)
                goto too_many;
            option.fingerprint_update++;
            break;

        case arglex_token_pairs:
            if (level != OPTION_LEVEL_COMMAND_LINE)
                goto not_in_env;
            if (option.pairs)
                goto too_many;
            option.pairs++;
            break;

        case arglex_token_script:
            if (level != OPTION_LEVEL_COMMAND_LINE)
                goto not_in_env;
            if (option.script)
                goto too_many;
            option.script++;
            break;

        case arglex_token_web:
            if (level != OPTION_LEVEL_COMMAND_LINE)
                goto not_in_env;
            if (option.web)
                goto too_many;
            option.web++;
            break;

        case arglex_token_string:
            if (level != OPTION_LEVEL_COMMAND_LINE)
            {
                if (strchr(arglex_value.alv_string, '='))
                {
                    fatal_intl
                    (
                        0,
                        i18n("may not assign variables in environment variable")
                    );
                }
                else
                {
                    fatal_intl
                    (
                        0,
                        i18n("may not name targets in environment variable")
                    );
                }
            }
            else
            {
                char            *cp;

                cp = strchr(arglex_value.alv_string, '=');
                if (!cp)
                {
                    s = str_from_c(arglex_value.alv_string);
                    string_list_append(&option.o_target, s);
                    str_free(s);
                }
                else
                {
                    s = str_from_c(arglex_value.alv_string);
                    string_list_append(&option.o_vardef, s);
                    str_free(s);
                }
            }
            break;

        case arglex_token_star:
            type = OPTION_STAR;
            goto normal_on;

        case arglex_token_star_not:
            type = OPTION_STAR;
            goto normal_off;

        case arglex_token_strip_dot:
            type = OPTION_STRIP_DOT;
            goto normal_on;

        case arglex_token_strip_dot_not:
            type = OPTION_STRIP_DOT;
            goto normal_off;

        case arglex_token_update:
            type = OPTION_UPDATE;
            goto normal_on;

        case arglex_token_update_not:
            type = OPTION_UPDATE;
            goto normal_off;

        case arglex_token_parallel:
            if (arglex() != arglex_token_number)
            {
                s = str_from_c("parallel_jobs=4");
                string_list_append(&option.o_vardef, s);
                str_free(s);
                continue;
            }
            s = str_format("parallel_jobs=%d", (int)arglex_value.alv_number);
            string_list_append(&option.o_vardef, s);
            str_free(s);
            break;

        case arglex_token_parallel_not:
            s = str_from_c("parallel_jobs=1");
            string_list_append(&option.o_vardef, s);
            str_free(s);
            break;

        case arglex_token_shallow:
            type = OPTION_SHALLOW;
            goto normal_on;

        case arglex_token_shallow_not:
            type = OPTION_SHALLOW;
            goto normal_off;
        }
        arglex();
    }
}