Advertisement
Guest User

dlapiotrka

a guest
Dec 20th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.45 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package interfejs_so;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Scanner;
  10. /**
  11. *
  12. * @author Konrad
  13. */
  14. public class Shell {
  15. Boolean system;
  16. Boolean session;
  17. String command;
  18. ArrayList<String> parts;
  19. Shell()
  20. {
  21. system = false;
  22. session = false;
  23. command = null;
  24. parts = new ArrayList<>();
  25. }
  26. void system()
  27. {
  28. system=true;
  29. start();
  30. FileManagement filemanagement = new FileManagement();
  31. Process_container procmen = new Process_container();
  32. Scheduler scheduler = new Scheduler(procmen.get_by_PID(0));
  33. Memory memory = new Memory();
  34. while(system)
  35. {
  36.  
  37. login();
  38. while(session)
  39. {
  40. Scanner sc = new Scanner(System.in);
  41. System.out.print("bigOS:\\User>");
  42. command=sc.nextLine();
  43. for(int i=0;i<command.length();i++)
  44. {
  45. if((int)command.charAt(i)<=90&&(int)command.charAt(i)>=65)
  46. {
  47. int help = (int)command.charAt(i);
  48. help=help+32;
  49. String newCommand = command.substring(0,i)+(char)help+command.substring(i+1);
  50. command=newCommand;
  51. }
  52. }
  53. cut();
  54. execute(procmen);
  55. }
  56. }
  57. }
  58. void cut()
  59. {
  60. parts.clear();
  61. String help="";
  62. for(int i=0;i<command.length();i++)
  63. {
  64. if(command.charAt(i)!=' ')
  65. {
  66. help=help+command.charAt(i);
  67. }
  68. else
  69. {
  70. parts.add(help);
  71. help="";
  72. }
  73. if(i==command.length()-1)
  74. {
  75. parts.add(help);
  76. }
  77.  
  78. }
  79.  
  80. }
  81. void start()
  82. {
  83. System.out.println("Tu jest logo bigOS");
  84. }
  85. void login()
  86. {
  87. while(true)
  88. {
  89. Scanner sc = new Scanner(System.in);
  90. System.out.printf("User: ");
  91. String user = sc.nextLine();
  92. System.out.printf("Password: ");
  93. String password = sc.nextLine();
  94. // Zabezpieczeniowiec sprawdza poprawnosc i laczy
  95. // Jezeli polaczyl jest return i session=true
  96. // Jezeli nie, pytanie czy chce zakonczyc prace systemu
  97. session=true;
  98. return;
  99. }
  100. }
  101. void execute(Process_container procmen)
  102. {
  103. switch(parts.get(0))
  104. {
  105.  
  106. case "help":
  107. {
  108. if(parts.size()==1)
  109. System.out.println("help");
  110. else
  111. System.out.println("Bledne argumenty");
  112. break;
  113. }
  114. case "dir":
  115. {
  116. if(parts.size()==1)
  117. // Zabezpieczeniowiec sprawdza
  118. //Pliki->wypisanie plikow
  119. System.out.println("dir");
  120. else
  121. System.out.println("Bledne argumenty");
  122. break;
  123. }
  124. case "shutdown":
  125. {
  126. if(parts.size()==1)
  127. {
  128. session=false;
  129. system = false;
  130. }
  131. else if(parts.size()==2 && parts.get(1).equals("-l"))
  132. session=false;
  133. else
  134. System.out.println("Bledne argumenty");
  135. break;
  136. }
  137. case "df":
  138. {
  139. if(parts.size()==2)
  140. {
  141. // Zabezpieczeniowiec -> sprawdza
  142. // Pliki->usuwanie
  143. System.out.println("Usunieto "+parts.get(1));
  144.  
  145. }
  146. else
  147. System.out.println("Bledne argumenty");
  148.  
  149. break;
  150. }
  151. case "cf":
  152. {
  153. // Tutaj trzeba umowic sie ile argumentow
  154. System.out.println("Tworze plik");
  155. break;
  156. }
  157. case "wf":
  158. {
  159. if(parts.size()>2)
  160. {
  161. System.out.printf("Dopisuje do pliku "+parts.get(1)+": ");
  162. for(int i=2;i<parts.size();i++)
  163. System.out.printf(parts.get(i));
  164. // Zabezpieczeniowiec->sprawdza uprawnienia
  165. // Pliki->dopisac do pliku
  166.  
  167. }
  168. else
  169. System.out.println("Bledne argumenty");
  170. break;
  171. }
  172. case "tasklist":
  173. {
  174. if(parts.size()==1)
  175. {
  176. System.out.println("Wyswietla procesy");
  177. procmen.show_all_processes();
  178. }
  179. else
  180. System.out.println("Bledne argumenty");
  181. break;
  182. }
  183. case "cp":
  184. {
  185. if(parts.size()==4)
  186. {
  187. for(int i=0;i<parts.get(3).length();i++)
  188. if(Character.isDigit(parts.get(3).charAt(i)));
  189. else
  190. {
  191. System.out.println("Bledne argumenty");
  192. }
  193. procmen.create_process(parts.get(1),parts.get(2),Integer.parseInt(parts.get(3)));
  194. System.out.println("Tworze proces");
  195. }
  196. else if(parts.size()==5)
  197. {
  198. for(int i=0;i<parts.get(3).length();i++)
  199. if(Character.isDigit(parts.get(3).charAt(i)));
  200. else
  201. {
  202. System.out.println("Bledne argumenty");
  203. }
  204. for(int i=0;i<parts.get(4).length();i++)
  205. if(Character.isDigit(parts.get(4).charAt(i)));
  206. else
  207. {
  208. System.out.println("Bledne argumenty");
  209. }
  210. procmen.create_process(parts.get(1),parts.get(2),Integer.parseInt(parts.get(3)),Integer.parseInt(parts.get(4)));
  211. System.out.println("Tworze proces");
  212. }
  213. else
  214. System.out.println("Bledne argumenty");
  215. break;
  216. }
  217. case "type":
  218. {
  219. if(parts.size()==2)
  220. {
  221. //Wypisanie zawartosci pliku parts[2]
  222. }
  223. else if(parts.size()==4)
  224. {
  225. if((int)parts.get(2).charAt(0)==62)
  226. if(parts.get(2).length()== 2)
  227. {
  228. if((int)parts.get(2).charAt(1)==62)
  229. {
  230. // utworzenie nowego pliku parts[4] z zawartoscia pliku parts[2]
  231. }
  232. else
  233. System.out.println("Bledne argumenty");
  234. }
  235. else if (parts.get(2).length()==1)
  236. {
  237. // wpisanie zawartosci pliku parts[2] do istniejacego pliku parts[4]
  238. }
  239. else
  240. System.out.println("Bledne argumenty");
  241. else {
  242. System.out.println("Bledne argumenty");
  243. }
  244. }
  245. else
  246. {
  247. System.out.println("Bledne argumenty");
  248. }
  249. break;
  250. }
  251. case "net":
  252. {
  253. if(parts.size()>1)
  254. {
  255.  
  256. if("user".equals(parts.get(1)))
  257. {
  258. if(parts.size()==3)
  259. {
  260. //Wypisanie info o uzytkowniku parts[2]
  261. }
  262. else if(parts.size()==4)
  263. {
  264. if("/delete".equals(parts.get(3)))
  265. {
  266. //usuwa uzytkownika parts[2]
  267. }
  268. else
  269. {
  270. System.out.println("Bledne argumenty");
  271. }
  272. }
  273. else if(parts.size()==5)
  274. {
  275. if("/add".equals(parts.get(4)))
  276. {
  277. //Dodaje uzytkownika o nazwie parts[2] i hasle parts[3]
  278. }
  279. else
  280. {
  281. System.out.println("Bledne argumenty");
  282. }
  283. }
  284. else
  285. {
  286. System.out.println("Bledne argumenty");
  287. }
  288.  
  289. }
  290. else
  291. {
  292. System.out.println("Bledne argumenty");
  293. }
  294. }
  295. else
  296. {
  297.  
  298. }
  299. break;
  300. }
  301. default:
  302. {
  303.  
  304. System.out.println("'"+command+ "' jest nieznana komenda.");
  305. break;
  306. }
  307. }
  308.  
  309. }
  310.  
  311.  
  312.  
  313. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement