示例#1
0
static void		print_output_64(struct symtab_command *sym, char *ptr,
							struct mach_header_64 *header, t_symtab *symt)
{
	struct load_command		*lc;
	char					*stringtable;
	struct nlist_64			*array;
	uint32_t				i;

	i = 0;
	array = (void *)ptr + sym->symoff;
	stringtable = (void *)ptr + sym->stroff;
	lc = (void *)ptr + sizeof(*header);
	if (!verif((void *)array) || !verif((void *)stringtable) ||
	!verif((void *)lc))
		return (file_broken());
	array = symt->bonus == NO_SORT ? array
	: tri_bulle_64(stringtable, array, sym->nsyms);
	symtab_building(symt, header, lc);
	while (i < sym->nsyms)
	{
		display_out_64(array[i], stringtable + array[i].n_un.n_strx,
		type_element(array[i], symt), symt);
		i++;
	}
}
示例#2
0
void			handle_64(char *ptr, t_symtab *symt)
{
	int						ncmds;
	int						i;
	struct mach_header_64	*header;
	struct load_command		*lc;
	struct symtab_command	*sym;

	header = (struct mach_header_64 *)ptr;
	lc = (void *)ptr + sizeof(*header);
	if (!verif((void *)lc) || !verif((void *)header))
		return (file_broken());
	ncmds = header->ncmds;
	i = 0;
	while (i < ncmds)
	{
		if (lc->cmd == LC_SYMTAB)
		{
			sym = (struct symtab_command *)lc;
			print_output_64(sym, ptr, header, symt);
			break ;
		}
		if (!verif((void *)lc + lc->cmdsize))
			return (file_broken());
		lc = (void *)lc + lc->cmdsize;
		i++;
	}
}
示例#3
0
	void TestMonteCarlo(int nb_simu,int nb_var,int nb_pas,int type_generateur,int type_inverse) {
		cout << "nb_simu="<<nb_simu<<" nb_var ="<<nb_var<<" nb pas="******"Test de l'alea du compilateur" <<endl;
					res[i] = verif(Generateur::Alea_C(nb_var,nb_pas,nb_simu+i*nb_simu,type_inverse));
					cout <<endl;
					break;
				case 2:
					cout<<"Test de l'alea COngruentiel "<<endl;
					res[i] = verif(Generateur::Alea_Congruentiel(13,nb_var,nb_pas,nb_simu+i*nb_simu,type_inverse));
					cout<<endl;
					break;
				case 3:
					cout<<"Test de l'alea SOBOL avec Quantlib"<<endl;
					res[i] = verif(Generateur::Alea_Sobol_QMC(nb_var,nb_pas,nb_simu+i*nb_simu));
					cout<<endl;
					break;
			}
		}
		for(int j=0;j<4;j++) {
			for(int i=0;i<10;i++) {
				cout << i<<" "<<j <<res[i][j] <<endl ;
			}
			cout << endl;
		}


	}
示例#4
0
	TestAlea(int nb_simu,int nb_var,int nb_pas,int type_generateur) {
		res = vector<vector<double>>();
		cout << "nb_simu="<<nb_simu<<" nb_var ="<<nb_var<<" nb pas="******"Test de l'alea du compilateur avec Box-Muller :" <<endl;
				verif(Generateur::Alea_C(nb_var,nb_pas,nb_simu,1));
				cout << "Test de l'alea du compilateur avec Moro/Baesley :" <<endl;
				verif(Generateur::Alea_C(nb_var,nb_pas,nb_simu,2));
				cout <<endl;
				break;
			case 2:
				cout<<"Test de l'alea COngruentiel avec Box-Muller"<<endl;
				verif(Generateur::Alea_Congruentiel(13,nb_var,nb_pas,nb_simu,1));
				cout<<"Test de l'alea COngruentiel avec Moro/Baesley"<<endl;
				verif(Generateur::Alea_Congruentiel(13,nb_var,nb_pas,nb_simu,2));
				cout<<endl;
				break;
			case 3:
				cout<<"Test de l'alea SOBOL avec Quantlib"<<endl;
				verif(Generateur::Alea_Sobol_QMC(nb_var,nb_pas,nb_simu));
				cout<<endl;
				break;
			default:
				cout <<"Bienvenur dans le test de l'alea, c'est a vous de faire les test avec la fonction verif"<<endl;
		}
	}
