<commit_before>#!/bin/env bash

# A script to expand #PRINTSTR macro in C0 program.
# This script expand #PRINTSTR to calls to `put1()`s and
# print the processed source code to STDOUT

# example.c
# #include "stdio.h"
#
# void main()
# {
#     #PRINTSTR hello world!
#     wrln();
#     commit;
# }

# after processing by ./strsplitter.bash example.c:
# #include "stdio.h"
#
# void main()
# {
# put1('h');put1('e');put1('l');put1('l');put1('o');put1(' ');put1('w');put1('o');put1('r');put1('l');put1('d');put1('!');
#     wrln();
#     commit;
# }


if [ $# -lt 1 ]; then
    echo "Usage: $0 file"
    exit 1
fi

file=$1

# keep spaces
OLD_IFS="$IFS"
IFS=

while read line; do
    nospace=`echo "$line" | sed 's/^ *//'`
    if [ "${nospace:0:9}" == "#PRINTSTR" ]; then
        str=${nospace:10}
        for (( i=0; i<${#str}; i++ )); do
            echo -n "put1('${str:$i:1}');"
        done
        echo ""
    elif [ "${nospace:0:8}" == "#PRINTLN" ]; then
        str=${nospace:9}
        for (( i=0; i<${#str}; i++ )); do
            echo -n "put1('${str:$i:1}');"
        done
        echo "wrln();"
    else
        echo "$line"
    fi
done <$file<commit_msg>strsplitter.bash also support PRINTLN("str") style special functions to cooperate preprocessors<commit_after>#!/bin/env bash

# A script to expand #PRINTSTR macro in C0 program.
# This script expand #PRINTSTR to calls to `put1()`s and
# print the processed source code to STDOUT

# example.c
# #include "stdio.h"
#
# void main()
# {
#     PRINTLN("hello world!")
#     commit;
# }

# after processing by ./strsplitter.bash example.c:
# #include "stdio.h"
#
# void main()
# {
# put1('h');put1('e');put1('l');put1('l');put1('o');put1(' ');put1('w');put1('o');put1('r');put1('l');put1('d');put1('!');wrln();
#     commit;
# }


if [ $# -lt 1 ]; then
    echo "Usage: $0 file"
    exit 1
fi

file=$1

# keep spaces
OLD_IFS="$IFS"
IFS=

while read line; do
    nospace=`echo "$line" | sed 's/^ *//'`
    if [ "${nospace:0:9}" == "#PRINTSTR" ]; then
        str=${nospace:10}
        for (( i=0; i<${#str}; i++ )); do
            echo -n "put1('${str:$i:1}');"
        done
        echo ""
    elif [ "${nospace:0:8}" == "#PRINTLN" ]; then
        str=${nospace:9}
        for (( i=0; i<${#str}; i++ )); do
            echo -n "put1('${str:$i:1}');"
        done
        echo "wrln();"
    elif [ "${nospace:0:9}" == "PRINTSTR(" ]; then
        str=${nospace:10}
        for (( i=0; i<${#str}-3; i++ )); do
            echo -n "put1('${str:$i:1}');"
        done
        echo ""
    elif [ "${nospace:0:8}" == "PRINTLN(" ]; then
        str=${nospace:9}
        for (( i=0; i<${#str}-3; i++ )); do
            echo -n "put1('${str:$i:1}');"
        done
        echo "wrln();"
    else
        echo "$line"
    fi
done <$file
{'fraction_non_alphanumeric': 0.2341113105924596, 'fraction_numerical': 0.027648114901256734, 'mean_word_length': 2.571794871794872, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, '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': '7622270', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1080, 'n_words': 258}