|
|
@@ -4,24 +4,17 @@
|
|
|
#include <unistd.h>
|
|
|
#include <errno.h>
|
|
|
#include <stdlib.h>
|
|
|
+#include <stdbool.h>
|
|
|
|
|
|
#define BUF_SIZE 256
|
|
|
|
|
|
-typedef struct node {
|
|
|
- char* string;
|
|
|
- struct node* next;
|
|
|
-} fifo;
|
|
|
-
|
|
|
-void fifo_append(fifo* head, char* new_string);
|
|
|
-char* fifo_read(fifo** head);
|
|
|
-
|
|
|
int main(int argc, char* argv[]) {
|
|
|
if (argc <= 1) {
|
|
|
printf("Too few arguments\n");
|
|
|
return 1;
|
|
|
}
|
|
|
- printf("%d\n", argc);
|
|
|
|
|
|
+ const bool HAS_INCLUDES = argc > 2;
|
|
|
char name[strlen(argv[1]) + 2];
|
|
|
strcpy(name, argv[1]);
|
|
|
strcat(name, ".c");
|
|
|
@@ -39,14 +32,14 @@ int main(int argc, char* argv[]) {
|
|
|
errno = 0;
|
|
|
|
|
|
const int fd = creat(path, S_IRUSR | S_IWUSR | S_IROTH);
|
|
|
-
|
|
|
+
|
|
|
int includes_n = argc - 2;
|
|
|
int lines_n = 4 + includes_n;
|
|
|
|
|
|
char* lines[BUF_SIZE];
|
|
|
|
|
|
int lines_i = 0;
|
|
|
- if (argc > 2) {
|
|
|
+ if (HAS_INCLUDES) {
|
|
|
for (int i = 2; i < argc; i++) {
|
|
|
char* line = (char*) malloc(BUF_SIZE);
|
|
|
strcpy(line, "#include <");
|
|
|
@@ -56,16 +49,19 @@ int main(int argc, char* argv[]) {
|
|
|
lines[lines_i] = line;
|
|
|
|
|
|
lines_i++;
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
lines[lines_i] = "\n";
|
|
|
+ lines[++lines_i] = "int main() {\n\n";
|
|
|
+ lines[++lines_i] = " return 0;\n";
|
|
|
+ lines[++lines_i] = "}";
|
|
|
+ } else {
|
|
|
+ lines[lines_i] = "int main() {\n\n";
|
|
|
+ lines[++lines_i] = " return 0;\n";
|
|
|
+ lines[++lines_i] = "}";
|
|
|
+ lines_n--;
|
|
|
}
|
|
|
|
|
|
- lines[++lines_i] = "int main() {\n\n";
|
|
|
- lines[++lines_i] = " return 0;\n";
|
|
|
- lines[++lines_i] = "}";
|
|
|
-
|
|
|
-
|
|
|
for (int i = 0; i < lines_n; i++) {
|
|
|
write(fd, lines[i], strlen(lines[i]));
|
|
|
}
|