summaryrefslogtreecommitdiff
path: root/src/bin/pad.c
blob: f520de3ad45bc6a0462480ddd31ea859d2a672b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc,char *argv[]) {
 short in;
 int i=0;
 int width=argc>1?atoi(argv[1]):80;
 char with=argc>2?argv[2][0]:' ';
 char *line=argc>3?argv[3]:0;
 if(width <= 0) width=80;
 if(!line) {
  while((in=fgetc(stdin)) != -1) {
   if(in == '\n') {
    for(;i%width || i == 0;i++) {
     putchar(with);
    }
    i=-1;
   }
   i++;
   putchar(in);
  }
 } else {
  i=strlen(line);
 }
 if(i != 0 || line) {
  if(line) fputs(line,stdout);
  for(;i%width || i == 0;i++) {
   putchar(with);
  }
 }
 return 0;
}