brickviking / list

list is a curses-based interactive file listing program that combines the functions of less and hexdump into one handy program. It displays text on the screen in one of two different formats, either in hexadecimal dump format (a la MS-DOS debug.com format), or in text format, similar to what the programs less and more do.
GNU General Public License v2.0
2 stars 0 forks source link

Can't create list.debug on MS-DOS without LFN support #3

Open brickviking opened 2 years ago

brickviking commented 2 years ago

Given this project started off as a DOS program, trying to create list.debug in the temp directory would have failed for the DOS platform. Perhaps this should be looked at.

list.c:28:

...
20:   if(NULL == fi->BugWriteFName) { 
21:    if(!getenv("TEMP"))  /* Whoops, no TEMP variable defined */
22:      strcpy(TempPath, "/tmp/list.debug"); /* This should be the last resort filename, not the default */
23:    else {
24:  /* Should this be a file in the users home dir instead? The only place where this
25:   * wouldn't work is where the home dir is not writeable. 
26:   */
27      strcpy(TempPath, getenv("TEMP")); /* Else, we found a candidate dir to use */:
28:      sprintf(TempPath + (strlen(TempPath) + 1), "list.debug"); /* lets hope this is the right length */
29:      }
30:  }
...
brickviking commented 1 year ago

At least on MS-DOS-like systems (including FreeDOS here) you could use LFN, but only if it's supported. On places where LFN isn't immediately available, you're stuck with simply calling it list.dbg to get the same usable concept underneath them.

You could try this, at least when fenced by #ifdef:

...
20:   if(NULL == fi->BugWriteFName) { 
21:    if(!getenv("TEMP"))  /* Whoops, no TEMP variable defined */
22:--      strcpy(TempPath, "/tmp/list.debug"); /* This should be the last resort filename, not the default */
22:++      strcpy(TempPath, "/tmp/list.dbg"); /* This should be the last resort filename, not the default */
23:    else {
24:  /* Should this be a file in the users home dir instead? The only place where this
25:   * wouldn't work is where the home dir is not writeable. 
26:   */
27      strcpy(TempPath, getenv("TEMP")); /* Else, we found a candidate dir to use */:
28:--      sprintf(TempPath + (strlen(TempPath) + 1), "list.debug"); /* lets hope this is the right length */
28:++      sprintf(TempPath + (strlen(TempPath) + 1), "list.dbg"); /* lets hope this is the right length */
29:      }
30:  }
...
brickviking commented 1 year ago

One of the only other problems to solve with that #ifdef is: how do we find out if LFN is: 1) supported? 2) active at runtime?

This might properly be a #ifndef instead (i.e. #ifndef LFN, however that turns up), but we don't know that at run time, and it's no use at compile time, which is when #ifdef/#ifndef is commonly checked. How's it done during run time? Env vars?