Is there some C libraries that could help make terminal app?

Programming languages, Coding, executables, and scripting.
Post Reply
Posts: 66
Joined: 2014-09-27 20:54

Is there some C libraries that could help make terminal app?

#1 Post by larienna »

Some time ago, I worked on this java project

Which consist in making a game in terminal mode. Where you play the game through a series of commands. It allows you to play test the design of a game without all the chrome and user interface. In summary, it's a command line string analyzer that launch runnable classes with the game logic in it.

Now I wondered if I could do the same in C for another game of mine in order to tests a series of game logic functions. The idea would be to make a terminal application like MySql, associate each command to a function pointer and launch the appropriate function with the parameters when the command is typed.

So my first questions: Is there any C library that could help make MySql style terminal program?

Since terminal applications are more common in the C and in the linux ecosystem, I though that such library should be more likely to exist in C than in Java.


Then I though further, maybe I don't need to handle the terminal itself. Maybe I could use a command line system like GIT, where I pass the in game commands in parameter to the program like:

Code: Select all

mygame save.file command param1 param2
The only issue is that I might need to pass the save game file in parameter after each call, but I would not need to program any terminal, and I could benefit from bash script and other linux feature. The program would just branch to the right function according to the "command" keyword.

Second question: Is there any C library that could help making GIT style command line applications?


Third (it's more a reflection than a question), I am starting to gain interest in Kotlin, and I was not sure if I should convert my project above in Kotlin since functions are handled much more easily than in java. That would prevent the need to encapsulate each game logic routines into a class of it's own. Then I made the discovery that Kotlin can launch C functions using the native compiler. So instead of making 2 projects that does the same thing, I could combine both ideas together allowing to run as plain C program or from Kotlin app.

I am not sure if it's portable on Android, I guess so since android has the NDK (native development kit). I am also not sure how both of them could be fusioned. Since I would do a lot of string operation with SQL in the game logic, it should be better to keep the game logic in kotlin for easier string manipulations. Kotlin can also easily be lauched on terminal with kotlin scripts, so maybe the only thing I need is launching C functions from kotlin to test plain C only game logic. Allowing me to reuse the kotlin terminal application for both java/kotlin and plain C projects.

Posts: 66
Joined: 2014-09-27 20:54

Re: Is there some C libraries that could help make terminal

#2 Post by larienna »

After more thinking, what I am looking for is a kind of manual testing framework. Like Cunit and Junit, but not automated. I don't think such thing exists.

The idea is to be able allowed to run specific functions in the business logic via command line. What is being tested here is either the implementation or if the mechanics are fun and balanced.

The problem with the Black Book project I listed above, is that it was used as an middleman between the software and the business logic. If instead I could make an independent testing tool that call the business logic functions directly, I would not need to care about portability since it will not become included in the game.

An alternate way to do this: each game project can launch business logic functions from the command line. That could require a lot of programming, especially for arguments validation an using a large switch-case to branch to the right function. Maybe I could make some sort of a library to reduce code duplication like simplifying argument reading (like getopts) and branching to the right functions with an array map of commands and function pointers.

Posts: 521
Joined: 2020-05-03 14:16

Re: Is there some C libraries that could help make terminal

#3 Post by LE_746F6D617A7A69 »

If I understand You correctly, this problem is related to having a lexer and/or a parser which is processing the user input.
99% of problems like this one are addressed by Flex and Bison - I doubt that anyone can invent anything better - the code generated by Flex/Bison is AFAIN the fastest solution for most of the cases (*read the manuals to learn about special cases)
Bill Gates: "(...) In my case, I went to the garbage cans at the Computer Science Center and I fished out listings of their operating system."
The_full_story and Nothing_have_changed

Post Reply