better args parsing in mkfimg
This commit is contained in:
		
							parent
							
								
									65eaca26cc
								
							
						
					
					
						commit
						c59eedd33c
					
				@ -926,13 +926,16 @@ Usage:  mkfimg [options]  quux.fimg width height
 | 
				
			|||||||
        -v      increase verbosity
 | 
					        -v      increase verbosity
 | 
				
			||||||
\end{verbatim}
 | 
					\end{verbatim}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Il y a deux syntaxes possibles pour les dimensions de l'image générée~:
 | 
				
			||||||
 | 
					deux nombres séparés ou la notation \texttt{WIDTHxHEIGHT}.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
La plupart des types d'image générée prennent un paramètre flottant qui
 | 
					La plupart des types d'image générée prennent un paramètre flottant qui
 | 
				
			||||||
devra être donné avec l'option \texttt{-k F.F} avec une valeur par défaut
 | 
					devra être donné avec l'option \texttt{-k F.F} avec une valeur par défaut
 | 
				
			||||||
à $1.0$, ce qui n'est pas toujours une bonne valeur.
 | 
					à $1.0$, ce qui n'est pas toujours une bonne valeur.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{description}	\index{XXX}
 | 
					\begin{description}	\index{XXX}
 | 
				
			||||||
\item [black/gray/grey:] efface avec 0.0 (black) ou avec la valeur
 | 
					\item [black/gray/grey:] efface avec 0.0 (black) ou avec la valeur
 | 
				
			||||||
		\texttt{-k} (gray).
 | 
							\texttt{-k} (niveau de gris).
 | 
				
			||||||
\item [drand48:] beaucoup de bruit dans chacun des canaux.
 | 
					\item [drand48:] beaucoup de bruit dans chacun des canaux.
 | 
				
			||||||
\item [hdeg/vdeg:] dégradé du noir au blanc (relatif à \texttt{-k}).
 | 
					\item [hdeg/vdeg:] dégradé du noir au blanc (relatif à \texttt{-k}).
 | 
				
			||||||
\end{description}
 | 
					\end{description}
 | 
				
			||||||
 | 
				
			|||||||
@ -63,7 +63,7 @@ int		foo;
 | 
				
			|||||||
puts("Usage:\tmkfimg [options]  quux.fimg width height");
 | 
					puts("Usage:\tmkfimg [options]  quux.fimg width height");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
puts("\t-k N.N\tgive a float parameter");
 | 
					puts("\t-k N.N\tgive a float parameter");
 | 
				
			||||||
fputs("\t-t bla\thowto make the pic\n\t\t", stdout);
 | 
					fputs("\t-t bla\thowto make the pic :\n\t\t", stdout);
 | 
				
			||||||
for (foo=0; types[foo].code; foo++) {
 | 
					for (foo=0; types[foo].code; foo++) {
 | 
				
			||||||
	printf("%s ", types[foo].name);
 | 
						printf("%s ", types[foo].name);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -79,7 +79,7 @@ exit(0);
 | 
				
			|||||||
/* --------------------------------------------------------------------- */
 | 
					/* --------------------------------------------------------------------- */
 | 
				
			||||||
int main(int argc, char *argv[])
 | 
					int main(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
int		foo, opt;
 | 
					int		foo, opt, nbargs;
 | 
				
			||||||
int		width, height;
 | 
					int		width, height;
 | 
				
			||||||
char		*fname;
 | 
					char		*fname;
 | 
				
			||||||
float		fvalue = 1.0;
 | 
					float		fvalue = 1.0;
 | 
				
			||||||
@ -103,18 +103,30 @@ for (foo=0; foo<argc; foo++)
 | 
				
			|||||||
	fprintf(stderr, "%3d  %s\n", foo, argv[foo]);
 | 
						fprintf(stderr, "%3d  %s\n", foo, argv[foo]);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (3 != argc-optind) {
 | 
					 | 
				
			||||||
	fprintf(stderr, "%s need filename, width & height\n", argv[0]);
 | 
					 | 
				
			||||||
	exit(1);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if (type < 0) {
 | 
					if (type < 0) {
 | 
				
			||||||
	fprintf(stderr, "type '%s' is unknow\n", tname);
 | 
						fprintf(stderr, "type '%s' is unknow\n", tname);
 | 
				
			||||||
	exit(2);
 | 
						exit(2);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					nbargs = argc-optind;
 | 
				
			||||||
 | 
					switch (nbargs) {
 | 
				
			||||||
 | 
						case 2:
 | 
				
			||||||
 | 
							if (2!=parse_WxH(argv[optind+1], &width, &height)) {
 | 
				
			||||||
 | 
								fprintf(stderr, "%s: parse error on '%s'\n",
 | 
				
			||||||
 | 
										argv[0], argv[optind+1]);
 | 
				
			||||||
 | 
								exit(1);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case 3:
 | 
				
			||||||
 | 
							width = atoi(argv[optind+1]);
 | 
				
			||||||
 | 
							height = atoi(argv[optind+2]);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							fprintf(stderr, "%s need filename, width & height\n", argv[0]);
 | 
				
			||||||
 | 
							exit(1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fname = argv[optind];
 | 
					fname = argv[optind];
 | 
				
			||||||
width = atoi(argv[optind+1]);	height = atoi(argv[optind+2]);	
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (verbosity>1) fprintf(stderr, "*** mkfimg *** %s %s\n", __DATE__, __TIME__);
 | 
					if (verbosity>1) fprintf(stderr, "*** mkfimg *** %s %s\n", __DATE__, __TIME__);
 | 
				
			||||||
if (verbosity)   fprintf(stderr, "making  '%s'  %dx%d, type %d\n",
 | 
					if (verbosity)   fprintf(stderr, "making  '%s'  %dx%d, type %d\n",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user