示例#1
0
int main(int argc, char * argv[]) {
  int iter;

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs); 
  initialization();
#ifdef _CIVL

  if(nxl != 0) {
    memcpy(&u_curr[1], &u_init[first], sizeof(double) * nxl);
    memcpy(&u_prev[1], &u_curr[1], sizeof(double) * nxl);
  }

#else

  if(nxl != 0) {
    init(first, nxl);
    memcpy(&u_curr[1], &u_prev[1], nxl * sizeof(double));
  }

#endif
  for(iter = 0; iter < nsteps; iter++) {
    if(iter % wstep == 0)
	write_frame(iter);
    if(nxl != 0){
      exchange();
      update();
    }
  }
  free(u_curr);
  free(u_prev);
  free(u_next);
  MPI_Finalize(); 
  return 0;
}
示例#2
0
/*sortQuick: This function will sort the array passed in with a quick sort
 It will also count the number of compares and moves while the heapsort is 
 running.
 Input: randomArray(array of ints),left(int),right(int),compares(int*),moves(int*)
 Return: Nothing*/
/*3*/void sortQuick(int randomArray[],int left,int right,int*compares,int*moves)
{
	int pivot,sortLeft,sortRight;

	if((right - left) >= 3){
		medianLeft(randomArray,left,right,compares,moves);
		pivot = randomArray[left];
        *moves+=1;
		sortLeft = left+1;
		sortRight = right;
		while(sortLeft <= sortRight){
			while(*compares+=1,randomArray[sortLeft] >= pivot){ //Determines ascending or descending
				sortLeft = sortLeft+1;;
			}//end while
			while(*compares+=1,randomArray[sortRight] < pivot){ //Determines ascending or descending
				sortRight = sortRight-1;;
			}//end while
			if(sortLeft <= sortRight){
				exchange(randomArray,sortLeft,sortRight);
                *moves+=3;
				sortLeft = sortLeft+1;
				sortRight = sortRight-1;;
			}//end if
		}//end while
		randomArray[left] = randomArray[sortLeft-1];
        *moves+=1;
		randomArray[sortLeft-1] = pivot;
        *moves+=1;
		if(left < sortRight)
			sortQuick(randomArray,left,sortRight-1,compares,moves);
		if(sortLeft < right)
			sortQuick(randomArray,sortLeft,right,compares,moves);
	}//end if
	else
		sortInsertion(randomArray,right,compares,moves);
}//end sortQuick
示例#3
0
/* sets a date, mapping given date into standard form if needed */
int
set_date(
    char *	date)
{
    char *cmd = NULL;

    clear_dir_list();

    cmd = g_strconcat("DATE ", date, NULL);
    if (converse(cmd) == -1)
	exit(1);

    /* if a host/disk/directory is set, then check if that directory
       is still valid at the new date, and if not set directory to
       mount_point */
    if (disk_path != NULL) {
	g_free(cmd);
	cmd = g_strconcat("OISD ", disk_path, NULL);
	if (exchange(cmd) == -1)
	    exit(1);
	if (server_happy())
	{
	    suck_dir_list_from_server();
	}
	else
	{
	    g_printf(_("No index records for cwd on new date\n"));
	    g_printf(_("Setting cwd to mount point\n"));
	    g_free(disk_path);
	    disk_path = g_strdup("/");	/* fake it */
	    clear_dir_list();
	}
    }
    amfree(cmd);
    return 0;
}
示例#4
0
// Function to process which action to take with current trade
void portfolio::action(pTrade input){
  //  cout << "Enter action" << endl;
  if(input.sortID == "CD")
    return;

  if(input.type == "buy" || input. type == "Buy")
    buy(input);
  else if (input.type == "sell" || input.type == "Sell")
    sell(input);
  else if (input.type == "donate" || input.type == "Donate")
    donate(input);
  else if (input.type == "aquisition" || input.type == "Aquisition")
    acquistion(input);
  else if(input.type == "spinoff" || input.type == "Spinoff")
    spinoff(input);
  else if(input.type == "reverse split" || input.type == "split")
    split(input);
  else if(input.type == "exchange")
    exchange(input);
  else if(input.type == "dividend")
    dividend(input);

  //  cout << "Exit action" << endl << endl;
}
示例#5
0
/*6*/void reheapDown(int randomArray[],int root,int last,int*compares,int*moves)
{
    int leftKey,rightKey,largeChildIndex;
    
    if((root*2+1) <= last){
        leftKey = randomArray[root*2+1];
        if((root*2+2) <= last)
            rightKey = randomArray[root*2+2];
        else
            rightKey = 7500;
        if(leftKey < rightKey)  //Determines ascending or descending
            largeChildIndex = root*2+1;
        else
            largeChildIndex = root*2+2;
        if(*compares+=1,randomArray[root] > randomArray[largeChildIndex]) //Determines ascending or descending
        {
            exchange(randomArray,root,largeChildIndex);
            *moves+=1;
            reheapDown(randomArray,largeChildIndex,last,compares,moves);
        }
    }
    
    
}
示例#6
0
void quickSort(int array[], int start, int end)
{
    int left = start-1;
    int right = end+1;
    const int pivot = array[start];

    if(start >= end)
        return;

    while(1)
    {
        do right--;
        while(array[right] > pivot);
        do left++;
        while(array[left] < pivot);

        if(left < right)
            exchange(array, left, right);
        else break;
    }

    quickSort(array, start, right);
    quickSort(array, right+1, end);
}
示例#7
0
bool Channel::BasicGet(Envelope::ptr_t &envelope, const std::string &queue,
                       bool no_ack) {
  const boost::array<boost::uint32_t, 2> GET_RESPONSES = {
      {AMQP_BASIC_GET_OK_METHOD, AMQP_BASIC_GET_EMPTY_METHOD}};
  m_impl->CheckIsConnected();

  amqp_basic_get_t get = {};
  get.queue = amqp_cstring_bytes(queue.c_str());
  get.no_ack = no_ack;

  amqp_channel_t channel = m_impl->GetChannel();
  amqp_frame_t response = m_impl->DoRpcOnChannel(channel, AMQP_BASIC_GET_METHOD,
                                                 &get, GET_RESPONSES);

  if (AMQP_BASIC_GET_EMPTY_METHOD == response.payload.method.id) {
    m_impl->ReturnChannel(channel);
    m_impl->MaybeReleaseBuffersOnChannel(channel);
    return false;
  }

  amqp_basic_get_ok_t *get_ok =
      (amqp_basic_get_ok_t *)response.payload.method.decoded;
  boost::uint64_t delivery_tag = get_ok->delivery_tag;
  bool redelivered = (get_ok->redelivered == 0 ? false : true);
  std::string exchange((char *)get_ok->exchange.bytes, get_ok->exchange.len);
  std::string routing_key((char *)get_ok->routing_key.bytes,
                          get_ok->routing_key.len);

  BasicMessage::ptr_t message = m_impl->ReadContent(channel);
  envelope = Envelope::Create(message, "", delivery_tag, exchange, redelivered,
                              routing_key, channel);

  m_impl->ReturnChannel(channel);
  m_impl->MaybeReleaseBuffersOnChannel(channel);
  return true;
}
示例#8
0
文件: getopt.c 项目: Ailick/rpcs3
int _getopt_internal_r (int argc, TCHAR *const *argv, const TCHAR *optstring, const struct option *longopts, int *longind, int long_only, struct _getopt_data *d, int posixly_correct)
{
	int print_errors = d->opterr;

	if (argc < 1)
		return -1;

	d->optarg = NULL;

	if (d->optind == 0 || !d->__initialized)
	{
		if (d->optind == 0)
			d->optind = 1;
		optstring = _getopt_initialize (optstring, d, posixly_correct);
		d->__initialized = 1;
	}
	else if (optstring[0] == _T('-') || optstring[0] == _T('+'))
		optstring++;
	if (optstring[0] == _T(':'))
		print_errors = 0;

	if (d->__nextchar == NULL || *d->__nextchar == _T('\0'))
	{
		if (d->__last_nonopt > d->optind)
			d->__last_nonopt = d->optind;
		if (d->__first_nonopt > d->optind)
			d->__first_nonopt = d->optind;

		if (d->__ordering == PERMUTE)
		{
			if (d->__first_nonopt != d->__last_nonopt && d->__last_nonopt != d->optind)
				exchange ((TCHAR **) argv, d);
			else if (d->__last_nonopt != d->optind)
				d->__first_nonopt = d->optind;

			while (d->optind < argc && (argv[d->optind][0] != _T('-') || argv[d->optind][1] == _T('\0')))
				d->optind++;
			d->__last_nonopt = d->optind;
		}

		if (d->optind != argc && !_tcscmp(argv[d->optind], _T("--")))
		{
			d->optind++;

			if (d->__first_nonopt != d->__last_nonopt && d->__last_nonopt != d->optind)
				exchange ((TCHAR **) argv, d);
			else if (d->__first_nonopt == d->__last_nonopt)
				d->__first_nonopt = d->optind;
			d->__last_nonopt = argc;

			d->optind = argc;
		}

		if (d->optind == argc)
		{
			if (d->__first_nonopt != d->__last_nonopt)
				d->optind = d->__first_nonopt;
			return -1;
		}

		if ((argv[d->optind][0] != _T('-') || argv[d->optind][1] == _T('\0')))
		{
			if (d->__ordering == REQUIRE_ORDER)
				return -1;
			d->optarg = argv[d->optind++];
			return 1;
		}

		d->__nextchar = (argv[d->optind] + 1 + (longopts != NULL && argv[d->optind][1] == _T('-')));
	}

	if (longopts != NULL && (argv[d->optind][1] == _T('-') || (long_only && (argv[d->optind][2] || !_tcschr(optstring, argv[d->optind][1])))))
	{
		TCHAR *nameend;
		const struct option *p;
		const struct option *pfound = NULL;
		int exact = 0;
		int ambig = 0;
		int indfound = -1;
		int option_index;

		for (nameend = d->__nextchar; *nameend && *nameend != _T('='); nameend++);

		for (p = longopts, option_index = 0; p->name; p++, option_index++)
			if (!_tcsncmp(p->name, d->__nextchar, nameend - d->__nextchar))
			{
				if ((unsigned int)(nameend - d->__nextchar) == (unsigned int)_tcslen(p->name))
				{
					pfound = p;
					indfound = option_index;
					exact = 1;
					break;
				}
				else if (pfound == NULL)
				{
					pfound = p;
					indfound = option_index;
				}
				else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val)
					ambig = 1;
			}

			if (ambig && !exact)
			{
				if (print_errors)
				{
					_ftprintf(stderr, _T("%s: option '%s' is ambiguous\n"),
						argv[0], argv[d->optind]);
				}
				d->__nextchar += _tcslen(d->__nextchar);
				d->optind++;
				d->optopt = 0;
				return _T('?');
			}

			if (pfound != NULL)
			{
				option_index = indfound;
				d->optind++;
				if (*nameend)
				{
					if (pfound->has_arg)
						d->optarg = nameend + 1;
					else
					{
						if (print_errors)
						{
							if (argv[d->optind - 1][1] == _T('-'))
							{
								_ftprintf(stderr, _T("%s: option '--%s' doesn't allow an argument\n"),argv[0], pfound->name);
							}
							else
							{
								_ftprintf(stderr, _T("%s: option '%c%s' doesn't allow an argument\n"),argv[0], argv[d->optind - 1][0],pfound->name);
							}

						}

						d->__nextchar += _tcslen(d->__nextchar);

						d->optopt = pfound->val;
						return _T('?');
					}
				}
				else if (pfound->has_arg == 1)
				{
					if (d->optind < argc)
						d->optarg = argv[d->optind++];
					else
					{
						if (print_errors)
						{
							_ftprintf(stderr,_T("%s: option '--%s' requires an argument\n"),argv[0], pfound->name);
						}
						d->__nextchar += _tcslen(d->__nextchar);
						d->optopt = pfound->val;
						return optstring[0] == _T(':') ? _T(':') : _T('?');
					}
				}
				d->__nextchar += _tcslen(d->__nextchar);
				if (longind != NULL)
					*longind = option_index;
				if (pfound->flag)
				{
					*(pfound->flag) = pfound->val;
					return 0;
				}
				return pfound->val;
			}

			if (!long_only || argv[d->optind][1] == _T('-') || _tcschr(optstring, *d->__nextchar) == NULL)
			{
				if (print_errors)
				{
					if (argv[d->optind][1] == _T('-'))
					{
						/* --option */
						_ftprintf(stderr, _T("%s: unrecognized option '--%s'\n"),argv[0], d->__nextchar);
					}
					else
					{
						/* +option or -option */
						_ftprintf(stderr, _T("%s: unrecognized option '%c%s'\n"),argv[0], argv[d->optind][0], d->__nextchar);
					}
				}
				d->__nextchar = (TCHAR *)_T("");
				d->optind++;
				d->optopt = 0;
				return _T('?');
			}
	}

	{
		TCHAR c = *d->__nextchar++;
		TCHAR *temp = (TCHAR*)_tcschr(optstring, c);

		if (*d->__nextchar == _T('\0'))
			++d->optind;

		if (temp == NULL || c == _T(':') || c == _T(';'))
		{
			if (print_errors)
			{
				_ftprintf(stderr, _T("%s: invalid option -- '%c'\n"), argv[0], c);
			}
			d->optopt = c;
			return _T('?');
		}
		if (temp[0] == _T('W') && temp[1] == _T(';'))
		{
			TCHAR *nameend;
			const struct option *p;
			const struct option *pfound = NULL;
			int exact = 0;
			int ambig = 0;
			int indfound = 0;
			int option_index;

			if (*d->__nextchar != _T('\0'))
			{
				d->optarg = d->__nextchar;
				d->optind++;
			}
			else if (d->optind == argc)
			{
				if (print_errors)
				{
					_ftprintf(stderr,
						_T("%s: option requires an argument -- '%c'\n"),
						argv[0], c);
				}
				d->optopt = c;
				if (optstring[0] == _T(':'))
					c = _T(':');
				else
					c = _T('?');
				return c;
			}
			else
				d->optarg = argv[d->optind++];

			for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != _T('='); nameend++);

			for (p = longopts, option_index = 0; p->name; p++, option_index++)
				if (!_tcsncmp(p->name, d->__nextchar, nameend - d->__nextchar))
				{
					if ((unsigned int) (nameend - d->__nextchar) == _tcslen(p->name))
					{
						pfound = p;
						indfound = option_index;
						exact = 1;
						break;
					}
					else if (pfound == NULL)
					{
						pfound = p;
						indfound = option_index;
					}
					else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val)
						ambig = 1;
				}
				if (ambig && !exact)
				{
					if (print_errors)
					{
						_ftprintf(stderr, _T("%s: option '-W %s' is ambiguous\n"),
							argv[0], d->optarg);
					}
					d->__nextchar += _tcslen(d->__nextchar);
					d->optind++;
					return _T('?');
				}
				if (pfound != NULL)
				{
					option_index = indfound;
					if (*nameend)
					{
						if (pfound->has_arg)
							d->optarg = nameend + 1;
						else
						{
							if (print_errors)
							{
								_ftprintf(stderr, _T("\
													 %s: option '-W %s' doesn't allow an argument\n"),
													 argv[0], pfound->name);
							}

							d->__nextchar += _tcslen(d->__nextchar);
							return _T('?');
						}
					}
					else if (pfound->has_arg == 1)
					{
						if (d->optind < argc)
							d->optarg = argv[d->optind++];
						else
						{
							if (print_errors)
							{
								_ftprintf(stderr, _T("\
													 %s: option '-W %s' requires an argument\n"),
													 argv[0], pfound->name);
							}
							d->__nextchar += _tcslen(d->__nextchar);
							return optstring[0] == _T(':') ? _T(':') : _T('?');
						}
					}
					else
示例#9
0
	void store(T v, memory_order order=memory_order_seq_cst) volatile
	{
		exchange(v);
	}
示例#10
0
atomic32::atomic32(long val)
{
	exchange(val);
}
示例#11
0
long	atomic32::operator=(long val)
{
	return exchange(val);
}
示例#12
0
atomic32::atomic32(const atomic32& other)
{
	exchange(other.load());
}
示例#13
0
void do_domain(DNS::Resolver& res, char const* dom_cp)
{
  auto const dom{Domain{dom_cp}};

  auto cnames = res.get_strings(DNS::RR_type::CNAME, dom.ascii().c_str());
  if (!cnames.empty()) {
    // RFC 2181 section 10.1. CNAME resource records
    CHECK_EQ(cnames.size(), 1);
    std::cout << dom << " is an alias for " << cnames.front() << '\n';
  }

  auto as = res.get_strings(DNS::RR_type::A, dom.ascii().c_str());
  for (auto const& a : as) {
    do_addr(res, a.c_str());
  }

  auto aaaas = res.get_strings(DNS::RR_type::AAAA, dom.ascii().c_str());
  for (auto const& aaaa : aaaas) {
    do_addr(res, aaaa.c_str());
  }

  auto q{DNS::Query{res, DNS::RR_type::MX, dom.ascii()}};
  if (!q.has_record()) {
    std::cout << "no records\n";
    return;
  }

  TLD  tld_db;
  auto reg_dom{tld_db.get_registered_domain(dom.ascii())};
  if (dom != reg_dom) {
    std::cout << "registered domain is " << reg_dom << '\n';
  }

  check_uribls(res, dom.ascii().c_str());

  if (q.authentic_data()) {
    std::cout << "MX records authentic for domain " << dom << '\n';
  }

  auto mxs{q.get_records()};

  mxs.erase(std::remove_if(begin(mxs), end(mxs),
                           [](auto const& rr) {
                             return !std::holds_alternative<DNS::RR_MX>(rr);
                           }),
            end(mxs));

  if (!mxs.empty())
    std::cout << "mail for " << dom << " is handled by\n";

  std::sort(begin(mxs), end(mxs), [](auto const& a, auto const& b) {
    auto mxa = std::get<DNS::RR_MX>(a);
    auto mxb = std::get<DNS::RR_MX>(b);
    if (mxa.preference() == mxb.preference())
      return mxa.exchange() < mxb.exchange();
    return mxa.preference() < mxb.preference();
  });

  for (auto const& mx : mxs) {
    if (std::holds_alternative<DNS::RR_MX>(mx)) {
      auto x = std::get<DNS::RR_MX>(mx);
      std::cout << std::setfill(' ') << std::setw(3) << x.preference() << ' '
                << x.exchange() << '\n';
    }
  }
}
示例#14
0
/* do this by looking for the longest mount point which matches the
   current directory */
int
guess_disk (
    char *	cwd,
    size_t	cwd_len,
    char **	dn_guess,
    char **	mpt_guess)
{
    size_t longest_match = 0;
    size_t current_length;
    size_t cwd_length;
    int local_disk = 0;
    generic_fsent_t fsent;
    char *fsname = NULL;
    char *disk_try = NULL;

    *dn_guess = NULL;
    *mpt_guess = NULL;

    if (getcwd(cwd, cwd_len) == NULL) {
	return -1;
	/*NOTREACHED*/
    }
    cwd_length = strlen(cwd);
    dbprintf(_("guess_disk: %zu: \"%s\"\n"), cwd_length, cwd);

    if (open_fstab() == 0) {
	return -1;
	/*NOTREACHED*/
    }

    while (get_fstab_nextentry(&fsent))
    {
	current_length = fsent.mntdir ? strlen(fsent.mntdir) : (size_t)0;
	dbprintf(_("guess_disk: %zu: %zu: \"%s\": \"%s\"\n"),
		  longest_match,
		  current_length,
		  fsent.mntdir ? fsent.mntdir : _("(mntdir null)"),
		  fsent.fsname ? fsent.fsname : _("(fsname null)"));
	if ((current_length > longest_match)
	    && (current_length <= cwd_length)
	    && (g_str_has_prefix(cwd, fsent.mntdir)))
	{
	    longest_match = current_length;
	    g_free(*mpt_guess);
	    *mpt_guess = g_strdup(fsent.mntdir);
	    if(strncmp(fsent.fsname,DEV_PREFIX,(strlen(DEV_PREFIX))))
	    {
	        g_free(fsname);
	        fsname = g_strdup(fsent.fsname);
            }
	    else
	    {
	        g_free(fsname);
	        fsname = g_strdup(fsent.fsname + strlen(DEV_PREFIX));
	    }
	    local_disk = is_local_fstype(&fsent);
	    dbprintf(_("guess_disk: local_disk = %d, fsname = \"%s\"\n"),
		      local_disk,
		      fsname);
	}
    }
    close_fstab();

    if (longest_match == 0) {
	amfree(*mpt_guess);
	amfree(fsname);
	return -1;			/* ? at least / should match */
    }

    if (!local_disk) {
	amfree(*mpt_guess);
	amfree(fsname);
	return 0;
    }

    /* have mount point now */
    /* disk name may be specified by mount point (logical name) or
       device name, have to determine */
    g_printf(_("Trying disk %s ...\n"), *mpt_guess);
    disk_try = g_strconcat("DISK ", *mpt_guess, NULL);		/* try logical name */
    if (exchange(disk_try) == -1)
	exit(1);
    amfree(disk_try);
    if (server_happy())
    {
	*dn_guess = g_strdup(*mpt_guess);		/* logical is okay */
	amfree(fsname);
	return 1;
    }
    g_printf(_("Trying disk %s ...\n"), fsname);
    disk_try = g_strconcat("DISK ", fsname, NULL);		/* try device name */
    if (exchange(disk_try) == -1)
	exit(1);
    amfree(disk_try);
    if (server_happy())
    {
	*dn_guess = g_strdup(fsname);			/* dev name is okay */
	amfree(fsname);
	return 1;
    }

    /* neither is okay */
    amfree(*mpt_guess);
    amfree(fsname);
    return 2;
}
示例#15
0
void CCAD_5_23Dlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	double fine0[N+2];
	double fine[N+2]={0};
	double b[N+1];
	double j[N+1];
	int flag=0;
	int i;
	CWnd * x=(CWnd *) GetDlgItem(IDC_STATIC);
	CDC * pDC1 =x->GetDC() ;
	
	CBrush brush_1(RGB(255,255,255));
	CBrush brush_2(RGB(0,0,0));
	CRect rect(0,0,700,500);
	do_fine0(fine0,N);
	 while(!flag)
	 {
	 do_b(b,fine0,N);
	 do_j(j,fine0,N);
	 zhuigan(fine,b,j,N-1);
	 flag=check(fine,N);
//	 printf("%d",flag);
	 exchange(fine0,fine,N-1);
	 }
for(i=0;i<500;i++)
				{
				fine0[i]=(int)(fine0[i]*500);
			
				}
	 	pDC1->Rectangle(rect);
	pDC1->FillRect(rect,&brush_1);
	pDC1->SelectObject(brush_2);

	
	
		
				for(i=0;i<500;i++)
				{
		//		pDC1->Ellipse(i,fine0[i],i+1,fine0[i]+1); // ×¢Òâ¾ÍÐÐ
			pDC1->SetPixel(i+50,450-fine0[i],RGB(0,128,128)); 
				if(i%10==0)
				{
					pDC1->SetPixel(i-1+50,450-fine0[i]-1,RGB(0,0,0));
					pDC1->SetPixel(i-1+50,450-fine0[i]+1,RGB(0,0,0));
					pDC1->SetPixel(i+1+50,450-fine0[i]-1,RGB(0,0,0));
					pDC1->SetPixel(i+1+50,450-fine0[i]+1,RGB(0,0,0));
					pDC1->SetPixel(i-2+50,450-fine0[i]-2,RGB(0,0,0));
					pDC1->SetPixel(i-2+50,450-fine0[i]+2,RGB(0,0,0));
					pDC1->SetPixel(i+2+50,450-fine0[i]-2,RGB(0,0,0));
					pDC1->SetPixel(i+2+50,450-fine0[i]+2,RGB(0,0,0));
				}
				}
				for(i=0;i<5;i++)
				{
					pDC1->SetPixel(100+50,450-i,RGB(0,0,0));
					pDC1->SetPixel(200+50,450-i,RGB(0,0,0));
					pDC1->SetPixel(300+50,450-i,RGB(0,0,0));
					pDC1->SetPixel(400+50,450-i,RGB(0,0,0));
					pDC1->SetPixel(500+50,450-i,RGB(0,0,0));

					pDC1->SetPixel(i+50,450-50,RGB(0,0,0));
					pDC1->SetPixel(i+50,450-100,RGB(0,0,0));
					pDC1->SetPixel(i+50,450-150,RGB(0,0,0));
					pDC1->SetPixel(i+50,450-200,RGB(0,0,0));
				
				}
				for(i=0;i<=550;i++)
				{
					pDC1->SetPixel(i+50,450,RGB(0,0,0));
				
				}
				for(i=200;i<=450;i++)
					pDC1->SetPixel(50,i,RGB(0,0,0));
				pDC1->TextOut(50,451,"0");
				pDC1->TextOut(150,451,"0.1");
				pDC1->TextOut(250,451,"0.2");
				pDC1->TextOut(350,451,"0.3");
				pDC1->TextOut(450,451,"0.4");
				pDC1->TextOut(550,451,"0.5");

			
				pDC1->TextOut(30,450-50-10,"0.1");
				pDC1->TextOut(30,450-100-10,"0.2");
				pDC1->TextOut(30,450-150-10,"0.3");
				pDC1->TextOut(30,450-200-10,"0.4");


				pDC1->SetPixel(600-1,450-1,RGB(0,0,0));
				pDC1->SetPixel(600-2,450-2,RGB(0,0,0));
				pDC1->SetPixel(600-3,450-3,RGB(0,0,0));
				pDC1->SetPixel(600-4,450-4,RGB(0,0,0));
				pDC1->SetPixel(600-1,450+1,RGB(0,0,0));
				pDC1->SetPixel(600-2,450+2,RGB(0,0,0));
				pDC1->SetPixel(600-3,450+3,RGB(0,0,0));
				pDC1->SetPixel(600-4,450+4,RGB(0,0,0));

				pDC1->SetPixel(50-1,200+1,RGB(0,0,0));
				pDC1->SetPixel(50-2,200+2,RGB(0,0,0));
				pDC1->SetPixel(50-3,200+3,RGB(0,0,0));
				pDC1->SetPixel(50-4,200+4,RGB(0,0,0));
				pDC1->SetPixel(50+1,200+1,RGB(0,0,0));
				pDC1->SetPixel(50+2,200+2,RGB(0,0,0));
				pDC1->SetPixel(50+3,200+3,RGB(0,0,0));
				pDC1->SetPixel(50+4,200+4,RGB(0,0,0));

	 
}
示例#16
0
  void ButtonBox::on_size_request(int& w_, int& h_)
  {
#ifdef NDEBUG
    testInvariant(TEST_EXPANDABLE_VISIBLE_COUNT);
#endif

    Container::on_size_request(w_, h_);

    ProxySizeRequest proxy_size_request(*this, w_, h_);

    _expandable_childrens_size_request  = 0;

    if(get_children().size()==0)
      return;

    _n_visible_children=0;

    _max_child_width  = _min_max_child_width;
    _max_child_height = _min_max_child_height;

    if(get_is_horizontal())
      exchange(_max_child_width, _max_child_height);

    for(BoxChildContainerList::iterator iter = _start_children.begin(); iter!=_end_children.end();)
    {
      if(iter==_start_children.end())
      {
        iter  = _end_children.begin();
        continue;
      }

      if(iter->child->is_visible())
      {
        ++_n_visible_children;

        ProxyChild proxy_child(*this, *iter->child);

        _max_child_width = MAX(_max_child_width , proxy_child.get_size_request_width());
        _max_child_height = MAX(_max_child_height , proxy_child.get_size_request_height());
      }

      ++iter;
    }

    if(get_layout()==BUTTONBOX_SPREAD)
      proxy_size_request.h() += (_n_visible_children+1) * _spacing;
    else
      proxy_size_request.h() += (_n_visible_children-1) * _spacing;
    proxy_size_request.h() += _max_child_height*_n_visible_children;
    proxy_size_request.w() += _max_child_width;

    _children_size_request_width  = w_;
    _children_size_request_height  = h_;

    if(get_is_horizontal())
    {
      exchange(_max_child_width, _max_child_height);
    }

#ifdef NDEBUG
    testInvariant(TEST_EXPANDABLE_VISIBLE_COUNT);
#endif
  }
