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