From 8cd69fe13d7784ef092e1918cea374ada4898db6 Mon Sep 17 00:00:00 2001 From: cas Date: Fri, 22 Oct 1999 18:05:40 +0000 Subject: [PATCH] Initial revision --- src/EDL/EDL.cdl | 89 ++ src/EDL/EDL.cxx | 78 ++ src/EDL/EDL.lex | 165 +++ src/EDL/EDL.yacc | 244 ++++ src/EDL/EDL_API.cdl | 170 +++ src/EDL/EDL_API.cxx | 289 +++++ src/EDL/EDL_CMPLRS.edl | 14 + src/EDL/EDL_File.cdl | 45 + src/EDL/EDL_File.cxx | 75 ++ src/EDL/EDL_FunctionSignature.hxx | 6 + src/EDL/EDL_Interpretor.cdl | 149 +++ src/EDL/EDL_Interpretor.cxx | 1734 ++++++++++++++++++++++++++++ src/EDL/EDL_Library.cdl | 50 + src/EDL/EDL_Library.cxx | 104 ++ src/EDL/EDL_ProcedureSignature.hxx | 6 + src/EDL/EDL_Template.cdl | 66 ++ src/EDL/EDL_Template.cxx | 187 +++ src/EDL/EDL_Variable.cdl | 43 + src/EDL/EDL_Variable.cxx | 73 ++ src/EDL/FILES | 7 + src/EDL/edl_rule.h | 75 ++ 21 files changed, 3669 insertions(+) create mode 100755 src/EDL/EDL.cdl create mode 100755 src/EDL/EDL.cxx create mode 100755 src/EDL/EDL.lex create mode 100755 src/EDL/EDL.yacc create mode 100755 src/EDL/EDL_API.cdl create mode 100755 src/EDL/EDL_API.cxx create mode 100755 src/EDL/EDL_CMPLRS.edl create mode 100755 src/EDL/EDL_File.cdl create mode 100755 src/EDL/EDL_File.cxx create mode 100755 src/EDL/EDL_FunctionSignature.hxx create mode 100755 src/EDL/EDL_Interpretor.cdl create mode 100755 src/EDL/EDL_Interpretor.cxx create mode 100755 src/EDL/EDL_Library.cdl create mode 100755 src/EDL/EDL_Library.cxx create mode 100755 src/EDL/EDL_ProcedureSignature.hxx create mode 100755 src/EDL/EDL_Template.cdl create mode 100755 src/EDL/EDL_Template.cxx create mode 100755 src/EDL/EDL_Variable.cdl create mode 100755 src/EDL/EDL_Variable.cxx create mode 100755 src/EDL/FILES create mode 100755 src/EDL/edl_rule.h diff --git a/src/EDL/EDL.cdl b/src/EDL/EDL.cdl new file mode 100755 index 0000000..9a109bd --- /dev/null +++ b/src/EDL/EDL.cdl @@ -0,0 +1,89 @@ +-- File: EDL.cdl +-- Created: Thu Jun 1 18:01:41 1995 +-- Author: Christophe LEYNADIER +-- +---Copyright: Matra Datavision 1995 + +package EDL + uses MMgt, + TCollection, + TColStd, + OSD +is + imported FunctionSignature; + + class API; + ---Purpose: User API for EDL. + + class Variable; + ---Purpose: for each variable of an EDL source. + + class MapOfVariable instantiates DataMap from TCollection(AsciiString from TCollection, + Variable from EDL, + AsciiString from TCollection); + ---Purpose: for all variables of an EDL source. + + class SequenceOfVariable instantiates Sequence from TCollection (Variable from EDL); + class HSequenceOfVariable instantiates HSequence from TCollection (Variable from EDL, + SequenceOfVariable from EDL); + + class Template; + ---Purpose: for each template in an EDL source. + + class MapOfTemplate instantiates DataMap from TCollection(AsciiString from TCollection, + Template from EDL, + AsciiString from TCollection); + ---Purpose: for all templates of an EDL source. + + class Library; + ---Purpose: for calling function from others libraries from EDL + + class MapOfLibrary instantiates DataMap from TCollection(AsciiString from TCollection, + Library from EDL, + AsciiString from TCollection); + + class File; + ---Purpose: to opened files in EDL. + + class MapOfFile instantiates DataMap from TCollection(AsciiString from TCollection, + File from EDL, + AsciiString from TCollection); + + + -- ENUMERATIONS + -- + enumeration ParameterMode is + VARIABLE, + STRING + end; + + enumeration Error is + NORMAL, + SYNTAXERROR, + VARNOTFOUND, + TEMPMULTIPLEDEFINED, + TEMPLATENOTDEFINED, + LIBRARYNOTFOUND, + LIBNOTOPEN, + FUNCTIONNOTFOUND, + FILEOPENED, + FILENOTOPENED, + FILENOTFOUND, + TOOMANYINCLUDELEVEL + end; + + -- PRIVATE + -- + private class StackOfBoolean instantiates Stack from TCollection(Boolean from Standard); + ---Purpose: for evaluation of expressions + + private class Interpretor; + + -- METHODES + -- + PrintError(anError : Error from EDL; anArg : CString from Standard); + +end; + + + diff --git a/src/EDL/EDL.cxx b/src/EDL/EDL.cxx new file mode 100755 index 0000000..765e163 --- /dev/null +++ b/src/EDL/EDL.cxx @@ -0,0 +1,78 @@ +#include +#include + +#include + +#ifndef WNT + extern int EDLlineno; + extern TCollection_AsciiString EDL_CurrentFile; +#else + extern "C" int EDLlineno; + extern TCollection_AsciiString EDL_CurrentFile; +#endif // WNT + + +static void (*EDL_ErrorMsgHandler) (Standard_CString aMsg) = NULL; + +Standard_EXPORT void EDL_SetErrorMsgHandler(void (*aMsgHandler) (Standard_CString aMsg)) +{ + EDL_ErrorMsgHandler = aMsgHandler; + return; +} + +void EDL::PrintError(const EDL_Error anError, const Standard_CString anArg) +{ + char *format; + char *errortext; + + if (EDLlineno >= 0) { + format = "%s : line %d : %s%s\n"; + } + else { + format = "call from C++ : %s%s\n"; + } + + switch (anError) { + case EDL_NORMAL: errortext = "Done : "; + break; + case EDL_SYNTAXERROR: errortext = "Syntax error"; + break; + case EDL_VARNOTFOUND: errortext = "Variable not found : "; + break; + case EDL_TEMPMULTIPLEDEFINED: errortext = "Template already defined : "; + break; + case EDL_TEMPLATENOTDEFINED: errortext = "Template not defined : "; + break; + case EDL_LIBRARYNOTFOUND: errortext = "Library not found : "; + break; + case EDL_LIBNOTOPEN: errortext = "Library not open : "; + break; + case EDL_FUNCTIONNOTFOUND: errortext = "Function not found : "; + break; + case EDL_FILEOPENED: errortext = "File opened : "; + break; + case EDL_FILENOTOPENED: errortext = "File not opened : "; + break; + case EDL_TOOMANYINCLUDELEVEL: errortext = "Too many include levels : "; + break; + } + + if(!EDL_ErrorMsgHandler) { + if (EDLlineno >= 0) { + printf(format,EDL_CurrentFile.ToCString(),EDLlineno,errortext,anArg); + } + else { + printf(format,errortext,anArg); + } + } else { + char TheMsg[1024]; + if (EDLlineno >= 0) { + sprintf(TheMsg,format,EDL_CurrentFile.ToCString(),EDLlineno,errortext,anArg); + } + else { + sprintf(TheMsg, format,errortext,anArg); + } + (*EDL_ErrorMsgHandler) (TheMsg); + } + +} diff --git a/src/EDL/EDL.lex b/src/EDL/EDL.lex new file mode 100755 index 0000000..01c23a9 --- /dev/null +++ b/src/EDL/EDL.lex @@ -0,0 +1,165 @@ + +%{ +#include +#include +#define yylval EDLlval +#include +#include + +#define MAX_CHAR 256 /* The limit of a identifier. */ +#define MAX_STRING (MAX_CHAR * 10) /* The limit of a string. */ +#define MAX_COMMENT (MAX_CHAR * 300) /* The limit of comment line */ + +static char identifier[MAX_CHAR +1]; +static char integer [MAX_CHAR +1]; +static char real [MAX_CHAR +1]; +static char literal [MAX_CHAR +1]; +static char string [MAX_STRING +1]; + +char FileName[11][256]; +FILE *FileDesc[10]; +int LineStack[10]; +YY_BUFFER_STATE EDL_Buffers[10]; + +int numFileDesc = -1; + +int templateDef = 0; +int EDLlineno; +int VerboseMode = 0; + +#ifdef WNT +#define YY_INPUT(buf,result,max_size) \ + if ( (result = fread( (char *) buf, sizeof(char), max_size, yyin)) == 0 ) \ + if(ferror(yyin)) YY_FATAL_ERROR( "input in flex scanner failed" ); +#endif + + + +%} + + +/* The specials keywords */ + +COMMENT [-][-] + +/* The identifiers without underscore at begining and end */ + +IDENTIFIER [A-Za-z0-9_-]+ + +/* [A-Za-z][A-Za-z0-9_]*[A-Za-z0-9] */ + + +/* Integer and real */ + +INTEGER [+-]?[0-9]+ +/* REAL [+-]?[0-9]+"."[0-9]+([Ee][+-]?[0-9]+)? */ + +/* Literal, variable and string */ +/* [A-Za-z][A-Za-z0-9_]*[A-Za-z0-9] */ + +LITERAL "'"."'" +STRING \"[^"\n]*["\n] +VARNAME "%"{1}([A-Za-z0-9_-]+) +/* TEMPLATEDEF ^[ \t]*"$" */ +TEMPLATEDEF "$" +/* The LEX directives. */ + +/* %p 5000 */ +/* %a 9000 */ +/* %o 10000 */ + +%% + +{COMMENT}.*\n {EDLlineno++;} + +@verboseon { if (edl_must_execute()) { VerboseMode = 1; printf("%d. @verboseon",EDLlineno);} return(VERBOSEON);} +@verboseoff { if (edl_must_execute()) { if (VerboseMode) printf("%d. @verboseoff",EDLlineno); VerboseMode = 0;} return(VERBOSEOFF);} +@uses { if (VerboseMode && edl_must_execute()) printf("%d. @uses ",EDLlineno); return(USES); } +@template { templateDef = 1; if (VerboseMode && edl_must_execute()) printf("%d. @template ",EDLlineno); return(TEMPLATE);} +is { if (VerboseMode && edl_must_execute()) printf(" is\n"); return(IS);} +@set { if (VerboseMode && edl_must_execute()) printf("%d. @set ",EDLlineno); return(SET); } +@unset { if (VerboseMode && edl_must_execute()) printf("%d. @unset ",EDLlineno); return(UNSET); } +@ifdefined { if (VerboseMode && edl_must_execute()) printf("%d. @ifdefined ",EDLlineno); return(IFDEFINED); } +@ifnotdefined { if (VerboseMode && edl_must_execute()) printf("%d. @ifnotdefined ",EDLlineno); return(IFNOTDEFINED); } +defined { if (VerboseMode && edl_must_execute()) printf(" defined ",EDLlineno); return(INSTRDEFINED); } +notdefined { if (VerboseMode && edl_must_execute()) printf(" notdefined ",EDLlineno); return(INSTRNOTDEFINED); } +@iffile { if (VerboseMode && edl_must_execute()) printf("%d. @iffile ",EDLlineno); return(IFFILE); } +@ifnotfile { if (VerboseMode && edl_must_execute()) printf("%d. @ifnotfile ",EDLlineno); return(IFNOTFILE); } +file { if (VerboseMode && edl_must_execute()) printf(" file ",EDLlineno); return(INSTRFILE); } +notfile { if (VerboseMode && edl_must_execute()) printf(" notfile ",EDLlineno); return(INSTRNOTFILE); } +@if { if (VerboseMode && edl_must_execute()) printf("%d. @if ",EDLlineno); return(IF); } +then { if (VerboseMode && edl_must_execute()) printf(" then\n"); return(THEN); } +@else { if (VerboseMode && edl_must_execute()) printf("@else\n"); return(ELSE); } +@endif { if (VerboseMode && edl_must_execute()) printf("%d. @endif",EDLlineno); return(ENDIF); } +@end { templateDef = 0; if (VerboseMode && edl_must_execute()) printf("%d. @end",EDLlineno); return(END); } +@cout { if (VerboseMode && edl_must_execute()) printf("%d. @cout ",EDLlineno); return(COUT); } +@file { if (VerboseMode && edl_must_execute()) printf("%d. @file ",EDLlineno); return(AFILE); } +@string { if (VerboseMode && edl_must_execute()) printf("%d. @string ",EDLlineno); return(ASTRING); } +@openlib { if (VerboseMode && edl_must_execute()) printf("%d. @openlib ",EDLlineno); return(OPENLIB); } +@closelib { if (VerboseMode && edl_must_execute()) printf("%d. @closelib ",EDLlineno); return(CLOSELIB); } +@call { if (VerboseMode && edl_must_execute()) printf("%d. @call ",EDLlineno); return(CALLLIB); } +@apply { if (VerboseMode && edl_must_execute()) printf("%d. @apply ",EDLlineno); return(APPLY); } +@write { if (VerboseMode && edl_must_execute()) printf("%d. @write ",EDLlineno); return(WRITE); } +@close { if (VerboseMode && edl_must_execute()) printf("%d. @close ",EDLlineno); return(CLOSE); } +@addtotemplate { if (VerboseMode && edl_must_execute()) printf("%d. @addtotemplate ",EDLlineno); return(ADDTOTEMPLATE); } +@cleartemplate { if (VerboseMode && edl_must_execute()) printf("%d. @cleartemplate ",EDLlineno); return(CLEARTEMPLATE); } +"+=" { if (VerboseMode && edl_must_execute()) printf(" += "); return(PLUSEQUAL); } +== { if (VerboseMode && edl_must_execute()) printf(" == "); EDLlval.ope = EQ; return(EQ); } +!= { if (VerboseMode && edl_must_execute()) printf(" != "); EDLlval.ope = NEQ; return(NEQ); } +; { if (VerboseMode && edl_must_execute()) printf(";\n"); return(SEPARATOR); } +"||" { if (VerboseMode && edl_must_execute()) printf(" || "); EDLlval.ope = LOGOR; return(LOGOR); } +"&&" { if (VerboseMode && edl_must_execute()) printf(" && "); EDLlval.ope = LOGAND; return(LOGAND); } + +{STRING} { /* we kill the quotes from string */ + if (VerboseMode && edl_must_execute()) printf("%s",yytext); + EDLlval.str = edl_string(yytext,yyleng); + return(STR); + } +{VARNAME} { EDLlval.str = edl_strdup(EDLtext, yyleng); if (VerboseMode && edl_must_execute()) printf(" %s ",EDLtext); return(VAR);} +{IDENTIFIER} { EDLlval.str = edl_strdup(EDLtext, yyleng); if (VerboseMode && edl_must_execute()) printf(" %s ",EDLtext); return(IDENT);} +[ \t]+ {/* We don't take care of line feed, space or tabulation */} +{TEMPLATEDEF}.*\n { EDLlval.str = edl_strdup(EDLtext,yyleng); if (VerboseMode && edl_must_execute()) printf("%d. %s",EDLlineno,EDLtext); EDLlineno++; return(TEMPDEF);} + + +[\n] { EDLlineno++;} +. { if (VerboseMode && edl_must_execute()) printf("%c",yytext[0]); return yytext[0]; } +%% + +void EDL_SetFile() +{ + YY_BUFFER_STATE buf = yy_create_buffer(EDLin,YY_BUF_SIZE); + + EDL_Buffers[numFileDesc] = YY_CURRENT_BUFFER; + + yy_switch_to_buffer(buf); +} + + +/* we need this for '@uses' clause */ +int EDLwrap() +{ + char c[2]; + edlstring _currentFile; + + if (numFileDesc < 0) { + return 1; + } + else { + fclose(EDLin); + + yy_delete_buffer(YY_CURRENT_BUFFER); + + EDLin = FileDesc[numFileDesc]; + EDLlineno = LineStack[numFileDesc] + 1; + + _currentFile.str = &(FileName[numFileDesc][0]); + _currentFile.length = strlen(&(FileName[numFileDesc][0])); + EDL_SetCurrentFile(_currentFile); + + yy_switch_to_buffer(EDL_Buffers[numFileDesc]); + + numFileDesc--; + + return 0; + } +} diff --git a/src/EDL/EDL.yacc b/src/EDL/EDL.yacc new file mode 100755 index 0000000..987afd7 --- /dev/null +++ b/src/EDL/EDL.yacc @@ -0,0 +1,244 @@ +%{ +#include +/* all parser must define this variable */ + +#define yyv EDLv + +extern FILE *FileDesc[]; +extern numFileDesc; +extern FILE *EDLin; +/* extern int edl_must_execute(); */ + +#include + +%} +%token USES +%token TEMPLATE +%token ADDTOTEMPLATE +%token CLEARTEMPLATE +%token END +%token SET +%token UNSET +%token INSTRDEFINED +%token INSTRNOTDEFINED +%token IFDEFINED +%token IFNOTDEFINED +%token IFFILE +%token IFNOTFILE +%token INSTRFILE +%token INSTRNOTFILE +%token IF +%token THEN +%token ELSE +%token ENDIF +%token COUT +%token IS +%token EQ +%token NEQ +%token LOGOR +%token LOGAND +%token SEPARATOR +%token ASTRING +%token AFILE +%token OPENLIB +%token CLOSELIB +%token CALLLIB +%token APPLY +%token WRITE +%token CLOSE +%token VERBOSEON +%token VERBOSEOFF +%token PLUSEQUAL +%token STR IDENT TEMPDEF VAR +%token EQ NEQ LOGOR LOGAND +%type logoperator expr_operator +%type tempdefs identifier filename ifdefcond +%union { + edlstring str; + int ope; +} + +%% +statements: statement + | statements statement; + +statement: + | use_dec + | addtotemplate_dec + | cleartemplate_dec + | template_dec + | ifdefined_dec + | ifnotdefined_dec + | if_dec + | set_dec + | unset_dec + | cout_dec + | string_dec + | file_dec + | iffileexists_dec + | iffilenotexists_dec + | openlib_dec + | closelib_dec + | apply_dec + | calllib_dec + | write_dec + | close_dec + | verboseon_dec + | verboseoff_dec + ; + +use_dec: USES STR SEPARATOR { edl_uses($2); } + | USES VAR SEPARATOR { edl_uses_var($2); } + ; + +verboseoff_dec: VERBOSEOFF SEPARATOR + ; + +verboseon_dec: VERBOSEON SEPARATOR + ; + +template_dec: templatehead identifier { edl_create_template($2); } '(' listvars ')' IS tempdefs END SEPARATOR { edl_end_template(); } + ; + +templatehead: TEMPLATE + ; + +addtotemplate_dec: ADDTOTEMPLATE identifier { edl_set_template($2); } IS tempdefs END SEPARATOR { edl_end_template(); } + ; + +cleartemplate_dec: CLEARTEMPLATE identifier SEPARATOR { edl_clear_template($2); } + ; + +identifier: IDENT + ; + +tempdefs: TEMPDEF { edl_add_to_template($1); } + | tempdefs TEMPDEF { edl_add_to_template($2); } + ; + +apply_dec: APPLY VAR '=' IDENT { edl_apply_template($4); } SEPARATOR { edl_end_apply($2); } + ; + +listvars: + | VAR { edl_add_to_varlist($1); } + | listvars ',' VAR { edl_add_to_varlist($3); } + ; + +iffileexists_dec: IFFILE '(' VAR ')' {edl_fileexist_var($3); } if_follow + | IFFILE '(' STR ')' {edl_fileexist($3); } if_follow + ; + + +iffilenotexists_dec: IFNOTFILE '(' VAR ')' {edl_filenotexist_var($3); } if_follow + | IFNOTFILE '(' STR ')' {edl_filenotexist($3); } if_follow + ; + +ifdefined_dec: IFDEFINED '(' ifdefcond ')' {edl_isvardefined($3); } THEN statements if_end_dec + ; +ifnotdefined_dec: IFNOTDEFINED '(' ifdefcond ')' {edl_isvarnotdefined($3); } THEN statements if_end_dec + ; +if_dec: IF '(' conditions ')' THEN statements if_end_dec + ; + +if_follow: THEN statements if_end_dec + ; + +ifdefcond: VAR + | IDENT + ; + + +if_end_dec: ENDIF SEPARATOR { edl_clear_execution_status(); } + | ELSE { edl_else_execution_status(); } statements ENDIF SEPARATOR { edl_clear_execution_status(); } + ; + +set_dec: SET VAR '=' STR SEPARATOR { edl_set_var($2,$4); edlstring_free($2); edlstring_free($4);} + | SET VAR '=' VAR SEPARATOR { edl_set_varvar($2,$4); edlstring_free($2); edlstring_free($4);} + | SET VAR '=' '[' VAR ']' SEPARATOR { edl_set_varevalvar($2,$5); edlstring_free($2); edlstring_free($5);} + | SET '[' VAR ']' '=' STR SEPARATOR { edl_set_pvar($3,$6); edlstring_free($3); edlstring_free($6);} + | SET '[' VAR ']' '=' VAR SEPARATOR { edl_set_pvarvar($3,$6); edlstring_free($3); edlstring_free($6);} + | SET '[' VAR ']' '=' '[' VAR ']' SEPARATOR { edl_set_pvarevalvar($3,$7); edlstring_free($3); edlstring_free($7);} + ; + +unset_dec: UNSET VAR SEPARATOR { edl_unset_var($2); edlstring_free($2); } + | UNSET '[' VAR ']' SEPARATOR { edl_unset_pvar($3); edlstring_free($3); } + ; + +cout_dec: COUT { edl_clear_printlist(); } printlists SEPARATOR { edl_cout(); } + ; + +string_dec: ASTRING { edl_clear_printlist(); } string_end_dec + ; + +string_end_dec: VAR '=' printlists SEPARATOR { edl_create_string_var($1); } + | VAR PLUSEQUAL { edl_printlist_addps_var($1); } printlists SEPARATOR { edl_create_string_var($1); } + ; + +printlists: printlist + | printlists printlist + ; + +printlist: + | VAR { edl_printlist_add_var($1); } + | STR { edl_printlist_add_str($1); } + ; + + +file_dec: AFILE IDENT filename SEPARATOR { edl_open_file($2,$3); } + ; + +filename: VAR { edl_set_varname(); } + | STR { edl_set_str(); } + ; + +write_dec: WRITE IDENT VAR SEPARATOR { edl_write_file($2,$3); } + ; + +close_dec: CLOSE IDENT SEPARATOR { edl_close_file($2); } + ; + +openlib_dec: OPENLIB IDENT SEPARATOR { edl_open_library($2); } + ; + +calllib_dec: CALLLIB IDENT '.' IDENT '(' arglists ')' SEPARATOR { edl_call_procedure_library($2,$4); } + | CALLLIB VAR '=' IDENT '.' IDENT '(' arglists ')' SEPARATOR { edl_call_function_library($4,$6,$2); } + ; + +arglists: arglist + | arglists ',' arglist + ; + +arglist: + | VAR { edl_arglist_add_var($1); } + | STR { edl_arglist_add_str($1); } + ; + +closelib_dec: CLOSELIB IDENT SEPARATOR { edl_close_library($2); } + ; + +conditions: condition { edl_eval_condition(); } + | conditions condition + ; + +condition: VAR logoperator STR { edl_test_condition($1,$2,$3); } + | condition expr_operator condition { edl_eval_local_condition($2); } + | '(' condition ')' + | INSTRDEFINED '(' ifdefcond ')' {edl_isvardefinedm($3); } + | INSTRNOTDEFINED '(' ifdefcond ')' {edl_isvarnotdefinedm($3); } + | INSTRFILE '(' VAR ')' {edl_fileexist_varm($3); } + | INSTRNOTFILE '(' VAR ')' {edl_filenotexist_varm($3); } + | INSTRFILE '(' STR ')' {edl_fileexistm($3); } + | INSTRNOTFILE '(' STR ')' {edl_filenotexistm($3); } + ; + +logoperator: EQ + | NEQ + ; + +expr_operator: LOGAND + | LOGOR + ; + +%% + + diff --git a/src/EDL/EDL_API.cdl b/src/EDL/EDL_API.cdl new file mode 100755 index 0000000..3a07f1e --- /dev/null +++ b/src/EDL/EDL_API.cdl @@ -0,0 +1,170 @@ +-- File: EDL_API.cdl +-- Created: Wed Sep 13 10:15:27 1995 +-- Author: Kernel +-- +---Copyright: Matra Datavision 1995 + +class API from EDL + + inherits TShared from MMgt + + uses HSequenceOfHAsciiString from TColStd, + HSequenceOfAsciiString from TColStd, + HAsciiString from TCollection, + Error from EDL, + Template from EDL, + Variable from EDL, + Interpretor from EDL, + DataMapIteratorOfMapOfTemplate from EDL, + DataMapIteratorOfMapOfVariable from EDL + + is + + Create returns mutable API from EDL; + + Openlib(me; aName : CString from Standard) + returns Error from EDL; + ---Purpose: Open a shared library named + -- The name must not be the name of the file + -- but the significant part : + -- + -- ex.: + -- + -- for library libTest.so + -- the name must be Test + + Call(me; aLibName : CString from Standard; + aFunction : CString from Standard; + anArgList : HSequenceOfHAsciiString from TColStd) + returns Error from EDL; + ---Purpose: Call a function from library with + -- the arguments list + -- The name of the library is the same than Openlib + + Closelib(me; aName : CString from Standard); + ---Purpose: Close the library named + -- The name is the same than Openlib + + AddTemplate(me; aName : CString from Standard; + aDefinition : HSequenceOfHAsciiString from TColStd; + aVarList : HSequenceOfHAsciiString from TColStd); + ---Purpose: Add a template named with as definition + + Apply(me; aResult : CString from Standard; + aName : CString from Standard); + ---Purpose: Evaluate a template named with the variables + -- list and set the result in a variable named + + RemoveTemplate(me; aName : CString from Standard); + ---Purpose: Remove a template + + GetTemplate(me; aName : CString from Standard) + returns Template from EDL; + ---C++: return & + + AddVariable(me; aName : CString from Standard; + aValue : CString from Standard); + ---Purpose: Create a variable or modifie it s value + + AddVariable(me; aName : CString from Standard; + aValue : Integer from Standard); + ---Purpose: Create a variable or modifie it s value + + AddVariable(me; aName : CString from Standard; + aValue : Real from Standard); + ---Purpose: Create a variable or modifie it s value + + AddVariable(me; aName : CString from Standard; + aValue : Character from Standard); + ---Purpose: Create a variable or modifie it s value + + GetVariable(me; aName : CString from Standard) + returns Variable from EDL; + ---C++: return & + ---Purpose: Returns the value of the variable named . + + GetVariableValue(me; aName : CString from Standard) + returns mutable HAsciiString from TCollection; + ---Purpose: Returns the value of the variable named . + + RemoveVariable(me; aName : CString from Standard); + ---Purpose: Remove a variable named . + + IsDefined(me; aName : CString from Standard) + returns Boolean from Standard; + ---Purpose: Return Standard_True if a variable or template named is defined + + OpenFile(me; aName : CString from Standard; + aPath : CString from Standard) + returns Error from EDL; + ---Purpose: Open a file named with a filename + -- can be either a variable name or a full path. + -- Ex. in EDL : @file afile "/tmp/output.txt"; + -- or + -- @file afile %filename; + + WriteFile(me; aName : CString from Standard; + aVar : CString from Standard); + ---Purpose: Write in file (see OpenFile for the name) the value + -- of the variable named + + WriteFileConst(me; aName : CString from Standard; + aVar : CString from Standard); + ---Purpose: Write in file (see OpenFile for the name) the value + -- named + + WriteFileConst(me; aName : CString from Standard; + aValue : Character from Standard); + ---Purpose: Write in file (see OpenFile for the name) the value + -- named + + WriteFileConst(me; aName : CString from Standard; + aValue : Integer from Standard); + ---Purpose: Write in file (see OpenFile for the name) the value + -- named + + WriteFileConst(me; aName : CString from Standard; + aValue : Real from Standard); + ---Purpose: Write in file (see OpenFile for the name) the value + -- named + + CloseFile(me; aName : CString from Standard); + ---Purpose: Close the file named (see OpenFile for the name) + + + AddIncludeDirectory(me; aDirectory : CString from Standard); + ---Purpose: Add a directory to the EDL file search list + -- for the @uses command + + RemoveIncludeDirectory(me; aDirectory : CString from Standard); + ---Purpose: Remove a directory from the EDL file search list + -- for the @uses command + + GetIncludeDirectory(me) + returns mutable HSequenceOfAsciiString from TColStd; + ---Purpose: return the directory list + + GetTemplateIterator(me) + returns DataMapIteratorOfMapOfTemplate from EDL; + + GetVariableIterator(me) + returns DataMapIteratorOfMapOfVariable from EDL; + + ClearVariables(me); + ---Purpose: Destroy all variables. + + ClearTemplates(me); + ---Purpose: Destroy all templates. + + ClearIncludes(me); + ---Purpose: Destroy all include directories. + + Execute(me; aFileName : CString from Standard) + returns Error from EDL; + ---Purpose: Execute the EDL file . + + fields + + myInter : Interpretor from EDL; + + end; diff --git a/src/EDL/EDL_API.cxx b/src/EDL/EDL_API.cxx new file mode 100755 index 0000000..0a5f2a3 --- /dev/null +++ b/src/EDL/EDL_API.cxx @@ -0,0 +1,289 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +EDL_API::EDL_API() +{ + myInter = new EDL_Interpretor; +} + +EDL_Error EDL_API::Openlib(const Standard_CString aName) const +{ + EDL_Error result; + + result = myInter->AddLibrary(aName); + + return result; +} + +EDL_Error EDL_API::Call(const Standard_CString aLibName, + const Standard_CString aFunction, + const Handle(TColStd_HSequenceOfHAsciiString)& anArgList) const +{ + EDL_Error result; + Standard_Integer i; + + for (i = 1; i <= anArgList->Length(); i++) { + if (anArgList->Value(i)->Value(1) == '%') { + myInter->AddToArgList(anArgList->Value(i)->ToCString()); + } + else { + myInter->AddToArgList(".",anArgList->Value(i)->ToCString()); + } + } + + result = myInter->CallFunction(aLibName,aFunction,0L); + + return result; +} + +void EDL_API::Closelib(const Standard_CString aName) const +{ + myInter->RemoveLibrary(aName); +} + +void EDL_API::AddTemplate(const Standard_CString aName, + const Handle(TColStd_HSequenceOfHAsciiString)& aDefinition, + const Handle(TColStd_HSequenceOfHAsciiString)& aVarList) const +{ + Standard_Integer i; + + myInter->AddTemplate(aName); + + for (i = 1; i <= aDefinition->Length(); i++) { + myInter->GetTemplate(aName).AddLine(aDefinition->Value(i)->ToCString()); + } + + myInter->GetTemplate(aName).VariableList(aVarList); +} + +void EDL_API::Apply(const Standard_CString aResult, + const Standard_CString aName) const +{ + Standard_Integer i; + EDL_Template& atemp = myInter->GetTemplate(aName); + Handle(TColStd_HSequenceOfHAsciiString) theVariable = atemp.GetVariableList(); + + for (i = 1; i <= theVariable->Length(); i++) { + myInter->AddToVariableList(theVariable->Value(i)->ToCString()); + } + + myInter->EvalTemplate(aName,aResult); + myInter->ClearVariableList(); +} + +void EDL_API::RemoveTemplate(const Standard_CString aName) const +{ + myInter->RemoveTemplate(aName); +} + +EDL_Template& EDL_API::GetTemplate(const Standard_CString aName) const +{ + if (aName != NULL) { + return myInter->GetTemplate(aName); + } + else { + Standard_NullObject::Raise("EDL_API::GetTemplate - aName is NULL"); + } + return myInter->GetTemplate(aName); + +} + +void EDL_API::AddVariable(const Standard_CString aName, + const Standard_CString aValue) const +{ + myInter->AddVariable(aName,aValue); +} + +void EDL_API::AddVariable(const Standard_CString aName, + const Standard_Integer aValue) const +{ + Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString(aValue); + + myInter->AddVariable(aName,str->ToCString()); +} + +void EDL_API::AddVariable(const Standard_CString aName, + const Standard_Real aValue) const +{ + Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString(aValue); + + myInter->AddVariable(aName,str->ToCString()); +} + +void EDL_API::AddVariable(const Standard_CString aName, + const Standard_Character aValue) const +{ + char str[2]; + + str[0] = (char)aValue; + str[1] = '\0'; + + myInter->AddVariable(aName,str); +} + +EDL_Variable& EDL_API::GetVariable(const Standard_CString aName) const +{ + if (aName != NULL) { + return myInter->GetVariable(aName); + } + else { + Standard_NullObject::Raise("EDL_API::GetVariable - aName is NULL"); + } + return myInter->GetVariable(aName); +} + +Handle(TCollection_HAsciiString) EDL_API::GetVariableValue(const Standard_CString aName) const +{ + Handle(TCollection_HAsciiString) result; + + result = new TCollection_HAsciiString(myInter->GetVariable(aName).GetValue()); + + return result; +} + +void EDL_API::RemoveVariable(const Standard_CString aName) const +{ + myInter->RemoveVariable(aName); +} + +Standard_Boolean EDL_API::IsDefined(const Standard_CString aName) const +{ + return myInter->IsDefined(aName); +} + +EDL_Error EDL_API::OpenFile(const Standard_CString aName, + const Standard_CString aPath) const +{ + EDL_Error result; + Standard_CString thePath; + EDL_ParameterMode OldMode = myInter->GetParameterType(); + + if (aPath[0] == '%') { + thePath = myInter->GetVariable(aPath).GetValue(); + } + else { + thePath = aPath; + } + + myInter->SetParameterType(EDL_STRING); + result = myInter->AddFile(aName,thePath); + myInter->SetParameterType(OldMode); + + return result; +} + +void EDL_API::WriteFile(const Standard_CString aName, + const Standard_CString aVar) const +{ + myInter->GetFile(aName).Write(myInter->GetVariable(aVar).GetValue()); +} + +void EDL_API::WriteFileConst(const Standard_CString aName, + const Standard_CString aValue) const +{ + if (aValue != 0L) { + myInter->GetFile(aName).Write(aValue); + } +} + +void EDL_API::WriteFileConst(const Standard_CString aName, + const Standard_Character aValue) const +{ + char str[2]; + + str[0] = (char)aValue; + str[1] = '\0'; + + myInter->GetFile(aName).Write(str); +} + +void EDL_API::WriteFileConst(const Standard_CString aName, + const Standard_Integer aValue) const +{ + Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString(aValue); + + myInter->GetFile(aName).Write(str->ToCString()); +} + +void EDL_API::WriteFileConst(const Standard_CString aName, + const Standard_Real aValue) const +{ + Handle(TCollection_HAsciiString) str = new TCollection_HAsciiString(aValue); + + myInter->GetFile(aName).Write(str->ToCString()); +} + +void EDL_API::CloseFile(const Standard_CString aName) const +{ + myInter->GetFile(aName).Close(); + myInter->RemoveFile(aName); +} + +void EDL_API::AddIncludeDirectory(const Standard_CString aDirectory) const +{ + myInter->AddIncludeDirectory(aDirectory); +} + +void EDL_API::RemoveIncludeDirectory(const Standard_CString aDirectory) const +{ + Handle(TColStd_HSequenceOfAsciiString) aSeq = myInter->GetIncludeDirectory(); + Standard_Integer i; + Standard_Boolean IsFound = Standard_False; + + for (i = 1; i <= aSeq->Length() && !IsFound; i++) { + if (aSeq->Value(i).IsEqual(aDirectory)) { + IsFound = Standard_True; + aSeq->Remove(i); + } + } +} + +Handle(TColStd_HSequenceOfAsciiString) EDL_API::GetIncludeDirectory() const +{ + return myInter->GetIncludeDirectory(); +} + +EDL_DataMapIteratorOfMapOfVariable EDL_API::GetVariableIterator() const +{ + return myInter->GetVariableIterator(); +} + +EDL_DataMapIteratorOfMapOfTemplate EDL_API::GetTemplateIterator() const +{ + return myInter->GetTemplateIterator(); +} + +void EDL_API::ClearVariables() const +{ + myInter->ClearSymbolTable(); +} + +void EDL_API::ClearTemplates() const +{ + myInter->ClearTemplateTable(); +} + +void EDL_API::ClearIncludes() const +{ + myInter->GetIncludeDirectory()->Clear(); +} + +EDL_Error EDL_API::Execute(const Standard_CString aFileName) const +{ + EDL_Error result; + + result = myInter->Parse(aFileName); + + return result; +} + diff --git a/src/EDL/EDL_CMPLRS.edl b/src/EDL/EDL_CMPLRS.edl new file mode 100755 index 0000000..3b031e2 --- /dev/null +++ b/src/EDL/EDL_CMPLRS.edl @@ -0,0 +1,14 @@ +-- File: EDL_CMPLRS.edl +-- Author: Jean GAUTIER +-- History: Thu Dec 4 16:22:56 1997 Jean GAUTIER Creation +-- Copyright: Matra Datavision 1997 + +@ifnotdefined ( %EDL_CMPLRS_EDL) then +@set %EDL_CMPLRS_EDL = ""; + +@if ( %Station == "hp" ) then +@string %CMPLRS_C_Options = " -Ae "; +@endif; + + +@endif; diff --git a/src/EDL/EDL_File.cdl b/src/EDL/EDL_File.cdl new file mode 100755 index 0000000..6935aeb --- /dev/null +++ b/src/EDL/EDL_File.cdl @@ -0,0 +1,45 @@ +-- File: EDL_File.cdl +-- Created: Fri Jun 9 12:15:36 1995 +-- Author: Christophe LEYNADIER +-- +---Copyright: Matra Datavision 1995 + +class File from EDL +uses HAsciiString from TCollection +is + + Create + returns File from EDL; + + Create(aName : CString from Standard) + returns File from EDL; + + Assign(me : out; aFile : File from EDL); + ---C++: alias operator = + + Destroy(me : out); + ---C++: alias ~ + + GetName(me) + returns CString from Standard; + + Open(me : out) + returns Boolean from Standard; + + Write(me : out; aBuffer : CString from Standard); + + Read(me) + returns CString from Standard; + + Close(me : out); + + GetFile(me) + returns Address from Standard; + + +fields + + myName : HAsciiString from TCollection; + myFile : Address from Standard; + +end; diff --git a/src/EDL/EDL_File.cxx b/src/EDL/EDL_File.cxx new file mode 100755 index 0000000..0784e52 --- /dev/null +++ b/src/EDL/EDL_File.cxx @@ -0,0 +1,75 @@ +#include +#include + +EDL_File::EDL_File() +{ + myFile = NULL; +} + +EDL_File::EDL_File(const Standard_CString aName) +{ + myFile = NULL; + + if (aName != NULL) { + myName = new TCollection_HAsciiString(aName); + } +} + +void EDL_File::Assign(const EDL_File& aFile) +{ + if (aFile.GetName() != NULL) { + myName = new TCollection_HAsciiString(aFile.GetName()); + } + + myFile = aFile.GetFile(); +} + +void EDL_File::Destroy() +{ +} + +Standard_CString EDL_File::GetName() const +{ + return myName->ToCString(); +} + +Standard_Boolean EDL_File::Open() +{ + Standard_Boolean aResult = Standard_False; + + if (!myName.IsNull()) { + myFile = (Standard_Address)fopen(myName->ToCString(),"w"); + + if (myFile != NULL) { + aResult = Standard_True; + } + } + + return aResult; +} + +void EDL_File::Write(const Standard_CString aBuffer) +{ + if (myFile != NULL) { + fprintf((FILE*)myFile,"%s",aBuffer); + } +} + +Standard_CString EDL_File::Read() const +{ + return NULL; +} + +void EDL_File::Close() +{ + if (myFile != NULL) { + fclose((FILE*)myFile); + myFile = NULL; + } +} + +Standard_Address EDL_File::GetFile() const +{ + return myFile; +} + diff --git a/src/EDL/EDL_FunctionSignature.hxx b/src/EDL/EDL_FunctionSignature.hxx new file mode 100755 index 0000000..addc432 --- /dev/null +++ b/src/EDL/EDL_FunctionSignature.hxx @@ -0,0 +1,6 @@ +#ifndef _EDL_FunctionSignature_HeaderFile +#define _EDL_FunctionSignature_HeaderFile +#include +#define EDL_FUNCTION(name) extern "C" EDL_Variable name( const int argc,const EDL_Variable*argv) +typedef EDL_Variable (*EDL_FunctionSignature)(const int,const EDL_Variable*); +#endif diff --git a/src/EDL/EDL_Interpretor.cdl b/src/EDL/EDL_Interpretor.cdl new file mode 100755 index 0000000..b1634fe --- /dev/null +++ b/src/EDL/EDL_Interpretor.cdl @@ -0,0 +1,149 @@ +-- File: EDL_Interpretor.cdl +-- Created: Tue Jun 13 10:35:35 1995 +-- Author: Christophe LEYNADIER +-- +---Copyright: Matra Datavision 1995 + +private class Interpretor from EDL + +inherits TShared from MMgt + +uses AsciiString from TCollection, + MapOfVariable from EDL, + HSequenceOfAsciiString from TColStd, + MapOfTemplate from EDL, + MapOfFile from EDL, + MapOfLibrary from EDL, + StackOfBoolean from EDL, + HSequenceOfVariable from EDL, + Error from EDL, + ParameterMode from EDL, + File from EDL, + Variable from EDL, + Template from EDL, + Library from EDL, + DataMapIteratorOfMapOfTemplate from EDL, + DataMapIteratorOfMapOfVariable from EDL + +is + + Create returns mutable Interpretor from EDL; + + ClearAll(me : mutable); + ---C++: alias ~ + + ClearSymbolTable(me : mutable); + + ClearTemplateTable(me : mutable); + + ClearVariableList(me : mutable); + + ClearArgList(me : mutable); + + ClearRetList(me : mutable); + + Parse(me : mutable; aFile : CString from Standard) + returns Error from EDL; + + AddIncludeDirectory(me : mutable; aDirectory : CString from Standard) + returns Error from EDL; + GetIncludeDirectory(me) + returns mutable HSequenceOfAsciiString from TColStd; + + AddFile(me : mutable; aVariable : CString from Standard; aFilename : CString from Standard) + returns Error from EDL; + GetFile(me : mutable; aVariable : CString from Standard) + returns File from EDL; + ---C++: return & + + RemoveFile(me : mutable; aVariable : CString from Standard); + + AddVariable(me : mutable; aVariable : CString from Standard; aValue : CString from Standard) + returns Error from EDL; + GetVariable(me : mutable; aVariable : CString from Standard) + returns Variable from EDL; + ---C++: return & + IsDefined(me; aVariable : CString from Standard) + returns Boolean from Standard; + + IsFile(me; aVariable : CString from Standard) + returns Boolean from Standard; + + RemoveVariable(me : mutable; aVariable : CString from Standard); + + AddTemplate(me : mutable; aTemplate : CString from Standard) + returns Error from EDL; + AddToTemplate(me : mutable; aTemplate : CString from Standard) + returns Error from EDL; + ClearTemplate(me : mutable; aTemplate : CString from Standard) + returns Error from EDL; + GetTemplate(me : mutable; aTemplate : CString from Standard) + returns Template from EDL; + ---C++: return & + EvalTemplate(me : mutable; aTemplate : CString from Standard; aResult : CString from Standard); + RemoveTemplate(me : mutable; aTemplate : CString from Standard); + + AddLibrary(me : mutable; aLibrary : CString from Standard) + returns Error from EDL; + GetLibrary(me : mutable; aLibrary : CString from Standard) + returns Library from EDL; + ---C++: return & + + CallFunction(me : mutable; aLibname : CString from Standard; aFunction : CString from Standard; aRetuenName : CString from Standard) + returns Error from EDL; + + RemoveLibrary(me : mutable; aLibrary : CString from Standard); + + AddExecutionStatus(me : mutable; aValue : Boolean from Standard); + GetExecutionStatus(me : mutable) + returns Boolean from Standard; + RemoveExecutionStatus(me : mutable) + returns Boolean from Standard; + + SetParameterType(me : mutable; aMode : ParameterMode from EDL); + GetParameterType(me) + returns ParameterMode from EDL; + + AddExpressionMember(me : mutable; aValue : Boolean from Standard); + GetExpressionMember(me : mutable) + returns Boolean from Standard; + + SetPrintList(me : mutable; aValue : CString from Standard); + GetPrintList(me : mutable) + returns AsciiString from TCollection; + ---C++: return & + + SetCurrentTemplate(me : mutable; aValue : CString from Standard); + GetCurrentTemplate(me : mutable) + returns AsciiString from TCollection; + ---C++: return & + + AddToVariableList(me : mutable; aVariable : CString from Standard); + GetVariableList(me) + returns mutable HSequenceOfVariable from EDL; + + AddToArgList(me : mutable; aVariable : CString from Standard); + AddToArgList(me : mutable; aVariable : CString from Standard; aValue : CString from Standard); + + GetTemplateIterator(me) + returns DataMapIteratorOfMapOfTemplate from EDL; + + GetVariableIterator(me) + returns DataMapIteratorOfMapOfVariable from EDL; + +fields + mySymbolTable : MapOfVariable from EDL; + myIncludeTable : HSequenceOfAsciiString from TColStd; + myTemplateTable : MapOfTemplate from EDL; + myFileTable : MapOfFile from EDL; + myLibraryTable : MapOfLibrary from EDL; + myExecutionStatus : StackOfBoolean from EDL; + myParameterType : ParameterMode from EDL; + myExpressionMember : StackOfBoolean from EDL; + myPrintList : AsciiString from TCollection; + myCurrentTemplate : AsciiString from TCollection; + myVariableList : HSequenceOfVariable from EDL; + myArgList : HSequenceOfVariable from EDL; + myRetList : HSequenceOfVariable from EDL; + +end; diff --git a/src/EDL/EDL_Interpretor.cxx b/src/EDL/EDL_Interpretor.cxx new file mode 100755 index 0000000..fe96eb9 --- /dev/null +++ b/src/EDL/EDL_Interpretor.cxx @@ -0,0 +1,1734 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +extern "C" { +#include +} + +#include + +#ifdef WNT +#include +#else +#include +#endif + + +extern "C" {EDLparse();} +extern "C" {EDLlex();} +extern "C" {void EDL_SetFile();} + +#ifndef WNT +extern FILE *EDLin; +extern int EDLlineno; +extern char *EDLtext; +extern char FileName[][256]; +extern numFileDesc; +#else +extern "C" FILE *EDLin; +extern "C" int EDLlineno; +extern "C" char *EDLtext; +extern "C" char FileName[][256]; +extern "C" numFileDesc; +#endif // WNT + +extern "C" { + void EDLerror(char* err,char *arg) { + EDL::PrintError(EDL_SYNTAXERROR," "); + Standard_NullObject::Raise(); + } +} + +EDL_Interpretor *GlobalInter = NULL; + +TCollection_AsciiString EDL_CurrentFile; + +// Class EDL_Interpretor +// +EDL_Interpretor::EDL_Interpretor() +{ + myIncludeTable = new TColStd_HSequenceOfAsciiString; + myIncludeTable->Append("."); + + myVariableList = new EDL_HSequenceOfVariable; + + myArgList = new EDL_HSequenceOfVariable; + + myRetList = new EDL_HSequenceOfVariable; + + myParameterType = EDL_VARIABLE; +} + +void EDL_Interpretor::ClearAll() +{ + mySymbolTable.Clear(); + + if (!myIncludeTable.IsNull()) { + myIncludeTable->Clear(); + } + + if (!myIncludeTable.IsNull()) { + myIncludeTable->Append("."); + } + + myTemplateTable.Clear(); + myFileTable.Clear(); + myLibraryTable.Clear(); + myExecutionStatus.Clear(); + myParameterType = EDL_VARIABLE; + myExpressionMember.Clear(); + myPrintList.Clear(); + myCurrentTemplate.Clear(); + + if (!myVariableList.IsNull()) { + myVariableList->Clear(); + } + + if (!myArgList.IsNull()) { + myArgList->Clear(); + } + + if (!myRetList.IsNull()) { + myRetList->Clear(); + } +} + +void EDL_Interpretor::ClearSymbolTable() +{ + mySymbolTable.Clear(); +} + +void EDL_Interpretor::ClearTemplateTable() +{ + myTemplateTable.Clear(); +} + +void EDL_Interpretor::ClearVariableList() +{ + myVariableList->Clear(); +} + +void EDL_Interpretor::ClearArgList() +{ + myArgList->Clear(); +} + +void EDL_Interpretor::ClearRetList() +{ + myRetList->Clear(); +} + +extern "C" { + void EDLrestart(FILE *); +} + +EDL_Error EDL_Interpretor::Parse(const Standard_CString aFile) +{ + GlobalInter = this; + Standard_Boolean IsFound = Standard_False; + Standard_Integer DirCount = 1, + LenName = strlen(aFile); + + Handle(TColStd_HSequenceOfAsciiString) IncludeDirectory = GlobalInter->GetIncludeDirectory(); + + if (aFile != NULL) { + FILE *fic = 0L; + DirCount = 1; + + if (fic = fopen(aFile,"r")) { + IsFound = Standard_True; + } + + while (!IsFound && DirCount <= IncludeDirectory->Length()) { + static char tmpName[1024]; + const TCollection_AsciiString& adir = IncludeDirectory->Value(DirCount); + memcpy(tmpName, adir.ToCString(), adir.Length()); + tmpName[adir.Length()] = '/'; + strcpy(&(tmpName[adir.Length()+1]),aFile); + +#ifndef WNT + if( !access(tmpName, F_OK) ) +#else + if ( GetFileAttributes(tmpName) != 0xFFFFFFFF ) +#endif + { + if (fic = fopen(tmpName,"r")) { + IsFound = Standard_True; + } + } + + //delete [] tmpName; + DirCount++; + } + + if (fic) { + edlstring edlstr; + edlstr.str = aFile; + edlstr.length = strlen(aFile); + EDL_SetCurrentFile(edlstr); + EDLin = fic; + EDLlineno = 1; + numFileDesc = -1; + EDLrestart(EDLin); + EDLparse(); + + fclose(fic); + } + else { + return EDL_FILEOPENED; + } + + EDLlineno = -1; + } + else { + return EDL_FILEOPENED; + } + + GlobalInter = NULL; + + return EDL_NORMAL; +} + +EDL_Error EDL_Interpretor::AddIncludeDirectory(const Standard_CString aDirectory) +{ + TCollection_AsciiString aDir(aDirectory); + + myIncludeTable->Append(aDir); + + return EDL_NORMAL; +} + +Handle(TColStd_HSequenceOfAsciiString) EDL_Interpretor::GetIncludeDirectory() const +{ + return myIncludeTable; +} + +EDL_Error EDL_Interpretor::AddFile(const Standard_CString aVariable, const Standard_CString filename) +{ + TCollection_AsciiString anAscName(aVariable); + char *realFilename = filename; + + // we can open a file with a name defined by a string or a variable + // + if (myParameterType == EDL_VARIABLE) { + TCollection_AsciiString aFileName(filename); + + if (mySymbolTable.IsBound(aFileName)) { + realFilename = mySymbolTable.Find(aFileName).GetValue(); + } + else { + EDL::PrintError(EDL_VARNOTFOUND,filename); + return EDL_VARNOTFOUND; + } + } + + if (myFileTable.IsBound(anAscName)) { + EDL::PrintError(EDL_FILEOPENED,aVariable); + return EDL_FILEOPENED; + } + else { + EDL_File aFile(realFilename); + + if (aFile.Open()) { + myFileTable.Bind(anAscName,aFile); + } + else { + EDL::PrintError(EDL_FILENOTOPENED,realFilename); + return EDL_FILENOTOPENED; + } + } + + return EDL_NORMAL; +} + +EDL_File& EDL_Interpretor::GetFile(const Standard_CString aVariable) +{ + TCollection_AsciiString anAscName(aVariable); + + if (myFileTable.IsBound(anAscName)) { + return myFileTable.ChangeFind(anAscName); + } + else { + // Raise + // + EDL::PrintError(EDL_FILENOTOPENED,aVariable); + Standard_NoSuchObject::Raise(); + } + return myFileTable.ChangeFind(anAscName); +} + +void EDL_Interpretor::RemoveFile(const Standard_CString aVariable) +{ + TCollection_AsciiString anAscName(aVariable); + + if (myFileTable.IsBound(anAscName)) { + myFileTable.UnBind(anAscName); + } + else { + // Raise + // + EDL::PrintError(EDL_FILENOTOPENED,aVariable); + Standard_NoSuchObject::Raise(); + } +} + +EDL_Error EDL_Interpretor::AddVariable(const Standard_CString aVariable, const Standard_CString aValue) +{ + if (aVariable != NULL && aValue != NULL) { + TCollection_AsciiString anAscName(aVariable); + + if (aVariable[0] != '%') { + // Raise + // + anAscName.AssignCat(" : wrong indirection..."); + EDL::PrintError(EDL_VARNOTFOUND,anAscName.ToCString()); + Standard_NoSuchObject::Raise(); + } + + if (mySymbolTable.IsBound(anAscName)) { + mySymbolTable.ChangeFind(anAscName).SetValue(aValue); + } + else { + EDL_Variable aVar(aVariable,aValue); + mySymbolTable.Bind(anAscName,aVar); + } + } + else { + return EDL_SYNTAXERROR; + } + + return EDL_NORMAL; +} + +EDL_Variable& EDL_Interpretor::GetVariable(const Standard_CString aVariable) +{ + if (aVariable != NULL) { + + TCollection_AsciiString anAscName(aVariable); + + if (mySymbolTable.IsBound(anAscName)) { + return mySymbolTable.ChangeFind(anAscName); + } + else { + // Raise + // + EDL::PrintError(EDL_VARNOTFOUND,aVariable); + Standard_NoSuchObject::Raise(); + } + } + else { + // Raise + EDL::PrintError(EDL_VARNOTFOUND,aVariable); + Standard_NullObject::Raise(); + } + return mySymbolTable.ChangeFind(TCollection_AsciiString ()); +} + +Standard_Boolean EDL_Interpretor::IsDefined(const Standard_CString aVariable) const +{ + if (aVariable != NULL) { + + TCollection_AsciiString anAscName(aVariable); + + if (mySymbolTable.IsBound(anAscName) ||myTemplateTable.IsBound(anAscName)) { + return Standard_True; + } + else { + return Standard_False; + } + } + else { + return Standard_False; + } +} + +Standard_Boolean EDL_Interpretor::IsFile(const Standard_CString aFileName) const +{ + if (aFileName != NULL) { + + TCollection_AsciiString fname(aFileName); + + Standard_Boolean IsFound = Standard_False; + Standard_Integer DirCount = 1, + LenName = fname.Length(); + + Handle(TColStd_HSequenceOfAsciiString) IncludeDirectory = GetIncludeDirectory(); + + DirCount = 1; + while (!IsFound && DirCount <= IncludeDirectory->Length()) { + static char tmpName[1024]; + const TCollection_AsciiString& adir = IncludeDirectory->Value(DirCount); + memcpy(tmpName, adir.ToCString(), adir.Length()); + tmpName[adir.Length()] = '/'; + strcpy(&(tmpName[adir.Length()+1]),aFileName); + +#ifndef WNT + if( !access(tmpName, F_OK) ) +#else + if ( GetFileAttributes(tmpName) != 0xFFFFFFFF ) +#endif + { + IsFound = Standard_True; + } + DirCount++; + } + return IsFound; + } + else { + return Standard_False; + } +} + +void EDL_Interpretor::RemoveVariable(const Standard_CString aVariable) +{ + if (aVariable != NULL) { + TCollection_AsciiString anAscName(aVariable); + + if (mySymbolTable.IsBound(anAscName)) { + mySymbolTable.UnBind(anAscName); + } + else { + // Raise + // + EDL::PrintError(EDL_VARNOTFOUND,aVariable); + Standard_NoSuchObject::Raise(); + } + } + else { + // Raise + EDL::PrintError(EDL_VARNOTFOUND,aVariable); + Standard_NullObject::Raise(); + } +} + +EDL_Error EDL_Interpretor::AddTemplate(const Standard_CString aTemplate) +{ + if (aTemplate != NULL) { + myCurrentTemplate = aTemplate; + + if (myTemplateTable.IsBound(myCurrentTemplate)) { + myTemplateTable.UnBind(myCurrentTemplate); + } + + EDL_Template aTmp(aTemplate); + myTemplateTable.Bind(myCurrentTemplate,aTmp); + } + else { + // Raise + // + Standard_NullObject::Raise(); + } + + return EDL_NORMAL; +} + +EDL_Error EDL_Interpretor::AddToTemplate(const Standard_CString aTemplate) +{ + if (aTemplate != NULL) { + + if (myTemplateTable.IsBound(myCurrentTemplate)) { + myCurrentTemplate = aTemplate; + } + else { + EDL::PrintError(EDL_TEMPLATENOTDEFINED,aTemplate); + Standard_NoSuchObject::Raise(); + } + } + else { + // Raise + // + Standard_NullObject::Raise(); + } + + return EDL_NORMAL; +} +EDL_Error EDL_Interpretor::ClearTemplate(const Standard_CString aTemplate) +{ + if (aTemplate != NULL) { + TCollection_AsciiString TmpName(aTemplate); + + if (myTemplateTable.IsBound(TmpName)) { + myTemplateTable.ChangeFind(TmpName).ClearLines(); + } + else { + EDL::PrintError(EDL_TEMPLATENOTDEFINED,aTemplate); + Standard_NoSuchObject::Raise(); + } + } + else { + // Raise + // + Standard_NullObject::Raise(); + } + + return EDL_NORMAL; +} + +EDL_Template& EDL_Interpretor::GetTemplate(const Standard_CString aTemplate) +{ + if (aTemplate != NULL) { + TCollection_AsciiString TmpName(aTemplate); + + if (myTemplateTable.IsBound(TmpName)) { + return myTemplateTable.ChangeFind(TmpName); + } + else { + EDL::PrintError(EDL_TEMPLATENOTDEFINED,aTemplate); + Standard_NoSuchObject::Raise(); + } + } + else { + // Raise + // + Standard_NullObject::Raise(); + } + return myTemplateTable.ChangeFind(TCollection_AsciiString()); +} + +EDL_DataMapIteratorOfMapOfTemplate EDL_Interpretor::GetTemplateIterator() const +{ + EDL_DataMapIteratorOfMapOfTemplate amapi(myTemplateTable); + + return amapi; +} + +EDL_DataMapIteratorOfMapOfVariable EDL_Interpretor::GetVariableIterator() const +{ + EDL_DataMapIteratorOfMapOfVariable amapi(mySymbolTable); + + return amapi; +} + +void EDL_Interpretor::EvalTemplate(const Standard_CString aTemplate, const Standard_CString aResult) +{ + TCollection_AsciiString anAscName(aTemplate); + + myTemplateTable.ChangeFind(anAscName).Eval(myVariableList); + + Handle(TColStd_HSequenceOfAsciiString) aNewResult = myTemplateTable.Find(anAscName).GetEval(); + Standard_CString aValue; + Standard_Integer nbByte = 0, + i; + for (i = 1; i <= aNewResult->Length(); i++) { + nbByte = nbByte + aNewResult->Value(i).Length(); + } + + aValue = (Standard_CString) aStorageManager.Allocate(nbByte + 1); + aValue[0] = '\0'; + Standard_Integer idx=0; + for (i = 1; i <= aNewResult->Length(); i++) { + const TCollection_AsciiString& astr = aNewResult->Value(i); + memcpy(&aValue[idx], astr.ToCString(), astr.Length()); + idx += astr.Length(); + } + aValue[nbByte] = '\0'; + + AddVariable(aResult,aValue); + + aStorageManager.Free((void*&)aValue, nbByte + 1); +} + +void EDL_Interpretor::RemoveTemplate(const Standard_CString aTemplate) +{ + if (aTemplate != NULL) { + TCollection_AsciiString TmpName(aTemplate); + + if (myTemplateTable.IsBound(TmpName)) { + myTemplateTable.UnBind(TmpName); + } + } + else { + // Raise + // + Standard_NullObject::Raise(); + } +} + +EDL_Error EDL_Interpretor::AddLibrary(const Standard_CString aLibrary) +{ + if (aLibrary != NULL) { + TCollection_AsciiString anAscName(aLibrary); + + if (myLibraryTable.IsBound(anAscName)) { + } + else { + EDL_Library aLib(aLibrary); + char *aStatus = aLib.GetStatus(); + + if (aStatus != NULL) { + EDL::PrintError(EDL_LIBNOTOPEN,aStatus); + return EDL_LIBNOTOPEN; + } + else { + myLibraryTable.Bind(anAscName,aLib); + } + } + } + else { + // Raise + // + Standard_NullObject::Raise(); + } + return EDL_LIBNOTOPEN; +} + +EDL_Library& EDL_Interpretor::GetLibrary(const Standard_CString aLibrary) +{ + if (aLibrary != NULL) { + TCollection_AsciiString aName(aLibrary); + + if (myLibraryTable.IsBound(aName)) { + return myLibraryTable.ChangeFind(aName); + } + else { + // Raise + // + Standard_NoSuchObject::Raise(); + } + } + else { + // Raise + // + Standard_NullObject::Raise(); + } + return myLibraryTable.ChangeFind(TCollection_AsciiString()); +} + +EDL_Error EDL_Interpretor::CallFunction(const Standard_CString libname, const Standard_CString funcname, const Standard_CString returnName) +{ + if (libname != NULL) { + TCollection_AsciiString anAscName(libname); + + if (!myLibraryTable.IsBound(anAscName)) { + EDL::PrintError(EDL_LIBRARYNOTFOUND,libname); + return EDL_LIBRARYNOTFOUND; + } + else { + OSD_Function aFunc = myLibraryTable.Find(anAscName).GetSymbol(funcname); + + if (aFunc == NULL) { + EDL::PrintError(EDL_FUNCTIONNOTFOUND,funcname); + return EDL_FUNCTIONNOTFOUND; + } + else { + EDL_Variable* argv = new EDL_Variable[myArgList->Length()]; + EDL_Variable returnVar; + Standard_Integer argc = myArgList->Length(); + Standard_Integer i; + + for (i = 0; i < argc; i++) { + argv[i] = myArgList->Value(i+1); + } + + if (returnName != 0L) { + EDL_FunctionSignature aFFunc = (EDL_FunctionSignature)aFunc; + returnVar = (*aFFunc)(argc,argv); + AddVariable(returnName,returnVar.GetValue()); + } + else { + EDL_ProcedureSignature aFFunc = (EDL_ProcedureSignature)aFunc; + (*aFFunc)(argc,argv); + } + + delete [] argv; + myArgList->Clear(); + myRetList->Clear(); + } + } + } + + return EDL_NORMAL; +} + +void EDL_Interpretor::RemoveLibrary(const Standard_CString aLibrary) +{ + if (aLibrary != NULL) { + TCollection_AsciiString aName(aLibrary); + + if (myLibraryTable.IsBound(aName)) { + myLibraryTable.UnBind(aName); + } + else { + // Raise + // + EDL::PrintError(EDL_LIBRARYNOTFOUND,aLibrary); + Standard_NoSuchObject::Raise(); + } + } + else { + // Raise + // + Standard_NullObject::Raise(); + } +} + +void EDL_Interpretor::AddExecutionStatus(const Standard_Boolean aValue) +{ + myExecutionStatus.Push(aValue); +} + +Standard_Boolean EDL_Interpretor::RemoveExecutionStatus() +{ + Standard_Boolean aResult; + + if (!myExecutionStatus.IsEmpty()) { + aResult = myExecutionStatus.Top(); + myExecutionStatus.Pop(); + } + else { + aResult = Standard_True; + } + + return aResult; +} + +Standard_Boolean EDL_Interpretor::GetExecutionStatus() +{ + Standard_Boolean aResult; + + if (!myExecutionStatus.IsEmpty()) { + aResult = myExecutionStatus.Top(); + } + else { + aResult = Standard_True; + } + + return aResult; +} + +void EDL_Interpretor::SetParameterType(const EDL_ParameterMode aMode) +{ + myParameterType = aMode; +} + +EDL_ParameterMode EDL_Interpretor::GetParameterType() const +{ + return myParameterType; +} + +void EDL_Interpretor::AddExpressionMember(const Standard_Boolean aValue) +{ + myExpressionMember.Push(aValue); +} + +Standard_Boolean EDL_Interpretor::GetExpressionMember() +{ + Standard_Boolean aResult = myExpressionMember.Top(); + + myExpressionMember.Pop(); + + return aResult; +} + +void EDL_Interpretor::SetPrintList(const Standard_CString aValue) +{ + if (aValue != NULL) { + myPrintList = aValue; + } + else { + myPrintList.Clear(); + } +} + +TCollection_AsciiString& EDL_Interpretor::GetPrintList() +{ + return myPrintList; +} + +void EDL_Interpretor::SetCurrentTemplate(const Standard_CString aValue) +{ + if (aValue != NULL) { + myCurrentTemplate = aValue; + } + else { + myCurrentTemplate.Clear(); + } +} + +TCollection_AsciiString& EDL_Interpretor::GetCurrentTemplate() +{ + return myCurrentTemplate; +} + +void EDL_Interpretor::AddToVariableList(const Standard_CString aVariable) +{ + if (aVariable != NULL) { + TCollection_AsciiString aVar(aVariable); + + if (!mySymbolTable.IsBound(aVar)) { + EDL::PrintError(EDL_VARNOTFOUND,aVariable); + // Raise + // + Standard_NoSuchObject::Raise(); + } + else { + myVariableList->Append(mySymbolTable.Find(aVar)); + } + } + else { + // Raise + // + Standard_NullObject::Raise(); + } +} + +Handle(EDL_HSequenceOfVariable) EDL_Interpretor::GetVariableList() const +{ + return myVariableList; +} + +void EDL_Interpretor::AddToArgList(const Standard_CString aVariable) +{ + if (aVariable != NULL) { + TCollection_AsciiString aVar(aVariable); + + if (!mySymbolTable.IsBound(aVar)) { + EDL::PrintError(EDL_VARNOTFOUND,aVariable); + // Raise + // + Standard_NoSuchObject::Raise(); + } + else { + myArgList->Append(mySymbolTable.Find(aVar)); + } + } + else { + // Raise + // + Standard_NullObject::Raise(); + } +} + +void EDL_Interpretor::AddToArgList(const Standard_CString aVariable, const Standard_CString aValue) +{ + EDL_Variable aVar(aVariable,aValue); + myArgList->Append(aVar); +} + +// Implementation +// -------------- + +#ifdef HPUX +#define const +#endif + +// add an includes directory to the table +// +void edl_add_include_directory(const edlstring adirectory) +{ + GlobalInter->AddIncludeDirectory(adirectory.str); + if (adirectory.str) aStorageManager.Free((void*&)adirectory.str, adirectory.length+1); +} + +// set type of parameter to varname +// +void edl_set_varname() +{ + GlobalInter->SetParameterType(EDL_VARIABLE); +} + +// set type of parameter to str +// +void edl_set_str() +{ + GlobalInter->SetParameterType(EDL_STRING); +} + +// answer if a instruction can be executed +// in respect with the execution status stack +// +Standard_Boolean edl_must_execute() +{ + return GlobalInter->GetExecutionStatus(); +} + +// destruction of a variable : +// +void edl_unset_var(const edlstring varname) +{ + if (!edl_must_execute()) return; + + GlobalInter->RemoveVariable(varname.str); +} + +// destruction of a pointer variable : +// +void edl_unset_pvar(const edlstring varname) +{ + if (!edl_must_execute()) return; + char *aString = GlobalInter->GetVariable(varname.str).GetValue(); + + GlobalInter->RemoveVariable(aString); +} + +// assign or creation of a variable : +// if the variable doesnt exist we create it , otherwise we change its value... +// +void edl_set_var(const edlstring varname, const edlstring value) +{ + if (!edl_must_execute()) return; + + GlobalInter->AddVariable(varname.str,value.str); +} + +// assign or creation of a variable with an other variable: +// if the variable doesnt exist we create it , otherwise we change its value... +// +void edl_set_varvar(const edlstring varname, const edlstring value) +{ + if (!edl_must_execute()) return; + + // we need to erase the quote + // + char *aString = GlobalInter->GetVariable(value.str).GetValue(); + + GlobalInter->AddVariable(varname.str,aString); +} + +// assign or creation of a variable with a pointer: +// if the variable doesnt exist we create it , otherwise we change its value... +// +void edl_set_varevalvar(const edlstring varname, const edlstring value) +{ + if (!edl_must_execute()) return; + + // we need to erase the quote + // + char *aVarPointer = GlobalInter->GetVariable(value.str).GetValue(); + char *aString = GlobalInter->GetVariable(aVarPointer).GetValue(); + GlobalInter->AddVariable(varname.str,aString); +} + +// assign or creation of a variable : +// if the variable doesnt exist we create it , otherwise we change its value... +// +void edl_set_pvar(const edlstring varname, const edlstring value) +{ + if (!edl_must_execute()) return; + char *aString = GlobalInter->GetVariable(varname.str).GetValue(); + + GlobalInter->AddVariable(aString,value.str); +} + +// assign or creation of a variable with an other variable: +// if the variable doesnt exist we create it , otherwise we change its value... +// +void edl_set_pvarvar(const edlstring varname, const edlstring value) +{ + if (!edl_must_execute()) return; + + // we need to erase the quote + // + char *aString = GlobalInter->GetVariable(value.str).GetValue(); + char *aString2 = GlobalInter->GetVariable(varname.str).GetValue(); + + GlobalInter->AddVariable(aString2,aString); +} + +// assign or creation of a variable with a pointer: +// if the variable doesnt exist we create it , otherwise we change its value... +// +void edl_set_pvarevalvar(const edlstring varname, const edlstring value) +{ + if (!edl_must_execute()) return; + + // we need to erase the quote + // + char *aVarPointer = GlobalInter->GetVariable(value.str).GetValue(); + char *aString = GlobalInter->GetVariable(aVarPointer).GetValue(); + char *aString2 = GlobalInter->GetVariable(varname.str).GetValue(); + + GlobalInter->AddVariable(aString2,aString); +} + + +// evaluation of an expression like +// rule : (VAR logoperator STR) +// +void edl_test_condition(const edlstring varname, int ope, const edlstring value) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&) varname.str, varname.length+1); + if (value.str) aStorageManager.Free((void*&)value.str, value.length+1); + return; + } + + char *aString1 = GlobalInter->GetVariable(varname.str).GetValue(), + *aString2 = value.str; + + Standard_Integer aResult = strcmp(aString1,aString2); + Standard_Boolean aMember; + + switch (ope) { + case EQ: if (aResult == 0) { + aMember = Standard_True; + } + else { + aMember = Standard_False; + } + break; + case NEQ: if (aResult != 0) { + aMember = Standard_True; + } + else { + aMember = Standard_False; + } + break; + default: + EDLerror("wrong logical operator...",""); + exit(EDL_SYNTAXERROR); + } + + // we add the evaluation of the expression to the stack + // + GlobalInter->AddExpressionMember(aMember); + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + if (value.str) aStorageManager.Free((void*&)value.str, value.length+1); +} + +// evaluation of a complex expression +// rule : (condition [|| &&] expr_operator condition) +// +void edl_eval_local_condition(int ope) +{ + if (!edl_must_execute()) return; + + Standard_Boolean Left,Right,Result; + + Left = GlobalInter->GetExpressionMember(); + Right = GlobalInter->GetExpressionMember(); + + switch (ope) { + case LOGAND: Result = Left && Right; + break; + case LOGOR: Result = Left || Right; + break; + default: EDLerror("wrong logical operator..."," "); + exit(EDL_SYNTAXERROR); + } + + // we add the result of the evaluation to the stack + // + GlobalInter->AddExpressionMember(Result); +} + +// take the results from previous expressions evaluation +// from stack and build a final result +// rule : conditions: condition +// +void edl_eval_condition() +{ + if (!edl_must_execute()) { + GlobalInter->AddExecutionStatus(Standard_False); + } + else { + Standard_Boolean Result = GlobalInter->GetExpressionMember(); + + // add a new level of execution + // + GlobalInter->AddExecutionStatus(Result); + } +} + +void edl_isvardefined(const edlstring varname) +{ + if (!edl_must_execute()) { + GlobalInter->AddExecutionStatus(Standard_False); + } + else { + Standard_Boolean Result = GlobalInter->IsDefined(varname.str); + + // add a new level of execution + // + GlobalInter->AddExecutionStatus(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_isvardefinedm(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + else { + Standard_Boolean Result = GlobalInter->IsDefined(varname.str); + + // add a new member of expression + // + GlobalInter->AddExpressionMember(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_fileexist(const edlstring varname) +{ + if (!edl_must_execute()) { + GlobalInter->AddExecutionStatus(Standard_False); + } + else { + Standard_Boolean Result = GlobalInter->IsFile(varname.str); + + // add a new level of execution + // + GlobalInter->AddExecutionStatus(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_fileexistm(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + else { + Standard_Boolean Result = GlobalInter->IsFile(varname.str); + + // add a new level of execution + // + GlobalInter->AddExpressionMember(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_fileexist_var(const edlstring varname) +{ + if (!edl_must_execute()) { + GlobalInter->AddExecutionStatus(Standard_False); + } + else { + EDL_Variable& aVar = GlobalInter->GetVariable(varname.str); + Standard_Boolean Result = GlobalInter->IsFile(aVar.GetValue()); + + // add a new level of execution + // + GlobalInter->AddExecutionStatus(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_fileexist_varm(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + else { + EDL_Variable& aVar = GlobalInter->GetVariable(varname.str); + Standard_Boolean Result = GlobalInter->IsFile(aVar.GetValue()); + + // add a new level of execution + // + GlobalInter->AddExpressionMember(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_filenotexist(const edlstring varname) +{ + if (!edl_must_execute()) { + GlobalInter->AddExecutionStatus(Standard_False); + } + else { + Standard_Boolean Result = !GlobalInter->IsFile(varname.str); + + // add a new level of execution + // + GlobalInter->AddExecutionStatus(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_filenotexistm(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + else { + Standard_Boolean Result = !GlobalInter->IsFile(varname.str); + + // add a new level of execution + // + GlobalInter->AddExpressionMember(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_filenotexist_var(const edlstring varname) +{ + if (!edl_must_execute()) { + GlobalInter->AddExecutionStatus(Standard_False); + } + else { + EDL_Variable& aVar = GlobalInter->GetVariable(varname.str); + Standard_Boolean Result = !GlobalInter->IsFile(aVar.GetValue()); + + // add a new level of execution + // + GlobalInter->AddExecutionStatus(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_filenotexist_varm(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + else { + EDL_Variable& aVar = GlobalInter->GetVariable(varname.str); + Standard_Boolean Result = !GlobalInter->IsFile(aVar.GetValue()); + + // add a new level of execution + // + GlobalInter->AddExpressionMember(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_isvarnotdefined(const edlstring varname) +{ + if (!edl_must_execute()) { + GlobalInter->AddExecutionStatus(Standard_False); + } + else { + Standard_Boolean Result = !GlobalInter->IsDefined(varname.str); + + // add a new level of execution + // + GlobalInter->AddExecutionStatus(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_isvarnotdefinedm(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + else { + Standard_Boolean Result = !GlobalInter->IsDefined(varname.str); + + // add a new level of execution + // + GlobalInter->AddExpressionMember(Result); + } + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +// remove one level of execution status +// rule : ENDIF; +// +void edl_clear_execution_status() +{ + GlobalInter->RemoveExecutionStatus(); +} + +// clear the print list +// +void edl_clear_printlist() +{ + GlobalInter->SetPrintList(NULL); +} + +// c++ like cout +// +void edl_cout() +{ + if (!edl_must_execute()) return; + + cout << GlobalInter->GetPrintList() << endl; +} + +// @string function +// +void edl_create_string_var(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + const TCollection_AsciiString& asciistr = GlobalInter->GetPrintList(); + edlstring astr; + astr.str = asciistr.ToCString(); + astr.length = asciistr.Length(); + edl_set_var(varname,astr); + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +// add the value of a variable to the print list +// +void edl_printlist_add_var(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + + // we need to erase the quote + // + char* aString = GlobalInter->GetVariable(varname.str).GetValue(); + + GlobalInter->GetPrintList().AssignCat(aString); + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +// add the value of a variable to the print list +// we dont free variable memory because it s used after +void edl_printlist_addps_var(const edlstring varname) +{ + if (!edl_must_execute()) { + return; + } + + // we need to erase the quote + // + char *aString = GlobalInter->GetVariable(varname.str).GetValue(); + + GlobalInter->GetPrintList().AssignCat(aString); +} + +// add a string to the print list +// +void edl_printlist_add_str(const edlstring str) +{ + if (!edl_must_execute()) { + if (str.str) aStorageManager.Free((void *&)str.str,str.length+1); + return; + } + + GlobalInter->GetPrintList().AssignCat(str.str); + if (str.str) aStorageManager.Free((void *&)str.str,str.length+1); +} + +// create a new template var +// +void edl_create_template(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + + GlobalInter->AddTemplate(varname.str); + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_set_template(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + + GlobalInter->AddToTemplate(varname.str); + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +void edl_clear_template(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + + GlobalInter->ClearTemplate(varname.str); + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +// add a line to a template in construction +// +void edl_add_to_template(const edlstring line) +{ + if (!edl_must_execute()) { + if (line.str) aStorageManager.Free((void*&)line.str, line.length+1); + return; + } + + // we remove the $ + // + GlobalInter->GetTemplate(GlobalInter->GetCurrentTemplate().ToCString()).AddLine(&(line.str[1])); + if (line.str) aStorageManager.Free((void*&)line.str, line.length+1); +} + +// close a template +// +void edl_end_template() +{ + if (!edl_must_execute()) return; + + GlobalInter->SetCurrentTemplate(NULL); +} + +// begin to eval a template +// +void edl_apply_template(const edlstring tempname) +{ + if (!edl_must_execute()) { + if (tempname.str) aStorageManager.Free((void*&)tempname.str, tempname.length+1); + return; + } + + GlobalInter->SetCurrentTemplate(tempname.str); + + GlobalInter->ClearVariableList(); + + + // to check if the template is defined + // + EDL_Template& atemp = GlobalInter->GetTemplate(tempname.str); + Handle(TColStd_HSequenceOfHAsciiString) listvar = atemp.GetVariableList(); + + for (Standard_Integer i = 1; i <= listvar->Length(); i++) { + GlobalInter->AddToVariableList(listvar->Value(i)->ToCString()); + } + + if (tempname.str) aStorageManager.Free((void*&)tempname.str, tempname.length+1); +} + +// add the variables used in the template +// +void edl_add_to_varlist(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + + Handle(TCollection_HAsciiString) aVarName = new TCollection_HAsciiString(varname.str); + + GlobalInter->GetTemplate(GlobalInter->GetCurrentTemplate().ToCString()).AddToVariableList(aVarName); + + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +// evaluation of the template +// +void edl_end_apply(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + + GlobalInter->EvalTemplate(GlobalInter->GetCurrentTemplate().ToCString(),varname.str); + GlobalInter->ClearVariableList(); + + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +// load and open a shared library +// +void edl_open_library(const edlstring library) +{ + if (!edl_must_execute()) { + if (library.str) aStorageManager.Free((void*&)library.str, library.length+1); + return; + } + + GlobalInter->AddLibrary(library.str); + if (library.str) aStorageManager.Free((void*&)library.str, library.length+1); +} + +// close a shared library +// +void edl_close_library(const edlstring library) +{ + if (!edl_must_execute()) { + if (library.str) aStorageManager.Free((void*&)library.str, library.length+1); + return; + } + + GlobalInter->RemoveLibrary(library.str); + if (library.str) aStorageManager.Free((void*&)library.str, library.length+1); +} + +// add a variable to arguments list +// +void edl_arglist_add_var(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + + GlobalInter->AddToArgList(varname.str); + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +// add a string to arguments list +// note : the temp variable '.' is used +// but not inserted in the symbols table +// +void edl_arglist_add_str(const edlstring string) +{ + if (!edl_must_execute()) { + if (string.str) aStorageManager.Free((void*&)string.str, string.length+1); + return; + } + + GlobalInter->AddToArgList(".",string.str); + if (string.str) aStorageManager.Free((void*&)string.str, string.length+1); +} + +// call a function in a library opened before +// +void edl_call_procedure_library(const edlstring libname, const edlstring funcname) +{ + if (!edl_must_execute()) { + if (libname.str) aStorageManager.Free((void*&)libname.str, libname.length+1); + if (funcname.str) aStorageManager.Free((void*&)funcname.str, funcname.length+1); + return; + } + + EDL_Error aResult = GlobalInter->CallFunction(libname.str,funcname.str,0L); + + if (libname.str) aStorageManager.Free((void*&)libname.str, libname.length+1); + if (funcname.str) aStorageManager.Free((void*&)funcname.str, funcname.length+1); + + if (aResult != EDL_NORMAL) { + Standard_NoSuchObject::Raise(); + } +} + +// call a function in a library opened before +// +void edl_call_function_library(const edlstring libname, const edlstring funcname, const edlstring resname) +{ + if (!edl_must_execute()) { + if (libname.str) aStorageManager.Free((void*&)libname.str, libname.length+1); + if (funcname.str) aStorageManager.Free((void*&)funcname.str, funcname.length+1); + if (resname.str) aStorageManager.Free((void*&)resname.str, resname.length+1); + return; + } + + EDL_Error aResult = GlobalInter->CallFunction(libname.str,funcname.str,resname.str); + + if (libname.str) aStorageManager.Free((void*&)libname.str, libname.length+1); + if (funcname.str) aStorageManager.Free((void*&)funcname.str, funcname.length+1); + if (resname.str) aStorageManager.Free((void*&)resname.str, resname.length+1); + + if (aResult != EDL_NORMAL) { + Standard_NoSuchObject::Raise(); + } +} + +// open a file +// +void edl_open_file(const edlstring varname, const edlstring filename) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + if (filename.str) aStorageManager.Free((void*&)filename.str, filename.length+1); + return; + } + + EDL_Error aResult = GlobalInter->AddFile(varname.str,filename.str); + + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + if (filename.str) aStorageManager.Free((void*&)filename.str, filename.length+1); + + if (aResult != EDL_NORMAL) { + Standard_NoSuchObject::Raise(); + } +} + +// write in a file +// +void edl_write_file(const edlstring varname, const edlstring buffername) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + if (buffername.str) aStorageManager.Free((void*&)buffername.str, buffername.length+1); + return; + } + + EDL_File& aFile = GlobalInter->GetFile(varname.str); + EDL_Variable& aVar = GlobalInter->GetVariable(buffername.str); + + aFile.Write(aVar.GetValue()); + + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + if (buffername.str) aStorageManager.Free((void*&)buffername.str, buffername.length+1); +} + +// close a file +// +void edl_close_file(const edlstring varname) +{ + if (!edl_must_execute()) { + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); + return; + } + + EDL_File& aFile = GlobalInter->GetFile(varname.str); + + aFile.Close(); + GlobalInter->RemoveFile(varname.str); + if (varname.str) aStorageManager.Free((void*&)varname.str, varname.length+1); +} + +// include and process a file +// rule : uses ; + +#ifndef WNT + extern FILE *FileDesc[]; + extern int LineStack[]; + extern numFileDesc; + extern FILE *EDLin; +#else + extern "C" FILE *FileDesc[]; + extern "C" int LineStack[]; + extern "C" numFileDesc; + extern "C" FILE *EDLin; +#endif // WNT + +void edl_uses_var(const edlstring var) +{ + if (edl_must_execute()) { + EDL_Variable& aVar = GlobalInter->GetVariable(var.str); + TCollection_AsciiString anAscName = aVar.GetValue(); + + edlstring fname; + fname.str = (char *) aStorageManager.Allocate(anAscName.Length() + 1); + memcpy(fname.str, anAscName.ToCString(), anAscName.Length()+1); + fname.length = anAscName.Length(); + edl_uses(fname); + } + + if (var.str) aStorageManager.Free((void*&)var.str, var.length+1); +} + +void edl_uses(const edlstring filename) +{ + Standard_Boolean IsFound = Standard_False; + Standard_Integer DirCount = 1, + LenName = filename.length; + + Handle(TColStd_HSequenceOfAsciiString) IncludeDirectory = GlobalInter->GetIncludeDirectory(); + + // from lex + // + + if (edl_must_execute()) { + numFileDesc++; + + if (numFileDesc > 9) { + EDL::PrintError(EDL_TOOMANYINCLUDELEVEL," "); + Standard_NoSuchObject::Raise(); + } + + FileDesc[numFileDesc] = EDLin; + LineStack[numFileDesc] = EDLlineno; + + memcpy(&(FileName[numFileDesc][0]),EDL_CurrentFile.ToCString(), EDL_CurrentFile.Length()+1); + memcpy(&(FileName[10][0]), filename.str, filename.length+1); + + edlstring _currentFile; + _currentFile.str = &(FileName[10][0]); + _currentFile.length = filename.length; + EDL_SetCurrentFile(_currentFile); + + EDLlineno = 1; + DirCount = 1; + EDLin = 0; + while (!IsFound && DirCount <= IncludeDirectory->Length()) { + static char tmpName[1024]; + +#ifdef HPUX +#undef const +#endif + const TCollection_AsciiString& adir = IncludeDirectory->Value(DirCount); +#ifdef HPUX +#define const +#endif + memcpy(tmpName, adir.ToCString(), adir.Length()); + tmpName[adir.Length()] = '/'; + strcpy(&(tmpName[adir.Length()+1]),filename.str); + +#ifndef WNT + if( !access(tmpName, F_OK) ) +#else + if ( GetFileAttributes(tmpName) != 0xFFFFFFFF ) +#endif + { + EDLin = fopen(tmpName,"r"); + + if (EDLin != 0L) { + IsFound = Standard_True; + EDL_SetFile(); + } + } + DirCount++; + } + + if (EDLin == NULL) { + EDL::PrintError(EDL_FILENOTOPENED,filename.str); + if (filename.str) aStorageManager.Free((void*&)filename.str, filename.length+1); + EDLin = FileDesc[numFileDesc]; + EDLlineno = LineStack[numFileDesc]; + numFileDesc--; + Standard_NoSuchObject::Raise(); + } + } + if (filename.str) aStorageManager.Free((void*&)filename.str, filename.length+1); +} + +void edl_else_execution_status() +{ + Standard_Boolean currentstatus = GlobalInter->RemoveExecutionStatus(); + + if (edl_must_execute()) { + GlobalInter->AddExecutionStatus(!currentstatus); + } + else { + GlobalInter->AddExecutionStatus(currentstatus); + } +} + +void EDL_SetCurrentFile(const edlstring fname) +{ + EDL_CurrentFile = (Standard_CString)fname.str; +} + +edlstring edl_strdup(const char* buf, const int length) +{ + edlstring ret; + ret.str = (char *) aStorageManager.Allocate(length+1); + memcpy(ret.str, buf,length+1); + ret.length = length; + return ret; +} + +edlstring edl_string(const char* buf, const int length) +{ + edlstring ret; + ret.str = (char *) aStorageManager.Allocate(length-1); + memcpy(ret.str, &buf[1], length-1); + ret.str[length - 2] = '\0'; + ret.length = length-2; + return ret; +} + +void edlstring_free(const edlstring buf) +{ + if(buf.str) aStorageManager.Free((void*&)buf.str, buf.length+1); +} + +#ifdef HPUX +#undef const +#endif diff --git a/src/EDL/EDL_Library.cdl b/src/EDL/EDL_Library.cdl new file mode 100755 index 0000000..d788942 --- /dev/null +++ b/src/EDL/EDL_Library.cdl @@ -0,0 +1,50 @@ +-- File: EDL_Library.cdl +-- Created: Wed Jun 7 10:47:14 1995 +-- Author: Christophe LEYNADIER +-- +---Copyright: Matra Datavision 1995 + +class Library from EDL + +uses SharedLibrary from OSD, + Function from OSD, + AsciiString from TCollection, + HAsciiString from TCollection + +is + + Create + returns Library from EDL; + + Create(aName : CString from Standard) + returns Library from EDL; + + Assign(me : out; aLib : Library from EDL); + ---C++: alias operator = + + Destroy(me); + ---C++: alias ~ + + GetName(me) + returns CString from Standard; + + GetSymbol(me; aName : CString from Standard) + returns Function from OSD; + + GetStatus(me) + returns CString from Standard; + + Close(me); + + HashCode(myclass; aVar : Library from EDL; Upper : Integer from Standard) + returns Integer from Standard; + + IsEqual(myclass; alib1 : Library from EDL; alib2 : Library from EDL) + returns Boolean from Standard; + +fields + + myName : HAsciiString from TCollection; + myLib : SharedLibrary from OSD; + +end; diff --git a/src/EDL/EDL_Library.cxx b/src/EDL/EDL_Library.cxx new file mode 100755 index 0000000..baa03ad --- /dev/null +++ b/src/EDL/EDL_Library.cxx @@ -0,0 +1,104 @@ +#include + +#ifdef HPUX +#define LIBLEN 3 +#define TAILLEN 3 +#define TAILWORD ".sl" +#define HEADWORD "lib" +#else +#if WNT +#define TAILWORD ".dll" +#define HEADWORD "" +#define LIBLEN 0 +#define TAILLEN 4 +#else +#define LIBLEN 3 +#define TAILLEN 3 +#define TAILWORD ".so" +#define HEADWORD "lib" +#endif +#endif + + +EDL_Library::EDL_Library() +{ +} + +EDL_Library::EDL_Library(const Standard_CString aName) +{ + if (aName != NULL) { + char *SysName = 0L; + + myName = new TCollection_HAsciiString(aName); + + SysName = new char[strlen(aName) + 1 + LIBLEN + TAILLEN]; +#ifndef WNT + strcpy(SysName,HEADWORD); + strcat(SysName,myName->ToCString()); +#else + strcpy(SysName,myName->ToCString()); +#endif + strcat(SysName,TAILWORD); + + myLib.SetName(SysName); + myLib.DlOpen(OSD_RTLD_LAZY); + + delete [] SysName; + } +} + +void EDL_Library::Assign(const EDL_Library& aLib) +{ + if (!aLib.myName.IsNull()) { + myName = new TCollection_HAsciiString(aLib.myName); + } + + if (aLib.myLib.Name() != NULL) { + myLib.SetName(aLib.myLib.Name()); + myLib.DlOpen(OSD_RTLD_LAZY); + } +} + +void EDL_Library::Destroy() const +{ +} + +Standard_CString EDL_Library::GetName() const +{ + return myName->ToCString(); +} + +OSD_Function EDL_Library::GetSymbol(const Standard_CString aName) const +{ + OSD_Function aFunc; + + aFunc = myLib.DlSymb(aName); + + return aFunc; +} + +Standard_CString EDL_Library::GetStatus() const +{ + return myLib.DlError(); +} + +void EDL_Library::Close() const +{ + myLib.DlClose(); +} + +Standard_Integer EDL_Library::HashCode(const EDL_Library& aVar, const Standard_Integer Upper) +{ + return ::HashCode(aVar.GetName(),Upper); +} + +Standard_Boolean EDL_Library::IsEqual(const EDL_Library& aTemp1, const EDL_Library& aTemp2) +{ + Standard_Boolean aResult = Standard_False; + + if (strcmp(aTemp1.GetName(),aTemp2.GetName()) == 0) { + aResult = Standard_True; + } + + return aResult; +} diff --git a/src/EDL/EDL_ProcedureSignature.hxx b/src/EDL/EDL_ProcedureSignature.hxx new file mode 100755 index 0000000..4c32cf5 --- /dev/null +++ b/src/EDL/EDL_ProcedureSignature.hxx @@ -0,0 +1,6 @@ +#ifndef _EDL_ProcedureSignature_HeaderFile +#define _EDL_ProcedureSignature_HeaderFile +class EDL_Variable; +#define EDL_PROCEDURE(name) extern "C" void name( const int argc,const EDL_Variable*argv) +typedef void (*EDL_ProcedureSignature)(const int,const EDL_Variable*); +#endif diff --git a/src/EDL/EDL_Template.cdl b/src/EDL/EDL_Template.cdl new file mode 100755 index 0000000..2252993 --- /dev/null +++ b/src/EDL/EDL_Template.cdl @@ -0,0 +1,66 @@ +-- File: EDL_Template.cdl +-- Created: Tue Jun 6 14:37:55 1995 +-- Author: Christophe LEYNADIER +-- +---Copyright: Matra Datavision 1995 + +class Template from EDL + +uses HSequenceOfAsciiString from TColStd, + HSequenceOfHAsciiString from TColStd, + HAsciiString from TCollection, + HSequenceOfVariable from EDL + +is + + Create + returns Template from EDL; + + Create(aName : CString from Standard) + returns Template from EDL; + + Create(aTmp : Template from EDL) + returns Template from EDL; + + Assign(me : out; aTemplate : Template from EDL); + ---C++: alias operator = + + Destroy(me); + ---C++: alias ~ + + GetName(me) + returns CString from Standard; + + + GetLine(me; index : Integer from Standard) + returns CString from Standard; + + SetLine(me : out; index : Integer from Standard; aValue : CString from Standard); + + AddLine(me : out; aValue : CString from Standard); + + ClearLines(me : out); + + + Eval(me : out; aVar : HSequenceOfVariable from EDL); + + GetEval(me) + returns mutable HSequenceOfAsciiString from TColStd; + + VariableList(me : out; aVarList : HSequenceOfHAsciiString from TColStd); + AddToVariableList(me : out; aVarName : HAsciiString from TCollection); + GetVariableList(me) + returns mutable HSequenceOfHAsciiString from TColStd; + + HashCode(myclass; aVar : Template from EDL; Upper : Integer from Standard) + returns Integer from Standard; + + IsEqual(myclass; aTemp1 : Template from EDL; aTemp2 : Template from EDL) + returns Boolean from Standard; + +fields + myName : HAsciiString from TCollection; + myVariable : HSequenceOfHAsciiString from TColStd; + myValue : HSequenceOfAsciiString from TColStd; + myEval : HSequenceOfAsciiString from TColStd; +end; diff --git a/src/EDL/EDL_Template.cxx b/src/EDL/EDL_Template.cxx new file mode 100755 index 0000000..d1151bb --- /dev/null +++ b/src/EDL/EDL_Template.cxx @@ -0,0 +1,187 @@ +#include +#include +#include + +EDL_Template::EDL_Template() +{ + myValue = new TColStd_HSequenceOfAsciiString; + myEval = new TColStd_HSequenceOfAsciiString; + myVariable = new TColStd_HSequenceOfHAsciiString; +} + +EDL_Template::EDL_Template(const Standard_CString aName) +{ + myValue = new TColStd_HSequenceOfAsciiString; + myEval = new TColStd_HSequenceOfAsciiString; + myVariable = new TColStd_HSequenceOfHAsciiString; + + if (aName != NULL) { + myName = new TCollection_HAsciiString(aName); + } +} + +EDL_Template::EDL_Template(const EDL_Template& aTemplate) +{ + Assign(aTemplate); +} + +void EDL_Template::Assign(const EDL_Template& aTemplate) +{ + Standard_Integer i; + + if (aTemplate.GetName() != NULL) { + myName = new TCollection_HAsciiString(aTemplate.GetName()); + } + + myValue = new TColStd_HSequenceOfAsciiString; + + for (i = 1; i <= aTemplate.myValue->Length(); i++) { + myValue->Append(aTemplate.myValue->Value(i)); + } + + myEval = new TColStd_HSequenceOfAsciiString; + + for (i = 1; i <= aTemplate.myEval->Length(); i++) { + myEval->Append(aTemplate.myEval->Value(i)); + } + + myVariable = new TColStd_HSequenceOfHAsciiString; + + for (i = 1; i <= aTemplate.myVariable->Length(); i++) { + myVariable->Append(aTemplate.myVariable->Value(i)); + } +} + +void EDL_Template::Destroy() const +{ +} + +Standard_CString EDL_Template::GetName() const +{ + return myName->ToCString(); +} + +Standard_CString EDL_Template::GetLine(const Standard_Integer index) const +{ + if (index > 0 && index <= myValue->Length()) { + return myValue->Value(index).ToCString(); + } + else return NULL; +} + +void EDL_Template::SetLine(const Standard_Integer index, const Standard_CString aValue) +{ + if (index > 0 && index <= myValue->Length() && aValue != NULL) { + myValue->SetValue(index,aValue); + } +} + +void EDL_Template::AddLine(const Standard_CString aValue) +{ + TCollection_AsciiString aLine(aValue); + Standard_Integer pos; + + pos = aLine.SearchFromEnd("\\^"); + + if (pos > 0) { + aLine.Trunc(pos-1); + } + + myValue->Append(aLine); +} + +void EDL_Template::ClearLines() +{ + myValue->Clear(); +} + +void EDL_Template::Eval(const Handle(EDL_HSequenceOfVariable)& aVar) +{ + Standard_Integer nbVar = aVar->Length(), + nbLine = myValue->Length(); + static char newString[131072], + result [400000]; + Standard_CString vname, vvalue; + + myEval->Clear(); + + newString[0] = '\0'; + result[0] = '\0'; + + for (Standard_Integer lineCount = 1; lineCount <= nbLine; lineCount++) { + Standard_Integer ipos,lenvname,rpos; + + memcpy(newString,myValue->Value(lineCount).ToCString(),myValue->Value(lineCount).Length()+1); + + for (Standard_Integer varCount = 1; varCount <= nbVar; varCount++) { + vname = aVar->Value(varCount).GetName(); + vvalue = aVar->Value(varCount).GetValue(); + lenvname = strlen(vname); + + for (rpos = ipos = 0; newString[ipos] && ipos < 131072; ipos++) { + if (newString[ipos] == '%') { + + if (memcmp(&newString[ipos],vname,lenvname) == 0) { + for (Standard_Integer vpos = 0; vvalue[vpos] != 0; vpos++) { + result[rpos] = vvalue[vpos]; + rpos++; + } + + ipos += lenvname - 1; + } + else { + result[rpos] = newString[ipos]; + rpos++; + } + } + else { + result[rpos] = newString[ipos]; + rpos++; + } + } + + result[rpos] = '\0'; + memcpy(newString,result,rpos+1); + } + + myEval->Append(TCollection_AsciiString()); + myEval->ChangeValue(myEval->Length()).Copy(newString); + } +} + +Handle(TColStd_HSequenceOfAsciiString) EDL_Template::GetEval() const +{ + return myEval; +} + +void EDL_Template::VariableList(const Handle(TColStd_HSequenceOfHAsciiString)& aVar) +{ + myVariable = aVar; +} + +void EDL_Template::AddToVariableList(const Handle(TCollection_HAsciiString)& aVarName) +{ + myVariable->Append(aVarName); +} + +Handle(TColStd_HSequenceOfHAsciiString) EDL_Template::GetVariableList() const +{ + return myVariable; +} + +Standard_Integer EDL_Template::HashCode(const EDL_Template& aVar, const Standard_Integer Upper) +{ + return ::HashCode(aVar.GetName(),Upper); +} + +Standard_Boolean EDL_Template::IsEqual(const EDL_Template& aTemp1, const EDL_Template& aTemp2) +{ + Standard_Boolean aResult = Standard_False; + + if (strcmp(aTemp1.GetName(),aTemp2.GetName()) == 0) { + aResult = Standard_True; + } + + return aResult; +} + diff --git a/src/EDL/EDL_Variable.cdl b/src/EDL/EDL_Variable.cdl new file mode 100755 index 0000000..beaa85a --- /dev/null +++ b/src/EDL/EDL_Variable.cdl @@ -0,0 +1,43 @@ +-- File: EDL_Variable.cdl +-- Created: Thu Jun 1 18:07:36 1995 +-- Author: Christophe LEYNADIER +-- +---Copyright: Matra Datavision 1995 + +class Variable from EDL +uses HAsciiString from TCollection +is + Create + returns Variable from EDL; + + Create(aName : CString from Standard; aValue : CString from Standard) + returns Variable from EDL; + + Create(aVar : Variable from EDL) + returns Variable from EDL; + + Assign(me : out; aVar : Variable from EDL); + ---C++: alias operator = + + Destroy(me); + ---C++: alias ~ + + GetName(me) + returns CString from Standard; + + GetValue(me) + returns CString from Standard; + + SetValue(me : out; aValue : CString from Standard); + + HashCode(myclass; aVar : Variable from EDL; Upper : Integer from Standard) + returns Integer from Standard; + + IsEqual(myclass; aVar1 : Variable from EDL; aVar2 : Variable from EDL) + returns Boolean from Standard; + +fields + myName : HAsciiString from TCollection; + myValue : HAsciiString from TCollection; + +end; diff --git a/src/EDL/EDL_Variable.cxx b/src/EDL/EDL_Variable.cxx new file mode 100755 index 0000000..4853548 --- /dev/null +++ b/src/EDL/EDL_Variable.cxx @@ -0,0 +1,73 @@ +#include + +EDL_Variable::EDL_Variable() +{ +} + +EDL_Variable::EDL_Variable(const Standard_CString aName, const Standard_CString aValue) +{ + + if (aName != NULL) { + myName = new TCollection_HAsciiString(aName); + } + + if (aValue != NULL) { + myValue = new TCollection_HAsciiString(aValue); + } +} + +EDL_Variable::EDL_Variable(const EDL_Variable& aVar) +{ + Assign(aVar); +} + +void EDL_Variable::Assign(const EDL_Variable& aVar) +{ + if (!aVar.myName.IsNull()) { + myName = aVar.myName; + } + + if (!aVar.myValue.IsNull()) { + myValue = aVar.myValue; + } +} + +void EDL_Variable::Destroy() const +{ +} + +Standard_CString EDL_Variable::GetName() const +{ + return myName->ToCString(); +} + +Standard_CString EDL_Variable::GetValue() const +{ + return myValue->ToCString(); +} + +void EDL_Variable::SetValue(const Standard_CString aValue) +{ + myValue.Nullify(); + + if (aValue != NULL) { + myValue = new TCollection_HAsciiString(aValue); + } +} + +Standard_Integer EDL_Variable::HashCode(const EDL_Variable& aVar, const Standard_Integer Upper) +{ + return ::HashCode(aVar.GetName(),Upper); +} + +Standard_Boolean EDL_Variable::IsEqual(const EDL_Variable& aVar1, const EDL_Variable& aVar2) +{ + Standard_Boolean aResult = Standard_False; + + if (strcmp(aVar1.GetName(),aVar2.GetName()) == 0) { + aResult = Standard_True; + } + + return aResult; +} + diff --git a/src/EDL/FILES b/src/EDL/FILES new file mode 100755 index 0000000..eca6d57 --- /dev/null +++ b/src/EDL/FILES @@ -0,0 +1,7 @@ +EDL.yacc +EDL.lex +edl_rule.h +EDL_CMPLRS.edl +EDL_FunctionSignature.hxx +EDL_ProcedureSignature.hxx + diff --git a/src/EDL/edl_rule.h b/src/EDL/edl_rule.h new file mode 100755 index 0000000..23bb692 --- /dev/null +++ b/src/EDL/edl_rule.h @@ -0,0 +1,75 @@ + +typedef struct _edlstring { + char *str; + int length; +} edlstring; + +#ifdef HPUX +#define const +#endif + +void edl_set_var(const edlstring,const edlstring); +void edl_set_varvar(const edlstring,const edlstring); +void edl_set_varevalvar(const edlstring,const edlstring); +void edl_set_pvar(const edlstring,const edlstring); +void edl_set_pvarvar(const edlstring,const edlstring); +void edl_set_pvarevalvar(const edlstring,const edlstring); +void edl_unset_var(const edlstring); +void edl_unset_pvar(const edlstring); +void edl_test_condition(const edlstring,int,const edlstring); +void edl_eval_condition(); +void edl_eval_local_condition(int); +void edl_clear_execution_status(); +void edl_cout(); +void edl_create_string_var(const edlstring); +void edl_printlist_add_var(const edlstring); +void edl_printlist_addps_var(const edlstring); +void edl_printlist_add_str(const edlstring); +void edl_clear_printlist(); +void edl_create_template(const edlstring); +void edl_set_template(const edlstring); +void edl_clear_template(const edlstring); +void edl_add_to_template(const edlstring); +void edl_end_template(); +void edl_apply_template(const edlstring); +void edl_add_to_varlist(const edlstring); +void edl_end_apply(const edlstring); +void edl_open_library(const edlstring); +void edl_close_library(const edlstring); +void edl_call_function_library(const edlstring, const edlstring, const edlstring); +void edl_call_procedure_library(const edlstring, const edlstring); +void edl_arglist_add_var(const edlstring); +void edl_arglist_add_str(const edlstring); +unsigned int edl_must_execute(); +void edl_open_file(const edlstring,const edlstring); +void edl_write_file(const edlstring,const edlstring); +void edl_close_file(const edlstring); +void edl_set_varname(); +void edl_set_str(); +void edl_add_include_directory(const edlstring); +void edl_uses(const edlstring); +void edl_uses_var(const edlstring); +void edl_isvardefined(const edlstring); +void edl_isvarnotdefined(const edlstring); +void edl_else_execution_status(); +void edl_fileexist(const edlstring); +void edl_filenotexist(const edlstring); +void edl_fileexist_var(const edlstring); +void edl_filenotexist_var(const edlstring); + +void edl_isvardefinedm(const edlstring); +void edl_isvarnotdefinedm(const edlstring); +void edl_fileexistm(const edlstring); +void edl_filenotexistm(const edlstring); +void edl_fileexist_varm(const edlstring); +void edl_filenotexist_varm(const edlstring); + +void EDL_SetCurrentFile( const edlstring); + +edlstring edl_strdup(const char *, const int ); +edlstring edl_string(const char *, const int ); +void edlstring_free(const edlstring ); + +#ifdef HPUX +#undef const +#endif -- 2.39.5