Exemplo n.º 1
0
/**
 * Menu principal do programa, no qual o usuário pode escolher a operação a ser realizada
 * @param db:	ponteiro para database
 * @return: 	0 caso o usuário deseja sair do programa
				1 caso contrário	
*/
int menu_principal(database_t *db){
	char opcao;

	titulo("_");

	//Opções do menu
	#ifdef MENU_IU
		printf("1. Inserir usuário\n");
		printf("2. Remover usuário\n");
		printf("3. Pesquisar usuário\n");
		printf("4. Buscar gostos musicais semelhantes\n");
		printf("5. Buscar usuários mais jovens\n");
		printf("6. Buscar gêneros mais populares\n");
		printf("7. Buscar usuários por idade e gênero\n");
		printf("8. Fechar o programa\n");
	#endif // MENU_IU

	//opcao recebe a escolha do usuário
	opcao = _getchar();
	
	//Vai para a operação desejada
	switch(opcao){
		case '1':
			menu_1(db);
			return 1;
		case '2':
			menu_2(db);
			return 1;
		case '3':
			menu_3(db);
			return 1;
		case '4':
			menu_4(db);
			return 1;
		case '5':
			menu_5(db);
			return 1;
		case '6':
			menu_6(db);
			return 1;
		case '7':
			menu_7(db);
			return 1;
		case '8':		//Ao retornar 0, sai do while na main
			return 0;
		default:		//Se o caracter for inválido, volta ao menu principal
			return 1;
	}
}
Exemplo n.º 2
0
void    main_menu ( int menu )
{
    switch ( menu ) {                                 /* go to menu X    */
    case 0:
        menu_initial();
        break;
    case 1:
        menu_1();
        break;
    case 2:
        menu_2();
        break;
    case 3:
        menu_3();
        break;
    case 4:
        menu_4();
        break;
    case 5:
        menu_5();
        break;
    case 6:
        menu_6();
        break;
    case 7:
        menu_7();
        break;
    case 8:
        menu_8();
        break;
    case 9:
        printinfo();
        welcome();
        pause;
        clearscr(pm->term_length);
        break;                     
    default:
        fprintf ( stderr,"ERROR: Unrecognised menu in main_menu\n");
        break;
    }
}
Exemplo n.º 3
0
void    menu_3 (void)
{
    int loop = TRUE;
    int i;
    int c;
    
    clearscr(pm->term_length);
    while (loop) {
        printf (" Changing defaults\n");
        printf (" Options\n");
        printf (" %-40.40s", "(1) Change the ASCII delimiter in output");
        printf ("{%s}\n", 
            (pm->seperator == ' ' ) ? "space" : 
            (pm->seperator == '\t') ? "tab" : 
            (pm->seperator == ',' ) ? "," : 
            "ERROR" );

        printf (" %-40.40s", "(2) Run silently, No Warnings");
        printf ("{%s}\n", (pm->verbose) ? "FALSE" : "TRUE");
        printf (" %-40.40s", "(3) Log warnings/information to a file");
        printf ("{%s}\n", (strlen(pm->curr_logfilename) > 1) ? "TRUE" : 
                "FALSE");
        printf (" %-40.40s", "(4) Number of lines on screen");
        printf ("{%d}\n", pm->term_length);
        printf (" %-40.40s", "(5) Change the genetic code");
        printf ("{%s}\n", cu[pm->code].des);
        printf (" %-40.40s", "(6) Change the Fop/CBI values");
        printf ("{%s}\n", fop[pm->f_type].des);
        printf (" %-40.40s", "(7) Change the CAI values");
        printf ("{%s}\n", cai[pm->c_type].des);
        printf (" %-40.40s", "(8) Output Human or Computer readable");
        printf ("{%s readable}\n", (pm->seq_format == 'M') ? "Computer" : 
                "Human"); 
        printf (" %-40.40s", "(9) Concatenate or individual genes");
        printf ("{%s genes}\n", (pm->totals == TRUE ? "concatenate":
                "individual"));      
        printf (" %s", "(10) Correspondence analysis defaults\n");
    
        printf (" (X) Return to previous menu\n");
        printf ("Choices enclosed with curly brackets are the current "
                "defaults\n");
        printf (" Select a menu choice, (Q)uit or (H)elp -> ");
        gets(pm->junk);
        clearscr(pm->term_length);

        if (isalpha((int) pm->junk[0])|| pm->junk[0]=='\0') {
            switch (c = toupper((int) pm->junk[0])){
              case 'Q': 
                my_exit(2,"menu 3");           /* decided to quit program  */
                break;
              case 'H':
                chelp("menu_3");
                break;
              case 'X':
              case '\0':
                return; /*     way out of loop is X or blank line          */
                break;
              default:
                fprintf(stderr,"The answer %s is not a valid\n", pm->junk);
                pause;
                continue;
                break;
                }
        }

        c=0;
        if (isdigit((int)pm->junk[0]))
            c = atoi(pm->junk);
        if ( c <= 0 && c > 10 ) {
            fprintf( stderr, "The answer %s is not valid\n", pm->junk);
            continue;
        }

        switch ((int) c) {
        case 1:
            clearscr(pm->term_length);
            printf (" The current separator is  \"%s\"\n",  
                (pm->seperator == ' ' ) ? "space" : 
                (pm->seperator == '\t') ? "tab" : 
                (pm->seperator == ',' ) ? "," : 
                "ERROR" );
            printf (" Please select a new separator \t:");
            gets(pm->junk);
            c = pm->junk[0];             /* take first character of string */

            if ( strchr ("\t, ", (int)c) == NULL || c == '\0' ) {
                                     /* remember the \0 is in every string */
                printf( "WARNING: The chosen separator %s is unsuitable\n", 
                        pm->junk);
                printf( "\tSeparator is unchanged try comma,tab "
                        "or space\n\n");
            } else
                pm->seperator = (char) c;  /* specify the column separator */

            break;
        case 2:                            /* warn about overwriting files?*/
            clearscr(pm->term_length);
            pm->verbose = (char) ((pm->verbose) ? FALSE : TRUE);
            pm->warn         = (char) ((pm->warn        ) ? FALSE : TRUE);
            break;
        case 3:                            /* redirect errors to a file    */
            if ( strlen(pm->curr_logfilename) > 1 ) {
                strcpy(pm->curr_logfilename , "" );   /* blank logfilename */
                pm->my_err = stderr;                  /* redirects errors  */
                                                      /* to stderr         */
                fclose(pm->logfile);                  /* close logfile     */ 
            } else {
                                       /* open logfile and redirect stderr */
                if (!(pm->logfile = open_file("log filename        \t",
                    "warning.log", "w", (int) pm->verbose)))
                    my_exit(1," open log file menu 3");
                pm->my_err = pm->logfile;
                strncpy(pm->curr_logfilename, pm->junk, MAX_FILENAME_LEN-1);
            }                                                 /* end of if */
            break;

        case 4:                                       /* No of line on term*/
            printf("Please give the new height of the screen [%i] ", 
                    pm->term_length);
            gets(pm->junk);
            if ( isdigit( (int) pm->junk[0]))
                pm->term_length = atoi(pm->junk) ;
            break;

        case 5:                                      /*Change genetic code */
            clearscr(pm->term_length);
            printf(" Genetic codes currently supported are\n");
           /* NumGeneticCodes is given in codonW.h                         */
           for ( i = 0 ; i < NumGeneticCodes ; i++) {
                (pm->code == i) ? printf ( " (%i) {%-45.45s %-17.17s}", i, 
                    cu[i].des, cu[i].typ) : 
                    printf ( " (%i)  %-45.45s %-17.17s ", i, cu[i].des, 
                        cu[i].typ) ;
                printf("\n");
            }
            printf("Choice enclosed with curly brackets is "
                   "the current code\n");
            printf("Please select a new code [no change]\n");
            gets(pm->junk);
            if ( isdigit( (int) pm->junk[0]) ) {
                c = (char)atoi(pm->junk);
                if ( c > 0 && c < NumGeneticCodes && pm->code!= (char) c ){ 
                    pm->code = (char) c;
                    initilize_point(pm->code,pm->f_type, pm->c_type);  
                    }
            }
            break;

        case 6:                                     /*Change optimal codons*/
            clearscr(pm->term_length);
            printf(" Fop values pre-loaded are\n");
            /* NumFopSpecies  defined with the Fop_struct in codonW.h      */
            for ( i = 0 ; i < NumFopSpecies ; i++) {
                (pm->f_type == i) ? printf (" (%i) {%-25.25s %-40.40s}", 
                    i, fop[i].des, fop[i].ref) : 
                    printf (" (%i)  %-25.25s %-40.40s ", i, fop[i].des, 
                        fop[i].ref) ;
                printf("\n");
            }
            printf ("Choice enclosed with curly brackets is the current "
                "selection\n");
            printf ("Please select a type [no change]\n");
            gets(pm->junk);
            if ( isdigit( (int) pm->junk[0]) ) {
                c = (char)atoi(pm->junk);
                if ( c > 0 && c < NumFopSpecies && pm->f_type!=(char) c) {
                        pm->f_type = (char) c;  
                        initilize_point(pm->code,pm->f_type, pm->c_type);
                }
            }
            break;

        case 7:                                      /*Change CAI w values */
            clearscr(pm->term_length);
            printf(" CAI types currently supported are\n");

            /*  NumCaiSpecies currently defined in codonW.h                */
            for ( i = 0 ; i < NumCaiSpecies ; i++) {
                (pm->c_type == i) ? printf (" (%i) {%-25.25s %-40.40s}", 
                    i, cai[i].des, cai[i].ref) : 
                    printf (" (%i)  %-25.25s %-40.40s ", i, cai[i].des, 
                        cai[i].ref) ;
                printf("\n");
            }
            printf ("Choice enclosed with curly brackets is the current "
                "selection\n");
            printf ("Please chose a new CAI [no change]\n");
            gets(pm->junk);
            if ( isdigit( (int) pm->junk[0]) ) {
                c = (char)atoi( pm->junk);

                /* if valid value and different from the current choice    */
                if (  c > 0 && c < NumCaiSpecies && pm->c_type!=(char) c){
                    pm->c_type = (char) c;
                    initilize_point(pm->code,pm->f_type, pm->c_type);
                    }
            }
            break;
       case 8:                       /* machine or human readable format  */
             clearscr(pm->term_length);
             pm->seq_format = 
                (char) (  pm->seq_format == 'M' ? 'H' : 'M'); /*toggle    */
             break;
      case 9:                        /* concatenate genes?                */
            clearscr(pm->term_length);
            pm->totals    = (char) (pm->totals == TRUE ? FALSE : TRUE); 
            break;
     case 10:                       /* change COA default then go to menu5*/
           clearscr(pm->term_length);
           if( !pm->coa ) 
                menu_5();
           else 
                menu_coa();           
           break;
     default:
            fprintf( stderr, "The answer %s is not a valid\n", pm->junk);
            break;
     }
    }
  return;
}