Commit 81d733c566ccef3c6fbb92003719eeb859018163

Authored by Alain Prouté
1 parent 918956f3

fixed the bug about stat() in lexer.l

anubis_dev/compiler/src/compil.h
... ... @@ -128,7 +128,7 @@ extern char * strdupz(const char *);
128 128 extern char * strduppz(const char *, const char *);
129 129 extern char * strdupppz(const char *, const char *, const char *);
130 130 extern FILE * fopenz(const char *name, const char *mode);
131   -extern FILE * fopensrc(const char *name);
  131 +extern FILE * fopensrc(const char *name, int n);
132 132 void mkdirz(const char *dirname);
133 133 extern int lineno;
134 134 extern int colno;
... ...
anubis_dev/compiler/src/index.c
... ... @@ -481,7 +481,7 @@ void make_index_for_file(char *fname)
481 481 lineno = 1;
482 482 colno = 1;
483 483 current_file_abs_path = fname;
484   - yyin = fopensrc(fname);
  484 + yyin = fopensrc(fname,4);
485 485 add_to_already_included(fname);
486 486 yyrestart(yyin);
487 487 begin_INITIAL();
... ...
anubis_dev/compiler/src/lexer.l
... ... @@ -247,7 +247,7 @@ extern void NormalizeFileName(char *pathName);
247 247  
248 248  
249 249 /* open an Anubis source file. */
250   -FILE *fopensrc(const char *name)
  250 +FILE *fopensrc(const char *name, int n)
251 251 /* The given name may be either absolute or relative. It
252 252 must be immediately converted into an absolute path,
253 253 because the compiler uses ONLY absolute file paths
... ... @@ -264,7 +264,7 @@ FILE *fopensrc(const char *name)
264 264 FILE *result;
265 265 struct stat st;
266 266  
267   - //printf("\nExecuting fopensrc(%s)\n",name);
  267 + //printf("\nExecuting fopensrc(%s,%d)\n",name,n);
268 268  
269 269 /* compute absolute path of file */
270 270 if (is_absolute_path(name))
... ... @@ -286,10 +286,6 @@ FILE *fopensrc(const char *name)
286 286 normalize_filepath(linecol(),fopensrc_abs_path); /* eliminates /xxx/../ (see expr.cpp) */
287 287 //printf("fopensrc: after filepath normalization: %s\n",fopensrc_abs_path);
288 288  
289   - /* check that the file is a regular file */
290   - //if (stat(fopensrc_abs_path,&st) != 0) { printf("Cannot stat\n"); goto not_found; } /* file not found */
291   - //if (!(S_ISREG(st.st_mode))) { printf("Not a regular file\n"); goto not_found; } /* file is not a regular file */
292   -
293 289 /* open the file */
294 290 result = fopen(fopensrc_abs_path,"rt");
295 291  
... ... @@ -297,6 +293,13 @@ FILE *fopensrc(const char *name)
297 293  
298 294 if (result != NULL)
299 295 {
  296 + /* check that the file is a regular file */
  297 + if (fstat(fileno(result),&st) != 0) { // printf("Cannot stat %s\n",fopensrc_abs_path);
  298 + fclose(result);
  299 + goto not_found; } /* file not found */
  300 + if (!(S_ISREG(st.st_mode))) { // printf("Not a regular file\n");
  301 + fclose(result);
  302 + goto not_found; } /* file is not a regular file */
300 303 /* the file has been successfully opened */
301 304 fopensrc_cur_dir = strdupz(path_prefix(fopensrc_abs_path));
302 305 assert(is_absolute_path(fopensrc_cur_dir));
... ... @@ -315,7 +318,7 @@ FILE *fopensrc(const char *name)
315 318  
316 319 includePathsCheckFile(name); /* makes a side effect on fopensrc_abs_path */
317 320  
318   - //printf("fopensrc: definitive file path: %s\n",fopensrc_abs_path);
  321 + // printf("fopensrc: definitive file path: %s\n",fopensrc_abs_path);
319 322  
320 323 /* (2) try to open the file whose path has been found by includePathsCheckFile */
321 324  
... ... @@ -327,8 +330,15 @@ FILE *fopensrc(const char *name)
327 330 result = fopen(fopensrc_abs_path,"rt");
328 331 if (result != NULL)
329 332 {
330   - fopensrc_cur_dir = strdupz(path_prefix(fopensrc_abs_path));
331   - return result;
  333 + /* check that the file is a regular file */
  334 + if (fstat(fileno(result),&st) != 0) { // printf("Cannot stat %s\n",fopensrc_abs_path);
  335 + fclose(result);
  336 + goto not_found; } /* file not found */
  337 + if (!(S_ISREG(st.st_mode))) { // printf("Not a regular file\n");
  338 + fclose(result);
  339 + goto not_found; } /* file is not a regular file */
  340 + fopensrc_cur_dir = strdupz(path_prefix(fopensrc_abs_path));
  341 + return result;
332 342 }
333 343 }
334 344  
... ... @@ -446,7 +456,7 @@ int is_already_included(char *name)
446 456 U32 i;
447 457 FILE *fp;
448 458 //NormalizeFileName(name);
449   - fp = fopensrc(name);
  459 + fp = fopensrc(name,2);
