-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain1Coder.c
More file actions
131 lines (112 loc) · 5.14 KB
/
Copy pathMain1Coder.c
File metadata and controls
131 lines (112 loc) · 5.14 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
************************************************************
* COMPILERS COURSE - Algonquin College
* Code version: Fall, 2025
* Author: Alex Vu and Yassine Amraoui
* Professors: Paulo Sousa
************************************************************
"\t=-------------------------------------------------------------------=\n",
"\t| COMPILERS - ALGONQUIN COLLEGE (S25) |\n",
"\t=-------------------------------------------------------------------=\n",
"\t @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n",
"\t @@ @@ \n",
"\t @@ %&@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ @@ \n",
"\t @@ @%% (@@@@@@@@@ @ @ @@ \n",
"\t @@ @& @ @ @ @ @ @@ \n",
"\t @@ @ @ % / / @@@@@@ @ @@ \n",
"\t @@ & @ @ @@ @ @@ \n",
"\t @@ @/ @*@ @ @ @ @ @@ \n",
"\t @@ @@@@ @@ @ @ @ @@ \n",
"\t @@ /@@ @@@ @ @ @@ \n",
"\t @@ @ / / @@ @ @ @@ \n",
"\t @@ @ @@ /@/ @@@ @ @ @@ \n",
"\t @@ @@@@@@@@@@@@@@@ @ @@ \n",
"\t @@ @@ \n",
"\t @@ S T R U C T U R A L @@ \n",
"\t @@ By Alex Vu and Yassine Amraoui @@ \n",
"\t @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \n",
"\t \n",
"\t[COMPILER SCRIPT ..................................................]\n",*/
/*
************************************************************
* File name: MainCoder.c
* Compiler: MS Visual Studio 2022
* Course: CST 8152 � Compilers, Lab Section: [011, 012]
* Assignment: A12, A22, A32.
* Date: Sep 01 2025
* Professor: Paulo Sousa
* Purpose: This file is the main code for Buffer/Reader (A12)
* Function list: (...).
*************************************************************/
/*
*.............................................................................
* ADVICE 1:
* Please check the "TODO" labels to develop your activity.
*
* ADVICE 2: Preprocessor directives
* The #define _CRT_SECURE_NO_WARNINGS should be used in MS Visual Studio projects
* to suppress the warnings about using "unsafe" functions like fopen()
* and standard sting library functions defined in string.h.
* The define directive does not have any effect on other compiler projects
* (Gcc, VSCode, Codeblocks, etc.).
*.............................................................................
*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#ifndef COMPILERS_H_
#include "Compilers.h"
#endif
#ifndef CODER_H_
#include "Step1Coder.h"
#endif
/* Check for ANSI C compliancy */
#define ANSI_C 0
#if defined(__STDC__)
#undef ANSI_C
#define ANSI_C 1
#endif
/*
* TODO .......................................................................
* Basically, change all datatypes to your language definitions
* (see "Compilers.h")
*/
/*
* -------------------------------------------------------------
* Function declarations
* -------------------------------------------------------------
*/
struct_int main1Coder(struct_int argc, struct_strg* argv) {
if (argc < 4) {
printf("Usage: %s [cypher=1|decypher=0] <input_file> <output_file>\n", argv[0]);
return EXIT_FAILURE;
}
struct_strg operation = argv[2];
struct_char inputPath[256];
struct_char outputPath[256];
struct_strg key = STR_LANGNAME;
/* Build paths with InOut/ and InOut/ folders */
snprintf(inputPath, sizeof(inputPath), "InOut/%s", argv[3]);
snprintf(outputPath, sizeof(outputPath), "InOut/%s", argv[4]);
int encode = atoi(operation); // 1 = cypher, 0 = decypher
if (encode == 1)
cypher(inputPath, outputPath, key);
else if (encode == 0)
decypher(inputPath, outputPath, key);
else {
errorPrint("%s%s%s", "Error: Unknown operation ", operation, ". Use '1' for cypher or '0' for decypher.\n");
return EXIT_FAILURE;
}
printf("Output written to '%s'\n", outputPath);
// Optional: preview output content in memory
struct_strg output = vigenereMem(inputPath, key, encode);
if (output) {
printf("OUTPUT:\n%s\n", output);
free(output);
}
printf("Operation '%s' completed successfully.\n", operation);
return EXIT_SUCCESS;
}