int kanji_posbuf(int offset, const char *buf) { int n,m; n=0; m=0; for (;;) { if (m>=offset|| buf[n]=='\0') return n; m+=kanji_countdsp(buf[n], m); n+=kanji_countbuf(buf[n]); } }
/* 新型lineedit処理系 */ int le_getcsx(le_t *lep) { int csx,i; csx=0; for (i=0; i< lep->lx;) { if (lep->buf[i]=='\0') break; csx+= kanji_countdsp(lep->buf[i], csx); i=kanji_posnext(i, lep->buf); } csx+= lep->lx-i; return csx; }
int kanji_poscandsp(int offset, const char *buf) { int n,m,a,ln; ln=strlen(buf); n=m=a=0; for (;;) { if (n==offset) return offset; if (n>offset) return m; if (a>ln || buf[a]=='\0') return n; m=n; n+=kanji_countdsp(buf[a], n); a+=kanji_countbuf(buf[a]); } }
void strjfcpy(char *s,const char *t,size_t bytes,size_t len) { int n,m; for (;*t!=0;) { n=kanji_countbuf(*t); m=kanji_countdsp(*t, -1); if (bytes<n || len<m) break; memcpy(s, t, n); s+=n; t+=n; bytes-=n; len-=m; } for (;len>0&& bytes>0; --len,--bytes) *s++=' '; *s='\0'; }