ViSP
vpMyio.cpp
1 /****************************************************************************
2  *
3  * $Id: vpMyio.cpp 5284 2015-02-09 14:24:10Z fspindle $
4  *
5 * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Description:
34  * Le module "myio.c" contient les procedures d'entree/sortie
35  * des types definis dans le module "my.h".
36  * Les entrees non specifiees sont effectuees
37  * sur le fichier "source" du module "lex.c".
38  * Pour les mots cles des "fprintf_..." voir "token.c".
39  *
40  * Authors:
41  * Jean-Luc CORRE
42  *
43  *****************************************************************************/
44 
45 
46 
47 
48 #include <visp/vpMy.h>
49 #include <visp/vpToken.h>
50 #include <visp/vpLex.h>
51 
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #ifndef DOXYGEN_SHOULD_SKIP_THIS
56 
57 
58 extern char *mytext; /* chaine du symbole courant */
59 
60 
61 /*
62  * La procedure "fscanf_float" lit en ascii un nombre flottant.
63  * Entree :
64  * fp Nombre flottant a lire.
65  */
66 void fscanf_float (float *fp)
67 {
68  int t;
69 
70  if ((t = lex ()) != T_FLOAT && t != T_INT)
71  lexerr ("start", "float expected", NULL);
72  *fp = (t == T_INT) ? (float) myint : myfloat;
73 }
74 
75 /*
76  * La procedure "fscanf_Index" lit en ascii un indice.
77  * Entree :
78  * ip Indice a lire.
79  */
80 void fscanf_Index (Index *ip)
81 {
82  if (lex () != T_INT)
83  lexerr ("start", "integer expected", NULL);
84  *ip = (Index) myint;
85 }
86 
87 /*
88  * La procedure "fscanf_int" lit en ascii un nombre entier.
89  * Entree :
90  * ip Nombre entier a lire.
91  */
92 void fscanf_int (int *ip)
93 {
94  if (lex () != T_INT)
95  lexerr ("start", "integer expected", NULL);
96  *ip = myint;
97 }
98 
99 /*
100  * La procedure "fscanf_string" lit en ascii une chaine de caracteres.
101  * Entree :
102  * str Chaine a lire.
103  */
104 void fscanf_string (char **str)
105 {
106  if (lex () != T_STRING)
107  lexerr ("start", "string expected", NULL);
108  if (*str == NULL)
109  *str = (char *) malloc ((mylength + 1) * sizeof (char));
110  else
111  *str = (char *) realloc (*str, (mylength + 1) * sizeof (char));
112 
113  if (*str == NULL) {
114  printf("Unable to read the string: bad memory allocation");
115  return;
116  }
117 
118  strncpy (*str, mytext, mylength);
119 }
120 
121 /*
122  * La procedure "fscanf_Type" lit en ascii un octet.
123  * Entree :
124  * ip Type a lire.
125  */
126 void fscanf_Type (Type *ip)
127 {
128  if (lex () != T_INT)
129  lexerr ("start", "integer expected", NULL);
130  *ip = (Type ) myint;
131 }
132 
133 #endif