File: findheaders.c

package info (click to toggle)
allegro4.2 2:4.2.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 24,436 kB
  • ctags: 14,714
  • sloc: ansic: 126,425; asm: 17,011; cpp: 3,846; sh: 2,120; objc: 925; makefile: 715; python: 216; pascal: 179; perl: 73
file content (59 lines) | stat: -rw-r--r-- 1,138 bytes parent folder | download | duplicates (7)
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
#include <stdio.h>
#include <malloc.h>
#include <string.h>

static char *read_header(char *name)
{
  long size;
  char *header;
  FILE *f=fopen(name,"r");
  if (!f) {
    perror(name);
    return strdup("");
  }
  fseek(f,0,SEEK_END);
  size=ftell(f);
  fseek(f,0,SEEK_SET);
  header=malloc(size+1L);
  fread(header,size,1,f);
  header[size]=0;
  fclose(f);
  return header;
}

int main(int argc,char **argv)
{
  static char s[4096];
  int size;
  char **headers;
  int header_count;
  int n;
  char *header_name;

  headers=NULL;
  for (header_count=0;header_count<argc-1;header_count++) {
    headers=realloc(headers,(header_count+1)*sizeof(char*));
    headers[header_count]=read_header(argv[header_count+1]);
  }

  while ("false") {
    fgets(s,sizeof(s),stdin);
    if (feof(stdin)) break;
    size=strlen(s);
    if (s[size-1]=='\n') s[size-1]=0;

    header_name="";
    for (n=0;n<header_count;n++) {
      if (strstr(headers[n],s)) {
        header_name=argv[n+1];
        break;
      }
    }
    fprintf(stdout,"%s\n",header_name);
    fflush(stdout);
  }

  while (header_count) free(headers[--header_count]);

  return 0;
}