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

📄 main.c

📁 fdisk source code, 是一个完整的fdisk的工具。
💻 C
📖 第 1 页 / 共 2 页
字号:

  Read_Partition_Tables();
}

/*
/////////////////////////////////////////////////////////////////////////////
//  MAIN ROUTINE
/////////////////////////////////////////////////////////////////////////////
*/
void main(int argc, char *argv[], char *env[])
{
  int command_ok;
  int index;
  int location;
//  int i;

  /* First check to see if the "/?" command-line switch was entered.  If it
     was, then don't bother doing anything else.  Just display the help and
     exit.  This ensures that the hard disks are not accessed.              */
  if( (argv[1][1]=='?') && ( (argc==2) || (argc==3) ) )
    {
    flags.do_not_pause_help_information=FALSE;
    flags.screen_color=7;
    flags.use_freedos_label=FALSE;

    if( (argv[2][1]=='N') || (argv[2][1]=='n') )
      {
      flags.do_not_pause_help_information=TRUE;
      Shift_Command_Line_Options(1);
      }

    Display_Help_Screen();
    exit(0);
    }

  /* Place the filename of this program into filename */
  index=strlen(argv[0]);
  location=0;
  do
    {
    if(argv[0] [index]=='\\')
      {
      location=index+1;
      index=-1;
      }
    index--;
    }while(index>=0);

  index=location;
  do
    {
    filename[index-location]=argv[0] [index];
    index++;
    }while(index<=(strlen(argv[0])) );

  index=0;
  do
    {
    if(filename[index]=='.') filename[index]=0;
    index++;
    }while(index<12);

  /* Place the path of this program into path. */
  if(location>0)
    {
    index=0;
    do
      {
      path[index]=argv[0] [index];

      index++;
      }while(index<location);
    path[index]=0;
    }
  else path[0]=0;

  Initialization(&*env);

#ifdef DEBUG
  if(debug.path==TRUE)
    {
    printf("\nThe PATH to \"%s\" is:  ",filename);
    printf("\"%s\"\n\n",path);
    Pause();
    }
#endif

  /* New Parsing Routine */
  /* The command line format is:                                            */
  /* /aaaaaaaaaa:999999,999 9 /aaaaaaaaaa:999999,999 /aaaaaaaaaa:999999,999 /aaaaaaaaaa:999999,999   */
  /* Where:   "a" is an ascii character and "9" is a number                 */
  /* Note:  The second "9" in the above command line format is the drive    */
  /*        number.  This drive number can now be anywhere on the line.     */

  /* If "FDISK" is typed without any options */
  number_of_command_line_options=Get_Options(&*argv,argc);
  if(number_of_command_line_options==0)
    {
    Interactive_User_Interface();
    exit(0);
    }
  else
    {
    flags.use_iui=FALSE;
    do
      {
#ifdef DEBUG
      if(debug.command_line_arguments==TRUE)
	{
	int command_line_index=0;

	printf("\n");
	do
	  {
	  printf("/%s:",arg[command_line_index].choice);
	  printf("%d,",arg[command_line_index].value);
	  printf("%d ",arg[command_line_index].extra_value);
	  command_line_index++;
	  }while(command_line_index<number_of_command_line_options);

	Pause();
	}
#endif

      command_ok=FALSE;

      switch(arg[0].choice[0])
	{
	case 'A':
	  {
	  if(0==strcmp(arg[0].choice,"ACTIVATE"))
	    {
	    if((arg[0].value<1) || (arg[0].value>4))
	      {
	      printf("\nPartition number is out of range (1-4)...Operation Terminated.\n");
	      exit(9);
	      }

	    Set_Active_Partition(int(arg[0].value-1));
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }

	  if(0==strcmp(arg[0].choice,"ACTOK"))
	    {
	    if( (flags.version==W95B) || (flags.version==W98) )
	     Ask_User_About_FAT32_Support();

	    Interactive_User_Interface();
	    exit(0);
	    }

	  if(0==strcmp(arg[0].choice,"AMBR"))
	    {
	    Create_Alternate_MBR();
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }

	  if(0==strcmp(arg[0].choice,"AUTO"))
	    {
	    Automatically_Partition_Hard_Drive();
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }
	  }
	  break;

	case 'C':
	  {
	  if(0==strcmp(arg[0].choice,"CLEAR"))
	    {
	    if(flags.using_default_drive_number==TRUE)
	      {
	      printf("\nNo drive number has been entered...Operation Terminated.\n");
	      exit(9);
	      }

	    Clear_Partition_Table();
	    command_ok=TRUE;

	    Re_Initialization();
	    Shift_Command_Line_Options(1);
	    }

	  if(0==strcmp(arg[0].choice,"CLEARALL"))
	    {
	    if(flags.using_default_drive_number==TRUE)
	      {
	      printf("\nNo drive number has been entered...Operation Terminated.\n");
	      exit(9);
	      }

	    Clear_Entire_Sector_Zero();
	    command_ok=TRUE;

	    Re_Initialization();
	    Shift_Command_Line_Options(1);
	    }

	  if(0==strcmp(arg[0].choice,"CLEARFLAG"))
	    {
	    Command_Line_Clear_Flag();
	    command_ok=TRUE;
	    }

	  if(0==strcmp(arg[0].choice,"CMBR"))
	    {
	    Create_MBR();
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }
	  }
	  break;

	case 'D':
	  {
	  if(0==strcmp(arg[0].choice,"DEACTIVATE"))
	    {
	    Clear_Active_Partition();
	    Write_Partition_Tables();
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }

	  if(0==strcmp(arg[0].choice,"DELETE"))
	    {
	    Command_Line_Delete();
	    command_ok=TRUE;
	    }

	  if(0==strcmp(arg[0].choice,"DUMP"))
	    {
	    Dump_Partition_Information();
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }
	  }
	  break;

	case 'E':
	  {
	  if(0==strcmp(arg[0].choice,"EXT"))
	    {
	    Command_Line_Create_Extended_Partition();
	    command_ok=TRUE;
	    }
	  }
	  break;

	case 'F':
	  {
	  if(0==strcmp(arg[0].choice,"FPRMT"))
	    {
	    if( (flags.version==W95B) || (flags.version==W98) ) flags.fprmt=TRUE;
	    Interactive_User_Interface();
	    exit(0);
	    }
	  }
	  break;

	case 'I':
	  {
	  if(0==strcmp(arg[0].choice,"INFO"))
	    {
	    Command_Line_Info();
	    command_ok=TRUE;
	    }
/*
    Add in the future.....
	  if(0==strcmp(arg[0].choice,"IUI"))
	    {
	    flags.return_from_iui=TRUE;
	    Interactive_User_Interface();
	    flags.return_from_iui=FALSE;
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }
*/
	  }
	  break;

	case 'L':
	  {
	  if(0==strcmp(arg[0].choice,"LOG"))
	    {
	    Command_Line_Create_Logical_DOS_Drive();
	    command_ok=TRUE;
	    }

	  if(0==strcmp(arg[0].choice,"LOGO"))
	    {
	    flags.fat32=FALSE;
	    Command_Line_Create_Logical_DOS_Drive();
	    flags.fat32=TRUE;
	    command_ok=TRUE;
	    }
	  }
	  break;

	case 'M':
	  {
	  if(0==strcmp(arg[0].choice,"MBR"))
	    {
	    Create_MBR();
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }

	  if(0==strcmp(arg[0].choice,"MODIFY"))
	    {
	    Command_Line_Modify();
	    command_ok=TRUE;
	    }

	  if(0==strcmp(arg[0].choice,"MONO"))
	    {
	    flags.monochrome=TRUE;
	    textcolor(7);
	    flags.use_iui=TRUE;
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }

	  if(0==strcmp(arg[0].choice,"MOVE"))
	    {
	    Command_Line_Move();
	    command_ok=TRUE;
	    }
	  }
	  break;

	case 'P':
	  {
	  if(0==strcmp(arg[0].choice,"PRI"))
	    {
	    Command_Line_Create_Primary_Partition();
	    command_ok=TRUE;
	    }

	  if(0==strcmp(arg[0].choice,"PRIO"))
	    {
	    flags.fat32=FALSE;
	    Command_Line_Create_Primary_Partition();
	    flags.fat32=TRUE;
	    command_ok=TRUE;
	    }
	  }
	  break;

	case 'Q':
	  {
	  if(0==strcmp(arg[0].choice,"Q"))
	    {
	    flags.reboot=FALSE;

	    if( (flags.version==W95B) || (flags.version==W98) )
	     Ask_User_About_FAT32_Support();

	    Interactive_User_Interface();
	    exit(0);
	    }
	  }
	  break;

	case 'R':
	  {
	  if(0==strcmp(arg[0].choice,"REBOOT"))
	    {
	    Write_Partition_Tables();            /* If no changes have been  */
						 /* made, then this function */
	    Reboot_PC();                         /* will simply return       */
	    }                                    /* without writing anything.*/

	  if(0==strcmp(arg[0].choice,"RMBR"))
	    {
	    Remove_MBR();
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }
	  }
	  break;

	case 'S':
	  {
/*
	  if(0==strcmp(arg[0].choice,"SAVE"))
	    {
	    Write_Partition_Tables();
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }
*/

	  if(0==strcmp(arg[0].choice,"SETFLAG"))
	    {
	    Command_Line_Set_Flag();
	    command_ok=TRUE;
	    }

	  if(0==strcmp(arg[0].choice,"SMBR"))
	    {
	    Save_MBR();
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }

	  if(0==strcmp(arg[0].choice,"STATUS"))
	    {
	    Command_Line_Status();
	    command_ok=TRUE;
	    }

	  if(0==strcmp(arg[0].choice,"SWAP"))
	    {
	    Command_Line_Swap();
	    command_ok=TRUE;
	    }
	  }
	  break;

	case 'T':
	  {
	  if(0==strcmp(arg[0].choice,"TESTFLAG"))
	    {
	    Command_Line_Test_Flag();
	    command_ok=TRUE;
	    }
	  }
	  break;

	case 'X':
	  {
	  if(0==strcmp(arg[0].choice,"X"))
	    {
	    Command_Line_X();
	    exit(0);
	    }

	  if(0==strcmp(arg[0].choice,"XO"))
	    {
	    flags.extended_options_flag=TRUE;
	    flags.allow_abort=TRUE;
	    flags.del_non_dos_log_drives=TRUE;
	    flags.set_any_pri_part_active=TRUE;
	    flags.use_iui=TRUE;
	    command_ok=TRUE;

	    Shift_Command_Line_Options(1);
	    }
	  }
	  break;

	case '?':
	  {
	  if(0==strcmp(arg[1].choice,"NOPAUSE"))
	    {
	    flags.do_not_pause_help_information=TRUE;
	    Shift_Command_Line_Options(1);
	    }
	  Display_Help_Screen();
	  command_ok=TRUE;

	  Shift_Command_Line_Options(1);
	  }
	  break;

	default:
	  {
	  printf("\nSyntax Error...Operation Terminated.\n");
	  exit(1);
	  }
	}

      if(command_ok==FALSE)
	{
	printf("\nSyntax Error...Operation Terminated.\n");
	exit(1);
	}

      }while(number_of_command_line_options>0);

#ifdef DEBUG
    if(debug.write==FALSE) Pause();
#endif

    if(flags.use_iui==TRUE) Interactive_User_Interface();

    Write_Partition_Tables();
    exit(0);
    }
}

⌨️ 快捷键说明

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