示例#17
0
int
_getopt_internal ( int argc,
     char *const *argv,
     const char *optstring,
     const struct option *longopts,
     int *longind,
     int long_only)

{
  int option_index;

  optarg = 0;

  /* Initialize the internal data when the first call is made.
     Start processing options with ARGV-element 1 (since ARGV-element 0
     is the program name); the sequence of previously skipped
     non-option ARGV-elements is empty.  */

  if (optind == 0)
    {
      first_nonopt = last_nonopt = optind = 1;

      nextchar = NULL;

      /* Determine how to handle the ordering of options and nonoptions.  */

      if (optstring[0] == '-')
	{
	  ordering = RETURN_IN_ORDER;
	  ++optstring;
	}
      else if (optstring[0] == '+')
	{
	  ordering = REQUIRE_ORDER;
	  ++optstring;
	}
   #ifndef _WIN32
      else if (getenv ("POSIXLY_CORRECT") != NULL)
	ordering = REQUIRE_ORDER;
   #endif
      else
	ordering = PERMUTE;
    }

  if (nextchar == NULL || *nextchar == '\0')
    {
      if (ordering == PERMUTE)
	{
	  /* If we have just processed some options following some non-options,
	     exchange them so that the options come first.  */

	  if (first_nonopt != last_nonopt && last_nonopt != optind)
	    exchange ((char **) argv);
	  else if (last_nonopt != optind)
	    first_nonopt = optind;

	  /* Now skip any additional non-options
	     and extend the range of non-options previously skipped.  */

	  while (optind < argc
		 && (argv[optind][0] != '-' || argv[optind][1] == '\0')
#ifdef GETOPT_COMPAT
		 && (longopts == NULL
		     || argv[optind][0] != '+' || argv[optind][1] == '\0')
#endif				/* GETOPT_COMPAT */
		 )
	    optind++;
	  last_nonopt = optind;
	}

      /* Special ARGV-element `--' means premature end of options.
	 Skip it like a null option,
	 then exchange with previous non-options as if it were an option,
	 then skip everything else like a non-option.  */

      if (optind != argc && !strcmp (argv[optind], "--"))
	{
	  optind++;

	  if (first_nonopt != last_nonopt && last_nonopt != optind)
	    exchange ((char **) argv);
	  else if (first_nonopt == last_nonopt)
	    first_nonopt = optind;
	  last_nonopt = argc;

	  optind = argc;
	}

      /* If we have done all the ARGV-elements, stop the scan
	 and back over any non-options that we skipped and permuted.  */

      if (optind == argc)
	{
	  /* Set the next-arg-index to point at the non-options
	     that we previously skipped, so the caller will digest them.  */
	  if (first_nonopt != last_nonopt)
	    optind = first_nonopt;
	  return EOF;
	}

      /* If we have come to a non-option and did not permute it,
	 either stop the scan or describe it to the caller and pass it by.  */

      if ((argv[optind][0] != '-' || argv[optind][1] == '\0')
#ifdef GETOPT_COMPAT
	  && (longopts == NULL
	      || argv[optind][0] != '+' || argv[optind][1] == '\0')
#endif				/* GETOPT_COMPAT */
	  )
	{
	  if (ordering == REQUIRE_ORDER)
	    return EOF;
	  optarg = argv[optind++];
	  return 1;
	}

      /* We have found another option-ARGV-element.
	 Start decoding its characters.  */

      nextchar = (argv[optind] + 1
		  + (longopts != NULL && argv[optind][1] == '-'));
    }

  if (longopts != NULL
      && ((argv[optind][0] == '-'
	   && (argv[optind][1] == '-' || long_only))
#ifdef GETOPT_COMPAT
	  || argv[optind][0] == '+'
#endif				/* GETOPT_COMPAT */
	  ))
    {
      const struct option *p;
      char *s = nextchar;
      int exact = 0;
      int ambig = 0;
      const struct option *pfound = NULL;
      int indfound = 0;

      while (*s && *s != '=')
	s++;

      /* Test all options for either exact match or abbreviated matches.  */
      for (p = longopts, option_index = 0; p->name;
	   p++, option_index++)
	if (!strncmp (p->name, nextchar, s - nextchar))
	  {
	    if (s - nextchar == my_strlen (p->name))
	      {
		/* Exact match found.  */
		pfound = p;
		indfound = option_index;
		exact = 1;
		break;
	      }
	    else if (pfound == NULL)
	      {
		/* First nonexact match found.  */
		pfound = p;
		indfound = option_index;
	      }
	    else
	      /* Second nonexact match found.  */
	      ambig = 1;
	  }

      if (ambig && !exact)
	{
	  if (opterr)
	    fprintf (stderr, "%s: option `%s' is ambiguous\n",
		     argv[0], argv[optind]);
	  nextchar += my_strlen (nextchar);
	  optind++;
	  return BAD_OPTION;
	}

      if (pfound != NULL)
	{
	  option_index = indfound;
	  optind++;
	  if (*s)
	    {
	      /* Don't test has_arg with >, because some C compilers don't
		 allow it to be used on enums.  */
	      if (pfound->has_arg)
		optarg = s + 1;
	      else
		{
		  if (opterr)
		    {
		      if (argv[optind - 1][1] == '-')
			/* --option */
			fprintf (stderr,
				 "%s: option `--%s' doesn't allow an argument\n",
				 argv[0], pfound->name);
		      else
			/* +option or -option */
			fprintf (stderr,
			     "%s: option `%c%s' doesn't allow an argument\n",
			     argv[0], argv[optind - 1][0], pfound->name);
		    }
		  nextchar += my_strlen (nextchar);
		  return BAD_OPTION;
		}
	    }
	  else if (pfound->has_arg == 1)
	    {
	      if (optind < argc)
		optarg = argv[optind++];
	      else
		{
		  if (opterr)
		    fprintf (stderr, "%s: option `%s' requires an argument\n",
			     argv[0], argv[optind - 1]);
		  nextchar += my_strlen (nextchar);
		  return optstring[0] == ':' ? ':' : BAD_OPTION;
		}
	    }
	  nextchar += my_strlen (nextchar);
	  if (longind != NULL)
	    *longind = option_index;
	  if (pfound->flag)
	    {
	      *(pfound->flag) = pfound->val;
	      return 0;
	    }
	  return pfound->val;
	}
      /* Can't find it as a long option.  If this is not getopt_long_only,
	 or the option starts with '--' or is not a valid short
	 option, then it's an error.
	 Otherwise interpret it as a short option.  */
      if (!long_only || argv[optind][1] == '-'
#ifdef GETOPT_COMPAT
	  || argv[optind][0] == '+'
#endif				/* GETOPT_COMPAT */
	  || my_index (optstring, *nextchar) == NULL)
	{
	  if (opterr)
	    {
	      if (argv[optind][1] == '-')
		/* --option */
		fprintf (stderr, "%s: unrecognized option `--%s'\n",
			 argv[0], nextchar);
	      else
		/* +option or -option */
		fprintf (stderr, "%s: unrecognized option `%c%s'\n",
			 argv[0], argv[optind][0], nextchar);
	    }
	  nextchar = (char *) "";
	  optind++;
	  return BAD_OPTION;
	}
    }

  /* Look at and handle the next option-character.  */

  {
    char c = *nextchar++;
    char *temp = my_index (optstring, c);

    /* Increment `optind' when we start to process its last character.  */
    if (*nextchar == '\0')
      ++optind;

    if (temp == NULL || c == ':')
      {
	if (opterr)
	  {
#if 0
	    if (c < 040 || c >= 0177)
	      fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
		       argv[0], c);
	    else
	      fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
#else
	    /* 1003.2 specifies the format of this message.  */
	    fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
#endif
	  }
	optopt = c;
	return BAD_OPTION;
      }
    if (temp[1] == ':')
      {
	if (temp[2] == ':')
	  {
	    /* This is an option that accepts an argument optionally.  */
	    if (*nextchar != '\0')
	      {
		optarg = nextchar;
		optind++;
	      }
	    else
	      optarg = 0;
	    nextchar = NULL;
	  }
	else
	  {
	    /* This is an option that requires an argument.  */
	    if (*nextchar != '\0')
	      {
		optarg = nextchar;
		/* If we end this ARGV-element by taking the rest as an arg,
		   we must advance to the next element now.  */
		optind++;
	      }
	    else if (optind == argc)
	      {
		if (opterr)
		  {
#if 0
		    fprintf (stderr, "%s: option `-%c' requires an argument\n",
			     argv[0], c);
#else
		    /* 1003.2 specifies the format of this message.  */
		    fprintf (stderr, "%s: option requires an argument -- %c\n",
			     argv[0], c);
#endif
		  }
		optopt = c;
		if (optstring[0] == ':')
		  c = ':';
		else
		  c = BAD_OPTION;
	      }
	    else
	      /* We already incremented `optind' once;
		 increment it again when taking next ARGV-elt as argument.  */
	      optarg = argv[optind++];
	    nextchar = NULL;
	  }
      }
    return c;
  }
}
示例#18
0
int
main(
    int		argc,
    char **	argv)
{
    in_port_t my_port;
    struct servent *sp;
    int i;
    time_t timer;
    char *lineread = NULL;
    struct sigaction act, oact;
    extern char *optarg;
    extern int optind;
    char cwd[STR_SIZE], *dn_guess = NULL, *mpt_guess = NULL;
    char *service_name;
    char *line = NULL;
    struct tm *tm;

    /*
     * Configure program for internationalization:
     *   1) Only set the message locale for now.
     *   2) Set textdomain for all amanda related programs to "amanda"
     *      We don't want to be forced to support dozens of message catalogs.
     */  
    setlocale(LC_MESSAGES, "C");
    textdomain("amanda"); 

    safe_fd(-1, 0);

    set_pname("amoldrecover");

    /* Don't die when child closes pipe */
    signal(SIGPIPE, SIG_IGN);

    dbopen(DBG_SUBDIR_CLIENT);

    localhost = g_malloc(MAX_HOSTNAME_LENGTH+1);
    if (gethostname(localhost, MAX_HOSTNAME_LENGTH) != 0) {
	error(_("cannot determine local host name\n"));
	/*NOTREACHED*/
    }
    localhost[MAX_HOSTNAME_LENGTH] = '\0';

    g_free(config);
    config = g_strdup(DEFAULT_CONFIG);

    dbrename(config, DBG_SUBDIR_CLIENT);

    check_running_as(RUNNING_AS_ROOT);

    amfree(server_name);
    server_name = getenv("AMANDA_SERVER");
    if(!server_name) server_name = DEFAULT_SERVER;
    server_name = g_strdup(server_name);

    amfree(tape_server_name);
    tape_server_name = getenv("AMANDA_TAPESERVER");
    if(!tape_server_name) tape_server_name = DEFAULT_TAPE_SERVER;
    tape_server_name = g_strdup(tape_server_name);

    config_init(CONFIG_INIT_CLIENT, NULL);

    if (config_errors(NULL) >= CFGERR_WARNINGS) {
	config_print_errors();
	if (config_errors(NULL) >= CFGERR_ERRORS) {
	    g_critical(_("errors processing config file"));
	}
    }

    if (argc > 1 && argv[1][0] != '-')
    {
	/*
	 * If the first argument is not an option flag, then we assume
	 * it is a configuration name to match the syntax of the other
	 * Amanda utilities.
	 */
	char **new_argv;

	new_argv = (char **) g_malloc((size_t)((argc + 1 + 1) * sizeof(*new_argv)));
	new_argv[0] = argv[0];
	new_argv[1] = "-C";
	for (i = 1; i < argc; i++)
	{
	    new_argv[i + 1] = argv[i];
	}
	new_argv[i + 1] = NULL;
	argc++;
	argv = new_argv;
    }
    while ((i = getopt(argc, argv, "C:s:t:d:U")) != EOF)
    {
	switch (i)
	{
	    case 'C':
		g_free(config);
		config = g_strdup(optarg);
		break;

	    case 's':
		g_free(server_name);
		server_name = g_strdup(optarg);
		break;

	    case 't':
		g_free(tape_server_name);
		tape_server_name = g_strdup(optarg);
		break;

	    case 'd':
		g_free(tape_device_name);
		tape_device_name = g_strdup(optarg);
		break;

	    case 'U':
	    case '?':
		(void)g_printf(USAGE);
		return 0;
	}
    }
    if (optind != argc)
    {
	(void)g_fprintf(stderr, USAGE);
	exit(1);
    }

    amfree(disk_name);
    amfree(mount_point);
    amfree(disk_path);
    dump_date[0] = '\0';

    /* Don't die when child closes pipe */
    signal(SIGPIPE, SIG_IGN);

    /* set up signal handler */
    act.sa_handler = sigint_handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
#ifdef SA_RESTORER
    act.sa_restorer = NULL;
#endif
    if (sigaction(SIGINT, &act, &oact) != 0) {
	error(_("error setting signal handler: %s"), strerror(errno));
	/*NOTREACHED*/
    }

    service_name = "amandaidx";

    g_printf(_("AMRECOVER Version %s. Contacting server on %s ...\n"),
	   VERSION, server_name);
    if ((sp = getservbyname(service_name, "tcp")) == NULL) {
	error(_("%s/tcp unknown protocol"), service_name);
	/*NOTREACHED*/
    }
    server_socket = stream_client_privileged(server_name,
					     (in_port_t)ntohs((in_port_t)sp->s_port),
					     0,
					     0,
					     &my_port,
					     0);
    if (server_socket < 0) {
	error(_("cannot connect to %s: %s"), server_name, strerror(errno));
	/*NOTREACHED*/
    }
    if (my_port >= IPPORT_RESERVED) {
        aclose(server_socket);
	error(_("did not get a reserved port: %d"), my_port);
	/*NOTREACHED*/
    }

    /* get server's banner */
    if (grab_reply(1) == -1) {
        aclose(server_socket);
	exit(1);
    }
    if (!server_happy())
    {
	dbclose();
	aclose(server_socket);
	exit(1);
    }

    /* do the security thing */
    line = get_security();
    if (converse(line) == -1) {
        aclose(server_socket);
	exit(1);
    }
    if (!server_happy()) {
        aclose(server_socket);
	exit(1);
    }
    memset(line, '\0', strlen(line));
    amfree(line);

    /* try to get the features from the server */
    {
	char *our_feature_string = NULL;
	char *their_feature_string = NULL;

	our_features = am_init_feature_set();
	our_feature_string = am_feature_to_string(our_features);
	line = g_strconcat("FEATURES ", our_feature_string, NULL);
	if(exchange(line) == 0) {
	    their_feature_string = g_strdup(server_line+13);
	    indexsrv_features = am_string_to_feature(their_feature_string);
	}
	else {
	    indexsrv_features = am_set_default_feature_set();
        }
	amfree(our_feature_string);
	amfree(their_feature_string);
	amfree(line);
    }

    /* set the date of extraction to be today */
    (void)time(&timer);
    tm = localtime(&timer);
    if (tm)
	strftime(dump_date, sizeof(dump_date), "%Y-%m-%d", tm);
    else
	error(_("BAD DATE"));

    g_printf(_("Setting restore date to today (%s)\n"), dump_date);
    line = g_strconcat("DATE ", dump_date, NULL);
    if (converse(line) == -1) {
        aclose(server_socket);
	exit(1);
    }
    amfree(line);

    line = g_strconcat("SCNF ", config, NULL);
    if (converse(line) == -1) {
        aclose(server_socket);
	exit(1);
    }
    amfree(line);

    if (server_happy())
    {
	/* set host we are restoring to this host by default */
	amfree(dump_hostname);
	set_host(localhost);
	if (dump_hostname)
	{
            /* get a starting disk and directory based on where
	       we currently are */
	    switch (guess_disk(cwd, sizeof(cwd), &dn_guess, &mpt_guess))
	    {
		case 1:
		    /* okay, got a guess. Set disk accordingly */
		    g_printf(_("$CWD '%s' is on disk '%s' mounted at '%s'.\n"),
			   cwd, dn_guess, mpt_guess);
		    set_disk(dn_guess, mpt_guess);
		    set_directory(cwd);
		    if (server_happy() && !g_str_equal(cwd, mpt_guess))
		        g_printf(_("WARNING: not on root of selected filesystem, check man-page!\n"));
		    amfree(dn_guess);
		    amfree(mpt_guess);
		    break;

		case 0:
		    g_printf(_("$CWD '%s' is on a network mounted disk\n"),
			   cwd);
		    g_printf(_("so you must 'sethost' to the server\n"));
		    /* fake an unhappy server */
		    server_line[0] = '5';
		    break;

		case 2:
		case -1:
		default:
		    g_printf(_("Use the setdisk command to choose dump disk to recover\n"));
		    /* fake an unhappy server */
		    server_line[0] = '5';
		    break;
	    }
	}
    }

    quit_prog = 0;
    do
    {
	if ((lineread = readline("amrecover> ")) == NULL) {
	    clearerr(stdin);
	    putchar('\n');
	    break;
	}
	if (lineread[0] != '\0') 
	{
	    add_history(lineread);
	    process_line(lineread);	/* act on line's content */
	}
	amfree(lineread);
    } while (!quit_prog);

    dbclose();

    aclose(server_socket);
    return 0;
}
示例#19
0
void
BCU1SerialLowLevelDriver::Run (pth_sem_t * stop1)
{
  pth_event_t stop = pth_event (PTH_EVENT_SEM, stop1);
  pth_event_t input = pth_event (PTH_EVENT_SEM, &in_signal);
  pth_event_t timeout = pth_event (PTH_EVENT_RTIME, pth_time (0, 10));
  while (pth_event_status (stop) != PTH_STATUS_OCCURRED)
    {
      int error;
      timeout =
	pth_event (PTH_EVENT_RTIME | PTH_MODE_REUSE, timeout,
		   pth_time (0, 150));
      pth_event_concat (stop, input, timeout, NULL);
      pth_wait (stop);
      pth_event_isolate (stop);
      pth_event_isolate (input);
      timeout =
	pth_event (PTH_EVENT_RTIME | PTH_MODE_REUSE, timeout,
		   pth_time (0, 200));
      pth_event_concat (stop, timeout, NULL);

      struct timeval v1, v2;
      gettimeofday (&v1, 0);

      CArray e;
      CArray r;
      uchar s;
      if (!inqueue.isempty ())
	{
	  const CArray & c = inqueue.top ();
	  e.resize (c () + 1);
	  s = c () & 0x1f;
	  s |= 0x20;
	  s |= 0x80 * bitcount (s);
	  e[0] = s;
	  e.setpart (c, 1);
	}
      else
	{
	  e.resize (1);
	  e[0] = 0xff;
	}
      if (!startsync ())
	{
	  error = 1;
	  goto err;
	}
      if (!exchange (e[0], s, stop))
	{
	  error = 3;
	  goto err;
	}
      if (!endsync ())
	{
	  error = 2;
	  goto err;
	}
      if (s == 0xff && e[0] != 0xff)
	{
	  for (unsigned i = 1; i < e (); i++)
	    {
	      if (!startsync ())
		{
		  error = 1;
		  goto err;
		}
	      if (!exchange (e[i], s, stop))
		{
		  error = 3;
		  goto err;
		}
	      if (endsync ())
		{
		  error = 2;
		  goto err;
		}
	    }
	  if (s != 0x00)
	    {
	      error = 10;
	      goto err;
	    }
	  inqueue.get ();
	  TRACEPRINTF (t, 0, this, "Sent");
	  pth_sem_dec (&in_signal);
	  if (inqueue.isempty ())
	    pth_sem_set_value (&send_empty, 1);
	}
      else if (s != 0xff)
	{
	  r.resize ((s & 0x1f));
	  for (unsigned i = 0; i < (s & 0x1f); i++)
	    {
	      if (!startsync ())
		{
		  error = 1;
		  goto err;
		}
	      if (!exchange (0, r[i], stop))
		{
		  error = 3;
		  goto err;
		}
	      if (!endsync ())
		{
		  error = 2;
		  goto err;
		}
	    }
	  TRACEPRINTF (t, 0, this, "Recv");
	  outqueue.put (new CArray (r));
	  pth_sem_inc (&out_signal, 1);
	}
      gettimeofday (&v2, 0);
      TRACEPRINTF (t, 1, this, "Recvtime: %d",
		   v2.tv_sec * 1000000L + v2.tv_usec -
		   (v1.tv_sec * 1000000L + v1.tv_usec));

      if (0)
	{
	err:
	  gettimeofday (&v2, 0);
	  TRACEPRINTF (t, 1, this, "ERecvtime: %d",
		       v2.tv_sec * 1000000L + v2.tv_usec -
		       (v1.tv_sec * 1000000L + v1.tv_usec));
	  setstat (getstat () & ~(TIOCM_RTS | TIOCM_CTS));
	  pth_usleep (2000);
	  while ((getstat () & TIOCM_CTS));
	  TRACEPRINTF (t, 0, this, "Restart %d", error);
	}

      pth_event_isolate (timeout);
    }
  pth_event_free (timeout, PTH_FREE_THIS);
  pth_event_free (stop, PTH_FREE_THIS);
  pth_event_free (input, PTH_FREE_THIS);
}
示例#20
0
文件: 0518_5.c 项目: 12ashk/etude
int main(void)
{
  exchange();

  return 0;
}
示例#21
0
long	atomic32::operator=(const atomic32& other)
{
	return exchange(other.load());
}
void config_multi_touch(struct _ntrig_bus_device *dev,
	struct input_dev *input_device)
{
	int i;
	__u16 min_x = dev->logical_min_x;
	__u16 max_x = dev->logical_max_x;
	__u16 min_y = dev->logical_min_y;
	__u16 max_y = dev->logical_max_y;
#ifdef ROTATE_ANDROID
	//__u16 tmp;
#endif

