Exemplo n.º 1
0
bool_t start_file_fun(void *user, const char_t *file, const char_t **xpaths) {
  parserinfo_mv_t *pinfo = (parserinfo_mv_t *)user;
  if( pinfo ) {

    if( checkflag(pinfo->flags,MV_FLAG_TARGET) ) {

      if( (strcmp(file, "stdin") == 0) && 
	  checkflag(pinfo->rcm.flags, RCM_WRITE_FILES) ) {
	errormsg(E_WARNING, "cannot write to stdin, ignoring this file.\n");
	return FALSE;
      }
      cp_start_target_rcm(&pinfo->rcm, file);

    } else {

      if( strcmp(file, "stdout") == 0 ) {
	if( checkflag(pinfo->flags, MV_FLAG_SEEN_STDOUT) ) {
	  if( false_and_setflag(&pinfo->flags, MV_FLAG_WARN_STDOUT) ) {
	    errormsg(E_WARNING, 
		     "only one stdout target allowed, ignoring remaining.\n");
	  }
	}
	setflag(&pinfo->flags, MV_FLAG_SEEN_STDOUT);
      }
    
      if( checkflag(pinfo->rcm.flags, RCM_WRITE_FILES) ) {

	if( strcmp(file, "stdin") == 0 ) {
	  errormsg(E_WARNING, "cannot write to stdin, ignoring this file.\n");
	  return FALSE;
	}

      } else {

	/* this only occurs the first time the target is seen */
	if( (strcmp(file, pinfo->target) == 0) && 
	    pinfo->tempfile && (pinfo->tempfd != -1) ) {
	  open_redirect_stdout(pinfo->tempfd);
	  setflag(&pinfo->rcm.flags, RCM_RM_OUTPUT);
	}

      }
      rm_start_file_rcm(&pinfo->rcm, file);

    }
    return TRUE;
  }
  return FALSE;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
/****************************************************************************
 *
 ***************************************************************************/
{
char	 err_file[100];
long	 err_line;
int 	 err_char;
int 	 err;
void	 *pexe;
char	 *efname = NULL;						/* Errors file name.	*/
char	 *sfname = NULL;						/* Source file name.	*/
char	 *dfname = NULL;						/* Dump file name.		*/
Boolean   runflag = TRUE;
char	 *argp;
int 	 counter;
Poco_lib *builtin_libs;

builtin_libs = get_poco_libs();

#ifndef __TURBOC__
  init_stdfiles();	/* initialize PJ stdin, stdout, etc */
#endif

signal(SIGFPE, fpe_handler);	// install floating point error trapping

for (counter = 1; counter < argc; counter++)
	{
	argp = argv[counter];
	if (*argp == '-')
		{
		switch (toupper(*++argp))
			{
			case 'C':                           /* Compile-only switch...   */
				runflag = FALSE;
				break;
#ifdef DEVELOPMENT
			case 'T':                           /* Trace... */
				po_trace_flag = TRUE;
				po_trace_file = stdout;
				break;
#endif /* DEVELOPMENT */
			case 'D':                           /* Dump file name...        */
				if (*++argp != '\0')
					dfname = argp;
				else
					dfname = "DUMP.";
				break;
			case 'O':                           /* Redirection file name... */
				if (*++argp != 0)
					efname = argp;
				else
					efname = "stdout.txt";
				break;
			case 'L':                           /* punt builtin libs...*/
				builtin_libs = NULL;
				break;
			case 'V':
				fprintf(stdout,"Poco version " VRSN_STR "\n");
				break;
			default:							/* Fat-finger case...		*/
				break;
			}
		}
	else
		{
		sfname = argp;		/* It's not a switch, must be the source file. */
		}
	}

if (NULL == sfname)
	sfname = "test.poc";

if (NULL == strchr(sfname, '.'))        /* If no '.' in name, tack on .POC */
	strcat(sfname, ".poc");

if (NULL != efname)
	if (Success != (err = open_redirect_stdout(efname)))
		{
		fprintf(stdout, "Error attempting to redirect stdout to '%s'\n", efname);
		exit(-1);
		}

if (Success == (err = compile_poco(&pexe, sfname, NULL, dfname,
					builtin_libs,
					err_file, &err_line, &err_char,
					incdirs
					)))
	{
#ifdef DEVELOPMENT
	po_run_protos = (((Poco_run_env *)pexe)->protos);	/* for trace */
#endif /* DEVELOPMENT */
	if (runflag)
		{
		err = run_poco(&pexe, NULL,
							check_abort, NULL, &err_line);
		}

	free_poco(&pexe);
	}

if (err < Success )
	{
	switch (err)
		{
		case Err_no_memory:
			fprintf(stdout,"Out of memory\n");
			break;
		case Err_no_file:
			fprintf(stdout,"Couldn't find %s\n", sfname);
			break;
		case Err_create:
			fprintf(stdout,"Couldn't create error/dump/trace files (disk full?)\n");
			break;
		case Err_syntax:
			fprintf(stdout,"Poco C syntax error.\n");
			break;
		case Err_poco_internal:
			fprintf(stdout,"Poco compiler failed self-check.\n");
			break;
		case Err_no_main:
			fprintf(stdout,"Program does not contain a main() routine.\n");
			break;
		case Err_in_err_file:
		case Err_abort:
		default:
			break;
		}
	fprintf(stdout,"Error code %d\n", err);
	}

	if (efname != NULL)
		close_redirect_stdout();

#ifndef __TURBOC__
  cleanup_lfiles(); /* cleanup PJ stdin, stdout, etc */
#endif

	return err;
}