示例#5
0
Personne saisie( Personne P)
{

printf("donner votre nom \n");
scanf("%s",& P.nom);
printf("donner votre prenom \n");
scanf("%s",& P.prenom);
do {
printf("donner votre code regional suivit de votre numero \n");
scanf("%d",& P.code);
scanf("%d",& P.numero);
} while (verif(P.code)!=3 || verif(P.numero)!=7);

return P;
}
示例#6
0
void supprimeringredient::valider_supprimer()
{
    int choix = QMessageBox::question(this,"Notice!","Voulez vous supprimer l\'ingredient suivant ?",QMessageBox::Yes,QMessageBox::No);

        if (choix == QMessageBox::Yes)
        {
            table->setQuery(QString("UPDATE ingredients SET ingredients = null WHERE ingredients = ").append("\""+ui->comboIngredients->currentText()+"\""));
            QSqlQuery verif(QString("SELECT ingredients FROM ingredients WHERE ingredients.ingredients != \"\" AND ingredients = ").append("\""+ui->comboIngredients->currentText()+"\""));
            int i = -1;
            while (verif.next())
            {
                i++;

            }
            if (i == -1)
	    {
                QMessageBox::information(this,"Notice","L\'ingredient a été supprimé avec succès",QMessageBox::Ok);
		QSqlQuery requete("SELECT DISTINCT ingredients FROM produit where ingredients != \"\"");
    while(requete.next())
    {
      ui->comboIngredients->addItem(requete.value(0).toString());
    }
		
	    }

             }
            if (choix == QMessageBox::No)
                return;



}
示例#7
0
void	flags(char *str, DIR *directory, char *ahmed)
{
	if (!verif(str))
		return ;
	if (ft_strchr(str, 'a') && ft_strchr(str, 'l') && ft_strchr(str, 't') && ft_strchr(str, 'r'))
		fn_list(directory, ahmed, 0);
	else if (ft_strchr(str, '1') && ft_strchr(str, 'a') && ft_strchr(str, 'r') && ft_strchr(str, 't'))
		lister(directory, ahmed, 1);
	else if (ft_strchr(str, 'l') && ft_strchr(str, 'r') && ft_strchr(str, 't'))
		fn_list(directory, ahmed, 2);
	else if (ft_strchr(str, 'a') && ft_strchr(str, 'l') && ft_strchr(str, 't'))
		fn_list(directory, ahmed, 3);
	else if (ft_strchr(str, 'a') && ft_strchr(str, 'l') && ft_strchr(str, 'r'))
		fn_list(directory, ahmed, 4);
	else if (ft_strchr(str, '1') && ft_strchr(str, 'r') && ft_strchr(str, 't'))
		lister(directory, ahmed, 5);
	else if (ft_strchr(str, '1') && ft_strchr(str, 'a') && ft_strchr(str, 'r'))
		lister(directory, ahmed, 6);
	else if (ft_strchr(str, '1') && ft_strchr(str, 't') && ft_strchr(str, 'a'))
		lister(directory, ahmed, 7);
	else if (ft_strchr(str, 'r') && ft_strchr(str, 't'))
		lister(directory, ahmed, 8);
	else if (ft_strchr(str, 'l') && ft_strchr(str, 't'))
		fn_list(directory, ahmed, 9);
	suite(str, directory, ahmed);
}
示例#8
0
文件: c4-H.c 项目: foobarna/OS
int main(int x, char* a[]){
FILE *f,*f2, *f3;
f = fopen(a[1], "r");
f2 = fopen(a[2], "r");
f3 = fopen(a[3],"a");
if (verif(f,f2,f3)){
fseek(f, 0, SEEK_END);
long j = ftell(f);
fseek(f2, 0, SEEK_END);
long k = ftell(f2);
char m[SIZE+1],l[SIZE],n[SIZE+SIZE];
int q = 0,i;

while (k>0 && j>0){
fseek(f, q, SEEK_SET);
i = (j<SIZE) ? j : (k<SIZE) ? k : SIZE;
j = fisier1(j,f,l);
k = fisier2(k,f2,m);
concat(l,m,n,i);
printf("%s\n",n);
scrie(f3,n,i);
q = q + SIZE;
}
fclose(f);
fclose(f2);
fclose(f3);
}
return 0;
}
示例#9
0
static void		symtab_building_bis(t_symtab *symt,
	struct segment_command_64 *seg, struct section_64 *sect)
{
	symt->i = 0;
	while (symt->i < seg->nsects)
	{
		if (ft_strcmp(sect->sectname, SECT_TEXT) == 0 &&
			ft_strcmp(sect->segname, SEG_TEXT) == 0)
		{
			symt->text = symt->ns;
		}
		else if (ft_strcmp(sect->sectname, SECT_DATA) == 0 &&
			ft_strcmp(sect->segname, SEG_DATA) == 0)
		{
			symt->data = symt->ns;
		}
		else if (ft_strcmp(sect->sectname, SECT_BSS) == 0 &&
			ft_strcmp(sect->segname, SEG_DATA) == 0)
			symt->bss = symt->ns;
		if (!verif((void *)sect + sizeof(*sect)))
			return (file_broken());
		sect = (void *)sect + sizeof(*sect);
		symt->ns++;
		symt->i++;
	}
}
示例#10
0
文件: main.c 项目: thomaselain/fillit
int			main(int argc, char **argv)
{
	t_env		*e;
	int			i;

	e = NULL;
	i = -1;
	if (argc != 2)
	{
		ft_putendl("Usage : ./fillit <filename>");
		return (0);
	}
	e = new_env(e);
	e->file = argv[1];
	read_file(e);
	c_pieces(e);
	while (++i < e->nb_piece && i < 26)
		e->t[i] = scan(e->buf, i);
	if (verif(e) == 1)
		return (0);
	new_square(e);
	resolve(e);
	display_grid(e);
	free(e);
	return (0);
}
示例#11
0
文件: main.c 项目: boujeh/Translater
int main(int argc,char *argv[]) {

	if (argc > 1) {
		
		if(verif(argv,argc)){
		printHelp();
		}else{
			int i=1;
			while(argc > i){
			if(!optionT(argv[i]))
			translate(argv[i++]);
			}
		}
	}else
	{
		char *text=NULL;
		text = (char *)malloc(sizeof(char)*100);
		printf("Give a text to translate : \n");
		getLine(text);
		translate(text);
		free(text);
	}
	return 0;

}
示例#12
0
文件: b_0_49.cpp 项目: jakexie/micmac
template <class Type> Bench_PackB_IM<Type>::Bench_PackB_IM
(
	Pt2di SZ,
	Fonc_Num f
) :
	sz     (SZ),
	im1    (ImInit(sz,f)),
        mPer   (16 * (INT)(2+(NRrandom3()*20))),
	pck    (sz.x,sz.y,im1.in(),mPer)
{
	verif();
}
示例#13
0
bool			Menu::lunchGame(int nbPlayers, Game &game)
{
  bool			back = false;

  while (!names.empty())
    names.pop_back();

  while (game.play() && back == false)
    {
      if (nbPlayers == 0)
	{
	  game.stopSound();
	  game.loadMap(10, 20, nbPlayers);
	  game.lunchCharacter(event, nbPlayers, names);
	  back = true;
	}
      game.initScene();
      switch (drawNameMenu(nbPlayers)) {
      case Click::CANCEL:
	back = true;
	break ;
      case Click::PLAY:
	for (int i = 0; i < nbPlayers; i++) {
	  switch (i) {
	  case 0:
	    names.push_back(getNameP1());
	    break ;
	  case 1:
	    names.push_back(getNameP2());
	    break ;
	  case 2:
	    names.push_back(getNameP3());
	    break;
	  default:
	    break ;
	  }
	}
	if (verif()) {
	  std::cout << "Start Game name = " << names[0].c_str() << std::endl;
	  game.stopSound();
	  game.loadMap(10, 20, nbPlayers);
	  game.lunchCharacter(event, nbPlayers, names);
	  back = true;
	}
	break;
      default:
	break;
      }
      game.endScene();
    }
  return back;
}
示例#14
0
List max_on_row(const Table& T) {
	verif(T);
	int l = T.size();
	int c = T[0].size();
	List L = initList(c,-1e7);
	for (int i=0; i<l; i++) {
		for (int j=0; j<c; j++) {
			int a = T[i][j];
			if (a>L[j]) L[j] = a;
		}
	}
	return L;
}
示例#15
0
文件: b.cpp 项目: dushmi/informatics
void back(int poz) {
  if (poz == k + 1) {
    verif();
    return;
  }

  for (int i = 1; i <= k; ++i)
    if (!f[i]) {
      f[i] = 1;
      perm[poz] = i;
      back(poz + 1);
      f[i] = 0;
    }
}
示例#16
0
文件: main.c 项目: atipex/Projets
int			main(int argc, char **argv)
{
	if (argc > 1)
	{
		check_def();
		if (verif(argv[1]))
		{
			ft_putendl("Good");
			return (1);
		}
		return (0);
	}
	ft_putendl_fd("You need an assembly file \".s\"", 2);
	return (0);
}
示例#17
0
void matchImages(int right_img_ix)
{
   // The keypoint structure is expected to have members called x, y, ori,
   // scale, and image. See also MyKeypoint.h
   std::vector< MyKeypoint > left_kpts, right_kpts;

   // A descriptor is stored as a std::bitset
   BRIEF desc;
   std::vector< std::bitset< BRIEF::DESC_LEN > > feat_left, feat_right;

   // Structure providing the ground truth
   static const float TOL = 2.f;     // pixel tolerance for accepting a match
   MatchVerifier< MyKeypoint, GroundTruthMiko > verif("wall/", TOL);

   // Load images
   const IplImage *left_img = verif.getGroundTruth().getImage(1);
   const IplImage *right_img = verif.getGroundTruth().getImage(right_img_ix);
   assert(left_img);
   assert(right_img);

   // Detect, for example, SURF points
   detectSURF(left_img, std::back_inserter(left_kpts), BRIEF::INIT_PATCH_SZ);
   detectSURF(right_img, std::back_inserter(right_kpts), BRIEF::INIT_PATCH_SZ);

   // Compute descriptors
   desc.getBRIEF(left_kpts, feat_left);
   desc.getBRIEF(right_kpts, feat_right);

   // Match descriptors
   printf("[OK] Matching %i against %i descriptors...\n",
          (int)feat_left.size(), (int)feat_right.size());
   BRIEFMatcher< MyKeypoint, BRIEF::DESC_LEN > matcher;
   std::vector< MyKeypoint > match_left, match_right;
   matcher.matchLeftRight(feat_left, feat_right, left_kpts, right_kpts,
                          std::inserter(match_left, match_left.begin()),
                          std::inserter(match_right, match_right.begin()));

   // Compute percentage of correct matches
   float rr = verif.getRecognitionRate(match_left, match_right, right_img_ix);
   printf("[OK] Got %.2f%% of %i retrieved matches right\n", rr*100, (int)match_left.size());

   // Save result image
   drawResult(match_left, match_right, left_img, right_img);
}
示例#18
0
void			symtab_building(t_symtab *symt, struct
	mach_header_64 *header, struct load_command *lc)
{
	struct segment_command_64	*seg;
	struct section_64			*sect;

	while (symt->j < header->ncmds)
	{
		if (lc->cmd == LC_SEGMENT_64)
		{
			seg = (struct segment_command_64 *)lc;
			sect = (struct section_64 *)((void *)seg + sizeof(*seg));
			symtab_building_bis(symt, seg, sect);
		}
		if (!verif((void *)lc + lc->cmdsize))
			return (file_broken());
		lc = (void *)lc + lc->cmdsize;
		symt->j++;
	}
}
示例#19
0
文件: allum1.c 项目: simepy/Allum1
int		main()
{
  t_pp		*pp;

  if ((pp = malloc(sizeof(t_pp))) &&
      (pp->buf = malloc(sizeof(char) * 4097)) == NULL)
    return (0);
  pp->i = pp->line = pp->nb_matches = pp->flag = 0;
  pp->flag2 = 0;
  while (pp->flag2 != 1)
    {
      pp->ia = pp->player = 0;
      if ((pp->i % 2) == 0 && pp->i >= 1)
	extend(pp);
      else if ((pp->i % 2) == 1 && pp->i >= 1)
	ai(pp);
      else
	print_updated_board_game(pp);
      pp->flag2 = verif(pp);
      pp->i++;
    }
  end(pp);
}
示例#20
0
文件: b_0_49.cpp 项目: jakexie/micmac
template <class Type> void  Bench_PackB_IM<Type>::verif()
{
        INT def = (INT)(NRrandom3() * 1000);  
        verif( rectangle(Pt2di(1,0),Pt2di(2,1)));
	for (INT k=0; k<10 ; k++)
	{
            verif( rectangle(Pt2di(k,0),Pt2di(k+1,10)  ),def);
            verif( rectangle(Pt2di(k,0),Pt2di(k+10,10) ),def);
            verif( rectangle(Pt2di(k,0),Pt2di(k+100,10)),def);
            verif( rectangle(Pt2di(k,0),Pt2di(k+200,10)),def);
	}



	verif( im1.all_pts());
	verif( rectangle(Pt2di(-10,-20),sz+Pt2di(30,40)),def);
	verif( disc(sz/2.0,euclid(sz)/1.8),def);


	{
	for (INT k=0 ; k<10 ; k++)
	{
		Pt2dr c = sz/2.0 + Pt2dr(NRrandom3(),NRrandom3())*20;
		REAL ray = 1+NRrandom3()*100;
        verif(disc(c,ray),def);
	}
	}



    ELISE_COPY(disc(CentreRand(),RayonRand()),1,im1.out()| pck.out());
	verif(im1.all_pts());

    ELISE_COPY(disc(CentreRand(),RayonRand()),frandr()*8,im1.out()| pck.out());
	verif(im1.all_pts());

    INT NbPts = (INT)(3 + NRrandom3()*10);

    ElList<Pt2di> Lpt;
	{
    for (INT k=0; k<NbPts ; k++)
       Lpt = Lpt+Pt2di(CentreRand());
	}

    ELISE_COPY(polygone(Lpt),NRrandom3()<0.1,im1.out()| pck.out());
	verif(im1.all_pts());



      ModifCSte(rectangle(Pt2di(5,0),Pt2di(10,10)),2);
      verif(im1.all_pts());

      ModifLut(rectangle(Pt2di(0,5),Pt2di(12,12)),FX&3);
      verif(im1.all_pts());

      //ModifCSte(disc(Pt2di(50,50),20),3);
      ModifCSte(disc(Pt2dr(50,50),20),3); // __NEW
      verif(im1.all_pts());


      for (INT NbC =0 ; NbC < 20 ; NbC++)
      {
          ElList<Pt2di> lPt;
          for (INT iPt =0 ; iPt < 20; iPt ++)
          {
              lPt  = lPt + Pt2di(CentreRand());
          }
          ModifCSte(polygone(lPt),INT(NRrandom3() * 3));
          verif(im1.all_pts());
      }

      Pt2di P_00 (0,0);
      Pt2di P_10 (sz.x,0);
      Pt2di P_01 (0,sz.y);
      ElList<Pt2di> lP1;
      lP1 =  lP1 + P_00; lP1 =  lP1 + P_01; lP1 =  lP1 + P_10;

      ModifCSte(polygone(lP1),7);
      verif(im1.all_pts());





    TiffVerif();

}
示例#21
0
文件: socket.c 项目: YannGarbe/m4101c
int creer_serveur(int port) {
	
	
	int socket_serveur ;
	socket_serveur = socket ( AF_INET , SOCK_STREAM , 0);

	if ( socket_serveur == -1)
	{
		perror ( " socket_serveur " );
		/* traitement de l ’ erreur */
	}
	/* Utilisation de la socket serveur */
	
	struct sockaddr_in saddr;
	saddr.sin_family = AF_INET; /* Socket ipv4 */
	saddr.sin_port = htons (port); /* Port d ’ écoute */
	saddr.sin_addr.s_addr = INADDR_ANY; /* écoute sur toutes les interfaces */

	/*Ajout de la modif socket*/
	int optval = 1;
	if (setsockopt(socket_serveur, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)) == -1)
		perror("Can not set SO_REUSEADDR");


	if (bind(socket_serveur , (struct sockaddr*)&saddr, sizeof(saddr)) == -1)
	{
		perror ( " bind socker_serveur " );
		/* traitement de l ’ erreur */
	}

	if ( listen ( socket_serveur , 10) == -1)
	{
		perror ("listen socket_serveur");
		/* traitement d ’ erreur */
	}
	
	
	int socket_client;
	

	/* On peut maintenant dialoguer avec le client */
	const char *message_bienvenue = " Bonjour , bienvenue sur mon serveur. Ce serveur est un projet d'un étudiant de Lille 1 dans le module 'Prog Sys'. \n Mon nom est Yann Garbé et je suis le créateur de ce serveur. Bon pour l'instant, il ne sert pas à grand chose, je vous l'accorde mais j'espère qu'il grandira.\n Avant tout, merci d'utiliser ce serveur ! \n Aussi, ce projet est disponible sur GitHub ici : 'https://github.com/YannGarbe'. Vous pouvez consulter  la page si vous la voulez mais il n'y a pas grand chose.\n Petit poème : \nA travers les soupirs, les plaintes et le râle\nPoursuivons jusqu’au bout la funèbre spirale\nDe ses détours maudits.\nNotre guide n’est pas Virgile le poëte,\nLa Béatrix vers nous ne penche pas la tête\nDu fond du paradis.\n\nPour guide nous avons une vierge au teint pâle\nQui jamais ne reçut le baiser d’or du hâle\nDes lèvres du soleil.\nSa joue est sans couleur et sa bouche bleuâtre,\nLe bouton de sa gorge est blanc comme l’albâtre,\nAu lieu d’être vermeil.\n\nUn souffle fait plier sa taille délicate ;\nSes bras, plus transparents que le jaspe ou l’agate,\nPendent languissamment ;\nSa main laisse échapper une fleur qui se fane,\nEt, ployée à son dos, son aile diaphane\nReste sans mouvement.\n\nPlus sombres que la nuit, plus fixes que la pierre,\nSous leur sourcil d’ébène et leur longue paupière\nLuisent ses deux grands yeux,\nComme l’eau du Léthé qui va muette et noire,\nSes cheveux débordés baignent sa chair d’ivoire\nA flots silencieux.\n\nDes feuilles de ciguë avec des violettes\nSe mêlent sur son front aux blanches bandelettes,\nChaste et simple ornement ;\nQuant au reste, elle est nue, et l’on rit et l’on tremble\nEn la voyant venir ; car elle a tout ensemble\nL’air sinistre et charmant.\n\nQuoiqu’elle ait mis le pied dans tous les lits du monde,\nSous sa blanche couronne elle reste inféconde\nDepuis l’éternité.\nL’ardent baiser s’éteint sur sa lèvre fatale,\nEt personne n’a pu cueillir la rose pâle\nDe sa virginité.\n\nThéophile Gautier, La comédie de la mort\n\n" ;

	char buffer [512];
	sleep(1);
	int pid;
	FILE * file;
	int erreur = 1;
	int errorNotFound = 0;
	int first = 0;
	char * msgError="\nHTTP/1.1 400 Bad Request\n\rConnection: close\n\rContent-Length: 17 \n\n\r400 Bad request\n\r\n";
	
	char * msgSuccess="\nHTTP/1.1 200 OK\n\rContent-Length: \n\n";

	char * msgNotFound="\nHTTP/1.1 404 Not Found\n\rConnection: close\n\rContent-Length: 17 \n\n\r404 Not Found\n\r";
	initialiser_signaux();
	while ((socket_client = accept(socket_serveur, NULL, NULL)) != -1) 
	{

		file = fdopen (socket_client , "w+" );
			if (file==NULL)
			{
				perror("fdopen");
			}
	
		pid = fork();
		if (pid == 0)
		{
			
			//write ( socket_client, message_bienvenue , strlen(message_bienvenue));
			/*while(fgets(buffer, 512, file) != NULL) 
			{*/
			char * msg;
			while((msg=req(buffer, file, sizeof(buffer)/sizeof(buffer[0]))))
			{	
				//fprintf(file, "<mygaServer> %s", buffer);
				//printf("%s\n", buffer);
				if(errorNotFound==1 && ((strcmp(msg,"\r\n")==0)||(strcmp(msg,"\n")==0))){
					fprintf(file, msgNotFound);
					errorNotFound=0;
					first = 0;
				}

	
				else if(erreur==1 && ((strcmp(msg,"\r\n")==0)||(strcmp(msg,"\n")==0)))
				{
					fprintf(file, msgError);
					first = 0;
				}
				else if(errorNotFound == 0 && erreur==0 && ((strcmp(msg,"\r\n")==0)||(strcmp(msg,"\n")==0)))
				{
							char str[15];
							sprintf(str, "%d", (int)strlen(message_bienvenue));
							char * message_end = concatenation(str,"\n\n\r200 OK\n\r");
							msgSuccess = concatenation(msgSuccess,message_end);
							fprintf(file, msgSuccess);
							msgSuccess="\nHTTP/1.1 200 OK\n\rContent-Length: ";
							printf("Connection Accomplie!\n");
							erreur=1;
							first = 0;
							fprintf(file, message_bienvenue);
				}
				if(verif(msg)==0 && first==0)
				{
					erreur=0;
				} 
				else if (verif(msg) ==404 &&  first==0)
				{
					errorNotFound = 1;
				}

				if(msg && ((strcmp(msg,"\r\n")!=0)&&(strcmp(msg,"\n")!=0))){
					first = 1;
				}
			}	
			fclose(file);
			exit (0);
		} else {
			close(socket_client);
		}
		
		}
		//close(socket_serveur);
		return port;

	} 
