<commit_before>#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#include "pickopt.c"

void print_help(char *bin_name)
{
    fprintf(stderr, "usage:\n\t %s binary_ply [--strip-normals] "
            "[--strip-colors] [--strip-header] > ascii_ply\n", bin_name);
}

// fast forward "f" until "lin" is found. "lin" is read.
static int eat_until_this_line(FILE *f, char *lin)
{
    int out = 0;
    char buf[FILENAME_MAX] = {0};
    while (fgets(buf, FILENAME_MAX, f)) {
        out++;
        if (0 == strcmp(buf, lin))
            break;
    }
    return out;
}

// prints "f" on stdout until "lin" is found. Does not print "lin".
static int print_until_this_line(FILE *f, char *lin)
{
    int out = 0;
    char buf[FILENAME_MAX] = {0};
    while (fgets(buf, FILENAME_MAX, f)) {
        out++;
        if (0 == strcmp(buf, lin))
            break;
        else
            printf("%s", buf);
    }
    return out;
}

int main(int c, char *v[])
{
    if (c != 2 && c != 3 && c != 4 && c != 5) {
        print_help(*v);
        return 1;
    }

	bool strip_n = (pick_option(&c, &v, "-strip-normals", NULL) != NULL);
	bool strip_c = (pick_option(&c, &v, "-strip-colors", NULL) != NULL);
	bool strip_h = (pick_option(&c, &v, "-strip-header", NULL) != NULL);

    // read args
    const char *filename = v[1];

    // open the input binary file
    FILE *f = fopen(filename, "rb");

    int nb_lines = 0;
    if (strip_h) {
        eat_until_this_line(f, "format binary_little_endian 1.0\n");
        nb_lines = eat_until_this_line(f, "end_header\n");
    } else {
        // copy the header, replace the 'format' line, and remove the line about
        // normals if needed
        print_until_this_line(f, "format binary_little_endian 1.0\n");
        printf("format ascii 1.0\n");
        if (strip_n) {
            print_until_this_line(f, "property float nx\n");
            eat_until_this_line(f, "property float nz\n");
        }
        nb_lines = print_until_this_line(f, "end_header\n");
        printf("end_header\n");
    }
    bool normals = strip_n | (nb_lines > 10) ;

    // then read the binary body of the file
    // each 'line' contains a position X = (x, y, z), eventually a normal N =
    // (nx, ny, nz) and color C = (r, g, b)
    float X[3];
    float N[3];
    unsigned char C[3];

    while (!feof(f)) {
        fread(X, sizeof(float), 3, f);
        if (normals)
            fread(N, sizeof(float), 3, f);
        fread(C, sizeof(unsigned char), 3, f);
        printf("%.10f %.10f %.10f", X[0], X[1], X[2]);
        if (normals & !strip_n)
            printf(" %.1f %.1f %.1f", N[0], N[1], N[2]);
        if (!strip_c)
            printf(" %d %d %d\n", C[0], C[1], C[2]);
        else
            printf("\n");
    }

    fclose(f);
    return 0;
}<commit_msg>fixed bin2asc warnings<commit_after>#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#include "pickopt.c"

void print_help(char *bin_name)
{
    fprintf(stderr, "usage:\n\t %s binary_ply [--strip-normals] "
            "[--strip-colors] [--strip-header] > ascii_ply\n", bin_name);
}

// fast forward "f" until "lin" is found. "lin" is read.
static int eat_until_this_line(FILE *f, char *lin)
{
    int out = 0;
    char buf[FILENAME_MAX] = {0};
    while (fgets(buf, FILENAME_MAX, f)) {
        out++;
        if (0 == strcmp(buf, lin))
            break;
    }
    return out;
}

// prints "f" on stdout until "lin" is found. Does not print "lin".
static int print_until_this_line(FILE *f, char *lin)
{
    int out = 0;
    char buf[FILENAME_MAX] = {0};
    while (fgets(buf, FILENAME_MAX, f)) {
        out++;
        if (0 == strcmp(buf, lin))
            break;
        else
            printf("%s", buf);
    }
    return out;
}

int main(int c, char *v[])
{
    if (c != 2 && c != 3 && c != 4 && c != 5) {
        print_help(*v);
        return 1;
    }

	bool strip_n = (pick_option(&c, &v, "-strip-normals", NULL) != NULL);
	bool strip_c = (pick_option(&c, &v, "-strip-colors", NULL) != NULL);
	bool strip_h = (pick_option(&c, &v, "-strip-header", NULL) != NULL);

    // read args
    const char *filename = v[1];

    // open the input binary file
    FILE *f = fopen(filename, "rb");

    int nb_lines = 0;
    if (strip_h) {
        eat_until_this_line(f, "format binary_little_endian 1.0\n");
        nb_lines = eat_until_this_line(f, "end_header\n");
    } else {
        // copy the header, replace the 'format' line, and remove the line about
        // normals if needed
        print_until_this_line(f, "format binary_little_endian 1.0\n");
        printf("format ascii 1.0\n");
        if (strip_n) {
            print_until_this_line(f, "property float nx\n");
            eat_until_this_line(f, "property float nz\n");
        }
        nb_lines = print_until_this_line(f, "end_header\n");
        printf("end_header\n");
    }
    bool normals = strip_n | (nb_lines > 10) ;

    // then read the binary body of the file
    // each 'line' contains a position X = (x, y, z), eventually a normal N =
    // (nx, ny, nz) and color C = (r, g, b)
    size_t n;
    float X[3];
    float N[3];
    unsigned char C[3];

    while (!feof(f)) {
        n = fread(X, sizeof(float), 3, f);
        if (normals)
            n = fread(N, sizeof(float), 3, f);
        n = fread(C, sizeof(unsigned char), 3, f);
        printf("%.10f %.10f %.10f", X[0], X[1], X[2]);
        if (normals & !strip_n)
            printf(" %.1f %.1f %.1f", N[0], N[1], N[2]);
        if (!strip_c)
            printf(" %d %d %d\n", C[0], C[1], C[2]);
        else
            printf("\n");
    }

    fclose(f);
    return 0;
}
{'fraction_non_alphanumeric': 0.17013703505961916, 'fraction_numerical': 0.016550987720234916, 'mean_word_length': 2.2169433314253006, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4169992', 'n_tokens_mistral': 2150, 'n_tokens_neox': 2070, 'n_words': 575}