/*This program works just like MS-DOS. It takes in the input, uses the C Library, uses the system files and function, executing and displaying the code on the same command prompt.
*/

/*************************************************
Author: Rajnesh Prasad
Program: Disk Operating System(DOS) from C Language
Date: 4th July, 2006
**************************************************/
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <dir.h>
#include <windows.h>

char *current_directory(char *path);
void welcome();
void menu();

void main()
{
	char command[50];
   char olddir[150];
   //Changing the console color(www.daniweb.com)
   HANDLE  hConsole;
   hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

   system("TITLE DOS --- Designed by Rajneshwar Prasad");
   cls:
   system("COLOR 0F");
   welcome();

   do{
   	aptech:
   	current_directory(olddir);
      SetConsoleTextAttribute(hConsole, 14);
	   printf(" %s  ",olddir);
      SetConsoleTextAttribute(hConsole, 12);
  	 	gets(command);
      SetConsoleTextAttribute(hConsole, 24);
      if(strcmpi(command,"1")==0){
      	menu();
         goto aptech;
      }
      else if(strcmpi(command,"2")==0){
      	system("calc.exe");
      }
      else if(strcmpi(command,"3")==0){
      	system("mspaint.exe");
      }
      else if(strcmpi(command,"cls")==0){
         system("cls");
      	goto cls;
      }
      else if(strcmpi(command,"cd..")==0){
      		chdir("\\");
      }
      else if(strcmpi(command,"c:")==0){
      		system("c:\\");
      }
      else{
      	SetConsoleTextAttribute(hConsole, 10);
      	printf("  ");
         SetConsoleTextAttribute(hConsole, 11);
			system(command);
      }
   }while(strcmp(command,"exit"));
}
char *current_directory(char *path)
{
  strcpy(path, "X:\\");
  path[0] = 'A' + getdisk();
  getcurdir(0, path+3);
  return(path);
}
void welcome(){
	printf("\t\t\t--------------------------------\n");
	printf("\t\t\tºAuthor :   Rajneshw…r Prasad  º\n");
   printf("\t\t\tºProgram:   DOS from C Languageº\n");
   printf("\t\t\tº             ¸2006            º\n");
   //Changing the console color(www.daniweb.com)
   HANDLE  hConsole;
   hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
   SetConsoleTextAttribute(hConsole, 5);
   printf("\t\t\t\n\n");
   SetConsoleTextAttribute(hConsole, 4);
   printf("\t\t\tEnter 1 to get other menus\n\n");
}
void menu(){
	HANDLE  hConsole;
   hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hConsole, 2);
	printf("--------------------------------\n");
	printf("ºCalculator     :             2º\n");
   printf("ºMicrosoft Paint:             3º\n");
   printf("º             ¸2006            º\n");

   SetConsoleTextAttribute(hConsole, 5);
   printf("\n\n");
}