コード例 #1
0
ファイル: gmx_fatal.c プロジェクト: aar2163/GROMACS
static void bputs(char *msg,int *len,const char *s,int fld)
{
  for (fld-=(int)strlen(s); fld>0; fld--) 
    bputc(msg,len,' ');
  while (*s) 
    bputc(msg,len,*(s++));
}
コード例 #2
0
ファイル: bprintdbl.c プロジェクト: Logout22/Escape
int bprintdbl(FILE *f,double d,uint precision) {
	int c = 0;
	llong val = 0;

	/* Note: this is probably not a really good way of converting IEEE754-floating point numbers
	 * to string. But its simple and should be enough for my purposes :) */

	if(isnan(d)) {
		if(d < 0)
			c += RETERR(bputc(f,'-'));
		c += RETERR(bputs(f,"nan",-1));
	}
	else if(isinf(d)) {
		if(d < 0)
			c += RETERR(bputc(f,'-'));
		c += RETERR(bputs(f,"inf",-1));
	}
	else {
		val = (llong)d;
		c += bprintl(f,val);
		d -= val;
		if(d < 0)
			d = -d;
		RETERR(bputc(f,'.'));
		c++;
		while(precision-- > 0) {
			d *= 10;
			val = (llong)d;
			RETERR(bputc(f,(val % 10) + '0'));
			d -= val;
			c++;
		}
	}
	return c;
}
コード例 #3
0
ファイル: bputs.c プロジェクト: Logout22/Escape
int bputs(FILE *f,const char *str,int precision) {
	char c;
	const char *begin = str;
	if(precision != -1) {
		while((c = *str++) && precision-- > 0)
			RETERR(bputc(f,c));
	}
	else {
		while((c = *str++))
			RETERR(bputc(f,c));
	}
	return str - begin - 1;
}
コード例 #4
0
ファイル: bprintul.c プロジェクト: Logout22/Escape
int bprintul(FILE *f,ullong u,uint base,const char *hexchars) {
	int c = 0;
	if(u >= base)
		c += RETERR(bprintul(f,u / base,base,hexchars));
	RETERR(bputc(f,hexchars[(u % base)]));
	return c + 1;
}
コード例 #5
0
ファイル: gmx_fatal.c プロジェクト: aar2163/GROMACS
static void bputi(char *msg,int *len,int val,int radix,int fld,bool bNeg)
{
  int fmax=0;
  
  if (bNeg)
    fmax=1;
    
  if (val<radix)
    {
      for (fld--; fld>fmax; fld--) 
	bputc(msg,len,' ');
      if (bNeg)
	bputc(msg,len,'-');
      bputd(msg,len,val);
    }
  else
    {
      if (bNeg)
	bputc(msg,len,'-');
      bputi(msg,len,val/radix,radix,fld-1,FALSE);
      bputd(msg,len,val%radix);
    }
}
コード例 #6
0
ファイル: bprintdblpad.c プロジェクト: Logout22/Escape
int bprintdblpad(FILE *f,double d,uint pad,uint flags,uint precision) {
	int count = 0;
	llong pre = (llong)d;
	bool nan = isnan(d);
	bool inf = isinf(d);
	/* pad left */
	if(!(flags & FFL_PADRIGHT) && pad > 0) {
		size_t width;
		if(nan || inf)
			width = (d < 0 || (flags & (FFL_FORCESIGN | FFL_SPACESIGN))) ? 4 : 3;
		else
			width = getllwidth(pre) + precision + 1;
		if(pre > 0 && (flags & (FFL_FORCESIGN | FFL_SPACESIGN)))
			width++;
		if(pad > width)
			count += RETERR(bprintpad(f,pad - width,flags));
	}
	/* print '+' or ' ' instead of '-' */
	PRINT_SIGNED_PREFIX(count,f,pre,flags);
	/* print number */
	if(nan) {
		if(d < 0)
			count += RETERR(bputc(f,'-'));
		count += RETERR(bputs(f,"nan",-1));
	}
	else if(inf) {
		if(d < 0)
			count += RETERR(bputc(f,'-'));
		count += RETERR(bputs(f,"inf",-1));
	}
	else
		count += RETERR(bprintdbl(f,d,precision));
	/* pad right */
	if((flags & FFL_PADRIGHT) && (int)pad > count)
		count += RETERR(bprintpad(f,pad - count,flags));
	return count;
}
コード例 #7
0
ファイル: statevar.c プロジェクト: ricksladkey/vile
int
var_CHAR(TBUFF **rp, const char *vp)
{
    int status = FALSE;

    if (rp) {
	if (valid_buffer(curbp) && !is_empty_buf(curbp)) {
	    render_int(rp, CharAtDot());
	} else {
	    tb_scopy(rp, error_val);
	}
	status = TRUE;
    } else if (vp) {
	if ((status = check_editable(curbp)) == TRUE) {
	    int c;
	    mayneedundo();
	    (void) ldel_chars(1L, FALSE);	/* delete 1 char */
	    c = scan_int(vp);
	    if ((status = bputc(c)) == TRUE)
		(void) backchar(FALSE, 1);
	}
    }
    return status;
}
コード例 #8
0
ファイル: msgs.c プロジェクト: ricksladkey/vile
/*
 * This is invoked as a wrapper for 'kbd_putc()'.  It writes to the Messages
 * scratch buffer, and also to the message line.  If the Messages buffer isn't
 * visible, it is automatically popped up when a new message line is begun.
 * Since it's a scratch buffer, popping it down destroys it.
 */
