second_pass.c
void second_pass(fileInformation *file_info){
    file_info->line_num = 0;
    while(!feof(file_info->file)){
        bool there_is_label;
        data_or_string_or_ext_or_ent status; /*gets what kind of label it is */
        before_and_after *before_and_after_struct;/*struct to be used with the splitLine function */
        memset(file_info->line_content, '\0',LINE_LENGTH);
        fgets(file_info->line_content,LINE_LENGTH,file_info->file );
        before_and_after_struct = malloc(sizeof(before_and_after));
        file_info->line_num+=1;/*after validating line size were increasing the line counter */

        strcpy(file_info->line_content,trim(file_info->line_content));
        if(*file_info->line_content == '\0'|| *file_info->line_content == ';')
            continue;
        /*value will hold if there is label */
        there_is_label = return_if_label_exist_on_the_first_place(file_info->line_content,before_and_after_struct);

        if(there_is_label){
        strcpy(file_info->line_content,trim(before_and_after_struct->after));

        }

        strcpy(file_info->line_content,trim(file_info->line_content));
        /*checking if there is instruction command */
        status = return_data_or_string_or_ext_or_ent(file_info->line_content, before_and_after_struct, file_info);
        /*getting rid of white spaces */
        strcpy(before_and_after_struct->before,trim(before_and_after_struct->before));
        strcpy(before_and_after_struct->after,trim(before_and_after_struct->after));

        /*data and string has been dealt in the first pass */
        if(status == DOT_DATA || status == DOT_STRING)
            continue;
    /*if were dealing with extern we will update the value in all the places that the label has been used */
        else if(status == DOT_EXTERN) {
            int address;
            address = return_address_by_label(file_info,before_and_after_struct->after);
            update_extern_name(file_info->code_head,address,before_and_after_struct->after);
        }

        else if(status == DOT_ENTRY){
            if(update_entry(file_info->symbol_head,before_and_after_struct->after,file_info)== FALSE){
                printf("Symbol is not defined on line %d\n",file_info->line_num);
                file_info->status = TRUE;
                continue;
            }

            if(update_entry(file_info->symbol_head,before_and_after_struct->after, file_info) == FALSE) {
                file_info->status = TRUE;
                continue;
            }
        }
        else
            handle_inst_second_pass(file_info, before_and_after_struct);
    }
}
/**
 * handeling the second pass of the assembler program
 * @param file_info struct to hold all the needed data to handle the input file
 */
handeling the second pass of the assembler program
@param file_info struct to hold all the needed data to handle the input file
handeling the second pass of the assembler program @param file_info struct to hold all the needed data to handle the input file
void second_pass(fileInformation *file_info){
    file_info->line_num = 0;
    while(!feof(file_info->file)){
        bool there_is_label;
        data_or_string_or_ext_or_ent status; 
        before_and_after *before_and_after_struct;
        memset(file_info->line_content, '\0',LINE_LENGTH);
        fgets(file_info->line_content,LINE_LENGTH,file_info->file );
        before_and_after_struct = malloc(sizeof(before_and_after));
        file_info->line_num+=1;
        strcpy(file_info->line_content,trim(file_info->line_content));
        if(*file_info->line_content == '\0'|| *file_info->line_content == ';')
            continue;
        there_is_label = return_if_label_exist_on_the_first_place(file_info->line_content,before_and_after_struct);
        if(there_is_label){
        strcpy(file_info->line_content,trim(before_and_after_struct->after));
        }
        strcpy(file_info->line_content,trim(file_info->line_content));
        status = return_data_or_string_or_ext_or_ent(file_info->line_content, before_and_after_struct, file_info);
        strcpy(before_and_after_struct->before,trim(before_and_after_struct->before));
        strcpy(before_and_after_struct->after,trim(before_and_after_struct->after));
        if(status == DOT_DATA || status == DOT_STRING)
            continue;
        else if(status == DOT_EXTERN) {
            int address;
            address = return_address_by_label(file_info,before_and_after_struct->after);
            update_extern_name(file_info->code_head,address,before_and_after_struct->after);
        }
        else if(status == DOT_ENTRY){
            if(update_entry(file_info->symbol_head,before_and_after_struct->after,file_info)== FALSE){
                printf("Symbol is not defined on line %d\n",file_info->line_num);
                file_info->status = TRUE;
                continue;
            }
            if(update_entry(file_info->symbol_head,before_and_after_struct->after, file_info) == FALSE) {
                file_info->status = TRUE;
                continue;
            }
        }
        else
            handle_inst_second_pass(file_info, before_and_after_struct);
    }
}
void second_pass ( fileInformation * file_info ) { file_info -> line_num = 0 ; while ( ! feof ( file_info -> file ) ) { bool there_is_label ; data_or_string_or_ext_or_ent status ; before_and_after * before_and_after_struct ; memset ( file_info -> line_content , ' \0 ' , LINE_LENGTH ) ; fgets ( file_info -> line_content , LINE_LENGTH , file_info -> file ) ; before_and_after_struct = malloc ( sizeof ( before_and_after ) ) ; file_info -> line_num += 1 ; strcpy ( file_info -> line_content , trim ( file_info -> line_content ) ) ; if ( * file_info -> line_content == ' \0 ' || * file_info -> line_content == ' ' ) continue ; there_is_label = return_if_label_exist_on_the_first_place ( file_info -> line_content , before_and_after_struct ) ; if ( there_is_label ) { strcpy ( file_info -> line_content , trim ( before_and_after_struct -> after ) ) ; } strcpy ( file_info -> line_content , trim ( file_info -> line_content ) ) ; status = return_data_or_string_or_ext_or_ent ( file_info -> line_content , before_and_after_struct , file_info ) ; strcpy ( before_and_after_struct -> before , trim ( before_and_after_struct -> before ) ) ; strcpy ( before_and_after_struct -> after , trim ( before_and_after_struct -> after ) ) ; if ( status == DOT_DATA || status == DOT_STRING ) continue ; else if ( status == DOT_EXTERN ) { int address ; address = return_address_by_label ( file_info , before_and_after_struct -> after ) ; update_extern_name ( file_info -> code_head , address , before_and_after_struct -> after ) ; } else if ( status == DOT_ENTRY ) { if ( update_entry ( file_info -> symbol_head , before_and_after_struct -> after , file_info ) == FALSE ) { printf ( " \n " , file_info -> line_num ) ; file_info -> status = TRUE ; continue ; } if ( update_entry ( file_info -> symbol_head , before_and_after_struct -> after , file_info ) == FALSE ) { file_info -> status = TRUE ; continue ; } } else handle_inst_second_pass ( file_info , before_and_after_struct ) ; } }
handeling the second pass of the assembler program
 @param file_info struct to hold all the needed data to handle the input file
handeling the second pass of the assembler program @param file_info struct to hold all the needed data to handle the input file
/*gets what kind of label it is */ /*struct to be used with the splitLine function */ /*after validating line size were increasing the line counter */ /*value will hold if there is label */ /*checking if there is instruction command */ /*getting rid of white spaces */ /*data and string has been dealt in the first pass */ /*if were dealing with extern we will update the value in all the places that the label has been used */