示例#1
0
文件: whoami.c 项目: osstudy/glidix
int main()
{
	printUser("euid", geteuid());
	printUser("uid", getuid());
	
	int count = getgroups(0, NULL);
	gid_t *groups = (gid_t*) malloc(sizeof(gid_t)*count);
	getgroups(count, groups);
	
	printf("groups: ");
	
	int i;
	for (i=0; i<count; i++)
	{
		gid_t gid = groups[i];
		const char *name = "?";
		
		struct group *grp = getgrgid(gid);
		if (grp != NULL)
		{
			name = grp->gr_name;
		};
		
		printf("%u <%s>", (unsigned int) gid, name);
		if (i != (count-1)) printf(", ");
	};
	printf("\n");
	
	return 0;
};
void EntityManager_Print(FILE *ofp, const char *header, const EntityManager *entityManager) {
  htab *t = NULL;

  if (header != NULL) fprintf(ofp, "%s\n", header); // print the header even for NULL items
  if (entityManager == NULL) {
    snprintf(errStr, sizeof(errStr), "EntityManager_Print: entityManager must not be NULL");
    return;
  }
  t = entityManager->Users->Items;
  if (hfirst(t)) {
    do {
      printUser(ofp, "", (void *)hstuff(t));
    } while (hnext(t));
  }
  t = entityManager->Groups->Items;
  if (hfirst(t)) {
    do {
      printGroup(ofp, "", (void *)hstuff(t));
    } while (hnext(t));
  }
  t = entityManager->Resources->Items;
  if (hfirst(t)) {
    do {
      printResource(ofp, "", (void *)hstuff(t));
    } while (hnext(t));
  }
  fprintf(ofp, "\n");
}
示例#3
0
//User is chosen, value between 1 and 5
void selectUser() {

 userselected = 1;
 int done = 0;
 lcd.clear();

 while(!done) {
  printUser();
  pressed = btnpressed();
  switch (pressed) {
  case UP :
  if(userselected > 1) userselected--;
  break;
  case DOWN :
  if(userselected < 5) userselected++;
  break;
  case SELECT :
  done = 1;
  break;

  }
  delay(500);
 }


}
// Print user information include its properties
STATIC void fullPrintUser(FILE *ofp, const char *header, const void *u) {
  const userData *entity = NULL;

  printUser(ofp, header, u);
  if (u == NULL) return;
  entity = (const userData *)u;
  printProperties(ofp, entity->PropertiesData);
}
void printUserList( User * userList, int numUsers )
{
	int i;
	for( i = 0; i < numUsers; i++ )
	{
		printUser( &userList[i] );
	}
}
/** \brief Menu de funciones para informar datos en pantalla.
    1= Mostrar cantidad de usuarios
    2= Mostrar a los usuarios
    3= Mostrar usuarios y sus comentarios
    4= Cosas nuevas de la sesion
    5= los primeros usuarios dados de alta
 * \param usuarios: arraylist donde se guardan los usuarios
 * \param comentarios: arraylist donde se guardan los comentarios
 * \param usuariosOriginales: arraylist donde se guardan los usuarios que se tenian al iniciar el programa
 * \param comentariosOriginales: arraylist donde se guardan los comentarios que se tenian al iniciar el programa
 */
