Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX_DESCRICAO 55
  5.  
  6. typedef struct{
  7. int hh;
  8. int mm;
  9. int ss;
  10. } horario;
  11.  
  12. typedef struct
  13. {
  14. int prior;
  15. horario chegada;
  16. char descricao[MAX_DESCRICAO];
  17. } celula;
  18.  
  19. void imprime_celula(celula* celula)
  20. {
  21. if (celula->prior <= 9)
  22. {
  23. printf("0");
  24. }
  25.  
  26. printf("%d %d:%d:%d %s\n", celula->prior,
  27. celula->chegada.hh,
  28. celula->chegada.mm,
  29. celula->chegada.ss,
  30. celula->descricao);
  31. }
  32.  
  33. horario horario_criar(char* token_horario)
  34. {
  35. horario novo_horario;
  36.  
  37. char* hora = strtok(token_horario, ":");
  38. novo_horario.hh = atoi(hora);
  39.  
  40. char* minuto = strtok(NULL, ":");
  41. novo_horario.mm = atoi(minuto);
  42.  
  43. char* segundo = strtok(NULL, ":");
  44. novo_horario.ss = atoi(segundo);
  45.  
  46. return novo_horario;
  47.  
  48. }
  49.  
  50. celula celula_criar(horario horario, int prioridade, char* descricao)
  51. {
  52. celula nova_celula =
  53. {
  54. .prior = prioridade, .chegada = horario
  55. };
  56.  
  57. strcpy(nova_celula.descricao, descricao);
  58. return nova_celula;
  59. }
  60.  
  61. celula celula_criar_add(char* descricao_entrada)
  62. {
  63. char* lixo = strtok(descricao_entrada, " ");//lixo contém a palavra add
  64.  
  65. printf("LIXO = %s\n", lixo);
  66.  
  67. char* prioridade = strtok(NULL, " ");
  68.  
  69. printf("PRIORIDADE = %s\n", prioridade);
  70. if (prioridade == NULL) { printf("prioridade eh null\n"); exit(1); }
  71. int prioridade_int = atoi(prioridade);
  72.  
  73. /*lixo = strtok(NULL, " ");
  74.  
  75. if (lixo == NULL)
  76. {
  77. printf("lixo eh NULL\n");
  78. exit(1);
  79. }
  80.  
  81. printf("lixo = %s\n", lixo);
  82. exit(1);*/
  83.  
  84. char* hora = strtok(NULL, " ");
  85.  
  86. char* processo=strtok(NULL, " ");
  87.  
  88. int prioridade_int = 0;
  89. horario novo_horario = horario_criar(hora);
  90. celula nova_celula = celula_criar(novo_horario, prioridade_int, processo);
  91.  
  92. return nova_celula;
  93. }
  94.  
  95. void parse_change(char* descricao_entrada)
  96. {
  97. char* lixo = strtok(descricao_entrada, "-");//lixo contém change
  98. char* char_da_funcao = strtok(NULL, " ");
  99.  
  100.  
  101. if ((*char_da_funcao) == 't')
  102. {
  103. char* token_horario_antigo = strtok(NULL, "|");
  104. printf("%s\n", token_horario_antigo);
  105. char* token_horario_novo = strtok(NULL, "|");
  106. printf("%s", token_horario_novo);
  107. horario horario_antigo = horario_criar(token_horario_antigo);
  108. horario horario_novo = horario_criar(token_horario_novo);
  109.  
  110. //modifica_processo_por_tempo(vector, horario_antigo, horario_novo);
  111. }
  112. else
  113. {// o char da entrada é p
  114.  
  115. char* token_prioridade_antiga = strtok(NULL, "|");
  116. int prioridade_antiga = atoi(token_prioridade_antiga);
  117.  
  118.  
  119. char* token_prioridade_nova = strtok(NULL, "|");
  120. int prioridade_nova = atoi(token_prioridade_nova);
  121.  
  122. //modifica_processo_por_prioridade(vector, prioridade_antiga, prioridade_nova);
  123.  
  124. }
  125. };
  126.  
  127. char parse_next(char* descricao_entrada)
  128. {
  129. char* lixo = strtok(descricao_entrada, "-");
  130. char* char_da_funcao = strtok(NULL, " ");
  131.  
  132.  
  133. return (*char_da_funcao);
  134. };
  135.  
  136. char parse_imprime(char* descricao_entrada)
  137. {
  138. char* lixo = strtok(descricao_entrada, "-");
  139. char* char_da_funcao = strtok(NULL, " ");
  140.  
  141.  
  142. return (*char_da_funcao);
  143. };
  144.  
  145. char parse_exec(char* descricao_entrada)
  146. {
  147. char* lixo = strtok(descricao_entrada, "-");
  148. char* char_da_funcao = strtok(NULL, " ");
  149.  
  150.  
  151. return (*char_da_funcao);
  152. };
  153.  
  154. int main()
  155. {
  156. char descricao_entrada[MAX_DESCRICAO];
  157. char* selecao;
  158. //Vector* vector;
  159.  
  160. while (1)
  161. {
  162. fgets(descricao_entrada, 50, stdin);
  163.  
  164. selecao = strtok(descricao_entrada," ");
  165.  
  166. if (strcmp(selecao, "quit") == 0) // strcmp retorna zero se as strings são iguais
  167. {
  168. break;
  169. }
  170. else if (strcmp(selecao, "add") == 0)
  171. {
  172. celula nova_celula = celula_criar_add(descricao_entrada);
  173. imprime_celula(&nova_celula);
  174. //inserir(vector,nova_celula);
  175. continue;
  176. }
  177. else if (strcmp(selecao, "next") == 0)
  178. {
  179. char opcao = parse_next(descricao_entrada);
  180.  
  181. //proximo_processo(vector, opcao);
  182.  
  183. continue;
  184. }
  185. else if (strcmp(selecao, "exec") == 0)
  186. {
  187. char opcao = parse_exec(descricao_entrada);
  188.  
  189. //executa_processo(vector, opcao);
  190.  
  191. continue;
  192. }
  193. else if (strcmp(selecao, "change") == 0)
  194. {
  195. parse_change(descricao_entrada);
  196. continue;
  197. }
  198. else if (strcmp(selecao, "print") == 0)
  199. {
  200. char opcao = parse_imprime(descricao_entrada);
  201.  
  202. //imprime_processo(vector, opcao);
  203. continue;
  204. }
  205.  
  206. }
  207.  
  208. //vector_destructor(&vector);
  209.  
  210. return 0;
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement