コード例 #1
0
int clip_PG_OUT_TIMESTAMP(ClipMachine* mp){
	PG_ROWSET* rowset = (PG_ROWSET*)_clip_fetch_c_item(
		mp,_clip_parni(mp,1),_C_ITEM_TYPE_SQL);
	int totext = _clip_parl(mp,3);
	struct tm time;
	time_t bindate;
	char* date;
	int len;

	if(!rowset){
		_clip_trap_err(mp,0,0,0,subsys,ER_NOROWSET,er_norowset);
		return 1;
	}
	if((!totext)&&rowset->binary){
		
		memset(&time,0,sizeof(time));
		_clip_pardc(mp,2,&time.tm_year,&time.tm_mon,&time.tm_mday,&time.tm_wday);
		time.tm_year -= 1900;
		time.tm_mon--;

		bindate = mktime(&time);
		_clip_retcn(mp,(char*)(&bindate),4);
	} else {
		date = _clip_parcl(mp,2,&len);
	        _clip_retc(mp,date);

//		char str[25];
//		_pg_out_date(mp,str,rowset->conn->datestyle,rowset->conn->textdate,_clip_pardj(mp,2));
//		_clip_retc(mp,str);
	}
	return 0;
}
コード例 #2
0
int
clip_TRANSLATE_CHARSET(ClipMachine * ClipMachineMemory)
{
   int len = 0, r;

   char *p1 = _clip_parc(ClipMachineMemory, 1);

   char *p2 = _clip_parc(ClipMachineMemory, 2);

   unsigned char *str = (unsigned char *) _clip_parcl(ClipMachineMemory, 3, &len);

   unsigned char *s;

   if (!p1 || !p2 || !str)
      return EG_ARG;

   if (!strcasecmp(p1, p2))
   {
      _clip_retcn(ClipMachineMemory, (char *) str, len);
      return 0;
   }

   if (!strcasecmp(p1, "utf-8"))
   {
      char *result;

      if (!_clip_translate_fromutf8(p2, (char *) str, len, &result))
      {
	 _clip_retc(ClipMachineMemory, result);
	 free(result);
      }
      else
	 _clip_retc(ClipMachineMemory, (char *) str);
      return 0;
   }

   if (!strcasecmp(p2, "utf-8"))
   {
      char *result;

      if (!_clip_translate_toutf8(p1, str, len, &result))
      {
	 _clip_retc(ClipMachineMemory, result);
	 free(result);
      }
      else
	 _clip_retc(ClipMachineMemory, (char *) str);
      return 0;
   }

   s = (unsigned char *) malloc(len + 1);
   s[len] = 0;

   if ((r = _clip_translate_charset(p1, p2, str, s, len)))
      return r;

   _clip_retcn_m(ClipMachineMemory, (char *) s, len);

   return 0;
}
コード例 #3
0
int clip_PG_OUT_DATETIME(ClipMachine* mp){
	PG_ROWSET* rowset = (PG_ROWSET*)_clip_fetch_c_item(
		mp,_clip_parni(mp,1),_C_ITEM_TYPE_SQL);
	long time;
	long date = _clip_pardtj(mp,2,&time);
	int totext = _clip_parl(mp,3);

	if(!rowset){
		_clip_trap_err(mp,0,0,0,subsys,ER_NOROWSET,er_norowset);
		return 1;
	}
	if((!totext)&&rowset->binary){
		long l = date - _clip_jdate(1,1,2000);
		double d = l*(24*60*60) + time/1000;
		_clip_retcn(mp,(char*)&d,8);
	} else {
		char str[26];
		int y,m,d,w,h,mm,s,t,q;

		_clip_cdate(date,&d,&m,&y,&w);
		h = time/(60*60*1000);
		q = time%(60*60*1000);
		mm = q/(60*1000);
		q %= 60*1000;
		s = q/(1000);
		t = q%1000;
		snprintf(str,sizeof(str),"%04d-%02d-%02d %02d:%02d:%02d.%02d+00",y,m,d,h,mm,s,t);
		_clip_retc(mp,str);
	}
	return 0;
}
コード例 #4
0
ファイル: clip_CHARMIX.c プロジェクト: amery/clip-angelo
int
clip_CHARMIX(ClipMachine * ClipMachineMemory)
{
   int l1, l2, i;

   unsigned char *ret;

   unsigned char *str1 = (unsigned char *) _clip_parcl(ClipMachineMemory, 1, &l1);

   unsigned char *str2 = (unsigned char *) _clip_parcl(ClipMachineMemory, 2, &l2);

   if (str1 == NULL || str2 == NULL)
   {
      _clip_retc(ClipMachineMemory, "");
      return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "CHARMIX");
   }
   if (l2 == 0)
   {
      _clip_retcn(ClipMachineMemory, (char *) str1, l1);
      return 0;
   }

   ret = malloc(l1 * 2 + 1);
   for (i = 0; i < l1; i++)
   {
      ret[i * 2] = str1[i % l1];
      ret[i * 2 + 1] = str2[i % l2];
   }
   ret[l1 * 2] = 0;
   _clip_retcn_m(ClipMachineMemory, (char *) ret, l1 * 2);
   return 0;
}
コード例 #5
0
ファイル: odbc_clip.c プロジェクト: amery/clip-itk
int clip_ODBC_OUT_DATE(ClipMachine* mp){
	long julian = _clip_pardj(mp,1);
	short int s[3] = {0,0,0};
	int yy,mm,dd,ww;

	if((_clip_parinfo(mp,1) == DATE_t) && julian){
		_clip_cdate(julian,&dd,&mm,&yy,&ww);
		s[0] = yy; s[1] = mm; s[2] = dd;
	}
	_clip_retcn(mp,(char*)s,6);
	return 0;
}
コード例 #6
0
ファイル: clip_WEIGHTCHR.c プロジェクト: amery/clip-angelo
int
clip_WEIGHTCHR(ClipMachine * ClipMachineMemory)
{
   int i;

   unsigned char ch = _clip_parni(ClipMachineMemory, 1);

   for (i = 0; i < 256 && _clip_cmptbl[i] != ch; i++)
      ;
   _clip_retcn(ClipMachineMemory, (char *) &i, 1);
   return 0;
}
コード例 #7
0
ファイル: odbc_clip.c プロジェクト: amery/clip-itk
int clip_ODBC_OUT_TIME(ClipMachine* mp){
	int len;
	const char* t = _clip_parcl(mp,1,&len);
	short int s[3] = {0,0,0};

	if(!((_clip_parinfo(mp,1) != CHARACTER_t) || !t || (len < 8))){
		s[0] = atoi(t);
		s[1] = atoi(t+3);
		s[2] = atoi(t+6);
	}
	_clip_retcn(mp,(char*)s,6);
	return 0;
}
コード例 #8
0
ファイル: _tcp.c プロジェクト: amery/clip-itk
int
clip_IPADDR2BIN(ClipMachine *mp)
{
	char * addr = _clip_parc(mp, 1);
	struct in_addr ina;

	if (tcp_host_addr(addr, &ina) == 0)
		_clip_retcn(mp, (char *)&ina, sizeof(struct in_addr));
	else
		_clip_retc(mp, "");

	return 0;
}
コード例 #9
0
ファイル: odbc_clip.c プロジェクト: amery/clip-itk
int clip_ODBC_OUT_TIMESTAMP(ClipMachine* mp){
	long time;
	long julian = _clip_pardtj(mp,1,&time);
	short int s[6] = {0,0,0,0,0,0};
	int yy,mm,dd,ww;
	long t;

	if(_clip_parinfo(mp,1) == DATE_t){
		if(julian){
			_clip_cdate(julian,&dd,&mm,&yy,&ww);
			s[0] = yy; s[1] = mm; s[2] = dd;
		}
		s[3] = time / (60*60*1000);
		t = time % (60*60*1000);
		s[4] = t / (60*1000);
		s[5] = (t % (60*1000)) / 1000;
	}
	_clip_retcn(mp,(char*)s,12);
	return 0;
}
コード例 #10
0
int clip_PG_OUT_DATE(ClipMachine* mp){
	PG_ROWSET* rowset = (PG_ROWSET*)_clip_fetch_c_item(
		mp,_clip_parni(mp,1),_C_ITEM_TYPE_SQL);
	long date = _clip_pardj(mp,2);
	int totext = _clip_parl(mp,3);

	if(!rowset){
		_clip_trap_err(mp,0,0,0,subsys,ER_NOROWSET,er_norowset);
		return 1;
	}
	if((!totext)&&rowset->binary){
		long d = date-2451545;
		_clip_retcn(mp,(char*)&d,4);
	} else {
		char str[11];
		int y,m,d,w;

		_clip_cdate(date,&d,&m,&y,&w);
		snprintf(str,sizeof(str),"%04d-%02d-%02d",y,m,d);
		_clip_retc(mp,str);
	}
	return 0;
}
コード例 #11
0
ファイル: odbc_clip.c プロジェクト: amery/clip-itk
int clip_ODBC_OUT_FLOAT(ClipMachine* mp){
	float d = _clip_parnd(mp,1);
	_clip_retcn(mp,(char*)&d,4);
	return 0;
}
コード例 #12
0
ファイル: odbc_clip.c プロジェクト: amery/clip-itk
int clip_ODBC_OUT_DOUBLE(ClipMachine* mp){
	double d = _clip_parnd(mp,1);
	_clip_retcn(mp,(char*)&d,8);
	return 0;
}
コード例 #13
0
ファイル: clip_CHARRELREP.c プロジェクト: amery/clip-angelo
int
clip_CHARRELREP(ClipMachine * ClipMachineMemory)
{
   int l, l1, l2, l3, l4, l5, cpos;

   unsigned char *e1, *e2, *e3 = NULL, *e4;

   unsigned char *ee1, *ee3, *cur, *ret;

   unsigned char *end1, *end2, *end3, *end4;

   unsigned char *str1 = (unsigned char *) _clip_parcl(ClipMachineMemory, 1, &l1);

   unsigned char *str2 = (unsigned char *) _clip_parcl(ClipMachineMemory, 2, &l2);

   unsigned char *str3 = (unsigned char *) _clip_parcl(ClipMachineMemory, 3, &l3);

   unsigned char *str4 = (unsigned char *) _clip_parcl(ClipMachineMemory, 4, &l4);

   unsigned char *str5 = (unsigned char *) _clip_parcl(ClipMachineMemory, 5, &l5);

   int rset = (*(char *) (_clip_fetch_item(ClipMachineMemory, HASH_csetref)) == 't');

   if (str1 == NULL || str2 == NULL || str3 == NULL || str4 == NULL || str5 == NULL)
   {
      _clip_retc(ClipMachineMemory, "");
      return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "CHARRELREP");
   }
   if (l1 == 0 || l3 == 0)
   {
      _clip_retcn(ClipMachineMemory, (char *) str4, l4);
      return 0;
   }
   l = 0;
   cpos = 0;
   ret = malloc(l + 1);
   cur = str4;
   end1 = str1 + l1;
   end3 = str3 + l3;
   end2 = str2 + l2 - l1 + 1;
   end4 = str4 + l4 - l3 + 1;
   for (e2 = str2, e4 = str4; e2 < end2 && e4 < end4; e2++, e4++)
   {
      for (e1 = str1, ee1 = e2; e1 < end1 && *e1 == *ee1; e1++, ee1++);
      if (e1 == end1)
	 for (e3 = str3, ee3 = e4; e3 < end3 && *e3 == *ee3; e3++, ee3++);
      if (e1 == end1 && e3 == end3)
      {
	 l += e4 - cur + l5;
	 ret = realloc(ret, l + 1);
	 memcpy(ret + cpos, cur, e4 - cur);
	 cpos += e4 - cur;
	 memcpy(ret + cpos, str5, l5);
	 cpos += l5;
	 e2 += l3;
	 e4 += l3;
	 cur = e4;
      }

   }
   l += str4 + l4 - cur;
   ret = realloc(ret, l + 1);
   memcpy(ret + cpos, cur, str4 + l4 - cur);
   ret[l] = 0;
   if (rset && _clip_par_isref(ClipMachineMemory, 4))
      _clip_par_assign_str(ClipMachineMemory, 4, (char *) ret, l);
   _clip_retcn_m(ClipMachineMemory, (char *) ret, l);
   return 0;
}
コード例 #14
0
int clip_PG_OUT_INT8(ClipMachine* mp){
	double d = _clip_parnd(mp,1);
	long long l = (long long)d;
	_clip_retcn(mp,(char*)&l,8);
	return 0;
}
コード例 #15
0
int clip_PG_OUT_INT2(ClipMachine* mp){
	short int s = (short int)_clip_parnd(mp,1);
	_clip_retcn(mp,(char*)&s,2);
	return 0;
}
コード例 #16
0
int clip_PG_OUT_INT4(ClipMachine* mp){
	int i = _clip_parnd(mp,1);
	_clip_retcn(mp,(char*)&i,4);
	return 0;
}
コード例 #17
0
ファイル: clip_WORDREPL.c プロジェクト: amery/clip-angelo
int
clip_WORDREPL(ClipMachine * ClipMachineMemory)
{
   int l, l1, l2, l3, sovp = 0, rcur;

   short *ret, *cur, *s, *e1, *e2, *end, *send, *buf;

   short *sstr = (short *) _clip_parcl(ClipMachineMemory, 1, &l1);

   short *str = (short *) _clip_parcl(ClipMachineMemory, 2, &l2);

   short *rstr = (short *) _clip_parcl(ClipMachineMemory, 3, &l3);

   int flag = _clip_parl(ClipMachineMemory, 4);

   int count = _clip_parni(ClipMachineMemory, 5);

   int cset = (*(unsigned char *) _clip_fetch_item(ClipMachineMemory, HASH_csetatmupa)) == 't';

   int rset = (*(char *) (_clip_fetch_item(ClipMachineMemory, HASH_csetref)) == 't');

   if (sstr == NULL || str == NULL || rstr == NULL)
   {
      _clip_retc(ClipMachineMemory, "");
      return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "WORDREPL");
   }
   if (count < 0)
      count = 0;
   buf = str;
   if (l1 == 0)
   {
      _clip_retcn(ClipMachineMemory, (char *) str, l2);
      return 0;
   }
   l1 = l1 >> 1;
   l2 = l2 >> 1;
   l3 = l3 >> 1;
   while (1)
   {
      l = 0;
      ret = malloc((l + 1) * 2);
      e1 = buf;
      cur = buf;
      end = buf + l2;
      send = sstr + l1;
      for (sovp = 0, rcur = 0; e1 < end; e1++)
      {
	 if (*e1 != *sstr)
	    continue;
	 for (s = sstr, e2 = e1; s < send && e2 < end && *s == *e2; s++, e2++);
	 if (s != send)
	    continue;
	 sovp++;
	 /*
	    if (flag && (sovp!=count || count==0))
	    continue;
	  */
	 l += e1 - cur + l3;
	 ret = realloc(ret, (l + 1) * 2);
	 memcpy(ret + rcur, cur, (e1 - cur) * 2);
	 rcur += e1 - cur;
	 memcpy(ret + rcur, rstr, l3 * 2);
	 rcur += l3;
	 e1 = e2 - 1;
	 cur = e2;
	 if (count != 0 && sovp == count)
	 {
	    e1 = end;
	    break;
	 }
      }
      l += e1 - cur;
      ret = realloc(ret, (l + 1) * 2);
      memcpy(ret + rcur, cur, (e1 - cur) * 2);
      ret[l] = 0;
      if (buf != str)
	 free(buf);
      if (!cset || sovp == 0 || flag || count != 0)
	 break;
      buf = malloc((l + 1) * 2);
      memcpy(buf, ret, l * 2);
      l2 = l;
      free(ret);
   }
   if (rset && _clip_par_isref(ClipMachineMemory, 2))
      _clip_par_assign_str(ClipMachineMemory, 2, (char *) ret, l * 2);
   _clip_retcn_m(ClipMachineMemory, (char *) ret, l * 2);
   return 0;
}
コード例 #18
0
int clip_PG_OUT_FLOAT(ClipMachine* mp){
	float f = (float)_clip_parnd(mp,1);
	_clip_retcn(mp,(char*)&f,4);
	return 0;
}