Commit 7c842670 authored by johnvg@science.ru.nl's avatar johnvg@science.ru.nl

pass full name of abc file to backend, remove file searching code from windows backend

parent 97af71b3
......@@ -12,7 +12,6 @@ extern SymbDef scc_dependency_list;
SymbDef MakeNewSymbolDefinition (char *module, char *name, int arity, SDefKind kind);
char *ConvertSymbolToString (Symbol symb);
void ReadInlineCode (void);
void InitChecker (void);
void GenDependencyList (void);
NodeDefs NewNodeDef (NodeId nid, Node node);
......
......@@ -103,7 +103,7 @@ char *ABCFileName;
Bool OpenABCFile (char *fname)
{
OutFile = FOpen (fname, abcFile, "w");
OutFile = FOpen (fname, "w");
if (OutFile!=NULL){
#if defined (POWER)
......@@ -131,7 +131,7 @@ void CloseABCFile (char *fname)
StaticMessage (True, "<open file>", "Write error (disk full?)");
}
if (CompilerError)
FDelete (fname, abcFile);
FDelete (fname);
OpenedFile = (File) NIL;
}
}
......
......@@ -44,9 +44,8 @@
extern char *PATHLIST;
extern char *GetFileExtension (FileKind kind);
extern File FOpen (char *wname, FileKind kind, char *mode);
extern int FDelete (char *fname, FileKind kind);
extern File FOpen (char *fname, char *mode);
extern int FDelete (char *fname);
extern int FClose (File f);
extern int FPutS (char *s, File f);
......@@ -56,10 +55,6 @@ extern int FPrintF (File f, char *fmt,...);
extern int FPrintF (); /* (File w, char *fmt,...) */
#endif
#ifndef __ppc__
extern char *FGetS (char *s, int n, File f);
#endif
#ifdef _VARARGS_
extern void DoError (char *fmt,...);
extern void DoFatalError (char *fmt,...);
......
......@@ -20,261 +20,19 @@
# include <winbase.h>
#endif
char *GetFileExtension (FileKind kind)
File FOpen (char *fname,char *mode)
{
switch (kind){
case abcFile:
return ".abc";
case obj00File:
case obj20File:
case obj81File:
return ".obj";
case iclFile:
return ".icl";
case dclFile:
return ".dcl";
case hsFile:
return ".hs";
case assFile:
return ".a";
case sunAssFile:
return ".s";
case applFile:
case otherFile:
default:
return "";
}
}
char clean_lib_directory[129] = ".";
static int file_exists (char *file_name)
{
HANDLE h;
WIN32_FIND_DATA find_data;
h=FindFirstFile (file_name,&find_data);
if (h!=INVALID_HANDLE_VALUE){
FindClose (h);
return True;
} else
return False;
}
static int use_clean_system_files_folder=1;
extern char *path_parameter;
static void append_file_name_and_ext (char *path_p,char *fname_p,char *ext,int in_clean_system_files_folder)
{
int i;
char c;
if (in_clean_system_files_folder){
int last_dot_i;
last_dot_i = -1;
i=0;
while (c=fname_p[i], c!='\0'){
if (c=='.')
last_dot_i=i;
++i;
}
if (last_dot_i>=0){
i=0;
while (i<last_dot_i){
path_p[i]=fname_p[i];
++i;
}
path_p[i]='\\';
path_p+=last_dot_i+1;
fname_p+=last_dot_i+1;
}
strcpy (path_p,"Clean System Files\\");
path_p += 19;
i=0;
while (c=fname_p[i], c!='\0'){
path_p[i] = c;
++i;
}
path_p+=i;
} else {
int i;
char c;
i=0;
while (c=fname_p[i], c!='\0'){
path_p[i] = c=='.' ? '\\' : c;
++i;
}
path_p+=i;
return fopen (fname,mode);
}
i=0;
do {
c=ext[i];
path_p[i]=c;
++i;
} while (c!='\0');
}
static Bool findfilepath (char *fname,FileKind kind,char *path)
{
char *s,*path_elem,c,*pathlist,*ext;
int in_clean_system_files_folder;
pathlist=path_parameter;
if (pathlist==NULL)
pathlist=".";
ext = GetFileExtension (kind);
in_clean_system_files_folder=0;
if (use_clean_system_files_folder)
switch (kind){
case abcFile:
case obj00File:
case obj20File:
case obj81File:
in_clean_system_files_folder=1;
}
if (! (fname[0]=='\\' || (fname[0]!=0 && fname[1]==':'))){
path_elem = pathlist;
s=path_elem;
for (;;){
c = *s;
if (c == ';' || c == '\0'){
char *from_p,*dest_p;
from_p=path_elem;
dest_p=path;
while (from_p<s)
*dest_p++ = *from_p++;
*dest_p = '\0';
*dest_p++ = '\\';
append_file_name_and_ext (dest_p,fname,ext,in_clean_system_files_folder);
if (file_exists (path))
return True;
if (c == '\0')
break;
path_elem = ++s;
} else
++s;
}
}
append_file_name_and_ext (path,fname,ext,in_clean_system_files_folder);
return file_exists (path);
}
static char *skip_after_last_dot (char *s)
{
int i,after_last_dot_i;
char c;
after_last_dot_i=0;
i=0;
while (c=s[i],c!='\0'){
++i;
if (c=='.')
after_last_dot_i=i;
}
return &s[after_last_dot_i];
}
File FOpen (char *fname,FileKind kind,char *mode)
{
char path[MAXPATHLEN];
Bool res;
if (fname[0]=='\\' || (fname[0]!=0 && fname[1]==':')){
strcpy (path,fname);
strcat (path,GetFileExtension (kind));
return fopen (path,mode);
}
if (mode[0]=='r'){
findfilepath (fname,kind,path);
return fopen (path,mode);
} else {
res=findfilepath (fname,dclFile,path);
if (!res)
res=findfilepath (fname,iclFile,path);
if (!res)
res=findfilepath (fname,hsFile,path);
if (res){
char *p,*after_last_slash;
after_last_slash=NULL;
p=path;
while (*p)
if (*p++=='\\')
after_last_slash=p;
if (after_last_slash==NULL)
after_last_slash=path;
if (use_clean_system_files_folder){
strcpy (after_last_slash,"Clean System Files");
if (!file_exists (path)){
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
CreateDirectory (path,&sa);
}
strcat (after_last_slash,"\\");
strcat (after_last_slash,skip_after_last_dot (fname));
} else
strcpy (after_last_slash,skip_after_last_dot (fname));
strcat (after_last_slash,GetFileExtension (kind));
return fopen (path,mode);
} else
return NULL;
}
}
int FClose (File f)
{
return fclose ((FILE *) f);
}
int FDelete (char *fname, FileKind kind)
int FDelete (char *fname)
{
char path[MAXPATHLEN];
Bool res;
res = findfilepath (fname,kind,path);
if (res)
return remove (path);
else
return -1;
return remove (fname);
}
int FPrintF (File f, char *fmt, ...)
......@@ -289,11 +47,6 @@ int FPrintF (File f, char *fmt, ...)
return n;
}
char *FGetS (char *s, int n, File f)
{
return fgets (s, n, (FILE *) f);
}
int FPutS (char *s, File f)
{
return fputs (s, (FILE *) f);
......
......@@ -94,6 +94,17 @@ closeTclFile (Yes tcl_file) files
closeTclFile _ files
= (True,files);
abc_file_name_in_clean_system_files_folder :: !String !String !*File !*Files -> (!Bool, !String, !*File, !*Files)
abc_file_name_in_clean_system_files_folder mod_dir mod_name error files
// mod_dir ends with DirectorySeparator
# (csf_directory_path,file_name) = make_clean_system_files_dir_and_file_name (mod_dir +++ mod_name)
# file_path = csf_directory_path +++ {DirectorySeparator} +++ file_name +++ ".abc"
# (ok, files) = ensureCleanSystemFilesExists csf_directory_path files
| not ok
# error = fwrites ("can't create folder \"" +++ csf_directory_path +++"\"\n") error
= (False, file_path, error, files)
= (True, file_path, error, files)
:: CoclOptions =
{ moduleName:: {#Char}
, pathName ::{#Char}
......@@ -325,14 +336,16 @@ compileModule options backendArgs cache=:{dcl_modules,functions_and_macros,prede
hp_type_heaps=heaps.hp_type_heaps
type_var_heap=hp_type_heaps.th_vars
attrHeap=hp_type_heaps.th_attrs
# (success,functions_and_macros,var_heap,type_var_heap,attrHeap,error,out)
# (success,functions_and_macros,var_heap,type_var_heap,attrHeap,error,out,files)
= case optionalSyntaxTree of
Yes syntaxTree
# functions_and_macros = syntaxTree.fe_icl.icl_functions
# (Yes path) = mbModPath
# (csf_dir_exists,abc_file_path,error,files) = abc_file_name_in_clean_system_files_folder path options.moduleName error files
# (success, var_heap, type_var_heap, attrHeap, error, out)
= backEndInterface outputPath (map appendRedirection backendArgs) options.listTypes options.outPath predef_symbols syntaxTree main_dcl_module_n
= backEndInterface abc_file_path (map appendRedirection backendArgs) options.listTypes options.outPath predef_symbols syntaxTree main_dcl_module_n
var_heap type_var_heap attrHeap error out
-> (success,functions_and_macros,var_heap,type_var_heap,attrHeap,error,out)
-> (success,functions_and_macros,var_heap,type_var_heap,attrHeap,error,out,files)
with
appendRedirection arg
= case arg of
......@@ -343,17 +356,7 @@ compileModule options backendArgs cache=:{dcl_modules,functions_and_macros,prede
arg
-> arg
No
-> (False,{},var_heap,type_var_heap,attrHeap,error,out)
with
/*
outputPath
= if (options.outputPathName == "")
(directoryName options.pathName +++ "Clean System Files" +++ {DirectorySeparator} +++ baseName options.pathName)
options.outputPathName
*/
outputPath
// = /* directoryName options.pathName +++ "Clean System Files" +++ {DirectorySeparator} +++ */ baseName options.pathName
= baseName options.pathName
-> (False,{},var_heap,type_var_heap,attrHeap,error,out,files)
# heaps = {heaps & hp_var_heap=var_heap, hp_type_heaps = {th_vars=type_var_heap, th_attrs=attrHeap}}
# (closed, files) = fclose out files
| not closed
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment