Subject:
|
Re: Getting rif off the 8.3 nomenclature??? (scanf tricks)
|
Newsgroups:
|
lugnet.cad.dat.parts, lugnet.cad.dev
|
Date:
|
Thu, 29 Mar 2007 01:05:06 GMT
|
Viewed:
|
1554 times
|
| |
| |
In lugnet.cad.dat.parts, Kevin L. Clague wrote:
|
Given that sscanf splits things up by whitespace, I think LPub and LSynth
would misparse file names with blanks or tabs in them.
As I said, Willy has a good argument, and well worthy of consideration.
I think that as long as there is embedded white space is not allowed, the
change will be backward compatible and not cause problems (at least not for
LPub and LSynth).
|
I have no idea whether this could be worked into your sscanf usage, but it is
possible to read whitespace into strings with the scanf functions using
scanlists (sets of [valid] or [^invalid] characters). Its not the most
elegant solution, but heres a simplistic C example anyway:
#include <stdio.h>
int main(int argc, char *argv[])
{
int color;
float x, y, z, a, b, c, d, e, f, g, h, i;
char filename[FILENAME_MAX]; /* PATH_MAX, etc. */
int fieldsRead;
fieldsRead = scanf( " 1 %d %f %f %f %f %f %f %f %f %f %f %f %f %[^\n\r]",
&color, &x, &y, &z, &a, &b, &c, &d, &e, &f, &g, &h, &i,
filename );
if (fieldsRead == 14)
printf( "Filename: %s\n", filename);
return 0;
}
It attempts to read an LDraw part reference line from standard input. Instead of
%s, the filename is read with the scanlist %[^\n\r], which reads
everything it runs into until it hits end-of-line characters. Example usage
(compiled as scantest with gcc scantest.c -o scantest):
> ./scantest
1 4 0 0 0 1 0 0 0 1 0 0 0 1 3001.dat
Filename: 3001.dat
So far so good. Now we try a goofy filename with lots of whitespace:
> ./scantest
1 4 0 0 0 1 0 0 0 1 0 0 0 1 s\ whitespace\ everywhere \I look.dat
Filename: s\ whitespace\ everywhere \I look.dat
Ta-da! Whitespace read with scanf without too much hassle.
This example kind of exploits the fact that the field that may contain
whitespace is at the end of the line, but if you play around with the idea Im
sure more robust scanners should be possible.
Anyway, I would agree that there really need not be any whitespace in the
official part library filenames. However, I do find 8.3 character filename
limitations exceptionally archaic, and as an end user I do like to use natural
whitespace instead of hyphens or underscores in filenames (LDraw models or
otherwise). So, thought Id share this C trivia just in case it helps lead to an
easier-ish solution.
Be well,
Jim
|
|
Message has 1 Reply:
Message is in Reply To:
| | Re: Getting rif off the 8.3 nomenclature???
|
| (...) Sorry for posting to my own post. In particular if the "longer file names" cannot have blanks in the names, then there is no problem for LPub or LSynth. 20.3 would require no changes at to LPub or LSynth. Given that sscanf splits things up by (...) (18 years ago, 28-Mar-07, to lugnet.cad.dat.parts)
|
25 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|