	__set_bit(EV_ABS, input_device->evbit);

	__set_bit(ABS_MT_POSITION_X, input_device->absbit);
	__set_bit(ABS_MT_POSITION_Y, input_device->absbit);
	__set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
#ifdef MT_REPORT_TYPE_B
	__set_bit(ABS_MT_WIDTH_MINOR, input_device->absbit);
	__set_bit(ABS_MT_PRESSURE, input_device->absbit);
#ifndef DISABLE_TOOL_TYPE
	__set_bit(ABS_MT_TOOL_TYPE, input_device->absbit);
#endif /*DISABLE_TOOL_TYPE*/
#else
	__set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
#endif
	/**
	 *   [48/0x30] - ABS_MT_TOUCH_MAJOR  0 .. 40
	 *   [50/0x32] - ABS_MT_WIDTH_MAJOR  0 .. 8000
	 *   [53/0x35] - ABS_MT_POSITION_X   0 .. 1023
	 *   [54/0x36] - ABS_MT_POSITION_Y   0.. 599
	 *   ABS_MT_POSITION_Y =
	 */
	ntrig_dbg_lvl(NTRIG_DEBUG_LEVEL_ONCE,
		"inside %s before VIRTUAL_KEYS_SUPPORTED\n", __func__);

	if (virtual_keys_supported()) {
		ntrig_dbg("inside %s with VIRTUAL_KEYS_SUPPORTED1\n", __func__);

		__set_bit(EV_KEY, input_device->evbit);
		for (i = 0; i < get_virtual_keys_num(); i++)
			__set_bit(get_virt_keys_scan_code(i),
				input_device->keybit);

		min_x += get_touch_screen_border_left();
		max_x -= get_touch_screen_border_right();
		min_y += get_touch_screen_border_down();
		max_y -= get_touch_screen_border_up();
		ntrig_dbg("inside %s with VIRTUAL_KEYS_SUPPORTED2\n", __func__);
	} else {
		ntrig_dbg("inside %s with VIRTUAL_KEYS_SUPPORTED undefined\n",
			__func__);
	}

#ifdef ROTATE_ANDROID
	/* Exchange the x/y boundaries to make the rotation code simpler */
	exchange(&min_x, &min_y);
	exchange(&max_x, &max_y);
#endif
	input_set_abs_params(input_device, ABS_MT_POSITION_X,
		min_x, max_x, 0, 0);
	input_set_abs_params(input_device, ABS_MT_POSITION_Y,
		min_y, max_y, 0, 0);
	input_set_abs_params(input_device, ABS_MT_WIDTH_MAJOR, 0,
		ABS_MT_WIDTH_MAX, 0, 0);
	input_set_abs_params(input_device, ABS_MT_WIDTH_MINOR, 0,
		ABS_MT_WIDTH_MAX, 0, 0);
#ifdef MT_REPORT_TYPE_B
	input_set_abs_params(input_device, ABS_MT_PRESSURE, 1, 255, 0, 0);
#ifndef DISABLE_TOOL_TYPE
	input_set_abs_params(input_device, ABS_MT_TOOL_TYPE, 0, 1, 0, 0);
#endif /*DISABLE_TOOL_TYPE*/
#else
	input_set_abs_params(input_device, ABS_MT_TOUCH_MAJOR, 0,
		ABS_MT_TOUCH_MAJOR_MAX, 0, 0);
#endif
	/** ABS_MT_ORIENTATION: we use 0 or 1 values, we only detect
	 *  90 degree rotation (by looking at the maximum of dx and
	 *  dy reported by sensor */
	input_set_abs_params(input_device, ABS_MT_ORIENTATION, 0, 1, 0, 0);
	input_set_abs_params(input_device, ABS_MT_TRACKING_ID, 0,
		ABS_MT_TRACKING_ID_MAX, 0, 0);

