├── .gitignore ├── README.md ├── android ├── io_mouse.bas ├── io_multikey.bas ├── io_serial.bas ├── sys_fmem.bas ├── sys_getexename.bas ├── sys_getexepath.bas └── sys_portio.bas ├── array_boundchk.bas ├── array_clear.bas ├── array_clearobj.bas ├── array_core.bas ├── array_destructobj.bas ├── array_destructstr.bas ├── array_erase.bas ├── array_eraseobj.bas ├── array_erasestr.bas ├── array_getdesc.bas ├── array_lbound.bas ├── array_redim.bas ├── array_redim_obj.bas ├── array_redimpresv.bas ├── array_redimpresv_obj.bas ├── array_redimto.bas ├── array_resetdesc.bas ├── array_ubound.bas ├── con_input.bas ├── con_lineinp.bas ├── con_lineinp_wstr.bas ├── con_locate.bas ├── con_pos.bas ├── con_print_raw.bas ├── con_print_raw_uni.bi ├── con_print_raw_wstr.bas ├── con_print_tty.bas ├── con_print_tty_uni.bi ├── con_print_tty_wstr.bas ├── con_readline.bas ├── crt_extra ├── signal.bi ├── stdio.bi ├── stdlib.bi ├── string.bi ├── sys │ └── stat.bi └── wctype.bi ├── darwin ├── io_mouse.bas ├── io_multikey.bas ├── io_serial.bas ├── sys_fmem.bas ├── sys_getexename.bas └── sys_getexepath.bas ├── data.bas ├── data_readbool.bas ├── data_readbyte.bas ├── data_readdouble.bas ├── data_readint.bas ├── data_readlong.bas ├── data_readshort.bas ├── data_readsingle.bas ├── data_readstr.bas ├── data_readubyte.bas ├── data_readuint.bas ├── data_readulong.bas ├── data_readushort.bas ├── data_readwstr.bas ├── dev_com.bas ├── dev_com_private.bi ├── dev_com_test.bas ├── dev_cons_open.bas ├── dev_err_open.bas ├── dev_file_close.bas ├── dev_file_encod_open.bas ├── dev_file_encod_read.bas ├── dev_file_encod_read_core.bas ├── dev_file_encod_read_wstr.bas ├── dev_file_encod_readline.bas ├── dev_file_encod_readline_wstr.bas ├── dev_file_encod_write.bas ├── dev_file_encod_write_wstr.bas ├── dev_file_eof.bas ├── dev_file_flush.bas ├── dev_file_lock.bas ├── dev_file_open.bas ├── dev_file_read.bas ├── dev_file_read_wstr.bas ├── dev_file_readline.bas ├── dev_file_readline_wstr.bas ├── dev_file_seek.bas ├── dev_file_size.bas ├── dev_file_tell.bas ├── dev_file_unlock.bas ├── dev_file_write.bas ├── dev_file_write_wstr.bas ├── dev_lpt.bas ├── dev_lpt_close.bas ├── dev_lpt_test.bas ├── dev_lpt_write.bas ├── dev_lpt_write_wstr.bas ├── dev_pipe_close.bas ├── dev_pipe_open.bas ├── dev_scrn.bas ├── dev_scrn_close.bas ├── dev_scrn_eof.bas ├── dev_scrn_init.bas ├── dev_scrn_read.bas ├── dev_scrn_read_wstr.bas ├── dev_scrn_readline.bas ├── dev_scrn_readline_wstr.bas ├── dev_scrn_write.bas ├── dev_scrn_write_wstr.bas ├── dev_stdio_close.bas ├── dos ├── dos_private_thread.bi ├── fb_dos.bi ├── thread_cond.bas ├── thread_core.bas └── thread_mutex.bas ├── error.bas ├── error_assert.bas ├── error_assert_wstr.bas ├── error_getset.bas ├── error_message.bas ├── error_ptrchk.bas ├── fb.bi ├── fb_array.bi ├── fb_config.bi ├── fb_console.bi ├── fb_data.bi ├── fb_datetime.bi ├── fb_device.bi ├── fb_error.bi ├── fb_file.bi ├── fb_gfx_private.bi ├── fb_hook.bi ├── fb_legacy.bi ├── fb_math.bi ├── fb_oop.bi ├── fb_print.bi ├── fb_printer.bi ├── fb_private_error.bi ├── fb_private_file.bi ├── fb_private_hdynload.bi ├── fb_private_thread.bi ├── fb_profile.bi ├── fb_serial.bi ├── fb_string.bi ├── fb_system.bi ├── fb_thread.bi ├── fb_unicode.bi ├── file_attr.bas ├── file_close.bas ├── file_copy_crt.bas ├── file_datetime.bas ├── file_dir64.bas ├── file_dirnext.bas ├── file_dirnext64.bas ├── file_encod.bas ├── file_eof.bas ├── file_exists.bas ├── file_flush.bas ├── file_free.bas ├── file_get.bas ├── file_get_wstr.bas ├── file_getarray.bas ├── file_getstr.bas ├── file_hconvpath.bas ├── file_input_bool.bas ├── file_input_byte.bas ├── file_input_file.bas ├── file_input_float.bas ├── file_input_int.bas ├── file_input_longint.bas ├── file_input_short.bas ├── file_input_str.bas ├── file_input_tok.bas ├── file_input_tok_wstr.bas ├── file_input_ubyte.bas ├── file_input_uint.bas ├── file_input_ulongint.bas ├── file_input_ushort.bas ├── file_input_wstr.bas ├── file_inputstr.bas ├── file_kill.bas ├── file_len.bas ├── file_lineinp.bas ├── file_lineinp_wstr.bas ├── file_loc.bas ├── file_lock.bas ├── file_open.bas ├── file_opencom.bas ├── file_opencons.bas ├── file_openencod.bas ├── file_openerr.bas ├── file_openlpt.bas ├── file_openpipe.bas ├── file_openscrn.bas ├── file_openshort.bas ├── file_print.bas ├── file_print_wstr.bas ├── file_put.bas ├── file_put_wstr.bas ├── file_putarray.bas ├── file_putback.bas ├── file_putback_wstr.bas ├── file_putstr.bas ├── file_reset.bas ├── file_resetex.bas ├── file_seek.bas ├── file_seteof.bas ├── file_size.bas ├── file_tell.bas ├── file_winputstr.bas ├── freebsd ├── io_mouse.bas ├── io_multikey.bas ├── io_serial.bas ├── sys_fmem.bas ├── sys_getexename.bas └── sys_getexepath.bas ├── gosub.bas ├── hook_cls.bas ├── hook_color.bas ├── hook_getmouse.bas ├── hook_getmouse64.bas ├── hook_getsize.bas ├── hook_getx.bas ├── hook_getxy.bas ├── hook_gety.bas ├── hook_inkey.bas ├── hook_isredir.bas ├── hook_lineinp.bas ├── hook_lineinp_wstr.bas ├── hook_locate_ex.bas ├── hook_multikey.bas ├── hook_pageset.bas ├── hook_pcopy.bas ├── hook_ports.bas ├── hook_print_wstr.bas ├── hook_printstr.bas ├── hook_readstr.bas ├── hook_readxy.bas ├── hook_setmouse.bas ├── hook_sleep.bas ├── hook_view_update.bas ├── hook_width.bas ├── init.bas ├── intl_get.bas ├── intl_getdateformat.bas ├── intl_getmonthname.bas ├── intl_getset.bas ├── intl_gettimeformat.bas ├── intl_getweekdayname.bas ├── io_hinkey.bas ├── io_lpos.bas ├── io_lprint_bool.bas ├── io_lprint_byte.bas ├── io_lprint_fix.bas ├── io_lprint_fp.bas ├── io_lprint_int.bas ├── io_lprint_longint.bas ├── io_lprint_short.bas ├── io_lprint_str.bas ├── io_lprint_wstr.bas ├── io_lprintusg.bas ├── io_lprintvoid.bas ├── io_print.bas ├── io_print_bool.bas ├── io_print_byte.bas ├── io_print_fix.bas ├── io_print_fp.bas ├── io_print_int.bas ├── io_print_longint.bas ├── io_print_short.bas ├── io_print_wstr.bas ├── io_printpad.bas ├── io_printpad_wstr.bas ├── io_printusg.bas ├── io_printvoid.bas ├── io_printvoid_wstr.bas ├── io_serial_private.bi ├── io_setpos.bas ├── io_spc.bas ├── io_view.bas ├── io_viewhlp.bas ├── io_widthdev.bas ├── io_widthfile.bas ├── io_write_wstr.bas ├── io_writebool.bas ├── io_writebyte.bas ├── io_writefloat.bas ├── io_writeint.bas ├── io_writelongint.bas ├── io_writeshort.bas ├── io_writestr.bas ├── io_writevoid.bas ├── legacy_str_lcase.bas ├── legacy_str_ucase.bas ├── legacy_strw_lcase.bas ├── legacy_strw_ucase.bas ├── license.txt ├── linux ├── io_mouse.bas ├── io_multikey.bas ├── io_serial.bas ├── sys_fmem.bas ├── sys_getexename.bas ├── sys_getexepath.bas └── sys_portio.bas ├── list.bas ├── listdyn.bas ├── makefile ├── math_cvn.bas ├── math_fix.bas ├── math_frac.bas ├── math_log10.bas ├── math_rnd.bas ├── math_sgn.bas ├── mem_copyclear.bas ├── netbsd ├── io_mouse.bas ├── io_multikey.bas ├── io_serial.bas ├── sys_fmem.bas ├── sys_getexename.bas └── sys_getexepath.bas ├── oop_istypeof.bas ├── oop_object.bas ├── oop_object_copyctor.bas ├── profile.bas ├── profile_calls.bas ├── profile_cycles.bas ├── qb_file_open.bas ├── qb_inkey.bas ├── qb_sleep.bas ├── qb_str_convto.bas ├── qb_str_convto_flt.bas ├── qb_str_convto_lng.bas ├── scancodes.bas ├── signals.bas ├── static ├── fbrt0.bas ├── fbrt1.bas └── fbrt2.bas ├── str_asc.bas ├── str_assign.bas ├── str_base.bas ├── str_bin.bas ├── str_bin_lng.bas ├── str_bin_ptr.bas ├── str_chr.bas ├── str_comp.bas ├── str_concat.bas ├── str_concatassign.bas ├── str_concatbyref.bas ├── str_convfrom.bas ├── str_convfrom_bool.bas ├── str_convfrom_int.bas ├── str_convfrom_lng.bas ├── str_convfrom_rad.bas ├── str_convfrom_radlng.bas ├── str_convfrom_uint.bas ├── str_convfrom_ulng.bas ├── str_convto.bas ├── str_convto_bool.bas ├── str_convto_flt.bas ├── str_convto_lng.bas ├── str_core.bas ├── str_cvmk.bas ├── str_del.bas ├── str_fill.bas ├── str_format.bas ├── str_ftoa.bas ├── str_hex.bas ├── str_hex_lng.bas ├── str_hex_ptr.bas ├── str_hskip.bas ├── str_instr.bas ├── str_instrany.bas ├── str_instrrev.bas ├── str_instrrevany.bas ├── str_lcase.bas ├── str_left.bas ├── str_leftself.bas ├── str_len.bas ├── str_ltrim.bas ├── str_ltrimany.bas ├── str_ltrimex.bas ├── str_mid.bas ├── str_midassign.bas ├── str_misc.bas ├── str_oct.bas ├── str_oct_lng.bas ├── str_oct_ptr.bas ├── str_right.bas ├── str_rtrim.bas ├── str_rtrimany.bas ├── str_rtrimex.bas ├── str_set.bas ├── str_tempdescf.bas ├── str_tempdescv.bas ├── str_tempdescz.bas ├── str_tempres.bas ├── str_trim.bas ├── str_trimany.bas ├── str_trimex.bas ├── str_ucase.bas ├── strw_alloc.bas ├── strw_asc.bas ├── strw_assign.bas ├── strw_bin.bas ├── strw_bin_lng.bas ├── strw_bin_ptr.bas ├── strw_chr.bas ├── strw_comp.bas ├── strw_concat.bas ├── strw_concatassign.bas ├── strw_convassign.bas ├── strw_convconcat.bas ├── strw_convfrom.bas ├── strw_convfrom_bool.bas ├── strw_convfrom_int.bas ├── strw_convfrom_lng.bas ├── strw_convfrom_rad.bas ├── strw_convfrom_radlng.bas ├── strw_convfrom_str.bas ├── strw_convfrom_uint.bas ├── strw_convfrom_ulng.bas ├── strw_convto.bas ├── strw_convto_bool.bas ├── strw_convto_flt.bas ├── strw_convto_lng.bas ├── strw_convto_str.bas ├── strw_del.bas ├── strw_fill.bas ├── strw_ftoa.bas ├── strw_hex.bas ├── strw_hex_lng.bas ├── strw_hex_ptr.bas ├── strw_instr.bas ├── strw_instrany.bas ├── strw_instrrev.bas ├── strw_instrrevany.bas ├── strw_lcase.bas ├── strw_left.bas ├── strw_len.bas ├── strw_ltrim.bas ├── strw_ltrimany.bas ├── strw_ltrimex.bas ├── strw_mid.bas ├── strw_midassign.bas ├── strw_oct.bas ├── strw_oct_lng.bas ├── strw_oct_ptr.bas ├── strw_right.bas ├── strw_rtrim.bas ├── strw_rtrimany.bas ├── strw_rtrimex.bas ├── strw_set.bas ├── strw_space.bas ├── strw_trim.bas ├── strw_trimany.bas ├── strw_trimex.bas ├── strw_ucase.bas ├── swap_mem.bas ├── swap_str.bas ├── swap_wstr.bas ├── sys_cdir.bas ├── sys_chain.bas ├── sys_chdir.bas ├── sys_cmd.bas ├── sys_environ.bas ├── sys_exec.bas ├── sys_exepath.bas ├── sys_mkdir.bas ├── sys_parseargs.bas ├── sys_rmdir.bas ├── sys_run.bas ├── sys_shell.bas ├── thread_call.bas ├── thread_create.bas ├── thread_ctx.bas ├── thread_detach.bas ├── thread_obj.bas ├── thread_self.bas ├── thread_wait.bas ├── time_core.bas ├── time_date.bas ├── time_dateadd.bas ├── time_datediff.bas ├── time_datepart.bas ├── time_dateserial.bas ├── time_dateset.bas ├── time_datevalue.bas ├── time_decodeserdate.bas ├── time_decodesertime.bas ├── time_isdate.bas ├── time_monthname.bas ├── time_now.bas ├── time_parsedate.bas ├── time_parsedatetime.bas ├── time_parsetime.bas ├── time_sleep.bas ├── time_sleepex.bas ├── time_time.bas ├── time_timeserial.bas ├── time_timeset.bas ├── time_timevalue.bas ├── time_week.bas ├── time_weekdayname.bas ├── unix ├── drv_intl_get.bas ├── drv_intl_getdateformat.bas ├── drv_intl_getmonthname.bas ├── drv_intl_gettimeformat.bas ├── drv_intl_getweekdayname.bas ├── fb_private_console.bi ├── fb_private_scancodes_x11.bi ├── fb_unix.bi ├── file_copy.bas ├── file_dir.bas ├── file_hflush.bas ├── file_hlock.bas ├── file_hreset.bas ├── file_hseteof.bas ├── hdynload.bas ├── hinit.bas ├── hinit_enable_vt100_escapes.bas ├── io_cls.bas ├── io_color.bas ├── io_getsize.bas ├── io_getx.bas ├── io_getxy.bas ├── io_gety.bas ├── io_inkey.bas ├── io_input.bas ├── io_isredir.bas ├── io_locate.bas ├── io_maxrow.bas ├── io_pageset.bas ├── io_pcopy.bas ├── io_printbuff.bas ├── io_printbuff_wstr.bas ├── io_printer.bas ├── io_readstr.bas ├── io_readxy.bas ├── io_scroll.bas ├── io_viewupdate.bas ├── io_width.bas ├── io_xfocus.bas ├── scancodes_x11.bas ├── sys_beep.bas ├── sys_delay.bas ├── sys_dylib.bas ├── sys_execex.bas ├── sys_getcwd.bas ├── sys_hshell.bas ├── thread_cond.bas ├── thread_core.bas ├── thread_mutex.bas ├── time_setdate.bas ├── time_settime.bas ├── time_timer.bas └── unix_private_thread.bi ├── utf_convfrom_char.bas ├── utf_convfrom_wchar.bas ├── utf_convto_char.bas ├── utf_convto_wchar.bas ├── utf_core.bas ├── vfs_open.bas ├── win32 ├── .gitignore ├── drv_intl_get.bas ├── drv_intl_getdateformat.bas ├── drv_intl_getmonthname.bas ├── drv_intl_gettimeformat.bas ├── drv_intl_getweekdayname.bas ├── fb_private_console.bi ├── fb_private_intl.bi ├── fb_win32.bi ├── fbportio.bi ├── fbportio_inline.bi ├── file_copy.bas ├── file_dir.bas ├── file_hflush.bas ├── file_hlock.bas ├── file_hreset.bas ├── file_hseteof.bas ├── hdynload.bas ├── hinit.bas ├── intl_core.bas ├── io_cls.bas ├── io_color.bas ├── io_gethnd.bas ├── io_getsize.bas ├── io_getx.bas ├── io_getxy.bas ├── io_gety.bas ├── io_inkey.bas ├── io_input.bas ├── io_isredir.bas ├── io_locate.bas ├── io_maxrow.bas ├── io_mouse.bas ├── io_multikey.bas ├── io_pageset.bas ├── io_pcopy.bas ├── io_printbuff.bas ├── io_printbuff_wstr.bas ├── io_printer.bas ├── io_printer_private.bi ├── io_readstr.bas ├── io_readxy.bas ├── io_screensize.bas ├── io_scroll.bas ├── io_serial.bas ├── io_viewupdate.bas ├── io_width.bas ├── io_window.bas ├── sys_beep.bas ├── sys_delay.bas ├── sys_dylib.bas ├── sys_execex.bas ├── sys_fmem.bas ├── sys_getcwd.bas ├── sys_getexename.bas ├── sys_getexepath.bas ├── sys_getshortpath.bas ├── sys_hshell.bas ├── sys_portio.bas ├── thread_cond.bas ├── thread_core.bas ├── thread_mutex.bas ├── time_setdate.bas ├── time_settime.bas ├── time_timer.bas └── win32_private_thread.bi └── x86 └── cpudetect.bas /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.asm 3 | *.wfbe 4 | *.o 5 | /obj/ 6 | /lib/ 7 | -------------------------------------------------------------------------------- /android/io_mouse.bas: -------------------------------------------------------------------------------- 1 | /' console mode mouse functions '/ 2 | 3 | #include "../fb.bi" 4 | 5 | extern "C" 6 | function fb_ConsoleGetMouse( x as long ptr, y as long ptr, z as long ptr, buttons as long ptr, clip as long ptr ) as long 7 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 8 | end function 9 | 10 | function fb_ConsoleSetMouse( x as long, y as long, cursor as long, clip as long ) as long 11 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 12 | end function 13 | end extern -------------------------------------------------------------------------------- /android/io_multikey.bas: -------------------------------------------------------------------------------- 1 | /' console multikey() '/ 2 | 3 | #include "../fb.bi" 4 | 5 | extern "C" 6 | function fb_ConsoleMultikey ( scancode as long ) as long 7 | fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 8 | return FB_FALSE 9 | end function 10 | end extern -------------------------------------------------------------------------------- /android/sys_fmem.bas: -------------------------------------------------------------------------------- 1 | /' fre() function '/ 2 | 3 | #include "../fb.bi" 4 | #include "crt/unistd.bi" 5 | 6 | extern "C" 7 | function fb_GetMemAvail FBCALL ( mode as long ) as size_t 8 | return sysconf(_SC_AVPHYS_PAGES) * sysconf(_SC_PAGE_SIZE) 9 | end function 10 | end extern 11 | -------------------------------------------------------------------------------- /android/sys_getexename.bas: -------------------------------------------------------------------------------- 1 | /' get the executable's name '/ 2 | 3 | #include "../fb.bi" 4 | #include "crt/sys/stat.bi" 5 | 6 | extern"C" 7 | function fb_hGetExeName( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 8 | dim as ubtye ptr p 9 | dim as ubyte linkname(0 to 10243) 10 | dim as stat finfo 11 | dim as ssize_t _len 12 | 13 | sprintf(linkname, "/proc/%d/exe", getpid()) 14 | if stat(linkname, @finfo) = 0 and _len = readlink(linkname, dst, maxlen - 1) > -1 then 15 | /' Linux-like proc fs is available '/ 16 | dst[_len] = "\0" 17 | p = strrchr(dst, "/") 18 | if (p <> NULL) 19 | p += 1 20 | else 21 | p = dst 22 | end if 23 | else 24 | p = NULL 25 | end if 26 | 27 | return p 28 | end function 29 | end extern -------------------------------------------------------------------------------- /android/sys_getexepath.bas: -------------------------------------------------------------------------------- 1 | /' get the executable path '/ 2 | 3 | #include "../fb.bi" 4 | #include "crt/sys/stat.bi" 5 | 6 | extern "C" 7 | function fb_hGetExePath( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 8 | dim as ubyte ptr char 9 | dim as stat finfo 10 | dim as ssize_t _len 11 | 12 | if (stat("/proc/self/exe", @finfo) == 0) and (_len = readlink("/proc/self/exe", dst, maxlen - 1)) > -1 then 13 | /' Linux-like proc fs is available. But if running from an app this uselessly points at /system/bin. '/ 14 | dst[_len] = "\0" 15 | p = strrchr(dst, "/") 16 | if p = dst then /' keep the "/" rather than returning "" '/ 17 | *(p + 1) = "\0" 18 | else if (p) then 19 | *p = "\0" 20 | else 21 | dst[0] = "\0" 22 | end if 23 | else 24 | p = NULL 25 | end if 26 | 27 | return p 28 | end function 29 | end extern -------------------------------------------------------------------------------- /android/sys_portio.bas: -------------------------------------------------------------------------------- 1 | /' ports I/O functions '/ 2 | 3 | #include "../fb.bi" 4 | 5 | extern "C" 6 | function fb_hIn( port as ushort ) as long 7 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 8 | end function 9 | 10 | function fb_hOut( port as ushot, value as ubyte ) as long 11 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 12 | end function 13 | end extern -------------------------------------------------------------------------------- /array_destructobj.bas: -------------------------------------------------------------------------------- 1 | /' ERASE for dynamic arrays of objects: destruct elements and free the array '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_hArrayDtorObj ( array as FBARRAY ptr, dtor as FB_DEFCTOR, keep_idx as size_t ) 7 | dim as size_t elements, element_len 8 | dim as ubyte ptr this_ 9 | 10 | if ( array->_ptr = NULL ) then 11 | exit sub 12 | end if 13 | 14 | elements = fb_ArrayLen( array ) 15 | 16 | /' call dtors in the inverse order '/ 17 | element_len = array->element_len 18 | this_ = cast(ubyte ptr, (array->_ptr)) + ((elements - 1) * element_len) 19 | 20 | while( elements > keep_idx ) 21 | /' !!!FIXME!!! check exceptions (only if rewritten in C++) '/ 22 | dtor( this_ ) 23 | this_ -= element_len 24 | elements -= 1 25 | wend 26 | end sub 27 | 28 | sub fb_ArrayDestructObj FBCALL ( array as FBARRAY ptr, dtor as FB_DEFCTOR ) 29 | fb_hArrayDtorObj( array, dtor, 0 ) 30 | end sub 31 | end extern -------------------------------------------------------------------------------- /array_destructstr.bas: -------------------------------------------------------------------------------- 1 | /' ERASE for dynamic arrays of var-len strings '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_hArrayDtorStr ( array as FBARRAY ptr, dtor as FB_DEFCTOR, keep_idx as size_t ) 7 | dim as size_t elements 8 | dim as FBSTRING ptr this_ 9 | 10 | if ( array->_ptr = NULL ) then 11 | exit sub 12 | end if 13 | 14 | elements = fb_ArrayLen( array ) 15 | 16 | /' call dtors in the inverse order '/ 17 | this_ = cast(FBSTRING ptr, array->_ptr) + (elements-1) 18 | 19 | while( elements > keep_idx ) 20 | if ( this_->data <> NULL ) then 21 | fb_StrDelete( this_ ) 22 | end if 23 | this_ -= 1 24 | elements -= 1 25 | wend 26 | end sub 27 | 28 | sub fb_ArrayDestructStr FBCALL ( array as FBARRAY ptr ) 29 | fb_hArrayDtorStr( array, NULL, 0 ) 30 | end sub 31 | end extern -------------------------------------------------------------------------------- /array_eraseobj.bas: -------------------------------------------------------------------------------- 1 | /' ERASE for dynamic arrays of objects: destruct elements and free the array '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_ArrayEraseObj FBCALL ( array as FBARRAY ptr, ctor as FB_DEFCTOR, dtor as FB_DEFCTOR ) as long 7 | 8 | if( (array->flags and FBARRAY_FLAGS_FIXED_LEN) <> 0 ) then 9 | fb_ArrayClearObj( array, ctor, dtor ) 10 | else 11 | if( dtor ) then 12 | fb_ArrayDestructObj( array, dtor ) 13 | end if 14 | fb_ArrayErase( array ) 15 | end if 16 | 17 | return fb_ErrorSetNum( FB_RTERROR_OK ) 18 | 19 | end function 20 | end extern 21 | -------------------------------------------------------------------------------- /array_erasestr.bas: -------------------------------------------------------------------------------- 1 | /' ERASE for dynamic arrays of var-len strings '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_ArrayStrErase FBCALL ( array as FBARRAY ptr ) 7 | 8 | fb_ArrayDestructStr( array ) 9 | 10 | /' only free the memory if it's not a fixed length array '/ 11 | if( array andalso ( ( array->flags and FBARRAY_FLAGS_FIXED_LEN ) = 0 ) ) then 12 | fb_ArrayErase( array ) 13 | end if 14 | 15 | end sub 16 | end extern -------------------------------------------------------------------------------- /array_getdesc.bas: -------------------------------------------------------------------------------- 1 | /' fbc-int API: array descriptor internals '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "c" 6 | function fb_ArrayGetDesc FBCALL ( array as FBARRAY ptr ) as FBARRAY ptr 7 | return array 8 | end function 9 | end extern 10 | -------------------------------------------------------------------------------- /array_redim_obj.bas: -------------------------------------------------------------------------------- 1 | /' redim function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_ArrayRedimObj ( array as FBARRAY ptr, element_len as size_t, ctor as FB_DEFCTOR, dtor as FB_DEFCTOR,dimensions as size_t, ... ) as long 7 | dim as cva_list ap 8 | dim as long res 9 | 10 | /' free old '/ 11 | if ( dtor <> NULL ) then 12 | fb_ArrayDestructObj( array, dtor ) 13 | end if 14 | fb_ArrayErase( array ) 15 | 16 | cva_start( ap, dimensions ) 17 | /' Have to assume doclear=TRUE, because we have no doclear parameter here, 18 | and don't know what to do, so better be safe. '/ 19 | res = fb_hArrayAlloc( array, element_len, TRUE, ctor, dimensions, ap ) 20 | cva_end( ap ) 21 | 22 | return res 23 | end function 24 | end extern -------------------------------------------------------------------------------- /array_redimpresv_obj.bas: -------------------------------------------------------------------------------- 1 | /' redim preserve function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_ArrayRedimPresvObj ( array as FBARRAY ptr, element_len as size_t, ctor as FB_DEFCTOR, dtor as FB_DEFCTOR, dimensions as size_t, ... ) as long 7 | dim as cva_list ap 8 | dim as long res 9 | 10 | cva_start( ap, dimensions ) 11 | 12 | /' Have to assume doclear=TRUE, because we have no doclear parameter here, 13 | and don't know what to do, so better be safe. '/ 14 | 15 | /' new? '/ 16 | if ( array->_ptr = NULL ) then 17 | res = fb_hArrayAlloc( array, element_len, TRUE, ctor, dimensions, ap ) 18 | else 19 | /' realloc.. '/ 20 | dim as FB_DTORMULT dtor_mult = iif(dtor <> NULL, @fb_hArrayDtorObj, NULL ) 21 | res = fb_hArrayRealloc( array, element_len, TRUE, ctor, dtor_mult, dtor, dimensions, ap ) 22 | end if 23 | 24 | cva_end( ap ) 25 | 26 | return res 27 | end function 28 | end extern 29 | -------------------------------------------------------------------------------- /array_resetdesc.bas: -------------------------------------------------------------------------------- 1 | /' !!!REMOVEME!!! '/ 2 | /' descriptor reset, for dynamic local arrays '/ 3 | 4 | #include "fb.bi" 5 | 6 | extern "C" 7 | sub fb_ArrayResetDesc FBCALL ( array as FBARRAY ptr ) 8 | array->data = NULL 9 | array->_ptr = NULL 10 | array->size = 0 11 | 12 | /' array->element_len = 0; '/ 13 | /' array->dimensions = 0; '/ 14 | 15 | /' only keep flags we make decisions on. These will 16 | will have been set when the array descriptor was 17 | first allocated and must be kept. 18 | '/ 19 | 20 | array->flags = array->flags and (FBARRAY_FLAGS_DIMENSIONS or FBARRAY_FLAGS_FIXED_DIM or FBARRAY_FLAGS_FIXED_LEN) 21 | memset( @array->dimTB(0), 0, array->dimensions * sizeof( FBARRAYDIM ) ) 22 | 23 | end sub 24 | end extern 25 | -------------------------------------------------------------------------------- /con_input.bas: -------------------------------------------------------------------------------- 1 | /' input function '/ 2 | 3 | #include "fb.bi" 4 | #include "fb_private_file.bi" 5 | 6 | extern "C" 7 | function fb_ConsoleInput FBCALL ( text as FBSTRING ptr, addquestion as long, addnewline as long ) as long 8 | dim as FB_INPUTCTX ptr ctx 9 | dim as long res 10 | 11 | fb_DevScrnInit_Read( ) 12 | 13 | if ( fb_IsRedirected( TRUE ) <> NULL ) then 14 | /' del if temp '/ 15 | fb_hStrDelTemp( text ) 16 | 17 | return fb_FileInput( 0 ) 18 | end if 19 | 20 | ctx = fb_get_thread_inputctx( ) 21 | 22 | fb_StrDelete( @ctx->str ) 23 | ctx->handle = 0 24 | ctx->status = 0 25 | ctx->index = 0 26 | 27 | res = fb_LineInput( text, @ctx->str, -1, 0, addquestion, addnewline ) 28 | 29 | return res 30 | end function 31 | end extern -------------------------------------------------------------------------------- /con_locate.bas: -------------------------------------------------------------------------------- 1 | /' locate function entry point, returns current position '/ 2 | 3 | #include "fb.bi" 4 | 5 | /':::::'/ 6 | extern "C" 7 | function fb_Locate FBCALL ( row as long, col as long, cursor as long, start as long, _stop as long ) as long 8 | dim as long new_pos 9 | dim as long res = fb_LocateEx( row, col, cursor, @new_pos ) 10 | if ( res <> FB_RTERROR_OK ) then 11 | fb_LocateEx( 0, 0, cursor, @new_pos ) 12 | end if 13 | return new_pos 14 | end function 15 | end extern 16 | -------------------------------------------------------------------------------- /con_pos.bas: -------------------------------------------------------------------------------- 1 | /' implementation of pos(dummy), simply redirects to fb_GetX() '/ 2 | 3 | #include "fb.bi" 4 | 5 | /':::::'/ 6 | extern "C" 7 | function fb_Pos FBCALL ( dummy as long ) as long 8 | return fb_GetX() 9 | end function 10 | end extern -------------------------------------------------------------------------------- /con_print_raw.bas: -------------------------------------------------------------------------------- 1 | /' print raw data - no interpretation is done '/ 2 | 3 | #include "fb.bi" 4 | 5 | #define FB_CONPRINTRAW_ fb_ConPrintRaw 6 | #define FB_TCHAR ubyte 7 | #define FB_CON_HOOK_TWRITE Write 8 | #define FB_TCHAR_ADVANCE( iter, count ) iter += count 9 | 10 | #include "con_print_raw_uni.bi" 11 | -------------------------------------------------------------------------------- /con_print_raw_wstr.bas: -------------------------------------------------------------------------------- 1 | /' print raw data - no interpretation is done '/ 2 | 3 | #include "fb.bi" 4 | 5 | 6 | #define FB_CONPRINTRAW_ fb_ConPrintRawWstr 7 | #define FB_TCHAR FB_WCHAR 8 | #define FB_CON_HOOK_TWRITE Write 9 | #define FB_TCHAR_ADVANCE( iter, count ) iter += count 10 | 11 | #include "con_print_raw_uni.bi" 12 | -------------------------------------------------------------------------------- /con_print_tty.bas: -------------------------------------------------------------------------------- 1 | /' print text data - using TTY (teletype) interpretation '/ 2 | 3 | #include "fb.bi" 4 | 5 | #define FB_CONPRINTTTY_ fb_ConPrintTTY 6 | #define FB_CONPRINTRAW_ fb_ConPrintRaw 7 | #define FB_TCHAR ubyte 8 | #define FB_TCHAR_GET(p) (*(p)) 9 | #define FB_TCHAR_ADVANCE(i,c) i += c 10 | #define FB_TCHAR_GET_CHAR_SIZE(p) 1 11 | #define _TC(c) c 12 | 13 | #include "con_print_tty_uni.bi" 14 | -------------------------------------------------------------------------------- /con_print_tty_wstr.bas: -------------------------------------------------------------------------------- 1 | /' print wide text data - using TTY (teletype) interpretation '/ 2 | 3 | #include "fb.bi" 4 | 5 | #define FB_CONPRINTTTY_ fb_ConPrintTTYWstr 6 | #define FB_CONPRINTRAW_ fb_ConPrintRawWstr 7 | #define FB_TCHAR FB_WCHAR 8 | #define FB_TCHAR_GET(p) (*(p)) 9 | #define FB_TCHAR_ADVANCE(i,c) i += c 10 | #define FB_TCHAR_GET_CHAR_SIZE(p) 1 11 | #define _TC(c) _LC(c) 12 | 13 | #include "con_print_tty_uni.bi" 14 | -------------------------------------------------------------------------------- /crt_extra/signal.bi: -------------------------------------------------------------------------------- 1 | Extern "C" 2 | 3 | Type signal_func As Sub cdecl(byVal sigNum as Long) 4 | 5 | Declare Function raise cdecl(ByVal sig as Long) As Long 6 | Declare Function signal cdecl(ByVal sigNum As Long, ByVal func As signal_func) as signal_func 7 | 8 | '' Same in Win32 + POSIX 9 | #define SIGINT 2 10 | #define SIGILL 4 11 | #define SIGFPE 8 12 | #define SIGSEGV 11 13 | #define SIGTERM 15 14 | 15 | #if defined( HOST_WIN32 ) 16 | #define SIGBREAK 21 17 | #define SIGABRT 22 18 | #define NSIG 23 19 | #else 20 | #define SIGABRT 6 21 | #define NSIG 32 22 | #error "Please check the signal ids in crt_extra/signal.bi are correct for this platform" 23 | #endif 24 | 25 | End Extern 26 | -------------------------------------------------------------------------------- /crt_extra/sys/stat.bi: -------------------------------------------------------------------------------- 1 | #ifdef HOST_LINUX 2 | 3 | '' mkdir has an extra parameter on non Windows 4 | '' These are from the glibc manual 5 | '' https://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html 6 | #define S_IRUSR &O0400 7 | #define S_IWUSR &O0200 8 | #define S_IXUSR &O0100 9 | #define S_IRWXU ( S_IXUSR or S_IWUSR or S_IRUSR ) 10 | #define S_IRGRP &O0040 11 | #define S_IWGRP &O0020 12 | #define S_IXGRP &O0010 13 | #define S_IRWXG ( S_IXGRP or S_IWGRP or S_IRGRP ) 14 | #define S_IROTH &O0004 15 | #define S_IWOTH &O0002 16 | #define S_IXOTH &O0001 17 | #define S_IRWXO ( S_IXOTH or S_IWOTH or S_IROTH ) 18 | #define S_ISUID &O04000 19 | #define S_ISGID &O02000 20 | #define S_ISVTX &O01000 21 | 22 | #define S_IREAD S_IRUSR 23 | #define S_IWRITE S_IWUSR 24 | #define S_IEXEC S_IXUSR 25 | 26 | extern "C" 27 | 28 | declare function _mkdir alias "mkdir" cdecl (byval newdir as zstring ptr, byval perm as long) as long 29 | 30 | end extern 31 | 32 | #endif -------------------------------------------------------------------------------- /darwin/io_mouse.bas: -------------------------------------------------------------------------------- 1 | /' console mode mouse functions '/ 2 | 3 | #include "../fb.bi" 4 | 5 | extern "C" 6 | function fb_ConsoleGetMouse( x as long ptr, y as long ptr, z as long ptr, buttons as long ptr, clip as long ptr ) as long 7 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 8 | end function 9 | 10 | function fb_ConsoleSetMouse( x as long, y as long, cursor as long, clip as long ) as long 11 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 12 | end function 13 | end extern -------------------------------------------------------------------------------- /darwin/io_multikey.bas: -------------------------------------------------------------------------------- 1 | /' console multikey() '/ 2 | 3 | #include "../fb.bi" 4 | 5 | extern "C" 6 | function fb_ConsoleMultikey ( scancode as long ) as long 7 | fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 8 | return FB_FALSE 9 | end function 10 | end extern -------------------------------------------------------------------------------- /darwin/sys_getexename.bas: -------------------------------------------------------------------------------- 1 | /' get the executable's name '/ 2 | 3 | #include "../fb.bi" 4 | 5 | extern "C" 6 | declare function _NSGetExecutablePath(buf as ubyte ptr, bufsize as uint32_t ptr) as long 7 | 8 | function fb_hGetExeName( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 9 | dim as ubyte ptr p 10 | dim as uint32_t _len = maxlen 11 | 12 | if (_NSGetExecutablePath(dst, @_len) = 0) then 13 | dst[_len] = 0 14 | p = strrchr(dst, asc("/")) 15 | if (p <> NULL) then 16 | p += 1 17 | else 18 | p = dst 19 | end if 20 | else 21 | p = NULL 22 | end if 23 | 24 | return p 25 | end function 26 | end extern -------------------------------------------------------------------------------- /darwin/sys_getexepath.bas: -------------------------------------------------------------------------------- 1 | /' get the executable path '/ 2 | 3 | #include "../fb.bi" 4 | ''#include "mach-o/dyld.h" 5 | 6 | extern "C" 7 | 8 | declare function _NSGetExecutablePath(buf as ubyte ptr, bufsize as uint32_t ptr) as long 9 | 10 | function fb_hGetExePath( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 11 | dim as ubyte ptr p 12 | dim as uint32_t _len = maxlen 13 | 14 | if (_NSGetExecutablePath(dst, @_len) = 0) then 15 | dst[len] = 0 16 | p = strrchr(dst, asc("/")) 17 | if (p = dst) then /' keep the "/" rather than returning "" '/ 18 | p += 1 19 | *p = 0 20 | elseif (p <> 0) then 21 | *p = 0 22 | /' OS X likes to append "/." to the path, so remove it '/ 23 | p -= 2 24 | if (*p = asc("/") and *(p-1) = asc(".")) then 25 | *p = 0 26 | end if 27 | else 28 | dst[0] = 0 29 | else 30 | p = NULL 31 | end if 32 | return p 33 | end function 34 | end extern -------------------------------------------------------------------------------- /data.bas: -------------------------------------------------------------------------------- 1 | /' DATA core '/ 2 | 3 | #include "fb.bi" 4 | 5 | dim shared as FB_DATADESC ptr __fb_data_ptr = NULL 6 | 7 | extern "C" 8 | private sub hSkipLink( ) 9 | /' If a link was reached, move to the next non-link, or NULL ("EOF") '/ 10 | while ( __fb_data_ptr <> NULL andalso (__fb_data_ptr->len = FB_DATATYPE_LINK) ) 11 | __fb_data_ptr = __fb_data_ptr->next 12 | wend 13 | 14 | DBG_ASSERT( (__fb_data_ptr = NULL) orelse (__fb_data_ptr->len <> FB_DATATYPE_LINK) ) 15 | end sub 16 | 17 | sub fb_DataRestore FBCALL ( labeladdr as FB_DATADESC ptr ) 18 | FB_LOCK() 19 | 20 | __fb_data_ptr = labeladdr 21 | hSkipLink( ) 22 | 23 | FB_UNLOCK() 24 | end sub 25 | 26 | /' Callers are expected to FB_LOCK/FB_UNLOCK '/ 27 | sub fb_DataNext( ) 28 | /' Move forward in current DATA table, if any '/ 29 | if ( __fb_data_ptr <> NULL ) then 30 | DBG_ASSERT( __fb_data_ptr->len <> FB_DATATYPE_LINK ) 31 | __fb_data_ptr += 1 32 | hSkipLink( ) 33 | end if 34 | end sub 35 | end extern -------------------------------------------------------------------------------- /data_readbool.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for boolean's '/ 2 | 3 | #include "fb.bi" 4 | 5 | /':::::'/ 6 | extern "C" 7 | sub fb_DataReadBool FBCALL ( dst as boolean ptr ) 8 | FB_LOCK() 9 | 10 | if ( __fb_data_ptr <> NULL ) then 11 | if ( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 12 | *dst = cast(size_t, __fb_data_ptr->ofs) 13 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 14 | *dst = fb_WstrToBool( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 15 | else 16 | *dst = fb_hStr2Bool( __fb_data_ptr->zstr, __fb_data_ptr->len ) 17 | end if 18 | else 19 | /' no more DATA '/ 20 | *dst = 0 21 | end if 22 | 23 | fb_DataNext( ) 24 | 25 | FB_UNLOCK() 26 | end sub 27 | end extern -------------------------------------------------------------------------------- /data_readbyte.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for byte's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadByte FBCALL ( dst as byte ptr ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> NULL) then 10 | if( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | *dst = cast(size_t, __fb_data_ptr->ofs) 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | *dst = fb_WstrToInt( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 14 | else 15 | *dst = fb_hStr2Int( __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | /' no more DATA '/ 19 | *dst = 0 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readdouble.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for double's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadDouble FBCALL ( dst as double ptr ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> 0 ) then 10 | if( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | *dst = cast(size_t, __fb_data_ptr->ofs) 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | *dst = fb_WstrToDouble( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 14 | else 15 | *dst = fb_hStr2Double( __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | /' no more DATA '/ 19 | *dst = 0.0 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readint.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for integer's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadInt FBCALL ( dst as long ptr ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> NULL ) then 10 | if ( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | *dst = cast(size_t, __fb_data_ptr->ofs) 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | *dst = fb_WstrToInt( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 14 | else 15 | *dst = fb_hStr2Int( __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | /' no more DATA '/ 19 | *dst = 0.0 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readlong.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for long integer's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadLongint FBCALL ( dst as longint ptr ) 7 | FB_LOCK() 8 | 9 | if( __fb_data_ptr <> NULL ) then 10 | if( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | *dst = cast(size_t, __fb_data_ptr->ofs) 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | *dst = fb_WstrToLongint( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 14 | else 15 | *dst = fb_hStr2Longint( __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | /' no more DATA '/ 19 | *dst = 0 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readshort.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for short's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadShort FBCALL ( dst as short ptr ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> 0) then 10 | if( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | *dst = cast(size_t, __fb_data_ptr->ofs) 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | *dst = fb_WstrToInt( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 14 | else 15 | *dst = fb_hStr2Int( __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | /' no more DATA '/ 19 | *dst = 0 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readsingle.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for single's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadSingle FBCALL ( dst as single ptr ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> NULL ) then 10 | if ( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | *dst = cast(size_t, __fb_data_ptr->ofs) 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | *dst = fb_WstrToDouble( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 14 | else 15 | *dst = fb_hStr2Double( __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | /' no more DATA '/ 19 | *dst = 0.0 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readstr.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for strings '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadStr FBCALL ( dst as any ptr, dst_size as ssize_t, fillrem as long ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> NULL ) then 10 | if ( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | /' !!!WRITEME!!! '/ 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | fb_WstrAssignToA( dst, dst_size, __fb_data_ptr->wstr, fillrem ) 14 | else 15 | fb_StrAssign( dst, dst_size, __fb_data_ptr->zstr, 0, fillrem ) 16 | end if 17 | else 18 | /' no more DATA, return empty string '/ 19 | fb_StrAssign( dst, dst_size, sadd(""), 0, fillrem ) 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readubyte.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for ubyte's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadUByte FBCALL ( dst as ubyte ptr ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> NULL ) then 10 | if ( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | *dst = cast(size_t, __fb_data_ptr->ofs) 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | *dst = fb_WstrToUInt( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 14 | else 15 | *dst = fb_hStr2UInt( __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | /' no more DATA '/ 19 | *dst = 0 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readuint.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for uinteger's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadUInt FBCALL ( dst as ulong ptr ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> NULL ) then 10 | if ( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | *dst = cast(size_t, __fb_data_ptr->ofs) 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | *dst = fb_WstrToUInt( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 14 | else 15 | *dst = fb_hStr2UInt( __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | /' no more DATA '/ 19 | *dst = 0 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readulong.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for ulong integer's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadULongint FBCALL ( dst as ulongint ptr ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> NULL ) then 10 | if ( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | *dst = cast(size_t, __fb_data_ptr->ofs) 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | *dst = fb_WstrToULongint( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 14 | else 15 | *dst = fb_hStr2ULongint( __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | /' no more DATA '/ 19 | *dst = 0 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readushort.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for ushort's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadUShort FBCALL ( dst as ushort ptr ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> NULL ) then 10 | if ( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | *dst = cast(size_t, __fb_data_ptr->ofs) 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | *dst = fb_WstrToUInt( __fb_data_ptr->wstr, __fb_data_ptr->len and &h7FFF ) 14 | else 15 | *dst = fb_hStr2UInt( __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | /' no more DATA '/ 19 | *dst = 0 20 | end if 21 | 22 | fb_DataNext( ) 23 | 24 | FB_UNLOCK() 25 | end sub 26 | end extern -------------------------------------------------------------------------------- /data_readwstr.bas: -------------------------------------------------------------------------------- 1 | /' read stmt for wstring's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_DataReadWstr FBCALL ( dst as FB_WCHAR ptr, dst_size as ssize_t ) 7 | FB_LOCK() 8 | 9 | if ( __fb_data_ptr <> NULL ) then 10 | if ( __fb_data_ptr->len = FB_DATATYPE_OFS ) then 11 | /' !!!WRITEME!!! '/ 12 | elseif ( (__fb_data_ptr->len and FB_DATATYPE_WSTR) <> 0 ) then 13 | fb_WstrAssign( dst, dst_size, __fb_data_ptr->wstr ) 14 | else 15 | fb_WstrAssignFromA( dst, dst_size, __fb_data_ptr->zstr, __fb_data_ptr->len ) 16 | end if 17 | else 18 | dim as FB_WCHAR nullString = 0 19 | /' no more DATA, return empty string '/ 20 | fb_WstrAssign( dst, dst_size, @nullString ) 21 | end if 22 | 23 | fb_DataNext( ) 24 | 25 | FB_UNLOCK() 26 | end sub 27 | end extern 28 | -------------------------------------------------------------------------------- /dev_com_private.bi: -------------------------------------------------------------------------------- 1 | type DEV_COM_INFO 2 | as any ptr hSerial 3 | as ubyte ptr pszDevice 4 | as long iPort 5 | as FB_SERIAL_OPTIONS Options 6 | end type 7 | -------------------------------------------------------------------------------- /dev_file_close.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevFileClose( handle as FB_FILE ptr ) as long 7 | dim as FILE ptr fp 8 | 9 | FB_LOCK() 10 | 11 | fp = cast(FILE ptr, handle->opaque) 12 | 13 | if ( fp <> NULL ) then 14 | fclose( fp ) 15 | end if 16 | 17 | handle->opaque = NULL 18 | 19 | FB_UNLOCK() 20 | 21 | return fb_ErrorSetNum( FB_RTERROR_OK ) 22 | end function 23 | end extern -------------------------------------------------------------------------------- /dev_file_encod_read.bas: -------------------------------------------------------------------------------- 1 | /' UTF-encoded input for file devices '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevFileReadEncod( handle as FB_FILE ptr, dst as any ptr, max_chars as size_t ptr ) as long 7 | dim as FILE ptr fp 8 | dim as size_t chars 9 | 10 | FB_LOCK() 11 | 12 | chars = *max_chars 13 | 14 | fp = cast(FILE ptr, handle->opaque) 15 | if ( fp = stdout or fp = stderr ) then 16 | fp = stdin 17 | end if 18 | 19 | if ( fp = NULL ) then 20 | FB_UNLOCK() 21 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 22 | end if 23 | 24 | /' do read '/ 25 | chars = fb_hFileRead_UTFToChar( fp, handle->encod, dst, chars ) 26 | 27 | /' fill with nulls if at eof '/ 28 | if ( chars <> *max_chars ) then 29 | memset( (cast(ubyte ptr, dst)) + chars, 0, *max_chars - chars ) 30 | end if 31 | 32 | *max_chars = chars 33 | 34 | FB_UNLOCK() 35 | 36 | return fb_ErrorSetNum( FB_RTERROR_OK ) 37 | end function 38 | end extern -------------------------------------------------------------------------------- /dev_file_flush.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevFileFlush( handle as FB_FILE ptr ) as long 7 | dim as FILE ptr fp 8 | dim as long errorRet = FB_RTERROR_OK 9 | 10 | FB_LOCK() 11 | 12 | fp = cast(FILE ptr, handle->opaque) 13 | 14 | if ( fp = NULL ) then 15 | errorRet = FB_RTERROR_ILLEGALFUNCTIONCALL 16 | elseif( fflush( fp ) <> 0 ) then 17 | errorRet = FB_RTERROR_FILEIO 18 | end if 19 | 20 | FB_UNLOCK() 21 | 22 | return fb_ErrorSetNum( errorRet ) 23 | end function 24 | end extern -------------------------------------------------------------------------------- /dev_file_lock.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevFileLock( handle as FB_FILE ptr, position as fb_off_t, size as fb_off_t ) as long 7 | dim as FILE ptr fp 8 | dim as long res 9 | 10 | if ( size = 0 ) then 11 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 12 | end if 13 | 14 | FB_LOCK() 15 | 16 | fp = cast(FILE ptr, handle->opaque) 17 | 18 | if ( fp = NULL ) then 19 | FB_UNLOCK() 20 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 21 | end if 22 | 23 | res = fb_hFileLock( fp, position, size ) 24 | 25 | FB_UNLOCK() 26 | 27 | return res 28 | end function 29 | end extern -------------------------------------------------------------------------------- /dev_file_seek.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevFileSeek( handle as FB_FILE ptr, offset as fb_off_t, whence as long ) as long 7 | dim as long res 8 | dim as FILE ptr fp 9 | 10 | FB_LOCK() 11 | 12 | fp = cast(FILE ptr, handle->opaque) 13 | 14 | if ( fp = NULL ) then 15 | FB_UNLOCK() 16 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 17 | end if 18 | 19 | res = fb_ErrorSetNum( iif(fseeko( fp, offset, whence ) = 0, FB_RTERROR_OK, FB_RTERROR_FILEIO) ) 20 | 21 | FB_UNLOCK() 22 | 23 | return res 24 | end function 25 | end extern 26 | -------------------------------------------------------------------------------- /dev_file_tell.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevFileTell( handle as FB_FILE ptr, pOffset as fb_off_t ptr ) as long 7 | dim as FILE ptr fp 8 | 9 | FB_LOCK() 10 | 11 | fp = cast(FILE ptr, handle->opaque) 12 | 13 | if ( fp = NULL ) then 14 | FB_UNLOCK() 15 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 16 | end if 17 | 18 | *pOffset = ftello( fp ) 19 | 20 | FB_UNLOCK() 21 | 22 | return fb_ErrorSetNum( FB_RTERROR_OK ) 23 | end function 24 | end extern 25 | -------------------------------------------------------------------------------- /dev_file_unlock.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevFileUnlock( handle as FB_FILE ptr, position as fb_off_t, size as fb_off_t ) as long 7 | dim as long res 8 | dim as FILE ptr fp 9 | 10 | if ( size = 0 ) then 11 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 12 | end if 13 | 14 | FB_LOCK() 15 | 16 | fp = cast(FILE ptr, handle->opaque) 17 | if ( fp = NULL ) then 18 | FB_UNLOCK() 19 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 20 | end if 21 | 22 | res = fb_hFileUnlock( fp, position, size ) 23 | 24 | FB_UNLOCK() 25 | 26 | return res 27 | end function 28 | end extern -------------------------------------------------------------------------------- /dev_file_write.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevFileWrite( handle as FB_FILE ptr, value as const any ptr, valuelen as size_t ) as long 7 | dim as FILE ptr fp 8 | 9 | FB_LOCK() 10 | 11 | fp = cast(FILE ptr, handle->opaque) 12 | 13 | if ( fp = NULL ) then 14 | FB_UNLOCK() 15 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 16 | end if 17 | 18 | /' do write '/ 19 | if ( fwrite( cast(any ptr, value), 1, valuelen, fp ) <> valuelen ) then 20 | FB_UNLOCK() 21 | return fb_ErrorSetNum( FB_RTERROR_FILEIO ) 22 | end if 23 | 24 | FB_UNLOCK() 25 | 26 | return fb_ErrorSetNum( FB_RTERROR_OK ) 27 | end function 28 | end extern -------------------------------------------------------------------------------- /dev_lpt_close.bas: -------------------------------------------------------------------------------- 1 | /' LPTx device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevLptClose( handle as FB_FILE ptr ) as long 7 | dim as long res 8 | dim as DEV_LPT_INFO ptr devInfo 9 | 10 | FB_LOCK() 11 | 12 | devInfo = cast(DEV_LPT_INFO ptr, handle->opaque) 13 | if ( devInfo->uiRefCount = 1 ) then 14 | res = fb_PrinterClose( devInfo ) 15 | 16 | if ( res = FB_RTERROR_OK ) then 17 | free(devInfo->pszDevice) 18 | free(devInfo) 19 | else 20 | devInfo->uiRefCount -= 1 21 | res = fb_ErrorSetNum( FB_RTERROR_OK ) 22 | end if 23 | end if 24 | FB_UNLOCK() 25 | 26 | return res 27 | end function 28 | end extern -------------------------------------------------------------------------------- /dev_lpt_write.bas: -------------------------------------------------------------------------------- 1 | /' LPTx device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevLptWrite( handle as FB_FILE ptr, value as const any ptr, valuelen as size_t ) as long 7 | dim as long res 8 | 9 | FB_LOCK() 10 | 11 | res = fb_PrinterWrite(cast(DEV_LPT_INFO ptr, handle->opaque), value, valuelen ) 12 | 13 | FB_UNLOCK() 14 | 15 | return res 16 | end function 17 | end extern -------------------------------------------------------------------------------- /dev_lpt_write_wstr.bas: -------------------------------------------------------------------------------- 1 | /' LPTx device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevLptWriteWstr( handle as FB_FILE ptr, value as const FB_WCHAR ptr, valuelen as size_t ) as long 7 | dim as long res 8 | 9 | FB_LOCK() 10 | 11 | res = fb_PrinterWriteWstr(cast(DEV_LPT_INFO ptr, handle->opaque), value, valuelen ) 12 | 13 | FB_UNLOCK() 14 | 15 | return res 16 | end function 17 | end extern -------------------------------------------------------------------------------- /dev_pipe_close.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevPipeClose( handle as FB_FILE ptr ) as long 7 | #if defined( HOST_DOS ) or defined( HOST_UNIX ) or defined( HOST_WIN32 ) 8 | dim as FILE ptr fp 9 | 10 | FB_LOCK() 11 | 12 | fp = cast(FILE ptr, handle->opaque) 13 | if ( fp <> NULL ) then 14 | pclose( fp ) 15 | end if 16 | 17 | handle->opaque = NULL 18 | 19 | FB_UNLOCK() 20 | return fb_ErrorSetNum( FB_RTERROR_OK ) 21 | #else 22 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 23 | #endif 24 | end function 25 | end extern -------------------------------------------------------------------------------- /dev_scrn_close.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevScrnClose( handle as FB_FILE ptr ) as long 7 | FB_LOCK() 8 | fb_DevScrnEnd( handle ) 9 | FB_UNLOCK() 10 | return fb_ErrorSetNum( FB_RTERROR_OK ) 11 | end function 12 | end extern -------------------------------------------------------------------------------- /dev_scrn_readline.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevScrnReadLine( handle as FB_FILE ptr, dst as FBSTRING ptr ) as long 7 | return fb_LineInput( NULL, dst, -1, FALSE, FALSE, TRUE ) 8 | end function 9 | 10 | sub fb_DevScrnInit_ReadLine( ) 11 | fb_DevScrnInit_NoOpen( ) 12 | 13 | FB_LOCK( ) 14 | if ( FB_HANDLE_SCREEN->hooks->pfnReadLine = NULL ) then 15 | FB_HANDLE_SCREEN->hooks->pfnReadLine = @fb_DevScrnReadLine 16 | end if 17 | FB_UNLOCK( ) 18 | end sub 19 | end extern -------------------------------------------------------------------------------- /dev_scrn_readline_wstr.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevScrnReadLineWstr( handle as FB_FILE ptr, dst as FB_WCHAR ptr, dst_chars as ssize_t ) as long 7 | dim as long res 8 | dim as FBSTRING temp = ( 0, 0, 0 ) 9 | 10 | /' !!!FIXME!!! no unicode input supported '/ 11 | 12 | res = fb_LineInput( NULL, cast(any ptr, @temp), -1, FALSE, FALSE, TRUE ) 13 | 14 | if ( res = FB_RTERROR_OK ) then 15 | fb_WstrAssignFromA( dst, dst_chars, cast(any ptr ,@temp), -1 ) 16 | end if 17 | 18 | fb_StrDelete( @temp ) 19 | 20 | return res 21 | end function 22 | 23 | sub fb_DevScrnInit_ReadLineWstr( ) 24 | fb_DevScrnInit_NoOpen( ) 25 | 26 | FB_LOCK( ) 27 | if ( FB_HANDLE_SCREEN->hooks->pfnReadLineWstr = NULL ) then 28 | FB_HANDLE_SCREEN->hooks->pfnReadLineWstr = @fb_DevScrnReadLineWstr 29 | end if 30 | FB_UNLOCK( ) 31 | end sub 32 | end extern -------------------------------------------------------------------------------- /dev_scrn_write.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevScrnWrite( handle as FB_FILE ptr, value as const any ptr, valuelen as size_t ) as long 7 | fb_PrintBufferEx( value, valuelen, 0 ) 8 | return fb_ErrorSetNum( FB_RTERROR_OK ) 9 | end function 10 | 11 | sub fb_DevScrnInit_Write( ) 12 | fb_DevScrnInit_NoOpen( ) 13 | 14 | FB_LOCK( ) 15 | if( FB_HANDLE_SCREEN->hooks->pfnWrite = NULL ) then 16 | FB_HANDLE_SCREEN->hooks->pfnWrite = @fb_DevScrnWrite 17 | end if 18 | FB_UNLOCK( ) 19 | end sub 20 | end extern -------------------------------------------------------------------------------- /dev_scrn_write_wstr.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevScrnWriteWstr( handle as FB_FILE ptr, value as const FB_WCHAR ptr, valuelen as size_t ) as long 7 | fb_PrintBufferWstrEx( value, valuelen, 0 ) 8 | return fb_ErrorSetNum( FB_RTERROR_OK ) 9 | end function 10 | 11 | sub fb_DevScrnInit_WriteWstr( ) 12 | fb_DevScrnInit_NoOpen( ) 13 | 14 | FB_LOCK( ) 15 | if ( FB_HANDLE_SCREEN->hooks->pfnWriteWstr = NULL ) then 16 | FB_HANDLE_SCREEN->hooks->pfnWriteWstr = @fb_DevScrnWriteWstr 17 | end if 18 | FB_UNLOCK( ) 19 | end sub 20 | end extern -------------------------------------------------------------------------------- /dev_stdio_close.bas: -------------------------------------------------------------------------------- 1 | /' file device '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DevStdIoClose( handle as FB_FILE ptr ) as long 7 | FB_LOCK() 8 | 9 | handle->opaque = NULL 10 | 11 | FB_UNLOCK() 12 | 13 | return fb_ErrorSetNum( FB_RTERROR_OK ) 14 | end function 15 | end extern -------------------------------------------------------------------------------- /dos/dos_private_thread.bi: -------------------------------------------------------------------------------- 1 | #ifdef ENABLE_MT 2 | #include "crt/pthread.bi" 3 | 4 | type _FBMUTEX 5 | as pthread_mutex_t id 6 | end type 7 | 8 | Type _FBCOND 9 | as pthread_cond_t id 10 | End Type 11 | #endif 12 | -------------------------------------------------------------------------------- /error_assert.bas: -------------------------------------------------------------------------------- 1 | /' assertion functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_Assert FBCALL ( filename as ubyte ptr, linenum as long, funcname as ubyte ptr, expression as ubyte ptr ) 7 | snprintf( @__fb_errmsg(0), FB_ERRMSG_SIZE, _ 8 | "%s(%d): assertion failed at %s: %s\n", _ 9 | filename, linenum, funcname, expression ) 10 | 11 | __fb_errmsg(FB_ERRMSG_SIZE-1) = 0 12 | 13 | /' Let fb_hRtExit() show the message '/ 14 | __fb_ctx.errmsg = @__fb_errmsg(0) 15 | 16 | fb_End( 1 ) 17 | end sub 18 | 19 | sub fb_AssertWarn FBCALL ( filename as ubyte ptr, linenum as long, funcname as ubyte ptr, expression as ubyte ptr ) 20 | /' Printing to stderr, as done with assert() or runtime error messages 21 | in fb_hRtExit() '/ 22 | fprintf( stderr, "%s(%d): assertion failed at %s: %s\n", _ 23 | filename, linenum, funcname, expression ) 24 | end sub 25 | end extern -------------------------------------------------------------------------------- /error_message.bas: -------------------------------------------------------------------------------- 1 | /' error message buffer shared by fb_Die() and fb_Assert() functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | dim as ubyte __fb_errmsg(0 to FB_ERRMSG_SIZE - 1) 6 | -------------------------------------------------------------------------------- /error_ptrchk.bas: -------------------------------------------------------------------------------- 1 | /' null pointer checking function '/ 2 | 3 | #ifdef fb_NullPtrChk 4 | #undef fb_NullPtrChk 5 | #endif 6 | 7 | #include "fb.bi" 8 | 9 | extern "C" 10 | /':::::'/ 11 | function fb_NullPtrChk FBCALL ( _ptr as any ptr, linenum as long, fname as const ubyte ptr ) as any ptr 12 | if ( _ptr = NULL ) then 13 | return cast(any ptr, fb_ErrorThrowEx( FB_RTERROR_NULLPTR, linenum, fname, NULL, NULL )) 14 | else 15 | return NULL 16 | end if 17 | end function 18 | end extern -------------------------------------------------------------------------------- /fb_legacy.bi: -------------------------------------------------------------------------------- 1 | extern "C" 2 | declare function fb_LCASE FBCALL ( src as FBSTRING ptr ) as FBSTRING ptr 3 | declare function fb_UCASE FBCALL ( src as FBSTRING ptr ) as FBSTRING ptr 4 | 5 | declare function fb_WstrLcase FBCALL ( src as const FB_WCHAR ptr ) as FB_WCHAR ptr 6 | declare function fb_WstrUcase FBCALL ( src as const FB_WCHAR ptr ) as FB_WCHAR ptr 7 | end extern -------------------------------------------------------------------------------- /fb_oop.bi: -------------------------------------------------------------------------------- 1 | #ifdef fb_IsTypeOf 2 | #undef fb_IsTypeOf 3 | #endif 4 | 5 | type FB_RTTI 6 | as any ptr stdlistVT 7 | as ubyte ptr id 8 | as FB_RTTI ptr pRTTIBase 9 | end type 10 | 11 | type FB_BASEVT 12 | as any ptr nullPtr 13 | as FB_RTTI ptr pRTTI 14 | end type 15 | 16 | type FB_OBJECT 17 | as FB_BASEVT ptr pVT 18 | end type 19 | 20 | extern "C" 21 | /' Object class constructor & copy constructor '/ 22 | declare sub _ZN10fb_ObjectC1Ev alias "_ZN10fb_Object$C1Ev"( as FB_OBJECT ptr ) 23 | declare sub _ZN10fb_ObjectC1ERKS_ alias "_ZN10fb_Object$C1ERKS_"( this_ as FB_OBJECT ptr, rhs as const FB_OBJECT ptr ) 24 | declare function fb_IsTypeOf FBCALL ( obj as FB_OBJECT ptr, typeRTTI as FB_RTTI ptr ) as long 25 | end extern -------------------------------------------------------------------------------- /fb_private_error.bi: -------------------------------------------------------------------------------- 1 | type _FB_ERRHANDLER As FB_ERRHANDLER 2 | 3 | type FB_ERRORCTX 4 | as _FB_ERRHANDLER handler 5 | as long err_num 6 | as long line_num 7 | as const ubyte ptr mod_name 8 | as const ubyte ptr fun_name 9 | as any ptr res_lbl 10 | as any ptr resnxt_lbl 11 | end type 12 | 13 | declare function fb_get_thread_errorctx( ) as FB_ERRORCTX ptr -------------------------------------------------------------------------------- /fb_private_file.bi: -------------------------------------------------------------------------------- 1 | type _FB_FILE as FB_FILE 2 | type _FBSTRING as FBSTRING 3 | type FB_INPUTCTX 4 | as _FB_FILE ptr handle 5 | as long status 6 | as _FBSTRING str 7 | as long index 8 | end type 9 | 10 | declare function fb_get_thread_inputctx( ) as FB_INPUTCTX ptr -------------------------------------------------------------------------------- /fb_private_hdynload.bi: -------------------------------------------------------------------------------- 1 | #if defined(HOST_UNIX) or defined(HOST_WIN32) 2 | 3 | #ifdef HOST_WIN32 4 | #include "windows.bi" 5 | type FB_DYLIB as HANDLE 6 | #else 7 | type FB_DYLIB as any ptr 8 | #endif 9 | 10 | extern "C" 11 | declare function fb_hDynLoad ( libname as const ubyte ptr, funcname as const ubyte const ptr ptr, funcptr as any ptr ptr ) as FB_DYLIB 12 | declare function fb_hDynLoadAlso ( _lib as FB_DYLIB, funcname as const ubyte const ptr ptr, funcptr as any ptr ptr, count as ssize_t ) as long 13 | declare sub fb_hDynUnload ( _lib as FB_DYLIB ptr ) 14 | end extern 15 | #endif 16 | -------------------------------------------------------------------------------- /file_datetime.bas: -------------------------------------------------------------------------------- 1 | /' get file date/time by filename '/ 2 | 3 | /' 4 | !!! FIXME !!! - update the crt headers 5 | - have issues here with duplicate definitions in the crt headers 6 | - need to update crt headers to allow these includes to work together 7 | '/ 8 | 9 | #include "fb.bi" 10 | #include "crt/time.bi" 11 | #include "crt/sys/stat.bi" 12 | 13 | extern "C" 14 | function fb_FileDateTime FBCALL ( filename as const ubyte ptr ) as double 15 | dim as stat buf 16 | if ( _stat( cast(ubyte ptr, filename), @buf ) <> 0 ) then 17 | return 0.0 18 | end if 19 | 20 | dim as tm ptr _tm = localtime( @buf.st_mtime ) 21 | if ( _tm = NULL ) then 22 | return 0.0 23 | end if 24 | 25 | return fb_DateSerial( 1900 + _tm->tm_year, 1+_tm->tm_mon, _tm->tm_mday ) + fb_TimeSerial( _tm->tm_hour, _tm->tm_min, _tm->tm_sec ) 26 | end function 27 | end extern -------------------------------------------------------------------------------- /file_dir64.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_Dir64 FBCALL ( filespec as FBSTRING ptr, attrib as long, outattrib as longint ptr ) as FBSTRING ptr 5 | dim as long ioutattrib 6 | dim as FBSTRING ptr res 7 | 8 | res = fb_Dir( filespec, attrib, @ioutattrib ) 9 | 10 | *outattrib = ioutattrib 11 | return res 12 | end function 13 | end extern -------------------------------------------------------------------------------- /file_dirnext.bas: -------------------------------------------------------------------------------- 1 | /' dir() '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_DirNext FBCALL ( attrib as long ptr ) as FBSTRING ptr 7 | static as FBSTRING fname = ( 0, 0, 0 ) 8 | return fb_Dir( @fname, 0, attrib ) 9 | end function 10 | end extern -------------------------------------------------------------------------------- /file_dirnext64.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_DirNext64 FBCALL ( outattrib as longint ptr ) as FBSTRING ptr 5 | dim as long ioutattrib 6 | dim as FBSTRING ptr res 7 | 8 | res = fb_DirNext( @ioutattrib ) 9 | 10 | *outattrib = ioutattrib 11 | return res 12 | end function 13 | end extern -------------------------------------------------------------------------------- /file_encod.bas: -------------------------------------------------------------------------------- 1 | /' string to file encoding function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_hFileStrToEncoding( _encoding as const ubyte ptr ) as FB_FILE_ENCOD 8 | if ( _encoding = NULL ) then 9 | return FB_FILE_ENCOD_DEFAULT 10 | end if 11 | 12 | if ( strncasecmp( _encoding, "UTF", 3 ) = 0 ) then 13 | _encoding += 3 14 | 15 | if ( *_encoding = asc("-") ) then 16 | _encoding += 1 17 | end if 18 | 19 | if ( *_encoding = asc("8") ) then 20 | return FB_FILE_ENCOD_UTF8 21 | end if 22 | 23 | if ( strcmp( _encoding, "16" ) = 0 ) then 24 | return FB_FILE_ENCOD_UTF16 25 | end if 26 | 27 | if ( strcmp( _encoding, "32" ) = 0 ) then 28 | return FB_FILE_ENCOD_UTF32 29 | end if 30 | else 31 | if ( strncasecmp( _encoding, "ASC", 3 ) = 0 ) then 32 | return FB_FILE_ENCOD_ASCII 33 | end if 34 | end if 35 | 36 | return FB_FILE_ENCOD_DEFAULT 37 | end function 38 | end extern -------------------------------------------------------------------------------- /file_eof.bas: -------------------------------------------------------------------------------- 1 | /' eof function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_FileEofEx( handle as FB_FILE ptr ) as long 8 | dim as long res 9 | 10 | if ( FB_HANDLE_USED(handle) = 0 ) then 11 | return FB_TRUE 12 | end if 13 | 14 | FB_LOCK() 15 | 16 | if ( handle->hooks = NULL or handle->hooks->pfnEof = NULL ) then 17 | FB_UNLOCK() 18 | return FB_TRUE 19 | end if 20 | 21 | if ( handle->putback_size <> 0 ) then 22 | FB_UNLOCK() 23 | return FB_FALSE 24 | end if 25 | 26 | if ( handle->hooks->pfnEof <> NULL ) then 27 | res = handle->hooks->pfnEof( handle ) 28 | else 29 | res = FB_TRUE 30 | end if 31 | 32 | FB_UNLOCK() 33 | 34 | return res 35 | end function 36 | 37 | /':::::'/ 38 | function fb_FileEof FBCALL ( fnum as long ) as long 39 | return fb_FileEofEx(FB_FILE_TO_HANDLE(fnum)) 40 | end function 41 | end extern -------------------------------------------------------------------------------- /file_exists.bas: -------------------------------------------------------------------------------- 1 | /' file existence testing '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_FileExists FBCALL ( filename as const ubyte ptr ) as long 7 | dim as FILE ptr fp 8 | 9 | fp = fopen(cast(ubyte ptr, filename), "r") 10 | if (fp <> 0) then 11 | fclose(fp) 12 | return FB_TRUE 13 | else 14 | return FB_FALSE 15 | end if 16 | end function 17 | end extern 18 | -------------------------------------------------------------------------------- /file_free.bas: -------------------------------------------------------------------------------- 1 | /' freefile function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_FileFree FBCALL ( ) as long 8 | dim as long i 9 | 10 | FB_LOCK() 11 | 12 | for i = 1 to FB_MAX_FILES - FB_RESERVED_FILES 13 | dim as FB_FILE ptr handle = FB_FILE_TO_HANDLE(i) 14 | if (handle->hooks = NULL) then 15 | FB_UNLOCK() 16 | return i 17 | end if 18 | next 19 | 20 | FB_UNLOCK() 21 | 22 | return 0 23 | end function 24 | end extern -------------------------------------------------------------------------------- /file_hconvpath.bas: -------------------------------------------------------------------------------- 1 | /' path conversion '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_hConvertPath( path as ubyte ptr ) 7 | dim as ssize_t i, _len 8 | 9 | DBG_ASSERT( path <> NULL ) 10 | 11 | _len = strlen( path ) 12 | for i = 0 to _len - 1 13 | #if defined( HOST_DOS ) or defined( HOST_XBOX ) 14 | if ( path[i] = asc("/") ) then 15 | path[i] = asc("\") 16 | end if 17 | #else 18 | if ( path[i] = asc("\") ) then 19 | path[i] = asc("/") 20 | end if 21 | #endif 22 | next 23 | end sub 24 | end extern 25 | -------------------------------------------------------------------------------- /file_input_bool.bas: -------------------------------------------------------------------------------- 1 | /' input function for boolean '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/math.bi" 5 | 6 | extern "C" 7 | /':::::'/ 8 | function fb_InputBool FBCALL ( dst as ubyte ptr ) as long 9 | dim as ubyte buffer(0 to FB_INPUT_MAXNUMERICLEN) 10 | dim as ssize_t _len 11 | dim as long isfp 12 | 13 | _len = fb_FileInputNextToken( @buffer(0), FB_INPUT_MAXNUMERICLEN, FB_FALSE, @isfp ) 14 | 15 | *dst = cast(ubyte, fb_hStr2Bool( @buffer(0), _len )) 16 | 17 | return fb_ErrorSetNum( FB_RTERROR_OK ) 18 | end function 19 | end extern -------------------------------------------------------------------------------- /file_input_byte.bas: -------------------------------------------------------------------------------- 1 | /' input function for signed bytes '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/math.bi" 5 | 6 | extern "C" 7 | function fb_InputByte FBCALL ( dst as ubyte ptr ) as long 8 | dim as ubyte buffer(0 to FB_INPUT_MAXNUMERICLEN) 9 | dim as ssize_t _len 10 | dim as long isfp 11 | 12 | _len = fb_FileInputNextToken( @buffer(0), FB_INPUT_MAXNUMERICLEN, FB_FALSE, @isfp ) 13 | 14 | if ( isfp = FALSE ) then 15 | *dst = cast(ubyte, fb_hStr2Int( @buffer(0), _len )) 16 | else 17 | *dst = cast(ubyte, rint( fb_hStr2Double( @buffer(0), _len ) )) 18 | end if 19 | return fb_ErrorSetNum( FB_RTERROR_OK ) 20 | end function 21 | end extern -------------------------------------------------------------------------------- /file_input_int.bas: -------------------------------------------------------------------------------- 1 | /' input function for signed integers '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/math.bi" 5 | 6 | extern "C" 7 | function fb_InputInt FBCALL ( dst as long ptr ) as long 8 | dim as ubyte buffer(0 to FB_INPUT_MAXNUMERICLEN) 9 | dim as ssize_t _len 10 | dim as long isfp 11 | 12 | _len = fb_FileInputNextToken( @buffer(0), FB_INPUT_MAXNUMERICLEN, FB_FALSE, @isfp ) 13 | 14 | if ( isfp = FALSE ) then 15 | *dst = fb_hStr2Int( @buffer(0), _len ) 16 | else 17 | *dst = cast(long, rint( fb_hStr2Double( @buffer(0), _len ) )) 18 | end if 19 | 20 | return fb_ErrorSetNum( FB_RTERROR_OK ) 21 | end function 22 | end extern -------------------------------------------------------------------------------- /file_input_longint.bas: -------------------------------------------------------------------------------- 1 | /' input function for signed long long's '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/math.bi" 5 | 6 | extern "C" 7 | function fb_InputLongint FBCALL ( dst as longint ptr ) as long 8 | dim as ubyte buffer(0 to FB_INPUT_MAXNUMERICLEN) 9 | dim as ssize_t _len 10 | dim as long isfp 11 | 12 | _len = fb_FileInputNextToken( @buffer(0), FB_INPUT_MAXNUMERICLEN, FB_FALSE, @isfp ) 13 | 14 | if ( isfp = FALSE ) then 15 | if ( _len <= FB_INPUT_MAXINTLEN ) then 16 | *dst = fb_hStr2Int( @buffer(0), _len ) 17 | else 18 | *dst = fb_hStr2Longint( @buffer(0), _len ) 19 | end if 20 | else 21 | *dst = cast(longint, rint( fb_hStr2Double( @buffer(0), _len ) )) 22 | end if 23 | 24 | return fb_ErrorSetNum( FB_RTERROR_OK ) 25 | end function 26 | end extern -------------------------------------------------------------------------------- /file_input_short.bas: -------------------------------------------------------------------------------- 1 | /' input function for signed shorts '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/math.bi" 5 | 6 | extern "C" 7 | function fb_InputShort FBCALL ( dst as short ptr ) as long 8 | dim as ubyte buffer(0 to FB_INPUT_MAXNUMERICLEN) 9 | dim as ssize_t _len 10 | dim as long isfp 11 | 12 | _len = fb_FileInputNextToken( @buffer(0), FB_INPUT_MAXNUMERICLEN, FB_FALSE, @isfp ) 13 | 14 | if ( isfp = FALSE ) then 15 | *dst = cast(short, fb_hStr2Int( @buffer(0), _len )) 16 | else 17 | *dst = cast(short, rint( fb_hStr2Double( @buffer(0), _len ) )) 18 | end if 19 | 20 | return fb_ErrorSetNum( FB_RTERROR_OK ) 21 | end function 22 | end extern -------------------------------------------------------------------------------- /file_input_str.bas: -------------------------------------------------------------------------------- 1 | /' input function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_InputString FBCALL ( dst as any ptr, _strlen as ssize_t, fillrem as long ) as long 7 | dim as ubyte buffer(0 to FB_INPUT_MAXSTRINGLEN) 8 | dim as long isfp 9 | 10 | fb_FileInputNextToken( @buffer(0), FB_INPUT_MAXSTRINGLEN, TRUE, @isfp ) 11 | 12 | fb_StrAssign( dst, _strlen, @buffer(0), 0, fillrem ) 13 | 14 | return fb_ErrorSetNum( FB_RTERROR_OK ) 15 | end function 16 | end extern -------------------------------------------------------------------------------- /file_input_ubyte.bas: -------------------------------------------------------------------------------- 1 | /' input function for unsigned bytes '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/math.bi" 5 | 6 | extern "C" 7 | function fb_InputUbyte FBCALL ( dst as ubyte ptr ) as long 8 | dim as ubyte buffer(0 to FB_INPUT_MAXNUMERICLEN) 9 | dim as ssize_t _len 10 | dim as long isfp 11 | 12 | _len = fb_FileInputNextToken( @buffer(0), FB_INPUT_MAXNUMERICLEN, FB_FALSE, @isfp ) 13 | 14 | if ( isfp = FALSE ) then 15 | *dst = cast(ubyte, fb_hStr2UInt( @buffer(0), _len )) 16 | else 17 | *dst = cast(ubyte, rint( fb_hStr2Double( @buffer(0), _len ) )) 18 | end if 19 | 20 | return fb_ErrorSetNum( FB_RTERROR_OK ) 21 | end function 22 | end extern -------------------------------------------------------------------------------- /file_input_uint.bas: -------------------------------------------------------------------------------- 1 | /' input function for unsigned integers '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/math.bi" 5 | 6 | extern "C" 7 | function fb_InputUint FBCALL ( dst as ulong ptr ) as long 8 | dim as ubyte buffer(0 to FB_INPUT_MAXNUMERICLEN) 9 | dim as ssize_t _len 10 | dim as long isfp 11 | 12 | _len = fb_FileInputNextToken( @buffer(0), FB_INPUT_MAXNUMERICLEN, FB_FALSE, @isfp ) 13 | 14 | if ( isfp = FALSE ) then 15 | *dst = fb_hStr2UInt( @buffer(0), _len ) 16 | else 17 | *dst = cast(ulong, rint( fb_hStr2Double( @buffer(0), _len ) )) 18 | end if 19 | 20 | return fb_ErrorSetNum( FB_RTERROR_OK ) 21 | end function 22 | end extern -------------------------------------------------------------------------------- /file_input_ulongint.bas: -------------------------------------------------------------------------------- 1 | /' input function for signed long long's '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/math.bi" 5 | 6 | extern "C" 7 | function fb_InputUlongint FBCALL ( dst as ulongint ptr ) as long 8 | dim as ubyte buffer(0 to FB_INPUT_MAXNUMERICLEN) 9 | dim as ssize_t _len 10 | dim as long isfp 11 | 12 | _len = fb_FileInputNextToken( @buffer(0), FB_INPUT_MAXNUMERICLEN, FB_FALSE, @isfp ) 13 | 14 | if ( isfp = FALSE ) then 15 | if ( _len <= FB_INPUT_MAXINTLEN ) then 16 | *dst = cast(ulongint,cast(longint,fb_hStr2Int( @buffer(0), _len ))) 17 | else 18 | *dst = fb_hStr2ULongint( @buffer(0), _len ) 19 | end if 20 | else 21 | *dst = cast(ulongint, rint( fb_hStr2Double( @buffer(0), _len ) )) 22 | end if 23 | 24 | return fb_ErrorSetNum( FB_RTERROR_OK ) 25 | end function 26 | end extern -------------------------------------------------------------------------------- /file_input_ushort.bas: -------------------------------------------------------------------------------- 1 | /' input function for usigned shorts '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/math.bi" 5 | 6 | extern "C" 7 | function fb_InputUshort FBCALL ( dst as ushort ptr ) as long 8 | dim as ubyte buffer(0 to FB_INPUT_MAXNUMERICLEN) 9 | dim as ssize_t _len 10 | dim as long isfp 11 | 12 | _len = fb_FileInputNextToken( @buffer(0), FB_INPUT_MAXNUMERICLEN, FB_FALSE, @isfp ) 13 | 14 | if ( isfp = FALSE ) then 15 | *dst = cast(ushort, fb_hStr2UInt( @buffer(0), _len )) 16 | else 17 | *dst = cast(ushort, rint( fb_hStr2Double( @buffer(0), _len ) )) 18 | end if 19 | 20 | return fb_ErrorSetNum( FB_RTERROR_OK ) 21 | end function 22 | end extern -------------------------------------------------------------------------------- /file_input_wstr.bas: -------------------------------------------------------------------------------- 1 | /' input function for wstring's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_InputWstr FBCALL ( _str as FB_WCHAR ptr, length as ssize_t ) as long 7 | dim as FB_WCHAR buffer(0 to FB_INPUT_MAXSTRINGLEN) 8 | 9 | fb_FileInputNextTokenWstr( @buffer(0), FB_INPUT_MAXSTRINGLEN, TRUE ) 10 | 11 | fb_WstrAssign( _str, length, @buffer(0) ) 12 | return fb_ErrorSetNum( FB_RTERROR_OK ) 13 | end function 14 | end extern -------------------------------------------------------------------------------- /file_kill.bas: -------------------------------------------------------------------------------- 1 | /' kill function '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/errno.bi" 5 | 6 | /':::::'/ 7 | extern "C" 8 | function fb_FileKill FBCALL ( _str as FBSTRING ptr ) as long 9 | dim as long res = 0, _err = 0 10 | 11 | if ( _str->data <> NULL ) then 12 | res = remove( _str->data ) 13 | _err = errno 14 | end if 15 | 16 | /' del if temp '/ 17 | fb_hStrDelTemp( _str ) 18 | 19 | if ( res = 0 ) then 20 | res = FB_RTERROR_OK 21 | else 22 | select case (_err) 23 | case ENOENT: 24 | res = FB_RTERROR_FILENOTFOUND 25 | case EACCES: 26 | res = FB_RTERROR_FILEIO 27 | case EPERM: 28 | res = FB_RTERROR_NOPRIVILEGES 29 | default: 30 | res = FB_RTERROR_ILLEGALFUNCTIONCALL 31 | end select 32 | end if 33 | 34 | return fb_ErrorSetNum( res ) 35 | end function 36 | end extern -------------------------------------------------------------------------------- /file_len.bas: -------------------------------------------------------------------------------- 1 | /' get file length by filename '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_FileLenEx( filename as const ubyte ptr ) as fb_off_t 7 | dim as FILE ptr fp 8 | dim as fb_off_t _len 9 | 10 | fp = fopen( cast(ubyte ptr, filename), "rb" ) 11 | if ( fp <> NULL ) then 12 | if ( fseeko( fp, 0, SEEK_END ) = 0 ) then 13 | _len = ftello( fp ) 14 | if ( _len <> -1 ) then 15 | fclose( fp ) 16 | fb_ErrorSetNum( FB_RTERROR_OK ) 17 | return _len 18 | end if 19 | end if 20 | 21 | fclose( fp ) 22 | end if 23 | 24 | fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 25 | return 0 26 | end function 27 | 28 | function fb_FileLen FBCALL ( filename as const ubyte ptr ) as longint 29 | return fb_FileLenEx( filename ) 30 | end function 31 | end extern -------------------------------------------------------------------------------- /file_lineinp_wstr.bas: -------------------------------------------------------------------------------- 1 | /' line input function for wstrings '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_FileLineInputWstr FBCALL ( fnum as long, dst as FB_WCHAR ptr, max_chars as ssize_t ) as long 7 | dim as FB_FILE ptr handle = FB_FILE_TO_HANDLE(fnum) 8 | 9 | if ( FB_HANDLE_USED(handle) = 0 ) then 10 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 11 | end if 12 | 13 | if ( handle->hooks->pfnReadLineWstr = NULL ) then 14 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 15 | end if 16 | 17 | return handle->hooks->pfnReadLineWstr( handle, dst, max_chars ) 18 | end function 19 | end extern -------------------------------------------------------------------------------- /file_loc.bas: -------------------------------------------------------------------------------- 1 | /' seek function and stmt '/ 2 | 3 | #include "fb.bi" 4 | 5 | /':::::'/ 6 | extern "C" 7 | function fb_FileLocationEx( handle as FB_FILE ptr ) as fb_off_t 8 | dim as fb_off_t _pos 9 | 10 | if ( FB_HANDLE_USED(handle) = 0 ) then 11 | return 0 12 | end if 13 | 14 | FB_LOCK() 15 | 16 | _pos = fb_FileTellEx( handle ) 17 | 18 | if (_pos <> 0) then 19 | _pos -= 1 20 | select case ( handle->mode ) 21 | case FB_FILE_MODE_INPUT, FB_FILE_MODE_OUTPUT: 22 | /' if in seq mode, divide by 128 (QB quirk) '/ 23 | _pos /= 128 24 | end select 25 | end if 26 | 27 | FB_UNLOCK() 28 | 29 | return _pos 30 | end function 31 | 32 | /':::::'/ 33 | function fb_FileLocation FBCALL ( fnum as long ) as longint 34 | return fb_FileLocationEx( FB_FILE_TO_HANDLE(fnum) ) 35 | end function 36 | end extern 37 | -------------------------------------------------------------------------------- /file_open.bas: -------------------------------------------------------------------------------- 1 | /' open and core file functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_FileOpenEx( handle as FB_FILE ptr, _str as FBSTRING ptr, mode as ulong, access_ as ulong, _lock as ulong, _len as long ) as long 7 | return fb_FileOpenVfsEx( handle, _str, mode, access_, _lock, _len, FB_FILE_ENCOD_DEFAULT, @fb_DevFileOpen ) 8 | end function 9 | 10 | function fb_FileOpen FBCALL ( _str as FBSTRING ptr, mode as ulong, access_ as ulong, _lock as ulong, fnum as long, _len as long ) as long 11 | if ( FB_FILE_INDEX_VALID( fnum ) = NULL ) then 12 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 13 | end if 14 | return fb_FileOpenEx( FB_FILE_TO_HANDLE(fnum), _str, mode, access_, _lock, _len ) 15 | end function 16 | end extern -------------------------------------------------------------------------------- /file_opencom.bas: -------------------------------------------------------------------------------- 1 | /' open COMx '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_FileOpenCom FBCALL ( str_filename as FBSTRING ptr, mode as ulong, access_ as ulong, _lock as ulong, fnum as long, _len as long, _encoding as const ubyte ptr ) as long 8 | if ( FB_FILE_INDEX_VALID( fnum ) = NULL ) then 9 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 10 | end if 11 | 12 | return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum), _ 13 | str_filename, _ 14 | mode, _ 15 | access_, _ 16 | _lock, _ 17 | _len, _ 18 | fb_hFileStrToEncoding( _encoding ), _ 19 | @fb_DevComOpen ) 20 | end function 21 | end extern -------------------------------------------------------------------------------- /file_opencons.bas: -------------------------------------------------------------------------------- 1 | /' open CONS '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_FileOpenCons FBCALL ( str_filename as FBSTRING ptr, mode as ulong, access_ as ulong, _lock as ulong, fnum as long, _len as long, _encoding as const ubyte ptr ) as long 8 | if ( FB_FILE_INDEX_VALID( fnum ) = NULL ) then 9 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 10 | end if 11 | 12 | return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum), _ 13 | str_filename, _ 14 | mode, _ 15 | access_, _ 16 | _lock, _ 17 | _len, _ 18 | fb_hFileStrToEncoding( _encoding ), _ 19 | @fb_DevConsOpen ) 20 | end function 21 | end extern -------------------------------------------------------------------------------- /file_openencod.bas: -------------------------------------------------------------------------------- 1 | /' UTF-encoded file open function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_FileOpenEncod FBCALL ( _str as FBSTRING ptr, mode as ulong, access_ as ulong, _lock as ulong, fnum as long, _len as long, _encoding as const ubyte ptr ) as long 8 | 9 | if ( FB_FILE_INDEX_VALID( fnum ) = NULL ) then 10 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 11 | end if 12 | 13 | dim as FB_FILE_ENCOD encod = fb_hFileStrToEncoding( _encoding ) 14 | 15 | return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum), _str, mode, _ 16 | access_, _lock, _len, encod, _ 17 | iif(encod = FB_FILE_ENCOD_ASCII, _ 18 | @fb_DevFileOpen, _ 19 | @fb_DevFileOpenEncod) ) 20 | end function 21 | end extern -------------------------------------------------------------------------------- /file_openerr.bas: -------------------------------------------------------------------------------- 1 | /' open ERR '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_FileOpenErr FBCALL ( str_filename as FBSTRING ptr, mode as ulong, access_ as ulong, _lock as ulong, fnum as long, _len as long, _encoding as const ubyte ptr ) as long 8 | if ( FB_FILE_INDEX_VALID( fnum ) = NULL ) then 9 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 10 | end if 11 | 12 | return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum), _ 13 | str_filename, _ 14 | mode, _ 15 | access_, _ 16 | _lock, _ 17 | _len, _ 18 | fb_hFileStrToEncoding( _encoding ), _ 19 | @fb_DevErrOpen ) 20 | end function 21 | end extern -------------------------------------------------------------------------------- /file_openpipe.bas: -------------------------------------------------------------------------------- 1 | /' open PIPE '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_FileOpenPipe FBCALL ( str_filename as FBSTRING ptr, mode as ulong,_ 8 | access_ as ulong, _lock as ulong, _ 9 | fnum as long, _len as long, _encoding as const ubyte ptr ) as long 10 | if ( FB_FILE_INDEX_VALID( fnum ) = NULL ) then 11 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 12 | end if 13 | 14 | return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum), _ 15 | str_filename, _ 16 | mode, _ 17 | access_, _ 18 | _lock, _ 19 | _len, _ 20 | fb_hFileStrToEncoding( _encoding ), _ 21 | @fb_DevPipeOpen ) 22 | end function 23 | end extern -------------------------------------------------------------------------------- /file_openscrn.bas: -------------------------------------------------------------------------------- 1 | /' open SCRN '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_FileOpenScrn FBCALL ( str_filename as FBSTRING ptr, mode as ulong, _ 8 | access_ as ulong, _lock as ulong, _ 9 | fnum as long, _len as long, _encoding as const ubyte ptr ) as long 10 | if ( FB_FILE_INDEX_VALID( fnum ) = NULL ) then 11 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 12 | end if 13 | 14 | fb_DevScrnInit( ) 15 | 16 | return fb_FileOpenVfsEx( FB_FILE_TO_HANDLE(fnum), _ 17 | str_filename, _ 18 | mode, _ 19 | access_, _ 20 | _lock, _ 21 | _len, _ 22 | fb_hFileStrToEncoding( _encoding ), _ 23 | @fb_DevScrnOpen ) 24 | end function 25 | end extern -------------------------------------------------------------------------------- /file_print.bas: -------------------------------------------------------------------------------- 1 | /' print # function (formating is done at io_prn) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_hFilePrintBufferEx( handle as FB_FILE ptr, buffer as const any ptr, _len as size_t ) as long 8 | fb_DevScrnInit_Write( ) 9 | return fb_FilePutDataEx( handle, 0, buffer, _len, TRUE, TRUE, FALSE ) 10 | end function 11 | 12 | /':::::'/ 13 | function fb_hFilePrintBuffer( fnum as long, buffer as const ubyte ptr ) as long 14 | return fb_hFilePrintBufferEx( FB_FILE_TO_HANDLE(fnum), buffer, strlen( buffer ) ) 15 | end function 16 | end extern -------------------------------------------------------------------------------- /file_print_wstr.bas: -------------------------------------------------------------------------------- 1 | /' print # function (formating is done at io_prn) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_hFilePrintBufferWstrEx( handle as FB_FILE ptr, buffer as const FB_WCHAR ptr, _len as size_t) as long 8 | fb_DevScrnInit_WriteWstr( ) 9 | return fb_FilePutDataEx( handle, 0, buffer, _len, TRUE, TRUE, TRUE ) 10 | end function 11 | 12 | /':::::'/ 13 | function fb_hFilePrintBufferWstr ( fnum as long, buffer as const FB_WCHAR ptr ) as long 14 | return fb_hFilePrintBufferWstrEx( FB_FILE_TO_HANDLE(fnum), buffer, fb_wstr_Len( buffer ) ) 15 | end function 16 | end extern -------------------------------------------------------------------------------- /file_put_wstr.bas: -------------------------------------------------------------------------------- 1 | /' put # function for wstrings '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_FilePutWstrEx( handle as FB_FILE ptr, _pos as fb_off_t, _str as FB_WCHAR ptr, _len as ssize_t ) as long 7 | dim as long res 8 | 9 | /' perform call ... but only if there's data ... '/ 10 | if ( (_str <> NULL) and (_len > 0) ) then 11 | res = fb_FilePutDataEx( handle, _pos, cast(any ptr, _str), _len, TRUE, TRUE, TRUE ) 12 | else 13 | res = fb_ErrorSetNum( FB_RTERROR_OK ) 14 | end if 15 | 16 | return res 17 | end function 18 | 19 | function fb_FilePutWstr FBCALL ( fnum as long, _pos as long, _str as FB_WCHAR ptr, str_len as ssize_t ) as long 20 | return fb_FilePutWstrEx(FB_FILE_TO_HANDLE(fnum), _pos, _str, str_len) 21 | end function 22 | 23 | function fb_FilePutWstrLarge FBCALL ( fnum as long, _pos as longint, _str as FB_WCHAR ptr, str_len as ssize_t ) as long 24 | return fb_FilePutWstrEx(FB_FILE_TO_HANDLE(fnum), _pos, _str, str_len) 25 | end function 26 | end extern -------------------------------------------------------------------------------- /file_putarray.bas: -------------------------------------------------------------------------------- 1 | /' put # function for arrays '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_FilePutArray FBCALL ( fnum as long, _pos as long, src as FBARRAY ptr ) as long 7 | return fb_FilePutData( fnum, _pos, src->_ptr, src->size, TRUE, FALSE ) 8 | end function 9 | 10 | function fb_FilePutArrayLarge FBCALL ( fnum as long, _pos as longint, src as FBARRAY ptr ) as long 11 | return fb_FilePutData( fnum, _pos, src->_ptr, src->size, TRUE, FALSE ) 12 | end function 13 | end extern -------------------------------------------------------------------------------- /file_reset.bas: -------------------------------------------------------------------------------- 1 | /' RESET function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_FileReset FBCALL ( ) 8 | dim as long i 9 | 10 | if ( __fb_ctx.do_file_reset = FALSE ) then 11 | exit sub 12 | end if 13 | 14 | __fb_ctx.do_file_reset = FALSE 15 | 16 | FB_LOCK() 17 | 18 | for i = 1 to (FB_MAX_FILES - FB_RESERVED_FILES) 19 | dim as FB_FILE ptr handle = FB_FILE_TO_HANDLE_VALID( i ) 20 | if ( handle->hooks <> NULL ) then 21 | DBG_ASSERT(handle->hooks->pfnClose <> NULL) 22 | handle->hooks->pfnClose( handle ) 23 | end if 24 | next 25 | 26 | /' clear all file handles '/ 27 | memset( FB_FILE_TO_HANDLE_VALID( 1 ), _ 28 | 0, _ 29 | sizeof(FB_FILE) * (FB_MAX_FILES - FB_RESERVED_FILES) ) 30 | 31 | FB_UNLOCK() 32 | end sub 33 | end extern -------------------------------------------------------------------------------- /file_resetex.bas: -------------------------------------------------------------------------------- 1 | /' recover stdio after redirection '/ 2 | 3 | #include "fb.bi" 4 | 5 | /' streamno: 6 | 0 Reset stdin 7 | 1 Reset stdout '/ 8 | extern "C" 9 | sub fb_FileResetEx FBCALL ( streamno as long ) 10 | dim as long errnum 11 | 12 | FB_LOCK() 13 | 14 | select case ( streamno ) 15 | case 0, 1: 16 | errnum = iif(fb_hFileResetEx( streamno ) <> 0, FB_RTERROR_OK, FB_RTERROR_FILEIO) 17 | case else: 18 | errnum = FB_RTERROR_ILLEGALFUNCTIONCALL 19 | end select 20 | 21 | FB_UNLOCK() 22 | 23 | fb_ErrorSetNum( errnum ) 24 | end sub 25 | end extern -------------------------------------------------------------------------------- /freebsd/io_mouse.bas: -------------------------------------------------------------------------------- 1 | /' console mode mouse functions '/ 2 | 3 | #include "../fb.bi" 4 | 5 | Extern "c" 6 | Function fb_ConsoleGetMouse( x as long ptr, y as long ptr, z as long ptr, buttons as long ptr, clip as long ptr ) as long 7 | 8 | if (x) then *x = -1 9 | if (y) then *y = -1 10 | if (z) then *z = -1 11 | if (buttons) then *buttons = -1 12 | 13 | if (clip) *clip = -1; return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 14 | End Function 15 | 16 | Function fb_ConsoleSetMouse( x as long, y as long, cursor as long, clip as long ) as long 17 | 18 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 19 | End Function 20 | End Extern -------------------------------------------------------------------------------- /freebsd/io_multikey.bas: -------------------------------------------------------------------------------- 1 | /' console multikey() '/ 2 | 3 | #include "../fb.bi" 4 | 5 | Extern "c" 6 | Function fb_ConsoleMultikey( scancode as long ) as long 7 | 8 | fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 9 | return FB_FALSE 10 | End Function 11 | End Extern -------------------------------------------------------------------------------- /freebsd/sys_fmem.bas: -------------------------------------------------------------------------------- 1 | /' fre() function '/ 2 | 3 | #include "../fb.bi" 4 | #include "sys/sysctl.bi" 5 | #include "sys/vmmeter.bi" 6 | #include "vm/vm_param.bi" 7 | 8 | Extern "c" 9 | Function fb_GetMemAvail FBCALL ( mode as long ) as size_t 10 | 11 | dim mib(0 to 1) as long = { CTL_VM, VM_TOTAL } 12 | dim vmt as vmtotal 13 | dmi size as size_t = sizeof(vmtotal) 14 | 15 | if( sysctl( @mib(0), 2, @vmt, @size, NULL, 0 ) ) then return 0 16 | 17 | return vmt.t_free * sysconf( _SC_PAGE_SIZE ) 18 | End Function 19 | End Extern -------------------------------------------------------------------------------- /freebsd/sys_getexename.bas: -------------------------------------------------------------------------------- 1 | /' get the executable's name '/ 2 | 3 | #include "../fb.bi" 4 | #include "sys/sysctl.bi" 5 | 6 | Extern "c" 7 | Function fb_hGetExeName( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 8 | 9 | dim len_ as size_t = maxlen 10 | dim p as ubyte ptr 11 | dim mib(0 to 3) as long = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1} 12 | 13 | if (sysctl(@mib(0), 4, dst, @len_, NULL, 0) = 0) then 14 | dst[len_] = 0 15 | p = strrchr(dst, asc("/")) 16 | if (p <> NULL) then 17 | p += 1 18 | else 19 | p = dst 20 | end if 21 | else 22 | p = NULL 23 | end if 24 | 25 | return p 26 | End Function 27 | End Extern 28 | -------------------------------------------------------------------------------- /freebsd/sys_getexepath.bas: -------------------------------------------------------------------------------- 1 | /' get the executable path '/ 2 | 3 | #include "../fb.bi" 4 | #include "sys/sysctl.bi" 5 | 6 | Extern "c" 7 | Function fb_hGetExePath( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 8 | 9 | dim len_ as size_t = maxlen 10 | dim p as ubyte ptr 11 | dim mib(0 to 3) as long = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1} 12 | 13 | if (sysctl(@mib(0), 4, dst, @len_, NULL, 0) = 0) then 14 | p = strrchr(dst, asc("/")) 15 | if (p = dst) then /' keep the "/" rather than returning "" '/ 16 | *(p + 1) = 0 17 | elseif (p) then 18 | *p = 0 19 | else 20 | dst[0] = 0 21 | end if 22 | else 23 | p = NULL 24 | end if 25 | 26 | return p 27 | End Function 28 | End Extern 29 | -------------------------------------------------------------------------------- /hook_cls.bas: -------------------------------------------------------------------------------- 1 | /' cls entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_Cls FBCALL ( mode as long ) 8 | fb_DevScrnInit_NoOpen( ) 9 | 10 | FB_LOCK() 11 | 12 | if ( __fb_ctx.hooks.clsproc <> NULL ) then 13 | __fb_ctx.hooks.clsproc( mode ) 14 | else 15 | fb_ConsoleClear( mode ) 16 | end if 17 | 18 | FB_HANDLE_SCREEN->line_length = 0 19 | 20 | FB_UNLOCK() 21 | 22 | end sub 23 | end extern -------------------------------------------------------------------------------- /hook_color.bas: -------------------------------------------------------------------------------- 1 | /' color entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_Color FBCALL ( fc as ulong, bc as ulong, flags as long ) as ulong 8 | dim as long cur 9 | 10 | FB_LOCK() 11 | 12 | if ( __fb_ctx.hooks.colorproc <> NULL ) then 13 | cur = __fb_ctx.hooks.colorproc( fc, bc, flags ) 14 | else 15 | cur = fb_ConsoleColor( fc, bc, flags ) 16 | end if 17 | 18 | FB_UNLOCK() 19 | 20 | return cur 21 | end function 22 | end extern -------------------------------------------------------------------------------- /hook_getmouse.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_GetMouse FBCALL ( x as long ptr, y as long ptr, z as long ptr, buttons as long ptr, clip as long ptr ) as long 5 | dim as long res 6 | 7 | FB_LOCK() 8 | 9 | if ( __fb_ctx.hooks.getmouseproc <> NULL ) then 10 | res = __fb_ctx.hooks.getmouseproc( x, y, z, buttons, clip ) 11 | else 12 | res = fb_ConsoleGetMouse( x, y, z, buttons, clip ) 13 | end if 14 | 15 | FB_UNLOCK() 16 | 17 | return res 18 | end function 19 | end extern -------------------------------------------------------------------------------- /hook_getmouse64.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_GetMouse64 FBCALL ( x as longint ptr, y as longint ptr, z as longint ptr, buttons as longint ptr, clip as longint ptr ) as long 5 | dim as long res, ix = -1, iy = -1, iz = -1, ibuttons = -1, iclip = -1 6 | 7 | res = fb_GetMouse( @ix, @iy, @iz, @ibuttons, @iclip ) 8 | 9 | if (x) then *x = ix 10 | if (y) then *y = iy 11 | if (z) then *z = iz 12 | if (buttons) then *buttons = ibuttons 13 | if (clip) then *clip = iclip 14 | return res 15 | end function 16 | end extern -------------------------------------------------------------------------------- /hook_getsize.bas: -------------------------------------------------------------------------------- 1 | /' getsize entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_GetSize FBCALL ( cols as long ptr, rows as long ptr ) 8 | FB_LOCK() 9 | 10 | if ( __fb_ctx.hooks.getsizeproc <> NULL ) then 11 | __fb_ctx.hooks.getsizeproc( cols, rows ) 12 | else 13 | fb_ConsoleGetSize( cols, rows ) 14 | end if 15 | 16 | FB_UNLOCK() 17 | end sub 18 | end extern -------------------------------------------------------------------------------- /hook_getx.bas: -------------------------------------------------------------------------------- 1 | /' getx entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_GetX FBCALL ( ) as long 8 | dim as long res 9 | 10 | FB_LOCK() 11 | 12 | if ( __fb_ctx.hooks.getxproc <> NULL ) then 13 | res = __fb_ctx.hooks.getxproc( ) 14 | else 15 | res = fb_ConsoleGetX( ) 16 | end if 17 | 18 | FB_UNLOCK() 19 | 20 | return res 21 | end function 22 | end extern -------------------------------------------------------------------------------- /hook_getxy.bas: -------------------------------------------------------------------------------- 1 | /' getxy entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_GetXY FBCALL ( col as long ptr, row as long ptr ) 8 | FB_LOCK() 9 | 10 | if ( __fb_ctx.hooks.getxyproc <> NULL ) then 11 | __fb_ctx.hooks.getxyproc( col, row ) 12 | else 13 | fb_ConsoleGetXY( col, row ) 14 | end if 15 | FB_UNLOCK() 16 | end sub 17 | end extern -------------------------------------------------------------------------------- /hook_gety.bas: -------------------------------------------------------------------------------- 1 | /' gety entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_GetY FBCALL ( ) as long 8 | dim as long res 9 | 10 | FB_LOCK() 11 | 12 | if ( __fb_ctx.hooks.getyproc <> NULL ) then 13 | res = __fb_ctx.hooks.getyproc( ) 14 | else 15 | res = fb_ConsoleGetY( ) 16 | end if 17 | FB_UNLOCK() 18 | 19 | return res 20 | end function 21 | end extern -------------------------------------------------------------------------------- /hook_isredir.bas: -------------------------------------------------------------------------------- 1 | /' input/ouput redirection check '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_IsRedirected FBCALL ( is_input as long ) as long 7 | dim as long result 8 | 9 | FB_LOCK( ) 10 | 11 | if ( __fb_ctx.hooks.isredirproc <> NULL ) then 12 | result = __fb_ctx.hooks.isredirproc( is_input ) 13 | else 14 | result = fb_ConsoleIsRedirected( is_input ) 15 | end if 16 | 17 | FB_UNLOCK( ) 18 | 19 | return result 20 | end function 21 | end extern -------------------------------------------------------------------------------- /hook_lineinp.bas: -------------------------------------------------------------------------------- 1 | /' console line input function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_LineInput FBCALL ( text as FBSTRING ptr, dst as any ptr, dst_len as ssize_t, fillrem as long, addquestion as long, addnewline as long ) as long 7 | dim as FB_LINEINPUTPROC lineinputproc 8 | 9 | FB_LOCK() 10 | lineinputproc = __fb_ctx.hooks.lineinputproc 11 | FB_UNLOCK() 12 | 13 | if ( lineinputproc <> NULL ) then 14 | return lineinputproc( text, dst, dst_len, fillrem, addquestion, addnewline ) 15 | else 16 | return fb_ConsoleLineInput( text, dst, dst_len, fillrem, addquestion, addnewline ) 17 | end if 18 | end function 19 | end extern -------------------------------------------------------------------------------- /hook_lineinp_wstr.bas: -------------------------------------------------------------------------------- 1 | /' console line input function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_LineInputWstr FBCALL ( text as const FB_WCHAR ptr, dst as FB_WCHAR ptr, max_chars as ssize_t, addquestion as long, addnewline as long ) as long 7 | dim as FB_LINEINPUTWPROC fn 8 | 9 | FB_LOCK() 10 | fn = __fb_ctx.hooks.lineinputwproc 11 | FB_UNLOCK() 12 | 13 | if ( fn <> NULL ) then 14 | return fn( text, dst, max_chars, addquestion, addnewline ) 15 | else 16 | return fb_ConsoleLineInputWstr( text, dst, max_chars, addquestion, addnewline ) 17 | end if 18 | end function 19 | end extern -------------------------------------------------------------------------------- /hook_multikey.bas: -------------------------------------------------------------------------------- 1 | /' multikey entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_Multikey FBCALL ( scancode as long ) as long 8 | dim as long res 9 | 10 | FB_LOCK() 11 | 12 | if ( __fb_ctx.hooks.multikeyproc <> NULL ) then 13 | res = __fb_ctx.hooks.multikeyproc( scancode ) 14 | else 15 | res = fb_ConsoleMultikey( scancode ) 16 | end if 17 | FB_UNLOCK() 18 | 19 | return res 20 | end function 21 | end extern -------------------------------------------------------------------------------- /hook_pageset.bas: -------------------------------------------------------------------------------- 1 | /' 'screen , pg, pg' entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_PageSet FBCALL ( active as long, visible as long ) as long 7 | dim as long res 8 | 9 | fb_DevScrnInit_NoOpen( ) 10 | 11 | FB_LOCK() 12 | 13 | if ( __fb_ctx.hooks.pagesetproc <> NULL ) then 14 | res = __fb_ctx.hooks.pagesetproc( active, visible ) 15 | else 16 | if ( (active >= FB_CONSOLE_MAXPAGES) or (visible >= FB_CONSOLE_MAXPAGES) ) then 17 | res = -1 18 | else 19 | res = fb_ConsolePageSet( active, visible ) 20 | end if 21 | end if 22 | 23 | FB_UNLOCK() 24 | 25 | return res 26 | end function 27 | end extern -------------------------------------------------------------------------------- /hook_pcopy.bas: -------------------------------------------------------------------------------- 1 | /' pcopy entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_PageCopy FBCALL ( src as long, dst as long ) as long 7 | fb_DevScrnInit_NoOpen( ) 8 | 9 | FB_LOCK() 10 | 11 | dim as long res 12 | 13 | if ( __fb_ctx.hooks.pagecopyproc <> NULL ) then 14 | res = __fb_ctx.hooks.pagecopyproc( src, dst ) 15 | else 16 | if( (src >= FB_CONSOLE_MAXPAGES) or (dst >= FB_CONSOLE_MAXPAGES) ) then 17 | return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL) 18 | end if 19 | 20 | res = fb_ConsolePageCopy( src, dst ) 21 | end if 22 | 23 | FB_UNLOCK() 24 | 25 | return res 26 | end function 27 | end extern -------------------------------------------------------------------------------- /hook_print_wstr.bas: -------------------------------------------------------------------------------- 1 | /' print wstring entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_PrintBufferWstrEx FBCALL ( buffer as const FB_WCHAR ptr, _len as size_t, mask as long ) 8 | FB_LOCK() 9 | 10 | if ( __fb_ctx.hooks.printbuffwproc <> NULL ) then 11 | __fb_ctx.hooks.printbuffwproc( buffer, _len, mask ) 12 | else 13 | fb_ConsolePrintBufferWstrEx( buffer, _len, mask ) 14 | end if 15 | 16 | FB_UNLOCK() 17 | 18 | end sub 19 | 20 | /':::::'/ 21 | sub fb_PrintBufferWstr FBCALL ( buffer as const FB_WCHAR ptr, mask as long ) 22 | fb_PrintBufferWstrEx( buffer, fb_wstr_Len( buffer ), mask ) 23 | end sub 24 | end extern -------------------------------------------------------------------------------- /hook_printstr.bas: -------------------------------------------------------------------------------- 1 | /' print string entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_PrintBufferEx FBCALL ( buffer as const any ptr, _len as size_t, mask as long ) 8 | FB_LOCK() 9 | 10 | if ( __fb_ctx.hooks.printbuffproc <> NULL ) then 11 | __fb_ctx.hooks.printbuffproc( buffer, _len, mask ) 12 | else 13 | fb_ConsolePrintBufferEx( buffer, _len, mask ) 14 | end if 15 | 16 | FB_UNLOCK() 17 | end sub 18 | 19 | /':::::'/ 20 | sub fb_PrintBuffer FBCALL ( buffer as const ubyte ptr, mask as long ) 21 | fb_PrintBufferEx( buffer, strlen( buffer ), mask ) 22 | end sub 23 | end extern -------------------------------------------------------------------------------- /hook_readstr.bas: -------------------------------------------------------------------------------- 1 | /' input$|line input entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_ReadString( buffer as ubyte ptr, _len as ssize_t, f as FILE ptr ) as ubyte ptr 7 | dim as ubyte ptr result 8 | 9 | if ( f <> stdin ) then 10 | result = fgets( buffer, _len, f ) 11 | else 12 | FB_LOCK( ) 13 | if ( __fb_ctx.hooks.readstrproc <> NULL ) then 14 | result = __fb_ctx.hooks.readstrproc( buffer, _len ) 15 | else 16 | result = fb_ConsoleReadStr( buffer, _len ) 17 | end if 18 | FB_UNLOCK( ) 19 | end if 20 | 21 | return result 22 | end function 23 | end extern -------------------------------------------------------------------------------- /hook_readxy.bas: -------------------------------------------------------------------------------- 1 | /' reads color valoe or character from X/Y position '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_ReadXY FBCALL ( col as long, row as long, colorflag as long ) as ulong 8 | dim as ulong res 9 | 10 | FB_LOCK() 11 | 12 | if ( __fb_ctx.hooks.readxyproc <> NULL ) then 13 | res = __fb_ctx.hooks.readxyproc( col, row, colorflag ) 14 | else 15 | res = fb_ConsoleReadXY( col, row, colorflag ) 16 | end if 17 | 18 | FB_UNLOCK() 19 | 20 | return res 21 | end function 22 | end extern -------------------------------------------------------------------------------- /hook_setmouse.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_SetMouse FBCALL ( x as long, y as long, cursor as long, clip as long ) as long 5 | dim as long res 6 | 7 | FB_LOCK() 8 | 9 | if ( __fb_ctx.hooks.getmouseproc <> NULL ) then 10 | res = __fb_ctx.hooks.setmouseproc( x, y, cursor, clip ) 11 | else 12 | res = fb_ConsoleSetMouse( x, y, cursor, clip ) 13 | end if 14 | 15 | FB_UNLOCK() 16 | 17 | return res 18 | end function 19 | end extern -------------------------------------------------------------------------------- /hook_sleep.bas: -------------------------------------------------------------------------------- 1 | /' sleep function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_Sleep FBCALL ( msecs as long ) 8 | dim as FB_SLEEPPROC sleepproc 9 | FB_LOCK() 10 | sleepproc = __fb_ctx.hooks.sleepproc 11 | FB_UNLOCK() 12 | if( sleepproc <> NULL ) then 13 | sleepproc( msecs ) 14 | else 15 | fb_ConsoleSleep( msecs ) 16 | end if 17 | end sub 18 | end extern -------------------------------------------------------------------------------- /hook_view_update.bas: -------------------------------------------------------------------------------- 1 | /' call back function that gets called whenever VIEW PRINT was called '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_ViewUpdate FBCALL ( ) 8 | FB_LOCK() 9 | 10 | if ( __fb_ctx.hooks.viewupdateproc <> NULL ) then 11 | __fb_ctx.hooks.viewupdateproc( ) 12 | else 13 | fb_ConsoleViewUpdate( ) 14 | end if 15 | 16 | FB_UNLOCK() 17 | end sub 18 | end extern -------------------------------------------------------------------------------- /hook_width.bas: -------------------------------------------------------------------------------- 1 | /' width entrypoint, default to console mode '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_Width FBCALL ( cols as long, rows as long ) as long 8 | dim as long cur 9 | 10 | fb_DevScrnInit_NoOpen( ) 11 | 12 | FB_LOCK() 13 | 14 | if ( __fb_ctx.hooks.widthproc <> NULL ) then 15 | cur = __fb_ctx.hooks.widthproc( cols, rows ) 16 | else 17 | cur = fb_ConsoleWidth( cols, rows ) 18 | end if 19 | 20 | if ( cols>0 ) then 21 | FB_HANDLE_SCREEN->width = cols 22 | end if 23 | 24 | /' Reset VIEW PRINT '/ 25 | if ( (cols > 0) orelse (rows > 0) ) then 26 | fb_ConsoleView( 0, 0 ) 27 | end if 28 | 29 | FB_UNLOCK() 30 | 31 | return iif((cols < 1 andalso rows < 1), cur, 0) 32 | end function 33 | end extern -------------------------------------------------------------------------------- /intl_get.bas: -------------------------------------------------------------------------------- 1 | /' get i18n data '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_IntlGet( Index as eFbIntlIndex, disallow_localized as long ) as const ubyte ptr 8 | if( fb_I18nGet() <> NULL and disallow_localized = 0 ) then 9 | dim as const ubyte ptr pszResult = fb_DrvIntlGet( Index ) 10 | if ( pszResult <> NULL ) then 11 | return pszResult 12 | end if 13 | end if 14 | 15 | select case ( Index ) 16 | case eFIL_DateDivider: 17 | return sadd("/") 18 | case eFIL_TimeDivider: 19 | return sadd(":") 20 | case eFIL_NumDecimalPoint: 21 | return sadd(".") 22 | case eFIL_NumThousandsSeparator: 23 | return sadd(",") 24 | end select 25 | 26 | return NULL 27 | end function 28 | end extern -------------------------------------------------------------------------------- /intl_getdateformat.bas: -------------------------------------------------------------------------------- 1 | /' get short DATE format '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_IntlGetDateFormat( buffer as ubyte ptr, _len as size_t, disallow_localized as long ) as long 8 | if ( fb_I18nGet( ) <> NULL and disallow_localized = 0 ) then 9 | if ( fb_DrvIntlGetDateFormat( buffer, _len ) ) then 10 | return TRUE 11 | end if 12 | end if 13 | if ( _len < 11 ) then 14 | return FALSE 15 | end if 16 | memcpy(buffer, sadd("MM/dd/yyyy"), 11) 17 | return TRUE 18 | end function 19 | end extern -------------------------------------------------------------------------------- /intl_getset.bas: -------------------------------------------------------------------------------- 1 | /' turns internationalization on/off and queries status '/ 2 | 3 | #include "fb.bi" 4 | 5 | dim shared as long intl_on = TRUE 6 | 7 | extern "C" 8 | /':::::'/ 9 | sub fb_I18nSet FBCALL ( on_off as long ) 10 | intl_on = on_off <> 0 11 | end sub 12 | 13 | /':::::'/ 14 | function fb_I18nGet FBCALL ( ) as long 15 | return intl_on 16 | end function 17 | end extern -------------------------------------------------------------------------------- /intl_gettimeformat.bas: -------------------------------------------------------------------------------- 1 | /' get short TIME format '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_IntlGetTimeFormat( buffer as ubyte ptr, _len as size_t, disallow_localized as long ) as long 8 | if ( fb_I18nGet() <> NULL and disallow_localized = 0 ) then 9 | if ( fb_DrvIntlGetTimeFormat( buffer, _len ) <> NULL ) then 10 | return TRUE 11 | end if 12 | end if 13 | if ( _len < 9 ) then 14 | return FALSE 15 | end if 16 | strcpy(buffer, "HH:mm:ss") 17 | return TRUE 18 | end function 19 | end extern -------------------------------------------------------------------------------- /io_hinkey.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | /' Builds the string to be returned by the console/gfx inkey() functions '/ 5 | 6 | function fb_hMakeInkeyStr( key as long ) as FBSTRING ptr 7 | dim as FBSTRING ptr res 8 | 9 | if ( key > &hFF ) then 10 | /' 2-byte extended keycode '/ 11 | res = fb_CHR( 2, (key and &hFF), (key shr 8) ) 12 | else 13 | res = fb_CHR( 1, key ) 14 | end if 15 | 16 | return res 17 | end function 18 | end extern -------------------------------------------------------------------------------- /io_lpos.bas: -------------------------------------------------------------------------------- 1 | /' Returns the printers X position '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_LPos FBCALL ( printer_index as long ) as long 8 | dim as long cur 9 | dim as ubyte buffer(0 to 31) 10 | 11 | FB_LOCK() 12 | 13 | sprintf(@buffer(0), "LPT%d:", (printer_index+1)) 14 | cur = fb_DevPrinterGetOffset( @buffer(0) ) 15 | 16 | FB_UNLOCK() 17 | 18 | return cur 19 | end function 20 | end extern -------------------------------------------------------------------------------- /io_lprint_bool.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (boolean) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_LPrintBool FBCALL ( fnum as long, _val as ubyte, mask as long ) 8 | fb_LPrintInit() 9 | mask = FB_PRINT_CONVERT_BIN_NEWLINE(mask) 10 | FB_PRINTNUM( fnum, fb_hBoolToStr( _val ), mask, "%", "s" ) 11 | end sub 12 | end extern -------------------------------------------------------------------------------- /io_lprint_byte.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (byte) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_LPrintByte FBCALL ( fnum as long, _val as ubyte, mask as long ) 8 | fb_LPrintInit() 9 | mask = FB_PRINT_CONVERT_BIN_NEWLINE(mask) 10 | FB_PRINTNUM( fnum, cast(long, _val), mask, "% ", "d" ) 11 | end sub 12 | 13 | /':::::'/ 14 | sub fb_LPrintUByte FBCALL ( fnum as long, _val as ubyte, mask as long ) 15 | fb_LPrintInit() 16 | mask = FB_PRINT_CONVERT_BIN_NEWLINE(mask) 17 | FB_PRINTNUM( fnum, cast(ulong, _val), mask, "%", "u" ) 18 | end sub 19 | end extern -------------------------------------------------------------------------------- /io_lprint_fix.bas: -------------------------------------------------------------------------------- 1 | /' print [#] functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_LPrintFixString FBCALL ( fnum as long, s as const ubyte ptr, mask as long ) 8 | fb_LPrintInit() 9 | fb_PrintFixStringEx(FB_FILE_TO_HANDLE(fnum), s, FB_PRINT_CONVERT_BIN_NEWLINE(mask)) 10 | end sub 11 | end extern -------------------------------------------------------------------------------- /io_lprint_fp.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (floating point) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_LPrintSingle FBCALL ( fnum as long, _val as single, mask as long ) 8 | dim as ubyte buffer(0 to 8+1+9) '[8+1+9+1] 9 | 10 | fb_LPrintInit() 11 | fb_PrintFixString( fnum, fb_hFloat2Str( cast(double, _val), @buffer(0), 7, FB_F2A_ADDBLANK ), FB_PRINT_CONVERT_BIN_NEWLINE(mask) ) 12 | end sub 13 | 14 | /':::::'/ 15 | sub fb_LPrintDouble FBCALL ( fnum as long, _val as double, mask as long ) 16 | dim as ubyte buffer(0 to 16+1+9) '[16+1+9+1] 17 | 18 | fb_LPrintInit() 19 | fb_PrintFixString( fnum, fb_hFloat2Str( _val, @buffer(0), 16, FB_F2A_ADDBLANK ), FB_PRINT_CONVERT_BIN_NEWLINE(mask) ) 20 | end sub 21 | end extern -------------------------------------------------------------------------------- /io_lprint_int.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (int) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_LPrintInt FBCALL ( fnum as long, _val as long, mask as long ) 8 | fb_LPrintInit() 9 | mask = FB_PRINT_CONVERT_BIN_NEWLINE(mask) 10 | FB_PRINTNUM( fnum, _val, mask, "% ", "d" ) 11 | end sub 12 | 13 | /':::::'/ 14 | sub fb_LPrintUInt FBCALL ( fnum as long, _val as ulong, mask as long ) 15 | fb_LPrintInit() 16 | mask = FB_PRINT_CONVERT_BIN_NEWLINE(mask) 17 | FB_PRINTNUM( fnum, _val, mask, "%", "u" ) 18 | end sub 19 | end extern -------------------------------------------------------------------------------- /io_lprint_longint.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (longint) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_LPrintLongint FBCALL ( fnum as long, _val as longint, mask as long) 8 | fb_LPrintInit() 9 | mask = FB_PRINT_CONVERT_BIN_NEWLINE(mask) 10 | FB_PRINTNUM( fnum, _val, mask, "% ", FB_LL_FMTMOD "d" ) 11 | end sub 12 | 13 | /':::::'/ 14 | sub fb_LPrintULongint FBCALL ( fnum as long, _val as ulongint, mask as long ) 15 | fb_LPrintInit() 16 | mask = FB_PRINT_CONVERT_BIN_NEWLINE(mask) 17 | FB_PRINTNUM( fnum, _val, mask, "%", FB_LL_FMTMOD "u" ) 18 | end sub 19 | end extern -------------------------------------------------------------------------------- /io_lprint_short.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (short) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_LPrintShort FBCALL ( fnum as long, _val as short, mask as long ) 8 | fb_LPrintInit() 9 | mask = FB_PRINT_CONVERT_BIN_NEWLINE(mask) 10 | FB_PRINTNUM( fnum, _val, mask, "% ", "hd" ) 11 | end sub 12 | 13 | /':::::'/ 14 | sub fb_LPrintUShort FBCALL ( fnum as long, _val as ushort, mask as long) 15 | fb_LPrintInit() 16 | mask = FB_PRINT_CONVERT_BIN_NEWLINE(mask) 17 | FB_PRINTNUM( fnum, _val, mask, "%", "hu" ) 18 | end sub 19 | end extern -------------------------------------------------------------------------------- /io_lprint_str.bas: -------------------------------------------------------------------------------- 1 | /' print [#] functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_LPrintString FBCALL ( fnum as long, s as FBSTRING ptr, mask as long ) 8 | fb_LPrintInit() 9 | fb_PrintStringEx(FB_FILE_TO_HANDLE(fnum), s, FB_PRINT_CONVERT_BIN_NEWLINE(mask) ) 10 | end sub 11 | end extern 12 | -------------------------------------------------------------------------------- /io_lprint_wstr.bas: -------------------------------------------------------------------------------- 1 | /' print [#] functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_LPrintWstr FBCALL ( fnum as long, s as const FB_WCHAR ptr, mask as long ) 8 | fb_LPrintInit() 9 | 10 | fb_PrintWstrEx( FB_FILE_TO_HANDLE(fnum), s, FB_PRINT_CONVERT_BIN_NEWLINE(mask) ) 11 | end sub 12 | end extern -------------------------------------------------------------------------------- /io_lprintusg.bas: -------------------------------------------------------------------------------- 1 | /' print using function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_LPrintUsingInit FBCALL ( fmtstr as FBSTRING ptr ) as long 8 | dim as long res = fb_LPrintInit() 9 | if ( res <> FB_RTERROR_OK ) then 10 | return res 11 | end if 12 | return fb_PrintUsingInit( fmtstr ) 13 | end function 14 | end extern -------------------------------------------------------------------------------- /io_lprintvoid.bas: -------------------------------------------------------------------------------- 1 | /' print functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_LPrintVoid FBCALL ( fnum as long, mask as long ) 8 | fb_LPrintInit() 9 | fb_PrintVoidEx( FB_FILE_TO_HANDLE(fnum), FB_PRINT_CONVERT_BIN_NEWLINE(mask) ) 10 | end sub 11 | end extern -------------------------------------------------------------------------------- /io_print_bool.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (boolean) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_PrintBool FBCALL ( fnum as long, _val as ubyte, mask as long ) 8 | FB_PRINTNUM( fnum, fb_hBoolToStr( _val ), mask, "%", "s" ) 9 | end sub 10 | end extern -------------------------------------------------------------------------------- /io_print_byte.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (byte) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_PrintByte FBCALL ( fnum as long, _val as ubyte, mask as long ) 8 | FB_PRINTNUM( fnum, cast(long, _val), mask, "% ", "d" ) 9 | end sub 10 | 11 | /':::::'/ 12 | sub fb_PrintUByte FBCALL ( fnum as long, _val as ubyte, mask as long ) 13 | FB_PRINTNUM( fnum, cast(ulong, _val), mask, "%", "u" ) 14 | end sub 15 | end extern -------------------------------------------------------------------------------- /io_print_fix.bas: -------------------------------------------------------------------------------- 1 | /' print [#] functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | private sub fb_hPrintStrEx( handle as FB_FILE ptr, s as const ubyte ptr, _len as size_t, mask as long ) 8 | if ( _len <> 0 ) then 9 | FB_PRINT_EX(handle, s, _len, 0) 10 | end if 11 | 12 | fb_PrintVoidEx( handle, mask ) 13 | end sub 14 | 15 | /':::::'/ 16 | sub fb_PrintFixStringEx ( handle as FB_FILE ptr, s as const ubyte ptr, mask as long ) 17 | if ( s = NULL ) then 18 | fb_PrintVoidEx( handle, mask ) 19 | else 20 | fb_hPrintStrEx( handle, s, strlen( s ), mask ) 21 | end if 22 | end sub 23 | 24 | /':::::'/ 25 | sub fb_PrintFixString FBCALL ( fnum as long, s as const ubyte ptr, mask as long ) 26 | fb_PrintFixStringEx(FB_FILE_TO_HANDLE(fnum), s, mask) 27 | end sub 28 | end extern -------------------------------------------------------------------------------- /io_print_fp.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (floating point) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_PrintSingle FBCALL ( fnum as long, _val as single, mask as long ) 7 | dim as ubyte buffer(0 to 8+1+9) '[8+1+9+1] 8 | fb_PrintFixString( fnum, fb_hFloat2Str( cast(double, _val), @buffer(0), 7, FB_F2A_ADDBLANK ), mask ) 9 | end sub 10 | 11 | sub fb_PrintDouble FBCALL ( fnum as long, _val as double, mask as long ) 12 | dim as ubyte buffer(0 to 16+1+9) '[16+1+9+1] 13 | fb_PrintFixString( fnum, fb_hFloat2Str( _val, @buffer(0), 16, FB_F2A_ADDBLANK ), mask ) 14 | end sub 15 | end extern -------------------------------------------------------------------------------- /io_print_int.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (int) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_PrintInt FBCALL ( fnum as long, _val as long, mask as long ) 8 | FB_PRINTNUM( fnum, _val, mask, "% ", "d" ) 9 | end sub 10 | 11 | /':::::'/ 12 | sub fb_PrintUInt FBCALL ( fnum as long, _val as ulong, mask as long ) 13 | FB_PRINTNUM( fnum, _val, mask, "%", "u" ) 14 | end sub 15 | end extern -------------------------------------------------------------------------------- /io_print_longint.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (longint) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_PrintLongint FBCALL ( fnum as long, _val as longint, mask as long ) 8 | FB_PRINTNUM( fnum, _val, mask, "% ", FB_LL_FMTMOD "d" ) 9 | end sub 10 | 11 | /':::::'/ 12 | sub fb_PrintULongint FBCALL ( fnum as long, _val as ulongint, mask as long ) 13 | FB_PRINTNUM( fnum, _val, mask, "%", FB_LL_FMTMOD "u" ) 14 | end sub 15 | end extern -------------------------------------------------------------------------------- /io_print_short.bas: -------------------------------------------------------------------------------- 1 | /' print [#] function (short) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_PrintShort FBCALL ( fnum as long, _val as short, mask as long ) 8 | FB_PRINTNUM( fnum, _val, mask, "% ", "hd" ) 9 | end sub 10 | 11 | /':::::'/ 12 | sub fb_PrintUShort FBCALL ( fnum as long, _val as ushort, mask as long ) 13 | FB_PRINTNUM( fnum, _val, mask, "%", "hu" ) 14 | end sub 15 | end extern -------------------------------------------------------------------------------- /io_printvoid.bas: -------------------------------------------------------------------------------- 1 | /' print functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_PrintVoidEx( handle as FB_FILE ptr, mask as long ) 8 | if ( mask and FB_PRINT_BIN_NEWLINE ) then 9 | FB_PRINT_EX(handle, @FB_BINARY_NEWLINE, sizeof(FB_BINARY_NEWLINE)-1, mask) 10 | elseif ( mask and FB_PRINT_NEWLINE ) then 11 | FB_PRINT_EX(handle, @FB_NEWLINE, sizeof(FB_NEWLINE)-1, mask) 12 | elseif ( mask and FB_PRINT_PAD ) then 13 | fb_PrintPadEx( handle, mask and not(FB_PRINT_HLMASK) ) 14 | end if 15 | end sub 16 | 17 | /':::::'/ 18 | sub fb_PrintVoid FBCALL ( fnum as long, mask as long ) 19 | fb_PrintVoidEx( FB_FILE_TO_HANDLE(fnum), mask ) 20 | end sub 21 | end extern -------------------------------------------------------------------------------- /io_printvoid_wstr.bas: -------------------------------------------------------------------------------- 1 | /' print functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_PrintVoidWstrEx( handle as FB_FILE ptr, mask as long ) 8 | if ( mask and FB_PRINT_BIN_NEWLINE ) then 9 | FB_PRINTWSTR_EX( handle, @FB_BINARY_NEWLINE_WSTR, sizeof( FB_BINARY_NEWLINE_WSTR ) / sizeof( FB_WCHAR ) - 1, mask ) 10 | elseif ( mask and FB_PRINT_NEWLINE ) then 11 | FB_PRINTWSTR_EX( handle, @FB_NEWLINE_WSTR, sizeof( FB_NEWLINE_WSTR ) / sizeof( FB_WCHAR ) - 1, mask ) 12 | elseif ( mask and FB_PRINT_PAD ) then 13 | fb_PrintPadWstrEx( handle, mask and not(FB_PRINT_HLMASK) ) 14 | end if 15 | end sub 16 | 17 | /':::::'/ 18 | sub fb_PrintVoidWstr FBCALL ( fnum as long , mask as long ) 19 | fb_PrintVoidWstrEx( FB_FILE_TO_HANDLE(fnum), mask ) 20 | end sub 21 | end extern -------------------------------------------------------------------------------- /io_serial_private.bi: -------------------------------------------------------------------------------- 1 | #if defined(HOST_WIN32) 2 | #include "windows.bi" 3 | type W32_SERIAL_INFO 4 | as HANDLE hDevice 5 | as long iPort 6 | as FB_SERIAL_OPTIONS ptr pOptions 7 | end type 8 | #elseif defined(HOST_LINUX) 9 | /' Uncomment HAS_LOCKDEV to active lock file funcionality, not forget 10 | * compile whith -llockdev 11 | '/ 12 | /' #define HAS_LOCKDEV 1 '/ 13 | type LINUX_SERIAL_INFO 14 | as long sfd 15 | as termios oldtty, newtty 16 | #ifdef HAS_LOCKDEV 17 | as pid_t pplckid 18 | #endif 19 | as long iPort 20 | as FB_SERIAL_OPTIONS ptr pOptions 21 | end type 22 | #elseif defined(HOST_DOS) 23 | type DOS_SERIAL_INFO 24 | as long com_num 25 | as FB_SERIAL_OPTIONS ptr pOptions 26 | end type 27 | #endif 28 | -------------------------------------------------------------------------------- /io_setpos.bas: -------------------------------------------------------------------------------- 1 | /' Sets a file handles line length '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_SetPos FBCALL ( handle as FB_FILE ptr, line_length as long ) as long 7 | FB_LOCK() 8 | handle->line_length = line_length 9 | FB_UNLOCK() 10 | 11 | return fb_ErrorSetNum( FB_RTERROR_OK ) 12 | end function 13 | end extern -------------------------------------------------------------------------------- /io_writebool.bas: -------------------------------------------------------------------------------- 1 | /' write [#] function (boolean) '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_WriteBool FBCALL ( fnum as long, _val as ubyte, mask as long ) 8 | FB_WRITENUM( fnum, fb_hBoolToStr( _val ), mask, "%s" ) 9 | end sub 10 | end extern -------------------------------------------------------------------------------- /io_writebyte.bas: -------------------------------------------------------------------------------- 1 | /' write [#] functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_WriteByte FBCALL ( fnum as long, _val as byte, mask as long ) 8 | FB_WRITENUM( fnum, _val, mask, "%d" ) 9 | end sub 10 | 11 | /':::::'/ 12 | sub fb_WriteUByte FBCALL ( fnum as long, _val as ubyte , mask as long ) 13 | FB_WRITENUM( fnum, _val, mask, "%u" ) 14 | end sub 15 | end extern -------------------------------------------------------------------------------- /io_writeint.bas: -------------------------------------------------------------------------------- 1 | /' write [#] functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_WriteInt FBCALL ( fnum as long, _val as long, mask as long ) 8 | FB_WRITENUM( fnum, _val, mask, "%d" ) 9 | end sub 10 | 11 | /':::::'/ 12 | sub fb_WriteUInt FBCALL ( fnum as long, _val as ulong, mask as long ) 13 | FB_WRITENUM( fnum, _val, mask, "%u" ) 14 | end sub 15 | end extern -------------------------------------------------------------------------------- /io_writelongint.bas: -------------------------------------------------------------------------------- 1 | /' write [#] functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_WriteLongint FBCALL ( fnum as long, _val as longint, mask as long ) 8 | FB_WRITENUM( fnum, _val, mask, "%" FB_LL_FMTMOD "d" ) 9 | end sub 10 | 11 | /':::::'/ 12 | sub fb_WriteULongint FBCALL ( fnum as long, _val as ulongint, mask as long ) 13 | FB_WRITENUM( fnum, _val, mask, "%" FB_LL_FMTMOD "u" ) 14 | end sub 15 | end extern -------------------------------------------------------------------------------- /io_writeshort.bas: -------------------------------------------------------------------------------- 1 | /' write [#] functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_WriteShort FBCALL ( fnum as long, _val as short, mask as long ) 8 | FB_WRITENUM( fnum, _val, mask, "%hd" ) 9 | end sub 10 | 11 | /':::::'/ 12 | sub fb_WriteUShort FBCALL ( fnum as long, _val as ushort, mask as long ) 13 | FB_WRITENUM( fnum, _val, mask, "%hu" ) 14 | end sub 15 | end extern -------------------------------------------------------------------------------- /io_writevoid.bas: -------------------------------------------------------------------------------- 1 | /' write [#] functions '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_WriteVoid FBCALL ( fnum as long, mask as long ) 8 | dim as ubyte ptr buffer 9 | 10 | if ( mask and FB_PRINT_NEWLINE ) then 11 | *buffer = asc(FB_NEWLINE) 12 | 13 | elseif ( mask and FB_PRINT_PAD ) then 14 | *buffer = asc(!"\t") 15 | 16 | else 17 | buffer = NULL 18 | end if 19 | 20 | if ( buffer <> NULL ) then 21 | FB_PRINT(fnum, buffer, mask) 22 | end if 23 | end sub 24 | end extern -------------------------------------------------------------------------------- /legacy_str_lcase.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_LCASE FBCALL ( src as FBSTRING ptr ) as FBSTRING ptr 5 | return fb_StrLcase2( src, 0 ) 6 | end function 7 | end extern 8 | -------------------------------------------------------------------------------- /legacy_str_ucase.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_UCASE FBCALL ( src as FBSTRING ptr ) as FBSTRING ptr 5 | return fb_StrUcase2( src, 0 ) 6 | end function 7 | end extern 8 | -------------------------------------------------------------------------------- /legacy_strw_lcase.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_WstrLcase FBCALL ( src as const FB_WCHAR ptr ) as FB_WCHAR ptr 5 | return fb_WstrLcase2( src, 0 ) 6 | end function 7 | end extern 8 | -------------------------------------------------------------------------------- /legacy_strw_ucase.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_WstrUcase FBCALL ( src as const FB_WCHAR ptr ) as FB_WCHAR ptr 5 | return fb_WstrUcase2( src, 0 ) 6 | end function 7 | end extern -------------------------------------------------------------------------------- /linux/sys_fmem.bas: -------------------------------------------------------------------------------- 1 | /' fre() function '/ 2 | 3 | #include "../fb.bi" 4 | #include "sys/sysinfo.bi" 5 | 6 | Extern "c" 7 | Function fb_GetMemAvail FBCALL( mode as long ) as size_t 8 | 9 | return get_avphys_pages() * sysconf(_SC_PAGE_SIZE) 10 | End Function 11 | End Extern 12 | -------------------------------------------------------------------------------- /linux/sys_getexename.bas: -------------------------------------------------------------------------------- 1 | /' get the executable's name '/ 2 | 3 | #include "../fb.bi" 4 | #include "crt/sys/stat.bi" 5 | 6 | Extern "c" 7 | Function fb_hGetExeName( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 8 | 9 | dim p as ubyte ptr 10 | dim linkname(0 to 1023) as ubyte 11 | dim linknameptr as ubyte ptr = @linkname(0) 12 | dim finfo as stat 13 | dim len_ as ssize_t 14 | 15 | sprintf(linknameptr, "/proc/%d/exe", getpid()) 16 | if (stat(linknameptr, @finfo) = 0) then 17 | len_ = readlink(linknameptr, dst, maxlen - 1) 18 | if (len_ > -1) then 19 | /' Linux-like proc fs is available '/ 20 | dst[len_] = 0 21 | p = strrchr(dst, asc("/")) 22 | if (p <> NULL) then 23 | p += 1 24 | else 25 | p = dst 26 | end if 27 | end if 28 | else 29 | p = NULL 30 | end if 31 | 32 | return p 33 | End Function 34 | End Extern 35 | -------------------------------------------------------------------------------- /linux/sys_getexepath.bas: -------------------------------------------------------------------------------- 1 | /' get the executable path '/ 2 | 3 | #include "../fb.bi" 4 | #include "crt/sys/stat.bi" 5 | 6 | Extern "c" 7 | Function fb_hGetExePath( dst as ubyte ptr, maxlen as ssize_t ) As ubyte ptr 8 | 9 | dim p as ubyte ptr 10 | dim finfo as stat 11 | dim len as ssize_t 12 | 13 | if (stat("/proc/self/exe", @finfo) = 0) then 14 | len = readlink("/proc/self/exe", dst, maxlen - 1) 15 | if(len > -1) then 16 | /' Linux-like proc fs is available '/ 17 | dst[len] = 0 18 | p = strrchr(dst, asc("/")) 19 | if (p = dst) then /' keep the "/" rather than returning "" '/ 20 | *(p + 1) = 0 21 | elseif (p <> Null) then 22 | *p = 0 23 | else 24 | dst[0] = 0 25 | end if 26 | end if 27 | else 28 | p = NULL 29 | end if 30 | 31 | return p 32 | End Function 33 | End Extern -------------------------------------------------------------------------------- /math_cvn.bas: -------------------------------------------------------------------------------- 1 | /' CV# numeric routines '/ 2 | 3 | #include "fb.bi" 4 | 5 | #macro hDoCVn(from, to_t, size) 6 | if ( (size) = sizeof(from) and (size) = sizeof(to_t) ) then 7 | dim as to_t _to 8 | memcpy( @_to, @from, size ) 9 | return _to 10 | else 11 | return cast(to_t, 0) 12 | end if 13 | #endmacro 14 | 15 | extern "C" 16 | function fb_CVDFROMLONGINT FBCALL ( ll as longint ) as double 17 | hDoCVn( ll, double, 8 ) 18 | end function 19 | 20 | function fb_CVSFROML FBCALL ( l as long ) as single 21 | hDoCVn( l, single, 4 ) 22 | end function 23 | 24 | function fb_CVLFROMS FBCALL ( f as single ) as long 25 | hDoCVn( f, long, 4 ) 26 | end function 27 | 28 | function fb_CVLONGINTFROMD FBCALL ( d as double ) as longint 29 | hDoCVn( d, longint, 8 ) 30 | end function 31 | end extern -------------------------------------------------------------------------------- /math_fix.bas: -------------------------------------------------------------------------------- 1 | /' fix function for singles and doubles FIX( x ) = SGN( x ) * INT( ABS( x ) ) '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/math.bi" 5 | 6 | extern "C" 7 | /':::::'/ 8 | function fb_FIXSingle FBCALL ( x as single ) as single 9 | return floorf(fabsf( x )) * fb_SGNSingle( x ) 10 | end function 11 | 12 | /':::::'/ 13 | function fb_FIXDouble FBCALL ( x as double ) as double 14 | return floor( fabs( x ) ) * fb_SGNDouble( x ) 15 | end function 16 | end extern -------------------------------------------------------------------------------- /math_frac.bas: -------------------------------------------------------------------------------- 1 | /' frac( x ) = x - fix( x ) - returns the fractional part of a float '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_FRACf FBCALL ( x as single ) as single 7 | return x - fb_FIXSingle( x ) 8 | end function 9 | 10 | function fb_FRACd FBCALL ( x as double ) as double 11 | return x - fb_FIXDouble( x ) 12 | end function 13 | end extern -------------------------------------------------------------------------------- /mem_copyclear.bas: -------------------------------------------------------------------------------- 1 | /' LSET for non-strings '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_MemCopyClear FBCALL ( dst as ubyte ptr, dstlen as size_t, src as ubyte ptr, srclen as size_t ) 7 | dim as size_t bytes 8 | 9 | if ( (dst = NULL) or (src = NULL) or (dstlen = 0) ) then 10 | exit sub 11 | end if 12 | 13 | bytes = iif(dstlen <= srclen, dstlen, srclen) 14 | 15 | /' move '/ 16 | if( bytes > 0 ) then 17 | memcpy( dst, src, bytes ) 18 | end if 19 | 20 | /' clear remainder '/ 21 | dstlen -= bytes 22 | if ( dstlen > 0 ) then 23 | memset( @dst[bytes], 0, dstlen ) 24 | end if 25 | end sub 26 | end extern 27 | -------------------------------------------------------------------------------- /netbsd/io_mouse.bas: -------------------------------------------------------------------------------- 1 | /' console mode mouse functions '/ 2 | 3 | #include "../fb.bi" 4 | 5 | Extern "c" 6 | Function fb_ConsoleGetMouse( x as long ptr, y as long ptr, z as long ptr, buttons as long ptr, clip as long ptr ) as long 7 | 8 | if (x) then *x = -1 9 | if (y) then *y = -1 10 | if (z) then *z = -1 11 | if (buttons) then *buttons = -1 12 | if (clip) then *clip = -1 13 | 14 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 15 | End Function 16 | 17 | Function fb_ConsoleSetMouse( x as long, y as long, cursor as long, clip as long ) as long 18 | 19 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 20 | End Function 21 | End Extern -------------------------------------------------------------------------------- /netbsd/io_multikey.bas: -------------------------------------------------------------------------------- 1 | /' console multikey() '/ 2 | 3 | #include "../fb.bi" 4 | 5 | Extern "c" 6 | Function fb_ConsoleMultikey( scancode as long ) as long 7 | 8 | fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 9 | return FB_FALSE 10 | End Function 11 | End Extern 12 | -------------------------------------------------------------------------------- /netbsd/sys_fmem.bas: -------------------------------------------------------------------------------- 1 | /' fre() function '/ 2 | 3 | #include "../fb.bi" 4 | 5 | Extern "c" 6 | Function fb_GetMemAvail FBCALL( mode as long ) as size_t 7 | 8 | /' !!!WRITEME!!! '/ 9 | return 0 10 | End Function 11 | End Extern 12 | -------------------------------------------------------------------------------- /netbsd/sys_getexename.bas: -------------------------------------------------------------------------------- 1 | /' get the executable's name '/ 2 | 3 | #include "../fb.bi" 4 | #include "crt/sys/stat.bi" 5 | 6 | Extern "c" 7 | Function fb_hGetExeName( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 8 | 9 | dim p as ubyte ptr 10 | dim finfo as stat 11 | dim len_ as ssize_t 12 | dim procpath as ZString Ptr = sadd("/proc/curproc/exe") 13 | 14 | if (stat(procpath, @finfo) = 0) then 15 | len_ = readlink(procpath, dst, maxlen - 1) 16 | if(len_ > -1) then 17 | /' NetBSD-like proc fs is available '/ 18 | dst[len_] = 0 19 | p = strrchr(dst, asc("/")) 20 | if (p <> NULL) then 21 | p += 1 22 | else 23 | p = dst 24 | end if 25 | end if 26 | else 27 | p = NULL 28 | end if 29 | 30 | return p 31 | End Function 32 | End Extern -------------------------------------------------------------------------------- /netbsd/sys_getexepath.bas: -------------------------------------------------------------------------------- 1 | /' get the executable path '/ 2 | 3 | #include "../fb.bi" 4 | #include "crt/sys/stat.bi" 5 | 6 | Extern "c" 7 | Function fb_hGetExeName( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 8 | 9 | dim p as ubyte ptr 10 | dim finfo as stat 11 | dim len_ as ssize_t 12 | dim procpath as Const ZString Ptr = sadd("/proc/curproc/exe") 13 | 14 | if ((stat(procpath, @finfo) = 0) then 15 | len_ = readlink(procpath, dst, maxlen - 1) 16 | if(len_ > -1) then 17 | /' NetBSD-like proc fs is available '/ 18 | dst[len_] = 0 19 | p = strrchr(dst, asc("/")) 20 | if (p = dst) then /' keep the "/" rather than returning "" '/ 21 | *(p + 1) = 0 22 | elseif p <> Null then 23 | *p = 0 24 | else 25 | dst[0] = 0 26 | end if 27 | end if 28 | else 29 | p = NULL 30 | end if 31 | 32 | return p 33 | End Function 34 | End Extern 35 | -------------------------------------------------------------------------------- /oop_istypeof.bas: -------------------------------------------------------------------------------- 1 | /' is operator '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_IsTypeOf FBCALL ( obj as FB_OBJECT ptr, typeRTTI as FB_RTTI ptr ) as long 7 | if ( obj = NULL ) then 8 | return FB_FALSE 9 | end if 10 | 11 | dim as FB_RTTI ptr objRTTI = cast(FB_BASEVT ptr,((cast(ubyte ptr, obj->pVT))- sizeof( FB_BASEVT )))->pRTTI 12 | while ( objRTTI <> NULL ) 13 | /' note: can't compare just the address because object or type could be declared in a DLL '/ 14 | if ( strcmp( objRTTI->id, typeRTTI->id ) = 0 ) then 15 | return FB_TRUE 16 | end if 17 | 18 | objRTTI = objRTTI->pRTTIBase 19 | wend 20 | 21 | return FB_FALSE 22 | end function 23 | end extern -------------------------------------------------------------------------------- /oop_object.bas: -------------------------------------------------------------------------------- 1 | /' Object class methods '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | extern as FB_RTTI __fb_ZTS6Object 7 | extern as FB_BASEVT Object_VT 8 | 9 | dim shared as FB_RTTI __fb_ZTS6Object = ( NULL, sadd("6OBJECT"), NULL ) 10 | dim shared as FB_BASEVT Object_VT = ( NULL, @__fb_ZTS6Object ) 11 | 12 | /' constructor fb_Object$( ) '/ 13 | sub _ZN10fb_ObjectC1Ev alias "_ZN10fb_Object$C1Ev"( this_ as FB_OBJECT ptr ) 14 | this_->pVT = cast(FB_BASEVT ptr ,((cast(ubyte ptr, @Object_VT)) + sizeof( FB_BASEVT ))) 15 | end sub 16 | end extern 17 | -------------------------------------------------------------------------------- /oop_object_copyctor.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | /' constructor fb_Object$( byref rhs as const fb_Object$ ) '/ 5 | sub _ZN10fb_ObjectC1ERKS_ alias "_ZN10fb_Object$C1ERKS_"( this_ as FB_OBJECT ptr, rhs as const FB_OBJECT ptr ) 6 | /' Just initialize the vptr properly (we cannot just copy it from the 7 | rhs, because that may really be a different object type that just was 8 | up-casted), nothing else to do. '/ 9 | _ZN10fb_ObjectC1Ev( this_ ) 10 | end sub 11 | end extern -------------------------------------------------------------------------------- /qb_inkey.bas: -------------------------------------------------------------------------------- 1 | /' QB compatible INKEY '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_InkeyQB FBCALL ( ) as FBSTRING ptr 8 | dim as FBSTRING ptr res = fb_Inkey() 9 | 10 | FB_LOCK() 11 | 12 | if ( res <> NULL andalso res->data <> NULL andalso ( FB_STRSIZE(res) = 2 ) andalso ( res->data[0] = FB_EXT_CHAR ) ) then 13 | res->data[0] = 0 14 | end if 15 | 16 | FB_UNLOCK() 17 | 18 | return res 19 | end function 20 | end extern -------------------------------------------------------------------------------- /qb_sleep.bas: -------------------------------------------------------------------------------- 1 | /' QB compatible SLEEP '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_SleepQB FBCALL ( secs as long ) 8 | fb_Sleep( iif(secs < 0, secs, secs * 1000) ) 9 | end sub 10 | end extern -------------------------------------------------------------------------------- /static/fbrt0.bas: -------------------------------------------------------------------------------- 1 | /' FB runtime initialization and cleanup 2 | 3 | We use a global constructor and destructor for this. Where possible they 4 | should run first/last respectively, such that it's safe for FB programs to 5 | use the FB runtime from inside its own global ctors/dtors. '/ 6 | 7 | #include "../fb.bi" 8 | 9 | /' note: they must be static, or shared libraries in Linux would reuse the 10 | same function '/ 11 | 12 | extern "C" 13 | private sub fb_hDoInit( ) constructor 101 14 | fb_hRtInit( ) 15 | end sub 16 | 17 | private sub fb_hDoExit( ) destructor 101 18 | fb_hRtExit( ) 19 | end sub 20 | end extern -------------------------------------------------------------------------------- /static/fbrt1.bas: -------------------------------------------------------------------------------- 1 | /' FB runtime initialization and cleanup 2 | 3 | We use a global constructor and destructor for this. Where possible they 4 | should run first/last respectively, such that it's safe for FB programs to 5 | use the FB runtime from inside its own global ctors/dtors. '/ 6 | 7 | #include "../fb.bi" 8 | 9 | /' note: they must be static, or shared libraries in Linux would reuse the 10 | same function '/ 11 | 12 | extern "C" 13 | private sub fb_hDoInit( ) constructor 101 14 | fb_hRtInit( ) 15 | fb_InitProfile( ) 16 | end sub 17 | 18 | private sub fb_hDoExit( ) destructor 101 19 | fb_EndProfile( 0 ) 20 | fb_hRtExit( ) 21 | end sub 22 | end extern 23 | -------------------------------------------------------------------------------- /static/fbrt2.bas: -------------------------------------------------------------------------------- 1 | /' FB runtime initialization and cleanup 2 | 3 | We use a global constructor and destructor for this. Where possible they 4 | should run first/last respectively, such that it's safe for FB programs to 5 | use the FB runtime from inside its own global ctors/dtors. '/ 6 | 7 | #include "../fb.bi" 8 | 9 | /' note: they must be static, or shared libraries in Linux would reuse the 10 | same function '/ 11 | 12 | extern "C" 13 | private sub fb_hDoInit( ) constructor 101 14 | fb_hRtInit( ) 15 | fb_InitProfileCycles( ) 16 | end sub 17 | 18 | private sub fb_hDoExit( ) destructor 101 19 | fb_EndProfileCycles( 0 ) 20 | fb_hRtExit( ) 21 | end sub 22 | end extern 23 | -------------------------------------------------------------------------------- /str_asc.bas: -------------------------------------------------------------------------------- 1 | /' asc function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_ASC FBCALL ( _str as FBSTRING ptr, _pos as ssize_t ) as ulong 7 | dim a as ulong 8 | dim _len as ssize_t 9 | 10 | if( _str = NULL ) then 11 | return 0 12 | end if 13 | 14 | _len = FB_STRSIZE( _str ) 15 | 16 | if( (_str->data = NULL) or (_len = 0) or (_pos <= 0) or (_pos > _len) ) then 17 | a = 0 18 | else 19 | a = cast(ubyte, _str->data[_pos-1]) 20 | end if 21 | 22 | /' del if temp '/ 23 | fb_hStrDelTemp( _str ) 24 | 25 | return a 26 | end function 27 | end extern -------------------------------------------------------------------------------- /str_base.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | /':::::'/ 5 | function fb_HEX FBCALL ( num as long ) as FBSTRING ptr 6 | return fb_HEX_i ( num ) 7 | end function 8 | 9 | 10 | /':::::'/ 11 | function fb_OCT FBCALL ( num as long ) as FBSTRING ptr 12 | return fb_OCT_i ( num ) 13 | end function 14 | 15 | 16 | /':::::'/ 17 | function fb_BIN FBCALL ( num as long ) as FBSTRING ptr 18 | return fb_BIN_i ( num ) 19 | end function 20 | end extern -------------------------------------------------------------------------------- /str_bin.bas: -------------------------------------------------------------------------------- 1 | /' bin$ routines '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_BIN_b FBCALL ( num as ubyte ) as FBSTRING ptr 7 | return fb_BINEx_l( num, 0 ) 8 | end function 9 | 10 | function fb_BIN_s FBCALL ( num as ushort ) as FBSTRING ptr 11 | return fb_BINEx_l( num, 0 ) 12 | end function 13 | 14 | function fb_BIN_i FBCALL ( num as ulong ) as FBSTRING ptr 15 | return fb_BINEx_l( num, 0 ) 16 | end function 17 | 18 | function fb_BINEx_b FBCALL ( num as ubyte, digits as long ) as FBSTRING ptr 19 | return fb_BINEx_l( num, digits ) 20 | end function 21 | 22 | function fb_BINEx_s FBCALL ( num as ushort, digits as long ) as FBSTRING ptr 23 | return fb_BINEx_l( num, digits ) 24 | end function 25 | 26 | function fb_BINEx_i FBCALL ( num as ulong, digits as long ) as FBSTRING ptr 27 | return fb_BINEx_l( num, digits ) 28 | end function 29 | end extern -------------------------------------------------------------------------------- /str_bin_ptr.bas: -------------------------------------------------------------------------------- 1 | /' bin(any ptr) function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_BIN_p FBCALL ( p as const any ptr ) as FBSTRING ptr 7 | #ifdef HOST_64BIT 8 | return fb_BIN_l( cast(ulongint, p) ) 9 | #else 10 | return fb_BIN_i( cast(uinteger, p) ) 11 | #endif 12 | end function 13 | 14 | function fb_BINEx_p FBCALL ( p as const any ptr, digits as long ) as FBSTRING ptr 15 | #ifdef HOST_64BIT 16 | return fb_BINEx_l( cast(ulongint, p), digits ) 17 | #else 18 | return fb_BINEx_i( cast(uinteger, p), digits ) 19 | #endif 20 | end function 21 | end extern -------------------------------------------------------------------------------- /str_chr.bas: -------------------------------------------------------------------------------- 1 | /' chr$ routine '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_CHR cdecl ( args as long, ... ) as FBSTRING ptr 7 | dim dst as FBSTRING ptr 8 | dim ap as any ptr 9 | dim num as ulong 10 | dim i as long 11 | 12 | if ( args <= 0 ) then 13 | return @__fb_ctx.null_desc 14 | end if 15 | cva_start( ap, args ) 16 | 17 | /' alloc temp string '/ 18 | dst = fb_hStrAllocTemp( NULL, args ) 19 | if ( dst <> NULL ) then 20 | /' convert '/ 21 | for i = 0 to args - 1 22 | num = cva_arg( ap, ulong ) 23 | dst->data[i] = cast(ubyte, num) 24 | next 25 | dst->data[args] = 0 26 | else 27 | dst = @__fb_ctx.null_desc 28 | end if 29 | cva_end( ap ) 30 | 31 | return dst 32 | end function 33 | end extern -------------------------------------------------------------------------------- /str_convto_bool.bas: -------------------------------------------------------------------------------- 1 | /' str$ routines for boolean 2 | * 3 | '/ 4 | 5 | #include "fb.bi" 6 | 7 | extern "C" 8 | 9 | /':::::'/ 10 | function fb_hBoolToStr FBCALL ( num as ubyte ) as ubyte ptr 11 | static false_string as zstring ptr = @"false" 12 | static true_string as zstring ptr = @"true" 13 | 14 | return iif( num, true_string, false_string ) 15 | end function 16 | 17 | /':::::'/ 18 | function fb_BoolToStr FBCALL ( num as ubyte ) as FBSTRING ptr 19 | dim as FBSTRING ptr dst 20 | 21 | dst = fb_hStrAllocTemp( NULL, 8 ) 22 | if ( dst <> NULL ) then 23 | dim as ubyte ptr src = fb_hBoolToStr( num ) 24 | fb_hStrCopy( dst->data, src, strlen(src) ) 25 | fb_hStrSetLength( dst, strlen(src) ) 26 | else 27 | dst = @__fb_ctx.null_desc 28 | end if 29 | 30 | return dst 31 | end function 32 | end extern 33 | -------------------------------------------------------------------------------- /str_del.bas: -------------------------------------------------------------------------------- 1 | /' string deletion function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | sub fb_StrDelete FBCALL ( _str as FBSTRING ptr ) 8 | if ( (_str = NULL) or (_str->data = NULL) ) then 9 | return 10 | end if 11 | 12 | free( cast( any ptr, _str->data ) ) 13 | 14 | _str->data = NULL 15 | _str->len = 0 16 | _str->size = 0 17 | end sub 18 | end extern -------------------------------------------------------------------------------- /str_hex.bas: -------------------------------------------------------------------------------- 1 | /' hex$ routines '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_HEX_b FBCALL ( num as ubyte ) as FBSTRING ptr 7 | return fb_HEXEx_l( num, 0 ) 8 | end function 9 | 10 | function fb_HEX_s FBCALL ( num as ushort ) as FBSTRING ptr 11 | return fb_HEXEx_l( num, 0 ) 12 | end function 13 | 14 | function fb_HEX_i FBCALL ( num as ulong ) as FBSTRING ptr 15 | return fb_HEXEx_l( num, 0 ) 16 | end function 17 | 18 | function fb_HEXEx_b FBCALL ( num as ubyte, digits as long ) as FBSTRING ptr 19 | return fb_HEXEx_l( num, digits ) 20 | end function 21 | 22 | function fb_HEXEx_s FBCALL ( num as ushort, digits as long ) as FBSTRING ptr 23 | return fb_HEXEx_l( num, digits ) 24 | end function 25 | 26 | function fb_HEXEx_i FBCALL ( num as ulong, digits as long ) as FBSTRING ptr 27 | return fb_HEXEx_l( num, digits ) 28 | end function 29 | end extern -------------------------------------------------------------------------------- /str_hex_ptr.bas: -------------------------------------------------------------------------------- 1 | /' hex(any ptr) function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_HEX_p FBCALL ( p as const any ptr ) as FBSTRING ptr 7 | #ifdef HOST_64BIT 8 | return fb_HEX_l( cast(ulongint, p) ) 9 | #else 10 | return fb_HEX_i( cast(ulong, p) ) 11 | #endif 12 | end function 13 | 14 | function fb_HEXEx_p FBCALL ( p as const any ptr, digits as long ) as FBSTRING ptr 15 | #ifdef HOST_64BIT 16 | return fb_HEXEx_l( cast(ulongint, p), digits ) 17 | #else 18 | return fb_HEXEx_i( cast(ulong, p), digits ) 19 | #endif 20 | end function 21 | end extern -------------------------------------------------------------------------------- /str_hskip.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_hStrSkipChar FBCALL ( s as ubyte ptr, _len as ssize_t, c as long ) as ubyte ptr 5 | dim as ubyte ptr p = s 6 | 7 | if ( s <> NULL ) then 8 | _len -= 1 9 | while ( (_len >= 0) and (cast(long, *p) = c) ) 10 | p += 1 11 | _len -= 1 12 | wend 13 | end if 14 | return p 15 | end function 16 | 17 | function fb_hStrSkipCharRev FBCALL ( s as ubyte ptr, _len as ssize_t, c as long ) as ubyte ptr 18 | dim as ubyte ptr p 19 | 20 | if ( (s = NULL) or (_len <= 0) ) then 21 | return s 22 | end if 23 | 24 | p = @s[_len-1] 25 | 26 | /' fixed-len's are filled with null's as in PB, strip them too '/ 27 | _len -= 1 28 | while ( (_len >= 0) and ((cast(long, *p) = c) or (cast(long, *p) = 0) ) ) 29 | p -= 1 30 | _len -= 1 31 | wend 32 | 33 | return p 34 | end function 35 | end extern -------------------------------------------------------------------------------- /str_left.bas: -------------------------------------------------------------------------------- 1 | /' left$ function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_LEFT FBCALL ( src as FBSTRING ptr, chars as ssize_t ) as FBSTRING ptr 7 | dim as FBSTRING ptr dst 8 | dim as ssize_t _len, src_len 9 | 10 | if ( src = NULL ) then 11 | return @__fb_ctx.null_desc 12 | end if 13 | 14 | FB_STRLOCK() 15 | 16 | src_len = FB_STRSIZE( src ) 17 | if ( (src->data <> NULL) and (chars > 0) and (src_len > 0) ) then 18 | if ( chars > src_len ) then 19 | _len = src_len 20 | else 21 | _len = chars 22 | end if 23 | 24 | /' alloc temp string '/ 25 | dst = fb_hStrAllocTemp_NoLock( NULL, _len ) 26 | if ( dst <> NULL ) then 27 | /' simple copy '/ 28 | fb_hStrCopy( dst->data, src->data, _len ) 29 | else 30 | dst = @__fb_ctx.null_desc 31 | end if 32 | else 33 | dst = @__fb_ctx.null_desc 34 | end if 35 | 36 | /' del if temp '/ 37 | fb_hStrDelTemp_NoLock( src ) 38 | 39 | FB_STRUNLOCK() 40 | 41 | return dst 42 | end function 43 | end extern -------------------------------------------------------------------------------- /str_len.bas: -------------------------------------------------------------------------------- 1 | /' string length function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_StrLen FBCALL ( _str as any ptr, str_size as ssize_t ) as ssize_t 7 | dim as ssize_t _len 8 | 9 | if ( _str = NULL ) then 10 | return 0 11 | end if 12 | 13 | /' is dst var-len? '/ 14 | if ( str_size = FB_STRSIZEVARLEN ) then 15 | _len = FB_STRSIZE( _str ) 16 | 17 | /' delete temp? '/ 18 | fb_hStrDelTemp( cast(FBSTRING ptr, _str) ) 19 | else 20 | /' this routine will never be called for fixed-len strings, as 21 | their sizes are known at compiler-time, as such, this must be 22 | a zstring, so find out the real len (as in C/PB) '/ 23 | _len = strlen( cast(ubyte ptr,_str) ) 24 | end if 25 | 26 | return _len 27 | end function 28 | end extern -------------------------------------------------------------------------------- /str_misc.bas: -------------------------------------------------------------------------------- 1 | /' misc string routines '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_SPACE FBCALL ( _len as ssize_t ) as FBSTRING ptr 7 | dim as FBSTRING ptr dst 8 | 9 | if ( _len > 0 ) then 10 | /' alloc temp string '/ 11 | dst = fb_hStrAllocTemp( NULL, _len ) 12 | if ( dst <> NULL ) then 13 | /' fill it '/ 14 | memset( dst->data, 32, _len ) 15 | 16 | /' null char '/ 17 | dst->data[_len] = 0 18 | else 19 | dst = @__fb_ctx.null_desc 20 | end if 21 | else 22 | dst = @__fb_ctx.null_desc 23 | end if 24 | 25 | return dst 26 | end function 27 | end extern -------------------------------------------------------------------------------- /str_oct.bas: -------------------------------------------------------------------------------- 1 | /' oct$ routines '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_OCT_b FBCALL ( num as ubyte ) as FBSTRING ptr 7 | return fb_OCTEx_l( num, 0 ) 8 | end function 9 | 10 | function fb_OCT_s FBCALL ( num as ushort ) as FBSTRING ptr 11 | return fb_OCTEx_l( num, 0 ) 12 | end function 13 | 14 | function fb_OCT_i FBCALL ( num as ulong ) as FBSTRING ptr 15 | return fb_OCTEx_l( num, 0 ) 16 | end function 17 | 18 | function fb_OCTEx_b FBCALL ( num as ubyte, digits as long ) as FBSTRING ptr 19 | return fb_OCTEx_l( num, digits ) 20 | end function 21 | 22 | function fb_OCTEx_s FBCALL ( num as ushort, digits as long ) as FBSTRING ptr 23 | return fb_OCTEx_l( num, digits ) 24 | end function 25 | 26 | function fb_OCTEx_i FBCALL ( num as ulong, digits as long ) as FBSTRING ptr 27 | return fb_OCTEx_l( num, digits ) 28 | end function 29 | end extern -------------------------------------------------------------------------------- /str_oct_ptr.bas: -------------------------------------------------------------------------------- 1 | /' oct(any ptr) function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_OCT_p FBCALL ( p as const any ptr ) as FBSTRING ptr 7 | #ifdef HOST_64BIT 8 | return fb_OCT_l( cast(ulongint, p) ) 9 | #else 10 | return fb_OCT_i( cast(ulong, p) ) 11 | #endif 12 | end function 13 | 14 | function fb_OCTEx_p FBCALL ( p as const any ptr, digits as long ) as FBSTRING ptr 15 | #ifdef HOST_64BIT 16 | return fb_OCTEx_l( cast(ulongint, p), digits ) 17 | #else 18 | return fb_OCTEx_i( cast(ulong, p), digits ) 19 | #endif 20 | end function 21 | end extern -------------------------------------------------------------------------------- /str_tempdescf.bas: -------------------------------------------------------------------------------- 1 | /' temp string descriptor allocation for fixed-len strings '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_StrAllocTempDescF FBCALL ( _str as ubyte ptr, str_size as ssize_t ) as FBSTRING ptr 7 | dim as FBSTRING ptr dsc 8 | 9 | FB_STRLOCK() 10 | 11 | /' alloc a temporary descriptor '/ 12 | dsc = fb_hStrAllocTempDesc( ) 13 | 14 | FB_STRUNLOCK() 15 | 16 | if ( dsc = NULL ) then 17 | return @__fb_ctx.null_desc 18 | end if 19 | 20 | dsc->data = _str 21 | 22 | /' can't use strlen() if the size is known '/ 23 | if ( str_size > 0 ) then 24 | /' less the null-term '/ 25 | dsc->len = str_size - 1 26 | elseif( str_size and FB_STRISFIXED ) then 27 | dsc->len = str_size and FB_STRSIZEMSK 28 | else 29 | if ( _str <> NULL ) then 30 | dsc->len = strlen( _str ) 31 | else 32 | dsc->len = 0 33 | end if 34 | end if 35 | 36 | dsc->size = dsc->len 37 | 38 | return dsc 39 | end function 40 | end extern -------------------------------------------------------------------------------- /str_tempdescv.bas: -------------------------------------------------------------------------------- 1 | /' legacy: temp string descriptor allocation for var-len strings '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_StrAllocTempDescV FBCALL ( _str as FBSTRING ptr ) as FBSTRING ptr 7 | dim as FBSTRING ptr dsc 8 | 9 | FB_STRLOCK() 10 | 11 | /' alloc a temporary descriptor '/ 12 | dsc = fb_hStrAllocTempDesc( ) 13 | 14 | FB_STRUNLOCK() 15 | 16 | if ( dsc = NULL ) then 17 | return @__fb_ctx.null_desc 18 | end if 19 | 20 | dsc->data = _str->data 21 | dsc->len = FB_STRSIZE( _str ) 22 | dsc->size = _str->size 23 | 24 | return dsc 25 | end function 26 | end extern -------------------------------------------------------------------------------- /str_tempdescz.bas: -------------------------------------------------------------------------------- 1 | /' temp string descriptor allocation for zstring's '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_StrAllocTempDescZEx FBCALL ( _str as const ubyte ptr, _len as ssize_t ) as FBSTRING ptr 7 | dim as FBSTRING ptr dsc 8 | 9 | FB_STRLOCK() 10 | 11 | /' alloc a temporary descriptor '/ 12 | dsc = fb_hStrAllocTempDesc( ) 13 | 14 | FB_STRUNLOCK() 15 | 16 | if ( dsc = NULL ) then 17 | return @__fb_ctx.null_desc 18 | end if 19 | 20 | dsc->data = cast(ubyte ptr, _str) 21 | dsc->len = _len 22 | dsc->size = _len 23 | 24 | return dsc 25 | end function 26 | 27 | function fb_StrAllocTempDescZ FBCALL ( _str as const ubyte ptr ) as FBSTRING ptr 28 | dim as ssize_t _len 29 | 30 | /' find the true size '/ 31 | if ( _str <> NULL ) then 32 | _len = strlen( _str ) 33 | else 34 | _len = 0 35 | end if 36 | 37 | return fb_StrAllocTempDescZEx( _str, _len ) 38 | end function 39 | end extern -------------------------------------------------------------------------------- /str_tempres.bas: -------------------------------------------------------------------------------- 1 | /' temp result string allocation '/ 2 | 3 | #include "fb.bi" 4 | 5 | /':::::'/ 6 | extern "C" 7 | function fb_StrAllocTempResult FBCALL ( src as FBSTRING ptr ) as FBSTRING ptr 8 | dim as FBSTRING ptr dsc 9 | 10 | FB_STRLOCK() 11 | 12 | /' alloc a temporary descriptor (the current one at stack will be trashed) '/ 13 | dsc = fb_hStrAllocTempDesc( ) 14 | if ( dsc = NULL ) then 15 | FB_STRUNLOCK() 16 | return @__fb_ctx.null_desc 17 | end if 18 | 19 | /' copy just the descriptor, setting it as a temp string '/ 20 | dsc->data = src->data 21 | dsc->len = src->len or FB_TEMPSTRBIT 22 | dsc->size = src->size 23 | 24 | /' just for safety.. '/ 25 | src->data = NULL 26 | src->len = 0 27 | src->size = 0 28 | 29 | FB_STRUNLOCK() 30 | 31 | return dsc 32 | end function 33 | end extern -------------------------------------------------------------------------------- /strw_alloc.bas: -------------------------------------------------------------------------------- 1 | /' wstring allocation function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrAlloc FBCALL ( chars as ssize_t ) as FB_WCHAR ptr 7 | if ( chars <= 0 ) then 8 | return NULL 9 | end if 10 | 11 | return fb_wstr_AllocTemp( chars ) 12 | end function 13 | end extern -------------------------------------------------------------------------------- /strw_asc.bas: -------------------------------------------------------------------------------- 1 | /' ascw function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrAsc FBCALL ( _str as const FB_WCHAR ptr, _pos as ssize_t ) as ulong 7 | dim as ssize_t _len 8 | 9 | if ( _str = NULL ) then 10 | return 0 11 | end if 12 | 13 | _len = fb_wstr_Len( _str ) 14 | if ( (_len = 0) orelse (_pos <= 0) orelse (_pos > _len) ) then 15 | return 0 16 | else 17 | #ifdef HOST_DOS 18 | /' on DOS, FB_WCHAR is a 'char' which is 19 | typically signed. To avoid an undesired 20 | sign extension for chars >= 128, cast 21 | to unsigned char first 22 | '/ 23 | return cast(ubyte, _str[_pos-1]) 24 | #else 25 | return _str[_pos-1] 26 | #endif 27 | end if 28 | end function 29 | end extern -------------------------------------------------------------------------------- /strw_assign.bas: -------------------------------------------------------------------------------- 1 | /' unicode string assigning function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrAssign FBCALL ( dst as FB_WCHAR ptr, dst_chars as ssize_t, src as FB_WCHAR ptr ) as FB_WCHAR ptr 7 | dim as ssize_t src_chars 8 | 9 | if ( dst = NULL ) then 10 | return dst 11 | end if 12 | 13 | if ( src = 0 ) then 14 | src_chars = 0 15 | else 16 | src_chars = fb_wstr_Len( src ) 17 | end if 18 | 19 | /' src NULL? '/ 20 | if ( src_chars = 0 ) then 21 | *dst = 0 22 | else 23 | if ( dst_chars > 0 ) then 24 | dst_chars -= 1 /' less the null-term '/ 25 | /' not enough? clamp '/ 26 | if ( dst_chars < src_chars ) then 27 | src_chars = dst_chars 28 | end if 29 | end if 30 | 31 | fb_wstr_Copy( dst, src, src_chars ) 32 | end if 33 | 34 | return dst 35 | end function 36 | end extern -------------------------------------------------------------------------------- /strw_bin.bas: -------------------------------------------------------------------------------- 1 | /' binw$ routines '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrBin_b FBCALL ( num as ubyte ) as FB_WCHAR ptr 7 | return fb_WstrBinEx_l( num, 0 ) 8 | end function 9 | 10 | function fb_WstrBin_s FBCALL ( num as ushort ) as FB_WCHAR ptr 11 | return fb_WstrBinEx_l( num, 0 ) 12 | end function 13 | 14 | function fb_WstrBin_i FBCALL ( num as ulong ) as FB_WCHAR ptr 15 | return fb_WstrBinEx_l( num, 0 ) 16 | end function 17 | 18 | function fb_WstrBinEx_b FBCALL ( num as ubyte, digits as long ) as FB_WCHAR ptr 19 | return fb_WstrBinEx_l( num, digits ) 20 | end function 21 | 22 | function fb_WstrBinEx_s FBCALL ( num as ushort, digits as long ) as FB_WCHAR ptr 23 | return fb_WstrBinEx_l( num, digits ) 24 | end function 25 | 26 | function fb_WstrBinEx_i FBCALL ( num as ulong, digits as long ) as FB_WCHAR ptr 27 | return fb_WstrBinEx_l( num, digits ) 28 | end function 29 | end extern -------------------------------------------------------------------------------- /strw_bin_ptr.bas: -------------------------------------------------------------------------------- 1 | /' wbin(any ptr) function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrBin_p FBCALL ( p as const any ptr ) as FB_WCHAR ptr 7 | #ifdef HOST_64BIT 8 | return fb_WstrBin_l( cast(ulongint, p) ) 9 | #else 10 | return fb_WstrBin_i( cast(ulong, p) ) 11 | #endif 12 | end function 13 | 14 | function fb_WstrBinEx_p FBCALL ( p as const any ptr, digits as long ) as FB_WCHAR ptr 15 | #ifdef HOST_64BIT 16 | return fb_WstrBinEx_l( cast(ulongint, p), digits ) 17 | #else 18 | return fb_WstrBinEx_i( cast(ulong, p), digits ) 19 | #endif 20 | end function 21 | end extern -------------------------------------------------------------------------------- /strw_chr.bas: -------------------------------------------------------------------------------- 1 | /' chrw$ routine '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrChr ( args as long, ... ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr dst, s 8 | dim as any ptr ap 9 | dim as ulong num 10 | dim as long i = any 11 | 12 | if ( args <= 0 ) then 13 | return NULL 14 | end if 15 | 16 | /' alloc temp string '/ 17 | cva_start( ap, args ) 18 | 19 | dst = fb_wstr_AllocTemp( args ) 20 | if ( dst <> NULL ) then 21 | /' convert '/ 22 | s = dst 23 | i = 0 24 | while( i < args ) 25 | num = cva_arg( ap, ulong ) 26 | *s = num 27 | s += 1 28 | i += 1 29 | wend 30 | /' null-term '/ 31 | *s = 0 32 | end if 33 | 34 | cva_end( ap ) 35 | 36 | return dst 37 | end function 38 | end extern -------------------------------------------------------------------------------- /strw_concat.bas: -------------------------------------------------------------------------------- 1 | /' wstring concatenation function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrConcat FBCALL ( str1 as const FB_WCHAR ptr, str2 as const FB_WCHAR ptr ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr dst, d 8 | dim as ssize_t str1_len, str2_len 9 | 10 | if ( str1 <> NULL ) then 11 | str1_len = fb_wstr_Len( str1 ) 12 | else 13 | str1_len = 0 14 | end if 15 | 16 | if ( str2 <> NULL ) then 17 | str2_len = fb_wstr_Len( str2 ) 18 | else 19 | str2_len = 0 20 | end if 21 | 22 | /' NULL? '/ 23 | if ( str1_len + str2_len = 0 ) then 24 | return NULL 25 | end if 26 | 27 | /' alloc temp string '/ 28 | dst = fb_wstr_AllocTemp( str1_len + str2_len ) 29 | 30 | /' do the concatenation '/ 31 | d = fb_wstr_Move( dst, str1, str1_len ) 32 | d = fb_wstr_Move( d, str2, str2_len ) 33 | *d = 0 34 | 35 | return dst 36 | end function 37 | end extern -------------------------------------------------------------------------------- /strw_concatassign.bas: -------------------------------------------------------------------------------- 1 | /' string concat and assign (s = s + expr) function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrConcatAssign FBCALL ( dst as FB_WCHAR ptr, dst_chars as ssize_t, src as const FB_WCHAR ptr ) as FB_WCHAR ptr 7 | dim as ssize_t src_len, dst_len 8 | 9 | /' NULL? '/ 10 | if ( (dst = NULL) or (src = NULL) ) then 11 | return dst 12 | end if 13 | 14 | src_len = fb_wstr_Len( src ) 15 | if ( src_len = 0 ) then 16 | return dst 17 | end if 18 | 19 | dst_len = fb_wstr_Len( dst ) 20 | 21 | /' don't check ptr's '/ 22 | if ( dst_chars > 0 ) then 23 | dst_chars -= 1 /' less the null-term '/ 24 | 25 | if ( src_len > dst_chars - dst_len ) then 26 | src_len = dst_chars - dst_len 27 | end if 28 | 29 | fb_wstr_Copy( @dst[dst_len], src, src_len ) 30 | end if 31 | 32 | return dst 33 | end function 34 | end extern -------------------------------------------------------------------------------- /strw_convto.bas: -------------------------------------------------------------------------------- 1 | /' strw$ routines for int, uint '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_IntToWstr FBCALL ( num as long ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr dst 8 | 9 | /' alloc temp string '/ 10 | dst = fb_wstr_AllocTemp( sizeof( long ) * 3 ) 11 | if ( dst <> NULL ) then 12 | /' convert '/ 13 | FB_WSTR_FROM_INT( dst, num ) 14 | end if 15 | 16 | return dst 17 | end function 18 | 19 | function fb_UIntToWstr FBCALL ( num as ulong ) as FB_WCHAR ptr 20 | dim as FB_WCHAR ptr dst 21 | 22 | /' alloc temp string '/ 23 | dst = fb_wstr_AllocTemp( sizeof( long ) * 3 ) 24 | if ( dst <> NULL ) then 25 | /' convert '/ 26 | FB_WSTR_FROM_UINT( dst, num ) 27 | end if 28 | 29 | return dst 30 | end function 31 | end extern -------------------------------------------------------------------------------- /strw_convto_bool.bas: -------------------------------------------------------------------------------- 1 | /' strw$ routines for boolean '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | 7 | /':::::'/ 8 | function fb_hBoolToWstr FBCALL ( num as ubyte ) as FB_WCHAR ptr 9 | return iif(num <> 0, @wstr("true"), @wstr("false")) 10 | end function 11 | 12 | /':::::'/ 13 | function fb_BoolToWstr FBCALL ( num as ubyte ) as FB_WCHAR ptr 14 | dim as FB_WCHAR ptr dst 15 | 16 | /' alloc temp string '/ 17 | dst = fb_wstr_AllocTemp( 5 ) 18 | 19 | if ( dst <> NULL ) then 20 | dim as FB_WCHAR ptr src = fb_hBoolToWstr(num) 21 | fb_wstr_Copy( dst, src, fb_wstr_Len(src) ) 22 | end if 23 | 24 | return dst 25 | end function 26 | end extern 27 | -------------------------------------------------------------------------------- /strw_convto_lng.bas: -------------------------------------------------------------------------------- 1 | /' strw$ routines for longint, ulongint '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_LongintToWstr FBCALL ( num as longint ) as FB_WCHAR ptr 8 | dim as FB_WCHAR ptr dst 9 | 10 | /' alloc temp string '/ 11 | dst = fb_wstr_AllocTemp( sizeof( longint ) * 3 ) 12 | if ( dst <> NULL ) then 13 | /' convert '/ 14 | FB_WSTR_FROM_INT64( dst, num ) 15 | end if 16 | 17 | return dst 18 | end function 19 | 20 | /':::::'/ 21 | function fb_ULongintToWstr FBCALL ( num as ulongint ) as FB_WCHAR ptr 22 | dim as FB_WCHAR ptr dst 23 | 24 | /' alloc temp string '/ 25 | dst = fb_wstr_AllocTemp( sizeof( longint ) * 3 ) 26 | if ( dst <> NULL ) then 27 | /' convert '/ 28 | FB_WSTR_FROM_UINT64( dst, num ) 29 | end if 30 | 31 | return dst 32 | end function 33 | end extern -------------------------------------------------------------------------------- /strw_del.bas: -------------------------------------------------------------------------------- 1 | /' wstring deletion function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_WstrDelete FBCALL ( _str as FB_WCHAR ptr ) 7 | if ( _str = NULL ) then 8 | exit sub 9 | end if 10 | 11 | fb_wstr_Del( _str ) 12 | end sub 13 | end extern -------------------------------------------------------------------------------- /strw_fill.bas: -------------------------------------------------------------------------------- 1 | /' stringw$ function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrFill1 FBCALL ( chars as ssize_t, c as long ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr dst 8 | 9 | if( chars <= 0 ) then 10 | return NULL 11 | end if 12 | 13 | /' alloc temp string '/ 14 | dst = fb_wstr_AllocTemp( chars ) 15 | if ( dst <> NULL ) then 16 | /' fill it '/ 17 | fb_wstr_Fill( dst, c, chars ) 18 | end if 19 | 20 | return dst 21 | end function 22 | 23 | function fb_WstrFill2 FBCALL ( chars as ssize_t, src as const FB_WCHAR ptr ) as FB_WCHAR ptr 24 | dim as FB_WCHAR ptr dst 25 | 26 | if ( (chars > 0) and (src <> NULL) and (fb_wstr_Len( src ) > 0) ) then 27 | dst = fb_WstrFill1( chars, src[0] ) 28 | else 29 | dst = NULL 30 | end if 31 | 32 | return dst 33 | end function 34 | end extern -------------------------------------------------------------------------------- /strw_ftoa.bas: -------------------------------------------------------------------------------- 1 | /' float to wstring, internal usage '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_FloatExToWstr( _val as double, buffer as FB_WCHAR ptr, digits as long, mask as long ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr p 8 | dim as ssize_t _len 9 | 10 | if( mask and FB_F2A_ADDBLANK ) then 11 | p = @buffer[1] 12 | else 13 | p = buffer 14 | end if 15 | 16 | swprintf( p, 16+8+1, @wstr("%.*g"), digits, _val ) 17 | 18 | _len = fb_wstr_Len( p ) 19 | 20 | if ( _len > 0 ) then 21 | /' skip the dot at end if any '/ 22 | if ( _len > 0 ) then 23 | if ( p[_len-1] = 46 ) then 24 | p[_len-1] = 0 25 | end if 26 | end if 27 | end if 28 | 29 | /' '/ 30 | if ( (mask and FB_F2A_ADDBLANK) > 0 ) then 31 | if ( *p <> 45 ) then 32 | *buffer = 32 33 | return buffer 34 | else 35 | return p 36 | end if 37 | else 38 | return p 39 | end if 40 | end function 41 | end extern 42 | -------------------------------------------------------------------------------- /strw_hex.bas: -------------------------------------------------------------------------------- 1 | /' hexw$ routines '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrHex_b FBCALL ( num as ubyte ) as FB_WCHAR ptr 7 | return fb_WstrHexEx_l( num, 0 ) 8 | end function 9 | 10 | function fb_WstrHex_s FBCALL ( num as ushort ) as FB_WCHAR ptr 11 | return fb_WstrHexEx_l( num, 0 ) 12 | end function 13 | 14 | function fb_WstrHex_i FBCALL ( num as ulong ) as FB_WCHAR ptr 15 | return fb_WstrHexEx_l( num, 0 ) 16 | end function 17 | 18 | function fb_WstrHexEx_b FBCALL ( num as ubyte, digits as long ) as FB_WCHAR ptr 19 | return fb_WstrHexEx_l( num, digits ) 20 | end function 21 | 22 | function fb_WstrHexEx_s FBCALL ( num as ushort, digits as long ) as FB_WCHAR ptr 23 | return fb_WstrHexEx_l( num, digits ) 24 | end function 25 | 26 | function fb_WstrHexEx_i FBCALL ( num as ulong, digits as long ) as FB_WCHAR ptr 27 | return fb_WstrHexEx_l( num, digits ) 28 | end function 29 | end extern -------------------------------------------------------------------------------- /strw_hex_ptr.bas: -------------------------------------------------------------------------------- 1 | /' whex(any ptr) function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrHex_p FBCALL ( p as const any ptr ) as FB_WCHAR ptr 7 | #ifdef HOST_64BIT 8 | return fb_WstrHex_l( cast(ulongint, p) ) 9 | #else 10 | return fb_WstrHex_i( cast(ulong, p) ) 11 | #endif 12 | end function 13 | 14 | function fb_WstrHexEx_p FBCALL ( p as const any ptr, digits as long ) as FB_WCHAR ptr 15 | #ifdef HOST_64BIT 16 | return fb_WstrHexEx_l( cast(ulongint, p), digits ) 17 | #else 18 | return fb_WstrHexEx_i( cast(ulong, p), digits ) 19 | #endif 20 | end function 21 | end extern -------------------------------------------------------------------------------- /strw_instr.bas: -------------------------------------------------------------------------------- 1 | /' instrw function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrInstr FBCALL ( start as ssize_t, src as const FB_WCHAR ptr, patt as const FB_WCHAR ptr ) as ssize_t 7 | dim as ssize_t r 8 | dim as FB_WCHAR ptr p 9 | 10 | if ( (src = NULL) orelse (patt = NULL) ) then 11 | return 0 12 | end if 13 | 14 | if ( (start > 0) andalso (start <= fb_wstr_Len( src )) andalso (fb_wstr_Len( patt ) <> 0 )) then 15 | p = fb_wstr_Instr( @src[start-1], patt ) 16 | if( p <> NULL ) then 17 | r = fb_wstr_CalcDiff( src, p ) + 1 18 | else 19 | r = 0 20 | end if 21 | else 22 | r = 0 23 | end if 24 | 25 | return r 26 | end function 27 | end extern -------------------------------------------------------------------------------- /strw_instrany.bas: -------------------------------------------------------------------------------- 1 | /' instranyw function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrInstrAny FBCALL ( start as ssize_t, src as const FB_WCHAR ptr, patt as const FB_WCHAR ptr ) as ssize_t 7 | dim as ssize_t r = 0 8 | 9 | if ( (src <> NULL) andalso (patt <> NULL) ) then 10 | dim as ssize_t size_src = fb_wstr_Len( src ) 11 | 12 | if ( (start > 0) andalso (start <= size_src) ) then 13 | r = fb_wstr_InstrAny( @src[start-1], patt ) + start 14 | 15 | if ( r > size_src ) then 16 | r = 0 17 | end if 18 | end if 19 | end if 20 | 21 | return r 22 | end function 23 | end extern -------------------------------------------------------------------------------- /strw_instrrevany.bas: -------------------------------------------------------------------------------- 1 | /' instrrevanyw function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrInstrRevAny FBCALL ( src as const FB_WCHAR ptr, patt as const FB_WCHAR ptr, start as ssize_t ) as ssize_t 7 | if ( (src <> NULL) andalso (patt <> NULL) ) then 8 | dim as ssize_t size_src = fb_wstr_Len(src) 9 | dim as ssize_t size_patt = fb_wstr_Len(patt) 10 | dim as ssize_t i 11 | 12 | if ( (size_src <> 0) andalso (size_patt <> 0) andalso (start <> 0)) then 13 | if ( start < 0 ) then 14 | start = size_src 15 | elseif ( start > size_src ) then 16 | start = 0 17 | end if 18 | 19 | while ( start <> 0 ) 20 | start -= 1 21 | i = 0 22 | while( i <> size_patt ) 23 | if ( src[start] = patt[i] ) then 24 | return start + 1 25 | end if 26 | i += 1 27 | wend 28 | wend 29 | end if 30 | end if 31 | 32 | return 0 33 | end function 34 | end extern -------------------------------------------------------------------------------- /strw_left.bas: -------------------------------------------------------------------------------- 1 | /' leftw$ function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrLeft FBCALL ( src as const FB_WCHAR ptr, chars as ssize_t ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr dst 8 | dim as ssize_t _len 9 | 10 | if ( src = NULL ) then 11 | return NULL 12 | end if 13 | 14 | _len = fb_wstr_Len( src ) 15 | if ( (chars <= 0) or (_len = 0) ) then 16 | return NULL 17 | end if 18 | 19 | if ( chars < _len ) then 20 | _len = chars 21 | end if 22 | 23 | /' alloc temp string '/ 24 | dst = fb_wstr_AllocTemp( _len ) 25 | if ( dst <> NULL ) then 26 | fb_wstr_Copy( dst, src, _len ) 27 | end if 28 | 29 | return dst 30 | end function 31 | end extern -------------------------------------------------------------------------------- /strw_len.bas: -------------------------------------------------------------------------------- 1 | /' wstring length function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrLen FBCALL ( _str as FB_WCHAR ptr ) as ssize_t 7 | if ( _str = NULL ) then 8 | return 0 9 | end if 10 | 11 | return fb_wstr_Len( _str ) 12 | end function 13 | end extern -------------------------------------------------------------------------------- /strw_ltrim.bas: -------------------------------------------------------------------------------- 1 | /' ltrimw$ function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrLTrim FBCALL ( src as const FB_WCHAR ptr ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr dst 8 | dim as const FB_WCHAR ptr p 9 | dim as ssize_t _len 10 | 11 | if ( src = NULL ) then 12 | return NULL 13 | end if 14 | 15 | _len = fb_wstr_Len( src ) 16 | p = fb_wstr_SkipChar( src, _len, asc(" ") ) 17 | 18 | _len -= fb_wstr_CalcDiff( src, p ) 19 | if ( _len <= 0 ) then 20 | return NULL 21 | end if 22 | 23 | /' alloc temp string '/ 24 | dst = fb_wstr_AllocTemp( _len ) 25 | if ( dst <> NULL ) then 26 | fb_wstr_Copy( dst, p, _len ) 27 | end if 28 | 29 | return dst 30 | end function 31 | end extern -------------------------------------------------------------------------------- /strw_mid.bas: -------------------------------------------------------------------------------- 1 | /' midw$ function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrMid FBCALL ( src as const FB_WCHAR ptr, start as ssize_t, _len as ssize_t ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr dst 8 | dim as ssize_t src_len 9 | 10 | if ( src = NULL ) then 11 | return NULL 12 | end if 13 | 14 | src_len = fb_wstr_Len( src ) 15 | if ( src_len = 0 ) then 16 | return NULL 17 | end if 18 | 19 | if ( (start <= 0) or (start > src_len) or (_len = 0) ) then 20 | return NULL 21 | end if 22 | 23 | start -= 1 24 | 25 | if ( _len < 0 ) then 26 | _len = src_len 27 | end if 28 | 29 | if ( start + _len > src_len ) then 30 | _len = src_len - start 31 | end if 32 | 33 | /' alloc temp string '/ 34 | dst = fb_wstr_AllocTemp( _len ) 35 | if ( dst <> NULL ) then 36 | fb_wstr_Copy( dst, @src[start], _len ) 37 | end if 38 | 39 | return dst 40 | end function 41 | end extern -------------------------------------------------------------------------------- /strw_midassign.bas: -------------------------------------------------------------------------------- 1 | /' midw$ statement '/ 2 | 3 | #include "fb.bi" 4 | extern "C" 5 | sub fb_WstrAssignMid FBCALL ( dst as FB_WCHAR ptr, dst_len as ssize_t, start as ssize_t, _len as ssize_t, src as const FB_WCHAR ptr ) 6 | dim as ssize_t src_len 7 | 8 | if ( (dst = NULL) or (src = NULL) ) then 9 | exit sub 10 | end if 11 | 12 | src_len = fb_wstr_Len( src ) 13 | if ( src_len = 0 ) then 14 | exit sub 15 | end if 16 | 17 | if ( dst_len = 0 ) then 18 | /' it's a pointer, assume it's large enough '/ 19 | dst_len = fb_wstr_Len( dst ) + src_len 20 | end if 21 | 22 | if ( (start > 0) and (start <= dst_len) ) then 23 | start -= 1 24 | 25 | if ( (_len < 1) or (_len > src_len) ) then 26 | _len = src_len 27 | end if 28 | 29 | if ( start + _len > dst_len ) then 30 | _len = (dst_len - start) - 1 31 | end if 32 | 33 | /' without the null-term '/ 34 | fb_wstr_Move( @dst[start], src, _len ) 35 | end if 36 | end sub 37 | end extern -------------------------------------------------------------------------------- /strw_oct.bas: -------------------------------------------------------------------------------- 1 | /' woct$ routines '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrOct_b FBCALL ( num as ubyte ) as FB_WCHAR ptr 7 | return fb_WstrOctEx_l( num, 0 ) 8 | end function 9 | 10 | function fb_WstrOct_s FBCALL ( num as ushort ) as FB_WCHAR ptr 11 | return fb_WstrOctEx_l( num, 0 ) 12 | end function 13 | 14 | function fb_WstrOct_i FBCALL ( num as ulong ) as FB_WCHAR ptr 15 | return fb_WstrOctEx_l( num, 0 ) 16 | end function 17 | 18 | function fb_WstrOctEx_b FBCALL ( num as ubyte, digits as long ) as FB_WCHAR ptr 19 | return fb_WstrOctEx_l( num, digits ) 20 | end function 21 | 22 | function fb_WstrOctEx_s FBCALL ( num as ushort, digits as long ) as FB_WCHAR ptr 23 | return fb_WstrOctEx_l( num, digits ) 24 | end function 25 | 26 | function fb_WstrOctEx_i FBCALL ( num as ulong, digits as long ) as FB_WCHAR ptr 27 | return fb_WstrOctEx_l( num, digits ) 28 | end function 29 | end extern -------------------------------------------------------------------------------- /strw_oct_ptr.bas: -------------------------------------------------------------------------------- 1 | /' woct(any ptr) function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrOct_p FBCALL ( p as const any ptr ) as FB_WCHAR ptr 7 | #ifdef HOST_64BIT 8 | return fb_WstrOct_l( cast(ulongint, p) ) 9 | #else 10 | return fb_WstrOct_i( cast(ulong, p) ) 11 | #endif 12 | end function 13 | 14 | function fb_WstrOctEx_p FBCALL ( p as const any ptr, digits as long ) as FB_WCHAR ptr 15 | #ifdef HOST_64BIT 16 | return fb_WstrOctEx_l( cast(ulongint, p), digits ) 17 | #else 18 | return fb_WstrOctEx_i( cast(ulong, p), digits ) 19 | #endif 20 | end function 21 | end extern -------------------------------------------------------------------------------- /strw_right.bas: -------------------------------------------------------------------------------- 1 | /' rightw$ function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrRight FBCALL ( src as const FB_WCHAR ptr, chars as ssize_t ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr dst 8 | dim as ssize_t _len, src_len 9 | 10 | if ( src = NULL ) then 11 | return NULL 12 | end if 13 | 14 | src_len = fb_wstr_Len( src ) 15 | if ( (chars <= 0) or (src_len = 0) ) then 16 | return NULL 17 | end if 18 | 19 | if ( chars > src_len ) then 20 | _len = src_len 21 | else 22 | _len = chars 23 | end if 24 | 25 | /' alloc temp string '/ 26 | dst = fb_wstr_AllocTemp( _len ) 27 | if ( dst <> NULL ) then 28 | /' simple rev copy '/ 29 | fb_wstr_Copy( dst, @src[src_len - _len], _len ) 30 | end if 31 | 32 | return dst 33 | end function 34 | end extern -------------------------------------------------------------------------------- /strw_rtrim.bas: -------------------------------------------------------------------------------- 1 | /' rtrimw$ function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrRTrim FBCALL ( src as const FB_WCHAR ptr ) as FB_WCHAR ptr 7 | dim dst as FB_WCHAR ptr 8 | dim p as const FB_WCHAR ptr 9 | dim chars as ssize_t 10 | 11 | if( src = NULL ) then 12 | return NULL 13 | end if 14 | 15 | chars = fb_wstr_Len( src ) 16 | if( chars <= 0 ) then 17 | return NULL 18 | end if 19 | 20 | p = fb_wstr_SkipCharRev( src, chars, 32 ) 21 | chars = fb_wstr_CalcDiff( src, p ) 22 | if( chars <= 0 ) then 23 | return NULL 24 | end if 25 | 26 | /' alloc temp string '/ 27 | dst = fb_wstr_AllocTemp( chars ) 28 | if( dst <> NULL ) then 29 | /' simple copy '/ 30 | fb_wstr_Copy( dst, src, chars ) 31 | end if 32 | 33 | return dst 34 | end function 35 | end extern -------------------------------------------------------------------------------- /strw_space.bas: -------------------------------------------------------------------------------- 1 | /' spacew$ function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrSpace FBCALL ( chars as ssize_t ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr dst 8 | 9 | if ( chars <= 0 ) then 10 | return NULL 11 | end if 12 | 13 | /' alloc temp string '/ 14 | dst = fb_wstr_AllocTemp( chars ) 15 | if ( dst <> NULL ) then 16 | /' fill it '/ 17 | fb_wstr_Fill( dst, 32, chars ) 18 | end if 19 | 20 | return dst 21 | end function 22 | end extern -------------------------------------------------------------------------------- /strw_trim.bas: -------------------------------------------------------------------------------- 1 | /' trimw$ function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_WstrTrim FBCALL ( src as const FB_WCHAR ptr ) as FB_WCHAR ptr 7 | dim as FB_WCHAR ptr dst 8 | dim as const FB_WCHAR ptr p 9 | dim as ssize_t chars 10 | 11 | if ( src = NULL ) then 12 | return NULL 13 | end if 14 | 15 | chars = fb_wstr_Len( src ) 16 | if ( chars <= 0 ) then 17 | return NULL 18 | end if 19 | 20 | p = fb_wstr_SkipCharRev( src, chars, asc(" ") ) 21 | chars = fb_wstr_CalcDiff( src, p ) 22 | if ( chars <= 0 ) then 23 | return NULL 24 | end if 25 | 26 | p = fb_wstr_SkipChar( src, chars, asc(" ") ) 27 | chars -= fb_wstr_CalcDiff( src, p ) 28 | if ( chars <= 0 ) then 29 | return NULL 30 | end if 31 | 32 | /' alloc temp string '/ 33 | dst = fb_wstr_AllocTemp( chars ) 34 | if ( dst <> NULL ) then 35 | /' simple copy '/ 36 | fb_wstr_Copy( dst, p, chars ) 37 | end if 38 | 39 | return dst 40 | end function 41 | end extern -------------------------------------------------------------------------------- /swap_mem.bas: -------------------------------------------------------------------------------- 1 | /' swap for non-strings '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | sub fb_MemSwap FBCALL ( dst as ubyte ptr, src as ubyte ptr, bytes as ssize_t ) 7 | dim as ssize_t i 8 | dim as ulong ti 9 | dim as ubyte tb 10 | 11 | if ( (dst = NULL) orelse (src = NULL) orelse (bytes <= 0) ) then 12 | exit sub 13 | end if 14 | 15 | FB_LOCK() 16 | 17 | /' words '/ 18 | for i = 0 to (bytes shr 2) - 1 19 | ti = *cast(ulong ptr, src) 20 | *cast(ulong ptr, src) = *cast(ulong ptr, dst) 21 | *cast(ulong ptr, dst) = ti 22 | 23 | src += sizeof(ulong) 24 | dst += sizeof(ulong) 25 | next 26 | 27 | /' remainder '/ 28 | for i = 0 to (bytes and 3) - 1 29 | tb = *src 30 | *src = *dst 31 | src += 1 32 | *dst = tb 33 | dst += 1 34 | next 35 | 36 | FB_UNLOCK() 37 | end sub 38 | end extern -------------------------------------------------------------------------------- /sys_cdir.bas: -------------------------------------------------------------------------------- 1 | /' curdir$ '/ 2 | 3 | #include "fb.bi" 4 | #ifdef HOST_WIN32 5 | #include "windows.bi" /' for MAX_PATH '/ 6 | #endif 7 | 8 | extern "C" 9 | function fb_CurDir FBCALL ( ) as FBSTRING ptr 10 | dim as FBSTRING ptr dst 11 | dim as ubyte tmp(0 to MAX_PATH - 1) 12 | dim as ssize_t _len 13 | 14 | FB_LOCK() 15 | 16 | _len = fb_hGetCurrentDir( @tmp(0), MAX_PATH ) 17 | 18 | /' alloc temp string '/ 19 | if ( _len > 0 ) then 20 | dst = fb_hStrAllocTemp( NULL, _len ) 21 | if ( dst <> NULL ) then 22 | memcpy( dst->data, @tmp(0), _len + 1 ) 23 | else 24 | dst = @__fb_ctx.null_desc 25 | end if 26 | else 27 | dst = @__fb_ctx.null_desc 28 | end if 29 | 30 | FB_UNLOCK() 31 | 32 | return dst 33 | end function 34 | end extern -------------------------------------------------------------------------------- /sys_chain.bas: -------------------------------------------------------------------------------- 1 | /' chain function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_Chain FBCALL ( program as FBSTRING ptr ) as long 7 | return fb_ExecEx( program, NULL, TRUE ) 8 | end function 9 | end extern -------------------------------------------------------------------------------- /sys_chdir.bas: -------------------------------------------------------------------------------- 1 | /' chdir function '/ 2 | 3 | #include "fb.bi" 4 | #ifndef HOST_WIN32 5 | /' 6 | !!! FIXME !!! - update the crt headers 7 | ''' The Windows unistd,bi tries including getopt.bi that doesn't exist 8 | ''' Luckily windows' _chdir is in io.bi so doesn't need this 9 | '/ 10 | #include "crt/unistd.bi" 11 | #endif 12 | 13 | 14 | extern "C" 15 | function fb_ChDir FBCALL ( path as FBSTRING ptr ) as long 16 | dim as long res 17 | 18 | #ifdef HOST_WIN32 19 | res = _chdir( path->data ) 20 | #else 21 | res = chdir_( path->data ) 22 | #endif 23 | 24 | /' del if temp '/ 25 | fb_hStrDelTemp( path ) 26 | 27 | return res 28 | end function 29 | end extern -------------------------------------------------------------------------------- /sys_exec.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | 3 | extern "C" 4 | function fb_Exec FBCALL ( program as FBSTRING ptr, args as FBSTRING ptr ) as long 5 | return fb_ExecEx( program, args, TRUE ) 6 | end function 7 | end extern -------------------------------------------------------------------------------- /sys_exepath.bas: -------------------------------------------------------------------------------- 1 | /' exepath$ '/ 2 | 3 | #include "fb.bi" 4 | #ifdef HOST_WIN32 5 | #include "windows.bi" 6 | #endif 7 | 8 | extern "C" 9 | function fb_ExePath FBCALL ( ) as FBSTRING ptr 10 | dim as FBSTRING ptr dst 11 | dim as ubyte ptr p 12 | dim as ubyte tmp(0 to MAX_PATH) 13 | dim as ssize_t _len 14 | 15 | p = fb_hGetExePath( @tmp(0), MAX_PATH ) 16 | 17 | if ( p <> NULL ) then 18 | /' alloc temp string '/ 19 | _len = strlen( @tmp(0) ) 20 | dst = fb_hStrAllocTemp( NULL, _len ) 21 | if ( dst <> NULL ) then 22 | fb_hStrCopy( dst->data, @tmp(0), _len ) 23 | else 24 | dst = @__fb_ctx.null_desc 25 | end if 26 | else 27 | dst = @__fb_ctx.null_desc 28 | end if 29 | 30 | return dst 31 | end function 32 | end extern -------------------------------------------------------------------------------- /sys_mkdir.bas: -------------------------------------------------------------------------------- 1 | /' mkdir function '/ 2 | 3 | #include "fb.bi" 4 | #include "crt_extra/sys/stat.bi" 5 | 6 | /':::::'/ 7 | extern "C" 8 | function fb_MkDir FBCALL ( path as FBSTRING ptr ) as long 9 | dim as long res 10 | 11 | #ifdef HOST_WIN32 12 | res = _mkdir( path->data ) 13 | #else 14 | res = _mkdir( path->data, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ) 15 | #endif 16 | 17 | /' del if temp '/ 18 | fb_hStrDelTemp( path ) 19 | 20 | return res 21 | end function 22 | end extern -------------------------------------------------------------------------------- /sys_rmdir.bas: -------------------------------------------------------------------------------- 1 | /' rmdir function '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/io.bi" 5 | 6 | extern "C" 7 | /':::::'/ 8 | function fb_RmDir FBCALL ( path as FBSTRING ptr ) as long 9 | dim as long res 10 | 11 | #ifdef HOST_WIN32 12 | res = _rmdir( path->data ) 13 | #else 14 | res = rmdir_( path->data ) 15 | #endif 16 | 17 | /' del if temp '/ 18 | fb_hStrDelTemp( path ) 19 | 20 | return res 21 | end function 22 | end extern -------------------------------------------------------------------------------- /sys_run.bas: -------------------------------------------------------------------------------- 1 | /' RUN function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_Run FBCALL ( program as FBSTRING ptr, args as FBSTRING ptr ) as long 7 | if ( fb_ExecEx( program, args, FALSE ) <> -1 ) then 8 | fb_End( 0 ) 9 | end if 10 | 11 | return -1 12 | end function 13 | end extern -------------------------------------------------------------------------------- /sys_shell.bas: -------------------------------------------------------------------------------- 1 | /' SHELL command '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | function fb_Shell FBCALL ( program as FBSTRING ptr ) as long 7 | dim as long errcode = -1 8 | 9 | if ( program <> 0 and program->data <> NULL ) then 10 | errcode = fb_hShell( program->data ) 11 | end if 12 | 13 | /' del if temp '/ 14 | fb_hStrDelTemp( program ) 15 | 16 | return errcode 17 | end function 18 | end extern -------------------------------------------------------------------------------- /thread_detach.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | #include "fb_private_thread.bi" 3 | 4 | extern "C" 5 | Sub fb_ThreadDetach FBCALL( ByVal thread As FBTHREAD Ptr ) 6 | 7 | #if defined(HOST_DOS) AndAlso not defined(ENABLE_MT) 8 | Exit Sub 9 | #else 10 | 11 | If( thread = NULL ) Then 12 | Exit Sub 13 | End If 14 | 15 | If ( thread->Detach( ) ) Then 16 | Delete thread 17 | End If 18 | #endif 19 | 20 | End Sub 21 | End Extern -------------------------------------------------------------------------------- /thread_self.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | #include "fb_private_thread.bi" 3 | 4 | Extern "c" 5 | Function fb_ThreadSelf FBCALL ( ) As FBTHREAD Ptr 6 | Return fb_GetCurrentThread( ) 7 | End Function 8 | End Extern 9 | -------------------------------------------------------------------------------- /thread_wait.bas: -------------------------------------------------------------------------------- 1 | #include "fb.bi" 2 | #include "fb_private_thread.bi" 3 | 4 | extern "C" 5 | Sub fb_ThreadWait FBCALL( ByVal thread As FBTHREAD Ptr ) 6 | 7 | #if defined(HOST_DOS) AndAlso not defined(ENABLE_MT) 8 | Exit Sub 9 | #else 10 | 11 | Dim curThread As FBThread Ptr = fb_GetCurrentThread( ) 12 | 13 | '' Can't wait for the current thread 14 | If( ( thread = NULL ) OrElse ( curThread = thread ) ) Then 15 | Exit Sub 16 | End If 17 | 18 | If ( thread->WaitForExit( -1 ) ) Then 19 | Delete thread 20 | End If 21 | #endif 22 | 23 | End Sub 24 | End Extern -------------------------------------------------------------------------------- /time_date.bas: -------------------------------------------------------------------------------- 1 | /' date$ function '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/time.bi" 5 | 6 | extern "C" 7 | /':::::'/ 8 | function fb_Date FBCALL ( ) as FBSTRING ptr 9 | dim as FBSTRING ptr dst 10 | dim as time_t rawtime 11 | dim as tm ptr ptm 12 | 13 | /' guard by global lock because time/localtime might not be thread-safe '/ 14 | FB_LOCK() 15 | 16 | rawtime = time_( NULL ) 17 | 18 | /' Note: localtime() can return NULL due to weird value from time() '/ 19 | ptm = localtime( @rawtime ) 20 | if( ptm <> NULL ) then 21 | /' done last so it's not leaked '/ 22 | dst = fb_hStrAllocTemp( NULL, 2+1+2+1+4 ) 23 | if( dst <> NULL ) then 24 | sprintf( dst->data, "%02d-%02d-%04d", 1+ptm->tm_mon, ptm->tm_mday, 1900+ptm->tm_year ) 25 | else 26 | dst = @__fb_ctx.null_desc 27 | end if 28 | else 29 | dst = @__fb_ctx.null_desc 30 | end if 31 | 32 | FB_UNLOCK() 33 | 34 | return dst 35 | end function 36 | end extern -------------------------------------------------------------------------------- /time_dateserial.bas: -------------------------------------------------------------------------------- 1 | /' dateserial function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_DateSerial FBCALL ( _year as long, _month as long, _day as long ) as long 8 | dim as long result = 2 9 | dim as long cur_year = 1900 10 | dim as long cur_month = 1 11 | dim as long cur_day = 1 12 | 13 | fb_hNormalizeDate( @_day, @_month, @_year ) 14 | 15 | if ( cur_year < _year ) then 16 | while ( cur_year <> _year ) 17 | result += fb_hTimeDaysInYear( cur_year ) 18 | cur_year += 1 19 | wend 20 | else 21 | while ( cur_year <> _year ) 22 | result -= fb_hTimeDaysInYear( cur_year ) 23 | cur_year -= 1 24 | wend 25 | end if 26 | 27 | while ( cur_month <> _month ) 28 | result += fb_hTimeDaysInMonth( cur_month, _year ) 29 | cur_month += 1 30 | wend 31 | 32 | result += _day - cur_day 33 | 34 | return result 35 | end function 36 | end extern -------------------------------------------------------------------------------- /time_datevalue.bas: -------------------------------------------------------------------------------- 1 | /' datevalue function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_DateValue FBCALL ( s as FBSTRING ptr ) as long 8 | dim as long _year 9 | dim as long _month 10 | dim as long _day 11 | dim as long succeeded = fb_DateParse( s, @_day, @_month, @_year ) 12 | 13 | fb_hStrDelTemp( s ) 14 | 15 | if ( succeeded = 0 ) then 16 | fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 17 | return 0 18 | end if 19 | 20 | fb_ErrorSetNum( FB_RTERROR_OK ) 21 | 22 | return fb_DateSerial( _year, _month, _day ) 23 | end function 24 | end extern -------------------------------------------------------------------------------- /time_isdate.bas: -------------------------------------------------------------------------------- 1 | /' isdate function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_IsDate FBCALL ( s as FBSTRING ptr ) as long 8 | dim as long _year 9 | dim as long _month 10 | dim as long _day 11 | dim as long succeeded = fb_DateParse( s, @_day, @_month, @_year ) 12 | 13 | fb_hStrDelTemp( s ) 14 | 15 | if ( succeeded = 0 ) then 16 | return 0 17 | end if 18 | 19 | return -1 20 | end function 21 | end extern -------------------------------------------------------------------------------- /time_monthname.bas: -------------------------------------------------------------------------------- 1 | /' returns the month name '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_MonthName FBCALL ( _month as long, abbreviation as long ) as FBSTRING ptr 8 | dim as FBSTRING ptr res 9 | 10 | if ( _month < 1 or _month > 12 ) then 11 | fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL) 12 | return @__fb_ctx.null_desc 13 | end if 14 | 15 | fb_ErrorSetNum( FB_RTERROR_OK ) 16 | 17 | res = fb_IntlGetMonthName( _month, abbreviation, FALSE ) 18 | if ( res = NULL ) then 19 | fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL) 20 | res = @__fb_ctx.null_desc 21 | end if 22 | 23 | return res 24 | end function 25 | end extern -------------------------------------------------------------------------------- /time_now.bas: -------------------------------------------------------------------------------- 1 | /' NOW function '/ 2 | 3 | #include "fb.bi" 4 | #include "crt/time.bi" 5 | 6 | extern "C" 7 | /':::::'/ 8 | function fb_Now FBCALL ( ) as double 9 | dim as double dblTime, dblDate 10 | dim as time_t rawtime 11 | dim as tm ptr ptm 12 | 13 | /' guard by global lock because time/localtime might not be thread-safe '/ 14 | FB_LOCK() 15 | 16 | time_( @rawtime ) 17 | 18 | /' Note: localtime() can return NULL due to weird value from time() '/ 19 | ptm = localtime( @rawtime ) 20 | if (ptm = NULL) then 21 | return 0.0 22 | end if 23 | 24 | dblDate = fb_DateSerial( 1900 + ptm->tm_year, 1 + ptm->tm_mon, ptm->tm_mday ) 25 | dblTime = fb_TimeSerial( ptm->tm_hour, ptm->tm_min, ptm->tm_sec ) 26 | 27 | FB_UNLOCK() 28 | 29 | return dblDate + dblTime 30 | end function 31 | end extern -------------------------------------------------------------------------------- /time_sleepex.bas: -------------------------------------------------------------------------------- 1 | /' sleep multiplexer function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_SleepEx FBCALL ( msecs as long, kind as long ) as long 8 | select case ( kind ) 9 | case 0: 10 | fb_Sleep( msecs ) 11 | case 1: 12 | fb_Delay( msecs ) 13 | case else: 14 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 15 | end select 16 | return fb_ErrorSetNum( FB_RTERROR_OK ) 17 | end function 18 | end extern -------------------------------------------------------------------------------- /time_timeserial.bas: -------------------------------------------------------------------------------- 1 | /' timeserial function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_TimeSerial FBCALL ( _hour as long, _minute as long, _second as long ) as double 8 | dim as double dblHour = 1.0 * cast(double, _hour) / 24.0 9 | dim as double dblMinute = 1.0 * _minute / (24.0 * 60.0) 10 | dim as double dblSecond = 1.0 * _second / (24.0 * 60.0 * 60.0) 11 | return dblHour + dblMinute + dblSecond 12 | end function 13 | end extern -------------------------------------------------------------------------------- /time_timevalue.bas: -------------------------------------------------------------------------------- 1 | /' timevalue function '/ 2 | 3 | #include "fb.bi" 4 | 5 | extern "C" 6 | /':::::'/ 7 | function fb_TimeValue FBCALL ( s as FBSTRING ptr ) as double 8 | dim as long _hour 9 | dim as long _minute 10 | dim as long _second 11 | dim as long succeeded = fb_TimeParse( s, @_hour, @_minute, @_second ) 12 | 13 | fb_hStrDelTemp( s ) 14 | 15 | if ( succeeded = 0 ) then 16 | fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 17 | return 0 18 | end if 19 | 20 | fb_ErrorSetNum( FB_RTERROR_OK ) 21 | 22 | return fb_TimeSerial( _hour, _minute, _second ) 23 | end function 24 | end extern -------------------------------------------------------------------------------- /unix/drv_intl_get.bas: -------------------------------------------------------------------------------- 1 | /' get i18n data '/ 2 | 3 | #include "../fb.bi" 4 | #include "langinfo.bi" 5 | 6 | Function fb_DrvIntlGet( eFbIntlIndex Index ) as const ubyte ptr 7 | 8 | select case Index 9 | case eFIL_DateDivider 10 | return "/" 11 | case eFIL_TimeDivider 12 | return ":" 13 | case eFIL_NumDecimalPoint 14 | return nl_langinfo( RADIXCHAR ) 15 | case eFIL_NumThousandsSeparator 16 | return nl_langinfo( THOUSEP ) 17 | end select 18 | return NULL 19 | End Function 20 | -------------------------------------------------------------------------------- /unix/fb_private_scancodes_x11.bi: -------------------------------------------------------------------------------- 1 | #ifndef DISABLE_X11 2 | 3 | #include "X11/Xlib.bi" 4 | #include "X11/keysym.bi" 5 | 6 | Type XOPENDISPLAY As Function(as ubyte ptr) as Display ptr 7 | Type XCLOSEDISPLAY As Function (as Display ptr) as long 8 | Type XQUERYKEYMAP As Sub(as Display ptr, as ubyte ptr) 9 | Type XDISPLAYKEYCODES As Function(as Display ptr, as long ptr, as long ptr) as long 10 | Type XGETKEYBOARDMAPPING As Function(as Display ptr, as KeyCode, as long, as long ptr) as KeySym ptr 11 | Type XFREE as Function(as Any ptr) as long 12 | 13 | extern fb_x11keycode_to_scancode(0 to 255) as ubyte 14 | 15 | Declare Sub fb_hInitX11KeycodeToScancodeTb 16 | ( 17 | display_ as Display ptr, 18 | DisplayKeycodes as XDISPLAYKEYCODES, 19 | GetKeyboardMapping as XGETKEYBOARDMAPPING, 20 | free as XFREE 21 | ) 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /unix/fb_unix.bi: -------------------------------------------------------------------------------- 1 | ' #include 2 | ' #include 3 | 4 | #define FBCALL 5 | 6 | /' newline for console/file I/O '/ 7 | #define FB_NEWLINE !"\n" 8 | #define FB_NEWLINE_WSTR _LC(!"\n") 9 | 10 | /' newline for printer I/O '/ 11 | #define FB_BINARY_NEWLINE !"\r\n" 12 | #define FB_BINARY_NEWLINE_WSTR _LC(!"\r\n") 13 | 14 | #define FB_LL_FMTMOD "ll" 15 | 16 | #define FB_CONSOLE_MAXPAGES 1 17 | 18 | /' Relying on -D_FILE_OFFSET_BITS=64 to transparently remap to off64_t '/ 19 | #if not defined(_FILE_OFFSET_BITS) or _FILE_OFFSET_BITS <> 64 20 | #error Expected _FILE_OFFSET_BITS=64 21 | #endif 22 | type fb_off_t as off_t 23 | 24 | declare sub fb_BgLock FBCALL( ) 25 | declare sub fb_BgUnlock FBCALL( ) 26 | #define BG_LOCK() fb_BgLock() 27 | #define BG_UNLOCK() fb_BgUnlock() 28 | 29 | /' Global variable for disabling hard-coded VT100 escape sequences in 30 | fb_hTermOut(). '/ 31 | extern __fb_enable_vt100_escapes as integer 32 | -------------------------------------------------------------------------------- /unix/file_copy.bas: -------------------------------------------------------------------------------- 1 | /' file copy '/ 2 | 3 | #include "../fb.bi" 4 | 5 | Extern "C" 6 | Function fb_FileCopy FBCALL ( source as const ubyte ptr, destination as const ubyte ptr ) as Long 7 | return fb_CrtFileCopy( source, destination ) 8 | End Function 9 | End Extern -------------------------------------------------------------------------------- /unix/file_hflush.bas: -------------------------------------------------------------------------------- 1 | /' flush system buffers '/ 2 | 3 | #include "../fb.bi" 4 | 5 | Extern "c" 6 | Function fb_hFileFlushEx( f as FILE ptr ) as Long 7 | if( fsync( fileno( f ) ) <> 0 ) then 8 | return fb_ErrorSetNum( FB_RTERROR_FILEIO ) 9 | end if 10 | 11 | return fb_ErrorSetNum( FB_RTERROR_OK ) 12 | End Function 13 | End Extern -------------------------------------------------------------------------------- /unix/file_hreset.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | 3 | Extern "c" 4 | Function fb_hFileResetEx( streamno as long ) As Long 5 | 6 | dim f as FILE ptr 7 | 8 | if( streamno = 0 ) then 9 | f = freopen( "/dev/tty", "r", stdin ) 10 | else 11 | f = freopen( "/dev/tty", "w", stdout ) 12 | end if 13 | 14 | return (f <> NULL) 15 | End Function 16 | End Extern -------------------------------------------------------------------------------- /unix/file_hseteof.bas: -------------------------------------------------------------------------------- 1 | /' low-level truncate / set end of file '/ 2 | 3 | #include "../fb.bi" 4 | #include "unistd.bi" 5 | 6 | Function fb_hFileSetEofEx( f as FILE ptr ) As Long 7 | 8 | dim pos as fb_off_t 9 | 10 | pos = ftello( f ) 11 | if ( ftruncate( fileno( f ), pos ) <> 0 ) then 12 | return fb_ErrorSetNum( FB_RTERROR_FILEIO ) 13 | end if 14 | 15 | return fb_ErrorSetNum( FB_RTERROR_OK ) 16 | 17 | End Function 18 | 19 | 20 | -------------------------------------------------------------------------------- /unix/hinit_enable_vt100_escapes.bas: -------------------------------------------------------------------------------- 1 | /' Global variable for disabling hard-coded VT100 escape sequences in 2 | fb_hTermOut(). 3 | 4 | This is our default implementation of this global variable - set to TRUE. 5 | It is supposed to be used when there is no other implementation of the global 6 | variable. It must be in its own object file to let the linker prefer a 7 | __fb_enable_vt100_escapes symbol from an earlier object (e.g. one provided by 8 | the FB program). 9 | 10 | This way, FB programs can override this one with their own implementation. 11 | They can then set the variable to TRUE/FALSE at runtime as needed. '/ 12 | 13 | Dim Shared __fb_enable_vt100_escapes As Long = -1 14 | -------------------------------------------------------------------------------- /unix/io_getsize.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "fb_private_console.bi" 3 | 4 | Extern "C" 5 | Sub fb_ConsoleGetSize FBCALL( cols as long ptr, rows as long ptr) 6 | 7 | if( __fb_con.inited = 0) then 8 | if( cols <> Null ) then *cols = 80 9 | if( rows <> Null ) then *rows = 24 10 | Exit Sub 11 | end if 12 | 13 | BG_LOCK( ) 14 | fb_hRecheckConsoleSize( TRUE ) 15 | BG_UNLOCK( ) 16 | 17 | if( cols <> Null ) then *cols = __fb_con.w 18 | if( rows <> Null ) then *rows = __fb_con.h 19 | End Sub 20 | End Extern -------------------------------------------------------------------------------- /unix/io_getx.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "fb_private_console.bi" 3 | 4 | Extern "c" 5 | Function fb_ConsoleGetX( ) As Long 6 | 7 | dim x as long 8 | fb_ConsoleGetXY( @x, NULL ) 9 | return x 10 | End Function 11 | End Extern -------------------------------------------------------------------------------- /unix/io_gety.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "fb_private_console.bi" 3 | 4 | Extern "c" 5 | Function fb_ConsoleGetY( ) As Long 6 | 7 | dim y as long 8 | fb_ConsoleGetXY( NULL, @y ) 9 | return y 10 | End Function 11 | 12 | End Extern 13 | -------------------------------------------------------------------------------- /unix/io_input.bas: -------------------------------------------------------------------------------- 1 | /' console input helpers '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | Extern "c" 7 | Function fb_hConsoleInputBufferChanged( ) As Long 8 | return fb_KeyHit() 9 | End Function 10 | End Extern -------------------------------------------------------------------------------- /unix/io_isredir.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | 3 | Extern "c" 4 | Function fb_ConsoleIsRedirected( is_input As Long ) As Long 5 | 6 | dim filenum as Long = fileno( Iif(is_input, stdin, stdout) ) 7 | return Iif( isatty( filenum ) = 0, FB_TRUE, FB_FALSE ) 8 | End Function 9 | End Extern -------------------------------------------------------------------------------- /unix/io_maxrow.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "fb_private_console.bi" 3 | 4 | Extern "c" 5 | Function fb_ConsoleGetMaxRow( ) As Long 6 | 7 | if( __fb_con.inited = 0 ) then return 24 8 | 9 | BG_LOCK( ) 10 | fb_hRecheckConsoleSize( TRUE ) 11 | BG_UNLOCK( ) 12 | return __fb_con.h 13 | End Function 14 | End Extern 15 | -------------------------------------------------------------------------------- /unix/io_pageset.bas: -------------------------------------------------------------------------------- 1 | /' console 'screen , pg, pg' function '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | Extern "c" 7 | Function fb_ConsolePageSet( active As Long, visible As Long ) As Long 8 | 9 | return -1 10 | End Function 11 | End Extern 12 | -------------------------------------------------------------------------------- /unix/io_pcopy.bas: -------------------------------------------------------------------------------- 1 | /' console pcopy function '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | Extern "c" 7 | Function fb_ConsolePageCopy( src as long, dst as long ) As Long 8 | 9 | return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL ) 10 | End Function 11 | End Extern -------------------------------------------------------------------------------- /unix/io_readxy.bas: -------------------------------------------------------------------------------- 1 | /' console SCREEN() function (character/color query) '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | Extern "c" 7 | Function fb_ConsoleReadXY FBCALL( x as long, y as long, colorflag as long ) as Ulong 8 | 9 | dim buffer as ubyte ptr 10 | 11 | if( __fb_con.inited = 0 ) then 12 | return 0 13 | end if 14 | 15 | BG_LOCK( ) 16 | fb_hRecheckConsoleSize( TRUE ) 17 | BG_UNLOCK( ) 18 | 19 | if ((x < 1) orelse (x > __fb_con.w) orelse (y < 1) orelse (y > __fb_con.h)) then 20 | return 0 21 | end if 22 | 23 | if (colorflag <> 0) then 24 | buffer = __fb_con.attr_buffer 25 | else 26 | buffer = __fb_con.char_buffer 27 | end if 28 | 29 | return buffer[((y - 1) * __fb_con.w) + x - 1] 30 | End Function 31 | End Extern -------------------------------------------------------------------------------- /unix/io_scroll.bas: -------------------------------------------------------------------------------- 1 | /' console scrolling for when VIEW is used '/ 2 | 3 | #include "../fb.bi" 4 | #include "../unix/fb_private_console.bi" 5 | 6 | Extern "c" 7 | Sub fb_ConsoleScroll(nrows as long) 8 | 9 | fb_hTermOut(SEQ_SCROLL, 0, nrows) 10 | End Sub 11 | End Extern 12 | -------------------------------------------------------------------------------- /unix/io_viewupdate.bas: -------------------------------------------------------------------------------- 1 | /' view print update (console, no gfx) '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | Extern "c" 7 | Sub fb_ConsoleViewUpdate( ) 8 | 9 | if (__fb_con.inited = 0) then 10 | Exit Sub 11 | end if 12 | __fb_con.scroll_region_changed = True 13 | fb_hTermOut(SEQ_SCROLL_REGION, fb_ConsoleGetBotRow(), fb_ConsoleGetTopRow()) 14 | End Sub 15 | End Extern 16 | -------------------------------------------------------------------------------- /unix/io_width.bas: -------------------------------------------------------------------------------- 1 | /' console width() function '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | Extern "c" 7 | Function fb_ConsoleWidth( cols as long, rows as long ) as long 8 | 9 | if( __fb_con.inited = 0 ) then 10 | return (80 Or (25 Shl 16)) 11 | end if 12 | 13 | BG_LOCK( ) 14 | fb_hRecheckConsoleSize( TRUE ) 15 | BG_UNLOCK( ) 16 | 17 | dim cur as long = __fb_con.w Or (__fb_con.h Shl 16) 18 | 19 | if ((cols > 0) orelse (rows > 0)) then 20 | BG_LOCK() 21 | 22 | if (cols <= 0) then 23 | cols = __fb_con.w 24 | end if 25 | if (rows <= 0) then 26 | rows = __fb_con.h 27 | end if 28 | fb_hTermOut(SEQ_WINDOW_SIZE, rows, cols) 29 | 30 | BG_UNLOCK() 31 | 32 | fb_ConsoleClear( 0 ) 33 | end if 34 | 35 | return cur 36 | End Function 37 | End Extern 38 | -------------------------------------------------------------------------------- /unix/sys_beep.bas: -------------------------------------------------------------------------------- 1 | /' beep function '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | Extern "c" 7 | Sub fb_Beep FBCALL( ) 8 | 9 | fb_hTermOut(SEQ_BEEP, 0, 0) 10 | End Sub 11 | End Extern 12 | -------------------------------------------------------------------------------- /unix/sys_delay.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "sys/select.bi" 3 | 4 | Extern "C" 5 | Sub fb_Delay FBCALL( msecs as long ) 6 | 7 | dim tv as timeval 8 | tv.tv_sec = msecs / 1000 9 | tv.tv_usec = (msecs Mod 1000) * 1000 10 | select(0, NULL, NULL, NULL, @tv) 11 | End Sub 12 | End Extern -------------------------------------------------------------------------------- /unix/sys_getcwd.bas: -------------------------------------------------------------------------------- 1 | /' get current dir '/ 2 | 3 | #include "../fb.bi" 4 | 5 | Extern "c" 6 | Function fb_hGetCurrentDir( dst as ubyte ptr, maxlen as ssize_t ) as ssize_t 7 | 8 | if( getcwd( dst, maxlen ) <> NULL ) then 9 | return strlen( dst ) 10 | end if 11 | return 0 12 | End Function 13 | End Extern 14 | -------------------------------------------------------------------------------- /unix/sys_hshell.bas: -------------------------------------------------------------------------------- 1 | /' SHELL command '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | #include "sys/wait.bi" 6 | 7 | Extern "c" 8 | Function fb_hShell( program as ubyte ptr ) as long 9 | 10 | dim errcode as long 11 | 12 | FB_LOCK( ) 13 | fb_hExitConsole() 14 | FB_UNLOCK( ) 15 | 16 | errcode = system( program ) 17 | 18 | /' system() result uses same format as the status 19 | returned by waitpid(), or -1 on error '/ 20 | if( ( errcode <> -1 ) AndAlso WIFEXITED( errcode ) ) then 21 | errcode = WEXITSTATUS( errcode ) 22 | if( errcode = 127 ) then 23 | /' /bin/sh could not be executed '/ 24 | /' FIXME: can't tell difference if /bin/sh returned 127 '/ 25 | errcode = -1 26 | end if 27 | end if 28 | 29 | FB_LOCK( ) 30 | fb_hInitConsole() 31 | FB_UNLOCK( ) 32 | 33 | return errcode 34 | End Function 35 | End Extern 36 | -------------------------------------------------------------------------------- /unix/thread_mutex.bas: -------------------------------------------------------------------------------- 1 | /' mutex handling routines '/ 2 | 3 | #include "../fb.bi" 4 | #include "unix_private_thread.bi" 5 | 6 | Extern "c" 7 | Function fb_MutexCreate FBCALL( void ) As FBMUTEX Ptr 8 | 9 | Dim mutex As FBMUTEX Ptr = New FBMUTEX 10 | If( mutex <> Null) Then 11 | pthread_mutex_init( @mutex->id, NULL ) 12 | End if 13 | 14 | Return mutex 15 | End Function 16 | 17 | Sub fb_MutexDestroy FBCALL( ByVal mutex As FBMUTEX Ptr ) 18 | 19 | If( mutex <> Null ) Then 20 | pthread_mutex_destroy( @mutex->id ) 21 | Delete mutex 22 | End If 23 | End Sub 24 | 25 | Sub fb_MutexLock FBCALL( ByVal mutex As FBMUTEX Ptr ) 26 | 27 | If( mutex <> Null ) Then 28 | pthread_mutex_lock( @mutex->id ) 29 | End If 30 | End Sub 31 | 32 | Sub fb_MutexUnlock FBCALL( ByVal mutex As FBMUTEX Ptr ) 33 | 34 | If( mutex <> Null ) Then 35 | pthread_mutex_unlock( @mutex->id ) 36 | End If 37 | End Sub 38 | End Extern 39 | -------------------------------------------------------------------------------- /unix/time_setdate.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "sys/time.bi" 3 | 4 | Extern "c" 5 | Function fb_hSetDate( int y, int m, int d ) as long 6 | 7 | dim month_len(0 To 11) as const long = _ 8 | { _ 9 | 2678400, 2419200, 2678400, 2592000, 2678400, 2592000, _ 10 | 2678400, 2678400, 2592000, 2678400, 2592000, 2678400 _ 11 | } 12 | 13 | dim tv as timeval 14 | dim secs as time_t 15 | dim i as long 16 | 17 | if( y < 1970 ) then 18 | return -1 19 | end if 20 | gettimeofday( @tv, NULL ) 21 | secs = tv.tv_sec Mod 86400 22 | tv.tv_sec = 0 23 | for i = 1970 to y - 1 24 | tv.tv_sec += 31536000 25 | if( ((i Mod 4) = 0) OrElse ((i / 400) = 0) ) then 26 | d += 1 27 | end if 28 | Next 29 | tv.tv_sec += (m * month_len(m-1)) 30 | if( ((y Mod 4) = 0) OrElse ((y / 400) = 0) ) then 31 | d += 1 32 | end if 33 | tv.tv_sec += (d * 86400) + secs 34 | if( settimeofday( @tv, NULL ) ) then 35 | return -1 36 | end if 37 | 38 | return 0 39 | End Function 40 | End Extern 41 | 42 | -------------------------------------------------------------------------------- /unix/time_settime.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "sys/time.bi" 3 | 4 | Extern "c" 5 | Function fb_hSetTime( h as long, m as long, s as long ) as long 6 | 7 | dim tv as timeval 8 | gettimeofday( @tv, NULL ) 9 | tv.tv_sec -= (tv.tv_sec Mod 86400) 10 | tv.tv_sec += (h * 3600) + (m * 60) + s 11 | if( settimeofday( @tv, NULL ) ) then 12 | return -1 13 | end if 14 | return 0 15 | End Function 16 | End Extern 17 | -------------------------------------------------------------------------------- /unix/time_timer.bas: -------------------------------------------------------------------------------- 1 | /' timer() function '/ 2 | 3 | #include "../fb.bi" 4 | #include "time.bi" 5 | #include "sys/time.bi" 6 | 7 | Extern "c" 8 | Function fb_Timer FBCALL( ) as double 9 | 10 | dim tv as timeval 11 | dim result as double 12 | gettimeofday(@tv, NULL) 13 | result = tv.tv_sec * 1000000.0 14 | result += tv.tv_usec 15 | return result * 0.000001 16 | End Function 17 | End Extern 18 | -------------------------------------------------------------------------------- /unix/unix_private_thread.bi: -------------------------------------------------------------------------------- 1 | #include "crt/pthread.bi" 2 | 3 | type _FBMUTEX 4 | as pthread_mutex_t id 5 | end type 6 | 7 | type _FBCOND 8 | as pthread_cond_t id 9 | end type 10 | -------------------------------------------------------------------------------- /win32/.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | -------------------------------------------------------------------------------- /win32/drv_intl_get.bas: -------------------------------------------------------------------------------- 1 | /' get i18n data '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_intl.bi" 5 | 6 | extern "C" 7 | function fb_DrvIntlGet ( Index as eFbIntlIndex ) as const ubyte ptr 8 | static as ubyte buf(0 to 127) 9 | dim as LCTYPE _lctype 10 | 11 | select case Index 12 | case eFIL_DateDivider: 13 | _lctype = LOCALE_SDATE 14 | case eFIL_TimeDivider: 15 | _lctype = LOCALE_STIME 16 | case eFIL_NumDecimalPoint: 17 | _lctype = LOCALE_SDECIMAL 18 | case eFIL_NumThousandsSeparator: 19 | _lctype = LOCALE_STHOUSAND 20 | case else: 21 | return NULL 22 | end select 23 | 24 | return iif(fb_hGetLocaleInfo( LOCALE_USER_DEFAULT, _lctype, @buf(0), ARRAY_SIZEOF(buf) - 1 ), @buf(0), NULL) 25 | end function 26 | end extern -------------------------------------------------------------------------------- /win32/fb_private_intl.bi: -------------------------------------------------------------------------------- 1 | #include "windows.bi" 2 | 3 | extern "C" 4 | declare function fb_hGetLocaleInfo ( Locale as LCID, _LCType as LCTYPE, pszBuffer as ubyte ptr, uiSize as size_t ) as ubyte ptr 5 | declare function fb_hIntlConvertString ( source as FBSTRING ptr, source_cp as long, dest_cp as long ) as FBSTRING ptr 6 | end extern -------------------------------------------------------------------------------- /win32/fbportio.bi: -------------------------------------------------------------------------------- 1 | #define FBPORTIO_VERSION 256 2 | #define FBPORTIO 32768 3 | #define IOCTL_GRANT_IOPM CTL_CODE(FBPORTIO, 2048, METHOD_BUFFERED, FILE_ANY_ACCESS) 4 | #define IOCTL_GET_VERSION CTL_CODE(FBPORTIO, 2049, METHOD_BUFFERED, FILE_ANY_ACCESS) -------------------------------------------------------------------------------- /win32/file_copy.bas: -------------------------------------------------------------------------------- 1 | /' file copy '/ 2 | 3 | #include "../fb.bi" 4 | #include "windows.bi" 5 | 6 | extern "C" 7 | function fb_FileCopy FBCALL ( source as const ubyte ptr, destination as const ubyte ptr ) as long 8 | dim as BOOL res 9 | res = CopyFile( source, destination, FALSE ) 10 | return fb_ErrorSetNum( iif(res = FALSE, FB_RTERROR_ILLEGALFUNCTIONCALL, FB_RTERROR_OK) ) 11 | end function 12 | end extern -------------------------------------------------------------------------------- /win32/file_hflush.bas: -------------------------------------------------------------------------------- 1 | /' low-level flush system buffers '/ 2 | 3 | #include "../fb.bi" 4 | #include "crt/io.bi" 5 | #include "windows.bi" 6 | 7 | extern "C" 8 | 9 | function fb_hFileFlushEx( f as FILE ptr ) as long 10 | 11 | if( FlushFileBuffers( cast(HANDLE, _get_osfhandle( _fileno( f ) ) ) ) = 0 ) then 12 | return fb_ErrorSetNum( FB_RTERROR_FILEIO ) 13 | end if 14 | 15 | return fb_ErrorSetNum( FB_RTERROR_OK ) 16 | end function 17 | 18 | end extern -------------------------------------------------------------------------------- /win32/file_hlock.bas: -------------------------------------------------------------------------------- 1 | /' low-level lock and unlock functions '/ 2 | 3 | #include "../fb.bi" 4 | #include "crt/io.bi" 5 | #include "windows.bi" 6 | 7 | extern "C" 8 | function fb_hFileLock cdecl ( f as FILE ptr, inipos as fb_off_t, size as fb_off_t ) as long 9 | return fb_ErrorSetNum( iif(LockFile( cast(HANDLE, _get_osfhandle( _fileno( f ) )), inipos, 0, size, 0 ) = TRUE, FB_RTERROR_OK, FB_RTERROR_FILEIO) ) 10 | end function 11 | 12 | function fb_hFileUnlock cdecl ( f as FILE ptr, inipos as fb_off_t, size as fb_off_t ) as long 13 | return fb_ErrorSetNum( iif(UnlockFile( cast(HANDLE, _get_osfhandle( _fileno( f ) )), inipos, 0, size, 0 ) = TRUE, FB_RTERROR_OK, FB_RTERROR_FILEIO) ) 14 | end function 15 | end extern -------------------------------------------------------------------------------- /win32/file_hreset.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "fb_private_console.bi" 3 | 4 | extern "C" 5 | function fb_hFileResetEx cdecl ( streamno as long ) as long 6 | dim as FILE ptr f 7 | 8 | fb_hConsoleResetHandles() 9 | 10 | if ( streamno = 0 ) then 11 | f = freopen( "CONIN$", "r", stdin ) 12 | else 13 | f = freopen( "CONOUT$", "w", stdout ) 14 | end if 15 | /' force handles to be reinitialized now '/ 16 | fb_hConsoleGetHandle( TRUE ) 17 | 18 | return (f <> NULL) 19 | end function 20 | end extern -------------------------------------------------------------------------------- /win32/file_hseteof.bas: -------------------------------------------------------------------------------- 1 | /' low-level truncate / set end of file '/ 2 | 3 | #include "../fb.bi" 4 | #include "windows.bi" 5 | 6 | extern "C" 7 | 8 | function fb_hFileSetEofEx( f as FILE ptr ) as long 9 | 10 | dim h as HANDLE = cast(HANDLE, _get_osfhandle( _fileno( f ) ) ) 11 | dim as long errorCode = iif ( _ 12 | SetEndOfFile( h ) = 0, _ 13 | FB_RTERROR_FILEIO, _ 14 | FB_RTERROR_OK _ 15 | ) 16 | 17 | return fb_ErrorSetNum( errorCode ) 18 | 19 | end function 20 | 21 | end extern 22 | -------------------------------------------------------------------------------- /win32/io_getsize.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "fb_private_console.bi" 3 | 4 | extern "C" 5 | sub fb_ConsoleGetSize FBCALL ( cols as long ptr, rows as long ptr ) 6 | dim as long nrows, ncols 7 | 8 | fb_InitConsoleWindow() 9 | 10 | if ( FB_CONSOLE_WINDOW_EMPTY() ) then 11 | ncols = FB_SCRN_DEFAULT_WIDTH 12 | nrows = FB_SCRN_DEFAULT_HEIGHT 13 | else 14 | fb_hConsoleGetWindow( NULL, NULL, @ncols, @nrows ) 15 | end if 16 | 17 | if( cols <> NULL ) then 18 | *cols = ncols 19 | end if 20 | if( rows <> NULL ) then 21 | *rows = nrows 22 | end if 23 | end sub 24 | end extern -------------------------------------------------------------------------------- /win32/io_getx.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "fb_private_console.bi" 3 | 4 | extern "C" 5 | function fb_ConsoleGetRawXEx( hConsole as HANDLE ) as long 6 | dim as CONSOLE_SCREEN_BUFFER_INFO info 7 | if( GetConsoleScreenBufferInfo( hConsole, @info ) = 0 ) then 8 | return 0 9 | end if 10 | return info.dwCursorPosition.X 11 | end function 12 | 13 | function fb_ConsoleGetRawX( ) as long 14 | return fb_ConsoleGetRawXEx( __fb_out_handle ) 15 | end function 16 | 17 | function fb_ConsoleGetX( ) as long 18 | dim as long x = fb_ConsoleGetRawX() 19 | fb_hConvertFromConsole( @x, NULL, NULL, NULL ) 20 | return x 21 | end function 22 | end extern -------------------------------------------------------------------------------- /win32/io_gety.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "fb_private_console.bi" 3 | 4 | extern "C" 5 | function fb_ConsoleGetRawYEx( hConsole as HANDLE ) as long 6 | dim as CONSOLE_SCREEN_BUFFER_INFO info 7 | if ( GetConsoleScreenBufferInfo( hConsole, @info ) = 0 ) then 8 | return 0 9 | end if 10 | return info.dwCursorPosition.Y 11 | end function 12 | 13 | function fb_ConsoleGetRawY( ) as long 14 | return fb_ConsoleGetRawYEx( __fb_out_handle ) 15 | end function 16 | 17 | function fb_ConsoleGetY( ) as long 18 | dim as long y = fb_ConsoleGetRawY() 19 | fb_hConvertFromConsole( NULL, @y, NULL, NULL ) 20 | return y 21 | end function 22 | end extern -------------------------------------------------------------------------------- /win32/io_isredir.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "fb_private_console.bi" 3 | 4 | extern "C" 5 | function fb_ConsoleIsRedirected ( is_input as long ) as long 6 | dim as DWORD mode 7 | 8 | return iif((GetConsoleMode( iif(is_input, __fb_in_handle, __fb_out_handle), @mode ) = 0), FB_TRUE, FB_FALSE) 9 | end function 10 | end extern -------------------------------------------------------------------------------- /win32/io_maxrow.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "fb_private_console.bi" 3 | 4 | extern "C" 5 | function fb_ConsoleGetMaxRow( ) as long 6 | dim as COORD _max_ = GetLargestConsoleWindowSize( __fb_out_handle ) 7 | return iif((_max_.Y = 0), FB_SCRN_DEFAULT_HEIGHT, _max_.Y + 1) 8 | end function 9 | end extern -------------------------------------------------------------------------------- /win32/io_printer_private.bi: -------------------------------------------------------------------------------- 1 | #include "windows.bi" 2 | #include "win/winspool.bi" 3 | 4 | Type _W32_PRINTER_INFO as W32_PRINTER_INFO 5 | 6 | type FnEmuPrint as Sub ( pInfo as _W32_PRINTER_INFO ptr, pText as const any ptr, uiLength as size_t, isunicode as long) 7 | 8 | type _Emu 9 | as DWORD dwFullSizeX 10 | as DWORD dwFullSizeY 11 | as DWORD dwSizeX 12 | as DWORD dwSizeY 13 | as DWORD dwOffsetX 14 | as DWORD dwOffsetY 15 | as DWORD dwDPI_X 16 | as DWORD dwDPI_Y 17 | 18 | as DWORD dwCurrentX 19 | as DWORD dwCurrentY 20 | as HFONT hFont 21 | as COLORREF clFore, clBack 22 | as DWORD dwFontSizeX 23 | as DWORD dwFontSizeY 24 | as long iPageStarted 25 | 26 | as FnEmuPrint pfnPrint 27 | end Type 28 | 29 | /' Win32-specific printer information '/ 30 | type W32_PRINTER_INFO 31 | as HANDLE hPrinter 32 | as DWORD dwJob 33 | as HDC hDc 34 | as _Emu Emu 35 | end type 36 | -------------------------------------------------------------------------------- /win32/io_readstr.bas: -------------------------------------------------------------------------------- 1 | /' console line input function '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | extern "C" 7 | function fb_ConsoleReadStr( buffer as ubyte ptr, _len as size_t ) as ubyte ptr 8 | dim as ubyte ptr res 9 | 10 | fb_hRestoreConsoleWindow( ) 11 | FB_CON_CORRECT_POSITION() 12 | fb_hConsolePutBackEvents( ) 13 | 14 | res = fgets( buffer, _len, stdin ) 15 | 16 | fb_hUpdateConsoleWindow( ) 17 | 18 | return res 19 | end function 20 | end extern -------------------------------------------------------------------------------- /win32/io_readxy.bas: -------------------------------------------------------------------------------- 1 | /' console SCREEN() function (character/color query) '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | extern "C" 7 | function fb_ConsoleReadXY FBCALL ( col as long, row as long, colorflag as long ) as ulong 8 | dim as TCHAR character 9 | dim as WORD attribute 10 | dim as DWORD res 11 | dim as COORD coord 12 | 13 | fb_hConvertToConsole( @col, @row, NULL, NULL ) 14 | 15 | coord.X = cast(SHORT, col) 16 | coord.Y = cast(SHORT, row) 17 | 18 | if ( colorflag <> NULL ) then 19 | ReadConsoleOutputAttribute( __fb_out_handle, @attribute, 1, coord, @res) 20 | return (cast(ulong, attribute)) and &hfffful 21 | else 22 | ReadConsoleOutputCharacter( __fb_out_handle, @character, 1, coord, @res) 23 | return (cast(ulong, character)) and iif(sizeof(TCHAR) = 1, &hfful, &hfffful) 24 | end if 25 | end function 26 | end extern -------------------------------------------------------------------------------- /win32/io_screensize.bas: -------------------------------------------------------------------------------- 1 | /' size of the screen buffer '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | extern "C" 7 | sub fb_ConsoleGetScreenSizeEx( hConsole as HANDLE, cols as long ptr, rows as long ptr ) 8 | dim as CONSOLE_SCREEN_BUFFER_INFO info 9 | if ( GetConsoleScreenBufferInfo( hConsole, @info ) = 0 ) then 10 | if ( cols <> NULL ) then 11 | *cols = FB_SCRN_DEFAULT_WIDTH 12 | end if 13 | if ( rows <> NULL ) then 14 | *rows = FB_SCRN_DEFAULT_HEIGHT 15 | end if 16 | else 17 | if ( cols <> NULL ) then 18 | *cols = info.dwSize.X 19 | end if 20 | if ( rows <> NULL ) then 21 | *rows = info.dwSize.Y 22 | end if 23 | end if 24 | end sub 25 | 26 | sub fb_ConsoleGetScreenSize FBCALL ( cols as long ptr, rows as long ptr ) 27 | fb_ConsoleGetScreenSizeEx( __fb_out_handle, cols, rows ) 28 | end sub 29 | end extern -------------------------------------------------------------------------------- /win32/io_viewupdate.bas: -------------------------------------------------------------------------------- 1 | /' view print update (console, no gfx) '/ 2 | 3 | #include "../fb.bi" 4 | #include "fb_private_console.bi" 5 | 6 | extern "C" 7 | sub fb_ConsoleViewUpdate( ) 8 | fb_hUpdateConsoleWindow( ) 9 | end sub 10 | end extern -------------------------------------------------------------------------------- /win32/sys_beep.bas: -------------------------------------------------------------------------------- 1 | /' beep function '/ 2 | 3 | #include "../fb.bi" 4 | #include "windows.bi" 5 | 6 | extern "C" 7 | sub fb_Beep FBCALL ( ) 8 | _Beep( 1000, 250 ) 9 | end sub 10 | end extern -------------------------------------------------------------------------------- /win32/sys_delay.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "windows.bi" 3 | 4 | extern "C" 5 | sub fb_Delay FBCALL ( msecs as long ) 6 | Sleep_( msecs ) 7 | end sub 8 | end extern -------------------------------------------------------------------------------- /win32/sys_fmem.bas: -------------------------------------------------------------------------------- 1 | /' fre() function '/ 2 | 3 | #include "../fb.bi" 4 | #include "windows.bi" 5 | 6 | extern "C" 7 | function fb_GetMemAvail FBCALL ( mode as long ) as size_t 8 | dim as MEMORYSTATUS ms 9 | ms.dwLength = sizeof( MEMORYSTATUS ) 10 | GlobalMemoryStatus( @ms ) 11 | return ms.dwAvailPhys 12 | end function 13 | end extern -------------------------------------------------------------------------------- /win32/sys_getcwd.bas: -------------------------------------------------------------------------------- 1 | /' get current dir '/ 2 | 3 | #include "../fb.bi" 4 | #include "windows.bi" 5 | 6 | extern "C" 7 | function fb_hGetCurrentDir( dst as ubyte ptr, maxlen as ssize_t ) as ssize_t 8 | return GetCurrentDirectory( maxlen, dst ) 9 | end function 10 | end extern -------------------------------------------------------------------------------- /win32/sys_getexename.bas: -------------------------------------------------------------------------------- 1 | /' get the executable's name '/ 2 | 3 | #include "../fb.bi" 4 | #include "windows.bi" 5 | 6 | extern "C" 7 | function fb_hGetExeName( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 8 | GetModuleFileName( GetModuleHandle( NULL ), dst, maxlen ) 9 | 10 | dim as ubyte ptr p = strrchr( dst, asc("\") ) 11 | if ( p <> NULL ) then 12 | p += 1 13 | else 14 | p = dst 15 | end if 16 | return p 17 | end function 18 | end extern 19 | -------------------------------------------------------------------------------- /win32/sys_getexepath.bas: -------------------------------------------------------------------------------- 1 | /' get the executable path '/ 2 | 3 | #include "../fb.bi" 4 | #include "windows.bi" 5 | 6 | extern "C" 7 | function fb_hGetExePath( dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 8 | GetModuleFileName( GetModuleHandle( NULL ), dst, maxlen ) 9 | 10 | dim as ubyte ptr p = strrchr( dst, asc(!"\\") ) 11 | if ( p <> NULL ) then 12 | *p = 0 13 | else 14 | dst[0] = 0 15 | end if 16 | 17 | /' just a drive letter? make sure \ follows to prevent using relative path '/ 18 | if ( maxlen > 3 and dst[2] = 0 and dst[1] = asc(":") ) then 19 | if ( (dst[0] and not(32)) >= asc("A") and (dst[0] and not(32)) <= asc("Z") ) then 20 | dst[2] = asc(!"\\") 21 | dst[3] = 0 22 | end if 23 | end if 24 | 25 | return p 26 | end function 27 | end extern -------------------------------------------------------------------------------- /win32/sys_getshortpath.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "windows.bi" 3 | 4 | extern "C" 5 | function fb_hGetShortPath( src as ubyte ptr, dst as ubyte ptr, maxlen as ssize_t ) as ubyte ptr 6 | if ( strchr( src, Asc(" ") ) = NULL ) then 7 | strncpy( dst, src, maxlen ) 8 | dst[maxlen - 1] = 0 9 | else 10 | GetShortPathName( src, dst, maxlen ) 11 | end if 12 | 13 | return dst 14 | end function 15 | end extern -------------------------------------------------------------------------------- /win32/sys_hshell.bas: -------------------------------------------------------------------------------- 1 | /' SHELL command '/ 2 | 3 | #include "../fb.bi" 4 | 5 | extern "C" 6 | function fb_hShell( program as ubyte ptr ) as long 7 | return system_( program ) 8 | end function 9 | end extern -------------------------------------------------------------------------------- /win32/thread_mutex.bas: -------------------------------------------------------------------------------- 1 | /' mutex handling routines '/ 2 | 3 | #include "../fb.bi" 4 | #include "win32_private_thread.bi" 5 | 6 | extern "C" 7 | function fb_MutexCreate FBCALL ( ) as FBMUTEX ptr 8 | dim as FBMUTEX ptr mutex = New FBMUTEX 9 | if ( mutex <> NULL ) then 10 | mutex->id = CreateSemaphore( NULL, 1, 1, NULL ) 11 | end if 12 | 13 | return mutex 14 | end function 15 | 16 | sub fb_MutexDestroy FBCALL ( mutex as FBMUTEX ptr ) 17 | if ( mutex <> NULL ) then 18 | CloseHandle( mutex->id ) 19 | Delete mutex 20 | end if 21 | end sub 22 | 23 | sub fb_MutexLock FBCALL ( mutex as FBMUTEX ptr ) 24 | if ( mutex <> NULL ) then 25 | WaitForSingleObject( mutex->id, INFINITE ) 26 | end if 27 | end sub 28 | 29 | sub fb_MutexUnlock FBCALL ( mutex as FBMUTEX ptr ) 30 | if ( mutex <> NULL ) then 31 | ReleaseSemaphore( mutex->id, 1, NULL ) 32 | end if 33 | end sub 34 | end extern -------------------------------------------------------------------------------- /win32/time_setdate.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "windows.bi" 3 | 4 | extern "C" 5 | function fb_hSetDate( y as long, m as long, d as long ) as long 6 | /' get current local time and date '/ 7 | dim as SYSTEMTIME st 8 | GetLocalTime( @st ) 9 | 10 | /' set time fields '/ 11 | st.wYear = y 12 | st.wMonth = m 13 | st.wDay = d 14 | 15 | /' set system time relative to local time zone '/ 16 | if ( SetLocalTime( @st ) = 0) then 17 | return -1 18 | end if 19 | 20 | /' send WM_TIMECHANGE to all top-level windows on NT and 95/98/Me 21 | * (_not_ on 2K/XP etc.) '/ 22 | /' if ((GetVersion() & 0xFF) == 4) 23 | SendMessage(HWND_BROADCAST, WM_TIMECHANGE, 0, 0); '/ 24 | 25 | return 0 26 | end function 27 | end extern -------------------------------------------------------------------------------- /win32/time_settime.bas: -------------------------------------------------------------------------------- 1 | #include "../fb.bi" 2 | #include "windows.bi" 3 | 4 | extern "C" 5 | function fb_hSetTime( h as long, m as long, s as long ) as long 6 | /' get current local time and date '/ 7 | dim as SYSTEMTIME st 8 | GetLocalTime( @st ) 9 | 10 | /' set time fields '/ 11 | st.wHour = h 12 | st.wMinute = m 13 | st.wSecond = s 14 | 15 | /' set system time relative to local time zone '/ 16 | if ( SetLocalTime( @st ) = 0 ) then 17 | return -1 18 | end if 19 | 20 | /' send WM_TIMECHANGE to all top-level windows on NT and 95/98/Me 21 | * (_not_ on 2K/XP etc.) '/ 22 | /'if ((GetVersion() & 0xFF) == 4) 23 | SendMessage(HWND_BROADCAST, WM_TIMECHANGE, 0, 0);'/ 24 | 25 | return 0 26 | end function 27 | end extern -------------------------------------------------------------------------------- /win32/time_timer.bas: -------------------------------------------------------------------------------- 1 | /' timer() function '/ 2 | 3 | #include "../fb.bi" 4 | #include "crt/time.bi" 5 | #include "windows.bi" 6 | 7 | #define TIMER_NONE 0 8 | #define TIMER_NORMAL 1 9 | #define TIMER_HIGHRES 2 10 | dim shared as long _timer = TIMER_NONE 11 | dim shared as double frequency 12 | 13 | extern "C" 14 | function fb_Timer FBCALL ( ) as double 15 | dim as LARGE_INTEGER count 16 | 17 | if ( _timer = TIMER_NONE ) then 18 | if ( QueryPerformanceFrequency( @count ) <> NULL ) then 19 | frequency = 1.0 / cast(double, count.QuadPart) 20 | _timer = TIMER_HIGHRES 21 | else 22 | _timer = TIMER_NORMAL 23 | end if 24 | end if 25 | 26 | if ( _timer = TIMER_NORMAL ) then 27 | return cast(double, GetTickCount( )) * 0.001 28 | else 29 | QueryPerformanceCounter( @count ) 30 | return cast(double, count.QuadPart) * frequency 31 | end if 32 | end function 33 | end extern -------------------------------------------------------------------------------- /win32/win32_private_thread.bi: -------------------------------------------------------------------------------- 1 | #include "windows.bi" 2 | type _FBMUTEX 3 | as HANDLE id 4 | end type 5 | 6 | type w9x_t 7 | as HANDLE event(0 to 1) 8 | end type 9 | 10 | type nt_t 11 | as HANDLE sema /' semaphore for waiters '/ 12 | as HANDLE waiters_done /' event '/ 13 | as Boolean was_broadcast 14 | end type 15 | 16 | Type _FBCOND 17 | /' data common to both implementations '/ 18 | as long waiters_count 19 | as CRITICAL_SECTION waiters_count_lock 20 | union 21 | as w9x_t w9x 22 | as nt_t nt 23 | end union 24 | end type --------------------------------------------------------------------------------