Changeset 3607


Ignore:
Timestamp:
08/02/09 13:09:42 (4 years ago)
Author:
sam
Message:

Implement conio.h functions cgets(), cputs(), getpass(), movetext(),
putch() and _setcurstortype().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/caca_conio.c

    r3602 r3607  
    3737static int unget_ch = -1; 
    3838static int kbhit_ch = -1; 
    39 static char pass_buffer[BUFSIZ]; 
    40 static char cgets_buffer[BUFSIZ]; 
     39static char pass_buffer[8 + 1]; 
    4140 
    4241static void conio_init(void); 
     
    4443static void conio_fini(void); 
    4544 
    46 int caca_conio_directvideo; 
    47 int caca_conio__wscroll; 
     45int caca_conio_directvideo = 0; 
     46int caca_conio__wscroll = 1; 
    4847 
    4948/** \brief DOS conio.h cgets() equivalent */ 
    5049char * caca_conio_cgets(char *str) 
    5150{ 
    52     conio_init(); 
    53  
    54     /* TODO: implement this function */ 
    55     cgets_buffer[0] = '\0'; 
    56  
    57     return cgets_buffer; 
     51    int len = ((uint8_t *)str)[0]; 
     52    int pos = 0; 
     53 
     54    conio_init(); 
     55 
     56    while (pos < len) 
     57    { 
     58        int ch = caca_conio_getch(); 
     59        if (ch == '\n' || ch == '\r') 
     60            break; 
     61        str[2 + pos] = (char)(uint8_t)ch; 
     62        /* FIXME: handle scrolling */ 
     63        caca_put_char(cv, caca_wherex(cv), caca_wherey(cv), ch); 
     64        caca_gotoxy(cv, caca_wherex(cv) + 1, caca_wherey(cv)); 
     65        pos++; 
     66    } 
     67 
     68    str[2 + pos] = '\0'; 
     69    str[1] = (char)(uint8_t)pos; 
     70 
     71    conio_refresh(); 
     72 
     73    return str + 2; 
    5874} 
    5975 
     
    7591    conio_init(); 
    7692 
     93    /* FIXME: must work within the currently active text window */ 
    7794    caca_clear_canvas(cv); 
    7895    caca_gotoxy(cv, 0, 0); 
     
    89106    conio_init(); 
    90107 
     108    /* FIXME: handle scrolling */ 
    91109    va_start(args, format); 
    92110    ret = caca_vprintf(cv, caca_wherex(cv), caca_wherey(cv), format, args); 
     
    103121int caca_conio_cputs(const char *str) 
    104122{ 
    105     conio_init(); 
    106  
    107     /* TODO: implement this function */ 
    108  
    109     return 0; 
    110 } 
    111  
    112 /** \brief DOS conio.h cscanf() equivalent */ 
     123    int ch; 
     124 
     125    conio_init(); 
     126 
     127    while ((ch = (uint8_t)*str++)) 
     128    { 
     129        /* FIXME: handle windows, scrolling, '\n' and '\r' */ 
     130        caca_put_char(cv, caca_wherex(cv), caca_wherey(cv), ch); 
     131        caca_gotoxy(cv, caca_wherex(cv) + 1, caca_wherey(cv)); 
     132    } 
     133 
     134    conio_refresh(); 
     135 
     136    return ch; 
     137} 
     138 
     139/** \brief DOS stdio.h cscanf() equivalent */ 
    113140int caca_conio_cscanf(char *format, ...) 
    114141{ 
     
    198225char * caca_conio_getpass(const char *prompt) 
    199226{ 
    200     conio_init(); 
    201  
    202     /* TODO: implement this function */ 
    203     pass_buffer[0] = '\0'; 
     227    int pos = 0; 
     228 
     229    conio_init(); 
     230 
     231    while (pos < 8) 
     232    { 
     233        int ch = caca_conio_getch(); 
     234        if (ch == '\n' || ch == '\r') 
     235            break; 
     236        pass_buffer[pos] = (char)(uint8_t)ch; 
     237        pos++; 
     238    } 
     239 
     240    pass_buffer[pos] = '\0'; 
     241 
     242    conio_refresh(); 
    204243 
    205244    return pass_buffer; 
     
    296335                        int destleft, int desttop) 
    297336{ 
    298     conio_init(); 
    299  
    300     /* TODO: implement this function */ 
    301  
    302     return 0; 
     337    caca_canvas_t *tmp; 
     338 
     339    conio_init(); 
     340 
     341    if (left < 1 || top < 1 || left > right || top > bottom 
     342         || destleft < 1 || desttop < 1 || destleft > right 
     343         || desttop > bottom || right > caca_get_canvas_width(cv) 
     344         || bottom > caca_get_canvas_width(cv)) 
     345        return 0; 
     346 
     347    tmp = caca_create_canvas(right - left + 1, bottom - top + 1); 
     348    caca_blit(tmp, 1 - left, 1 - top, cv, NULL); 
     349    caca_blit(cv, destleft - 1, desttop - 1, tmp, NULL); 
     350 
     351    conio_refresh(); 
     352 
     353    return 1; 
    303354} 
    304355 
     
    343394    conio_init(); 
    344395 
    345     /* TODO: implement this function */ 
    346  
    347     return 0; 
     396    /* FIXME: handle scrolling, windows */ 
     397    caca_put_char(cv, caca_wherex(cv), caca_wherey(cv), ch); 
     398    caca_gotoxy(cv, caca_wherex(cv) + 1, caca_wherey(cv)); 
     399 
     400    return ch; 
    348401} 
    349402 
     
    363416    conio_init(); 
    364417 
    365     /* TODO: implement this function */ 
     418    switch(cur_t) 
     419    { 
     420        case CACA_CONIO__NOCURSOR: 
     421            caca_set_cursor(dp, 0); 
     422            break; 
     423        case CACA_CONIO__SOLIDCURSOR: 
     424        case CACA_CONIO__NORMALCURSOR: 
     425            caca_set_cursor(dp, 1); 
     426            break; 
     427    } 
     428 
     429    conio_refresh(); 
    366430} 
    367431 
Note: See TracChangeset for help on using the changeset viewer.