File: ircman.c

package info (click to toggle)
epic5 2.0.1-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 4,696 kB
  • ctags: 6,357
  • sloc: ansic: 69,814; makefile: 715; ruby: 227; sh: 178; perl: 13
file content (72 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download | duplicates (10)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ircman.c by David N. Welton <davidw@efn.org>  */
/* This is free software under the terms of the GNU GPL  */
#include <stdio.h>
#include <stdlib.h>
          
int main (int argc, char *argv[])
{         
  FILE *fd;
  FILE *pgr;
      
  char *pager;
      
  int ch; 
  int boldflag = 0;   
  int revflag = 0;
  int ulflag = 0;
        
  if (argv[1] != NULL)
    fd = fopen (argv[1], "r");
  else
    {
      fprintf(stderr, "Usage: %s file\n", argv[0]);
      exit (1);
    }
  if (fd == NULL)
    {
      fprintf(stderr, "Could not open %s\n", argv[1]);
      exit (1);
    }            

  if(pager = getenv("PAGER")) {
    pgr = popen(pager, "w");
    if (pgr == NULL)
      {
        fputs("Danger, will robinson\n", stderr);
        exit (1);
      }
  } else {
    pgr = stdout;
  }  
  
  while((ch = fgetc(fd)) != EOF )
    {      
      switch (ch)
        {
        case '^V':
          revflag ^= 1;
          continue;
          break;
        case '^B':
          boldflag ^= 1;
          continue;
          break;
        case '^_':
          ulflag ^= 1;
          continue;
          break;
        }

      if (revflag)
        { putc(ch,pgr); putc(',pgr); putc(ch,pgr); }
      else if (boldflag)
        { putc(ch,pgr); putc(',pgr); putc(ch,pgr); }
      else if (ulflag)
        { putc('_',pgr); putc(',pgr); putc(ch,pgr); }
      else
        putc(ch,pgr);
    }
  close(fd);
  pclose(pgr);
}