hbase

heirloom base
git clone git://git.2f30.org/hbase
Log | Files | Refs | README

dorfmt.c (985B)


      1 /* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */
      2 #include <stdarg.h>
      3 #include <string.h>
      4 #include "plan9.h"
      5 #include "fmt.h"
      6 #include "fmtdef.h"
      7 
      8 /* format the output into f->to and return the number of characters fmted  */
      9 
     10 /* BUG: THIS FILE IS NOT UPDATED TO THE  NEW SPEC */
     11 int
     12 dorfmt(Fmt *f, const Rune *fmt)
     13 {
     14 	Rune *rt, *rs;
     15 	int r;
     16 	char *t, *s;
     17 	int nfmt;
     18 
     19 	nfmt = f->nfmt;
     20 	for(;;){
     21 		if(f->runes){
     22 			rt = (Rune*)f->to;
     23 			rs = (Rune*)f->stop;
     24 			while((r = *fmt++) && r != '%'){
     25 				FMTRCHAR(f, rt, rs, r);
     26 			}
     27 			f->nfmt += rt - (Rune *)f->to;
     28 			f->to = rt;
     29 			if(!r)
     30 				return f->nfmt - nfmt;
     31 			f->stop = rs;
     32 		}else{
     33 			t = (char*)f->to;
     34 			s = (char*)f->stop;
     35 			while((r = *fmt++) && r != '%'){
     36 				FMTRUNE(f, t, f->stop, r);
     37 			}
     38 			f->nfmt += t - (char *)f->to;
     39 			f->to = t;
     40 			if(!r)
     41 				return f->nfmt - nfmt;
     42 			f->stop = s;
     43 		}
     44 
     45 		fmt = (Rune*)__fmtdispatch(f, (Rune*)fmt, 1);
     46 		if(fmt == nil)
     47 			return -1;
     48 	}
     49 	return 0;		/* not reached */
     50 }