getopt cuneiform-cli support

Bug #260959 reported by Serge Poltavsky
10
Affects Status Importance Assigned to Milestone
Cuneiform for Linux
Fix Released
Undecided
Unassigned

Bug Description

This patch is adding GNU/getopt command line parsing. Using getopt can help to add new options more easily.
Also it sends error messages to stderr stream. I think, that division that streams let users easy work with output by giving /dev/stdout as output filename. So errors will not be mixed with useful data.

Revision history for this message
Serge Poltavsky (serge-uliss) wrote :
Revision history for this message
Alex Samorukov (samm-os2) wrote :

thanks a lot. btw, i tried rtf output but got a crash. Is it usable on your side?

Revision history for this message
Serge Poltavsky (serge-uliss) wrote :

yes, rtf output works normally on my 32bit Gentoo

Revision history for this message
Alex Samorukov (samm-os2) wrote :

Thanks, i will check on i386 to see if it is amd64 related. Very strange. And you a got a usable output?? I found a place on the rtf code where wsprintf called, and in current windummy its just a plug. I patched this to get usable output, and it works but still print some warnings:

-int wsprintf(LPTSTR lpOut, LPCTSTR lpFmt, ...) {
- return sprintf(lpOut, "WSPRINTF-FUNCTION");
-}
+
+ int wsprintf(LPTSTR lpOut, LPCTSTR lpFmt, ...) {
+ char buffer[256];
+ int ret;
+ va_list args;
+ va_start (args, lpFmt);
+ ret=vsprintf (lpOut,lpFmt, args);
+ perror (buffer);
+ va_end (args);
+ return ret;
+}

Revision history for this message
Serge Poltavsky (serge-uliss) wrote :

yes, you are right, I just cat cuneiform-out.rtf, but no one editor can't open it, because of
«WSPRINTF-FUNCTION» garbage.
After cat cuneiform-out.rtf | sed 's/WSPRINTF\-FUNCTION//g' > out.rtf all works

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

The problem with this patch is that getopt is not supported natively on Windows. So you would have to write fallback routines for use with MSVC. And then it would make sense to use that everywhere (because most people are on Unix and an untested codepath is a non-working codepath).

The other parts of you patch seem sensible. I'll apply suitable parts of it soon.

Revision history for this message
Alex Samorukov (samm-os2) wrote :

we may static link getopt.(c|h) to the cli sources in case of MSVC. AFAIK getopt has bsd-like license, so we may include it sources without problem.

Revision history for this message
Serge Poltavsky (serge-uliss) wrote :

GNU getopt is licensed by LGPL so we can include it source files in distibution. It's need to include
getopt.h getopt.c, getopt1.c and COPYING.LIB to source code.

if target system use GLIBC, this files will not increase size of program

Revision history for this message
Alex Samorukov (samm-os2) wrote :

getopt is older then [L]GPL and exists also in BSD license (e.g. in FreeBSD), which has no such requirements.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

You can not add LGPL sources to BSD projects directly. You can only link to them. So making it work is more difficult than just rolling your own.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

I have just committed a patch that has all the same functionality as this patch, but does not use getopt. It's a bit uglier but on the other hand 100% portable.

Revision history for this message
Alex Samorukov (samm-os2) wrote :

please, also don`t forget to about https://bugs.launchpad.net/cuneiform-linux/+bug/260959/comments/4, because without this rtf files are not usable.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

Pushed.

Changed in cuneiform-linux:
status: New → Fix Committed
Changed in cuneiform-linux:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.