/* * Intender.c * Intender * * Created by Lucas on 07/12/2006. * Distributed under the GNU General Public Licence * */ #include "CIntendation.h" /* -ed- '>' en trop */ #include "Utilities.h" #include #include #include #define DEBUG 1 #if 0 #define DEBUG_SRC "/Users/lucas/Desktop/mouseHandler.c" #define DEBUG_TITLE "mouseHandler.c" #define DEBUG_DESTINATION "/Users/lucas/Desktop/mouseHandler.c.html" #else #define DEBUG_SRC "main.c" #define DEBUG_TITLE DEBUG_SRC #define DEBUG_DESTINATION DEBUG_SRC ".html" #endif #define TAILLE_MAX 4096 //char *readFromFile(const char *path){ // char *cData = NULL; // FILE* fichier = NULL; // char chaine[4096] = NULL; // // fichier = fopen(path, "r"); // // if (fichier != NULL){ // while (fgets(chaine, TAILLE_MAX, fichier) != NULL){ // cData = strFromStrings(cData, chaine); // } // fclose(fichier); // } else { // return NULL; // } // // return cData; //} // //unsigned char writeToFile(const char *path, const char *data){ // FILE* fichier = NULL; // // fichier = fopen(path, "w"); // // if (fichier != NULL){ // unsigned int lgt = strlen(data); // unsigned int i = 0; // for (i = 0;i < lgt;i++){ // fputc( data[i], fichier); // } // fclose(fichier); // return 1; // } else { // return NULL; // } //} /* -ed- ajoute 'const' */ char const *getSrcPath (void) { #if DEBUG return DEBUG_SRC; #else char path[1000]; printf ("Entrez l'adresse complete du fichier contenant le code a convertir pour le Web :\n->"); if (DEBUG) scanf ("%s", path); printf ("\n"); if (path == NULL) { printf ("Adresse invalide."); free (path); exit (1); } return path; #endif } char const *getTitle (void) { printf ("Creation des en-tetes...\nEntrez le titre a afficher :\n->"); char title[1000]; if (DEBUG) return DEBUG_TITLE; scanf ("%s", title); char *result = title; return result; } char const *getDestinationPath (void) { #if DEBUG return DEBUG_DESTINATION; #else char path[1000]; printf ("Entrez l'adresse complete du fichier ou vous souhaitez enregistrer le code cree :\n->"); scanf ("%s", path); printf ("\n"); /* -ed- comment un tableau pourrait il e^tre NULL ? if (path == NULL) { printf ("Adresse invalide."); exit (1); } */ /* -ed- NON, on a pas le droit de retourner l'adresse d'un tableau local... */ return path; #endif } int main (void) { char *data = NULL; char *cIntended = NULL; printf ("\nBienvenue dans Intender 1.0 Beta\n" "Copyright 2006-2007 Spootnik-Dev (http://spootnikdev.dyndns.org/)\n"); printf ("\nInitialisation de Intender...\n\n"); { char const *cPath = getSrcPath (); data = readFromFile (cPath); if (data != NULL) { printf ("Lecture du fichier %s en cours ...\n", cPath); printf ("%s", data); } else { printf ("Fichier %s introuvable.\n", cPath); return EXIT_FAILURE; } } printf ("Creation du code HTML...\n"); cIntended = intendedHTMLCodeFromString (data); free (data), data = NULL; if (cIntended != NULL) { printf ("Code cree...\n"); printf ("%s", cIntended); } else { printf ("Erreur lors de la creation du code.\n"); return 0; } char *cFinalData = NULL; cFinalData = strFromStrings (cFinalData, ""); char *cTitle = NULL; cTitle = strFromStrings (cTitle, ""); char const *title = getTitle (); /* -ed- pour comparer une chaine, c'est strcmp()... */ if (strcmp (title, "") != 0) cTitle = strFromStrings (cTitle, title); else cTitle = strFromStrings (cTitle, "Titre"); cTitle = strFromStrings (cTitle, "
\n

\n\n
\n");
   cFinalData = strFromStrings (cFinalData, cTitle);
   free (cTitle);
   cFinalData = strFromStrings (cFinalData, cIntended);
   free (cIntended);
   cFinalData = strFromStrings (cFinalData, "
\n
\n\n"); char *cDestination = NULL; printf ("Enregistrement du code...\n"); char const *destPath = getDestinationPath (); cDestination = strFromStrings (cDestination, destPath); printf ("Enregistrement du fichier %s...\n", cDestination); int ok = writeToFile (cDestination, cFinalData); if (!ok) { printf ("Erreur lors de l'enregistrement du fichier.\n"); } else { printf ("Fichier enregistre avec succes.\n"); } return 0; }