コード例 #1
0
ファイル: pathman.cpp プロジェクト: xaberus/nih
  Error PathMan::read_dir(const char * path) {
    uint32_t len = strlen(path);
    char word[len+1];
    memcpy(word, path, len);
    word[len ] = 0;
    char * ppath[] = {word, 0};

    LookUp lu = lookup("/"), flu;

    if (lu.err)
      return lu.err;

    FTSENT *node;
    FTS *tree = fts_open(ppath, FTS_NOCHDIR, 0);

    if (!tree)
      return FAILURE;

    {
      size_t len;
      while ((node = fts_read(tree))) {
        char word[node->fts_pathlen + 3];

        if (node->fts_info & FTS_F) {
          mkword(node, word, len);
          flu = add_file(word, 0);

          if (flu.err)
            goto fout;

          flu.file->offset = 0;
          flu.file->size = node->fts_statp->st_size;
        } else if (node->fts_info & FTS_D) {
          mkword(node, word, len);
          if (len > 1) {
            if (word[len - 1] != '/') {
              word[len++] = '/';
            }
            word[len] = 0;

            lu = add_dir(word, 0);

            if (lu.err)
              goto dout;
          }
        }
      }
      fts_close(tree);
    }

    return SUCCESS;
  fout:
    fts_close(tree);
    return flu.err;
  dout:
    fts_close(tree);
    return lu.err;
  }
コード例 #2
0
ファイル: mic_driver.c プロジェクト: jwq2011/iFly-mic_driver
int VCSetDACVolume(Command_t * command, cmd_dac_gain_id dac_gain_id)
{
	int ret_val, mem_info;

	reset_time_out();
	mem_info = dac_gain_id;
	command->data[0] = 0;
	command->data[1] = 0;
	command->data[2] = 1;
	command->data[3] = mkword(0x34, mem_info);
	ret_val = send_cmd(command, APP_ID_CTRL, CMD_SET(CONTROL_APP_I2C_TUNNEL_DATA), 4);
	if (ret_val<0)
	{
		return ret_val; /* err code*/
	}
	command->data[0] = 0;
	ret_val = send_cmd(command, APP_ID_CTRL, CONTROL_APP_I2C_TUNNEL_APPLY, 1);
	if (ret_val<0)
	{
		return ret_val; /* err code*/
	}

	mem_info |= 0x100;
	command->data[0] = 0;
	command->data[1] = 0;
	command->data[2] = 1;
	command->data[3] = mkword(0x35, mem_info);
	ret_val = send_cmd(command, APP_ID_CTRL, CMD_SET(CONTROL_APP_I2C_TUNNEL_DATA), 4);
	if (ret_val<0)
	{
		return ret_val; /* err code*/
	}
	command->data[0] = 0;
	ret_val = send_cmd(command, APP_ID_CTRL, CONTROL_APP_I2C_TUNNEL_APPLY, 1);
	if (ret_val<0)
	{
		return ret_val; /* err code*/
	}
	return(0);
}
コード例 #3
0
ファイル: main.c プロジェクト: sa-spag/acc
int main(int argc, char *const *argv) {
    FILE *data = NULL;
    struct parameters p;
    char o, *tok, tmp[256];
    word_t word;
    struct d_entry *d_entry;

    p.delimiters = NULL;
    STAILQ_INIT(&p.dictionary);

    // Initialisation des parametres
    while((o = getopt (argc, argv, "a:A:d:D:w:W:hHvV")) != -1)
        switch(o) {
            case 'w':
            case 'W':
                tok = strtok(optarg, " ");
                do {
                    if((d_entry = (struct d_entry *) malloc(sizeof(struct d_entry))))
                        if((d_entry->string = (char *) calloc((strlen(tok) + 1), sizeof(char)))) {
                            strcpy(d_entry->string, tok);
                            STAILQ_INSERT_TAIL(&p.dictionary, d_entry, entries);
                        }
                        else {
                            fprintf(
                                stderr,
                                "%s: Unable to create a dictionary entry for the word \"%s\": %s\n",
                                *argv, tok, strerror(errno)
                            );
                            free(d_entry);
                        }
                    else
                        fprintf(
                            stderr,
                            "%s: Unable to create a dictionary entry for the word \"%s\": %s\n",
                            *argv, tok, strerror(errno)
                        );
                } while((tok = strtok(NULL, " ")));
                break;
            case 'd':
            case 'D':
                p.delimiters = optarg;
                break;
            case 'h':
            case 'H':
                switch(system("cat help.txt")) {
                    case 1:
                        fprintf(stderr, "%s: \"help.txt\" does not exist", *argv);
                    case -1:
                        return EXIT_FAILURE;
                    default:
                        return EXIT_SUCCESS;
                        break;
                }
                break;
            case 'v':
            case 'V':
                verbose = true;
                break;
            case '?':
            default:
                fprintf(stderr, "Usage: %s %s\n", *argv, USAGE);
                return EXIT_FAILURE;
                break;
        }

    // Chargement des dictionnaires
    while(optind < argc - 1) {
        if(!(data = fopen(argv[optind], "r")))
            fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
        else {
            addWords(data, &p.dictionary);
        }
        fclose(data);
        optind++;
    }

    if(optind >= argc) {
        fprintf(stderr, "Usage: %s %s\n", *argv, USAGE);
        return EXIT_FAILURE;
    }

    // Chargement de l'automate
    if(!(data = fopen(argv[optind], "r"))) {
        fprintf(stderr, "%s: %s: %s\n", *argv, argv[optind], strerror(errno));
        return EXIT_FAILURE;
    }
    if(!parse(data, &(p.fsm))) {
        fprintf(stderr, "%s: Unable to parse the automaton file\n", *argv);
        fclose(data);
        return EXIT_FAILURE;
    }
    fclose(data);

    // Lecture de mots sur l'entree standard
    if(STAILQ_EMPTY(&p.dictionary)) {
        while(printf("> "), scanf("%255[^\n]s\n", tmp)) {
            word = mkword(tmp, p.delimiters);
            printf("%s - %srecognized by the automaton\n", tmp, recognize(&p.fsm, word) ? "" : "un");
            wfree(word);
            getchar();
        }
    }

    // Lecture du dictionnaire
    while((d_entry = STAILQ_FIRST(&p.dictionary))) {
        word = mkword(d_entry->string, p.delimiters);
        printf("%s - %srecognized by the automaton\n", d_entry->string, recognize(&p.fsm, word) ? "" : "un");
        wfree(word);
        STAILQ_REMOVE_HEAD(&p.dictionary, entries);
        free(d_entry->string);
        free(d_entry);
    }

    freeFsm(&(p.fsm));
    return EXIT_SUCCESS;
}