/* * SelectItem - select item to set from a menu */ vi_rc SelectItem( selectitem *si ) { int j; file *cfile; selflinedata sfd; vi_rc rc; tempFileSetup( &cfile, si->list, si->maxlist, 0, false ); /* * get selected line */ memset( &sfd, 0, sizeof( sfd ) ); sfd.f = cfile; sfd.wi= si->wi; sfd.title = si->title; sfd.allow_rl = si->allowrl; sfd.hilite = si->hilite; sfd.show_lineno = si->show_lineno; sfd.retevents = si->retevents; sfd.event = si->event; sfd.cln = si->cln; sfd.eiw = si->eiw; sfd.is_menu = si->is_menu; rc = SelectLineInFile( &sfd ); si->event = sfd.event; if( rc == ERR_NO_ERR ) { if( sfd.sl == -1 || sfd.sl == 0 ) { if( si->result != NULL ) { si->result[0] = 0; } si->num = -1; } else { j = (int) sfd.sl - 1; if( si->result != NULL ) { strcpy( si->result, si->list[j] ); } si->num = j; } } /* * done, free memory */ if( cfile != NULL ) { FreeEntireFile( cfile ); } DCDisplayAllLines(); return( rc ); } /* SelectItem */
/* * SelectItemAndValue - select item from list and give it a value */ vi_rc SelectItemAndValue( window_info *wi, char *title, char **list, int maxlist, vi_rc (*updatertn)( char *, char *, int * ), int indent, char **vals, int valoff ) { // int j; file *cfile; selflinedata sfd; vi_rc rc; tempFileSetup( &cfile, list, maxlist, indent, true ); for( ;; ) { /* * go get selected line */ memset( &sfd, 0, sizeof( sfd ) ); sfd.f = cfile; sfd.wi = wi; sfd.title = title; sfd.checkres = updatertn; sfd.cln = 1; sfd.eiw = NO_WINDOW; sfd.vals = vals; sfd.valoff = valoff; rc = SelectLineInFile( &sfd ); if( rc != ERR_NO_ERR ) { break; } if( sfd.sl == -1 ) { break; } // j = (int) sfd.sl - 1; } /* * done, free memory */ if( cfile != NULL ) { FreeEntireFile( cfile ); } DCDisplayAllLines(); return( rc ); } /* SelectItemAndValue */
/* * SelectFileOpen - select file from specified directory */ vi_rc SelectFileOpen( char *dir, char **result_ptr, char *mask, bool want_all_dirs ) { char dd[FILENAME_MAX], cdir[FILENAME_MAX]; int j; file *cfile; fcb *cfcb; line *cline; selflinedata sfd; bool need_entire_path; char *result = *result_ptr; vi_rc rc; /* * get current directory */ strcpy( dd, dir ); strcpy( cdir, dir ); SetCWD( dir ); need_entire_path = FALSE; /* * work through all files */ for( ;; ) { if( dd[strlen( dd ) - 1] != FILE_SEP ) { strcat( dd, FILE_SEP_STR ); } strcat( dd, mask ); rc = GetSortDir( dd, want_all_dirs ); if( rc != ERR_NO_ERR ) { return( rc ); } /* * allocate temporary file structure */ cfile = FileAlloc( NULL ); FormatDirToFile( cfile, TRUE ); /* * go get selected line */ memset( &sfd, 0, sizeof( sfd ) ); sfd.f = cfile; sfd.wi = &dirw_info; sfd.title = CurrentDirectory; sfd.show_lineno = TRUE; sfd.cln = 1; sfd.eiw = NO_WINDOW; rc = SelectLineInFile( &sfd ); if( rc != ERR_NO_ERR ) { break; } if( sfd.sl == -1 ) { result[0] = 0; break; } j = (int) sfd.sl - 1; if( j >= DirFileCount || DirFiles[j]->attr & _A_SUBDIR ) { if( j >= DirFileCount ) { GimmeLinePtr( j + 1, cfile, &cfcb, &cline ); dd[0] = cline->data[3]; dd[1] = ':'; dd[2] = 0; } else { strcpy( dd, cdir ); if( dd[strlen(dd) - 1] != FILE_SEP ) { strcat( dd, FILE_SEP_STR ); } strcat( dd, DirFiles[j]->name ); } FreeEntireFile( cfile ); rc = SetCWD( dd ); if( rc != ERR_NO_ERR ) { return( rc ); } need_entire_path = TRUE; strcpy( cdir, CurrentDirectory ); strcpy( dd, CurrentDirectory ); continue; } if( need_entire_path ) { strcpy( result, CurrentDirectory ); if( result[strlen(result) - 1] != FILE_SEP ) { strcat( result, FILE_SEP_STR ); } } else { result[0] = 0; } strcat( result, DirFiles[j]->name ); break; } /* * done, free memory */ FreeEntireFile( cfile ); DCDisplayAllLines(); return( rc ); } /* SelectFileOpen */