CompuServe Thread

#C-hunks?

9 messages in this thread
#42173From: Supra CorpAug 11, 1994 4:15 PM
help. here's what I have.. I have a 300 k ascii file that I need to put in a string (one, BIG string) I don't want to have it in the code of the main program (takes forever to scroll through it all) so I wanted to have it in a separte file (hunk or otherwise) and link it to the program during compiling..I have tried using MCS (make C string) and bin2hk (both from the libs here) but can't get it to work correctly.. any and all help appreciated, Alex — it's been a long time since for i=1 to 10 print i next i
#42183From: Mal LansellAug 12, 1994 8:04 AM
Alex Why not just alloc some memory and load it in at run-time? You can use a pointer of type char to point to the string, and can use this variable as you would an array, or string in all the C string functions. This approach allows you to change the ascii text without recompiling. Mal
#42229From: Supra CorpAug 15, 1994 9:28 AM
I can't have 2 files..only one. Thanks for responding.. Alex
#42240From: Mal LansellAug 16, 1994 8:31 AM
One file eh? If nothing else works, and you have an assembler, you could turn the file into a linkable object by using a file such as this: XDEF _stringname _stringname incbin "string_file_path_&_name" end Assembling this will produce a linkable file that you can combine with your main program. Make sure your assembler is set to produce a linkable rather than executable file. To access the data, just have the line extern far char *stringname; somewhere in your C header file. I don't know which compiler and assembler you have, but I know SAS/C and Devpac produce compatible object files. I hope this helps. Mal
#42188From: Arnie CachelinAug 12, 1994 11:18 AM
Make a separate file, str.c, put in : . char BigString[] = " <your string here>"; compile this, then link the str.o to your main program. Declare the string there as . extern char *BigString; should work fine, and your compiler woun't have to re-compile the string each time.
#42230From: Supra CorpAug 15, 1994 9:28 AM
I tried that.. I get an error 11: string too large or not terminated sigh… Alex (thanks for responding!)
#42233From: Arnie CachelinAug 15, 1994 6:23 PM
hmmm.. maybe you have to terminate each line with a 'line continuation char '\' for the string to carry over the CR. Another thing I've resorted to was an ARexx script to take a text file, and convert it to something like: . ULONG Str[] = 0x414e5239, 0x3336445A, … or even: . UBYTE 0x41,0x4e,… the byte version would make a bigger source, due to added '0x' and ','.
#42203From: Wolf FaustAug 13, 1994 6:09 AM
Well, I don't see any problems using MCS with SAS as long as you declare the text as __far and don't use the small data options (don't use the usual SD during linking!). I haven't tried it yet with 300dkb but I surely used that scheme with my program above the usual small data hunk size… — Wolf Faust, Am Dorfgarten 10, 60435 Frankfurt, Germany —
#42221From: Supra CorpAug 14, 1994 7:06 PM
I am not sure if I am using the correct linking commands..I thought it would work as well..going to try again. Thanks Alex