<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [newbie] opening a textfile and reading it line by line in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77881#M7800</link>
    <description>&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;When I write the linePtr to the alert window it shows whats left of the textfile starting from the position after the search string. But when I try to figure out how long this piece of information is by using &lt;PRE&gt;BMGetPtrSize(linePtr)&lt;/PRE&gt; &lt;BR /&gt;
I get the result &lt;B&gt;0&lt;/B&gt;. &lt;/BLOCKQUOTE&gt;

OK, I understand. This won't work because BMGetPtrSize will only tell you the size of a block of memory allocated as a Ptr, i.e. you can't ask it the size of an arbitrary address. A Ptr is not a string - it is an allocated block of memory which could contain anything.&lt;BR /&gt;
&lt;BR /&gt;
As Oleg said, you can get the number of bytes between two addresses by using simple subtraction.
&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;The second line in the file says &lt;B&gt;..TEGNSETT DOSN8&lt;/B&gt;, which means &lt;B&gt;characterset MS-Dos Norwegian 8-bits&lt;/B&gt;. If I'm to speculate, I would guess the reason for getting the strange &lt;B&gt;.??†&lt;/B&gt; result when trying to display the first character, which is a &lt;B&gt;.&lt;/B&gt;, is that the character in it self only occupies the first 8 bits of the 32 bit byte.  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_confused.gif" style="display : inline;" /&gt;&lt;/BLOCKQUOTE&gt;

Your assessment of the encoding type name sounds logical - hopefully it is an 8-bit encoding, because you can then use standard C/C++ string handling. BTW, a byte is an 8-bit value; a 32 bit value is often referred to as a long integer.&lt;BR /&gt;
 
&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;I would be happy to send you the file - coming soon to a mailbox near you...  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" style="display : inline;" /&gt;  &lt;/BLOCKQUOTE&gt;
Got it - I'll let you now once I've had a chance to look into it.</description>
    <pubDate>Tue, 06 Jul 2004 15:30:58 GMT</pubDate>
    <dc:creator>Ralph Wessel</dc:creator>
    <dc:date>2004-07-06T15:30:58Z</dc:date>
    <item>
      <title>[newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77867#M7786</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;I tried to use the example from the documentation:
&lt;PRE&gt;#include "DG.h"    // brings file selection dialog (and also includes Location)

IO::Location loc;

if (!DGGetOpenFile (&amp;amp;loc)) {    // returns the selected location in loc
    // no file (folder, link) location was selected
}&lt;/PRE&gt;
but I just couldn't get it to work. I even searched through all the documentation without finding any other reference to DGGetOpenFile. So I gave it up.&lt;BR /&gt;&lt;BR /&gt;Then I tried:
&lt;PRE&gt;	IO::Location fileLoc;    // Location instance
	IO::File file (fileLoc);
	char buffer[128];

DG::FileDialog dlg (DG::FileDialog::OpenMultiFile);

    if (!dlg.Invoke ())
        return false;

    int count = dlg.GetSelectionCount ();

    for (int n = 0; n &amp;lt; count; n++) {
        IO::File file (dlg.GetSelectedFile (n));
	 errorCode = file.Open (IO::File::ReadMode);    // opening the file in read-only mode
	 errorCode = file.ReadBin(buffer, 128);

 DGAlert(DG_INFORMATION, "Inside while", buffer, 0, "OK", "Cancel", 0);
       
    }

&lt;/PRE&gt;
This lets me open my file from a filedialog. One problem though, is that I can't open it as myFile.sos, which is what it is, I have to rename it to myFile.txt. Why is that, and what can I do with it?&lt;BR /&gt;&lt;BR /&gt;The other thing is that I can't read one line at the time. How do I do that?&lt;BR /&gt;Yet another thing is that, if I can't read one line at the time, how do I read the whole file at once. And then the stringmanager doesn't seem too equiped whith functions to parse the text and split it up in sutable chunks. Can I use standard c++ functions and includes as well as the ones that comes with the API?&lt;BR /&gt;-- &lt;BR /&gt;Regards,&lt;BR /&gt;Tor Jørgen&lt;/DIV&gt;</description>
      <pubDate>Mon, 07 Aug 2023 10:18:29 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77867#M7786</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-07T10:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77868#M7787</link>
      <description>Haven't tried the DG yet, but I can write to filestreams as in regular C/C++
&lt;PRE&gt;FILE *stream;
if( (stream = fopen("test.dat", "w"))!=NULL)
{
	fprintf( stream, "blablah %.3f \n", 27.0);
}
fclose(stream);
_fcloseall();
_flushall();&lt;/PRE&gt;
I guess, for ArchiCAD conformance, you should try to use the API-tools instead. Don't know how portable this is and you probably want to use the sytem FileOpen &amp;amp; Save-dialogs as well...</description>
      <pubDate>Thu, 01 Jul 2004 13:58:46 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77868#M7787</guid>
      <dc:creator>stefan</dc:creator>
      <dc:date>2004-07-01T13:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77869#M7788</link>
      <description>&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;&lt;PRE&gt;IO::Location loc; 
 
if (!DGGetOpenFile (&amp;amp;loc)) {    // returns the selected location in loc
    // no file (folder, link) location was selected
}&lt;/PRE&gt; but I just couldn't get it to work. I even searched through all the documentation without finding any other reference to DGGetOpenFile.&lt;/BLOCKQUOTE&gt;
I haven't found any reference to this either, but it does work with a slight modification. Without specific documentation, you can often find the information you need by searching through the Support files, especially the Include files. For example, the declaration of DGGetOpenFile is:&lt;PRE&gt;DG_DLL_EXPORT bool CCALL	DGGetOpenFile (CIO::Location* retLocation,
										   long popupItemCount = 0, DGTypePopupItem* popupItems = NULL,
										   const CIO::Location* defLocation = NULL,
										   const char* title = NULL, long flags = 0);

