File: exten.c

package info (click to toggle)
afio 2.5.1.20160103+gitc8e4317-1
  • links: PTS, VCS
  • area: non-free
  • in suites: bullseye, buster, sid, stretch
  • size: 864 kB
  • ctags: 647
  • sloc: ansic: 4,903; sh: 139; makefile: 83; awk: 19
file content (95 lines) | stat: -rw-r--r-- 1,726 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>


#include "patchlevel.h"

#include "afio.h"


struct extnode { char *ext; struct extnode *next; };

/* merge in auto-generated list of default extensions mentioned in the manpage */
#include "exten_default.h"

/* Read file extensions of files that are not to be compressed
 * from compextsfile.
 * Extenstions in the file are seperated by whitespace.
 * a # begins a comment that lasts till the end of the line.
 */
int readcompexts(char *compextsfile)
{
 FILE *infile;
 char ex[81];
 int c;
 struct extnode *tmp;

 if(compextsfile[0]=='+') compextsfile++; else compexts=NULL;

 infile=fopen(compextsfile,"r");
 if(infile==0)
   {
     fprintf (stderr,
	      "Can't read configuration file %s\n",
	      compextsfile);
     return 0;
   }

 while(fscanf(infile,"%80s",ex)!=EOF)
   {
     if(ex[0]=='#')
       { /* throw away comment. */
        do{
           c=fgetc(infile);
           if(c==EOF)  { fclose(infile); return 1; }
          }while(c!='\n');
        continue;
       }

     tmp=(struct extnode *)malloc(sizeof(struct extnode));
     if(tmp==NULL) break;
     if((tmp->ext=strdup(ex))==NULL) break;
     tmp->next=compexts;
     compexts=tmp;
   }

 fclose(infile);
 return 1;
}

int matchcompext(char *s)
{
 struct extnode *p;
 size_t sl;

 p=compexts;
 sl=strlen(s);

 while(p!=NULL)
   {
    if(sl >= strlen(p->ext))
      {
	if(extcasesens)
	  {
            if(strcmp(s+sl-strlen(p->ext),p->ext)==0) return 1;
	  }
	else
	  {
            if(strcasecmp(s+sl-strlen(p->ext),p->ext)==0) return 1;
	  }
      }
     p=p->next;
   }

 if(namecmp_ext(s)==0) return 1;

 return 0;
}