#define _POSIX_C_SOURCE 1 #include #include #include #include #include "chaine.h" extern char **environ; static char filtre(char c) { if (islower(c)) return toupper(c); return c; } int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s «motif»\n", argv[0]); exit(EXIT_FAILURE); } char *motif = chaine_dup(argv[1]); char *motif_majuscule = chaine_fdup(motif, filtre); for (char **p = environ; *p != NULL; p++) { char *variable = chaine_dup(*p); char *valeur = strchr(variable, '='); char *valeur_majuscule; *valeur++ = '\0'; valeur_majuscule = chaine_fdup(valeur, filtre); if (strstr(valeur_majuscule, motif_majuscule) != NULL) printf("%s = %s\n", variable, valeur); free(valeur_majuscule); free(variable); } return EXIT_SUCCESS; }