int openf(char* buf) { // Load first cluster of a file in buffer if (movefirstdirentry()) return -1; while(cmpname(buf,curdirentry.DIR_Name)) if (movenextdirentry()) return -2; if (!(curdirentry.DIR_Attr & ATT_DIRECTORY)) { if (sdmmc_sdcard_readsectors(lba_addr(curdirentry.DIR_FstClus),1,(void*)&filesect)) return FAT_ERR_SDREAD; curfilesect = lba_addr(curdirentry.DIR_FstClus); curfile.DIR_Attr = curdirentry.DIR_Attr; curfile.DIR_FstClus = curdirentry.DIR_FstClus; curfile.DIR_FileSize = curdirentry.DIR_FileSize;; return (filesectorcount=curfilesectorcluster=0); } return -1; }
int changedir(char* buf) { // Change current directory uint8_t i; if ((buf[0]==0)) return -1; if ((buf[0]=='\\')&&(buf[1]==0)) { if (sdmmc_sdcard_readsectors(lba_addr(fat.BPB_RootClus),1,(void*)§)) return FAT_ERR_SDREAD; curdirsect = lba_addr(fat.BPB_RootClus); curdirsectorcluster=0; curdir.DIR_Name[0]='\\'; curdir.DIR_Name[1]=0x20; curdir.DIR_Name[2]=0x20; curdir.DIR_Name[3]=0x20; curdir.DIR_Name[4]=0x20; curdir.DIR_Name[5]=0x20; curdir.DIR_Name[6]=0x20; curdir.DIR_Name[7]=0x20; curdir.DIR_Name[8]=0x20; curdir.DIR_Name[9]=0x20; curdir.DIR_Name[10]=0x20; curdir.DIR_Attr = 17; curdir.DIR_FstClus = fat.BPB_RootClus; curdir.DIR_FileSize = 0; direntrycount=0; return 0; } if ((buf[0]=='.')&&(buf[1]==0)) return (direntrycount=0); // note: ".." can be searched like any other dir if (movefirstdirentry()) return -1; while(cmpname(buf,curdirentry.DIR_Name)) if (movenextdirentry()) return -2; if (curdirentry.DIR_Attr & ATT_DIRECTORY) { if (sdmmc_sdcard_readsectors(lba_addr(curdirentry.DIR_FstClus),1,(void*)§)) return FAT_ERR_SDREAD; curdirsect = lba_addr(curdirentry.DIR_FstClus); curdirsectorcluster=0; for (i=0; i<11; i++) curdir.DIR_Name[i]=curdirentry.DIR_Name[i]; curdir.DIR_Attr = curdirentry.DIR_Attr; curdir.DIR_FstClus = curdirentry.DIR_FstClus; curdir.DIR_FileSize = curdirentry.DIR_FileSize;; return (direntrycount=0); } return -1; }
void get_ini_parm(void) { u32t size = 0; void* ini = 0; u32t btype = hlp_boottype(); if (btype==QSBT_FAT || btype==QSBT_SINGLE) ini = hlp_freadfull("QSINIT.INI",&size,0); if (!ini) ini = hlp_freadfull("OS2LDR.INI",&size,0); if (ini) { char* cfgp = (char*)hlp_memrealloc(ini, size+1); char skipeol = 0, lstart = 1, backch = 0, error = 0, // error in string reason = 0, // collecting now: 1 - section name, 2 - key name, 3 - key section = 0; // 1 - config int value = 0, errline = 1, strln =-1; if (!cfgp) return; else ini=cfgp; cfgp[size++]=0; sto_save(STOKEY_INIDATA,cfgp,size,0); while (size--) { char cc=*cfgp++; if (!size) cc='\n'; if (skipeol && cc=='\n') skipeol=0; if (!skipeol) switch (cc) { case ' ' : case '\t': if (strln>0) strln++; break; case '\n': if (strln>0 && reason<3) { backch=1; error=1; break; } errline++; case '\r': { if (strln > 0 || value) { long rc = str2long(cfgp-1-strln); switch (value) { // "DBPORT" case 1: if (rc>0 && !safeMode) hlp_seroutset(rc,0); break; // "BAUDRATE" case 2: hlp_seroutset(0,rc); break; // "RESETMODE" case 3: if (rc) { if (rc!=43 && rc!=50) rc=25; vio_setmode(rc); } break; // "NOAF" case 4: useAFio=0; break; // "MFSPRINT" case 5: if (rc>0) mfs_rmcmode=0; break; } strln=0; value=0; } lstart=1; reason=0; break; } case '=' : if (reason==2 && strln>0) { value=0; if (section==1) { // "config" int ii=0; while (strList[ii]) if (!cmpname(strList[ii++], cfgp-1, strln)) { value=ii; break; } } if (!value) skipeol=1; else reason=3; strln=0; } else error=1; break; case ';' : if (lstart) skipeol=1; else if ( strln> 0 ) strln++; break; case '[' : if (lstart) { strln=0; reason=1; section=0; } else error=1; break; case ']' : if (reason==1 && !lstart) { if (!cmpname("CONFIG", cfgp-1, strln)) section=1; else section=0; strln=0; skipeol=1; } else error=1; reason=0; break; default: if (lstart==1 && section) { reason=2; strln=0; } lstart=0; if (strln>=0) strln++; } if (backch) { *--cfgp=cc; size++; backch=0; } if (error) { skipeol=1; error=0; reason=0; strln=0; } } //hlp_memfree(ini); } else { #ifdef INITDEBUG serial_init(ComPortAddr = 0x2F8); #endif } log_printf("hi!\n"); log_printf("%s\n",aboutstr); }
int fileselector(char *name, char *path, char *filter, char *title, int filemode) { int c, d, scrrep; int color; int files; int filepos = 0; int fileview = 0; int lastclick = 0; int lastfile = 0; int lowest; int exitfilesel; DIR *dir; struct dirent *de; struct stat st; #ifdef __WIN32__ char drivestr[] = "A:\\"; char driveexists[26]; #endif char cmpbuf[MAX_PATHNAME]; char tempname[MAX_PATHNAME]; // Set initial path (if any) if (strlen(path)) chdir(path); // Scan for all existing drives #ifdef __WIN32__ for (c = 0; c < 26; c++) { drivestr[0] = 'A'+c; if (GetDriveType(drivestr) > 1) driveexists[c] = 1; else driveexists[c] = 0; } #endif // Read new directory NEWPATH: getcwd(path, MAX_PATHNAME); files = 0; // Deallocate old names for (c = 0; c < MAX_DIRFILES; c++) { if (direntry[c].name) { free(direntry[c].name); direntry[c].name = NULL; } } #ifdef __WIN32__ // Create drive letters for (c = 0; c < 26; c++) { if (driveexists[c]) { drivestr[0] = 'A'+c; direntry[files].name = strdup(drivestr); direntry[files].attribute = 2; files++; } } #endif // Process directory #ifdef __amigaos__ dir = opendir(""); #else dir = opendir("."); #endif if (dir) { char *filtptr = strstr(filter, "*"); if (!filtptr) filtptr = filter; else filtptr++; for (c = 0; c < strlen(filter); c++) filter[c] = tolower(filter[c]); while ((de = readdir(dir))) { if ((files < MAX_DIRFILES) && (strlen(de->d_name) < MAX_FILENAME)) { direntry[files].name = strdup(de->d_name); direntry[files].attribute = 0; stat(de->d_name, &st); if (st.st_mode & S_IFDIR) { direntry[files].attribute = 1; files++; } else { int c; // If a file, must match filter strcpy(cmpbuf, de->d_name); if ((!strcmp(filtptr, "*")) || (!strcmp(filtptr, ".*"))) files++; else { for (c = 0; c < strlen(cmpbuf); c++) cmpbuf[c] = tolower(cmpbuf[c]); if (strstr(cmpbuf, filtptr)) files++; else { free(direntry[files].name); direntry[files].name = NULL; } } } } } closedir(dir); } // Sort the filelist in a most horrible fashion for (c = 0; c < files; c++) { lowest = c; for (d = c+1; d < files; d++) { if (direntry[d].attribute < direntry[lowest].attribute) { lowest = d; } else { if (direntry[d].attribute == direntry[lowest].attribute) { if (cmpname(direntry[d].name, direntry[lowest].name) < 0) { lowest = d; } } } } if (lowest != c) { DIRENTRY swaptemp = direntry[c]; direntry[c] = direntry[lowest]; direntry[lowest] = swaptemp; } } // Search for the current filename fileview = 0; filepos = 0; for (c = 0; c < files; c++) { if ((!direntry[c].attribute) && (!cmpname(name, direntry[c].name))) { filepos = c; } } exitfilesel = -1; while (exitfilesel < 0) { int cc = cursorcolortable[cursorflash]; if (cursorflashdelay >= 6) { cursorflashdelay %= 6; cursorflash++; cursorflash &= 3; } fliptoscreen(); getkey(); if (lastclick) lastclick--; if (win_quitted) { exitprogram = 1; for (c = 0; c < MAX_DIRFILES; c++) { if (direntry[c].name) { free(direntry[c].name); direntry[c].name = NULL; } } return 0; } if (mouseb) { // Cancel (click outside) if ((mousey < 3) || (mousey > 3+VISIBLEFILES+6) || (mousex <= 4+10) || (mousex >= 75+10)) { if ((!prevmouseb) && (lastclick)) exitfilesel = 0; } // Select dir,name,filter if ((mousey >= 3+VISIBLEFILES+3) && (mousey <= 3+VISIBLEFILES+5) && (mousex >= 14+10) && (mousex <= 73+10)) { filemode = mousey - (3+VISIBLEFILES+3) + 1; if ((filemode == 3) && (!prevmouseb) && (lastclick)) goto ENTERFILE; } // Select file from list if ((mousey >= 3) && (mousey <= 3+VISIBLEFILES+2) && (mousex >= 6+10) && (mousex <= 73+10)) { filemode = 0; filepos = mousey - 4 - 1 + fileview; if (filepos < 0) filepos = 0; if (filepos > files-1) filepos = files - 1; if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name); if ((!prevmouseb) && (lastclick) && (lastfile == filepos)) goto ENTERFILE; } } if (!filemode) { if (((key >= '0') && (key <= '0')) || ((key >= 'a') && (key <= 'z')) || ((key >= 'A') && (key <= 'Z'))) { char k = tolower(key); int oldfilepos = filepos; for (filepos = oldfilepos + 1; filepos < files; filepos++) if (tolower(direntry[filepos].name[0]) == k) break; if (filepos >= files) { for (filepos = 0; filepos < oldfilepos; filepos++) if (tolower(direntry[filepos].name[0]) == k) break; } if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name); } } switch(rawkey) { case KEY_ESC: exitfilesel = 0; break; case KEY_BACKSPACE: if (!filemode) { #ifdef __amigaos__ chdir("/"); #else chdir(".."); #endif goto NEWPATH; } break; case KEY_HOME: if (!filemode) { filepos = 0; if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name); } break; case KEY_END: if (!filemode) { filepos = files-1; if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name); } break; case KEY_PGUP: for (scrrep = PGUPDNREPEAT; scrrep; scrrep--) { if ((!filemode) && (filepos > 0)) { filepos--; if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name); } } break; case KEY_UP: if ((!filemode) && (filepos > 0)) { filepos--; if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name); } break; case KEY_PGDN: for (scrrep = PGUPDNREPEAT; scrrep; scrrep--) { if ((!filemode) && (filepos < files-1)) { filepos++; if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name); } } break; case KEY_DOWN: if ((!filemode) && (filepos < files-1)) { filepos++; if (!direntry[filepos].attribute) strcpy(name, direntry[filepos].name); } break; case KEY_TAB: if (!shiftpressed) { filemode++; if (filemode > 3) filemode = 0; } else { filemode--; if (filemode < 0) filemode = 3; } break; case KEY_ENTER: ENTERFILE: switch(filemode) { case 0: switch (direntry[filepos].attribute) { case 0: strcpy(name, direntry[filepos].name); exitfilesel = 1; break; case 1: chdir(direntry[filepos].name); goto NEWPATH; case 2: strcpy(tempname, direntry[filepos].name); if (strlen(tempname)) { if (tempname[strlen(tempname)-1] != '\\') strcat(tempname, "\\"); } chdir(tempname); goto NEWPATH; } break; case 1: chdir(path); case 2: filemode = 0; goto NEWPATH; case 3: exitfilesel = 1; break; } break; } switch(filemode) { case 1: editstring(path, MAX_PATHNAME); break; case 2: editstring(filter, MAX_FILENAME); break; case 3: editstring(name, MAX_FILENAME); break; } // Validate filelist view if (filepos < fileview) fileview = filepos; if (filepos - fileview >= VISIBLEFILES) fileview = filepos - VISIBLEFILES + 1; // Refresh fileselector display if (isplaying()) printstatus(); for (c = 0; c < VISIBLEFILES+7; c++) { printblank(50-(MAX_FILENAME+10)/2, 3+c, MAX_FILENAME+10); } drawbox(50-(MAX_FILENAME+10)/2, 3, 15, MAX_FILENAME+10, VISIBLEFILES+7); printblankc(50-(MAX_FILENAME+10)/2+1, 4, 15+16,MAX_FILENAME+8); printtext(50-(MAX_FILENAME+10)/2+1, 4, 15+16, title); for (c = 0; c < VISIBLEFILES; c++) { if ((fileview+c >= 0) && (fileview+c < files)) { switch (direntry[fileview+c].attribute) { case 0: sprintf(textbuffer, "%-60s ", direntry[fileview+c].name); break; case 1: sprintf(textbuffer, "%-60s <DIR>", direntry[fileview+c].name); break; case 2: sprintf(textbuffer, "%-60s <DRV>", direntry[fileview+c].name); break; } } else { sprintf(textbuffer, " "); } color = CNORMAL; if ((fileview+c) == filepos) color = CEDIT; textbuffer[68] = 0; printtext(50-(MAX_FILENAME+10)/2+1, 5+c, color, textbuffer); if ((!filemode) && ((fileview+c) == filepos)) printbg(50-(MAX_FILENAME+10)/2+1, 5+c, cc, 68); } printtext(50-(MAX_FILENAME+10)/2+1, 6+VISIBLEFILES, 15, "PATH: "); sprintf(textbuffer, "%-60s", path); textbuffer[MAX_FILENAME] = 0; color = CNORMAL; if (filemode == 1) color = CEDIT; printtext(50-(MAX_FILENAME+10)/2+9, 6+VISIBLEFILES, color, textbuffer); if ((filemode == 1) && (strlen(path) < MAX_FILENAME)) printbg(50-(MAX_FILENAME+10)/2+9+strlen(path), 6+VISIBLEFILES, cc, 1); printtext(50-(MAX_FILENAME+10)/2+1, 7+VISIBLEFILES, 15, "FILTER: "); sprintf(textbuffer, "%-60s", filter); textbuffer[MAX_FILENAME] = 0; color = CNORMAL; if (filemode == 2) color = CEDIT; printtext(50-(MAX_FILENAME+10)/2+9, 7+VISIBLEFILES, color, textbuffer); if (filemode == 2) printbg(50-(MAX_FILENAME+10)/2+9+strlen(filter), 7+VISIBLEFILES, cc, 1); printtext(50-(MAX_FILENAME+10)/2+1, 8+VISIBLEFILES, 15, "NAME: "); sprintf(textbuffer, "%-60s", name); textbuffer[MAX_FILENAME] = 0; color = CNORMAL; if (filemode == 3) color = CEDIT; printtext(50-(MAX_FILENAME+10)/2+9, 8+VISIBLEFILES, color, textbuffer); if (filemode == 3) printbg(50-(MAX_FILENAME+10)/2+9+strlen(name), 8+VISIBLEFILES, cc, 1); if (win_quitted) exitfilesel = 0; if ((mouseb) && (!prevmouseb)) { lastclick = DOUBLECLICKDELAY; lastfile = filepos; } } // Deallocate all used names for (c = 0; c < MAX_DIRFILES; c++) { if (direntry[c].name) { free(direntry[c].name); direntry[c].name = NULL; } } // Restore screen & exit printmainscreen(); return exitfilesel; }