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
  
/* 
|| This file is part of Pike. For copyright information see COPYRIGHT. 
|| Pike is distributed under GPL, LGPL and MPL. See the file COPYING 
|| for more information. 
|| $Id: patch_cc1.c,v 1.3 2002/10/11 01:39:34 nilsson Exp $ 
*/ 
 
/* 
 * Patch gcc so that it doesn't use .ua{half,word} directives. 
 * 
 * Henrik Grubbström 2000-01-25 
 */ 
 
#include <sys/types.h> 
#include <sys/stat.h> 
#include <fcntl.h> 
#include <stdio.h> 
 
#define BUFSIZE       65536 
#define OVERLAP 32 
 
char buffer[BUFSIZE+OVERLAP]; 
 
int main(int argc, char **argv) 
{ 
  int fd; 
  int offset = 0; 
  int len; 
  if (argc < 2) { 
    fprintf(stderr, "Usage:\n" 
            "\t%s <cc1>\n", argv[0]); 
    exit(1); 
  } 
 
  if (!strcmp(argv[1], "-v")) { 
    fprintf(stdout, "$Id: patch_cc1.c,v 1.3 2002/10/11 01:39:34 nilsson Exp $\n"); 
    exit(0); 
  } 
 
  if ((fd = open(argv[1], O_RDONLY)) < 0) { 
    fprintf(stderr, "Failed to open \"%s\" for reading.\n", argv[1]); 
    exit(1); 
  } 
 
  while ((len = read(fd, buffer + offset, BUFSIZE+OVERLAP-offset)) > 0) { 
    int i; 
    len += offset; 
    for(i=0; i < len-8; i++) { 
      if (buffer[i] == '.') { 
        /* Note: We can use strcmp(), since the string should be 
         * NUL-terminated in the buffer. */ 
        if (!strcmp(buffer+i, ".uaword")) { 
          buffer[i+1] = 'w'; 
          buffer[i+2] = 'o'; 
          buffer[i+3] = 'r'; 
          buffer[i+4] = 'd'; 
          buffer[i+5] = 0; 
          buffer[i+6] = 0; 
        } else if (!strcmp(buffer+i, ".uahalf")) { 
          buffer[i+1] = 'h'; 
          buffer[i+2] = 'a'; 
          buffer[i+3] = 'l'; 
          buffer[i+4] = 'f'; 
          buffer[i+5] = 0; 
          buffer[i+6] = 0; 
        } 
      } 
    } 
    if (len < BUFSIZE+OVERLAP) { 
      /* At EOF */ 
      write(1, buffer, len); 
      exit(0); 
    } 
    write(1, buffer, BUFSIZE); 
    memcpy(buffer, buffer+BUFSIZE, offset = (len-BUFSIZE)); 
  } 
  write(1, buffer, offset); 
  exit(0); 
}