Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
I have an app I've written that will read any file in binary mode and write it to a second (text) file in hex dump format. It's all command line stuff.

I would like to change this to write the output to a windowed application that I could scroll. I suspect there would be minimal changes needed to do this.

Anyone got a pointer? I'd be happy to share it when finished.

(Phase 2 might be allowing a text entry box where I can paste the input file name, or a "browse" button that opens a file-open dialog.)

Thanks, Todd
 

lin2mac

macrumors newbie
Jan 21, 2008
12
0
I have an app I've written that will read any file in binary mode and write it to a second (text) file in hex dump format. It's all command line stuff.

In OSX is there a difference between binary and text files? I thought that was a DOS/OS9 thing.
 

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
In OSX is there a difference between binary and text files? I thought that was a DOS/OS9 thing.

I don't know if Mac OS X considers them different or not, but it certainly matter hows a file is processed. File associations (or whatever it's called on a Mac) make them different. The contents of a file certainly would make them different. Which C or C++ I/O function is used makes them different.

It's my understand that "text" implies a certain format, like being full of displayable characters and newline characters and will generally display in editors as a human might expect.

Binary files, on the other hand, could have any available character encoding and be chock full of non-displayable characters, and "newline" characters that don't necessarily mean "new line".

Todd
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
I would like to change this to write the output to a windowed application that I could scroll. I suspect there would be minimal changes needed to do this.

Describe "minimal" :)

If your app is a CLI, then you will need to create a new Carbon app and put in all the fun event handling code, which is fortunately already provided for you in the Xcode's Carbon Application project template. But you'd still have to add your textbox code and such. And AFAIK there aren't many, if any, Carbon devs on this forum to help you.

What you want to do can be done with one line of Cocoa code. I can whip up a project if you want.
 

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
That is certainly gracious of you to offer.

I picked Carbon because I could use C and/or C++. I don't know Objective-C yet (but I have bought both the Obj-C book and the Cocoa book, for what that's worth!).

After posting, I did try a C++ Carbon Standard Application template. I wasn't sure where to go after that. There was a Window, and I could drag and drop text controls and/or a scrollbar to it, but without knowing the event model, that doesn't do me a lot of good.

Let me fuss with it some more. Tomorrow or the next day I may come back and take you up on your offer though! I feel like I have some more due diligence to do.

Thanks!
 

fimac

macrumors member
Jan 18, 2006
95
1
Finland
I have an app I've written that will read any file in binary mode and write it to a second (text) file in hex dump format. It's all command line stuff.

Hex Fiend is an open source hex editor -- browsing through the source may be instructive. http://www.ridiculousfish.com/hexfiend/.

Cocoa can call C++. Thus the non-graphical core of your application can remain implemented in C++, but with a Cocoa GUI. This is handy for Cocoa newbies like me ;)
 

SC68Cal

macrumors 68000
Feb 23, 2006
1,642
0
In OSX is there a difference between binary and text files? I thought that was a DOS/OS9 thing.


Text files are binary files. The only difference is that the binary digits are mapped to ASCII characters and then displayed as such.

For example:

Code:
#include <stdio.h>

main()
{

  int a = 54; // 54 is the ASCII character code for "6"
  printf("%c\n", a); // format to ASCII and print

}

Anyway, I thought it was cool.
 

fimac

macrumors member
Jan 18, 2006
95
1
Finland
Text files are binary files. The only difference is that the binary digits are mapped to ASCII characters and then displayed as such.

Files are quite simply sequences of zero or more bytes. The distinction between text and binary format relates to the translation of line-endings on read and write. Whilst Unix does not do (and has never done) this translation, Windows does (and always has).

Thus, when we talk about "text" or "binary" files, we are essentially describing whether the file is human-readable. (Example Library/Safari/Bookmarks.plist is binary, whereas Library/PubSub/Clients.plist is text -- at least on my 10.5.1 installation.)
 

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
Hex Fiend is an open source hex editor -- browsing through the source may be instructive. http://www.ridiculousfish.com/hexfiend/.

Cocoa can call C++. Thus the non-graphical core of your application can remain implemented in C++, but with a Cocoa GUI. This is handy for Cocoa newbies like me ;)

