comparison src/fileio.c @ 21304:1c2b68b607c8

(barf_or_query_if_file_exists): New arg QUICK. All calls changed.
author Richard M. Stallman <rms@gnu.org>
date Sat, 28 Mar 1998 08:25:53 +0000
parents 50929073a0ba
children 4f8b7860819e
comparison
equal deleted inserted replaced
21303:346595905ae4 21304:1c2b68b607c8
2039 QUERYSTRING is a name for the action that is being considered 2039 QUERYSTRING is a name for the action that is being considered
2040 to alter the file. 2040 to alter the file.
2041 2041
2042 *STATPTR is used to store the stat information if the file exists. 2042 *STATPTR is used to store the stat information if the file exists.
2043 If the file does not exist, STATPTR->st_mode is set to 0. 2043 If the file does not exist, STATPTR->st_mode is set to 0.
2044 If STATPTR is null, we don't store into it. */ 2044 If STATPTR is null, we don't store into it.
2045
2046 If QUICK is nonzero, we ask for y or n, not yes or no. */
2045 2047
2046 void 2048 void
2047 barf_or_query_if_file_exists (absname, querystring, interactive, statptr) 2049 barf_or_query_if_file_exists (absname, querystring, interactive, statptr, quick)
2048 Lisp_Object absname; 2050 Lisp_Object absname;
2049 unsigned char *querystring; 2051 unsigned char *querystring;
2050 int interactive; 2052 int interactive;
2051 struct stat *statptr; 2053 struct stat *statptr;
2054 int quick;
2052 { 2055 {
2053 register Lisp_Object tem; 2056 register Lisp_Object tem;
2054 struct stat statbuf; 2057 struct stat statbuf;
2055 struct gcpro gcpro1; 2058 struct gcpro gcpro1;
2056 2059
2061 if (! interactive) 2064 if (! interactive)
2062 Fsignal (Qfile_already_exists, 2065 Fsignal (Qfile_already_exists,
2063 Fcons (build_string ("File already exists"), 2066 Fcons (build_string ("File already exists"),
2064 Fcons (absname, Qnil))); 2067 Fcons (absname, Qnil)));
2065 GCPRO1 (absname); 2068 GCPRO1 (absname);
2066 tem = do_yes_or_no_p (format1 ("File %s already exists; %s anyway? ", 2069 tem = format1 ("File %s already exists; %s anyway? ",
2067 XSTRING (absname)->data, querystring)); 2070 XSTRING (absname)->data, querystring);
2071 if (quick)
2072 tem = Fy_or_n_p (tem);
2073 else
2074 tem = do_yes_or_no_p (tem);
2068 UNGCPRO; 2075 UNGCPRO;
2069 if (NILP (tem)) 2076 if (NILP (tem))
2070 Fsignal (Qfile_already_exists, 2077 Fsignal (Qfile_already_exists,
2071 Fcons (build_string ("File already exists"), 2078 Fcons (build_string ("File already exists"),
2072 Fcons (absname, Qnil))); 2079 Fcons (absname, Qnil)));
2125 encoded_newname = ENCODE_FILE (newname); 2132 encoded_newname = ENCODE_FILE (newname);
2126 2133
2127 if (NILP (ok_if_already_exists) 2134 if (NILP (ok_if_already_exists)
2128 || INTEGERP (ok_if_already_exists)) 2135 || INTEGERP (ok_if_already_exists))
2129 barf_or_query_if_file_exists (encoded_newname, "copy to it", 2136 barf_or_query_if_file_exists (encoded_newname, "copy to it",
2130 INTEGERP (ok_if_already_exists), &out_st); 2137 INTEGERP (ok_if_already_exists), &out_st, 0);
2131 else if (stat (XSTRING (encoded_newname)->data, &out_st) < 0) 2138 else if (stat (XSTRING (encoded_newname)->data, &out_st) < 0)
2132 out_st.st_mode = 0; 2139 out_st.st_mode = 0;
2133 2140
2134 ifd = open (XSTRING (encoded_file)->data, O_RDONLY); 2141 ifd = open (XSTRING (encoded_file)->data, O_RDONLY);
2135 if (ifd < 0) 2142 if (ifd < 0)
2363 encoded_newname = ENCODE_FILE (newname); 2370 encoded_newname = ENCODE_FILE (newname);
2364 2371
2365 if (NILP (ok_if_already_exists) 2372 if (NILP (ok_if_already_exists)
2366 || INTEGERP (ok_if_already_exists)) 2373 || INTEGERP (ok_if_already_exists))
2367 barf_or_query_if_file_exists (encoded_newname, "rename to it", 2374 barf_or_query_if_file_exists (encoded_newname, "rename to it",
2368 INTEGERP (ok_if_already_exists), 0); 2375 INTEGERP (ok_if_already_exists), 0, 0);
2369 #ifndef BSD4_1 2376 #ifndef BSD4_1
2370 if (0 > rename (XSTRING (encoded_file)->data, XSTRING (encoded_newname)->data)) 2377 if (0 > rename (XSTRING (encoded_file)->data, XSTRING (encoded_newname)->data))
2371 #else 2378 #else
2372 if (0 > link (XSTRING (encoded_file)->data, XSTRING (encoded_newname)->data) 2379 if (0 > link (XSTRING (encoded_file)->data, XSTRING (encoded_newname)->data)
2373 || 0 > unlink (XSTRING (encoded_file)->data)) 2380 || 0 > unlink (XSTRING (encoded_file)->data))
2438 encoded_newname = ENCODE_FILE (newname); 2445 encoded_newname = ENCODE_FILE (newname);
2439 2446
2440 if (NILP (ok_if_already_exists) 2447 if (NILP (ok_if_already_exists)
2441 || INTEGERP (ok_if_already_exists)) 2448 || INTEGERP (ok_if_already_exists))
2442 barf_or_query_if_file_exists (encoded_newname, "make it a new name", 2449 barf_or_query_if_file_exists (encoded_newname, "make it a new name",
2443 INTEGERP (ok_if_already_exists), 0); 2450 INTEGERP (ok_if_already_exists), 0, 0);
2444 2451
2445 unlink (XSTRING (newname)->data); 2452 unlink (XSTRING (newname)->data);
2446 if (0 > link (XSTRING (encoded_file)->data, XSTRING (encoded_newname)->data)) 2453 if (0 > link (XSTRING (encoded_file)->data, XSTRING (encoded_newname)->data))
2447 { 2454 {
2448 #ifdef NO_ARG_ARRAY 2455 #ifdef NO_ARG_ARRAY
2505 encoded_linkname = ENCODE_FILE (linkname); 2512 encoded_linkname = ENCODE_FILE (linkname);
2506 2513
2507 if (NILP (ok_if_already_exists) 2514 if (NILP (ok_if_already_exists)
2508 || INTEGERP (ok_if_already_exists)) 2515 || INTEGERP (ok_if_already_exists))
2509 barf_or_query_if_file_exists (encoded_linkname, "make it a link", 2516 barf_or_query_if_file_exists (encoded_linkname, "make it a link",
2510 INTEGERP (ok_if_already_exists), 0); 2517 INTEGERP (ok_if_already_exists), 0, 0);
2511 if (0 > symlink (XSTRING (encoded_filename)->data, 2518 if (0 > symlink (XSTRING (encoded_filename)->data,
2512 XSTRING (encoded_linkname)->data)) 2519 XSTRING (encoded_linkname)->data))
2513 { 2520 {
2514 /* If we didn't complain already, silently delete existing file. */ 2521 /* If we didn't complain already, silently delete existing file. */
2515 if (errno == EEXIST) 2522 if (errno == EEXIST)
4036 Vlast_coding_system_used = coding.symbol; 4043 Vlast_coding_system_used = coding.symbol;
4037 4044
4038 filename = Fexpand_file_name (filename, Qnil); 4045 filename = Fexpand_file_name (filename, Qnil);
4039 4046
4040 if (! NILP (confirm)) 4047 if (! NILP (confirm))
4041 barf_or_query_if_file_exists (filename, "overwrite", 1, 0); 4048 barf_or_query_if_file_exists (filename, "overwrite", 1, 0, 1);
4042 4049
4043 if (STRINGP (visit)) 4050 if (STRINGP (visit))
4044 visit_file = Fexpand_file_name (visit, Qnil); 4051 visit_file = Fexpand_file_name (visit, Qnil);
4045 else 4052 else
4046 visit_file = filename; 4053 visit_file = filename;