home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / proff.zoo / putwrd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-04  |  1003 b   |  50 lines

  1. #include <stdio.h>
  2. #include "proff.h"
  3. #include "debug.h"
  4.  
  5. #define brk brrk
  6.  
  7. /*
  8.  * putwrd - put a word in outbuf; includes margin justification
  9.  *
  10.  */
  11. putwrd(wrdbuf)
  12. char wrdbuf[];
  13. {
  14.     int last, llval, extra, w;
  15.  
  16. dprintf("putwrd  ");
  17.     w = width(wrdbuf);
  18.     last = (int)strlen(wrdbuf) + outp;         /* new end of outbuf */
  19. #ifdef DEBUG
  20. printf("strlen(wrdbuf) = %d\n",(int)strlen(wrdbuf));
  21. #endif
  22.     llval = rmval - tival;
  23.     if (outw + w > llval || last >= MAXOUT) {    /* too big */
  24.         last -= outp;
  25.         extra = llval - outw;
  26. #ifdef DEBUG
  27. printf("extra = %d\n",extra);
  28. #endif
  29.         for ( ; outp > 0; outp--)
  30.             if (outbuf[outp-1] == ' ')
  31.                 extra++;
  32.             else
  33.                 break;
  34.         if (rjust == YES) {
  35.             spread(outbuf, outp, extra, outwds);
  36.             if (extra > 0 && outwds > 1)
  37.                 outp += extra;
  38.         }
  39.         brk();        /* flush previous line */
  40.     }
  41. #ifdef DEBUG
  42. printf("putwrd: last=%d w=%d outp=%d llval=%d outw=%d extra=%d\n",
  43.         last,w,outp,llval,outw,extra);
  44. #endif
  45.     strcpy(&outbuf[outp],wrdbuf);
  46.     outp = last;
  47.     outw += w;
  48.     outwds++;
  49. }
  50.