1// This file is part of SmallBASIC
2//
3// lowlevel device (OS) I/O
4//
5// This program is distributed under the terms of the GPL v2.0 or later
6// Download the GNU Public License (GPL) from www.gnu.org
7//
8// Copyright(C) 2000 Nicholas Christopoulos
9
10/**
11 * @defgroup dev High-level drivers
12 */
13/**
14 * @defgroup dev_g High-level graphics driver
15 */
16/**
17 * @defgroup dev_s High-level sound driver
18 */
19/**
20 * @defgroup dev_i High-level input driver
21 */
22/**
23 * @defgroup dev_f High-level file-system driver
24 */
25
26#if !defined(_device_h)
27#define _device_h
28
29#include "config.h"
30
31#if USE_TERM_IO
32#include <termios.h>
33#endif
34
35#include "common/sys.h"
36#include "common/var.h"
37
38#if defined(__cplusplus)
39extern "C" {
40#endif
41
42/**
43 * @ingroup dev_g
44 * @struct pt_t
45 * point
46 */
47typedef struct {
48 double x, y;
49} pt_t;
50
51/**
52 * @ingroup dev_g
53 * @struct ipt_t
54 * point of integers
55 */
56typedef struct {
57 int32_t x, y;
58} ipt_t;
59
60/**
61 * @ingroup dev_g
62 *
63 * Bresenham's algorithm. For graphics drivers that has no lines, like term and SDL.
64 *
65 * @param x1 line coordinates
66 * @param y1 line coordinates
67 * @param x2 line coordinates
68 * @param y2 line coordinates
69 * @param dotproc setpixel() function
70 */
71void g_line(int x1, int y1, int x2, int y2, void (*dotproc) (int, int));
72
73/*
74 *
75 * colors - VGA16 compatible
76 *
77 * There are 16 colors. The second set of 8 colors its the high-light of the first set.
78 * Example:
79 * dark gray its CLR_BLACK+8
80 * light green its CLR_GREEN+8
81 * yellow its CLR_BROWN+8
82 */
83#define CLR_BLACK 0
84#define CLR_BLUE 1
85#define CLR_GREEN 2
86#define CLR_CYAN 3
87#define CLR_RED 4
88#define CLR_MAGENTA 5
89#define CLR_BROWN 6
90#define CLR_GRAY 7
91#define CLR_WHITE 15
92
93/**
94 * @ingroup dev
95 *
96 * @page glob_dev_var System driver global variables
97 *
98 * Globals are needed for speed and for memory-usage optimization
99 *
100 * @code
101 * byte os_charset; // System's charset (see os_charset_codes)
102 * uint32_t os_color_depth; // The number of bits of the supported colors
103 * // (i.e.: 8 for 256 colors, 15 or 16 for 64K, 24 or 32 for 1.6M)
104 * byte os_graphics; // Non-zero if the driver supports graphics
105 * int os_graf_mx; // Graphic mode: screen width
106 * int os_graf_my; // Graphic mode: screen height
107 * int32_t dev_Vx1, dev_Vy1, dev_Vx2, dev_Vy2;
108 * int32_t dev_Vdx, dev_Vdy; // Graphics - viewport
109 * int32_t dev_Wx1, dev_Wy1, dev_Wx2, dev_Wy2;
110 * int32_t dev_Wdx, dev_Wdy; // Graphics - window world coordinates
111 * long dev_fgcolor, dev_bgcolor; // Graphics - current colors
112 * @endcode
113 */
114
115/**
116 * @ingroup dev
117 * @enum os_charset_codes Charsets
118 */
119enum os_charset_codes {
120 enc_utf8, /**< 8bit - All European languages - default */
121 enc_sjis, /**< Japanese characters support */
122 enc_big5, /**< Chinese characters support */
123 enc_gmb, /**< Generic multibyte */
124 enc_unicode /**< Unicode */
125};
126
127#if !defined(DEVICE_MODULE)
128extern byte os_charset;
129
130extern byte os_color; // true if the output has real colors (256+ colors)
131extern uint32_t os_color_depth; // the number of bits of the supported colors
132 // (ex: 8 for 256 colors, 15 or 16 for 64K, 24 or 32 for 1.6M)
133extern byte os_graphics; // non-zero if the driver supports graphics
134extern int os_graf_mx; // graphic mode: maximum x
135extern int os_graf_my; // graphic mode: maximum y
136
137// graphics - viewport
138extern int32_t dev_Vx1;
139extern int32_t dev_Vy1;
140extern int32_t dev_Vx2;
141extern int32_t dev_Vy2;
142
143extern int32_t dev_Vdx;
144extern int32_t dev_Vdy;
145
146// graphics - window world coordinates
147extern int32_t dev_Wx1;
148extern int32_t dev_Wy1;
149extern int32_t dev_Wx2;
150extern int32_t dev_Wy2;
151
152extern int32_t dev_Wdx;
153extern int32_t dev_Wdy;
154
155// graphics - current colors
156extern long dev_fgcolor;
157extern long dev_bgcolor;
158
159#endif
160
161/*
162 *
163 * Driver basics
164 *
165 */
166
167/**
168 * @ingroup dev
169 *
170 * initialize OS drivers
171 *
172 * @param mode non-zero for graphics
173 * @param flags zero for normal (internal flags for reinitialize, used by win32 driver)
174 * @return non-zero on success
175 */
176int dev_init(int mode, int flags);
177
178/**
179 * @ingroup dev
180 *
181 * close the driver and restore computer mode
182 *
183 * @return non-zero on success
184 */
185int dev_restore(void);
186
187/*
188 *
189 * System basics
190 *
191 */
192
193/**
194 * @ingroup dev_i
195 *
196 * Internal keyboard buffer: store a key into the buffer
197 *
198 * @param ch the key-code
199 */
200void dev_pushkey(uint32_t ch);
201
202/**
203 * @ingroup dev_i
204 *
205 * Internal keyboard buffer: returns true if there is a key
206 *
207 * @return non-zero if there is a key on keyboard-buffer
208 */
209int dev_kbhit(void);
210
211/**
212 * @ingroup dev_i
213 *
214 * Internal keyboard buffer: clears keyboard buffer
215 */
216void dev_clrkb(void);
217
218/**
219 * @ingroup dev
220 *
221 * run process
222 *
223 * @param prog is the command-line
224 * @param v when non NULL, wait and return the process result
225 * @param wait bool whether to detach or wait for the process result
226 * @return non-zero on success
227 */
228int dev_run(const char *src, var_t *v, int wait);
229
230/**
231 * @ingroup dev
232 *
233 * Check's the system events queue
234 *
235 * a) stores keys into the keyboard buffer,
236 * b) store pen/mouse events,
237 * c) any other supported device.
238 *
239 * @param dead_loop
240 * if dead_loop is zero, the dev_events() will checks the events and then will return immediatly.
241 * if dead_loop is true, the dev_events() will wait for a new event.
242 *
243 * @return
244 * 0 if there is not new events in the queue.
245 * >0 the number of the new events.
246 * -1 that means BREAK (brun_break() it was called).
247 * -2 that means BREAK (executor displays "BREAK" message).
248 */
249int dev_events(int dead_loop);
250
251/**
252 * @ingroup dev
253 *
254 * delay for 'ms' milliseconds
255 *
256 * @param ms the milliseconds to pause
257 */
258void dev_delay(uint32_t ms);
259
260/**
261 * @ingroup dev_i
262 *
263 * Mouse & lightpen!
264 *
265 * Since 1988 the mouse was an new device for PC's, there is no mouse support on QB.
266 *
267 * <pre>
268 PEN, Lightpen & Mouse API
269 ================================
270 PEN(0) -> true (non zero) if there is a new pen or mouse event
271 PEN(1) -> PEN: last pen-down x; MOUSE: last mouse button down x
272 PEN(2) -> PEN: last pen-down y; MOUSE: last mouse button down y
273 PEN(3) -> QB compatiblity, don't use it
274 PEN(4) -> PEN: last/current x, MOUSE: the current x position only
275 if the left mouse button is pressed (like PEN is down)
276 PEN(5) -> PEN: last/current y, MOUSE: the current y position only
277 if the left mouse button is pressed (like PEN is down)
278 PEN(6) -> QB compatiblity, don't use it
279 PEN(7) -> QB compatiblity, don't use it
280 PEN(8) -> QB compatiblity, don't use it
281 PEN(9) -> QB compatiblity, don't use it
282
283 Mouse buttons:
284 PEN(10) -> current mouse x position
285 PEN(11) -> current mouse y position
286 PEN(12) -> true if the left mouse button is pressed
287 PEN(13) -> true if the right mouse button is pressed
288 PEN(14) -> true if the middle mouse button is pressed
289 * </pre>
290 *
291 * @note The PEN(x) function
292 *
293 * @param code is the information code
294 * @return a value based on 'code'
295 */
296int dev_getpen(int code);
297
298/**
299 * @ingroup dev_i
300 *
301 * enable/disable pen/mouse driver.
302 *
303 * @note That is the PEN ON/OFF command
304 *
305 * @param enable non-zero to enable pen/mouse driver.
306 */
307void dev_setpenmode(int enable);
308
309/*
310 *
311 * terminal input/output
312 *
313 */
314
315/**
316 * @ingroup dev_g
317 *
318 * prints a string to the SB's console
319 *
320 * @param str the string
321 */
322void dev_print(const char *str);
323
324/**
325 * @ingroup dev_g
326 *
327 * prints a string by using printf-style to the SB's console
328 *
329 * @param fmt the format
330 * @param ... the format's parameters
331 */
332void dev_printf(const char *fmt, ...);
333
334/**
335 * @ingroup dev_g
336 *
337 * prints a string by using printf-style to the SB's log file/console
338 *
339 * @param fmt the format
340 * @param ... the format's parameters
341 */
342void log_printf(const char *fmt, ...);
343
344/**
345 * @ingroup dev_g
346 *
347 * stack trace logger
348 */
349void dev_log_stack(const char *keyword, int type, int line);
350
351/**
352 * @ingroup dev_g
353 *
354 * clear screen
355 */
356void dev_cls(void);
357
358/**
359 * @ingroup dev_g
360 *
361 * sets the current x, y for texts or graphics
362 *
363 * @note AT command
364 *
365 * @param x the x in pixels
366 * @param y the y in pixels
367 */
368void dev_setxy(int x, int y, int transform);
369
370/**
371 * @ingroup dev_g
372 *
373 * returns the current x position
374 *
375 * @return the current x position
376 */
377int dev_getx(void);
378
379/**
380 * @ingroup dev_g
381 *
382 * returns the current y position
383 *
384 * @return the current y position
385 */
386int dev_gety(void);
387
388/**
389 * @ingroup dev_g
390 *
391 * sets the foreground and the background color
392 *
393 * @param fg the standard VGA foreground color
394 * @param bg the standard VGA foreground color
395 */
396void dev_settextcolor(long fg, long bg);
397
398/**
399 * @ingroup dev_i
400 *
401 * waits until a key is pressed and returns its code
402 *
403 * @return the key-code
404 */
405long int dev_getch(void);
406
407/**
408 * @ingroup dev_i
409 *
410 * reads a string from the console
411 *
412 * @note part of INPUT's code
413 *
414 * @param buf the buffer to store the string
415 * @param size the size of the buffer
416 * @return the buf or NULL on ESCAPE
417 */
418char *dev_gets(char *buf, int size);
419
420/*
421 *
422 * Graphics
423 *
424 */
425
426/**
427 * @ingroup dev_g
428 *
429 * sets the viewport.
430 * the viewport is a rectangle of the screen on that all output commands are write (todays we use the word 'window' for that).
431 * the window-command will maps its coordinates on viewport.
432 *
433 * a value of 0, 0, 0, 0 will reset (the viewport and the window) to defaults (the whole screen).
434 *
435 * @param x1 left
436 * @param y1 up
437 * @param x2 right
438 * @param y2 bottom
439 */
440void dev_viewport(int x1, int y1, int x2, int y2);
441
442/**
443 * @ingroup dev_g
444 *
445 * sets the window.
446 * the window are the world-coordinates system that maps to viewport.
447 *
448 * a value of 0, 0, 0, 0 will reset to defaults (same as viewport's).
449 *
450 * @param x1 left
451 * @param y1 up
452 * @param x2 right
453 * @param y2 bottom
454 */
455void dev_window(int x1, int y1, int x2, int y2);
456
457/**
458 * @ingroup dev_g
459 *
460 * returns the width of the text in pixels
461 *
462 * @param str the text
463 * @return the width of the text in pixels
464 */
465int dev_textwidth(const char *str);
466
467/**
468 * @ingroup dev_g
469 *
470 * returns the height of the text in pixels
471 *
472 * @param str the text
473 * @return the height of the text in pixels
474 */
475int dev_textheight(const char *str);
476
477/**
478 * @ingroup dev_g
479 *
480 * sets the foreground color. if the color is >= 0 the driver uses the standard 16 VGA colors,
481 * if the color is negative, the driver it must use RGB (-color) color value.
482 *
483 * @note RGB colors are new in SB, so avoid to use because it is not supported by all the drivers yet.
484 *
485 * @param color the foreground color
486 */
487void dev_setcolor(long color);
488
489/**
490 * @ingroup dev_g
491 *
492 * sets the pixel's value
493 *
494 * @param x the x position
495 * @param y the y position
496 */
497void dev_setpixel(int x, int y);
498
499/**
500 * @ingroup dev_g
501 *
502 * Returns the pixel's value.
503 * Since in SB the basic colors are the 16 standard VGA colors,
504 * the driver must returns 0-15 if the pixel match to VGA palette
505 * or -RGB if it is not.
506 *
507 * @param x the x position
508 * @param y the y position
509 * @return the color
510 */
511long dev_getpixel(int x, int y);
512
513/**
514 * @ingroup dev_g
515 *
516 * Cohen-Sutherland clipping algorithm.
517 *
518 * @param x1 line coordinates
519 * @param y1 line coordinates
520 * @param x2 line coordinates
521 * @param y2 line coordinates
522 * @param visible non-zero if the line or part of the line is visible
523 */
524void dev_clipline(int *x1, int *y1, int *x2, int *y2, int *visible);
525
526/**
527 * @ingroup dev_g
528 *
529 * draw a line
530 *
531 * @param x1 line coordinates
532 * @param y1 line coordinates
533 * @param x2 line coordinates
534 * @param y2 line coordinates
535 */
536void dev_line(int x1, int y1, int x2, int y2);
537
538/**
539 * @ingroup dev_g
540 *
541 * draw a rectangle
542 *
543 * @param x1 upper-left corner
544 * @param y1 upper-left corner
545 * @param x2 lower-right corner
546 * @param y2 lower-right corner
547 * @param fill non-zero to fill it with foreground color
548 */
549void dev_rect(int x1, int y1, int x2, int y2, int fill);
550
551/**
552 * @ingroup dev_g
553 *
554 * draw an ellipse
555 *
556 * @param xc x-center
557 * @param yc y-center
558 * @param xr x-radius
559 * @param yr y-radius
560 * @param aspect x/y (use 1)
561 * @param fill non-zero to fill it with foreground color
562 */
563void dev_ellipse(int xc, int yc, int xr, int yr, double aspect, int fill);
564
565/**
566 * @ingroup dev_g
567 *
568 * draw an arc
569 *
570 * @param xc x-center
571 * @param yc y-center
572 * @param r radius
573 * @param as angle-start in rad
574 * @param ae angle-end in rad
575 * @param aspect x/y (use 1)
576 */
577void dev_arc(int xc, int yc, double r, double as, double ae, double aspect);
578
579/**
580 * @ingroup dev_g
581 *
582 * floodfill, fills an area with the fill-color.
583 *
584 * there are two ways for that
585 *
586 * a) the scan-until,
587 * if you use the border-color (!=-1) the fill algoritm will fill all the area that included by
588 * the specified border-color.
589 *
590 * b) the scan-while,
591 * if you don't use the border-color (=-1) the fill algoritm will fill all the area that has
592 * the same color as the getpixel(x0,y0)
593 *
594 * @param x0 the point to start
595 * @param y0 the point to start
596 * @param fill_color the color to use for fill
597 * @param border_color the color of the border, use -1 for scan-while algorithm
598 */
599void dev_ffill(uint16_t x0, uint16_t y0, long fill_color, long border_color);
600
601/**
602 * @ingroup dev_g
603 *
604 * fill poly-line with the foreground color
605 *
606 * @param pts is a table of points
607 * @param ptNum is the number of the points to use
608 */
609void dev_pfill(ipt_t *pts, int ptNum);
610
611/**
612 * @ingroup dev_g
613 *
614 * Refreshes the graphic output. When used, the drawing to the graphic
615 * output window or screen is not visible until SHOWPAGE is performed
616 */
617void dev_show_page();
618
619/*
620 *
621 * Sound
622 *
623 */
624
625/**
626 * @ingroup dev_s
627 *
628 * produce the standard system's beep :)
629 */
630void dev_beep(void);
631
632/**
633 * @ingroup dev_s
634 *
635 * plays an OGG or MP3 file
636 *
637 * @param path the path to the OGG or MP3 file
638 */
639void dev_audio(const char *path);
640
641/**
642 * @ingroup dev_s
643 *
644 * produce a tone
645 * duration in ms, volume in percent, bgplay = play on background
646 *
647 * @param freq is the frequency
648 * @param dur_ms is the duration in milliseconds
649 * @param vol_prc is the volume (0-99)
650 * @param bgplay non-zero for play the tone in background
651 */
652void dev_sound(int freq, int dur_ms, int vol_prc, int bgplay);
653
654/**
655 * @ingroup dev_f
656 *
657 * clear background sound queue
658 */
659void dev_clear_sound_queue();
660
661/*
662 *
663 * FILE SYSTEM BASICS
664 *
665 */
666/**
667 * @ingroup dev_f
668 *
669 * matches a filename
670 *
671 * @param mask is the wild-cards
672 * @param name is the filename
673 * @return non-zero on success
674 */
675int wc_match(const char *mask, char *name);
676
677/**
678 * @ingroup dev_f
679 *
680 * initialize the file-system driver
681 *
682 * @return non-zero on success
683 */
684int dev_initfs(void);
685
686/**
687 * @ingroup dev_f
688 *
689 * close file-system (closes all files and all the drivers)
690 */
691void dev_closefs(void);
692
693/**
694 * @ingroup dev_f
695 *
696 * returns true if the file exists
697 *
698 * @param file is the filename
699 * @return non-zero if file exists
700 */
701int dev_fexists(const char *file);
702
703/**
704 * @ingroup dev_f
705 *
706 * copies a file
707 *
708 * @param file is the source
709 * @param file is the target
710 * @return non-zero on success
711 */
712int dev_fcopy(const char *file, const char *newfile);
713
714/**
715 * @ingroup dev_f
716 *
717 * renames a file
718 *
719 * @param file is the source
720 * @param file is the target
721 * @return non-zero on success
722 */
723int dev_frename(const char *file, const char *newname);
724
725/**
726 * @ingroup dev_f
727 *
728 * removes a file
729 *
730 * @param file is the filename
731 * @return non-zero on success
732 */
733int dev_fremove(const char *file);
734
735/**
736 * @ingroup dev_f
737 *
738 * returns the access attributes of the file. for more info see the chmod()
739 *
740 * @param file is the filename
741 * @return the access attributes of the file
742 */
743int dev_faccess(const char *file);
744
745#define VFS_ATTR_FILE 1 /**< dev_fattr(), regular file @ingroup dev_f */
746#define VFS_ATTR_DIR 2 /**< dev_fattr(), directory @ingroup dev_f */
747#define VFS_ATTR_LINK 4 /**< dev_fattr(), symbolic-link @ingroup dev_f */
748
749/**
750 * @ingroup dev_f
751 *
752 * returns some info about the file (symbolic-link, directory, regular file).
753 *
754 * see VFS_ATTR_FILE, VFS_ATTR_DIR, VFS_ATTR_LINK
755 *
756 * @param file is the filename
757 * @return the access attributes of the file
758 */
759int dev_fattr(const char *file);
760
761/**
762 * @ingroup dev_f
763 *
764 * returns the last-modified time for a file as a string
765 *
766 * @param file is the filename
767 * @param buffer the result text
768 * @return number of characters returned in buffer
769 */
770int dev_filemtime(var_t *v, char **buffer);
771
772/*
773 *
774 * FILE I/O
775 *
776 */
777
778/**
779 * @ingroup dev_f
780 * @typedef dev_ftype_t
781 * File-type (or better, what driver to use for that file)
782 */
783typedef enum {
784 ft_stream, /**< simple file */
785 ft_serial_port, /**< COMx:speed, serial port */
786 ft_socket_client, /**< SCLT:address:port, socket client */
787 ft_socket_server, // SSVR:address:port
788 ft_http_client
789} dev_ftype_t;
790
791/**
792 * @ingroup dev_f
793 * @typedef file_t file structure
794 */
795typedef struct {
796 char name[OS_PATHNAME_SIZE + 1]; /**< the file name */
797 dev_ftype_t type; /**< the driver to use */
798 int port; /**< the port (if device) */
799 long devspeed; /**< the speed (if device) */
800 byte *drv_data; /**< driver data used by low-level driver authors, (don't forget to set it to null on close()) */
801 uint32_t drv_dw[4]; /**< driver data used by low-level driver authors */
802
803#if USE_TERM_IO
804 struct termios oldtio, newtio; /**< termios info */
805#endif
806
807 int handle; /**< the file handle */
808 int last_error; /**< the last error-code */
809 int open_flags; /**< the open()'s flags */
810} dev_file_t;
811
812// flags for dev_fopen()
813#define DEV_FILE_INPUT 1 /**< dev_fopen() flags, open file for input (read-only) @ingroup dev_f */
814#define DEV_FILE_OUTPUT 2 /**< dev_fopen() flags, open file for output (create) @ingroup dev_f */
815#define DEV_FILE_APPEND 4 /**< dev_fopen() flags, open file for append (append or create) @ingroup dev_f */
816#define DEV_FILE_EXCL 8 /**< dev_fopen() flags, open file exclusive @ingroup dev_f */
817
818/**
819 * @ingroup dev_f
820 *
821 * returns a free file handle
822 *
823 * @return a free file handle
824 */
825int dev_freefilehandle(void);
826
827/**
828 * @ingroup dev_f
829 *
830 * returns the file info for a handle
831 *
832 * @return on success the file info; otherwise returns NULL
833 */
834dev_file_t *dev_getfileptr(int handle);
835
836/**
837 * @ingroup dev_f
838 *
839 * returns true if the file is opened
840 *
841 * @return true if the file is opened
842 */
843int dev_fstatus(int handle);
844
845/**
846 * @ingroup dev_f
847 *
848 * opens a file
849 *
850 * @param SBHandle is the RTL's file-handle
851 * @param name is the filename
852 * @param flags are the flags for open-mode (see DEV_FILE_xxx macros)
853 * @returns non-zero on success
854 */
855int dev_fopen(int SBHandle, const char *name, int flags);
856
857/**
858 * @ingroup dev_f
859 *
860 * returns the size of the available data
861 *
862 * @param SBHandle is the RTL's file-handle
863 * @return the size of the available data
864 */
865uint32_t dev_flength(int SBHandle);
866
867/**
868 * @ingroup dev_f
869 *
870 * closes a file
871 *
872 * @param SBHandle is the RTL's file-handle
873 * @returns non-zero on success
874 */
875int dev_fclose(int SBHandle);
876
877/**
878 * @ingroup dev_f
879 *
880 * moves the file-position-pointer to the specified offset
881 *
882 * @param SBHandle is the RTL's file-handle
883 * @param offset the new position
884 * @returns the new position
885 */
886uint32_t dev_fseek(int SBHandle, uint32_t offset);
887
888/**
889 * @ingroup dev_f
890 *
891 * returns the file-position-pointer
892 *
893 * @param SBHandle is the RTL's file-handle
894 * @return the file-position-pointer
895 */
896uint32_t dev_ftell(int SBHandle);
897
898/**
899 * @ingroup dev_f
900 *
901 * returns the end-of-file mark
902 *
903 * @param SBHandle is the RTL's file-handle
904 * @return non-zero if eof
905 */
906int dev_feof(int SBHandle);
907
908/**
909 * @ingroup dev_f
910 *
911 * writes a buffer to the file
912 *
913 * @param SBHandle is the RTL's file-handle
914 * @param buff is the data to write
915 * @param size is the size of the data
916 * @return non-zero on success
917 */
918int dev_fwrite(int SBHandle, byte *buff, uint32_t size);
919
920/**
921 * @ingroup dev_f
922 *
923 * reads a size bytes from the file
924 *
925 * @param SBHandle is the RTL's file-handle
926 * @param buff is a memory block to store the data
927 * @param size is the number of bytes to read
928 * @return non-zero on success
929 */
930int dev_fread(int SBHandle, byte *buff, uint32_t size);
931
932/**
933 * @ingroup dev_f
934 *
935 * returns the entire file contents
936 *
937 * @param fileName the file to read
938 * @return contents of the given file
939 */
940char *dev_read(const char *fileName);
941
942/**
943 * @ingroup dev_f
944 *
945 * creates a directory
946 *
947 * @param dir is the directory
948 */
949void dev_mkdir(const char *dir);
950
951/**
952 * @ingroup dev_f
953 *
954 * removes a directory
955 *
956 * @param dir is the directory
957 */
958void dev_rmdir(const char *dir);
959
960/**
961 * @ingroup dev_f
962 *
963 * changes the current directory
964 *
965 * @param dir is the directory
966 */
967void dev_chdir(const char *dir);
968
969/**
970 * @ingroup dev_f
971 *
972 * returns the current directory
973 *
974 * @return the current directory
975 */
976char *dev_getcwd(void);
977
978/**
979 * @ingroup dev
980 *
981 * returns the value of a specified system's environment variable
982 *
983 * @param var the name of the variable
984 * @return on success the value; otherwise NULL
985 */
986const char *dev_getenv(const char *var);
987
988/**
989 * @ingroup dev
990 *
991 * returns the number of the environment variables
992 * @return the number of the environment variables
993 */
994int dev_env_count();
995
996/**
997 * @ingroup dev
998 *
999 * returns the value of the nth system's environment variable
1000 *
1001 * @param n the index of the variable
1002 * @return on success the value; otherwise NULL
1003 */
1004const char *dev_getenv_n(int n);
1005
1006/**
1007 * @ingroup dev
1008 *
1009 * sets a system environment variable
1010 *
1011 * @param key the key to set
1012 * @param value the value to set
1013 * @return non-zero on success
1014 */
1015int dev_setenv(const char *key, const char *value);
1016
1017/**
1018 * @ingroup dev_f
1019 *
1020 * creates a list of filenames using wild-cards
1021 *
1022 * @param wc is the wild-cards string
1023 * @param count is the number of the elements (returned)
1024 * @return a char** array
1025 */
1026char_p_t *dev_create_file_list(const char *wc, int *count);
1027
1028/**
1029 * @ingroup dev_f
1030 *
1031 * destroys a file-list which was created with dev_create_file_list
1032 *
1033 * @param list is the char** array
1034 * @param count is the number of the elements
1035 */
1036void dev_destroy_file_list(char_p_t *list, int count);
1037
1038/**
1039 * @ingroup dev_f
1040 *
1041 * Returns the number of milliseconds that has passed since
1042 * some unknown point in time.
1043 */
1044uint32_t dev_get_millisecond_count();
1045
1046/**
1047 * @ingroup dev_f
1048 *
1049 * Trace or debug at the given line number
1050 */
1051void dev_trace_line(int lineNo);
1052
1053/**
1054 * @ingroup sys
1055 *
1056 * print a message and quits
1057 *
1058 * @param fmt the printf's style format
1059 * @param ... the format's parameters
1060 */
1061void panic(const char *fmt, ...);
1062
1063/**
1064 * @ingroup sys
1065 *
1066 * write to logfile
1067 *
1068 * @param buf is the string to write
1069 */
1070void lwrite(const char *buf);
1071
1072/**
1073 * @ingroup dev
1074 *
1075 * resize the window coordinate system
1076 */
1077void dev_resize(int width, int height);
1078
1079/**
1080 * @ingroup dev
1081 *
1082 * adjust the point to the window coordinate system
1083 */
1084void dev_map_point(int *x, int *y);
1085
1086#if defined(__cplusplus)
1087}
1088#endif
1089#endif
1090