Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------------------------------
- // NAME: Radoslav Hubenov
- // CLASS: XIa
- // NUMBER: 22
- // PROBLEM: #1
- // FILE NAME: main.c (unix file name)
- // FILE PURPOSE:
- // Main файлът ми, който свързва всички останали файлове.
- // Програмата реализира стандартната UNIX команда tail.
- //------------------------------------------------------------------------
- #include "tail.h"
- #include <unistd.h>
- #include <string.h>
- #include <stdio.h>
- #include "read_stdin.h"
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- int main(int argc, char* argv[]){
- char left_point[5] = "==> ";
- char right_point[5] = " <==\n";
- if(argc == 1){
- read_stdin();
- return 0;
- }
- for(int i = 1; i < argc; i++){
- if(!strcmp(argv[i], "-")){// Allow the user to write to stdin if '-' is one of the arguments
- read_stdin();
- continue;
- }
- if( access( argv[i], F_OK ) == -1 ) { //Check if file is opened succesfuly for error handling
- write(STDERR_FILENO, "tail: ", 6);
- write(STDERR_FILENO, "cannot open '", 13);
- write(STDERR_FILENO, argv[i], strlen(argv[i]));
- write(STDERR_FILENO, "' for reading: ", 15);
- perror("");
- continue;
- }
- if(argc > 2){ // Printing the name of the file if more than one file is opened
- write(STDOUT_FILENO, &left_point, strlen(left_point));
- write(STDOUT_FILENO, argv[i], strlen(argv[i]));
- write(STDOUT_FILENO, &right_point, strlen(right_point));
- }
- tail(argv[i]);
- if(i != argc - 1){
- write(STDOUT_FILENO, "\n", 1);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement