⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mes.c

📁 一个通用的隐性马尔可夫C代码库 开发环境:C语言 简要说明:这是一个通用的隐性马尔可夫C代码库
💻 C
📖 第 1 页 / 共 2 页
字号:
  free( txt );} /* mes_printf *//*============================================================================*/void mes_fformat( char* txt, char* logfile, int line, char* proc_info ) {   mes_time();  if( proc_info && strlen( proc_info ) ) {    mes_smart( MES_FLAG_FILE, proc_info, -1 );    mes_file( ":" );  }  mes_file_win( "format error" );  if( logfile && strlen( logfile )) {    mes_file_win( " in file " );    mes_file_win( logfile );  }   if( line >= 0 ) mes_aux( MES_FLAG_FILE_WIN, ": line %d", line );  if( logfile && strlen(txt) ) {    mes_file_win( " (" );    mes_file_win( txt );    mes_file_win( ")\n" );  }  else mes_file_win( "\n" );} /* mes_fformat *//*============================================================================*/void mes_err( char* txt, int error_nr, char* proc_info ) {   mes_time();  if( proc_info && strlen( proc_info ) ) {	 mes_file_win( proc_info );    mes_file_win( ":" );  }   if( error_nr >=0 && error_nr < sizeof(mes_err_txt) / sizeof(*mes_err_txt) ) {    mes_file_win( mes_err_txt[error_nr] );  }  if( txt ) {    mes_file_win( " (" );    mes_file_win( txt );    mes_file_win( ")\n" );  }  else mes_file_win( "\n" );} /* mes_err *//*============================================================================*/void mes_proc_start( char* proc_info ) {   mes_t *mpc = mes_process_get();  int i;    mes_time();  if( proc_info ) {    mes_file( proc_info );    mes_file( ":" );  }   mes_file( " ***** PROGRAM STARTED *****\n" );  if( mpc )  for( i = 0; i < mpc->argc; i++ ) {    if( !i ) mes_file( "program call name is : " );    else     mes_aux( MES_FLAG_FILE, "parameter %10d : ", i );    mes_file( mpc->argv[i] );    mes_file( "\n" );  } } /* mes_proc_start *//*============================================================================*/int mes_insert( FILE* fp, char src, int cnt ) {  int i = cnt;    if( fp && fp - stdout ) for( i = 0; i < cnt && !mes_fputc( fp, src ); i++ );  else for( i = 0; i < cnt; i++ ) mes_smart( MES_FLAG_WIN,&src,1);  if( i == cnt ) return(0);  return(-1);  } /* mes_insert *//******************************************************************************//******************************************************************************//*============================================================================*/void* mes_malloc( int bytes ) {   void* res;    if( bytes <= 0 ) bytes = 1;  res = malloc( bytes );  if( res ) return( res );   else mes_aux(MES_FLAG_TIME_WIN, "malloc: could not allocate %d bytes\n", bytes);  return( NULL );  } /* mes_malloc *//*============================================================================*/void* mes_calloc( int bytes ) {   void* res;    if( bytes <= 0 ) bytes = 1;  res = calloc( 1, bytes );  if( res ) return( res );   else mes_aux( MES_FLAG_TIME_WIN, "calloc: could not allocate %d bytes\n", bytes );  return( NULL );  } /* mes_calloc *//*============================================================================*/int mes_realloc( void** mem, int bytes ) {   void* res;    if( bytes <= 0 ) bytes = 1;  if( !mem ) return(-1);   if( !*mem ) res = malloc( bytes );  else res = realloc( *mem, bytes );  if( res ) { *mem = res; return(0); }  else mes_aux( MES_FLAG_TIME_WIN, 		"realloc: could not reallocate %d bytes\n", bytes );  return(-1);  } /* mes_realloc *//*============================================================================*/FILE* mes_fopen(const char* filename, char*attrstr ) {   FILE* fp;    if( mes_filename_check(filename) ) goto STOP;   if( !attrstr ) goto STOP;  if( !strcmp( filename, "stdout" ) ) {    return(stdout);      }  fp = fopen( filename, attrstr );  if( fp ) {    if( !strchr(attrstr, 'b') && !strchr( attrstr, 't' ) ) {      mes_file_win( "fopen: file \"" );      mes_file_win( filename );      mes_file_win( "\" opened with ambiguous attributes \"" );      mes_file_win( attrstr );      mes_file_win( "\"\n" );    }    return( fp );   }STOP:  mes_time();  mes_file_win( "fopen: could not open file \"" );  mes_file_win( filename );  mes_file_win( "\" with attribute \"" );  mes_file_win( attrstr );  mes_file_win( "\"\n" );  return(NULL);  } /* mes_fopen *//*============================================================================*/int mes_fread_quiet( FILE* fp, void* mem, int bytes ) {   if( !bytes ) return(0);   if( mem && fp ) return( fread( mem, 1, bytes, fp ) );  else mes_aux( MES_FLAG_TIME_WIN, 		"fread: could not read %d bytes from FILE(%p) to mem(%p)\n", 		bytes, fp, mem );  return(-1);  } /* mes_fread_quiet *//*============================================================================*/int mes_fread( FILE* fp, void* mem, int bytes ) {   if( !bytes ) return(0);   if( mem && fp && fread( mem, 1, bytes, fp ) == (unsigned int)bytes ) return(0);     else mes_aux( MES_FLAG_TIME_WIN, 		"fread: could not read %d bytes from FILE(%p) to mem(%p)\n", 		bytes, fp, mem );  return(-1);  } /* mes_fread *//*============================================================================*/int mes_fwrite( FILE* fp, void* mem, int bytes ) {   if( !fp || !mem  ) bytes = -1;  else if( bytes < 0 ) bytes = strlen(mem);  if( !bytes ) return(0);  if( bytes > 0 && fwrite(mem, 1, bytes, fp) == (unsigned int)bytes ) return(0);   else mes_aux( MES_FLAG_TIME_WIN, 		"fwrite: could not write %d bytes from mem(%p) to FILE(%p)\n", 		bytes, mem, fp );  return(-1);  } /* mes_fwrite *//*============================================================================*/int mes_fputc( FILE* fp, char chr ) {   if( fp && fputc( chr, fp ) != EOF ) return(0);     else mes_aux( MES_FLAG_TIME_WIN, 		"fputc: could not write byte %X to FILE(%p)\n", 		(int)chr&0xFF, fp );  return(-1);  } /* mes_fputc *//*============================================================================*/int mes_fputs( FILE* fp, char* str ) {   if( fp && str && fputs( str, fp ) != EOF ) return(0);    if( str ) mes_aux(MES_FLAG_TIME_WIN, "fputs: could not write string %s\n", str);  else      mes_aux(MES_FLAG_TIME_WIN, "fputs: could not write 0 pointer\n");    return(-1);  } /* mes_fputs *//*============================================================================*/int mes_fgetc( FILE* fp ) {   int res = fp ? fgetc( fp ) : EOF;  if( res != EOF ) return(res);   else mes_aux( MES_FLAG_TIME_WIN, "fgetc: end of FILE(%p)\n", fp );  return(res);  } /* mes_fgetc *//*============================================================================*/int mes_fflush( FILE* fp ) {   int res = fp ? fflush( fp ) : -1;    if( !res ) return(0);   else mes_aux( MES_FLAG_TIME_WIN, "fflush: could not flush FILE(%p)\n", fp );  return(res);  } /* mes_fflush *//*============================================================================*/int mes_fprintf( FILE* fp, char* format, ... ) {  va_list args;  char*   txt;    if( !format ) return(0);   va_start( args, format );  txt = mprintf_va( NULL, 0, format, args );  if( !txt ) {    mes_time();    mes_file_win( "sprintf_va: call with format string\"" );    mes_file_win( format );    mes_file_win( "\" without success\n" );    return(-1);      }    if( fp && fp - stdout ) mes_fputs( fp, txt );  else mes_win( txt );  free( txt );  return(1);  } /* mes_fprintf *//*============================================================================*/int mes_fseek( FILE* fp, long offset, int fromwhere ) {   int res = fp ? fseek( fp, offset, fromwhere ) : -1;    if( !res ) return(0);   mes_aux( MES_FLAG_TIME_WIN, "fseek: could not position FILE(%p) at %ld", 	   fp, offset );  switch( fromwhere ) {  case SEEK_SET : mes_aux( MES_FLAG_FILE_WIN, "\n" ); break;   case SEEK_END : mes_aux( MES_FLAG_FILE_WIN, " from the end\n" ); break;   case SEEK_CUR : mes_aux( MES_FLAG_FILE_WIN, " from current position\n" ); break;  default : mes_aux(MES_FLAG_FILE_WIN, " with undefinded offset %d\n", fromwhere);    break;  }  return(res);  } /* mes_fseek *//*============================================================================*/#ifdef WIN32int mes_fseek64( FILE *fp, unsigned int uoff, unsigned int loff, int fromwhere ) {/* lower 32bit in lpos, upper 32bit in upos */  int     fh; /* file handle */  __int64 pos64;  __int64 off64;  if( !fp ) return(0);    fh = _fileno( fp );  off64 = (((__int64)uoff)<<32)+(__int64)loff;  pos64 = _lseeki64( fh, off64, fromwhere );  if( pos64 == -1L ) {    mes_file_win( "_lseeki64 failed:" );    mes_file_win( strerror(errno) );    return(0);  }  return(1);}/*============================================================================*/int mes_ftell64( int fh, unsigned int *upos, unsigned int *lpos ) {  /* lower 32bit in *lpos, upper 32bit in *upos */  __int64 pos64;  if( fh<0 ) return(0);    pos64 = _lseeki64( fh, 0, SEEK_CUR );  if( pos64 == -1L ) {    mes_file_win( "_lseeki64 failed:" );    mes_file_win( strerror(errno) );    return(0);  }  *upos = (unsigned int)(pos64>>32);  *lpos = (unsigned int)pos64;  return(1);}#endif /* WIN32 *//*============================================================================*/int mes_ftell( FILE* fp ) {   int res = fp ? ftell( fp ) : -1;  if( res != -1 ) return( res );  else mes_aux( MES_FLAG_TIME_WIN, 		"ftell: could not find current position of FILE(%p)\n", 		fp );  return(res);} /* mes_ftell *//*============================================================================*/int mes_remove( char* filename ) {#define CUR_PROC "mes_remove"  int res = -1;    if( mes_filename_check(filename) ) goto STOP;   res = remove( filename );  if( !res ) return(0);STOP:  mes_time();  mes_file_win( "remove: could not remove file \"" );  mes_file_win( filename );  mes_file_win( "\";");  if( res != -1 ) mes_file_win( strerror(errno) );  mes_file_win( "\n" );  return(res);#undef CUR_PROC} /* mes_remove *//*============================================================================*/int mes_rename( char* oldname, char* newname ) {#define CUR_PROC "mes_rename"  int res = -1;    if( mes_filename_check(oldname) ) goto STOP;   if( mes_filename_check(newname) ) goto STOP; #if defined(_PPC_) || defined(WIN32)  if ( strcmp( oldname, newname ) ) {    FILE *fp;    fp = fopen( newname, "rb");    if (fp) {      fclose( fp );      mes_remove( newname );    }  }  else return(0);#endif  res = rename( oldname, newname );  if( !res ) return(res);STOP:    mes_time();    mes_file_win( "rename: could not rename \"" );    mes_file_win( oldname );    mes_file_win( "\" -> \"" );    mes_file_win( newname );    mes_file_win( "\"; ");    if( res != -1 ) mes_file_win( strerror(errno) );    mes_file_win( "\n" );  return(res);#undef CUR_PROC} /* mes_rename *//*============================================================================*/int mes_move( char* oldname, char* newname ) {#define CUR_PROC "mes_move"  int res = -1;  int tmp;    if( mes_filename_check( oldname ) ) goto STOP;  if( mes_filename_check( newname ) ) goto STOP;  if( !strcmp( oldname, newname ) ) goto STOP;    /* first try to rename */  tmp = mes_ability(0);  if( !mes_rename( oldname, newname ) ) {     res = 0;    mes_ability( tmp );    goto STOP;  }  mes_ability( tmp );  /* need to copy */  if( mes_copy( oldname, newname ) ) goto STOP;  mes_remove( oldname );    res = 0; STOP:  if( res<0 ) {    mes_time();    mes_file_win( "move: could not move " );    mes_file_win( oldname );    mes_file_win( " -> " );    mes_file_win( newname );    mes_file_win( "\n" );  }  return(res);#undef CUR_PROC} /* mes_move *//*============================================================================*/int mes_copy( char *oldname, char *newname) {#define CUR_PROC "mes_copy"  int   res = -1;  FILE* dst = NULL;  FILE* src = NULL;  char* buf = NULL;  if( (dst = mes_fopen( newname, "wb" )) == NULL) goto STOP;  if( (src = mes_fopen( oldname, "rb" )) == NULL) goto STOP;  if( (buf = mes_malloc( 0x10000*sizeof(char) )) == NULL ) goto STOP;  while (!feof(src)) {    int cnt = fread( buf, 1, 0x10000, src );    if( cnt<=0 ) break;    if( fwrite( buf, 1, cnt, dst ) <= 0 ) goto STOP;  }  res = 0; STOP:  if( buf ) free( buf );  if( src ) fclose( src );  if( dst ) fclose( dst );  return(res);# undef CUR_PROC}/* mes_copy *//*============================================================================*/FILE* mes_tmpfopen( char* path ) { # define CUR_PROC "mes_tmpfopen"  FILE* fp;  char  name[16];  char  tmpname[L_tmpnam+16];  int   i;    if( path ) strncpy( tmpname, path, L_tmpnam );  else       tmpname[0] = 0;    for( i = 0; i < 0x10000; i++ ) {    sprintf( name, "%80X.TMP", rand() );    strcat( tmpname, name );    fp = fopen( tmpname, "rb" );    if( fp ) { fclose(fp); continue; }    fp = fopen( tmpname, "w+b" );    if( fp ) return( fp );    break;  }  mes_time();    mes_file_win( "tmpfopen: no success\n" );  return(NULL);# undef CUR_PROC} /* mes_tmpfopen *//*============================================================================*/int mes_tmpfclose( FILE** fp ) {   if( !fp ) return(0);   if( !*fp ) return(0);  fclose( *fp );  (*fp) = 0;  return(0);} /* mes_tmpfclose *//*============================================================================*/FILE* mes_tmpfile(void) { # define CUR_PROC "mes_tmpfile"  FILE* fp = tmpfile();  if( fp ) return(fp);   else {    mes_time();    mes_file_win( "tmpfile: no success\n" );  }   return(NULL);    # undef CUR_PROC} /* mes_tmpfile */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -