Exemple #1
0
void printf(const char *format, ...)
{
       uint32 *arg;
       arg = &format;
       int c;
       char buf[64];
       arg++;
       while ((c = *format++) != 0)
         {
           if (c != '%')
             putc(c);
           else if(c == '%')
             {
               char *p;
     
               c = *format++;
               switch (c)
                 {
                 case 'd':
                 case 'u':
                 case 'x':
                   itoa(buf, *arg++);
                   prints(buf);
		   break;
		 case 'c':
		   changeColor(*((int*)arg++));
		   break;
		 case 's':
                   p = *arg++;
                   if (! p)
                     p = "(null)";
     
                 string:
                   while (*p)
                     putc(*p++);
                   break;
     
                 default:
                   putc(*((int *) arg++));
                   break;
                 }
             }
	}
}
bool sa_check_expect_file_line(const char *file, const char *function, int line, Array a, String *e, int ne) {
	base_init();
	base_count_check();
	if (a->n != ne) {
		printf("%s, line %d: Actual length %d "
			"differs from expected length %d\n", file, line, a->n, ne);
		return false;
	}
	if (a->s != sizeof(String)) {
		printf("%s, line %d: Actual element size %d "
			"differs from expected element size %lu\n", file, line, a->s, (unsigned long)sizeof(String));
		return false;
	}
	if (a->n < 0) {
		printf("%s, line %d: Invalid lengths %d\n", file, line, a->n);
		return false;		
	}
	if (ne < 0) {
		printf("%s, line %d: Invalid lengths %d\n", file, line, ne);
		return false;		
	}
	if (a->n > 0 && a->a == NULL) {
		printf("%s, line %d: Actual value array is NULL\n", file, line);
		return false;		
	}
	if (ne > 0 && e == NULL) {
		printf("%s, line %d: Expected value array is NULL\n", file, line);
		return false;		
	}
	String *sa = a->a;
	for (int i = 0; i < a->n; i++) {
		if (!s_equals(sa[i], e[i])) {
			printf("%s, line %d: Actual value ", file, line);
			printsa(sa, a->n);
			prints(" differs from expected value ");
			printsa(e, ne);
			printf(" at index %d.\n", i);
			return false;
		}
	}
	printf("%s, line %d: check passed\n", file, line);
	base_count_success();
	return true;
}
Exemple #3
0
int
pad_view()
{
  int fd, count;
  Pad *pad;

  if ((fd = open(FN_RUN_NOTE_PAD, O_RDONLY)) < 0)
    return XEASY;

  count = 0;
  mgets(-1);

  for (;;)
  {
    pad = mread(fd, sizeof(Pad));
    if (!pad)
    {
      vmsg(NULL);
      break;
    }
    else if (!(count % 5))    /* itoc.020122: 有 pad 才印 */
    {
      clear();
      move(0, 23);
      prints("【 酸 甜 苦 辣 留 言 板 】        第 %d 頁\n\n", count / 5 + 1);
    }

    outs(pad->msg);
    count++;

    if (!(count % 5))
    {
      move(b_lines, 0);
      outs("請按 [SPACE] 繼續觀賞,或按其他鍵結束: ");

      /* itoc.010127: 修正在偵測左右鍵全形下,按左鍵會跳離二層選單的問題 */
      if (vkey() != ' ')
        break;
    }
  }

  close(fd);
  return 0;
}
Exemple #4
0
static int init(void) 
{
	int cnt = 0;
#ifdef LWIP_STATS
	int stats_cnt = 0;
#endif

	lock_static_init(&net_lock);
	/* printc("netlock id %d\n", net_lock.lock_id); */
	NET_LOCK_TAKE();

	torlib_init();
	net_conn_init();
	cos_net_create_netif_thd();
	init_lwip();

	NET_LOCK_RELEASE();
	/* Start the tcp timer */
	while (1) {
		/* Sleep for a quarter of seconds as prescribed by lwip */
		NET_LOCK_TAKE();

		if (++cnt == 4) {
#ifdef TEST_TIMING
			timing_output();
#endif
		}
#ifdef LWIP_STATS
		if (++stats_cnt == 20) {
			stats_cnt = 0;
			stats_display();
		}
#endif
		tcp_tmr();
		NET_LOCK_RELEASE();
		timed_event_block(cos_spd_id(), 25); /* expressed in ticks currently */
		/* printc("use timer to tcp debug thread here...\n"); */
		cos_mpd_update();
	}

	prints("net: Error -- returning from init!!!");
	BUG();
	return 0;
}
int main(int argc, char **argv) {
    if (argc < 3) {
        prints("Usage: fstest <filename> <n>\n");
        return 1;
    } 

    int blocksize = MAX_BLOCK_SIZE;

    char *filename = argv[1];
    int filesize = atoi(argv[2]);
    if (blocksize > MAX_BLOCK_SIZE) {
        prints("Blocksize must be smaller!\n");
        return 1;
    }

    
    int filehandle = syscall_open(filename);
    if (filehandle < 0) {
        prints("failed to open file!\n");
        return 3;
    }
    
    int written = 0;
    while(written < filesize) {
        int i;
        int write = MIN(filesize - written, blocksize);
        for (i = 0; i < write; i++) {
            buffer[i] = char_for_pos(written + i);
        }
        write = syscall_write(filehandle, (void*)&buffer, write);
        if (write <= 0) {
            prints("failed to write!\n");
            return 3;
        }
        written += write;
    }
    prints("OK, fstest wrote bytes. closing file\n");
    if(syscall_close(filehandle) == -1) {
        prints("OK, fstest file close failed\n");
        return 1;
    }
    
    prints("OK, fstest closed file\n");

    return 0;
}
Exemple #6
0
// Displays Game Results
void printResults() {
	prints(0, 15, YELLOW, BLACK, "GAME OVER", 1);
	
	if(game.myScore > game.oppScore) {
		prints(0, 15, YELLOW, BLACK, "You won!", 1);
		prints(0, 15, YELLOW, BLACK, "Your Score: ", 1);
		integerprint(0, 15, YELLOW, BLACK, game.myScore);
		prints(WHITE, BLACK, "Opponent Score: ");
		integerprint(WHITE, BLACK, game.oppScore);
	} else {
		prints(0, 15, RED, BLACK, "You lost", 1);
		prints(0, 15, WHITE, BLACK, "Your Score: ");
		integerprint(0, 15, WHITE, BLACK, game.myScore);
		prints(0, 15, YELLOW, BLACK, "Opponent Score: ");
		integerprint(0, 15, YELLOW, BLACK, game.oppScore);
	}
}
Exemple #7
0
void cos_init(void *arg)
{
	static volatile int first = 1;
	
	union sched_param sp;
	pnums = avg = 0;
	inc1 = inc2 = 0;

#ifdef DEBUG_PERIOD	
	unsigned long cos_immediate_process_cnt_prev = 0;

	if (cos_get_thd_id() == debug_thd) {
		if (periodic_wake_create(cos_spd_id(), 100)) BUG();
		while(1) {
			periodic_wake_wait(cos_spd_id());
			printc("num interrupt_wait %ld interrupt_process %ld\n", 
			       interrupt_wait_cnt, interrupt_process_cnt);
			interrupt_wait_cnt = 0;
			interrupt_process_cnt = 0;
			if (cos_immediate_process_cnt > 0) {
				printc("num immediate interrupt_process %ld\n", 
				       cos_immediate_process_cnt - cos_immediate_process_cnt_prev);
				cos_immediate_process_cnt_prev = cos_immediate_process_cnt;
			}

		}
	}
#endif
	
	if (first) {
		first = 0;

#ifdef DEBUG_PERIOD		
		sp.c.type = SCHEDP_PRIO;
		sp.c.value = 10;
		debug_thd = sched_create_thd(cos_spd_id(), sp.v, 0, 0);
#endif

		init();
	} else {
		prints("net: not expecting more than one bootstrap.");
	}
}
Exemple #8
0
/*
 * These are for terminal keys debug
 */
void
_debug_print_ibuffer()
{
    static int y = 0;
    int i = 0;

    move(y % b_lines, 0);
    for (i = 0; i < t_columns; i++) 
	outc(' ');
    move(y % b_lines, 0);
    prints("%d. Current Buffer: %d/%d, ", y+1, icurrchar, ibufsize);
    outs(ANSI_COLOR(1) "[" ANSI_RESET);
    for (i = 0; i < ibufsize; i++)
    {
	int c = (unsigned char)inbuf[i];
	if(c < ' ')
	{
	    prints(ANSI_COLOR(1;33) "0x%02x" ANSI_RESET, c);
	} else {
Exemple #9
0
static tui_list_query_t online_users_query(tui_list_t *p)
{
	online_users_t *up = p->data;
	online_user_info_t *ip = up->users + p->cur;
	p->in_query = true;

	t_query(ip->name);
	screen_move(-1, 0);
	//% prints("\033[0;1;37;44m聊天[\033[1;32mt\033[37m] 寄信[\033[1;32mm\033[37m] "
	prints("\033[0;1;37;44m\xc1\xc4\xcc\xec[\033[1;32mt\033[37m] \xbc\xc4\xd0\xc5[\033[1;32mm\033[37m] "
			//% "送讯息[\033[1;32ms\033[37m] 加,减朋友[\033[1;32mo\033[37m,\033[1;32md\033[37m] "
			"\xcb\xcd\xd1\xb6\xcf\xa2[\033[1;32ms\033[37m] \xbc\xd3,\xbc\xf5\xc5\xf3\xd3\xd1[\033[1;32mo\033[37m,\033[1;32md\033[37m] "
			//% "选择使用者[\033[1;32m↑\033[37m,\033[1;32m↓\033[37m] "
			"\xd1\xa1\xd4\xf1\xca\xb9\xd3\xc3\xd5\xdf[\033[1;32m\xa1\xfc\033[37m,\033[1;32m\xa1\xfd\033[37m] "
			//% "求救[\033[1;32mh\033[37m]");
			"\xc7\xf3\xbe\xc8[\033[1;32mh\033[37m]");
	screen_flush();
	return DONOTHING;
}
Exemple #10
0
int main()
{
	int n, d;
	int i, j;

	for(i = 0; i < 100; i++)
		for(j = 0; j < 160; j++) {
			m[i][j] = 0;
		}
	calc();

	scanf("%d", &n);

	for(i = 0; i < n; i++) {
		scanf("%d", &d);
		prints(d);
	}
	return 0;
}
Exemple #11
0
int kps()
{
  int i;
  for (i=0; i<NPROC; i++){
    printf("Task %d ", i+1);
      printf("ppid="); 
         if (i>0) prints("  ");
         if (proc[i].status)
	   printf("%d", proc[i].ppid); 
         else
            printf("--");
         if (running==&proc[i])
	   printf("%s", "  RUNNING");
         else
	   printf("  %s",pStatus[proc[i].status]);
      printf("\n");
  }
  return(0);
}
Exemple #12
0
//The idea, here, is that we'll have a pre-populated list of function pointers
//to functions which take a current position in a string, the string itself, and
//attempt to turn the segment following the current position into the particular
//type of token/ast_node which that function handles. If it fails, it returns
//that it read nothing and the loop tries applying the next function until it
//runs out of functions.
//The functions are also responsible for updating the current line/column
//position in the source string
int main(void) {
	
	//In real life, we'll read this in from a file
	unsigned char code[] = "6-((12+5)/3)"; 
	unsigned int code_length = strlen(code);
	unsigned int cur_location = 0;
	unsigned int chars_consumed = 0;
	ast_node* active_node = (ast_node*)0;
	unsigned int cur_line = 1;
	unsigned int cur_column = 1;
	
	while(cur_location < code_length) {
		
		//Iterate through all the factory functions for 
		for(i = 0; i < node_builder_count; i++) {
		
			//Try to use a factory function on the stream
			chars_consumed = build_node[i](active_node, &cur_line, &cur_column, code, cur_location);
			
			//If we were able to interpret any of the stream, we're done
			if(chars_consumed)
				break;
		}
		
		if(!chars_consumed) {
			
			//If we iterated through all of the node builders and none of them
			//could complete any work, then we know we had a syntax error
			printf("The system encountered a syntax error and will quit.\n");
			break;
		}
		
		cur_location += chars_consumed;
	}
	
	//Here, if the entire string was consumed we would proceed on to parsing
	//the AST tree we just generated
	
	//Can probably get rid of this, but why not
	prints("Done.\n");
	
	return 0;
}
Exemple #13
0
static int print_card(int card,int x,int y)
{
  char *flower[4]={"¢á","¢Ö","¢Ò","¢Ñ"};
  char *poker[52]={"¢Ï","¢Ï","¢Ï","¢Ï","¢±","¢±","¢±","¢±","¢²","¢²","¢²","¢²",
                   "¢³","¢³","¢³","¢³","¢´","¢´","¢´","¢´","¢µ","¢µ","¢µ","¢µ",
                   "¢¶","¢¶","¢¶","¢¶","¢·","¢·","¢·","¢·","¢¸","¢¸","¢¸","¢¸",
                   "10","10","10","10","¢Ø","¢Ø","¢Ø","¢Ø","¢ß","¢ß","¢ß","¢ß",
                   "¢Ù","¢Ù","¢Ù","¢Ù"};

move(x,y);   prints("¢~¢w¢w¢w¢¡");
move(x+1,y); prints("¢x%s    ¢x",poker[card]);
move(x+2,y); prints("¢x%s    ¢x",flower[card%4]);
move(x+3,y); prints("¢x      ¢x");
move(x+4,y); prints("¢x      ¢x");
move(x+5,y); prints("¢x      ¢x");
move(x+6,y); prints("¢¢¢w¢w¢w¢£");
return 0;
}
Exemple #14
0
int show_pipe(PIPE *p){
  int i,j;

  printf("------------ PIPE CONTENTS ------------\n");
  printf("nreader=%d  nwriter=%d  ", p->nreader, p->nwriter);
  printf("data=%d  room=%d\n", p->data, p->room);

  prints("contents=>");

  if(p->data){
    j = p->tail;

    for(i =0; i < p->data; i++){
      putc(p->buf[j++]);
      j = j % PSIZE;
    }
  }

  printf("<\n----------------------------------------\n");
}
Exemple #15
0
void
monitor_refresh(sig)
{
  int i, boottime;
  if (sig) signal(sig, SIG_IGN);
  boottime = myinfo.idletimeout*120;
  if (boottime && ((monitor_idle += MONITOR_REFRESH) > boottime)) {
    disconnect(EXIT_TIMEDOUT);
  }
  if (bbs_check_mail()) {
    move(0, t_columns/3);
    prints("(You have mail.)");
  }
  DoShortUserList();
  for (i=0; i<global_ulist_sz; i++)
    if (!global_ulist[i].found) global_ulist[i].active = 0;

  signal(SIGALRM, monitor_refresh);
  alarm(MONITOR_REFRESH);
}
Exemple #16
0
int printf(char *format, ...)
{
	int width, pad;
	int pc = 0;
	char scr[2];
	 va_list args;
	 va_start(args, format);
	 for (; *format != 0; ++format) 
	 {
	      if (*format == '%') 
	      {
	             ++format;
	             width = pad = 0;
	             if (*format == '\0') break;
	             if (*format == '%') goto out;
	             /*if (*format == '-') 
	             {
	                   ++format;
	                   pad = PAD_RIGHT;
	             }
	             while (*format == '0') 
	             {
	                   ++format;
	                   pad |= PAD_ZERO;
	             }*/
	             for ( ; *format >= '0' && *format <= '9'; ++format) 
	             {
	                    width *= 10;
	                   width += *format - '0';
	             }
	             if( *format == 's' )
	             {
	                   char *s = (char *)va_arg( args, int );
	                   pc += prints (s?s:"(null)", width, pad);
	                   continue;
	             }
	             if( *format == 'd' ) 
	             {
	                   pc += printi (va_arg( args, long int ), 10, 1, width, pad, 'a');
	                   continue;
	             }
int periodic_wake_wait(spdid_t spdinv)
{
	spdid_t spdid = cos_spd_id();
	struct thread_event *te;
	u16_t tid = cos_get_thd_id();
	long long t;

	TAKE(spdid);
	te = te_pget(tid);
	if (NULL == te) BUG();
	if (!(te->flags & TE_PERIODIC)) goto err;
		
	assert(!EMPTY_LIST(te, next, prev));
	te->flags |= TE_BLOCKED;

	rdtscll(t);
	if (te->missed) {	/* we're late */
		long long diff;
		assert(te->completion);

		diff = (t - te->completion);
		te->lateness_tot += diff;
		//te->samples++;
		te->miss_lateness_tot += diff;
		//te->miss_samples++;
		
		te->completion = 0;
	} else {		/* on time! */
		te->completion = t;
	}
	RELEASE(spdid);

	if (-1 == sched_block(spdid, 0)) {
		prints("fprr: sched block failed in timed_event_periodic_wait.");
	}

	return 0;
err:
	RELEASE(spdid);
	return -1;
}
Exemple #18
0
static int print(int limit, char * *out, const char *format, va_list args)
{
    register int width, pad;
    register int pc = limit;
    char scr[2];

    for (; *format != 0 && pc; ++format) {
        if (*format == '%') {
            ++format;
            width = pad = 0;
            if (*format == '\0') {
                break;
            }
            if (*format == '%') {
                goto out;
            }
            if (*format == '-') {
                ++format;
                pad = PAD_RIGHT;
            }
            while (*format == '0') {
                ++format;
                pad |= PAD_ZERO;
            }
            for (; *format >= '0' && *format <= '9'; ++format) {
                width *= 10;
                width += *format - '0';
            }
            if (*format == 's') {
                register char *s = (char *)va_arg(args, int);
                pc -= prints(out, s ? s : "(null)", width, pad, pc);
                continue;
            }
            if (*format == 'd') {
                pc -= printi(out, va_arg(args, int), 10, 1, width, pad, 'a', pc);
                continue;
            }
            if (*format == 'x') {
                pc -= printi(out, va_arg(args, int), 16, 0, width, pad, 'a', pc);
                continue;
            }
static int print(char **out, const char *format, va_list args )
{
    int width, pad;
    int pc = 0;
    char scr[2];

    for (; *format != 0; ++format) {
        if (*format == '%') {
            ++format;
            width = pad = 0;
            if (*format == '\0') break;
            if (*format == '%') goto out;
            if (*format == '-') {
                ++format;
                pad = PAD_RIGHT;
            }

            while ((*format == 'h') || (*format == 'l'))
                ++format;

            while (*format == '0') {
                ++format;
                pad |= PAD_ZERO;
            }
            for ( ; *format >= '0' && *format <= '9'; ++format) {
                width *= 10;
                width += *format - '0';
            }
            if( *format == 's' ) {
                register char *s = (char *)va_arg( args, int );
                pc += prints (out, s?s:"(null)", width, pad);
                continue;
            }
            if( *format == 'd' ) {
                pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
                continue;
            }
            if( *format == 'x' || *format == 'p') {
                pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
                continue;
            }
Exemple #20
0
int win_sort() {
    int n, n2, tmp;
    char tmpID[20];
    screen_clear();
    //% prints("祝贺! 您刷新了自己的纪录!\r\n");
    prints("\xd7\xa3\xba\xd8! \xc4\xfa\xcb\xa2\xd0\xc2\xc1\xcb\xd7\xd4\xbc\xba\xb5\xc4\xbc\xcd\xc2\xbc!\r\n");
    pressanykey();
    for(n=0; n<=18; n++)
    for(n2=n+1; n2<=19; n2++)
    if(topT[n]> topT[n2]) {
        tmp= topT[n];
        topT[n]= topT[n2];
        topT[n2]= tmp;
        strcpy(tmpID, topID[n]);
        strcpy(topID[n], topID[n2]);
        strcpy(topID[n2], tmpID);
        strcpy(tmpID, topFROM[n]);
        strcpy(topFROM[n], topFROM[n2]);
        strcpy(topFROM[n2], tmpID);
    }
}
Exemple #21
0
static int set_smsg_show(struct _select_def *conf, int i)
{
    char title[41];
    char *c;

    if (strlen(s_m[i-conf->page_pos].context) > 40) {
        strncpy(title, s_m[i-conf->page_pos].context, 37);
        title[37]='.';
        title[38]='.';
        title[39]='.';
    } else {
        strcpy(title, s_m[i-conf->page_pos].context);
    }
    title[40]=0;

    if ((c = strchr(title, '\n'))!= NULL) *c=0;
    if ((c = strchr(title, '\r'))!= NULL) *c=0;

    prints(" %s%-3d %-13s %-14s %s %-40s%s",s_m[i-conf->page_pos].readed?"":"\033[1;5m", i , s_m[i-conf->page_pos].dest, s_m[i-conf->page_pos].time, s_m[i-conf->page_pos].type?"\033[1;32m发\033[m":"\033[1;33m收\033[m", title, s_m[i-conf->page_pos].readed?"":"\033[m");
    return SHOW_CONTINUE;
}
Exemple #22
0
static int set_al_show(struct _select_def *conf, int i)
{
	char title[41];
	char *c;

	if(strlen(a_l[i-conf->page_pos].memo) > 40){
		strncpy(title, a_l[i-conf->page_pos].memo, 37);
		title[37]='.';
		title[38]='.';
		title[39]='.';
	}else{
		strcpy(title, a_l[i-conf->page_pos].memo);
	}
	title[40]=0;

	if((c = strchr(title, '\n') )!= NULL) *c=0;
	if((c = strchr(title, '\r') )!= NULL) *c=0;

	prints(" %-3d %-8s %-10s %-10s %-12s %-28s", i, a_l[i-conf->page_pos].name, a_l[i-conf->page_pos].bbsid, a_l[i-conf->page_pos].group, a_l[i-conf->page_pos].mobile, title);
	return SHOW_CONTINUE;
}
Exemple #23
0
static tui_list_title_t online_users_title(tui_list_t *p)
{
	online_users_t *up = p->data;
	tui_header_line(up->follow ? "[关注列表]" : "[使用者列表]", true);
	screen_printf(" 寄信[\033[1;32mm\033[m] 送讯息[\033[1;32ms\033[m]"
			" 加,减关注[\033[1;32mo\033[m,\033[1;32md\033[m]"
			" 看说明档[\033[1;32m→\033[m,\033[1;32mRtn\033[m]"
			" 切换模式 [\033[1;32mf\033[m] 求救[\033[1;32mh\033[m]");
	
	//% const char *field = up->show_note ? "备注" : "昵称";
	const char *field = up->show_note ? "\xb1\xb8\xd7\xa2" : "\xea\xc7\xb3\xc6";

	char title[256];
	//% snprintf(title, sizeof(title), "\033[1;44m 编号  使用者代号   %s        "
	snprintf(title, sizeof(title), "\033[1;44m \xb1\xe0\xba\xc5  \xca\xb9\xd3\xc3\xd5\xdf\xb4\xfa\xba\xc5   %s        "
			//% "         上站位置            目前动态   发呆   \033[m\n",
			"         \xc9\xcf\xd5\xbe\xce\xbb\xd6\xc3            \xc4\xbf\xc7\xb0\xb6\xaf\xcc\xac   \xb7\xa2\xb4\xf4   \033[m\n",
			field);

	screen_move_clear(2);
	prints("%s", title);
}
Exemple #24
0
void msgline() {
	char buf[256], buf2[STRLEN * 2];
	void display_buffer();
	extern int talkrequest;
	int tmpshow;
	time_t now;

	if (ismsgline <= 0)
		return;
	now = time(0);
	tmpshow = showansi;
	showansi = 1;
	if (talkrequest) {
		talkreply();
		clear();
		showansi = 0;
		display_buffer();
		showansi = 1;
	}
	strcpy(buf, "");
	if (chkmail())
		strcat(buf, "¡¾ÐÅ¡¿");
	else
		strcat(buf, "¡¾  ¡¿");
	strcat(buf, "ÐÅÏä [°´Ctrl-QÇó¾È] ");
	sprintf(
			buf2,
			"[%s][%4.4d,%3.3d][%d] [%2s]",
			insert_character ? "²åÈë" : "¸Äд", currln + 1, currpnt + 1,
			linelen-1, enabledbchar ? "Ë«" : "µ¥");
	strcat(buf, buf2);
	sprintf(buf2, "\033[1;33m¡¾\033[1;32m%.23s\033[33m¡¿\033[m",
			getdatestring(now, DATE_ZH) + 6);
	strcat(buf, buf2);
	move(t_lines - 1, 0);
	clrtoeol();
	prints("%s", buf);
	showansi = tmpshow;
}
Exemple #25
0
int quiz_main()
{
    mysql_init(&s);
    if (!mysql_real_connect(&s,
                            sysconf_str("MYSQLHOST"),
                            sysconf_str("MYSQLUSER"),
                            sysconf_str("MYSQLPASSWORD"),
                            sysconf_str("MYSQLQUIZDATABASE"),
                            sysconf_eval("MYSQLPORT",1521), sysconf_str("MYSQLSOCKET"), 0)) {
        prints("%s\n", mysql_error(&s));
        pressanykey();
        return 0;
    }
    if (init_quiz()) {
        do {
            quiz_test();
        } while (quiz_again());
    }

    mysql_close(&s);
    return 0;
}
Exemple #26
0
// Show visit count and save it.
static void visitlog(int peak)
{
	time_t now;
	struct tm *tm;
	struct max_log_record max_log = { 0 };

	FILE *fp;
	fp = fopen(VISITLOG, "r+b");
	if (fp) {
		if (!fread(&max_log, sizeof(max_log), 1, fp)
			|| (max_log.year < 1990 || max_log.year> 2020)) {
			now = time(NULL);
			tm = localtime(&now);
			max_log.year = tm->tm_year + 1900;
			max_log.month = tm->tm_mon + 1;
			max_log.day = tm->tm_mday;
			max_log.visit = 0;
			max_log.logins = 0;
		}
		else {
			max_log.visit++;
			if (peak > max_log.logins)
				max_log.logins = peak;
		}
		fseek(fp, 0, SEEK_SET);
		fwrite(&max_log, sizeof(max_log), 1, fp);
		fclose(fp);
	}
	snprintf(genbuf, sizeof(genbuf), 
		//% "\033[1;32m从 [\033[36m%4d年%2d月%2d日\033[32m] 起, "
		"\033[1;32m\xb4\xd3 [\033[36m%4d\xc4\xea%2d\xd4\xc2%2d\xc8\xd5\033[32m] \xc6\xf0, "
		//% "最高人数记录: [\033[36m%d\033[32m] "
		"\xd7\xee\xb8\xdf\xc8\xcb\xca\xfd\xbc\xc7\xc2\xbc: [\033[36m%d\033[32m] "
		//% "累计访问人次: [\033[36m%lu\033[32m]\033[m\n",
		"\xc0\xdb\xbc\xc6\xb7\xc3\xce\xca\xc8\xcb\xb4\xce: [\033[36m%lu\033[32m]\033[m\n",
		max_log.year, max_log.month, max_log.day, max_log.logins,
		max_log.visit);
	prints("%s", genbuf);
}
Exemple #27
0
void cmain(void)
{
	int tmp;

	init_all();
							
	prints((u8 *)"\nMcu: System init OK!");
	
	while(1){
		delayms(500);
		sendhex32("\nmain while(1):", REG32(0xb0001010));
		sendhex32(NULL, REG32(0xb3420304));
		sendhex32(NULL, REG32(0xb3420010));
		sendhex32(NULL, rI2C0ST);
		if(vv){
			for(tmp =0; tmp < vv; tmp ++)
				sendhex16(*(buf + tmp));
		
		}
	}

}
Exemple #28
0
//	核对系统密码
int	check_systempasswd()
{
	FILE*	pass;
	char    passbuf[20], prepass[STRLEN];
	clear();
	if ((pass = fopen("etc/.syspasswd", "r")) != NULL) {
		fgets(prepass, STRLEN, pass);
		fclose(pass);
		prepass[strlen(prepass) - 1] = '\0';
		getdata(1, 0, "请输入系统密码: ", passbuf, 19, NOECHO, YEA);
		if (passbuf[0] == '\0' || passbuf[0] == '\n')
			return NA;
		if (!checkpasswd(prepass, passbuf)) {
			move(2, 0);
			prints("错误的系统密码...");
			securityreport("系统密码输入错误...", 0, 0);
			pressanykey();
			return NA;
		}
	}
	return YEA;
}
Exemple #29
0
static int help_refresh(struct _select_def *conf)
{
    int mode = *((int *)conf->arg);
    char searchstr[100];
    char helptitle[100];

    clear();
    move(0,0);
    if (mode == 0)
        strcpy(helptitle, "[全部模式帮助]");
    else snprintf(helptitle, 100, "[帮助 - %s]", helpmodestr[mode-1]);

    docmdtitle(helptitle, " \033[m退出[\033[1;32m←\033[m,\033[1;32mq\033[m] 详细[\033[1;32m→\033[m,\033[1;32mRtn\033[m] 搜索[\033[1;32ms\033[m] 显示所有[\033[1;32mf\033[m]\n");

    if (help_search[0])
        sprintf(searchstr, "搜索:%s",help_search);
    else
        searchstr[0]=0;
    move(2,0);
    prints("\033[0;1;44m  %-4s %-10s %-15s%s%-45s\033[m","序号","索引","介绍", help_search[0]?"\033[33m":"",searchstr);
    return SHOW_CONTINUE;
}
Exemple #30
0
int win_checkrec(int dt) {
    char id[20];
    int n;
    win_loadrec();
    strcpy(id, userid);
    if(dt < 50){
	clear();
	prints("р╩йг╩ЗфВхк!!!\n╥ёдЦк╞цъ1╥жжс\n");
	refresh();
	sleep(60);
	pressanykey();
	return 0;
    }
    for(n=0;n<20;n++)
    if(!strcmp(topID[n], id)) {
	if(stiger > topS[n]){
            topS[n]=stiger;
            win_saverec();
        }
        if(dt< topT[n]) {
            topT[n]= dt;
            strcpy(topFROM[n], fromhost);
            win_sort();
            win_saverec();
        }
        return 0;
    }
    if(dt<topT[19]) {
        strcpy(topID[19], id);
        topT[19]= dt;
        topS[19]= stiger;
        strcpy(topFROM[19], fromhost);
        win_sort();
        win_saverec();
        return 0;
    }
    return 0;
}