add option for bursting lines
This commit is contained in:
parent
08d65b254e
commit
8c09af80fb
1 changed files with 32 additions and 21 deletions
53
multif.c
53
multif.c
|
@ -8,11 +8,6 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Error : You must specify a directory\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
DIR* FD;
|
DIR* FD;
|
||||||
struct dirent* in_file;
|
struct dirent* in_file;
|
||||||
FILE *entry_file;
|
FILE *entry_file;
|
||||||
|
@ -20,6 +15,19 @@ int main(int argc, char *argv[])
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
ssize_t lineSize = 0;
|
ssize_t lineSize = 0;
|
||||||
|
int burst = 1;
|
||||||
|
if (argc < 2)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error : You must specify a directory\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (argc >= 3)
|
||||||
|
burst = atoi(argv[2]);
|
||||||
|
if (burst <= 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error : burst must be an integer greater than 0\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
char *directory = argv[1];
|
char *directory = argv[1];
|
||||||
strcat(directory, "/");
|
strcat(directory, "/");
|
||||||
|
@ -36,7 +44,6 @@ int main(int argc, char *argv[])
|
||||||
while ((in_file = readdir(FD)))
|
while ((in_file = readdir(FD)))
|
||||||
{
|
{
|
||||||
|
|
||||||
char *line = NULL;
|
|
||||||
if (!strcmp (in_file->d_name, ".") || !strcmp (in_file->d_name, ".."))
|
if (!strcmp (in_file->d_name, ".") || !strcmp (in_file->d_name, ".."))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -44,23 +51,27 @@ int main(int argc, char *argv[])
|
||||||
strcpy(entry_path,directory);
|
strcpy(entry_path,directory);
|
||||||
strcat(entry_path,in_file->d_name);
|
strcat(entry_path,in_file->d_name);
|
||||||
|
|
||||||
entry_file = fopen(entry_path, "a");
|
int c;
|
||||||
if (entry_file == NULL)
|
for (c = 0; c < burst; c++) {
|
||||||
{
|
char *line = NULL;
|
||||||
fprintf(stderr, "Error : Failed to open entry file - %s\n", strerror(errno));
|
entry_file = fopen(entry_path, "a");
|
||||||
|
if (entry_file == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error : Failed to open entry file - %s\n", strerror(errno));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lineSize = getline(&line, &len, stdin);
|
||||||
|
if (lineSize == -1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fprintf(entry_file, line);
|
||||||
|
|
||||||
|
/* When you finish with the file, close it */
|
||||||
|
fclose(entry_file);
|
||||||
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
lineSize = getline(&line, &len, stdin);
|
|
||||||
if (lineSize == -1)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fprintf(entry_file, line);
|
|
||||||
|
|
||||||
/* When you finish with the file, close it */
|
|
||||||
fclose(entry_file);
|
|
||||||
free(line);
|
|
||||||
}
|
}
|
||||||
rewinddir(FD);
|
rewinddir(FD);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue