WORD file_exists(BYTE *dir, BYTE *name) { BYTE f_name[80]; strcpy( dir, f_name ); strcat( f_name, name ); #if GEMDOS return( Fsfirst( ADDR(f_name), 0 ) ); #else return( dos_sfirst( ADDR(f_name), 0 ) ); #endif }
/* * Routine to load in desk accessories. Files by the name of *.ACC * will be loaded. */ static void ldaccs(void) { register WORD i; WORD ret; strcpy(&D.g_dir[0], "*.ACC"); dos_sdta((LONG)D.g_dta); /* if Control is held down then skip loading of accs */ if ((kbshift(-1) & (1<<2))) return; ret = TRUE; for(i=0; (i<NUM_ACCS) && (ret); i++) { ret = (i==0) ? dos_sfirst(D.g_dir, F_RDONLY) : dos_snext(); if (ret) sndcli(&gl_dta[30]); } }
/* * Count up to a maximum of NUM_ACCS desk accessories, saving * their names in acc_name[]. */ static WORD count_accs(void) { WORD i, rc; /* if Control is held down, skip loading of accessories */ if ((Kbshift(-1) & MODE_CTRL)) return 0; strcpy(D.g_work,"*.ACC"); dos_sdta(&D.g_dta); for (i = 0; i < NUM_ACCS; i++) { rc = (i==0) ? dos_sfirst(D.g_work,F_RDONLY) : dos_snext(); if (rc < 0) break; strlcpy(acc_name[i],D.g_dta.d_fname,LEN_ZFNAME); } return i; }
static WORD fs_active(BYTE *ppath, BYTE *pspec, WORD *pcount) { WORD ret; LONG thefile, fs_index, temp; register WORD i, j, gap; BYTE *fname, allpath[LEN_ZPATH+1]; gsx_mfset(ad_hgmice); thefile = 0L; fs_index = 0L; strcpy(allpath, ppath); /* 'allpath' gets all files */ fname = fs_back(allpath,NULL); strcpy(fname+1,"*.*"); dos_sdta((LONG)D.g_dta); ret = dos_sfirst(allpath, F_SUBDIR); while ( ret ) { /* if it is a real file */ /* or directory then */ /* save it and set */ /* first byte to tell */ /* which */ if (D.g_dta[30] != '.') { D.g_dta[29] = (D.g_dta[21] & F_SUBDIR) ? 0x07 : ' '; if ( (D.g_dta[29] == 0x07) || (wildcmp(pspec, &D.g_dta[30])) ) { fs_index = fs_add(thefile, fs_index); thefile++; } } ret = dos_snext(); if (thefile >= nm_files) { ret = FALSE; sound(TRUE, 660, 4); } } *pcount = thefile; /* sort files using shell*/ /* sort on page 108 of */ /* K&R C Prog. Lang. */ for(gap = thefile/2; gap > 0; gap /= 2) { for(i = gap; i < thefile; i++) { for (j = i-gap; j >= 0; j -= gap) { if ( fs_comp(ad_fsnames+g_fslist[j],ad_fsnames+g_fslist[j+gap]) <= 0 ) break; temp = g_fslist[j]; g_fslist[j] = g_fslist[j+gap]; g_fslist[j+gap] = temp; } } } gsx_mfset( ad_armice ); return(TRUE); }
WORD sh_find(BYTE *pspec) { WORD path; BYTE gotdir, *pname; pname = sh_name(pspec); /* get ptr to name */ gotdir = (pname != pspec); dos_sdta((LONG)D.g_dta); /* first, search in the application directory */ if (!gotdir && rlr->p_appdir[0] != '\0') { strcpy(D.g_dir, rlr->p_appdir); strcat(D.g_dir, pname); dos_sfirst(D.g_dir, F_RDONLY | F_SYSTEM); if (!DOS_ERR) { strcpy(pspec, D.g_dir); return 1; } } /* second, search in the current directory */ strcpy(D.g_dir, pspec); /* copy to local buffer */ if (!gotdir) { sh_curdir(D.g_dir); /* get current drive/dir*/ if (D.g_dir[3] != NULL) /* if not at root */ strcat(&D.g_dir[0], "\\"); /* add foreslash */ strcat(&D.g_dir[0], pname); /* append name to drive */ /* and directory. */ /* the actual search will be performed in the loop below */ } /* third, search in the AES path */ path = 0; do { dos_sfirst(D.g_dir, F_RDONLY | F_SYSTEM); if ( (DOS_AX == E_PATHNOTFND) || ((DOS_ERR) && ((DOS_AX == E_NOFILES) || (DOS_AX == E_PATHNOTFND) || (DOS_AX == E_FILENOTFND))) ) { path = sh_path(path, (LONG)D.g_dir, pname); DOS_ERR = TRUE; } else path = 0; } while ( !gotdir && DOS_ERR && path ); /* fourth, search in the current drive root directory */ if (DOS_ERR && !gotdir) { strcpy(D.g_dir, "\\"); strcat(D.g_dir, pname); dos_sfirst(D.g_dir, F_RDONLY | F_SYSTEM); } if (!DOS_ERR) strcpy(pspec, D.g_dir); return(!DOS_ERR); }