-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargument.c
More file actions
97 lines (88 loc) · 2.78 KB
/
argument.c
File metadata and controls
97 lines (88 loc) · 2.78 KB
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
/*******************/
/* argument.c */
/*******************/
#define ARGUMENT
#include "argument.h"
///////////////////////////////////////////////////////////////////////////////
int Lit_Arguments ( int argc, char ** argv )
{
int opt, i, IN ;
FILE * ptr ;
while ( (opt = getopt(argc, argv, "hRrCcnN")) != -1 )
{
switch ( opt )
{
case 'h' : case 'H' :
exit ( AfficheAide( 0 , "", argv[ 0 ] ) ) ;
case 'r' : case 'R' :
ARG.FILE_REN = 1 ;
break ;
case 'c' : case 'C' :
ARG.FILE_OUT = 1 ;
break ;
case 'n' : case 'N' :
/* if ( strcasecmp( optarg, "s" ) == 0 )
{
ARG.SPACE = 1 ;
ARG.LIGNE = 0 ;
ARG.CONVERT = 0 ;
}
else if ( strcasecmp( optarg, "n" ) == 0 )
{
ARG.SPACE = 0 ;
ARG.LIGNE = 1 ;
ARG.CONVERT = 0 ;
}
else if ( ( strcasecmp( optarg, "sn" ) == 0 ) || ( strcasecmp( optarg, "ns" ) == 0 ) )
{*/
ARG.SPACE = 1 ;
ARG.LIGNE = 1 ;
ARG.CONVERT = 0 ;
//}
break ;
default :
ARG.ERREUR = 1 ;
}
}
for ( i = optind, IN = 1 ; i < argc ; i++ )
{
// On teste existence du fichier en entrer
if ( ( ARG.FILE_IN ) || ( IN ) )
{
if ( NULL == ( ptr = fopen ( argv[ i ] , "rb" ) ) )
exit ( AfficheAide( 9, "Fichier inexistant OU probleme de droit", argv [ 0 ] ) ) ;
else
fclose ( ptr ) ;
ARG.FILE_IN = 1 ;
}
AjouteNom ( argv[ i ] , &(ARG.Files_Names) , &(ARG.Nbr_Files) ) ;
switch ( IN )
{
case 0 : IN = 1 ; break ;
case 1 : IN = 0 ; break ;
}
}
if ( ! ARG.FILE_IN )
exit ( AfficheAide (0,"", argv [ 0 ]) ) ;
return 0 ;
}
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// AFFICHE UNE AIDE SOMMAIRE
//
int AfficheAide ( int Code, char * Message, char * Nom )
{
if ( strcasecmp ( Message, "" ) != 0 )
fprintf ( stderr, "\033[0;31m%s\n\033[0;m", Message ) ;
printf ( "Usage : %s [OPTION] FILE [FILE]...\nConvertie FILE source dans le bon format\n", Nom ) ;
printf ( "Fichier source decrit un graphe de flux, ses sommets, ses capacités entre sommets, voir ses consommations courrantes\nLe fichier cible sera une matrice exploitable par des algo de maximisation de flux.\n" ) ;
printf ("\nOPTION :\n") ;
printf (" -R cree le nom fichier cible (foo.txt -> foo.mat)\n") ;
printf (" -C <file.in> <file.out> [...] ; ne cree pas les noms des fichiers cibles\n" ) ;
printf (" -N enleve les \\n et espaces doublés, ne cree pas de matrice de conso, ecrase fichier source \n") ;
printf ( "\nSyntaxe du fichier source :\n" ) ;
printf ( "\t[NAME] nom1 nom2 ... [END]\n" ) ;
printf ( "\t[RELATION]\n\tnom1 nom2 15\n\tnom5 nom4 20\n\t[END]\n" ) ;
printf ( "\t[CONS]\n\tnom1 nom2 5\n\tnom6 nom4 2\n\t[END]\n" ) ;
return Code ;
}