Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "private-etc: big profile changes" #5645

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
private-etc: cleanup tool changes
(cherry picked from commit 5d0822c)

Committer note: This only applies the changes from src/.
  • Loading branch information
netblue30 authored and kmk3 committed Feb 7, 2023
commit 2d15f33cd2651c7da8007e187f01c65a36598e55
54 changes: 27 additions & 27 deletions src/tools/cleanup_etc.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,27 @@ static void arr_clean(void) {
arr_x11 = 0;
}

static void arr_print(void) {
printf("private-etc ");
static char *arr_print(void) {
char *last_line = outptr;
outprintf("private-etc ");

if (arr_games) {
printf("@games,");
if (arr_games)
outprintf("@games,");
}
if (arr_tls_ca) {
printf("@tls-ca,");
if (arr_tls_ca)
outprintf("@tls-ca,");
}
if (arr_x11) {
printf("@x11,");
if (arr_x11)
outprintf("@x11,");
}

int i;
for (i = 0; i < arr_cnt; i++) {
printf("%s,", arr[i]);
for (i = 0; i < arr_cnt; i++)
outprintf("%s,", arr[i]);
if (*(outptr - 1) == ' ' || *(outptr - 1) == ',') {
outptr--;
*outptr = '\0';
}
printf("\n");
outprintf("\n");

return last_line;
}

static void process_file(const char *fname) {
Expand All @@ -127,6 +125,7 @@ static void process_file(const char *fname) {

outptr = outbuf;
*outptr = '\0';
arr_clean();

char line[MAX_BUF];
char orig_line[MAX_BUF];
Expand All @@ -135,17 +134,14 @@ static void process_file(const char *fname) {
while (fgets(line, MAX_BUF, fp)) {
cnt++;
if (strncmp(line, "private-etc ", 12) != 0) {
sprintf(outptr, "%s", line);
outptr += strlen(outptr);
outprintf("%s", line);
continue;
}
strcpy(orig_line,line);
char *ptr = strchr(line, '\n');
if (ptr)
*ptr = '\0';

print = 1;
strcpy(orig_line,line);

ptr = line + 12;
while (*ptr == ' ' || *ptr == '\t')
ptr++;
Expand All @@ -154,7 +150,7 @@ static void process_file(const char *fname) {
char *ptr2 = ptr;
while (*ptr2 != '\0') {
if (*ptr2 == ' ' || *ptr2 == '\t') {
fprintf(stderr, "Error: invlid private-etc line %s:%d\n", fname, cnt);
fprintf(stderr, "Error: invalid private-etc line %s:%d\n", fname, cnt);
exit(1);
}
ptr2++;
Expand Down Expand Up @@ -183,25 +179,29 @@ static void process_file(const char *fname) {
ptr = strtok(NULL, ",");
}

printf("\n%s: %s\n%s: ", fname, orig_line, fname);
arr_print();
arr_clean();
char *last_line = arr_print();
if (strcmp(last_line, orig_line) == 0) {
fclose(fp);
return;
}
printf("\n********************\n%s\n\n%s\n%s\n", fname, orig_line, last_line);
print = 1;
}

fclose(fp);

if (print) {
printf("Replace %s file? (Y/N): ", fname);
fgets(line, MAX_BUF, stdin);
if (*line == 'y' || *line == 'Y') {
// printf("Replace? (Y/N): ", fname);
// fgets(line, MAX_BUF, stdin);
// if (*line == 'y' || *line == 'Y') {
fp = fopen(fname, "w");
if (!fp) {
fprintf(stderr, "Error: cannot open profile file\n");
exit(1);
}
fprintf(fp, "%s", outbuf);
fclose(fp);
}
// }
}
}

Expand Down