Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : CMM2: V5.06.00b1 - Pages and Pages
Page 2 of 3 | |||||
Author | Message | ||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1083 |
I think this is good. This makes it easy to identify when at the root directory. IF RIGHT$(CWD$,1) = "/" THEN at root directory ELSE in sub-directory ============= I have another directory issue in which I don't think the CMM2 behaves in a sensible way. Suppose I am working on a BAS file in a sub-directory. This program includes support files that are in the same directory. I can edit, run, etc, all is fine. I turn off the CMM2 until next morning. When I turn it back on, bottom center of the screen shows the program I was working on: "A:/ThisDir/ThisProg.BAS" Great! I type RUN and ... "Error in line xx: Could not find the file" Not so great. So what is a sensible solution? Visit Vegipete's *Mite Library for cool programs. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5914 |
This is a common problem with Windows programming also. Try this at the start of your program: PRINT CWD$ p$ = MM.INFO(CURRENT) FOR n = LEN(p$) TO 1 STEP -1 IF MID$(p$,n,1) = "/" THEN EXIT FOR NEXT n p$ = LEFT$(p$,n-1) PRINT p$ CHDIR p$ PRINT CWD$ You don't need the trailing / for the root directory so there is no need to test for that case. As far as I know, there should always be at least one '/' in the MM.INFO(CURRENT) and not as the first character but smart programming would test. Jim VK7JH MMedit MMBasic Help |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
YMMV but I'm of the opinion that programs that change the current working directory and do not restore it are not "good citizens", ideally the restoration should be done ASAP so as to reduce the chance of the program exiting with an error and leaving the CWD changed. I believe some file commands on earlier 'mites (though I only have first-hand experience of the the CMM1) did not accept paths, or relative paths, or displayed various other 'idiosyncracies' however after some prompting @matherp has resolved all(?) of these for the CMM2 which means that instead of changing the CWD you can always specify a path to any file you need to access. If you look at the Welcome Tape version of "Lunar Lander" you can see this in practice, e.g. LOAD PNG WE.PROG_DIR$ + "/LanderPict.png" Where WE.PROG_DIR$ comes from "common/welcome.inc": Const WE.PROG_DIR$ = we.get_parent$(Mm.Info$(Current)) ' Gets the parent directory of 'f$', or the empty string if it does not have one. Function we.get_parent$(f$) Local i% For i% = Len(f$) To 1 Step -1 If InStr("/\", Mid$(f$, i%, 1)) > 0 Then Exit For Next i% If i% = 0 Then we.get_parent$ = "" Else we.get_parent$ = Left$(f$, i% - 1) EndIf End Function Which is my equivalent to Jim's code. Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Definitely agree with Tom on this one. I could restore the working directory to the directory of any stored program on power-up but IMHO that would be even more confusing in most circumstances so I think it is down to the programmer to use good practice and make their code completely independent of where any given user chooses to install it. and which directory they are in when they run it. I believe MMBASIC on the CMM2 gives you all the tools you need to do this. |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
Getting that printed out in big type and framed Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
Since it's such a useful piece of information, should you consider adding something like this so as to avoid the song and dance to determine it? prog_dir$ = MM.INFO$(CURRENT PROG DIR) Best wishes, Tom Edited 2020-11-23 21:40 by thwill Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
What does it return? The directory in which the current program file is located? |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
What does it return? The directory in which the current program file is located? Yes, because that is the piece of information you require to make a program run (and access its assets) independent of where it is situated. As shown above you can determine it as the parent of MM.INFO$(CURRENT), but if it could be added to the firmware it would save others the inconvenience of including that piece of code everywhere. I'd ask for a PARENT$(f$) function, but I'm aware of the limitations Tom Edited 2020-11-23 22:01 by thwill Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
If I do it logically it will have to be compatible with CWD$ e.g. A:/ or A:/zmim good enough? |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
e.g. A:/ or A:/zmim good enough? To be honest, not really , because the client code would still have to do this to be bullet-proof: relative_path_of_asset$ = "subdir/foo.png" path_to_asset$ = MM.INFO$(CURRENT PROG DIR) IF RIGHT$(path_to_asset$, 1) <> "/" THEN CAT path_to_asset$, "/" CAT path_to_asset$, relative_path_of_asset$ This is why the historical behaviour of CWD$ is so problematic in the first place. Regards, Tom Edited 2020-11-23 22:34 by thwill Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
Have you tried mm.info(path)? doesn't this do what you want now? I'm sure you must have asked for it? Not in the manual though hmmmmmm Edited 2020-11-23 22:42 by matherp |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
OK, that does work (and is inconsistent with CWD$ ), but I don't "think" it was me - needs adding to the documentation in any case. I asked for SEARCH PATH. Thanks anyway, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
One more thing, is there any chance DIR$() could return values in alphabetic sorted case-insensitive order instead of, what looks random, but I guess is "created" order ? I'm fairly certain the former would be more useful, and computing it in BASIC is potentially expensive in either time or space because unless the CMM2 is applying some artifical limit of its own I believe a directory can contain 1000's of entries can't it ? If it can't then it's fine, I've written the code to deal with the issue myself, but it does no harm to ask. Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
jirsoft Guru Joined: 18/09/2020 Location: Czech RepublicPosts: 532 |
I'm fairly certain the former would be more useful, and computing it in BASIC is potentially expensive in either time or space because unless the CMM2 is applying some artifical limit of its own I believe a directory can contain 1000's of entries can't it ? If it can't then it's fine, I've written the code to deal with the issue myself, but it does no harm to ask. Tom Hi Tom, I would like to leave it so as is now... I let to the users of NC also switch to unsorted view and with your idea we will loose the ability to see the structure as was created (and you can not get unsorted list, but sort you can anytime...) Edited 2020-11-23 22:54 by jirsoft Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
I would like to leave it so as is now... I let to the users of NC also switch to unsorted view and with your idea we will loose the ability to see the structure as was created (and you can not get unsorted list, but sort you can anytime...) This is undoubtedly true and a good argument. Have you stress tested NC with huge directories ? Looks like you have imposed an artifical 500 item limit, what happens if you exceed that ? Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8592 |
I probably agree that cwd$ is wrong but, I've checked, and as it is the same in all MMBasic versions it isn't something I can change. I could add mm.info(cwd) which would give a string that always ends with a / DIR$ can't be sorted as it would need to create a big datastructure and hold hold it between calls Edited 2020-11-23 23:03 by matherp |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
I'm not sure what is for the best Peter. I guess MM.INFO$(PATH) fulfills the actual use-case so maybe get that documented and maybe add something to the documentation of CWD$ but otherwise leave well alone ? I figured as much. One thing I "think" you could do is hold the last returned path and use that as a start point from which to determine what to return next but it would undoubtedly be slower than what you do now. I thought about doing it myself in BASIC, but ultimately decided it would need to go straight to a CSUB to be worthwhile. Thanks, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3848 |
@jirsoft, I'm not swearing to it but I think array.sort() in https://github.com/thwill1000/sptools/blob/develop-r1b3/src/common/array.inc probably has better speed if not space performance than NCsort(). If nothing else it might serve as inspiration for improvements. Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
jirsoft Guru Joined: 18/09/2020 Location: Czech RepublicPosts: 532 |
Best wishes, Tom Thanks Tom, I will for sure look on it (I already used built-in SOR() methods, but something stopped me from use it). I know since begin, that some methods in NC are slow, but I needed to have it done (and was too lazy for the moment look for faster alternatives) and now, when NC is near to my goal of functionality, it's time for optimisation... First I will finish the server (in Python), and then NC need to be all throughly tested (and make it faster). Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
jirsoft Guru Joined: 18/09/2020 Location: Czech RepublicPosts: 532 |
I would like to leave it so as is now... I let to the users of NC also switch to unsorted view and with your idea we will loose the ability to see the structure as was created (and you can not get unsorted list, but sort you can anytime...) This is undoubtedly true and a good argument. Have you stress tested NC with huge directories ? Looks like you have imposed an artifical 500 item limit, what happens if you exceed that ? Tom Another argument is listing DIRs before FILEs or mix it. On MacOS is standard sort it mixed, on Windows DIRs first... And for big directories: I didn't test it yet, but as you say, it's just artificial limit... I don't know, if is some limitation comming directly from SD card driver? And I can still set some limit, but give a warning. And current limit will I test, until now, I was just programming as good as I could. Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
Page 2 of 3 |
Print this page |