Example #1
0
int
clip_COMPLEMENT(ClipMachine * ClipMachineMemory)
{
   int len, dec;

   long d1, d2;

   int t = _clip_parinfo(ClipMachineMemory, 1);

   switch (t)
   {
   case LOGICAL_type_of_ClipVarType:
      _clip_retl(ClipMachineMemory, _clip_parl(ClipMachineMemory, 1));
      break;
   case NUMERIC_type_of_ClipVarType:
      _clip_parp(ClipMachineMemory, 1, &len, &dec);
      _clip_retndp(ClipMachineMemory, 0.00 - _clip_parnd(ClipMachineMemory, 1), len, dec);
      break;
   case CHARACTER_type_of_ClipVarType:
      clip_CHARNOT(ClipMachineMemory);
      break;
   case DATE_type_of_ClipVarType:
      d1 = _clip_jdate(1, 1, 3000);
      d2 = _clip_pardj(ClipMachineMemory, 1);
      if (d2 == 0)
	 _clip_retdj(ClipMachineMemory, d1);
      else
	 _clip_retdj(ClipMachineMemory, d1 - d2 + _clip_jdate(7, 1, 0));
      break;
   }
   return 0;
}
Example #2
0
int
clip_LASTDAYOM(ClipMachine * ClipMachineMemory)
{
   int dd, mm, yy, ww, mm1;

   struct tm *sysTime;

   long d;

   int numpar = _clip_parinfo(ClipMachineMemory, 0);

   _clip_pardc(ClipMachineMemory, 1, &yy, &mm, &dd, &ww);
   mm1 = _clip_parni(ClipMachineMemory, 1);
   if (numpar == 0 || mm1 != 0)
   {
      sysTime = _clip_sysdate();
      yy = sysTime->tm_year + 1900;
      mm = sysTime->tm_mon + 1;
      dd = sysTime->tm_mday;
      free(sysTime);
   }
   if (mm1 != 0)
      mm = mm1;
   d = _clip_jdate(1, mm + 1, yy);
   _clip_cdate(d, &dd, &mm1, &yy, &ww);
   while (mm != mm1)
   {
      d--;
      _clip_cdate(d, &dd, &mm1, &yy, &ww);
   }
   _clip_retndp(ClipMachineMemory, dd, 2, 0);
   return 0;
}
Example #3
0
int clip_PG_IN_DATETIME(ClipMachine* mp){
	PG_ROWSET* rowset = (PG_ROWSET*)_clip_fetch_c_item(
		mp,_clip_parni(mp,1),_C_ITEM_TYPE_SQL);
	char* date;
	long dd,tt;

	if(!rowset){
		_clip_trap_err(mp,0,0,0,subsys,ER_NOROWSET,er_norowset);
		return 1;
	}
	if(rowset->binary){
		double d;
		int l;

		date = _clip_parcl(mp,2,&l);
		d = *(double*)date;
		dd = _clip_jdate(1,1,2000)+d/(24*60*60);
		tt = ((long long)d*1000) % (24*60*60*1000);
		if(tt < 0)
			tt += 24*60*60*1000;
		_clip_retdtj(mp,dd,tt);
	} else {
		int l;
		date = _clip_parcl(mp,2,&l);
		_pg_in_iso_datetime(date,l,&dd,&tt);
		_clip_retdtj(mp,dd,tt);
	}
	return 0;
}
Example #4
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;
}
Example #5
0
int clip_ODBC_IN_TIMESTAMP(ClipMachine* mp){
	char* str = _clip_parc(mp,1);
	ClipVar* ret = RETPTR(mp);

	memset(ret,0,sizeof(ClipVar));
	if(str){
		ret->t.type = DATETIME_t;
		ret->dt.julian = _clip_jdate(*((short*)str+2),*((short*)str+1),*((short*)str));
		ret->dt.time = (*((short*)str+3)*60*60*1000) +
			(*((short*)str+4)*60*1000)+(*((short*)str+5)*1000);
	}
	return 0;
}
Example #6
0
int
_clip_dt_normalize(ClipDateTime * dt)
{
   int ii, jj, ww;

   long d;

   ii = dt->msec % 1000;
   jj = dt->msec / 1000;
   if (ii < 0)
   {
      jj--;
      ii = 1000 + ii;
   }
   dt->msec = ii;
   dt->sec += jj;

   ii = dt->sec % 60;
   jj = dt->sec / 60;
   if (ii < 0)
   {
      jj--;
      ii = 60 + ii;
   }
   dt->sec = ii;
   dt->min += jj;

   ii = dt->min % 60;
   jj = dt->min / 60;
   if (ii < 0)
   {
      jj--;
      ii = 60 + ii;
   }
   dt->min = ii;
   dt->hour += jj;

   ii = dt->hour % 24;
   jj = dt->hour / 24;
   if (ii < 0)
   {
      jj--;
      ii = 24 + ii;
   }
   dt->hour = ii;
   dt->day += jj;

   d = _clip_jdate(dt->day, dt->month, dt->year);
   _clip_cdate(d, &(dt->day), &(dt->month), &(dt->year), &ww);
   return 0;
}
Example #7
0
int
clip_SXDATE(ClipMachine * ClipMachineMemory)
{
   ClipVar *v = _clip_par(ClipMachineMemory, 1);

   ClipMachineMemory->m6_error = 0;
   switch (_clip_parinfo(ClipMachineMemory, 1))
   {
   case DATE_type_of_ClipVarType:
      _clip_retdj(ClipMachineMemory, v->ClipDateVar_d_of_ClipVar.julian_of_ClipDateVar);
      break;
   case CHARACTER_type_of_ClipVarType:
      _clip_retdj(ClipMachineMemory, _clip_str_to_date(v->ClipStrVar_s_of_ClipVar.ClipBuf_str_of_ClipStrVar.buf_of_ClipBuf, ClipMachineMemory->date_format, ClipMachineMemory->epoch));
      break;
   case NUMERIC_type_of_ClipVarType:
      {
	 long alf, a, b, c, d, e, r, dd, mm, yy;

	 long ju = v->ClipNumVar_n_of_ClipVar.double_of_ClipNumVar;

	 alf = (long) ((ju - 1867216.25) / 36524.25);
	 a = ju + 1L + alf - alf / 4;
	 b = a + 1524;
	 c = (long) ((b - 122.1) / 365.25);
	 d = (long) (365.25 * c);
	 e = (long) ((b - d) / 30.6001);
	 dd = b - d - (long) (30.6001 * e);
	 if (e < 14)
	    mm = e - 1;
	 else
	    mm = e - 13;
	 if (mm > 2)
	    yy = c - 4716;
	 else
	    yy = c - 4715;
	 r = _clip_jdate(dd, mm, yy);
	 _clip_retdj(ClipMachineMemory, r);
	 break;
      }
   default:
      _clip_retdj(ClipMachineMemory, 0);
      break;
   }
   return 0;
}
Example #8
0
void _pg_in_iso_datetime(char* date,int l,long* ddd,long* ttt){
	int m,d,y;
	long dd,tt;
	int z;
	if(date){
		y = atoi(date);
		m = atoi(date+5);
		d = atoi(date+8);
		dd = _clip_jdate(d,m,y);

		tt = atoi(date+11)*60*60*1000;
		tt += atoi(date+14)*60*1000;
		tt += atoi(date+17)*1000;
		if(date[19]=='.'){
			tt += atoi(date+20)*10;
			date += 3;
		}

		z = atoi(date+20);
		if(z > 12){ /* +0930 f.e. */
			z = (z/100)*60*60*1000 + (z%100)*60*1000;
		} else {
			z = z*60*60*1000;
		}
		if(date[19]=='+')
			tt -= z;
		else
			tt += z;
		if(tt < 0){
			dd--;
			tt += 24*60*60*1000;
		} else if(tt >= 24*60*60*1000){
			dd++;
			tt -= 24*60*60*1000;
		}
		*ddd = dd;
		*ttt = tt;
	} else {
		*ddd = 0;
		*ttt = 0;
	}
}
Example #9
0
long
_clip_str_to_date(char *str, char *format, int epoch)
{
   int i, j, len;

   int d = 0, m = 0, y = 0;
   int b[3] = { 0, 0, 0 };
   int mms[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
   char ch = 0;

   if (epoch == 0)
      epoch = CLIP_EPOCH_DEFAULT;
   if (format == NULL)
      format = CLIP_DATEFORMAT_DEFAULT;

   len = strlen(format);
   for (i = 0, j = 0; i < len; i++)
   {
      if (ch == format[i])
	 continue;
      switch (format[i])
      {
      case 'y':
      case 'Y':
	 y = j;
	 break;
      case 'm':
      case 'M':
	 m = j;
	 break;
      case 'd':
      case 'D':
	 d = j;
	 break;
      case ' ':
	 break;
      default:
	 j++;
	 break;
      }
      if (j > 2)
	 break;
      ch = format[i];
   }
   if (j < 2)
      return 0;

   len = strlen(str);

   for (i = 0; i < len && !isdigit(str[i]); i++);

   for (j = 0, b[0] = i; i < len && j < 2; i++)
   {
      ch = str[i];
      if ((ch < '0' || ch > '9') && ch != ' ')
      {
	 for (; i < len && !isdigit(str[i]); i++);
	 j++;
	 b[j] = i;
      }
   }
   if (j < 2)
      return 0;
   m = atoi(str + b[m]);
   d = atoi(str + b[d]);
   y = atoi(str + b[y]);
   if (m == 0 && d == 0 && y == 0)
      return 0;
   if (m > 12 || d > 31)
      return 0;
   /*
      printf("\nctod m=%d,d=%d,mms[m]=%d\n",m,d,mms[m]);
    */
   if (m > 0 && (d > mms[m - 1]))
      return 0;

   i = epoch % 100;
   j = epoch / 100;
   if (y < 100)
   {
      if (y < i)
	 y += (j + 1) * 100;
      else
	 y += j * 100;
   }
   return _clip_jdate(d, m, y);
}
Example #10
0
CLIP_DLLEXPORT void
_clip_retdc(ClipMachine * ClipMachineMemory, int yy, int mm, int dd)
{
   _clip_retdj(ClipMachineMemory, _clip_jdate(dd, mm, yy));
}
Example #11
0
int
clip_DIRECTORY(ClipMachine * ClipMachineMemory)
{
   char *str = _clip_parc(ClipMachineMemory, 1);

   char *attr = _clip_parc(ClipMachineMemory, 2);

   int i, *err, flag_dir = 0;

   char buf[PATH_MAX];

   char dirn[PATH_MAX + 1];

   char filen[PATH_MAX + 1];

   char fullname[PATH_MAX + 1];

   char buftime[9];

   struct dirent *dirp;

   struct stat statbuf;

   DIR *dirh;

   ClipVar var, *empty;

   ClipVar *rp = RETPTR(ClipMachineMemory);

   struct tm *sysTime;

   long vect[2];

   vect[0] = 0;
   vect[1] = 0;
   _clip_array(ClipMachineMemory, rp, 1, vect);

   if (attr == NULL || strlen(attr) == 0)
      /*     flag_dir = 1 */ ;
   else
   {
      for (i = 0; i < strlen(attr) && !flag_dir; i++)
	 flag_dir = (attr[i] == 'D');
   }

   if (str == NULL || strlen(str) == 0)
   {
      strcpy(filen, "*.*");
      getcwd(dirn, sizeof(dirn));
   }
   else
   {
      _clip_translate_path(ClipMachineMemory, str, buf, sizeof(buf));
      i = _clip_parse_path(buf, dirn, filen);
#ifdef _WIN32
      if (i < 0)
	 GetCurrentDirectory(PATH_MAX, dirn);
#else
      if (i < 0)
	 getcwd(dirn, sizeof(dirn));
#endif
   }
   dirh = opendir(*dirn == 0 ? "/" : dirn);

   err = _clip_fetch_item(ClipMachineMemory, HASH_ferror);

   if (dirh == NULL)
      *err = errno;
   else
      *err = 0;

   if (dirh == NULL)
   {
      return 0;
   }
   dirp = readdir(dirh);
   i = 0;
   while (dirp != NULL)
   {
#ifdef _WIN32
      if (_clip_glob_match(dirp->d_name, filen, 1) <= 0)
#else
      if (_clip_glob_match(dirp->d_name, filen, 0) <= 0)
#endif
      {
	 dirp = readdir(dirh);
	 continue;
      }
      snprintf(fullname, sizeof(fullname), "%s/%s", dirn, dirp->d_name);
      stat(fullname, &statbuf);
      if (S_ISDIR(statbuf.st_mode) && !flag_dir)
      {
	 dirp = readdir(dirh);
	 continue;
      }
      empty = malloc(sizeof(ClipVar));
      vect[0] = 5;
      _clip_array(ClipMachineMemory, empty, 1, vect);
      vect[0] = i + 1;
      _clip_asize(ClipMachineMemory, rp, 1, vect);
      vect[0] = i;
      _clip_aset(ClipMachineMemory, rp, empty, 1, vect);

      vect[1] = 0;
      memset(&var, 0, sizeof(ClipVar));
      var.ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType = CHARACTER_type_of_ClipVarType;
      var.ClipStrVar_s_of_ClipVar.ClipBuf_str_of_ClipStrVar.buf_of_ClipBuf = dirp->d_name;
      var.ClipStrVar_s_of_ClipVar.ClipBuf_str_of_ClipStrVar.len_of_ClipBuf = strlen(dirp->d_name);
      _clip_aset(ClipMachineMemory, rp, &var, 2, vect);

      memset(&var, 0, sizeof(ClipVar));
      var.ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType = NUMERIC_type_of_ClipVarType;
      var.ClipType_t_of_ClipVar.memo_of_ClipType = 0;
      var.ClipNumVar_n_of_ClipVar.double_of_ClipNumVar = statbuf.st_size;
      vect[1] = 1;
      _clip_aset(ClipMachineMemory, rp, &var, 2, vect);

      memset(&var, 0, sizeof(ClipVar));

      sysTime = localtime(&statbuf.st_mtime);
      var.ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType = DATE_type_of_ClipVarType;
      var.ClipDateVar_d_of_ClipVar.julian_of_ClipDateVar = _clip_jdate(sysTime->tm_mday, sysTime->tm_mon + 1, sysTime->tm_year + 1900);
      vect[1] = 2;
      _clip_aset(ClipMachineMemory, rp, &var, 2, vect);

      memset(&var, 0, sizeof(ClipVar));
      snprintf(buftime, 9, "%02d:%02d:%02d", sysTime->tm_hour, sysTime->tm_min, sysTime->tm_sec);
      var.ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType = CHARACTER_type_of_ClipVarType;
      var.ClipStrVar_s_of_ClipVar.ClipBuf_str_of_ClipStrVar.buf_of_ClipBuf = buftime;
      var.ClipStrVar_s_of_ClipVar.ClipBuf_str_of_ClipStrVar.len_of_ClipBuf = 8;
      vect[1] = 3;
      _clip_aset(ClipMachineMemory, rp, &var, 2, vect);

      memset(&var, 0, sizeof(ClipVar));
      buftime[1] = 0;
      if (S_ISDIR(statbuf.st_mode))
	 buftime[0] = 'D';
      else
	 buftime[0] = 'A';
      var.ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType = CHARACTER_type_of_ClipVarType;
      var.ClipStrVar_s_of_ClipVar.ClipBuf_str_of_ClipStrVar.buf_of_ClipBuf = buftime;
      var.ClipStrVar_s_of_ClipVar.ClipBuf_str_of_ClipStrVar.len_of_ClipBuf = 1;
      vect[1] = 4;
      _clip_aset(ClipMachineMemory, rp, &var, 2, vect);
      _clip_destroy(ClipMachineMemory, empty);
      free(empty);

      dirp = readdir(dirh);
      i++;
   }
   closedir(dirh);

   return 0;
}