Пример #1
0
/******************************************************************************
 *
 *	F I L E A P R O C (char *procname,char *filename, char *comm)
 *
 * Saves the procedure 'procname' in the file 'filename' for the command 'comm'.
 *
 * If the procname parameter is CHARNIL then saves all the currently known
 * procedures into the file filename
 * OR
 * if procname is not CHARNIL the procedure is checked to exist (lookup_proc()).
 *
 * The file "filename" is opened for write using iclopenasoutfp()
 * If procname is CHARNIL then forall_typed_symbols() is called with
 * listproc() to print all the procs to the file otherwise listproc() is used
 * once to list the named proc to filename.
 * The file filename is then closed using iclcloseasoutfp().
 *
 ******************************************************************************
 */
value
fileaproc(char *procname, char *filename, char *comm)
{
    extern value iclopenasoutfp (char *whofor, char *filename);	/* output.c */
    extern value iclcloseasoutfp(char *whofor, char *filename);	/* output.c */
    node *proc = NULL;
    value val;

    if (procname != CHARNIL) {				/* Named procedure */
	if( (proc = lookup_proc(procname)) == NODENIL)
	    return exception2(
		"PROCERR  %s: Unrecognised procedure or command name %s",
		comm, procname);
    } else
	if( symbol_total(world, SYM_PROC) == 0)	{	/* No procedures */
	    unlink(filename);
	    return trueval;
	}

    if (isexc(val = iclopenasoutfp(comm, filename)))
	return val;
    if (procname == CHARNIL )				/* All procedures */
	(void) forall_typed_symbols(SYM_PROC, listproc);
    else
	(void) listproc(procname, proc, 0);
    return (iclcloseasoutfp(comm, filename));
}
Пример #2
0
void
boost_throw_exception_test()
    {
    try
        {
        BOOST_THROW_EXCEPTION(exception1());
        BOOST_ERROR("BOOST_THROW_EXCEPTION failed to throw.");
        }
    catch(
    boost::exception & x )
        {
        char const * const * file=boost::get_error_info<boost::throw_function>(x);
        char const * const * function=boost::get_error_info<boost::throw_file>(x);
        int const * line=boost::get_error_info<boost::throw_line>(x);
        BOOST_TEST( file && *file );
        BOOST_TEST( function && *function );
        BOOST_TEST( line && *line==32 );
        }
    catch(
    ... )
        {
        BOOST_TEST(false);
        }
    try
        {
        BOOST_THROW_EXCEPTION(exception2() << test_data(42));
        BOOST_ERROR("BOOST_THROW_EXCEPTION failed to throw.");
        }
    catch(
    boost::exception & x )
        {
        char const * const * file=boost::get_error_info<boost::throw_function>(x);
        char const * const * function=boost::get_error_info<boost::throw_file>(x);
        int const * line=boost::get_error_info<boost::throw_line>(x);
        int const * data=boost::get_error_info<test_data>(x);
        BOOST_TEST( file && *file );
        BOOST_TEST( function && *function );
        BOOST_TEST( line && *line==52 );
        BOOST_TEST( data && *data==42 );
        }
    catch(
    ... )
        {
        BOOST_TEST(false);
        }
    }
Пример #3
0
/******************************************************************************
 *
 *	L O O K F O R _ V A R I A B L E _ V A L U E (symtab *sym, char * name)
 *
 * This routine looks up a variable in a given symbol_table.
 *
 * If the variable is a parameter then, on calling the current procedure we
 * could have passed EITHER an expression, which is evaluated and the formal
 * node's value member points to that value (whose interpret member will not
 * be parameter_interpret())
 * OR
 * a variable.  In this case the value member points to a node whose type is
 * TYPE_SYMTAB, whose interpret member is parameter_interpret(), whose
 * symboltable_part() member points to the symbol table of the corresponding
 * actual variable and whose sub[0] member points to a node that is the
 * corresponding actual variable (ie a name_interpret() node whose value field
 * is an ICL string whose value is the identity of the passed variable).
 *
 * If a value cannot be found, a suitable exception is returned.
 *
 * RETURNS AN ACTUAL VALUE STRUCTURE - IE A COPY OF ONE IN A
 * SYMBOL TABLE
 *
 ******************************************************************************
 */
value
lookfor_variable_value(symtab * sym, char *name)
{
    node *var, *var2;

    if ((var = get_symbol(sym, name, SYM_VARIABLE)) != NODENIL)
	return var->val;
    else if ((var = get_symbol(sym, name, SYM_PARAMETER)) == NODENIL)
	return exception1("UNDEFVAR variable \"%s\" not defined", name);
/*
 * do we have a parameter that was passed an expression ?
 */
    else if (var->interpret != parameter_interpret)
	return var->val;
    else if ((var2 = get_passbyreferencevar(var)) != NODENIL)
	return var2->val;
    else
	return exception2(
		"UNDEFVAR Parameter \"%s\" is undefined variable \"%s\"",
		 name,
		 string_part(var->sub[0]->val));
}
Пример #4
0
int main(int argc, char *argv[]) 
{
  char cmd_buff[1024];
  char *pinput;
  char *fname = argv[1];
  char *mode = "r";
  FILE *f= fopen(fname, mode);
  cmd_line *c, *backup;
  char* extra_buff;
  char* test = malloc(sizeof(char)*514);
  char buf[1024];

  if(argv[2] != NULL){ /*if trying to run batch with 2 filenames*/                                                
    err();
    exit(0);
  }

  if(f == NULL){ /*if read is invalid*/
    err();
    exit(0);
  }
  dw = getcwd(buf, 1024); /*for global var accessible to function calls*/
  while (1) {
    /*INTERACTIVE MODE*/
    if(argv[1] == NULL){ 
      myPrint("myshell> ");
      pinput = fgets(cmd_buff, 100, stdin);
      c = parseCmdLine(cmd_buff);
      backup = c;
      while(backup != NULL){
        processCmd(backup->c);
        backup = backup->next;
      }
    /*BATCH MODE*/ 
    }  else if(argv[1] != NULL){
      memset(cmd_buff,'\0',514);
      pinput = fgets(cmd_buff, 514, f);
      
      if (!pinput) { /*invalid fgets*/
        exit(0);
      }

      if((extra_buff = strstr(cmd_buff,"\n"))!=NULL) {/*check if whole command has been taken in*/
        if (check_space(cmd_buff)==0) /*if all blank spaces, don't print*/
          continue;
        else {
      myPrint(cmd_buff); /*print command*/
      collapsed_str(cmd_buff,test); 
      /*CATCH ERRORS RIGHT AWAY*/
      if(exception1(test)==1){
        err();
      }
      else if(exception2(test)==1) {
        err();
      }
      else if(exception3(test)==1) {
        continue;
      }
      /*PARSE*/
      else {
        c = parseCmdLine(cmd_buff);
        backup = c;
        while(backup != NULL){
          processCmd(backup->c);
          
          backup = backup->next;
        }
        free_cmdline(c);
      }
    }
      }
      /*COMMAND TOO LONG*/
      if(extra_buff==NULL) {
        myPrint(cmd_buff);

        while(fgets(cmd_buff,1024,f)!=NULL) {/*keep getting more chars while you can*/
          if((strlen(cmd_buff)<1023) || cmd_buff[1022]=='\n') { /*if new one is shorter than max, break*/
            myPrint(cmd_buff);
            memset(cmd_buff, '\0', 1024);
            break;
          }
          else 
            myPrint(cmd_buff); /*else keep getting*/
          memset(cmd_buff, '\0', 1024);
        }
    err();
      }
      
    }
  }
  free(test);   
fclose(f);
return 0;
}