00001
00002
00003
00004
00005 #include "intgetmd5.h"
00006 #include "MALLOC.h"
00007
00008 #ifdef _MSC_VER
00009 #define stricmp _stricmp
00010 #endif
00011
00012 extern char *md5_file(FILE *fp);
00013 extern char *md5_str(char *p);
00014
00015 int C2F(intgetmd5) __PARAMS((char *fname,unsigned long fname_len))
00016 {
00017 static int l1,n1,m1;
00018 char *output=NULL ;
00019
00020 Rhs=Max(Rhs,0);
00021 CheckRhs(1,2) ;
00022 CheckLhs(1,1) ;
00023
00024 if (Rhs==1)
00025 {
00026 if (GetType(1) == sci_strings)
00027 {
00028 char *Param1=NULL;
00029 FILE *fp=NULL;
00030 char *MD5=NULL;
00031
00032 GetRhsVar(1,"c",&m1,&n1,&l1);
00033 Param1=cstk(l1);
00034
00035 fp = fopen(Param1, "rb");
00036 if (fp)
00037 {
00038 MD5=md5_file(fp);
00039 fclose(fp);
00040
00041 output=(char*)MALLOC((strlen(MD5)+1)*sizeof(char));
00042 sprintf(output,"%s",MD5);
00043 if (MD5) {FREE(MD5);MD5=NULL;}
00044
00045 n1=1;
00046 CreateVarFromPtr( 1, "c",(m1=strlen(output), &m1),&n1,&output);
00047 if (output) {FREE(output);output=NULL;}
00048
00049 LhsVar(1) = 1;
00050 C2F(putlhsvar)();
00051 }
00052 else
00053 {
00054 Scierror(999,"file %s doesn't exist.",Param1);
00055 }
00056 }
00057 else
00058 {
00059 Scierror(999,"Invalid type parameter. it must be a string (a filename).");
00060 }
00061 }
00062 else
00063 {
00064 if ( (GetType(1) == sci_strings) && (GetType(2) == sci_strings) )
00065 {
00066 char *Param1=NULL;
00067 char *Param2=NULL;
00068
00069 GetRhsVar(1,"c",&m1,&n1,&l1);
00070 Param1=cstk(l1);
00071
00072 GetRhsVar(2,"c",&m1,&n1,&l1);
00073 Param2=cstk(l1);
00074
00075 #ifdef _MSC_VER
00076 if ( stricmp(Param2,"string")==0 )
00077 #else
00078 if ( strcmp(Param2,"string")==0 )
00079 #endif
00080 {
00081 char *MD5=NULL;
00082 MD5=md5_str(Param1);
00083
00084 output=(char*)MALLOC((strlen(MD5)+1)*sizeof(char));
00085 sprintf(output,"%s",MD5);
00086 if (MD5) {FREE(MD5);MD5=NULL;}
00087
00088 n1=1;
00089 CreateVarFromPtr( 1, "c",(m1=strlen(output), &m1),&n1,&output);
00090 if (output) {FREE(output);output=NULL;}
00091
00092 LhsVar(1) = 1;
00093 C2F(putlhsvar)();
00094 }
00095 else
00096 {
00097 Scierror(999,"Invalid second parameter. It must be \"string\".");
00098 }
00099 }
00100 else
00101 {
00102 Scierror(999,"Invalid type parameter. parameters must be strings.");
00103 }
00104 }
00105 return 0;
00106 }
00107