safeguard opening of file for debug output:

may be not allowed if caller is not started
in admin mode.
This commit is contained in:
Holger Vogt 2018-01-28 15:07:42 +01:00
parent 57156e16f6
commit a191697bd6
2 changed files with 58 additions and 46 deletions

View File

@ -619,21 +619,25 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile)
if (ft_ngdebug) { if (ft_ngdebug) {
/*debug: print into file*/ /*debug: print into file*/
FILE *fdo = fopen("debug-out2.txt", "w"); FILE *fdo = fopen("debug-out2.txt", "w");
struct card *t = NULL; if (fdo) {
fprintf(fdo, "**************** uncommented deck **************\n\n"); struct card *t = NULL;
/* always print first line */ fprintf(fdo, "**************** uncommented deck **************\n\n");
fprintf(fdo, "%6d %6d %s\n", deck->linenum_orig, deck->linenum, deck->line); /* always print first line */
/* here without out-commented lines */ fprintf(fdo, "%6d %6d %s\n", deck->linenum_orig, deck->linenum, deck->line);
for (t = deck->nextcard; t; t = t->nextcard) { /* here without out-commented lines */
if (*(t->line) == '*') for (t = deck->nextcard; t; t = t->nextcard) {
continue; if (*(t->line) == '*')
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line); continue;
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
}
fprintf(fdo, "\n****************** complete deck ***************\n\n");
/* now completely */
for (t = deck; t; t = t->nextcard)
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
fclose(fdo);
} }
fprintf(fdo, "\n****************** complete deck ***************\n\n"); else
/* now completely */ fprintf(stderr, "Warning: Cannot open file debug-out2.txt for saving debug info\n");
for (t = deck; t; t = t->nextcard)
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
fclose(fdo);
} }
for (dd = deck; dd; dd = dd->nextcard) { for (dd = deck; dd; dd = dd->nextcard) {
/* get csparams and create vectors, being /* get csparams and create vectors, being
@ -761,21 +765,25 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile)
if (ft_ngdebug) { if (ft_ngdebug) {
/*debug: print into file*/ /*debug: print into file*/
FILE *fdo = fopen("debug-out3.txt", "w"); FILE *fdo = fopen("debug-out3.txt", "w");
struct card *t = NULL; if (fdo) {
fprintf(fdo, "**************** uncommented deck **************\n\n"); struct card *t = NULL;
/* always print first line */ fprintf(fdo, "**************** uncommented deck **************\n\n");
fprintf(fdo, "%6d %6d %s\n", deck->linenum_orig, deck->linenum, deck->line); /* always print first line */
/* here without out-commented lines */ fprintf(fdo, "%6d %6d %s\n", deck->linenum_orig, deck->linenum, deck->line);
for (t = deck->nextcard; t; t = t->nextcard) { /* here without out-commented lines */
if (*(t->line) == '*') for (t = deck->nextcard; t; t = t->nextcard) {
continue; if (*(t->line) == '*')
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line); continue;
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
}
fprintf(fdo, "\n****************** complete deck ***************\n\n");
/* now completely */
for (t = deck; t; t = t->nextcard)
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
fclose(fdo);
} }
fprintf(fdo, "\n****************** complete deck ***************\n\n"); else
/* now completely */ fprintf(stderr, "Warning: Cannot open file debug-out3.txt for saving debug info\n");
for (t = deck; t; t = t->nextcard)
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
fclose(fdo);
} }
/* Now the circuit is defined, so generate the parse trees */ /* Now the circuit is defined, so generate the parse trees */

View File

@ -620,26 +620,30 @@ inp_readall(FILE *fp, char *dir_name, bool comfile, bool intfile, bool *expr_w_t
} }
if (ft_ngdebug) { if (ft_ngdebug) {
/*debug: print into file*/
FILE *fd = fopen("debug-out.txt", "w"); FILE *fd = fopen("debug-out.txt", "w");
struct card *t; if (fd) {
fprintf(fd, "**************** uncommented deck **************\n\n"); /*debug: print into file*/
/* always print first line */ struct card *t;
fprintf(fd, "%6d %6d %s\n", cc->linenum_orig, cc->linenum, cc->line); fprintf(fd, "**************** uncommented deck **************\n\n");
/* here without out-commented lines */ /* always print first line */
for (t = cc->nextcard; t; t = t->nextcard) { fprintf(fd, "%6d %6d %s\n", cc->linenum_orig, cc->linenum, cc->line);
if (*(t->line) == '*') /* here without out-commented lines */
continue; for (t = cc->nextcard; t; t = t->nextcard) {
fprintf(fd, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line); if (*(t->line) == '*')
} continue;
fprintf(fd, "\n****************** complete deck ***************\n\n"); fprintf(fd, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
/* now completely */ }
for (t = cc; t; t = t->nextcard) fprintf(fd, "\n****************** complete deck ***************\n\n");
fprintf(fd, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line); /* now completely */
fclose(fd); for (t = cc; t; t = t->nextcard)
fprintf(fd, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
fclose(fd);
fprintf(stdout, "max line length %d, max subst. per line %d, number of lines %d\n", fprintf(stdout, "max line length %d, max subst. per line %d, number of lines %d\n",
(int) max_line_length, no_braces, dynmaxline); (int)max_line_length, no_braces, dynmaxline);
}
else
fprintf(stderr, "Warning: Cannot open file debug-out.txt for saving debug info\n");
} }
} }