Beispiel #1
0
/*#######################################################################*/

extern const char *FTIMETYPE[]; /* in vfuopt.cpp */
void vfu_redraw() /* redraw file list and header */
{
  char t[MAX_PATH];
  VString str;

  str  = "Mask: ";
  str += files_mask;
  con_out(1,1,str,cINFO);
  con_ce(cINFO);
  if ( work_mode == WM_ARCHIVE )
    con_out( con_max_x()-34, 1, " [-ARCHIVE-] ", cWARNING );
  con_out(con_max_x()-17,1,"Press H for help",cINFO);
  con_out(con_max_x()-20,1,"VFU " VFU_VERSION " <H> for help",cINFO);

  str = "Path: ";
  str += work_path;
  if ( work_mode == WM_ARCHIVE )
    {
    str += "[";
    str += archive_name;
    str += "]/"; /* NOTE: to simulate root dir visually */
    str += archive_path;
    }
  str = str_dot_reduce( str, con_max_x()-1 );
  con_out(1,2,str,cINFO);
  con_ce(cINFO);

  str = "";

  if ( opt.sort_order == 'N' ) str = "NAME";
  if ( opt.sort_order == 'M' ) str = "NAME#";
  if ( opt.sort_order == 'E' ) str = "EXT";
  if ( opt.sort_order == 'A' ) str = "MODE";
  if ( opt.sort_order == 'O' ) str = "OWNER";
  if ( opt.sort_order == 'G' ) str = "GROUP";
  if ( opt.sort_order == 'T' ) str = "MTIME";
  if ( opt.sort_order == 'H' ) str = "CTIME";
  if ( opt.sort_order == 'C' ) str = "ATIME";
  if ( opt.sort_order == 'S' ) str = "SIZE";
  if ( opt.sort_order == 'Y' ) str = "TYPE";
  str += opt.sort_direction == 'A' ? "+" : "-";
  str = "(SORT:" + str + ")";
  con_out( con_max_x() - str_len( str ) + 1, 2, str, cHEADER );

  str = "";

  t[0] = 0;
  char *spos = t;
  if (opt.sort_order == 'D') opt.sort_order = 'T'; /* hack anyway */
  if (!opt.long_name_view)
    {
    if (opt.f_mode  ) spos += sprintf( spos, "%10s ", MODE_STRING );
    if (opt.f_owner ) spos += sprintf( spos, "   OWNER " );
    if (opt.f_group ) spos += sprintf( spos, "   GROUP " );
    if (opt.f_time  ) spos += sprintf( spos, "%s  TiME ", FTIMETYPE[opt.f_time_type] );
    if (opt.f_size  ) spos += sprintf( spos, filesize_fmt, "SiZE" );
    };
  if ( opt.f_mode + opt.f_owner + opt.f_group + opt.f_time + opt.f_size + opt.f_type == 0 )
    opt.f_type = 1; /* a hack really :) if all fields are off -- turn on type one */
  if (opt.f_type || opt.long_name_view) spos += sprintf( spos, "TP" );
  tag_mark_pos = strlen( t );
  sel_mark_pos = tag_mark_pos + 2;

  spos += sprintf( spos, "  #NAME    %s",
                   opt.long_name_view ? "( long name view )" : "" );

  str_pad( t, - con_max_x() );
  str_sleft( t, con_max_x() );

  con_out(1,3, t, cHEADER );
  show_pos( FLI+1, files_count );

  int z;

  for ( z = 0; z < PS; z++ )
    {
    ASSERT( FLP + z >= 0 );
    if ( FLP + z >= files_count )
      {
      con_out( 1, z+4, "~", cPLAIN );
      con_ce( cPLAIN );
      }
    else if ( files_list[FLP+z] == NULL )  /* FIXME: if NULL?! */
      {
      con_out( 1, z+4, "~", cPLAIN );
      con_ce( cPLAIN );
      }
    else
      vfu_draw( FLP + z );
    }
  if ( files_count <= 0 )
    con_out( ( con_max_x() - 20 ) / 2, 10, " *** No files found *** ", cHEADER);

}
Lng32 MXCI_RW_convDoIt (void *sqlciEnv, char* srcPtr, AttributeDetails* srcEntry,
  char *tgtPtr, AttributeDetails* tgtEntry, short formatting, ErrorValue* &e)
{
  Lng32 retcode = 0;
  ULng32 convFlags = 0;

  if (formatting)
    {
      // if formatting, blankpad target before doing the conversion.
      str_pad (tgtPtr,tgtEntry->displayLen_,' ');

      // the formatted target will be left blank padded (blanks to the left).
      convFlags |= CONV_LEFT_PAD;
    }
  else
    convFlags = 0;


  // SqlciEnv * sqlci_env = (SqlciEnv *)sqlciEnv;

  // Check for nullability.  The logic for this code
  // is in w:/exp/exp_conv.cpp::processNulls function

  //  Source is nullable 
  if (srcEntry->nullable_)  
    {
      //if data is null - if source data is acutally null
      if ((srcPtr[0] != '\0') || (srcPtr[1] != '\0')) 
        {
          if (formatting)
            {
	      //if Target is not nullable
	      if (!(tgtEntry->nullable_)  )
		{
		  tgtPtr[0] = '?';
		  return SUCCESS;  // Conversion has taken place.
		}
	      else 
		{
		  if (e == NULL)
		    {
		      e = new ErrorValue;
		    }
		  SetError(e, -SQLCI_RW_INVALID_FORMATTING);
		  ReportWriterError(e);
		  return ERR;
		}
            } // end of formatting
          else // if not formatting
            {
	      // source is nullable , source is null and target is nullable
	      if (tgtEntry->nullable_)
		{
		  str_pad (tgtPtr,2,'\377');
		  return SUCCESS;  // Conversion has taken place.
		}
	      else
                {
                  if (e == NULL)
		    {
		      e = new ErrorValue;
		    }
                  SetError(e, -SQLCI_CONV_NULL_TO_NOT_NULL);
                  ReportWriterError(e);
                  return ERR;
                }
            }// end of else of if not formatting
          
        }// end of source data is null
      
      // source is nullable but the source data is not null
      else 
        {
          srcPtr = (char*)srcPtr + 2; // skip the null indicator bytes
	  
        } // end of else if source is nullable but source data is not null
      
      //if source is not null and target is nullable
      // set null indicator in target if needed.
      
      if (tgtEntry->nullable_  )
	{
	  str_pad (tgtPtr,2,'\0');    // indicate that tgt is not null. Move the ptr by 2 bytes.
	  tgtPtr = (char*)tgtPtr + 2;
	}
      
    } // end of source is nullable

  char * VCLen = NULL;
  short VCLenSize = 0;
  if (DFS2REC::isAnyVarChar(tgtEntry->dataType_))
    {
      VCLen = tgtPtr;
      VCLenSize = 2;
      tgtPtr = (char*)tgtPtr + VCLenSize;
    }
  
  
  // If the datatype is of time INTERVAL or of type DATETIME, then
  // Set the datatype to _SQLDT_ASCII_F (char)
  // Set the length to the display length.
  // Set the precision to 0.
  // Set the scale to 0.
  
  Lng32 length_;
  Lng32 dataType_;
  Lng32 precision_;
  Lng32 scale_;
  
  if ( srcEntry->dataType_ == _SQLDT_DATETIME  || 
       ( srcEntry->dataType_ >= _SQLDT_INT_Y_Y && srcEntry->dataType_ <= _SQLDT_INT_D_F)
       )
    {
      length_ = srcEntry->displayLen_ ;
      dataType_ = 0;
      precision_ = 0;
      scale_ = 0;
    }
  else
    {
      length_ = srcEntry->length_;
      dataType_ = srcEntry->dataType_;
      precision_ = srcEntry->precision_;
      scale_ = srcEntry->scale_;
    }
  

#pragma warning (disable : 4244)   //warning elimination
#pragma nowarn(1506)   // warning elimination 
  retcode = convDoIt(srcPtr,
		     length_,
		     dataType_,
		     precision_,
		     scale_,
		     tgtPtr,
		     tgtEntry->length_,
		     tgtEntry->dataType_, 
		     tgtEntry->precision_,
		     tgtEntry->scale_,
		     VCLen,			//varCharLen
		     VCLenSize,		//varCharLenSize = 2
		     0,			//heap
		     0,		//diagsarea
		     CONV_UNKNOWN,
		     0,
		     convFlags);
#pragma warn(1506)  // warning elimination 
#pragma warning (default : 4244)   //warning elimination
  
  
  if (retcode)
    {
      return ERR;
    }
  else
    return SUCCESS;
  
}
Beispiel #3
0
int con_toggle_box( int x, int y, const char *title, ToggleEntry* toggles, ConMenuInfo *menu_info  )
{
  ScrollPos scroll;
  int z;

  int w = -1;
  int h = -1;

  int maxlen = 0;
  int count  = 0;
  while( toggles[count].key != -1 )
    {
    int sl = strlen( toggles[count].name );
    if (sl > maxlen) maxlen = sl;
    count++;
    }
  maxlen += 6+3; // 6 for state string and 3 for " key " string in the front

  if (w == -1) w = maxlen;
  if (h == -1) h = count;

  z = strlen(title);
  if (w < z) w = z;
  if (h > count) h = count;
  if (h == 0) h = 1;

  // FIXME: those should be fixed!!!
  if (x + w > con_max_x()) w = con_max_x() - x - 1;
  if (y + h > con_max_y()-4) h = con_max_y() - y - 5;

  VString str;
  VString str1;
  VString hots = "";
  for(z = 0; z < count; z++)
    if (strncmp("--", toggles[z].name, 2))
      str_add_ch( hots, toggles[z].key );
    else
      str_add_ch( hots,' ' );
  con_xy(x,y);
  int ch = 0;

  str = "";
  str = title;
  str_pad( str,-w, menu_info->bo ? '-' : ' ' );
  if (str_len(str) > w) str_sleft(str,w);
  if (menu_info->bo)
    str = ".-" + str + "-.";
  else
    str = "  " + str + "  ";
  con_out(x,y,str,menu_info->ti);
  y++;

  scroll.wrap = 1;
  scroll.set_min_max( 0, count-1 );
  scroll.set_pagesize( h );
  scroll.go( 0 );

  while(1)
    {
    for( z = 0; z < scroll.pagesize(); z++ )
      {
      if (scroll.page() + z >= count)
        {
        str = " ~";
        str_pad( str, -(w+2), ' ');
        }
      else
        {
        int sep = (strncmp("--", toggles[scroll.page()+z].name, 2) == 0);
        if (sep)
          {
          str = "";
          str += toggles[scroll.page()+z].name;
          str_pad( str, -w, '-');
          str += "--";
          }
        else
          {
          str = " "; str_add_ch( str, toggles[scroll.page()+z].key ); str += " ";
          str += toggles[scroll.page()+z].name;
          str_pad( str, -(w-6), ' ');
          str1 = toggles[scroll.page()+z].states[*(toggles[scroll.page()+z].data)];
          str_pad( str1, 6, ' '); str1 += " ";
          str += " " + str1;
          }
        }
      if (menu_info->bo)
        str = "|" + str + "|";
      else
        str = " " + str + " ";
//      if (str.len() > w) StrSLeft(str,w);
//      str = " " + str + " ";
      con_out( x, y+z, str, ( scroll.page()+z != scroll.pos() ) ? menu_info->cn : menu_info->ch );
      }
    if (menu_info->bo)
      {
      str = "";
      str_pad( str, w+2, '-' );
      str = "`" + str + "'";
      con_out( x, y+scroll.pagesize(), str, menu_info->cn );
      }
    ch = con_getch();
    menu_info->ec = ch;

    if ( ch == KEY_UP    ) scroll.up();
    if ( ch == KEY_DOWN  ) scroll.down();
    if ( ch == KEY_NPAGE ) scroll.npage();
    if ( ch == KEY_PPAGE ) scroll.ppage();
    if ( ch == KEY_HOME  ) scroll.home();
    if ( ch == KEY_END   ) scroll.end();

    if ( ch == 27 || ch == 8 ||  ch == KEY_BACKSPACE ) return 0; // exit on ESC or BS
    if ( ch < 0 || ch > 255 ) continue; //FIXME: unicode?
    if ( ch == 13 /* && strncmp("--", toggles[scroll.pos].name, 2) */ ) return 1;
    z = ( ch == ' ' ) ? scroll.pos() : str_find( hots, ch );
    if (z > -1 && strncmp("--", toggles[z].name, 2) )
      {
      int state = *(toggles[z].data) + 1;
      if (toggles[z].states[state] == NULL) state = 0;
      *(toggles[z].data) = state;
      }
    }
  return -1;
}
Beispiel #4
0
int con_menu_box( int x, int y, const char *title, VArray *va, int hotkeys, ConMenuInfo *menu_info  )
{
  ScrollPos scroll;
  int z;

  int w = -1;
  int h = -1;

  if (w == -1) w = va->max_len();
  if (h == -1) h = va->count();

  z = strlen(title);
  if (w < z) w = z;
  if (h > va->count()) h = va->count();
  if (h == 0) h = 1;

  // FIXME: those should be fixed!!!
  if (x + w > con_max_x()) w = con_max_x() - x - 4;
  if (y + h > con_max_y()-4) h = con_max_y() - y - 4;

  VString str;
  VString hots = "";
  if ( hotkeys > -1 )
    {
    for(z = 0; z < va->count(); z++)
      if (strncmp("--", va->get(z), 2))
        str_add_ch( hots, char(((const char*)(va->get(z)))[hotkeys]) );
      else
        str_add_ch( hots,' ' );
    str_up(hots);
    }
  con_xy(x,y);
  int ch = 0;

  str = " ";
  str += title;
  str += " ";
  str_pad( str,-(w), menu_info->bo ? '-' : ' ' );
  if (str_len(str) > w) str_sleft(str,w);
  if (menu_info->bo)
    str = ".-" + str + "-.";
  else
    str = "  " + str + "  ";
  con_out(x,y,str,menu_info->ti);
  y++;

  scroll.wrap = 1;
  scroll.set_min_max( 0, va->count()-1 );
  scroll.set_pagesize( h );
  scroll.go( 0 );

  while(1)
    {
    for( z = 0; z < scroll.pagesize(); z++ )
      {
      str = (scroll.page()+z >= va->count())? "~" : va->get(scroll.page()+z);

      if ( menu_info->hide_magic[0] )
        {
        int i = str_rfind( str, menu_info->hide_magic );
        if ( i != -1)
          str_sleft( str, i );
        }

      str_pad( str,-w , (strncmp("--", str, 2) == 0)?'-':' ');
      if (str_len(str) > w)
        str = str_dot_reduce( str, w );
      if (menu_info->bo)
        str = "| " + str + " |";
      else
        str = "  " + str + "  ";
      con_out( x, y+z, str, ( scroll.page()+z != scroll.pos() ) ? menu_info->cn : menu_info->ch );
      }
    if (menu_info->bo)
      {
      str = "";
      str_pad( str, w+2, '-' );
      str = "`" + str + "'";
      con_out( x, y+scroll.pagesize(), str, menu_info->cn );
      }
    ch = con_getch();
    menu_info->ec = ch;

    if ( ch == KEY_UP    ) scroll.up();
    if ( ch == KEY_DOWN  ) scroll.down();
    if ( ch == KEY_NPAGE ) scroll.npage();
    if ( ch == KEY_PPAGE ) scroll.ppage();
    if ( ch == KEY_HOME  ) scroll.home();
    if ( ch == KEY_END   ) scroll.end();

    if ( ch == 27 || ch == 8 ||  ch == KEY_BACKSPACE )
      {
      // exit on ESC or BS
      menu_info->ac = 0;
      return -1;
      }
    if ( ch < 0 || ch > 255 ) continue; //FIXME: unicode?
    if ( ch == 13 )
      {
      if (strncmp("--", va->get(scroll.pos()), 2) != 0) // ako e "--" e separator
        {
        menu_info->ec = hots[scroll.pos()];
        menu_info->ac = -1;
        return scroll.pos();
        }
      }
    if ( menu_info->ac > -1 && ch == menu_info->ac )
      {
      if (strncmp("--", va->get(scroll.pos()), 2) != 0) // ako e "--" e separator
        {
        menu_info->ec = hots[scroll.pos()];
        menu_info->ac = -2;
        return scroll.pos();
        }
      }
    z = str_find( hots, toupper(ch) );
    if (z > -1)
      {
      menu_info->ec = hots[z];
      menu_info->ac = -1;
      return z;
      }
    }
  menu_info->ac = -1;
  return -1;
}
Beispiel #5
0
integer_t lbfgsb_wrapper(integer_t n, integer_t m, real_t x[], real_t *f,
			 real_t g[], const real_t l[], const real_t u[],
			 const integer_t bnd[], real_t factr, real_t pgtol,
			 char task[], char csave[], integer_t isave[],
			 real_t dsave[], integer_t iprint)
{
  extern void mainlb_(integer_t *n, integer_t *m, real_t *x,
		      const real_t *l, const real_t *u, const integer_t *bnd,
		      real_t *f, real_t *g, real_t *factr, real_t *pgtol,
		      real_t *ws, real_t *wy, real_t *sy, real_t *ss,
		      real_t *wt, real_t *wn, real_t *snd,
		      real_t *z, real_t *r, real_t *d, real_t *t, real_t *wa,
		      integer_t *index, integer_t *iwhere, integer_t *indx2,
		      char *task, integer_t *iprint, char *csave,
		      logical_t *lsave, integer_t *isave, real_t *dsave,
		      ftnlen_t task_len, ftnlen_t csave_len);

 /* Notes about storage in working arrays:
  *
  *   - ISAVE[0..22]             -> ISAVE  in MAINLB (23 elements)
  *   - ISAVE[23..26]            -> LSAVE  in MAINLB  (4 elements)
  *   - ISAVE[26 + (1..N)]       -> INDEX  in MAINLB  (N elements)
  *   - ISAVE[26 + N + (1..N)]   -> IWHERE in MAINLB  (N elements)
  *   - ISAVE[26 + 2*N + (1..N)] -> INDX2  in MAINLB  (N elements)
  *
  *   - DSAVE[0..28]             -> DSAVE  in MAINLB (29 elements)
  *     index 27 of ISAVE;
  *   - arrays WS, ... get stored at index 29 of array DSAVE
  */
  integer_t l1   = m*n;
  integer_t l2   = m*m;
  integer_t l3   = 4*m*m;
  integer_t lws  = 29; /* see note */
  integer_t lwy  = lws + l1;
  integer_t lsy  = lwy + l1;
  integer_t lss  = lsy + l2;
  integer_t lwt  = lss + l2;
  integer_t lwn  = lwt + l2;
  integer_t lsnd = lwn + l3;
  integer_t lz   = lsnd + l3;
  integer_t lr   = lz + n;
  integer_t ld   = lr + n;
  integer_t lt   = ld + n;
  integer_t lwa  = lt + n;
  int c;
  logical_t lsave[4];

  /* copy LOGICAL values */
  lsave[0] = (isave[23] != 0);
  lsave[1] = (isave[24] != 0);
  lsave[2] = (isave[25] != 0);
  lsave[3] = (isave[26] != 0);

  /* call FORTRAN MAINLB subroutine with character arrays fixed */
  mainlb_(&n, &m, x, l, u, bnd, f, g, &factr, &pgtol,
	  &dsave[lws], &dsave[lwy],  &dsave[lsy], &dsave[lss], &dsave[lwt],
	  &dsave[lwn], &dsave[lsnd], &dsave[lz],  &dsave[lr],  &dsave[ld],
	  &dsave[lt], &dsave[lwa],
	  &isave[27], &isave[27 + n], &isave[27 + 2*n],
	  str_pad(task, LBFGSB_TASK_LENGTH), &iprint,
	  str_pad(csave, LBFGSB_TASK_LENGTH), lsave/*&isave[23]*/,
	  &isave[0], &dsave[0],
	  (ftnlen_t)LBFGSB_TASK_LENGTH, (ftnlen_t)LBFGSB_TASK_LENGTH);

  /* copy back LOGICAL values */
  isave[23] = lsave[0];
  isave[24] = lsave[1];
  isave[25] = lsave[2];
  isave[26] = lsave[3];
  
  /* fix character arrays and compute return value (JOB) */
  str_trim(task,  LBFGSB_TASK_LENGTH);
  str_trim(csave, LBFGSB_TASK_LENGTH);
  c = task[0];
  if (c == 'F' && task[1] == 'G')                     return 1;
  if (c == 'N' && ! strncmp(task, "NEW_X", 5))        return 2;
  if (c == 'C' && ! strncmp(task, "CONVERGENCE", 11)) return 3;
  if (c == 'W' && ! strncmp(task, "WARNING", 7))      return 4;
  if (c == 'S' && ! strncmp(task, "START", 5))        return 0;
  /*if (c == 'E' && ! strncmp(task, "ERROR", 5))*/    return 5;
}
Beispiel #6
0
Datei: strlib.c Projekt: j-fu/gr
char *str_ftoa(char *result, double value, double reference)

