src/dbg_ml.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. main
  2. usage
  3. test

   1 /* 
   2  * dbg_ml.c - 
   3  * by Hirotsugu Kakugawa
   4  *
   5  *
   6  */
   7 /*
   8  * Copyright (C) 2001 Hirotsugu Kakugawa. 
   9  * All rights reserved.
  10  *
  11  * This program is free software; you can redistribute it and/or modify
  12  * it under the terms of the GNU General Public License as published by
  13  * the Free Software Foundation; either version 2, or (at your option)
  14  * any later version.
  15  * 
  16  * This program is distributed in the hope that it will be useful,
  17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  * GNU General Public License for more details.
  20  * 
  21  * You should have received a copy of the GNU General Public License
  22  * along with this program; if not, write to the Free Software
  23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
  24  */
  25 
  26 #include "config.h"
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <ctype.h>
  30 #ifdef HAVE_UNISTD_H
  31 # include <unistd.h>
  32 #endif
  33 
  34 #ifdef __FreeBSD__
  35 #include <sys/types.h> 
  36 #include <sys/time.h> 
  37 #include <sys/resource.h> 
  38 #define RUSAGE_SELF 0
  39 #endif
  40 
  41 
  42 #include "VFlib-3_6.h"
  43 
  44 #define  DEFAULT_FONT  "timR18.pcf"
  45 
  46 
  47 char    *vflibcap;
  48 char    *fontname;
  49 double   mag;
  50 
  51 void  usage(void);
  52 void  test(int, int);
  53 
  54 
  55 int
  56 main(int argc, char **argv)
     /* [<][>][^][v][top][bottom][index][help] */
  57 {
  58   int  code;
  59   int  w;
  60 
  61   code     = -1;
  62   vflibcap = NULL;
  63   fontname = DEFAULT_FONT;
  64   mag      = 1.0;
  65   w        = 1;
  66 
  67   --argc; argv++;
  68   while (argc > 0){
  69     if ((argc >= 1)
  70         && ((strcmp(argv[0], "-h") == 0) || (strcmp(argv[0], "--help") == 0))){
  71       usage();
  72       exit(0);
  73     } else if ((argc >= 2) && (strcmp(argv[0], "-v") == 0)){
  74       --argc; argv++;
  75       vflibcap = argv[0];
  76       --argc; argv++;
  77     } else if ((argc >= 2) && (strcmp(argv[0], "-f") == 0)){
  78       --argc; argv++;
  79       fontname = argv[0];
  80       --argc; argv++;
  81     } else if ((argc >= 2) && (strcmp(argv[0], "-m") == 0)){
  82       --argc; argv++;
  83       mag = atof(argv[0]);
  84       --argc; argv++;
  85     } else if ((argc >= 2) && (strcmp(argv[0], "-w") == 0)){
  86       --argc; argv++;
  87       w = atof(argv[0]);
  88       --argc; argv++;
  89     } else if (argv[0][0] == '='){
  90       printf("Unknown option: %s\n", *argv);
  91       usage();
  92       exit(0);
  93     } else {
  94       sscanf(argv[0], "%i", &code);
  95       break;
  96     }
  97   }
  98 
  99   test(code, w);
 100 
 101   return 0;
 102 }
 103 
 104 void usage(void)
     /* [<][>][^][v][top][bottom][index][help] */
 105 {
 106   printf("dbg_ml\n");
 107   printf("Usage: dbg_ml [-v vflibcap] [-m mag] [-f fontname] charcode\n"); 
 108 }
 109 
 110 
 111 
 112 void
 113 test(int code, int w)
     /* [<][>][^][v][top][bottom][index][help] */
 114 {
 115   int  fid, i;
 116   VF_BITMAP  bm;
 117 #ifdef __FreeBSD__
 118   struct rusage  ru;
 119 #endif
 120 
 121 
 122   if (VF_Init(vflibcap, NULL) < 0){
 123     printf("VFlib initialization error\n");
 124     exit(1);
 125   }
 126 
 127   printf("** font=%s, char=%d", fontname, code);
 128 
 129   i = 1;
 130   for (;;){
 131     if ((i % 50) == 1){
 132 #ifdef __FreeBSD__
 133       printf("\n");
 134       if (getrusage(RUSAGE_SELF, &ru) >= 0){
 135         printf(" maxrss=%ldK", ru.ru_maxrss);
 136       }
 137 #endif
 138       printf("\n");
 139       printf("% 6d ", i);
 140     }
 141     printf("*"); fflush(stdout);
 142     i++;
 143     if ((fid = VF_OpenFont1(fontname, -1, -1, -1, mag, mag)) < 0){
 144       printf("\nCan't open font\n");
 145       return;
 146     }
 147     if (code > 0){
 148       bm = VF_GetBitmap1(fid, code, 1, 1);
 149       if (bm == NULL){
 150         printf("\nCan't get bitmap\n");
 151         return;
 152       }
 153       VF_FreeBitmap(bm);
 154     }
 155     VF_CloseFont(fid);
 156     fid = -1;
 157     if (w > 0) 
 158       usleep(1000*w);
 159   }
 160 }
 161 
 162 /*EOF*/

/* [<][>][^][v][top][bottom][index][help] */