// cleanWord()
// Requires:  std::string reference
// Returns:   None
// Trims end of line characters, leading spaces, and trailing spaces
// from the passed string reference.  After that, it transforms the
// word to lower case for consistent matching.
void cleanWord(std::string &s) {
  // Small chance of getting empty string, so don't check here every time.
  trimEndOfLine(s);
  trimLeadingWhitespace(s);
  trimTrailingWhitespace(s);
  toLowerString(s);
}
Exemple #2
0
void get_input(FORM *my_form, FIELD **field){
    int ch;
    int contLoop=1;
    char *temp = (char*)malloc(50*sizeof(char));
    while(contLoop)
    {   ch = getch();
        switch(ch)
        {   case KEY_BACKSPACE:
                form_driver(my_form, REQ_DEL_PREV);
                break;
            case KEY_DC:
                form_driver(my_form, REQ_DEL_CHAR);
                break;
            case KEY_LEFT:
                if (form_driver(my_form, REQ_LEFT_CHAR)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_PREV_FIELD);
                }
                break;
            case KEY_RIGHT:
                if (form_driver(my_form, REQ_RIGHT_CHAR)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_NEXT_FIELD);
                }
                break;
            case KEY_UP:
                if (form_driver(my_form, REQ_PREV_LINE)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_PREV_FIELD);
                }
                break;
            case KEY_DOWN:
                if (form_driver(my_form, REQ_NEXT_LINE)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_NEXT_FIELD);
                }
                break;
            case '\n':
                if (form_driver(my_form,REQ_VALIDATION)==E_OK){
                    int i;
                    int valid=1;
                    for(i=0;i<5;i++){
                        strcpy(temp,field_buffer(field[i],0));
                        trimTrailingWhitespace(temp);
                        if (strlen(temp)==0) valid=0;
                    }
                    
                    if (valid==1) contLoop=0;
                }
            default:
                form_driver(my_form, ch);
                break;
        }
    }
}
Exemple #3
0
FILE *openFile(){
    FIELD *field[3];
    FORM  *my_form;
    int ch;

    int contLoop = 1;
    FILE *file;
    char *fname = (char*)malloc(50*sizeof(char));;

    while(contLoop){

        /* Initialize the fields */
        field[0] = new_field(1, 30, 5, 1, 0, 0); //filename
        field[1] = new_field(1, 1, 7, 33, 0, 0); //overwrite?
        field[2] = NULL;

        /* Set field options */
        set_field_back(field[0], A_UNDERLINE);  /* Print a line for the option  */
        field_opts_off(field[0], O_AUTOSKIP);   /* Don't go to next field when this */
                            /* Field is filled up       */
        //set_field_back(field[1], A_UNDERLINE); 
        field_opts_off(field[1], O_AUTOSKIP);
        field_opts_off(field[1], O_VISIBLE);

        /* Create the form and post it */
        my_form = new_form(field);
        post_form(my_form);
        refresh();
        mvprintw(0,0,"iCal Generator\nWritten by Derek Redfern");
        mvprintw(4, 1, "Path and name of iCal file to create (without extension):");
        
        refresh();
        form_driver(my_form, REQ_FIRST_FIELD);
        /* Loop through to get user requests */
        while((ch = getch()) != '\n')
        {   switch(ch)
            {   case KEY_BACKSPACE:
                    form_driver(my_form, REQ_LEFT_CHAR);
                    form_driver(my_form, REQ_DEL_CHAR);
                    break;
                case KEY_LEFT:
                    form_driver(my_form, REQ_LEFT_CHAR);
                    break;
                case KEY_RIGHT:
                    form_driver(my_form, REQ_RIGHT_CHAR);
                    break;
                default:
                    /* If this is a normal character, it gets */
                    /* Printed                */    
                    form_driver(my_form, ch);
                    break;
            }
        }

        form_driver(my_form,REQ_VALIDATION);
        char *temp = field_buffer(field[0],0);
        int length = strlen(temp);
        strncpy(fname,temp,length);
        trimTrailingWhitespace(fname);
        strcat(fname,".ics");
        file = fopen(fname,"r");
        if (!(file==NULL)){
            mvprintw(7, 1, "Overwrite existing file? [y/n]: ");
            field_opts_on(field[1], O_VISIBLE);
            form_driver(my_form, REQ_NEXT_FIELD);
            field_opts_off(field[0], O_ACTIVE);

            while((ch = getch()) != '\n')
            {   switch(ch)
                {   case KEY_BACKSPACE:
                        form_driver(my_form, REQ_DEL_PREV);
                        break;
                    case 'y':   
                        form_driver(my_form, ch);
                        break;
                    case 'n':
                        form_driver(my_form, ch);
                        break;
                }
            }
            form_driver(my_form,REQ_VALIDATION);
            char *confirm = field_buffer(field[1],0);
            if (confirm[0]=='y'){ //confirm overwrite
                contLoop=0;
            } else {
                fclose(file); //close test file
            }
        } else {
            contLoop=0; //no file exists, proceed with write
        }

        /* Un post form and free the memory */
        unpost_form(my_form);
        free_form(my_form);
        free_field(field[0]);
        free_field(field[1]); 
    }
    file = fopen(fname,"w");
    return file;
}
Exemple #4
0
void getSummary(char *title, char *desc, char *loc){
    FIELD *field[3];
    FORM  *my_form;
    int ch;
    int contLoop=1;
    char *temp = (char*)malloc(50*sizeof(char));

    /* Initialize the fields */
    field[0] = new_field(1, 50, 5, 25, 0, 0); //title
    field[1] = new_field(4, 50, 7, 25, 0, 0); //description
    field[2] = new_field(1, 30, 12, 25, 0, 0); //location

    /* Set field options */
    set_field_back(field[0], A_UNDERLINE);
    field_opts_off(field[0], O_AUTOSKIP); 
                        
    set_field_back(field[1], A_UNDERLINE); 
    field_opts_off(field[1], O_AUTOSKIP);

    set_field_back(field[2], A_UNDERLINE); 
    field_opts_off(field[2], O_AUTOSKIP);

    /* Create the form and post it */
    my_form = new_form(field);
    post_form(my_form);
    mvprintw(0,0,"iCal Generator\nWritten by Derek Redfern");
    mvprintw(3,1,"Use arrow keys to navigate; press Enter to proceed\n");
    mvprintw(5, 1, "Event title (required): ");
    mvprintw(7, 1, "Event description: ");
    mvprintw(12, 1, "Event location: ");
    refresh();
    //getch();
    form_driver(my_form, REQ_FIRST_FIELD);
    /* Loop through to get user requests */
    while(contLoop)
    {   ch = getch();
        switch(ch)
        {   case KEY_BACKSPACE:
                form_driver(my_form, REQ_DEL_PREV);
                break;
            case KEY_DC:
                form_driver(my_form, REQ_DEL_CHAR);
                break;
            case KEY_LEFT:
                if (form_driver(my_form, REQ_LEFT_CHAR)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_PREV_LINE);
                }
                break;
            case KEY_RIGHT:
                if (form_driver(my_form, REQ_RIGHT_CHAR)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_NEXT_LINE);
                }
                break;
            case KEY_UP:
                if (form_driver(my_form, REQ_PREV_LINE)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_PREV_FIELD);
                }
                break;
            case KEY_DOWN:
                if (form_driver(my_form, REQ_NEXT_LINE)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_NEXT_FIELD);
                }
                break;
            case '\n':
                form_driver(my_form,REQ_VALIDATION);
                strcpy(temp,field_buffer(field[0],0));
                trimTrailingWhitespace(temp);
                if (strlen(temp)>0) contLoop=0;
            default:
                form_driver(my_form, ch);
                break;
        }
    }
    title = field_buffer(field[0],0);
    desc = field_buffer(field[1],0);
    loc = field_buffer(field[2],0);
    unpost_form(my_form);
    free_form(my_form);
    free_field(field[0]);
    free_field(field[1]); 
    free_field(field[2]); 
}