]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
added the C/C++ unifier
authorAndrew Tridgell <tridge@samba.org>
Sun, 31 Mar 2002 14:26:49 +0000 (16:26 +0200)
committerAndrew Tridgell <tridge@samba.org>
Sun, 31 Mar 2002 14:26:49 +0000 (16:26 +0200)
ccache.c
ccache.h
unify.c

index 89441ce55b0ec9e00f30ea306a9cad8c9d164cea..e7dc5e8c5730b6d67ce15ac387796bf13031015d 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -117,7 +117,6 @@ static void stabs_hash(const char *fname)
        int fd;
        struct stat st; 
        char *map;
-       int l_start, l_end;
 
        fd = open(fname, O_RDONLY);
        if (fd == -1 || fstat(fd, &st) != 0) {
@@ -136,23 +135,8 @@ static void stabs_hash(const char *fname)
        }
        close(fd);
 
-       l_start = 0;
-       while (l_start < st.st_size) {
-               l_end = l_start;
-               while (l_end < st.st_size && map[l_end] != '\n') {
-                       l_end++;
-               }
-               /* skip the hash on any lines that look like compiler line
-                  numbers */
-               if ((l_end - l_start) > 2 &&
-                   map[l_start] == '#' && map[l_start+1] == ' ' && 
-                   isdigit(map[l_start+2])) {
-                       l_start = l_end+1;
-                       continue;
-               }
-               hash_buffer(&map[l_start], 1 + l_end - l_start);
-               l_start = l_end+1;
-       }
+       /* pass it through the unifier */
+       unify(map, st.st_size);
 
        munmap(map, st.st_size);
 }
index 734d00fcdefac20a845ff48f4ab03013a4e574cc..9166f95d20f18afbfd5a0892241acd123591e367 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -88,6 +88,8 @@ void stats_set_limits(long maxfiles, long maxsize);
 size_t value_units(const char *s);
 void stats_set_sizes(const char *dir, size_t num_files, size_t total_size);
 
+void unify(unsigned char *p, size_t size);
+
 
 void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize);
 void cleanup_all(const char *dir);
diff --git a/unify.c b/unify.c
index 559ab4406e7fd800259099398715569a9fa457cc..6e19bc8993a1586a672ab5c1ab237053dcdafaeb 100644 (file)
--- a/unify.c
+++ b/unify.c
@@ -1,17 +1,28 @@
 /*
-  this file isn't used yet, but probably will be soon
+   Copyright (C) Andrew Tridgell 2002
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
+/*
+  C/C++ unifier
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/mman.h>
+  the idea is that changes that don't affect the resulting C code should not change
+  the hash
+*/
 
+#include "ccache.h"
 
 static char *s_tokens[] = {
        "...",  ">>=",  "<<=",  "+=",   "-=",   "*=",   "/=",   "%=",   "&=",   "^=",
@@ -37,10 +48,15 @@ static struct {
        char *toks[7];
 } tokens[256];
 
+/* build up the table used by the unifier */
 static void build_table(void)
 {
        unsigned char c;
        int i;
+       static int done;
+
+       if (done) return;
+       done = 1;
 
        memset(tokens, 0, sizeof(tokens));
        for (c=0;c<128;c++) {
@@ -69,30 +85,35 @@ static void build_table(void)
        }
 }
 
+/* buffer up characters before hashing them */
 static void pushchar(unsigned char c)
 {
        static unsigned char buf[64];
        static int len;
 
        if (c == 0) {
-               write(1, buf, len);
+               hash_buffer(buf, len);
                len = 0;
+               hash_buffer(NULL, 0);
                return;
        }
 
        buf[len++] = c;
        if (len == 64) {
-               write(1, buf, len);
+               hash_buffer(buf, len);
                len = 0;
        }
 }
 
-static void unify(unsigned char *p, size_t size)
+/* hash some C/C++ code after unifying */
+void unify(unsigned char *p, size_t size)
 {
        size_t ofs;
        unsigned char q;
        int i;
 
+       build_table();
+
        for (ofs=0; ofs<size;) {
                if (p[ofs] == '#') {
                        if ((size-ofs) > 2 && p[ofs+1] == ' ' && isdigit(p[ofs+2])) {
@@ -199,36 +220,3 @@ static void unify(unsigned char *p, size_t size)
        pushchar(0);
 }
 
-
-static unsigned char *map_file(const char *fname, size_t *size)
-{
-       int fd;
-       unsigned char *map;
-       struct stat st;
-
-       fd = open(fname, O_RDONLY);
-       if (fd == -1 || fstat(fd, &st) != 0) {
-               return NULL;
-       }
-       map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-       if (map == (unsigned char *)-1) {
-               return NULL;
-       }
-       close(fd);
-       *size = st.st_size;
-       return map;
-}
-
-
-int main(int argc, char *argv[])
-{
-       unsigned char *p;
-       size_t size;
-
-       build_table();
-
-       p = map_file(argv[1], &size);
-
-       unify(p, size);
-       return 0;
-}