Changeset 2568c94 in mainline for uspace/lib/c


Ignore:
Timestamp:
2012-08-17T17:15:19Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1789023
Parents:
4f351432 (diff), 01e397ac (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge mainline changes

Location:
uspace/lib/c
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    r4f351432 r2568c94  
    9696        generic/inetping.c \
    9797        generic/io/asprintf.c \
     98        generic/io/input.c \
    9899        generic/io/io.c \
    99100        generic/io/chargrid.c \
  • uspace/lib/c/generic/str.c

    r4f351432 r2568c94  
    134134       
    135135        return ch;
     136}
     137
     138/** Decode a single character from a string to the left.
     139 *
     140 * Decode a single character from a string of size @a size. Decoding starts
     141 * at @a offset and this offset is moved to the beginning of the previous
     142 * character. In case of decoding error, offset generally decreases at least
     143 * by one. However, offset is never moved before 0.
     144 *
     145 * @param str    String (not necessarily NULL-terminated).
     146 * @param offset Byte offset in string where to start decoding.
     147 * @param size   Size of the string (in bytes).
     148 *
     149 * @return Value of decoded character, U_SPECIAL on decoding error or
     150 *         NULL if attempt to decode beyond @a start of str.
     151 *
     152 */
     153wchar_t str_decode_reverse(const char *str, size_t *offset, size_t size)
     154{
     155        if (*offset == 0)
     156                return 0;
     157       
     158        size_t processed = 0;
     159        /* Continue while continuation bytes found */
     160        while (*offset > 0 && processed < 4) {
     161                uint8_t b = (uint8_t) str[--(*offset)];
     162               
     163                if (processed == 0 && (b & 0x80) == 0) {
     164                        /* 0xxxxxxx (Plain ASCII) */
     165                        return b & 0x7f;
     166                }
     167                else if ((b & 0xe0) == 0xc0 || (b & 0xf0) == 0xe0 ||
     168                    (b & 0xf8) == 0xf0) {
     169                        /* Start byte */
     170                        size_t start_offset = *offset;
     171                        return str_decode(str, &start_offset, size);
     172                }
     173                else if ((b & 0xc0) != 0x80) {
     174                        /* Not a continuation byte */
     175                        return U_SPECIAL;
     176                }
     177                processed++;
     178        }
     179        /* Too many continuation bytes */
     180        return U_SPECIAL;
    136181}
    137182
  • uspace/lib/c/include/io/console.h

    r4f351432 r2568c94  
    3737
    3838#include <sys/time.h>
     39#include <io/kbd_event.h>
    3940#include <io/keycode.h>
    4041#include <async.h>
     
    7071} console_ctrl_t;
    7172
    72 typedef enum {
    73         KEY_PRESS,
    74         KEY_RELEASE
    75 } kbd_event_type_t;
    76 
    77 /** Console event structure. */
    78 typedef struct {
    79         /** List handle */
    80         link_t link;
    81        
    82         /** Press or release event. */
    83         kbd_event_type_t type;
    84        
    85         /** Keycode of the key that was pressed or released. */
    86         keycode_t key;
    87        
    88         /** Bitmask of modifiers held. */
    89         keymod_t mods;
    90        
    91         /** The character that was generated or '\0' for none. */
    92         wchar_t c;
    93 } kbd_event_t;
    94 
    9573extern console_ctrl_t *console_init(FILE *, FILE *);
    9674extern void console_done(console_ctrl_t *);
  • uspace/lib/c/include/str.h

    r4f351432 r2568c94  
    5656
    5757extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
     58extern wchar_t str_decode_reverse(const char *str, size_t *offset, size_t sz);
    5859extern int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz);
    5960
Note: See TracChangeset for help on using the changeset viewer.