#include "matrixstruct.h"
#include "head.h"

int main(void){
    
    MATRIX2D** __matrixAddr = (MATRIX2D**)calloc(MAX_MATRIX_ALIVE,sizeof(MATRIX2D*));
    if(__matrixAddr == NULL) {printf("ERROR.__matrixAddr NotExist");return 1;}
    
    char mode;
    do{
        char inbuff;
        char _buff[BUFF_MAX];
        char n1,n2;
        int num1,num2;
        mode = buff_input(&inbuff,_buff);
        {
            switch(mode){
                case 1:
                    n1 = get_matrix_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    input_matrix(__matrixAddr,n1);
                    break;

                case 2:  // output
                    n1 = get_matrix_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    get_matrix(__matrixAddr,n1);

                    break;

                case 3:  // logic
                    n1 = get_matrix_num();
                    n2 = get_matrix_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    is_Matrix_Exist(__matrixAddr,n2);
                    logic_matrix(__matrixAddr,n1,n2);
                    break;

                case 4:  // edit
                    n1 = get_matrix_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    edit_matrix(__matrixAddr,n1);
                    break;

                case 5:  // random
                    n1 = get_matrix_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    matrix_random(__matrixAddr,n1);
                    break;

                case 6:  // copy
                    n1 = get_matrix_num();
                    n2 = get_matrix_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    free_matrix(__matrixAddr,n2);
                    copy_matrix(__matrixAddr,n1,n2);
                    break;

                case 7:  // destroy
                    n1 = get_matrix_num();
                    free_matrix(__matrixAddr,n1);
                    break;

                case 8:  // get colum
                    n1 = get_matrix_num();
                    num1 = get_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    get_matrix_col(__matrixAddr,n1,num1);
                    break;

                case 9:  // get row
                    n1 = get_matrix_num();
                    num1 = get_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    get_matrix_row(__matrixAddr,n1,num1);
                    break;

                case 10: // transp
                    n1 = get_matrix_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    transp_matrix(__matrixAddr,n1);
                    break;

                case 11: // determ
                    n1 = get_matrix_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    printf("%lld",determ_matrix(__matrixAddr,n1));
                    
                    break;

                case 12: //obr
                    n1 = get_matrix_num();
                    is_Matrix_Exist(__matrixAddr,n1);
                    obr_matrix(__matrixAddr,n1);
                    break;
 
                case 13:
                    n1 = get_matrix_num();
                    num1 = get_num();
                    num2 = get_num();
                    free_matrix(__matrixAddr,n1);
                    create_matrix(__matrixAddr,n1,num1,num2);
                    break;
                       
                case 15:
                    putchar('\n');
                    putchar('\n');
                    break;

                case 0:  // wrong input
                    break;
 
                case -1: return 0;
                }
        }
    }while(mode>=0);

    return 0;
}
