Subversion Repositories eduke32

Rev

Rev 4905 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4905 Rev 5058
Line 648... Line 648...
648
    if (!h) close(fh);
648
    if (!h) close(fh);
649
649
650
    return h;
650
    return h;
651
}
651
}
652
652
-
 
653
#define MAXGROUPFILES 8     // Warning: Fix groupfil if this is changed
-
 
654
#define MAXOPENFILES 64     // Warning: Fix filehan if this is changed
-
 
655
-
 
656
enum {
-
 
657
    GRP_RESERVED_ID_START = 254,
-
 
658
-
 
659
    GRP_ZIP = GRP_RESERVED_ID_START,
-
 
660
    GRP_FILESYSTEM = GRP_RESERVED_ID_START + 1,
-
 
661
};
-
 
662
-
 
663
EDUKE32_STATIC_ASSERT(MAXGROUPFILES <= GRP_RESERVED_ID_START);
-
 
664
653
int32_t numgroupfiles = 0;
665
int32_t numgroupfiles = 0;
654
static int32_t gnumfiles[MAXGROUPFILES];
666
static int32_t gnumfiles[MAXGROUPFILES];
655
static int32_t groupfil[MAXGROUPFILES] = {-1,-1,-1,-1,-1,-1,-1,-1};
667
static int32_t groupfil[MAXGROUPFILES] = {-1,-1,-1,-1,-1,-1,-1,-1};
656
static int32_t groupfilpos[MAXGROUPFILES];
668
static int32_t groupfilpos[MAXGROUPFILES];
657
static char *gfilelist[MAXGROUPFILES];
669
static char *gfilelist[MAXGROUPFILES];
658
static int32_t *gfileoffs[MAXGROUPFILES];
670
static int32_t *gfileoffs[MAXGROUPFILES];
659
671
660
static char filegrp[MAXOPENFILES];
672
static uint8_t filegrp[MAXOPENFILES];
661
static int32_t filepos[MAXOPENFILES];
673
static int32_t filepos[MAXOPENFILES];
662
static intptr_t filehan[MAXOPENFILES] =
674
static intptr_t filehan[MAXOPENFILES] =
663
{
675
{
664
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
676
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
665
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
677
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
666
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
678
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
667
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
679
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
668
};
680
};
-
 
681
669
#ifdef WITHKPLIB
682
#ifdef WITHKPLIB
670
static char filenamsav[MAXOPENFILES][260];
683
static char filenamsav[MAXOPENFILES][260];
671
static int32_t kzcurhand = -1;
684
static int32_t kzcurhand = -1;
672
685
673
int32_t cache1d_file_fromzip(int32_t fil)
686
int32_t cache1d_file_fromzip(int32_t fil)
674
{
687
{
675
    return (filegrp[fil] == 254);
688
    return (filegrp[fil] == GRP_ZIP);
676
}
689
}
677
#endif
690
#endif
678
691
679
int32_t initgroupfile(const char *filename)
692
int32_t initgroupfile(const char *filename)
680
{
693
{
Line 775... Line 788...
775
        }
788
        }
776
789
777
    // fix up the open files that need attention
790
    // fix up the open files that need attention
778
    for (i=0; i<MAXOPENFILES; i++)
791
    for (i=0; i<MAXOPENFILES; i++)
779
    {
792
    {
780
        if (filegrp[i] >= 254)         // external file (255) or ZIPped file (254)
793
        if (filegrp[i] >= GRP_RESERVED_ID_START)         // external file or ZIPped file
781
            continue;
794
            continue;
782
        else if (filegrp[i] == grpnum)   // close file in group we closed
795
        else if (filegrp[i] == grpnum)   // close file in group we closed
783
            filehan[i] = -1;
796
            filehan[i] = -1;
784
        else if (filegrp[i] > grpnum)   // move back a file in a group after the one we closed
797
        else if (filegrp[i] > grpnum)   // move back a file in a group after the one we closed
785
            filegrp[i]--;
798
            filegrp[i]--;
Line 801... Line 814...
801
    numgroupfiles = 0;
814
    numgroupfiles = 0;
802
815
803
    // JBF 20040111: "close" any files open in groups
816
    // JBF 20040111: "close" any files open in groups
804
    for (i=0; i<MAXOPENFILES; i++)
817
    for (i=0; i<MAXOPENFILES; i++)
805
    {
818
    {
806
        if (filegrp[i] < 254)   // JBF 20040130: not external or ZIPped
819
        if (filegrp[i] < GRP_RESERVED_ID_START)   // JBF 20040130: not external or ZIPped
807
            filehan[i] = -1;
820
            filehan[i] = -1;
808
    }
821
    }
809
}
822
}
810
823
811
#ifdef FILENAME_CASE_CHECK
824
#ifdef FILENAME_CASE_CHECK
Line 919... Line 932...
919
932
920
            Bfree(lastpfn);
933
            Bfree(lastpfn);
921
            lastpfn=NULL;
934
            lastpfn=NULL;
922
        }
935
        }
923
#endif
936
#endif
924
        filegrp[newhandle] = 255;
937
        filegrp[newhandle] = GRP_FILESYSTEM;
925
        filehan[newhandle] = fil;
938
        filehan[newhandle] = fil;
926
        filepos[newhandle] = 0;
939
        filepos[newhandle] = 0;
927
        return(newhandle);
940
        return(newhandle);
928
    }
941
    }
929
942
Line 940... Line 953...
940
        kzclose();
953
        kzclose();
941
    }
954
    }
942
    if (searchfirst != 1 && (i = kzipopen(filename)) != 0)
955
    if (searchfirst != 1 && (i = kzipopen(filename)) != 0)
943
    {
956
    {
944
        kzcurhand = newhandle;
957
        kzcurhand = newhandle;
945
        filegrp[newhandle] = 254;
958
        filegrp[newhandle] = GRP_ZIP;
946
        filehan[newhandle] = i;
959
        filehan[newhandle] = i;
947
        filepos[newhandle] = 0;
960
        filepos[newhandle] = 0;
948
        strcpy(filenamsav[newhandle],filename);
961
        strcpy(filenamsav[newhandle],filename);
949
        return newhandle;
962
        return newhandle;
950
    }
963
    }
Line 987... Line 1000...
987
{
1000
{
988
    int32_t i;
1001
    int32_t i;
989
    int32_t filenum = filehan[handle];
1002
    int32_t filenum = filehan[handle];
990
    int32_t groupnum = filegrp[handle];
1003
    int32_t groupnum = filegrp[handle];
991
1004
992
    if (groupnum == 255) return(Bread(filenum,buffer,leng));
1005
    if (groupnum == GRP_FILESYSTEM) return(Bread(filenum,buffer,leng));
993
#ifdef WITHKPLIB
1006
#ifdef WITHKPLIB
994
    else if (groupnum == 254)
1007
    else if (groupnum == GRP_ZIP)
995
    {
1008
    {
996
        if (kzcurhand != handle)
1009
        if (kzcurhand != handle)
997
        {
1010
        {
998
            if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); }
1011
            if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); }
999
            kzcurhand = handle;
1012
            kzcurhand = handle;
Line 1026... Line 1039...
1026
{
1039
{
1027
    int32_t i, groupnum;
1040
    int32_t i, groupnum;
1028
1041
1029
    groupnum = filegrp[handle];
1042
    groupnum = filegrp[handle];
1030
1043
1031
    if (groupnum == 255) return(Blseek(filehan[handle],offset,whence));
1044
    if (groupnum == GRP_FILESYSTEM) return(Blseek(filehan[handle],offset,whence));
1032
#ifdef WITHKPLIB
1045
#ifdef WITHKPLIB
1033
    else if (groupnum == 254)
1046
    else if (groupnum == GRP_ZIP)
1034
    {
1047
    {
1035
        if (kzcurhand != handle)
1048
        if (kzcurhand != handle)
1036
        {
1049
        {
1037
            if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); }
1050
            if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); }
1038
            kzcurhand = handle;
1051
            kzcurhand = handle;
Line 1064... Line 1077...
1064
int32_t kfilelength(int32_t handle)
1077
int32_t kfilelength(int32_t handle)
1065
{
1078
{
1066
    int32_t i, groupnum;
1079
    int32_t i, groupnum;
1067
1080
1068
    groupnum = filegrp[handle];
1081
    groupnum = filegrp[handle];
1069
    if (groupnum == 255)
1082
    if (groupnum == GRP_FILESYSTEM)
1070
    {
1083
    {
1071
        // return(filelength(filehan[handle]))
1084
        // return(filelength(filehan[handle]))
1072
        return Bfilelength(filehan[handle]);
1085
        return Bfilelength(filehan[handle]);
1073
    }
1086
    }
1074
#ifdef WITHKPLIB
1087
#ifdef WITHKPLIB
1075
    else if (groupnum == 254)
1088
    else if (groupnum == GRP_ZIP)
1076
    {
1089
    {
1077
        if (kzcurhand != handle)
1090
        if (kzcurhand != handle)
1078
        {
1091
        {
1079
            if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); }
1092
            if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); }
1080
            kzcurhand = handle;
1093
            kzcurhand = handle;
Line 1090... Line 1103...
1090
1103
1091
int32_t ktell(int32_t handle)
1104
int32_t ktell(int32_t handle)
1092
{
1105
{
1093
    int32_t groupnum = filegrp[handle];
1106
    int32_t groupnum = filegrp[handle];
1094
1107
1095
    if (groupnum == 255) return(Blseek(filehan[handle],0,BSEEK_CUR));
1108
    if (groupnum == GRP_FILESYSTEM) return(Blseek(filehan[handle],0,BSEEK_CUR));
1096
#ifdef WITHKPLIB
1109
#ifdef WITHKPLIB
1097
    else if (groupnum == 254)
1110
    else if (groupnum == GRP_ZIP)
1098
    {
1111
    {
1099
        if (kzcurhand != handle)
1112
        if (kzcurhand != handle)
1100
        {
1113
        {
1101
            if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); }
1114
            if (kztell() >= 0) { filepos[kzcurhand] = kztell(); kzclose(); }
1102
            kzcurhand = handle;
1115
            kzcurhand = handle;
Line 1112... Line 1125...
1112
}
1125
}
1113
1126
1114
void kclose(int32_t handle)
1127
void kclose(int32_t handle)
1115
{
1128
{
1116
    if (handle < 0) return;
1129
    if (handle < 0) return;
1117
    if (filegrp[handle] == 255) Bclose(filehan[handle]);
1130
    if (filegrp[handle] == GRP_FILESYSTEM) Bclose(filehan[handle]);
1118
#ifdef WITHKPLIB
1131
#ifdef WITHKPLIB
1119
    else if (filegrp[handle] == 254)
1132
    else if (filegrp[handle] == GRP_ZIP)
1120
    {
1133
    {
1121
        kzclose();
1134
        kzclose();
1122
        kzcurhand = -1;
1135
        kzcurhand = -1;
1123
    }
1136
    }
1124
#endif
1137
#endif