-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathcreate_script_help.c
More file actions
executable file
·111 lines (99 loc) · 2.5 KB
/
create_script_help.c
File metadata and controls
executable file
·111 lines (99 loc) · 2.5 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
// Copyright (C) 2015-2022 Scott Dwyer.
// You may use/distribute/modify this freely, under the terms of
// the GNU General Public License version 2 or later version.
// This software is distributed WITHOUT ANY WARRANTY.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdbool.h>
#include <unistd.h>
#include <dirent.h>
#include "util.h"
char name[256][256];
int main(void)
{
struct dirent **namelist;
int i,n;
int count = 0;
int index = 0;
char command[512];
int ret=0;
n = scandir("hddscripts", &namelist, 0, alphasort);
if (n < 0)
{
perror("scandir");
return (1);
}
else {
for (i = 0; i < n; i++)
{
if (namelist[i]->d_name[0] != '.')
{
//printf("%s\n", namelist[i]->d_name);
strcpy(name[count],namelist[i]->d_name);
count++;
}
free(namelist[i]);
}
}
free(namelist);
strcpy (command, "cat hddsupertool-p1.texi > hddsupertool.texi");
ret=system(command);
if(ret)
{
ERROR("Cat failed, error-code: %d",ret);
}
char *newdirectory = "hddscripts";
ret=chdir (newdirectory);
if(ret)
{
ERROR("chdir('%s') failed, error-code: %d", newdirectory, ret);
}
char *texifile = "../hddsupertool.texi";
FILE *texi_file = fopen(texifile, "a");
if (texi_file == NULL)
{
ERROR("Cannot open %s for writing (%s)", texifile, strerror(errno));
exit (1);
}
while( count > 0 )
{
//fprintf(stdout, "\n\n%s\n",name[index]);
//fprintf(stdout, "@example\n");
fprintf(texi_file, "\n\n%s\n",name[index]);
fprintf(texi_file, "@example\n");
//TODO: change to snprintf()
strcpy (command, "../hddsuperclone --tool -Q -t /dev/zero -f ");
strcat(command, name[index]);
strcat(command, " help=1 printhelp=1");
INFO("command: %s", command);
FILE *fp;
char path[1035];
/* Open the command for reading. */
fp = popen(command, "r");
if (fp == NULL) {
ERROR("Failed to run command '%s'", command);
exit(1);
}
/* Read the output a line at a time - output it. */
while (fgets(path, sizeof(path)-1, fp) != NULL) {
//fprintf(stdout, "%s", path);
fprintf(texi_file, "%s", path);
}
/* close */
pclose(fp);
//fprintf(stdout, "@end example\n");
fprintf(texi_file, "@end example\n");
index++;
count--;
}
fclose (texi_file);
ret=chdir ("..");
if(ret)
{
ERROR("chdir('..') failed, error-code: %d", ret);
}
strcpy (command, "cat hddsupertool-p2.texi >> hddsupertool.texi");
return(system (command));
}