Example #1
0
/* -------------------------------------------------------------------- */
static BOOL getInfo(char *file, struct fInfo * ours)
{
    struct fInfo info;
    FILE *fl;
    BOOL found = FALSE;

	if(changedir(roomBuf.rbdirname) == -1) {
		changedir(cfg->homepath);
		return FALSE;
	}

	if ((fl = fopen("fileinfo.cit", "rb")) == NULL) {
        return FALSE;
    }
    while (fread(&info, sizeof(struct fInfo), 1, fl) == 1 && !found) {
        if (strcmpi(file, info.fn) == SAMESTRING) {
            *ours = info;

            found = TRUE;
        }
    }

	changedir(cfg->homepath);
    return found;
}
Example #2
0
int
main(void) {
    int fd1, fd2;
    struct stat *stat;

    changedir("/testdir/test");
    fd1 = safe_open("testfile", O_RDWR | O_TRUNC);
    stat = safe_fstat(fd1);
    assert(stat->st_size == 0 && stat->st_nlinks == 1);

    safe_link("testfile", "orz");

    fd2 = safe_open("orz", O_RDONLY);
    stat = safe_fstat(fd1);
    assert(stat->st_size == 0 && stat->st_nlinks == 2);
    stat = safe_fstat(fd2);
    assert(stat->st_size == 0 && stat->st_nlinks == 2);

    const char *msg = "Hello world!!\n";
    static char buffer[1024];
    size_t len = strlen(msg);
    memcpy(buffer, msg, len);
    safe_write(fd1, buffer, len);

    changedir(".");
    memset(buffer, 0, sizeof(buffer));
    safe_read(fd2, buffer, len);
    assert(strncmp(buffer, msg, len) == 0);

    cprintf("link test ok.\n");

    safe_unlink("orz");
    stat = safe_fstat(fd2);
    assert(stat->st_size == len && stat->st_nlinks == 1);
    close(fd2);
    changedir(".");

    cprintf("unlink test ok.\n");

    fd2 = safe_open("testfile", O_RDWR | O_TRUNC);
    safe_write(fd1, buffer, len);

    stat = safe_fstat(fd2);
    assert(stat->st_size == len * 2 && stat->st_nlinks == 1);

    fd2 = safe_open("testfile", O_RDWR | O_TRUNC);

    assert(link("test", "..") != 0);
    assert(link("testfile", ".") != 0);
    assert(link("testfile", "./testfile") != 0);
    assert(unlink(".") != 0 && unlink("..") != 0);

    changedir(".");
    cprintf("sfs_filetest3 pass.\n");
    return 0;
}
Example #3
0
/* -------------------------------------------------------------------- */
void tutorial(char *filename)
{
    int  i;
    char temp[14];
    char oldverbose;
    
    outFlag     = OUTOK;
    setio(whichIO, echo, outFlag);

    if (!expert)  mPrintf("\n <3J0>ump <3N0>ext <3P0>ause <3S0>top\n");
    /* doCR(); */

    if (changedir(cfg.helppath) == -1 ) return;

    /* no bad files */
    if (checkfilename(filename, 0) == ERROR)
    {
        mPrintf(" No helpfile %s", filename);
        changedir(cfg.homepath);
        return;
    }

    if (ambig(filename))
    {
        /* fill our directory array according to filename */
        oldverbose = verbose;
        verbose = FALSE;
        filldirectory(filename);
        verbose = oldverbose;

        /* print out all the files */
        for (i = 0; filedir[i].entry[0] && 
        ( dumpf(filedir[i].entry) != ERROR) ; i++);

        if ( !i) mPrintf(" No helpfile %s", filename);

        /* free file directory structure */
        if(filedir != NULL)
        _ffree((void *)filedir);
    }
    else
    {
       strcpy(temp, filename);
       temp[strlen(temp)-1] = '@';

       if (filexists(temp) && *term.bold)
         dump(temp);
       else
         dumpf(filename);
    }

    /* go to our home-path */
    changedir(cfg.homepath);
}
Example #4
0
/* -------------------------------------------------------------------- */
void BLBRotate(char *base, char *ext, int *reg, int *ansi)
{
    char fn[15];
    char ext2[4];
    int  *num;
    
    strcpy(ext2, ext);
    
    /*
     * Are we doing ansi or normal
     */
    if (changedir(cfg.helppath) == -1 ) return;
    
    sprintf(fn, "%s.%2.2s@", base, ext);
    if(*term.bold && filexists(fn))
    {
        ext2[2] = '@';
        num = ansi;
    }
    else
    {
        num = reg;
    }
        
    if(*num == 0)
    {
        sprintf(fn, "%s.%s", base, ext2);
        dumpf(fn);
    }
    else
    {
        sprintf(fn, "%s%d.%s", base, *num, ext2);
        if (!filexists(fn))
        {
            sprintf(fn, "%s.%s", base, ext2);
            dumpf(fn);
            *num = 0;
        }
        else
        {
            dumpf(fn);
        }
    }
    
    (*num)++;

    changedir(cfg.homepath);
}
Example #5
0
Bool TERMWINDOWMEMBER n_login(void)
    {
    changedir(cfg.homepath);    // for @ command
    doccr();
    cPrintf(getnetmsg(53));

    char Macro[256];

    strcpy(Macro, node->GetLoginMacro());

    if (!parseLine(Macro))
        {
        OC.ansiattr = cfg.wattr;
        cPrintf(getnetmsg(54));
        OC.ansiattr = cfg.attr;

        return (FALSE);
        }

    OC.ansiattr = cfg.wattr;
    cPrintf(getnetmsg(45));
    OC.ansiattr = cfg.attr;
    doccr();
    doccr();

    return (TRUE);
    }
Example #6
0
int amigados_openDir(FSMNG * fsmng, char * path)
{
	int i;
	SECTNUM snum;

	if( changedir(fsmng,path,&snum,1) ==  RC_OK)
	{
		i = 0;
		while((long)fsmng->dirhandletable[i]!=-1 && i<128)
		{
			i++;
		}

		if(i == 128)
		{
			return HXCFE_ACCESSERROR;
		}

		fsmng->dirhandletable[i] = (void*)snum;

		fsmng->dirindex[i] = 0;

		return i+1;
	}

	return HXCFE_ACCESSERROR;
}
Example #7
0
int amigados_createFile(FSMNG * fsmng, char * filename)
{
	struct File *file;
	int i;
	char filen[256];
	char folderpath[256];
	SECTNUM snum;
	struct Volume * adfvolume;

	adfvolume = (struct Volume *)fsmng->volume;

	i = 0;
	while((long)fsmng->handletable[i]!=-1 && i<128)
	{
		i++;
	}
	if(i == 128) return HXCFE_ACCESSERROR;

	hxc_getpathfolder(filename,folderpath);

	if( changedir(fsmng,folderpath,&snum,1) ==  RC_OK)
	{
		hxc_getfilenamebase(filename,filen);

		file = adfOpenFile(adfvolume, filen, "w");
		if(file)
		{
			fsmng->handletable[i] = file;
			return i+1;
		}
	}

	return HXCFE_ACCESSERROR;
}
Example #8
0
void getRoom(int rm)
{
    long int s;

    /* load room #rm into memory starting at buf */
    thisRoom    = rm;
    s = (long)rm * (long)sizeof roomBuf;

    fseek(roomfl, s, 0);
    if (fread(&roomBuf, sizeof roomBuf, 1, roomfl) != 1)  
    {
        crashout("getRoom-EOF detected!");
    }

#ifdef GOODBYE    
    if (roomBuf.rbflags.MSDOSDIR)
    {
        if (changedir(roomBuf.rbdirname) == -1)
        {
            roomBuf.rbflags.MSDOSDIR = FALSE;
            roomBuf.rbflags.DOWNONLY = FALSE;
        
            noteRoom();
            putRoom(rm);
            
            sprintf(msgBuf->mbtext, 
                    "%s>'s directory unfound.\n Directory: %s\n", 
                    roomBuf.rbname, 
                    roomBuf.rbdirname);
            aideMessage();
        }
    }
#endif
}
Example #9
0
int amigados_openFile(FSMNG * fsmng, char * filename)
{
	struct File *file;
	int i;
	SECTNUM snum;
	char filen[256];
	struct Volume * adfvolume;

	adfvolume = (struct Volume *)fsmng->volume;

	i = 0;
	while(((long)fsmng->handletable[i]!=-1) && i<128)
	{
		i++;
	}
	if(i == 128) return HXCFE_ACCESSERROR;

	if( changedir(fsmng,filename,&snum,0) ==  RC_OK)
	{
		if( adfParentDir(adfvolume) == RC_OK )
		{
			hxc_getfilenamebase(filename,filen);

			file = adfOpenFile(adfvolume, filen, "r");
			if(file)
			{
				fsmng->handletable[i] = file;
				return i+1;
			}
		}
	}

	return HXCFE_ACCESSERROR;
}
Example #10
0
/* -------------------------------------------------------------------- */
static void updateFile(char *dir, char *file, char *user, char *comment)
{
    struct fInfo info, ours;
    FILE *fl;
	unsigned cntr = 0;
	int i, l;
	char *ptr;
	BOOL found = FALSE;

	/* let's make the structure clean */
	l = sizeof(struct fInfo);
	ptr = (char *) &ours;
	for(i=0; i<l; i++) ptr[i] = '\0';

	/* setup the buffer for write */
    strcpy(ours.fn, file);
    strcpy(ours.uploader, user);
    strcpy(ours.comment, comment);

	if(changedir(dir) == -1) {
		changedir(cfg->homepath);
		return;
	}
	if ((fl = fopen("fileinfo.cit", "r+b")) == NULL) {
		newFile("fileinfo.cit", &ours);
        return;
    }
    while (fread(&info, sizeof(struct fInfo), 1, fl) == 1 && !found) {
        if (strcmpi(file, info.fn) == SAMESTRING) {
			/* seek back and overwrite it */
			fseek(fl, (long) (sizeof(struct fInfo)*cntr), SEEK_SET);
			fwrite(&ours, sizeof(struct fInfo), 1, fl);
            found = TRUE;
        }
		cntr++;
	}

    fclose(fl);

    if (!found)
		newFile("fileinfo.cit", &ours);

	changedir(cfg->homepath);
}
Example #11
0
void writeTables(void)
{
    FILE  *fd;

    changedir(etcpath);

    if ((fd     = fopen("etc.dat" , "wb")) == NULL)
    {
        crashout("Can't make Etc.dat");
    }
    /* write out Etc.dat */
    fwrite(&cfg, sizeof cfg, 1, fd);
    fclose(fd);

    changedir(cfg.homepath);

    if ((fd  = fopen("log.tab" , "wb")) == NULL)
    {
        crashout("Can't make Log.tab");
    }
    /* write out Log.tab */
    fwrite(logTab, sizeof(struct lTable), cfg.MAXLOGTAB, fd);
    fclose(fd);
 
    writeMsgTab();

    if ((fd = fopen("room.tab", "wb")) == NULL)
    {
        crashout("Can't make Room.tab");
    }
    /* write out Room.tab */
    fwrite(roomTab, sizeof(struct rTable), MAXROOMS, fd);
    fclose(fd);

/* new cron.tab stuff */

    writeCrontab();

/* end of new cron.tab stuff */


    changedir(etcpath);
}
Example #12
0
int main(int argc, const char *argv[])
{
    int RUN = TRUE;
    char command[100] = "";
    char params[100] = "";

    int PIDstatus = 0;

    while (RUN) {/* Endlosschleife */
        strcpy(command, "");
        type_prompt(); /* Prompt ausgeben */

        read_command(command, params);  /* Eingabezeile von Tastatur lesen */

        if(!strcmp(command, "quit")) {
            quit_shell(&RUN);
        } else if (!strcmp(command, "version")) {
            get_version();
        } else if (!strcmp(command, "/")) {
            changedir(params);
        } else if (!strcmp(command, "help")) {
            print_help();
        } else {
            /* PIDstatus = fork(); [> Kind erzeugen <]*/
            /* if (PIDstatus < 0) {*/
            /*   printf("Unable to fork"); [> Fehlerbedingung <]*/
            /*   continue; [> Schleife wiederholen <]*/
            /* }*/
            /* if (PIDstatus > 0) {*/
            /*   waitpid (PIDstatus, &status, 0);   [> Elternprozess wartet auf Kind <]*/
            /* } else {*/
            /*   execve(command, params, 0);   [> Das Kind-Programm ausführen <]*/
            /* }*/
            PIDstatus = fork();
            if (PIDstatus < 0) {
                printf("Sorry, unable to fork");
            }
            else if (PIDstatus > 0) {
                if (params[strlen(params)-1] != '&') {
                    waitpid(PIDstatus,NULL,0);
                }
            }
            else {
                RUN = FALSE; // stop loop for this process
                if (params[strlen(params)-1] != '&') {
                    printf("\n"); // beautify output
                }
                if (execlp(command, (char const*)params, 0) == -1) {
                    printf("Programm nicht gefunden!\n");
                }
            }
        }
    }
    return 0;
}
Example #13
0
void writeTables(void)
{
    FILE  *fd;
    int i;

    changedir(etcpath);

    if ((fd     = fopen("etc.dat" , "wb")) == NULL)
    {
	crashout("Can't make ETC.DAT");
    }
    /* write out ETC.DAT */
    fwrite(&cfg, sizeof cfg, 1, fd);
    fclose(fd);

    changedir(cfg.homepath);

    if ((fd  = fopen("log.tab" , "wb")) == NULL)
    {
	crashout("Can't make LOG.TAB");
    }
    /* write out LOG.TAB */
    fwrite(logTab, sizeof(struct lTable), cfg.MAXLOGTAB, fd);
    fclose(fd);
 
    writeMsgTab();

    if ((fd = fopen("room.tab", "wb")) == NULL)
    {
	crashout("Can't make ROOM.TAB");
    }
    /* write out ROOM.TAB */
    fwrite(roomTab, sizeof(struct rTable), MAXROOMS, fd);
    fclose(fd);

#ifdef CRON
    writecrontab();
#endif

    changedir(etcpath);

}
Example #14
0
/*
 *  create a remote directory
 */