DG_DLL_EXPORT long CCALL	DGGetOpenFile (CIO::Location** retLocationArray,
										   long popupItemCount = 0, DGTypePopupItem* popupItems = NULL,
										   const CIO::Location* defLocation = NULL,
										   const char* title = NULL, long flags = 0);&lt;/PRE&gt;
This shows us there are two variants of this function: one which allows a single file to be selected, and another for multiple files. You probably want the first. This expects a pointer to a CIO::Location (try this instead of IO::Location).&lt;BR /&gt;
&lt;BR /&gt;
Next, you can optionally specify file filters for the format to be opened with popupItemCount and popupItems. 'popupItemCount' specifies the number of filters, and the filter specifications are in 'popupItems' (an array with popupItemCount items). Each item in popupItems is of type 'DGTypePopupItem', which can also be found in the Include files:&lt;PRE&gt;struct DGTypePopupItem {
	const char*	text;
	const char*	extensions;
	long		macType;
};&lt;/PRE&gt;
Briefly, you specify a name for the filter, the name extension, and a Macintosh file type descriptor (4 chars).&lt;BR /&gt;
&lt;BR /&gt;
'defLocation' allows you to specify a default starting point (not usually a good idea), and 'title' is the dialog title. 'flags' allows you to specify some of the file browser behaviour and appearance. Use the following:&lt;PRE&gt;// --- Constants for DGGetOpenFile ---------------------------------------------

#define DG_OF_NO_ALL_FILES				0x0001
#define DG_OF_NO_ROOT_GROUP				0x0002
#define DG_OF_GROUPS_FIRST				0x0004
#define DG_OF_DISPLAY_EXTENSIONS		0x0008
#define DG_OF_DONT_DISPLAY_EXTENSIONS	0x0010
#define DG_OF_LIST_SINGLE_CHILD_GROUPS	0x0020&lt;/PRE&gt;
So, if you wanted the user to open a single plain text file, and you didn't want to see all file types, you could write:&lt;PRE&gt;	CIO::Location loc;
	DGTypePopupItem	popup[1] = { {"Plain Text", "txt", 'TEXT'} };
	if (!DGGetOpenFile (&amp;amp;loc, 1, popup, 0, "Test", DG_OF_NO_ALL_FILES)) {
	    //No file selected
	}&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;The other thing is that I can't read one line at the time. How do I do that? ... if I can't read one line at the time, how do I read the whole file at once. And then the stringmanager doesn't seem too equiped whith functions to parse the text and split it up in sutable chunks. Can I use standard c++ functions and includes as well as the ones that comes with the API?&lt;/BLOCKQUOTE&gt;
You can use standard the C/C++ library (or others) for strings and i/o, but there are some issues to consider. Are you sure the file content is always text? And, more importantly, what is the encoding of the text, e.g. UTF8? You need to keep in mind that a single character is not necessarily a single byte.&lt;BR /&gt;
&lt;BR /&gt;
The standard C/C++ libraries largely work cross-platform. I recommend the C++ libraries over C, and it is well worth understanding the STL. The containers in the STL (vector, list, map etc) are particularly valuable.&lt;BR /&gt;
&lt;BR /&gt;
The ArchiCAD API can help with international text (to some extent), and it is best to try to use their string functions when interacting with ArchiCAD. Buffering and parsing text is a fairly big subject though. When you say you want to read a line, do you mean a line terminated by some combination of carriage return and linefeed, or a logical line in the syntax of the file format you are parsing? In any case, you need to parse the text - accumulating everything you read to a buffer - until you discover the conditions which terminate the line (or the file).&lt;BR /&gt;
&lt;BR /&gt;
If you are using the ArchiCAD API File class, you can obtain the file size with the GetDataLength method. You could then allocate a memory block large enough to accomodate the entire file and read it in one hit. You need to consider what size these files may be if you take this approach - buffering the contents will likely be far more efficient.</description>
      <pubDate>Thu, 01 Jul 2004 20:21:14 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77869#M7788</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2004-07-01T20:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77870#M7789</link>
      <description>Thanks again for a very thorough answer, Ralph &lt;E&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/E&gt; &lt;BR /&gt;
and thanks for the tip about using filestreams as in regular C/C++, Stefan. &lt;BR /&gt;
 &lt;BR /&gt;
Ralph wrote:&lt;BLOCKQUOTE&gt;When you say you want to read a line, do you mean a line terminated by some combination of carriage return and linefeed, or a logical line in the syntax of the file format you are parsing? In any case, you need to parse the text - accumulating everything you read to a buffer - until you discover the conditions which terminate the line (or the file).&lt;/BLOCKQUOTE&gt;
I mean a line terminated by some combination of carriage return and linefeed. &lt;BR /&gt;
 &lt;BR /&gt;
When I start reading the first part of the first line, which goes like this:&lt;BR /&gt;
 &lt;BR /&gt;
&lt;B&gt;.HODE 0:&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
and writes it to the alert or the reportwindow, what I get is this: &lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;.??† &lt;BR /&gt;
H??† &lt;BR /&gt;
O??† &lt;BR /&gt;
D??† &lt;BR /&gt;
E??† &lt;BR /&gt;
 ??† &lt;BR /&gt;
0??† &lt;BR /&gt;
&lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_confused.gif" style="display : inline;" /&gt;?† &lt;BR /&gt;
&lt;/B&gt; &lt;BR /&gt;
 &lt;BR /&gt;
I've copied this straight from the reportwindow. When I look at the preview I see that the last line which is a colon followed by two questionmarks is represented here by a confused smiley followed by one questionmark. (the smiley is kind of correct, though...) 
&lt;BLOCKQUOTE&gt;You could then allocate a memory block large enough to accomodate the entire file and read it in one hit. You need to consider what size these files may be if you take this approach - buffering the contents will likely be far more efficient.&lt;/BLOCKQUOTE&gt; &lt;BR /&gt;
I've tried to use &lt;PRE&gt;errorCode = file.GetDataLength(&amp;amp;fLength);&lt;/PRE&gt; but I'm not allowed to use the fLength-value to set the length of my charbuffer. &lt;BR /&gt;
 &lt;BR /&gt;
And I still can't make the DGGetOpenFile() work. I've included DG.h, File.hpp and Filesystem.hpp, do I need more?&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
Regards,&lt;BR /&gt;
Tor Jørgen</description>
      <pubDate>Fri, 02 Jul 2004 10:46:51 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77870#M7789</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-07-02T10:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77871#M7790</link>
      <description>&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;Ralph wrote:&lt;BLOCKQUOTE&gt;When you say you want to read a line, do you mean... etc &lt;/BLOCKQUOTE&gt;
I mean a line terminated by some combination of carriage return and linefeed.&lt;/BLOCKQUOTE&gt;
OK. Standard line endings are:&lt;UL&gt;&lt;LI&gt;Mac: carriage-return "\r"&lt;BR /&gt;
Win: carriage-return + linefeed "\r\n"&lt;BR /&gt;
Unix: linefeed "\n"&lt;/LI&gt;&lt;/UL&gt;
If you simply wanted to find where a line ended in an array of characters, you could use something like the 'find_first_of' method in the STL std::string class. I've implemented my own string class based on the String Manager functions to provide this functionality. However, note my comments on character width and encoding below.&lt;BR /&gt;

