Exemplo n.º 1
0
Arquivo: dhl.cpp Projeto: cjsoft/noip
void read() {
    scanf("%d %d", &n, &m);
    ll temp;
    int i, j;
    for (i = 1; i <= n; ++i) {
        for (j = 1; j < m; ++j) {
            // scanf("%u", &temp);
            gett(temp);
            add_edge(j, i, j + 1, i, temp);
            add_edge(j + 1, i, j, i, temp);
        }
    }
    for (i = 1; i < n; ++i) {
        for (j = 1; j <= m; ++j) {
            // scanf("%u", &temp);
            gett(temp);
            add_edge(j, i, j, i + 1, temp);
            add_edge(j, i + 1, j, i, temp);
        }
    }
    for (i = 1; i < n; ++i) {
        for (j = 1; j < m; ++j) {
            // scanf("%u", &temp);
            gett(temp);
            add_edge(j, i, j + 1, i + 1, temp);
            add_edge(j + 1, i + 1, j, i, temp);
        }
    }
}
Exemplo n.º 2
0
Arquivo: fib.cpp Projeto: hsk/docs
  void bench() {
    long start;
    start = gett();
    Int p(40);
    printf("%d\n", ((Fib2*)Fib2_v->data[p.id])->fib((Class*)&p));
    printf("%ld\n", gett() - start);

    start = gett();
    Int3 p3 = {Int3_classId, 40};
    printf("%d\n", ((Fib2*)Fib3_v->data[p3.id])->fib((Class*)&p3));
    printf("%ld\n", gett() - start);
  }
Exemplo n.º 3
0
static char *
get_token (FILE *fd)
{
  static char token[500];
  char *tp;
  int car;

  do gett (); while (ignore ());

  if (car == EOF)
    return NULL;

  tp = token;
  if (car == '\"' || car == '\'')
    {
      int delim = car;
      gett ();
      while (car != delim && car != '\n' && car != EOF &&
	  (u_int) (tp - token) < sizeof (token) - 1)
	{
	  *tp++ = car;
	  gett ();
	}
#if 0
      if (car != delim)
	fputs ("unterminated string\n", stderr);
#endif
    }
  else
    {
      while ((u_int) (tp - token) < sizeof (token) - 1 && !ignore ())
	{
	  *tp++ = car;
	  gett ();
	}
    }

  *tp++ = '\0';

  return token;
}
Exemplo n.º 4
0
const time_t TimeF::sett(
    const time_t &time
,   const bool forceUpdate)
{
    time_t t = time - utcOffset();

    m_time[0] = t;
    m_time[2] = m_time[0];

    m_timef[0] = _frac(secondsTof(t));
    m_timef[2] = m_timef[0];

    m_offset = 0;

    reset(forceUpdate);

    return gett();
}
Exemplo n.º 5
0
void main ()
{

    int i,c,l;
    char text[10000];

    printf("Enter text, what has to be formatted.\n");

    while( (l=gett(text) )>0 ){
	printf("---------------Non formatted text seems so:--------------------|\n%s\n---------------------------------------------------------------|\n",text);
//	form(l,text);
	decomment(l,text);
	printf("---------------Same text after formatting seems so:------------|\n%s\n---------------------------------------------------------------|\n",text);
	
    }
    printf("normal end of program\n");

}
Exemplo n.º 6
0
/*
 * retrieve tcp table for win xp and up
 */
