ProjectManager  0.2
MakefileChecking.h
1 /*
2  MakefileChecking.h
3 
4  Makefile integrity checking procedures for the ProjectManager application.
5 
6  Copyright (C) 2006 Saso Kiselkov
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 
23 #import <Foundation/NSObject.h>
24 #import <Foundation/NSString.h>
25 #import <Foundation/NSArray.h>
26 
27 static unsigned int
28 ComputeHashFromMakeString(NSString * fileString)
29 {
30  unichar * buf;
31  int i, n;
32  unsigned int hash = 0;
33 
34  n = [fileString length];
35  buf = (unichar *) malloc(sizeof(unichar) * n);
36  [fileString getCharacters: buf];
37 
38  for (i = 0; i < n; i++)
39  {
40  hash ^= buf[i];
41  hash = (hash << 1) | (hash >> (sizeof(hash) * 8 - 1));
42  }
43 
44  free(buf);
45 
46  return hash;
47 }
48 
49 static unsigned int
50 ComputeHashFromMakefile(NSString * filePath)
51 {
52  return ComputeHashFromMakeString([NSString stringWithContentsOfFile:
53  filePath]);
54 }