int
createdir(Node *node)
{
	if(changedir(node->parent) < 0)
		return -1;
	
	sendrequest("MKD", node->d->name);
	if(getreply(&ctlin, msg, sizeof(msg), 0) != Success)
		return -1;
	return 0;
}
Example #15
0
/*
 *  remove a remote directory
 */
int
removedir(Node *node)
{
	if(changedir(node->parent) < 0)
		return -1;
	
	sendrequest("RMD", s_to_c(node->remname));
	if(getreply(&ctlin, msg, sizeof(msg), 0) != Success)
		return -1;
	return 0;
}
void		cd(t_server *serv, char *cmd)
{
  char		*path;
  char		*newpath;

  path = split_string(cmd, ' ', 1);
  if (path != NULL)
    {
      if (path[0] == '/')
	{
	  newpath = xmalloc(PATH_MAX);
	  sprintf(newpath, "%s%s", serv->root, path);
	  changedir(serv, newpath);
	  free(newpath);
	}
      else
	changedir(serv, path);
      free(path);
    }
  else
    changedir(serv, serv->root);
}
Example #17
0
/*
 *  read a remote file
 */
int
readfile1(Node *node)
{
	Biobuf *bp;
	char buf[4*1024];
	long off;
	int n;
	int tries;

	if(changedir(node->parent) < 0)
		return -1;

	for(tries = 0; tries < 4; tries++){
		switch(data(OREAD, &bp, "RETR", s_to_c(node->remname))){
		case Extra:
			break;
		case TempFail:
			continue;
		default:
			return seterr(nosuchfile);
		}
		off = 0;
		while((n = read(Bfildes(bp), buf, sizeof buf)) > 0){
			if(filewrite(node, buf, off, n) != n){
				off = -1;
				break;
			}
			off += n;
		}
		if(off < 0)
			return -1;

		/* make sure a file gets created even for a zero length file */
		if(off == 0)
			filewrite(node, buf, 0, 0);

		close(Bfildes(bp));
		switch(getreply(&ctlin, msg, sizeof(msg), 0)){
		case Success:
			return off;
		case TempFail:
			continue;
		default:
			return seterr(nosuchfile);
		}
	}
	return seterr(nosuchfile);
}
Example #18
0
int main(int ac,char *av[])
{
  int i=0;
  int j=0;
  int k=0;
  int l=0;
  char dir1[MAXN];
  char dir2[MAXN];
  char dir3[MAXN];
  char filename[MAXN];
  time_t t;
  int maxfiles=0xFFFFFF;
  int createfiles=0;

  if (ac > 1) {
    sscanf(av[1],"%x",&maxfiles);
    if (maxfiles==0) {
      printf("maxfile argument error (0 value)\n");
      exit(1);
    }
  }
  time(&t);
  srandom((unsigned int)getpid()^(((unsigned int)t<<16)| (unsigned int)t>>16));
  printf("Create files\n");
  for (i = 0 ; i < 0xFF ; i++) {
    sprintf(dir1,"%2.2x",i);
    makedir(dir1);
    changedir(dir1);
    for (j = 0 ; j < 0xFF ; j++) {
      sprintf(dir2,"%2.2x",j);
      makedir(dir2);
      changedir(dir2);
      for (k = 0 ; k < 0xFF ; k++) {
	sprintf(dir3,"%2.2x",k);
	makedir(dir3);
	changedir(dir3);
	for (l = 0 ; l < 0xFF ; l++) {
	  sprintf(filename,"%s%s%s%2.2x",dir1,dir2,dir3,l);
	  create_file(filename);
	  if (maxfiles < createfiles++) {
	    goto end;
	  }
	}
	changedir("../");
      }
      changedir("../");
    }
    changedir("../");
  }
end:
  fprintf(stderr,"\nTotal create files: %d\n",filecount);
  printf("Done\n");
        return 0;
}
Example #19
0
/*
 *  turn a vms spec into a path
 */