450 460  
451 461 for (i = 0; i < next_already_included; i++)
452 462 {
... ... @@ -1114,7 +1124,7 @@ W [\ \t\r\n]
1114 1124 max_include));
1115 1125 anb_exit(1);
1116 1126 }
1117   - yyin = fopensrc(fname);
  1127 + yyin = fopensrc(fname,3);
1118 1128 add_to_already_included(fopensrc_abs_path);
1119 1129  
1120 1130 //printf("lexer line %d: current_file_id = %d, next_already_included = %d\n",__LINE__,current_file_id,next_already_included); fflush(stdout);
... ...
anubis_dev/compiler/src/main.cpp
... ... @@ -855,7 +855,7 @@ int main(int argc, const char **argv)
855 855 unput_token = 0;
856 856 snprintf(buf,buf_size,"predef_npd.aux");
857 857 predef_npd_aux = fopenz(buf,"wt");
858   - yyin = fopensrc(strdup("predef.anubis")); // must be executed from compiler/src
  858 + yyin = fopensrc(strdup("predef.anubis"),6); // must be executed from compiler/src
859 859 current_file_abs_path = (char *)"/predefined.anubis";
860 860 current_file_id = 0;
861 861 abs_file_paths_stack[0] = already_included[0] = (char *)"/predefined.anubis";
... ... @@ -915,7 +915,7 @@ int main(int argc, const char **argv)
915 915 current_file_abs_path);
916 916 }
917 917 //initialize_visibility();
918   - yyin = fopensrc(main_file_original_path);
  918 + yyin = fopensrc(main_file_original_path,5);
919 919 unput_token = 0;
920 920 initializing = 0;
921 921 yyrestart(yyin);
... ...
anubis_dev/library/network/remote_files_manager_common.anubis
... ... @@ -182,17 +182,24 @@ public define RFMshutdownAnswer
182 182 be used (even if not very useful) to transfer (hence copy) a file from the local machine to itself.
183 183  
184 184 Possible answers to a transfer command:
  185 +
  186 +public type RFMfileAnswer:
  187 + cannot_read_file (String filename),
  188 + cannot_create_file (String filename),
  189 + cannot_write_file (String filename),
  190 + cannot_set_file_mode (String filename),
  191 + cannot_set_file_times (String filename),
  192 + ok (String filename).
185 193  
186 194 public type RFMtransferAnswer:
187 195 source_server_not_responding,
188 196 target_server_not_responding,
189 197 invalid_source_password,
190 198 invalid_target_password,
191   - invalid_source_directory, // the directory is not in the list of allowed directories
192   - invalid_target_directory, // the directory is not in the list of allowed directories
193   - cannot_create_file,
194   - cannot_write_file,
195   - ok. // everything ok
  199 + invalid_source_directory, // the directory is not in the list of allowed directories
  200 + invalid_target_directory, // the directory is not in the list of allowed directories
  201 + files (List(RFMfileAnswer) result). // result of transfering files
  202 +
196 203  
197 204 A function for translating such an answer into English:
198 205  
... ... @@ -214,7 +221,7 @@ public define RFMtransferAnswer
214 221 For example:
215 222  
216 223 print(to_English(transfer(source(local, ".", "my_file.pdf"),
217   - target(my_server1, "archives"))))
  224 + target(my_server1, "archives", my_mode))))
218 225  
219 226 Recall: directories on a remote machine have names which are setup when configuring
220 227 the server and mapped to the actual directory path.
... ... @@ -289,6 +296,7 @@ public define RFMdeleteAnswer
289 296 read tools/basis.anubis
290 297 read tools/safe_save_retrieve.anubis
291 298 read system/string.anubis
  299 +read system/files.anubis