示例#22
0
bool Parser::parse(const int argc,char ** argv)
{
  this->cmd = argv[0];
  this->options[this->cmd] = NULL;
  reset_value();
  for(int i = 1; i < argc; i++)
  {
    map<string, option*>::iterator it;
    option *p = NULL;
    for(it = this->options.begin(); it != this->options.end(); ++it)
    {
      // cout << "key:" << it->first << endl;
      if(it->first == argv[i])
      {
        p = it->second;
        if(p->v != NULL)
        {
          continue;
        }
        value v;
        switch(p->dataType)
        {
        case BOOL:
          p->v = new value;
          p->v->on = true;
          logger->log(INFO, "%s=>true", it->first.c_str());
          break;
        case STRING:
          p->v = new value;
          p->v->str = new char[strlen(argv[++i]) + 1];
          strcpy(p->v->str, argv[i]);
          logger->log(INFO, "%s=>:%s", it->first.c_str(),p->v->str);
          break;
        default:
          COM_ERROR("type not supported...");
          return false;
        }

      }
    }
    //option is not found
    if(NULL == p)
    {
      if(argv[i][0] == '-' || NULL != this->options[this->cmd])
      {
        COM_ERROR("arg:%s is not exist in cmd %s", argv[i], this->cmd.c_str());
        help();
        return false;
      }
      else//asign input value
      {
        option * p = new option;
        if(p == NULL)
        {
          logger->log(DEBUG, "p is NULL");
        }
        p->description = "input";
        p->dataType = STRING;
        p->mandatory = true;
        p->v = new value;
        p->v->str = new char[strlen(argv[i]) + 1];
        strcpy(p->v->str, argv[i]);
        this->options[this->cmd] = p;
        logger->log(INFO, "%s=>:%s", this->cmd.c_str(), p->v->str);
      }
    }
  }
  //http://blog.csdn.net/since20140504/article/details/38269283
  if(verif() == false)
  {
    help();
    return false;
  }
  value *v = this->get_value(this->cmd);

  return true;
}
示例#23
0
/*----------------------------------------------------------------------
|       main
+---------------------------------------------------------------------*/
int
main(int /*argc*/, char** /*argv*/)
{
    NPT_Result result;


    NPT_String t = "hello";
    NPT_String base64;
    NPT_DataBuffer data;
    result = NPT_Base64::Encode((const NPT_Byte*)t.GetChars(), t.GetLength(), base64);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(base64 == "aGVsbG8=");
    result = NPT_Base64::Decode(base64.GetChars(), base64.GetLength(), data);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(data.GetDataSize() == t.GetLength());
    NPT_String tt((const char*)data.GetData(), data.GetDataSize());
    NPT_ASSERT(tt == t);

    t = "hello!";
    result = NPT_Base64::Encode((const NPT_Byte*)t.GetChars(), t.GetLength(), base64);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(base64 == "aGVsbG8h");
    result = NPT_Base64::Decode(base64.GetChars(), base64.GetLength(), data);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(data.GetDataSize() == t.GetLength());
    tt.Assign((const char*)data.GetData(), data.GetDataSize());
    NPT_ASSERT(tt == t);

    t = "hello!!";
    result = NPT_Base64::Encode((const NPT_Byte*)t.GetChars(), t.GetLength(), base64);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(base64 == "aGVsbG8hIQ==");
    result = NPT_Base64::Decode(base64.GetChars(), base64.GetLength(), data);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(data.GetDataSize() == t.GetLength());
    tt.Assign((const char*)data.GetData(), data.GetDataSize());
    NPT_ASSERT(tt == t);
    
    unsigned char r256_bin[] = {
        0x7d, 0x5f, 0xd0, 0xf4, 0x6a, 0xa8, 0xae, 0x34, 0x6e, 0x32, 0x1d, 0xa1,
        0xef, 0x66, 0xdd, 0x82, 0x76, 0xa6, 0xfd, 0x8c, 0x75, 0x97, 0xa0, 0x01,
        0x00, 0xde, 0x52, 0xef, 0xdf, 0xb6, 0x3e, 0xe4, 0x7b, 0x45, 0xdd, 0x2b,
        0xa1, 0x9c, 0xb0, 0x6d, 0x2c, 0x75, 0xb1, 0x87, 0x43, 0x0f, 0xea, 0x24,
        0x36, 0x11, 0x7e, 0xee, 0xd1, 0x91, 0x7f, 0x7b, 0x02, 0xea, 0x9a, 0x2a,
        0x25, 0xc0, 0xac, 0x99, 0xa4, 0x89, 0x55, 0x5b, 0x82, 0xdf, 0xb0, 0x7e,
        0xa1, 0x78, 0x0f, 0xdf, 0x25, 0x5f, 0x3d, 0xba, 0xcb, 0xbc, 0x35, 0x04,
        0xc3, 0xf4, 0xb8, 0xc0, 0x17, 0x8e, 0x75, 0x01, 0xe6, 0x2f, 0x88, 0x2c,
        0x76, 0x0a, 0x8c, 0x3f, 0x83, 0xd4, 0x10, 0xa8, 0x00, 0xfc, 0xa0, 0x92,
        0x7b, 0xae, 0xa3, 0x8c, 0x47, 0xea, 0x25, 0xf9, 0x29, 0x81, 0x1c, 0x21,
        0xf2, 0xf4, 0xfe, 0x07, 0x7e, 0x4b, 0x01, 0x79, 0x41, 0x3a, 0xb6, 0x71,
        0x0b, 0x75, 0xa7, 0x9d, 0x1b, 0x12, 0xc4, 0x46, 0x06, 0xf3, 0x5f, 0x00,
        0x05, 0x2a, 0x1b, 0x34, 0xd6, 0x87, 0xc4, 0x70, 0xcc, 0xc3, 0x9e, 0xa8,
        0x24, 0x2c, 0x97, 0x4e, 0xfc, 0x91, 0x70, 0x1c, 0x29, 0x66, 0xc3, 0x23,
        0xbf, 0xd7, 0x4d, 0x35, 0x51, 0xff, 0xeb, 0xde, 0x45, 0xbd, 0x8d, 0x80,
        0x44, 0x2a, 0x8d, 0xc0, 0xe8, 0x6a, 0xe2, 0x86, 0x46, 0x9f, 0xf2, 0x3c,
        0x93, 0x0d, 0x27, 0x02, 0xe4, 0x79, 0xa1, 0x21, 0xf4, 0x43, 0xcd, 0x4c,
        0x22, 0x25, 0x9e, 0x93, 0xeb, 0x77, 0x8e, 0x1e, 0x57, 0x1e, 0x9b, 0xcb,
        0x91, 0x86, 0xcf, 0x15, 0xaf, 0xd5, 0x03, 0x0f, 0x70, 0xbe, 0x6e, 0x37,
        0xea, 0x37, 0xdd, 0xf6, 0xa1, 0xb1, 0xf7, 0x05, 0xbc, 0x2d, 0x44, 0x60,
        0x35, 0xa4, 0x05, 0x0b, 0x22, 0x7d, 0x7a, 0x71, 0xe5, 0x1d, 0x8e, 0xcb,
        0xc3, 0xb8, 0x3a, 0xe1
    };
    NPT_String b64;
    NPT_Base64::Encode(r256_bin, sizeof(r256_bin), b64);
    NPT_DataBuffer r256_out;
    NPT_Base64::Decode(b64.GetChars(), b64.GetLength(), r256_out);
    NPT_ASSERT(r256_out.GetDataSize() == sizeof(r256_bin));
    NPT_ASSERT(r256_bin[sizeof(r256_bin)-1] == r256_out.GetData()[sizeof(r256_bin)-1]);

    unsigned char random_bytes[] = {
        0xc7, 0xee, 0x49, 0x9e, 0x2c, 0x8b, 0x1c, 0x16, 0x9e, 0x7f, 0x30, 0xd0,
        0xc6, 0x12, 0x30, 0x80, 0x81, 0xcd, 0x20, 0x20, 0x26, 0xaf, 0x4f, 0xd6,
        0xfc, 0x86, 0x2e, 0x85, 0xf3, 0x10, 0x38, 0x2b, 0x0e, 0xbb, 0x80, 0x68,
        0xbe, 0xff, 0x1c, 0xdc, 0x72, 0xb5, 0x0d, 0x8f, 0x8e, 0x6c, 0x09, 0x63,
        0xba, 0x21, 0x23, 0xb2, 0x24, 0x17, 0xd3, 0x17, 0x69, 0x44, 0x77, 0x11,
        0x36, 0x6a, 0x6e, 0xf2, 0x44, 0x87, 0xa1, 0xd3, 0xf3, 0x1f, 0x6c, 0x38,
        0x22, 0x4a, 0x44, 0x70, 0x66, 0xef, 0x8c, 0x3a, 0x51, 0xc8, 0xee, 0x85,
        0x00, 0x25, 0x93, 0x10, 0x2e, 0x0b, 0x1b, 0x03, 0x94, 0x47, 0x05, 0x22,
        0xd0, 0xc4, 0xec, 0x2e, 0xcc, 0xbc, 0xbb, 0x67, 0xfd, 0xec, 0x0e, 0xb1,
        0x3f, 0xbc, 0x82, 0xe0, 0xa7, 0x9c, 0xf3, 0xae, 0xbd, 0xb7, 0xab, 0x02,
        0xf1, 0xd9, 0x17, 0x4c, 0x9d, 0xeb, 0xe2, 0x00, 0x1e, 0x19, 0x6e, 0xb3,
        0xfd, 0x7d, 0xea, 0x49, 0x85, 0x43, 0x2f, 0x56, 0x81, 0x89, 0xba, 0x71,
        0x37, 0x10, 0xb5, 0x74, 0xab, 0x90, 0x4d, 0xc4, 0xd1, 0x0d, 0x8d, 0x6f,
        0x01, 0xf5, 0x2c, 0xc9, 0x1a, 0x79, 0xa1, 0x41, 0x71, 0x2b, 0xfb, 0xf3,
        0xd5, 0xe4, 0x2a, 0xf5, 0xad, 0x80, 0x7a, 0x03, 0xff, 0x5f, 0x45, 0x8c,
        0xec, 0x6a, 0x4b, 0x05, 0xe3, 0x65, 0x19, 0x70, 0x05, 0xad, 0xc4, 0xb8,
        0x4e, 0x9e, 0x9a, 0x36, 0x4a, 0x86, 0x9d, 0xf5, 0x99, 0xcb, 0x00, 0xb8,
        0xb9, 0xa7, 0x86, 0x18, 0xfc, 0x9a, 0xe7, 0x00, 0x6a, 0x67, 0xfa, 0x42,
        0x9d, 0xff, 0x4d, 0x7a, 0xe4, 0xe8, 0x03, 0x88, 0xff, 0x60, 0xe1, 0x8d,
        0x09, 0x5f, 0x6f, 0xde, 0x6b
    };
    NPT_Array<unsigned char> random(random_bytes, NPT_ARRAY_SIZE(random_bytes));

    t = "x+5JniyLHBaefzDQxhIwgIHNICAmr0/W/IYuhfMQOCsOu4Bovv8c3HK1DY+ObAlj\r\n"
        "uiEjsiQX0xdpRHcRNmpu8kSHodPzH2w4IkpEcGbvjDpRyO6FACWTEC4LGwOURwUi\r\n"
        "0MTsLsy8u2f97A6xP7yC4Kec8669t6sC8dkXTJ3r4gAeGW6z/X3qSYVDL1aBibpx\r\n"
        "NxC1dKuQTcTRDY1vAfUsyRp5oUFxK/vz1eQq9a2AegP/X0WM7GpLBeNlGXAFrcS4\r\n"
        "Tp6aNkqGnfWZywC4uaeGGPya5wBqZ/pCnf9NeuToA4j/YOGNCV9v3ms=";
    result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(data.GetDataSize() == 233);
    NPT_Array<unsigned char> verif(data.GetData(), data.GetDataSize());
    NPT_ASSERT(verif == random);

    result = NPT_Base64::Encode(&random[0], random.GetItemCount(), base64, NPT_BASE64_PEM_BLOCKS_PER_LINE);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(base64 == t);

    NPT_String t_url = t;
    t.Replace('/', '_');
    t.Replace('+', '-');
    result = NPT_Base64::Encode(&random[0], random.GetItemCount(), base64, NPT_BASE64_PEM_BLOCKS_PER_LINE, true);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(base64 == t);
    
    t = "76768484767685839";
    result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
    NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);

    t = "76869=978686";
    result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
    NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);

    t = "7686=8978686";
    result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
    NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);

    t = "7686==978686";
    result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
    NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);

    // test IP address parsing
    NPT_IpAddress ip;
    NPT_ASSERT(NPT_FAILED(ip.Parse("")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("a.b.c.d")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4.5")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4.")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4f")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.g.3.4")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.2..3.4")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.300.4")));
    NPT_ASSERT(NPT_SUCCEEDED(ip.Parse("1.2.3.4")));
    NPT_ASSERT(ip.AsBytes()[0] == 1);
    NPT_ASSERT(ip.AsBytes()[1] == 2);
    NPT_ASSERT(ip.AsBytes()[2] == 3);
    NPT_ASSERT(ip.AsBytes()[3] == 4);
    NPT_ASSERT(NPT_SUCCEEDED(ip.Parse("255.255.0.1")));
    NPT_ASSERT(ip.AsBytes()[0] == 255);
    NPT_ASSERT(ip.AsBytes()[1] == 255);
    NPT_ASSERT(ip.AsBytes()[2] == 0);
    NPT_ASSERT(ip.AsBytes()[3] == 1);
    NPT_ASSERT(NPT_SUCCEEDED(ip.Parse("0.0.0.0")));
    NPT_ASSERT(ip.AsBytes()[0] == 0);
    NPT_ASSERT(ip.AsBytes()[1] == 0);
    NPT_ASSERT(ip.AsBytes()[2] == 0);
    NPT_ASSERT(ip.AsBytes()[3] == 0);

    return 0;
}
示例#24
0
static void eval(Node *p){

	int i, lbl1, lbl2, size, temp = 0, attrib = 1;
	char *name;

	if (p == 0) return;
	switch(p->attrib){

		case CONTINUE:
		/* JMP cond*/
			break;		
		case BREAK:
		/* JMP fim */
			break;		
		case ELIF:
		
			break;

		case FOR:
			eval(p->SUB(0));
			fprintf(out, pfLABEL, mklbl(lbl1 = ++lbl));
			eval(p->SUB(1));
			fprintf(out, pfJZ, mklbl(lbl2 = ++lbl));
			IDpush();
			eval(p->SUB(3));
			eval(p->SUB(2));
			IDpop();
			fprintf(out, pfJMP, mklbl(lbl1));
			fprintf(out, pfLABEL, mklbl(lbl2));
			break;

		case ALLOCA:
			eval(p->SUB(1));
			fprintf(out, pfALLOC);
			fprintf(out, pfSP);
			eval(p->SUB(0));
			fprintf(out, pfSTORE);
			break;

		case EXTERN:						/* extern declarations        */
			for (i = 0; i < p->value.sub.num; i++){
				name = p->SUB(i)->SUB(0)->value.s;
				IDnew(EXTERN, name, p->SUB(i)->value.sub.num);
				fprintf(out, pfEXTRN, name);
			}
			break;
		case INIT:
			name = p->SUB(0)->SUB(0)->value.s;
			IDnew(INIT, name, p->SUB(1)->value.sub.num);
			fprintf(out, pfDATA);
			fprintf(out, pfALIGN);				/* make sure we are aligned   */
			
			fprintf(out, pfGLOBL, name, pfOBJ);
			fprintf(out, pfLABEL, name);
			for(i = 0; i < p->SUB(1)->value.sub.num; i++){
				fprintf(out, pfCONST, p->SUB(1)->SUB(i)->value.i);
			}
			fprintf(out, pfTEXT);
			fprintf(out, pfALIGN);				/* make sure we are aligned   */
			break;
		case CONST:
			fprintf(out, pfRODATA);
			fprintf(out, pfALIGN);

			name = p->SUB(0)->SUB(0)->value.s;
			IDnew(CONST, name, p->SUB(1)->value.sub.num);				
			fprintf(out, pfLABEL, name);			/* name variable location     */
			for (temp = 0; temp < p->SUB(1)->value.sub.num; temp++)
				fprintf(out, pfCONST, p->SUB(1)->SUB(temp)->value.i);
			fprintf(out, pfTEXT);
			fprintf(out, pfALIGN);
			break;
			
		case LVALUE2:
			for (i = 0; i < p->value.sub.num; i++)
				eval(p->SUB(i));
			break;
		case LVALUE:
  			name = p->SUB(0)->SUB(0)->value.s;

			if(p->SUB(0)->SUB(0)->attrib == IDLVALUE)
				IDnew(INT_NUMBER, name, offset);
			else if (p->SUB(0)->SUB(0)->attrib == IDARRAY)
				IDnew(ARRAY, name, offset);
			else{
				name = p->SUB(0)->SUB(0)->SUB(0)->value.s;
				offset -= 4 * p->SUB(0)->SUB(1)->value.i;
				IDnew(ARRAYINDEX, name, offset);
				break;
			}
			offset -= 4;
			break;
		case VAR:
			for (i = 0; i < p->value.sub.num; i++){
				eval(p->SUB(i));
			}
			break;

		case ARRAYINDEX:
			eval(p->SUB(1));
			if (p->SUB(1)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfINT, 4);				/* push an integer	      */
			fprintf(out, pfMUL);
			eval(p->SUB(0));
			fprintf(out, pfADD);

			break;
		case ARRAY:
			eval(p->SUB(0));	
			break;

		case FNNAME:
			name = p->SUB(0)->SUB(0)->value.s;
			if(p->value.sub.num == 2)
				temp = p->SUB(1)->value.sub.num;
			IDnew(FNNAME, name, temp);
			IDpush();
			IDnew(INT_NUMBER, name, -4);
			
			offset = -8;
			fprintf(out, pfTEXT);
			fprintf(out, pfALIGN);
			fprintf(out, pfGLOBL, name, pfFUNC);
			fprintf(out, pfLABEL, name);
			fprintf(out, pfENTER, args + 4);
			break;
		case FUNCTION:
			args = count_args(p);
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			fprintf(out, pfLOCAL, -4);
			fprintf(out, pfLOAD);
			fprintf(out, pfPOP);
			fprintf(out, pfLEAVE);
			fprintf(out, pfRET);
			IDpop();
			break;

		case INT_NUMBER:
			fprintf(out, pfINT, p->value.i);		/* push an integer	      */
			break;
		case ID:						/* */
			name = p->SUB(0)->value.s;
			switch(p->SUB(0)->attrib){
				case IDLVALUE:
				case IDARRAY:
				case IDARRAYINDEX:
					temp = IDfind(name, &attrib);
					fprintf(out, pfLOCAL, attrib);
					break;
				default:
					fprintf(out, pfADDR, name);
					break;
			}
			break;	
		case DO:
			fprintf(out, pfLABEL, mklbl(lbl1 = ++lbl));
			IDpush();
			eval(p->SUB(0));
			IDpop();
			fprintf(out, pfLABEL, mklbl(lbl2 = ++lbl));
			eval(p->SUB(1));
			fprintf(out, pfJNZ, mklbl(lbl1));
			if (p->value.sub.num > 2){			/* do else 			*/
				IDpush();
				eval(p->SUB(2));
				IDpop();
			}
			break;		
		case WHILE:
			fprintf(out, pfLABEL, mklbl(lbl1 = ++lbl));
			eval(p->SUB(0));
			fprintf(out, pfJZ, mklbl(lbl2 = ++lbl));
			IDpush();
			eval(p->SUB(1));
			IDpop();
			fprintf(out, pfJMP, mklbl(lbl1));
			fprintf(out, pfLABEL, mklbl(lbl2));
			if (p->value.sub.num > 2){			/* while else 			*/
				IDpush();
				eval(p->SUB(2));
				IDpop();
			}
			break;
		case CALL:
			name = p->SUB(0)->value.s;
			if(p->value.sub.num == 2) {	
				for(i = p->SUB(1)->value.sub.num; i > 0; i--){
					eval(p->SUB(i));		/* evaluate argument	      */
					if (p->SUB(i)->attrib != INT_NUMBER)
						fprintf(out, pfLOAD);
				}
			}
			fprintf(out, pfCALL, name);
			fprintf(out, pfTRASH, i);			/* remove the return value    */
			fprintf(out, pfPUSH);
			break;	

		case STR:						/* generate the string	      */			 
			fprintf(out, pfRODATA);				/* strings are DATA readonly  */
			fprintf(out, pfALIGN);				/* make sure we are aligned   */
			fprintf(out, pfLABEL, mklbl(lbl1 = ++lbl));	/* give the string a name     */
			fprintf(out, pfSTR, p->value.s); 		/* output string characters   */
				/* make the call */
			fprintf(out, pfTEXT);				/* return to the TEXT segment */
			fprintf(out, pfALIGN);				/* make sure we are aligned   */
			fprintf(out, pfADDR, mklbl(lbl1));
			break;

		case PRINTSTUFF:
			eval(p->SUB(0));
			if(p->SUB(0)->attrib == ID){
				fprintf(out, pfLOAD);
				fprintf(out, pfCALL, "printi");		/* call the print function    */
			}
			else if(p->SUB(0)->attrib == STR){
				fprintf(out, pfCALL, "prints");		/* call the print function    */
			}
			else if(p->SUB(0)->attrib == INT_NUMBER){
				fprintf(out, pfCALL, "printi");		/* call the print function    */
			}
			print = 0;
			break;
		case '!':
			print = 1;
			eval(p->SUB(0));				/* determine the value        */
			fprintf(out, pfTRASH, 4);			/* delete the printed value   */
			break;		
		case OUT:
			print = 1;
			eval(p->SUB(0));				/* determine the value        */
			fprintf(out, pfCALL, "println");		/* print a newline	      */
			fprintf(out, pfTRASH, 4);			/* delete the printed value   */
			break;
		case IF:
			eval(p->SUB(0));
			if (p->SUB(0)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfJZ, mklbl(lbl1 = ++lbl));
			IDpush();
			eval(p->SUB(1));
			IDpop();
			if (p->value.sub.num > 2){			/* if else 			*/
				fprintf(out, pfJMP, mklbl(lbl2 = ++lbl));
				fprintf(out, pfLABEL, mklbl(lbl1));
				IDpush();
				eval(p->SUB(2));
				IDpop();
				lbl1 = lbl2;
			}
			fprintf(out, pfLABEL, mklbl(lbl1));
			break;

		case BONUS:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;	
		case COMPOUND_STAT:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;
		case CONST_LIST:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;	
		case DECL_VAR_LIST:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;	
		case EXPRESSION_LIST:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;
		case EXTRA_STAT_LIST:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;
		case NUM_LIST:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;	
		case PROGRAM:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;
		case STATEMENT:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;
		case STATEMENT_LIST:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;
		case ULTRA:
			for (i = 0; i < p->value.sub.num; i++)
	  			eval(p->SUB(i));
			break;		

		case AND_OP:
			eval(p->SUB(0));				/* evaluate first argument    */
			if (p->SUB(0)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfDUP);
			fprintf(out, pfJZ, mklbl(lbl1 = ++lbl));
			fprintf(out, pfTRASH, 4);
			eval(p->SUB(1));				/* evaluate second argument   */
			if (p->SUB(0)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfLABEL, mklbl(lbl1));
			break;
		case OR_OP:
			eval(p->SUB(0));				/* evaluate first argument    */
			if (p->SUB(0)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfDUP);
			fprintf(out, pfJNZ, mklbl(lbl1 = ++lbl));
			fprintf(out, pfTRASH, 4);
			eval(p->SUB(1));				/* evaluate second argument   */
			if (p->SUB(0)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfLABEL, mklbl(lbl1));
			break;
		case NOT:
			eval(p->SUB(0));				/* evaluate argument	      */
			if (p->SUB(0)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfINT, 0);
			fprintf(out, pfEQ);
			break;
		case '?':
			fprintf(out, pfCALL, "readi");
			fprintf(out, pfPUSH);
			eval(p->SUB(0));
			fprintf(out, pfSTORE);
			break;
		case '=':
			eval(p->SUB(1));				/* determine the new value    */
			if(p->SUB(1)->attrib == '='){
				eval(p->SUB(1)->SUB(0));
				fprintf(out, pfLOAD);
			}
			eval(p->SUB(0));	 			/* determine the new address  */
			fprintf(out, pfSTORE);				/* store the value at address */
			break;
		case '@':
			eval(p->SUB(0));				/* evaluate argument	      */
			break;
		case SIMETRIC:
			eval(p->SUB(0));				/* evaluate argument	      */
			if (p->SUB(0)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfNEG);				/* make the 2-compliment      */
			break;
		case INC:
			eval(p->SUB(0));				/* evaluate argument	      */
			fprintf(out, pfINCR, 1);
			break;		
		case DEC:
			eval(p->SUB(0));				/* evaluate argument	      */
			fprintf(out, pfDECR, 1);
			break;
		case ADDEDATTRIB:
			eval(p->SUB(0));
			fprintf(out, pfLOAD);
			eval(p->SUB(1));
			if (p->SUB(1)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfADD);

			eval(p->SUB(0));				/* determine the new address  */
			fprintf(out, pfSTORE);				/* store the value at address */			
			break;

/*		case MINUSATTRIB:
			eval(p->SUB(0));
			fprintf(out, pfLOAD);
			eval(p->SUB(1));
			if (p->SUB(1)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfSUB);

			eval(p->SUB(0));	 			
			fprintf(out, pfSTORE);							
			break;

		case MULATTRIB:
			eval(p->SUB(0));
			fprintf(out, pfLOAD);
			eval(p->SUB(1));
			if (p->SUB(1)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfMUL);

			eval(p->SUB(0));	 			
			fprintf(out, pfSTORE);							
			break;

		case DIVATTRIB:
			eval(p->SUB(0));
			fprintf(out, pfLOAD);
			eval(p->SUB(1));
			if (p->SUB(1)->attrib != INT_NUMBER)
				fprintf(out, pfDIV);
			fprintf(out, pfADD);

			eval(p->SUB(0));	 			
			fprintf(out, pfSTORE);							
			break;

		case MODATTRIB:
			eval(p->SUB(0));
			fprintf(out, pfLOAD);
			eval(p->SUB(1));
			if (p->SUB(1)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			fprintf(out, pfMOD);

			eval(p->SUB(0));	 			
			fprintf(out, pfSTORE);							
			break;

		case EXPATTRIB:
			eval(p->SUB(0));
			fprintf(out, pfLOAD);
			eval(p->SUB(1));
			if (p->SUB(1)->attrib != INT_NUMBER)
				fprintf(out, pfLOAD);
			pow_flag = 1;
			fprintf(out, pfCALL, "power");
			fprintf(out, pfTRASH, 8);
			fprintf(out, pfPUSH);

			eval(p->SUB(0));	 			
			fprintf(out, pfSTORE);							
			break;
*/
		default:	
			if(print){
				if(p->attrib == '+'){
					for (i = 0; i < p->value.sub.num; i++){
	  					eval(p->SUB(i));

						if(p->SUB(i)->attrib == ID){
							fprintf(out, pfLOAD);
							fprintf(out, pfCALL, "printi");		/* call the print function    */
						}
						else if(p->SUB(i)->attrib == INT_NUMBER){
							fprintf(out, pfCALL, "printi");		/* call the print function    */
						}
	  					else if (p->SUB(i)->attrib == STR){
							fprintf(out, pfCALL, "prints");			/* call the print function    */
						}
						else if(p->SUB(i)->attrib == '*'){
							eval(p->SUB(i)->SUB(1));				/* determine the value        */
							if (p->SUB(i)->SUB(1)->attrib != INT_NUMBER)
								fprintf(out, pfLOAD);

							eval(p->SUB(i)->SUB(0));				/* determine the value        */

							printer_flag = 1;
							fprintf(out, pfCALL, "printer");		/* print a newline	      */
							fprintf(out, pfTRASH, 4);			/* remove the return value    */	
						}
					}
				}
				else{
					eval(p->SUB(1));				/* determine the value        */
					if (p->SUB(1)->attrib != INT_NUMBER)
						fprintf(out, pfLOAD);

					eval(p->SUB(0));				/* determine the value        */

					printer_flag = 1;
					fprintf(out, pfCALL, "printer");		/* print a newline	      */
					fprintf(out, pfTRASH, 4);			/* remove the return value    */	
				}
			}
			else{

				eval(p->SUB(1));				/* evaluate first argument    */
				if (p->SUB(1)->attrib != INT_NUMBER)
					fprintf(out, pfLOAD);

				switch(p->attrib){	 			/* make the operation ...     */
					case '+':
						eval(p->SUB(0));				/* determine the new value    */
						if (verif(p->SUB(0)))
							fprintf(out, pfLOAD);				
			
						fprintf(out, pfADD);
						break;
					case '-':	
						eval(p->SUB(0));				/* determine the new value    */
						if (p->SUB(0)->attrib != INT_NUMBER && p->SUB(0)->attrib != '-')
							fprintf(out, pfLOAD);	

						fprintf(out, pfSUB); 
						break;
					case '*':
						eval(p->SUB(0));				/* determine the new value    */
						if (p->SUB(0)->attrib != INT_NUMBER && p->SUB(0)->attrib != '*')
							fprintf(out, pfLOAD);		

						fprintf(out, pfMUL);
						break;
					case '/':
						eval(p->SUB(0));				/* determine the new value    */
						if (p->SUB(0)->attrib != INT_NUMBER && p->SUB(0)->attrib != '/')
							fprintf(out, pfLOAD);	

						fprintf(out, pfDIV);
						break;
					case '%':
						eval(p->SUB(0));				/* determine the new value    */
						if (p->SUB(0)->attrib != INT_NUMBER && p->SUB(0)->attrib != '%')
							fprintf(out, pfLOAD);	

						fprintf(out, pfMOD);
						break;
					case EXP:
						eval(p->SUB(0));				/* determine the new value    */
						if (p->SUB(0)->attrib != INT_NUMBER && p->SUB(0)->attrib != EXP)
							fprintf(out, pfLOAD);	

						pow_flag = 1;
						fprintf(out, pfCALL, "power");
						fprintf(out, pfTRASH, 8);
						fprintf(out, pfPUSH);
						break;
					case '<':
						fprintf(out, pfLT); break;
					case '>':
						fprintf(out, pfGT); break;
					case GE_OP:
						fprintf(out, pfGE); break;
					case LE_OP:
						fprintf(out, pfLE); break;
					case NE_OP:
						fprintf(out, pfNE); break;
					case EQ_OP:
						fprintf(out, pfEQ); break;
					case IMPLICA:
						eval(p->SUB(0));
						fprintf(out, pfNOT);
						eval(p->SUB(1));
						fprintf(out, pfOR);
						break;

					default:
						printf("WTF? Unknown %d ('%c') !\n", p->attrib, p->attrib);
				}
			}
	}
}
示例#25
0
/*----------------------------------------------------------------------
|       main
+---------------------------------------------------------------------*/
int
main(int /*argc*/, char** /*argv*/)
{
    NPT_Result result;


    NPT_String t = "hello";
    NPT_String base64;
    NPT_DataBuffer data;
    result = NPT_Base64::Encode((const NPT_Byte*)t.GetChars(), t.GetLength(), base64);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(base64 == "aGVsbG8=");
    result = NPT_Base64::Decode(base64.GetChars(), base64.GetLength(), data);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(data.GetDataSize() == t.GetLength());
    NPT_String tt((const char*)data.GetData(), data.GetDataSize());
    NPT_ASSERT(tt == t);

    t = "hello!";
    result = NPT_Base64::Encode((const NPT_Byte*)t.GetChars(), t.GetLength(), base64);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(base64 == "aGVsbG8h");
    result = NPT_Base64::Decode(base64.GetChars(), base64.GetLength(), data);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(data.GetDataSize() == t.GetLength());
    tt.Assign((const char*)data.GetData(), data.GetDataSize());
    NPT_ASSERT(tt == t);

    t = "hello!!";
    result = NPT_Base64::Encode((const NPT_Byte*)t.GetChars(), t.GetLength(), base64);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(base64 == "aGVsbG8hIQ==");
    result = NPT_Base64::Decode(base64.GetChars(), base64.GetLength(), data);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(data.GetDataSize() == t.GetLength());
    tt.Assign((const char*)data.GetData(), data.GetDataSize());
    NPT_ASSERT(tt == t);
    
    unsigned char r256_bin[] = {
        0x7d, 0x5f, 0xd0, 0xf4, 0x6a, 0xa8, 0xae, 0x34, 0x6e, 0x32, 0x1d, 0xa1,
        0xef, 0x66, 0xdd, 0x82, 0x76, 0xa6, 0xfd, 0x8c, 0x75, 0x97, 0xa0, 0x01,
        0x00, 0xde, 0x52, 0xef, 0xdf, 0xb6, 0x3e, 0xe4, 0x7b, 0x45, 0xdd, 0x2b,
        0xa1, 0x9c, 0xb0, 0x6d, 0x2c, 0x75, 0xb1, 0x87, 0x43, 0x0f, 0xea, 0x24,
        0x36, 0x11, 0x7e, 0xee, 0xd1, 0x91, 0x7f, 0x7b, 0x02, 0xea, 0x9a, 0x2a,
        0x25, 0xc0, 0xac, 0x99, 0xa4, 0x89, 0x55, 0x5b, 0x82, 0xdf, 0xb0, 0x7e,
        0xa1, 0x78, 0x0f, 0xdf, 0x25, 0x5f, 0x3d, 0xba, 0xcb, 0xbc, 0x35, 0x04,
        0xc3, 0xf4, 0xb8, 0xc0, 0x17, 0x8e, 0x75, 0x01, 0xe6, 0x2f, 0x88, 0x2c,
        0x76, 0x0a, 0x8c, 0x3f, 0x83, 0xd4, 0x10, 0xa8, 0x00, 0xfc, 0xa0, 0x92,
        0x7b, 0xae, 0xa3, 0x8c, 0x47, 0xea, 0x25, 0xf9, 0x29, 0x81, 0x1c, 0x21,
        0xf2, 0xf4, 0xfe, 0x07, 0x7e, 0x4b, 0x01, 0x79, 0x41, 0x3a, 0xb6, 0x71,
        0x0b, 0x75, 0xa7, 0x9d, 0x1b, 0x12, 0xc4, 0x46, 0x06, 0xf3, 0x5f, 0x00,
        0x05, 0x2a, 0x1b, 0x34, 0xd6, 0x87, 0xc4, 0x70, 0xcc, 0xc3, 0x9e, 0xa8,
        0x24, 0x2c, 0x97, 0x4e, 0xfc, 0x91, 0x70, 0x1c, 0x29, 0x66, 0xc3, 0x23,
        0xbf, 0xd7, 0x4d, 0x35, 0x51, 0xff, 0xeb, 0xde, 0x45, 0xbd, 0x8d, 0x80,
        0x44, 0x2a, 0x8d, 0xc0, 0xe8, 0x6a, 0xe2, 0x86, 0x46, 0x9f, 0xf2, 0x3c,
        0x93, 0x0d, 0x27, 0x02, 0xe4, 0x79, 0xa1, 0x21, 0xf4, 0x43, 0xcd, 0x4c,
        0x22, 0x25, 0x9e, 0x93, 0xeb, 0x77, 0x8e, 0x1e, 0x57, 0x1e, 0x9b, 0xcb,
        0x91, 0x86, 0xcf, 0x15, 0xaf, 0xd5, 0x03, 0x0f, 0x70, 0xbe, 0x6e, 0x37,
        0xea, 0x37, 0xdd, 0xf6, 0xa1, 0xb1, 0xf7, 0x05, 0xbc, 0x2d, 0x44, 0x60,
        0x35, 0xa4, 0x05, 0x0b, 0x22, 0x7d, 0x7a, 0x71, 0xe5, 0x1d, 0x8e, 0xcb,
        0xc3, 0xb8, 0x3a, 0xe1
    };
    NPT_String b64;
    NPT_Base64::Encode(r256_bin, sizeof(r256_bin), b64);
    NPT_DataBuffer r256_out;
    NPT_Base64::Decode(b64.GetChars(), b64.GetLength(), r256_out);
    NPT_ASSERT(r256_out.GetDataSize() == sizeof(r256_bin));
    NPT_ASSERT(r256_bin[sizeof(r256_bin)-1] == r256_out.GetData()[sizeof(r256_bin)-1]);

    unsigned char random_bytes[] = {
        0xc7, 0xee, 0x49, 0x9e, 0x2c, 0x8b, 0x1c, 0x16, 0x9e, 0x7f, 0x30, 0xd0,
        0xc6, 0x12, 0x30, 0x80, 0x81, 0xcd, 0x20, 0x20, 0x26, 0xaf, 0x4f, 0xd6,
        0xfc, 0x86, 0x2e, 0x85, 0xf3, 0x10, 0x38, 0x2b, 0x0e, 0xbb, 0x80, 0x68,
        0xbe, 0xff, 0x1c, 0xdc, 0x72, 0xb5, 0x0d, 0x8f, 0x8e, 0x6c, 0x09, 0x63,
        0xba, 0x21, 0x23, 0xb2, 0x24, 0x17, 0xd3, 0x17, 0x69, 0x44, 0x77, 0x11,
        0x36, 0x6a, 0x6e, 0xf2, 0x44, 0x87, 0xa1, 0xd3, 0xf3, 0x1f, 0x6c, 0x38,
        0x22, 0x4a, 0x44, 0x70, 0x66, 0xef, 0x8c, 0x3a, 0x51, 0xc8, 0xee, 0x85,
        0x00, 0x25, 0x93, 0x10, 0x2e, 0x0b, 0x1b, 0x03, 0x94, 0x47, 0x05, 0x22,
        0xd0, 0xc4, 0xec, 0x2e, 0xcc, 0xbc, 0xbb, 0x67, 0xfd, 0xec, 0x0e, 0xb1,
        0x3f, 0xbc, 0x82, 0xe0, 0xa7, 0x9c, 0xf3, 0xae, 0xbd, 0xb7, 0xab, 0x02,
        0xf1, 0xd9, 0x17, 0x4c, 0x9d, 0xeb, 0xe2, 0x00, 0x1e, 0x19, 0x6e, 0xb3,
        0xfd, 0x7d, 0xea, 0x49, 0x85, 0x43, 0x2f, 0x56, 0x81, 0x89, 0xba, 0x71,
        0x37, 0x10, 0xb5, 0x74, 0xab, 0x90, 0x4d, 0xc4, 0xd1, 0x0d, 0x8d, 0x6f,
        0x01, 0xf5, 0x2c, 0xc9, 0x1a, 0x79, 0xa1, 0x41, 0x71, 0x2b, 0xfb, 0xf3,
        0xd5, 0xe4, 0x2a, 0xf5, 0xad, 0x80, 0x7a, 0x03, 0xff, 0x5f, 0x45, 0x8c,
        0xec, 0x6a, 0x4b, 0x05, 0xe3, 0x65, 0x19, 0x70, 0x05, 0xad, 0xc4, 0xb8,
        0x4e, 0x9e, 0x9a, 0x36, 0x4a, 0x86, 0x9d, 0xf5, 0x99, 0xcb, 0x00, 0xb8,
        0xb9, 0xa7, 0x86, 0x18, 0xfc, 0x9a, 0xe7, 0x00, 0x6a, 0x67, 0xfa, 0x42,
        0x9d, 0xff, 0x4d, 0x7a, 0xe4, 0xe8, 0x03, 0x88, 0xff, 0x60, 0xe1, 0x8d,
        0x09, 0x5f, 0x6f, 0xde, 0x6b
    };
    NPT_Array<unsigned char> random(random_bytes, NPT_ARRAY_SIZE(random_bytes));

    t = "x+5JniyLHBaefzDQxhIwgIHNICAmr0/W/IYuhfMQOCsOu4Bovv8c3HK1DY+ObAlj\r\n"
        "uiEjsiQX0xdpRHcRNmpu8kSHodPzH2w4IkpEcGbvjDpRyO6FACWTEC4LGwOURwUi\r\n"
        "0MTsLsy8u2f97A6xP7yC4Kec8669t6sC8dkXTJ3r4gAeGW6z/X3qSYVDL1aBibpx\r\n"
        "NxC1dKuQTcTRDY1vAfUsyRp5oUFxK/vz1eQq9a2AegP/X0WM7GpLBeNlGXAFrcS4\r\n"
        "Tp6aNkqGnfWZywC4uaeGGPya5wBqZ/pCnf9NeuToA4j/YOGNCV9v3ms=";
    result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(data.GetDataSize() == 233);
    NPT_Array<unsigned char> verif(data.GetData(), data.GetDataSize());
    NPT_ASSERT(verif == random);

    result = NPT_Base64::Encode(&random[0], random.GetItemCount(), base64, NPT_BASE64_PEM_BLOCKS_PER_LINE);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(base64 == t);

    NPT_String t_url = t;
    t.Replace('/', '_');
    t.Replace('+', '-');
    result = NPT_Base64::Encode(&random[0], random.GetItemCount(), base64, NPT_BASE64_PEM_BLOCKS_PER_LINE, true);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(base64 == t);
    
    t = "76768484767685839";
    result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
    NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);

    t = "76869=978686";
    result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
    NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);

    t = "7686=8978686";
    result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
    NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);

    t = "7686==978686";
    result = NPT_Base64::Decode(t.GetChars(), t.GetLength(), data);
    NPT_ASSERT(result == NPT_ERROR_INVALID_FORMAT);

    // test IP address parsing
    NPT_IpAddress ip;
    NPT_ASSERT(NPT_FAILED(ip.Parse("")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("a.b.c.d")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4.5")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4.")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.3.4f")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.g.3.4")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.2..3.4")));
    NPT_ASSERT(NPT_FAILED(ip.Parse("1.2.300.4")));
    NPT_ASSERT(NPT_SUCCEEDED(ip.Parse("1.2.3.4")));
    NPT_ASSERT(ip.AsBytes()[0] == 1);
    NPT_ASSERT(ip.AsBytes()[1] == 2);
    NPT_ASSERT(ip.AsBytes()[2] == 3);
    NPT_ASSERT(ip.AsBytes()[3] == 4);
    NPT_ASSERT(NPT_SUCCEEDED(ip.Parse("255.255.0.1")));
    NPT_ASSERT(ip.AsBytes()[0] == 255);
    NPT_ASSERT(ip.AsBytes()[1] == 255);
    NPT_ASSERT(ip.AsBytes()[2] == 0);
    NPT_ASSERT(ip.AsBytes()[3] == 1);
    NPT_ASSERT(NPT_SUCCEEDED(ip.Parse("0.0.0.0")));
    NPT_ASSERT(ip.AsBytes()[0] == 0);
    NPT_ASSERT(ip.AsBytes()[1] == 0);
    NPT_ASSERT(ip.AsBytes()[2] == 0);
    NPT_ASSERT(ip.AsBytes()[3] == 0);

    // MIME parameter parser
    NPT_Map<NPT_String,NPT_String> params;
    result = NPT_ParseMimeParameters(NULL, params);
    NPT_ASSERT(result == NPT_ERROR_INVALID_PARAMETERS);
    
    result = NPT_ParseMimeParameters("", params);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(params.GetEntryCount() == 0);
        
    result = NPT_ParseMimeParameters("foo=bar", params);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(params.GetEntryCount() == 1);
    NPT_ASSERT(params["foo"] == "bar");
    params.Clear();

    result = NPT_ParseMimeParameters(" foo =bar", params);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(params.GetEntryCount() == 1);
    NPT_ASSERT(params["foo"] == "bar");
    params.Clear();

    result = NPT_ParseMimeParameters(" foo= bar", params);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(params.GetEntryCount() == 1);
    NPT_ASSERT(params["foo"] == "bar");
    params.Clear();
    
    result = NPT_ParseMimeParameters(" foo= bar;", params);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(params.GetEntryCount() == 1);
    NPT_ASSERT(params["foo"] == "bar");
    params.Clear();

    result = NPT_ParseMimeParameters("foo=\"bar\"", params);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(params.GetEntryCount() == 1);
    NPT_ASSERT(params["foo"] == "bar");
    params.Clear();

    result = NPT_ParseMimeParameters("foo=\"ba\"r\"", params);
    NPT_ASSERT(result == NPT_ERROR_INVALID_SYNTAX);
    params.Clear();

    result = NPT_ParseMimeParameters("foo=\"ba\\\"r\"", params);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(params.GetEntryCount() == 1);
    NPT_ASSERT(params["foo"] == "ba\"r");
    params.Clear();

    result = NPT_ParseMimeParameters("foo=\"bar\\\"\"", params);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(params.GetEntryCount() == 1);
    NPT_ASSERT(params["foo"] == "bar\"");
    params.Clear();

    result = NPT_ParseMimeParameters("foo=\"bar\\\\\"", params);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(params.GetEntryCount() == 1);
    NPT_ASSERT(params["foo"] == "bar\\");
    params.Clear();

    result = NPT_ParseMimeParameters("a=1;b=2; c=3; d=4 ; e=\"\\;\"; f=\";\"", params);
    NPT_ASSERT(NPT_SUCCEEDED(result));
    NPT_ASSERT(params.GetEntryCount() == 6);
    NPT_ASSERT(params["a"] == "1");
    NPT_ASSERT(params["b"] == "2");
    NPT_ASSERT(params["c"] == "3");
    NPT_ASSERT(params["d"] == "4");
    NPT_ASSERT(params["e"] == ";");
    NPT_ASSERT(params["f"] == ";");
    params.Clear();

    // number parsing
    float      f;
    int        i;
    NPT_Int32  i32;
    NPT_UInt32 ui32;
    NPT_Int64  i64;
    NPT_UInt64 ui64;

    SHOULD_FAIL(NPT_ParseInteger("ssdfsdf", i, false));
    SHOULD_FAIL(NPT_ParseInteger("", i, false));
    SHOULD_FAIL(NPT_ParseInteger(NULL, i, false));
    SHOULD_FAIL(NPT_ParseInteger("123a", i, false));
    SHOULD_FAIL(NPT_ParseInteger("a123", i, false));
    SHOULD_FAIL(NPT_ParseInteger(" 123", i, false));
    SHOULD_FAIL(NPT_ParseInteger("a 123", i, true));
    SHOULD_FAIL(NPT_ParseInteger(" a123", i, true));

    SHOULD_SUCCEED(NPT_ParseInteger("+1", i, false));
    SHOULD_EQUAL_I(i, 1);
    SHOULD_SUCCEED(NPT_ParseInteger("+123", i, false));
    SHOULD_EQUAL_I(i, 123);
    SHOULD_SUCCEED(NPT_ParseInteger("-1", i, false));
    SHOULD_EQUAL_I(i, -1);
    SHOULD_SUCCEED(NPT_ParseInteger("-123", i, false));
    SHOULD_EQUAL_I(i, -123);
    SHOULD_SUCCEED(NPT_ParseInteger("-123fgs", i, true));
    SHOULD_EQUAL_I(i, -123);
    SHOULD_SUCCEED(NPT_ParseInteger("  -123fgs", i, true));
    SHOULD_EQUAL_I(i, -123);
    SHOULD_SUCCEED(NPT_ParseInteger("0", i, true));
    SHOULD_EQUAL_I(i, 0);
    SHOULD_SUCCEED(NPT_ParseInteger("7768", i, true));
    SHOULD_EQUAL_I(i, 7768);

    SHOULD_SUCCEED(NPT_ParseInteger32("2147483647", i32, false));
    SHOULD_EQUAL_I(i32, 2147483647);
    SHOULD_SUCCEED(NPT_ParseInteger32("-2147483647", i32, false));
    SHOULD_EQUAL_I(i32, -2147483647);
    SHOULD_SUCCEED(NPT_ParseInteger32("-2147483648", i32, false));
    SHOULD_EQUAL_I(i32, (-2147483647 - 1));
    SHOULD_FAIL(NPT_ParseInteger32("2147483648", i32, false));
    SHOULD_FAIL(NPT_ParseInteger32("-2147483649", i32, false));
    SHOULD_FAIL(NPT_ParseInteger32("-21474836480", i32, false));
    SHOULD_FAIL(NPT_ParseInteger32("21474836470", i32, false));

    SHOULD_SUCCEED(NPT_ParseInteger32U("4294967295", ui32, false));
    SHOULD_EQUAL_I(ui32, 4294967295U);
    SHOULD_FAIL(NPT_ParseInteger32U("4294967296", ui32, false));
    SHOULD_FAIL(NPT_ParseInteger32U("-1", ui32, false));

    SHOULD_SUCCEED(NPT_ParseInteger64("9223372036854775807", i64, false));
    SHOULD_EQUAL_I(i64, NPT_INT64_C(9223372036854775807));
    SHOULD_SUCCEED(NPT_ParseInteger64("-9223372036854775807", i64, false));
    SHOULD_EQUAL_I(i64, NPT_INT64_C(-9223372036854775807));
    SHOULD_SUCCEED(NPT_ParseInteger64("-9223372036854775808", i64, false));
    SHOULD_EQUAL_I(i64, (NPT_INT64_C(-9223372036854775807) - NPT_INT64_C(1)));
    SHOULD_FAIL(NPT_ParseInteger64("9223372036854775808", i64, false));
    SHOULD_FAIL(NPT_ParseInteger64("-9223372036854775809", i64, false));
    SHOULD_FAIL(NPT_ParseInteger64("-9223372036854775897", i64, false));
    SHOULD_FAIL(NPT_ParseInteger64("9223372036854775897", i64, false));

    SHOULD_SUCCEED(NPT_ParseInteger64U("18446744073709551615", ui64, false));
    SHOULD_EQUAL_I(ui64, NPT_UINT64_C(18446744073709551615));
    SHOULD_FAIL(NPT_ParseInteger64U("18446744073709551616", ui64, false));
    SHOULD_FAIL(NPT_ParseInteger64U("-1", ui64, false));

    SHOULD_FAIL(NPT_ParseFloat("ssdfsdf", f, false));
    SHOULD_FAIL(NPT_ParseFloat("", f, false));
    SHOULD_FAIL(NPT_ParseFloat(NULL, f, false));
    SHOULD_FAIL(NPT_ParseFloat("123.", f, false));
    SHOULD_FAIL(NPT_ParseFloat("a123", f, false));
    SHOULD_FAIL(NPT_ParseFloat(" 123", f, false));
    SHOULD_FAIL(NPT_ParseFloat(" 127.89E5ff", f, false));

    SHOULD_SUCCEED(NPT_ParseFloat("+1.0", f, false));
    SHOULD_EQUAL_F(f, 1.0f);
    SHOULD_SUCCEED(NPT_ParseFloat("+123", f, false));
    SHOULD_EQUAL_F(f, 123.0f);
    SHOULD_SUCCEED(NPT_ParseFloat("-0.1", f, false));
    SHOULD_EQUAL_F(f, -0.1f);
    SHOULD_SUCCEED(NPT_ParseFloat("0.23e-13", f, false));
    SHOULD_EQUAL_F(f, 0.23e-13f);
    SHOULD_SUCCEED(NPT_ParseFloat(" 127.89E5ff", f, true));
    SHOULD_EQUAL_F(f, 127.89E5f);
    SHOULD_SUCCEED(NPT_ParseFloat("+0.3db", f, true));
    SHOULD_EQUAL_F(f, 0.3f);
    SHOULD_SUCCEED(NPT_ParseFloat("+.3db", f, true));
    SHOULD_EQUAL_F(f, 0.3f);
    SHOULD_SUCCEED(NPT_ParseFloat("-.3db", f, true));
    SHOULD_EQUAL_F(f, -0.3f);
    SHOULD_SUCCEED(NPT_ParseFloat(".3db", f, true));
    SHOULD_EQUAL_F(f, .3f);

    return 0;
}