/*
 *  str_ftoa - convert real value to floating equivalent
 */

{
  static char *digit = "0123456789";
  char format[STR_MAX];

  double abs_val;
  char str[STR_MAX], *fcp, *cp;
  int count, exponent, factor, mantissa;
  int fdigits, digits, scientific_notation;

  if (value != 0)
    {
      abs_val = fabs(value);

      exponent = (int) (log10(abs_val) + pow(10.0, -NDIGITS));
      if (exponent < 0)
	exponent--;

      factor = (NDIGITS - 1) - exponent;
      mantissa = (int) (abs_val * pow(10.0, factor) + 0.5);

      strcpy(result, "");

      count = 0;
      fdigits = digits = 0;

      do
	{
	  count++;

	  strcpy(str, result);
	  result[0] = digit[mantissa % 10];
	  result[1] = '\0';
	  strcat(result, str);

	  if (count == factor)
	    {
	      strcpy(str, result);
	      strcpy(result, ".");
	      strcat(result, str);
	    }

	  mantissa = mantissa / 10;
	}
      while (count != NDIGITS);

      scientific_notation = (exponent <= 1 - NDIGITS) || (exponent >= NDIGITS);

      if (scientific_notation || exponent < 0)
	{
	  if (!scientific_notation)
	    {
	      strcpy(str, "");
	      str_pad(str, '0', -exponent - 1);
	      strcat(str, result);
	      strcpy(result, str);
	    }

	  strcpy(str, "0.");
	  strcat(str, result);
	  strcpy(result, str);
	}

      if (value < 0)
	{
	  strcpy(str, "-");
	  strcat(str, result);
	  strcpy(result, str);
	}

      if (strchr(result, '.') != 0)
	{
	  str_remove(result, '0');
	  str_remove(result, '.');
	}

      if (scientific_notation)
	{
	  strcat(result, "E");
	  sprintf(str, "%d", exponent + 1);
	  strcat(result, str);
	}
      else
	{
	  sprintf(format, "%lg", reference);

	  if (strchr(format, 'E') == 0)

	    if ((fcp = strchr(format, '.')) != 0)
	      {
		fdigits = strlen(format) - (int) (fcp - format) - 1;

		if ((cp = strchr(result, '.')) != 0)
		  {
		    digits = strlen(result) - (int) (cp - result) - 1;

		    if (fdigits > digits)
		      strncat(result, "000000000", fdigits - digits);
		  }
		else
		  {
		    strcat(result, ".");
		    strncat(result, "000000000", fdigits);
		  }
	      }
	}
    }
  else
    strcpy(result, "0");

  return result;
}