Good idea. My purpose is a bit special, and I feel it will do me more good to learn from scratch than to start butchering someone else's code.

Here's my special purpose. (Reminds me of the movie "The Jerk")

I have EBCDIC files I want to edit on the Mac. They can be quite large - +- 500MB:

  • I want to have a toggle for the eyecatcher area to display in either ASCII or EBCDIC. (in case I want to look at a binary file is that not EBCDIC).
  • I want scrolling to be blazingly fast for these large file. What I think I'll do is merely scroll the offset column on the left, and when scrolling is done, seek into the file to get that data. This way, I'm not reading tons of data just to get through it for those time I want to get to the bottom of the data quickly.
    Code:
    Offset   Rec. Off. Data................................  Eyecatcher......
    00000000 000000    dddddddd dddddddd dddddddd ddddddddd *----------------*
    00000010 000010    dddddddd dddddddd dddddddd ddddddddd *----------------*
    ...
    000000D0 0000D0    dddddddd dddddddd dddd               *---------*
    
    
    000000DA 000000    dddddddd dddddddd dddddddd ddddddddd *----------------*
    000000EA 000010    dddddddd dddddddd dddddddd ddddddddd *----------------*
  • I want an option for carving the hex view up into fixed length records. So, let's say each record is 0xDA long. At offset 0x00, the first record starts. At offset 0xDA the second records starts, at 0x01B4 the 3rd record starts, etc. I want a visual break between each record.
  • I want a "global offset" on the far left column (showing the offset in the file from byte 0
  • I want a "record" offset, so for each record that is 0xDA long, I want an offset of 0x00 through 0xD9

Todd
 

fimac

macrumors member
Jan 18, 2006
95
1
Finland
Good idea. My purpose is a bit special, and I feel it will do me more good to learn from scratch than to start butchering someone else's code.

I hear you, I would do the same!

That said, Hex Fiend was specifically designed to deal with stupidly large files, and so it may be that you can re-use that part. Good luck with your project :)
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
That said, Hex Fiend was specifically designed to deal with stupidly large files, and so it may be that you can re-use that part. Good luck with your project :)

Hex Fiend does work really well with huge files. However, HexEdit (an older Carbon app), works very well also, and it too is open source.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
That is certainly gracious of you to offer.

I picked Carbon because I could use C and/or C++. I don't know Objective-C yet (but I have bought both the Obj-C book and the Cocoa book, for what that's worth!).

After posting, I did try a C++ Carbon Standard Application template. I wasn't sure where to go after that. There was a Window, and I could drag and drop text controls and/or a scrollbar to it, but without knowing the event model, that doesn't do me a lot of good.

Let me fuss with it some more. Tomorrow or the next day I may come back and take you up on your offer though! I feel like I have some more due diligence to do.

Thanks!

I forgot about this thread but remembered it today, so here's a Cocoa project I whipped up that demonstrates generating a C-style string from a C function, and then converting it so it can be placed into a text view, in Cocoa. I used a NIB because it's much easier but that really is the only confusing part about it IMO.
 

Attachments

  • TextOutput.zip
    60.6 KB · Views: 161

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
[size=+4]COOL![/size] I'll be studying this tonight. (The wife can go out to dinner by HERSELF!!)

Thank you, thank you, thank you! Todd
 

Tom1983

macrumors newbie
Feb 9, 2009
1
0
Moving from C to C++

I have been reading this page with big interest since I moved to XCode to translate my Pascal programs to C++ / Carbon (I know all very old stuff ;-)

when I tried the posted TextOut application it runned all right; so I tried to move forward and added a button to add text to the TextView window. Runs perfectly when I added it to the .c file provided - but when I tried to copy all the code to a .cpp file instead of a .c file I got the following error:

--------

"_pAddMyLines", referenced from:
-[Button_Action convert:] in Button_Action.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

-------

please note that I added the following code to the original .c file:

-------

char* pAddMyLines()
{
return "CPP Text in the window!! \n";
}

-----

and I created a new Carbon Control called "Button_Action" which basically contains the same lines as the Controller.m file provided.

Hope I explain it clearly enough? anyone who can explain why the same code doesn't work in a CPP file compared to a C file?

thanks in advance

Tom
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.