&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;When I start reading the first part of the first line, which goes like this:&lt;BR /&gt;
&lt;B&gt;.HODE 0:&lt;/B&gt;&lt;BR /&gt;
and writes it to the alert or the reportwindow, what I get is this: &lt;BR /&gt;
&lt;B&gt;.??† &lt;BR /&gt;
etc...&lt;/B&gt;&lt;/BLOCKQUOTE&gt;
As I mentioned above, your text may well be encoded. Basically, the old ASCII codes allowed for only 256 character symbols at most (1 byte per character), but many languages have vastly more symbols than that. Therefore, text needs to be in a form which can account for thousands of character symbols and also provide for commonality between them, e.g. common numeric symbols. This is a fairly deep subject, but the String Manager functions in the ArchiCAD API may be able to provide what you need.&lt;BR /&gt;
&lt;BR /&gt;
The problem is, I don't know much about the file format you are dealing with. Standard XML, for example, declares the encoding type so you know how to interpret it. Does the documentation for this format discuss encoding?&lt;BR /&gt;
&lt;BR /&gt;
Your encoding could be UTF-32 (4 bytes per character) because every character in your file is displayed with 4 symbols, and the leading character is the ASCII value. Read the String Manager documentation, and in particular look at 'GSCharCode' and 'CHSetDefaultCharCode'.&lt;BR /&gt;

&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;You could then allocate a memory block large enough to accomodate the entire file...&lt;/BLOCKQUOTE&gt; &lt;BR /&gt;
I've tried to use &lt;PRE&gt;errorCode = file.GetDataLength(&amp;amp;fLength);&lt;/PRE&gt; but I'm not allowed to use the fLength-value to set the length of my charbuffer. &lt;/BLOCKQUOTE&gt;
I don't know what you mean by, "not allowed to use fLength" - it's just a number which can be used to allocate a block of memory. Are you doing something like this:&lt;PRE&gt;		USize fLength = 0;
		file.GetDataLength(&amp;amp;fLength);
		GSPtr buff = BMAllocatePtr(fLength, ALLOCATE_CLEAR, 0);&lt;/PRE&gt;
You can then read the file data into 'buff'.&lt;BR /&gt;

&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;And I still can't make the DGGetOpenFile() work. I've included DG.h, File.hpp and Filesystem.hpp, do I need more?&lt;/BLOCKQUOTE&gt;
Did you copy/paste my example into your file?&lt;PRE&gt;&amp;nbsp; &amp;nbsp;CIO::Location loc; 
&amp;nbsp; &amp;nbsp;DGTypePopupItem&amp;nbsp; &amp;nbsp;popup[1] = { {"Plain Text", "txt", 'TEXT'} }; 
&amp;nbsp; &amp;nbsp;if (!DGGetOpenFile (&amp;amp;loc, 1, popup, 0, "Test", DG_OF_NO_ALL_FILES)) { 
&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; //No file selected 
&amp;nbsp; &amp;nbsp;}&lt;/PRE&gt;
Does this work?</description>
      <pubDate>Fri, 02 Jul 2004 12:17:21 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77871#M7790</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2004-07-02T12:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77872#M7791</link>
      <description>Thanks again, &lt;BR /&gt;
I tried copying your code into my project, Ralph, and after adding some more includes it worked &lt;E&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/E&gt; &lt;BR /&gt;
 &lt;BR /&gt;
I still can't get my debugging to work, so as a workaround I'm looking for a way to write numbers to the alert or the reportwindow. Is there a way to do this? I guess I have to do some sort of casting, but I just can't figure out how... &lt;BR /&gt;
 &lt;BR /&gt;
I've done most of my programming in flash before - except for some openGL code in C++ during my courses at the university - and it's really dawning on me that flash is kind of like playing in a sheltered kindergarten with the macromedia guys acting as the grownups making sure the kids don't hurt themselves... &lt;BR /&gt;
 &lt;BR /&gt;
--  &lt;BR /&gt;
Regards, &lt;BR /&gt;
Tor Jørgen</description>
      <pubDate>Sat, 03 Jul 2004 17:35:19 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77872#M7791</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-07-03T17:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77873#M7792</link>
      <description>I found out that I can use &lt;B&gt;ultoa&lt;/B&gt;, which made me realise - when I saw the numbers - that I'm not quite into this stuff yet... &lt;BR /&gt;
 &lt;BR /&gt;
--  &lt;BR /&gt;
Regards, &lt;BR /&gt;
Tor Jørgen</description>
      <pubDate>Sun, 04 Jul 2004 14:21:17 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77873#M7792</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-07-04T14:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77874#M7793</link>
      <description>I'm getting a little lost in all those ptrs and handles...  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_cry.gif" style="display : inline;" /&gt;  &lt;BR /&gt;
so I'll just keep posting these rookie-questions  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_smile.gif" style="display : inline;" /&gt;  &lt;BR /&gt;
 &lt;BR /&gt;
I'm reading the file into a buffer like Ralph suggested &lt;PRE&gt;		GSPtr buff = BMAllocatePtr(fLength, ALLOCATE_CLEAR, 0); 
		errorCode = file.ReadBin(buff, fLength); 
&lt;/PRE&gt; &lt;BR /&gt;
Then I'm searching for the first occurence of "\r" like this &lt;PRE&gt;		GSPtr linePtr = CHSearchSubstring("\r", buff, fLength);	// pointing to the first cr 
&lt;/PRE&gt; &lt;BR /&gt;
Then I'm left with a ptr to the beginning of the text in &lt;B&gt;buff&lt;/B&gt; and a ptr to the first cr in &lt;B&gt;linePtr&lt;/B&gt;. &lt;BR /&gt;
The length of buff is 22261 and the length of linePtr is 0, which is not quite what I wanted - but I guess it makes sense since it just points to the position of cr. &lt;BR /&gt;
 &lt;BR /&gt;
My question then is what kind of math do I have to perform to be able to copy the just the first line into another charbuffer? &lt;BR /&gt;
 &lt;BR /&gt;
--  &lt;BR /&gt;
Regards, &lt;BR /&gt;
Tor Jørgen</description>
      <pubDate>Mon, 05 Jul 2004 08:22:52 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77874#M7793</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-07-05T08:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77875#M7794</link>
      <description>As Ralph wrote, perhaps your file has the UTF-32 encoding.&lt;BR /&gt;
It seems, ArchiCAD API has no support of this encoding. &lt;BR /&gt;
I think, it will be easier for you if you will convert your file to ASCII ( or Unicode at last, if ASCII will not suitable) by some external software.&lt;BR /&gt;
Actually, you can not search ASCII substring like "\r" in a differently encoded string.</description>
      <pubDate>Mon, 05 Jul 2004 09:10:33 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77875#M7794</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2004-07-05T09:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77876#M7795</link>
      <description>I don't now what kind of encoding it has, but one of the first lines in the file says &lt;B&gt;characterset DOSN8&lt;/B&gt;, which I'm guessing is some sort of DOS textfile with norwegian characters in it - in other words it should include &lt;B&gt;Æ Ø Å&lt;/B&gt;, but I'm getting stuff like &lt;B&gt;ù è&lt;/B&gt; when I view it in TextEdit here on my Mac. &lt;BR /&gt;
 &lt;BR /&gt;
When I read it into &lt;B&gt;buff&lt;/B&gt; using the code I showed in my last post, and then write it to an alert or the reportwindow, the output look exactly like the file when I view it in TextEdit. From that I'm thinking that the API can handle the file ok. &lt;BR /&gt;
And if I search for "\r" and then write the new ptr to the alert or reportwindow, it shows the file starting at line 2. &lt;BR /&gt;
 &lt;BR /&gt;
I think my problem is more basic, like how do I use those ptrs and stuff to find out how many bytes I have to read or copy to get my hands on the next line. Maybe it so basic you can't even see the problem I'm having...  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_confused.gif" style="display : inline;" /&gt; &lt;BR /&gt;
 &lt;BR /&gt;
--  &lt;BR /&gt;
Regards, &lt;BR /&gt;
Tor Jørgen</description>
      <pubDate>Mon, 05 Jul 2004 10:18:21 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77876#M7795</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-07-05T10:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77877#M7796</link>
      <description>&lt;BLOCKQUOTE&gt;vannassen wrote:&lt;BR /&gt;I don't now what kind of encoding it has, but one of the first lines in the file says &lt;B&gt;characterset DOSN8&lt;/B&gt;, which I'm guessing is some sort of DOS textfile with norwegian characters in it - in other words it should include &lt;B&gt;Æ Ø Å&lt;/B&gt;, but I'm getting stuff like &lt;B&gt;ù è&lt;/B&gt; when I view it in TextEdit here on my Mac. 
&lt;/BLOCKQUOTE&gt;
Hmm, yes I think DOSN8 is a 8 bit encoding. I was mistaken the strange output example:&lt;BR /&gt;
H??† &lt;BR /&gt;
O??†&lt;BR /&gt;
&lt;BR /&gt;
Perhaps you need to convert some characters from DOSN8 to somesing other like ISO8859-10 ( &lt;A href="http://www.statkart.no/standard/sosi/html_32/del1_2/del1_2.htm" target="_blank"&gt;&lt;LINK_TEXT text="http://www.statkart.no/standard/sosi/ht ... del1_2.htm"&gt;http://www.statkart.no/standard/sosi/html_32/del1_2/del1_2.htm&lt;/LINK_TEXT&gt;&lt;/A&gt; )&lt;BR /&gt;

&lt;BLOCKQUOTE&gt;My question then is what kind of math do I have to perform to be able to copy the just the first line into another charbuffer? &lt;/BLOCKQUOTE&gt;

It seem I am not quite well understoood your issue.&lt;BR /&gt;
May be:&lt;BR /&gt;
&lt;BR /&gt;
long lineLength=linePtr-buff;&lt;BR /&gt;
char* lineBuffer=new char[lineLength+1];&lt;BR /&gt;
BNCopyMemory(lineBuffer,buff,lineLength);&lt;BR /&gt;
lineBuffer[lineLength]=0;&lt;BR /&gt;
// using the lineBuffer&lt;BR /&gt;
delete lineBuffer;&lt;BR /&gt;
&lt;BR /&gt;
But much better, instead:&lt;BR /&gt;
std::string line(buff,linePtr);</description>
      <pubDate>Mon, 05 Jul 2004 11:56:46 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77877#M7796</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2004-07-05T11:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77878#M7797</link>
      <description>Thanks Oleg, you made my day  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" style="display : inline;" /&gt; &lt;BR /&gt;
&lt;BR /&gt;
And I must say I'm impressed with you finding your way around norwegian documents &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_smile.gif" style="display : inline;" /&gt;&lt;BR /&gt;
-- &lt;BR /&gt;
Regards,&lt;BR /&gt;
Tor Jørgen</description>
      <pubDate>Mon, 05 Jul 2004 13:47:42 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77878#M7797</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-07-05T13:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77879#M7798</link>
      <description>&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;Then I'm searching for the first occurence of "\r" like this &lt;PRE&gt;		GSPtr linePtr = CHSearchSubstring("\r", buff, fLength);	// pointing to the first cr 
&lt;/PRE&gt; &lt;BR /&gt;
Then I'm left with a ptr to the beginning of the text in &lt;B&gt;buff&lt;/B&gt; and a ptr to the first cr in &lt;B&gt;linePtr&lt;/B&gt;. &lt;BR /&gt;
The length of buff is 22261 and the length of linePtr is 0, which is not quite what I wanted - but I guess it makes sense since it just points to the position of cr. &lt;BR /&gt;
My question then is what kind of math do I have to perform to be able to copy the just the first line into another charbuffer?&lt;/BLOCKQUOTE&gt;
Are you saying that after calling CHSearchSubstring, the return result in linePtr is 0? If so, it is indicating to you that the string was not found, i.e. it did not find a CR in the data buffer. You should certainly check for a null result anyway, because any to attempt to use the value would be invalid.&lt;BR /&gt;
&lt;BR /&gt;
However, if ArchiCAD has a problem with your string encoding (which it certainly seems to), the String Manager functions won't work. I wouldn't be surprised if it isn't even attempting to find a CR beyond the first character. You could try setting different default encodings for the String Manager to see if it makes a difference, e.g.:&lt;PRE&gt;CHSetDefaultCharCode(CC_WestEuropean);&lt;/PRE&gt;

Perhaps we could speed this up if I could take a look at this file. Can it be downloaded from somewhere? Otherwise you could send it to the address on Encina's contact page.</description>
      <pubDate>Mon, 05 Jul 2004 21:23:14 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77879#M7798</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2004-07-05T21:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77880#M7799</link>
      <description>Ralph wrote:&lt;BLOCKQUOTE&gt;Are you saying that after calling CHSearchSubstring, the return result in linePtr is 0?&lt;/BLOCKQUOTE&gt; &lt;BR /&gt;
What I was trying to say is: I guess the result in linePtr is the address to the first occurence of the search string. When I write the linePtr to the alert window it shows whats left of the textfile starting from the position after the search string. But when I try to figure out how long this piece of information is by using &lt;PRE&gt;BMGetPtrSize(linePtr)&lt;/PRE&gt; &lt;BR /&gt;
I get the result &lt;B&gt;0&lt;/B&gt;. &lt;BR /&gt;
 &lt;BR /&gt;
The second line in the file says &lt;B&gt;..TEGNSETT DOSN8&lt;/B&gt;, which means &lt;B&gt;characterset MS-Dos Norwegian 8-bits&lt;/B&gt;. If I'm to speculate, I would guess the reason for getting the strange &lt;B&gt;.??†&lt;/B&gt; result when trying to display the first character, which is a &lt;B&gt;.&lt;/B&gt;, is that the character in it self only occupies the first 8 bits of the 32 bit byte.  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_confused.gif" style="display : inline;" /&gt;  &lt;BR /&gt;
 &lt;BR /&gt;
I would be happy to send you the file - coming soon to a mailbox near you...  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" style="display : inline;" /&gt;  &lt;BR /&gt;
 &lt;BR /&gt;
--  &lt;BR /&gt;
Regards, &lt;BR /&gt;
Tor Jørgen</description>
      <pubDate>Tue, 06 Jul 2004 09:17:19 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77880#M7799</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2004-07-06T09:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77881#M7800</link>
      <description>&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;When I write the linePtr to the alert window it shows whats left of the textfile starting from the position after the search string. But when I try to figure out how long this piece of information is by using &lt;PRE&gt;BMGetPtrSize(linePtr)&lt;/PRE&gt; &lt;BR /&gt;
I get the result &lt;B&gt;0&lt;/B&gt;. &lt;/BLOCKQUOTE&gt;

OK, I understand. This won't work because BMGetPtrSize will only tell you the size of a block of memory allocated as a Ptr, i.e. you can't ask it the size of an arbitrary address. A Ptr is not a string - it is an allocated block of memory which could contain anything.&lt;BR /&gt;
&lt;BR /&gt;
As Oleg said, you can get the number of bytes between two addresses by using simple subtraction.
&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;The second line in the file says &lt;B&gt;..TEGNSETT DOSN8&lt;/B&gt;, which means &lt;B&gt;characterset MS-Dos Norwegian 8-bits&lt;/B&gt;. If I'm to speculate, I would guess the reason for getting the strange &lt;B&gt;.??†&lt;/B&gt; result when trying to display the first character, which is a &lt;B&gt;.&lt;/B&gt;, is that the character in it self only occupies the first 8 bits of the 32 bit byte.  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_confused.gif" style="display : inline;" /&gt;&lt;/BLOCKQUOTE&gt;

Your assessment of the encoding type name sounds logical - hopefully it is an 8-bit encoding, because you can then use standard C/C++ string handling. BTW, a byte is an 8-bit value; a 32 bit value is often referred to as a long integer.&lt;BR /&gt;
 
&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;I would be happy to send you the file - coming soon to a mailbox near you...  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" style="display : inline;" /&gt;  &lt;/BLOCKQUOTE&gt;
Got it - I'll let you now once I've had a chance to look into it.</description>
      <pubDate>Tue, 06 Jul 2004 15:30:58 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77881#M7800</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2004-07-06T15:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: [newbie] opening a textfile and reading it line by line</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77882#M7801</link>
      <description>&lt;BLOCKQUOTE&gt;Tor wrote:&lt;BR /&gt;I would be happy to send you the file - coming soon to a mailbox near you...  &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_biggrin.gif" style="display : inline;" /&gt; &lt;/BLOCKQUOTE&gt;

I took a look at the file, and it does indeed seem to be an 8-bit encoding. I was able to read and parse the file using the String Manager functions with the default character code set to 'CC_WestEuropean'. Use 'CHSetDefaultCharCode' to change the default if this is not your system default. Let me know if this improves the situation.   &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_smile.gif" style="display : inline;" /&gt;</description>
      <pubDate>Wed, 07 Jul 2004 22:07:35 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/newbie-opening-a-textfile-and-reading-it-line-by-line/m-p/77882#M7801</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2004-07-07T22:07:35Z</dc:date>
    </item>
  </channel>
</rss>

