Exemple #1
0
/*
  This function assumes that at least one between field1 and field2 is
  not empty.
*/
void print_fields (const char* field1, const char* field2,
		   size_t l1, size_t l2, 
		   unsigned long lineno1, unsigned long lineno2, 
		   unsigned long fieldno1, unsigned long fieldno2)
{
  fieldno1++; /* The field number must start from 1, not from 0 */
  fieldno2++; /* The field number must start from 1, not from 0 */
  if (*field1 == '\0')
    {
      printf ("##%-7lu       <==\n##%-7lu #>%-3lu ==> ", lineno1, lineno2, fieldno2);
      /* length(" #> ") + 3 = 7 white spaces before the arrow */
      writeln (field2, 0);
    }
  else if (*field2 == '\0')
    {
      printf ("##%-7lu #>%-3lu <== ", lineno1, fieldno1);
      writeln (field1, 0);
      /* length(" #> ") + 3 = 7 white spaces before the arrow */
      printf ("##%-7lu       ==>\n", lineno2);
    }
  else
    {
      printf ("##%-7lu #:%-3lu <== ", lineno1, fieldno1);
      print_head (field1, l1);
      putchar ('\n');
      printf ("##%-7lu #:%-3lu ==> ", lineno2, fieldno2);
      print_head (field2, l2);
      putchar ('\n');
    }
}
Exemple #2
0
void
print_rsa_pkey(FILE * outfile, gnutls_datum_t * m, gnutls_datum_t * e,
	       gnutls_datum_t * d, gnutls_datum_t * p, gnutls_datum_t * q,
	       gnutls_datum_t * u, gnutls_datum_t * exp1,
	       gnutls_datum_t * exp2, int cprint)
{
	print_head(outfile, "modulus", m->size, cprint);
	print_hex_datum(outfile, m, cprint);
	print_head(outfile, "public exponent", e->size, cprint);
	print_hex_datum(outfile, e, cprint);
	if (d) {
		print_head(outfile, "private exponent", d->size, cprint);
		print_hex_datum(outfile, d, cprint);
		print_head(outfile, "prime1", p->size, cprint);
		print_hex_datum(outfile, p, cprint);
		print_head(outfile, "prime2", q->size, cprint);
		print_hex_datum(outfile, q, cprint);
		print_head(outfile, "coefficient", u->size, cprint);
		print_hex_datum(outfile, u, cprint);
		if (exp1 && exp2) {
			print_head(outfile, "exp1", exp1->size, cprint);
			print_hex_datum(outfile, exp1, cprint);
			print_head(outfile, "exp2", exp2->size, cprint);
			print_hex_datum(outfile, exp2, cprint);
		}
	}
}
      int CacheStat::dump(const StatDumpFilter* dump_filter)
      {
        int ret = check_init() ? TAIR_RETURN_SUCCESS : TAIR_RETURN_FAILED;

        if (ret != TAIR_RETURN_SUCCESS)
        {
          log_error("dump fail. not init");
        }
        else if (file_->get_file_size() <= RESERVE_SIZE)
        {
          log_error("cache stat contain no data");
        }
        else
        {
          char buf[CACHE_STAT_SIZE * 1024];
          int64_t offset = RESERVE_SIZE;
          int32_t count = 0;
          int32_t read_len;
          cache_stat total_stat, last_stats[TAIR_MAX_AREA_COUNT];
          StatDumpFilter default_filter;
          const StatDumpFilter* filter = (NULL == dump_filter) ? &default_filter : dump_filter;
          bool should_dump = true;

          print_head();
          while (true)
          {
            if ((read_len = file_->pread_file(buf, sizeof(buf), offset)) < 0)
            {
              log_error("read file fail. ret: %d", ret);
              ret = read_len;
              break;
            }
            else if (read_len == 0)
            {
              break;
            }
            else
            {
              count = read_len / CACHE_STAT_SIZE;
              dump_stat(reinterpret_cast<cache_stat*>(buf), count, last_stats, &total_stat, filter, should_dump);
              offset += read_len - read_len % CACHE_STAT_SIZE;
            }
          }
          print_total_stat(&total_stat); // maybe read no sentinel at last
          print_head();
        }
        return ret;
      }
