mindos--Operating System
Summary: This implementation is a function for (1) Self-defined system prompt (2) custom command Set (8-10) (3) user input Help to find commands (4) The function of the List command, distinguish internal or external command (5) user input quit Quit (6) Internal command has dir, CD, MD, RD, CLS, date, time, Ren, copy, and so on. Added system (); The implement Window command operation added parameters can is used to determine if the command has insufficient parameters: command with parameters can not implement system operation
#include <stdio.h> #include <string.h> #include <stdlib.h>#include<windows.h>#defineMax 500structcmd{Charcmd[ -]; Charfunction[ -]; Cahr can; intPost;};intCount=0;voidInit (structCMD Cm[max]) {FILE*FP; if((Fp=fopen ("Cmd.txt","A +"))==NULL) {printf ("File Open error!\n"); Exit (0); } while(!feof (FP) &&fgetc (fp)! =EOF) {fseek (FP),-1L, Seek_cur); FSCANF (FP,"%s%s%c%d",&cm[count].cmd,&cm[count].function,&cm[count].can,&cm[count].post); Count++; } if(fclose (FP)) {printf ("Can not close the file!\n"); Exit (0); }}voidDisplaystructCMD Cm[max]) { for(intI=0; i<count;i++) {printf ("%-10s%s\n", STRUPR (cm[i].cmd), cm[i].function); STRLWR (Cm[i].cmd); }}voidProcessstructCMD Cm[max]) { Charstr[Ten]; printf ("Microsoft Windows XP [version 5.1.2600]\n"); printf ("(C) Copyright 1985-2001 Microsoft corp.\n"); while(strcmp (str,"quit")!=0) {printf ("\nc:\\documents and Settings\\hskd>"); scanf ("%s", str); STRLWR (str); BOOLflag=false; if(strcmp (str," Help")==0) {printf ("For more information about a command, type the help command name \ n"); Display (cm); Flag=true; }Else{ for(intI=0; i<count;i++) { if(strcmp (str,cm[i].cmd) = =0) { if(cm[i].post==1) printf ("'%s ' internal command entered correctly! \ n the command function is:%s\n", str,cm[i].function); Elseprintf ("'%s ' external command entered correctly! \ n the command function is:%s\n", str,cm[i].function); //implementing the Windwins commandsystem (STR); //determine if parameters are taken if(cm[i].can=='T') printf ("command with parameter \ n"); Else if(cm[i].can=='F') printf ("command with no parameters"); Elseprintf ("parametric commands available"); Flag=true; Break; } } if(!flag) { if(strcmp (str,"quit")!=0) printf ("'%s ' is not an internal or external command, or a program that can be run \ n or a batch file. \ n", str); }}} printf ("\ nthe program is over! \ n");}intMain () {structCMD Cm[max]; Init (CM); Process (cm); return 0;}
mindos--Operating System