Y_Less

strcmp

Aug 15th, 2013
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.10 KB | None | 0 0
  1. static int compare(cell *cstr1,cell *cstr2,int ignorecase,int length,int offs1)
  2. {
  3.   int index;
  4.   cell c1=0,c2=0;
  5.  
  6.   for (index=0; index<length; index++) {
  7.     c1=extractchar(cstr1,index+offs1,ignorecase);
  8.     c2=extractchar(cstr2,index,ignorecase);
  9.     assert(c1!=0 && c2!=0); /* string lengths are already checked, so zero-bytes should not occur */
  10.     if (c1!=c2)
  11.       break;
  12.   } /* for */
  13.  
  14.   if (c1<c2)
  15.     return -1;
  16.   if (c1>c2)
  17.     return 1;
  18.   return 0;
  19. }
  20.  
  21. /* strcmp(const string1[], const string2[], bool:ignorecase=false, length=cellmax)
  22.  */
  23. static cell AMX_NATIVE_CALL n_strcmp(AMX *amx,cell *params)
  24. {
  25.   cell *cstr1,*cstr2;
  26.   int len1,len2,len;
  27.   cell result;
  28.  
  29.   amx_GetAddr(amx,params[1],&cstr1);
  30.   amx_GetAddr(amx,params[2],&cstr2);
  31.  
  32.   /* get the maximum length to compare */
  33.   amx_StrLen(cstr1,&len1);
  34.   amx_StrLen(cstr2,&len2);
  35.   len=len1;
  36.   if (len>len2)
  37.     len=len2;
  38.   if (len>params[4])
  39.     len=params[4];
  40.   if (len==0)
  41.     return 0;
  42.  
  43.   result=compare(cstr1,cstr2,params[3],len,0);
  44.   if (result==0 && len!=params[4])
  45.     result=len1-len2;
  46.   return result;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment