Development - mkaito/habitcli GitHub Wiki
In the interest of keeping a list of things we might/could/should use or need, I'll be pasting links here.
Project Notes
-
C is hardly the most sane approach for what is essentially a fancy frontend to a HTTP/JSON API, especially with all the string handling that will be involved, and zero need for hardware/kernel interaction.
-
We're writing this in C/C++ so I can learn to write C/C++, how to manage memory, pointer magic, building a C project, and all that jazz.
-
Things I want to focus on: project structure and file layout, testing and test driven development, separating "backend" functionality into a library that is tested and built separately, data structures, pointers, and general "how to get things done in C" stuff, as well as using reasonably modern C, libraries and not reinventing the wheel.
-
It's probably a good idea to keep the API wrapped by a "separate" library
libhabit
that backs the interfaces of thehabit
executable. That way, things can be built and tested separately. This C noob has no idea whether that's a reasonable approach, or if I'm just forcing my Ruby ideals on C. -
The curses interface would be really nice, but I want to focus on the library and batch interface first, in order to nail the fundamentals and project management.
-
Should the curses interface be in the same executable, or should each interface have its own binary, dynlinked to the library?
Libraries
-
jsmn (pronounced like 'jasmine') is a minimalistic JSON parser in C. It can be easily integrated into the resource-limited projects or embedded systems.
-
libcurl - client-side URL transfers. Tutorial available here.
Reference
-
There's an API wrapper library for Javascript here. Might be worth checking.
-
Ditto for a Perl lib.
-
Ditto for a .NET lib
Testing
-
MinUnit -- a minimal unit testing framework for C. It's so minimal it's just 3 lines of macros.
-
Check is a unit testing framework for C. It features a simple interface for defining unit tests, putting little in the way of the developer. Tests are run in a separate address space, so both assertion failures and code errors that cause segmentation faults or other signals can be caught. Test results are reportable in the following: Subunit, TAP, XML, and a generic logging format.
Development notes
libcurl
Getting started
It appears that libcurl
is the de-facto standard HTTP/networking library for
C.
You can use curl-config --clflags
to find appropriate compiler flags, and
curl-config --libs
for linker flags.
Initialize curl once per program lifetime with a call to
curl_global_init()
, which takes a bitmask parameter to specify what exactly
to initialize. CURL_GLOBAL_ALL
should be a good default. CURL_GLOBAL_WIN32
should be used for, guess, windows, and CURL_GLOBAL_SSL
if you plan to use
SSL.
curl_easy_perform()
can detect whether curl_global_init()
has not been
called, and call it itself with a guessed bitmask. Relying on this is
considered bad style.
When you're done with curl, call curl_global_cleanup()
.
Repeated calls to init or cleanup should be avoided.
Interfaces
libcurl provides two interfaces: the easy interface and the multi interface.
The easy interface is, as the name implies, pretty simple. It's a blocking single-call interface.
The multi interface can do multiple asynchronous requests at a time.