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