DWORD windows_get_tcp_table(struct connection_table **table_connection)
{
	DWORD result = ERROR_SUCCESS;
	struct connection_entry * current_connection = NULL;
	MIB_TCPTABLE_OWNER_MODULE  * tablev4 = NULL;
	MIB_TCP6TABLE_OWNER_MODULE * tablev6 = NULL;
	MIB_TCPROW_OWNER_MODULE  * currentv4 = NULL;
	MIB_TCP6ROW_OWNER_MODULE * currentv6 = NULL;
	DWORD i, state, dwSize;


	ptr_GetExtendedTcpTable gett            = NULL;

	gett    = (ptr_GetExtendedTcpTable)GetProcAddress(GetModuleHandle("iphlpapi"), "GetExtendedTcpTable");

	// systems that don't support GetExtendedTcpTable
	if (gett == NULL) {
		return windows_get_tcp_table_win2000_down(table_connection);
	}
	do {
		// IPv4 part
		dwSize = 0;
		if (gett(NULL,&dwSize, TRUE, AF_INET, TCP_TABLE_OWNER_MODULE_ALL, 0) == ERROR_INSUFFICIENT_BUFFER) {
			tablev4 = (MIB_TCPTABLE_OWNER_MODULE *)malloc(dwSize);
			if (gett(tablev4, &dwSize, TRUE, AF_INET, TCP_TABLE_OWNER_MODULE_ALL, 0) == NO_ERROR) {
				for(i=0; i<tablev4->dwNumEntries; i++) {
					// check available memory and allocate if necessary
					if (check_and_allocate(table_connection) == ERROR_NOT_ENOUGH_MEMORY) {
						free(tablev4);
						return ERROR_NOT_ENOUGH_MEMORY;
					}
					currentv4 = &tablev4->table[i];
					current_connection = &(*table_connection)->table[(*table_connection)->entries];
					current_connection->type             = AF_INET;
					current_connection->local_addr.addr  = currentv4->dwLocalAddr;
					current_connection->remote_addr.addr = currentv4->dwRemoteAddr;
					current_connection->local_port       = ntohs((u_short)(currentv4->dwLocalPort & 0x0000ffff));
					// if socket is in LISTEN, remote_port is garbage, force value to 0
					if (currentv4->dwState == MIB_TCP_STATE_LISTEN)
						current_connection->remote_port  = 0;
					else
						current_connection->remote_port  = ntohs((u_short)(currentv4->dwRemotePort & 0x0000ffff));

					state = currentv4->dwState;
					if ((state <= 0) || (state > 12))
						state = 13; // points to UNKNOWN in the state array
					strncpy(current_connection->state, tcp_connection_states[state], sizeof(current_connection->state));
					strncpy(current_connection->protocol, "tcp", sizeof(current_connection->protocol));

					// force program_name to "-" and try to get real name through GetOwnerModuleFromXXXEntry
					strncpy(current_connection->program_name, "-", sizeof(current_connection->program_name));

					set_process_name(currentv4->dwOwningPid, current_connection->program_name, sizeof(current_connection->program_name));

					(*table_connection)->entries++;
				}
			}
			else { // gett failed
				result = GetLastError();
				if (tablev4)
					free(tablev4);
				break;
			}
			if (tablev4)
				free(tablev4);
		}
		// IPv6 part
		dwSize = 0;
		if (gett(NULL,&dwSize, TRUE, AF_INET6, TCP_TABLE_OWNER_MODULE_ALL, 0) == ERROR_INSUFFICIENT_BUFFER) {
			tablev6 = (MIB_TCP6TABLE_OWNER_MODULE *)malloc(dwSize);
			if (gett(tablev6, &dwSize, TRUE, AF_INET6, TCP_TABLE_OWNER_MODULE_ALL, 0) == NO_ERROR) {
				for(i=0; i<tablev6->dwNumEntries; i++) {
					// check available memory and allocate if necessary
					if (check_and_allocate(table_connection) == ERROR_NOT_ENOUGH_MEMORY) {
						free(tablev6);
						return ERROR_NOT_ENOUGH_MEMORY;
					}
					currentv6 = &tablev6->table[i];
					current_connection = &(*table_connection)->table[(*table_connection)->entries];
					current_connection->type             = AF_INET6;
					memcpy(&current_connection->local_addr.addr6, currentv6->ucLocalAddr, sizeof(current_connection->local_addr.addr6));
					memcpy(&current_connection->remote_addr.addr6, currentv6->ucRemoteAddr, sizeof(current_connection->remote_addr.addr6));
					current_connection->local_port       = ntohs((u_short)(currentv6->dwLocalPort & 0x0000ffff));
					// if socket is in LISTEN, remote_port is garbage, force value to 0
					if (currentv6->dwState == MIB_TCP_STATE_LISTEN)
						current_connection->remote_port  = 0;
					else
						current_connection->remote_port  = ntohs((u_short)(currentv6->dwRemotePort & 0x0000ffff));

					state = currentv6->dwState;
					if ((state <= 0) || (state > 12))
						state = 13; // points to UNKNOWN in the state array
					strncpy(current_connection->state, tcp_connection_states[state], sizeof(current_connection->state));
					strncpy(current_connection->protocol, "tcp6", sizeof(current_connection->protocol));

					// force program_name to "-" and try to get real name through GetOwnerModuleFromXXXEntry
					strncpy(current_connection->program_name, "-", sizeof(current_connection->program_name));

					set_process_name(currentv6->dwOwningPid, current_connection->program_name, sizeof(current_connection->program_name));

					(*table_connection)->entries++;
				}
			}
			else { // gett failed
				result = GetLastError();
				if (tablev6)
					free(tablev6);
				break;
			}
			if (tablev6)
				free(tablev6);
		}

	} while (0);
	return result;
}
int main(void){
	Charge chNull = NULL;
	ChargeArray chANull = NULL;
	Charge chrv;
	ChargeArray chArv; 
	int rv; 
	int len = 5; 
	int val = -999; 
	int spot = 3; //spot in array where testing functions
	double drv; 
	//valid:
	//Charge ch
	//ChargeArray chA

	printf("Testing: newCharge\n");
	Charge ch = newCharge();
	assert(ch !=NULL);  
	
	printf("Testing: newChargeA\n");
	ChargeArray chA = newChargeA(len);
	assert(chA !=NULL);  
	chArv = newChargeA(val);
	assert(chArv ==NULL);  

	printf("Testing: setDwel\n");
	rv= setDwel(chNull, 15.75);
	assert(rv==-1);
	rv= setDwel(ch, val);
	assert(rv==-1);
	rv= setDwel(ch, 15.75);
	assert(rv==0);
	
	printf("Testing: MinusDwel\n");
	rv= MinusDwel(chNull, 1.05);
	assert(rv==-1);
	rv= MinusDwel(ch, val);
	assert(rv==-1);
	rv= MinusDwel(ch, 14.25);
	assert(rv==0);
	
	printf("Testing: getDwel\n");
	drv= getDwel(chNull);
	assert(drv==-1);
	drv= getDwel(ch);
	printf("%f\n", drv);
	assert(drv==1.5);

	printf("Testing: printCharge, Expecting: dwelltime = 1.5 \n");
	rv= printCharge(chNull);
	assert(rv==-1); 
	rv= printCharge(ch);
	assert(rv==0); 

	printf("Testing: sett\n"); 
	rv= sett(chNull, 2.451);
	assert(rv==-1);
	rv= sett(ch, val);
	assert(rv==-1);
	rv= sett(ch, 2.451);
	assert(rv==0);
	printf("Testing: Plust\n"); 
	rv= Plust(chNull, 3.5);
	assert(rv==-1);
	rv= Plust(ch, val);
	assert(rv==-1);
	rv= Plust(ch, 3.5);
	assert(rv==0);
	printf("Testing: gett\n");
	drv= gett(chNull);
	assert(drv==-1);
	drv= gett(ch);
	printf("%f\n", drv);
	assert(drv==(2.451+3.5)); 

	printf("Testing: getCharge\n");
	chrv= getCharge(chANull, 4);
	assert(chrv==NULL); 
	chrv= getCharge(chA, -val); // i > len
	assert(chrv==NULL); 
	chrv= getCharge(chA, val);
	assert(chrv==NULL); 
	chrv= getCharge(chA, 4);
	assert(chrv!=NULL); 	

	printf("Testing: setCx\n"); 
	rv= setCx(chNull, 6);
	assert(rv==-1);
	rv= setCx(getCharge(chA, spot), val);
	assert(rv==0);
	rv= setCx(getCharge(chA, spot), 6);
	assert(rv==0);
	printf("Testing: CxPlus\n"); //x=8
	rv= CxPlus(chNull);
	assert(rv==-1);
	rv= CxPlus(getCharge(chA, spot));
	rv= CxPlus(getCharge(chA, spot)); //done twice
	assert(rv==0);
	printf("Testing: CxMinus\n"); //x=7 //tot_x = 7
	rv= CxMinus(chNull);
	assert(rv==-1);
	rv= CxMinus(getCharge(chA, spot)); //done once
	assert(rv==0);
	printf("Testing: CxPlusPeriodic\n"); //x=0  //tot_x = 8
	rv= CxPlusPeriodic(chNull, 2);
	assert(rv==-1);
	rv= CxPlusPeriodic(getCharge(chA, spot), val);
	assert(rv==-1);
	rv= CxPlusPeriodic(getCharge(chA, spot), 2); //add once
	assert(rv==0);
	printf("Testing: CxMinusPeriodic\n"); //x=4 //tot_x = 7
	rv= CxMinusPeriodic(chNull, 5);
	assert(rv==-1);
	rv= CxMinusPeriodic(getCharge(chA, spot), val);
	assert(rv==-1);
	rv= CxMinusPeriodic(getCharge(chA, spot), 5);
	assert(rv==0);
	printf("Testing: getCx\n");
	rv= getCx(chNull);
	assert(rv==-1);
	rv= getCx(getCharge(chA, spot));
	assert(rv==4);
	printf("Testing: getXdist\n");
	rv= getXdist(chNull);
	assert(rv==-1);
	rv= getXdist(getCharge(chA, spot));
	assert(rv==7);
	printf("Testing: printChargeA, Expecting: ch[3]->x = 4\n");
	rv= printChargeA(chANull);
	assert(rv==-1);
	rv= printChargeA(chA);
	assert(rv==0);

	printf("Testing: setCy\n"); 
	rv= setCy(chNull,8);
	assert(rv==-1);
	rv= setCy(ch, val);
	assert(rv==0);
	rv= setCy(ch, 8);
	assert(rv==0);
	printf("Testing: CyPlus\n"); //y=9 (after function successfully called)
	rv= CyPlus(chNull);
	assert(rv==-1);
	rv= CyPlus(ch);
	assert(rv==0); 
	printf("Testing: CyMinus\n");//y=7
	rv= CyMinus(chNull);
	assert(rv==-1);
	rv= CyMinus(ch);
	rv= CyMinus(ch); //subtract twice
	assert(rv==0); 
	printf("Testing: CyPlusPeriodic\n"); //y=0 
	rv= CyPlusPeriodic(chNull, 2);
	assert(rv==-1);
	rv= CyPlusPeriodic(ch, val);
	assert(rv==-1);
	rv= CyPlusPeriodic(ch, 2); //add once
	assert(rv==0);
	printf("Testing: CyMinusPeriodic\n"); //y=4
	rv= CyMinusPeriodic(chNull, 5);
	assert(rv==-1);
	rv= CyMinusPeriodic(ch, val);
	assert(rv==-1);
	rv= CyMinusPeriodic(ch, 5);
	assert(rv==0);
	printf("Testing: getCy\n");
	rv= getCy(chNull);
	assert(rv==-1);
	rv= getCy(ch);
	assert(rv==4);
	printf("Testing: setCz\n"); 
	rv= setCz(chNull,16);
	assert(rv==-1);
	rv= setCz(ch, val);
	assert(rv==0);
	rv= setCz(ch, 16);
	assert(rv==0);
	printf("Testing: CzPlus\n"); //z=18
	rv= CzPlus(chNull);
	assert(rv==-1);
	rv= CzPlus(ch);	
	rv= CzPlus(ch); //add twice
	assert(rv==0);
	printf("Testing: CzMinus\n"); //z=17
	rv= CzMinus(chNull);
	assert(rv==-1);
	rv= CzMinus(ch);
	assert(rv==0);
	printf("Testing: CzPlusPeriodic\n"); //z=0
	rv= CzPlusPeriodic(chNull, 5);
	assert(rv==-1);
	rv= CzPlusPeriodic(ch, val);
	assert(rv==-1);
	rv= CzPlusPeriodic(ch, 6);
	assert(rv==0);
	printf("Testing: CzMinusPeriodic\n"); // z=12
	rv= CzMinusPeriodic(chNull, 13);
	assert(rv==-1); 
	rv= CzMinusPeriodic(ch, val);
	assert(rv==-1); 
	rv= CzMinusPeriodic(ch, 13);
	assert(rv==0);
	printf("Testing: getCz\n");
	rv= getCz(chNull);
	assert(rv==-1);
	rv= getCz(ch);
	assert(rv==12);
  
   printf("Testing: deleteCharge\n");
	rv= deleteCharge(chNull);
	assert(rv==-1); 
	rv= deleteCharge(ch);
	assert(rv==0); 
	printf("Testing: deleteChargeA\n");
	rv= deleteChargeA(chANull);
	assert(rv==-1); 
	rv= deleteChargeA(chA);
	assert(rv==0);

  
  printf("Testing: initChargePath\n");
  Charge ch2 = newCharge();
  assert(ch2!=NULL);
  fprintf(stderr,"Should print ERROR message: ");
  rv = initChargePath(NULL, 3);
  assert(rv==-1);
  fprintf(stderr,"Should print ERROR message: ");
  rv = initChargePath(&ch2,1);
  assert(rv==-1);
  fprintf(stderr,"initializing same charge again with 2 nodes\n");
  rv = initChargePath(&ch2,2);
  assert(rv==0);
  printCharge(ch2);
  fprintf(stderr,"Should print ERROR message: ");
  rv = initChargePath(&ch2,2);
  assert(rv==-1);
  fprintf(stderr,"Deleting ch2\n");
  rv= deleteCharge(ch2);

  printf("Testing: initChargeArrayPath\n");
  ChargeArray cha2 = newChargeA(3);
  fprintf(stderr,"Should print ERROR message: ");
  rv = initChargeArrayPath(NULL, 2);
  assert(rv==-1);
  fprintf(stderr,"Should print ERROR message: ");
  rv = initChargeArrayPath(cha2,1);
  assert(rv==-1);
  rv = initChargeArrayPath(cha2,2);
  assert(rv==0);
  Charge ch3 = getCharge(cha2,2);
  assert(ch3!=NULL);
  rv= deleteChargeA(cha2);
  assert(rv==0);

	printf("Mission Completed\n");
	return 0;
}
Exemplo n.º 8
0
void airplane::rotate3(bool fs) {
	if(fule>0) {
		fule-=(getw()*gett());
		flyingUnit::rotate3(fs);
	}
}
Exemplo n.º 9
0
void missile::rotate3(bool fs) {
	fule-=(getw()*gett());
	flyingUnit::rotate3(fs);
}
Exemplo n.º 10
0
const t_longf TimeF::getNonModf(const bool updateFirst)
{
    return secondsTof(gett(updateFirst));
}
Exemplo n.º 11
0
Arquivo: fib1.cpp Projeto: hsk/docs
int main() {
  long start = gett();
  printf("%d\n", fib(40));
  printf("%ld\n", (gett() - start));
  return 0;
}