PageRenderTime 43ms CodeModel.GetById 33ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/farmR/src/glplib09.c

https://code.google.com/p/javawfm/
C | 95 lines | 37 code | 8 blank | 50 comment | 4 complexity | 377be40e9eb09d6038860c06fef217e8 MD5 | raw file
 1/* glplib09.c (formatted input/output) */
 2
 3/***********************************************************************
 4*  This code is part of GLPK (GNU Linear Programming Kit).
 5*
 6*  Copyright (C) 2000,01,02,03,04,05,06,07,08,2009 Andrew Makhorin,
 7*  Department for Applied Informatics, Moscow Aviation Institute,
 8*  Moscow, Russia. All rights reserved. E-mail: <mao@mai2.rcnet.ru>.
 9*
10*  GLPK is free software: you can redistribute it and/or modify it
11*  under the terms of the GNU General Public License as published by
12*  the Free Software Foundation, either version 3 of the License, or
13*  (at your option) any later version.
14*
15*  GLPK is distributed in the hope that it will be useful, but WITHOUT
16*  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17*  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18*  License for more details.
19*
20*  You should have received a copy of the GNU General Public License
21*  along with GLPK. If not, see <http://www.gnu.org/licenses/>.
22***********************************************************************/
23
24#define _GLPSTD_STDIO
25#include "glplib.h"
26
27/***********************************************************************
28*  NAME
29*
30*  lib_doprnt - perform formatted output (basic routine)
31*
32*  SYNOPSIS
33*
34*  #include "glplib.h"
35*  int lib_doprnt(int (*func)(void *info, int c), void *info,
36*     const char *fmt, va_list arg);
37*
38*  DESCRIPTION
39*
40*  The routine xdoprnt is a basic routine to perform formatted output.
41*  It is equivalent to the standard routine vfprintf, except that the
42*  output is passed to the formal routine func rather than to an output
43*  stream.
44*
45*  The formal routine func is called every time a next character should
46*  be written. If there is an output error, it should return a negative
47*  value, in which case the output is terminated.
48*
49*  RETURNS
50*
51*  The routine xdoprnt returns the number of characters passed to the
52*  formal routine func. However, if there was an output error (detected
53*  by the formal routine func), a negative value is returned. */
54
55int lib_doprnt(int (*func)(void *info, int c), void *info,
56      const char *fmt, va_list arg)
57{     int cnt, j;
58      char buf[4000+1];
59#ifdef HAVE_VSNPRINTF
60      cnt = vsnprintf(buf, sizeof(buf), fmt, arg);
61#else
62      cnt = vsprintf(buf, fmt, arg);
63#endif
64      xassert(0 <= cnt && cnt < sizeof(buf));
65      xassert((int)strlen(buf) == cnt);
66      for (j = 0; j < cnt; j++)
67      {  if (func(info, (unsigned char)buf[j]) < 0)
68         {  cnt = -1;
69            break;
70         }
71      }
72      return cnt;
73}
74
75/**********************************************************************/
76
77static int my_put(void *file, int c)
78{     return
79         xfputc(c, file);
80}
81
82int xfprintf(XFILE *file, const char *fmt, ...)
83{     va_list arg;
84      int ret;
85      va_start(arg, fmt);
86#if 0
87      ret = vfprintf(file->fp, fmt, arg);
88#else
89      ret = lib_doprnt(my_put, file, fmt, arg);
90#endif
91      va_end(arg);
92      return ret;
93}
94
95/* eof */