help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] adding --csv output


From: glpk xypron
Subject: Re: [Help-glpk] adding --csv output
Date: Sat, 15 Jan 2011 08:00:36 +0100

Hello Kevin, hello Andrew,

> Would further work on this patch be appreciated, or, more appropriately, 
> accepted?  Having CSV output would really help to more elegantly 
> streamline a couple of my workflows and needs.

As indicated I would rather avoid duplicate code
because it makes maintenance error prone.

If we want to follow the idea to change xfprintf to output CSV
the changes described below are necessary.

Andrew, could you, please, indicate what your thoughts about CSV
output are.

In glpenv.h:

A constant for csv files has to be added (after FH_FILE), e.g.
#define FH_FILE   0x11  /* FILE   */
#if 1 /* 16/I-2011 */
#define FH_CSV    0x12  /* CSV file */
#endif

In glpenv07.c:

xfopen has to be changed to set the type flag for csv if the filename
has extension ".csv", e.g.
#if 1 /* 16/I-2011 */
      char *ext = strrchr(fname, '.');
      type = FH_FILE;
      if (ext == NULL)
      {
      } else if (strcmp(ext, ".gz") == 0)
      {  type = FH_ZLIB;
      } else if (strcmp(ext, ".csv") == 0)
      {  type = FH_CSV;
      }
      if ( type != FH_ZLIB )
      {  fh = c_fopen(fname, mode);
      }
      else
      {  fh = z_fopen(fname, mode);
      }
#else
      if (!is_gz_file(fname))
      {  type = FH_FILE;
         fh = c_fopen(fname, mode);
      }
      else
      {  type = FH_ZLIB;
         fh = z_fopen(fname, mode);
      }
#endif


xfgetc, xfputc, xferror, xfeof, xfflush, xfclose have to be changed
to treat csv files like FH_FILE, e.g.
      switch (fp->type)
      {  case FH_FILE:
#if 1 /* 16/I-2011 */
         case FH_CSV:
#endif

A replacement for xfprintf has to be written, that parses the printf
format string, csv escapes all strings, and inserts commas, if the
file type is csv.

http://www.ijs.si/software/snprintf/
is a good starting point for writing a parser for printf format strings.

The reference for the csv file format should be
http://www.ietf.org/rfc/rfc4180.txt

Best regards

Xypron
-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de



reply via email to

[Prev in Thread] Current Thread [Next in Thread]