Print this page
2944 cscope-fast/invlib.[ch] use reserved word as identifier
Reviewed by: Albert Lee <trisk@nexenta.com>
Reviewed by: Gary Mills <gary_mills@fastmail.fm>
Reviewed by: Joerg Schilling <Joerg.Schilling@fokus.fraunhofer.de>


  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*      Copyright (c) 1988 AT&T     */
  23 /*        All Rights Reserved   */
  24 
  25 
  26 /*
  27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 #pragma ident   "%Z%%M% %I%     %E% SMI"
  32 
  33 #include <ctype.h>
  34 #include <stdio.h>
  35 #include <sys/types.h>
  36 #include <sys/sysmacros.h>
  37 #include <sys/byteorder.h>
  38 #if SHARE
  39 #include <sys/ipc.h>
  40 #include <sys/shm.h>
  41 #define ERR  -1
  42 #endif
  43 #include "invlib.h"
  44 #include "library.h"
  45 
  46 #define DEBUG           0       /* debugging code and realloc messages */
  47 #define BLOCKSIZE       2 * BUFSIZ      /* logical block size */
  48 #define LINEMAX         1000    /* sorted posting line max size */
  49 #define POSTINC         10000   /* posting buffer size increment */
  50 #define SEP             ' '     /* sorted posting field separator */
  51 #define SETINC          100     /* posting set size increment */
  52 #define STATS           0       /* print statistics */


 931                 free(item2);
 932         setsize2 = SETINC;
 933         if ((item2 = (POSTING *)malloc(SETINC * sizeof (POSTING))) == NULL) {
 934                 invcannotalloc(SETINC);
 935                 return (-1);
 936         }
 937         item = item1;
 938         enditem = item;
 939         return (0);
 940 }
 941 
 942 void
 943 boolclear(void)
 944 {
 945         numitems = 0;
 946         item = item1;
 947         enditem = item;
 948 }
 949 
 950 POSTING *
 951 boolfile(INVCONTROL *invcntl, long *num, int bool)
 952 {
 953         ENTRY   *entryptr;
 954         FILE    *file;
 955         char    *ptr;
 956         unsigned long   *ptr2;
 957         POSTING *newitem;
 958         POSTING posting;
 959         unsigned u;
 960         POSTING *newsetp, *set1p;
 961         long    newsetc, set1c, set2c;
 962 
 963         entryptr = (ENTRY *) (invcntl->logblk + 12) + invcntl->keypnt;
 964         ptr = invcntl->logblk + entryptr->offset;
 965         ptr2 = ((unsigned long *)ptr) +
 966             (entryptr->size + (sizeof (long) - 1)) / sizeof (long);
 967         *num = entryptr->post;
 968         switch (bool) {
 969         case OR:
 970         case NOT:
 971                 if (*num == 0) {
 972                         *num = numitems;
 973                         return (item);
 974                 }
 975         }
 976         /* make room for the new set */
 977         u = 0;
 978         switch (bool) {
 979         case AND:
 980         case NOT:
 981                 newsetp = set1p = item;
 982                 break;
 983 
 984         case OR:
 985                 u = enditem - item;
 986                 /* FALLTHROUGH */
 987         case REVERSENOT:
 988                 u += *num;
 989                 if (item == item2) {
 990                         if (u > setsize1) {
 991                                 u += SETINC;
 992                                 if ((item1 = (POSTING *) realloc(item1,
 993                                     u * sizeof (POSTING))) == NULL) {
 994                                         goto cannotalloc;
 995                                 }
 996                                 setsize1 = u;
 997                         }
 998                         newitem = item1;


1001                                 u += SETINC;
1002                                 if ((item2 = (POSTING *)realloc(item2,
1003                                     u * sizeof (POSTING))) == NULL) {
1004                                 cannotalloc:
1005                                         invcannotalloc(u * sizeof (POSTING));
1006                                         (void) boolready();
1007                                         *num = -1;
1008                                         return (NULL);
1009                                 }
1010                                 setsize2 = u;
1011                         }
1012                         newitem = item2;
1013                 }
1014                 set1p = item;
1015                 newsetp = newitem;
1016         }
1017         file = invcntl->postfile;
1018         (void) fseek(file, (long)*ptr2, SEEK_SET);
1019         read_next_posting(invcntl, &posting);
1020         newsetc = 0;
1021         switch (bool) {
1022         case OR:
1023                 /* while something in both sets */
1024                 set1p = item;
1025                 newsetp = newitem;
1026                 for (set1c = 0, set2c = 0;
1027                     set1c < numitems && set2c < *num; newsetc++) {
1028                         if (set1p->lineoffset < posting.lineoffset) {
1029                                 *newsetp++ = *set1p++;
1030                                 set1c++;
1031                         } else if (set1p->lineoffset > posting.lineoffset) {
1032                                 *newsetp++ = posting;
1033                                 read_next_posting(invcntl, &posting);
1034                                 set2c++;
1035                         } else if (set1p->type < posting.type) {
1036                                 *newsetp++ = *set1p++;
1037                                 set1c++;
1038                         } else if (set1p->type > posting.type) {
1039                                 *newsetp++ = posting;
1040                                 read_next_posting(invcntl, &posting);
1041                                 set2c++;




  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*      Copyright (c) 1988 AT&T     */
  23 /*        All Rights Reserved   */
  24 
  25 
  26 /*
  27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 


  31 #include <ctype.h>
  32 #include <stdio.h>
  33 #include <sys/types.h>
  34 #include <sys/sysmacros.h>
  35 #include <sys/byteorder.h>
  36 #if SHARE
  37 #include <sys/ipc.h>
  38 #include <sys/shm.h>
  39 #define ERR  -1
  40 #endif
  41 #include "invlib.h"
  42 #include "library.h"
  43 
  44 #define DEBUG           0       /* debugging code and realloc messages */
  45 #define BLOCKSIZE       2 * BUFSIZ      /* logical block size */
  46 #define LINEMAX         1000    /* sorted posting line max size */
  47 #define POSTINC         10000   /* posting buffer size increment */
  48 #define SEP             ' '     /* sorted posting field separator */
  49 #define SETINC          100     /* posting set size increment */
  50 #define STATS           0       /* print statistics */


 929                 free(item2);
 930         setsize2 = SETINC;
 931         if ((item2 = (POSTING *)malloc(SETINC * sizeof (POSTING))) == NULL) {
 932                 invcannotalloc(SETINC);
 933                 return (-1);
 934         }
 935         item = item1;
 936         enditem = item;
 937         return (0);
 938 }
 939 
 940 void
 941 boolclear(void)
 942 {
 943         numitems = 0;
 944         item = item1;
 945         enditem = item;
 946 }
 947 
 948 POSTING *
 949 boolfile(INVCONTROL *invcntl, long *num, int op)
 950 {
 951         ENTRY   *entryptr;
 952         FILE    *file;
 953         char    *ptr;
 954         unsigned long   *ptr2;
 955         POSTING *newitem;
 956         POSTING posting;
 957         unsigned u;
 958         POSTING *newsetp, *set1p;
 959         long    newsetc, set1c, set2c;
 960 
 961         entryptr = (ENTRY *) (invcntl->logblk + 12) + invcntl->keypnt;
 962         ptr = invcntl->logblk + entryptr->offset;
 963         ptr2 = ((unsigned long *)ptr) +
 964             (entryptr->size + (sizeof (long) - 1)) / sizeof (long);
 965         *num = entryptr->post;
 966         switch (op) {
 967         case OR:
 968         case NOT:
 969                 if (*num == 0) {
 970                         *num = numitems;
 971                         return (item);
 972                 }
 973         }
 974         /* make room for the new set */
 975         u = 0;
 976         switch (op) {
 977         case AND:
 978         case NOT:
 979                 newsetp = set1p = item;
 980                 break;
 981 
 982         case OR:
 983                 u = enditem - item;
 984                 /* FALLTHROUGH */
 985         case REVERSENOT:
 986                 u += *num;
 987                 if (item == item2) {
 988                         if (u > setsize1) {
 989                                 u += SETINC;
 990                                 if ((item1 = (POSTING *) realloc(item1,
 991                                     u * sizeof (POSTING))) == NULL) {
 992                                         goto cannotalloc;
 993                                 }
 994                                 setsize1 = u;
 995                         }
 996                         newitem = item1;


 999                                 u += SETINC;
1000                                 if ((item2 = (POSTING *)realloc(item2,
1001                                     u * sizeof (POSTING))) == NULL) {
1002                                 cannotalloc:
1003                                         invcannotalloc(u * sizeof (POSTING));
1004                                         (void) boolready();
1005                                         *num = -1;
1006                                         return (NULL);
1007                                 }
1008                                 setsize2 = u;
1009                         }
1010                         newitem = item2;
1011                 }
1012                 set1p = item;
1013                 newsetp = newitem;
1014         }
1015         file = invcntl->postfile;
1016         (void) fseek(file, (long)*ptr2, SEEK_SET);
1017         read_next_posting(invcntl, &posting);
1018         newsetc = 0;
1019         switch (op) {
1020         case OR:
1021                 /* while something in both sets */
1022                 set1p = item;
1023                 newsetp = newitem;
1024                 for (set1c = 0, set2c = 0;
1025                     set1c < numitems && set2c < *num; newsetc++) {
1026                         if (set1p->lineoffset < posting.lineoffset) {
1027                                 *newsetp++ = *set1p++;
1028                                 set1c++;
1029                         } else if (set1p->lineoffset > posting.lineoffset) {
1030                                 *newsetp++ = posting;
1031                                 read_next_posting(invcntl, &posting);
1032                                 set2c++;
1033                         } else if (set1p->type < posting.type) {
1034                                 *newsetp++ = *set1p++;
1035                                 set1c++;
1036                         } else if (set1p->type > posting.type) {
1037                                 *newsetp++ = posting;
1038                                 read_next_posting(invcntl, &posting);
1039                                 set2c++;