Пример #1
0
Файл: add.c Проект: jpflori/pari
static GEN
addsr_sign(long x, GEN y, long sy)
{
  long e, l, ly, sx;
  GEN z;

  if (!x) return rcopy_sign(y, sy);
  if (x < 0) { sx = -1; x = -x; } else sx = 1;
  e = expo(y) - expu(x);
  if (!sy)
  {
    if (e >= 0) return rcopy_sign(y, sy);
    if (sx == -1) x = -x;
    return stor(x, nbits2prec(-e));
  }

  ly = lg(y);
  if (e > 0)
  {
    l = ly - divsBIL(e);
    if (l < 3) return rcopy_sign(y, sy);
  }
  else l = ly + nbits2extraprec(-e);
  z = (GEN)avma;
  y = addrr_sign(stor(x,l), sx, y, sy);
  ly = lg(y); while (ly--) *--z = y[ly];
  avma = (pari_sp)z; return z;
}
Пример #2
0
int main( int argc, char ** argv )
{  
  cgiScript script( "text/html", false );
  Store_Form  stor(script); 
  Store_List mylist(script); // so you can set cookies 
  if( oLogin.testLoginStatus() )
  {
    script.closeHeader();
    cgiTemplates pgTemplate;    
    pgTemplate.load("Templates/adminPane.htmp");
    
    script << pgTemplate.getParagraph("top");

    stor.loadControlTemplates("Templates/form.htmp");  
    stor.form_action();  
    stor.form_display();
    
    
    mylist.loadListTemplates("Templates/list.htmp");  
    mylist.list_display();
    
    script << pgTemplate.getParagraph("bottom");
  }
  else
  {
    script.Redirect("signIn.html"); 
  } 
};
Пример #3
0
// You declared this function in the extern "C" block of the header.
// R will call this function to drive the processing of the Tree/Chain.
// Except for the name of your class (in this case met), your 
// function should look identical to the below... 
SEXP metToR(SEXP manager, SEXP nEntriesR, SEXP firstEntryR,
	    SEXP initialSizeR, SEXP growthFactorR, SEXP argsR)
{

  try {
    // Pull out the arguments
    Long64_t nEntries = INTEGER(nEntriesR)[0];
    Long64_t firstEntry = INTEGER(firstEntryR)[0];
    int initialSize = INTEGER(initialSizeR)[0];
    double growthFactor = REAL(growthFactorR)[0];

    // Get the Root chain manager
    checkForRootChainManagerPtr(manager);
    RootChainManager* rcm = (RootChainManager*) R_ExternalPtrAddr(manager);
    
    bool verbose = rcm->getVerbose();
    
    // Get the chain we wish to deal with
    TChain* tree = rcm->tree();
    
    // Create the TSelector (replace Met with your class name)
    Met stor(initialSize, growthFactor, verbose, tree->GetTreeOffset() );
                             
    // Process it!
    tree->Process(&stor, "", nEntries, firstEntry);
      
    // Return the data frame
    return stor.rDataFrame();
  }

  catch ( RDataFrameException e ) {
    error(e.what().c_str());
    return 0;
  }
}
Пример #4
0
void
dsi_recv(globus_gfs_operation_t       Operation,
         globus_gfs_transfer_info_t * TransferInfo,
         void                       * UserArg)
{
	stor(UserArg, Operation, TransferInfo);
}
Пример #5
0
void init(int tamMemoria) {
    iniciaMemoria(tamMemoria);
    int i;
    for (i = 0; i < tamMemoria; i++) {
        stor(i,0);
    }
    ula.AC = 0;
    ula.MBR = 0;
    ula.MQ = 0;
    uc.PC = 0;
    uc.MAR = 0;
    uc.IR = 0;
    uc.IBR = 0;
    uc.CIRCUITOCONTROLE.instrucaoEsquerdaRequirida = 1;
    uc.CIRCUITOCONTROLE.erro = 0;
    uc.CIRCUITOCONTROLE.proximaIBR = 0;
}
Пример #6
0
/* return a bound for T_2(P), P | polbase
 * max |b_i|^2 <= 3^{3/2 + d} / (4 \pi d) [P]_2,
 * where [P]_2 is Bombieri's 2-norm
 * Sum over conjugates
*/
static GEN
nf_Beauzamy_bound(GEN nf, GEN polbase)
{
  GEN lt,C,run,s, G = gmael(nf,5,2), POL, bin;
  long i,prec,precnf, d = degpol(polbase), n = degpol(nf[1]);

  precnf = gprecision(G);
  prec   = MEDDEFAULTPREC;
  bin = vecbinome(d);
  POL = polbase + 2;
  /* compute [POL]_2 */
  for (;;)
  {
    run= real_1(prec);
    s = real_0(prec);
    for (i=0; i<=d; i++)
    {
      GEN p1 = gnorml2(arch_for_T2(G, gmul(run, gel(POL,i)))); /* T2(POL[i]) */
      if (!signe(p1)) continue;
      if (lg(p1) == 3) break;
      /* s += T2(POL[i]) / binomial(d,i) */
      s = addrr(s, gdiv(p1, gel(bin,i+1)));
    }
    if (i > d) break;

    prec = (prec<<1)-2;
    if (prec > precnf)
    {
      nffp_t F; remake_GM(nf, &F, prec); G = F.G;
      if (DEBUGLEVEL>1) pari_warn(warnprec, "nf_factor_bound", prec);
    }
  }
  lt = leading_term(polbase);
  s = gmul(s, mulis(sqri(lt), n));
  C = powrshalf(stor(3,DEFAULTPREC), 3 + 2*d); /* 3^{3/2 + d} */
  return gdiv(gmul(C, s), gmulsg(d, mppi(DEFAULTPREC)));
}
Пример #7
0
void converteGrava(char * hexadecimal, int j) {
    int i;
    int numero;
    long int decimal = 0;
    long int expoente = 1;
    for (i = strlen(hexadecimal) - 1; i >= 0; i--) {
        switch (hexadecimal[i]) {
            case 10: //quando tem um \n
                continue;
            case '0' ... '9':
                numero = hexadecimal[i] - 48;
                break;
            case 'A':
                numero = 10;
                break;
            case 'B':
                numero = 11;
                break;
            case 'C':
                numero = 12;
                break;
            case 'D':
                numero = 13;
                break;
            case 'E':
                numero = 14;
                break;
            case 'F':
                numero = 15;
                break;
        }
        decimal += numero*expoente;
        expoente *= 16;
    }
    ula.MBR = decimal;
    stor(j);
}
Пример #8
0
/**
 * @brief conf_get_rules read rules from conf
 *
 * @param acc_str rules string
 *
 * @return zimg conf
 */
