Home | History | Annotate | Line # | Download | only in sort
init.c revision 1.17.16.1
      1  1.17.16.1      yamt /*	$NetBSD: init.c,v 1.17.16.1 2008/05/18 12:36:10 yamt Exp $	*/
      2        1.9  jdolecek 
      3        1.9  jdolecek /*-
      4        1.9  jdolecek  * Copyright (c) 2000-2003 The NetBSD Foundation, Inc.
      5        1.9  jdolecek  * All rights reserved.
      6        1.9  jdolecek  *
      7        1.9  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8        1.9  jdolecek  * by Ben Harris and Jaromir Dolecek.
      9        1.9  jdolecek  *
     10        1.9  jdolecek  * Redistribution and use in source and binary forms, with or without
     11        1.9  jdolecek  * modification, are permitted provided that the following conditions
     12        1.9  jdolecek  * are met:
     13        1.9  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14        1.9  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15        1.9  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.9  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17        1.9  jdolecek  *    documentation and/or other materials provided with the distribution.
     18        1.9  jdolecek  *
     19        1.9  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.9  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.9  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.9  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.9  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.9  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.9  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.9  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.9  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.9  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.9  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     30        1.9  jdolecek  */
     31        1.2     bjh21 
     32        1.1     bjh21 /*-
     33        1.1     bjh21  * Copyright (c) 1993
     34        1.1     bjh21  *	The Regents of the University of California.  All rights reserved.
     35        1.1     bjh21  *
     36        1.1     bjh21  * This code is derived from software contributed to Berkeley by
     37        1.1     bjh21  * Peter McIlroy.
     38        1.1     bjh21  *
     39        1.1     bjh21  * Redistribution and use in source and binary forms, with or without
     40        1.1     bjh21  * modification, are permitted provided that the following conditions
     41        1.1     bjh21  * are met:
     42        1.1     bjh21  * 1. Redistributions of source code must retain the above copyright
     43        1.1     bjh21  *    notice, this list of conditions and the following disclaimer.
     44        1.1     bjh21  * 2. Redistributions in binary form must reproduce the above copyright
     45        1.1     bjh21  *    notice, this list of conditions and the following disclaimer in the
     46        1.1     bjh21  *    documentation and/or other materials provided with the distribution.
     47        1.8       agc  * 3. Neither the name of the University nor the names of its contributors
     48        1.1     bjh21  *    may be used to endorse or promote products derived from this software
     49        1.1     bjh21  *    without specific prior written permission.
     50        1.1     bjh21  *
     51        1.1     bjh21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     52        1.1     bjh21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     53        1.1     bjh21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     54        1.1     bjh21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     55        1.1     bjh21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     56        1.1     bjh21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     57        1.1     bjh21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     58        1.1     bjh21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     59        1.1     bjh21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     60        1.1     bjh21  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     61        1.1     bjh21  * SUCH DAMAGE.
     62        1.1     bjh21  */
     63        1.1     bjh21 
     64        1.2     bjh21 #include "sort.h"
     65        1.2     bjh21 
     66        1.1     bjh21 #ifndef lint
     67  1.17.16.1      yamt __RCSID("$NetBSD: init.c,v 1.17.16.1 2008/05/18 12:36:10 yamt Exp $");
     68        1.2     bjh21 __SCCSID("@(#)init.c	8.1 (Berkeley) 6/6/93");
     69        1.1     bjh21 #endif /* not lint */
     70        1.1     bjh21 
     71        1.1     bjh21 #include <ctype.h>
     72        1.1     bjh21 #include <string.h>
     73        1.1     bjh21 
     74        1.2     bjh21 static void insertcol __P((struct field *));
     75        1.3  jdolecek static const char *setcolumn __P((const char *, struct field *, int));
     76        1.2     bjh21 
     77        1.1     bjh21 u_char gweights[NBINS];
     78        1.1     bjh21 
     79        1.1     bjh21 /*
     80        1.4  jdolecek  * masks of ignored characters.  Alltable is 256 ones.
     81        1.4  jdolecek  */
     82        1.4  jdolecek static u_char alltable[NBINS], dtable[NBINS], itable[NBINS];
     83        1.4  jdolecek 
     84        1.4  jdolecek /*
     85       1.12  jdolecek  * parsed key options
     86       1.12  jdolecek  */
     87       1.13    itojun struct coldesc *clist = NULL;
     88       1.12  jdolecek int ncols = 0;
     89       1.12  jdolecek 
     90       1.12  jdolecek /*
     91        1.1     bjh21  * clist (list of columns which correspond to one or more icol or tcol)
     92        1.1     bjh21  * is in increasing order of columns.
     93        1.1     bjh21  * Fields are kept in increasing order of fields.
     94        1.1     bjh21  */
     95        1.1     bjh21 
     96        1.1     bjh21 /*
     97        1.1     bjh21  * keep clist in order--inserts a column in a sorted array
     98        1.1     bjh21  */
     99        1.1     bjh21 static void
    100        1.1     bjh21 insertcol(field)
    101        1.1     bjh21 	struct field *field;
    102        1.1     bjh21 {
    103        1.1     bjh21 	int i;
    104       1.13    itojun 	struct coldesc *p;
    105       1.12  jdolecek 
    106       1.12  jdolecek 	/* Make space for new item */
    107       1.15  jdolecek 	p = realloc(clist, (ncols + 2) * sizeof(*clist));
    108       1.13    itojun 	if (!p)
    109       1.13    itojun 		err(1, "realloc");
    110       1.13    itojun 	clist = p;
    111       1.13    itojun 	memset(&clist[ncols], 0, sizeof(clist[ncols]));
    112       1.12  jdolecek 
    113        1.1     bjh21 	for (i = 0; i < ncols; i++)
    114        1.1     bjh21 		if (field->icol.num <= clist[i].num)
    115        1.1     bjh21 			break;
    116        1.1     bjh21 	if (field->icol.num != clist[i].num) {
    117        1.1     bjh21 		memmove(clist+i+1, clist+i, sizeof(COLDESC)*(ncols-i));
    118        1.1     bjh21 		clist[i].num = field->icol.num;
    119        1.1     bjh21 		ncols++;
    120        1.1     bjh21 	}
    121        1.1     bjh21 	if (field->tcol.num && field->tcol.num != field->icol.num) {
    122        1.1     bjh21 		for (i = 0; i < ncols; i++)
    123        1.1     bjh21 			if (field->tcol.num <= clist[i].num)
    124        1.1     bjh21 				break;
    125        1.1     bjh21 		if (field->tcol.num != clist[i].num) {
    126        1.1     bjh21 			memmove(clist+i+1, clist+i,sizeof(COLDESC)*(ncols-i));
    127        1.1     bjh21 			clist[i].num = field->tcol.num;
    128        1.1     bjh21 			ncols++;
    129        1.1     bjh21 		}
    130        1.1     bjh21 	}
    131        1.1     bjh21 }
    132        1.1     bjh21 
    133        1.1     bjh21 /*
    134        1.1     bjh21  * matches fields with the appropriate columns--n^2 but who cares?
    135        1.1     bjh21  */
    136        1.1     bjh21 void
    137        1.1     bjh21 fldreset(fldtab)
    138        1.1     bjh21 	struct field *fldtab;
    139        1.1     bjh21 {
    140        1.1     bjh21 	int i;
    141       1.13    itojun 
    142       1.13    itojun 	fldtab[0].tcol.p = clist + ncols - 1;
    143        1.1     bjh21 	for (++fldtab; fldtab->icol.num; ++fldtab) {
    144        1.5  jdolecek 		for (i = 0; fldtab->icol.num != clist[i].num; i++)
    145        1.5  jdolecek 			;
    146        1.1     bjh21 		fldtab->icol.p = clist + i;
    147        1.1     bjh21 		if (!fldtab->tcol.num)
    148        1.1     bjh21 			continue;
    149        1.5  jdolecek 		for (i = 0; fldtab->tcol.num != clist[i].num; i++)
    150        1.5  jdolecek 			;
    151        1.1     bjh21 		fldtab->tcol.p = clist + i;
    152        1.1     bjh21 	}
    153        1.1     bjh21 }
    154        1.1     bjh21 
    155        1.1     bjh21 /*
    156        1.1     bjh21  * interprets a column in a -k field
    157        1.1     bjh21  */
    158        1.3  jdolecek static const char *
    159        1.1     bjh21 setcolumn(pos, cur_fld, gflag)
    160        1.3  jdolecek 	const char *pos;
    161        1.1     bjh21 	struct field *cur_fld;
    162        1.1     bjh21 	int gflag;
    163        1.1     bjh21 {
    164        1.1     bjh21 	struct column *col;
    165       1.10  jdolecek 	char *npos;
    166        1.1     bjh21 	int tmp;
    167       1.10  jdolecek 	col = cur_fld->icol.num ? (&cur_fld->tcol) : (&cur_fld->icol);
    168       1.10  jdolecek 	col->num = (int) strtol(pos, &npos, 10);
    169       1.10  jdolecek 	pos = npos;
    170        1.1     bjh21 	if (col->num <= 0 && !(col->num == 0 && col == &(cur_fld->tcol)))
    171        1.1     bjh21 		errx(2, "field numbers must be positive");
    172        1.1     bjh21 	if (*pos == '.') {
    173        1.1     bjh21 		if (!col->num)
    174        1.1     bjh21 			errx(2, "cannot indent end of line");
    175        1.6   thorpej 		++pos;
    176       1.10  jdolecek 		col->indent = (int) strtol(pos, &npos, 10);
    177       1.10  jdolecek 		pos = npos;
    178        1.1     bjh21 		if (&cur_fld->icol == col)
    179        1.1     bjh21 			col->indent--;
    180        1.1     bjh21 		if (col->indent < 0)
    181        1.1     bjh21 			errx(2, "illegal offset");
    182        1.1     bjh21 	}
    183       1.10  jdolecek 	for(; (tmp = optval(*pos, cur_fld->tcol.num)); pos++)
    184       1.10  jdolecek 		cur_fld->flags |= tmp;
    185        1.1     bjh21 	if (cur_fld->icol.num == 0)
    186        1.1     bjh21 		cur_fld->icol.num = 1;
    187        1.1     bjh21 	return (pos);
    188        1.1     bjh21 }
    189        1.1     bjh21 
    190        1.1     bjh21 int
    191        1.1     bjh21 setfield(pos, cur_fld, gflag)
    192        1.3  jdolecek 	const char *pos;
    193        1.1     bjh21 	struct field *cur_fld;
    194        1.1     bjh21 	int gflag;
    195        1.1     bjh21 {
    196        1.1     bjh21 	int tmp;
    197        1.4  jdolecek 
    198        1.1     bjh21 	cur_fld->weights = ascii;
    199        1.1     bjh21 	cur_fld->mask = alltable;
    200        1.4  jdolecek 
    201        1.1     bjh21 	pos = setcolumn(pos, cur_fld, gflag);
    202        1.1     bjh21 	if (*pos == '\0')			/* key extends to EOL. */
    203        1.1     bjh21 		cur_fld->tcol.num = 0;
    204        1.1     bjh21 	else {
    205        1.1     bjh21 		if (*pos != ',')
    206        1.1     bjh21 			errx(2, "illegal field descriptor");
    207        1.1     bjh21 		setcolumn((++pos), cur_fld, gflag);
    208        1.1     bjh21 	}
    209        1.1     bjh21 	if (!cur_fld->flags)
    210        1.1     bjh21 		cur_fld->flags = gflag;
    211        1.1     bjh21 	tmp = cur_fld->flags;
    212        1.1     bjh21 
    213        1.1     bjh21 	/*
    214        1.1     bjh21 	 * Assign appropriate mask table and weight table.
    215        1.1     bjh21 	 * If the global weights are reversed, the local field
    216        1.1     bjh21 	 * must be "re-reversed".
    217        1.1     bjh21 	 */
    218        1.4  jdolecek 	if (((tmp & R) ^ (gflag & R)) && (tmp & F))
    219        1.1     bjh21 		cur_fld->weights = RFtable;
    220        1.1     bjh21 	else if (tmp & F)
    221        1.1     bjh21 		cur_fld->weights = Ftable;
    222        1.1     bjh21 	else if ((tmp & R) ^ (gflag & R))
    223        1.1     bjh21 		cur_fld->weights = Rascii;
    224        1.4  jdolecek 
    225        1.1     bjh21 	if (tmp & I)
    226        1.1     bjh21 		cur_fld->mask = itable;
    227        1.1     bjh21 	else if (tmp & D)
    228        1.1     bjh21 		cur_fld->mask = dtable;
    229        1.4  jdolecek 
    230        1.1     bjh21 	cur_fld->flags |= (gflag & (BI | BT));
    231        1.1     bjh21 	if (!cur_fld->tcol.indent)	/* BT has no meaning at end of field */
    232        1.4  jdolecek 		cur_fld->flags &= ~BT;
    233        1.4  jdolecek 
    234        1.1     bjh21 	if (cur_fld->tcol.num && !(!(cur_fld->flags & BI)
    235        1.1     bjh21 	    && cur_fld->flags & BT) && (cur_fld->tcol.num <= cur_fld->icol.num
    236       1.17  jdolecek 	    && cur_fld->tcol.indent != 0 /* == 0 -> end of field, i.e. okay */
    237        1.1     bjh21 	    && cur_fld->tcol.indent < cur_fld->icol.indent))
    238        1.1     bjh21 		errx(2, "fields out of order");
    239        1.1     bjh21 	insertcol(cur_fld);
    240        1.1     bjh21 	return (cur_fld->tcol.num);
    241        1.1     bjh21 }
    242        1.1     bjh21 
    243        1.1     bjh21 int
    244        1.1     bjh21 optval(desc, tcolflag)
    245        1.1     bjh21 	int desc, tcolflag;
    246        1.1     bjh21 {
    247        1.1     bjh21 	switch(desc) {
    248        1.1     bjh21 		case 'b':
    249        1.1     bjh21 			if (!tcolflag)
    250        1.5  jdolecek 				return (BI);
    251        1.1     bjh21 			else
    252        1.5  jdolecek 				return (BT);
    253        1.5  jdolecek 		case 'd': return (D);
    254        1.5  jdolecek 		case 'f': return (F);
    255        1.5  jdolecek 		case 'i': return (I);
    256        1.5  jdolecek 		case 'n': return (N);
    257        1.5  jdolecek 		case 'r': return (R);
    258        1.5  jdolecek 		default:  return (0);
    259        1.1     bjh21 	}
    260        1.1     bjh21 }
    261        1.1     bjh21 
    262       1.11  jdolecek /*
    263       1.11  jdolecek  * Replace historic +SPEC arguments with appropriate -kSPEC.
    264       1.11  jdolecek  */
    265        1.1     bjh21 void
    266        1.1     bjh21 fixit(argc, argv)
    267        1.1     bjh21 	int *argc;
    268        1.1     bjh21 	char **argv;
    269        1.1     bjh21 {
    270       1.11  jdolecek 	int i, j, fplus=0;
    271       1.11  jdolecek 	char *vpos, *tpos, spec[20];
    272       1.11  jdolecek 	int col, indent;
    273       1.11  jdolecek 	size_t sz;
    274        1.1     bjh21 
    275        1.1     bjh21 	for (i = 1; i < *argc; i++) {
    276       1.11  jdolecek 		if (argv[i][0] != '+' && !fplus)
    277       1.11  jdolecek 			continue;
    278       1.11  jdolecek 
    279       1.16       dsl 		if (fplus && (argv[i][0] != '-' || !isdigit((unsigned char)argv[i][1]))) {
    280       1.11  jdolecek 			fplus = 0;
    281       1.14  jdolecek 			if (argv[i][0] != '+') {
    282       1.14  jdolecek 				/* not a -POS argument, skip */
    283       1.14  jdolecek 				continue;
    284       1.14  jdolecek 			}
    285       1.11  jdolecek 		}
    286       1.11  jdolecek 
    287       1.11  jdolecek 		/* parse spec */
    288       1.11  jdolecek 		tpos = argv[i]+1;
    289       1.11  jdolecek 		col = (int)strtol(tpos, &tpos, 10);
    290       1.11  jdolecek 		if (*tpos == '.') {
    291       1.11  jdolecek 			++tpos;
    292       1.11  jdolecek 			indent = (int) strtol(tpos, &tpos, 10);
    293       1.11  jdolecek 		} else
    294       1.11  jdolecek 			indent = 0;
    295       1.11  jdolecek 		/* tpos points to optional flags now */
    296       1.11  jdolecek 
    297       1.11  jdolecek 		/*
    298       1.11  jdolecek 		 * For x.y, the obsolescent variant assumed 0 == beginning
    299       1.11  jdolecek 		 * of line, while the new form uses 0 == end of line.
    300       1.11  jdolecek 		 * Convert accordingly.
    301       1.11  jdolecek 		 */
    302       1.11  jdolecek 		if (!fplus) {
    303       1.11  jdolecek 			/* +POS */
    304       1.11  jdolecek 			col += 1;
    305       1.11  jdolecek 			indent += 1;
    306       1.11  jdolecek 		} else {
    307       1.11  jdolecek 			/* -POS */
    308       1.11  jdolecek 			if (indent > 0)
    309       1.11  jdolecek 				col += 1;
    310       1.11  jdolecek 		}
    311       1.11  jdolecek 
    312       1.11  jdolecek 		/* new style spec */
    313       1.11  jdolecek 		sz = snprintf(spec, sizeof(spec), "%d.%d%s", col, indent,
    314       1.11  jdolecek 		    tpos);
    315       1.11  jdolecek 
    316       1.11  jdolecek 		if (!fplus) {
    317       1.11  jdolecek 			/* Replace the +POS argument with new-style -kSPEC */
    318       1.11  jdolecek 			asprintf(&vpos, "-k%s", spec);
    319        1.1     bjh21 			argv[i] = vpos;
    320       1.11  jdolecek 			fplus = 1;
    321       1.11  jdolecek 		} else {
    322       1.11  jdolecek 			/*
    323       1.11  jdolecek 			 * Append the spec to one previously generated from
    324       1.11  jdolecek 			 * +POS argument, and remove the argv element.
    325       1.11  jdolecek 			 */
    326       1.11  jdolecek 			asprintf(&vpos, "%s,%s", argv[i-1], spec);
    327       1.11  jdolecek 			free(argv[i-1]);
    328       1.11  jdolecek 			argv[i-1] = vpos;
    329       1.11  jdolecek 			for (j=i; j < *argc; j++)
    330       1.11  jdolecek 				argv[j] = argv[j+1];
    331       1.11  jdolecek 			*argc -= 1;
    332       1.14  jdolecek 			i--;
    333        1.1     bjh21 		}
    334        1.1     bjh21 	}
    335        1.1     bjh21 }
    336        1.1     bjh21 
    337        1.1     bjh21 /*
    338        1.1     bjh21  * ascii, Rascii, Ftable, and RFtable map
    339        1.1     bjh21  * REC_D -> REC_D;  {not REC_D} -> {not REC_D}.
    340        1.1     bjh21  * gweights maps REC_D -> (0 or 255); {not REC_D} -> {not gweights[REC_D]}.
    341        1.1     bjh21  * Note: when sorting in forward order, to encode character zero in a key,
    342        1.1     bjh21  * use \001\001; character 1 becomes \001\002.  In this case, character 0
    343        1.1     bjh21  * is reserved for the field delimiter.  Analagously for -r (fld_d = 255).
    344        1.1     bjh21  * Note: this is only good for ASCII sorting.  For different LC 's,
    345        1.1     bjh21  * all bets are off.  See also num_init in number.c
    346        1.1     bjh21  */
    347        1.1     bjh21 void
    348        1.1     bjh21 settables(gflags)
    349        1.1     bjh21 	int gflags;
    350        1.1     bjh21 {
    351        1.1     bjh21 	u_char *wts;
    352        1.1     bjh21 	int i, incr;
    353        1.1     bjh21 	for (i=0; i < 256; i++) {
    354        1.1     bjh21 		ascii[i] = i;
    355        1.1     bjh21 		if (i > REC_D && i < 255 - REC_D+1)
    356        1.1     bjh21 			Rascii[i] = 255 - i + 1;
    357        1.1     bjh21 		else
    358        1.1     bjh21 			Rascii[i] = 255 - i;
    359        1.1     bjh21 		if (islower(i)) {
    360        1.4  jdolecek 			Ftable[i] = Ftable[toupper(i)];
    361        1.4  jdolecek 			RFtable[i] = RFtable[toupper(i)];
    362        1.1     bjh21 		} else if (REC_D>= 'A' && REC_D < 'Z' && i < 'a' && i > REC_D) {
    363        1.1     bjh21 			Ftable[i] = i + 1;
    364        1.1     bjh21 			RFtable[i] = Rascii[i] - 1;
    365        1.1     bjh21 		} else {
    366        1.1     bjh21 			Ftable[i] = i;
    367        1.1     bjh21 			RFtable[i] = Rascii[i];
    368        1.1     bjh21 		}
    369        1.1     bjh21 		alltable[i] = 1;
    370        1.4  jdolecek 
    371        1.1     bjh21 		if (i == '\n' || isprint(i))
    372        1.1     bjh21 			itable[i] = 1;
    373        1.4  jdolecek 		else
    374        1.4  jdolecek 			itable[i] = 0;
    375        1.4  jdolecek 
    376        1.1     bjh21 		if (i == '\n' || i == '\t' || i == ' ' || isalnum(i))
    377        1.1     bjh21 			dtable[i] = 1;
    378        1.4  jdolecek 		else
    379        1.4  jdolecek 			dtable[i] = 0;
    380        1.1     bjh21 	}
    381        1.4  jdolecek 
    382        1.1     bjh21 	Rascii[REC_D] = RFtable[REC_D] = REC_D;
    383        1.4  jdolecek 	if (isupper(REC_D))
    384        1.4  jdolecek 		Ftable[tolower(REC_D)]++;
    385        1.4  jdolecek 
    386        1.4  jdolecek 	if ((gflags & R) && !((gflags & F) && SINGL_FLD))
    387        1.1     bjh21 		wts = Rascii;
    388        1.4  jdolecek 	else if (!((gflags & F) && SINGL_FLD))
    389        1.1     bjh21 		wts = ascii;
    390        1.1     bjh21 	else if (gflags & R)
    391        1.1     bjh21 		wts = RFtable;
    392        1.1     bjh21 	else
    393        1.1     bjh21 		wts = Ftable;
    394        1.4  jdolecek 
    395        1.1     bjh21 	memmove(gweights, wts, sizeof(gweights));
    396        1.1     bjh21 	incr = (gflags & R) ? -1 : 1;
    397        1.1     bjh21 	for (i = 0; i < REC_D; i++)
    398        1.1     bjh21 		gweights[i] += incr;
    399        1.1     bjh21 	gweights[REC_D] = ((gflags & R) ? 255 : 0);
    400        1.4  jdolecek 	if (SINGL_FLD && (gflags & F)) {
    401        1.1     bjh21 		for (i = 0; i < REC_D; i++) {
    402        1.1     bjh21 			ascii[i] += incr;
    403        1.1     bjh21 			Rascii[i] += incr;
    404        1.1     bjh21 		}
    405        1.1     bjh21 		ascii[REC_D] = Rascii[REC_D] = gweights[REC_D];
    406        1.1     bjh21 	}
    407        1.1     bjh21 }
    408