File: vflbanner.c

package info (click to toggle)
vflib3 3.6.14.dfsg-1.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,548 kB
  • ctags: 3,710
  • sloc: ansic: 35,811; sh: 10,380; asm: 3,290; makefile: 961; lisp: 123; perl: 109; awk: 43
file content (145 lines) | stat: -rw-r--r-- 3,415 bytes parent folder | download | duplicates (6)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* 
 * vflbanner.c - a banner by VFlib
 * by Hirotsugu Kakugawa
 *
 *
 */
/*
 * Copyright (C) 1998 Hirotsugu Kakugawa. 
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
 */

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
#  include  <string.h>
#else
#  include  <strings.h>
#endif
#include "VFlib-3_6.h"

#define  DEFAULT_FONT  "timR18.pcf"


char    *vflibcap;
char    *fontname;
double   mag;

void  usage(void);
void  vflbanner(FILE *fp);


int
main(int argc, char **argv)
{
  vflibcap = NULL;
  fontname = DEFAULT_FONT;
  mag      = 1.0;

  --argc; argv++;
  while (argc > 0){
    if ((argc >= 1)
	&& ((strcmp(argv[0], "-h") == 0) || (strcmp(argv[0], "--help") == 0))){
      usage();
      exit(0);
    } else if ((argc >= 2) && (strcmp(argv[0], "-v") == 0)){
      --argc; argv++;
      vflibcap = argv[0];
      --argc; argv++;
    } else if ((argc >= 2) && (strcmp(argv[0], "-f") == 0)){
      --argc; argv++;
      fontname = argv[0];
      --argc; argv++;
    } else if ((argc >= 2) && (strcmp(argv[0], "-m") == 0)){
      --argc; argv++;
      mag = atof(argv[0]);
      --argc; argv++;
    } else {
      break;
    }
  }

  vflbanner(stdin);

  return 0;
}

void usage(void)
{
  printf("vflbanner - a banner program using VFlib\n");
  printf("Usage: vflbanner [-v vflibcap] [-m mag] [-f fontname]\n"); 
  printf("This program reads a text from standard input.  It supports\n");
  printf("1-bit encoded font only. Thus, `ctextpgm' is better than this.\n");
}


void
vflbanner(FILE  *fp)
{
  int  fid;
  int  ch; 
  int  pos_x, pos_y; 
  VF_BITMAP  bm, page_bm;
  struct vf_s_bitmaplist  PageBuff;

  if (VF_Init(vflibcap, NULL) < 0){
    printf("VFlib initialization error");
    switch (vf_error){
    case VF_ERR_INTERNAL:
      printf(" - Internal error.\n"); break;
    case VF_ERR_NO_MEMORY:
      printf(" - Server runs out of memory.\n"); break;
    case VF_ERR_NO_VFLIBCAP:
      printf(" -  No vflibcap.\n"); break;
    default: 
      printf(" -  Error code %d\n", vf_error); break;
    }
    fflush(stdout);
    exit(1);
  }

  if ((fid = VF_OpenFont1(fontname, -1, -1, -1, mag, mag)) < 0)
    return;
    
  VF_BitmapListInit(&PageBuff);

  pos_x = pos_y = 0; 
  while ((ch = getc(fp)) != EOF){
    if (iscntrl(ch))
      continue;
    if (!isprint(ch))
      ch = ' ';
    if ((bm = VF_GetBitmap1(fid, (long)ch, 1, 1)) == NULL)
      continue;
    VF_BitmapListPut(&PageBuff, bm, pos_x, pos_y);
    pos_x = pos_x + bm->mv_x;
  }

  page_bm = VF_BitmapListCompose(&PageBuff);
  VF_DumpBitmap(page_bm);
  VF_BitmapListFinish(&PageBuff);
  VF_FreeBitmap(page_bm);

  VF_CloseFont(fid);
}

/*EOF*/