static Node*
vmsextendpath(Node *np, char *name)
{
	np = extendpath(np, s_copy(name));
	if(!ISVALID(np)){
		np->d->qid.type = QTDIR;
		np->d->atime = time(0);
		np->d->mtime = np->d->atime;
		strcpy(np->d->uid, "who");
		strcpy(np->d->gid, "cares");
		np->d->mode = DMDIR|0777;
		np->d->length = 0;
		if(changedir(np) >= 0)
			VALID(np);
	}
	return np;
}
Example #20
0
File: tester.c Project: jre/upart
int
main(int argc, char *argv[])
{
	void (*mode)(FILE *);
	FILE *idx;
	int opt;

	myname = getmyname(argv[0]);

	mode = testfiles;
	while ((opt = getopt(argc, argv, "chrtv")) != -1) {
		switch (opt) {
		case 'c':
			mode = cleanfiles;
			break;
		case 'r':
			mode = regenfiles;
			break;
		case 't':
			mode = testfiles;
			break;
		case 'v':
			verbose = 1;
			break;
		default:
			printf("usage: %s [-chr] -f path -u path\n"
			    "  -c       clean test output\n"
			    "  -h       show this message and exit.\n"
			    "  -r       regenerate test output.\n"
			    "  -t       run tests (the default)\n"
			    "  -v       verbose mode\n",
			    myname);
			exit(EXIT_FAILURE);
		}
	}

	changedir();

	if ((idx = fopen(TESTINDEX_PATH, "r")) == NULL)
		fail("failed to open %s for reading", TESTINDEX_PATH);

	(*mode)(idx);

	return (0);
}
Example #21
0
int ambigUnlink(const char *filename, const char *directory)
    {
    int count = 0;

    if (directory && !changedir(directory))
        {
        return (0);
        }

    // keep going till it errors, which is end of directory
    FindFileC FF;
    if (FF.FindFirst(starstar))
        {
        do
            {
            if (FF.IsNormalFile())
                {
                // + 1 for strcat() call below
#ifdef WINCIT
                char Name[MAX_PATH + 1];
#else
                char Name[_MAX_PATH + 1];
#endif

                CopyStringToBuffer(Name, FF.GetFullName());

                if (!strpos('.', Name))
                    {
                    strcat(Name, getmsg(433));
                    }

                // filename match wildcard?
                if (u_match(Name, filename))
                    {
                    if (!unlink(Name))
                        {
                        count++;
                        }
                    }
                }
            } while (FF.FindNext());
        }

    return (count);
    }
