home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.lbl.gov
/
2014.05.ftp.ee.lbl.gov.tar
/
ftp.ee.lbl.gov
/
bmd-1.0beta.tar.Z
/
bmd-1.0beta.tar
/
bmd-1.0beta
/
app
/
omtd
/
file.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-17
|
3KB
|
127 lines
/*
* Copyright (c) 1990 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Lawrence Berkeley Laboratory,
* Berkeley, CA. The name of the University may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdlib.h>
#include <sys/file.h>
#include <unistd.h>
#include "readline.h"
/*
* XXX There should be a 'cd' command. And maybe 'ls'. Or a shell escape.
*/
static void
set_cwd()
{
char *path;
static int first = 1;
if (!first)
return;
first = 0;
path = getenv("MTDDIR");
if (path != 0 && chdir(path) != 0)
printf("cannot change directory to '%s'\n", path);
}
char *rindex();
static int
isbackup(name)
char *name;
{
name = rindex(name, '.');
return name != 0 && strcmp(name, ".bak") == 0;
}
static void
mtd_name(src, dst)
char *src, *dst;
{
char *cp;
cp = rindex(src, '.');
if (cp == 0 || strcmp(".mtd", cp) != 0)
sprintf(dst, "%s.mtd", src);
else
strcpy(dst, src);
}
save_command(fname)
char *fname;
{
char name[80], bak[80];
int fd;
set_cwd();
if (isbackup(fname)) {
printf("please don't use '.bak' extension for saving files\n");
return;
}
mtd_name(fname, name);
if (access(name, F_OK) == 0) {
sprintf(bak, "%s.bak", name);
if (rename(name, bak) != 0) {
printf("%s exists; cannot rename to %s\n", name, bak);
printf("save failed\n");
return;
}
printf("%s exists; renamed %s\n", name, bak);
}
fd = open(name, O_WRONLY|O_CREAT, 0644);
if (fd < 0) {
perror(name);
printf("save failed\n");
return;
}
write_tracks(fd);
write_tempo(fd);
write_master(fd);
close(fd);
}
load_command(fname)
char *fname;
{
char name[80];
int fd;
set_cwd();
if (access(fname, F_OK) == 0)
strcpy(name, fname);
else
mtd_name(fname, name);
fd = open(name, O_RDONLY, 0644);
if (fd < 0) {
perror(name);
printf("load failed\n");
return;
}
new();
read_tracks(fd);
read_tempo(fd);
read_master(fd);
close(fd);
}