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) {
/*debug: print into file*/
FILE *fdo = fopen("debug-out2.txt", "w");
struct card *t = NULL;
fprintf(fdo, "**************** uncommented deck **************\n\n");
/* always print first line */
fprintf(fdo, "%6d %6d %s\n", deck->linenum_orig, deck->linenum, deck->line);
/* here without out-commented lines */
for (t = deck->nextcard; t; t = t->nextcard) {
if (*(t->line) == '*')
continue;
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
if (fdo) {
struct card *t = NULL;
fprintf(fdo, "**************** uncommented deck **************\n\n");
/* always print first line */
fprintf(fdo, "%6d %6d %s\n", deck->linenum_orig, deck->linenum, deck->line);
/* here without out-commented lines */
for (t = deck->nextcard; t; t = t->nextcard) {
if (*(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");
/* now completely */
for (t = deck; t; t = t->nextcard)
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
fclose(fdo);
else
fprintf(stderr, "Warning: Cannot open file debug-out2.txt for saving debug info\n");
}
for (dd = deck; dd; dd = dd->nextcard) {
/* get csparams and create vectors, being
@ -761,21 +765,25 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile)
if (ft_ngdebug) {
/*debug: print into file*/
FILE *fdo = fopen("debug-out3.txt", "w");
struct card *t = NULL;
fprintf(fdo, "**************** uncommented deck **************\n\n");
/* always print first line */
fprintf(fdo, "%6d %6d %s\n", deck->linenum_orig, deck->linenum, deck->line);
/* here without out-commented lines */
for (t = deck->nextcard; t; t = t->nextcard) {
if (*(t->line) == '*')
continue;
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
if (fdo) {
struct card *t = NULL;
fprintf(fdo, "**************** uncommented deck **************\n\n");
/* always print first line */
fprintf(fdo, "%6d %6d %s\n", deck->linenum_orig, deck->linenum, deck->line);
/* here without out-commented lines */
for (t = deck->nextcard; t; t = t->nextcard) {
if (*(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");
/* now completely */
for (t = deck; t; t = t->nextcard)
fprintf(fdo, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
fclose(fdo);
else
fprintf(stderr, "Warning: Cannot open file debug-out3.txt for saving debug info\n");
}
/* 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) {
/*debug: print into file*/
FILE *fd = fopen("debug-out.txt", "w");
struct card *t;
fprintf(fd, "**************** uncommented deck **************\n\n");
/* always print first line */
fprintf(fd, "%6d %6d %s\n", cc->linenum_orig, cc->linenum, cc->line);
/* here without out-commented lines */
for (t = cc->nextcard; t; t = t->nextcard) {
if (*(t->line) == '*')
continue;
fprintf(fd, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
}
fprintf(fd, "\n****************** complete deck ***************\n\n");
/* now completely */
for (t = cc; t; t = t->nextcard)
fprintf(fd, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
fclose(fd);
if (fd) {
/*debug: print into file*/
struct card *t;
fprintf(fd, "**************** uncommented deck **************\n\n");
/* always print first line */
fprintf(fd, "%6d %6d %s\n", cc->linenum_orig, cc->linenum, cc->line);
/* here without out-commented lines */
for (t = cc->nextcard; t; t = t->nextcard) {
if (*(t->line) == '*')
continue;
fprintf(fd, "%6d %6d %s\n", t->linenum_orig, t->linenum, t->line);
}
fprintf(fd, "\n****************** complete deck ***************\n\n");
/* now completely */
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",
(int) max_line_length, no_braces, dynmaxline);
fprintf(stdout, "max line length %d, max subst. per line %d, number of lines %d\n",
(int)max_line_length, no_braces, dynmaxline);
}
else
fprintf(stderr, "Warning: Cannot open file debug-out.txt for saving debug info\n");
}
}