FreeFem / FreeFem-sources

FreeFEM source code
https://freefem.org/
Other
794 stars 192 forks source link

Changing behavior of include directive (DSL)? #37

Closed cdoucet closed 5 years ago

cdoucet commented 6 years ago

In Freefem's DSL, include directive does not look for files in the directory of the file calling this directive. For example, if include "bar.edp" is found in a file $FF_ROOT/foo.edp which is run from $SOMEWHERE, then bar.edp will be search in $SOMEWHERE instead of FF_ROOT.

I would like to modify this behavior (which is implemented in fflib/lex.cpp). The purpose of this modification is to be able to run edp files from anywhere without having to set FF_INCLUDEPATH for that. Note that $FF_ROOT is known because *(pilesource[level].filename) contains it.

Do you agree with this modification?

I prefer to ask before making a pull request.

frederichecht commented 6 years ago

Yes,

Le 30 juil. 2018 à 13:40, cdoucet notifications@github.com a écrit :

In Freefem's DSL, include directive does not look for files in the directory of the file calling this directive. For example, if include "bar.edp" is found in a file $FF_ROOT/foo.edp which is run from $SOMEWHERE, then bar.edp will be search in $SOMEWHERE instead of FF_ROOT.

I would like to modify this behavior (which is implemented in fflib/lex.cpp). The purpose of this modification is to be able to run edp files from anywhere without having to set FF_INCLUDEPATH for that. Note that $FF_ROOT is known because *(pilesource[level].filename) contains it.

Do you agree with this modification?

I prefer to ask before making a pull request.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/FreeFem/FreeFem-sources/issues/37, or mute the thread https://github.com/notifications/unsubscribe-auth/AFb2jBvzWBuCRcdNlAQ8i7E3W_OXQKXrks5uLvCugaJpZM4VmQYk.

cdoucet commented 6 years ago

I think there is a bug in mylex::xxxx::open in src/fflib/lex.cpp.

If FF_INCLUDEPATH is empty (i.e. lex->includedir), then the code tries to open ff (i.e. filename). It is ok.

However, if FF_INCLUDEPATH is not empty, then it tries to prepend ff with each path in FF_INCLUDEPATH without trying to open ff alone. But the error message in case of failure says that opening ff failed while it is actually false (even though it is actually the expected behavior). So, I think I will need to modify the original algorithm.

Furthermore, as I would like to modify the behavior of include directive, I need to know in which order files should be searched for. For example, let say that $FF_ROOT/foo.edp includes bar.edp and that it is run from $SOMEWHERE. What is the order of trials?

  1. $FF_ROOT/bar.edp, then $FF_INCLUDEPATH/bar.edp, then $SOMEWHERE/bar.edp
  2. $FF_INCLUDEPATH/bar.edp, then $FF_ROOT/bar.edp, then $SOMEWHERE/bar.edp
  3. $SOMEWHERE/bar.edp, then $FF_ROOT/bar.edp, then $FF_INCLUDEPATH/bar.edp
  4. $SOMEWHERE/bar.edp, then $FF_INCLUDEPATH/bar.edp, then $FF_ROOT/bar.edp

Something else?

cdoucet commented 6 years ago

After checking, there is no bug in the code. I make a PR with the following behavior:

  1. the file is searched with no path
  2. then the file is searched with the path to the directory of the file which includes it
  3. then the file is searched with paths contained in includedir (FF_INCLUDEPATH and more)

Therefore, only step 2 is new.