292 300 read tools/exceptions.anubis
293 301  
294 302  
... ... @@ -314,23 +322,37 @@ public type RFMPlace:
314 322 type RFMCommand:
315 323 shutdown,
316 324  
  325 + // check if a remote directory is valid
  326 + check_dir (String directory),
  327 +
  328 + // initiate a file transfer
317 329 check_put (String directory, // where to put the file
318   - String filename),
  330 + String filename,
  331 + Int size,
  332 + FileMode mode),
319 333  
320   - put (String directory, // where to put the file
321   - String filename, // name of the file
322   - ByteArray content, // of the file
  334 + // send a chunk of a file
  335 + put_chunk (String directory, // directory and
  336 + String filename, // file this chunk belongs to
  337 + Int rank, // chunk rank
  338 + ByteArray content, // content of chunk
323 339 ByteArray hash), // hash of content
324 340  
  341 + // signal that tranfer is finished
  342 + put_end (String directory,
  343 + String filename,
  344 + Int number_of_chunks),
  345 +
  346 + // get a file
325 347 get (String directory,
326 348 String filename),
327 349  
  350 + // delete a file
328 351 delete (String directory,
329 352 String filename).
330 353  
331 354  
332 355  
333   -
334 356 *** [2] Answers.
335 357  
336 358 type RFMAnswer:
... ... @@ -438,6 +460,25 @@ public define RFMshutdownAnswer
438 460  
439 461 *** [4.2] transfer.
440 462  
  463 +
  464 +type
  465 +
  466 +define List(String)
  467 + files_in // get only names of regular files and links
  468 + (
  469 + String directory,
  470 + String mask
  471 + ) =
  472 + map_select((FileDescription d) |-> if d is
  473 + {
  474 + no_info(_) then failure,
  475 + file(n,_,_,_) then success(n),
  476 + link(n,_,_,_) then todo("Extend transfer to files seen through a link"); failure,
  477 + directory(_,_,_) then failure
  478 + },
  479 + directory_full_list(directory,mask,mask,"")).
  480 +
  481 +
441 482 define RFMtransferAnswer
442 483 local_to_local
443 484 (
... ... @@ -446,11 +487,34 @@ define RFMtransferAnswer
446 487 String filemask,
447 488 // destination
448 489 String target_dir
449   - ) =
450   - todo("local_to_local").
  490 + ) =
  491 + files(map((String name) |-> if copy_file(source_dir/name,target_dir) is
  492 + {
  493 + cant_read_file then cannot_read_file(name),
  494 + cant_create_file then cannot_create_file(name),
  495 + copy_error then cannot_write_file(name),
  496 + copy_file_mode_error then cannot_set_file_mode(name),
  497 + copy_file_times_error then cannot_set_file_times(name),
  498 + copy_ok(written) then ok(name)
  499 + },
  500 + files_in(source_dir,filemask))).
  501 +
451 502  
452 503  
453 504 define RFMtransferAnswer
  505 + local_to_remote_1
  506 + (
  507 + // source
  508 + String source_dir,
  509 + String filename,
  510 + Int size,
  511 + FileMode mode,
  512 + // destination
  513 + SSL_Connection target_conn,
  514 + String target_dir
  515 + ).
  516 +
  517 +define RFMtransferAnswer
454 518 local_to_remote
455 519 (
456 520 // source
... ... @@ -460,7 +524,15 @@ define RFMtransferAnswer
460 524 SSL_Connection target_conn,
461 525 String target_dir
462 526 ) =
463   - todo("local_to_remote").
  527 + if send_datum(target_conn,check_dir(target_dir)) is
  528 + {
  529 + failure then invalid_target_directory,
  530 + success(_) then
  531 + map((String name) |-> local_to_remote
  532 + files_in(source_dir,filemask))
  533 + }.
  534 +
  535 +
464 536  
465 537 define RFMtransferAnswer
466 538 remote_to_local
... ... @@ -511,7 +583,7 @@ define RFMtransferAnswer
511 583 todo("remote_to_remote_get").
512 584  
513 585  
514   -public define RFMtransferAnswer
  586 + public define RFMtransferAnswer
