home *** CD-ROM | disk | FTP | other *** search
-
- /* p4misc.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved. */
-
- #include "p4misc.h"
- #include "d4all.h"
-
- #include <stdio.h>
- #include <string.h>
-
- #ifdef DO_CHSIZE
- #include <dos.h>
- #include <io.h>
- #endif
-
-
- #ifdef NO_FILELENGTH
- #include <sys/types.h>
- #include <sys/stat.h>
-
- long filelength( int hand )
- {
- struct stat str_stat ;
-
- fstat( hand, &str_stat ) ;
-
- return( (long) str_stat.st_size ) ;
- }
- #endif
-
-
- #ifdef NO_MEMMOVE
- void *memmove( void *dest, void *src, size_t count )
- {
- if ( dest < src )
- if ( (char *)dest + count <= (char *) src )
- {
- memcpy( dest, src, count ) ;
- return( src ) ;
- }
- else
- {
- /* Start at beginning of 'src' */
- int i ;
- for ( i=0; i< count; i++ )
- ((char *) dest)[i] = ((char *)src)[i] ;
- }
-
- if ( src < dest )
- if ( (char *) src + count <= (char *) dest )
- {
- memcpy( dest, src, count ) ;
- return( src ) ;
- }
- else
- {
- /* Start at end of 'src' */
- for(;count!=0;)
- {
- --count ;
- ((char *)dest)[count] = ((char *) src)[count] ;
- }
- }
-
- return( src ) ;
- }
- #endif
-
- #ifdef LANGUAGE
- #define NO_STRUPR
- #define NO_STRLWR
- #endif
-
- char * u4upper( char *str )
- {
- #ifdef NO_STRUPR
- char *ptr ;
-
- ptr = str ;
-
- while ( *ptr != '\000' )
- {
- if ( *ptr >= 'a' && *ptr <= 'z' )
- *ptr &= 0337 ;
- #ifdef GERMAN
- if ( *ptr >= '\201' )
- {
- switch( *ptr )
- {
- case '\204':
- *ptr = '\214' ;
- break ;
- case '\224':
- *ptr = '\231' ;
- break ;
- case (char) '\201':
- *ptr = '\232' ;
- break ;
- }
- }
- #endif
- ptr++ ;
- }
-
- return( str ) ;
- #else
- return strupr( str ) ;
- #endif
- }
-
- char *u4lower( char *str )
- {
- #ifdef NO_STRLWR
- char *ptr ;
-
- ptr = str ;
-
- while ( *ptr != '\000' )
- {
- if ( *ptr >= 'A' && *ptr <= 'Z' )
- *ptr |= 040 ;
- #ifdef GERMAN
- if ( *ptr >= '\201' )
- {
- switch( *ptr )
- {
- case '\214':
- *ptr = '\204' ;
- break ;
- case '\231':
- *ptr = '\224' ;
- break ;
- case '\232':
- *ptr = '\201' ;
- break ;
- }
- }
- #endif
- ptr++ ;
- }
-
- return( str ) ;
- #else
- return strlwr( str ) ;
- #endif
- }
-
- int u4toupper( int i_chr )
- {
- char str[2] ;
- if ( i_chr >= 256 ) return i_chr ;
- str[0] = (char) i_chr ;
- str[1] = 0 ;
- u4upper( str ) ;
- return (int) str[0] ;
- }
-
- int u4tolower( int i_chr )
- {
- char str[2] ;
- if ( i_chr >= 256 ) return i_chr ;
- str[0] = (char) i_chr ;
- str[1] = 0 ;
- u4lower( str ) ;
- return (int) str[0] ;
- }
-
- int u4remove( char *path )
- {
- #ifdef NO_REMOVE
- char buf[80] ;
- memset( buf, 0, sizeof(buf) ) ;
- strncpy( buf, path, sizeof(buf)-1 ) ;
- u4lower( buf ) ;
- return( unlink( buf ) ) ;
- #else
- #ifdef UNIX
- char buf[80] ;
- memset( buf, 0, sizeof(buf) ) ;
- strncpy( buf, path, sizeof(buf)-1 ) ;
- u4lower( buf ) ;
- return( remove( buf ) ) ;
- #else
- return remove( path ) ;
- #endif
- #endif
- }
-
-
- #ifdef NO_STRNICMP
- strnicmp( char *a, char *b, size_t n )
- {
- unsigned char a_char, b_char ;
-
- for ( ; *a != '\000' && *b != '\000' && n != 0; a++, b++, n-- )
- {
- a_char = (unsigned char) *a & 0xDF ;
- b_char = (unsigned char) *b & 0xDF ;
-
- if ( a_char < b_char ) return -1 ;
- if ( a_char > b_char ) return 1 ;
- }
-
- return 0 ;
- }
- #endif
-
-
- #ifdef DO_CHSIZE
- #ifdef OS2
- int chsize( int h, long sz )
- {
- extern unsigned far pascal DOSNEWSIZE( unsigned, unsigned long ) ;
-
- if ( DOSNEWSIZE( h, (unsigned long) sz) != 0 ) return -1 ;
- return 0 ;
- }
- #else
- #ifdef IS_386
- int chsize( int h, long sz )
- {
- union REGS in_regs, out_regs ;
- long lrc ;
-
- lrc = lseek( h, sz, 0 ) ;
- if ( lrc != sz ) return -1 ;
-
- in_regs.h.ah = 0x40 ;
- in_regs.x.ebx = h ;
- in_regs.x.ecx = 0 ;
- int386( 0x21, &in_regs, &out_regs ) ;
- if ( out_regs.w.ax == 0 )
- return 0 ;
- else
- return -1 ;
- }
- #else
- int chsize( int h, long sz )
- {
- union REGS in_regs, out_regs ;
- long lrc ;
-
- lrc = lseek( h, sz, 0 ) ;
- if ( lrc != sz ) return -1 ;
-
- in_regs.h.ah = 0x40 ;
- in_regs.x.bx = h ;
- in_regs.x.cx = 0 ;
- int86( 0x21, &in_regs, &out_regs ) ;
- if ( out_regs.x.ax == 0 )
- return 0 ;
- else
- return -1 ;
- }
- #endif
- #endif
- #endif
-
- #ifdef LANGUAGE
- /* This mapping is for German. */
- int v4map[256] =
- {
- /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 */
- 137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,
-
- /* 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 */
- 153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,
-
- /* 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47 */
- 0,114,129,120,121,106,119,131, 95, 96,107,104,109,105,108,115,
-
- /* 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 */
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,111,110,101,103,102,113,
-
- /* 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 */
- 118, 11, 14, 15, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30,
-
- /* 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 */
- 32, 33, 34, 35, 36, 37, 39, 40, 41, 42, 43, 97,116, 98,132,134,
-
- /* 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111 */
- 130, 44, 50, 51, 53, 54, 59, 60, 61, 62, 67, 68, 69, 70, 71, 74,
-
- /* 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127 */
- 78, 79, 80, 82, 83, 85, 89, 90, 91, 92, 94, 99,117,100,133,169,
-
- /* 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143 */
- 16, 84, 55, 48, 45, 47, 49, 52, 57, 58, 56, 66, 65, 64, 12, 13,
-
- /* 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159 */
- 19,127,128, 77, 73, 76, 88, 87, 93, 31, 38,122,123,124,126,125,
-
- /* 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175 */
- 46, 63, 75, 86, 72, 29,135,136,112,170,171,172,173,174,175,176,
-
- /* 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191 */
- 177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,
-
- /* 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207 */
- 193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,
-
- /* 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223 */
- 209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,
-
- /* 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239 */
- 225, 81,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
-
- /* 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 */
- 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
- } ;
-
- int u4memcmp( unsigned char *a, unsigned char *b, size_t len )
- {
- int i ;
-
- for (i=0; i<len; i++)
- if ( a[i] != b[i] )
- {
- if ( v4map[a[i]] < v4map[b[i]] ) return -1 ;
- return 1 ;
- }
- return 0 ;
- }
- #endif
-