ProjectManager  0.2
MakefileChecking.h
00001 /*
00002     MakefileChecking.h
00003 
00004     Makefile integrity checking procedures for the ProjectManager application.
00005 
00006     Copyright (C) 2006  Saso Kiselkov
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 */
00022 
00023 #import <Foundation/NSObject.h>
00024 #import <Foundation/NSString.h>
00025 #import <Foundation/NSArray.h>
00026 
00027 static unsigned int
00028 ComputeHashFromMakeString(NSString * fileString)
00029 {
00030   unichar * buf;
00031   int i, n;
00032   unsigned int hash = 0;
00033 
00034   n = [fileString length];
00035   buf = (unichar *) malloc(sizeof(unichar) * n);
00036   [fileString getCharacters: buf];
00037 
00038   for (i = 0; i < n; i++)
00039     {
00040       hash ^= buf[i];
00041       hash = (hash << 1) | (hash >> (sizeof(hash) * 8 - 1));
00042     }
00043 
00044   free(buf);
00045 
00046   return hash;
00047 }
00048 
00049 static unsigned int
00050 ComputeHashFromMakefile(NSString * filePath)
00051 {
00052   return ComputeHashFromMakeString([NSString stringWithContentsOfFile:
00053     filePath]);
00054 }