⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kbdinput.c

📁 Fdisk 1.2.1 Freedos下硬盘分区软件
💻 C
📖 第 1 页 / 共 2 页
字号:
      line_buffer_index=1;
      line_buffer[0]=input;
      input='\xff';
      type=CHARNUM;

      Position_Cursor((x_position+1),y_position);
      cprintf("%c",line_buffer[0]);
      }

    /* Process a legitimate entry if type==NUMYN. */
    if( (type==NUMYN) && ( (input=='Y') || (input=='N') || (input=='y')
     || (input=='n') ) )
      {
      type=YN;

      line_buffer[0]=' ';
      line_buffer_index=1;
      }

    /* Process a legitimate entry if type==NUMCHAR. */
    if( (type==NUMCHAR) && (optional_char_1[0]!=NULL)
     && (optional_char_2[0]!=NULL) )
      {
      char_max_range=atoi(optional_char_2);

      if( (input>='1') && (input<=(char_max_range+48)) )
        {
        line_buffer_index=1;
        line_buffer[0]=input;
        type=NUMCHAR;

        Position_Cursor((x_position+1),y_position);
        cprintf("%c",line_buffer[0]);
        }

      if( (input<'1') || (input>(char_max_range+48)) )
        {
        line_buffer_index=0;
        line_buffer[0]=0;
        type=CHAR;
        }
      }

    /* Process optional character fields. */
    if( (type==NUM) && ( (optional_char_1[0]!=NULL)
     || (optional_char_2[0]!=NULL) ) )
      {
      if( (input==optional_char_1[0]) || ( (input-32)==optional_char_1[0]) )
        {
	if(input>=97) input=input-32;

        line_buffer_index=1;
        line_buffer[0]=input;
        input='\xff';
        type=CHARNUM;

        Position_Cursor((x_position+1),y_position);
        cprintf("%c",line_buffer[0]);
        }

      if( (input==optional_char_2[0]) || ( (input-32)==optional_char_2[0]) )
        {
        if(input>=97) input=input-32;

        line_buffer_index=1;
        line_buffer[0]=input;
        input='\xff';
        type=CHARNUM;

        Position_Cursor((x_position+1),y_position);
        cprintf("%c",line_buffer[0]);
        }
      }

    if( (type==CHAR) && (optional_char_1[0]!=NULL)
     && (optional_char_2[0]!=NULL) )
      {
      char_max_range=atoi(optional_char_2);

      if( (input>='1') && (input<=(char_max_range+48)) )
        {
        line_buffer_index=1;
        line_buffer[0]=input;
        type=NUMCHAR;

        Position_Cursor((x_position+1),y_position);
        cprintf("%c",line_buffer[0]);
        }
      }

    if( ( (type==YN) || (type==NUMYN) ) && (optional_char_1[0]!=NULL)
     && (optional_char_2[0]!=NULL) )
      {
      char_max_range=atoi(optional_char_2);

      if( (input>='1') && (input<=(char_max_range+48)) )
        {
        line_buffer_index=1;
        line_buffer[0]=input;
        type=NUMYN;

        Position_Cursor((x_position+1),y_position);
        cprintf("%c",line_buffer[0]);
        }
      }

    if(type==CHAR)
      {
      /* Convert to upper case, if necessary. */
      if(input>=97) input=input-32;

      if( (input>=min_range) && (input<=max_range) )
        {
        line_buffer[0]=input;
        data=input;
        }
      else
        {
        proper_input_given=FALSE;
	line_buffer[0]=' ';
        data=99;

        Position_Cursor(4,23);
        cprintf("Invalid entry, please enter %c-",min_range);
        cprintf("%c.",max_range);
        }

      Position_Cursor((x_position+1),y_position);
      cprintf("%c",line_buffer[0]);
      }

    /* Process the backspace key if type==NUMCHAR. */
    if( (type==NUMCHAR) && (input==8) )
      {
      type=CHAR;

      line_buffer[0]=' ';
      line_buffer_index=1;

      Position_Cursor((x_position+1),y_position);
      cprintf("%c",line_buffer[0]);
      }

    if(type==YN)
      {
      switch (input) {
	case 'Y':
	  line_buffer[0]='Y';
	  data=TRUE;
	  break;
	case 'y':
	  line_buffer[0]='Y';
	  data=TRUE;
	  break;
	case 'N':
	  line_buffer[0]='N';
	  data=FALSE;
	  break;
	case 'n':
	  line_buffer[0]='N';
	  data=FALSE;
	  break;
	default:
	  proper_input_given=FALSE;
	  line_buffer[0]=' ';
	  data=99;

	  cprintAt(4,23,catgets(cat,4,7,"Invalid entry, please enter Y-N."));

	}

      Position_Cursor((x_position+1),y_position);
      cprintf("%c",line_buffer[0]);
      }

    /* Process the backspace key if type==NUMYN. */
    if( (type==NUMYN) && (input==8) )
      {
      type=YN;
      line_buffer[0]=' ';
      line_buffer_index=1;

      Position_Cursor((x_position+1),y_position);
      cprintf("%c",line_buffer[0]);
      }

    if( (type==NUM) && (input!='\xff') )
      {
      /* If the backspace key has not been hit. */
      if(input!=8)
        {
	invalid_input=FALSE;

        if(size_of_field>1)
	  {
	  min_range=0;
	  max_range=9;
	  }

	if( (input>='0') && (input<='9') )input=input-48;
	else
	  {
	  if(input<10) input=11;
	  }

	if( ( (size_of_field>1) && (input>max_range) ) || (input>9) )
	  {
	  proper_input_given=FALSE;

	  cprintAt(4,23,"Invalid entry, please enter %d-%d.",min_range,max_range);
	  invalid_input=TRUE;
	  }

	if( (size_of_field==1) && ( (input<min_range) || ( (input>max_range) && (input<10) ) ) )
	  {
	  proper_input_given=FALSE;

	  cprintAt(4,23,"%d is not a choice, please enter ",input);
	  cprintf("%d-%d.",min_range,max_range);
	  invalid_input=TRUE;
	  }

	if( (invalid_input==FALSE) && (line_buffer_index==size_of_field) && (size_of_field>1) )
	  {
	  proper_input_given=FALSE;

	  cprintAt(4,23,catgets(cat,4,8,"Invalid entry."));
	  invalid_input=TRUE;
          }

	if( (invalid_input==FALSE) && (line_buffer_index==size_of_field) && (size_of_field==1) )
	  {
	  line_buffer_index=0;
	  }

	if(invalid_input==FALSE)
	  {
	  if( (line_buffer_index==1) && (line_buffer[0]=='0') )
	    {
	    line_buffer[0]=0;
	    line_buffer_index=0;
	    }

	  line_buffer[line_buffer_index]=(input+48);
	  line_buffer_index++;
	  }
	}
      else
	{
	/* If the backspace key has been hit */
	line_buffer_index--;
	if(line_buffer_index<0) line_buffer_index=0;
	line_buffer[line_buffer_index]=0;

	if(line_buffer_index==0)
	  {
	  line_buffer[0]='0';
	  line_buffer_index=1;
	  }
	}

      /* Clear text box before displaying line_buffer */
      index=0;
      do
	{
	Position_Cursor((x_position+1+index),y_position);
	printf(" ");

	index++;
	}while(index<size_of_field);

      /* Display line_buffer */
      index=line_buffer_index;
      do
	{
	Position_Cursor((x_position+size_of_field-line_buffer_index+index),y_position);
	index--;
	cprintf("%c",line_buffer[index]);
	}while(index>0);
      }

    if( (type==NUMP) && (input!='\xff') )
      {
      /* If the backspace key has not been hit. */
      if(input!=8)
	{
	invalid_input=FALSE;

	if(size_of_field>1)
	  {
	  min_range=0;
	  max_range=9;
	  }

	if( (input=='%') && (percent_entered==FALSE) )
	  {
	  percent_entered=TRUE;
	  percent_just_entered=TRUE;
	  }

	if( (input>='0') && (input<='9') )input=input-48;
	else
	  {
	  if(input<10) input=11;
	  }

	if( (percent_entered==FALSE) && (percent_just_entered==FALSE) && ( ( (size_of_field>1) && (input>max_range) ) || (input>9) ) )
	  {
	  proper_input_given=FALSE;

	  cprintAt(4,23,"Invalid entry, please enter %d-%d.",min_range,max_range);
	  invalid_input=TRUE;
	  }

	if( (percent_entered==FALSE) && (size_of_field==1) && ( (input<min_range) || ( (input>max_range) && (input<10) ) ) )
	  {
	  proper_input_given=FALSE;

	  cprintAt(4,23,"%d is not a choice, please enter ",input);
	  cprintf("%d-%d.",min_range,max_range);
	  invalid_input=TRUE;
	  }

	if( ( (percent_entered==TRUE) && (percent_just_entered==FALSE) ) || ( (invalid_input==FALSE) && (line_buffer_index==size_of_field) && (size_of_field>1) ) )
	  {
	  proper_input_given=FALSE;

	  cprintAt(4,23,catgets(cat,4,8,"Invalid entry."));
          invalid_input=TRUE;
	  }

        if( (invalid_input==FALSE) && (line_buffer_index==size_of_field) && (size_of_field==1) )
          {
          line_buffer_index=0;
          }

        if(invalid_input==FALSE)
          {
          if( (line_buffer_index==1) && (line_buffer[0]=='0') )
            {
            line_buffer[0]=0;
            line_buffer_index=0;
            }

          if(percent_just_entered==TRUE)
            {
            percent_just_entered=FALSE;
            line_buffer[line_buffer_index]='%';
            line_buffer_index++;
            }
          else
            {
            line_buffer[line_buffer_index]=(input+48);
            line_buffer_index++;
            }
          }
        }
      else
        {
	/* If the backspace key has been hit */
        line_buffer_index--;
        if(line_buffer_index<0) line_buffer_index=0;
        line_buffer[line_buffer_index]=0;

	if(line_buffer_index==0)
          {
          line_buffer[0]='0';
          line_buffer_index=1;
          }

        if(percent_entered==TRUE) percent_entered=FALSE;
        }

      /* Clear text box before displaying line_buffer */
      index=0;
      do
        {
        Position_Cursor((x_position+1+index),y_position);
        printf(" ");

        index++;
        }while(index<size_of_field);

      /* Display line_buffer */
      index=line_buffer_index;
      do
        {
        Position_Cursor((x_position+size_of_field-line_buffer_index+index),y_position);
        index--;
        cprintf("%c",line_buffer[index]);
        }while(index>0);
      }

#ifdef DEBUG
    if(debug.input_routine==TRUE)
      {
      printAt(60,23,"                ");

      printAt(60,24,"                ");

      printAt(50,23,"Line Buffer:  %10s",line_buffer);

      printAt(50,24,"Line Buffer Index:  %d",line_buffer_index);

      if(percent_entered==TRUE)
        {
        printAt(75,24,"P");
        }
      else
        {
        printAt(75,24,"  ");
        }
      }
#endif

    /* Place brackets back on screen as a precautionary measure. */
    if(type!=ESC)
      {
      Position_Cursor(x_position,y_position);
      cprintf("[");

      Position_Cursor((x_position+size_of_field+1),y_position);
      cprintf("]");
      }

    }while(proper_input_given==FALSE);

  return(data);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -