<commit_before>#include "calc.h"

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

int calc(const char* p, int mul_div_flag)
{
    int i;
    int ans;

    ans = atoi(p);
    i = 0;
    while (p[i] != '\0'){
        while (isdigit(p[i])){
            i++;
        }
        switch (p[i]){
            case '+':
                return (ans + calc(p + i + 1, 0));
            case '-':
                return (ans - calc(p + i + 1, 0));
            case '*':
                ans *= calc(p + i + 1, 1);
                if (p[i + 1] == '('){
                    while (p[i] != ')'){
                        i++;
                    }
                }
                else {
                    i++;
                }
                break;
            case '/':
                ans /= calc(p + i + 1, 1);
                if (p[i + 1] == '('){
                    while (p[i] != ')'){
                        i++;
                    }
                }
                else {
                    i++;
                }
                break;
            case '(':
                return (calc(p + i + 1, 0));
            case ')':
            case '\0':
                return (ans);
            default:
                puts("Error");
                return (0);
        }
    }

    return (ans);
}<commit_msg>Fix () infinite loop<commit_after>#include "calc.h"

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

int calc(const char* p, int mul_div_flag)
{
    int i;
    int ans;

    ans = atoi(p);
    i = 0;
    while (p[i] != '\0'){
        while (isdigit(p[i])){
            i++;
        }
        switch (p[i]){
            case '+':
                return (ans + calc(p + i + 1, 0));
            case '-':
                return (ans - calc(p + i + 1, 0));
            case '*':
                ans *= calc(p + i + 1, 1);
                if (p[i + 1] == '('){
                    while (p[i] != ')'){
                        i++;
                    }
                }
                i++;
                break;
            case '/':
                ans /= calc(p + i + 1, 1);
                if (p[i + 1] == '('){
                    while (p[i] != ')'){
                        i++;
                    }
                }
                i++;
                break;
            case '(':
                return (calc(p + i + 1, 0));
            case ')':
            case '\0':
                return (ans);
            default:
                puts("Error");
                return (0);
        }
    }

    return (ans);
}
{'fraction_non_alphanumeric': 0.16360078277886497, 'fraction_numerical': 0.012524461839530333, 'mean_word_length': 0.7340569877883311, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '147521', 'n_tokens_mistral': 830, 'n_tokens_neox': 742, 'n_words': 182}