00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdlib.h>
00021 #include <stdio.h>
00022 #include <unistd.h>
00023 #include <string.h>
00024
00025 #include "cflow2vcg.h"
00026 #include "write_vcg.h"
00027
00028 #include "cflow_struct.h"
00029 #include "read_sun.h"
00030 #include "read_free.h"
00031
00032 #define NBMAX 512
00033 #define PROFONDEUR 30
00034
00035
00036
00037
00038
00039 #define NOEUD_INT 1
00040 #define NOEUD_EXT 2
00041
00042 typedef enum {
00043 INPUT_SUN,
00044 INPUT_FREE,
00045 INPUT_AUTO
00046 } INPUT_TYPE;
00047
00048 static int niveau_courant = 0;
00049 static int tab_niveaux[PROFONDEUR];
00050
00051 static int *tab_noeud_int;
00052 static int nb_noeud_int;
00053
00054 static int *tab_noeud_ext;
00055 static int nb_noeud_ext;
00056
00058 int classe_inv = CLASS_NULL;
00059
00060
00061 static INPUT_TYPE input_type;
00062
00063 void positionner_niveau(int numlig, int niveau)
00064 {
00065 niveau_courant = niveau - 1;
00066 tab_niveaux[niveau_courant] = numlig;
00067 }
00068
00069 int niveau_pere()
00070 {
00071 if (niveau_courant >= 1)
00072 return tab_niveaux[niveau_courant - 1];
00073 else
00074 return -1;
00075 }
00076
00078 void tab_dyn_ajouter_elem(int nouveau,
00079 int taille_realloc,
00080 int **p_tab,
00081 int *p_nb)
00082 {
00083
00084 if (*p_tab == NULL ||
00085 *p_nb % taille_realloc == 0)
00086 {
00087 *p_tab = realloc(*p_tab, sizeof (int) * (*p_nb + taille_realloc));
00088
00089 if (*p_tab == NULL)
00090 {
00091 (void) fprintf(stderr, "Erreur allocation.\n");
00092 exit(EXIT_FAILURE);
00093 }
00094 }
00095
00096
00097 (*p_tab)[*p_nb] = nouveau;
00098 (*p_nb)++;
00099 }
00100
00102 int int_compare(const void *elem1,
00103 const void *elem2)
00104 {
00105 int cmp;
00106 int entier1, entier2;
00107
00108 entier1 = *(int *) elem1;
00109 entier2 = *(int *) elem2;
00110
00111 if (entier1 == entier2)
00112 cmp = 0;
00113 else if (entier1 > entier2)
00114 cmp = 1;
00115 else
00116 cmp = -1;
00117
00118 return cmp;
00119 }
00120
00121 void *rechercher_parmi_interne(int noeud)
00122 {
00123 return bsearch(&noeud, tab_noeud_int, nb_noeud_int, sizeof(int), int_compare);
00124 }
00125
00126 #define afficher_noeud_int(label,numlig,type,fichier,ligne) \
00127 afficher_noeud((label),(numlig),type,fichier,ligne)
00128 #define afficher_noeud_ext(label,numlig) \
00129 afficher_noeud((label),(numlig),"","",0)
00130
00131 void usage(FILE * out, const char *progname)
00132 {
00133 (void) fprintf(out, "Usage: %s -h\n", progname);
00134 (void) fprintf(out, "Usage: %s -v\n", progname);
00135 (void) fprintf(out,
00136 "Usage: %s [ -i | -e ] [ -f i_format ] < file.cflow\n",
00137 progname);
00138 (void) fprintf(out, "\t-h: this help.\n");
00139 (void) fprintf(out, "\t-v: version information.\n");
00140 (void) fprintf(out,
00141 "\t-i: restrict to internal (defined) functions.\n");
00142 (void) fprintf(out,
00143 "\t-e: restrict to external (used) functions (less usefull).\n");
00144 (void) fprintf(out,
00145 "\t-f i_format: input format. Arg. should be sun or free.\n");
00146 (void) fprintf(out,
00147 "\t by default, it will be automatic as possible.\n");
00148 }
00149
00150 void version (FILE * out)
00151 {
00152
00153 #if (defined(PACKAGE) && defined(VERSION))
00154 (void) fprintf(out, "%s %s\n", PACKAGE, VERSION);
00155 #else
00156 (void) fprintf(out,
00157 "No package-version available (due to generation).\n"
00158 "CVS/RCS informations: $RCSfile: cflow2vcg.c,v $ $Revision: 1.5 $\n");
00159 #endif
00160
00161
00162 (void) fprintf(out,
00163 "Copyright (C) 2001 Guilhem BONNEFILLE\n"
00164 "This program comes with NO WARRANTY.\n"
00165 "You may redistribute copies of it under the terms of the\n"
00166 "GNU General Public License.\n"
00167 "For more information about these matters,\n"
00168 "see the files named COPYING.\n");
00169 }
00170
00171 int scan_line(const char *line, LINE_INFO * line_info)
00172 {
00173 int result = 0;
00174
00175 switch (input_type)
00176 {
00177 case INPUT_SUN:
00178 result = scan_sun(line, line_info);
00179 break;
00180 case INPUT_FREE:
00181 result = scan_free(line, line_info);
00182 break;
00183 case INPUT_AUTO:
00184
00185
00186 if ((result = scan_sun(line, line_info)) == 1)
00187 input_type = INPUT_SUN;
00188 else if ((result = scan_free(line, line_info)) == 1)
00189 input_type = INPUT_FREE;
00190 else
00191 {
00192 (void) fputs("Error: input format not recognized.\n",
00193 stderr);
00194 (void) fputs(" Read interupted.\n", stderr);
00195 exit (EXIT_FAILURE);
00196 }
00197 break;
00198 }
00199 return result;
00200 }
00201
00202 INPUT_TYPE get_input_type(const char *s_type)
00203 {
00204 if (strcmp (s_type, "sun") == 0)
00205 return INPUT_SUN;
00206 else if (strcmp (s_type, "free") == 0)
00207 return INPUT_FREE;
00208 else
00209 return INPUT_AUTO;
00210 }
00211
00212 int main(int argc, char *argv[])
00213 {
00214 int line_number;
00215 char ligne[NBMAX + 1];
00216 LINE_INFO line_info;
00217 int numligpere;
00218 int c;
00219 extern char *optarg;
00220 extern int optind;
00221
00222
00223 input_type = INPUT_AUTO;
00224
00225
00226 while ((c = getopt(argc, argv, "ievhf:")) != EOF)
00227 switch (c)
00228 {
00229 case 'i':
00230 classe_inv = CLASS_EXT;
00231 break;
00232 case 'e':
00233 classe_inv = CLASS_INT;
00234 break;
00235 case 'f':
00236 input_type = get_input_type (optarg);
00237 break;
00238 case 'v':
00239 version(stdout);
00240 return EXIT_SUCCESS;
00241 break;
00242 case 'h':
00243 usage(stdout, argv[0]);
00244 return EXIT_SUCCESS;
00245 break;
00246 case '?':
00247 usage(stderr, argv[0]);
00248 return EXIT_FAILURE;
00249 break;
00250 }
00251
00252 afficher_entete ();
00253
00254
00255 line_number = 0;
00256 while (fgets(ligne, NBMAX, stdin) != NULL)
00257 {
00258 ligne[NBMAX] = '\0';
00259
00260
00261 line_number++;
00262
00263
00264 if (scan_line(ligne, &line_info) == 0)
00265 {
00266 (void) fprintf(stderr, "Syntax error line %d\n",
00267 line_number);
00268 return EXIT_FAILURE;
00269 }
00270
00271 positionner_niveau(line_info.id, line_info.depth);
00272
00273 switch (line_info.type)
00274 {
00275 case EXTERNAL:
00276
00277 tab_dyn_ajouter_elem(line_info.id, NBMAX,
00278 &tab_noeud_ext, &nb_noeud_ext);
00279 afficher_noeud_ext(line_info.fct, line_info.id);
00280 break;
00281 case INTERNAL:
00282
00283 tab_dyn_ajouter_elem(line_info.id, NBMAX,
00284 &tab_noeud_int, &nb_noeud_int);
00285 afficher_noeud_int(line_info.fct, line_info.id,
00286 line_info.fct_type,
00287 line_info.src, line_info.line_src);
00288 break;
00289 }
00290
00291
00292 numligpere = niveau_pere();
00293 if (numligpere != -1)
00294 afficher_arc(numligpere, line_info.id);
00295 }
00296
00297 afficher_pied();
00298
00299 return EXIT_SUCCESS;
00300 }