Terminal window with printf/gets support as Mac OS X Library

This is a discussion on Terminal window with printf/gets support as Mac OS X Library within the Tech Board forums, part of the Community Boards category; Hi guys, Is there an open source project or commercial library that I can link to my code that creates ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    142

    Terminal window with printf/gets support as Mac OS X Library

    Hi guys,

    Is there an open source project or commercial library that I can link to my code that creates a terminal window with basic menus (File, Edit, Windows) so I can have double-clickable application that runs in that faux-terminal.

    On Mac OS X I can create text mode console application, but as such I can only use it from the Terminal application, typing its name in bash prompt. I can not have the application on desktop so I can double-click on it so it starts the terminal and runs in it. Well, at least that is what I know right now.

    Anyway, I have this friend working as developer and he's stuck in the eighties. Yes, I know. He is one of those guys that missed the GUI thing. But what can I do? He'll probably lose his job if I don't help him.

    He knows how to use printf() and gets() to write his applications. And he wrote hundreds of them. Maybe even a few thousand. He works in a company where everybody is trained to use these applications in succession. One application takes input, as I said via gets in console window and produces output in some database files. Then another application takes some more input and produces another file and then those files are fed into next application that produces printouts with reports and so on.

    Now they want to move to OS X and he's in big trouble. He needs to move all those terminal applications to Mac ASAP. We investigated the situation and at some point I said, OK, I can write the terminal window that would open automatically the first time you call printf().

    Well, turns out gets() is a pain to do. It handles all the events, menus, mouse clicks, keystrokes, copy/paste, cursor keys, saving the terminal content into a text file, printing the same content, you name it...

    So I wrote it over the weekend using all the code I wrote since '88 and it works. Sort of. There are a lot of rough edges and now I want to know if someone here wrote anything similar? Is there a library maybe or framework that gives basic functionality of a terminal window on OSX?
    Last edited by idelovski; 07-17-2011 at 05:57 PM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    What? Just create shortcuts to Terminal that pass the program to launch as a parameter.

    I don't have my Mac here to play with, but you can probably just create a shell script containing the line
    open -a Terminal /path/to/the/program
    and double-click that.

    Failing that, you can probably create something with Automator.



    Also, you do realize that gets() is the most evil function ever to make it into a standard, right?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    > but you can probably just create a shell script containing... Automator ...

    Ok, I'll check into that, but we already googled a lot for quick solutions and they never brought anything.

    > gets() is the most evil function ever to make it into a standard...

    And I always thought strncpy() is worse.



    I am not sure my friend even heard of stack overflows and similar stuff. He's been using this function all these years so what can I do now? My core version of gets() is called con_getsn() and it takes char pointer and int for buffer size, but then I created macro like this:
    Code:
    #define gets(s)  con_getsn(s,255)
    with the idea that he'll use buffers of 256 bytes. In time, he can convert all his calls from gets() to con_getsn() with the actual lengths he has in his code.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    strncpy() is nasty because it's hard to use right. But gets() is impossible to use right!
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    You are right about that. But personally, I never used gets() in my entire life for anything aside from few exercises I did when I started learning C. On the other hand, once I wasted several hours in debugger because of strncpy().

    When I found what was the problem, I was sure it was bug in Turbo C and Borland was to blame - well, that was "before" the internet. Then later I found out it was standard behavior and much later I read a story behind that function where Dennis Richie explains that he needed such function only for manipulation of file names on pdp computers back then or something like that, but yes, the whole thing was a mistake and he's sorry for it.
    Last edited by idelovski; 07-18-2011 at 09:21 AM.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by idelovski View Post

    On Mac OS X I can create text mode console application, but as such I can only use it from the Terminal application, typing its name in bash prompt. I can not have the application on desktop so I can double-click on it so it starts the terminal and runs in it. Well, at least that is what I know right now.
    I don't know what you mean here. If you have a console application on a Mac, you can double click it and a new terminal window will open (even if you have one already open) and your program will run. (The window will even stay open after the program finishes.) Now, if you mean you don't like the way the terminal window looks on a Mac, or you need something other than what it is, then that's a different issue I guess.

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    Geez - I have just created in Xcode a command line tool, type - C and yes, it works fine. When I double-click on it, the Terminal is started and application runs in it.

    I have no Idea what kind of project he created. He came to my office with his MacBook and he showed me in it that double-click does not work. Then I tried what happens in bash and I invoked cc on my computer with some helloworld.c and it didn't work. What an idiot. In haste I typed only "cc helloworld.c" and when I tried to run the resulting a.out it wouldn't run. If I just added "-o hello" at the end, and then double-clicked on resulting hello executable everything would have been ok. Now I checked again and I can see that a.out is marked to be opened with something called Saturn. I have no idea what it is and no wonder it can't run.

    Well, there are other reasons why Terminal solution wasn't as good as our terminal window, but we could have found solutions for everything. Ah! Anyway, at least I can put this thing into some of my desktop applications as a console window that displays internal progress of various processes or errors, warnings or... You know how it goes - You do something stupid and then you try to justify it somehow...



    P.S. I found Saturn on my computer. It is a profiling tool, but hidden in CHUD folder. No idea why it can't open o.aut if it's supposed to!?
    Last edited by idelovski; 07-18-2011 at 12:19 PM.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    It's not supposed to. a.out is the historical default output name for gcc executables, but .out doesn't mean executable on *nix systems, and whatever file format Saturn is looking for, this isn't it.

    (And I'm sure you'll find some way to reuse the code.... )

  9. #9
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    > And I'm sure you'll find some way to reuse the code....

    ... and build something like this: Qt/Caca Lighthouse Plugin

    "At the Qt Contributors Summit, Johannes‘ showed me his Qt/Caca Lighthouse plugin. Caca is a graphics library to output text instead of pixels. So this plugin lets you run Qt programs on the console."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can C work outside the terminal or CMD window?
    By ryantcb in forum C Programming
    Replies: 2
    Last Post: 07-22-2010, 01:11 PM
  2. terminal window size
    By eight8ball in forum C Programming
    Replies: 5
    Last Post: 01-08-2009, 07:48 AM
  3. Adding C++ support to C thought library?
    By sept in forum C Programming
    Replies: 20
    Last Post: 09-09-2008, 05:06 AM
  4. Writing to/reading from terminal window
    By ac251404 in forum Windows Programming
    Replies: 0
    Last Post: 05-19-2006, 01:06 PM
  5. Replies: 1
    Last Post: 09-25-2003, 08:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21