"Fossies" - the Fresh Open Source Software Archive

Member "afio-2.5.2/exten.c" (30 Nov 2018, 1726 Bytes) of package /linux/misc/afio-2.5.2.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "exten.c" see the Fossies "Dox" file reference documentation.

    1 
    2 #include <stdio.h>
    3 #include <string.h>
    4 #include <unistd.h>
    5 #include <stdlib.h>
    6 #include <sys/types.h>
    7 #include <sys/stat.h>
    8 
    9 
   10 #include "patchlevel.h"
   11 
   12 #include "afio.h"
   13 
   14 
   15 struct extnode { char *ext; struct extnode *next; };
   16 
   17 /* merge in auto-generated list of default extensions mentioned in the manpage */
   18 #include "exten_default.h"
   19 
   20 /* Read file extensions of files that are not to be compressed
   21  * from compextsfile.
   22  * Extenstions in the file are seperated by whitespace.
   23  * a # begins a comment that lasts till the end of the line.
   24  */
   25 int readcompexts(char *compextsfile)
   26 {
   27  FILE *infile;
   28  char ex[81];
   29  int c;
   30  struct extnode *tmp;
   31 
   32  if(compextsfile[0]=='+') compextsfile++; else compexts=NULL;
   33 
   34  infile=fopen(compextsfile,"r");
   35  if(infile==0)
   36    {
   37      fprintf (stderr,
   38           "Can't read configuration file %s\n",
   39           compextsfile);
   40      return 0;
   41    }
   42 
   43  while(fscanf(infile,"%80s",ex)!=EOF)
   44    {
   45      if(ex[0]=='#')
   46        { /* throw away comment. */
   47         do{
   48            c=fgetc(infile);
   49            if(c==EOF)  { fclose(infile); return 1; }
   50           }while(c!='\n');
   51         continue;
   52        }
   53 
   54      tmp=(struct extnode *)malloc(sizeof(struct extnode));
   55      if(tmp==NULL) break;
   56      if((tmp->ext=strdup(ex))==NULL) break;
   57      tmp->next=compexts;
   58      compexts=tmp;
   59    }
   60 
   61  fclose(infile);
   62  return 1;
   63 }
   64 
   65 int matchcompext(char *s)
   66 {
   67  struct extnode *p;
   68  size_t sl;
   69 
   70  p=compexts;
   71  sl=strlen(s);
   72 
   73  while(p!=NULL)
   74    {
   75     if(sl >= strlen(p->ext))
   76       {
   77     if(extcasesens)
   78       {
   79             if(strcmp(s+sl-strlen(p->ext),p->ext)==0) return 1;
   80       }
   81     else
   82       {
   83             if(strcasecmp(s+sl-strlen(p->ext),p->ext)==0) return 1;
   84       }
   85       }
   86      p=p->next;
   87    }
   88 
   89  if(namecmp_ext(s)==0) return 1;
   90 
   91  return 0;
   92 }
   93 
   94 
   95