0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / StepFile / stepread.c
CommitLineData
b311480e 1/*
973c2be1 2 Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3
973c2be1 4 This file is part of Open CASCADE Technology software library.
b311480e 5
d5f74e42 6 This library is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8 by the Free Software Foundation, with special exception defined in the file
9 OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 distribution for complete text of the license and disclaimer of any warranty.
b311480e 11
973c2be1 12 Alternatively, this file may be used under the terms of Open CASCADE
13 commercial license or contractual agreement.
b311480e 14*/
15
7fd59977 16/* pdn PRO16162: do restart in order to restore after possible crash or wrong data
b311480e 17*/
18/*rln 10.01.99 - transmission of define's into this file
19*/
20/**
21*/
d9ff84e8 22
23#include <stdlib.h>
24#include <stdio.h>
25#include <string.h>
26#include "recfile.ph"
94708556 27#include <OSD_OpenFile.hxx>
7fd59977 28
29/* StepFile_Error.c
30
31 Ce programme substitue au yyerror standard, qui fait "exit" (brutal !)
32 une action plus adaptee a un fonctionnement en process :
33
34 Affichage de la ligne qui a provoque l' erreur,
35 Preparation d'un eventuel appel suivant (vu qu on ne fait plus exit),
36 en pour le retour, on s'arrange pour lever une exception
37 (c-a-d qu on provoque un plantage)
38
39 Adaptation pour flex (flex autorise d avoir plusieurs lex dans un meme
40 executable) : les fonctions et variables sont renommees; et la
41 continuation a change
42*/
43
44static int lastno;
45extern int steplineno;
46
47extern void StepFile_Interrupt (char* nomfic); /* rln 13.09.00 port on HP*/
48int stepparse(void);
49void rec_debfile();
50void steprestart(FILE *input_file);
51void rec_finfile();
52
53void steperror (char *mess)
54{
55 char newmess[80];
56 if (steplineno == lastno) return;
57 lastno = steplineno;
58 sprintf (newmess,"At line %d, %s",steplineno+1,mess);
59
60/* yysbuf[0] = '\0';
61 yysptr = yysbuf;
62 * yylineno = 0; */
63
64 StepFile_Interrupt(newmess);
65}
66
67/* But de ce mini-programme : appeler yyparse et si besoin preciser un
68 fichier d'entree
69 StepFile_Error redefinit yyerror pour ne pas stopper (s'y reporter)
70*/
71
72extern FILE* stepin ; /* input de yyparse (executeur de lex-yacc) */
73extern int steplineno; /* compteur de ligne lex (pour erreurs) */
74
75
76/* Designation d'un fichier de lecture
77 (par defaut, c'est l'entree standard)
78
79 Appel : iflag = stepread_setinput ("...") ou (char[] ...) ;
80 stepread_setinput ("") [longueur nulle] laisse en standard
81 iflag retourne vaut 0 si c'est OK, 1 sinon
82*/
83
84FILE* stepread_setinput (char* nomfic)
85{
86 FILE* newin ;
87 if (strlen(nomfic) == 0) return stepin ;
94708556 88 newin = OSD_OpenFile(nomfic,"r");
89
7fd59977 90 if (newin == NULL) {
91 return NULL ;
92 } else {
93 stepin = newin ; return newin ;
94 }
95}
96
97void stepread_endinput (FILE* infic, char* nomfic)
98{
99 if (!infic) return;
100 if (strlen(nomfic) == 0) return;
101 fclose (infic);
102}
103
104/* Lecture d'un fichier ia grammaire lex-yacc
105 Appel : i = stepread() ; i est la valeur retournee par yyparse
106 (0 si OK, 1 si erreur)
107*/
108int stepread ()
109{
110 int letat;
111 lastno = 0;
112 steplineno = 0;
113 rec_debfile() ;
114 steprestart(stepin);
115 letat = stepparse() ;
116 rec_finfile() ;
117 return letat;
118}
119
120int stepwrap () { return 1; }