Changeset 52c4264 in mainline for uspace/lib/c
- Timestamp:
- 2012-08-17T12:23:52Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 267f235
- Parents:
- ae2c925 (diff), ad78054 (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. - Location:
- uspace/lib/c
- Files:
-
- 15 added
- 6 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
rae2c925 r52c4264 71 71 generic/device/hw_res_parsed.c \ 72 72 generic/device/char_dev.c \ 73 generic/device/graph_dev.c \ 73 74 generic/device/nic.c \ 74 75 generic/device/pci.c \ … … 95 96 generic/io/asprintf.c \ 96 97 generic/io/io.c \ 98 generic/io/chargrid.c \ 99 generic/io/output.c \ 97 100 generic/io/printf.c \ 98 101 generic/io/log.c \ … … 104 107 generic/io/printf_core.c \ 105 108 generic/io/console.c \ 109 generic/io/visualizer.c \ 110 generic/io/window.c \ 106 111 generic/iplink.c \ 107 112 generic/iplink_srv.c \ -
uspace/lib/c/generic/io/chargrid.c
rae2c925 r52c4264 27 27 */ 28 28 29 /** @addtogroup console29 /** @addtogroup libc 30 30 * @{ 31 31 */ … … 39 39 #include <bool.h> 40 40 #include <as.h> 41 #include "screenbuffer.h" 42 43 /** Structure for buffering state of one virtual console. 44 * 45 */ 46 struct screenbuffer { 47 size_t size; /**< Structure size */ 48 screenbuffer_flag_t flags; /**< Screenbuffer flags */ 49 50 sysarg_t cols; /**< Number of columns */ 51 sysarg_t rows; /**< Number of rows */ 52 53 sysarg_t col; /**< Current column */ 54 sysarg_t row; /**< Current row */ 55 bool cursor_visible; /**< Cursor visibility */ 56 57 char_attrs_t attrs; /**< Current attributes */ 58 59 sysarg_t top_row; /**< The first row in the cyclic buffer */ 60 charfield_t data[]; /**< Screen contents (cyclic buffer) */ 61 }; 62 63 /** Create a screenbuffer. 41 #include <io/chargrid.h> 42 43 /** Create a chargrid. 64 44 * 65 45 * @param[in] cols Number of columns. 66 46 * @param[in] rows Number of rows. 67 * @param[in] flags Screenbufferflags.68 * 69 * @return New screenbuffer.47 * @param[in] flags Chargrid flags. 48 * 49 * @return New chargrid. 70 50 * @return NULL on failure. 71 51 * 72 52 */ 73 screenbuffer_t *screenbuffer_create(sysarg_t cols, sysarg_t rows,74 screenbuffer_flag_t flags)53 chargrid_t *chargrid_create(sysarg_t cols, sysarg_t rows, 54 chargrid_flag_t flags) 75 55 { 76 56 size_t size = 77 sizeof( screenbuffer_t) + cols * rows * sizeof(charfield_t);78 screenbuffer_t *scrbuf;79 80 if ((flags & SCREENBUFFER_FLAG_SHARED) == SCREENBUFFER_FLAG_SHARED) {81 scrbuf = ( screenbuffer_t *) as_area_create(AS_AREA_ANY, size,57 sizeof(chargrid_t) + cols * rows * sizeof(charfield_t); 58 chargrid_t *scrbuf; 59 60 if ((flags & CHARGRID_FLAG_SHARED) == CHARGRID_FLAG_SHARED) { 61 scrbuf = (chargrid_t *) as_area_create(AS_AREA_ANY, size, 82 62 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); 83 63 if (scrbuf == AS_MAP_FAILED) 84 64 return NULL; 85 65 } else { 86 scrbuf = ( screenbuffer_t *) malloc(size);66 scrbuf = (chargrid_t *) malloc(size); 87 67 if (scrbuf == NULL) 88 68 return NULL; … … 99 79 100 80 scrbuf->top_row = 0; 101 screenbuffer_clear(scrbuf);81 chargrid_clear(scrbuf); 102 82 103 83 return scrbuf; 104 84 } 105 85 106 /** Return keyfield by coordinates 107 * 108 * The back buffer is organized as a cyclic buffer. 109 * Therefore we must take into account the topmost column. 110 * 111 * @param scrbuf Screenbuffer 112 * @param col Column position on screen 113 * @param row Row position on screen 114 * 115 * @return Keyfield structure on (row, col) 116 * 117 */ 118 charfield_t *screenbuffer_field_at(screenbuffer_t *scrbuf, sysarg_t col, 119 sysarg_t row) 120 { 121 return scrbuf->data + 122 ((row + scrbuf->top_row) % scrbuf->rows) * scrbuf->cols + 123 col; 124 } 125 126 bool screenbuffer_cursor_at(screenbuffer_t *scrbuf, sysarg_t col, sysarg_t row) 86 void chargrid_destroy(chargrid_t *srcbuf) 87 { 88 // TODO 89 } 90 91 bool chargrid_cursor_at(chargrid_t *scrbuf, sysarg_t col, sysarg_t row) 127 92 { 128 93 return ((scrbuf->cursor_visible) && (scrbuf->col == col) && … … 130 95 } 131 96 132 sysarg_t screenbuffer_get_top_row(screenbuffer_t *scrbuf)97 sysarg_t chargrid_get_top_row(chargrid_t *scrbuf) 133 98 { 134 99 return scrbuf->top_row; 135 100 } 136 101 137 static sysarg_t screenbuffer_update_rows(screenbuffer_t *scrbuf)102 static sysarg_t chargrid_update_rows(chargrid_t *scrbuf) 138 103 { 139 104 if (scrbuf->row == scrbuf->rows) { 140 105 scrbuf->row = scrbuf->rows - 1; 141 106 scrbuf->top_row = (scrbuf->top_row + 1) % scrbuf->rows; 142 screenbuffer_clear_row(scrbuf, scrbuf->row);107 chargrid_clear_row(scrbuf, scrbuf->row); 143 108 144 109 return scrbuf->rows; … … 148 113 } 149 114 150 static sysarg_t screenbuffer_update_cols(screenbuffer_t *scrbuf)115 static sysarg_t chargrid_update_cols(chargrid_t *scrbuf) 151 116 { 152 117 /* Column overflow */ … … 154 119 scrbuf->col = 0; 155 120 scrbuf->row++; 156 return screenbuffer_update_rows(scrbuf);121 return chargrid_update_rows(scrbuf); 157 122 } 158 123 … … 160 125 } 161 126 162 /** Store one character to screenbuffer.127 /** Store one character to chargrid. 163 128 * 164 129 * Its position is determined by scrbuf->col 165 130 * and scrbuf->row. 166 131 * 167 * @param scrbuf Screenbuffer.132 * @param scrbuf Chargrid. 168 133 * @param ch Character to store. 169 134 * @param update Update coordinates. … … 174 139 * 175 140 */ 176 sysarg_t screenbuffer_putchar(screenbuffer_t *scrbuf, wchar_t ch, bool update)141 sysarg_t chargrid_putchar(chargrid_t *scrbuf, wchar_t ch, bool update) 177 142 { 178 143 assert(scrbuf->col < scrbuf->cols); … … 180 145 181 146 charfield_t *field = 182 screenbuffer_field_at(scrbuf, scrbuf->col, scrbuf->row);147 chargrid_charfield_at(scrbuf, scrbuf->col, scrbuf->row); 183 148 184 149 field->ch = ch; … … 188 153 if (update) { 189 154 scrbuf->col++; 190 return screenbuffer_update_cols(scrbuf);155 return chargrid_update_cols(scrbuf); 191 156 } 192 157 … … 194 159 } 195 160 196 /** Jump to a new row in screenbuffer.197 * 198 * @param scrbuf Screenbuffer.161 /** Jump to a new row in chargrid. 162 * 163 * @param scrbuf Chargrid. 199 164 * 200 165 * @return Number of rows which have been affected. In usual … … 203 168 * 204 169 */ 205 sysarg_t screenbuffer_newline(screenbuffer_t *scrbuf)170 sysarg_t chargrid_newline(chargrid_t *scrbuf) 206 171 { 207 172 assert(scrbuf->col < scrbuf->cols); … … 211 176 scrbuf->row++; 212 177 213 return screenbuffer_update_rows(scrbuf);214 } 215 216 /** Jump to a new row in screenbuffer.217 * 218 * @param scrbuf Screenbuffer.178 return chargrid_update_rows(scrbuf); 179 } 180 181 /** Jump to a new row in chargrid. 182 * 183 * @param scrbuf Chargrid. 219 184 * @param tab_size Tab size. 220 185 * … … 224 189 * 225 190 */ 226 sysarg_t screenbuffer_tabstop(screenbuffer_t *scrbuf, sysarg_t tab_size)191 sysarg_t chargrid_tabstop(chargrid_t *scrbuf, sysarg_t tab_size) 227 192 { 228 193 assert(scrbuf->col < scrbuf->cols); … … 233 198 234 199 for (sysarg_t i = 0; i < spaces; i++) 235 flush += screenbuffer_putchar(scrbuf, ' ', true) - 1;200 flush += chargrid_putchar(scrbuf, ' ', true) - 1; 236 201 237 202 return flush; 238 203 } 239 204 240 /** Jump to the previous character in screenbuffer.205 /** Jump to the previous character in chargrid. 241 206 * 242 207 * Currently no scrollback is supported. 243 208 * 244 * @param scrbuf Screenbuffer.209 * @param scrbuf Chargrid. 245 210 * 246 211 * @return Number of rows which have been affected. In usual … … 250 215 * 251 216 */ 252 sysarg_t screenbuffer_backspace(screenbuffer_t *scrbuf)217 sysarg_t chargrid_backspace(chargrid_t *scrbuf) 253 218 { 254 219 assert(scrbuf->col < scrbuf->cols); … … 262 227 scrbuf->row--; 263 228 264 screenbuffer_putchar(scrbuf, ' ', false);229 chargrid_putchar(scrbuf, ' ', false); 265 230 return 2; 266 231 } 267 232 268 233 scrbuf->col--; 269 screenbuffer_putchar(scrbuf, ' ', false);234 chargrid_putchar(scrbuf, ' ', false); 270 235 return 1; 271 236 } 272 237 273 /** Clear the screenbuffer.274 * 275 * @param scrbuf Screenbuffer.276 * 277 */ 278 void screenbuffer_clear(screenbuffer_t *scrbuf)238 /** Clear the chargrid. 239 * 240 * @param scrbuf Chargrid. 241 * 242 */ 243 void chargrid_clear(chargrid_t *scrbuf) 279 244 { 280 245 for (size_t pos = 0; pos < (scrbuf->cols * scrbuf->rows); pos++) { … … 288 253 } 289 254 290 /** Update current screenbuffercoordinates291 * 292 * @param scrbuf Screenbuffer.255 /** Update current chargrid coordinates 256 * 257 * @param scrbuf Chargrid. 293 258 * @param col New column. 294 259 * @param row New row. 295 260 * 296 261 */ 297 void screenbuffer_set_cursor(screenbuffer_t *scrbuf, sysarg_t col, sysarg_t row)262 void chargrid_set_cursor(chargrid_t *scrbuf, sysarg_t col, sysarg_t row) 298 263 { 299 264 scrbuf->col = col; … … 301 266 } 302 267 303 void screenbuffer_set_cursor_visibility(screenbuffer_t *scrbuf, bool visible)268 void chargrid_set_cursor_visibility(chargrid_t *scrbuf, bool visible) 304 269 { 305 270 scrbuf->cursor_visible = visible; 306 271 } 307 272 308 /** Get current screenbuffercoordinates309 * 310 * @param scrbuf Screenbuffer.273 /** Get current chargrid coordinates 274 * 275 * @param scrbuf Chargrid. 311 276 * @param col Column. 312 277 * @param row Row. 313 278 * 314 279 */ 315 void screenbuffer_get_cursor(screenbuffer_t *scrbuf, sysarg_t *col,280 void chargrid_get_cursor(chargrid_t *scrbuf, sysarg_t *col, 316 281 sysarg_t *row) 317 282 { … … 323 288 } 324 289 325 bool screenbuffer_get_cursor_visibility(screenbuffer_t *scrbuf)290 bool chargrid_get_cursor_visibility(chargrid_t *scrbuf) 326 291 { 327 292 return scrbuf->cursor_visible; … … 330 295 /** Clear one buffer row. 331 296 * 332 * @param scrbuf Screenbuffer.297 * @param scrbuf Chargrid. 333 298 * @param row Row to clear. 334 299 * 335 300 */ 336 void screenbuffer_clear_row(screenbuffer_t *scrbuf, sysarg_t row)301 void chargrid_clear_row(chargrid_t *scrbuf, sysarg_t row) 337 302 { 338 303 for (sysarg_t col = 0; col < scrbuf->cols; col++) { 339 304 charfield_t *field = 340 screenbuffer_field_at(scrbuf, col, row);305 chargrid_charfield_at(scrbuf, col, row); 341 306 342 307 field->ch = 0; … … 346 311 } 347 312 348 /** Set screenbufferstyle.349 * 350 * @param scrbuf Screenbuffer.313 /** Set chargrid style. 314 * 315 * @param scrbuf Chargrid. 351 316 * @param style Style. 352 317 * 353 318 */ 354 void screenbuffer_set_style(screenbuffer_t *scrbuf, console_style_t style)319 void chargrid_set_style(chargrid_t *scrbuf, console_style_t style) 355 320 { 356 321 scrbuf->attrs.type = CHAR_ATTR_STYLE; … … 358 323 } 359 324 360 /** Set screenbuffercolor.361 * 362 * @param scrbuf Screenbuffer.325 /** Set chargrid color. 326 * 327 * @param scrbuf Chargrid. 363 328 * @param bgcolor Background color. 364 329 * @param fgcolor Foreground color. … … 366 331 * 367 332 */ 368 void screenbuffer_set_color(screenbuffer_t *scrbuf, console_color_t bgcolor,333 void chargrid_set_color(chargrid_t *scrbuf, console_color_t bgcolor, 369 334 console_color_t fgcolor, console_color_attr_t attr) 370 335 { … … 375 340 } 376 341 377 /** Set screenbufferRGB color.378 * 379 * @param scrbuf Screenbuffer.342 /** Set chargrid RGB color. 343 * 344 * @param scrbuf Chargrid. 380 345 * @param bgcolor Background color. 381 346 * @param fgcolor Foreground color. 382 347 * 383 348 */ 384 void screenbuffer_set_rgb_color(screenbuffer_t *scrbuf, pixel_t bgcolor,349 void chargrid_set_rgb_color(chargrid_t *scrbuf, pixel_t bgcolor, 385 350 pixel_t fgcolor) 386 351 { -
uspace/lib/c/generic/str.c
rae2c925 r52c4264 134 134 135 135 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 */ 153 wchar_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; 136 181 } 137 182 -
uspace/lib/c/generic/task.c
rae2c925 r52c4264 201 201 * 202 202 * This is really just a convenience wrapper over the more complicated 203 * loader API. Arguments are passed in a va_list. 204 * 205 * @param id If not NULL, the ID of the task is stored here on success. 206 * @param path Pathname of the binary to execute. 207 * @param cnt Number of arguments. 208 * @param ap Command-line arguments. 209 * 210 * @return Zero on success or negative error code. 211 * 212 */ 213 int task_spawn(task_id_t *task_id, const char *path, int cnt, va_list ap) 214 { 215 /* Allocate argument list. */ 216 const char **arglist = malloc(cnt * sizeof(const char *)); 217 if (arglist == NULL) 218 return ENOMEM; 219 220 /* Fill in arguments. */ 221 const char *arg; 222 cnt = 0; 223 do { 224 arg = va_arg(ap, const char *); 225 arglist[cnt++] = arg; 226 } while (arg != NULL); 227 228 /* Spawn task. */ 229 int rc = task_spawnv(task_id, path, arglist); 230 231 /* Free argument list. */ 232 free(arglist); 233 return rc; 234 } 235 236 /** Create a new task by running an executable from the filesystem. 237 * 238 * This is really just a convenience wrapper over the more complicated 203 239 * loader API. Arguments are passed as a null-terminated list of arguments. 204 240 * … … 216 252 va_list ap; 217 253 const char *arg; 218 const char **arglist;219 254 int cnt = 0; 220 255 … … 226 261 va_end(ap); 227 262 228 /* Allocate argument list. */229 arglist = malloc(cnt * sizeof(const char *));230 if (arglist == NULL)231 return ENOMEM;232 233 /* Fill in arguments. */234 cnt = 0;235 263 va_start(ap, path); 236 do { 237 arg = va_arg(ap, const char *); 238 arglist[cnt++] = arg; 239 } while (arg != NULL); 264 int rc = task_spawn(task_id, path, cnt, ap); 240 265 va_end(ap); 241 266 242 /* Spawn task. */243 int rc = task_spawnv(task_id, path, arglist);244 245 /* Free argument list. */246 free(arglist);247 267 return rc; 248 268 } -
uspace/lib/c/include/io/charfield.h
rae2c925 r52c4264 1 1 /* 2 2 * Copyright (c) 2006 Josef Cejka 3 * Copyright (c) 2011 Petr Koupy 3 4 * All rights reserved. 4 5 * … … 33 34 */ 34 35 35 #ifndef IMGMAP_SCREENBUFFER_H__36 #define IMGMAP_SCREENBUFFER_H__36 #ifndef LIBC_IO_CHARFIELD_H_ 37 #define LIBC_IO_CHARFIELD_H_ 37 38 38 39 #include <sys/types.h> … … 40 41 #include <io/color.h> 41 42 #include <io/style.h> 42 #include "fb.h"43 #include <io/pixel.h> 43 44 44 45 typedef enum { 45 SCREENBUFFER_FLAG_NONE = 0,46 SCREENBUFFER_FLAG_SHARED= 147 } screenbuffer_flag_t;46 CHAR_FLAG_NONE = 0, 47 CHAR_FLAG_DIRTY = 1 48 } char_flags_t; 48 49 49 50 typedef enum { … … 52 53 CHAR_ATTR_RGB 53 54 } char_attr_type_t; 54 55 typedef enum {56 CHAR_FLAG_NONE = 0,57 CHAR_FLAG_DIRTY = 158 } char_flags_t;59 55 60 56 typedef struct { … … 65 61 66 62 typedef struct { 67 pixel_t bgcolor; /**< Background color */68 pixel_t fgcolor; /**< Foreground color */63 pixel_t bgcolor; 64 pixel_t fgcolor; 69 65 } char_attr_rgb_t; 70 66 … … 80 76 } char_attrs_t; 81 77 82 /** One field on screen. It contain one character and its attributes. */83 78 typedef struct { 84 wchar_t ch; /**< Character itself */85 char_attrs_t attrs; /**< Character attributes */86 char_flags_t flags; /**< Character flags */79 wchar_t ch; 80 char_attrs_t attrs; 81 char_flags_t flags; 87 82 } charfield_t; 88 83 89 /** Compare two sets of attributes.90 *91 * @param a1 First attribute.92 * @param a2 Second attribute.93 *94 * @return True on equality95 *96 */97 84 static inline bool attrs_same(char_attrs_t a1, char_attrs_t a2) 98 85 { … … 115 102 } 116 103 117 extern screenbuffer_t *screenbuffer_create(sysarg_t, sysarg_t,118 screenbuffer_flag_t);119 120 extern charfield_t *screenbuffer_field_at(screenbuffer_t *, sysarg_t, sysarg_t);121 extern bool screenbuffer_cursor_at(screenbuffer_t *, sysarg_t, sysarg_t);122 123 extern sysarg_t screenbuffer_get_top_row(screenbuffer_t *);124 125 extern sysarg_t screenbuffer_putchar(screenbuffer_t *, wchar_t, bool);126 extern sysarg_t screenbuffer_newline(screenbuffer_t *);127 extern sysarg_t screenbuffer_tabstop(screenbuffer_t *, sysarg_t);128 extern sysarg_t screenbuffer_backspace(screenbuffer_t *);129 130 extern void screenbuffer_clear(screenbuffer_t *);131 extern void screenbuffer_clear_row(screenbuffer_t *, sysarg_t);132 133 extern void screenbuffer_set_cursor(screenbuffer_t *, sysarg_t, sysarg_t);134 extern void screenbuffer_set_cursor_visibility(screenbuffer_t *, bool);135 extern bool screenbuffer_get_cursor_visibility(screenbuffer_t *);136 137 extern void screenbuffer_get_cursor(screenbuffer_t *, sysarg_t *, sysarg_t *);138 139 extern void screenbuffer_set_style(screenbuffer_t *, console_style_t);140 extern void screenbuffer_set_color(screenbuffer_t *, console_color_t,141 console_color_t, console_color_attr_t);142 extern void screenbuffer_set_rgb_color(screenbuffer_t *, pixel_t, pixel_t);143 144 104 #endif 145 105 -
uspace/lib/c/include/ipc/dev_iface.h
rae2c925 r52c4264 38 38 /** Character device interface */ 39 39 CHAR_DEV_IFACE, 40 41 /** Graphic device interface */ 42 GRAPH_DEV_IFACE, 40 43 41 44 /** Network interface controller interface */ -
uspace/lib/c/include/str.h
rae2c925 r52c4264 56 56 57 57 extern wchar_t str_decode(const char *str, size_t *offset, size_t sz); 58 extern wchar_t str_decode_reverse(const char *str, size_t *offset, size_t sz); 58 59 extern int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz); 59 60 -
uspace/lib/c/include/task.h
rae2c925 r52c4264 38 38 #include <sys/types.h> 39 39 #include <abi/proc/task.h> 40 #include <stdarg.h> 40 41 41 42 typedef enum { … … 48 49 extern int task_kill(task_id_t); 49 50 50 extern task_id_t task_spawn(const char *, const char *const[], int *);51 51 extern int task_spawnv(task_id_t *, const char *path, const char *const []); 52 52 extern int task_spawnvf(task_id_t *, const char *path, const char *const [], 53 53 int *const []); 54 extern int task_spawn(task_id_t *, const char *path, int, va_list ap); 54 55 extern int task_spawnl(task_id_t *, const char *path, ...); 55 56
Note:
See TracChangeset
for help on using the changeset viewer.