Previous Tip  |  Next Tip  |  Design Tips   | [Bill's Home]

139. UNIX emulator

A major problem in networking is getting hands-on experience. In previous examples hardware devices, such as switches and wireless access points have been emulated. In this example an operating system is emulated. This can be used to teach the basic principles of networking in UNIX, without actually requiring to log-onto a working system. It, of course, can never replace the real thing, but it gives users a start in the main principles of the system.

[Expand]

 

The parsing of the user command is achieved with:

if (str=="ls") {disp.htmltext=""; msg=dir[level];}
else if (str=="cd" && ((level==0 && str1=="bin") || str1=="/bin") ) {prompt="[/bin ] % "; level=2; }
else if (str=="cd" && ((level==0 && str1=="cdrom") || str1=="/cdrom") ) {prompt="[/cdrom ] % "; level=3;}
else if (str=="cd" && ((level==0 && str1=="dev") || str1=="/dev") ) {prompt="[/dev ] % "; level=4;}
else if (str=="cd" && ((level==0 && str1=="devices") || str1=="/devices") ) {prompt="[/devices ] % "; level=5;}
else if (str=="cd" && ((level==0 && str1=="etc") || str1=="/etc") ) {prompt="[/etc ] % "; level=6;}

...