📄 port.c
字号:
path += strlen( path ); if (path[-1] != '/') { *path = '/'; path[1] = '\0'; } } return( rc );}/* * Name: set_current_directory * Purpose: set current directory * Date: November 13, 1993 * Passed: new_path: directory path, which may include drive letter * Notes: changes drive as well. */int set_current_directory( char *new_path ){register int rc; assert( new_path != NULL ); rc = OK; if (chdir( new_path ) == ERROR) rc = ERROR; return( rc );}/* * Name: get_full_path * Purpose: retrieve the fully-qualified path name for a file * Date: May 3, 1998 * Passed: in_path: path to be canonicalized * out_path: canonicalized path * Notes: out_path is assumed to be PATH_MAX characters. * * 980511: added test for non-existant file in LFN. * 990122: correct bug in above. * 020721: test for /dev/ paths. * 020727: rewrote the LFN part using _truename. * 021019: preserve a trailing slash. */void get_full_path( char *in_path, char *out_path ){int i;int rc = ERROR;char filename[NAME_MAX+1];int len, slash; len = strlen( in_path ) - 1; slash = (in_path[len] == '/' || in_path[len] == '\\'); /* * _fixpath doesn't seem to handle LFN too well; it converts all to lower- * case and doesn't expand the extended parent directories ("..." etc). */ if (_USE_LFN) { if (_truename( in_path, out_path ) != NULL) { if (file_exists( out_path ) == ERROR) { /* * _truename will successfully convert the path of a non-existant * file, but it's probably a mixture of long and short components. * Find the end of the path and convert it. */ for (i = strlen( out_path ) - 1; i > 1; --i) if (out_path[i] == '\\') break; if (i == 2) { /* * In the root directory - do nothing */ } else { strcpy( filename, out_path+i+1 ); out_path[i+1] = '\0'; _truename( out_path, out_path ); strcat( out_path, filename ); } } /* * Now I have to convert to lowercase and slashes myself. */ out_path[0] = bj_tolower( out_path[0] ); for (i = strlen( out_path ) - 1; i > 1; --i) if (out_path[i] == '\\') out_path[i] = '/'; rc = OK; } } if (rc == ERROR) _fixpath( in_path, out_path ); if (slash) { len = strlen( out_path ); if (out_path[len-1] != '/') { out_path[len++] = '/'; out_path[len] = '\0'; } }}/* * Name: get_ftime * Purpose: get the file's (modified) timestamp * Author: Jason Hood * Date: March 20, 2003 * Passed: fname: pointer to file's name * ftime: pointer to store the timestamp * Returns: OK if successful, ERROR if not (ftime unchanged). */int get_ftime( char *fname, ftime_t *ftime ){int handle;int rc = ERROR; handle = open( fname, O_RDONLY ); if (handle >= 0) { if (getftime( handle, (struct ftime*)ftime ) == 0) rc = OK; close( handle ); } return( rc );}/* * Name: set_ftime * Purpose: set the file's (modified) timestamp * Author: Jason Hood * Date: March 20, 2003 * Passed: fname: pointer to file's name * ftime: pointer to the timestamp * Returns: OK if successful, ERROR if not. */int set_ftime( char *fname, ftime_t *ftime ){int handle;int rc = ERROR; handle = open( fname, O_RDONLY ); if (handle >= 0) { if (setftime( handle, (struct ftime*)ftime ) == 0) rc = OK; close( handle ); } return( rc );}/* * Name: ftime_to_tm * Purpose: convert the file time to the tm structure * Author: Jason Hood * Date: March 20, 2003 * Passed: ftime: the file time to convert * Returns: pointer to the tm structure * Notes: only the date and time fields are set. */struct tm *ftime_to_tm( const ftime_t *ftime ){static struct tm t;struct ftime *ft; ft = (struct ftime*)ftime; t.tm_year = ft->ft_year + 80; /* tm is from 1900, ft is from 1980 */ t.tm_mon = ft->ft_month - 1; /* tm is from 0, ft is from 1 */ t.tm_mday = ft->ft_day; t.tm_hour = ft->ft_hour; t.tm_min = ft->ft_min; t.tm_sec = ft->ft_tsec * 2; /* file time halves the seconds */ return( &t );}/* * Name: test_clipboard * Purpose: determine if the clipboard is available * Author: Jason Hood * Date: November 29, 2003 * Returns: TRUE clipboard is available, FALSE if not */int test_clipboard( void ){__dpmi_regs regs; regs.x.ax = 0x1700; __dpmi_int( 0x2f, ®s ); no_clipboard = (regs.x.ax == 0x1700); return( !no_clipboard );}/* * Name: open_clipboard * Purpose: open the Windows clipboard * Author: Jason Hood * Date: August 27, 2002 * Returns: TRUE if opened, FALSE otherwise * Notes: expects test_clipboard to have been called first. */static int open_clipboard( void ){__dpmi_regs regs; if (no_clipboard) return( FALSE ); regs.x.ax = 0x1701; __dpmi_int( 0x2f, ®s ); return( regs.x.ax != 0 );}/* * Name: close_clipboard * Purpose: close the Windows clipboard * Author: Jason Hood * Date: August 27, 2002 */static void close_clipboard( void ){__dpmi_regs regs; regs.x.ax = 0x1708; __dpmi_int( 0x2f, ®s );}/* * Name: set_clipboard * Purpose: put text onto the Windows clipboard * Author: Jason Hood * Date: August 27, 2002 * Passed: text: the text to place * size: the length of the text (including NUL) * Returns: OK if successfully placed, ERROR otherwise */int set_clipboard( char *text, int size ){int seg, sel;__dpmi_regs regs;int rc = ERROR; if (open_clipboard( )) { seg = __dpmi_allocate_dos_memory( (size + 15) >> 4, &sel ); if (seg != -1) { dosmemput( text, size, seg << 4 ); regs.x.ax = 0x1702; /* empty clipboard */ __dpmi_int( 0x2f, ®s ); regs.x.ax = 0x1703; /* place data on clipboard */ regs.x.dx = 7; /* OEM text */ regs.x.es = seg; /* ES:BX pointer to data */ regs.x.bx = 0; regs.x.si = (unsigned)size >> 16; /* SI:CX size of data */ regs.x.cx = size & 0xffff; __dpmi_int( 0x2f, ®s ); if (regs.x.ax != 0) rc = OK; __dpmi_free_dos_memory( sel ); } close_clipboard( ); } return( rc );}/* * Name: get_clipboard * Purpose: get text from the Windows clipboard * Author: Jason Hood * Date: August 26, 2002 * Returns: pointer to the text or NULL if none/error * Notes: the caller should free the returned pointer */char *get_clipboard( void ){int seg, sel;int size;__dpmi_regs regs;char *text = NULL; if (open_clipboard( )) { regs.x.ax = 0x1704; /* clipboard size in DX:AX */ regs.x.dx = 7; /* OEM text */ __dpmi_int( 0x2f, ®s ); size = (regs.x.dx << 16) + regs.x.ax; if (size) { seg = __dpmi_allocate_dos_memory( (size + 15) >> 4, &sel ); if (seg != -1) { regs.x.ax = 0x1705; /* get data from clipboard */ regs.x.dx = 7; /* OEM Text */ regs.x.es = seg; /* ES:BX pointer to buffer */ regs.x.bx = 0; __dpmi_int( 0x2f, ®s ); if (regs.x.ax != 0) { text = malloc( size ); if (text != NULL) dosmemget( seg << 4, size, text ); } __dpmi_free_dos_memory( sel ); } } close_clipboard( ); } return( text );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -