A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Julio Jerez » Wed Aug 05, 2009 1:14 pm
guys I am working on a project that I will share later.
I am using a utility tha use fopen and I can no change it.
here is my quertion, is ther a way to open a file in memory?
like reading form memory isntera to a file
like:
fscans (file, "&datat)
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Marc » Thu Aug 06, 2009 6:14 am
I'm not entirely sure if your problem is to
0) let the utility, which is a seperate process, use a memory located file (for example created with CreateFile) as an input parameter and open it with fopen
1) have data in the same process and just want to parse it by getting a file handle for it and using the f* functions to read it piece by piece - but everything happens in the same process.
For 0) I had a similar problem once before, but I had access to the src. I changed it to use CreateFile because I didn't find a way to use fopen to access shared memories. I think it's not possible.
For 1) Afaik, FILE always represents a file on the disk or some special things like COM1. The polymorphism required for this is not available.
-
Marc
-
- Posts: 281
- Joined: Sun Mar 14, 2004 4:07 pm
- Location: Germany
-
by Julio Jerez » Thu Aug 06, 2009 8:50 am
Marc wrote:0) let the utility, which is a seperate process, use a memory located file (for example created with CreateFile) as an input parameter and open it with fopen
I guess that will be an option, how do I do that?
I am using Lex and Bison and tey use buffered files.
besically I want the option of using a piece of memory af a file.
The other alternative is me writing the lexcal code which Is not and atrcative preprostion.
do you know an alternative to Lex/Bison? tah can use Yacc Grammar
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Thu Aug 06, 2009 10:35 am
awesome that is exactly what I need.
I use Bison and Yacc in Xenix OS since 1989 and I love it, but I never had to used it reading from a memory buffer before.
Also I was looking for a newer version of Bison, the one I am uing is from 1999
But I can not find any with a visual studio build
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by martinsm » Thu Aug 06, 2009 10:38 am
What do you mean - visual studio build? Bison generates y.tab.c/h file, which you compile for your project. Only non-MSVC compatible thing I have found there, that there is #include <unistd.h> directive. And MSVC has no unistd.h file. I get around that by creating empty unistd.h file for MSVC
Latest bison usable from windows probably can be downloaded here:
http://gnuwin32.sourceforge.net/packages/bison.htm
-
martinsm
-
- Posts: 86
- Joined: Mon Dec 19, 2005 3:15 pm
- Location: Latvia
by Julio Jerez » Thu Aug 06, 2009 10:41 am
yes that is it,
I searched in Google some many different phrases like Bison for Win, and Bison for Visual studio and I could not find anything, I do have a working version but it is too old.
Thank you that is what I need.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Thu Aug 06, 2009 10:53 am
well that link takes me to the same link I foudn in me search.
http://ftp.gnu.org/gnu/bison/but none of those downloads have a Visual Studio project of a binary that I can use.
They used to have VS6 build.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Julio Jerez » Thu Aug 06, 2009 11:11 am
I added this to teh project
- Code: Select all
%{
#include <stdafx.h>
#include <stdio.h>
#include <ScriptCompile.h>
#ifdef YYSTYPE
#undef YYSTYPE
#endif
#define YY_NEVER_INTERACTIVE 1
#define YYSTYPE int
#include "scriptgrammar.cpp.h"
// Julio I added this
#define YY_BUFFER_STATE yy_scan_string(const char *str)
void count();
void comment();
int check_type();
%}
...
but it did not work do you know how to I instruct the Lex Grammar to scan from memory buffer?
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by martinsm » Thu Aug 06, 2009 11:44 am
I am doing it around yyparse() call:
- Code: Select all
typedef struct yy_buffer_state* YY_BUFFER_STATE;
extern YY_BUFFER_STATE yy_scan_string(const char*);
extern void yy_delete_buffer(YY_BUFFER_STATE);
extern int yyparse();
int main()
{
// ...
YY_BUFFER_STATE buf = yy_scan_string(memory_buffer);
yyparse();
yy_delete_buffer(buf);
// ...
}
-
martinsm
-
- Posts: 86
- Joined: Mon Dec 19, 2005 3:15 pm
- Location: Latvia
by Julio Jerez » Thu Aug 06, 2009 12:04 pm
it work!! awesome teh unly diffrence is tah I used a prefix, but otehr tah tah work like a cham.
- Code: Select all
typedef struct yy_buffer_state* YY_BUFFER_STATE;
extern YY_BUFFER_STATE cScript_scan_string(const char*);
extern void cScript_delete_buffer(YY_BUFFER_STATE b);
void* CSriptCompile (const char* program)
{
YY_BUFFER_STATE buf = cScript_scan_string(program);
cScriptparse ();
cScript_delete_buffer(buf);
}
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 40 guests