WORD wrfile( char *fstr ) { REG int ret, retmsg; int inhand,outhand; int time[2]; DMABUFFER *mydta, *saved; char *buffer; long copysiz, bufsiz, wrsiz, tmpsiz; int crted,sttime; char buf[2]; crted = 0; sttime = 1; retmsg = TRUE; rename = 0; open: /* open the source file */ if ( ( inhand = (WORD)Fopen(fixsrc, 0) ) < 0 ) { /* seek error or drive not ready */ /* if ( (inhand == E_SEEK) || (inhand == EDRVNR) ) return( FALSE ); */ /* skip */ if ( ( ret = fill_string( fixsrc, CNTOPEN ) ) == 1 ) { updatnum(NUMFILE, --numfiles); return SKIP; } else if (ret == 2) /* retry */ goto open; else /* abort */ goto ww_3; } if ( !ch_undo() || f_cancel ) /* user want to stop */ { Fclose( inhand ); ww_3: f_abort = 1; return( FALSE ); } saved = (DMABUFFER *)Fgetdta(); Fsetdta(mydta=(DMABUFFER *)malloc( (long)sizeof(DMABUFFER))); if ( Fsfirst( fixsrc, 0x37 ) ) { retmsg = SKIP; if ( do1_alert( RDERROR ) == 2 ) /* abort */ { f_abort = 1; retmsg = FALSE; } goto y2; } copysiz = mydta->d_fsize; buffer = (char *)malloc( copysiz ); if ( buffer ) { bufsiz = copysiz; } else { for (bufsiz = 128*1024L; bufsiz >= 1024L; bufsiz /= 2) { if ((buffer = (char *)malloc( bufsiz )) != 0) break; } if (!buffer) goto y2; } Fdatime( &time, inhand, 0 ); /* read the time and date */ rechkd: switch(chkdf(fstr, CPFILE)) { case CHECK: goto rechkd; case SKIP: retmsg = SKIP; goto y1; case QUIT: f_abort = 1; retmsg = FALSE; goto y1; case FALSE: retmsg = FALSE; goto y1; } /* if it is move operation, then try rename first */ if ( opcode == OP_MOVE ) { /* if same name and path, don't do it */ if ( strcmp( fixsrc, fixdst ) ) goto y22; Fclose( inhand ); if ( Frename(0, fixsrc, fixdst) >= 0 ) { inhand = (WORD)Fopen( fixdst, 0 ); if ( !p_timedate ) /* get the new time and date */ { time[0] = Tgettime(); time[1] = Tgetdate(); Fdatime( &time, inhand, 1 ); } y22: rename = 1; goto y1; } else inhand = (WORD)Fopen( fixsrc, 0 ); } while ( copysiz >= 0 ) /* let it passes through for zero file */ { tmpsiz = (copysiz > bufsiz) ? bufsiz : copysiz; if (Fread(inhand, tmpsiz, buffer) < 0) { retmsg = SKIP; if ( crted ) Fdelete( fixdst ); if (do1_alert( RDERROR ) == 2) { /* abort */ f_abort = 1; retmsg = FALSE; } goto y1; /* skip */ } create: if ( sttime ) { sttime = 0; if ((outhand = (WORD)Fcreate(fixdst, mydta->d_fattr&7)) < 0) { if ( ( ret = fill_string( fixdst, CNTCRTFL ) ) == 2 ) goto create; else if (ret == 3) /* abort */ { f_abort = 1; retmsg = FALSE; } else retmsg = SKIP; goto y1; } crted = 1; } if ((wrsiz = Fwrite(outhand, tmpsiz, buffer)) < 0) { retmsg = SKIP; Fclose(outhand); Fdelete(fixdst); if (do1_alert( WRERROR ) == 2) { /* abort */ f_abort = 1; retmsg = FALSE; } goto y1; } /* check if there are sufficent memory */ if (wrsiz != tmpsiz) { /* not sufficent memory ??*/ f_abort = 1; retmsg = FALSE; Fclose(outhand); Fdelete(fixdst); buf[0] = *fixdst; buf[1] = 0; fill_string( buf, STDISKFU ); goto y1; } copysiz -= tmpsiz; if ( !copysiz ) break; } if ( p_timedate ) Fdatime( &time, outhand, 1 ); y0: Fclose(outhand); y1: free(buffer); y2: updatnum(NUMFILE, --numfiles); Fsetdta(saved); y3: Fclose(inhand); free(mydta); if ( ( opcode == OP_MOVE ) && ( retmsg == TRUE ) ) upfdesk( fixsrc, fixdst ); return(retmsg); }
LOCAL WORD rs_read (WORD *global, CONST BYTE *fname) { WORD i, fh; BYTE tmpnam[128]; DTA dta, *old_dta; LONG size; WORD ret = TRUE; strcpy (tmpnam, fname); if (!shel_find (tmpnam)) { form_error (-33); return (FALSE); } rs_global = global; old_dta = Fgetdta (); Fsetdta (&dta); if (Fsfirst (tmpnam, 0x10) == 0) size = dta.d_length; else size = 0; Fsetdta (old_dta); if (size > sizeof (RSHDR) && (fh = Fopen (tmpnam, 0)) > 0) { if ((hdr_buf = (RSXHDR *)malloc (size + sizeof (RSXHDR))) != NULL) { (LONG)rs_hdr = (LONG)hdr_buf + sizeof (RSXHDR); if (Fread (fh, size, rs_hdr) == size) { if (((RSHDR *)rs_hdr)->rsh_vrsn == 3) memcpy (hdr_buf, rs_hdr, sizeof (RSXHDR)); else for (i = 0; i < sizeof (RSXHDR) / sizeof (LONG); i++) ((ULONG *)hdr_buf)[i] = ((UWORD *)rs_hdr)[i]; do_rsfix (hdr_buf->rsh_rssize); if (size > hdr_buf->rsh_rssize + 72L) /* Farbicons in der Resource? */ do_ciconfix ((ULONG)rs_hdr, hdr_buf, size); } else ret = FALSE; } else { form_error (-39); ret = FALSE; } Fclose (fh); } else ret = FALSE; return (ret); }
int doact( VOID ) { /* char *saved; */ DMABUFFER *dumb, * saved; REG int ret, retmsg; int error; if ( f_level >= ( COPYMAXDEPTH + 1 ) ) { act_1: do1_alert( STFO8DEE ); return( FALSE ); } /* changed CHAR * to DMABUFFER * in expression below - JTT */ if ( !( dumb = (DMABUFFER *)malloc( (LONG)sizeof( DMABUFFER ) ) ) ) goto act_1; f_level++; retmsg = TRUE; saved = (DMABUFFER *)Fgetdta(); Fsetdta( dumb ); strcat(getall, fixsrc); if ( !( error = Fsfirst(fixsrc, 0x37) ) ) { do { if ( !ch_undo( ) || f_cancel ) /* user want to abort */ { f_abort = 1; retmsg = FALSE; goto mvend; } if (dumb->d_fname[0] != HOME) { if (SUBDIR & dumb->d_fattr) { chkbuf(srclen, srcbuf, &fixsrc); /* check buf size */ addfile(fixsrc, dumb->d_fname); /* add a dir into the path */ strcat(bckslsh, fixsrc); if (opcode != OP_DELETE) { chkbuf(dstlen, dstbuf, &fixdst); /* check buf size */ strcat(dumb->d_fname, fixdst); } else goto dorec; updatbox(dumb->d_fname); rechkd1: /* update check the dir existing or not */ switch( chkdf( dumb->d_fname, CPDIR ) ) { case QUIT: f_abort = 1; retmsg = FALSE; goto mvend; case SKIP: backdir(fixsrc); backdir(fixdst); updatnum(NUMDIR, --numdirs); srclen -= FILE_LEN; /* subtract the add lenth */ dstlen -= FILE_LEN; /* subtract the add lenth */ retmsg = TRUE; continue; case FALSE: goto mvend; case CHECK: goto rechkd1; case OK: recrtd: if (Dcreate(fixdst)) { if ( write_save ) goto kk_1; switch( fill_string( fixdst, CNTCRTDR ) ) { case 1: /* skip */ backdir(fixsrc); backdir(fixdst); updatnum(NUMDIR, --numdirs); srclen -= FILE_LEN; /* subtract the add lenth */ dstlen -= FILE_LEN; /* subtract the add lenth */ continue; case 2: /* retry */ goto recrtd; default: /* quit */ f_abort = 1; retmsg = FALSE; goto mvend; }/* switch */ }/* if recrtd */ break; } kk_1: updatnum(NUMDIR, --numdirs); strcat(bckslsh, fixdst); dorec: if (!doact()) /* do the recursion */ { retmsg = FALSE; goto mvend; } if (opcode == OP_COPY) goto clndir; rmstarb(fixsrc); /* after call, -> c:\d1\ */ if (opcode == OP_DELETE) { getlastpath(filestr, fixsrc); updatbox(filestr); } remvd: if (Ddelete(fixsrc)) { /* delete a dir */ if ( ( ret = fill_string( fixsrc, CNTDELD ) ) == 2 ) goto remvd; /* retry */ else if (ret == 3) { /* abort */ f_abort = 1; retmsg = FALSE; goto mvend; } } else /* No error */ upfdesk( fixsrc, (BYTE*)0 ); clndir: backdir(fixsrc); /* back one dir */ srclen -= FILE_LEN; /* subtract the add lenth */ if (opcode == OP_DELETE) updatnum(NUMDIR, --numdirs); else { backdir(fixdst); /* back one dir */ dstlen -= FILE_LEN; /* subtract the add lenth */ } } else { getlastpath(filestr, fixdst); updatname(CPDIR, filestr); /* update the dir */ updatname( CPFILE, dumb->d_fname ); /* update the file */ chkbuf(srclen, srcbuf, &fixsrc); /* check buf size */ addfile(fixsrc, dumb->d_fname); if (opcode != OP_DELETE) { chkbuf(dstlen, dstbuf, &fixdst); /* check buf size */ addfile(fixdst, dumb->d_fname); rename = 0; if (!(retmsg = wrfile(dumb->d_fname))) goto mvend; if ((rename) || (retmsg == SKIP)) goto clnfile; } if (opcode == OP_COPY) goto clnfile; remvf: if (ret = (WORD)(Fdelete(fixsrc))) /* rm the file from source */ { /* seek error or drive not ready */ /* if ((ret == E_SEEK) || (ret == EDRVNR)) { retmsg = FALSE; goto mvend; } */ /* retry */ if ( ( ret = fill_string( fixsrc, CNTDELF ) ) == 2 ) goto remvf; else if ( ret == 3 ) { /* abort */ f_abort = 1; retmsg = FALSE; goto mvend; } } else upfdesk( fixsrc, (BYTE*)0 ); clnfile: backdir(fixsrc); /* back one dir */ srclen -= FILE_LEN; /* subtract the add lenth */ if (opcode == OP_DELETE) updatnum(NUMFILE, --numfiles); else { backdir(fixdst); /* back one dir */ dstlen -= FILE_LEN; /* subtract the add lenth */ } } } } while (!Fsnext()); } else { if ( error != EFILNF ) /* if not file not found */ retmsg = FALSE; /* then return error */ } mvend: Fsetdta( saved ); f_level--; free( dumb ); return( retmsg ); }
WORD countrec( VOID ) { /* char *saved; */ DMABUFFER *dumb, *saved; REG int retmsg; dumb = (DMABUFFER *)malloc( (LONG)sizeof(DMABUFFER) ); if ( !dumb ) { do1_alert( STFO8DEE ); return( FALSE ); } retmsg = TRUE; saved = (DMABUFFER *)Fgetdta(); /* save the current dta */ Fsetdta( dumb ); if (!Fsfirst(curall, 0x37)) { do { if (dumb->d_fname[0] != HOME) { if (SUBDIR & dumb->d_fattr) { /* setpath to one more down */ if (Dsetpath(dumb->d_fname)) { retmsg = FALSE; goto endrec; } numdirs++; if ( ++f_level > COPYMAXDEPTH ) { do1_alert( STFO8DEE ); retmsg = FALSE; goto endrec; } if (!countrec()) /* to the recursion setpath to one back */ { retmsg = FALSE; goto endrec; } f_level--; if (Dsetpath(baklvl)) { retmsg = FALSE; goto endrec; } } else { numfiles++; /* add up the file count and size */ tolsize += dumb->d_fsize; } } } while (!Fsnext()); } endrec: Fsetdta( saved ); /* reset the dta */ free( dumb ); return(retmsg); }
/* Save_Data() * ====================================================================== */ BOOLEAN Save_Data( void ) { DTA thedta, *saved; int fd; int *DataPtr; long EndIndex; BOOLEAN flag; flag = FALSE; saved = Fgetdta(); Fsetdta( &thedta ); if( Fsfirst( FPath, 0 ) <= -1 ) /* Can't find the file... */ { Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); form_alert( 1, alert2 ); } else { DataBuf = calloc( 1, thedta.d_length * 2L ); if( DataBuf ) { fd = Fopen( FPath, 0 ); if( fd <= 0 ) { form_alert( 1, alert1 ); } else { Buffer = ( long )DataBuf; Buffer = ( Buffer + 15L ) & 0xFFFFFFF0L; DataHdr = ( int *)Buffer; Fread( fd, thedta.d_length, DataHdr ); Fclose( fd ); EndIndex = thedta.d_length; DataPtr = FindString( DataHdr, DataHdr + EndIndex - 8 ); if( DataPtr ) { hdr = ( HEADER *)DataPtr; hdr_buffer.quality = Menu[ MQUALITY ].curvalue; hdr_buffer.nplanes = Menu[ MCOLOR ].curvalue + 1; hdr_buffer.PageSize = Menu[ MPAGESIZE ].curvalue; hdr_buffer.xres = xres_value; hdr_buffer.yres = yres_value; hdr_buffer.port = Menu[ MPORT ].curvalue; hdr_buffer.paper_feed = Menu[ MTRAY ].curvalue; *hdr = hdr_buffer; flag = TRUE; fd = Fcreate( FPath, 0 ); Fwrite( fd, thedta.d_length, DataHdr ); Fclose( fd ); } else { Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); form_alert( 1, alert3 ); } free( DataBuf ); } } else form_alert( 1, alert4 ); } Fsetdta( saved ); return( flag ); }
/* GetCDrivers() * ==================================================================== * Go thru the list of .sys files and try to load them. * Those that we can load, get the header and see if they are of the * new driver type. Get the filenames of those that are printer drivers * and store them in cdriver. Store their index into the driver array * into our cdriver array position. */ void GetCDrivers( void ) { DTA thedta, *saved; int fd; int *DataPtr; long EndIndex; int error; saved = Fgetdta(); Fsetdta( &thedta ); cdriver_count = 0; get_bitpath(); strcpy( FPath, epath ); strcat( FPath, "\\*.SYS"); error = Fsfirst( FPath, 0 ); /* Normal file search for 1st file */ if( error != E_OK ) /* No such files! */ { return; } do { sprintf( line_buf, "%s\\%s", epath, thedta.d_fname ); DataBuf = calloc( 1, thedta.d_length * 2L ); if( DataBuf ) { fd = Fopen( line_buf, 0 ); if( fd > 0 ) { Buffer = ( long )DataBuf; Buffer = ( Buffer + 15L ) & 0xFFFFFFF0L; DataHdr = ( int *)Buffer; Fread( fd, thedta.d_length, DataHdr ); Fclose( fd ); EndIndex = thedta.d_length; DataPtr = FindString( DataHdr, DataHdr + EndIndex - 8 ); if( DataPtr ) /* Look only for new drivers with headers*/ { hdr = ( HEADER *)DataPtr; hdr_buffer = ( HEADER )*hdr; hdr = &hdr_buffer; /* want only those drivers with real page sizes */ if( hdr->config_map & 0x3E ) { /* then get the name...*/ strcpy( cdrivers[ cdriver_count ], hdr->fname ); strcpy( drivers[ cdriver_count ], thedta.d_fname ); cdriver_count++; } } } free( DataBuf ); } else { /* memory error - break out of loop and exit routine */ form_alert( 1, alert4 ); break; } } while ( ( Fsnext() == E_OK ) && ( cdriver_count < MAX_DRIVERS ) ); SortCDriverNames(); Fsetdta( saved ); }
/* get_bitpath() * ==================================================================== * Get the font path from the ASSIGN.SYS * If there is NO ASSIGN.SYS, we substitute C: or A: instead. * */ void get_bitpath( void ) { int i, sys_file; long j; int error; char *fname; int alen; olddma = Fgetdta(); Fsetdta( &newdma ); /* Point to OUR buffer */ strcpy( epath, "C:\\ASSIGN.SYS" ); epath[0] = GetBaseDrive(); bufptr = 0L; BufferSize = 0L; error = Fsfirst( epath, 0 ); /* Normal file search for 1st file */ if( error == 0 ) { /* found it! */ bufptr = calloc( 1, newdma.d_length * 2L ); if( bufptr ) { BufferSize = newdma.d_length; if( (sys_file = Fopen( epath, 0 )) < 0) { Fsetdta( olddma ); /* Point to OLD buffer */ if( bufptr ) { free( bufptr ); bufptr = 0L; } form_alert( 1, alert1 ); return; } path_found = FALSE; do { i = 0; alen = (int)Fread( sys_file, BufferSize, bufptr ); do { if( !strncmp( &bufptr[i], "path", 4) || !strncmp( &bufptr[i], "PATH", 4) ) { strcpy( epath, extract_path( &i, alen ) ); path_found = TRUE; goto done; } else { while(( bufptr[i] != '\n' ) && ( i < alen )) { ++i; /* Skip to newline */ } ++i; } } while( i < alen ); } while( alen == BufferSize ); done: Fclose( sys_file ); if( bufptr ) { free( bufptr ); bufptr = 0L; } j = strlen( epath ); if( epath[ j - 1 ] == '\\' ) epath[ j - 1 ] = '\0'; } else form_alert( 1, alert1 ); } Fsetdta( olddma ); /* Point to OLD buffer */ fname = &epath[0]; fname = strupr( fname ); }
/* Read_Data() * ================================================================ */ BOOLEAN Read_Data( void ) { DTA thedta, *saved; int fd; int *DataPtr; long EndIndex; BOOLEAN flag; flag = FALSE; saved = Fgetdta(); Fsetdta( &thedta ); if( Fsfirst( FPath, 0 ) <= -1 ) /* Can't find the file... */ { Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); form_alert( 1, alert2 ); } else { DataBuf = calloc( 1, thedta.d_length * 2L ); if( DataBuf ) { fd = Fopen( FPath, 0 ); if( fd <= 0 ) { form_alert( 1, alert1 ); } else { Buffer = ( long )DataBuf; Buffer = ( Buffer + 15L ) & 0xFFFFFFF0L; DataHdr = ( int *)Buffer; Fread( fd, thedta.d_length, DataHdr ); Fclose( fd ); EndIndex = thedta.d_length; DataPtr = FindString( DataHdr, DataHdr + EndIndex - 8 ); if( DataPtr ) { hdr = ( HEADER *)DataPtr; hdr_buffer = ( HEADER )*hdr; hdr = &hdr_buffer; strcpy( title, hdr->fname ); flag = TRUE; } else { Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); form_alert( 1, alert3 ); } free( DataBuf ); } } else form_alert( 1, alert4 ); } Fsetdta( saved ); return( flag ); }
int __quickstat (const char *_path, struct stat *st, int lflag) { char tmpbuf[PATH_MAX]; char *path = (char *) _path; int nval; long r; if (!_path) { __set_errno (EFAULT); return -1; } if (*_path == '\0') { __set_errno (ENOENT); return -1; } if (__libc_unix_names) nval = 0; else { /* _unx2dos returns 1 for device names (like /dev/con) */ path = tmpbuf; nval = _unx2dos(_path, path, sizeof (tmpbuf)); } r = __sys_stat (path, st, lflag, 0); if (r != -ENOSYS) { if (r) { if ((r == -ENOTDIR) && _enoent (path)) { r = -ENOENT; } __set_errno (-r); return -1; } return 0; } { char *ext, drv; _DTA d; _DTA *olddta; int isdot = 0; int isdir = 0; __bzero (st, sizeof (*st)); /* Otherwise, check to see if we have a name like CON: or AUX: */ if (nval == 1) { st->st_mode = S_IFCHR | 0600; st->st_flags = 0; st->st_ino = __inode++; st->st_rdev = 0; st->st_mtime = st->st_ctime = st->st_atime = 0; st->st_dev = 0; st->st_nlink = 1; st->st_uid = geteuid(); st->st_gid = getegid(); st->st_size = st->st_blocks = 0; st->st_blksize = 1024; return 0; } /* A file name: check for root directory of a drive */ if (path[0] == '\\' && path[1] == 0) { drv = Dgetdrv() + 'A'; isdir = 1; goto rootdir; } if (((drv = path[0]) != 0) && path[1] == ':' && (path[2] == 0 || (path[2] == '\\' && path[3] == 0)) ) { rootdir: isdir = 1; st->st_mode = S_IFDIR | 0755; st->st_flags = 0; st->st_dev = isupper(drv) ? drv - 'A' : drv - 'a'; st->st_ino = 2; st->st_mtime = st->st_ctime = st->st_atime = 0; goto fill_dir; } /* Forbid wildcards in path names */ if (index(path, '*') || index (path, '?')) { __set_errno (ENOENT); return -1; } /* NOTE: Fsfirst(".",-1) or Fsfirst("..",-1) both fail under TOS, * so we kludge around this by using the fact that Fsfirst(".\*.*" * or "..\*.*" will return the correct file first (except, of course, * in root directories :-( ). * NOTE2: Some versions of TOS don't like Fsfirst("RCS\\", -1) either, * so we do the same thing if the path ends in '\\'. */ /* Find the end of the string. */ for (ext = path; ext[0] && ext[1]; ext++) ; /* Add appropriate kludge if necessary. */ if (*ext == '.' && (ext == path || ext[-1] == '\\' || ext[-1] == '.')) { isdot = 1; strcat (path, "\\*.*"); } else if (*ext == '\\') { isdot = 1; strcat (path, "*.*"); } olddta = Fgetdta(); Fsetdta(&d); r = Fsfirst (path, 0xff); Fsetdta (olddta); if (r < 0) { if (isdot && r == -ENOENT) goto rootdir; __set_errno (-r); return -1; } if (isdot && ((d.dta_name[0] != '.') || (d.dta_name[1]))) { goto rootdir; } if (((drv = *path) != 0) && path[1] == ':') st->st_dev = _toupper (drv) - 'A'; else st->st_dev = Dgetdrv (); st->st_ino = __inode++; st->st_flags = 0; st->st_mode = 0644 | (isdir ? S_IFDIR | 0111 : S_IFREG); if (st->st_flags & FA_RDONLY) st->st_mode &= ~0222; /* no write permission */ if (st->st_flags & FA_HIDDEN) st->st_mode &= ~0444; /* no read permission */ /* Check for a file with an executable extension */ ext = strrchr(_path, '.'); if (ext) { if (!strcmp (ext, ".app") || !strcmp (ext, ".gtp") || !strcmp (ext, ".ttp") || !strcmp (ext, ".prg") || !strcmp (ext, ".tos")) { st->st_mode |= 0111; } } if ((st->st_mode & S_IFMT) == S_IFREG) { st->st_size = d.dta_size; /* In Unix, blocks are measured in 512 bytes */ st->st_blocks = (st->st_size + 511) / 512; st->st_nlink = 1; /* we dont have hard links */ } else { fill_dir: st->st_size = 1024; st->st_blocks = 2; st->st_nlink = 2; /* "foo" && "foo/.." */ } st->st_uid = geteuid(); /* the current user owns every file */ st->st_gid = getegid(); st->st_blksize = 1024; } return 0; }
copy_dir () /* source und dest sind global; bei Fehler: return (1) */ { int source_len, dest_len, fd_source, fd_dest, error; char dta[44]; long old_dta, fail, size, count; error=0; source_len=strlen(source); dest_len=strlen(dest); old_dta=Fgetdta(); Fsetdta(dta); strcat(source,"\\*.*"); fail=Fsfirst(source,16); source[source_len]=0; while (!fail) { strcat(source,"\\"); strcat(source,dta+30); strcat(dest,"\\"); strcat(dest,dta+30); if (dta[21]==16) /* Directory */ { if (strcmp(dta+30,".")&&strcmp(dta+30,"..")) if (Dcreate(dest)) { printf("Ordner %s l„žt sich nicht anlegen.\n",dest); error=1; } else error|=copy_dir(source,dest); } else /* File */ { printf("%s nach %s\n",source,dest); if ((fd_source=Fopen(source,0))<0) { printf("Datei %s l„žt sich nicht ”ffnen.\n",source); error=1; } else if ((fd_dest=Fcreate(dest,dta[21]&~1))<0) { printf("Datei %s l„žt sich nicht einrichten.\n",dest); error=1; } else { size=*(long*)(dta+26); while (size) { count=(size<buf_size)?size:buf_size; size-=count; if (Fread(fd_source,count,buffer)!=count) { printf("Fehler beim Lesen von %s .\n",source); error=1; break; } if (Fwrite(fd_dest,count,buffer)!=count) { printf("Fehler beim Schreiben von %s .\n",dest); error=1; break; } } Fclose(fd_source); Fclose(fd_dest); fd_dest=Fopen(dest,1); Fdatime(fd_dest,dta+22,1); Fclose(fd_dest); } } source[source_len]=0; dest[dest_len]=0; fail=Fsnext(); } if (fail!=-49l) { printf("Ordner %s nicht gefunden.\n",source); error=1; } Fsetdta(old_dta); return (error); }
XDIR *x_opendir(const char *path, int *error) { #if _MINT_ if (mint) /* HR 151102 */ { XDIR *dir; if ((dir = malloc(sizeof(XDIR))) == NULL) *error = ENSMEM; else { dir->path = (char *) path; dir->type = x_inq_xfs(path, nil) ? 0 : 1; /* HR 151102 */ if (dir->type) { /* * Dos file system. */ dir->data.gdata.first = 1; #if USE_gemdos dir->data.gdata.old_dta = (DTA *) gemdos(47); gemdos(26, &dir->data.gdata.dta); #else dir->data.gdata.old_dta = Fgetdta(); Fsetdta(&dir->data.gdata.dta); #endif *error = 0; } else { /* * File system with long filenames. */ #if USE_gemdos if (((dir->data.handle = gemdos(0x128, path, 0)) & 0xFF000000L) == 0xFF000000L) #else if (((dir->data.handle = Dopendir(path, 0)) & 0xFF000000L) == 0xFF000000L) #endif { *error = xerror((int) dir->data.handle); free(dir); dir = NULL; } } } return dir; } else #endif { XDIR *dir; if ((dir = malloc(sizeof(XDIR))) == NULL) *error = ENSMEM; else { dir->path = (char *) path; dir->data.gdata.first = 1; #if USE_gemdos dir->data.gdata.old_dta = (DTA *) gemdos(47); gemdos(26, &dir->data.gdata.dta); #else dir->data.gdata.old_dta = Fgetdta(); Fsetdta(&dir->data.gdata.dta); #endif *error = 0; } return dir; } }
/* Code Principal */ int main(void) { int ability,i,fhandle; char buffer[2000]; DTA *mydta; char *pmodule; if ((mydta = (long)(Malloc(44))) == NULL) { printf("Erreur Reservation memoire !!!"); return -4; } Fsetdta(mydta); printf("\033E"); /* Initialisation du DSP */ ability=xbios(113); if ((Dsp_LoadProg(DSP_CODE,ability,buffer))==0) printf("Chargement du code DSP = OK !!!\n"); else { printf("Erreur de chargement du programme DSP !!!\n"); i=getchar(); return -1; } /* Chargement du module */ if (Fsfirst(MODULE,0) == 0) if ((pmodule=Malloc(TAILLE_BUFF+(mydta->d_length))) != NULL) { fhandle=Fopen(MODULE,0 ); Fread(fhandle,mydta->d_length,pmodule); Fclose(fhandle); } else { printf("Pas assez de memoire !!!\n"); i=getchar(); return -2; } else { printf("Module introuvable\n"); i=getchar(); return -3; } /* Initialisation du player */ printf("Un petit moment SVP...\n"); if (Player_dtm(0,pmodule,pmodule+mydta->d_length)==-1) { printf("Erreur initialisation du module !!!"); i=getchar(); return -2; } printf("Appuyez sur une RETURN...\n");
int open_file( WX **pwx, int *pvw, int *pvh ) { WX *wx; char file[14], *ppath; int i, ret; DTA mydta, *savedta; long readamt; char *readbuf; if( (wx = calloc( 1L, sizeof(WX) )) == NULL ) { return (int)ENSMEM; } wx->name[0] = (char)Dgetdrv() + 'A'; wx->name[1] = ':'; Dgetpath( &(wx->name[2]), 0 ); strcat( wx->name, "\\*.*" ); file[0] = 0; ret = fsel_input( wx->name, file, &i ); if( ret != 1 ) { goto err1; } else if( !i ) { ret = (int)ERROR; goto err1; } if( (ppath = strrchr( wx->name, '\\' )) == NULL ) ppath = wx->name; else ++ppath; strcpy( ppath, file ); savedta = Fgetdta(); Fsetdta( &mydta ); Fsfirst( wx->name, 1 ); Fsetdta( savedta ); if( (readbuf = (char *)Malloc(mydta.d_length)) <= NULL ) { ret = (int)ENSMEM; goto err1; } if( (ret = (int)Fopen(wx->name, 0)) < 0 ) goto err; graf_mouse( BUSYBEE, NULL ); readamt = Fread( ret, mydta.d_length, readbuf ); graf_mouse( ARROW, NULL ); Fclose( ret ); if( readamt != mydta.d_length ) { ret = (int)readamt; err: Mfree( readbuf ); err1: free( wx ); return ret; } wx->tabs = 4 * form_alert( 1, "[2][ What size tabs? ][ 4 | 8 ]" ); graf_mouse( BUSYBEE, NULL ); ret = parse_buf( readbuf, readamt, wx->tabs, &wx->line0, pvw, pvh ); graf_mouse( ARROW, NULL ); Mfree( readbuf ); if( ret != E_OK ) { free_tlines( wx->curline ); goto err1; } *pwx = wx; return ret; }
/* do_rename() * ==================================================================== */ void do_rename( int curb, int curc ) { int berror; olddma = Fgetdta(); Fsetdta( &newdma ); /* Point to OUR buffer */ /* Get SOURCE */ if( cstate ) /* Protection On or Off */ { /* Memory Protection */ if( bstate ) { /* Source is MINT.PRG - Memory Protection */ strcpy( Source, OnPath ); } else { /* Source is MINT.PRX - Memory Protection */ strcpy( Source, OffPath ); } } else { /* No Memory Protection */ if( bstate ) { /* Source is MINTNP.PRG - No Memory Protection */ strcpy( Source, NPOnPath ); } else { /* Source is MINTNP.PRX - No Memory Protection */ strcpy( Source, NPOffPath ); } } /* Get Destination - Turn ON or OFF */ if( curb ) { /* Turn ON MultiTOS */ /* Get Destination */ if( curc ) { /* Memory Protection */ /* Destination is MINT.PRG - Memory Protection */ strcpy( Destination, OnPath ); } else { /* No Memory Protection */ /* Destination is MINTNP.PRG - No Memory Protection */ strcpy( Destination, NPOnPath ); } /* Do the Renaming - TURN ON MULTITOS */ berror = Frename( 0, Source, Destination ); if( berror ) { if( berror == -13 ) /* write protected */ form_alert( 1, NoWrite ); else { /* Unable to Turn On MultiTOS */ form_alert( 1, NoOn ); } } else form_alert( 1, RebootText ); } else { /* Turn Off MultiTOS */ /* Get Destination */ if( curc ) { /* Destination is MINT.PRX - Memory Protection */ strcpy( Destination, OffPath ); } else { /* Destination is MINTNP.PRX - No Memory Protection */ strcpy( Destination, NPOffPath ); } /* Turn Off MultiTOS - */ berror = Frename( 0, Source, Destination ); if( berror ) { if( berror == -13 ) /* write protected */ form_alert( 1, NoWrite2 ); else { /* Unable to Turn off MultiTOS */ form_alert( 1, NoOff ); } } else form_alert( 1, RebootText ); } Fsetdta( olddma ); /* Point to OLD buffer */ }
/* initialize() * ==================================================================== */ int initialize( void ) { int berror; int flag; flag = TRUE; /* Get the Boot Drive and Muck the paths */ Drive = GetBaseDrive(); OnPath[0] = OffPath[0] = Drive; NPOnPath[0] = NPOffPath[0] = Drive; olddma = Fgetdta(); Fsetdta( &newdma ); /* Point to OUR buffer */ berror = Fsfirst( OnPath, 0 ); if( berror == E_OK ) /* Found it! */ { /* MINT IS ON! with Memory Protection */ Select( SETON ); Deselect( SETOFF ); Select( NPON ); Deselect( NPOFF ); bstate = TRUE; cstate = TRUE; } else { /* Check for No Memory Protection */ berror = Fsfirst( NPOnPath, 0 ); if( berror == E_OK ) { /* Found it! It is ON with No Memory Protection */ Select( NPOFF ); Deselect( NPON ); Select( SETON ); Deselect( SETOFF ); bstate = TRUE; cstate = FALSE; } else { /* Check for Off items */ /* Mint is OFF, with memory protection */ berror = Fsfirst( OffPath, 0 ); if( berror == E_OK ) /* Found it! */ { /* MInT.PRX is found! */ Select( SETOFF ); Deselect( SETON ); Select( NPON ); Deselect( NPOFF ); bstate = FALSE; cstate = TRUE; } else { /* Mint is off with no memory protection */ berror = Fsfirst( NPOffPath, 0 ); if( berror == E_OK ) { /* MintNP.prx is found */ Select( SETOFF ); Deselect( SETON ); Select( NPOFF ); Deselect( NPON ); bstate = FALSE; cstate = FALSE; } else { /* Mint is not on the hard disk...*/ form_alert( 1, nomint ); flag = FALSE; } } } } Fsetdta( olddma ); /* Point to OLD buffer */ return( flag ); }