#] #] ********************* #] loaddefs link d_Qndfs 'port C to Nial.NDF' - simple work to help convert a C++ program source to Nial Operation: C_to_Nial File The operation uses the library operations "stripblanks" and "find_string". The operation is not foolproof. Definitions such as "f is g" would not be found; nor would ones in which the items sought are on different lines. Assumes that a filename includes path if not in nialroot, and that only one `. occurs!! f_portCtoQNial := 'port C to Nial.NDF' ; loaddefs_start f_portCtoQNial ; #**************************** # List of operators, generated with : # $ cat "$d_Qndfs""port C to Nial.NDF" | grep "^#]" | sed 's/^#\]/ /' # ********************* loaddefs link d_Qndfs 'port C to Nial.NDF' - simple work to help convert a C++ program source to Nial C_to_Nial IS OP File - METHOD_AN1 IS 1 ; - METHOD_AN1_CJ IS 2 ; - METHOD_AN2 IS 3 ; - METHOD_AN2_CJ IS 4 ; - METHOD_AN1_LM IS 5 ; - METHOD_AN2_LM IS 6 ; - METHOD_REGRS_CJ IS 7 ; - METHOD_REGRS_LM IS 8 ; - METHOD_SS IS 9 ; - METHOD_SSG IS 10 ; - #C_to_Nial_testfilename IS OP File - Assignment_substitute_test IS OP Record - #*********************************** # Libraries (not needed here?...) library "stripblk library "findstri IF not in "string_split_by_string (EACH first symbols 0) THEN set "sketch; loaddefs 'C:\Documents and Settings\William Neil Howell\My Documents\Qnial\MY_NDFS\strings.ndf' 0; ENDIF; # need to make the following recursive for nested comments or multiple comments/ line! assumes total line with '*/ is ignored - not true.. still have to get rid of empty lines - could use code for this what happens to NULL string after */ or /* ? # C_to_Nial assumes that the '.c' filename occurs as the last period in the directory/filename! IF flag_debug THEN write 'loading C_to_Nial' ; ENDIF ; #] C_to_Nial IS OP File - C_to_Nial IS OP File { fin_dots := findall `. File ; IF tally Fin_dots >= 1 THEN Fin_dots := last fin_dots ; ELSE Fin_dots := tally File ; ENDIF ; Fin := open File "r ; Fout := open (link File|[tell fin_dots] '.ndf') "w ; % ; WHILE (Record := readfile Fin) ~= ??eof DO % do simple substitutions first! ; IF regexp_match '^(/\*)' Record THEN Record := '# ' link Record ; ELSE WHILE first (assgn := regexp '[^=!<>~:]=[^=]' Record) DO str := second assgn ; str2 := regexp_substitute '=' ' := ' str ; Record := regexp_substitute str str2 Record ; ENDWHILE ; Record := link string_split_by_string_with_sub '//' Record '%//' ; Record := link string_split_by_string_with_sub '==' Record ' = ' ; Record := link string_split_by_string_with_sub '*' Record ' * ' ; Record := link string_split_by_string_with_sub '* * ' Record '**' ; % don't really need for real C programs? ; Record := link string_split_by_string_with_sub '/ *' Record '/*' ; Record := link string_split_by_string_with_sub '\ *' Record '\*' ; Record := link string_split_by_string_with_sub '+' Record ' + ' ; Record := link string_split_by_string_with_sub '-' Record ' - ' ; Record := link string_split_by_string_with_sub '/' Record ' / ' ; ENDIF ; % ; % #define rearrangement - the following code maintains the format of the original line to some extent ; IF regexp_match '^(\#define)' Record THEN Strings := (OR ((` ` ) Eachleft match Record)) cut Record ; const := third Strings ; name := second Strings ; Record := regexp_substitute name '' Record ; namIS := link name ' IS ' ; Record := regexp_substitute '\#define ' namIS Record ; constColn := link const ' ; ' ; Record := regexp_substitute const constColn Record ; ENDIF ; writefile Fout Record ; ENDWHILE ; % ; EACH close Fin Fout ; } # Example: C_to_Nial 'C:\Data\Qnial\tests\activity.cpp' C_to_Nial 'C:\Data\Qnial\Masters, Timothy - Advanced algorithms\MLFN2\CONST.H' C_to_Nial 'C:\Data\Qnial\Masters, Timothy - Advanced algorithms\MLFN2\LayerNet_end.c' C_to_Nial 'C:\THENcuments and Settings\William Neil Howell\My Documents\Climate\Paillard\Howell - program\odeint.c' C_to_Nial 'C:\Documents and Settings\William Neil Howell\My Documents\Climate\Paillard\Howell - program\z_Old\rkqs.c' C_to_Nial 'C:\Documents and Settings\William Neil Howell\My Documents\Climate\Paillard\Howell - program\z_Old\rkck.c' C_to_Nial 'C:\Documents and Settings\William Neil Howell\My Documents\Climate\Paillard\Howell - program\z_Old\Bessel.c' C_to_Nial 'C:\Documents and Settings\William Neil Howell\My Documents\Qnial\MY_NDFS\Ord Diff Eq Integration\rk4.c' C_to_Nial 'C:\Documents and Settings\William Neil Howell\My Documents\Qnial\MY_NDFS\Ord Diff Eq Integration\rkdumb.c' # Strings := '#define NETMOD_COMPLEX_INPUT 3' IF flag_debug THEN write 'loading METHOD_AN1' ; ENDIF ; #] METHOD_AN1 IS 1 ; - METHOD_AN1 IS 1 ; IF flag_debug THEN write 'loading METHOD_AN1_CJ' ; ENDIF ; #] METHOD_AN1_CJ IS 2 ; - METHOD_AN1_CJ IS 2 ; IF flag_debug THEN write 'loading METHOD_AN2' ; ENDIF ; #] METHOD_AN2 IS 3 ; - METHOD_AN2 IS 3 ; IF flag_debug THEN write 'loading METHOD_AN2_CJ' ; ENDIF ; #] METHOD_AN2_CJ IS 4 ; - METHOD_AN2_CJ IS 4 ; IF flag_debug THEN write 'loading METHOD_AN1_LM' ; ENDIF ; #] METHOD_AN1_LM IS 5 ; - METHOD_AN1_LM IS 5 ; IF flag_debug THEN write 'loading METHOD_AN2_LM' ; ENDIF ; #] METHOD_AN2_LM IS 6 ; - METHOD_AN2_LM IS 6 ; IF flag_debug THEN write 'loading METHOD_REGRS_CJ' ; ENDIF ; #] METHOD_REGRS_CJ IS 7 ; - METHOD_REGRS_CJ IS 7 ; IF flag_debug THEN write 'loading METHOD_REGRS_LM' ; ENDIF ; #] METHOD_REGRS_LM IS 8 ; - METHOD_REGRS_LM IS 8 ; IF flag_debug THEN write 'loading METHOD_SS' ; ENDIF ; #] METHOD_SS IS 9 ; - METHOD_SS IS 9 ; IF flag_debug THEN write 'loading METHOD_SSG' ; ENDIF ; #] METHOD_SSG IS 10 ; - METHOD_SSG IS 10 ; # testing - various operators etc----------------------------------------------------------------- IF flag_debug THEN write 'loading #C_to_Nial_testfilename' ; ENDIF ; #] #C_to_Nial_testfilename IS OP File - #C_to_Nial_testfilename IS OP File { fin_dots := findall `. File ; IF tally Fin_dots >= 1 THEN Fin_dots := last fin_dots ; ELSE Fin_dots := tally File ; ENDIF ; link File|[tell fin_dots] '.ndf' } # test filenames C_to_Nial_testfilename 'g:\data\subdir\cool\jump.c' C_to_Nial_testfilename 'g:\data\sub.dir\cool\jump.c' C_to_Nial_testfilename 'g:\data\sub.dir.carrots\cool\jump.c' C_to_Nial_testfilename '' IF flag_debug THEN write 'loading Assignment_substitute_test' ; ENDIF ; #] Assignment_substitute_test IS OP Record - Assignment_substitute_test IS OP Record { % tester ; WHILE first (assgn := regexp '[^=!<>~:]=[^=]' Record) DO str := second assgn ; str2 := regexp_substitute '=' ':=' str; Record := regexp_substitute str str2 Record ; ENDWHILE ; assgn Record } # test Assignment_substitute_test setdeftrace "Assignment_substitute_test 1 Assignment_substitute_test 'for (i=0 ; i=3' regexp '[^=!<>~]=[^=]' 'for (i=0 ; i=3' regexp '[^=!<>~]=[^=]' 'for (i=0 ; i=3' #forget remarks for now - they are relatively easy to handle - just assume code &comments not usually intermixed % these actions result in lists of strings. They ignore nested remarks! ; IF regexp_match '/\*' Record THEN Record := string_split_by_string '/*' Record ; writefile Fout (first Record) ; writefile Fout '# ' ; ENDIF ; IF in_comment := l ; Fout EACHRIGHT writefile (rest Record); ELSE writefile Fout Record ; ENDIF; loaddefs_ended f_portCtoQNial ; # enddoc