1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
/*** io.c **********************************************************************
**
** This file is part of BibTool.
** It is distributed under the GNU General Public License.
** See the file COPYING for details.
**
** (c) 1996-2017 Gerd Neugebauer
**
** Net: gene@gerd-neugebauer.de
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2, or (at your option)
** any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
**-----------------------------------------------------------------------------
** Description:
**
**
******************************************************************************/
#include <bibtool/general.h>
#include <bibtool/error.h>
#include <bibtool/io.h>
#include "config.h"
/*****************************************************************************/
/* Internal Programs */
/*===========================================================================*/
#ifdef __STDC__
#define _ARG(A) A
#else
#define _ARG(A) ()
#endif
void save_input_file _ARG((char *file)); /* */
void save_macro_file _ARG((char *file)); /* */
void save_output_file _ARG((char * file)); /* */
/*****************************************************************************/
/* External Programs and Variables */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*****************************************************************************/
/*** Input File Pipe Section ***/
/*****************************************************************************/
#define InputFilePipeIncrement 8
static char **input_files;
static int input_file_size = 0;
static int input_file_ptr = 0;
#define InputPipeIsFull (input_file_ptr >= input_file_size)
#define InputPipeIsEmpty (input_file_ptr == 0)
#define PushToInputPipe(FILE) input_files[input_file_ptr++] = FILE
#define ForAllInputFiles(FILE) for (FILE=input_files; \
FILE<&input_files[input_file_ptr]; \
FILE++)
/*-----------------------------------------------------------------------------
** Function: save_input_file()
** Purpose: The input file pipe is a dynamic array of strings.
** This fifo stack is used to store the input \BibTeX{}
** files to be processed by \BibTool.
**
** This function is called to push an string into the pipe.
** If necessary the array has to be allocated or enlarged.
** This is done in larger junks to avoid lots of calls to
** |realloc()|.
** Arguments:
** file File name to save.
** Returns: nothing
**___________________________________________________ */
void save_input_file(file) /* */
char *file; /* */
{ /* */
if (file == NULL) /* */
{ WARNING("Missing input file name. Flag ignored.");/* */
return; /* */
} /* */
if (*file == '-' && file[1] == '\0') /* */
{ file = NULL; } /* */
/* */
if (InputPipeIsFull) /* No space left? */
{ input_file_size += InputFilePipeIncrement; /* */
/* */
if (InputPipeIsEmpty /* Try to enlarge array */
? NULL==(input_files= /* */
(char**)malloc(sizeof(char*) /* */
*(size_t)input_file_size))/* */
: NULL==(input_files= /* */
(char**)realloc((char*)input_files,/* */
sizeof(char*) /* */
*(size_t)input_file_size))/* */
) /* */
{ OUT_OF_MEMORY("input file pipe."); } /* */
} /* */
PushToInputPipe(file); /* */
} /*------------------------*/
/*-----------------------------------------------------------------------------
** Function: get_no_inputs()
** Type: int
** Purpose:
**
** Arguments:
**
** Returns:
**___________________________________________________ */
int get_no_inputs() /* */
{ /* */
return input_file_ptr; /* */
} /*------------------------*/
/*-----------------------------------------------------------------------------
** Function: get_input_file()
** Type: char *
** Purpose:
**
** Arguments:
** i
** Returns:
**___________________________________________________ */
char * get_input_file(i) /* */
int i; /* */
{ return (i >= 0 && i < input_file_ptr /* */
? input_files[i] /* */
: NULL); /* */
} /*------------------------*/
/*****************************************************************************/
/*** Output File Section ***/
/*****************************************************************************/
char *output_file = NULL; /* */
/*-----------------------------------------------------------------------------
** Function: save_output_file()
** Purpose: Simply feed the output file name into the static variable.
** This function is useful since it can be called from rsc.c
** Arguments:
** file File name to save
** Returns: nothing
**___________________________________________________ */
void save_output_file(file) /* */
char * file; /* */
{ if ( output_file != NULL ) /* */
{ WARNING2("Output file redefined: ",file); } /* */
output_file = file; /* */
} /*------------------------*/
/*-----------------------------------------------------------------------------
** Function: get_output_file()
** Type: char*
** Purpose:
**
** Arguments:
**
** Returns:
**___________________________________________________ */
char* get_output_file() /* */
{ return output_file; /* */
} /*------------------------*/
/*****************************************************************************/
/*** Macro File Section ***/
/*****************************************************************************/
char *macro_file = NULL; /* */
/*-----------------------------------------------------------------------------
** Function: save_macro_file()
** Purpose: Simply feed the macro file name into the static variable.
** This function is useful since it can be called from rsc.c
** Arguments:
** file File name to save
** Returns: nothing
**___________________________________________________ */
void save_macro_file(file) /* */
char *file; /* */
{ if ( macro_file != NULL ) /* */
{ WARNING2("Macro file redefined: ",file); } /* */
macro_file = file; /* */
} /*------------------------*/
/*-----------------------------------------------------------------------------
** Function: get_macro_file()
** Type: char*
** Purpose:
**
** Arguments:
**
** Returns:
**___________________________________________________ */
char* get_macro_file() /* */
{ return macro_file; /* */
} /*------------------------*/
|