52
52
#define rewind (fp ) fseek((fp), 0L, SEEK_SET) /* guarantee a return value */
53
53
#endif
54
54
55
- #ifndef HAS_NO_MKSTEMP
56
- #ifdef _MSC_VER
57
- static int FDECL (mkstemp , (char * ));
58
- #endif
59
- #endif
60
-
61
55
#if defined(UNIX ) && !defined(LINT ) && !defined(GCC_WARN )
62
56
static const char SCCS_Id [] UNUSED = "@(#)makedefs.c\t3.6\t2020/03/04" ;
63
57
#endif
@@ -136,8 +130,6 @@ static struct version_info version;
136
130
#define CLOSE_OFF_TABLE_STRING "99" /* for the close table */
137
131
#define FAR_OFF_TABLE_STRING "0xff" /* for the far table */
138
132
139
- #define FLG_TEMPFILE 0x01 /* flag for temp file */
140
-
141
133
#define sign (z ) ((z) < 0 ? -1 : ((z) ? 1 : 0))
142
134
#ifdef VISION_TABLES
143
135
static char xclear [MAX_ROW ][MAX_COL ];
@@ -179,7 +171,7 @@ extern void NDECL(objects_init); /* objects.c */
179
171
static void NDECL (link_sanity_check );
180
172
static char * FDECL (name_file , (const char * , const char * ));
181
173
static void FDECL (delete_file , (const char * template , const char * ));
182
- static FILE * FDECL (getfp , (const char * , const char * , const char * , int ));
174
+ static FILE * FDECL (getfp , (const char * , const char * , const char * ));
183
175
static void FDECL (do_ext_makedefs , (int , char * * ));
184
176
185
177
static void NDECL (make_version );
@@ -190,7 +182,8 @@ static char *FDECL(xcrypt, (const char *));
190
182
static unsigned long FDECL (read_rumors_file ,
191
183
(const char * , int * , long * , unsigned long ));
192
184
static boolean FDECL (get_gitinfo , (char * , char * ));
193
- static void FDECL (do_rnd_access_file , (const char * , const char * ));
185
+ static void FDECL (do_rnd_access_file ,
186
+ (const char * , const char * , const char * ));
194
187
static boolean FDECL (d_filter , (char * ));
195
188
static boolean FDECL (h_filter , (char * ));
196
189
static void NDECL (build_savebones_compat_string );
@@ -374,16 +367,19 @@ char *options;
374
367
* post-3.6.5:
375
368
* File must not be empty to avoid divide by 0
376
369
* in core's rn2(), so provide a default entry.
370
+ * [Second argument is used to construct a temporary file name
371
+ * without worrying about whether the file name macros from
372
+ * global.h have been modified with port-specific punctuation.]
377
373
*/
378
- do_rnd_access_file (EPITAPHFILE ,
374
+ do_rnd_access_file (EPITAPHFILE , "epitaph" ,
379
375
/* default epitaph: parody of the default engraving */
380
376
"No matter where I went, here I am." );
381
- do_rnd_access_file (ENGRAVEFILE ,
377
+ do_rnd_access_file (ENGRAVEFILE , "engrave" ,
382
378
/* default engraving: popularized by "The Adventures of
383
379
Buckaroo Bonzai Across the 8th Dimenstion" but predates
384
380
that 1984 movie; some attribute it to Confucius */
385
381
"No matter where you go, there you are." );
386
- do_rnd_access_file (BOGUSMONFILE ,
382
+ do_rnd_access_file (BOGUSMONFILE , "bogusmon" ,
387
383
/* default bogusmon: iconic monster that isn't in nethack */
388
384
"grue" );
389
385
break ;
@@ -429,39 +425,16 @@ const char *tag;
429
425
}
430
426
431
427
static FILE *
432
- getfp (template , tag , mode , flg )
428
+ getfp (template , tag , mode )
433
429
const char * template ;
434
430
const char * tag ;
435
431
const char * mode ;
436
- #ifndef HAS_NO_MKSTEMP
437
- int flg ;
438
- #else
439
- int flg UNUSED ;
440
- #endif
441
432
{
442
433
char * name = name_file (template , tag );
443
- FILE * rv = (FILE * ) 0 ;
444
- #ifndef HAS_NO_MKSTEMP
445
- boolean istemp = (flg & FLG_TEMPFILE ) != 0 ;
446
- char tmpfbuf [MAXFNAMELEN ];
447
- int tmpfd ;
448
- #endif
449
-
450
- #ifndef HAS_NO_MKSTEMP
451
- if (istemp ) {
452
- (void ) snprintf (tmpfbuf , sizeof tmpfbuf , DATA_TEMPLATE , "mdXXXXXX" );
453
- tmpfd = mkstemp (tmpfbuf );
454
- if (tmpfd >= 0 )
455
- rv = fdopen (tmpfd , WRTMODE ); /* temp file is always read+write */
456
- } else
457
- #endif
458
- rv = fopen (name , mode );
434
+ FILE * rv = fopen (name , mode );
435
+
459
436
if (!rv ) {
460
- Fprintf (stderr , "Can't open '%s'.\n" ,
461
- #ifndef HAS_NO_MKSTEMP
462
- istemp ? tmpfbuf :
463
- #endif
464
- name );
437
+ Fprintf (stderr , "Can't open '%s'.\n" , name );
465
438
exit (EXIT_FAILURE );
466
439
}
467
440
return rv ;
@@ -485,7 +458,7 @@ static int FDECL(grep_check_id, (const char *));
485
458
static void FDECL (grep_show_wstack , (const char * ));
486
459
static char * FDECL (do_grep_control , (char * ));
487
460
static void NDECL (do_grep );
488
- static void FDECL (grep0 , (FILE * , FILE * , int ));
461
+ static void FDECL (grep0 , (FILE * , FILE * ));
489
462
490
463
static int grep_trace = 0 ;
491
464
@@ -836,7 +809,7 @@ char *buf;
836
809
}
837
810
#endif
838
811
839
- static void grep0 (FILE * , FILE * , int );
812
+ static void grep0 (FILE * , FILE * );
840
813
841
814
static void
842
815
do_grep ()
@@ -851,26 +824,14 @@ do_grep()
851
824
exit (EXIT_FAILURE );
852
825
}
853
826
854
- grep0 (inputfp , outputfp , 0 );
827
+ grep0 (inputfp , outputfp );
855
828
}
856
829
857
830
static void
858
- grep0 (inputfp0 , outputfp0 , flg )
831
+ grep0 (inputfp0 , outputfp0 )
859
832
FILE * inputfp0 ;
860
833
FILE * outputfp0 ;
861
- #ifndef HAS_NO_MKSTEMP
862
- int flg ;
863
- #else
864
- int flg UNUSED ;
865
- #endif
866
834
{
867
- #ifndef HAS_NO_MKSTEMP
868
- /* if grep0 is passed FLG_TEMPFILE flag, it will
869
- leave the output file open when it returns.
870
- The caller will have to take care of calling
871
- fclose() when it is done with the file */
872
- boolean istemp = (flg & FLG_TEMPFILE ) != 0 ;
873
- #endif
874
835
char buf [16384 ]; /* looong, just in case */
875
836
876
837
while (!feof (inputfp0 ) && !ferror (inputfp0 )) {
@@ -910,12 +871,7 @@ int flg UNUSED;
910
871
exit (EXIT_FAILURE );
911
872
}
912
873
fclose (inputfp0 );
913
- #ifndef HAS_NO_MKSTEMP
914
- if (istemp )
915
- rewind (outputfp0 );
916
- else
917
- #endif
918
- fclose (outputfp0 );
874
+ fclose (outputfp0 );
919
875
if (grep_sp ) {
920
876
Fprintf (stderr , "%d unterminated conditional level%s\n" , grep_sp ,
921
877
grep_sp == 1 ? "" : "s" );
@@ -1013,12 +969,13 @@ unsigned long old_rumor_offset;
1013
969
}
1014
970
1015
971
static void
1016
- do_rnd_access_file (fname , deflt_content )
1017
- const char * fname ;
972
+ do_rnd_access_file (fname , basefname , deflt_content )
973
+ const char * fname , * basefname ;
1018
974
const char * deflt_content ;
1019
975
{
1020
- char * line , buf [ BUFSZ ];
976
+ char * line , greptmp [ 8 + 1 + 3 + 1 ];
1021
977
978
+ Sprintf (greptmp , "grep-%.3s.tmp" , basefname );
1022
979
Sprintf (filename , DATA_IN_TEMPLATE , fname );
1023
980
Strcat (filename , ".txt" );
1024
981
if (!(ifp = fopen (filename , RDTMODE ))) {
@@ -1045,13 +1002,9 @@ const char *deflt_content;
1045
1002
more likely to be picked than normal but it's nothing to worry about */
1046
1003
(void ) fputs (xcrypt (deflt_content ), ofp );
1047
1004
1048
- tfp = getfp (DATA_TEMPLATE , "grep.tmp" , WRTMODE , FLG_TEMPFILE );
1049
- grep0 (ifp , tfp , FLG_TEMPFILE );
1050
- #ifndef HAS_NO_MKSTEMP
1051
- ifp = tfp ;
1052
- #else
1053
- ifp = getfp (DATA_TEMPLATE , "grep.tmp" , RDTMODE , 0 );
1054
- #endif
1005
+ tfp = getfp (DATA_TEMPLATE , greptmp , WRTMODE );
1006
+ grep0 (ifp , tfp );
1007
+ ifp = getfp (DATA_TEMPLATE , greptmp , RDTMODE );
1055
1008
1056
1009
while ((line = fgetline (ifp )) != 0 ) {
1057
1010
if (line [0 ] != '#' && line [0 ] != '\n' )
@@ -1061,10 +1014,7 @@ const char *deflt_content;
1061
1014
Fclose (ifp );
1062
1015
Fclose (ofp );
1063
1016
1064
- #ifdef HAS_NO_MKSTEMP
1065
- delete_file (DATA_TEMPLATE , "grep.tmp" );
1066
- #endif
1067
-
1017
+ delete_file (DATA_TEMPLATE , greptmp );
1068
1018
return ;
1069
1019
}
1070
1020
@@ -2335,8 +2285,9 @@ do_oracles()
2335
2285
void
2336
2286
do_dungeon ()
2337
2287
{
2338
- char * line ;
2288
+ char * line , greptmp [ 8 + 1 + 3 + 1 ] ;
2339
2289
2290
+ Sprintf (greptmp , "grep-%.3s.tmp" , "dun" );
2340
2291
Sprintf (filename , DATA_IN_TEMPLATE , DGN_I_FILE );
2341
2292
if (!(ifp = fopen (filename , RDTMODE ))) {
2342
2293
perror (filename );
@@ -2353,13 +2304,10 @@ do_dungeon()
2353
2304
}
2354
2305
Fprintf (ofp , "%s" , Dont_Edit_Data );
2355
2306
2356
- tfp = getfp (DATA_TEMPLATE , "grep.tmp" , WRTMODE , FLG_TEMPFILE );
2357
- grep0 (ifp , tfp , FLG_TEMPFILE );
2358
- #ifndef HAS_NO_MKSTEMP
2359
- ifp = tfp ;
2360
- #else
2361
- ifp = getfp (DATA_TEMPLATE , "grep.tmp" , RDTMODE , 0 );
2362
- #endif
2307
+ tfp = getfp (DATA_TEMPLATE , greptmp , WRTMODE );
2308
+ grep0 (ifp , tfp );
2309
+ ifp = getfp (DATA_TEMPLATE , greptmp , RDTMODE );
2310
+
2363
2311
while ((line = fgetline (ifp )) != 0 ) {
2364
2312
SpinCursor (3 );
2365
2313
@@ -2370,13 +2318,10 @@ do_dungeon()
2370
2318
(void ) fputs (line , ofp );
2371
2319
free (line );
2372
2320
}
2373
-
2374
2321
Fclose (ifp );
2375
2322
Fclose (ofp );
2376
2323
2377
- #ifdef HAS_NO_MKSTEMP
2378
- delete_file (DATA_TEMPLATE , "grep.tmp" );
2379
- #endif
2324
+ delete_file (DATA_TEMPLATE , greptmp );
2380
2325
return ;
2381
2326
}
2382
2327
@@ -3009,24 +2954,6 @@ char *str;
3009
2954
return str ;
3010
2955
}
3011
2956
3012
- #ifndef HAS_NO_MKSTEMP
3013
- #ifdef _MSC_VER
3014
- int
3015
- mkstemp (template )
3016
- char * template ;
3017
- {
3018
- int err ;
3019
-
3020
- err = _mktemp_s (template , strlen (template ) + 1 );
3021
- if ( err != 0 )
3022
- return -1 ;
3023
- return _open (template ,
3024
- _O_RDWR | _O_BINARY | _O_TEMPORARY | _O_CREAT ,
3025
- _S_IREAD | _S_IWRITE );
3026
- }
3027
- #endif /* _MSC_VER */
3028
- #endif /* HAS_NO_MKSTEMP */
3029
-
3030
2957
/*
3031
2958
* macro used to control vision algorithms:
3032
2959
* VISION_TABLES => generate tables
0 commit comments