Пример #1
0
static naRef f_seek(naContext c, naRef me, int argc, naRef* args)
{
    struct naIOGhost* g = argc > 0 ? ioghost(args[0]) : 0;
    naRef pos = argc > 1 ? naNumValue(args[1]) : naNil();
    naRef whn = argc > 2 ? naNumValue(args[2]) : naNil();
    if(!g || !IS_NUM(pos) || !IS_NUM(whn))
        naRuntimeError(c, "bad argument to seek()");
    g->type->seek(c, g->handle, (int)pos.num, (int)whn.num);
    return naNil();
}
Пример #2
0
void remove_entry(const char *nameId, const char *fileName)	{
	//This removes the entry and then puts it back into the file.
	productList temp[150];
	int count, i, type;
	get_from_db(temp, &count, fileName);
	type = IS_NUM(nameId[0]);
	for(i = 0; i < count; i++)	{
		if(type == 0)	{
			if(strcmp(temp[i].name, nameId) == 0)	{
				strcpy(temp[i].name, "");
				strcpy(temp[i].id, "");
				temp[i].qty = 0;
				temp[i].price = 0;
				break;
			}
		} else {
			if(strcmp(temp[i].id, nameId) == 0)	{
				strcpy(temp[i].name, "");
				strcpy(temp[i].id, "");
				temp[i].qty = 0;
				temp[i].price = 0;
				break;
			}
		}
	}
	db_write(temp, count, fileName);
}
Пример #3
0
void search_db(productList *listOfEntries, int * const count, const char *nameId, const char *fileName)	{
	productList temp[100];
	int tempC = 0, i = 0, j = 0, type;
	int strLen;
	char temp1[20], temp2[20];
	//This is a precaution for when searching for a single exact value
	if(count != NULL)	{
		*count = 0;
	}
	get_from_db(temp, &tempC, fileName);
	strLen = strlen(nameId);
	type = IS_NUM(nameId[0]);
	strcpy(temp2, nameId);
	strlwr(temp2);
	for(i = 0; i <= tempC -1 ; i++)	{
		if(type == 1)	{
			if(strncmp( temp[i].id, temp2, strLen) == 0)	{
				listOfEntries[j++] = temp[i];
			}
		} else {
			strcpy(temp1, temp[i].name);
			strlwr(temp1);
			if(strncmp( temp1, temp2, strLen) == 0)	{
				listOfEntries[j++] = temp[i];
			}
		}
	}
	if(count != NULL)	{
		*count = j;
	}
	if(j == 0)	{
		//Error message to indicate that no entry was found of that name
		strcpy(listOfEntries[0].name, "");
	}
}
Пример #4
0
static bool can_convert( enum_field_types t )
{
	return ( IS_NUM(t)
	   || ( t == FIELD_TYPE_DATE )
	   || ( t == FIELD_TYPE_TIME )
	   || ( t == FIELD_TYPE_DATETIME ) );
}
Пример #5
0
void wrenDumpValue(Value value)
{
#if WREN_NAN_TAGGING
  if (IS_NUM(value))
  {
    printf("%.14g", AS_NUM(value));
  }
  else if (IS_OBJ(value))
  {
    dumpObject(AS_OBJ(value));
  }
  else
  {
    switch (GET_TAG(value))
    {
      case TAG_FALSE:     printf("false"); break;
      case TAG_NAN:       printf("NaN"); break;
      case TAG_NULL:      printf("null"); break;
      case TAG_TRUE:      printf("true"); break;
      case TAG_UNDEFINED: UNREACHABLE();
    }
  }
#else
  switch (value.type)
  {
    case VAL_FALSE:     printf("false"); break;
    case VAL_NULL:      printf("null"); break;
    case VAL_NUM:       printf("%.14g", AS_NUM(value)); break;
    case VAL_TRUE:      printf("true"); break;
    case VAL_OBJ:       dumpObject(AS_OBJ(value)); break;
    case VAL_UNDEFINED: UNREACHABLE();
  }
#endif
}
Пример #6
0
Variant f_mysql_fetch_field(CVarRef result, int field /* = -1 */) {
  MySQLResult *res = php_mysql_extract_result(result);
  if (res == NULL) return false;

  if (field != -1) {
    if (!res->seekField(field)) return false;
  }
  MySQLFieldInfo *info;
  if (!(info = res->fetchFieldInfo())) return false;

  Object obj(SystemLib::AllocStdClassObject());
  obj->o_set("name",         info->name);
  obj->o_set("table",        info->table);
  obj->o_set("def",          info->def);
  obj->o_set("max_length",   (int)info->max_length);
  obj->o_set("not_null",     IS_NOT_NULL(info->flags)? 1 : 0);
  obj->o_set("primary_key",  IS_PRI_KEY(info->flags)? 1 : 0);
  obj->o_set("multiple_key", info->flags & MULTIPLE_KEY_FLAG? 1 : 0);
  obj->o_set("unique_key",   info->flags & UNIQUE_KEY_FLAG? 1 : 0);
  obj->o_set("numeric",      IS_NUM(info->type)? 1 : 0);
  obj->o_set("blob",         IS_BLOB(info->flags)? 1 : 0);
  obj->o_set("type",         php_mysql_get_field_name(info->type));
  obj->o_set("unsigned",     info->flags & UNSIGNED_FLAG? 1 : 0);
  obj->o_set("zerofill",     info->flags & ZEROFILL_FLAG? 1 : 0);
  return obj;
}
Пример #7
0
int octet_count(syslog_parser *parser, char nb) {
    int retval = pa_advance;

    if (IS_NUM(nb)) {
        size_t mlength = parser->octets_remaining;

        mlength *= 10;
        mlength += nb - '0';

        if (mlength < parser->octets_remaining || mlength == UINT_MAX) {
            parser->error = SLERR_BAD_OCTET_COUNT;
        } else {
            parser->octets_remaining = mlength;
        }
    } else if (IS_WS(nb)) {
        parser->flags |= F_COUNT_OCTETS;
        parser->octets_remaining += 1;
        parser->message_length += parser->octets_remaining;

        set_state(parser, s_priority_start);

        retval = pa_rehash;
    } else {
        parser->error = SLERR_BAD_OCTET_COUNT;
    }

    return retval;
}
Пример #8
0
void wrenPrintValue(Value value)
{
  #if WREN_NAN_TAGGING
  if (IS_NUM(value))
  {
    printf("%.14g", AS_NUM(value));
  }
  else if (IS_OBJ(value))
  {
    printObject(AS_OBJ(value));
  }
  else
  {
    switch (GET_TAG(value))
    {
      case TAG_FALSE: printf("false"); break;
      case TAG_NAN: printf("NaN"); break;
      case TAG_NULL: printf("null"); break;
      case TAG_TRUE: printf("true"); break;
    }
  }
  #else
  switch (value.type)
  {
    case VAL_FALSE: printf("false"); break;
    case VAL_NULL: printf("null"); break;
    case VAL_NUM: printf("%.14g", AS_NUM(value)); break;
    case VAL_TRUE: printf("true"); break;
    case VAL_OBJ:
    {
      printObject(AS_OBJ(value));
    }
  }
  #endif
}
Пример #9
0
// Validates that the given argument in [args] is a Num. Returns true if it is.
// If not, reports an error and returns false.
static bool validateNum(WrenVM* vm, Value* args, int index, const char* argName)
{
  if (IS_NUM(args[index])) return true;

  args[0] = OBJ_VAL(wrenStringConcat(vm, argName, " must be a number."));
  return false;
}
Пример #10
0
void display_header() {
  MYSQL_FIELD *field_ptr;

  printf("Column details:\n");
  while ((field_ptr = mysql_fetch_field(res_ptr)) != NULL) {
    printf("\t Name: %s\n", field_ptr->name);
    printf("\t Type: ");
    if (IS_NUM(field_ptr->type)) {
      printf("Numberic field\n");
    } else {
      switch (field_ptr->type) {
        case FIELD_TYPE_VAR_STRING:
          printf("VARCHAR\n");
          break;
        case FIELD_TYPE_LONG:
          printf("LONG\n");
          break;
        default:
          printf("Type is %d, check in mysql_com.h\n", field_ptr->type);
      }
    }

    printf("\t Max width %ld\n", field_ptr->length);
    if (field_ptr->flags & AUTO_INCREMENT_FLAG)
      printf("\t Auto increments\n");
    printf("\n");
  }
}
void CProcessListTable::copy_data_func(QString *cpy, CMySQLQuery *qry, QTableSelection *sel, QMap<uint, ulong> *max_length_map)
{
  uint length;
  QString tmp;
  qry->dataSeek(0);
  for (int current_row = 0; current_row < numRows(); current_row++)
  {
    qry->next();
    if (!isRowSelected(current_row))
      continue;    
    *cpy += "|";
    for (int current_col = sel->leftCol(); current_col <= sel->rightCol(); current_col++)
    {
      if (horizontalHeader()->sectionSize(current_col) <= 0)
        continue;
      const char *str= query()->row(current_col) ? query()->row(current_col) : NULL_TEXT;
      length = (*max_length_map)[current_col];
      
      if (length > MAX_COLUMN_LENGTH)
      {
        *cpy += str;
        *cpy += "|";
      }
      else
      {
        tmp.sprintf(IS_NUM(qry->fields(current_col).type) ? "%*s |" : " %-*s|", length, str);
        *cpy += tmp;
      }
    }
    *cpy += "\n";
  }
}
Пример #12
0
ObjClass* wrenGetClass(WrenVM* vm, Value value)
{
  #if WREN_NAN_TAGGING
  if (IS_NUM(value)) return vm->numClass;
  if (IS_OBJ(value)) return getObjectClass(vm, AS_OBJ(value));

  switch (GET_TAG(value))
  {
    case TAG_FALSE: return vm->boolClass;
    case TAG_NAN: return vm->numClass;
    case TAG_NULL: return vm->nullClass;
    case TAG_TRUE: return vm->boolClass;
  }
  #else
  switch (value.type)
  {
    case VAL_FALSE: return vm->boolClass;
    case VAL_NULL: return vm->nullClass;
    case VAL_NUM: return vm->numClass;
    case VAL_TRUE: return vm->boolClass;
    case VAL_OBJ: return getObjectClass(vm, value.obj);
  }
  #endif

  return NULL; // Unreachable.
}
Пример #13
0
bool validateNum(WrenVM* vm, Value arg, const char* argName)
{
  if (IS_NUM(arg)) return true;

  vm->fiber->error = wrenStringFormat(vm, "$ must be a number.", argName);
  return false;
}
void display_header() {
    MYSQL_FIELD *field_ptr;

    printf("Column details:\n");

    while ((field_ptr = mysql_fetch_field(res_ptr)) != NULL) {
        printf("\t Name: %s\n", field_ptr->name);
        printf("\t Type: ");
        if (IS_NUM(field_ptr->type)) {
            printf("Numeric field\n");
        } else {
            switch(field_ptr->type) {
            case FIELD_TYPE_VAR_STRING:
                printf("VARCHAR\n");
                break;
            case FIELD_TYPE_LONG:
                printf("LONG\n");
                break;
            default:
                printf("Type is %d, check in mysql_com.h\n", field_ptr->type);
            } /* switch */
        } /* else */

        printf("\t Max width %ld\n", field_ptr->length); /* Note on versions of MySQL before 4.0 the format should be %d, rather than %ld */
        if (field_ptr->flags & AUTO_INCREMENT_FLAG)
            printf("\t Auto increments\n");
        printf("\n");
    } /* while */
}
Пример #15
0
const char *typeStr(Value v) {
    const char *s = "?";
    if (IS_NIL(v)) {
        s = "nil";
    } else if (IS_NUM(v)) {
        s = "number";
    } else if (IS_STRING(v)) {
        s = "string";
    } else if (IS_ARRAY(v)) {
        s = "array";
    } else if (IS_MAP(v)) {
        s = "map";
    } else if (IS_FUNC(v)) {
        s = "func";
    } else if (IS_CFUNC(v)) {
        s = "cfunc";
    } else if (IS_CF(v)) {
        s = "cf";
    } else if (IS_CP(v)) {
        s = "cp";
    } else if (IS_PROTO(v)) {
        s = "proto";
    } else if (IS_REG(v)) {
        s = "reg";
    }
    return s;
}
Пример #16
0
bool validateNum(WrenVM* vm, Value* args, int index, const char* argName)
{
  if (IS_NUM(args[index])) return true;

  args[0] = wrenStringFormat(vm, "$ must be a number.", argName);
  return false;
}
Пример #17
0
static int equal(naRef a, naRef b)
{
    if(IS_NUM(a)) return a.num == b.num;
    if(PTR(a).obj == PTR(b).obj) return 1;
    if(naStr_len(a) != naStr_len(b)) return 0;
    return memcmp(naStr_data(a), naStr_data(b), naStr_len(a)) == 0;
}
Пример #18
0
JNI int JNINAME(run)(JNIEnv *env, jobject jobj, jstring jtxt) {
    JavaLink context(env, jobj);
    const char *txt = env->GetStringUTFChars(jtxt, 0);
    Pepper pepper(&context);
    Func *f = pepper.parseStatList(txt);
    env->ReleaseStringUTFChars(jtxt, txt);
    Value v = pepper.run(f, 0, 0);
    return IS_NUM(v) ? (int) GET_NUM(v) : -1;
}
Пример #19
0
void
summary_stats (MYSQL_RES *res_set, unsigned int col_num)
{
MYSQL_FIELD   *field;
MYSQL_ROW     row;
unsigned int  n, missing;
double        val, sum, sum_squares, var;

  /* verify data requirements: column must be in range and numeric */
  if (col_num < 0 || col_num >= mysql_num_fields (res_set))
  {
    print_error (NULL, "illegal column number");
    return;
  }
  mysql_field_seek (res_set, col_num);
  field = mysql_fetch_field (res_set);
  if (!IS_NUM (field->type))
  {
    print_error (NULL, "column is not numeric");
    return;
  }

  /* calculate summary statistics */

  n = 0;
  missing = 0;
  sum = 0;
  sum_squares = 0;

  mysql_data_seek (res_set, 0);
  while ((row = mysql_fetch_row (res_set)) != NULL)
  {
    if (row[col_num] == NULL)
      missing++;
    else
    {
      n++;
      val = atof (row[col_num]);  /* convert string to number */
      sum += val;
      sum_squares += val * val;
    }
  }
  if (n == 0)
    printf ("No observations\n");
  else
  {
    printf ("Number of observations: %u\n", n);
    printf ("Missing observations: %u\n", missing);
    printf ("Sum: %g\n", sum);
    printf ("Mean: %g\n", sum / n);
    printf ("Sum of squares: %g\n", sum_squares);
    var = ((n * sum_squares) - (sum * sum)) / (n * (n - 1));
    printf ("Variance: %g\n", var);
    printf ("Standard deviation: %g\n", sqrt (var));
  }
}
Пример #20
0
int
get_signal (message * msg, ircserver * srv)
{
    if (IS_NUM (cmd[0]) && IS_NUM (cmd[1]) && IS_NUM (cmd[2]))
        return atoi (cmd);
    SET_OWN_SIGNAL (JOIN_OWN, msg->source->nick);
    SET_OWN_SIGNAL (KILL_OWN, prm[0]);
    SET_OWN_SIGNAL (KICK_OWN, prm[1]);
    SET_SIGNAL (PING);
    SET_SIGNAL (JOIN);
    SET_SIGNAL (KILL);
    SET_SIGNAL (MODE);
    SET_SIGNAL (KICK);
    SET_SIGNAL (ERROR);
    SET_SIGNAL (NOTICE);
    SET_OTH_SIGNAL (QUERY, IS ("PRIVMSG") && AMI (prm[0]));
    SET_OTH_SIGNAL (MESSAGE, IS ("PRIVMSG"));
    return 0;
}
Пример #21
0
int msg_start(syslog_parser *parser, const syslog_parser_settings *settings, char nb) {
    on_cb(parser, settings->on_msg_begin);

    if (IS_NUM(nb)) {
        set_state(parser, s_octet_count);
    } else {
        set_state(parser, s_priority_start);
    }

    return pa_rehash;
}
Пример #22
0
void CQueryTable::sortColumn(int col, bool ascending, bool wholeRows)
{
#ifdef DEBUG
  qDebug("CQueryTable::sortColumn(%d, %s, %s)", col, debug_string(booltostr(ascending)), debug_string(booltostr(wholeRows)));
#endif
  
  if (!query()->isResultNull())
    mySortColumn(col, IS_NUM(query()->fields(col).type) ? cmpIntTableItems : cmpTableItems, ascending, wholeRows);
  else
    CTable::sortColumn(col, ascending, wholeRows);
}
Пример #23
0
static int my_process_result_set(MYSQL_RES *result)
{
 MYSQL_ROW    row;
 MYSQL_FIELD  *field;
 unsigned int i;
 unsigned int row_count= 0;

 if (!result)
 return 0;

 my_print_result_metadata(result);

 while ((row= mysql_fetch_row(result)) != NULL)
 {
   mysql_field_seek(result, 0);
   if (!opt_silent)
   {
     fputc('\t', stdout);
     fputc('|', stdout);
   }

   for(i= 0; i< mysql_num_fields(result); i++)
   {
     field= mysql_fetch_field(result);
     if (!opt_silent)
     {
       if (row[i] == NULL)
       fprintf(stdout, " %-*s |", (int) field->max_length, "NULL");
       else if (IS_NUM(field->type))
       fprintf(stdout, " %*s |", (int) field->max_length, row[i]);
       else
       fprintf(stdout, " %-*s |", (int) field->max_length, row[i]);
     }
   }
   if (!opt_silent)
   {
     fputc('\t', stdout);
     fputc('\n', stdout);
   }
   row_count++;
 }
 if (!opt_silent)
 {
   if (row_count)
   my_print_dashes(result);

   if (mysql_errno(mysql) != 0)
   fprintf(stderr, "\n\tmysql_fetch_row() failed\n");
   else
   fprintf(stdout, "\n\t%d %s returned\n", row_count,
   row_count == 1 ? "row" : "rows");
 }
 return row_count;
}
Пример #24
0
bool validateKey(WrenVM* vm, Value arg)
{
  if (IS_BOOL(arg) || IS_CLASS(arg) || IS_FIBER(arg) || IS_NULL(arg) ||
      IS_NUM(arg) || IS_RANGE(arg) || IS_STRING(arg))
  {
    return true;
  }

  vm->fiber->error = CONST_STRING(vm, "Key must be a value type or fiber.");
  return false;
}
Пример #25
0
static naRef f_read(naContext c, naRef me, int argc, naRef* args)
{
    struct naIOGhost* g = argc > 0 ? ioghost(args[0]) : 0;
    naRef str = argc > 1 ? args[1] : naNil();
    naRef len = argc > 2 ? naNumValue(args[2]) : naNil();
    if(!g || !MUTABLE(str) || !IS_NUM(len))
        naRuntimeError(c, "bad argument to read()");
    if(naStr_len(str) < (int)len.num)
        naRuntimeError(c, "string not big enough for read");
    return naNum(g->type->read(c, g->handle, naStr_data(str),
                               (int)len.num));
}
Пример #26
0
bool validateKey(WrenVM* vm, Value* args, int index)
{
  Value arg = args[index];
  if (IS_BOOL(arg) || IS_CLASS(arg) || IS_NULL(arg) ||
      IS_NUM(arg) || IS_RANGE(arg) || IS_STRING(arg))
  {
    return true;
  }

  args[0] = CONST_STRING(vm, "Key must be a value type.");
  return false;
}
Пример #27
0
static double field2num( const char *s, enum_field_types t )
{
	if (!s) return NaN;  // MySQL null -- nothing there

	if ( IS_NUM(t) )
		{
		double val=NaN;
		if ( sscanf(s,"%lf",&val) != 1 )
			{ mexPrintf("Unreadable value \"%s\" of type %s\n",s,typestr(t));
			  return NaN; }
		return val;
		}
	else if ( t == FIELD_TYPE_DATE )
		{
		int yr, mon, day;
		if ( sscanf(s,"%4d-%2d-%2d",&yr,&mon,&day) != 3
		    || yr<1000 || yr>=3000 || mon<1 || mon>12 || day<1 || day>31 )
			{ mexPrintf("Unreadable value \"%s\" of type %s\n",s,typestr(t));
			  return NaN; }
		return (double) daynum(yr,mon,day);
		}
	else if ( t == FIELD_TYPE_TIME )
		{
		int hr, min, sec;
		if ( sscanf(s,"%2d:%2d:%2d",&hr,&min,&sec) != 3
		           || min>60 || sec>60 )
			{ mexPrintf("Unreadable value \"%s\" of type %s\n",s,typestr(t));
			  return NaN; }
		return (sec+60*(min+60*hr))/secinday;
		}
	else if ( t == FIELD_TYPE_DATETIME )
		{
		int yr, mon, day, hr, min, sec;
		if ( sscanf(s,"%4d-%2d-%2d %2d:%2d:%2d",&yr,&mon,&day,&hr,&min,&sec) != 6
		      || yr<1000 || yr>=3000 || mon<1 || mon>12 || day<1 || day>31
		      || min>60 || sec>60 )
			{ mexPrintf("Unreadable value \"%s\" of type %s\n",s,typestr(t));
			  return NaN; }
		return ((double) daynum(yr,mon,day))
		       + ((sec+60*(min+60*hr))/secinday );
		}
	else
		{
		mexPrintf("Tried to convert \"%s\" of type %s to numeric\n",s,typestr(t));
		mexErrMsgTxt("Internal inconsistency");
		}
}
Пример #28
0
int version(syslog_parser *parser, char nb) {
    int retval = pa_advance;

    if (IS_NUM(nb)) {
        uint16_t nversion = parser->msg_head->version;
        nversion *= 10;
        nversion += nb - '0';

        if (nversion < parser->msg_head->version|| nversion > 999) {
            parser->error = SLERR_BAD_VERSION;
        } else {
            parser->msg_head->version = nversion;
        }
    } else {
        set_state(parser, s_timestamp);
    }

    return retval;
}
Пример #29
0
void StringBuilder::append(Value v, bool raw) {
    void *ptr = GET_PTR(v);
    if (IS_STRING(v)) {
        if (!raw) { append('\''); }
        append(GET_CSTR(v), len(v));
        if (!raw) { append('\''); }
    } else if (IS_NUM(v)) {
        append(GET_NUM(v));
        return;
    } else if (IS_ARRAY(v)) {
        Array *a = (Array *) ptr;
        int size = a->size();
        append('[');
        for (int i = 0; i < size; ++i) {
            append(i ? ", " : "");
            append(a->getI(i));
        }
        append(']');
    } else if (IS_MAP(v)) {
        Map *m = (Map *) ptr;
        int size = m->size();
        append('{');
        Value *keys = m->keyBuf();
        Value *vals = m->valBuf();
        for (int i = 0; i < size; ++i) {
            append(i ? ", " : "");
            append(keys[i]);
            append(':');
            append(vals[i]);
        }
        append('}');
    } else if (IS_NIL(v)) {
        append("nil");
    } else {
        append('<');
        append(typeStr(v));
        append('>');
        char tmp[32];
        snprintf(tmp, sizeof(tmp), "%p", ptr);
        append(tmp);
    }
}
Пример #30
0
void mod_entry(productList newDetails, const char *replaceNameId, const char *fileName, int changeId)	{
	//Here the product name may have changed. So we open up the old one with the id or name and delete it. Then we write it anew where ever we need. But with the same id
	int count, i, type;
	char tFileName[11];
	//We delete the old one.
	strcpy(tFileName, "");
	if(IS_NUM(replaceNameId[0]))	{
		sprintf(tFileName, "%c%c%c", replaceNameId[0],replaceNameId[1],replaceNameId[2]);
		sprintf(tFileName, "%c_db.txt", atoi(tFileName)-4);
		remove_entry(replaceNameId, tFileName);
	} else {
		sprintf(tFileName, "%c_db.txt", replaceNameId[0]);
		remove_entry(replaceNameId, tFileName);
	}
	//Now that the old one is gone. We add a new one
	if(strcmp(fileName, tFileName) != 0)	{
		gInit.fileItemCount[tolower(tFileName[0])-97]--;
		gInit.fileItemCount[tolower(fileName[0])-97]++;
	}
	db_write(&newDetails, -1, fileName);
}