"/* This file is part of GNU epsilon, a functional language implementation\n"
"\n"
"Copyright (C) 2003 Luca Saiu\n"
"\n"
"GNU epsilon is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published\n"
"by the Free Software Foundation; either version 2, or (at your\n"
"option) any later version.\n"
"\n"
"GNU epsilon is distributed in the hope that it will be useful, but\n"
"WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
"General Public License for more details.\n"
"\n"
"You should have received a copy of the GNU General Public License\n"
"along with epsilon; see the file COPYING.  If not, write to the\n"
"Free Software Foundation, Inc., 59 Temple Place - Suite 330,\n"
"Boston, MA 02111-1307, USA. */\n"
"\n"
"\n"
"/* Code for the s_fileor instruction */\n"
"\n"
"char* filename;\n"
"integer_t i;\n"
"integer_t size;\n"
"\n"
"/* Convert top (the filename) into a C string: */\n"
"size = ((integer_t*)top)[0];\n"
"filename = (char*) xmalloc(sizeof(char) * (size + 1));\n"
"for(i = 0; i < size; i++)\n"
"     filename[i] = (char)(((integer_t*)top)[i + 1]);\n"
"filename[i] = \'\\0\';\n"
"\n"
"/* Open the file and put the FILE* into the I/O register: */\n"
"if((output_register = fopen(filename, \"r\")) == NULL)\n"
"  /* fopen() failed: */\n"
"  switch(errno){\n"
"  case ENOENT: {\n"
"    THROW(file_not_found_exception, NULL);\n"
"    break; /* just for uniformity */\n"
"  }\n"
"  case EACCES: case EPERM: {\n"
"    THROW(permission_denied_exception, NULL);\n"
"    break; /* just for uniformity */\n"
"  }\n"
"  default: {\n"
"    fprintf(stderr, \"fopen() failed (%s)\\n\", strerror (errno));\n"
"    fprintf(stderr, \"To do: deal with this case in s_fileor\\n\");\n"
"    THROW(unimplemented_exception, NULL);\n"
"  }\n"
"  } /* switch */\n"
"\n"
"\n"
"/* remove the filename from the stack: */\n"
"POP; \n"
"/* Free the C filename string */\n"
"free(filename);\n"
""
