/*
 *	Create a DECL_... node of code CODE, name NAME
 *	and data type TYPE. We do NOT enter this node
 *	in any sort of symbol table.
 *
 *	layout_decl is used to set up the decl's storage layout.
 *	Other slots are initialized to 0 or null pointers.
 */
tree
build_decl (enum tree_code code, tree name, tree type)
{
	register tree	t;

	t = make_node (code);

#if (0)	/*************************************/
	/*
	 *	That is not done, deliberately, so that
	 *	having error_mark_node as the type can
	 *	suppress useless errors in the use of
	 *	this variable.
	 */
	if (type == error_mark_node)
		type = integer_type_node;
#endif	/*************************************/

	DECL_NAME (t) = name;

	if (name)
	{
		DECL_PRINT_NAME (t) = IDENTIFIER_POINTER (name);
		DECL_ASSEMBLER_NAME (t) = IDENTIFIER_POINTER (name);
	}

	TREE_TYPE (t) = type;
	DECL_ARGUMENTS (t) = NULL_TREE;
	DECL_INITIAL (t) = NULL_TREE;

	if (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL)
		layout_decl (t, 0);
	elif (code == FUNCTION_DECL)
		DECL_MODE (t) = FUNCTION_MODE;

	return (t);

}	/* end build_decl */
Beispiel #2
0
main (int argc, const char *argv[])
{
	quad	q, p;

#if (0)	/*******************************************************/
	printf ("%d\n", __cmpdi2 ((quad)4, (quad)5));
	printf ("%d\n", __cmpdi2 ((quad)5, (quad)5));
	printf ("%d\n", __cmpdi2 ((quad)6, (quad)5));

	printf ("%d\n", __cmpdi2 ((quad)-4, (quad)-5));
	printf ("%d\n", __cmpdi2 ((quad)-5, (quad)-5));
	printf ("%d\n", __cmpdi2 ((quad)-6, (quad)-5));
	printf ("\n");
#endif	/*******************************************************/

	p = 5ll; q = 4ll;
	printf ("5 :: 4	=> ");

	if   (p > q)
		printf ("É maior\n");
	elif (p < q)
		printf ("É menor\n");
	else
/*
 ****************************************************************
 *	Programa principal					*
 ****************************************************************
 */
int
main (int argc, const char *argv[])
{
	XStandardColormap stdcmap, *cmp;
	Display		*dpy = NULL;
	Window		root, win;
	XGCValues	gcv;
	int		depth;

	FILE		*fp;
	XImage		*ximage = NULL;
	IMAGE		*last_image, *ip, *old_ip;
	int		nimages, times;

	const char	*display = NOSTR;
	int		time_interval = 0;
	int		opt, exit_val = 0;
	int		Nflag = 0;

	Atom		map;
	KeySym		key;

	save_argc = argc;	save_argv = argv;

	/*
	 *	Analisa as opções de execução.
	 */
	while ((opt = getopt (argc, argv, "d:f:HMNRs:v")) != EOF)
	{
		switch (opt)
		{
		    case 'd':
			display = optarg;
			break;

		    case 'f':
			if (strchr (optarg, '/') != NOSTR)
			{
				int	num, den;

				sscanf (optarg, "%d/%d", &num, &den);

				if (num != 1 || den <= 0 || den > 8)
					msg ("$Fator redutivo inválido");

				default_factor = -den + 1;
			}
			else
			{
				sscanf (optarg, "%d", &default_factor);

				if (default_factor <= 0 || default_factor > 8)
					msg ("$Fator de ampliação inválido");

				default_factor--;
			}
			break;

		    case 'H':
			help (0);
			break;

		    case 'M':
			return (0);

		    case 'N':
			Nflag++;
			break;

		    case 'R':
			Rflag++;
			break;

		    case 's':
			time_interval = atol (optarg);

			if (time_interval < 1 || time_interval > 60)
			{
				msg ("Argumento inválido para opção '-s'");
				help (1);
			}

			break;

		    case 'v':
			vflag++;
			break;

		    default:
			putc ('\n', stderr);
			help (2);

		}	/* end switch (opt) */

	}	/* end while (analisando opções) */

	argv += optind;
	argc -= optind;

	/*
	 *	Consistência final das Opções.
	 */
	if (Nflag)
	{
		if (argc > 0 || *argv != NOSTR)
			msg ("$Com a opção '-N' NÃO podem ser dados nomes de arquivos");

		argv = read_args_from_stdin (&argc);
	}

	if (Rflag && time_interval > 0)
		msg ("$As opções '-R' e '-s' são incompatíveis");

	/*
	 *	Constrói a Tabela de Imagens.
	 */
	for (/* acima */; *argv != NULL; argv++)
	{
		if (ftw (*argv, add_image_to_table) < 0)
			msg ("$*Erro em \"ftw (%s)\"", *argv);
	}

	if ((nimages = next_image - images) <= 0)
		msg ("$Não foram encontrados arquivos contendo imagens");

	last_image = next_image - 1;

	if (Rflag && nimages > 1)
	{
		/* Escolhe aleatoriamente uma imagem */

		images += (time (NULL) % nimages); last_image = images;

		msg ("Imagem a a janela-mãe: \"%s\"", images->i_name);
	}

	/*
	 *	Abre a conexão com o servidor.
	 */
	if ((dpy = XOpenDisplay (display)) == NULL)
	{
		msg
		(	"$Não consegui conectar-me ao servidor \"%s\"",
			XDisplayName (display)
		);
	}

	screen = DefaultScreen (dpy);
	depth  = DefaultDepth (dpy, screen);
	root   = RootWindow (dpy, screen);

	/*
	 *	Obtém o mapa de cores de acordo com a profundidade.
	 */
	cmp = &stdcmap;

	map = (depth <= 8) ? XA_RGB_DEFAULT_MAP : XA_RGB_BEST_MAP;

	if (!XGetStandardColormap (dpy, root, cmp, map))
	{
		cmp = NULL;
		msg ("Mapa de cores padrão para profundidade %d não disponível", depth);
	}

	/*
	 *	Decide se cria ou não uma janela para exibir as imagens.
	 */
	win = Rflag ? root : create_window (dpy);

	gcv.foreground = WhitePixel (dpy, screen);
	gcv.background = BlackPixel (dpy, screen);

	gc = XCreateGC (dpy, win, GCForeground|GCBackground, &gcv);

	/*
	 *	Mostra as imagens.
	 */
	for (times = 0, old_ip = NOIMAGE, ip = images; ip != NOIMAGE; times++)
	{
		if (vflag && (times & 15) == 0 && nimages > 0)
		{
			printf ("\n NUM  FMT   LARG x  ALT   FATOR   CORES   TAMANHO  ARQUIVO\n");
			printf ("--------------------------------------------------------------\n");
		}

		if (old_ip != ip)
		{
			/* Abre o arquivo que contém a imagem */

			if ((fp = fdopen (inopen (ip->i_dev, ip->i_ino), "r")) == NOFILE)
			{
				msg ("*Não consegui abrir o arquivo \"%s\"", ip->i_name);
				exit_val++; break;
			}

			/* Lê a imagem para a memória */

			if ((ximage = (*ip->i_format->f_load) (fp, 1, dpy, cmp, ip)) == NULL)
			{
				msg ("Não consegui ler imagens do arquivo \"%s\"", ip->i_name);
				fclose (fp); exit_val++; break;
			}

			fclose (fp);

			/* Imprime, se necessário, algumas informações sobre a imagem */

			if (vflag)
			{
				char	factor[8];

				if (ip->i_factor >= 0)
					snprintf (factor, sizeof (factor), "%d",    ip->i_factor + 1);
				else
					snprintf (factor, sizeof (factor), "1/%d", -ip->i_factor + 1);

				printf
				(	"%4d  %s   %4d x %4d   %4s %8d  %8d  %s\n",
					ip - images + 1, ip->i_format->f_extension,
					ip->i_width,	 ip->i_height,  factor,
					ip->i_ncolors,	 ip->i_file_sz, ip->i_name
				);
			}

			/* Mostra a imagem como fundo da janela */

			if (draw_window (dpy, win, ximage, ip) < 0)
				break;

		}	/* end if (nova imagem) */

		/* Aguarda eventos e analisa o retorno */

		key = wait_for_events (dpy, win, time_interval);

		old_ip = ip;

		switch (key)
		{
		    case 'q':
		    case 'Q':
		    case XK_Escape:
			ip = NOIMAGE;		/* Fim do programa */
			break;

		    case XK_Up:
		    case XK_KP_Up:
			if (ip > images)
				ip--;		/* Retrocede uma imagem */
			break;

		    case XK_Down:
		    case XK_KP_Down:
			if (ip < last_image)
				ip++;		/* Avança uma imagem */
			elif (time_interval > 0)
				ip = images;	/* Volta ao início */
			break;

		    case XK_Home:
		    case XK_KP_Home:
			ip = images;		/* Volta ao início */
			break;

		    case XK_End:
		    case XK_KP_End:
			ip = last_image;	/* Vai para a última imagem */
			break;

		    case XK_Right:
		    case XK_KP_Right:
			ip->i_factor++;		/* Aumenta o fator */
			old_ip = NOIMAGE;
			break;

		    case XK_Left:		/* Diminui o fator */
		    case XK_KP_Left:
			ip->i_factor--;
			old_ip = NOIMAGE;
			break;

		    default:
			break;

		}	/* end switch (tecla retornada) */

		if (ip != old_ip)
			XDestroyImage (ximage);

	}	/* end for (percorrendo imagens) */

	XFreeGC (dpy, gc);

	XCloseDisplay (dpy);

	return (exit_val);

}	/* end main */
Beispiel #4
0
int main(int argc, char **argv)
{
	char dcname[40];
	AccMask setmask = 0;	
	AccMask clearmask = 0;
	char *s;

        PrgName = argv [0];

	if( argc < (1 + 1))
	{
		printf("Usage: %s [[-+=][rwefghvxyzda]] <Objects>\n", PrgName);
		exit(1);
	}

	argv++;
	
	s = *argv;

	if( *s == '+' || *s == '-' || *s == '=' )
	{
		AccMask *mask = &setmask;
		if( *s == '-' ) mask = &clearmask;
		elif( *s == '=' ) clearmask = 0xff;

		s++;
		
		while( *s != '\0' )
		{
			int bit = getbit(*s,FileChars);
			if( bit == 0 ) bit = getbit(*s,DirChars);
			if( bit == 0 ) printf("invalid bit character %c\n",*s);
			*mask |= bit;
			s++;
		}
		argv++;
	}
	
	for( ; *argv != NULL; argv++ )
	{
		char *name = *argv;
		Object *o;
		word e;
		
		o = Locate(CurrentDir,name);
		
		if( o == NULL ) 
		{
			fprintf(stderr,"could not locate %s : %x\n",name,Result2(CurrentDir));		
			continue;
		}
	
		if( clearmask || setmask )
		{
			AccMask mask = o->Access.Access;
			mask &= ~clearmask;
			mask |= setmask;
			
			e = Refine(o,mask);

			if( e < 0 )
				fprintf(stderr,"refine of %s failed: %x\n",name,e);
		}		
		
		DecodeCapability(dcname,&o->Access);	

		printf("%s%s\n",dcname,o->Name);
	}

	return 0;
}
Beispiel #5
0
/*
 ****************************************************************
 *	Calcula o Incremento Ótimo das SDIs			*
 ****************************************************************
 */
void
SDIs_metabolism (void)
{
	SDI		*src_sd, *sd;
	SYMTB		*sp;
	long		span;
	int		incr, value_incr;
	long		old_value, new_value, base;
	char		found;

	/*
	 *	Prepara o ponteiro para o rótulo seguinte a cada SDI
	 */
	for (sp = defhead->s_def, sd = sdi_first; sd != NOSDI; sd = sd->i_next)
	{
		for (/* acima */; /* abaixo */; sp = sp->s_def)
		{
			if (sp == NOSYMTB)
				{ sd->i_list = NOSYMTB; break; } 

			if (sp->s.s_type != TEXT)
				continue;

			if (sp->s.s_value >= sd->i_value)
				{ sd->i_list = sp; break; } 
		}
	}

	/*
	 *	Percorre a lista de SDIs até que nada mais se altere
	 */
	do
	{
		found = 0;

		for (src_sd = sdi_first; src_sd != NOSDI; src_sd = src_sd->i_next)
		{
			if (src_sd->i_type != JMP)
				continue;

			/* Se o rótulo não pertencer à seção TEXT ou	*/
			/* estiver indefinido, força a opção longa	*/

			if ((sp = src_sd->i_label)->s.s_type != TEXT)
				span = 400000;
			else
				span = sp->s.s_value - src_sd->i_value;

			if (span >= 0)		/* Para frente */
			{
				if   (span <= 127)
					incr = 0;
				elif (span <= 32767)
					incr = src_sd->i_med_inc;
				else
					incr = src_sd->i_max_inc;
			}
			else			/* Para trás */
			{
				if   (span >= -128)
					incr = 0;
				elif (span - src_sd->i_med_inc >= -32768)
					incr = src_sd->i_med_inc;
				else
					incr = src_sd->i_max_inc;
			}
Beispiel #6
0
static	void	produce_text_map(char *file, int rows, int cols, int hardware)
{ FILE	*output;
  int	i, j;
  
  if (file == (char *) NULL)
   output = stdout;
  else
   { output = fopen(file, "w");
     if (output == (FILE *) NULL)
      { fprintf(stderr, "buildrm: failed to open output file %s\n", file);
        exit(EXIT_FAILURE);
      }
   }
  fputs("Network /Net {\n", output);
  if (hardware == TelmatHardware)
   fputs("\tProcessor root { ~IO, ~00, , ext; system; }\n", output);
  else
   fputs("\tProcessor root { ~IO, ~00, , ; system; }\n", output);
  fputs("\tProcessor IO   { ~root; IO; }\n", output);
  fputs("\t{\n", output);
  switch(hardware)
   { case	NullHardware :
   	fputs("\t\tReset { driver; ; null_ra.d }\n", output);
   	break;
     case	TramHardware :
     	fputs("\t\tReset { driver; ; tram_ra.d }\n", output);
     	break;
     case	ParsytecHardware :
     	fputs("\t\tReset { driver; ; pa_ra.d }\n", output);
     	break;
     case	TelmatHardware :
     	fputs("\t\tReset { driver; silent; telmat_r.d }\n", output);
     	fputs("\t\tConfigure { driver; silent; telmat_c.d }\n", output);
     	break;
     case	MeikoHardware	:
     	fputs("\t\tReset { driver; ; rte_ra.d }\n", output);
     	fputs("\t\tConfigure { driver; ; rte_c.d }\n", output);
     	break;
   }

   for (i = 0; i < rows; i++)
    for (j = 0; j < cols; j++)
     { fprintf(output, "\t\tProcessor %02d { ", (i * cols) + j);

	/* link 0 */
       if ((i == 0) && (j == 0))
        fputs(" ~root,", output);
       elif (i == 0)
        fputs("      ,", output);
       else
        fprintf(output, "   ~%02d,", ((i - 1) * cols) + j);
        
       /* link 1 */
       if (j == (cols - 1))
        fputs("    ,", output);
       else
        fprintf(output, " ~%02d,", (i * cols) + j + 1);
        
       /* link 2 */
       if (i == (rows -1))
        fputs("    ,", output);
       else
        fprintf(output, " ~%02d,", ((i + 1) * cols) + j);
        
       /* and link 3 */
       if (j == 0)
        fputs("    ", output);
       else
        fprintf(output, " ~%02d", (i * cols) + j - 1);
        
       fputs("; }\n", output);
     }
Beispiel #7
0
// =============================================================================
//
// Try to parse an expression symbol (i.e. an OPER_erator or OPER_erand or a colon)
// from the lexer.
//
ExpressionSymbol* Expression::parseSymbol()
{
	int pos = m_lexer->position();
	ExpressionValue* op = null;

	if (m_lexer->next (TK_Colon))
		return new ExpressionColon;

	// Check for OPER_erator
	for (const OperatorInfo& op : g_Operators)
		if (m_lexer->next (op.token))
			return new ExpressionOperator ((ExpressionOperatorType) (&op - &g_Operators[0]));

	// Check sub-expression
	if (m_lexer->next (TK_ParenStart))
	{
		Expression expr (m_parser, m_lexer, m_type);
		m_lexer->mustGetNext (TK_ParenEnd);
		return expr.getResult()->clone();
	}

	op = new ExpressionValue (m_type);

	// Check function
	if (CommandInfo* comm = findCommandByName (m_lexer->peekNextString()))
	{
		m_lexer->skip();

		if (m_type != TYPE_Unknown && comm->returnvalue != m_type)
			error ("%1 returns an incompatible data type", comm->name);

		op->setBuffer (m_parser->parseCommand (comm));
		return op;
	}

	// Check for variables
	if (m_lexer->next (TK_DollarSign))
	{
		m_lexer->mustGetNext (TK_Symbol);
		Variable* var = m_parser->findVariable (getTokenString());

		if (var == null)
			error ("unknown variable %1", getTokenString());

		if (var->type != m_type)
			error ("expression requires %1, variable $%2 is of type %3",
				dataTypeName (m_type), var->name, dataTypeName (var->type));

		if (var->isarray)
		{
			m_lexer->mustGetNext (TK_BracketStart);
			Expression expr (m_parser, m_lexer, TYPE_Int);
			expr.getResult()->convertToBuffer();
			DataBuffer* buf = expr.getResult()->buffer()->clone();
			buf->writeDWord (DH_PushGlobalArray);
			buf->writeDWord (var->index);
			op->setBuffer (buf);
			m_lexer->mustGetNext (TK_BracketEnd);
		}
		elif (var->writelevel == WRITE_Constexpr)
			op->setValue (var->value);
		else
		{
/*
 ****************************************************************
 *	Ponto de Entrada					*
 ****************************************************************
 */
int
main (int argc, const char *argv[])
{
	int		opt;
	char		*mail_file;
	const char	*user;
	const char	*display = NOSTR, *geometry = NOSTR;
	const char	*fore_color_str, *user_fore_color_str = NOSTR;
	const char	*back_color_str, *user_back_color_str = NOSTR;
	const char	*str;

	save_argc = argc;
	save_argv = argv;

	/*
	 *	Analisa os argumentos para o programa.
	 */
	while ((opt = getopt (argc, argv, "MHid:D:g:b:f:u:m:")) != EOF)
	{
		switch (opt)
		{
		    case 'M':
			exit (0);

		    case 'H':
			help (0);

		    case 'i':
			iconic_state = IconicState;
			break;

		    case 'd':
			display = optarg;
			break;

		    case 'D':
		/***	desktop = optarg;	***/
			break;

		    case 'g':
			geometry = optarg;
			break;

		    case 'b':
			user_back_color_str = optarg;
			break;

		    case 'f':
			user_fore_color_str = optarg;
			break;

		    case 'u':
			clock_update = atol (optarg);
			if (clock_update < 1 || clock_update > MAX_CLOCK)
			{
				msg
				(	"$Argumento fora dos limites para"
					" opção '-u'"
				);
			}
			break;

		    case 'm':
			mail_update = atol (optarg);
			if (mail_update < 1 || mail_update > MAX_CLOCK)
			{
				msg
				(	"$Argumento fora dos limites para"
					" opção '-m'"
				);
			}
			break;

		    default:			/* Erro */
			putc ('\n', stderr);
			help (1);
		}
	}

	argv += optind;
	argc -= optind;

	if (argc != 0)
		help (1);

	/*
	 *	Abre a conexão com o servidor.
	 */
	if ((dpy = XOpenDisplay (display)) == NULL)
	{
		msg
		(	"$Não consegui conexão com o servidor \"%s\"",
			XDisplayName (display)
		);
	}

	/*
	 *	Guarda algumas informações da conexão.
	 */
	screen	= DefaultScreen (dpy);
	root	= RootWindow (dpy, screen);

	/*
	 ****** Tenta obter os valores de "XDefault" ************
	 */
	if   (user_fore_color_str != NOSTR)
		fore_color_str = user_fore_color_str;
	elif ((str = XGetDefault (dpy, "XClock", "foreground")) != NOSTR)
		fore_color_str = str;
	else
Beispiel #9
0
int
main(
     int argc,
     char **argv )
{
  long 		info      = false;
  int		size;
  long		changed   = false;
  long		progtype;
  char *	file      = NULL;
  char *	type 	  = NULL;
  char *	name	  = 0;
  long		stacksize = -1;
  long		heapsize  = -1;
  long		modules	  = false;

  
  argv++;
  
  while ( *argv != 0 )
    {
      char *arg = *argv;
      
      if ( *arg++ == '-' )
	{
	  switch ( *arg++ )
	    {
	    case 'n':
	      _ARG_;
	      name = arg;
	      break;
	      
	    case 's':
	      _ARG_;
	      stacksize = (long)atol( arg );
	      break;
	      
	    case 'h':
	      _ARG_;
	      heapsize = (long)atol( arg );
	      break;			
	      
	    case 'i':
	      info = true;
	      break;	
	      
	    case 'm':
	      modules = true;
	      break;
	      
	    }
	}
      else
	{
	  file = *argv;
	}
      
      argv++;
    }

  if (file == NULL)
    {
      fprintf( stderr, "objed: must have name of file to examine\n" );
      exit(1);
    }
  
  if (name == 0 && stacksize == -1 && heapsize == -1) /* nowt to write */
    {
      fd = fopen(file,"rb");
    }
  else
    {
#if defined(__TRAN) || defined(__ARM) || defined(R140) || defined(__C40) || defined (__HELIOS)
      fd = fopen( file, "r+b" );
#else
      fd = fopen( file, "rwb" );
#endif
    }
  
  if ( fd == 0 ) 
    { fprintf(stderr, "Cannot open %s\n",file );
      exit(1);
    }
  
  size = fread( &hdr, 1, sizeof (ImageHdr), fd );
  
  if ( size != sizeof(ImageHdr) )
   { fprintf( stderr, "Read failure: %d\n", size );
     exit(1);
   }
  
    {
      static Image_Magics	Values[] =
	{
	  /*
	   * XXX - the following have been extracted from /hsrc/include/module.h
	   *       make sure that they are kept up to date
	   */

	  { 0x12345678L,	"Transputer Helios Executable\n" },
	  { 0xc4045601L,	"Helios-C40 Executable\n" },
	  { 0x0a245601L,	"Helios-ARM Executable\n" },
	  { 0x86045601L,	"Helios-I860 Executable\n" },
#ifdef HOSTISBIGENDIAN
	  { 0x01560468L,	"Helios-M68K Executable\n" },
#else
	  { 0x68045601L,	"Helios-M68K Executable\n" },
#endif
	  { TaskForce_Magic,	"Task Force Binary\n" },
	  { RmLib_Magic,	"Resource Management Library Binary\n" }
	};
      unsigned long	value = swapword( hdr.Magic );
      int		i;


      for (i = sizeof (Values) / sizeof (Values[0]); i--;)
	{
	  if (value == Values[ i ].Magic)
	    {
	      printf( Values[ i ].Type );
	      break;	      
	    }
	}
      
      if (i < 0)
	{
	  fprintf( stderr,  "File not object image\n" );
	  exit(1);
	}

      if (Values[i].Magic == 0x01560468)
	{
	  swapopt = FALSE;
	}      
    }
  
  if ( info )
    printf( "Image size = %ld bytes\n", swapword( hdr.Size ) );

  size = fread( &prog, 1, sizeof (Program), fd );
  
  if ( size != sizeof (Program) )
   { fprintf(stderr, "Read failure: %d\n", size );
     exit(1);
   }
   
  progtype = swapword( prog.Module.Type );
  
  if   ( progtype == T_Program ) type = "Program";
  elif ( progtype == T_Module  ) type = "Module";
  elif ( progtype == T_ResRef  ) type = "ResRef"; 
  
  if ( type == NULL )
   { fprintf(stderr, "Invalid Module type: %lx\n",progtype );
     exit(1);
   }
  
  if ( info )
    {
      printf( "Object type is %s\n",type );
  
      printf( "Name is '%s' ",prog.Module.Name );
    }
  
  if ( name != 0 )
    {
      int i;

      
      changed = true;
      
      for (i = 0; i < 32; i++ )
	prog.Module.Name[ i ] = 0;
      
      strncpy( prog.Module.Name, name, 31 );
      
      if ( info )
	printf( "New = '%s'", prog.Module.Name );
    }
  
  if ( info )
    putchar('\n');
  
  if ( swapword( prog.Module.Type ) == T_Program )
    {
      if ( info )
	printf( "Stacksize = %ld ", swapword( prog.Stacksize ) );
      
      if ( stacksize != -1 )
	{
	  changed = true;
	  
	  prog.Stacksize = swapword( stacksize );
	  
	  if ( info )
	    printf( "New = %ld", stacksize );
	}
      
      if ( info )
	printf( "\nHeapsize = %ld ", swapword( prog.Heapsize ) );
      
      if ( heapsize != -1 )
	{
	  changed = true;
	  
	  prog.Heapsize = swapword( heapsize );
	  
	  if ( info )
	    printf( "New = %ld", heapsize );
	}
      
      if ( info )
	putchar('\n');
    }
  else if (stacksize != -1 || heapsize != -1)
    {
      printf( "Cannot set stacksize/heapsize - image does not include a program stucture\n" );
    }
  
  if ( modules )
    putmodules();
  
  if ( changed )
    {
      
      fseek( fd, 0L, SEEK_SET );
      
      size = fwrite( &hdr, 1, sizeof (ImageHdr), fd );
      
      if ( size != sizeof (ImageHdr) )
	{ fprintf(stderr,  "Write failure writing header: wrote %d bytes, errno = %d\n",
	      size, errno);
	  exit(1);
	}
      
      size = fwrite( &prog, 1, sizeof (Program), fd );
      
      if ( size != sizeof (Program) )
	{ fprintf( stderr, "Write failure writing program: wrote %d bytes, errno = %d\n",
	      size, errno);
	  exit(1);
	}	      
    }
  
  fclose( fd );
  
  return 0;

} /* main */
Beispiel #10
0
int main(int argc, char **argv)
{ WORD		mask, new_mask;
  Object 	*sm;
  int		c;
  bool		interactive	= TRUE;
  bool		all		= FALSE;
  bool		disable		= FALSE;
  bool		most		= FALSE;
  bool		redirect	= FALSE;
  bool		revert		= FALSE;
  int		i;

  if (argc > 1) interactive = FALSE;

  new_mask = 0;
    
  for (i = 1; i < argc; i++)
   { char *temp = argv[i];

     if (!strcmp(temp, "all"))   
      { all = TRUE; continue; }
     if (!strcmp(temp, "none"))
      { disable = TRUE; continue; }
     if (!strcmp(temp, "most"))
      { most = TRUE; continue; }
     if (!strcmp(temp, "redirect"))
      { redirect = TRUE; continue; }
     if (!strcmp(temp, "revert"))
      { revert = TRUE; continue; }      

     if (!strncmp(temp, "cre", 3))
      { new_mask ^= dbg_Create; continue; }
     if (!strncmp(temp, "mon", 3))
      { new_mask ^= dbg_Monitor; continue; }
     if (!strncmp(temp, "del", 3))
      { new_mask ^= dbg_Delete; continue; }
     if (!strncmp(temp, "mem", 3))
      { new_mask ^= dbg_Memory; continue; }
     if (!strncmp(temp, "ioc", 3))
      { new_mask ^= dbg_IOC; continue; }
     usage();
   }

  sm = Locate(Null(Object), "/sm");
  if (sm eq Null(Object))
   { fprintf(stderr, "diag_sm : failed to locate Session Manager.\n");
     return(EXIT_FAILURE);
   }
   
  if (!interactive)
   { if (redirect) sm_redirect(sm);
     if (revert)   sm_revert(sm);

     if (disable)
      mask = 0;
     elif (most)
      mask = dbg_Create | dbg_Delete;
     elif (all)
      mask = dbg_Create | dbg_Delete | dbg_Monitor;
     else
      { mask = sm_private(sm, dbg_Inquire);
        if (mask < 0)
         { fprintf(stderr, "diag_sm : communication breakdown.\n");
           return(EXIT_FAILURE);
         }
      }
      
     mask ^= new_mask;
     if ((mask = sm_private(sm, mask)) < 0)
      { fprintf(stderr, "diag_sm: communication breakdown.\n");
        return(EXIT_FAILURE);
      }
     else
      return(EXIT_SUCCESS);
   }
Beispiel #11
0
/*
 ****************************************************************
 *	Imprime o diretório corrente				*
 ****************************************************************
 */
void
do_df (int argc, const char *argv[])
{
	const UNI	*up = &uni;
	int		livres, total, usados, ruins, index;
	int		end_index;
	short		clusno;
	int		opt;

	/*
	 *	Analisa as opções
	 */
	while ((opt = cmd_getopt (argv, "H")) >= 0)
	{
		switch (opt)
		{
		    case 'H':			/* Help */
			do_df_help ();
			return;

		    default:			/* Erro */
			fprintf (stderr, "\n");
			do_df_help ();
			return;
		}
	}

	/*
	 *	Pequena consistência
	 */
	argc -= cmd_optind;
	argv += cmd_optind;

	if (argc != 0)
		{ do_df_help (); return; }

	/*
	 *	Verifica quantos "clusters" estão livres
	 */
	get_whole_fat ();

	for
	(	livres = 0, ruins = 0,
		index = 2, end_index = 2 + up->u_n_clusters;
		index < end_index;
		index++
	) 
	{
		if   (C_ISFREE (clusno = get_fat_value (index)))
			livres++;
		elif (C_ISBAD (clusno))
			ruins++;
	}

	total  = up->u_n_clusters;
	usados = total - livres - ruins;

	total  = BLTOKB (up->u_sectors_per_cluster * total);
	usados = BLTOKB (up->u_sectors_per_cluster * usados);
	livres = BLTOKB (up->u_sectors_per_cluster * livres);
	ruins  = BLTOKB (up->u_sectors_per_cluster * ruins);

	/*
	 *	Imprime o cabeçalho
	 */
	printf
	(	"RW DISPOSITIVO         SISTEMA    "
		" TOTAL  ALOCADOS  LIVRES  RUINS (KB)   %%\n"
	);

	/*
	 *	Imprime o resultado
	 */
	printf ("%s ", fs_status == FS_MOUNT_RO ? "RO" : "  ");
	printf ("%-20.20s", dev_nm);
	printf ("%-8.8s  ", sb.s_id);
	printf ("%7d   %7d %7d %6d      ", total, usados, livres, ruins);
	printf
	(	"%s %%\n",
		total == 0 ? "?" : editpercent (getpercent (usados, total - ruins))
	);

}	/* end do_df */