Accueil > > > PETITE CONSOL
PETITE CONSOL
Information sur la source
Description
Salut ! Je debute dans le C et pour m'apprendre a gérré toute sorte de fonctions, j'ai créé une petite consol, un espece de MS-DOS en beacoups plus petit car elle ne contient que 4 fonction ^^
Source
- EXPLORER.C :
- ¯¯¯¯¯¯¯¯¯¯
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #include <unistd.h>
- #include "dir.h"
-
- int main(int argc, char *argv[])
- {
- char tmp[30],tmp2[20];
- char d2[200] = "c:/";
- printf("Tapez \"help\" pour connaitre la liste des fonctions disponibles\n");
- while(1)
- {
- printf("%s",d2);
- gets(tmp);
-
- if(tmp[0] == 'd' && tmp[1] == 'i' && tmp[2] == 'r')
- {
- dir(&d2[0],tmp);
- } else if(tmp[0] == 'c' && tmp[1] == 'd')
- {
- cd(&d2[0],tmp);
- } else if(!strcmp(tmp, "exit"))
- {
- exit(0);
- } else if(tmp[0] == 's' && tmp[1] == 'e' && tmp[2] == 'a' && tmp[3] == 'r'&& tmp[4] == 'c'&& tmp[5] == 'h')
- {
- search(&d2[0],tmp);
- } else if(tmp[0] == 'h' && tmp[1] == 'e' && tmp[2] == 'l' && tmp[3] == 'p')
- {
- help(&d2[0],tmp);
- }else
- {
- printf("\nCette commande n'existe pas\n");
- }
-
- }
- return 0;
- }
-
-
-
-
- DIR.H :
- ¯¯¯¯¯
- #include "cmp.h"
-
- help(char *d2, char tmpcd[30])
- {
- char *tmpcd2;
- tmpcd2 = strchr(tmpcd,' ');
- if (tmpcd2 == NULL)
- {
- tmpcd2 = "rien";
- }
- else
- {
- *tmpcd2++ = 0;
- }
-
- if(!strcmp(tmpcd2, "rien"))
- printf("Liste des fonctions disponibles :\n- cd\n- dir\n- search\n- exit\nPour en savoir plus sur une de ces fonctions : \"help <nom_de_la_fonction>\"\n");
- else if(!strcmp(tmpcd2, "cd"))
- printf("Fonction cd : \"cd <nom_du_dossier>\" ex : 'cd program files'\n");
- else if(!strcmp(tmpcd2, "dir"))
- printf("Fonction dir : \"dir\" ou \"dir <Filtre>\" ex : 'dir' ou 'dir *.exe'\n");
- else if(!strcmp(tmpcd2, "search"))
- printf("Fonction search : \"search <Filtre>\" ex : 'search *.exe'\n");
- else if(!strcmp(tmpcd2, "exit"))
- printf("Fonction exit : \"exit\" ex : 'exit'\n");
- }
-
- scan()
- {
- WIN32_FIND_DATA File;
- HANDLE liste;
- liste = FindFirstFile("*.*", &File);
- do
- {
- if(File.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // ==> Repertoire
- {
- printf("<REP>\t%s\n",File.cFileName);
- }
- else // ==> Fichier
- {
- printf("\t%s\t%d,%d Ko\n",
- File.cFileName, // Nom
- (File.nFileSizeHigh*MAXDWORD+File.nFileSizeLow)/1024, //taille
- (File.nFileSizeHigh*MAXDWORD+File.nFileSizeLow)%1024);
- }
- } while((FindNextFile(liste, &File)));
- // FindClose() ferme la recherche
- FindClose(liste);
- printf("\n");
- }
-
-
- void parent(char *d2)
- {
- int a,b;
- a=b=0;
- while(d2[a] != 0)
- {
- if(d2[a] == d2[2] && d2[a+1] != 0)
- {
- b=a;
- }
- a=a+1;
- }
- d2[b+1]=0;
- }
-
- dir(char *d2, char tmpcd[30])
- {
- char *tmpcd2;
- tmpcd2 = strchr(tmpcd,' ');
- if (tmpcd2 == NULL)
- {
- tmpcd2 = "*.*";
- }
- else
- {
- *tmpcd2++ = 0;
- }
-
- SetCurrentDirectory (d2);
- WIN32_FIND_DATA File;
- HANDLE liste;
- liste = FindFirstFile(tmpcd2, &File);
- do
- {
- if(File.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // ==> Repertoire
- {
- printf("<REP>\t%s\n",File.cFileName);
- }
- else // ==> Fichier
- {
- printf("\t%s\t%d,%d Ko\n",
- File.cFileName, // Nom
- (File.nFileSizeHigh*MAXDWORD+File.nFileSizeLow)/1024, //taille
- (File.nFileSizeHigh*MAXDWORD+File.nFileSizeLow)%1024);
- }
- } while((FindNextFile(liste, &File)));
- // FindClose() ferme la recherche
- FindClose(liste);
- printf("\n");
- }
-
- cd(char *d2, char tmpcd[30])
- {
- char *tmpcd2;
- tmpcd2 = strchr(tmpcd,' ');
- if (tmpcd2 == NULL)
- {
- printf("\nCette commande n'existe pas\n");
- return(0);
- }
- *tmpcd2++ = 0;
- strcat(d2, tmpcd2);
- strcat(d2, "/");
- if ((SetCurrentDirectory (d2)) == 1 && strcmp(tmpcd2, "."))
- {
- if (!strcmp(tmpcd2, ".."))
- {
- parent(&d2[0]);
- parent(&d2[0]);
- }
- }
- else
- {
- printf("Le dossier %s n'existe pas.\n", tmpcd2);
- parent(&d2[0]);
- }
- }
-
- search(char *d2, char tmpcd[30])
- {
- char d3[2000][1000];
- char *tmpcd2;
- int i,j,y;
- tmpcd2 = strchr(tmpcd,' ');
- if (tmpcd2 == NULL)
- {
- printf("Erreur de syntaxe, \"search <nom>\"\n");
- return(0);
- }
- else
- {
- *tmpcd2++ = 0;
- }
- strcpy(d3[0],d2);
- j=i=y=0;
-
- while(strcmp(d3[0], ""))
- {
- SetCurrentDirectory (d3[j]);
- WIN32_FIND_DATA File;
- HANDLE liste;
- liste = FindFirstFile("*", &File); //tmpcd2 est le fichier a trouvé
- do
- {
- if(File.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // ==> Repertoire
- {
- if(strcmp(File.cFileName, "..") && strcmp(File.cFileName, "."))
- {
- i++;
- //printf("<REP>\t%s\n",File.cFileName);
- strcat(d3[i], d3[0]);
- strcat(d3[i], File.cFileName);
- strcat(d3[i], "/");
- if(cmp(File.cFileName, tmpcd2)==0)
- {
- y++;
- printf("%s%s/\n",d3[0],File.cFileName);
- }
- }
-
- }
- else if(cmp(File.cFileName, tmpcd2)==0) // ==> Fichier
- {
- printf("%s%s\n",d3[0],File.cFileName);
- y++;
- }
- }while((FindNextFile(liste, &File)));
- FindClose(liste);
-
- while(strcmp(d3[j], ""))
- {
- strcpy(d3[j],d3[j+1]);
- j++;
- }
- j=0;
- i--;
- }
-
- printf("%d fichier(s) trouvé\n",y);
- printf("\n");
- }
-
-
-
- CMP.H :
- ¯¯¯¯¯
- int cmp(char a[],char b[])
- {
- int i,j;
- j = 0;
- char *y, *c;
-
- for (i=0;i<strlen(a);i++)
- {
- if (a[i] > 64 && a[i] < 91)
- a[i] = a[i] + 32;
- }
- for (i=0;i<strlen(b);i++)
- {
- if (b[i] > 64 && b[i] < 91)
- b[i] = b[i] + 32;
- }
-
- for (i=0;i<strlen(b);i++)
- {
- if (b[i] == '*')
- {
- if (b[i+1]!=0)
- {
- if ((c = strchr(&b[i+1],'*')) == NULL)
- {
- if (!strcmp(&a[strlen(a)-strlen(&b[i+1])],&b[i+1]))
- return(0);
- else
- return(3);
- }
- } else
- {
- return(0);
- }
-
- *c = 0;
- if( (y = strpbrk(&a[j], &b[i+1])) == NULL )
- return(1);
- printf("\t%i",y);
- j=y-a+strlen(&b[i+1]);
- i=i+strlen(&b[i+1]);
- y=NULL;
- if (c != NULL)
- *c = '*';
- } else
- {
- if ((c = strchr(&b[i+1],'*')) == NULL)
- {
- if(!strcmp(a,b))
- return(0);
- else
- return(22);
- }
- if(a[j] != b[i])
- return(2);
- j++;
- }
- }
- return(0);
- }
EXPLORER.C :
¯¯¯¯¯¯¯¯¯¯
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <unistd.h>
#include "dir.h"
int main(int argc, char *argv[])
{
char tmp[30],tmp2[20];
char d2[200] = "c:/";
printf("Tapez \"help\" pour connaitre la liste des fonctions disponibles\n");
while(1)
{
printf("%s",d2);
gets(tmp);
if(tmp[0] == 'd' && tmp[1] == 'i' && tmp[2] == 'r')
{
dir(&d2[0],tmp);
} else if(tmp[0] == 'c' && tmp[1] == 'd')
{
cd(&d2[0],tmp);
} else if(!strcmp(tmp, "exit"))
{
exit(0);
} else if(tmp[0] == 's' && tmp[1] == 'e' && tmp[2] == 'a' && tmp[3] == 'r'&& tmp[4] == 'c'&& tmp[5] == 'h')
{
search(&d2[0],tmp);
} else if(tmp[0] == 'h' && tmp[1] == 'e' && tmp[2] == 'l' && tmp[3] == 'p')
{
help(&d2[0],tmp);
}else
{
printf("\nCette commande n'existe pas\n");
}
}
return 0;
}
DIR.H :
¯¯¯¯¯
#include "cmp.h"
help(char *d2, char tmpcd[30])
{
char *tmpcd2;
tmpcd2 = strchr(tmpcd,' ');
if (tmpcd2 == NULL)
{
tmpcd2 = "rien";
}
else
{
*tmpcd2++ = 0;
}
if(!strcmp(tmpcd2, "rien"))
printf("Liste des fonctions disponibles :\n- cd\n- dir\n- search\n- exit\nPour en savoir plus sur une de ces fonctions : \"help <nom_de_la_fonction>\"\n");
else if(!strcmp(tmpcd2, "cd"))
printf("Fonction cd : \"cd <nom_du_dossier>\" ex : 'cd program files'\n");
else if(!strcmp(tmpcd2, "dir"))
printf("Fonction dir : \"dir\" ou \"dir <Filtre>\" ex : 'dir' ou 'dir *.exe'\n");
else if(!strcmp(tmpcd2, "search"))
printf("Fonction search : \"search <Filtre>\" ex : 'search *.exe'\n");
else if(!strcmp(tmpcd2, "exit"))
printf("Fonction exit : \"exit\" ex : 'exit'\n");
}
scan()
{
WIN32_FIND_DATA File;
HANDLE liste;
liste = FindFirstFile("*.*", &File);
do
{
if(File.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // ==> Repertoire
{
printf("<REP>\t%s\n",File.cFileName);
}
else // ==> Fichier
{
printf("\t%s\t%d,%d Ko\n",
File.cFileName, // Nom
(File.nFileSizeHigh*MAXDWORD+File.nFileSizeLow)/1024, //taille
(File.nFileSizeHigh*MAXDWORD+File.nFileSizeLow)%1024);
}
} while((FindNextFile(liste, &File)));
// FindClose() ferme la recherche
FindClose(liste);
printf("\n");
}
void parent(char *d2)
{
int a,b;
a=b=0;
while(d2[a] != 0)
{
if(d2[a] == d2[2] && d2[a+1] != 0)
{
b=a;
}
a=a+1;
}
d2[b+1]=0;
}
dir(char *d2, char tmpcd[30])
{
char *tmpcd2;
tmpcd2 = strchr(tmpcd,' ');
if (tmpcd2 == NULL)
{
tmpcd2 = "*.*";
}
else
{
*tmpcd2++ = 0;
}
SetCurrentDirectory (d2);
WIN32_FIND_DATA File;
HANDLE liste;
liste = FindFirstFile(tmpcd2, &File);
do
{
if(File.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // ==> Repertoire
{
printf("<REP>\t%s\n",File.cFileName);
}
else // ==> Fichier
{
printf("\t%s\t%d,%d Ko\n",
File.cFileName, // Nom
(File.nFileSizeHigh*MAXDWORD+File.nFileSizeLow)/1024, //taille
(File.nFileSizeHigh*MAXDWORD+File.nFileSizeLow)%1024);
}
} while((FindNextFile(liste, &File)));
// FindClose() ferme la recherche
FindClose(liste);
printf("\n");
}
cd(char *d2, char tmpcd[30])
{
char *tmpcd2;
tmpcd2 = strchr(tmpcd,' ');
if (tmpcd2 == NULL)
{
printf("\nCette commande n'existe pas\n");
return(0);
}
*tmpcd2++ = 0;
strcat(d2, tmpcd2);
strcat(d2, "/");
if ((SetCurrentDirectory (d2)) == 1 && strcmp(tmpcd2, "."))
{
if (!strcmp(tmpcd2, ".."))
{
parent(&d2[0]);
parent(&d2[0]);
}
}
else
{
printf("Le dossier %s n'existe pas.\n", tmpcd2);
parent(&d2[0]);
}
}
search(char *d2, char tmpcd[30])
{
char d3[2000][1000];
char *tmpcd2;
int i,j,y;
tmpcd2 = strchr(tmpcd,' ');
if (tmpcd2 == NULL)
{
printf("Erreur de syntaxe, \"search <nom>\"\n");
return(0);
}
else
{
*tmpcd2++ = 0;
}
strcpy(d3[0],d2);
j=i=y=0;
while(strcmp(d3[0], ""))
{
SetCurrentDirectory (d3[j]);
WIN32_FIND_DATA File;
HANDLE liste;
liste = FindFirstFile("*", &File); //tmpcd2 est le fichier a trouvé
do
{
if(File.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // ==> Repertoire
{
if(strcmp(File.cFileName, "..") && strcmp(File.cFileName, "."))
{
i++;
//printf("<REP>\t%s\n",File.cFileName);
strcat(d3[i], d3[0]);
strcat(d3[i], File.cFileName);
strcat(d3[i], "/");
if(cmp(File.cFileName, tmpcd2)==0)
{
y++;
printf("%s%s/\n",d3[0],File.cFileName);
}
}
}
else if(cmp(File.cFileName, tmpcd2)==0) // ==> Fichier
{
printf("%s%s\n",d3[0],File.cFileName);
y++;
}
}while((FindNextFile(liste, &File)));
FindClose(liste);
while(strcmp(d3[j], ""))
{
strcpy(d3[j],d3[j+1]);
j++;
}
j=0;
i--;
}
printf("%d fichier(s) trouvé\n",y);
printf("\n");
}
CMP.H :
¯¯¯¯¯
int cmp(char a[],char b[])
{
int i,j;
j = 0;
char *y, *c;
for (i=0;i<strlen(a);i++)
{
if (a[i] > 64 && a[i] < 91)
a[i] = a[i] + 32;
}
for (i=0;i<strlen(b);i++)
{
if (b[i] > 64 && b[i] < 91)
b[i] = b[i] + 32;
}
for (i=0;i<strlen(b);i++)
{
if (b[i] == '*')
{
if (b[i+1]!=0)
{
if ((c = strchr(&b[i+1],'*')) == NULL)
{
if (!strcmp(&a[strlen(a)-strlen(&b[i+1])],&b[i+1]))
return(0);
else
return(3);
}
} else
{
return(0);
}
*c = 0;
if( (y = strpbrk(&a[j], &b[i+1])) == NULL )
return(1);
printf("\t%i",y);
j=y-a+strlen(&b[i+1]);
i=i+strlen(&b[i+1]);
y=NULL;
if (c != NULL)
*c = '*';
} else
{
if ((c = strchr(&b[i+1],'*')) == NULL)
{
if(!strcmp(a,b))
return(0);
else
return(22);
}
if(a[j] != b[i])
return(2);
j++;
}
}
return(0);
}
Conclusion
J'attend avec impatience vos reactions ;)
Ps : Si l'un de vous sais comment ajouté une fonction pour se connecter a des FTP et pouvoir naviger sur les FTP comme je le fait ici dans le disque dur local, qu'il n'esite pas
Merci
Historique
- 09 août 2004 00:38:02 :
- update
- 09 août 2004 16:26:18 :
- - remplacement de scan.h et cmp.h par scan.c et cmp.c
- insertion d'un type de retour pour toute les fonctions
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
MATRICE TEMPLATEMATRICE TEMPLATE par hjr2610
Cliquez pour lire la suite par hjr2610 RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|