converting PSP from objective C to C