Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

26 lines
724 B

  1. #include "fmt.h"
  2. /* "foo" -> " foo"
  3. * write padlen-srclen spaces, if that is >= 0. Then copy srclen
  4. * characters from src. Truncate only if total length is larger than
  5. * maxlen. Return number of characters written. */
  6. unsigned long fmt_pad(char* dest,const char* src,unsigned long srclen,unsigned long padlen,unsigned long maxlen) {
  7. long todo;
  8. char* olddest=dest;
  9. char* max=dest+maxlen;
  10. todo=padlen-srclen;
  11. if (dest==0) {
  12. int sum=srclen>padlen?srclen:padlen;
  13. return sum>maxlen?maxlen:sum;
  14. }
  15. for (; todo>0; --todo) {
  16. if (dest>max) break;
  17. *dest=' '; ++dest;
  18. }
  19. for (todo=srclen; todo>0; --todo) {
  20. if (dest>max) break;
  21. *dest=*src; ++dest; ++src;
  22. }
  23. return dest-olddest;
  24. }