diff options
| author | Eric Andersen <andersen@codepoet.org> | 1999-10-19 06:02:44 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 1999-10-19 06:02:44 +0000 |
| commit | 3e0fbae15eca940c70075c8eade3f2c735fa34b6 (patch) | |
| tree | 4ce22d21a451f695eaf1ea8ef446438414984ef3 | |
| parent | abc7d597cb78a0ee3e92ecaeb73f6cbb2a3412bf (diff) | |
| download | busybox-w32-3e0fbae15eca940c70075c8eade3f2c735fa34b6.tar.gz busybox-w32-3e0fbae15eca940c70075c8eade3f2c735fa34b6.tar.bz2 busybox-w32-3e0fbae15eca940c70075c8eade3f2c735fa34b6.zip | |
fixes grep, added loadfont from debian bootfloppies.
-Erik
| -rw-r--r-- | applets/busybox.c | 3 | ||||
| -rw-r--r-- | busybox.c | 3 | ||||
| -rw-r--r-- | busybox.def.h | 17 | ||||
| -rw-r--r-- | console-tools/loadfont.c | 234 | ||||
| -rw-r--r-- | findutils/grep.c | 153 | ||||
| -rw-r--r-- | grep.c | 153 | ||||
| -rw-r--r-- | internal.h | 1 | ||||
| -rw-r--r-- | loadfont.c | 234 |
8 files changed, 600 insertions, 198 deletions
diff --git a/applets/busybox.c b/applets/busybox.c index 16ccce67e..cb0e2a728 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
| @@ -72,6 +72,9 @@ static const struct Applet applets[] = { | |||
| 72 | #ifdef BB_LN //bin | 72 | #ifdef BB_LN //bin |
| 73 | {"ln", ln_main}, | 73 | {"ln", ln_main}, |
| 74 | #endif | 74 | #endif |
| 75 | #ifdef BB_LOADFONT //usr/bin | ||
| 76 | {"loadfont", loadfont_main}, | ||
| 77 | #endif | ||
| 75 | #ifdef BB_LOADKMAP //sbin | 78 | #ifdef BB_LOADKMAP //sbin |
| 76 | {"loadkmap", loadkmap_main}, | 79 | {"loadkmap", loadkmap_main}, |
| 77 | #endif | 80 | #endif |
| @@ -72,6 +72,9 @@ static const struct Applet applets[] = { | |||
| 72 | #ifdef BB_LN //bin | 72 | #ifdef BB_LN //bin |
| 73 | {"ln", ln_main}, | 73 | {"ln", ln_main}, |
| 74 | #endif | 74 | #endif |
| 75 | #ifdef BB_LOADFONT //usr/bin | ||
| 76 | {"loadfont", loadfont_main}, | ||
| 77 | #endif | ||
| 75 | #ifdef BB_LOADKMAP //sbin | 78 | #ifdef BB_LOADKMAP //sbin |
| 76 | {"loadkmap", loadkmap_main}, | 79 | {"loadkmap", loadkmap_main}, |
| 77 | #endif | 80 | #endif |
diff --git a/busybox.def.h b/busybox.def.h index 7ca522b3a..e37916845 100644 --- a/busybox.def.h +++ b/busybox.def.h | |||
| @@ -13,29 +13,30 @@ | |||
| 13 | #define BB_DD | 13 | #define BB_DD |
| 14 | #define BB_DF | 14 | #define BB_DF |
| 15 | #define BB_DMESG | 15 | #define BB_DMESG |
| 16 | #define BB_DUTMP | 16 | //#define BB_DUTMP |
| 17 | #define BB_FALSE | 17 | #define BB_FALSE |
| 18 | #define BB_FDFLUSH | 18 | #define BB_FDFLUSH |
| 19 | #define BB_FIND | 19 | #define BB_FIND |
| 20 | #define BB_GREP | 20 | #define BB_GREP |
| 21 | //#define BB_HALT | 21 | #define BB_HALT |
| 22 | #define BB_INIT | 22 | #define BB_INIT |
| 23 | #define BB_KILL | 23 | #define BB_KILL |
| 24 | //#define BB_LENGTH | 24 | //#define BB_LENGTH |
| 25 | #define BB_LN | 25 | #define BB_LN |
| 26 | #define BB_LOADFONT | ||
| 26 | #define BB_LOADKMAP | 27 | #define BB_LOADKMAP |
| 27 | #define BB_LS | 28 | #define BB_LS |
| 28 | #define BB_MAKEDEVS | 29 | //#define BB_MAKEDEVS |
| 29 | //#define BB_MATH | 30 | //#define BB_MATH |
| 30 | #define BB_MKDIR | 31 | #define BB_MKDIR |
| 31 | #define BB_MKNOD | 32 | #define BB_MKNOD |
| 32 | //#define BB_MKSWAP | 33 | #define BB_MKSWAP |
| 33 | #define BB_MNC | 34 | //#define BB_MNC |
| 34 | #define BB_MORE | 35 | #define BB_MORE |
| 35 | #define BB_MOUNT | 36 | #define BB_MOUNT |
| 36 | //#define BB_MT | 37 | #define BB_MT |
| 37 | #define BB_MV | 38 | #define BB_MV |
| 38 | #define BB_PRINTF | 39 | //#define BB_PRINTF |
| 39 | #define BB_PWD | 40 | #define BB_PWD |
| 40 | #define BB_REBOOT | 41 | #define BB_REBOOT |
| 41 | #define BB_RM | 42 | #define BB_RM |
| @@ -50,4 +51,4 @@ | |||
| 50 | #define BB_UPDATE | 51 | #define BB_UPDATE |
| 51 | #define BB_UTILITY | 52 | #define BB_UTILITY |
| 52 | #define BB_ZCAT | 53 | #define BB_ZCAT |
| 53 | #define BB_GZIP | 54 | //#define BB_GZIP |
diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c new file mode 100644 index 000000000..a10fa8a69 --- /dev/null +++ b/console-tools/loadfont.c | |||
| @@ -0,0 +1,234 @@ | |||
| 1 | /* | ||
| 2 | * loadfont.c - Eugene Crosser & Andries Brouwer | ||
| 3 | * | ||
| 4 | * Version 0.96bb | ||
| 5 | * | ||
| 6 | * Loads the console font, and possibly the corresponding screen map(s). | ||
| 7 | * (Adapted for busybox by Matej Vela.) | ||
| 8 | */ | ||
| 9 | #include "internal.h" | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <string.h> | ||
| 12 | #include <fcntl.h> | ||
| 13 | #include <memory.h> | ||
| 14 | #include <stdlib.h> | ||
| 15 | #include <unistd.h> | ||
| 16 | #include <sys/types.h> | ||
| 17 | #include <sys/stat.h> | ||
| 18 | #include <dirent.h> | ||
| 19 | #include <errno.h> | ||
| 20 | #include <sys/ioctl.h> | ||
| 21 | #include <sys/kd.h> | ||
| 22 | #include <endian.h> | ||
| 23 | |||
| 24 | #define PSF_MAGIC1 0x36 | ||
| 25 | #define PSF_MAGIC2 0x04 | ||
| 26 | |||
| 27 | #define PSF_MODE512 0x01 | ||
| 28 | #define PSF_MODEHASTAB 0x02 | ||
| 29 | #define PSF_MAXMODE 0x03 | ||
| 30 | #define PSF_SEPARATOR 0xFFFF | ||
| 31 | |||
| 32 | static const char loadfont_usage[] = "loadfont\n" | ||
| 33 | "\n" | ||
| 34 | "\tLoad a console font from standard input.\n" | ||
| 35 | "\n"; | ||
| 36 | |||
| 37 | struct psf_header | ||
| 38 | { | ||
| 39 | unsigned char magic1, magic2; /* Magic number */ | ||
| 40 | unsigned char mode; /* PSF font mode */ | ||
| 41 | unsigned char charsize; /* Character size */ | ||
| 42 | }; | ||
| 43 | |||
| 44 | #define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2) | ||
| 45 | |||
| 46 | static void loadnewfont(int fd); | ||
| 47 | |||
| 48 | extern int | ||
| 49 | loadfont_main(int argc, char **argv) | ||
| 50 | { | ||
| 51 | int fd; | ||
| 52 | |||
| 53 | fd = open("/dev/tty0", O_RDWR); | ||
| 54 | if (fd < 0) { | ||
| 55 | fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno)); | ||
| 56 | return 1; | ||
| 57 | } | ||
| 58 | loadnewfont(fd); | ||
| 59 | |||
| 60 | return 0; | ||
| 61 | } | ||
| 62 | |||
| 63 | static void | ||
| 64 | do_loadfont(int fd, char *inbuf, int unit, int fontsize) { | ||
| 65 | char buf[16384]; | ||
| 66 | int i; | ||
| 67 | |||
| 68 | memset(buf,0,sizeof(buf)); | ||
| 69 | |||
| 70 | if (unit < 1 || unit > 32) { | ||
| 71 | fprintf(stderr, "Bad character size %d\n", unit); | ||
| 72 | exit(1); | ||
| 73 | } | ||
| 74 | |||
| 75 | for (i = 0; i < fontsize; i++) | ||
| 76 | memcpy(buf+(32*i), inbuf+(unit*i), unit); | ||
| 77 | |||
| 78 | #if defined( PIO_FONTX ) && !defined( sparc ) | ||
| 79 | { | ||
| 80 | struct consolefontdesc cfd; | ||
| 81 | |||
| 82 | cfd.charcount = fontsize; | ||
| 83 | cfd.charheight = unit; | ||
| 84 | cfd.chardata = buf; | ||
| 85 | |||
| 86 | if (ioctl(fd, PIO_FONTX, &cfd) == 0) | ||
| 87 | return; /* success */ | ||
| 88 | perror("PIO_FONTX ioctl error (trying PIO_FONT)"); | ||
| 89 | } | ||
| 90 | #endif | ||
| 91 | if (ioctl(fd, PIO_FONT, buf)) { | ||
| 92 | perror("PIO_FONT ioctl error"); | ||
| 93 | exit(1); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | static void | ||
| 98 | do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) { | ||
| 99 | struct unimapinit advice; | ||
| 100 | struct unimapdesc ud; | ||
| 101 | struct unipair *up; | ||
| 102 | int ct = 0, maxct; | ||
| 103 | int glyph; | ||
| 104 | u_short unicode; | ||
| 105 | |||
| 106 | maxct = tailsz; /* more than enough */ | ||
| 107 | up = (struct unipair *) malloc(maxct * sizeof(struct unipair)); | ||
| 108 | if (!up) { | ||
| 109 | fprintf(stderr, "Out of memory?\n"); | ||
| 110 | exit(1); | ||
| 111 | } | ||
| 112 | for (glyph = 0; glyph < fontsize; glyph++) { | ||
| 113 | while (tailsz >= 2) { | ||
| 114 | unicode = (((u_short) inbuf[1]) << 8) + inbuf[0]; | ||
| 115 | tailsz -= 2; | ||
| 116 | inbuf += 2; | ||
| 117 | if (unicode == PSF_SEPARATOR) | ||
| 118 | break; | ||
| 119 | up[ct].unicode = unicode; | ||
| 120 | up[ct].fontpos = glyph; | ||
| 121 | ct++; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | /* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP | ||
| 126 | this printf did not work on many kernels */ | ||
| 127 | |||
| 128 | advice.advised_hashsize = 0; | ||
| 129 | advice.advised_hashstep = 0; | ||
| 130 | advice.advised_hashlevel = 0; | ||
| 131 | if(ioctl(fd, PIO_UNIMAPCLR, &advice)) { | ||
| 132 | #ifdef ENOIOCTLCMD | ||
| 133 | if (errno == ENOIOCTLCMD) { | ||
| 134 | fprintf(stderr, "It seems this kernel is older than 1.1.92\n"); | ||
| 135 | fprintf(stderr, "No Unicode mapping table loaded.\n"); | ||
| 136 | } else | ||
| 137 | #endif | ||
| 138 | perror("PIO_UNIMAPCLR"); | ||
| 139 | exit(1); | ||
| 140 | } | ||
| 141 | ud.entry_ct = ct; | ||
| 142 | ud.entries = up; | ||
| 143 | if(ioctl(fd, PIO_UNIMAP, &ud)) { | ||
| 144 | #if 0 | ||
| 145 | if (errno == ENOMEM) { | ||
| 146 | /* change advice parameters */ | ||
| 147 | } | ||
| 148 | #endif | ||
| 149 | perror("PIO_UNIMAP"); | ||
| 150 | exit(1); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | static void | ||
| 155 | loadnewfont(int fd) { | ||
| 156 | int unit; | ||
| 157 | char inbuf[32768]; /* primitive */ | ||
| 158 | int inputlth, offset; | ||
| 159 | |||
| 160 | /* | ||
| 161 | * We used to look at the length of the input file | ||
| 162 | * with stat(); now that we accept compressed files, | ||
| 163 | * just read the entire file. | ||
| 164 | */ | ||
| 165 | inputlth = fread(inbuf, 1, sizeof(inbuf), stdin); | ||
| 166 | if (ferror(stdin)) { | ||
| 167 | perror("Error reading input font"); | ||
| 168 | exit(1); | ||
| 169 | } | ||
| 170 | /* use malloc/realloc in case of giant files; | ||
| 171 | maybe these do not occur: 16kB for the font, | ||
| 172 | and 16kB for the map leaves 32 unicode values | ||
| 173 | for each font position */ | ||
| 174 | if (!feof(stdin)) { | ||
| 175 | perror("Font too large"); | ||
| 176 | exit(1); | ||
| 177 | } | ||
| 178 | |||
| 179 | /* test for psf first */ | ||
| 180 | { | ||
| 181 | struct psf_header psfhdr; | ||
| 182 | int fontsize; | ||
| 183 | int hastable; | ||
| 184 | int head0, head; | ||
| 185 | |||
| 186 | if (inputlth < sizeof(struct psf_header)) | ||
| 187 | goto no_psf; | ||
| 188 | |||
| 189 | psfhdr = * (struct psf_header *) &inbuf[0]; | ||
| 190 | |||
| 191 | if (!PSF_MAGIC_OK(psfhdr)) | ||
| 192 | goto no_psf; | ||
| 193 | |||
| 194 | if (psfhdr.mode > PSF_MAXMODE) { | ||
| 195 | fprintf(stderr, "Unsupported psf file mode\n"); | ||
| 196 | exit(1); | ||
| 197 | } | ||
| 198 | fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256); | ||
| 199 | #if !defined( PIO_FONTX ) || defined( sparc ) | ||
| 200 | if (fontsize != 256) { | ||
| 201 | fprintf(stderr, "Only fontsize 256 supported\n"); | ||
| 202 | exit(1); | ||
| 203 | } | ||
| 204 | #endif | ||
| 205 | hastable = (psfhdr.mode & PSF_MODEHASTAB); | ||
| 206 | unit = psfhdr.charsize; | ||
| 207 | head0 = sizeof(struct psf_header); | ||
| 208 | head = head0 + fontsize*unit; | ||
| 209 | if (head > inputlth || (!hastable && head != inputlth)) { | ||
| 210 | fprintf(stderr, "Input file: bad length\n"); | ||
| 211 | exit(1); | ||
| 212 | } | ||
| 213 | do_loadfont(fd, inbuf + head0, unit, fontsize); | ||
| 214 | if (hastable) | ||
| 215 | do_loadtable(fd, inbuf + head, inputlth-head, fontsize); | ||
| 216 | return; | ||
| 217 | } | ||
| 218 | no_psf: | ||
| 219 | |||
| 220 | /* file with three code pages? */ | ||
| 221 | if (inputlth == 9780) { | ||
| 222 | offset = 40; | ||
| 223 | unit = 16; | ||
| 224 | } else { | ||
| 225 | /* bare font */ | ||
| 226 | if (inputlth & 0377) { | ||
| 227 | fprintf(stderr, "Bad input file size\n"); | ||
| 228 | exit(1); | ||
| 229 | } | ||
| 230 | offset = 0; | ||
| 231 | unit = inputlth/256; | ||
| 232 | } | ||
| 233 | do_loadfont(fd, inbuf+offset, unit, 256); | ||
| 234 | } | ||
diff --git a/findutils/grep.c b/findutils/grep.c index 657bb2570..de1c820a0 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
| @@ -1,17 +1,25 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 1999 by David I. Bell | 2 | * Mini grep implementation for busybox |
| 3 | * Permission is granted to use, distribute, or modify this source, | ||
| 4 | * provided that this copyright notice remains intact. | ||
| 5 | * | 3 | * |
| 6 | * The "grep" command, taken from sash. | 4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> |
| 7 | * This provides basic file searching. | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 8 | * | 19 | * |
| 9 | * Permission to distribute this code under the GPL has been granted. | ||
| 10 | * Modified for busybox by Erik Andersen <andersee@debian.org> <andersen@lineo.com> | ||
| 11 | */ | 20 | */ |
| 12 | 21 | ||
| 13 | #include "internal.h" | 22 | #include "internal.h" |
| 14 | |||
| 15 | #include <stdio.h> | 23 | #include <stdio.h> |
| 16 | #include <dirent.h> | 24 | #include <dirent.h> |
| 17 | #include <errno.h> | 25 | #include <errno.h> |
| @@ -22,95 +30,53 @@ | |||
| 22 | 30 | ||
| 23 | 31 | ||
| 24 | const char grep_usage[] = | 32 | const char grep_usage[] = |
| 25 | "Search the input file(s) for lines matching the given pattern.\n" | 33 | "grep [-ihn]... PATTERN [FILE]...\n" |
| 26 | "\tI search stdin if no files are given.\n" | 34 | "Search for PATTERN in each FILE or standard input.\n\n" |
| 27 | "\tI can't grok full regular expressions.\n" | 35 | "\t-h\tsuppress the prefixing filename on output\n" |
| 28 | "usage: grep [in] PATTERN [FILES]...\n" | 36 | "\t-i\tignore case distinctions\n" |
| 29 | "\ti=ignore case, n=list line numbers\n"; | 37 | "\t-n\tprint line number with output lines\n\n" |
| 30 | 38 | "This version of grep matches strings (not full regexps).\n"; | |
| 31 | 39 | ||
| 32 | 40 | ||
| 33 | /* | 41 | /* |
| 34 | * See if the specified word is found in the specified string. | 42 | * See if the specified needle is found in the specified haystack. |
| 35 | */ | 43 | */ |
| 36 | static int search (const char *string, const char *word, int ignoreCase) | 44 | static int search (const char *haystack, const char *needle, int ignoreCase) |
| 37 | { | 45 | { |
| 38 | const char *cp1; | ||
| 39 | const char *cp2; | ||
| 40 | int len; | ||
| 41 | int lowFirst; | ||
| 42 | int ch1; | ||
| 43 | int ch2; | ||
| 44 | |||
| 45 | len = strlen (word); | ||
| 46 | |||
| 47 | if (!ignoreCase) { | ||
| 48 | while (TRUE) { | ||
| 49 | string = strchr (string, word[0]); | ||
| 50 | |||
| 51 | if (string == NULL) | ||
| 52 | return FALSE; | ||
| 53 | |||
| 54 | if (memcmp (string, word, len) == 0) | ||
| 55 | return TRUE; | ||
| 56 | |||
| 57 | string++; | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | /* | ||
| 62 | * Here if we need to check case independence. | ||
| 63 | * Do the search by lower casing both strings. | ||
| 64 | */ | ||
| 65 | lowFirst = *word; | ||
| 66 | |||
| 67 | if (isupper (lowFirst)) | ||
| 68 | lowFirst = tolower (lowFirst); | ||
| 69 | |||
| 70 | while (TRUE) { | ||
| 71 | while (*string && (*string != lowFirst) && | ||
| 72 | (!isupper (*string) || (tolower (*string) != lowFirst))) { | ||
| 73 | string++; | ||
| 74 | } | ||
| 75 | 46 | ||
| 76 | if (*string == '\0') | 47 | if (ignoreCase == FALSE) { |
| 48 | haystack = strstr (haystack, needle); | ||
| 49 | if (haystack == NULL) | ||
| 77 | return FALSE; | 50 | return FALSE; |
| 78 | 51 | return TRUE; | |
| 79 | cp1 = string; | 52 | } else { |
| 80 | cp2 = word; | 53 | int i; |
| 81 | 54 | char needle1[BUF_SIZE]; | |
| 82 | do { | 55 | char haystack1[BUF_SIZE]; |
| 83 | if (*cp2 == '\0') | 56 | |
| 84 | return TRUE; | 57 | strncpy( haystack1, haystack, sizeof(haystack1)); |
| 85 | 58 | strncpy( needle1, needle, sizeof(needle1)); | |
| 86 | ch1 = *cp1++; | 59 | for( i=0; i<sizeof(haystack1) && haystack1[i]; i++) |
| 87 | 60 | haystack1[i]=tolower( haystack1[i]); | |
| 88 | if (isupper (ch1)) | 61 | for( i=0; i<sizeof(needle1) && needle1[i]; i++) |
| 89 | ch1 = tolower (ch1); | 62 | needle1[i]=tolower( needle1[i]); |
| 90 | 63 | haystack = strstr (haystack1, needle1); | |
| 91 | ch2 = *cp2++; | 64 | if (haystack == NULL) |
| 92 | 65 | return FALSE; | |
| 93 | if (isupper (ch2)) | 66 | return TRUE; |
| 94 | ch2 = tolower (ch2); | ||
| 95 | |||
| 96 | } | ||
| 97 | while (ch1 == ch2); | ||
| 98 | |||
| 99 | string++; | ||
| 100 | } | 67 | } |
| 101 | return (TRUE); | ||
| 102 | } | 68 | } |
| 103 | 69 | ||
| 104 | 70 | ||
| 105 | extern int grep_main (int argc, char **argv) | 71 | extern int grep_main (int argc, char **argv) |
| 106 | { | 72 | { |
| 107 | FILE *fp; | 73 | FILE *fp; |
| 108 | const char *word; | 74 | const char *needle; |
| 109 | const char *name; | 75 | const char *name; |
| 110 | const char *cp; | 76 | const char *cp; |
| 111 | int tellName; | 77 | int tellName=TRUE; |
| 112 | int ignoreCase; | 78 | int ignoreCase=FALSE; |
| 113 | int tellLine; | 79 | int tellLine=FALSE; |
| 114 | long line; | 80 | long line; |
| 115 | char buf[BUF_SIZE]; | 81 | char buf[BUF_SIZE]; |
| 116 | 82 | ||
| @@ -120,8 +86,7 @@ extern int grep_main (int argc, char **argv) | |||
| 120 | argc--; | 86 | argc--; |
| 121 | argv++; | 87 | argv++; |
| 122 | if (argc < 1) { | 88 | if (argc < 1) { |
| 123 | fprintf (stderr, "%s", grep_usage); | 89 | usage(grep_usage); |
| 124 | return 1; | ||
| 125 | } | 90 | } |
| 126 | 91 | ||
| 127 | if (**argv == '-') { | 92 | if (**argv == '-') { |
| @@ -134,29 +99,28 @@ extern int grep_main (int argc, char **argv) | |||
| 134 | ignoreCase = TRUE; | 99 | ignoreCase = TRUE; |
| 135 | break; | 100 | break; |
| 136 | 101 | ||
| 102 | case 'h': | ||
| 103 | tellName = FALSE; | ||
| 104 | break; | ||
| 105 | |||
| 137 | case 'n': | 106 | case 'n': |
| 138 | tellLine = TRUE; | 107 | tellLine = TRUE; |
| 139 | break; | 108 | break; |
| 140 | 109 | ||
| 141 | default: | 110 | default: |
| 142 | fprintf (stderr, "Unknown option\n"); | 111 | usage(grep_usage); |
| 143 | return 1; | ||
| 144 | } | 112 | } |
| 145 | } | 113 | } |
| 146 | 114 | ||
| 147 | word = *argv++; | 115 | needle = *argv++; |
| 148 | argc--; | 116 | argc--; |
| 149 | 117 | ||
| 150 | tellName = (argc > 1); | ||
| 151 | |||
| 152 | while (argc-- > 0) { | 118 | while (argc-- > 0) { |
| 153 | name = *argv++; | 119 | name = *argv++; |
| 154 | 120 | ||
| 155 | fp = fopen (name, "r"); | 121 | fp = fopen (name, "r"); |
| 156 | |||
| 157 | if (fp == NULL) { | 122 | if (fp == NULL) { |
| 158 | perror (name); | 123 | perror (name); |
| 159 | |||
| 160 | continue; | 124 | continue; |
| 161 | } | 125 | } |
| 162 | 126 | ||
| @@ -164,17 +128,16 @@ extern int grep_main (int argc, char **argv) | |||
| 164 | 128 | ||
| 165 | while (fgets (buf, sizeof (buf), fp)) { | 129 | while (fgets (buf, sizeof (buf), fp)) { |
| 166 | line++; | 130 | line++; |
| 167 | |||
| 168 | cp = &buf[strlen (buf) - 1]; | 131 | cp = &buf[strlen (buf) - 1]; |
| 169 | 132 | ||
| 170 | if (*cp != '\n') | 133 | if (*cp != '\n') |
| 171 | fprintf (stderr, "%s: Line too long\n", name); | 134 | fprintf (stderr, "%s: Line too long\n", name); |
| 172 | 135 | ||
| 173 | if (search (buf, word, ignoreCase)) { | 136 | if (search (buf, needle, ignoreCase)==TRUE) { |
| 174 | if (tellName) | 137 | if (tellName==TRUE) |
| 175 | printf ("%s: ", name); | 138 | printf ("%s: ", name); |
| 176 | 139 | ||
| 177 | if (tellLine) | 140 | if (tellLine==TRUE) |
| 178 | printf ("%ld: ", line); | 141 | printf ("%ld: ", line); |
| 179 | 142 | ||
| 180 | fputs (buf, stdout); | 143 | fputs (buf, stdout); |
| @@ -186,7 +149,7 @@ extern int grep_main (int argc, char **argv) | |||
| 186 | 149 | ||
| 187 | fclose (fp); | 150 | fclose (fp); |
| 188 | } | 151 | } |
| 189 | return 0; | 152 | exit( TRUE); |
| 190 | } | 153 | } |
| 191 | 154 | ||
| 192 | 155 | ||
| @@ -1,17 +1,25 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 1999 by David I. Bell | 2 | * Mini grep implementation for busybox |
| 3 | * Permission is granted to use, distribute, or modify this source, | ||
| 4 | * provided that this copyright notice remains intact. | ||
| 5 | * | 3 | * |
| 6 | * The "grep" command, taken from sash. | 4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> |
| 7 | * This provides basic file searching. | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 8 | * | 19 | * |
| 9 | * Permission to distribute this code under the GPL has been granted. | ||
| 10 | * Modified for busybox by Erik Andersen <andersee@debian.org> <andersen@lineo.com> | ||
| 11 | */ | 20 | */ |
| 12 | 21 | ||
| 13 | #include "internal.h" | 22 | #include "internal.h" |
| 14 | |||
| 15 | #include <stdio.h> | 23 | #include <stdio.h> |
| 16 | #include <dirent.h> | 24 | #include <dirent.h> |
| 17 | #include <errno.h> | 25 | #include <errno.h> |
| @@ -22,95 +30,53 @@ | |||
| 22 | 30 | ||
| 23 | 31 | ||
| 24 | const char grep_usage[] = | 32 | const char grep_usage[] = |
| 25 | "Search the input file(s) for lines matching the given pattern.\n" | 33 | "grep [-ihn]... PATTERN [FILE]...\n" |
| 26 | "\tI search stdin if no files are given.\n" | 34 | "Search for PATTERN in each FILE or standard input.\n\n" |
| 27 | "\tI can't grok full regular expressions.\n" | 35 | "\t-h\tsuppress the prefixing filename on output\n" |
| 28 | "usage: grep [in] PATTERN [FILES]...\n" | 36 | "\t-i\tignore case distinctions\n" |
| 29 | "\ti=ignore case, n=list line numbers\n"; | 37 | "\t-n\tprint line number with output lines\n\n" |
| 30 | 38 | "This version of grep matches strings (not full regexps).\n"; | |
| 31 | 39 | ||
| 32 | 40 | ||
| 33 | /* | 41 | /* |
| 34 | * See if the specified word is found in the specified string. | 42 | * See if the specified needle is found in the specified haystack. |
| 35 | */ | 43 | */ |
| 36 | static int search (const char *string, const char *word, int ignoreCase) | 44 | static int search (const char *haystack, const char *needle, int ignoreCase) |
| 37 | { | 45 | { |
| 38 | const char *cp1; | ||
| 39 | const char *cp2; | ||
| 40 | int len; | ||
| 41 | int lowFirst; | ||
| 42 | int ch1; | ||
| 43 | int ch2; | ||
| 44 | |||
| 45 | len = strlen (word); | ||
| 46 | |||
| 47 | if (!ignoreCase) { | ||
| 48 | while (TRUE) { | ||
| 49 | string = strchr (string, word[0]); | ||
| 50 | |||
| 51 | if (string == NULL) | ||
| 52 | return FALSE; | ||
| 53 | |||
| 54 | if (memcmp (string, word, len) == 0) | ||
| 55 | return TRUE; | ||
| 56 | |||
| 57 | string++; | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | /* | ||
| 62 | * Here if we need to check case independence. | ||
| 63 | * Do the search by lower casing both strings. | ||
| 64 | */ | ||
| 65 | lowFirst = *word; | ||
| 66 | |||
| 67 | if (isupper (lowFirst)) | ||
| 68 | lowFirst = tolower (lowFirst); | ||
| 69 | |||
| 70 | while (TRUE) { | ||
| 71 | while (*string && (*string != lowFirst) && | ||
| 72 | (!isupper (*string) || (tolower (*string) != lowFirst))) { | ||
| 73 | string++; | ||
| 74 | } | ||
| 75 | 46 | ||
| 76 | if (*string == '\0') | 47 | if (ignoreCase == FALSE) { |
| 48 | haystack = strstr (haystack, needle); | ||
| 49 | if (haystack == NULL) | ||
| 77 | return FALSE; | 50 | return FALSE; |
| 78 | 51 | return TRUE; | |
| 79 | cp1 = string; | 52 | } else { |
| 80 | cp2 = word; | 53 | int i; |
| 81 | 54 | char needle1[BUF_SIZE]; | |
| 82 | do { | 55 | char haystack1[BUF_SIZE]; |
| 83 | if (*cp2 == '\0') | 56 | |
| 84 | return TRUE; | 57 | strncpy( haystack1, haystack, sizeof(haystack1)); |
| 85 | 58 | strncpy( needle1, needle, sizeof(needle1)); | |
| 86 | ch1 = *cp1++; | 59 | for( i=0; i<sizeof(haystack1) && haystack1[i]; i++) |
| 87 | 60 | haystack1[i]=tolower( haystack1[i]); | |
| 88 | if (isupper (ch1)) | 61 | for( i=0; i<sizeof(needle1) && needle1[i]; i++) |
| 89 | ch1 = tolower (ch1); | 62 | needle1[i]=tolower( needle1[i]); |
| 90 | 63 | haystack = strstr (haystack1, needle1); | |
| 91 | ch2 = *cp2++; | 64 | if (haystack == NULL) |
| 92 | 65 | return FALSE; | |
| 93 | if (isupper (ch2)) | 66 | return TRUE; |
| 94 | ch2 = tolower (ch2); | ||
| 95 | |||
| 96 | } | ||
| 97 | while (ch1 == ch2); | ||
| 98 | |||
| 99 | string++; | ||
| 100 | } | 67 | } |
| 101 | return (TRUE); | ||
| 102 | } | 68 | } |
| 103 | 69 | ||
| 104 | 70 | ||
| 105 | extern int grep_main (int argc, char **argv) | 71 | extern int grep_main (int argc, char **argv) |
| 106 | { | 72 | { |
| 107 | FILE *fp; | 73 | FILE *fp; |
| 108 | const char *word; | 74 | const char *needle; |
| 109 | const char *name; | 75 | const char *name; |
| 110 | const char *cp; | 76 | const char *cp; |
| 111 | int tellName; | 77 | int tellName=TRUE; |
| 112 | int ignoreCase; | 78 | int ignoreCase=FALSE; |
| 113 | int tellLine; | 79 | int tellLine=FALSE; |
| 114 | long line; | 80 | long line; |
| 115 | char buf[BUF_SIZE]; | 81 | char buf[BUF_SIZE]; |
| 116 | 82 | ||
| @@ -120,8 +86,7 @@ extern int grep_main (int argc, char **argv) | |||
| 120 | argc--; | 86 | argc--; |
| 121 | argv++; | 87 | argv++; |
| 122 | if (argc < 1) { | 88 | if (argc < 1) { |
| 123 | fprintf (stderr, "%s", grep_usage); | 89 | usage(grep_usage); |
| 124 | return 1; | ||
| 125 | } | 90 | } |
| 126 | 91 | ||
| 127 | if (**argv == '-') { | 92 | if (**argv == '-') { |
| @@ -134,29 +99,28 @@ extern int grep_main (int argc, char **argv) | |||
| 134 | ignoreCase = TRUE; | 99 | ignoreCase = TRUE; |
| 135 | break; | 100 | break; |
| 136 | 101 | ||
| 102 | case 'h': | ||
| 103 | tellName = FALSE; | ||
| 104 | break; | ||
| 105 | |||
| 137 | case 'n': | 106 | case 'n': |
| 138 | tellLine = TRUE; | 107 | tellLine = TRUE; |
| 139 | break; | 108 | break; |
| 140 | 109 | ||
| 141 | default: | 110 | default: |
| 142 | fprintf (stderr, "Unknown option\n"); | 111 | usage(grep_usage); |
| 143 | return 1; | ||
| 144 | } | 112 | } |
| 145 | } | 113 | } |
| 146 | 114 | ||
| 147 | word = *argv++; | 115 | needle = *argv++; |
| 148 | argc--; | 116 | argc--; |
| 149 | 117 | ||
| 150 | tellName = (argc > 1); | ||
| 151 | |||
| 152 | while (argc-- > 0) { | 118 | while (argc-- > 0) { |
| 153 | name = *argv++; | 119 | name = *argv++; |
| 154 | 120 | ||
| 155 | fp = fopen (name, "r"); | 121 | fp = fopen (name, "r"); |
| 156 | |||
| 157 | if (fp == NULL) { | 122 | if (fp == NULL) { |
| 158 | perror (name); | 123 | perror (name); |
| 159 | |||
| 160 | continue; | 124 | continue; |
| 161 | } | 125 | } |
| 162 | 126 | ||
| @@ -164,17 +128,16 @@ extern int grep_main (int argc, char **argv) | |||
| 164 | 128 | ||
| 165 | while (fgets (buf, sizeof (buf), fp)) { | 129 | while (fgets (buf, sizeof (buf), fp)) { |
| 166 | line++; | 130 | line++; |
| 167 | |||
| 168 | cp = &buf[strlen (buf) - 1]; | 131 | cp = &buf[strlen (buf) - 1]; |
| 169 | 132 | ||
| 170 | if (*cp != '\n') | 133 | if (*cp != '\n') |
| 171 | fprintf (stderr, "%s: Line too long\n", name); | 134 | fprintf (stderr, "%s: Line too long\n", name); |
| 172 | 135 | ||
| 173 | if (search (buf, word, ignoreCase)) { | 136 | if (search (buf, needle, ignoreCase)==TRUE) { |
| 174 | if (tellName) | 137 | if (tellName==TRUE) |
| 175 | printf ("%s: ", name); | 138 | printf ("%s: ", name); |
| 176 | 139 | ||
| 177 | if (tellLine) | 140 | if (tellLine==TRUE) |
| 178 | printf ("%ld: ", line); | 141 | printf ("%ld: ", line); |
| 179 | 142 | ||
| 180 | fputs (buf, stdout); | 143 | fputs (buf, stdout); |
| @@ -186,7 +149,7 @@ extern int grep_main (int argc, char **argv) | |||
| 186 | 149 | ||
| 187 | fclose (fp); | 150 | fclose (fp); |
| 188 | } | 151 | } |
| 189 | return 0; | 152 | exit( TRUE); |
| 190 | } | 153 | } |
| 191 | 154 | ||
| 192 | 155 | ||
diff --git a/internal.h b/internal.h index a77ac38bb..8bf9c3eb4 100644 --- a/internal.h +++ b/internal.h | |||
| @@ -76,6 +76,7 @@ extern int init_main(int argc, char** argv); | |||
| 76 | extern int kill_main(int argc, char** argv); | 76 | extern int kill_main(int argc, char** argv); |
| 77 | extern int length_main(int argc, char** argv); | 77 | extern int length_main(int argc, char** argv); |
| 78 | extern int ln_main(int argc, char** argv); | 78 | extern int ln_main(int argc, char** argv); |
| 79 | extern int loadfont_main(int argc, char** argv); | ||
| 79 | extern int loadkmap_main(int argc, char** argv); | 80 | extern int loadkmap_main(int argc, char** argv); |
| 80 | extern int losetup_main(int argc, char** argv); | 81 | extern int losetup_main(int argc, char** argv); |
| 81 | extern int ls_main(int argc, char** argv); | 82 | extern int ls_main(int argc, char** argv); |
diff --git a/loadfont.c b/loadfont.c new file mode 100644 index 000000000..a10fa8a69 --- /dev/null +++ b/loadfont.c | |||
| @@ -0,0 +1,234 @@ | |||
| 1 | /* | ||
| 2 | * loadfont.c - Eugene Crosser & Andries Brouwer | ||
| 3 | * | ||
| 4 | * Version 0.96bb | ||
| 5 | * | ||
| 6 | * Loads the console font, and possibly the corresponding screen map(s). | ||
| 7 | * (Adapted for busybox by Matej Vela.) | ||
| 8 | */ | ||
| 9 | #include "internal.h" | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <string.h> | ||
| 12 | #include <fcntl.h> | ||
| 13 | #include <memory.h> | ||
| 14 | #include <stdlib.h> | ||
| 15 | #include <unistd.h> | ||
| 16 | #include <sys/types.h> | ||
| 17 | #include <sys/stat.h> | ||
| 18 | #include <dirent.h> | ||
| 19 | #include <errno.h> | ||
| 20 | #include <sys/ioctl.h> | ||
| 21 | #include <sys/kd.h> | ||
| 22 | #include <endian.h> | ||
| 23 | |||
| 24 | #define PSF_MAGIC1 0x36 | ||
| 25 | #define PSF_MAGIC2 0x04 | ||
| 26 | |||
| 27 | #define PSF_MODE512 0x01 | ||
| 28 | #define PSF_MODEHASTAB 0x02 | ||
| 29 | #define PSF_MAXMODE 0x03 | ||
| 30 | #define PSF_SEPARATOR 0xFFFF | ||
| 31 | |||
| 32 | static const char loadfont_usage[] = "loadfont\n" | ||
| 33 | "\n" | ||
| 34 | "\tLoad a console font from standard input.\n" | ||
| 35 | "\n"; | ||
| 36 | |||
| 37 | struct psf_header | ||
| 38 | { | ||
| 39 | unsigned char magic1, magic2; /* Magic number */ | ||
| 40 | unsigned char mode; /* PSF font mode */ | ||
| 41 | unsigned char charsize; /* Character size */ | ||
| 42 | }; | ||
| 43 | |||
| 44 | #define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2) | ||
| 45 | |||
| 46 | static void loadnewfont(int fd); | ||
| 47 | |||
| 48 | extern int | ||
| 49 | loadfont_main(int argc, char **argv) | ||
| 50 | { | ||
| 51 | int fd; | ||
| 52 | |||
| 53 | fd = open("/dev/tty0", O_RDWR); | ||
| 54 | if (fd < 0) { | ||
| 55 | fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno)); | ||
| 56 | return 1; | ||
| 57 | } | ||
| 58 | loadnewfont(fd); | ||
| 59 | |||
| 60 | return 0; | ||
| 61 | } | ||
| 62 | |||
| 63 | static void | ||
| 64 | do_loadfont(int fd, char *inbuf, int unit, int fontsize) { | ||
| 65 | char buf[16384]; | ||
| 66 | int i; | ||
| 67 | |||
| 68 | memset(buf,0,sizeof(buf)); | ||
| 69 | |||
| 70 | if (unit < 1 || unit > 32) { | ||
| 71 | fprintf(stderr, "Bad character size %d\n", unit); | ||
| 72 | exit(1); | ||
| 73 | } | ||
| 74 | |||
| 75 | for (i = 0; i < fontsize; i++) | ||
| 76 | memcpy(buf+(32*i), inbuf+(unit*i), unit); | ||
| 77 | |||
| 78 | #if defined( PIO_FONTX ) && !defined( sparc ) | ||
| 79 | { | ||
| 80 | struct consolefontdesc cfd; | ||
| 81 | |||
| 82 | cfd.charcount = fontsize; | ||
| 83 | cfd.charheight = unit; | ||
| 84 | cfd.chardata = buf; | ||
| 85 | |||
| 86 | if (ioctl(fd, PIO_FONTX, &cfd) == 0) | ||
| 87 | return; /* success */ | ||
| 88 | perror("PIO_FONTX ioctl error (trying PIO_FONT)"); | ||
| 89 | } | ||
| 90 | #endif | ||
| 91 | if (ioctl(fd, PIO_FONT, buf)) { | ||
| 92 | perror("PIO_FONT ioctl error"); | ||
| 93 | exit(1); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | static void | ||
| 98 | do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) { | ||
| 99 | struct unimapinit advice; | ||
| 100 | struct unimapdesc ud; | ||
| 101 | struct unipair *up; | ||
| 102 | int ct = 0, maxct; | ||
| 103 | int glyph; | ||
| 104 | u_short unicode; | ||
| 105 | |||
| 106 | maxct = tailsz; /* more than enough */ | ||
| 107 | up = (struct unipair *) malloc(maxct * sizeof(struct unipair)); | ||
| 108 | if (!up) { | ||
| 109 | fprintf(stderr, "Out of memory?\n"); | ||
| 110 | exit(1); | ||
| 111 | } | ||
| 112 | for (glyph = 0; glyph < fontsize; glyph++) { | ||
| 113 | while (tailsz >= 2) { | ||
| 114 | unicode = (((u_short) inbuf[1]) << 8) + inbuf[0]; | ||
| 115 | tailsz -= 2; | ||
| 116 | inbuf += 2; | ||
| 117 | if (unicode == PSF_SEPARATOR) | ||
| 118 | break; | ||
| 119 | up[ct].unicode = unicode; | ||
| 120 | up[ct].fontpos = glyph; | ||
| 121 | ct++; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | /* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP | ||
| 126 | this printf did not work on many kernels */ | ||
| 127 | |||
| 128 | advice.advised_hashsize = 0; | ||
| 129 | advice.advised_hashstep = 0; | ||
| 130 | advice.advised_hashlevel = 0; | ||
| 131 | if(ioctl(fd, PIO_UNIMAPCLR, &advice)) { | ||
| 132 | #ifdef ENOIOCTLCMD | ||
| 133 | if (errno == ENOIOCTLCMD) { | ||
| 134 | fprintf(stderr, "It seems this kernel is older than 1.1.92\n"); | ||
| 135 | fprintf(stderr, "No Unicode mapping table loaded.\n"); | ||
| 136 | } else | ||
| 137 | #endif | ||
| 138 | perror("PIO_UNIMAPCLR"); | ||
| 139 | exit(1); | ||
| 140 | } | ||
| 141 | ud.entry_ct = ct; | ||
| 142 | ud.entries = up; | ||
| 143 | if(ioctl(fd, PIO_UNIMAP, &ud)) { | ||
| 144 | #if 0 | ||
| 145 | if (errno == ENOMEM) { | ||
| 146 | /* change advice parameters */ | ||
| 147 | } | ||
| 148 | #endif | ||
| 149 | perror("PIO_UNIMAP"); | ||
| 150 | exit(1); | ||
| 151 | } | ||
| 152 | } | ||
| 153 | |||
| 154 | static void | ||
| 155 | loadnewfont(int fd) { | ||
| 156 | int unit; | ||
| 157 | char inbuf[32768]; /* primitive */ | ||
| 158 | int inputlth, offset; | ||
| 159 | |||
| 160 | /* | ||
| 161 | * We used to look at the length of the input file | ||
| 162 | * with stat(); now that we accept compressed files, | ||
| 163 | * just read the entire file. | ||
| 164 | */ | ||
| 165 | inputlth = fread(inbuf, 1, sizeof(inbuf), stdin); | ||
| 166 | if (ferror(stdin)) { | ||
| 167 | perror("Error reading input font"); | ||
| 168 | exit(1); | ||
| 169 | } | ||
| 170 | /* use malloc/realloc in case of giant files; | ||
| 171 | maybe these do not occur: 16kB for the font, | ||
| 172 | and 16kB for the map leaves 32 unicode values | ||
| 173 | for each font position */ | ||
| 174 | if (!feof(stdin)) { | ||
| 175 | perror("Font too large"); | ||
| 176 | exit(1); | ||
| 177 | } | ||
| 178 | |||
| 179 | /* test for psf first */ | ||
| 180 | { | ||
| 181 | struct psf_header psfhdr; | ||
| 182 | int fontsize; | ||
| 183 | int hastable; | ||
| 184 | int head0, head; | ||
| 185 | |||
| 186 | if (inputlth < sizeof(struct psf_header)) | ||
| 187 | goto no_psf; | ||
| 188 | |||
| 189 | psfhdr = * (struct psf_header *) &inbuf[0]; | ||
| 190 | |||
| 191 | if (!PSF_MAGIC_OK(psfhdr)) | ||
| 192 | goto no_psf; | ||
| 193 | |||
| 194 | if (psfhdr.mode > PSF_MAXMODE) { | ||
| 195 | fprintf(stderr, "Unsupported psf file mode\n"); | ||
| 196 | exit(1); | ||
| 197 | } | ||
| 198 | fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256); | ||
| 199 | #if !defined( PIO_FONTX ) || defined( sparc ) | ||
| 200 | if (fontsize != 256) { | ||
| 201 | fprintf(stderr, "Only fontsize 256 supported\n"); | ||
| 202 | exit(1); | ||
| 203 | } | ||
| 204 | #endif | ||
| 205 | hastable = (psfhdr.mode & PSF_MODEHASTAB); | ||
| 206 | unit = psfhdr.charsize; | ||
| 207 | head0 = sizeof(struct psf_header); | ||
| 208 | head = head0 + fontsize*unit; | ||
| 209 | if (head > inputlth || (!hastable && head != inputlth)) { | ||
| 210 | fprintf(stderr, "Input file: bad length\n"); | ||
| 211 | exit(1); | ||
| 212 | } | ||
| 213 | do_loadfont(fd, inbuf + head0, unit, fontsize); | ||
| 214 | if (hastable) | ||
| 215 | do_loadtable(fd, inbuf + head, inputlth-head, fontsize); | ||
| 216 | return; | ||
| 217 | } | ||
| 218 | no_psf: | ||
| 219 | |||
| 220 | /* file with three code pages? */ | ||
| 221 | if (inputlth == 9780) { | ||
| 222 | offset = 40; | ||
| 223 | unit = 16; | ||
| 224 | } else { | ||
| 225 | /* bare font */ | ||
| 226 | if (inputlth & 0377) { | ||
| 227 | fprintf(stderr, "Bad input file size\n"); | ||
| 228 | exit(1); | ||
| 229 | } | ||
| 230 | offset = 0; | ||
| 231 | unit = inputlth/256; | ||
| 232 | } | ||
| 233 | do_loadfont(fd, inbuf+offset, unit, 256); | ||
| 234 | } | ||
