예제 #1
0
파일: amxargs.c 프로젝트: z80/mapper
/* bool: argvalue(index=0, const option[]="", &value=cellmin)
 * returns true if the option was found and false otherwise
 */
static cell AMX_NATIVE_CALL n_argvalue(AMX *amx, const cell *params)
{
    const TCHAR *option, *key;
    int length;
    cell *cptr;

    amx_StrParam(amx, params[2], key);
    cptr = amx_Address(amx, params[3]);

    option = matcharg(key, (int)params[1], &length);
    if (option == NULL)
        return 0;

    /* check whether we must write the value of the option at all */
    if (length > 0 && (_istdigit(*option) || *option == __T('-')))
        *cptr = _tcstol(option, NULL, 10);

    return 1;
}
예제 #2
0
/* bool: argstr(index=0, const option[]="", value[]="", maxlength=sizeof value, bool:pack=false)
 * returns true if the option was found and false otherwise
 */
static cell AMX_NATIVE_CALL n_argstr(AMX *amx, const cell *params)
{
  const TCHAR *option, *key;
  int length, max;
  TCHAR *str;
  cell *cptr;

  max = (int)params[4];
  if (max <= 0)
    return 0;
  amx_StrParam(amx, params[2], key);
  amx_GetAddr(amx, params[3], &cptr);
  if (cptr == NULL) {
    amx_RaiseError(amx, AMX_ERR_NATIVE);
    return 0;
  } /* if */

  option = matcharg(key, (int)params[1], &length);
  if (option == NULL)
    return 0;           /* option not found */

  /* check whether we must write the value of the option at all; in case the
   * size is one cell and that cell is already zero, we do not write anything
   * back
   */
  assert(params[4] > 0);
  if (params[4] > 1 || *cptr != 0) {
    if (params[5])
      max *= sizeof(cell);
    if (max > length + 1)
      max = length + 1;
    str = (TCHAR *)alloca(max*sizeof(TCHAR));
    if (str == NULL) {
      amx_RaiseError(amx, AMX_ERR_NATIVE);
      return 0;
    } /* if */
    memcpy(str, option, (max - 1) * sizeof(TCHAR));
    str[max - 1] = __T('\0');
    amx_SetString(cptr, (char*)str, (int)params[5], sizeof(TCHAR)>1, max);
  } /* if */

  return 1;
}