Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define OP_BACKSPACE 1
- #define OP_COPY 2
- #define OP_MOVE 3
- #define OP_DELETE 4
- #define OP_PASTE 5
- #define OP_UNDO 6
- #define OP_REDO 7
- #define OP_INSERT 8
- void applyop(int idx, int n, FILE *f, NODE **h, int v[8], int pos)
- {
- int i;
- char buff[64];
- for (i = 0; i < n; i++)
- {
- fgets(buff, 64, f);
- if (i != idx)
- continue;
- switch (v[i])
- {
- case OP_BACKSPACE:
- {
- // aplici backspace cu parametrul pos si h
- }
- case OP_PASTE:
- {
- // la fel
- }
- case OP_MOVE:
- {
- x = atoi(buff + 5);
- // aplici move cu parametrii x, h, pos
- }
- // etc
- }
- }
- }
- fscanf(f, "%d", &n);
- getchar();
- for(i = 0; i < n; i++)
- {
- fgets(buff, 64, f);
- if (!strcmp(buff, "backspace"))
- v[i] = OP_BACKSPACE;
- else if (!strcmp(buff, "undo"))
- v[i] = OP_UNDO;
- else if (!strcmp(buff, "redo"))
- v[i] = OP_REDO;
- else if (!strcmp(buff, "paste"))
- v[i] = OP_PASTE;
- else if (!strstr(buff, "copy"))
- v[i] = OP_COPY;
- else if (!strstr(buff, "delete"))
- v[i] = OP_DELETE;
- else if (!strstr(buff, "insert"))
- v[i] = OP_INSERT;
- else
- v[i] = OP_MOVE;
- }
- for (i = 0, undo = -1; i < n; i++)
- {
- if (i+1 < n)
- {
- if (v[i+1] == OP_UNDO)
- undo = i;
- }
- if (undo == i)
- continue;
- if (v[i] == OP_REDO)
- {
- if (undo != -1)
- {
- // aplica operatia undo.
- undo = -1;
- }
- else
- printf("Nu a fost gasita nicio operatie undo precedenta!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement