Boston, MA 02111-1307, USA. */
+#include "system.h"
+
#if defined (VMS) & !defined (__VMS_POSIX)
#include <ssdef.h>
#define unlink delete
#endif
#include <stdio.h>
-#include "system.h"
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#include "files.h"
#include "alloc.h"
#include "gram.h"
void openfiles PARAMS((void));
void open_extra_files PARAMS((void));
FILE *tryopen PARAMS((char *, char *)); /* This might be a good idea */
+int tryclose PARAMS((FILE *));
void done PARAMS((int));
extern char *program_name;
openfiles (void)
{
char *name_base;
+#ifdef MSDOS
register char *cp;
+#endif
char *filename;
int base_length;
int short_base_length;
strlwr (infile);
#endif /* _WIN32 && !__CYGWIN32__ */
-#if (defined(unix) || defined(__unix) || defined(__unix__))
+#if (defined(unix) || defined(__unix) || defined(__unix__) || defined(__EMX__))
{
char *tmp_ptr = getenv("TMPDIR");
{
FILE *ftmp;
int c;
- char *filename, *cp;
+ char *filename;
+#ifdef MSDOS
+ char *cp;
+#endif
- if (fparser)
- fclose(fparser);
+ tryclose(fparser);
if (! noparserflag)
{
rewind(fattrs);
while((c=getc(fattrs))!=EOF) /* Thank god for buffering */
putc(c,ftmp);
- fclose(fattrs);
+ tryclose(fattrs);
fattrs=ftmp;
fguard = tryopen(guardfile, "w");
return ptr;
}
-void
-done (int k)
+int
+tryclose (FILE *ptr)
{
- if (faction)
- fclose(faction);
-
- if (fattrs)
- fclose(fattrs);
+ int result;
- if (fguard)
- fclose(fguard);
-
- if (finput)
- fclose(finput);
+ if (ptr == NULL)
+ return 0;
- if (fparser)
- fclose(fparser);
+ result = fclose (ptr);
+ if (result == EOF)
+ {
+ fprintf (stderr, "%s: ", program_name);
+ perror ("fclose");
+ done (2);
+ }
+ return result;
+}
- if (foutput)
- fclose(foutput);
+void
+done (int k)
+{
+ tryclose(faction);
+ tryclose(fattrs);
+ tryclose(fguard);
+ tryclose(finput);
+ tryclose(fparser);
+ tryclose(foutput);
/* JF write out the output file */
if (k == 0 && ftable)
rewind(ftable);
while((c=getc(ftable)) != EOF)
putc(c,ftmp);
- fclose(ftmp);
- fclose(ftable);
+ tryclose(ftmp);
+ tryclose(ftable);
if (definesflag)
{
rewind(fdefines);
while((c=getc(fdefines)) != EOF)
putc(c,ftmp);
- fclose(ftmp);
- fclose(fdefines);
+ tryclose(ftmp);
+ tryclose(fdefines);
}
}