|
|
@@ -43,26 +43,31 @@ int main(int argc, char* argv[]) {
|
|
|
int includes_n = argc - 2;
|
|
|
int lines_n = 4 + includes_n;
|
|
|
|
|
|
- fifo* lines_head = (fifo*) malloc(sizeof(fifo));
|
|
|
- lines_head->string = "";
|
|
|
- lines_head->next = NULL;
|
|
|
+ char* lines[BUF_SIZE];
|
|
|
|
|
|
+ int lines_i = 0;
|
|
|
if (argc > 2) {
|
|
|
for (int i = 2; i < argc; i++) {
|
|
|
- char line[BUF_SIZE] = "#include <";
|
|
|
+ char* line = (char*) malloc(BUF_SIZE);
|
|
|
+ strcpy(line, "#include <");
|
|
|
strcat(line, argv[i]);
|
|
|
strcat(line, ".h>\n");
|
|
|
- fifo_append(lines_head, line);
|
|
|
+
|
|
|
+ lines[lines_i] = line;
|
|
|
+
|
|
|
+ lines_i++;
|
|
|
+
|
|
|
}
|
|
|
- fifo_append(lines_head, "\n");
|
|
|
+ lines[lines_i] = "\n";
|
|
|
}
|
|
|
|
|
|
- fifo_append(lines_head, "int main() {\n\n");
|
|
|
- fifo_append(lines_head, " return 0;\n");
|
|
|
- fifo_append(lines_head, "}");
|
|
|
+ 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, fifo_read(&lines_head), strlen(lines_head->string));
|
|
|
+ write(fd, lines[i], strlen(lines[i]));
|
|
|
}
|
|
|
|
|
|
close(fd);
|
|
|
@@ -75,31 +80,3 @@ int main(int argc, char* argv[]) {
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
-void fifo_append(fifo* head, char* string) {
|
|
|
- fifo* last = head;
|
|
|
-
|
|
|
- char* new_string = (char*) malloc(sizeof(char) * strlen(string));
|
|
|
- strcpy(new_string, string);
|
|
|
-
|
|
|
- while (last->next != NULL)
|
|
|
- last = last->next;
|
|
|
-
|
|
|
- fifo* new_node = (fifo*) malloc(sizeof(fifo));
|
|
|
- new_node->string = new_string;
|
|
|
- new_node->next = NULL;
|
|
|
-
|
|
|
- last->next = new_node;
|
|
|
-}
|
|
|
-
|
|
|
-char* fifo_read(fifo** head) {
|
|
|
- char* return_value = (*head)->string;
|
|
|
-
|
|
|
- fifo* prev_head = *head;
|
|
|
-
|
|
|
- *head = (*head)->next;
|
|
|
-
|
|
|
- free(prev_head);
|
|
|
-
|
|
|
- return return_value;
|
|
|
-}
|