zimg_access_conf_t * conf_get_rules(const char *acc_str)
{
    if(acc_str == NULL)
        return NULL;
    zimg_access_conf_t *acconf = (zimg_access_conf_t *)malloc(sizeof(zimg_access_conf_t));
    if(acconf == NULL)
        return NULL;
    acconf->n = 0;
    acconf->rules = NULL;
    size_t acc_len = strlen(acc_str); 
    char *acc = (char *)malloc(acc_len);
    if(acc == NULL)
    {
        return NULL;
    }
    strncpy(acc, acc_str, acc_len);
    char *start = acc, *end;
    while(start <= acc+acc_len)
    {
        end = strchr(start, ';');
        end = (end) ? end : acc+acc_len;
        char *mode = start;
        char *range = strchr(mode, ' ');
        if (range)
        {
            zimg_rule_t *this_rule = (zimg_rule_t *)malloc(sizeof(zimg_rule_t));
            if (this_rule == NULL) {
                start = end + 1;
                continue;
            }
            (void) memset(this_rule, 0, sizeof(zimg_rule_t));
            this_rule->deny = (mode[0] == 'd') ? 1 : 0;
            size_t range_len;
            range++;
            range_len = end - range;

            uint all = (range_len == 3 && strstr(range, "all") == range);

            if (!all) {
                int rc;
                rc = stor((unsigned char *)range, range_len, this_rule);
                if (rc == ZIMG_ERROR) {
                    start = end + 1;
                    continue;
                }
            }

            zimg_rules_t *rules = (zimg_rules_t *)malloc(sizeof(zimg_rules_t));
            if (rules == NULL) {
                start = end + 1;
                continue;
            }

            rules->value= this_rule;
            rules->next = acconf->rules;
            acconf->rules = rules;
            acconf->n++;
        }
        start = end + 1;
    }
    free(acc);
    return acconf;
}
Пример #9
0
void exec_comm(int cl){

	int size,j=0,i=0, port;
	char buff[1024], *param,*command, *param1,*filename;
	char commands[100],buff2[200],dir[200];
	fd_set fds;

	memset(buff, '\0', 1024);

	if((recv(clients[cl]->sock, buff, sizeof(buff), 0))<0){
		perror("error in Receiving");
		exit(1);
		}
	printf("%s\n",buff);
	command = strtok (buff," ");		
	
	//buff[size-2]=0;  // -'\r' et  -'\n'
	/*while(buff[j]){
		param[i]=buff[j+1];
		i++;j++;
	}*/
	//param = strchr(buff," "); // param <- commande
	param = strtok (NULL, " ");
	
	for (j = 0; j < strlen(command); j++)
    		command[j]=toupper(command[j]);
  	printf("%s\n",command);
  	
  	printf("%s\n",param);
	for (j = 0; j < 8; j++)

		if (!strcmp(command,commandes[j])) break;

	

	switch(j){

		case QUIT:	if (clients[cl]->pid) kill(clients[cl]->pid,SIGTERM);
				clients[cl]->pid=0;
				close(clients[cl]->sock);
				clients[cl]->sock=0; 
  				clients[cl]->dataport=0;
				nb_users--;
				printf("%s\n", commandes[j]);
				break;	

		case  PORT:	port = atoi(param);
				clients[cl]->dataport = port;
				printf("%s %s\n", commandes[j], param);
				send(clients[cl]->sock, ok, strlen(ok)+1, 0);
				break;	
	
		case CWD:	strcpy(tmp,clients[cl]->curdir);
				strcat(tmp,"/");
				strcat(tmp,param);
				if(chdir(tmp)<0){
					perror("error");
					memset(msz,'\0',sizeof(msz));
					sprintf(msz,"%s","No Such Directory");
					send(clients[cl]->sock, msz, strlen(msz)+1, 0);
				}
				else{	
					memset(clients[cl]->curdir, '\0', (strlen(clients[cl]->curdir)+1));
					strcpy(clients[cl]->curdir,tmp);
					memset(msz,'\0',sizeof(msz));
					sprintf(msz,"%s","Directory Changed");
					send(clients[cl]->sock, msz, strlen(msz)+1, 0);
					printf("%s  %s\n", commandes[j],clients[cl]->curdir);
				}	
				prompt();
				break;	

		

		case RGET:	//param1 = strtok(param,"-");
				//filename = strtok(NULL,"-");
				//port = atoi(param1);
				//clients[cl]->dataport = port;
				//send(clients[cl]->sock, ok, strlen(ok)+1, 0);
				//	printf("%s %s\n", commandes[j], filename);
				
				strcat(commands,"ls -R ");
				system("ls");
				strcat(commands,param);
				printf("%s",param);
				system(commands);
				FILE *fd = popen(commands,"r");
				while(fgets(buff, sizeof(buff), fd)!=NULL){
					if(buff[(strlen(buff)-1)]==':'){
						//strcpy(dir,buff);
						//printf("%s",dir);
						memcpy(dir,buff,strlen(buff)-2);
						if(send(clients[cl]->sock,buff, strlen(buff), 0)<0)
								perror("Send");
					}
					else{
					strcat(dir,"param/");
					strcat(dir,buff);
					strcpy(buff,dir);
					if(send(clients[cl]->sock,buff, strlen(buff), 0)<0)
						perror("Send");
					}		
				}
				//rget(cl,param);
				break;
		 
		 case MGET:				
				strcat(commands,"ls ");
				//system("ls");
				strcat(commands,param);
				printf("%s",param);
				//system(commands);
				fd = popen(commands,"r");
				while(fgets(buff, sizeof(buff), fd)!=NULL){
					printf("\n%s",buff);
					if(send(clients[cl]->sock,buff, strlen(buff), 0)<0)
						perror("Send");
					}
				
				//rget(cl,param);
				break;
		
		
		// Since the list of files can be a considerable size, it is better to create a child
		// Which will deal with the client
		case LIST:	port = atoi(param);
				printf("%d",port);
				clients[cl]->dataport = port;
				if( (clients[cl]->pid = fork()) == 0 ){ 
					send(clients[cl]->sock, ok, strlen(ok)+1, 0);
					my_list(cl);
				}
				//send(clients[cl]->sock, ok, strlen(ok)+1, 0);
				printf("%s %s\n", commandes[j], clients[cl]->curdir);
				break;

		// Because a file can be of great size, it is better to create a child Which will deal with the sending to the client
		case RETR:	param1 = strtok(param,"-");
				filename = strtok(NULL,"-");
				port = atoi(param1);
				clients[cl]->dataport = port;
				if( (clients[cl]->pid = fork()) == 0 ) { 
					send(clients[cl]->sock, ok, strlen(ok)+1, 0);
					retr(cl, filename);
				}
				printf("%s %s\n", commandes[j], param);
				break;

		// Because a file can be of great size, it is better to create a child Which will deal with the recovery from the client

		case STOR:	param1 = strtok(param,"-");
				filename = strtok(NULL,"-");
				port = atoi(param1);
				clients[cl]->dataport = port;
				if( (clients[cl]->pid = fork()) == 0 ){
					if(send(clients[cl]->sock, ok, strlen(ok)+1, 0)<0)
						perror("send");
					stor(cl, filename);
				}
				printf("%s %s\n", commandes[j], param);	
				break;

		// Because a file can be of great size, it is better to create a child Which will deal with the removal

		
		
		//By default, we consider that if a client sends commands incomprehensible, it must be disconnected
		default:	if (clients[cl]->pid) kill(clients[cl]->pid,SIGTERM);
				if (clients[cl]->pid) kill(clients[cl]->pid,SIGTERM);
  				clients[cl]->pid=0;
				close(clients[cl]->sock);
				clients[cl]->sock = 0;
				clients[cl]->dataport = 0;
				nb_users--;
				printf("Client %d Disocnnected\n",cl);
				break;
				prompt();
	}	
}
Пример #10
0
int main()
{	
	//allocate memory for registers and program data
	byte  reg[16];
	byte mem[4096];
	//unsigned int offset = (unsigned int)mem - 0x200;
	word I = 0x200;
	int i;
	//printf("Hello World!\n");
	//printf("Char size: %u\n",CHAR_BIT);
	//printf("Char min: %u\n",CHAR_MIN);
	//printf("Char max: %u\n",UCHAR_MAX);
	//printf("mem start: %p\n",mem);
	//printf("mem + 1: %p\n",mem+1);

	//fill registers to make the string "Hello World",
	//print it with printf, save it to memory, then
	//load it again 
	seti(reg+0x0,0x48);
	seti(reg+0x1,0x65);
	seti(reg+0x2,0x6C);
	seti(reg+0x3,0x6C);
	seti(reg+0x4,0x6F);
	seti(reg+0x5,0x20);
	seti(reg+0x6,0x57);
	seti(reg+0x7,0x6F);
	seti(reg+0x8,0x72);
	seti(reg+0x9,0x6C);
	seti(reg+0xA,0x64);
	seti(reg+0xB,0x0);
	//print string
	printf("%s\n",reg);
	printf("Register contents after setting\n");
	printregs(stdout,reg);
	printf("Memory contents before doing anythong\n");
	printmem(stdout,mem,0x200,0x20F);
	//printf("Store register contents in memory");
	stor(reg,0xB,mem,&I);
	//printmem(stdout,mem,0x200,0x20F);
	//zero all the registers
	memset(reg,0,REG_COUNT);
	printf("Memory after saving\n");
	printmem(stdout,mem,0x200,0x20F);
	printf("Read memory as a string, line below should read \"Hello World\"\n");
	printf("%s\n",mem+0x200);
	printf("Registers should all be 0\n");
	printregs(stdout,reg);
	printf("Registers should now hold just the 2nd word\n");
	I = 0x206;
	load(reg,0x5,mem,&I); //should load "World"
	printregs(stdout,reg);
	printf("%s\n",reg);
	
	//test the other opcodes
	printf("Clear registers\n");
	memset(reg,0,REG_COUNT);
	printregs(stdout,reg);
	seti(reg+0x0,0x1);
	printf("set V0 to 1\n");
	printregs(stdout,reg);
	set(reg+0x1,reg+0x0);
	printf("Set V1 to V0 (1)\n");
	printregs(stdout,reg);
	addi(reg+0x0,0x2);
	printf("Added 2 to V0,should now be 3\n");
	printregs(stdout,reg);
	add(reg+0x0,reg+0x1,reg+0xF);
	printf("Add V0 and V1, store answer in V0\n");
	printregs(stdout,reg);
	addi(reg+0x2,0xFF);
	add(reg+0x0,reg+0x2,reg+0xF);
	printf("Testing carry flag, add 255 to V2 and add V2 to V0 (sets CF)\n");
	printregs(stdout,reg);
	subyx(reg+0x0,reg+0x2,reg+0xF);
	printf("V0 - V2, V0 should be 0xFC, VF = 0\n");
	printregs(stdout,reg);
	subxy(reg+0x1,reg+0x2,reg+0xF);
	printf("V2 (0xFF) - V1 (0x1) -> V1 (0xFE),VF = 1\n");
	printregs(stdout,reg);
}
Пример #11
0
void decodificaExecuta() {
    switch (uc.IR) {
        case 0xA: //load mq
            ula.AC = ula.MQ;
            break;
        case 0x9: //load mq,m(x)
            buscaOperandos();
            ula.MQ = ula.MBR;
            break;
        case 0x21: //stor m(x)
            ula.MBR = ula.AC;
            stor(uc.MAR);
            break;
        case 0x1: //load m(x)
            buscaOperandos();
            ula.AC = ula.MBR;
            break;
        case 0x2: //load -m(x)
            buscaOperandos();
            ula.AC = ula.MBR;
            ula.AC ^= 0x8000000000;
            break;
        case 0x3: //load |m(x)|
            buscaOperandos();
            ula.AC = ula.MBR;
            ula.AC &= 0x7FFFFFFFFF;
            break;
        case 0x4: //load -|m(x)|
            buscaOperandos();
            ula.AC = ula.MBR;
            ula.AC &= 0x7FFFFFFFFF;
            ula.AC ^= 0x8000000000;
            break;
        case 0xD: //jump m(x,0:19)
            uc.PC = uc.MAR;
            uc.CIRCUITOCONTROLE.proximaIBR = 0;
            break;
        case 0xE: //jump m(x,20:39)
            uc.PC = uc.MAR;
            uc.CIRCUITOCONTROLE.proximaIBR = 0;
            uc.CIRCUITOCONTROLE.instrucaoEsquerdaRequirida = 0;
            break;
        case 0xF: //jump+ m(x,0:19)
            if (ula.AC <= 0x7FFFFFFFFF){
                uc.PC = uc.MAR;
                uc.CIRCUITOCONTROLE.proximaIBR = 0;
            }
            break;
        case 0x10: //jump + m(x,20:39)
            if (ula.AC <= 0x7FFFFFFFFF){
                uc.PC = uc.MAR;
                uc.CIRCUITOCONTROLE.proximaIBR = 0;
                uc.CIRCUITOCONTROLE.instrucaoEsquerdaRequirida = 0;
            }
            break;
        case 0x5: //add m(x)
            buscaOperandos();
            circuitoLogicoAritmetico();
            break;
        case 0x6: //sub m(x)
            buscaOperandos();
            circuitoLogicoAritmetico();
            break;
        case 0x7: //add |m(x)|
            buscaOperandos();
            circuitoLogicoAritmetico();
            break;
        case 0x8: //sub |m(x)|
            buscaOperandos();
            circuitoLogicoAritmetico();
            break;
        case 0xB: //mul m(x)
            buscaOperandos();
            circuitoLogicoAritmetico();
            break;
        case 0xC: //div m(x)
            buscaOperandos();
            circuitoLogicoAritmetico();
            break;
        case 0x14: //lsh
            circuitoLogicoAritmetico();
            break;
        case 0x15: //rsh
            circuitoLogicoAritmetico();
            break;
        case 0x12: //stor m(x,8:19)
            ula.MBR = ula.AC;
            storEndereco(uc.MAR,1);
            break;
        case 0x13: //stor m(x,28:39)
            ula.MBR = ula.AC;
            storEndereco(uc.MAR,0);
            break;
        case 0x0: //exit
            uc.PC = -1;
    }
}