/* file padwsp.c */

#if !defined(COMPILE_ENVIRONMENT)
#include <gp/stdcenvf.h> /* std compile environment for functions */
#endif

char *pad_words_with_space(char *out, int out_lim,char *in, int npad)
  /************************************************/
  /*  Pads word tokens in *in with <npad> spaces, */
  /*  putting result into *out.                   */
  /************************************************/
   {char *proc = "pad_words_with_space";
    int i, j, k;
    /* code */
 db_enter_msg(proc,1); /* debug only */
    i = 0;
    j = 0;
    while (in[i] != '\0')
      {while ((in[i] != '\0') && (isspace(in[i]))) i += 1;
       if (in[i] != '\0')
         {for (k = 1; k <= npad; k++)
            {if (j < out_lim) out[j++] = ' ';
             else fatal_error(proc,"st OVF",-11);
            }
          while ((in[i] != '\0')&&(!isspace(in[i])))
            {if (j < LONG_LINE) out[j++] = in[i++];
             else fatal_error(proc,"st OVF",-11);
      }  }  }
    for (k = 1; k <= npad; k++)
      {if (j < LONG_LINE) out[j++] = ' ';
       else fatal_error(proc,"st OVF",-11);
      }
    out[j] = '\0';
 db_enter_msg(proc,1); /* debug only */
    return out;
   } 