int informar(ArrayList *usuarios,ArrayList *usuariosOriginales,ArrayList *comentarios,ArrayList *comentariosOriginales)
{
    int i,j, opcion;
    EComments* comment;
    EComments *commentAux;
    User *usuario;
    User *userAux;
    int usuariosAMostrar=5;
    ArrayList* pArray;

    opcion=imprimirMenu("1- Mostrar cantidad de usuarios\n2- Mostrar a los usuarios\n3- Mostrar usuarios y sus comentarios\n4- Cosas nuevas de la sesion\n5- los primeros usuarios dados de alta\n");
    fflush(stdin);
    printf("\n-------------------------------------------\n");
    switch(opcion)
    {
    case 1:
        if(usuarios->isEmpty(usuarios)==1)
            printf("No hay usuarios dados de alta!\n\n");
        if(usuarios->isEmpty(usuarios)==0)
            printf("Existen %d usuarios dados de alta.\n\n",usuarios->len(usuarios));
        break;
    case 2:
        for(i=0; i<usuarios->size; i++)
        {
            printUser(usuarios->get(usuarios,i));
        }
        printf("\n");
        break;
    case 3:
        for(i=0; i<usuarios->size; i++)
        {
            usuario= usuarios->get(usuarios,i);
            printUser(usuarios->get(usuarios,i));

            for(j=0; j<comentarios->size; j++)
            {
                comment = (comentarios->get(comentarios,j));
                if(usuario->id == comment->idComentador)
                {
                    printf("Indice: %d. Comentario: %s Nick:%s Cantidad de likes:%d\r\n\n",comentarios->indexOf(comentarios,*(comentarios->pElements+j)),comment->comments,usuario->name,comment->likes);
                }
            }
        }
        printf("\n");

        break;

        {
        case 4:
            if((al_containsAll(usuarios, usuariosOriginales)) && (al_containsAll(comentarios, comentariosOriginales)) && usuarios->size == usuariosOriginales->size && comentarios->size == comentariosOriginales->size)
            {
                printf("No se realizaron modificaciones en la sesion actual.\n\n");
            }
            else
            {
                for(i=0; i<usuarios->size; i++)
                {
                    userAux=usuarios->get(usuarios,i);
                    if(usuarios->contains(usuariosOriginales,userAux)==0)
                    {
                        printf("\n-----NUEVOS USUARIOS-----\nNombre= %s\nNick= %s\n",userAux->name, userAux->nick);
                    }
                }
                for(i=0; i<comentarios->size; i++)
                {
                    commentAux=comentarios->get(comentarios,i);
                    if(comentarios->contains(comentariosOriginales,commentAux)==0)
                    {
                        printf("\n-----NUEVOS COMENTARIOS-----\nCOMENTARIO= %s\nLikes= %d\n",commentAux->comments, commentAux->likes);
                    }
                }
            }
            printf("\n");
            break;
        case 5:
            if(usuarios->size < usuariosAMostrar)
                usuariosAMostrar =usuarios->size;

            pArray = usuarios->subList(usuarios,0,usuariosAMostrar);
            printf("Los primeros usuarios fueron:");
            for(i=0; i<usuariosAMostrar; i++)
            {
                userAux=pArray->get(pArray,i);
                printf("\n%d = %s (Nick= %s)",i+1,userAux->name,userAux->nick);
            }
            printf("\n\n\n");

            break;
        default:
            printf("No existe esa opcion... Reintente\n\n");
            system("pause");
            system("cls");
            break;
        }
    }
    return 0;
}
示例#7
0
int User(UserNodePtr User,HashTablePtr H){
	int choice;
    int id;
    char name[NameSize];
    LinkNodePtr MFriend,TFriend;
    printf("***********************************\n"
           "*      Enter your choice          *\n"
           "*      1 to view yourself         *\n"
           "*      2 to add a friend          *\n"
           "*      3 to delete a friend       *\n"
           "*      4 to follow somebody       *\n"
           "*      5 to cancel follow         *\n"
           "*      6 to find mutual friend    *\n"
           "*      7 to find twice friend     *\n"
           "*      8 to view somebody         *\n"
           "*      9 to end                   *\n"
           "***********************************\n");
    printf("your choice:\n");
    if(!scanf("%d",&choice)){
        printf("input error!!!\n");
        exit(1);
    }

    while(choice != 9){
        switch(choice){
            case 1:
                printUser(User,H);
                break;
            case 2:
                printf("***********************************\n"
                       "*      Enter your choice          *\n"
                       "*      1 by id                    *\n"
                       "*      2 by name                  *\n"
                       "***********************************\n");
                printf("your choice:\n");
                if(!scanf("%d",&choice)){
                    printf("input error!!!\n");
                    choice = 0;
                }
                switch(choice){
                    case 1:
                        printf("input your friend's id:\n");
                        scanf("%d",&id);
                        if(FindId(id,H) != NULL) {
                            InsertFriends(User->Name, FindId(id, H)->Name, NameSize, H);
                        }else{
                            printf("Can't find!!!\n");
                        }
                        Write(H);
                        break;
                    case 2:
                        printf("input your firend's name:\n");
                        getchar();
                        scanf("%[^\n]",name);
                        if(Find(name,NameSize,H) != NULL) {
                            InsertFriends(User->Name, name, NameSize, H);
                        }else{
                            printf("Can't find!!!\n");
                        }
                        Write(H);
                        break;
                    default:
                        printf("Invalid choice!!!\n");
                        break;
                }
                break;
            case 3:
                printf("***********************************\n"
                       "*      Enter your choice          *\n"
                       "*      1 by id                    *\n"
                       "*      2 by name                  *\n"
                       "***********************************\n");
                printf("your choice:\n");
                if(!scanf("%d",&choice)){
                    printf("input error!!!\n");
                    choice = 0;
                }
                switch(choice){
                    case 1:
                        printf("input your friend's id:\n");
                        scanf("%d",&id);
                        if(FindId(id,H) != NULL) {
                            DeleteFriends(User->Name, FindId(id, H)->Name, NameSize, H);
                        }else{
                            printf("Can't find!!!\n");
                        }
                        Write(H);
                        break;
                    case 2:
                        printf("input your firend's name:\n");
                        getchar();
                        scanf("%[^\n]",name);
                        if(Find(name,NameSize,H) != NULL) {
                            DeleteFriends(User->Name, name, NameSize, H);
                        }else{
                            printf("Can't find!!!\n");
                        }
                        Write(H);
                        break;
                    default:
                        printf("Invalid choice!!!\n");
                        break;
                }
                break;
            case 4:
                printf("***********************************\n"
                       "*      Enter your choice          *\n"
                       "*      1 by id                    *\n"
                       "*      2 by name                  *\n"
                       "***********************************\n");
                printf("your choice:\n");
                if(!scanf("%d",&choice)){
                    printf("input error!!!\n");
                    choice = 0;
                }
                switch(choice){
                    case 1:
                        printf("input your follow's id:\n");
                        scanf("%d",&id);
                        if(FindId(id,H) != NULL) {
                            InsertFollows(User->Name, FindId(id, H)->Name, NameSize, H);
                        }else{
                            printf("Can't find!!!\n");
                        }
                        Write(H);
                        break;
                    case 2:
                        printf("input your follow's name:\n");
                        getchar();
                        scanf("%[^\n]",name);
                        if(Find(name,NameSize,H) != NULL) {
                            InsertFollows(User->Name, name, NameSize, H);
                        }else{
                            printf("Can't find!!!\n");
                        }
                        Write(H);
                        break;
                    default:
                        printf("Invalid choice!!!\n");
                        break;
                }
                break;
            case 5:
                printf("***********************************\n"
                       "*      Enter your choice          *\n"
                       "*      1 by id                    *\n"
                       "*      2 by name                  *\n"
                       "***********************************\n");
                printf("your choice:\n");
                if(!scanf("%d",&choice)){
                    printf("input error!!!\n");
                    choice = 0;
                }
                switch(choice){
                    case 1:
                        printf("input your follow's id:\n");
                        scanf("%d",&id);
                        if(FindId(id,H) != NULL) {
                            DeleteFollows(User->Name, FindId(id, H)->Name, NameSize, H);
                        }else{
                            printf("Can't find!!!\n");
                        }
                        Write(H);
                        break;
                    case 2:
                        printf("input your follow's name:\n");
                        getchar();
                        scanf("%[^\n]",name);
                        if(Find(name,NameSize,H) != NULL) {
                            DeleteFollows(User->Name, name, NameSize, H);
                        }else{
                            printf("Can't find!!!\n");
                        }
                        Write(H);
                        break;
                    default:
                        printf("Invalid choice!!!\n");
                        break;
                }
                break;
            case 6:
                printf("input a name:\n");
                getchar();
                scanf("%[^\n]",name);
                if(Find(name,NameSize,H) != NULL){
                    MFriend = Intersection(User->Name,name,NameSize,H);
                    printList(MFriend,H);
                }else{
                    printf("Can't find!!!\n");
                }
                break;
            case 7:
                printf("input a name:\n");
                getchar();
                scanf("%[^\n]",name);
                if(Find(name,NameSize,H) != NULL){
                    TFriend = Twice(User->Name,name,NameSize,H);
                    printList(TFriend,H);
                }else{
                    printf("Can't find!!!\n");
                }
                break;
            case 8:
                printf("***********************************\n"
                       "*    Please input your choice     *\n"
                       "*          1  friends             *\n"
                       "*          2  follows             *\n"
                       "*          3  fans                *\n"
                       "***********************************\n");
                printf("your choice:\n");
                scanf("%d",&choice);
                switch (choice){
                    case 1:
                        printFriend(User,H);
                        break;
                    case 2:
                        printFollow(User,H);
                        break;
                    case 3:
                        printFan(User,H);
                        break;
                }
                break;
            default:
                printf("Invalid choice!!!\n");
                break;
        }
        printf("***********************************\n"
               "*      Enter your choice          *\n"
               "*      1 to view yourself         *\n"
               "*      2 to add a friend          *\n"
               "*      3 to delete a friend       *\n"
               "*      4 to follow somebody       *\n"
               "*      5 to cancel follow         *\n"
               "*      6 to find mutual           *\n"
               "*      7 to find twice            *\n"
               "*      8 to view somebody         *\n"
               "*      9 to end                   *\n"
               "***********************************\n");
        printf("your choice:\n");
        if(!scanf("%d",&choice)){
            printf("input error!!!\n");
            exit(1);
        }
    }
}