figlet.c

来自「xen虚拟机源代码安装包」· C语言 代码 · 共 2,077 行 · 第 1/4 页

C
2,077
字号
/* * XXXXXXXXXXXXXXXXXXXXXXXXXXX *  * This is a HACKED figlet source file for Xen. *  * Hacked to output C octal strings for inclusion in a header file. * Support for opening zipped files is removed. *  * Go to www.figlet.org for the unhacked Figlet sources. *//****************************************************************************  FIGlet Copyright 1991, 1993, 1994 Glenn Chappell and Ian Chai  FIGlet Copyright 1996, 1997, 1998, 1999, 2000, 2001 John Cowan  FIGlet Copyright 2002 Christiaan Keet  Portions written by Paul Burton and Christiaan Keet  Internet: <info@figlet.org>  FIGlet, along with the various FIGlet fonts and documentation, is    copyrighted under the provisions of the Artistic License (as listed    in the file "Artistic-license.txt" which is included in this package.****************************************************************************/#define DATE "13 July 2002"#define VERSION "2.2.1"#define VERSION_INT 20201/* FIGlet (Frank, Ian & Glenn's Letters) *//* by Glenn Chappell *//* Apr 1991 *//* Automatic file addition by Ian Chai May 1991 *//* Punctuation and numbers addition by Ian Chai Jan 1993 *//* Full ASCII by Glenn Chappell Feb 1993 *//* Line-breaking, general rewrite by Glenn Chappell Mar 1993 *//* Hard blanks by Glenn Chappell Apr 1993 *//* Release 2.0 5 Aug 1993 *//* Right-to-left printing, extended char set by Glenn Chappell Dec 1993 *//* Control files by Glenn Chappell Feb 1994 *//* Release 2.1 12 Aug 1994 *//* Release 2.1.1 25 Aug 1994 *//* Release 2.1.2 by Gilbert (Mad Programmer) Healton: Add -A command line    option.  Sept 8, 1996 *//* Release 2.2 by John Cowan: multibyte inputs, compressed fonts,   mapping tables, kerning/smushing options. *//* Release 2.2.1 by Christiaan Keet: minor updates including readmes   FAQs and comments. 13 July 2002. The new official FIGlet website is    http://www.figlet.org/  */#define DEFAULTFONTDIR "."#define DEFAULTFONTFILE "xen.flf"#include <stdio.h>#ifdef __STDC__#include <stdlib.h>#endif#include <string.h>#include <ctype.h>#include <fcntl.h>     /* Needed for get_columns */#ifdef unix#include <sys/ioctl.h> /* Needed for get_columns */#endif#define ZFILE FILE#define Zopen fopen#define Zgetc fgetc#define Zungetc(_x,_y) fseek(_y,-1,SEEK_CUR)#define Zclose fclose#define MYSTRLEN(x) ((int)strlen(x)) /* Eliminate ANSI problem */#define DIRSEP '/'#define DIRSEP2 '\\'/* Leave alone for Unix and MS-DOS/Windows!Note: '/' also used in filename in get_columns(). */#define FONTFILESUFFIX ".flf"#define FONTFILEMAGICNUMBER "flf2"#define FSUFFIXLEN MYSTRLEN(FONTFILESUFFIX)#define CONTROLFILESUFFIX ".flc"#define CONTROLFILEMAGICNUMBER "flc2"   /* no longer used in 2.2 */#define CSUFFIXLEN MYSTRLEN(CONTROLFILESUFFIX)#define DEFAULTCOLUMNS 80/****************************************************************************  Globals dealing with chars that are read****************************************************************************/typedef long inchr; /* "char" read from stdin */inchr *inchrline;  /* Alloc'd inchr inchrline[inchrlinelenlimit+1]; */                   /* Note: not null-terminated. */int inchrlinelen,inchrlinelenlimit;inchr deutsch[7] = {196, 214, 220, 228, 246, 252, 223};  /* Latin-1 codes for German letters, respectively:     LATIN CAPITAL LETTER A WITH DIAERESIS = A-umlaut     LATIN CAPITAL LETTER O WITH DIAERESIS = O-umlaut     LATIN CAPITAL LETTER U WITH DIAERESIS = U-umlaut     LATIN SMALL LETTER A WITH DIAERESIS = a-umlaut     LATIN SMALL LETTER O WITH DIAERESIS = o-umlaut     LATIN SMALL LETTER U WITH DIAERESIS = u-umlaut     LATIN SMALL LETTER SHARP S = ess-zed  */int hzmode;  /* true if reading double-bytes in HZ mode */int gndbl[4]; /* gndbl[n] is true if Gn is double-byte */inchr gn[4]; /* Gn character sets: ASCII, Latin-1, none, none */int gl; /* 0-3 specifies left-half Gn character set */int gr; /* 0-3 specifies right-half Gn character set */int Myargc;  /* to avoid passing around argc and argv */char **Myargv;/****************************************************************************  Globals dealing with chars that are written****************************************************************************/typedef struct fc {  inchr ord;  char **thechar;  /* Alloc'd char thechar[charheight][]; */  struct fc *next;  } fcharnode;fcharnode *fcharlist;char **currchar;int currcharwidth;int previouscharwidth;char **outputline;    /* Alloc'd char outputline[charheight][outlinelenlimit+1]; */int outlinelen;/****************************************************************************  Globals dealing with command file storage****************************************************************************/typedef struct cfn {  char *thename;  struct cfn *next;  } cfnamenode;cfnamenode *cfilelist,**cfilelistend;typedef struct cm {  int thecommand;  inchr rangelo;  inchr rangehi;  inchr offset;  struct cm *next;  } comnode;comnode *commandlist,**commandlistend;/****************************************************************************  Globals affected by command line options****************************************************************************/int deutschflag,justification,paragraphflag,right2left,multibyte;int cmdinput;#define SM_SMUSH 128#define SM_KERN 64#define SM_EQUAL 1#define SM_LOWLINE 2#define SM_HIERARCHY 4#define SM_PAIR 8#define SM_BIGX 16#define SM_HARDBLANK 32int smushmode;#define SMO_NO 0     /* no command-line smushmode */#define SMO_YES 1    /* use command-line smushmode, ignore font smushmode */#define SMO_FORCE 2  /* logically OR command-line and font smushmodes */int smushoverride;int outputwidth;int outlinelenlimit;char *fontdirname,*fontname;/****************************************************************************  Globals read from font file****************************************************************************/char hardblank;int charheight;/****************************************************************************  Name of program, used in error messages****************************************************************************/char *myname;#ifdef TIOCGWINSZ/****************************************************************************  get_columns  Determines the number of columns of /dev/tty.  Returns the number of  columns, or -1 if error.  May return 0 if columns unknown.  Requires include files <fcntl.h> and <sys/ioctl.h>.  by Glenn Chappell & Ian Chai 14 Apr 1993****************************************************************************/int get_columns(){  struct winsize ws;  int fd,result;  if ((fd = open("/dev/tty",O_WRONLY))<0) return -1;  result = ioctl(fd,TIOCGWINSZ,&ws);  close(fd);  return result?-1:ws.ws_col;}#endif /* ifdef TIOCGWINSZ *//****************************************************************************  myalloc  Calls malloc.  If malloc returns error, prints error message and  quits.****************************************************************************/#ifdef __STDC__char *myalloc(size_t size)#elsechar *myalloc(size)int size;#endif{  char *ptr;#ifndef __STDC__  extern void *malloc();#endif  if ((ptr = (char*)malloc(size))==NULL) {    fprintf(stderr,"%s: Out of memory\n",myname);    exit(1);    }  else {    return ptr;    }}/****************************************************************************  hasdirsep  Returns true if s1 contains a DIRSEP or DIRSEP2 character.****************************************************************************/int hasdirsep(s1)char *s1;{  if (strchr(s1, DIRSEP)) return 1;  else if (strchr(s1, DIRSEP2)) return 1;  else return 0;}/****************************************************************************  suffixcmp  Returns true if s2 is a suffix of s1; uses case-blind comparison.****************************************************************************/int suffixcmp(s1, s2)char *s1;char *s2;{  int len1, len2;  len1 = MYSTRLEN(s1);  len2 = MYSTRLEN(s2);  if (len2 > len1) return 0;  s1 += len1 - len2;  while (*s1) {    if (tolower(*s1) != tolower(*s2)) return 0;    s1++;    s2++;    }  return 1;}   /****************************************************************************  skiptoeol  Skips to the end of a line, given a stream.  Handles \r, \n, or \r\n.****************************************************************************/void skiptoeol(fp)ZFILE *fp;{  int dummy;  while (dummy=Zgetc(fp),dummy!=EOF) {    if (dummy == '\n') return;    if (dummy == '\r') {      dummy = Zgetc(fp);      if (dummy != EOF && dummy != '\n') Zungetc(dummy,fp);      return;      }  }}/****************************************************************************  myfgets  Local version of fgets.  Handles \r, \n, and \r\n terminators.****************************************************************************/char *myfgets(line,maxlen,fp)char *line;int maxlen;ZFILE *fp;{  int c = 0;  char *p;  p = line;  while((c=Zgetc(fp))!=EOF&&maxlen) {    *p++ = c;    maxlen--;    if (c=='\n') break;    if (c=='\r') {      c = Zgetc(fp);      if (c != EOF && c != '\n') Zungetc(c,fp);      *(p-1) = '\n';      break;      }    }  *p = 0;  return (c==EOF) ? NULL : line;}/****************************************************************************  usageerr  Prints "Usage: ...." line to the given stream.****************************************************************************/void printusage(out)FILE *out;{  fprintf(out,    "Usage: %s [ -cklnoprstvxDELNRSWX ] [ -d fontdirectory ]\n",    myname);  fprintf(out,    "              [ -f fontfile ] [ -m smushmode ] [ -w outputwidth ]\n");  fprintf(out,    "              [ -C controlfile ] [ -I infocode ] [ message ]\n");}/****************************************************************************  printinfo  Prints version and copyright message, or utility information.****************************************************************************/void printinfo(infonum)int infonum;{  switch (infonum) {    case 0: /* Copyright message */      printf("FIGlet Copyright 1991-2002 Glenn Chappell, Ian Chai, ");      printf("John Cowan, Christiaan Keet\n");      printf("Internet: <info@figlet.org> ");      printf("Version: %s, date: %s\n\n",VERSION,DATE);      printf("FIGlet, along with the various FIGlet fonts");      printf(" and documentation, may be\n");      printf("freely copied and distributed.\n\n");      printf("If you use FIGlet, please send an");      printf(" e-mail message to <info@figlet.org>.\n\n");      printf("The latest version of FIGlet is available from the");      printf(" web site,\n\thttp://www.figlet.org/\n\n");      printusage(stdout);      break;    case 1: /* Version (integer) */      printf("%d\n",VERSION_INT);      break;    case 2: /* Font directory */      printf("%s\n",fontdirname);      break;    case 3: /* Font */      printf("%s\n",fontname);      break;    case 4: /* Outputwidth */      printf("%d\n",outputwidth);    }}/****************************************************************************  readmagic  Reads a four-character magic string from a stream.****************************************************************************/void readmagic(fp,magic)ZFILE *fp;char *magic;{  int i;  for (i=0;i<4;i++) {    magic[i] = Zgetc(fp);    }  magic[4] = 0;  }  /****************************************************************************  skipws  Skips whitespace characters from a stream.****************************************************************************/void skipws(fp)ZFILE *fp;{  int c;  while (c=Zgetc(fp),isascii(c)&&isspace(c)) ;  Zungetc(c,fp);  }/****************************************************************************  readnum  Reads a number from a stream.  Accepts "0" prefix for octal and  "0x" or "0X" for hexadecimal.  Ignores leading whitespace.****************************************************************************/void readnum(fp,nump)ZFILE *fp;inchr *nump;{  int acc = 0;  char *p;  int c;  int base;  int sign = 1;  char digits[] = "0123456789ABCDEF";  skipws(fp);  c = Zgetc(fp);  if (c=='-') {    sign = -1;    }  else {    Zungetc(c,fp);    }  c = Zgetc(fp);  if (c=='0') {     c = Zgetc(fp);     if (c=='x'||c=='X') {       base = 16;       }     else {       base = 8;       Zungetc(c,fp);       }    }  else {    base = 10;    Zungetc(c,fp);    }  while((c=Zgetc(fp))!=EOF) {    c=toupper(c);    p=strchr(digits,c);    if (!p) {      Zungetc(c,fp);      *nump = acc * sign;      return;      }    acc = acc*base+(p-digits);    }  *nump = acc * sign;  }  /****************************************************************************  readTchar

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?