Exemple #4
0
char *weather_date(FILE *fp, char *ptr, char *title, int type) {
	char date1[20], date2[20];

	if (NULL == fp || !ptr)
		return NULL;
	if (NULL == (ptr = strstr(ptr, "标准头结束")))
		return NULL;
	if (NULL == (ptr = newstrstr(ptr, "<TABLE", 12)))
		return NULL;
	if (NULL == (ptr = newstrstr(ptr, "<TD", 3)))
		return NULL;
	if (NULL == (ptr = strchr(ptr, '>')))
		return NULL;
	strncpy(date1, ++ptr, sizeof(date1));
	if (strchr(date1, '<'))
		*strchr(date1, '<') = 0;
	ptr = newstrstr(ptr, ">", 2);
	if (!ptr)
		return 0;
	strncpy(date2, --ptr, sizeof(date2));
	if (strchr(date2, '<'))
		*strchr(date2, '<') = 0;
	print_head(fp, date1, date2, title, type);
	ptr = newstrstr(ptr, "<tr", 2);
	ptr = strhtmltag(ptr, "/td");
	return ptr;
}
Exemple #5
0
void print_item(string tag)
{
    string type, stag;
    int *dims;

    type = get_type(instr, tag);
    if (streq(type, SetType)) {
	get_set(instr, tag);
	print_set(tag);
	while ((stag = next_item_tag(instr)) != NULL) {
	    print_item(stag);
	    free(stag);
	}
	get_tes(instr, tag);
	print_tes(tag);
    } else {
	dims = get_dimensions(instr, tag);
	print_head(tag, type, dims);
	print_data(tag, type, dims);
	endline();
	if (dims != NULL)
	    free(dims);
    }
    free(type);
}
Exemple #6
0
/*
 *	Run the CPU emulation endless
 */
static void do_go(char *s)
{
	while (isspace((int)*s))
		s++;
	if (isxdigit((int)*s))
		PC = exatoi(s);
	cont:
	cpu_state = CONTIN_RUN;
	cpu_error = NONE;
	switch(cpu) {
	case Z80:
		cpu_z80();
		break;
	case I8080:
		cpu_8080();
		break;
	}
	if (cpu_error == OPHALT)
		if (handel_break())
			if (!cpu_error)
				goto cont;
	cpu_err_msg();
	print_head();
	print_reg();
}
Exemple #7
0
void print_list()
  {
  int i;
  TITEM *t;

  if (!pagelen) print_head();
  if (!grp_sort)
     {
     for(i=0,t=itlist;i<item_count;i++,t++)
        {
        endpage(i);
        print_polozka(i,t);
        }
     }
  else
     {
     TITEM *list;
     int *nums;
     list=(TITEM *)malloc(sizeof(TITEM)*item_count);
     nums=(int *)malloc(sizeof(int)*item_count);
     counting_sort(itlist,list,item_count,nums);
     for(i=0,t=list;i<item_count;i++,t++)
        {
        endpage(i);
        print_polozka(nums[i],t);
        }
     free(list);
     free(nums);
     }
  }
Exemple #8
0
int main(int argc, char **argv){
	if(argc == 1){
		int i;
		array = malloc(sizeof(double)*X*Y);
		if(array == NULL){
			printf("failed : malloc() -- exit.\n");
			exit(0);
		}
		*array = malloc(sizeof(double *)*Y);
		if(*array == NULL){
			printf("failed : malloc() -- exit.\n");
			exit(0);
		}
		for(i=0;i<Y;i++){
			array[i] = *array+i*X;
		}
		array[3][9] = 9;
		//printf("%d\n",array[3][9]);
		read_to_array_from_stdin();
	}else if(argc == 2){	//for test
		print_def();
		exit(0);
	}else if(argc == 3){
		sscanf(argv[1],"%d",&wid);
		sscanf(argv[2],"%d",&hei);
		print_head(wid*init_x_scale, hei*init_y_scale);
		print_def();
		print_offset(init_x_scale,init_y_scale,-1,0);
		print_next_from_stdin();
		print_tail();
		exit(0);
	}
}
Exemple #9
0
static void dump_kern_db(FILE *fp)
{
	json_writer_t *jw = json_output ? jsonw_new(fp) : NULL;
	struct ifstat_ent *n;

	if (jw) {
		jsonw_start_object(jw);
		jsonw_pretty(jw, pretty);
		jsonw_name(jw, info_source);
		jsonw_start_object(jw);
	} else
		print_head(fp);

	for (n = kern_db; n; n = n->next) {
		if (!match(n->name))
			continue;

		if (jw)
			print_one_json(jw, n, n->val);
		else
			print_one_if(fp, n, n->val);
	}
	if (json_output)
		fprintf(fp, "\n} }\n");
}
Exemple #10
0
void dump_incr_db(FILE *fp)
{
	struct ifstat_ent *n, *h;
	h = hist_db;

	print_head(fp);

	for (n=kern_db; n; n=n->next) {
		int i;
		unsigned long long vals[MAXS];
		struct ifstat_ent *h1;

		memcpy(vals, n->val, sizeof(vals));

		for (h1 = h; h1; h1 = h1->next) {
			if (h1->ifindex == n->ifindex) {
				for (i = 0; i < MAXS; i++)
					vals[i] -= h1->val[i];
				h = h1->next;
				break;
			}
		}
		if (!match(n->name))
			continue;
		print_one_if(fp, n, vals);
	}
}
Exemple #11
0
/*
 *	Execute several steps with trace output
 */
void do_trace(char *s)
{
	register int count, i;

	while (isspace((int)*s))
		s++;
	if (*s == '\0')
		count =	20;
	else
		count =	atoi(s);
	cpu_state = SINGLE_STEP;
	cpu_error = NONE;
	print_head();
	print_reg();
	for (i = 0; i <	count; i++) {
		cpu();
		print_reg();
		if (cpu_error) {
			if (cpu_error == OPHALT) {
				if (!handel_break()) {
					break;
				}
			} else
				break;
		}
	}
	cpu_err_msg();
}
Exemple #12
0
void endpage(int i)
  {
  if (pagelen && i%pagelen==0)
     {
     if (i) putc(12,stdout);
     print_head();
     }
  }
Exemple #13
0
main(int argc, char *argv[]) {
int		fdin;		// file desk
struct stat	fdstat;		// stat file
AVT_HEAD	head;		// head of AVT file
AVT_IPHYSTAPE	*iphystape;	// list iphystape

	if (argc < 2) {
		fprintf(stderr, "Usage: %s <file.avt>\n", argv[0]);
		return(0);
	}

	// пробуем открыть
	fdin = open(argv[1], O_RDONLY, 0);
	if (fdin < 0) {
		fprintf(stderr, "Can't open file '%s'\n", argv[1]);
		return(0);
	}

	// статистика по файлу для проверок
	if (fstat(fdin, &fdstat) < 0) {
		fprintf(stderr, "Can't stat file '%s'\n", argv[1]);
		close(fdin);
		return(0);
	}

	// загрузим заголовок
	if (read(fdin, &head, sizeof(AVT_HEAD)) != 40) {
		fprintf(stderr, "Error read HEAD from file '%s'.\n", argv[1]);
		close(fdin);
		return(0);
	}
	print_head(head);
	// проверим версию
	if (head.avtformat != 1) {
		fprintf(stderr, "Format '%d' not supported.\n", head.avtformat);
		close(fdin);
		return(0);
	}

	iphystape = new AVT_IPHYSTAPE;
	if ((lseek(fdin, head.iphystape, SEEK_SET) != head.iphystape) ||
		(read(fdin, iphystape, sizeof(AVT_IPHYSTAPE)) != 40)) {
		fprintf(stderr, "Error read from file '%s'!\n", argv[1]);
		delete iphystape;
		close(fdin);
		return(0);
	}
	print_iphystape(iphystape);

	if (tree_view(fdin, head.rootdir)) {
		fprintf(stderr, "Error read from file '%s'!\n", argv[1]);
		delete iphystape;
		close(fdin);
	}

	delete iphystape;
	close(fdin);
};
Exemple #14
0
void
print_dsa_pkey(FILE * outfile, gnutls_datum_t * x, gnutls_datum_t * y,
	       gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * g,
	       int cprint)
{
	if (x) {
		print_head(outfile, "private key", x->size, cprint);
		print_hex_datum(outfile, x, cprint);
	}
	print_head(outfile, "public key", y->size, cprint);
	print_hex_datum(outfile, y, cprint);
	print_head(outfile, "p", p->size, cprint);
	print_hex_datum(outfile, p, cprint);
	print_head(outfile, "q", q->size, cprint);
	print_hex_datum(outfile, q, cprint);
	print_head(outfile, "g", g->size, cprint);
	print_hex_datum(outfile, g, cprint);
}
Exemple #15
0
static int			print_head_or_dir(void *data)
{
	if (DATA->arg && ((t_fprint *)DATA->print) != &d_print)
		print_head(DATA);
	else if (((t_fprint *)DATA->print) == &d_print)
	{
		print_dir_name(DATA);
		return (0);
	}
	return (1);
}
Exemple #16
0
static void dump_kern_db(FILE *fp)
{
	struct ifstat_ent *n;

	print_head(fp);

	for (n=kern_db; n; n=n->next) {
		if (!match(n->name))
			continue;
		print_one_if(fp, n, n->val);
	}
}
Exemple #17
0
void
print_ecc_pkey(FILE * outfile, gnutls_ecc_curve_t curve,
	       gnutls_datum_t * k, gnutls_datum_t * x, gnutls_datum_t * y,
	       int cprint)
{
	if (cprint != 0)
		fprintf(outfile, "/* curve: %s */\n",
			gnutls_ecc_curve_get_name(curve));
	else
		fprintf(outfile, "curve:\t%s\n",
			gnutls_ecc_curve_get_name(curve));

	if (k) {
		print_head(outfile, "private key", k->size, cprint);
		print_hex_datum(outfile, k, cprint);
	}
	print_head(outfile, "x", x->size, cprint);
	print_hex_datum(outfile, x, cprint);
	print_head(outfile, "y", y->size, cprint);
	print_hex_datum(outfile, y, cprint);
}
Exemple #18
0
int main(int argc, char **argv){
	if(argc == 3){
		sscanf(argv[1],"%d",&wid);
		sscanf(argv[2],"%d",&hei);
		print_head(wid*init_x_scale, hei*init_y_scale);
		print_def();
		print_offset(init_x_scale,init_y_scale,-1,hei-1);
		print_next_from_stdin();
		print_tail();
		exit(0);
	}
	return(0);
}
Exemple #19
0
void Logger::error(const char* fmt,...) {
	print_head(_file,2);
	va_list arg;
	const char* p = "\n";
	va_start(arg,fmt);
	vsprintf(_buffer,fmt,arg);
	va_end(arg);
#ifndef _WIN32
	p = _file == stdout ? NONE "\n" : "\n";
#endif
	strcat(_buffer,p);
	fwrite(_buffer,strlen(_buffer),1,_file);
}
Exemple #20
0
void register_main()
{
	struct sockaddr_in servaddr;
	struct hostent* server;
	int sock;
	clientInfo c_info;
	int flag;
	
	print_head();
	if(register_connnet(&servaddr,server,&sock)==RET_ERR)
	{
		exit(0);
	}	
	
	
	while(1)
	{
		system("clear");
		print_head();
		register_input(&c_info);
		
		if(!register_is(sock,&c_info))
		{
			printf("\t\t注册成功\n");
			printf("按任意键回到主菜单\n");
			close(sock);
			getchar();
			getchar();
			return ;
		}
		printf("姓名必须唯一\n");
		getchar();
		printf("\t\t是否继续注册?y/n ");
		if(getchar()!='y')
			break;
		while(getchar()!='\n');
	}
	//scanf("%d",&flag);
}
Exemple #21
0
void print_object(int y, int x, int c){
	switch (c)
	{
	case 'b': print_brick(y, x);   break;
	case 'w': print_water(y, x);   break;
	case 'g': print_grass(y, x);   break;
	case 'c': print_wall(y, x);    break;
	case '1': print_red(y, x);     break;
	case '2': print_blue(y, x);    break;
	case '3': print_white(y, x);   break;
	case 'h': print_head(y, x);    break;
	default:  print_blanko(y, x);  break;
	}
}
Exemple #22
0
/*
 *	Run the CPU emulation endless
 */
void do_go(void)
{
	cont:
	cpu_state = CONTIN_RUN;
	cpu_error = NONE;
	cpu();
	if (cpu_error == OPHALT)
		if (handel_break())
			if (!cpu_error)
				goto cont;
	cpu_err_msg();
	print_head();
	print_reg();
}
Exemple #23
0
static void
print_dh_info(FILE * outfile, gnutls_datum_t * p, gnutls_datum_t * g,
	      unsigned int q_bits, int cprint)
{
	if (q_bits > 0) {
		if (cprint != 0)
			fprintf(outfile,
				"\n /* recommended key length: %d bytes */\n\n",
				(7 + q_bits) / 8);
		else
			fprintf(outfile,
				"\nRecommended key length: %d bits\n\n",
				q_bits);
	}

	print_head(outfile, "generator", g->size, cprint);
	print_hex_datum(outfile, g, cprint);

	print_head(outfile, "prime", p->size, cprint);
	print_hex_datum(outfile, p, cprint);


}
Exemple #24
0
/*
 *	Execute a single step
 */
void do_step(void)
{
	BYTE *p;

	cpu_state = SINGLE_STEP;
	cpu_error = NONE;
	cpu();
	if (cpu_error == OPHALT)
		handel_break();
	cpu_err_msg();
	print_head();
	print_reg();
	p = PC;
	disass(&p, p - ram);
}
int main(int argc, char **argv)
{
  print_head();
  print_constant_int("UM_KERN_PAGE_SIZE", PAGE_SIZE);
  print_constant_str("UM_KERN_EMERG", KERN_EMERG);
  print_constant_str("UM_KERN_ALERT", KERN_ALERT);
  print_constant_str("UM_KERN_CRIT", KERN_CRIT);
  print_constant_str("UM_KERN_ERR", KERN_ERR);
  print_constant_str("UM_KERN_WARNING", KERN_WARNING);
  print_constant_str("UM_KERN_NOTICE", KERN_NOTICE);
  print_constant_str("UM_KERN_INFO", KERN_INFO);
  print_constant_str("UM_KERN_DEBUG", KERN_DEBUG);
  print_tail();
  return(0);
}
Exemple #26
0
void TEST(int count_of_tests, const char *(names_of_tests[]), int *(arrays_for_tests[]), int n, int count_of_sf, const char *(sf_names[]), sorting_func sf[]){
    int *temp = (int*)malloc(n*sizeof(int));
    
    //печать шапки таблицы
    print_head(count_of_sf, sf_names);
    
    for (int i = 0; i < count_of_tests; ++i) {
        printf("%20s", names_of_tests[i]);
        for (int j = 0; j < count_of_sf; ++j) {
            copy(arrays_for_tests[i], arrays_for_tests[i]+n, temp);
            printf("%15f", sort(temp, n, sf[j]));
        }
        printf("\n");
    }
    free(temp);
}
Exemple #27
0
void Logger::info(int level,const char* fmt,...) {
	if(level >= _level) {
		const char*p = "\n";
		print_head(_file,0);
		va_list arg;

		va_start(arg,fmt);
		vsprintf(_buffer,fmt,arg);
		va_end(arg);
#ifndef _WIN32
		p = (_file == stdout ? NONE "\n" : "\n");
#endif
		strcat(_buffer,p);
		fwrite(_buffer,strlen(_buffer),1,_file);
	}
}
Exemple #28
0
static void dump_incr_db(FILE *fp)
{
	struct ifstat_ent *n, *h;
	json_writer_t *jw = json_output ? jsonw_new(fp) : NULL;

	h = hist_db;
	if (jw) {
		jsonw_start_object(jw);
		jsonw_pretty(jw, pretty);
		jsonw_name(jw, info_source);
		jsonw_start_object(jw);
	} else
		print_head(fp);

	for (n = kern_db; n; n = n->next) {
		int i;
		unsigned long long vals[MAXS];
		struct ifstat_ent *h1;

		memcpy(vals, n->val, sizeof(vals));

		for (h1 = h; h1; h1 = h1->next) {
			if (h1->ifindex == n->ifindex) {
				for (i = 0; i < MAXS; i++)
					vals[i] -= h1->val[i];
				h = h1->next;
				break;
			}
		}
		if (!match(n->name))
			continue;

		if (jw)
			print_one_json(jw, n, n->val);
		else
			print_one_if(fp, n, vals);
	}

	if (jw) {
		jsonw_end_object(jw);

		jsonw_end_object(jw);
		jsonw_destroy(&jw);
	}
}
Exemple #29
0
/*
 *	Run the CPU emulation endless
 */
static void do_go(char *s)
{
	while (isspace((int)*s))
		s++;
	if (isxdigit((int)*s))
		PC = ram + exatoi(s);
	cont:
	cpu_state = CONTIN_RUN;
	cpu_error = NONE;
	cpu();
	if (cpu_error == OPHALT)
		if (handel_break())
			if (!cpu_error)
				goto cont;
	cpu_err_msg();
	print_head();
	print_reg();
}
Exemple #30
0
/*
 *	Execute a single step
 */
static void do_step(void)
{
	BYTE *p;

	cpu_state = SINGLE_STEP;
	cpu_error = NONE;
	switch(cpu) {
	case Z80:
		cpu_z80();
		break;
	case I8080:
		cpu_8080();
		break;
	}
	if (cpu_error == OPHALT)
		handel_break();
	cpu_err_msg();
	print_head();
	print_reg();
	p = mem_base() + PC;
	disass(&p, PC);
}