int
msg_putc(int c)
{
    BUFFER *savebp = curbp;
    WINDOW *savewp = curwp;
    MARK savemk;
    int saverow = ttrow;
    int savecol = ttcol;
    register BUFFER *bp;
    register WINDOW *wp;

    if ((bp = create_msgs()) == 0)
	return TRUE;

    savemk = DOT;
    beginDisplay();
    /*
     * Modify the current-buffer state as unobtrusively as possible (i.e.,
     * don't modify the buffer order, and don't make the buffer visible if
     * it isn't already!).  To use the 'bputc()' logic, though, we've got
     * to have a window, even if it's not real.
     */
    curbp = bp;
    if ((wp = bp2any_wp(bp)) == NULL) {
	static WINDOW dummy;
	wp = &dummy;
	wp->w_bufp = bp;
    }
    curwp = wp;
    DOT.l = lback(buf_head(bp));
    DOT.o = llength(DOT.l);

    /*
     * Write into the [Messages]-buffer
     */
#if OPT_TRACE
    if (c == '\n') {
	static TBUFF *ss;
	int len = (DOT.o > 0) ? DOT.o : 1;
	if (tb_init(&ss, EOS) != 0
	    && tb_bappend(&ss,
			  (DOT.o > 0) ? lvalue(DOT.l) : "?",
			  (size_t) len) != 0
	    && tb_append(&ss, EOS) != 0) {
	    TRACE(("msg:%s\n",
		   visible_buff(tb_values(ss),
				(int) tb_length(ss) - 1, TRUE)));
	}
    }
#endif
    if ((c != '\n') || (DOT.o > 0)) {
	bputc(c);
	b_clr_changed(bp);
    }

    /* Finally, restore the original current-buffer and write the character
     * to the message line.
     */
    curbp = savebp;
    curwp = savewp;
    if (savewp)
	DOT = savemk;
    movecursor(saverow, savecol);
    if (c != '\n') {
	if (sgarbf) {
	    mlsavec(c);
	} else {
	    kbd_putc(c);
	}
    }
    endofDisplay();

    return TRUE;
}
コード例 #9
0
ファイル: fputc.c プロジェクト: Nils-TUD/Escape
int fputc(int c,FILE *file) {
	return bputc(file,c);
}
コード例 #10
0
ファイル: gmx_fatal.c プロジェクト: aar2163/GROMACS
void gmx_fatal(int f_errno,const char *file,int line,const char *fmt,...)
{
  va_list ap;
  const char    *p;
  char    cval,*sval,msg[STRLEN];
  char    ibuf[64],ifmt[64];
  int     index,ival,fld,len;
  double  dval;
#ifdef _SPECIAL_VAR_ARG
  int     f_errno,line;
  char    *fmt,*file;
  
  va_start(ap,);
  f_errno = va_arg(ap,int);
  file    = va_arg(ap,char *);
  line    = va_arg(ap,int);
  fmt     = va_arg(ap,char *);
#else
  va_start(ap,fmt);
#endif

  clean_fatal_tmp_file();
  
  len=0;
  for (p=fmt; *p; p++) {
    if (*p!='%')
      bputc(msg,&len,*p);
    else {
      p++;
      fld=getfld(&p);
      switch(*p) {
      case 'x':
	ival=va_arg(ap,int);
	sprintf(ifmt,"0x%%%dx",fld);
	sprintf(ibuf,ifmt,(unsigned int)ival);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'd':
	ival=va_arg(ap,int);
	sprintf(ifmt,"%%%dd",fld);
	sprintf(ibuf,ifmt,ival);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'u':
	ival=va_arg(ap,unsigned);
	sprintf(ifmt,"%%%du",fld);
	sprintf(ibuf,ifmt,ival);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'f':
	dval=va_arg(ap,double);
	sprintf(ifmt,"%%%df",fld);
	sprintf(ibuf,ifmt,dval);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'g':
	dval=va_arg(ap,double);
	sprintf(ifmt,"%%%dg",fld);
	sprintf(ibuf,ifmt,dval);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'c':
	cval=(char) va_arg(ap,int); /* char is promoted to int */
	bputc(msg,&len,cval);
	break;
      case 's':
	sval=va_arg(ap,char *);
	if (sval == NULL)
	  sval = strdup("(null)");
	bputs(msg,&len,sval,fld);
	break;
      case '%':
	bputc(msg,&len,*p);
	break;
      default:
	break;
      }
    }
  }
  va_end(ap);
  bputc(msg,&len,'\0');

  fatal_errno = f_errno;
  
  _gmx_error("fatal",msg,file,line);
}
コード例 #11
0
ファイル: gmx_fatal.c プロジェクト: aar2163/GROMACS
static void bputd(char *msg,int *len,int d)
{
  if (d<10) bputc(msg,len,d+'0'); else bputc(msg,len,d-10+'a');
}
コード例 #12
0
ファイル: conf-parse.c プロジェクト: NZOI/moe-cms
static void
unichar_dumper(struct fastbuf *b, uns *up)
{
  bput_utf8(b, *up);
  bputc(b, ' ');
}
コード例 #13
0
ファイル: fatal.c プロジェクト: Chadi-akel/cere
void fatal_error(int fatal_errno,char *fmt,...)
{
  va_list ap;
  char    *p,cval,*sval,msg[STRLEN];
  char    ibuf[64],ifmt[64];
  int     index,ival,fld,len;
  double  dval;
#ifdef _SPECIAL_VAR_ARG
  int     fatal_errno;
  char    *fmt;
  
  va_start(ap,);
  fatal_errno=va_arg(ap,int);
  fmt=va_arg(ap,char *);
#else
  va_start(ap,fmt);
#endif

  if (fatal_tmp_file) {
    fprintf(stderr,"Cleaning up temporary file %s\n",fatal_tmp_file);
    remove(fatal_tmp_file);
    sfree(fatal_tmp_file);
    fatal_tmp_file = NULL;
  }
  
  len=0;
  bputs(msg,&len,"Fatal error: ",0);
  for (p=fmt; *p; p++) {
    if (*p!='%')
      bputc(msg,&len,*p);
    else {
      p++;
      fld=getfld(&p);
      switch(*p) {
      case 'x':
	ival=va_arg(ap,int);
	sprintf(ifmt,"0x%%%dx",fld);
	sprintf(ibuf,ifmt,(unsigned int)ival);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'd':
	ival=va_arg(ap,int);
	sprintf(ifmt,"%%%dd",fld);
	sprintf(ibuf,ifmt,ival);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'f':
	dval=va_arg(ap,double);
	sprintf(ifmt,"%%%df",fld);
	sprintf(ibuf,ifmt,dval);
	for(index=0; (index<(int)strlen(ibuf)); index++)
	  bputc(msg,&len,ibuf[index]);
	break;
      case 'c':
	cval=(char) va_arg(ap,int); /* char is promoted to int */
	bputc(msg,&len,cval);
	break;
      case 's':
	sval=va_arg(ap,char *);
	bputs(msg,&len,sval,fld);
	break;
      default:
	break;
      }
    }
  }
  va_end(ap);
  bputc(msg,&len,'\0');

  quit_gmx(fatal_errno,msg);
}