📄 utils.c
字号:
/****************************************************************/
/* COPYRIGHT NOTICE */
/* ---------------- */
/* All software in this listing remain the strict copyright */
/* of Ilija Kovacevic and cannot be copied or used in any way */
/* except by written permission of Ilija Kovacevic. */
/* */
/* Copyright (c) 1992 Ilija Kovacevic */
/* www.kov.com email ilija@kov.com */
/****************************************************************/
#include <ctype.h>
#include <errno.h>
#include <dwgin.h>
PUBLIC void warn_perror( char *fmt,... )
{
va_list ap;
char error_message[ 256 ];
va_start( ap,fmt );
vsprintf( error_message, fmt, ap );
va_end( ap );
warning( "%s",error_message );
}
PUBLIC void set_extension( char *name,char *extension )
{
for ( ; *name; ++name )
{
if ( *name EQ '.' ) break;
}
*name++ = '.';
*name = NULL;
strcpy( name,extension );
}
#ifdef UNIX
PUBLIC long filelength( int file )
{
struct stat status;
fstat( file,&status );
return( status.st_size );
}
PUBLIC int strcmpi( char *string1,char *string2 )
{
return( strcmp( string1,string2 ) );
}
PUBLIC char *strupr( char *string )
{
char *p;
for ( p = string; *p; ++p ) *p = toupper( *p );
return( string );
}
PUBLIC char *strlwr( char *string )
{
char *p;
for ( p = string; *p; ++p ) *p = tolower( *p );
return( string );
}
#endif
PUBLIC void convert_string_to_lower_case( char *string )
{
char *p;
for ( p = string; *p; ++p ) *p = tolower( *p );
}
PUBLIC DOUBLE rad_to_degrees( DOUBLE angle )
{
return( angle * 180.0/PI );
}
void dprintf( char *fmt, ... )
{
static FILE *output;
static int first_time = true;
char status[ 256 ];
va_list ap;
va_start( ap,fmt );
vsprintf( status,fmt,ap );
va_end( ap );
if ( first_time )
{
first_time = false;
output = fopen( "debug","w" );
}
else output = fopen( "debug","a" );
fprintf( output,status );
fclose( output );
}
PUBLIC void fatal_error( char *fmt,... )
{
va_list ap;
char message[ 256 ];
char buffer[ 80 ];
va_start( ap,fmt );
vsprintf( message, fmt, ap );
va_end( ap );
sprintf( buffer,"Fatal error : %s",message );
warning( buffer );
terminate( 1 );
}
PUBLIC char *get_memory( int size )
{
char *memory;
memory = ( char * )calloc( size,1 );
if ( !memory ) read_error( "Out of memory" );
return( memory );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -