示例#1
0
int main(){
	char s[100]={0};
	printf("Input your string: ");
	gets(s);
	printf("Specify operation? ");
	int a;
	scanf("%d",&a);
	switch(a){
		case 1: 
			printf("Replaced character? ");
			char rpc=ugetchar();
			printf("With? ");
			char nc=ugetchar();
			int i;
			for(i=0;s[i]!='\0';i++)
				if(s[i]==rpc)s[i]=nc;
			printf("New String: %s",s);
			break;
		case 2:
			printf("Deleted Character? ");
			char delc=ugetchar();
			char* ptr;
			while((ptr=strchr(s,delc))!=NULL)
				memmove(ptr,ptr+1,strlen(s)-(ptr-s));
			printf("New String: %s",s);
			break;
		default:
			printf("Illegal operation!");
			exit(1);
	}
	return 0;
}
示例#2
0
// Routine to fill the stream buffer from the com port.
// Returns the first character read.
int fil_sys_buf(unsigned int max_count, unsigned char *stream_ptr)
{
    unsigned int ch, count = 0;
	extern int ugetchar(void);
    do
    {
		ch = ugetchar();
		
		switch (ch)
		{
	    	case 0x8:
				// Delete code.
				if (count > 0)
				{
			    	stream_ptr--;
				    count--;
				}
				sendchar((char *)&ch);
				break;
	    case 0xd:
				// Carriage return code, change to 0xa.
				ch = 0xa;
				count--;
	    default:
				sendchar((char *)&ch);
				*stream_ptr++ = ch;
				count++;
				break;
		}
    }while (ch != 0xa);
    stream_ptr -= count;
    return max_count - (count + 1);
}
示例#3
0
文件: printf.c 项目: kcoewoys/work
char *ugets(char *buf)
{
	char *save = buf;
	char c;

	while((c = ugetchar()) != '\r'){
		*buf = c;
		uputchar(c);
		buf++;
	}
	*buf = '\0';
	uputchar('\r');
        uputchar('\n');

	return save;
}
示例#4
0
/*
 * The debug_wait was used to wait for the "KEY" to enter debug mode.
 * 
 */
void debug_wait()
{
	int i;
	char ch;
	// Waiting 3 sec to enter debug mode.
	uprintf("Press ESC to enter debug mode ");
	for( i=0;i < 6;i++)
	{
		sleep(500); // 0.5 sec
		if( ukbhit() )
		{
			ch=ugetchar();
			/* Enter the debug mode if the key "ESC" or "B" was pressed */
			if( (ch == 27) || (ch == 'B') )sh(0,0);
		}
		uputchar('.');
	}
	uputchar('\n');
}
示例#5
0
void inic_top(void)
{
		int i = 0;
		int c = 0;

		static uint64_t last_core_idle_value[CVMX_MAX_CORES];
		uint64_t idle_delta[CVMX_MAX_CORES];
		int first_loop = 1;
		cvmx_sysinfo_t *sys_info_ptr = cvmx_sysinfo_get();

		uprint(CLI_CURSOR_OFF);

		while(c==0x0)
		{
				uprint(CLI_GOTO_TOP);
				uprint(CLI_ERASE_WIN);
				uprint("\n");

				if (first_loop)
				{
						for (i=0; i<CVMX_MAX_CORES; i++) last_core_idle_value[i] = cvmx_fau_fetch_and_add64(core_idle_cycles[i], 0x0);
						cvmx_wait(sys_info_ptr->cpu_clock_hz);
						first_loop = 0;
						c = ugetchar();
						continue;
				}

				for (i=0; i<CVMX_MAX_CORES; i++)
				{
						idle_delta[i] = cvmx_fau_fetch_and_add64(core_idle_cycles[i], 0x0) - last_core_idle_value[i];
						last_core_idle_value[i] = cvmx_fau_fetch_and_add64(core_idle_cycles[i], 0x0);

						if (idle_delta[i] > sys_info_ptr->cpu_clock_hz) idle_delta[i] = sys_info_ptr->cpu_clock_hz;
				}

				uprint(CLI_REVERSE);
				uprint(" Stack Cores Utilization \n");
				uprint(CLI_NORMAL);
				uprint("\n\n");

				for (i=0; i<CVMX_MAX_CORES; i++)
				{
						if ((cvmx_coremask_core(i) & coremask_data) != 0)
						{
								if (i != cvm_common_get_last_core(coremask_data))
								{
										float val = (float)((float)idle_delta[i]/(float)sys_info_ptr->cpu_clock_hz);

										val = (1.0 - val);

										uprint("    Core %2d : ", i);
										uprint(CLI_BOLD);
										uprint("%-3.1f %%\n", ((float)val*100.0));
										uprint(CLI_NORMAL);
								}
						}
				}

				uprint("\n\nPress any key to exit...\n");

				cvmx_wait(sys_info_ptr->cpu_clock_hz);
				c = ugetchar();
		}

		uprint(CLI_CURSOR_ON);
}