Annotation of sbbs/src/uifc/filepick.c, revision 1.1

1.1     ! root        1: #include <ctype.h>
        !             2: 
        !             3: #include "dirwrap.h"
        !             4: #include "uifc.h"
        !             5: #include "ciolib.h"
        !             6: #include "mouse.h"
        !             7: #include "keys.h"
        !             8: 
        !             9: #include "filepick.h"
        !            10: 
        !            11: enum {
        !            12:         DIR_LIST
        !            13:        ,FILE_LIST
        !            14:        ,MASK_FIELD
        !            15:        ,CURRENT_PATH
        !            16:        ,FIELD_LIST_TERM
        !            17: };
        !            18: 
        !            19: void drawfpwindow(uifcapi_t *api)
        !            20: {
        !            21:        char lbuf[1024];
        !            22:        int i;
        !            23:        int j;
        !            24:        int listheight=0;
        !            25:        int height;
        !            26:        int width;
        !            27:        char  shade[1024];
        !            28: 
        !            29:        width=SCRN_RIGHT-SCRN_LEFT+1;
        !            30: 
        !            31:        height=api->scrn_len-3;
        !            32:        /* Make sure it's odd */
        !            33:        if(!(width%2))
        !            34:                width--;
        !            35: 
        !            36:        listheight=height-7;
        !            37: 
        !            38:         i=0;
        !            39:        lbuf[i++]='\xc9';
        !            40:        lbuf[i++]=api->hclr|(api->bclr<<4);
        !            41:        for(j=1;j<width-1;j++) {
        !            42:                lbuf[i++]='\xcd';
        !            43:                lbuf[i++]=api->hclr|(api->bclr<<4);
        !            44:        }
        !            45:        if(api->mode&UIFC_MOUSE && width>6) {
        !            46:                lbuf[2]='[';
        !            47:                lbuf[3]=api->hclr|(api->bclr<<4);
        !            48:                lbuf[4]=0xfe;
        !            49:                lbuf[5]=api->lclr|(api->bclr<<4);
        !            50:                lbuf[6]=']';
        !            51:                lbuf[7]=api->hclr|(api->bclr<<4);
        !            52:                lbuf[8]='[';
        !            53:                lbuf[9]=api->hclr|(api->bclr<<4);
        !            54:                lbuf[10]='?';
        !            55:                lbuf[11]=api->lclr|(api->bclr<<4);
        !            56:                lbuf[12]=']';
        !            57:                lbuf[13]=api->hclr|(api->bclr<<4);
        !            58:                api->buttony=SCRN_TOP;
        !            59:                api->exitstart=SCRN_LEFT+1;
        !            60:                api->exitend=SCRN_LEFT+3;
        !            61:                api->helpstart=SCRN_LEFT+4;
        !            62:                api->helpend=SCRN_LEFT+6;
        !            63:        }
        !            64:        lbuf[i++]='\xbb';
        !            65:        lbuf[i]=api->hclr|(api->bclr<<4);
        !            66:        puttext(SCRN_LEFT,SCRN_TOP,SCRN_LEFT+width-1,SCRN_TOP,lbuf);
        !            67:        lbuf[5]=api->hclr|(api->bclr<<4);
        !            68:        lbuf[11]=api->hclr|(api->bclr<<4);
        !            69:        for(j=2;j<14;j+=2)
        !            70:                lbuf[j]='\xcd';
        !            71:        lbuf[0]='\xc8';
        !            72:        lbuf[(width-1)*2]='\xbc';
        !            73:        puttext(SCRN_LEFT,SCRN_TOP+height-1
        !            74:                ,SCRN_LEFT+width-1,SCRN_TOP+height-1,lbuf);
        !            75:        lbuf[0]='\xcc';
        !            76:        lbuf[(width-1)*2]='\xb9';
        !            77:        lbuf[width-1]='\xcb';
        !            78:        puttext(SCRN_LEFT,SCRN_TOP+2,SCRN_LEFT+width-1,SCRN_TOP+2,lbuf);
        !            79:        lbuf[width-1]='\xca';
        !            80:        puttext(SCRN_LEFT,SCRN_TOP+3+listheight
        !            81:                ,SCRN_LEFT+width-1,SCRN_TOP+3+listheight,lbuf);
        !            82:        lbuf[0]='\xba';
        !            83:        lbuf[(width-1)*2]='\xba';
        !            84:        for(j=2;j<(width-1)*2;j+=2)
        !            85:                lbuf[j]=' ';
        !            86:        puttext(SCRN_LEFT,SCRN_TOP+1,
        !            87:                SCRN_LEFT+width-1,SCRN_TOP+1,lbuf);
        !            88:        puttext(SCRN_LEFT,SCRN_TOP+height-2,
        !            89:                SCRN_LEFT+width-1,SCRN_TOP+height-2,lbuf);
        !            90:        puttext(SCRN_LEFT,SCRN_TOP+height-3,
        !            91:                SCRN_LEFT+width-1,SCRN_TOP+height-3,lbuf);
        !            92:        lbuf[width-1]='\xba';
        !            93:        for(j=0;j<listheight;j++)
        !            94:                puttext(SCRN_LEFT,SCRN_TOP+3+j
        !            95:                        ,SCRN_LEFT+width-1,SCRN_TOP+3+j,lbuf);
        !            96:        
        !            97: 
        !            98:        /* Shadow */
        !            99:        if(api->bclr==BLUE) {
        !           100:                gettext(SCRN_LEFT+width,SCRN_TOP+1,SCRN_LEFT+width+1
        !           101:                        ,SCRN_TOP+(height-1),shade);
        !           102:                for(j=1;j<1024;j+=2)
        !           103:                        shade[j]=DARKGRAY;
        !           104:                puttext(SCRN_LEFT+width,SCRN_TOP+1,SCRN_LEFT+width+1
        !           105:                        ,SCRN_TOP+(height-1),shade);
        !           106:                gettext(SCRN_LEFT+2,SCRN_TOP+height,SCRN_LEFT+width+1
        !           107:                        ,SCRN_TOP+height,shade);
        !           108:                for(j=1;j<width*2;j+=2)
        !           109:                        shade[j]=DARKGRAY;
        !           110:                puttext(SCRN_LEFT+2,SCRN_TOP+height,SCRN_LEFT+width+1
        !           111:                        ,SCRN_TOP+height,shade);
        !           112:        }
        !           113: }
        !           114: 
        !           115: void free_opt_list(char ***opts)
        !           116: {
        !           117:        char **p;
        !           118: 
        !           119:        if(*opts==NULL)
        !           120:                return;
        !           121:        for(p=*opts; *p && (*p)[0]; p++) {
        !           122:                if(*p)
        !           123:                        FREE_AND_NULL((*p));
        !           124:        }
        !           125:        FREE_AND_NULL(*opts);
        !           126: }
        !           127: 
        !           128: char *insensitive_mask(char *mask)
        !           129: {
        !           130: #ifdef __unix__
        !           131:        char *in;
        !           132:        char *out;
        !           133:        static char nmask[MAX_PATH*4+1];
        !           134: 
        !           135:        out=nmask;
        !           136:        for(in=mask; *in; in++) {
        !           137:                if(isalpha(*in)) {
        !           138:                        *(out++)='[';
        !           139:                        *(out++)=tolower(*in);
        !           140:                        *(out++)=toupper(*in);
        !           141:                        *(out++)=']';
        !           142:                }
        !           143:                else
        !           144:                        *(out++)=*in;
        !           145:        }
        !           146:        *out=0;
        !           147:        return(nmask);
        !           148: #else
        !           149:        return(mask);
        !           150: #endif
        !           151: }
        !           152: 
        !           153: char *getdirname(char *path)
        !           154: {
        !           155:        char *p1;
        !           156:        char *p2;
        !           157: 
        !           158:        p1=strrchr(path,'/');
        !           159: #ifdef _WIN32
        !           160:        p2=strrchr(path,'\\');
        !           161:        if(p2 > p1)
        !           162:                p1=p2;
        !           163: #endif
        !           164:        p2 = path;
        !           165:        if(p1 > path) {
        !           166:                for(p2=p1-1; p2>=path && !IS_PATH_DELIM(*p2); p2--);
        !           167:                if(IS_PATH_DELIM(*p2) && *(p2+1))
        !           168:                        p2++;
        !           169:        }
        !           170:        return(p2);
        !           171: }
        !           172: 
        !           173: char **get_file_opt_list(char **fns, int files, int dirsonly, int root)
        !           174: {
        !           175:        char **opts;
        !           176:        int  i;
        !           177:        int  j=0;
        !           178: 
        !           179:        opts=(char **)malloc((files+2)*sizeof(char *));
        !           180:        if(opts==NULL)
        !           181:                return(NULL);
        !           182:        memset(opts, 0, (files+2)*sizeof(char *));
        !           183:        if(dirsonly) {
        !           184:                if(!root)
        !           185:                        opts[j++]=strdup("..");
        !           186:        }
        !           187:        for(i=0;i<files;i++) {
        !           188:                if(isdir(fns[i])) {
        !           189:                        if(dirsonly)
        !           190:                                opts[j++]=strdup(getdirname(fns[i]));
        !           191:                }
        !           192:                else {
        !           193:                        if(!dirsonly)
        !           194:                                opts[j++]=strdup(getfname(fns[i]));
        !           195:                }
        !           196:        }
        !           197:        opts[j]="";
        !           198:        return(opts);
        !           199: }
        !           200: 
        !           201: void display_current_path(uifcapi_t *api, char *path)
        !           202: {
        !           203:        char    dpath[MAX_PATH+2];
        !           204:        int width;
        !           205:        int height;
        !           206:        char    *p;
        !           207: 
        !           208:        height=api->scrn_len-3;
        !           209:        width=SCRN_RIGHT-SCRN_LEFT-3;
        !           210:        SAFECOPY(dpath, path);
        !           211:        while(strlen(dpath) > width) {
        !           212:                /* Just remove paths from the start. */
        !           213:                dpath[0]='.';
        !           214:                dpath[1]='.';
        !           215:                dpath[2]='.';
        !           216:                memmove(dpath+3, dpath+(strlen(dpath)-width+4), width-1);
        !           217:        }
        !           218:        /* For Win32, convert all "confusing" / to \\ */
        !           219: #ifdef _WIN32
        !           220:        for(p=dpath; *p; p++) {
        !           221:                if(*p=='/')
        !           222:                        *p='\\';
        !           223:        }
        !           224: #endif
        !           225: 
        !           226:        api->printf(SCRN_LEFT+2, SCRN_TOP+height-2, api->lclr|(api->bclr<<4), "%-*s", width, dpath);
        !           227: }
        !           228: 
        !           229: int mousetofield(int currfield, int opts, int height, int width, int listheight, int listwidth, int *dcur, int *dbar, int *fcur, int *fbar)
        !           230: {
        !           231:        int newfield;
        !           232:        int nbar;
        !           233:        int bardif;
        !           234:        struct mouse_event mevnt;
        !           235: 
        !           236:        newfield=currfield;
        !           237:        if(getmouse(&mevnt)==0) {
        !           238:                if(mevnt.endx >= SCRN_LEFT + 1
        !           239:                                && mevnt.endx <= SCRN_LEFT + listwidth
        !           240:                                && mevnt.endy >= SCRN_TOP + 3
        !           241:                                && mevnt.endy <= SCRN_TOP + 2 + listheight) {
        !           242:                        newfield = DIR_LIST;
        !           243:                        if(mevnt.endx == SCRN_LEFT + 1)
        !           244:                                ungetmouse(&mevnt);
        !           245:                        else {
        !           246:                                bardif = (mevnt.starty - SCRN_TOP - 3) - *dbar;
        !           247:                                *dbar += bardif;
        !           248:                                *dcur += bardif;
        !           249:                        }
        !           250:                }
        !           251:                if(mevnt.endx >= SCRN_LEFT + 1 + listwidth + 1
        !           252:                                && mevnt.endx <= SCRN_LEFT + 1 + listwidth * 2
        !           253:                                && mevnt.endy >= SCRN_TOP + 3
        !           254:                                && mevnt.endy <= SCRN_TOP + 2 + listheight) {
        !           255:                        newfield = FILE_LIST;
        !           256:                        if(mevnt.endx == SCRN_LEFT + 1 + listwidth + 1)
        !           257:                                ungetmouse(&mevnt);
        !           258:                        else {
        !           259:                                bardif = (mevnt.starty - SCRN_TOP - 3) - *fbar;
        !           260:                                *fbar += bardif;
        !           261:                                *fcur += bardif;
        !           262:                        }
        !           263:                }
        !           264:                if(!(opts & UIFC_FP_MSKNOCHG)
        !           265:                                && (mevnt.endx >= SCRN_LEFT + 1
        !           266:                                        && mevnt.endx <= SCRN_LEFT + width - 2
        !           267:                                        && mevnt.endy == SCRN_TOP + height - 3)) {
        !           268:                        newfield = MASK_FIELD;
        !           269:                        ungetmouse(&mevnt);
        !           270:                }
        !           271:                if(opts & UIFC_FP_ALLOWENTRY
        !           272:                                && mevnt.endx >= SCRN_LEFT + 1
        !           273:                                && mevnt.endx <= SCRN_LEFT + width - 2
        !           274:                                && mevnt.endy == SCRN_TOP + height - 2) {
        !           275:                        newfield = CURRENT_PATH;
        !           276:                        ungetmouse(&mevnt);
        !           277:                }
        !           278:        }
        !           279:        return(newfield);
        !           280: }
        !           281: 
        !           282: int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char *msk, int opts)
        !           283: {
        !           284:        char    cfile[MAX_PATH*5+1];            /* Current full path to file */
        !           285:        char    cpath[MAX_PATH+1];                      /* Current path */
        !           286:        char    drive[3];
        !           287:        char    tdir[MAX_PATH+1];
        !           288:        char    fname[MAX_PATH+1];
        !           289:        char    ext[MAX_PATH+1];
        !           290:        char    cmsk[MAX_PATH*4+1];                     /* Current file mask */
        !           291:        char    cglob[MAX_PATH*4+1];            /* File glob patter */
        !           292:        char    dglob[MAX_PATH*4+1];            /* Directory glob pattern */
        !           293:        char    *p;
        !           294:        glob_t  fgl;                                            /* Files */
        !           295:        glob_t  dgl;                                            /* Directories */
        !           296:        int             dircur=0;
        !           297:        int             dirbar=0;
        !           298:        int             filecur=0;
        !           299:        int             filebar=0;
        !           300:        int             listwidth;
        !           301:        char    **dir_list=NULL;
        !           302:        char    **file_list=NULL;
        !           303:        int             currfield=DIR_LIST;
        !           304:        int             lastfield=DIR_LIST;
        !           305:        int             i;
        !           306:        int             root=0;                                         /* Is this the root of the file system? */
        !           307:                                                                                /* On *nix, this just means no .. on Win32,
        !           308:                                                                                 * Something should be done about drive letters. */
        !           309:        int             reread=FALSE;
        !           310:        int             lbclr;
        !           311:        char    *lastpath=NULL;
        !           312:        char    *tmplastpath=NULL;
        !           313:        char    *tmppath=NULL;
        !           314:        int             width;
        !           315:        int             height;
        !           316:        char    *YesNo[]={"Yes", "No", ""};
        !           317:        int             finished=FALSE;
        !           318:        int             retval=0;
        !           319:        int             fieldmove;
        !           320: 
        !           321:        height=api->scrn_len-3;
        !           322:        width=SCRN_RIGHT-SCRN_LEFT-3;
        !           323: 
        !           324:        lbclr=api->lbclr;
        !           325: 
        !           326:        /* No struct passed */
        !           327:        if(fp==NULL)
        !           328:                return(-1);
        !           329: 
        !           330:        /* Illegal options */
        !           331:        if((opts & UIFC_FP_MULTI)==UIFC_FP_MULTI && (opts & (UIFC_FP_ALLOWENTRY|UIFC_FP_OVERPROMPT|UIFC_FP_CREATPROMPT)))
        !           332:                return(-1);
        !           333: 
        !           334:        fp->files=0;
        !           335:        fp->selected=NULL;
        !           336: 
        !           337:        /* No initial path specified */
        !           338:        if(dir==NULL || !dir[0])
        !           339:                SAFECOPY(cpath,".");
        !           340: 
        !           341:        FULLPATH(cpath,((dir==NULL||dir[0]==0)?".":dir),sizeof(cpath));
        !           342:        backslash(cpath);
        !           343: 
        !           344:        if(msk==NULL || msk[0]==0) {
        !           345:                SAFECOPY(cmsk,"*");
        !           346:        }
        !           347:        else {
        !           348:                SAFECOPY(cmsk,msk);
        !           349:        }
        !           350:        listwidth=SCRN_RIGHT-SCRN_LEFT+1;
        !           351:        listwidth-=listwidth%2;
        !           352:        listwidth-=3;
        !           353:        listwidth/=2;
        !           354:        /* Draw the file picker itself... */
        !           355:        hold_update = TRUE;
        !           356:        drawfpwindow(api);
        !           357:        /* Display the title centered */
        !           358:        i=strlen(title);
        !           359:        if(i>width-4)
        !           360:                i=width-4;
        !           361:        api->printf(SCRN_LEFT+2, SCRN_TOP+1, api->hclr|(api->bclr<<4), "%*s%-*s", (width-i)/2-2, "", i, title);
        !           362:        api->printf(SCRN_LEFT+2, SCRN_TOP+height-3, api->hclr|(api->bclr<<4), "Mask: ");
        !           363:        while(!finished) {
        !           364:                hold_update = TRUE;
        !           365:                api->printf(SCRN_LEFT+8, SCRN_TOP+height-3, api->lclr|(api->bclr<<4), "%-*s", width-7, cmsk);
        !           366:                tmppath=strdup(cpath);
        !           367:                if(tmppath != NULL)
        !           368:                        FULLPATH(cpath,tmppath,sizeof(cpath));
        !           369:                FREE_AND_NULL(tmppath);
        !           370: 
        !           371: #ifdef __unix__
        !           372:                if(cpath[0]==0) {
        !           373:                        cpath[0]='/';
        !           374:                        cpath[1]=0;
        !           375:                }
        !           376: #endif
        !           377:                backslash(cpath);
        !           378:                sprintf(cglob,"%s%s",cpath,(opts&UIFC_FP_MSKCASE)?cmsk:insensitive_mask(cmsk));
        !           379:                sprintf(dglob,"%s*",cpath);
        !           380:                switch(currfield) {
        !           381:                        case DIR_LIST:
        !           382:                                if(lastfield==DIR_LIST)
        !           383:                                        sprintf(cfile,"%s%s",cpath,cmsk);
        !           384:                                break;
        !           385:                }
        !           386: 
        !           387: #ifdef __unix__
        !           388:                if(cpath[0]==0) {
        !           389:                        cpath[0]='/';
        !           390:                        cpath[1]=0;
        !           391:                }
        !           392:                if(cpath[1]==0)
        !           393:                        root=TRUE;
        !           394:                else
        !           395:                        root=FALSE;
        !           396: #else
        !           397: /* #error Need to do something about root paths (in get_file_opt_list() too!) */
        !           398: #endif
        !           399:                if(glob(dglob, GLOB_MARK, NULL, &dgl)!=0 && !isdir(cpath)) {
        !           400:                        if(lastpath==NULL) {
        !           401:                                fp->files=0;
        !           402:                                retval=-1;
        !           403:                                goto cleanup;
        !           404:                        }
        !           405:                        hold_update=FALSE;
        !           406:                        api->msg("Cannot read directory!");
        !           407:                        SAFECOPY(cpath, lastpath);
        !           408:                        FREE_AND_NULL(lastpath);
        !           409:                        currfield=lastfield;
        !           410:                        continue;
        !           411:                }
        !           412:                if(glob(cglob, 0, NULL, &fgl)!=0)
        !           413:                        fgl.gl_pathc=0;
        !           414:                api->list_height=api->scrn_len-3-7;
        !           415:                dir_list=get_file_opt_list(dgl.gl_pathv, dgl.gl_pathc, TRUE, root);
        !           416:                file_list=get_file_opt_list(fgl.gl_pathv, fgl.gl_pathc, FALSE, root);
        !           417:                globfree(&dgl);
        !           418:                globfree(&fgl);
        !           419:                reread=FALSE;
        !           420:                dircur=dirbar=filecur=filebar=0;
        !           421:                while(!reread) {
        !           422:                        hold_update=TRUE;
        !           423:                        display_current_path(api, cfile);
        !           424:                        api->lbclr=api->lclr|(api->bclr<<4);
        !           425:                        api->list(WIN_NOBRDR|WIN_FIXEDHEIGHT|WIN_IMM|WIN_REDRAW,1,3,listwidth,&dircur,&dirbar,NULL,dir_list);
        !           426:                        api->list(WIN_NOBRDR|WIN_FIXEDHEIGHT|WIN_IMM|WIN_REDRAW,1+listwidth+1,3,listwidth,&filecur,&filebar,NULL,file_list);
        !           427:                        api->lbclr=lbclr;
        !           428:                        lastfield=currfield;
        !           429:                        fieldmove=0;
        !           430:                        hold_update = FALSE;
        !           431:                        switch(currfield) {
        !           432:                                case DIR_LIST:
        !           433:                                        i=api->list(WIN_NOBRDR|WIN_FIXEDHEIGHT|WIN_EXTKEYS|WIN_UNGETMOUSE,1,3,listwidth,&dircur,&dirbar,NULL,dir_list);
        !           434:                                        if(i==-1) {             /* ESC */
        !           435:                                                retval=fp->files=0;
        !           436:                                                goto cleanup;
        !           437:                                        }
        !           438:                                        if(i==-2-'\t')  /* TAB */
        !           439:                                                fieldmove=1;
        !           440:                                        if(i==-3842)    /* Backtab */
        !           441:                                                fieldmove=-1;
        !           442:                                        if(i==-2-CIO_KEY_MOUSE)
        !           443:                                                currfield=mousetofield(currfield, opts, height, width, api->list_height, listwidth, &dircur, &dirbar, &filecur, &filebar);
        !           444:                                        if(i>=0) {
        !           445:                                                FREE_AND_NULL(lastpath);
        !           446:                                                lastpath=strdup(cpath);
        !           447:                                                strcat(cpath,dir_list[i]);
        !           448:                                                reread=TRUE;
        !           449:                                                sprintf(cfile,"%s%s",cpath,cmsk);
        !           450:                                        }
        !           451:                                        break;
        !           452:                                case FILE_LIST:
        !           453:                                        i=api->list(WIN_NOBRDR|WIN_FIXEDHEIGHT|WIN_EXTKEYS|WIN_UNGETMOUSE,1+listwidth+1,3,listwidth,&filecur,&filebar,NULL,file_list);
        !           454:                                        if(i==-1) {
        !           455:                                                retval=fp->files=0;
        !           456:                                                goto cleanup;
        !           457:                                        }
        !           458:                                        if(i>=0) {
        !           459:                                                sprintf(cfile,"%s%s",cpath,file_list[i]);
        !           460:                                                if((opts & UIFC_FP_MULTI)!=UIFC_FP_MULTI) {
        !           461:                                                        retval=fp->files=1;
        !           462:                                                        fp->selected=(char **)malloc(sizeof(char *));
        !           463:                                                        if(fp->selected==NULL) {
        !           464:                                                                fp->files=0;
        !           465:                                                                retval=-1;
        !           466:                                                                goto cleanup;
        !           467:                                                        }
        !           468:                                                        fp->selected[0]=strdup(cfile);
        !           469:                                                        if(fp->selected[0]==NULL) {
        !           470:                                                                FREE_AND_NULL(fp->selected);
        !           471:                                                                fp->files=0;
        !           472:                                                                retval=-1;
        !           473:                                                                goto cleanup;
        !           474:                                                        }
        !           475:                                                        api->list(WIN_NOBRDR|WIN_FIXEDHEIGHT|WIN_IMM|WIN_REDRAW,1+listwidth+1,3,listwidth,&filecur,&filebar,NULL,file_list);
        !           476:                                                        finished=reread=TRUE;
        !           477:                                                }
        !           478:                                        }
        !           479:                                        if(i==-2-'\t')
        !           480:                                                fieldmove=1;
        !           481:                                        if(i==-3842)    /* Backtab */
        !           482:                                                fieldmove=-1;
        !           483:                                        if(i==-2-CIO_KEY_MOUSE)
        !           484:                                                currfield=mousetofield(currfield, opts, height, width, api->list_height, listwidth, &dircur, &dirbar, &filecur, &filebar);
        !           485:                                        break;
        !           486:                                case CURRENT_PATH:
        !           487:                                        FREE_AND_NULL(tmplastpath);
        !           488:                                        tmplastpath=strdup(cpath);
        !           489:                                        api->getstrxy(SCRN_LEFT+2, SCRN_TOP+height-2, width-1, cfile, sizeof(cfile)-1, K_EDIT|K_TABEXIT|K_MOUSEEXIT, &i);
        !           490:                                        if(i==ESC) {
        !           491:                                                retval=fp->files=0;
        !           492:                                                goto cleanup;
        !           493:                                        }
        !           494:                                        if((opts & (UIFC_FP_FILEEXIST|UIFC_FP_PATHEXIST)) && !fexist(cfile)) {
        !           495:                                                FREE_AND_NULL(tmplastpath);
        !           496:                                                api->msg("No such path/file!");
        !           497:                                                continue;
        !           498:                                        }
        !           499:                                        if(isdir(cfile))
        !           500:                                                backslash(cfile);
        !           501:                                        _splitpath(cfile, drive, tdir, fname, ext);
        !           502:                                        sprintf(cpath,"%s%s",drive,tdir);
        !           503:                                        if(!isdir(cpath)) {
        !           504:                                                FREE_AND_NULL(tmplastpath);
        !           505:                                                api->msg("No such path!");
        !           506:                                                continue;
        !           507:                                        }
        !           508:                                        if(i==CIO_KEY_MOUSE)
        !           509:                                                currfield=mousetofield(currfield, opts, height, width, api->list_height, listwidth, &dircur, &dirbar, &filecur, &filebar);
        !           510:                                        if(i==3840)
        !           511:                                                fieldmove=-1;
        !           512:                                        else {
        !           513:                                                if(currfield == CURRENT_PATH)
        !           514:                                                        fieldmove=1;
        !           515:                                        }
        !           516:                                        sprintf(cfile,"%s%s%s%s",drive,tdir,fname,ext);
        !           517:                                        if(strchr(fname,'*') !=NULL || strchr(fname,'?') !=NULL
        !           518:                                                || strchr(ext,'*') !=NULL || strchr(ext,'?') !=NULL
        !           519:                                                || (isdir(cfile) && !(opts & UIFC_FP_DIRSEL) && (i=='\r' || i=='\n'))
        !           520:                                                || (!isdir(cfile) && i!='\r' && i!='\n')) {
        !           521:                                                if(opts & UIFC_FP_MSKNOCHG) {
        !           522:                                                        sprintf(cfile,"%s%s%s",drive,tdir,cmsk);
        !           523:                                                        FREE_AND_NULL(tmplastpath);
        !           524:                                                        api->msg("File mask cannot be changed");
        !           525:                                                        continue;
        !           526:                                                }
        !           527:                                                else {
        !           528:                                                        if(!isdir(cfile))
        !           529:                                                                sprintf(cmsk, "%s%s", fname, ext);
        !           530:                                                        reread=TRUE;
        !           531:                                                }
        !           532:                                                break;
        !           533:                                        }
        !           534:                                        else {
        !           535:                                                if((opts & UIFC_FP_MULTI)!=UIFC_FP_MULTI && (i=='\r' || i!='\n'))
        !           536:                                                fieldmove=0;
        !           537:                                        }
        !           538:                                        if((currfield != CURRENT_PATH) || fieldmove)
        !           539:                                                break;
        !           540:                                        if(isdir(cfile)) {
        !           541:                                                if((opts & UIFC_FP_MULTI)!=UIFC_FP_MULTI && i!='\t' && i != 3840) {
        !           542:                                                        if(opts & UIFC_FP_DIRSEL) {
        !           543:                                                                finished=reread=TRUE;
        !           544:                                                                retval=fp->files=1;
        !           545:                                                                fp->selected=(char **)malloc(sizeof(char *));
        !           546:                                                                if(fp->selected==NULL) {
        !           547:                                                                        fp->files=0;
        !           548:                                                                        retval=-1;
        !           549:                                                                        goto cleanup;
        !           550:                                                                }
        !           551:                                                                fp->selected[0]=strdup(cfile);
        !           552:                                                                if(fp->selected[0]==NULL) {
        !           553:                                                                        free(fp->selected);
        !           554:                                                                        fp->files=0;
        !           555:                                                                        retval=-1;
        !           556:                                                                        goto cleanup;
        !           557:                                                                }
        !           558:                                                        }
        !           559:                                                }
        !           560:                                                SAFECOPY(cpath, cfile);
        !           561:                                                backslash(cfile);
        !           562:                                                strcat(cfile,cmsk);
        !           563:                                        }
        !           564:                                        if(tmplastpath != NULL) {
        !           565:                                                if(strcmp(tmplastpath, cpath)) {
        !           566:                                                        reread=TRUE;
        !           567:                                                        FREE_AND_NULL(lastpath);
        !           568:                                                        lastpath=tmplastpath;
        !           569:                                                        tmplastpath=NULL;
        !           570:                                                }
        !           571:                                        }
        !           572:                                        FREE_AND_NULL(tmplastpath);
        !           573:                                        if((opts & UIFC_FP_MULTI)!=UIFC_FP_MULTI && i!='\t' && i!=3840) {
        !           574:                                                retval=fp->files=1;
        !           575:                                                fp->selected=(char **)malloc(sizeof(char *));
        !           576:                                                if(fp->selected==NULL) {
        !           577:                                                        fp->files=0;
        !           578:                                                        retval=-1;
        !           579:                                                        goto cleanup;
        !           580:                                                }
        !           581:                                                fp->selected[0]=strdup(cfile);
        !           582:                                                if(fp->selected[0]==NULL) {
        !           583:                                                        FREE_AND_NULL(fp->selected);
        !           584:                                                        fp->files=0;
        !           585:                                                        retval=-1;
        !           586:                                                        goto cleanup;
        !           587:                                                }
        !           588:                                                finished=reread=TRUE;
        !           589:                                        }
        !           590:                                        break;
        !           591:                                case MASK_FIELD:
        !           592:                                        p=strdup(cmsk);
        !           593:                                        api->getstrxy(SCRN_LEFT+8, SCRN_TOP+height-3, width-7, cmsk, sizeof(cmsk)-1, K_EDIT|K_TABEXIT|K_MOUSEEXIT, &i);
        !           594:                                        if(i==CIO_KEY_MOUSE)
        !           595:                                                currfield=mousetofield(currfield, opts, height, width, api->list_height, listwidth, &dircur, &dirbar, &filecur, &filebar);
        !           596:                                        if(i==ESC) {
        !           597:                                                retval=fp->files=0;
        !           598:                                                goto cleanup;
        !           599:                                        }
        !           600:                                        if(strcmp(cmsk, p)) {
        !           601:                                                sprintf(cfile,"%s%s",cpath,cmsk);
        !           602:                                                reread=TRUE;
        !           603:                                        }
        !           604:                                        FREE_AND_NULL(p);
        !           605:                                        if(i==3840)
        !           606:                                                fieldmove=-1;
        !           607:                                        else
        !           608:                                                fieldmove=1;
        !           609:                                        break;
        !           610:                        }
        !           611:                        currfield+=fieldmove;
        !           612:                        if(currfield<0)
        !           613:                                currfield=FIELD_LIST_TERM-1;
        !           614:                        while(1) {
        !           615:                                if(currfield==MASK_FIELD && (opts & UIFC_FP_MSKNOCHG)) {
        !           616:                                        currfield+=fieldmove;
        !           617:                                        continue;
        !           618:                                }
        !           619:                                if(currfield==CURRENT_PATH && !(opts & UIFC_FP_ALLOWENTRY)) {
        !           620:                                        currfield+=fieldmove;
        !           621:                                        continue;
        !           622:                                }
        !           623:                                break;
        !           624:                        }
        !           625:                        if(currfield==FIELD_LIST_TERM)
        !           626:                                currfield=DIR_LIST;
        !           627:                }
        !           628:                free_opt_list(&file_list);
        !           629:                free_opt_list(&dir_list);
        !           630:                if(finished) {
        !           631:                        if((opts & UIFC_FP_OVERPROMPT) && fexist(cfile)) {
        !           632:                                if(api->list(WIN_MID|WIN_SAV, 0,0,0, &i, NULL, "File exists, overwrite?", YesNo)!=0)
        !           633:                                        finished=FALSE;
        !           634:                        }
        !           635:                        if((opts & UIFC_FP_CREATPROMPT) && !fexist(cfile)) {
        !           636:                                if(api->list(WIN_MID|WIN_SAV, 0,0,0, &i, NULL, "File does not exist, create?", YesNo)!=0)
        !           637:                                        finished=FALSE;
        !           638:                        }
        !           639:                }
        !           640:        }
        !           641: 
        !           642: cleanup:               /* Cleans up allocated variables returns from function */
        !           643:        FREE_AND_NULL(lastpath);
        !           644:        FREE_AND_NULL(tmppath);
        !           645:        FREE_AND_NULL(tmplastpath);
        !           646:        free_opt_list(&file_list);
        !           647:        free_opt_list(&dir_list);
        !           648:        return(retval);
        !           649: }
        !           650: 
        !           651: int filepick_free(struct file_pick *fp)
        !           652: {
        !           653:        int i;
        !           654: 
        !           655:        for(i=0; i<fp->files; i++) {
        !           656:                FREE_AND_NULL(fp->selected[i]);
        !           657:        }
        !           658:        FREE_AND_NULL(fp->selected);
        !           659:        return(0);
        !           660: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.