	ntrig_dbg("inside %s after VIRTUAL_KEYS_SUPPORTED\n", __func__);
}
示例#23
0
atomic32::atomic32()
{
	exchange(0);
}
示例#24
0
//#####################################################################
// Function Simplex
//#####################################################################
// requires incident_elements
// returns the simplex containing these nodes - returns 0 if no simplex contains these nodes
template<int d> int SIMPLEX_MESH<d>::
Simplex(const VECTOR<int,d+1>& nodes) const
{
    assert(incident_elements);
    // find shortest list of elements
    int short_list=nodes[1];VECTOR<int,d> check=nodes.Remove_Index(1);
    for(int i=1;i<=d;i++)if((*incident_elements)(check[i]).m < (*incident_elements)(short_list).m) exchange(short_list,check[i]);
    // search short list for other nodes
    for(int k=1;k<=(*incident_elements)(short_list).m;k++){int t=(*incident_elements)(short_list)(k);
        if(Nodes_In_Simplex(check,t)) return t;}
    return 0;
}
示例#25
0
/* Extract the node with the minimum key, at index 1, from the
   min-heap. */
void extract_min(double key[], int handle[], int heap_index[], int size) {
  exchange(key, handle, heap_index, 1, size);
  heapify(key, handle, heap_index, 1, size-1);
}
示例#26
0
int _getopt_internal(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only)
{

	if (argc < 1)
		return -1;

	optarg = NULL;

	if (optind == 0 || !__getopt_initialized) {
		if (optind == 0)
			optind = 1;			/* Don't scan ARGV[0], the program name.  */
		optstring = _getopt_initialize(argc, argv, optstring);
		__getopt_initialized = 1;
	}

	/* Test whether ARGV[optind] points to a non-option argument.
	   Either it does not have option syntax, or there is an environment flag
	   from the shell indicating it is not an option.  The later information
	   is only used when the used in the GNU libc.  */
#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')

	if (nextchar == NULL || *nextchar == '\0') {
		/* Advance to the next ARGV-element.  */

		/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
		   moved back by the user (who may also have changed the arguments).  */
		if (last_nonopt > optind)
			last_nonopt = optind;
		if (first_nonopt > optind)
			first_nonopt = optind;

		if (ordering == PERMUTE) {
			/* If we have just processed some options following some non-options,
			   exchange them so that the options come first.  */

			if (first_nonopt != last_nonopt && last_nonopt != optind)
				exchange((char **) argv);
			else if (last_nonopt != optind)
				first_nonopt = optind;

			/* Skip any additional non-options
			   and extend the range of non-options previously skipped.  */

			while (optind < argc && NONOPTION_P)
				optind++;
			last_nonopt = optind;
		}

		/* The special ARGV-element `--' means premature end of options.
		   Skip it like a null option,
		   then exchange with previous non-options as if it were an option,
		   then skip everything else like a non-option.  */

		if (optind != argc && !strcmp(argv[optind], "--")) {
			optind++;

			if (first_nonopt != last_nonopt && last_nonopt != optind)
				exchange((char **) argv);
			else if (first_nonopt == last_nonopt)
				first_nonopt = optind;
			last_nonopt = argc;

			optind = argc;
		}

		/* If we have done all the ARGV-elements, stop the scan
		   and back over any non-options that we skipped and permuted.  */

		if (optind == argc) {
			/* Set the next-arg-index to point at the non-options
			   that we previously skipped, so the caller will digest them.  */
			if (first_nonopt != last_nonopt)
				optind = first_nonopt;
			return -1;
		}

		/* If we have come to a non-option and did not permute it,
		   either stop the scan or describe it to the caller and pass it by.  */

		if (NONOPTION_P) {
			if (ordering == REQUIRE_ORDER)
				return -1;
			optarg = argv[optind++];
			return 1;
		}

		/* We have found another option-ARGV-element.
		   Skip the initial punctuation.  */

		nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-'));
	}

	/* Decode the current option-ARGV-element.  */

	/* Check whether the ARGV-element is a long option.

	   If long_only and the ARGV-element has the form "-f", where f is
	   a valid short option, don't consider it an abbreviated form of
	   a long option that starts with f.  Otherwise there would be no
	   way to give the -f short option.

	   On the other hand, if there's a long option "fubar" and
	   the ARGV-element is "-fu", do consider that an abbreviation of
	   the long option, just like "--fu", and not "-f" with arg "u".

	   This distinction seems to be the most useful approach.  */

	if (longopts != NULL && (argv[optind][1] == '-' || (long_only && (argv[optind][2]
																	  || !my_index(optstring, argv[optind][1]))))) {
		char *nameend;
		const struct option *p;
		const struct option *pfound = NULL;
		int exact = 0;
		int ambig = 0;
		int indfound = -1;
		int option_index;

		for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
			/* Do nothing.  */ ;

		/* Test all long options for either exact match
		   or abbreviated matches.  */
		for (p = longopts, option_index = 0; p->name; p++, option_index++)
			if (!strncmp(p->name, nextchar, nameend - nextchar)) {
				if ((UINT) (nameend - nextchar)
					== (UINT) strlen(p->name)) {
					/* Exact match found.  */
					pfound = p;
					indfound = option_index;
					exact = 1;
					break;
				} else if (pfound == NULL) {
					/* First nonexact match found.  */
					pfound = p;
					indfound = option_index;
				} else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val)
					/* Second or later nonexact match found.  */
					ambig = 1;
			}

		if (ambig && !exact) {
			PRINT_ERROR( "%s: option `%s' is ambiguous\n", argv[0], argv[optind]);
			nextchar += strlen(nextchar);
			optind++;
			optopt = 0;
			return '?';
		}

		if (pfound != NULL) {
			option_index = indfound;
			optind++;
			if (*nameend) {
				/* Don't test has_arg with >, because some C compilers don't
				   allow it to be used on enums.  */
				if (pfound->has_arg)
					optarg = nameend + 1;
				else {
					if (argv[optind - 1][1] == '-') {
						/* --option */
						PRINT_ERROR( "%s: option `--%s' doesn't allow an argument\n", argv[0], pfound->name);
					} else {
						/* +option or -option */
						PRINT_ERROR("%s: option `%c%s' doesn't allow an argument\n", argv[0], argv[optind - 1][0], pfound->name);
					}
					nextchar += strlen(nextchar);

					optopt = pfound->val;
					return '?';
				}
			} else if (pfound->has_arg == 1) {
				if (optind < argc)
					optarg = argv[optind++];
				else {
					PRINT_ERROR("%s: option `%s' requires an argument\n", argv[0], argv[optind - 1]);
					nextchar += strlen(nextchar);
					optopt = pfound->val;
					return optstring[0] == ':' ? ':' : '?';
				}
			}
			nextchar += strlen(nextchar);
			if (longind != NULL)
				*longind = option_index;
			if (pfound->flag) {
				*(pfound->flag) = pfound->val;
				return 0;
			}
			return pfound->val;
		}

		/* Can't find it as a long option.  If this is not getopt_long_only,
		   or the option starts with '--' or is not a valid short
		   option, then it's an error.
		   Otherwise interpret it as a short option.  */
		if (!long_only || argv[optind][1] == '-' || my_index(optstring, *nextchar) == NULL) {
			if (argv[optind][1] == '-') {
				/* --option */
				PRINT_ERROR("%s: unrecognized option `--%s'\n", argv[0], nextchar);
			} else {
				/* +option or -option */
				PRINT_ERROR("%s: unrecognized option `%c%s'\n", argv[0], argv[optind][0], nextchar);
			}
			nextchar = (char *) "";
			optind++;
			optopt = 0;
			return '?';
		}
	}

	/* Look at and handle the next short option-character.  */

	{
		char c = *nextchar++;
		char *temp = my_index(optstring, c);

		/* Increment `optind' when we start to process its last character.  */
		if (*nextchar == '\0')
			++optind;

		if (temp == NULL || c == ':') {
			/* 1003.2 specifies the format of this message.  */
			PRINT_ERROR("%s: illegal option -- %c\n", argv[0], c);
			optopt = c;
			return '?';
		}
#ifdef SPECIAL_TREATMENT_FOR_W
		/* Convenience. Treat POSIX -W foo same as long option --foo */
		if (temp[0] == 'W' && temp[1] == ';') {
			char *nameend;
			const struct option *p;
			const struct option *pfound = NULL;
			int exact = 0;
			int ambig = 0;
			int indfound = 0;
			int option_index;

			/* This is an option that requires an argument.  */
			if (*nextchar != '\0') {
				optarg = nextchar;
				/* If we end this ARGV-element by taking the rest as an arg,
				   we must advance to the next element now.  */
				optind++;
			} else if (optind == argc) {
				/* 1003.2 specifies the format of this message.  */
				PRINT_ERROR("%s: option requires an argument -- %c\n", argv[0], c);
				optopt = c;
				if (optstring[0] == ':')
					c = ':';
				else
					c = '?';
				return c;
			} else
				/* We already incremented `optind' once;
				   increment it again when taking next ARGV-elt as argument.  */
				optarg = argv[optind++];

			/* optarg is now the argument, see if it's in the
			   table of longopts.  */

			for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
				/* Do nothing.  */ ;

			/* Test all long options for either exact match
			   or abbreviated matches.  */
			for (p = longopts, option_index = 0; p->name; p++, option_index++)
				if (!strncmp(p->name, nextchar, nameend - nextchar)) {
					if ((UINT) (nameend - nextchar) == strlen(p->name)) {
						/* Exact match found.  */
						pfound = p;
						indfound = option_index;
						exact = 1;
						break;
					} else if (pfound == NULL) {
						/* First nonexact match found.  */
						pfound = p;
						indfound = option_index;
					} else
						/* Second or later nonexact match found.  */
						ambig = 1;
				}
			if (ambig && !exact) {
				PRINT_ERROR("%s: option `-W %s' is ambiguous\n", argv[0], argv[optind]);
				nextchar += strlen(nextchar);
				optind++;
				return '?';
			}
			if (pfound != NULL) {
				option_index = indfound;
				if (*nameend) {
					/* Don't test has_arg with >, because some C compilers don't
					   allow it to be used on enums.  */
					if (pfound->has_arg)
						optarg = nameend + 1;
					else {
						PRINT_ERROR("%s: option `-W %s' doesn't allow an argument\n", argv[0], pfound->name);
						nextchar += strlen(nextchar);
						return '?';
					}
				} else if (pfound->has_arg == 1) {
					if (optind < argc)
						optarg = argv[optind++];
					else {
						PRINT_ERROR("%s: option `%s' requires an argument\n", argv[0], argv[optind - 1]);
						nextchar += strlen(nextchar);
						return optstring[0] == ':' ? ':' : '?';
					}
				}
				nextchar += strlen(nextchar);
				if (longind != NULL)
					*longind = option_index;
				if (pfound->flag) {
					*(pfound->flag) = pfound->val;
					return 0;
				}
				return pfound->val;
			}
			nextchar = NULL;
			return 'W';			/* Let the application handle it.   */
		}
#endif
		if (temp[1] == ':') {
			if (temp[2] == ':') {
				/* This is an option that accepts an argument optionally.  */
				if (*nextchar != '\0') {
					optarg = nextchar;
					optind++;
				} else
					optarg = NULL;
				nextchar = NULL;
			} else {
				/* This is an option that requires an argument.  */
				if (*nextchar != '\0') {
					optarg = nextchar;
					/* If we end this ARGV-element by taking the rest as an arg,
					   we must advance to the next element now.  */
					optind++;
				} else if (optind == argc) {
					/* 1003.2 specifies the format of this message.  */
					PRINT_ERROR("%s: option requires an argument -- %c\n", argv[0], c);
					optopt = c;
					if (optstring[0] == ':')
						c = ':';
					else
						c = '?';
				} else
					/* We already incremented `optind' once;
					   increment it again when taking next ARGV-elt as argument.  */
					optarg = argv[optind++];
				nextchar = NULL;
			}
		}
		return c;
	}
}
示例#27
0
/** procedure compare() 
   The parameter dir indicates the sorting direction, ASCENDING 
   or DESCENDING; if (a[i] > a[j]) agrees with the direction, 
   then a[i] and a[j] are interchanged.
**/
inline void compare(int i, int j, int dir) {
  if (dir==(a[i]>a[j])) 
    exchange(i,j);
}
示例#28
0
int partition_rand(Array &a, int p, int r)
{
    int i = rand()%(r-p) + p;
    exchange(a[r], a[i]);
    return partition(a, p, r);
}
示例#29
0
//反转,和sort配合,进行降序排列
void reverse(int * digits)
{
	exchange(&digits[1],&digits[2]);
	exchange(&digits[0],&digits[3]);
}
示例#30
0
/*makeNearSort: This function exchanges index 10 with 11
 and 90 with 91 to unsort a piece of the sorted array.
 Input: randomArray(array of ints)
 Return: Nothing*/
/*10*/void makeNearSort(int randomArray[])
{
    exchange(randomArray,10,11);
    exchange(randomArray,90,91);
}//end exchange