From 3ed71134b00d13f674ae555d489ed3f7c262c849 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 19 Nov 2015 19:43:41 +0000 Subject: Update flex from ancient 2.5.4 to the recent 2.5.39. This work was all done by Serguey Parkhomovsky. Thanks. Some changes from upstream: * Removed autotools cruft/localization/texinfo manual/etc * Kept the old manpage, as the new manpage is content-free * Used safe string handling functions and fixed several compiler warnings * pledge(2). Flex 2.5.39 now forks/execs its filter chains and needs proc exec in addition to what was previously pledged * Removed register keyword from all variable declarations * renamed parse.c, parse.h, scan.c, skel.c with init prefix so compiling flex outside of obj by accident wouldn't clobber the bootstrap files * Minor fixes (spelling, accessing buf[strlen(buf) - 1] for zero-length strings in initscan.c/scan.l, etc) that were already in our tree This is a huge change, so it's going in the tree code bomb style. I'm not excited about the growth in complexity (like now running m4 to _post_ process lexers) but hopefully this will be a one time update and we will now take "ownership" of the code. --- usr.bin/lex/ecs.c | 161 +++++++++++++++++++++++++----------------------------- 1 file changed, 75 insertions(+), 86 deletions(-) (limited to 'usr.bin/lex/ecs.c') diff --git a/usr.bin/lex/ecs.c b/usr.bin/lex/ecs.c index 7dfb5423eee..569b445e36f 100644 --- a/usr.bin/lex/ecs.c +++ b/usr.bin/lex/ecs.c @@ -1,50 +1,48 @@ -/* $OpenBSD: ecs.c,v 1.6 2003/06/04 17:34:44 millert Exp $ */ +/* $OpenBSD: ecs.c,v 1.7 2015/11/19 19:43:40 tedu Exp $ */ /* ecs - equivalence class routines */ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Vern Paxson. - * - * The United States Government has rights in this work pursuant - * to contract no. DE-AC03-76SF00098 between the United States - * Department of Energy and the University of California. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ +/* Copyright (c) 1990 The Regents of the University of California. */ +/* All rights reserved. */ + +/* This code is derived from software contributed to Berkeley by */ +/* Vern Paxson. */ + +/* The United States Government has rights in this work pursuant */ +/* to contract no. DE-AC03-76SF00098 between the United States */ +/* Department of Energy and the University of California. */ + +/* This file is part of flex */ + +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted provided that the following conditions */ +/* are met: */ + +/* 1. Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ + +/* Neither the name of the University nor the names of its contributors */ +/* may be used to endorse or promote products derived from this software */ +/* without specific prior written permission. */ + +/* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ +/* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ +/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ +/* PURPOSE. */ -/* $Header: /cvs/OpenBSD/src/usr.bin/lex/ecs.c,v 1.6 2003/06/04 17:34:44 millert Exp $ */ #include "flexdef.h" /* ccl2ecl - convert character classes to set of equivalence classes */ -void ccl2ecl() - { - int i, ich, newlen, cclp, ccls, cclmec; +void ccl2ecl () +{ + int i, ich, newlen, cclp, ccls, cclmec; - for ( i = 1; i <= lastccl; ++i ) - { + for (i = 1; i <= lastccl; ++i) { /* We loop through each character class, and for each character * in the class, add the character's equivalence class to the * new "character" class we are creating. Thus when we are all @@ -55,21 +53,19 @@ void ccl2ecl() newlen = 0; cclp = cclmap[i]; - for ( ccls = 0; ccls < ccllen[i]; ++ccls ) - { + for (ccls = 0; ccls < ccllen[i]; ++ccls) { ich = ccltbl[cclp + ccls]; cclmec = ecgroup[ich]; - if ( cclmec > 0 ) - { + if (cclmec > 0) { ccltbl[cclp + newlen] = cclmec; ++newlen; - } } + } ccllen[i] = newlen; - } } +} /* cre8ecs - associate equivalence class numbers with class members @@ -80,10 +76,10 @@ void ccl2ecl() * Returned is the number of classes. */ -int cre8ecs( fwd, bck, num ) -int fwd[], bck[], num; - { - int i, j, numcl; +int cre8ecs (fwd, bck, num) + int fwd[], bck[], num; +{ + int i, j, numcl; numcl = 0; @@ -92,16 +88,15 @@ int fwd[], bck[], num; * is positive, then x is the representative of its equivalence * class. */ - for ( i = 1; i <= num; ++i ) - if ( bck[i] == NIL ) - { + for (i = 1; i <= num; ++i) + if (bck[i] == NIL) { bck[i] = ++numcl; - for ( j = fwd[i]; j != NIL; j = fwd[j] ) + for (j = fwd[i]; j != NIL; j = fwd[j]) bck[j] = -numcl; - } + } return numcl; - } +} /* mkeccl - update equivalence classes based on character class xtions @@ -119,12 +114,12 @@ int fwd[], bck[], num; * NUL_mapping is the value which NUL (0) should be mapped to. */ -void mkeccl( ccls, lenccl, fwd, bck, llsiz, NUL_mapping ) -Char ccls[]; -int lenccl, fwd[], bck[], llsiz, NUL_mapping; - { - int cclp, oldec, newec; - int cclm, i, j; +void mkeccl (ccls, lenccl, fwd, bck, llsiz, NUL_mapping) + Char ccls[]; + int lenccl, fwd[], bck[], llsiz, NUL_mapping; +{ + int cclp, oldec, newec; + int cclm, i, j; static unsigned char cclflags[CSIZE]; /* initialized to all '\0' */ /* Note that it doesn't matter whether or not the character class is @@ -133,11 +128,10 @@ int lenccl, fwd[], bck[], llsiz, NUL_mapping; cclp = 0; - while ( cclp < lenccl ) - { + while (cclp < lenccl) { cclm = ccls[cclp]; - if ( NUL_mapping && cclm == 0 ) + if (NUL_mapping && cclm == 0) cclm = NUL_mapping; oldec = bck[cclm]; @@ -145,22 +139,19 @@ int lenccl, fwd[], bck[], llsiz, NUL_mapping; j = cclp + 1; - for ( i = fwd[cclm]; i != NIL && i <= llsiz; i = fwd[i] ) - { /* look for the symbol in the character class */ - for ( ; j < lenccl; ++j ) - { + for (i = fwd[cclm]; i != NIL && i <= llsiz; i = fwd[i]) { /* look for the symbol in the character class */ + for (; j < lenccl; ++j) { int ccl_char; - if ( NUL_mapping && ccls[j] == 0 ) + if (NUL_mapping && ccls[j] == 0) ccl_char = NUL_mapping; else ccl_char = ccls[j]; - if ( ccl_char > i ) + if (ccl_char > i) break; - if ( ccl_char == i && ! cclflags[j] ) - { + if (ccl_char == i && !cclflags[j]) { /* We found an old companion of cclm * in the ccl. Link it into the new * equivalence class and flag it as @@ -176,8 +167,8 @@ int lenccl, fwd[], bck[], llsiz, NUL_mapping; /* Get next equivalence class member. */ /* continue 2 */ goto next_pt; - } } + } /* Symbol isn't in character class. Put it in the old * equivalence class. @@ -185,48 +176,46 @@ int lenccl, fwd[], bck[], llsiz, NUL_mapping; bck[i] = oldec; - if ( oldec != NIL ) + if (oldec != NIL) fwd[oldec] = i; oldec = i; - next_pt: ; - } + next_pt:; + } - if ( bck[cclm] != NIL || oldec != bck[cclm] ) - { + if (bck[cclm] != NIL || oldec != bck[cclm]) { bck[cclm] = NIL; fwd[oldec] = NIL; - } + } fwd[newec] = NIL; /* Find next ccl member to process. */ - for ( ++cclp; cclflags[cclp] && cclp < lenccl; ++cclp ) - { + for (++cclp; cclflags[cclp] && cclp < lenccl; ++cclp) { /* Reset "doesn't need processing" flag. */ cclflags[cclp] = 0; - } } } +} /* mkechar - create equivalence class for single character */ -void mkechar( tch, fwd, bck ) -int tch, fwd[], bck[]; - { +void mkechar (tch, fwd, bck) + int tch, fwd[], bck[]; +{ /* If until now the character has been a proper subset of * an equivalence class, break it away to create a new ec */ - if ( fwd[tch] != NIL ) + if (fwd[tch] != NIL) bck[fwd[tch]] = bck[tch]; - if ( bck[tch] != NIL ) + if (bck[tch] != NIL) fwd[bck[tch]] = fwd[tch]; fwd[tch] = NIL; bck[tch] = NIL; - } +} -- cgit v1.2.3