Example #22
0
File: ftcd.c Project: elhmn/Vog42sh
int		ft_cd(t_cmd *dat, t_env *env)
{
	char		*target;
	int			ret;

	if (!dat->arg[1])
	{
		if (!(target = gethomedir(env)))
			return (1);
	}
	else
	{
		if (!(target = getinput(dat, env)))
			return (2);
	}
	ret = changedir(dat, target, env);
	free(target);
	return (ret);
}
Example #23
0
/* closes invalid directory rooms */
void checkdir(void)
{
    if (roomBuf.rbflags.MSDOSDIR)
    {
        if (changedir(roomBuf.rbdirname) == -1)
        {
            roomBuf.rbflags.MSDOSDIR = FALSE;
            roomBuf.rbflags.DOWNONLY = FALSE;
        
            noteRoom();
            putRoom(thisRoom);
            
            sprintf(msgBuf->mbtext, 
                    "%s>'s directory not found.\n Directory: %s\n", 
                    roomBuf.rbname, 
                    roomBuf.rbdirname);
            aideMessage();
        }
    }
}
Example #24
0
int main(void)
{
	int fd1, fd2;
	struct stat *stat;

	changedir("/testdir/test"); {
		safe_mkdir("/testdir/test/dir0/");
		assert(mkdir("testfile") != 0 && mkdir("../test/dir0/") != 0);
		assert(mkdir("dir0/dir1/dir2") != 0);
		safe_mkdir("dir0/dir1/");

		fd1 = safe_open("file1", O_CREAT | O_RDWR | O_EXCL);
		fd2 = safe_open("file1", O_CREAT | O_RDWR);

		stat = safe_fstat(fd1);
		assert(stat->st_nlinks == 1);
		stat = safe_fstat(fd2);
		assert(stat->st_nlinks == 1);

		assert(open("file1", O_CREAT | O_EXCL) < 0);
		changedir(".");

		safe_link("file1", "dir0/dir1/file2");
		changedir(".");

		stat = safe_fstat(fd1);
		assert(stat->st_nlinks == 2);
	}

	changedir("dir0/dir1"); {
		assert(unlink("dir0/dir1") != 0);

		safe_unlink("/testdir/test/dir0/dir1/file2");
		safe_unlink("/testdir/test/dir0/dir1");

		stat = safe_fstat(fd1);
		assert(stat->st_nlinks == 1);
	}

	changedir("/testdir/test/dir0"); {
		safe_unlink("../file1");
		safe_unlink("../dir0");
	}

	changedir("/testdir/test");
	printf("sfs_dirtest2 pass.\n");
	return 0;
}
Example #25
0
int amigados_createDir( FSMNG * fsmng,char * foldername)
{
	char filen[256];
	char folderpath[256];
	SECTNUM snum;
	struct Volume * adfvolume;

	adfvolume = (struct Volume *)fsmng->volume;

	hxc_getpathfolder(foldername,folderpath);

	if( changedir(fsmng,folderpath,&snum,1) ==  RC_OK)
	{
		hxc_getfilenamebase(foldername,filen);

		if(adfCreateDir(adfvolume, adfvolume->curDirPtr, filen) == RC_OK)
		{
			return HXCFE_NOERROR;
		}
	}

	return HXCFE_ACCESSERROR;
}
Example #26
0
/*
 *  write back a file
 */
int
createfile1(Node *node)
{
	Biobuf *bp;
	char buf[4*1024];
	long off;
	int n;

	if(changedir(node->parent) < 0)
		return -1;

	if(data(OWRITE, &bp, "STOR", s_to_c(node->remname)) != Extra)
		return -1;
	for(off = 0; ; off += n){
		n = fileread(node, buf, off, sizeof(buf));
		if(n <= 0)
			break;
		write(Bfildes(bp), buf, n);
	}
	close(Bfildes(bp));
	if(getreply(&ctlin, msg, sizeof(msg), 0) != Success)
		return -1;
	return off;
}
Example #27
0
int jalan(char** bagian,int posisi)
{
	pid_t pid;
	int cek=0;
	if(strcmp(bagian[0],"cd")==0)
	{
		int hasil;
		hasil = changedir();
		return hasil;
	}
	else
	{
		if(strcmp(bagian[posisi-1],"&")==0) cek=1;
		pid = fork();
		if(pid==0)
		{
			if(cek==1) bagian[posisi-1]='\0';
			execvp(bagian[0], bagian);
			return 0;
		}
		else if(pid<0)
		{
			printf("ERROR\n");
			return -1;
		}
		else
		{
			if(cek==1);
			else{
				int status;
				waitpid(pid,&status,0);
			    }
			return 0;
		}
	}
}
Example #28
0
 int main(int argc, char *argv[])
 {
    // Input buffer and and commands
 	char buffer[BUFFER_LEN] = { 0 };
 	char command[BUFFER_LEN] = { 0 };
 	char arg[BUFFER_LEN] = { 0 };
 	char fileN [256] = {0};
 	bool enterManual = true;
    // variable used to check pass
 	bool check =false;

    // current working directory
    char cwd[PATH_MAX + 1];

    // Get the argurment for the file.
 	tokenize(argv[1]);
    // Checking through the files for the bat file
 	check = foldercheck(tokens[0]);
    // copies the file into a tmp variable before we clear tokens
 	strcpy(fileN, tokens[0]);
 	clearTokens();
    // If the file was found
 	if(check)
 	{   
        // Load the file
 		FILE *f;
 		f=fopen(fileN, "r");

        //sets it so you do not go into manual entry afterwords
 		enterManual = false;

        if (getcwd(cwd, PATH_MAX + 1) != NULL) {
            printf("%s$ ", cwd);
        }
        // Enters a loop to get the inputs from the file
 		while(fgets(buffer, BUFFER_LEN,f) != NULL)
 		{
            // tokenizes the buffer
 			tokenize(buffer);
 			strcpy(command, tokens[0]);
            //Checks for commands
 			if(strcmp(command, "dir") ==0)
 			{
 				directory();
 			}
 			else if (strcmp(command, "cd") == 0)
 			{

 				changedir(tokens[1]);
 			}

 			else if(strcmp(command, "clr") ==0)
 			{
 				clear();
 			}
 			else if(strcmp(command, "echo") == 0)
 			{
 				echo(tokens,i);
 			}

 			else if(strcmp(command, "pause") == 0)
 			{
 				pausing();
 			}

 			else if(strcmp(command, "environ")==0)
 			{
 				environ();
 			}
 			else if(strcmp(command, "help") ==0)
 			{
                help(tokens[1]);
 			}
            // quit command -- exit the shell
 			else if (strcmp(command, "quit") == 0)
 			{
 				return EXIT_SUCCESS;
 			}
            // If it is not a valid command checks if they are trying to start a program
 			else
 			{   
                // Check if there is a file in the program
 				check = false;
 				check = foldercheck(command);
                // if program name is found
 				if(check)
 				{  
                    // create first part of program string
                    char begin[250] = {"./"};
                    strcat (begin,tokens[0]);
                    int count = 0;
                    check = true;
                    // Loops 7 times to get the max of seven parameter
                    for(int i = 1; i < 7; i++)
                    {   
                        // makes it so no blanks go into the checks
                        if(strcmp(tokens[i]," ") != 0)
                        {
                            // checks for write symbol 
                            if(strcmp(tokens[i], ">") == 0)
                            {
                                // gets next token and sets it to write
                                i++;
                                freopen(tokens[i],"w",stdout);
                            }
                            // cbecks for append symbol
                            else if (strcmp(tokens[i], ">>") == 0)
                            {
                                // gets next token and sets it to append
                                i++;
                                freopen(tokens[i],"a",stdout);
                            }
                            // checks for read input
                            else if (strcmp(tokens[i], "<") == 0)
                            {
                                // gets next input for file name and checks if it is a file
                                i++;
                                if(foldercheck(tokens[i]))
                                {
                                    // reads from file
                                    freopen(tokens[i],"r",stdin);    
                                }else
                                {
                                    // not found sets it to terminal and writes
                                    i = 7;
                                    freopen("/dev/tty", "w", stdout);
                                    printf("Invalid file read entry \n");
                                    check = false;
                                }
                            }
                            // checks if two args have already pass
                            else if(count < 2)
                            {
                                // appends the argument to the program call
                                count++;
                                char append [256] = {" "};
                                strcat (append,tokens[i]);
                                strcat (begin, append);
                            }
                            // Invalid call has been passed
                            else
                            {
                                freopen("/dev/tty", "w", stdout);
                                printf("Invalid file program entry type \n");
                                check = false;
                                i = 7;
                            }
                        }
                    }
                    // Runs if valid program call has been called
                    if(check)
                    {
                        system(begin);
                    }
                    freopen("/dev/tty", "w", stdout);
                    freopen("/dev/tty", "r", stdin);    
                }// Command does not exist
 				else
 				{
 					printf("Unsupported command, use help to display the manual. Please enter Manualy. %s \n",  command);
 					clearTokens();
 					enterManual = true;
 					break;

 				}
 			}
 			clearTokens();
            // Fetches cwd and prints it out before input
            if (getcwd(cwd, PATH_MAX + 1) != NULL) {
                printf("%s$ ", cwd);
            }
 		}
 	}
    // Checks if the user has to enter manually for the shell
 	if(enterManual)
 	{
        if (getcwd(cwd, PATH_MAX + 1) != NULL) {
            printf("%s$ ", cwd);
        }
 		while (fgets(buffer, BUFFER_LEN, stdin) != NULL)
 		{
            // tokenizes the buffer
 			tokenize(buffer);
 			strcpy(command, tokens[0]);
            //Checks for commands
 			if(strcmp(command, "dir") ==0)
 			{
 				directory();
 			}
 			else if (strcmp(command, "cd") == 0)
 			{

 				changedir(tokens[1]);
 			}

 			else if(strcmp(command, "clr") ==0)
 			{
 				clear();
 			}
 			else if(strcmp(command, "echo") == 0)
 			{
 				echo(tokens,i);
 			}

 			else if(strcmp(command, "pause") == 0)
 			{
 				pausing();
 			}

 			else if(strcmp(command, "environ")==0)
 			{
 				environ();
 			}
 			else if(strcmp(command, "help") ==0)
 			{
                help(tokens[1]);
 			}
            // quit command -- exit the shell
 			else if (strcmp(command, "quit") == 0)
 			{
 				return EXIT_SUCCESS;
 			}
            // If it is not a valid command checks if they are trying to start a program
 			else
 			{   
                // Check if there is a file in the program
 				check = false;
 				check = foldercheck(command);
                // if the program is found
 				if(check)
 				{
                    // create first part of program string
                    char begin[250] = {"./"};
                    strcat (begin,tokens[0]);
                    int count = 0;
                    check = true;
                    // Loops 7 times to get the max of seven parameter
                    for(int i = 1; i < 7; i++)
                    {   
                        // makes it so no blanks go into the checks
                        if(strcmp(tokens[i]," ") != 0)
                        {
                            // checks for write symbol 
                            if(strcmp(tokens[i], ">") == 0)
                            {
                                // gets next token and sets it to write
                                i++;
                                freopen(tokens[i],"w",stdout);
                            }
                            // cbecks for append symbol
                            else if (strcmp(tokens[i], ">>") == 0)
                            {
                                // gets next token and sets it to append
                                i++;
                                freopen(tokens[i],"a",stdout);
                            }
                            // checks for read input
                            else if (strcmp(tokens[i], "<") == 0)
                            {
                                // gets next input for file name and checks if it is a file
                                i++;
                                if(foldercheck(tokens[i]))
                                {
                                    // reads from file
                                    freopen(tokens[i],"r",stdin);    
                                }else
                                {
                                    // not found sets it to terminal and writes
                                    i = 7;
                                    freopen("/dev/tty", "w", stdout);
                                    printf("Invalid file read entry \n");
                                    check = false;
                                }
                            }
                            // checks if two args have already pass
                            else if(count < 2)
                            {
                                // appends the argument to the program call
                                count++;
                                char append [256] = {" "};
                                strcat (append,tokens[i]);
                                strcat (begin, append);
                            }
                            // Invalid call has been passed
                            else
                            {
                                freopen("/dev/tty", "w", stdout);
                                printf("Invalid file program entry type \n");
                                check = false;
                                i = 7;
                            }
                        }
                    }
                    // Runs if valid program call has been called
                    if(check)
                    {
                        system(begin);
                    }
                    freopen("/dev/tty", "w", stdout);
                    freopen("/dev/tty", "r", stdin);    
 				}
 				else
 				{
 					printf("Unsupported command, use help to display the manual.%s \n",  command);

 				}
 			}
 			clearTokens();
            // Fetches cwd and prints it out before input
            if (getcwd(cwd, PATH_MAX + 1) != NULL) {
                printf("%s$ ", cwd);
            }
 		}    
 	}   

 	return EXIT_SUCCESS;
 }
