summaryrefslogtreecommitdiff
path: root/support/mnu/dupcent.c
blob: 791094a4c6558a9c2ec94c6c420e7e3e58b68e81 (plain)
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
34
35
36
37
38
39
40
41

/* Program DUPCENT duplicates the per cent character */
/* ************************************************* */
/* 30.1.1993                              Petr Olsak */

/* Program types the input file to terminal, but all per cent characters
   are duplicated.  The DOS line can look as:
      dupcent param1 param2
   where
      param1 ... the input file name (including the path if needed)
      param2 (optionally) ... the text, which is included before each line
   The program is used for OPTIONS/SAVE item in TeX menu system (for example).
*/

#include <stdio.h>
#include <string.h>

#define FGETC(INPUT) (feof(INPUT)||i>=127 ? '\n' : fgetc(INPUT))

FILE *input;
char r[128];

main(int argc, char *argv[])
{
  register int i;

  input = fopen(argv[1], "r");
  if (input != NULL )  while (!feof(input))
  {
    i = 0;
    lab1: while ((r[i]=FGETC(input)) != '\n' && r[i] != '%') i++;
    if (feof(input) && r[i-1]==-1) r[--i] = '\n' ;
    if (r[i]=='%') { r[++i]='%'; i++; goto lab1;}
    r[i]=0;
    if (argv[2] == NULL || r[0]==0) printf ("%s\n", r);
    else printf ("%s %s\n", argv[2], r);
  }
  return 0;

}