X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=support%2Flibrarian%2Fsdcclib.c;h=913b1f03898609be2b2e6b0a9bb8c294fa543674;hb=d2d27270cceb98099b7fef26231aef40d9f6156e;hp=2993c32f1bde69b4448206066607794473ff0848;hpb=79817be2151a8c590738100dbbd1eddfc0f67b40;p=fw%2Fsdcc diff --git a/support/librarian/sdcclib.c b/support/librarian/sdcclib.c index 2993c32f..913b1f03 100644 --- a/support/librarian/sdcclib.c +++ b/support/librarian/sdcclib.c @@ -15,11 +15,14 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#define _POSIX_ +#include #include #include #include -#define _POSIX_ -#include +#if !defined(__BORLANDC__) && !defined(_MSC_VER) +#include +#endif char ProgName[PATH_MAX]; char LibName[PATH_MAX]; @@ -41,7 +44,7 @@ char AdbName[PATH_MAX]; #define NEQ(A,B) strcmp((A),(B)) int action=0; -FILE *lib, *newlib, *rel, *adb, *index; +FILE *lib, *newlib, *rel, *adb, *libindex; char FLine[MAXLINE+1]; char ModName[MAXLINE+1]; int state=0; @@ -58,7 +61,7 @@ void GetNameFromPath(char * path, char * name) void ChangeExtension(char * path, char * ext) { - int i, j; + int i; for(i=0; path[i]!=0; i++); for(; (path[i]!='.')&&(path[i]!='\\')&&(path[i]!='/')&&(i>=0); i--); @@ -86,7 +89,6 @@ void CleanLine(char * buff) int set_options (char * opt) { - char temp[255]; int rvalue=0, unknown=0; static char Help[] = "Usage: %s [-options] library relfile\n\n" @@ -186,6 +188,7 @@ void AddRel(void) long newlibpos, indexsize; char symname[MAXLINE+1]; char c; + int IsDOSStyle=0; strcpy(LibNameTmp, LibName); ChangeExtension(LibNameTmp, "__L"); @@ -204,7 +207,7 @@ void AddRel(void) if(rel==NULL) { printf("ERROR: Couldn't open file '%s'", RelName); - fclose(lib); + if(lib!=NULL) fclose(lib); return; } } @@ -214,17 +217,17 @@ void AddRel(void) if(newlib==NULL) { printf("ERROR: Couldn't create temporary file '%s'", LibNameTmp); - fclose(lib); + if(lib!=NULL) fclose(lib); fclose(rel); return; } fprintf(newlib, "\n\n"); - index=fopen(IndexName, "w"); - if(index==NULL) + libindex=fopen(IndexName, "w"); + if(libindex==NULL) { printf("ERROR: Couldn't create temporary file '%s'", IndexName); - fclose(lib); + if(lib!=NULL) fclose(lib); fclose(newlib); fclose(rel); return; @@ -248,7 +251,7 @@ void AddRel(void) { newlibpos=ftell(newlib); fprintf(newlib, "\n%s\n", FLine); - fprintf(index, "\n%s %ld\n", FLine, newlibpos); + fprintf(libindex, "\n%s %ld\n", FLine, newlibpos); state++; } } @@ -258,7 +261,7 @@ void AddRel(void) if(EQ(FLine, "")) { fprintf(newlib, "\n"); - fprintf(index, "\n\n"); + fprintf(libindex, "\n\n"); state=0; inrel=0; } @@ -269,7 +272,7 @@ void AddRel(void) if(FLine[0]=='S') { sscanf(FLine, "S %s %c", symname, &c); - if(c=='D') fprintf(index, "%s\n", symname); + if(c=='D') fprintf(libindex, "%s\n", symname); } } break; @@ -280,7 +283,7 @@ void AddRel(void) { newlibpos=ftell(newlib); fprintf(newlib, "\n%s\n\n", ModName); - fprintf(index, "\n%s %ld\n", ModName, newlibpos); + fprintf(libindex, "\n%s %ld\n", ModName, newlibpos); while(!feof(rel)) { FLine[0]=0; @@ -293,11 +296,11 @@ void AddRel(void) if(FLine[0]=='S') { sscanf(FLine, "S %s %c", symname, &c); - if(c=='D') fprintf(index, "%s\n", symname); + if(c=='D') fprintf(libindex, "%s\n", symname); } } fclose(rel); - fprintf(index, "\n"); + fprintf(libindex, "\n"); fprintf(newlib, "\n\n"); adb=fopen(AdbName, "r"); @@ -319,27 +322,34 @@ void AddRel(void) } /*Put the temporary files together as a new library file*/ - indexsize=ftell(index); - fflush(index); + indexsize=ftell(libindex); + fflush(libindex); fflush(newlib); fclose(newlib); if(lib!=NULL) fclose(lib); - fclose(index); + fclose(libindex); newlib=fopen(LibNameTmp, "r"); lib=fopen(LibName, "w"); - index=fopen(IndexName, "r"); + libindex=fopen(IndexName, "r"); + + fprintf(lib, "\n\n\n"); + + /*Find out if the \n is expanded to \r\n or not*/ + if(ftell(lib)!=(long)strlen("\n\n\n")) + { + IsDOSStyle=1; + } - fprintf(lib, "\n\n"); - fprintf(lib, "\n"); + indexsize+=ftell(lib)+strlen("0123456789\n\n\n\n"); + if(IsDOSStyle) indexsize+=4; - indexsize+=ftell(lib)+12+14; fprintf(lib, "%10ld\n", indexsize); - while(!feof(index)) + while(!feof(libindex)) { FLine[0]=0; - fgets(FLine, MAXLINE, index); + fgets(FLine, MAXLINE, libindex); fprintf(lib, "%s", FLine); } fprintf(lib, "\n\n\n"); @@ -355,10 +365,10 @@ void AddRel(void) fclose(newlib); fclose(lib); - fclose(index); + fclose(libindex); - unlink(LibNameTmp); - unlink(IndexName); + _unlink(LibNameTmp); + _unlink(IndexName); } void ExtractRel(void)