示例#1
0
int	get_map_value(void)
{
	int		rslt;
	int		i;
	int		j;

	rslt = 0;
	i = -1;
	while (++i < get_map()->height)
	{
		j = -1;
		while (++j < get_map()->width)
		{
			rslt += get_cell_value(i, j);
		}
	}
	return (rslt);
}
示例#2
0
TEST(GET_CELL_VALUE,NOTZERO)
{
	ASSERT_EQ(-1,get_cell_value("C:\\Users\\l00219108\\Documents\\Visual Studio 2010\\Projects\\csvapi\\Debug\\test.csv", 2, 4, value));
}
示例#3
0
TEST(GET_CELL_VALUE,VALUE)
{
	ASSERT_EQ(0,set_cell_value("C:\\Users\\l00219108\\Documents\\Visual Studio 2010\\Projects\\csvapi\\Debug\\test.csv", 1, 2, "abc"));
	ASSERT_EQ(0,get_cell_value("C:\\Users\\l00219108\\Documents\\Visual Studio 2010\\Projects\\csvapi\\Debug\\test.csv", 1, 2, value));
	EXPECT_STREQ("abc",value);
}
示例#4
0
int main(int argc, char **argv)
{
    Operation operation; // operacie na vstupe, napr. select, min, max ...
    RangeFunction range_function; // range funkcia na vstupe, napr. row, col, ...
    int row_y0, row_y1, col_x0, col_x1 = -1; // pomocne premenne pre vyberove funkcie
    double double_tmp; // pomocna premenna pre typ double
    char word[MAX_LENGTH]; // obsah bunky
    int act_row = 1; // riadok, na ktorom sa momentalne nechadzam
    int act_col = 1; // stlpec, na ktorom sa momentalne nechadzam

    double result = 0.0; // priebezny a celkovy vysledok matematickych funkcii
    int count = 0; // pocet spracovanych cisel v matematickych funkciach
    int cell_in_area = FALSE; // kontrola ci sa nachadzam v zadanej oblasti


    if((strcmp("--help", argv[1]) == 0))  /* Ak je zadany parameter -- help tak vypise napovedu */
    {
    printf("%s", HELPMSG);
    return EXIT_SUCCESS;
    }
    /* Spracovanie vstupnych parametrov */
    if(argc == 1)
    {
        fprintf(stderr,"Nebol zadany ziadny argument, pre napovedu spustite program v tvare ./proj1 -- help\n"); // ak uzivatel nezada ziadny parameter tak mu vypise hlasenie
        return EXIT_FAILURE;
    }

    if (argc > 7)
      fprintf(stderr,"CHYBA zadal si prilis mnoho argumentov \n");

       // Operacia select, min, max ...
    if(get_operation(argv[1], &operation) == EXIT_FAILURE){
         fprintf(stderr,"ERROR, pre napovedu spustite program v tvare ./proj1 -- help\n");
        return EXIT_FAILURE;
    }
    if(argc < 2 + operation.required_parameters)
    {
        fprintf(stderr,"ERROR: Malo paramterov pre operaciu \n");
        return EXIT_FAILURE;
    }

    // Rozsah/vyber, napr. row, rows, col, ...
    if(get_range(argv[2], &range_function) == EXIT_FAILURE){
        fprintf(stderr,"ERROR \n");
        return EXIT_FAILURE;
    }


    if(argc < 3 + range_function.required_parameters)
    {
        printf("ERROR: Malo argumentov pre vyberovu funkciu \n");
        return EXIT_FAILURE;
    }
    /* Osetrenie vyberovych funkcii.
     Ak je pre vyberovu funkciu pozuitych vela argumentov, zoberiem prvy a ostatne ignorujem (napr.: `row 4 5', do row pojde 4 a 5 ignorujem). */
    switch(range_function.function)
    {
        case row:
            if(is_number(argv[3], &double_tmp) && (int) double_tmp > 0)
            {
                row_y0 = (int) double_tmp;
                row_y1 = row_y0;
                col_x0 = -1;
                col_x1 = -1;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            break;
        case col:
            if(is_number(argv[3], &double_tmp) && (int) double_tmp > 0)
            {
                row_y0 = -1;
                row_y1 = -1;
                col_x0 = (int) double_tmp;
                col_x1 = col_x0;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            break;
        case rows:
            col_x0 = -1;
            col_x1 = -1;
            if(is_number(argv[3], &double_tmp) && (int) double_tmp > 0)
            {
                row_y0 = (int) double_tmp;
            }
            else
            {
               fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            if(is_number(argv[4], &double_tmp) && (int) double_tmp > 0)
            {
                row_y1 = (int) double_tmp;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            break;
        case cols:
            row_y0 = -1;
            row_y1 = -1;
            if(is_number(argv[3], &double_tmp) && (int) double_tmp > 0)
            {
                col_x0 = (int) double_tmp;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            if(is_number(argv[4], &double_tmp) && (int) double_tmp > 0)
            {
                col_x1 = (int) double_tmp;
            }
            else
            {
               fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            break;
        case range:
            if(is_number(argv[3], &double_tmp) && (int) double_tmp > 0)
            {
                row_y0 = (int) double_tmp;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            if(is_number(argv[4], &double_tmp) && (int) double_tmp > 0)
            {
                row_y1 = (int) double_tmp;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            if(is_number(argv[5], &double_tmp) && (int) double_tmp > 0)
            {
                col_x0 = (int) double_tmp;
            }
            else
            {
               fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
               return EXIT_FAILURE;
            }
            if(is_number(argv[6], &double_tmp) && (int) double_tmp > 0)
            {
                col_x1 = (int) double_tmp;
            }
            else
            {
                fprintf(stderr,"ERROR: Argumenty vyberovych funkcii musia byt kladne cele cisla okrem nuly!\n");
                return EXIT_FAILURE;
            }
            break;
        default:
            fprintf(stderr,"ERROR neznama akcias\n");
            return EXIT_FAILURE;
    }

    // Kontrola, ci su hranice rozsahov vyberovych funkcii OK
    if(row_y1 < row_y0)
    {
        fprintf(stderr,"ERROR:Index riadka Y musi byt vacsi ako index riadka X.\n");
        return EXIT_FAILURE;
    }
    
    if(col_x1 < col_x0)
    {
        fprintf(stderr,"ERROR:Index stlpca B musi byt vacsi ako index stlpca A.\n");
        return EXIT_FAILURE;
    }

    /* Spracovanie stdin.  Najprv zistim,ci sa bunka nachadza v pozadovanej oblasti a nasledne si nacitam jej obsah. 
     Citam bunku aj ked sa nenachadza v pozadovanej oblasti */
    while((cell_in_area = in_range(act_row, act_col, row_y0, row_y1, col_x0, col_x1), 
                get_cell_value(word, &act_row, &act_col) != EXIT_FAILURE))
    {
        if(cell_in_area) // ak sa bunka nachadza v pozadovanej oblasti, pokracujem v spracovani.
        {
            switch(operation.function)
            {
                case select:
                    if(operation_select(word) == EXIT_SUCCESS)
                        printf("\n"); 
                    else
                        return EXIT_FAILURE;
                    break;

                case min:
                    count++;
                    if(operation_min(word, &result, count) == EXIT_FAILURE)
                        return EXIT_FAILURE;
                    break;

                case max:
                    count++;
                    if(operation_max(word, &result, count) == EXIT_FAILURE)
                        return EXIT_FAILURE;
                    break;

                case sum:
                    if(operation_sum(word, &result) == EXIT_FAILURE)
                        return EXIT_FAILURE;
                    break;

                case avg:
                    count++;
                    if(operation_sum(word, &result) == EXIT_FAILURE)
                       return EXIT_FAILURE;
                    break;

                default:
                   fprintf(stderr,"ERROR:Neznama operacia\n");
                   return EXIT_FAILURE;
           }
        }

        // Ak dosiahnem hornu hranicu riadkov, koncim spracovanie.
        if(row_y1 != -1 && row_y1 < act_row){
            break;
        }
    }
    // Osetrenie vynimok pri vypise vysledku.
    switch(operation.function)
    {
        case select:
            // Nerobim nic, len aby som sa nedostal do default
            break;

        case avg:
            result /= (double) count;

        default:
            printf("%.10g", result);
            printf("\n");
    }
    return EXIT_SUCCESS;
}