515 587 transfer
516 588 (
517 589 RFMSource src,
... ... @@ -591,6 +663,66 @@ public define RFMtransferAnswer
591 663 }.
592 664  
593 665  
594   -
  666 + *** [5] to_English.
  667 +
  668 +public define String
  669 + to_English
  670 + (
  671 + RFMshutdownAnswer a
  672 + ) =
  673 + if a is
  674 + {
  675 + no_local_server then "There is no local server.",
  676 + server_not_responding then "The server is not responding.",
  677 + cannot_send then "Cannot send datd to the server.",
  678 + cannot_receive then "Cannot receive data from the server.",
  679 + invalid_server_answer then "Invalid server answer.",
  680 + exiting then "The server is shutting down."
  681 + }.
  682 +
  683 +public define String
  684 + to_English
  685 + (
  686 + RFMtransferAnswer a
  687 + ) =
  688 + if a is
  689 + {
  690 + source_server_not_responding then "The source server is not responding.",
  691 + target_server_not_responding then "The target server is not responding.",
  692 + invalid_source_password then "Invalid password for source server.",
  693 + invalid_target_password then "Invalid password for target server.",
  694 + invalid_source_directory then "Invalid directory on source server.",
  695 + invalid_target_directory then "Invalid directory on target server.",
  696 + files(l) then
  697 + concat(map((RFMfileAnswer fa) |-> if fa is
  698 + {
  699 + cannot_read_file(filename) then "cannot read '"+filename+"'",
  700 + cannot_create_file(filename) then "cannot create '"+filename+"'",
  701 + cannot_write_file(filename) then "cannot write'"+filename+"'",
  702 + cannot_set_file_mode(filename) then "cannot set mode for '"+filename+"'",
  703 + cannot_set_file_times(filename) then "cannot set times for '"+filename+"'",
  704 + ok(filename) then "file '"+filename+"' copied",
  705 + },l),
  706 + "\n")
  707 + }.
  708 +
  709 +public define String
  710 + to_English
  711 + (
  712 + RFMdeleteAnswer a
  713 + ) =
  714 + if a is
  715 + {
  716 + server_not_responding then "The server is not responding.",
  717 + invalid_password then "Invalid password.",
  718 + invalid_directory then "Invalid directory.",
  719 + file_not_found then "File not found.",
  720 + cannot_delete_file then "Cannot delete file.",
  721 + ok then "File deleted."
  722 + }.
  723 +
  724 +
  725 +
  726 +
595 727  
596 728  
... ...
anubis_dev/library/syntactic_analysis/anubis_output.anubis
... ... @@ -1283,7 +1283,7 @@ define One
1283 1283 print_acceptable_tokens
1284 1284 (
1285 1285 Stream s,
1286   - Word32 state_id,
  1286 + Word32 state_id,
1287 1287 String parser_name,
1288 1288 List(BehaviorEntry) behaviors,
1289 1289 List(String) non_terminals
... ... @@ -1510,7 +1510,7 @@ define One
1510 1510 print_state_function_beginning
1511 1511 (
1512 1512 Stream s,
1513   - Word32 state_id,
  1513 + Word32 state_id,
1514 1514 String parser_name,
1515 1515 List(String) stack,
1516 1516 List(TypeEntry) type_table,
... ...
anubis_dev/library/syntactic_analysis/make_automaton.anubis
... ... @@ -1260,7 +1260,7 @@ define One
1260 1260 ) =
1261 1261 with id1 = state_id(source), id2 = state_id(target),
1262 1262 /*
1263   - (if (verbose /*& id1 /= id2*/)
  1263 + (if (verbose)
1264 1264 then print(stderr,id1+"->"+id2+" ")
1265 1265 else unique);
1266 1266 */
... ...
anubis_dev/library/tools/basis.anubis
... ... @@ -13,8 +13,7 @@
13 13 This file was originally containing a very long list of basic things. Finding
14 14 what we needed in it became problematic. Thanks to the new initial keyword
15 15 'transmit', it was possible since version 1.13.5 of Anubis to split it into
16   - several parts without the need to change even a comma in the files using
17   - it (at least I hope it works like this; AP).
  16 + several parts without the need to change even a comma in the files using it.
18 17  
19 18 Below is a brief description of each 'chapter' of basis.anubis. The details
20 19 for a given chapter are to be found in the corresponding (transmited) Anubis
... ... @@ -22,16 +21,15 @@
22 21  
23 22 *** (1) Booleans.
24 23  
  24 +transmit bool.anubis
  25 +
25 26 Basic utilities for booleans (type Bool), such as conjunction, disjunction, negation,...
26 27 The same for boolean predicates (type $T -> Bool).
27 28 Also contains multiple 'and' (mapand) and 'or' (mapor),
28 29 and non equality (/= and !=).
29 30  
30   -transmit bool.anubis
31 31  
32   - *** (2) Integers.
33   -
34   -
  32 + *** (2) Integers and rational numbers.
35 33  
36 34 transmit int.anubis
37 35 transmit rationals.anubis
... ...