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

#include "pmake.h"
#define deli " \t\n\r\f\v\\\0"
int is_comment_or_empty(const char *line) {
    for (int i = 0; i < strlen(line); i++){
        if (line[i] == '#') {
            return 1;
        }
        if (line[i] != '\t' && line[i] != ' ') {
            return 0;
        }
    }
    return 1;
}

int main() {
    char *filename = "Makefile";
    FILE *fp=fopen(filename, "r");
            int count;
	char *placeholder = malloc(sizeof(char)*MAXLINE);
        char *line = fgets(placeholder, MAXLINE, fp);
        int line_count=0;
        Rule *curr = malloc(sizeof(Rule));

        while (line != NULL){
        line = fgets(placeholder, MAXLINE, fp);
        line_count ++;
        }
        

        fseek(fp, 0, SEEK_SET); 

	int start = 0;
	Rule *temp = curr;
	int com_count=0; 

	char ***tab = malloc(sizeof(char**)*line_count); 
	line = fgets(placeholder, MAXLINE, fp);
        while (line != NULL){
        if (is_comment_or_empty(placeholder)){
                line = fgets(placeholder, MAXLINE, fp);
        continue;
        }
        
        else{
        
        char *target = malloc(sizeof(char*)*MAXLINE);
  
    	char *colon = strchr(placeholder, ':');
    	Action *acurr;
        if (colon != NULL){

        strncpy(target, placeholder, colon - line);
        target[colon-line-1] = '\0';

        curr->target=target;

       char *dep = malloc(sizeof(Dependency)*MAXLINE);
        strcpy(dep, colon + 2);
       char *tok = strtok(dep, deli);

        count = 0;
       char **str = malloc(sizeof(char*)*MAXLINE);
        while (tok != NULL){
        str[count] = tok;

        tok = strtok(NULL, deli);
        count += 1;
        
        }
        str[count] = NULL;
        tab[com_count] = str;
        colon = NULL;
        com_count++;
        }
     
        else{
        Action *acurr = malloc(sizeof(Action));
        Action *aprev;
        aprev = NULL;
        char *tok1 = strtok(placeholder, deli);
        int index = 0;
        int space_count = 0;
       
        for (int i = 1; i < MAXLINE; i++){
        if (placeholder[i-1] == ' ' && placeholder[i]!= ' '){
        space_count ++;
        }
        }
        
        char **args = malloc((space_count +1)* sizeof(char*));

         while (tok1 != NULL){
            args[index]= tok1;
            tok1 = strtok(NULL, deli);
            index ++;
       }
        args[index]=NULL;
        acurr->args=args;
        if (aprev != NULL){
        aprev->next_act= acurr;}
        acurr=NULL;

      
        }
        
        }
        
  

       line = fgets(placeholder, MAXLINE, fp);

       if (line==NULL){
       curr->next_rule = NULL;

       
       }
       else {
       curr->next_rule = malloc(sizeof(Rule));
       curr=curr->next_rule;
       }

       }

       printf("%s\n", temp->target);
   return 0;
}

there shouldn't be an abortion.