Print this page
8485 Remove set but unused variables in usr/src/cmd
   1 /*

   2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
   3  * Use is subject to license terms.
   4  */
   5 
   6 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
   7 /*        All Rights Reserved   */
   8 
   9 /*
  10  * Copyright (c) 1980 Regents of the University of California.
  11  * All rights reserved. The Berkeley software License Agreement
  12  * specifies the terms and conditions for redistribution.
  13  */
  14 
  15 #pragma ident   "%Z%%M% %I%     %E% SMI"
  16 
  17 #include <stdio.h>
  18 #include <locale.h>
  19 #include <assert.h>
  20 #define SAME 0
  21 #define FGCT 10
  22 #define FGSIZE 150
  23 
  24 int keepold = 1;        /* keep old things for fgrep search */
  25 char fgspace[FGSIZE];
  26 char *fgp = fgspace;
  27 char *fgnames[FGCT];
  28 char **fgnamp = fgnames;
  29 
  30 extern char *mindex();
  31 
  32 long
  33 findline(char *in, char **out, int outlen, long indexdate)
  34 {
  35         static char name[100] = "";
  36         char *p, **ftp;
  37         extern long gdate();
  38         static FILE *fa = NULL;
  39         long lp, llen;
  40         int len, k, nofil;
  41 
  42 #if D1
  43         fprintf(stderr, "findline: %s\n", in);
  44 #endif
  45         if (mindex(in, '!'))
  46                 return (0);
  47 
  48         nofil = in[0] == 0;
  49         for (p = in; *p && *p != ':' && *p != ';'; p++)
  50                 ;
  51         if (*p) *p++ = 0;
  52         else p = in;
  53         k = sscanf(p, "%ld,%ld", &lp, &llen);
  54 #ifdef D1
  55         fprintf(stderr, "p %s k %d lp %ld llen %ld\n", p, k, lp, llen);
  56 #endif
  57         if (k < 2) {
  58                 lp = 0;
  59                 llen = outlen;
  60         }
  61 #ifdef D1
  62         fprintf(stderr, "lp %ld llen %ld\n", lp, llen);
  63 #endif
  64 #ifdef D1
  65         fprintf(stderr, "fa now %o, p %o in %o %s\n", fa, p, in, in);
  66 #endif
  67         if (nofil) {
  68 #if D1
  69                 fprintf(stderr, "set fa to stdin\n");
  70 #endif
  71                 fa = stdin;
  72         } else
  73                 if (strcmp(name, in) != 0 || 1) {
  74 #if D1
  75                         fprintf(stderr, "old: %s new %s not equal\n", name, in);
  76 #endif
  77                         if (fa != NULL)
  78                                 fa = freopen(in, "r", fa);
  79                         else
  80                                 fa = fopen(in, "r");
  81 #if D1
  82                         if (fa == NULL)
  83                                 fprintf(stderr, "failed to (re)open *%s*\n",
  84                                     in);
  85 #endif
  86                         if (fa == NULL)
  87                                 return (0);
  88                         /* err("Can't open %s", in); */
  89                         strcpy(name, in);
  90                         if (gdate(fa) > indexdate && indexdate != 0) {
  91                                 if (keepold) {
  92                                         for (ftp = fgnames; ftp < fgnamp; ftp++)
  93                                                 if (strcmp(*ftp, name) == SAME)
  94                                                         return (0);
  95                                         strcpy(*fgnamp++ = fgp, name);
  96                                         assert(fgnamp < fgnames+FGCT);
  97                                         while (*fgp && *fgp != ':')
  98                                                 fgp++;
  99                                         *fgp++ = 0;
 100                                         assert(fgp < fgspace+FGSIZE);
 101                                         return (0);
 102                                 }
 103                                 fprintf(stderr, gettext(
 104                                     "Warning: index predates file '%s'\n"),
 105                                     name);
 106                         }
 107                 }
 108 #if D1
 109                 else
 110                         fprintf(stderr, "old %s new %s same fa %o\n",
 111                             name, in, fa);
 112 #endif
 113         if (fa != NULL) {
 114                 fseek(fa, lp, 0);
 115                 *out = (char *)malloc(llen + 1);
 116                 if (*out == NULL) {
 117                         return (0);
 118                 }
 119                 len = fread(*out, 1, llen, fa);
 120                 *(*out + llen) = 0;
 121 #ifdef D1
 122                 fprintf(stderr, "length as read is %d\n", len);
 123 #endif
 124         }
 125         return (llen);
 126 }
   1 /*
   2  * Copyright 2017 Gary Mills
   3  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
   4  * Use is subject to license terms.
   5  */
   6 
   7 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
   8 /*        All Rights Reserved   */
   9 
  10 /*
  11  * Copyright (c) 1980 Regents of the University of California.
  12  * All rights reserved. The Berkeley software License Agreement
  13  * specifies the terms and conditions for redistribution.
  14  */
  15 


  16 #include <stdio.h>
  17 #include <locale.h>
  18 #include <assert.h>
  19 #define SAME 0
  20 #define FGCT 10
  21 #define FGSIZE 150
  22 
  23 int keepold = 1;        /* keep old things for fgrep search */
  24 char fgspace[FGSIZE];
  25 char *fgp = fgspace;
  26 char *fgnames[FGCT];
  27 char **fgnamp = fgnames;
  28 
  29 extern char *mindex();
  30 
  31 long
  32 findline(char *in, char **out, int outlen, long indexdate)
  33 {
  34         static char name[100] = "";
  35         char *p, **ftp;
  36         extern long gdate();
  37         static FILE *fa = NULL;
  38         long lp, llen;
  39         int k, nofil;
  40 



  41         if (mindex(in, '!'))
  42                 return (0);
  43 
  44         nofil = in[0] == 0;
  45         for (p = in; *p && *p != ':' && *p != ';'; p++)
  46                 ;
  47         if (*p) *p++ = 0;
  48         else p = in;
  49         k = sscanf(p, "%ld,%ld", &lp, &llen);



  50         if (k < 2) {
  51                 lp = 0;
  52                 llen = outlen;
  53         }






  54         if (nofil) {



  55                 fa = stdin;
  56         } else
  57                 if (strcmp(name, in) != 0 || 1) {



  58                         if (fa != NULL)
  59                                 fa = freopen(in, "r", fa);
  60                         else
  61                                 fa = fopen(in, "r");

  62                         if (fa == NULL)




  63                                 return (0);
  64                         /* err("Can't open %s", in); */
  65                         strcpy(name, in);
  66                         if (gdate(fa) > indexdate && indexdate != 0) {
  67                                 if (keepold) {
  68                                         for (ftp = fgnames; ftp < fgnamp; ftp++)
  69                                                 if (strcmp(*ftp, name) == SAME)
  70                                                         return (0);
  71                                         strcpy(*fgnamp++ = fgp, name);
  72                                         assert(fgnamp < fgnames+FGCT);
  73                                         while (*fgp && *fgp != ':')
  74                                                 fgp++;
  75                                         *fgp++ = 0;
  76                                         assert(fgp < fgspace+FGSIZE);
  77                                         return (0);
  78                                 }
  79                                 fprintf(stderr, gettext(
  80                                     "Warning: index predates file '%s'\n"),
  81                                     name);
  82                         }
  83                 }





  84         if (fa != NULL) {
  85                 fseek(fa, lp, 0);
  86                 *out = (char *)malloc(llen + 1);
  87                 if (*out == NULL) {
  88                         return (0);
  89                 }
  90                 (void) fread(*out, 1, llen, fa);
  91                 *(*out + llen) = 0;



  92         }
  93         return (llen);
  94 }