-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
117 lines (99 loc) · 3.17 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "editor.h"
int main()
{
Tlista *editor = (Tlista *)(malloc(sizeof(Tlista)));
TPilha *pilha = (TPilha *)(malloc(sizeof(TPilha)));
int startMode = 1;
int insertMode = 0;
inicEditor(editor);
iniciarPilha(pilha);
limparTerminal();
while (startMode == 1)
{
char comando[LINHA_TAM];
//char *comando = (char *)malloc(sizeof(char) * TAM);
fgets(comando, sizeof(comando), stdin);
//scanf("%[^\n]", comando);
int ehComando = verificarComando(comando);
if (ehComando == NOT_CMD && insertMode == 1)
{
if (editor->linhaCorrent == NULL)
adicionarLinha(editor, comando);
else
adicionarDepoisdaCorrente(editor, comando);
}
else if (ehComando != NOT_CMD)
{
int startCommandIndex = ehComando;
int commandCode = checkCommand(startCommandIndex, comando);
switch (commandCode)
{
case CMD_INSERIR: // Inserir
insertMode = 1;
//printf("INSERINDO\n");
break;
case CMD_REMOVER: // remover m, n
insertMode = 0;
//printf("REMOVENDO\n");
cmd_remover(editor, comando);
break;
case CMD_LINHA: // linha m
insertMode = 0;
cmd_linha(editor, comando);
break;
case CMD_LOCALIZAR: // localizar %x
insertMode = 0;
cmd_localizar(editor, comando);
break;
case CMD_ALTERAR: // alterar %x %y %
insertMode = 0;
//printf("ALTERAR\n");
cmd_alterar(editor, comando);
break;
case CMD_ULTIMO: // ultimo (to test)
insertMode = 0;
cmd_ultimo(editor);
break;
case CMD_IMPRIMIR: // imprimir m, n
insertMode = 0;
cmd_imprimir(editor, comando);
break;
case CMD_FIM: // fim
//startMode = 0;
//insertMode = 0;
cmdFim(&startMode, &insertMode);
break;
case CMD_INV: // prninv m, n
insertMode = 0;
cmd_prninv(editor, comando);
break;
case CMD_DEL: // deletar %x%
insertMode = 0;
//printf("DELETAR\n");
cmdDeletar(editor, comando, pilha);
break;
case CMD_UNDO: //undo
printf("UNDO\n");
insertMode = 0;
/*empilhar(pilha, "ola");
empilhar(pilha, "elia");
empilhar(pilha, "t");
desempilhar(pilha);*/
//printf("%s \n", pilha->pTopo->info.frase);
undo(editor, pilha);
break;
default:
insertMode = 0;
error(21);
break;
}
}
else
error(20);
}
//fflush(stdin);
return 0;
}