/*
 * Soubor:  20110318-Fri-odkaz-na-fce.c
 * Datum:   18.03.2011 10:03
 * Autor:   Marek Nožka, nozka <@t> spseol <d.t> cz
 * Licence: GNU/GPL 
 * Úloha: 
 * Popis:   
 ****************************************************/
#define _ISOC99_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

/* ***************    Makra    ******************** */
#define ARREYC 1024

/* ***************   Funkce    ******************** */

double deg2rad(double deg)
{
    return deg*M_PI/180;
}

double rad2rad(double rad)
{
    return rad;
}

double cotg(double rad) 
{
    return 1/tan(rad);
}

/****************************************************
 *               Hlavní program.
 ****************************************************/
int main(int argc, char *argv[])
{

    /* f_convert je odkaz na funkci, která přebírá double a vrací double */
    double (*f_convert)(double);    
    double (*f_gonio)(double);
    char line[ARREYC];
    double number, from, to, step;
    char choice[ARREYC];
    
    f_convert = deg2rad; 

    while ( printf(" >>> "), fgets(line, ARREYC, stdin) != NULL ) {
        if ( sscanf(line, "%s %lg %lg %lg", choice, &from, &to, &step) == 4 ) {
            ;
        } else if ( sscanf(line, "%s %lg", choice, &number) == 2 ) {
            if ( choice[0] == 's' ) 
                f_gonio = sin;
            else if ( choice[0] == 'c')
                f_gonio = cos;
            else if ( choice[0] == 't')
                f_gonio = tan;
            else if ( choice[0] == 'o')
                f_gonio = cotg;
            printf("%7.3F\n",f_gonio( f_convert(number) ));
        } else if ( sscanf(line, "%s", choice ) == 1 ) {
            if ( choice[0] == 'd') {
                f_convert = deg2rad; 
            } else if ( strcmp(choice, "r") == 0 ) {
                f_convert = rad2rad; 
            } else {
                fprintf(stderr,"neplatný vstup\n");
            }
        }
    }


    return 0;
}

