Exemple #1
0
/**
 * Hangs up the modem if user online. Whether using modem or not, sets
 * hangup to 1.
 */
void hang_it_up() {
  hangup = true;
#if !defined( __unix__ ) && !defined( __APPLE__ )

  if (!ok_modem_stuff) {
    return;
  }

  GetSession()->remoteIO()->dtr(false);
  if (!GetSession()->remoteIO()->carrier()) {
    return;
  }

  wait1(9);
  if (!GetSession()->remoteIO()->carrier()) {
    return;
  }

  wait1(9);
  if (!GetSession()->remoteIO()->carrier()) {
    return;
  }
  int i = 0;
  GetSession()->remoteIO()->dtr(true);
  while (i++ < 2 && GetSession()->remoteIO()->carrier()) {
    wait1(27);
    rputs("\x1\x1\x1");
    wait1(54);
    rputs((modem_i->hang[0]) ? modem_i->hang : "ATH\r");
    wait1(6);
  }
  GetSession()->remoteIO()->dtr(true);
#endif
}
Exemple #2
0
void sbbs_t::cursor_home(void)
{
	if(term_supports(ANSI))
		rputs("\x1b[H");
	else
		outchar(FF);	/* this will clear some terminals, do nothing with others */
}
// Displays a string to the remote user.  (This is the door's main output function)
void local(char* szString, short nColor, short nNewLines)
{
   short n;

   attr(nColor);

   if ( szString != NULL )
      rputs(szString);

   if ( nColor != 7 )
      attr(7);

   for(n = 0; n < nNewLines; n++)
      {
      rputs("\r\n");
      }
}
Exemple #4
0
void sbbs_t::attr(int atr)
{
	char	str[16];

	if(!term_supports(ANSI))
		return;
	rputs(ansi(atr,curatr,str));
	curatr=atr;
}
Exemple #5
0
void sbbs_t::cursor_down(int count)
{
	if(count<1)
		return;
	if(!term_supports(ANSI))
		return;
	if(count>1)
		rprintf("\x1b[%dB",count);
	else
		rputs("\x1b[B");
}
Exemple #6
0
int sbbs_t::rprintf(const char *fmt, ...)
{
	va_list argptr;
	char sbuf[4096];

	va_start(argptr,fmt);
	vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
	sbuf[sizeof(sbuf)-1]=0;	/* force termination */
	va_end(argptr);
	return(rputs(sbuf));
}
Exemple #7
0
void sbbs_t::cleartoeol(void)
{
	int i,j;

	if(term_supports(ANSI))
		rputs("\x1b[K");
	else {
		i=j=column;
		while(++i<cols)
			outcom(' ');
		while(++j<cols)
			outcom(BS); 
	}
}
Exemple #8
0
void sbbs_t::cursor_right(int count)
{
	if(count<1)
		return;
	if(term_supports(ANSI)) {
		if(count>1)
			rprintf("\x1b[%dC",count);
		else
			rputs("\x1b[C");
	} else {
		for(int i=0;i<count;i++)
			outcom(' ');
	}
	column+=count;
}
struct ast* eval_native_method(struct ast* m){
	if (m != NULL){
    char* method_name;
    if (m->node_type == N_METHOD_CALL_2) {
      method_name = strdup(((struct method_call_node*)m)->method_name);
    } else if (m->node_type == N_IDENTIFIER) {
      method_name = strdup(((struct identifier_node*)m)->name);
    };

		if (!strcmp(method_name, PUTS)) {
			return rputs(m);
    } else if (!strcmp(method_name, GETS)) {
      return rgets();
    };
	};
  return new_nil_node();
};
Exemple #10
0
void sbbs_t::cursor_left(int count)
{
	if(count<1)
		return;
	if(term_supports(ANSI)) {
		if(count>1)
			rprintf("\x1b[%dD",count);
		else
			rputs("\x1b[D");
	} else {
		for(int i=0;i<count;i++)
			outcom('\b');
	}
	if(column > count)
		column-=count;
	else
		column=0;
}
// Backspaces the given number of times (60 at most)
void backspace(short nTimes)
{
   short n;
   char szStr[190];

   if ( nTimes > 60 )
      nTimes = 60;
      
   strcpy(szStr, "\b \b");
   
   for (n = 1; n < nTimes; n++)
      {
      strcat(szStr, "\b \b");
      }

   rputs(szStr);

   
   /*attr(LCYAN);
   rputs("Backspace\n\r");*/   
}
void newline()
{
   attr(7);
   rputs("\r\n");
}
struct ast* rputs(struct ast* a){

