eb.c

来自「NIST Handwriting OCR Testbed」· C语言 代码 · 共 79 行

C
79
字号
/* Routines for using a (hidden) error buffer, which holds a sequenceof error messages (or they could be any strings).Contains:# proc: eb_cat - cats a (hidden) error buffer, which holds a sequence# proc:          of error messages# proc: eb_get - gets a (hidden) error buffer, which holds a sequence# proc:          of error messages# proc: eb_clr - clears a (hidden) error buffer, which holds a sequence# proc:          of error messages*/#include <stdio.h>#include <stdlib.h>#include <mlp/defs.h>/* How many extra bytes to allocate -- beyond the amount that is goingto be just barely sufficient -- at the initial malloc and at eachrealloc: */#define NBYTES_EXTRA 500static char *errbuf;static int nbytes_used;/********************************************************************//* Catenates a string onto the error buffer, after checking whetherbuffer is going to be large enough and if not, enlarging it. */voideb_cat(str)char str[];{  static char first = TRUE;  static int nbytes_allocated;  if(first) {    first = FALSE;    nbytes_used = strlen(str) + 1;    nbytes_allocated = nbytes_used + NBYTES_EXTRA;    if((errbuf = malloc(nbytes_allocated)) == (char *)NULL)      syserr("eb_cat (eb.c)", "malloc", "errbuf");    strcpy(errbuf, str);  }  else {    nbytes_used += strlen(str);    if(nbytes_used > nbytes_allocated) {      nbytes_allocated = nbytes_used + NBYTES_EXTRA;      if((errbuf = realloc(errbuf, nbytes_allocated)) == (char *)NULL)	syserr("eb_cat (eb.c)", "realloc", "errbuf");    }    strcat(errbuf, str);  }}/********************************************************************//* Returns the error buffer. */char *eb_get(){  return errbuf;}/********************************************************************//* Clears the error buffer, in effect, so that it can be filled with anew sequence of strings.  (Does not free the buffer.) */voideb_clr(){  *errbuf = (char)NULL;  nbytes_used = 1;}  /********************************************************************/

⌨️ 快捷键说明

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