Example #1
0
/*
*Takes pointer to bounds array as input.
*Balances the amount of string to enumerate
* evenly among the threads. With several calls
* num_to_string.
*/
void balance(bounds *b){
   double total=0;
   int i = 1; //i keeps track of the power
   while(i<=keysize){
      total+=pow(26,i);
      ++i;
   }
   double quo = total/threads;
   quo = floor(quo);
   int remainder = fmod(total,threads);
   quo--; //Decrement so that additon below works out.
   i = 0; //i is repurposed for index counting
   double start;
   double finish = -1;
   while(i<(threads-1)){
      start = finish+1;
      num_to_string(start,b[i].s);
      finish = start + quo;
      num_to_string(finish,b[i].f);
      ++i;
   }
   //For the final thread.
   start = finish+1;
   num_to_string(start,b[i].s);
   finish = start + quo + remainder;
   num_to_string(finish,b[i].f);
}
Example #2
0
inline bool TblIndexInsertValid(JNIEnv* env, T* pTable, jlong columnIndex, jlong rowIndex)
{
    if (!TblColIndexValid(env, pTable, columnIndex))
        return false;
    bool rowErr = realm::util::int_greater_than(rowIndex, pTable->size()+1);
    if (rowErr) {
        TR_ERR("rowIndex %" PRId64 " > %" PRId64 " - invalid!", S64(rowIndex), S64(pTable->size()))
        ThrowException(env, IndexOutOfBounds,
            "rowIndex " + num_to_string(rowIndex) +
            " > available rows " + num_to_string(pTable->size()) + ".");
    }
    return !rowErr;
}
Example #3
0
void IterDialog::OnMinus(wxCommandEvent& event)
{
	// Decreases iterations.
	if(number - 1 > 0) number--;
	text = num_to_string((int)number);
	textCtrl->SetValue(text);
	target->ChangeIterations(number);
}
Example #4
0
void IterDialog::OnPlus(wxCommandEvent& event)
{
	// Increases iterations.
	number++;
	text = num_to_string((int)number);
	textCtrl->SetValue(text);
	target->ChangeIterations(number);
}
Example #5
0
inline bool RowIndexValid(JNIEnv* env, T* pTable, jlong rowIndex, bool offset=false)
{
    if (rowIndex < 0) {
        ThrowException(env, IndexOutOfBounds, "rowIndex is less than 0.");
        return false;
    }
    size_t size = pTable->size();
    if (size > 0 && offset)
        size -= 1;
    bool rowErr = realm::util::int_greater_than_or_equal(rowIndex, size);
    if (rowErr) {
        TR_ERR("rowIndex %" PRId64 " > %" PRId64 " - invalid!", S64(rowIndex), S64(size))
        ThrowException(env, IndexOutOfBounds,
            "rowIndex > available rows: " +
            num_to_string(rowIndex) + " > " + num_to_string(size));
    }
    return !rowErr;
}
Example #6
0
IterDialog::IterDialog(bool *Active, Fractal *_target, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style)
	: wxFrame(parent, id, title, pos, size, style)
{
	// WX Frame.
#ifdef __linux__
	wxIcon icon(GetWxAbsPath("Resources/icon.ico"), wxBITMAP_TYPE_ICO);
#elif _WIN32
    wxIcon icon(GetWxAbsPath("Resources\\icon.ico"), wxBITMAP_TYPE_ICO);
#endif
	this->SetIcon(icon);

	active = Active;
	target = _target;
	this->SetSizeHints(wxSize(314,124), wxSize(314,124));

	wxBoxSizer* boxxy;
	boxxy = new wxBoxSizer(wxVERTICAL);

	panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
	wxBoxSizer* subBoxxy;
	subBoxxy = new wxBoxSizer(wxVERTICAL);

	wxStaticBoxSizer* textBoxxy;
	textBoxxy = new wxStaticBoxSizer(new wxStaticBox(panel, wxID_ANY, wxT(iterationsTxt)), wxHORIZONTAL);	// Txt: "Iterations"

	number = target->GetIterations();
	text = num_to_string((int)number);
	textCtrl = new wxTextCtrl(panel, wxID_ANY, text, wxDefaultPosition, wxDefaultSize, 0);
	textBoxxy->Add(textCtrl, 0, wxALL, 5);

	plusButton = new wxButton(panel, wxID_ANY, wxT("+"), wxDefaultPosition, wxDefaultSize, 0);
	textBoxxy->Add(plusButton, 0, wxALL, 5);

	minusButton = new wxButton(panel, wxID_ANY, wxT("-"), wxDefaultPosition, wxDefaultSize, 0);
	textBoxxy->Add(minusButton, 0, wxALL, 5);

	subBoxxy->Add(textBoxxy, 1, wxEXPAND, 5);

	wxBoxSizer* buttonBoxxy;
	buttonBoxxy = new wxBoxSizer(wxHORIZONTAL);

	acceptButton = new wxButton(panel, wxID_ANY, wxT(okTxt), wxDefaultPosition, wxDefaultSize, 0);	// Txt: "Ok"
	buttonBoxxy->Add(acceptButton, 0, wxALL, 5);

	applyButton = new wxButton(panel, wxID_ANY, wxT(applyTxt), wxDefaultPosition, wxDefaultSize, 0);	// Txt: "Apply"
	buttonBoxxy->Add(applyButton, 0, wxALL, 5);

	subBoxxy->Add(buttonBoxxy, 0, 0, 5);

	panel->SetSizer(subBoxxy);
	panel->Layout();
	subBoxxy->Fit(panel);
	boxxy->Add(panel, 1, wxEXPAND | wxALL, 0);

	this->SetSizer(boxxy);
	this->Layout();

	this->Centre(wxBOTH);

	plusButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(IterDialog::OnPlus), NULL, this);
	minusButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(IterDialog::OnMinus), NULL, this);
	acceptButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(IterDialog::OnOk), NULL, this);
	applyButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(IterDialog::OnApply), NULL, this);
}
Example #7
0
void IterDialog::SetTarget(Fractal* _target)
{
	target = _target;
	textCtrl->SetValue(num_to_string((int)target->GetIterations()));
	number = target->GetIterations();
}
Example #8
0
int main(int argc, char **argv)
{
  char *me = argv[0], *data, **new_argv;
  char *exe_path, *lib_path, *dll_path;
  int start, prog_end, end, count, fd, v, en, x11;
  int argpos, inpos, collcount = 1, fix_argv;

  if (config[7] == '[') {
    write_str(2, argv[0]);
    write_str(2, ": this is an unconfigured starter\n");
    return 1;
  }

  if (me[0] == '/') {
    /* Absolute path */
  } else if (has_slash(me)) {
    /* Relative path with a directory: */
    char *buf;
    long buflen = 4096;
    buf = (char *)malloc(buflen);
    me = path_append(getcwd(buf, buflen), me);
  } else {
    /* We have to find the executable by searching PATH: */
    char *path = copy_string(getenv("PATH")), *p, *m;
    int more;

    if (!path) {
      path = "";
    }

    while (1) {
      /* Try each element of path: */
      for (p = path; *p && (*p != ':'); p++) { }
      if (*p) {
	*p = 0;
	more = 1;
      } else
	more = 0;

      if (!*path)
	break;

      m = path_append(path, me);

      if (executable_exists(m)) {
	if (m[0] != '/')
	  m = path_append(getcwd(NULL, 0), m);
	me = m;
	break;
      }
      free(m);

      if (more)
	path = p + 1;
      else
	break;
    }
  }
  
  /* me is now an absolute path to the binary */

  /* resolve soft links */
  while (1) {
    int len, bufsize = 127;
    char *buf;
    buf = (char *)malloc(bufsize + 1);
    len = readlink(me, buf, bufsize);
    if (len < 0) {
      if (errno == ENAMETOOLONG) {
	/* Increase buffer size and try again: */
	bufsize *= 2;
	buf = (char *)malloc(bufsize + 1);
      } else
	break;
    } else {
      /* Resolve buf relative to me: */
      buf[len] = 0;
      buf = absolutize(buf, me);
      me = buf;
      buf = (char *)malloc(bufsize + 1);
    }
  }

  start = as_int(config + 8);
  prog_end = as_int(config + 12);
  end = as_int(config + 16);
  count = as_int(config + 20);
  x11 = as_int(config + 24);

  fix_argv = try_elf_section(me, &start, &prog_end, &end);

  {
    int offset, len;
    offset = _coldir_offset;
    while (1) {
      len = strlen(_coldir + offset);
      offset += len + 1;
      if (!_coldir[offset])
	break;
      collcount++;
    }
  }

  data = (char *)malloc(end - prog_end);
  new_argv = (char **)malloc((count + argc + (2 * collcount) + 8) * sizeof(char*));

  fd = open(me, O_RDONLY, 0);
  lseek(fd, prog_end, SEEK_SET);
  {
    int expected_length = end - prog_end;
    if (expected_length != read(fd, data, expected_length)) {
      printf("read failed to read all %i bytes from file %s\n", expected_length, me);
      abort();
    }
  }
  close(fd);
  
  exe_path = data;
  data = next_string(data);

  lib_path = data;
  data = next_string(data);

  exe_path = absolutize(exe_path, me);
  lib_path = absolutize(lib_path, me);

# ifdef OS_X
#  define LD_LIB_PATH "DYLD_LIBRARY_PATH"
# else
#  define LD_LIB_PATH "LD_LIBRARY_PATH"
# endif

  if (*lib_path) {
    dll_path = getenv(LD_LIB_PATH);
    if (!dll_path) {
      dll_path = "";
    }
    dll_path = string_append(dll_path, ":");
    dll_path = string_append(lib_path, dll_path);
    dll_path = string_append(LD_LIB_PATH "=", dll_path);
    putenv(dll_path);
  }

  new_argv[0] = me;

  argpos = 1;
  inpos = 1;

  /* Keep all X11 flags to the front: */
  if (x11) {
    int n;
    while (inpos < argc) {
      n = is_x_flag(argv[inpos]);
      if (!n)
	break;
      if (inpos + n > argc) {
	write_str(2, argv[0]);
	write_str(2, ": missing an argument for ");
	write_str(2, argv[inpos]);
	write_str(2, "\n");
	return 1;
      }
      while (n--) {
	new_argv[argpos++] = argv[inpos++];
      }
    }
  }

  /* Add -X and -S flags */
  {
    int offset, len;
    offset = _coldir_offset;
    new_argv[argpos++] = "-X";
    new_argv[argpos++] = absolutize(_coldir + offset, me);
    while (1) {
      len = strlen(_coldir + offset);
      offset += len + 1;
      if (!_coldir[offset])
	break;
      new_argv[argpos++] = "-S";
      new_argv[argpos++] = absolutize(_coldir + offset, me);
    }
  }

  if (fix_argv) {
    /* next three args are "-k" and numbers; fix 
       the numbers to match start and prog_end */
    fix_argv = argpos + 1;
  }

  /* Add built-in flags: */
  while (count--) {
    new_argv[argpos++] = data;
    data = next_string(data);
  }

  /* Propagate new flags (after the X11 flags) */
  while (inpos < argc) {
    new_argv[argpos++] = argv[inpos++];
  }

  new_argv[argpos] = NULL;

  if (fix_argv) {
    new_argv[fix_argv] = num_to_string(start);
    new_argv[fix_argv+1] = num_to_string(prog_end);
  }

  /* Execute the original binary: */

  v = execv(exe_path, new_argv);
  en = errno;

  write_str(2, argv[0]);
  write_str(2, ": failed to start ");
  write_str(2, exe_path);
  write_str(2, " (");
  write_str(2, strerror(en));
  write_str(2, ")\n");
  if (*lib_path) {
    write_str(2, " used library path ");
    write_str(2, lib_path);
    write_str(2, "\n");
  }

  return v;
}
Example #9
0
string RegVar::serializar(){
string serialized= num_to_string(this->size(), BYTES_FOR_RV_LENGTH_REPRESENTATION);
return serialized.append(this->get());
}
Example #10
0
/* Callback which gets called when a new row is selected
   in the acr's variable treeview.
   We use if to set the togglebuttons and entries to correspond to the
   selected row.
*/
static void
on_acr_selection_change (GtkTreeSelection *selection, gpointer data)
{
  struct recode_dialog *rd = data;
  GtkTreeModel *model = NULL;
  GtkTreeIter iter;

  GValue ov_value = {0};
  GValue nv_value = {0};
  struct old_value *ov = NULL;
  struct new_value *nv = NULL;

  if ( ! gtk_tree_selection_get_selected (selection, &model, &iter) )
    return;


  gtk_tree_model_get_value (GTK_TREE_MODEL (model), &iter,
			    COL_VALUE_OLD, &ov_value);

  gtk_tree_model_get_value (GTK_TREE_MODEL (model), &iter,
			    COL_VALUE_NEW, &nv_value);

  ov = g_value_get_boxed (&ov_value);
  nv = g_value_get_boxed (&nv_value);

  if (nv)
    {
      switch (nv->type)
	{
	case NV_NUMERIC:
	  {
	    gchar *str = num_to_string (nv->v.v);

	    gtk_toggle_button_set_active
	      (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_VALUE]), TRUE);

	    gtk_entry_set_text (GTK_ENTRY (rd->new_value_entry), str);
	    g_free (str);
	  }
	  break;
	case NV_STRING:
	  gtk_toggle_button_set_active
	    (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_VALUE]), TRUE);

	  gtk_entry_set_text (GTK_ENTRY (rd->new_value_entry), nv->v.s);
	  break;
	case NV_SYSMIS:
	  gtk_toggle_button_set_active
	    (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_SYSMIS]), TRUE);

	  break;
	case NV_COPY:
	  gtk_toggle_button_set_active
	    (GTK_TOGGLE_BUTTON (rd->toggle [BUTTON_NEW_COPY]), TRUE);

	  break;
	default:
	  g_warning ("Invalid new value type");
	  break;
	}

      g_value_unset (&nv_value);
    }

  psppire_val_chooser_set_status (PSPPIRE_VAL_CHOOSER (rd->old_value_chooser), ov);
}
Example #11
0
		if (flags & HUMAN_FLAG)
			fprintf(fp, " %6s %6s %6s %3s%%",
				bbs_to_string(bcount, s, sizeof(s)),
				bbs_to_string(bused, u, sizeof(u)),
				bbs_to_string(bfree, a, sizeof(a)),
				pct_to_string(bused, bcount, p, sizeof(p)));
		else
			fprintf(fp, " %10llu %10llu %10llu  %3s%%",
				(unsigned long long)bcount >> 1,
				(unsigned long long)bused >> 1,
				(unsigned long long)bfree >> 1,
				pct_to_string(bused, bcount, p, sizeof(p)));
	} else if (form & XFS_INODE_QUOTA) {
		if (flags & HUMAN_FLAG)
			fprintf(fp, " %6s %6s %6s %3s%%",
				num_to_string(icount, s, sizeof(s)),
				num_to_string(iused, u, sizeof(u)),
				num_to_string(ifree, a, sizeof(a)),
				pct_to_string(iused, icount, p, sizeof(p)));
		else
			fprintf(fp, " %10llu %10llu %10llu  %3s%%",
				(unsigned long long)icount,
				(unsigned long long)iused,
				(unsigned long long)ifree,
				pct_to_string(iused, icount, p, sizeof(p)));
	} else if (form & XFS_RTBLOCK_QUOTA) {
		if (flags & HUMAN_FLAG)
			fprintf(fp, " %6s %6s %6s %3s%%",
				bbs_to_string(rcount, s, sizeof(s)),
				bbs_to_string(rused, u, sizeof(u)),
				bbs_to_string(rfree, a, sizeof(a)),
Example #12
0
char * create_item_key( struct item * this_item ) {
    int key_num = NUM_PRODUCTIONS * this_item->prod_num + this_item->dot;
    return num_to_string( key_num );
}
Example #13
0
const char *get_staff_name(int sec_num, int staff_num)
{
	static char name[30], num[2][30];
	sprintf(name, "staff%sx%s", num_to_string(sec_num, num[0]), num_to_string(staff_num, num[1]));
	return name;
}