  if (a->node_type == N_METHOD_CALL_0 || a->node_type == N_METHOD_CALL_1 || a->node_type == N_METHOD_CALL_2) {
    struct method_call_node* m = (struct method_call_node*)a;
    struct list_node* arg_node = m->args;

    // caso especial: puts() sin parámetros imprime salto de línea
    if (arg_node == NULL) {
      printf("\n");

    // comportamiento normal
    } else {  
      while(arg_node != NULL){
        struct ast* evaluated = eval_ast(arg_node->arg);
        rputs(evaluated);
        arg_node = arg_node->next;
      };
    };

  } else if (a->node_type == N_ARRAY) {
    int arr_size = array_tree_size(a->left);
    struct ast* result[arr_size];
    struct ast* ptr = a->left;
    int i;
    for (i = 0; i < arr_size; i++) {
      result[i] = ptr;
      ptr = ptr->right;
    };

    ptr = result[arr_size-1];
    for (i = arr_size-1; i >= 0; i--) {
      rputs(eval_ast(result[i]));
    };

  } else if (a->node_type == N_ARRAY_CONTENT) {
    rputs(eval_ast(a->left));

  } else if (a->node_type == N_STRING_1) {
    printf("%s\n", string_value(a));

  } else if (a->node_type == N_STRING_2) {

    char * str = malloc(sizeof( strlen(string_value(a)) ));
    strcpy(str, string_value(a));
    str = build_end_of_lines(str);
    printf("%s\n", str);

  } else if (a->node_type == N_INTEGER) {
    printf("%d\n", int_value(a));

  } else if (a->node_type == N_DOUBLE) {
    double d = double_value(a);
    if ( d - floor(d) == 0.0 ) {
      printf( "%g.0\n", d );
    } else {
      printf( "%g\n", d );
    };

  } else if (a->node_type == N_BOOL) {
    printf("%s\n", bool_value(a) ? "true" : "false");

  } else if (a->node_type == N_NIL) {
    printf("\n");

  } else if (a->node_type == N_OBJECT) {
    struct object_node * object = (struct object_node *) a;
    printf("<#%s:%p>\n", object->class_ptr->name, (void *)object);

  } else {
    printf("Puts doesn't support %s type, sorry :D\n", type_name(a->node_type));
  };
  return new_nil_node();
};
Exemple #14
0
void optiq_opi_compute_stat()
{
    int size, rank;
    MPI_Comm_rank (MPI_COMM_WORLD, &rank);
    MPI_Comm_size (MPI_COMM_WORLD, &size);

    if (rank == 0)
    {
	int mincopies = 0, maxcopies = 0, medcopies = 0, total_numcopies = 0;
	int minrputs = 0, maxrputs = 0, medrputs = 0, total_rputs = 0;
	int minlinkloads = 0, maxlinkloads = 0, medlinkloads = 0;
        double total_linkloads = 0;
	double avgcopies = 0, avglinkloads = 0, avgrputs = 0;

	std::vector<int> copies (max_opi.all_numcopies, max_opi.all_numcopies + size);
	std::sort (copies.begin(), copies.end());

	std::vector<int> rputs (max_opi.all_numrputs, max_opi.all_numrputs + size);
	std::sort (rputs.begin(), rputs.end());

	std::vector<int> linkloads (max_opi.all_link_loads, max_opi.all_link_loads + size * 9);
	std::sort (linkloads.begin(), linkloads.end());
	opi.linkloads = linkloads;

	int ncpy = 0, nrput = 0, nlinks = 0;
	maxcopies = copies[size - 1];
	maxrputs = rputs[size - 1];
	maxlinkloads = linkloads[size * 9 - 1];

	std::map<int, int>::iterator it;
	opi.copies_dist.clear();

	for (int i = size; i >= 0; i--)
	{
	    if (copies[i] != 0)
	    {
		total_numcopies += copies[i];
		mincopies = copies[i];
		ncpy++;

		it = opi.copies_dist.find(copies[i]);

		if (it == opi.copies_dist.end())
		{
		    opi.copies_dist.insert(std::pair<int, int>(copies[i], 1));
		}
		else
		{
		    it->second++;
		}
	    }

	    if (rputs[i] != 0)
	    {
		total_rputs += rputs[i];
		minrputs = rputs[i];
		nrput++;
	    }
	}

	for (int i = size * 9; i >= 0; i--)
	{
	    if (linkloads[i] != 0)
	    {
		total_linkloads += linkloads[i];
		minlinkloads = linkloads[i];
		nlinks++;
	    }
	}

	medcopies = copies[size - 1 - ncpy/2];
	avgcopies = (double) total_numcopies / ncpy;

	medrputs = rputs[size - 1 - nrput/2];
	avgrputs = (double) total_rputs / nrput;

	medlinkloads = linkloads[size * 9 - 1 - nlinks/2];
	avglinkloads = total_linkloads / nlinks;

	opi.copies.max = maxcopies;
	opi.copies.min = mincopies;
	opi.copies.avg = avgcopies;
	opi.copies.med = medcopies;
	opi.copies.total = total_numcopies;
	
	opi.rputs.max = maxrputs;
	opi.rputs.min = minrputs;
	opi.rputs.avg = avgrputs;
	opi.rputs.med = medrputs;
	opi.rputs.total = total_rputs;

	opi.load_link.max = maxlinkloads;
	opi.load_link.min = minlinkloads;
	opi.load_link.avg = avglinkloads;
	opi.load_link.med = medlinkloads;
	opi.load_link.total = total_linkloads;
    }
}