1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#if defined (WIN32)
# include <windows.h>
# define TO_CONSOLE__(dest, src, size) \
CharToOemBuff((src), (dest), (size))
#else
# include <string.h>
# define TO_CONSOLE__(dest, src, size) \
strncat((dest), (src), (size) - 1)
#endif
char *to_console(char *dest, char const *src, size_t size)
{
char *p_ret = NULL;
if (dest != NULL && src != NULL && size > 1)
{
*dest = 0;
TO_CONSOLE__(dest, src, size);
p_ret = dest;
}
return p_ret;
}
int chemin(char *langue, char *path, FILE *config)
{
char c, lang[3], tampon[60];
int i;
if(config == NULL)
{
to_console(tampon, "\nErreur: le fichier config.spell est introuvable\n", sizeof tampon);
puts(tampon);
return 1;
}
while(fgetc(config) != EOF)
{
fseek(config, -1, SEEK_CUR);
i = 0;
while(c != ' ')
{
c = fgetc(config);
lang[i] = c;
i++;
}
lang[2] = '\0';
if(strcmp(lang, langue) == 0)
{
/* Recupération du chemin */
i = 0;
while(c != '\n')
{
c = fgetc(config);
path[i] = c;
i++;
}
path[i-1] = '\0';
return 0;
}
while(c != '\n')
c = fgetc(config);
}
to_console(tampon, "\nErreur de lecture du fichier config.spell", sizeof tampon);
puts(tampon);
to_console(tampon, "\nLa langue spécifiée est introuvable", sizeof tampon);
puts(tampon);
to_console(tampon, "\nVerifiez que les chemins d'accès sont corrects\n", sizeof tampon);
puts(tampon);
return 1;
}
int main(int argc, char *argv[])
{
char *path = (char*)malloc(sizeof(char)), tampon[60];
FILE *config;
config = fopen("config.spell", "rb");
if(verification(argc, argv) == 1) /* La fonction là n'est pas présente */
return 1;
if(chemin(argv[2], path, config) == 1)
{
fclose(config);
return 1;
}
to_console(tampon, path, sizeof tampon);
puts(tampon);
fclose(config);
return 0;
}
/* Contenu du fichier config.spell */
fr D:/dev-cpp/projets/L3/Projet/Dictionnaires/french.dict
en D:/dev-cpp/projets/L3/Projet/Dictionnaires/british-english.dict |
Partager