Example #29
0
/*
 *  read a remote directory
 */
int
readdir(Node *node)
{
	Biobuf *bp;
	char *line;
	Node *np;
	Dir *d;
	long n;
	int tries, x, files;
	static int uselist;
	int usenlist;
	String *remname;

	if(changedir(node) < 0)
		return -1;

	usenlist = 0;
	for(tries = 0; tries < 3; tries++){
		if(usenlist || usenlst)
			x = data(OREAD, &bp, "NLST", nil);
		else if(os == Unix && !uselist)
			x = data(OREAD, &bp, "LIST -l", nil);
		else
			x = data(OREAD, &bp, "LIST", nil);
		switch(x){
		case Extra:
			break;
/*		case TempFail:
			continue;
*/
		default:
			if(os == Unix && uselist == 0){
				uselist = 1;
				continue;
			}
			return seterr(nosuchfile);
		}
		files = 0;
		while(line = Brdline(bp, '\n')){
			n = Blinelen(bp);
			if(debug)
				write(2, line, n);
			if(n > 1 && line[n-2] == '\r')
				n--;
			line[n - 1] = 0;

			d = crackdir(line, &remname);
			if(d == nil)
				continue;
			files++;
			np = extendpath(node, remname);
			d->qid.path = np->d->qid.path;
			d->qid.vers = np->d->qid.vers;
			d->type = np->d->type;
			d->dev = 1;			/* mark node as valid */
			if(os == MVS && node == remroot){
				d->qid.type = QTDIR;
				d->mode |= DMDIR;
			}
			free(np->d);
			np->d = d;
		}
		close(Bfildes(bp));

		switch(getreply(&ctlin, msg, sizeof(msg), 0)){
		case Success:
			if(files == 0 && !usenlst && !usenlist){
				usenlist = 1;
				continue;
			}
			if(files && usenlist)
				usenlst = 1;
			if(usenlst)
				node->chdirunknown = 1;
			return 0;
		case TempFail:
			break;
		default:
			return seterr(nosuchfile);
		}
	}
	return seterr(nosuchfile);
}
Example #30
0
char doRegular(char expand, char c)
{
    char toReturn;
    int i;
    int done = 0;
    label doorinfo;

    toReturn = FALSE;

    for (i = 0; !expand && i < MAXEXTERN && extCmd[i].name[0]; ++i) {
        if (c == toupper(extCmd[i].name[0]) && (onConsole || !extCmd[i].local)) {
            done = 1;
            mPrintf("\b%s", extCmd[i].name);
            doCR();
            if (changedir(cfg.aplpath) == ERROR) {
                mPrintf("  -- Can't find application directory.\n\n");
                changedir(cfg.homepath);
            }
        /* apsystem(extCmd[i].command); */
            sprintf(doorinfo, "DORINFO%d.DEF", onConsole ? 0 : userdat.apl_com);
            extFmtRun(extCmd[i].command, doorinfo);
        }
    }
    if (!done) {
        switch (c) {

            case 'S':
                if (gl_user.sysop && expand) {
                    mPrintf("\b\bSysop Menu");
                    doCR();
                    doSysop();
                } else {
                    toReturn = TRUE;
                }
                break;

            case 'A':
                if (gl_user.aide) {
                    doAide(expand, 'E');
                } else {
                    toReturn = TRUE;
                }
                break;

            case 'C':
                doChat(expand, '\0');
                break;
            case 'D':
                doDownload(expand);
                break;
            case 'E':
                doEnter(expand, 'm');
                break;
            case 'F':
                doRead(expand, 'f');
                break;
            case 'G':
                doGoto(expand, FALSE);
                break;
            case 'H':
                doHelp(expand);
                break;
            case 'I':
                doIntro();
                break;
            case 'J':
                mPrintf("\bJump back to ");
                unGotoRoom();
                break;
            case 'K':
                doKnown(expand, 'r');
                break;
            case 'L':
                if (!loggedIn) {
                    doLogin(expand);
                } else {
                    if (!getYesNo(confirm, 0))
                        break;
                    doLogout(expand, 's');
                    doLogin(expand);
                }
                break;
            case 'N':
            case 'O':
            case 'R':
                doRead(expand, tolower(c));
                break;

            case 'B':
                doGoto(expand, TRUE);
                break;
            case 'T':
                doLogout(expand, 'q');
                break;
            case 'U':
                doUpload(expand);
                break;
            case 'X':
                if (!expand) {
                    doEnter(expand, 'x');
                } else {
                    doXpert();
                }
                break;

            case '=':
            case '+':
                doNext();
                break;
            case '\b':
                mPrintf("  ");
            case '-':
                doPrevious();
                break;

            case ']':
            case '>':
                doNextHall();
                break;
            case '[':
            case '<':
                doPreviousHall();
                break;
            case '~':
                mPrintf("\bAnsi %s\n ", gl_term.ansiOn ?
					gl_str.off : gl_str.on);
                gl_term.ansiOn = !gl_term.ansiOn;
                break;

            case '!':
                mPrintf("\bIBM Graphics %s\n ", gl_term.IBMOn ?
					gl_str.off:gl_str.on);
                gl_term.IBMOn = !gl_term.IBMOn;
                break;

            case '?':
                nextmenu("mainopt", &(cfg.cnt.mainopttut), 1);
				listExterns();
                break;

            case 0:     /* never gets here in shell mode... */
                if (newCarrier) {
                    greeting();

                    if (cfg.forcelogin) {
                        doCR();
                        doCR();
                        i = 0;
                        while (!loggedIn && gotCarrier()) {
                            doLogin(2);
                            if (++i > 3) {
                                Initport();
                                toReturn = TRUE;
                                break;
                            }
                        }
                    }
                    newCarrier = FALSE;
                }
                if (logBuf.lbflags.NODE && loggedIn) {
                    net_slave();

                    haveCarrier = FALSE;
                    modStat = FALSE;
                    newCarrier = FALSE;
                    justLostCarrier = FALSE;
                    onConsole = FALSE;
                    disabled = FALSE;
                    callout = FALSE;

                    delay(2000);

                    Initport();

                    cfg.callno++;
                    terminate(FALSE, FALSE);
                }
                if (justLostCarrier || ExitToMsdos) {
                    justLostCarrier = FALSE;
                    if (loggedIn)
                        terminate(FALSE, FALSE);
                }
                break;      /* irrelevant value */

            default:
                toReturn = TRUE;
                break;
        }
    }
    /* if they get unverified online */
    if (logBuf.VERIFIED)
        terminate(FALSE, FALSE);

    /* update25();	*/
	do_idle(0);
    return toReturn;
}