<commit_before>/* Example code for Exercises in C.

Modified version of an example from Chapter 2.5 of Head First C.

*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <regex.h>

#define NUM_TRACKS 5

char tracks[][80] = {
    "So What",
    "Freddie Freeloader",
    "Blue in Green",
    "All Blues",
    "Flamenco Sketches"
};


typedef struct {
    regex_t inner_struct[1];
} Regex;


/* Returns a new Regex that matches the given pattern.
 *
 * pattern: string regex
 * flags: flags passed to regcomp
 * returns: new Regex 
 */
Regex *make_regex(char *pattern, int flags) {
    // FILL THIS IN!
    return NULL;
}

/* Checks whether a regex matches a string.
 *
 * regex: Regex
 * s: string
 * returns: 1 if there's a match, 0 otherwise
 */
int regex_match(Regex *regex, char *s) {
    // FILL THIS IN!
    return 0;
}

/* Frees a Regex.
 *
 * regex: Regex
 */
void regex_free(Regex *regex) {
    // FILL THIS IN!
}


/* Finds all tracks that match the given pattern.
 *
 * Prints track number and title.
 */
void find_track_regex(char pattern[])
{
    int i;

    Regex *regex = make_regex(pattern, REG_EXTENDED | REG_NOSUB);

    for (i=0; i<NUM_TRACKS; i++) {
	if (regex_match(regex, tracks[i])) {
	    printf("Track %i: '%s'\n", i, tracks[i]);
	}
    }

    regex_free(regex);
}


int main (int argc, char *argv[])
{
    char *pattern = "F.*F.*";
    find_track_regex(pattern);

    return 0;
}<commit_msg>ADD: ex05 progress... still not finished... so sad<commit_after>/* Example code for Exercises in C.

Modified version of an example from Chapter 2.5 of Head First C.

*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <regex.h>

#define NUM_TRACKS 5

char tracks[][80] = {
    "So What",
    "Freddie Freeloader",
    "Blue in Green",
    "All Blues",
    "Flamenco Sketches"
};


typedef struct {
    regex_t inner_struct;
} Regex;


/* Returns a new Regex that matches the given pattern.
 *
 * pattern: string regex
 * flags: flags passed to regcomp
 * returns: new Regex 
 */
Regex *make_regex(char *pattern, int flags) {
    Regex *reg;
    regex_t *regex;

    if (regcomp(regex, pattern, flags)) {
        fprintf(stderr, "Could not compile regex\n");
        exit(1);
    }

    reg->inner_struct = *regex;
    return reg;
}

/* Checks whether a regex matches a string.
 *
 * regex: Regex
 * s: string
 * returns: 1 if there's a match, 0 otherwise
 */
int regex_match(Regex *regex, char *s) {
    // If match
    if (!regexec(&regex->inner_struct, s, 0, NULL, 0)) {
        return 1;
    }

    return 0;
}

/* Frees a Regex.
 *
 * regex: Regex
 */
void regex_free(Regex *regex) {
    free(regex);
}


/* Finds all tracks that match the given pattern.
 *
 * Prints track number and title.
 */
void find_track_regex(char pattern[])
{
    int i;

    Regex *regex = make_regex(pattern, REG_EXTENDED | REG_NOSUB);

    for (i=0; i<NUM_TRACKS; i++) {
	//if (regex_match(regex, tracks[i])) {
	    printf("Track %i: '%s'\n", i, tracks[i]);
	//}
    }

    regex_free(regex);
}


int main (int argc, char *argv[])
{
    char *pattern = "F.*F.*";
    find_track_regex(pattern);

    return 0;
}
{'fraction_non_alphanumeric': 0.14126984126984127, 'fraction_numerical': 0.008571428571428572, 'mean_word_length': 2.8853267570900125, 'pattern_counts': {'":': 0, '<': 13, '<?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': '5084003', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1116, 'n_words': 357}