예제 #1
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* menu */
void shell (void) {
	/* run shell */
	VClear ();
	VSync ();
	VRestore ();
	runl(0, ABSSHELL, SHELL, "-i", NULL);
	VReopen ();
	VClear ();
	setdir (cur == left ? right : left, NULL);
	setdir (cur, NULL);
}
예제 #2
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* main, menu */
void reread (dir *d) {
	register char *p;

	if (! (p = getwstring (50, d->d.cwd, " Change directory ", "Change directory to")))
		return;
	if (! strcmp (p, d->d.cwd))
		setdir (d, NULL);
	else if (cur->chdir(p) < 0)
		error ("Cannot chdir to %s", p);
	else
		setdir (d, ".");
	d->chdir(d->d.cwd);
}
예제 #3
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* menu */
void setrevsort (int k) {
	register dir *c = k=='l' ? left : right;

	c->d.revsort ^= 1;
	setdir (c, NULL);
	cur->chdir(cur->d.cwd);
}
예제 #4
0
파일: ARVORE.C 프로젝트: h3nnn4n/main_ccs
void inclui_no(pont &inicio)  //versao nao recursiva
{clrscr();
 pont pai, filho;
 int number;
 printf("Digite valor: ");
 scanf("%i", &number);

 if (inicio == 0)   //arvore vazia
    { inicio = maketree(number);
    }
 else
    {pai = filho = inicio;
     while (filho != NULL)
	{ pai = filho;  //porque filho sera alterado e preciso deste end
			//que serah pai do novo filho
	  if (number > (pai->valor) )
		filho = filho->dir;
	  else
		filho = filho->esq;
	}
     if (number > (pai->valor) )
	setdir(pai, number);
     else
	setesq(pai, number);
    }

}
예제 #5
0
static int parse_include(const char *v, void *data)
{
	int rc;
	char cwd[PATH_MAX];
	if (!strlowcmp(v, DEFAULT_THEME))
		return 0;
	if (curtheme_loading && curtheme_loading->type == THEME_GAME
		&& strlowcmp(v, curtheme_loading->dir)
		&& theme_lookup(v, THEME_GAME)) { /* internal theme? */
		return game_theme_load(v, THEME_GAME);
	}
	getdir(cwd, sizeof(cwd));
	setdir(game_cwd);
	rc = game_theme_load(v, THEME_GLOBAL);
/*	if (!rc)
		game_theme_select(v); */
	setdir(cwd);
	return rc;
}
예제 #6
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* menu */
void setpattern (int k) {
	dir *d = k=='l' ? left : right;
	register char *p;

	if (! (p = getwstring (20, d->d.pattern, " Set pattern ", "Set pattern for files")))
		return;
	strncpy (d->d.pattern, p, PATSZ);
	d->d.pattern [PATSZ-1] = 0;
	setdir (d, NULL);
	cur->chdir(cur->d.cwd);
}
예제 #7
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* local */
void editfnam (register char *name) {
register d;
register char *p;
char buf [80];
struct stat st;

	if (stat (name, &st) >= 0) {
		if ((st.st_mode & S_IFMT) != S_IFREG) {
			error ("Cannot edit special files");
			return;
		}
	} else {
		d = creat (name, 0644);
		if (d < 0) {
			error ("Cannot create %s", name);
			return;
		}
		close (d);
	}
	if (useredit) {
		strcpy (buf, editname);
		strcat (buf, " ");
		strcat (buf, name);
		VRestore ();
		syscmd (buf);
		VReopen ();
		VRedraw ();
		setdir (cur == left ? right : left, NULL);
		setdir (cur, NULL);
		return;
	}
	if ((d = open (name, 2)) < 0) {
		error ("Cannot open %s for writing", name);
		return;
	}
	/* skip directory name */
	for (p=name; *p; ++p);
	for (; p>=name && *p!='/'; --p);
	EDITFILE editfile(d, name, p+1);
	close (d);
}
예제 #8
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* main, menu */
void mydelete (void) {
	char buf [80];
	register struct file *p;
	register c;

	if (c = tagged ()) {
		/* delete group of files */

		sprintf (buf, "You have selected %d file%s.", c, c>1 ? "s" : "");
		if (getchoice (0, " Delete ", buf, NULL, " Delete ", " Cancel ", NULL))
			return;
		sprintf (buf, "You are DELETING %d selected file%s from", c, c>1 ? "s" : "");
		if (getchoice (1, " Delete ", buf, cur->d.cwd, " Ok ", " Cancel ", NULL))
			return;
		for (p=cur->d.cat; p<cur->d.cat+cur->d.num; ++p)
			if (p->tag && unlink (p->name) < 0)
				error ("Cannot delete %s", p->name);
	} else if ((c = (p = &cur->d.cat[cur->d.curfile])->mode & S_IFMT) == S_IFDIR) {
		/* delete directory */

		if (getchoice (0, " Delete ", "Do you wish to delete directory",
		    p->name, " Delete ", " Cancel ", NULL))
			return;
		if (runl(1, "/bin/rmdir", "rmdir", p->name, NULL)) {
			error ("Cannot delete directory %s", p->name);
			return;
		}
	} else if (c == S_IFREG) {
		/* delete regular file */

		if (getchoice (0, " Delete ", "Do you wish to delete",
		    p->name, " Delete ", " Cancel ", NULL))
			return;
		if (unlink (p->name) < 0) {
			error ("Cannot delete %s", p->name);
			return;
		}
	}
	setdir (cur == left ? right : left, NULL);
	setdir (cur, NULL);
}
예제 #9
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* menu */
void setsort (int k, int sk) {
	register dir *c = k=='l' ? left : right;

	switch (sk) {
	case 'n':       c->d.sort = SORTNAME;     break;
	case 'x':       c->d.sort = SORTEXT;      break;
	case 't':       c->d.sort = SORTTIME;     break;
	case 'z':       c->d.sort = SORTSIZE;     break;
	case 'u':       c->d.sort = SORTSKIP;     break;
	}
	setdir (c, NULL);
	cur->chdir(cur->d.cwd);
}
예제 #10
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* main, menu */
void view (void) {
char buf [80];
register char *name = cur->d.cat[cur->d.curfile].name;
register d;

	if (userview) {
		strcpy (buf, viewname);
		strcat (buf, " ");
		strcat (buf, name);
		VRestore ();
		syscmd (buf);
		VReopen ();
		VRedraw ();
		setdir (cur == left ? right : left, NULL);
		setdir (cur, NULL);
		return;
	}
	if ((d = open (name, 0)) < 0) {
		error ("Cannot open %s", name);
		return;
	}
	VIEWFILE viewfile(d, name);
	close (d);
}
예제 #11
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* main, menu */
void makedir (void) {
	register char *p;

	if (! (p = getstring (60, NULL, " Make directory ", "Create the directory")))
		return;
	switch (exist (p)) {
	default:
	case 'f':
		error ("File %s exists", p);
		break;
	case 'd':
		error ("Directory %s already exists", p);
		break;
	case 0:
		if (runl(1, "/bin/mkdir", "mkdir", p, NULL)) {
			error ("Cannot create directory %s", p);
			break;
		}
		setdir (cur == left ? right : left, NULL);
		setdir (cur, NULL);
		findfile (cur, p);
		break;
	}
}
예제 #12
0
파일: main.cpp 프로젝트: kotohvost/arvid
execute () {
	register struct file *file = &cur->d.cat[cur->d.curfile];
	register char *name = file->name;
	int updir, dev, ino;

	switch (file->mode & S_IFMT) {
	case S_IFDIR:
		if (! strcmp (name, ".")) {
//			setdir (cur, NULL);
			break;
		}
		if (updir = !strcmp (name, "..")) {
			dev = cur->d.dev;
			ino = cur->d.ino;
		}
		if (cur->chdir(name) < 0)
			break;
		setdir (cur, ".");
		if (updir) {
			for (cur->d.curfile=0; cur->d.curfile<cur->d.num; ++cur->d.curfile) {
				if (cur->d.cat[cur->d.curfile].dev == dev &&
				    cur->d.cat[cur->d.curfile].ino == ino)
					break;
			}
			if (cur->d.curfile >= cur->d.num)
				cur->d.curfile = 0;
			if (cur->d.topfile + PAGELEN (cur) <= cur->d.curfile)
				cur->d.topfile = cur->d.curfile - PAGELEN (cur) + 1;
		}
		if (visualwin) {
			draw.drawdir(left, 0, left, right);
			draw.drawdir(right, 0, left, right);
		}
		break;
//	case S_IFREG:
//		if (file->execable)
//			strcpy (command, file->name);
//		else
//			excommand (command, file->name);
//		cpos = strlen (command);
//		if (! command [0])
//			break;
//		cmd.exec(cur, &left, &right, file->execable ? 1 : 0, 1);
//		draw.draw(cur, &left, &right);
//		break;
	}
}
예제 #13
0
파일: psort.c 프로젝트: BWK/os161
int
main(int argc, char *argv[])
{
	initprogname(argc > 0 ? argv[0] : NULL);

	doargs(argc, argv);
	correctsize = (off_t) (numkeys*sizeof(int));

	setdir();

	genkeys();
	sort();
	validate();
	complainx("Succeeded.");

	unsetdir();

	return 0;
}
예제 #14
0
파일: filesel.c 프로젝트: Azizou/XaoS
int ui_keyfilesel(int k)
{
    if (!filevisible)
	return 0;
    if (k == UIKEY_ESC)
	ui_closefilesel(0);
    else
	switch (active) {
	default:
	    active = AFILE;
	    uih->display = 1;
	    break;
	case ADIR:
	    if (ui_textkey(dir, k))
		break;
	    if (k == '\n' || k == 13) {
		active = AFILE;
		setexactdir(dir->text);
		uih->display = 1;
	    }
	    if (k == UIKEY_UP) {
		active = AOK;
		uih->display = 1;
		activebutton = 1;
	    }
	    if (k == '\t' || k == UIKEY_DOWN) {
		active++;
		uih->display = 1;
	    }
	    break;
	case AFILELIST:
	    switch (k) {
	    case '\t':
	    case UIKEY_RIGHT:
		uih->display = 1;
		active = ADIRLIST;
		break;
	    case UIKEY_LEFT:
		uih->display = 1;
		active = ADIR;
		break;
	    case UIKEY_UP:
		if (selectedname) {
		    uih->display = 1;
		    selectedname--;
		    if (selectedname < namestart)
			namestart = selectedname;
		}
		break;
	    case UIKEY_DOWN:
		if (selectedname < nnames - 1) {
		    uih->display = 1;
		    selectedname++;
		    if (selectedname >= namestart + NVISIBLE)
			namestart = selectedname - NVISIBLE + 1;
		}
		break;
	    case UIKEY_HOME:
		if (selectedname) {
		    uih->display = 1;
		    selectedname = namestart = 0;
		}
		break;
	    case UIKEY_END:
		if (selectedname < nnames - 1) {
		    uih->display = 1;
		    selectedname = nnames - 1;;
		    if (selectedname >= namestart + NVISIBLE)
			namestart = selectedname - NVISIBLE + 1;
		}
		break;
	    case '\n':
	    case 13:
		setname(selectedname);
		uih->display = 1;
		active = AFILE;
		break;
	    }
	    break;
	case ADIRLIST:
	    switch (k) {
	    case '\t':
	    case UIKEY_RIGHT:
		uih->display = 1;
		active = AFILE;
		break;
	    case UIKEY_LEFT:
		uih->display = 1;
		active = AFILELIST;
		break;
	    case UIKEY_UP:
		if (selecteddir) {
		    uih->display = 1;
		    selecteddir--;
		    if (selecteddir < dirstart)
			dirstart = selecteddir;
		}
		break;
	    case UIKEY_DOWN:
		if (selecteddir < ndirs - 1) {
		    uih->display = 1;
		    selecteddir++;
		    if (selecteddir >= dirstart + NVISIBLE)
			dirstart = selecteddir - NVISIBLE + 1;
		}
		break;
	    case UIKEY_HOME:
		if (selecteddir) {
		    uih->display = 1;
		    selecteddir = dirstart = 0;
		}
		break;
	    case UIKEY_END:
		if (selecteddir < ndirs - 1) {
		    uih->display = 1;
		    selecteddir = ndirs - 1;;
		    if (selecteddir >= dirstart + NVISIBLE)
			dirstart = selecteddir - NVISIBLE + 1;
		}
		break;
	    case '\n':
	    case 13:
		setdir(selecteddir);
		uih->display = 1;
		break;
	    }
	    break;
	case AFILE:
	    if (ui_textkey(filename, k))
		break;
	    if (k == '\t' || k == UIKEY_DOWN) {
		active++;
		uih->display = 1;
		activebutton = 0;
	    }
	    if (k == UIKEY_UP) {
		active--;
		uih->display = 1;
	    }

	    if (k == '\n' || k == 13) {
		ui_closefilesel(1);
	    }
	    break;
	case AOK:
	    if (k == '\n' || k == 13)
		ui_closefilesel(!activebutton);
	    if (k == '\t' || k == UIKEY_RIGHT || k == UIKEY_DOWN) {
		uih->display = 1;
		activebutton++;
		if (activebutton > 2) {
		    activebutton = 0;
		    active = ADIR;
		}
	    }
	    if (k == UIKEY_LEFT || k == UIKEY_UP) {
		uih->display = 1;
		activebutton--;
		if (activebutton < 0) {
		    activebutton = 0;
		    active = AFILE;
		}
	    }
	}
    return 1;
}
예제 #15
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* menu */
void switchhidden (void) {
	showhidden ^= 1;
	setdir (cur == left ? right : left, NULL);
	setdir (cur, NULL);
}
예제 #16
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* main, menu */
void renmove (void) {
	char buf [MAXPATHLEN+20];
	char *name;
	register struct file *p;
	register c;
	int done, all, ch;
	int exd, exf;

	if (c = tagged ()) {
		/* move group of files */

		sprintf (buf, "Rename or move %d file%s to", c, c>1 ? "s" : "");
		if (! (name = getstring (60, (cur==left?right:left)->cwd,
		    " Rename ", buf)))
			return;
		runset (name);
		exd = exist (name);
		all = 0;
		for (p=cur->d.cat; p<cur->d.cat+cur->d.num; ++p)
			if (p->tag) {
				sprintf (buf, "%s/%s", name, p->name);
				exf = exd=='d' ? exist (buf) : 0;
				if (exd=='f' || exf=='f') {
					if (! all) {
						ch = getchoice (1, " Rename ", "File exists",
							exf=='f' ? buf : name,
							" Overwrite ", " All ", " Cancel ");
						switch (ch) {
						default:
						case 2:         /* cancel */
							continue;
						case 1:         /* all */
							all = 1;
						}
					}
				} else if (exf == 'd') {
					error ("%s is a directory", buf);
					continue;
				}
				runarg (p->name);
			}
		message (" Move ", "Moving %d file%s to %s ...", c, c>1 ? "s" : "", name);
		done = rundone ("/bin/mv", "mv");
		if (done) {
			endmesg ();
			message (" Move ", "Done");
		} else
			error ("Error while moving %d file%s to %s",
				c, c>1 ? "s" : "", name);
		endmesg ();
		name = 0;
	} else if ((c = (p = &cur->d.cat[cur->d.curfile])->mode & S_IFMT) == S_IFDIR) {
		/* rename directory */

		sprintf (buf, "Rename \"%s\" to", strtail (p->name, '/', 60));
		if (! (name = getstring (60, (cur==left?right:left)->cwd, " Rename ", buf)))
			return;
		exd = exist (name);
		sprintf (buf, "%s/%s", name, p->name);
		exf = exd=='d' ? exist (buf) : 0;
		if (exd=='f' || exf=='f') {
			if (getchoice (1, " Rename ", "File exists",
			    exf=='f' ? buf : name,
			    " Overwrite ", " Cancel ", NULL))
				return;
		} else if (exf == 'd') {
			error ("Directory %s exists", buf);
			return;
		}
		if (runl(1, "/bin/mv", "mv", p->name, name, NULL)) {
			error ("Cannot move %s to %s", p->name, name);
			return;
		}
	} else if (c == S_IFREG) {
		/* move regular file */

		sprintf (buf, "Rename or move \"%s\" to", p->name);
		if (! (name = getstring (60, (cur==left?right:left)->cwd, " Rename ", buf)))
			return;
		exd = exist (name);
		sprintf (buf, "%s/%s", name, p->name);
		exf = exd=='d' ? exist (buf) : 0;
		if (exd=='f' || exf=='f') {
			if (getchoice (1, " Rename ", "File exists",
			    exf=='f' ? buf : name,
			    " Overwrite ", " Cancel ", NULL))
				return;
		} else if (exf == 'd') {
			error ("%s is a directory", buf);
			return;
		}
		if (runl(1, "/bin/mv", "mv", p->name, name, NULL)) {
			error ("Cannot move %s to %s", p->name, name);
			return;
		}
	}
	setdir (cur == left ? right : left, NULL);
	setdir (cur, NULL);
	if (name)
		findfile (cur, name);
}
예제 #17
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* main, menu */
void directory(int k, int sk) {
	setdir (cur, sk == 'r' ? "/" : home);
}
예제 #18
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* menu */
void makeslink (void) {
	char buf [80];
	char *name;
	register struct file *p;
	register c;
	int done;
	int exd, exf;

	if (c = tagged ()) {
		/* symlink group of files */

		sprintf (buf, "Symlink %d file%s to", c, c>1 ? "s" : "");
		if (! (name = getstring (60, (cur==left?right:left)->cwd,
		    " Symlink ", buf)))
			return;
		runset (name);
		exd = exist (name);
		for (p=cur->d.cat; p<cur->d.cat+cur->d.num; ++p)
			if (p->tag) {
				sprintf (buf, "%s/%s", name, p->name);
				exf = exd=='d' ? exist (buf) : 0;
				if (exd=='f' || exf=='f') {
					if (getchoice (1, " Symlink ", "File exists",
					    exf=='f' ? buf : name,
					    " Overwrite ", " Cancel ", NULL))
						continue;
				} else if (exf == 'd') {
					error ("%s is a directory", buf);
					continue;
				}
				runarg (p->name);
				p->tag = 0;
			}
		runarg ("-s");
		message (" Symlink ", "Linking %d file%s to %s ...", c, c>1 ? "s" : "", name);
		done = rundone ("/bin/ln", "ln");
		if (done) {
			endmesg ();
			message (" Symlink ", "Done");
		} else
			error ("Error while linking %d file%s to %s",
				c, c>1 ? "s" : "", name);
		endmesg ();
	} else if ((c = (p = &cur->d.cat[cur->d.curfile])->mode & S_IFMT) == S_IFDIR) {
		/* symlinking directory */
	} else if (c == S_IFREG) {
		/* symlink regular file */

		sprintf (buf, "Symlink \"%s\" to", p->name);
		if (! (name = getstring (60, (cur==left?right:left)->cwd, " Symlink ", buf)))
			return;
		exd = exist (name);
		sprintf (buf, "%s/%s", name, p->name);
		exf = exd=='d' ? exist (buf) : 0;
		if (exd=='f' || exf=='f') {
			if (getchoice (1, " Symlink ", "File exists",
			    exf=='f' ? buf : name,
			    " Overwrite ", " Cancel ", NULL))
				return;
		} else if (exf == 'd') {
			error ("%s is a directory", buf);
			return;
		}
		if (runl(1, "/bin/ln", "ln", "-s", p->name, name, NULL)) {
			error ("Cannot symlink %s to %s", p->name, name);
			return;
		}
	}
	setdir (cur == left ? right : left, NULL);
	setdir (cur, NULL);
}
예제 #19
0
파일: cmd.cpp 프로젝트: kotohvost/arvid
/* main, menu */
void copy (void) {
	char buf [80];
	char *name;
	register struct file *p;
	register c;
	int done, all, ch;
	int exd, exf;

	if (c = tagged ()) {
		/* copy group of files */

		sprintf (buf, "Copy %d file%s to", c, c>1 ? "s" : "");
		if (! (name = getstring (60, (cur==left?right:left)->d.cwd,
		    " Copy ", buf)))
			return;
#if 0
		runset (name);
		exd = exist (name);
		all = 0;
		for (p = cur->d.cat; p < cur->d.cat + cur->d.num; ++p)
			if (p->tag) {
				sprintf (buf, "%s/%s", name, p->name);
				exf = exd=='d' ? exist (buf) : 0;
				if (exd=='f' || exf=='f') {
					if (! all) {
						ch = getchoice (1, " Copy ", "File exists",
							exf=='f' ? buf : name,
							" Overwrite ", " All ", " Cancel ");
						switch (ch) {
						case 2:         /* cancel */
							--c;
							continue;
						case 1:         /* all */
							all = 1;
						case 0:         /* all */
							break;
						default:
							runcancel ();
							return;
						}
					}
				} else if (exf == 'd') {
					error ("%s is a directory", buf);
					continue;
				}
				runarg (p->name);
				p->tag = 0;
			}
		if (c <= 0) {
			runcancel ();
			return;
		}
		message (" Copy ", "Copying %d file%s to %s ...", c, c>1 ? "s" : "", name);
		done = rundone ("/bin/cp", "cp");
		if (done) {
			endmesg ();
			message (" Copy ", "Done");
		} else
			error ("Error while copying %d file%s to %s",
				c, c>1 ? "s" : "", name);
		endmesg ();
#endif
	} else if ((c = (p = &cur->d.cat[cur->d.curfile])->mode & S_IFMT) == S_IFDIR) {
		/* copying directory */
	} else if (c == S_IFREG) {
		/* copy regular file */

		sprintf (buf, "Copy \"%s\" to", p->name);
		if (! (name = getstring (60, (cur==left?right:left)->d.cwd, " Copy ", buf)))
			return;
		exd = exist (cur==left?right:left, name);
		sprintf (buf, "%s/%s", name, p->name);
		exf = exd=='d' ? exist (cur==left?right:left, buf) : 0;
		if (exd=='f' || exf=='f') {
			if (getchoice (1, " Copy ", "File exists",
			    exf=='f' ? buf : name,
			    " Overwrite ", " Cancel ", NULL))
				return;
		} else if (exf == 'd') {
			error ("%s is a directory", buf);
			return;
		}
		/* copying */
		ReadWrite rf;
		strncpy(rf.from, cur->d.cwd, sizeof(rf.from));
		strncat(rf.from, "/", sizeof(rf.from));
		strncat(rf.from, p->name, sizeof(rf.from));
		strncpy(rf.to, buf, sizeof(rf.to));
		rfiles.AddReadFile(&rf);
	}
	setdir (cur == left ? right : left, NULL);
	setdir (cur, NULL);
}
int main(int argc,char **argv)
{
   char demfile[MAXLN],angfile[MAXLN],slopefile[MAXLN],flowfile[MAXLN];
   int err,useflowfile=0,i,prow=0,pcol=0;
   
   if(argc < 2)
    {
	   printf("Error: To run this program, use either the Simple Usage option or\n");
	   printf("the Usage with Specific file names option\n");
	   goto errexit;
    }
    else if(argc > 2)
	{
		i = 1;
//		printf("You are running %s with the Specific File Names Usage option.\n", argv[0]);
	}
	else {
		i = 2;
//		printf("You are running %s with the Simple Usage option.\n", argv[0]);
	}
	while(argc > i)
	{
		if(strcmp(argv[i],"-fel")==0)
		{
			i++;
			if(argc > i)
			{
				strcpy(demfile,argv[i]);
				i++;
			}
			else goto errexit;
		}
		else if(strcmp(argv[i],"-slp")==0)
		{
			i++;
			if(argc > i)
			{
				strcpy(slopefile,argv[i]);
				i++;
			}
			else goto errexit;
		}
                else if(strcmp(argv[i],"-mf")==0)
                {
                        i++;
                        if(argc > i)
                        {
                                prow = atoi(argv[i]);
                                i++;
                                if(argc > i)
                                {
                                        pcol = atoi(argv[i]);
                                        i++;
                                }
                                else goto errexit;
                        }
                        else goto errexit;
                        if(prow <=0 || pcol <=0)
                                goto errexit;
                }
		else if(strcmp(argv[i],"-ang")==0)
		{
			i++;
			if(argc > i)
			{
				strcpy(angfile,argv[i]);
				i++;
			}
			else goto errexit;
		}
		else if(strcmp(argv[i],"-sfdr")==0)
		{
			i++;
			if(argc > i)
			{
				strcpy(flowfile,argv[i]);
				i++;
				useflowfile=1;
			}
			else goto errexit;
		}

		else 
		{
			goto errexit;
		}
	}
	if( argc == 2) {
		nameadd(demfile,argv[1],"fel");
		nameadd(angfile,argv[1],"ang");
		nameadd(slopefile,argv[1],"slp");
	}
    if((err=setdir(demfile,angfile,slopefile,flowfile,useflowfile,prow,pcol)) != 0)
        printf("Setdir error %d\n",err); 
    return 0;
	
	errexit:
	   printf("Simple Usage:\n %s <basefilename>\n",argv[0]);
	   printf("Usage with specific file names:\n %s -fel <demfile>\n",argv[0]);
       printf("-slp <slopefile> -ang <angfile> [-sfdr <flowfile>]\n");
	   printf("(The <basefilename> is the name of the raw digital elevation model\n");
	   printf("(The <demfile> is the pit filled or carved DEM input file.\n");
	   printf("(The <slopefile> is the slope output file.\n");
	   printf("(The <angfile> is the output D-infinity flow direction file.\n");
       printf("[-sfdr <flowfile>] is the optional user imposed stream flow direction file.\n");
       printf("The following are appended to the file names\n");
       printf("before the files are opened:\n");
       printf("fel    carved or pit filled input elevation file\n");
       printf("slp    D-infinity slope file (output)\n");
	   printf("ang   D-infinity flow direction output file\n");
      return 0; 
}     
예제 #21
0
파일: filesel.c 프로젝트: Azizou/XaoS
int ui_mousefilesel(int x, int y, int buttons, int flags)
{
    static int grabbed = -1;
    if (!filevisible)
	return 0;
    if (grabbed >= 0 && (flags & MOUSE_DRAG)) {
	if (!grabbed) {
	    int pos;
	    pos =
		(y - LISTSTART) * nnames / (LISTEND - LISTSTART -
					    2 * BORDERHEIGHT);
	    if (pos >= nnames - NVISIBLE)
		pos = nnames - NVISIBLE;
	    if (pos < 0)
		pos = 0;
	    if (pos != namestart) {
		namestart = pos;
		uih->display = 1;
		if (selectedname < pos)
		    selectedname = pos;
		if (selectedname >= pos + NVISIBLE)
		    selectedname = pos + NVISIBLE - 1;
	    }
	} else {
	    int pos;
	    pos =
		(y - LISTSTART) * ndirs / (LISTEND - LISTSTART -
					   2 * BORDERHEIGHT);
	    if (pos >= ndirs - NVISIBLE)
		pos = ndirs - NVISIBLE;
	    if (pos < 0)
		pos = 0;
	    if (pos != dirstart) {
		dirstart = pos;
		uih->display = 1;
		if (selecteddir < pos)
		    selecteddir = pos;
		if (selecteddir >= pos + NVISIBLE)
		    selecteddir = pos + NVISIBLE - 1;
	    }
	}
    } else
	grabbed = -1;
    if (x < filex || y < filey || x > filex + filewidth
	|| y > filex + fileheight) {
	if (flags & MOUSE_PRESS)
	    ui_closefilesel(0);
	return 1;
    }
    if (y < LISTSTART) {
	if (pressedbutton != -1)
	    pressedbutton = -1, uih->display = 1;
	if ((flags & MOUSE_MOVE) && active != ADIR)
	    active = ADIR, uih->display = 1;
	if (flags & MOUSE_PRESS)
	    ui_textmouse(dir, x, y);
    } else if (y < LISTEND) {
	int mouseat = 0;
	if (pressedbutton != -1)
	    pressedbutton = -1, uih->display = 1;
	if (x > filex + filewidth / 2)
	    mouseat = 1, x -= filewidth / 2;
	x -= filex;
	if (flags & MOUSE_MOVE) {
	    if (!mouseat && active != AFILELIST)
		active = AFILELIST, uih->display = 1;
	    if (mouseat && active != ADIRLIST)
		active = ADIRLIST, uih->display = 1;
	}
	if (x > LISTWIDTH && (flags & MOUSE_PRESS))
	    grabbed = mouseat;
	else {
	    if (flags & MOUSE_PRESS) {
		int atitem =
		    (y - LISTSTART -
		     BORDERHEIGHT) / xtextheight(uih->image, uih->font);
		if (atitem < 0)
		    atitem = 0;
		if (!mouseat) {
		    atitem += namestart;
		    if (atitem < nnames) {
			if (atitem == selectedname
			    && !strcmp(names[selectedname],
				       filename->text)) {
			    ui_closefilesel(1);
			} else {
			    selectedname = atitem;
			    uih->display = 1;
			    setname(selectedname);
			}
		    }
		} else {
		    atitem += dirstart;
		    if (atitem < ndirs) {
			selecteddir = atitem;
			uih->display = 1;
			setdir(selecteddir);
		    }
		}
	    }
	}
    } else if (y < OKSTART) {
	if (pressedbutton != -1)
	    pressedbutton = -1, uih->display = 1;
	/*exit(1); */
	if ((flags & MOUSE_MOVE) && active != AFILE)
	    active = AFILE, uih->display = 1;
	if (flags & MOUSE_PRESS)
	    ui_textmouse(filename, x, y);
    } else {
	int mouseat = 0;
	if (x > filex + filewidth / 2)
	    mouseat = 1;
	if (flags & MOUSE_PRESS) {
	    if (active != AOK)
		active = AOK, uih->display = 1;
	    if (activebutton != mouseat || pressedbutton != mouseat)
		activebutton = pressedbutton = mouseat, uih->display = 1;
	}
	if ((flags & MOUSE_MOVE) && pressedbutton != mouseat)
	    uih->display = 1, pressedbutton = -1, active =
		AOK, activebutton = mouseat;
	if ((flags & MOUSE_RELEASE) && pressedbutton == mouseat)
	    ui_closefilesel(!mouseat);
    }
    return 1;
}
예제 #22
0
bool manage::go(){
	int t=1<<2;int id=2;char u[8]={0};flash a;
while(id<31){
	if(t&user)
	if(only&&robot&(1<<id))//机器
	{	
		man.control=control[id];
		int dir = man.AI_c();
		setdir(dir,id);
		man.control->SETDIR(dir);
		u[0]=id;
		int w = man.control->run();

	switch (w)
	{
		//case 1:eat();break;
	case 0:break;
	case 1:break;//食物
	case WALL:	leave(id); 
		u[0]=id;
		a.n=2;
	a.DoModal();
	dlg.Create(IDD_NET);
	dlg.ShowWindow(SW_SHOW);
		return false; break;//撞墙死
	default:
		a.DoModal();
	dlg.Create(IDD_NET);
	dlg.ShowWindow(SW_SHOW);
		leave(id);u[0]=id;
		//dlg.sendmessage('5',u);
		return false;
	}
	}
	else//网络部分
	
	{	
		u[0]=id+'0';
		//::Sleep(10);
		/*if(dlg.server&&!only)
		dlg.sendmessage('7',u);*/
		//::Sleep(20);
		int w=control[id]->run();
		//*****************************************网络部分添加
		//dlg.sendmessage();
		char tt[4] = { 0 };
		tt[0] =id+'0';
		tt[1]='0'+control[id]->head.x;
		tt[2]='0'+control[id]->head.y;
		//m.setdir(dir,id);
		dlg.sendmessage('9',tt);

	//*****************************************
		Sleep(20);
		switch (w)
		{
			//case 1:eat();break;
		case 0:break;
		case 1:
			dlg.sendmessage('7',u);
			break;//食物
		case WALL:	
			leave(id);
			u[0]=id+'0';
			if(!only)
				dlg.sendmessage('5',u);//死亡
			 return false; //撞墙死
		default:
			leave(id);
			u[0]=id+'0';
			if(!only)
		dlg.sendmessage('5',u);
			if (w&(1 << id)){ ; }//自杀
			else if (t<0){ ; }//和别人一起死
			else {
				int kill = getn(w);

			}//被kill杀
			return false;
		}
	}
	id++;t=t<<1;
}
	return 1;
}
예제 #23
0
파일: main.cpp 프로젝트: kotohvost/arvid
main (int argc, char **argv, char **envp) {
	register c;

	if (argc > 2) {
		outerr("Usage: deco [dirname]\n",0);
		exit (1);
	}
	outerr("Demos Commander, Copyright (C) 1989-1994 Serge Vakulenko\n",0);
	palette = dflt_palette;
	EnvInit (envp);
	uid = getuid ();
	gid = getgid ();
# ifdef GROUPS
	gidnum = getgroups (sizeof(gidlist)/sizeof(gidlist[0]), (unsigned int *)gidlist);
# endif
	ppid = getppid ();
	user = username (uid);
	group = groupname (gid);
	tty = ttyname (0);
	machine = getmachine ();
#if 0
	sigign();
#else
	signal(SIGTERM, SIG_IGN);
	signal(SIGQUIT, SIG_IGN);
	signal(SIGINT, SIG_IGN);
# ifdef SIGTSTP
	signal(SIGTSTP, SIG_IGN);
# endif
#endif
	init ();
//	inithome ();
	VClear ();
/* init class dir */
	if (argc > 1)
//		chdir (argv [1]);
		left = new dir(argv [1]);
	else
		left = new dir;
	right = new dir;
	left->d.basecol = 0;
	right->d.basecol = 40;
/*-----------*/
	initfile.read();
	if (uid == 0)
		palette.dimfg = 6;
	v.VSetPalette (palette.fg, palette.bg, palette.revfg, palette.revbg,
		palette.boldfg, palette.boldbg, palette.boldrevfg, palette.boldrevbg,
		palette.dimfg, palette.dimbg, palette.dimrevfg, palette.dimrevbg);
	setdir (left, ".");
	setdir (right, ".");
	left->chdir(left->d.cwd);
	cur = left;
	draw.draw(cur, left, right);
	for (;;) {
		if (! cmdreg)
			draw.drawcursor(cur);
//		cmd.drawcmd(cur, &left, &right);
		VSync ();
		c = KeyGet ();
		if (! cmdreg)
			draw.undrawcursor(cur);
		switch (c) {
		case '+':               /* select */
		case '-':               /* unselect */
			if (! cpos && ! cmdreg && ! cur->d.status) {
				if (c == '+')
					tagall ();
				else
					untagall ();
				draw.draw(cur, left, right);
				continue;
			}
		default:
//			if (c>=' ' && c<='~' || c>=0300 && c<=0376) {
//				if (cpos || c!=' ')
//					cmd.inscmd(c);
//				continue;
//			}
			VBeep ();
			continue;
//		case cntrl ('V'):       /* quote next char */
//			cmd.inscmd(quote ());
//			continue;
//		case cntrl ('J'):       /* insert file name */
//			if (! cmdreg && ! cur->status)
//				cmd.namecmd(cur);
//			continue;
//		case cntrl ('G'):
//			cmd.delcmd();
//			continue;
//		case meta ('b'):        /* backspace */
//			if (cpos) {
//				cmd.leftcmd();
//				cmd.delcmd();
//			}
//			continue;
		case cntrl ('O'):       /* set/unset command mode */
		case cntrl ('P'):       /* set/unset command mode */
			switchcmdreg ();
			if (! cmdreg)
				visualwin = 1;
			draw.draw(cur, left, right);
			continue;
		case cntrl ('M'):         /* return */
//			if (command [0]) {
//				cmd.exec(cur, &left, &right, 1, 1);
//				draw.draw(cur, &left, &right);
//				continue;
//			}
			if (cmdreg) {
				cmdreg = 0;
				if (! visualwin) {
					visualwin = 1;
					setdir (cur==left ? right : left, NULL);
					setdir (cur, NULL);
				}
				draw.draw(cur, left, right);
				continue;
			}
			execute ();
			continue;
		case cntrl (']'):       /* redraw screen */
			VRedraw ();
			continue;
//		case cntrl ('B'):        /* history */
//			if (! visualwin)
//				VClearBox (1, 0, LINES-2, 80);
//			cmd.histmenu(cur, &left, &right);
//			draw.draw(cur, &left, &right);
//			continue;
		case meta ('A'):        /* f1 */
			genhelp ();
			draw.draw(cur, left, right);
			continue;
		case meta ('B'):          /* f2 */
			udm.menu();
			draw.draw(cur, left, right);
			continue;
		case meta ('I'):        /* f9 */
			mymenu.runmenu (cur==left ? 'l' : 'r');
			draw.draw(cur, left, right);
			continue;
		case meta ('J'):        /* f0 */
		case cntrl ('C'):       /* quit */
			quit ();
			continue;
		case cntrl ('U'):       /* swap panels */
			swappanels ();
			draw.draw(cur, left, right);
			continue;
		case cntrl ('F'):       /* full screen */
			fullscreen ();
			draw.draw(cur, left, right);
			continue;
		case cntrl ('^'):       /* cd / */
			directory (0, 'r');
			if (! cur->d.status)
				draw.drawdir(cur, 1, left, right);
			continue;
		case cntrl ('\\'):      /* cd $HOME */
			directory (0, 'o');
			if (! cur->d.status)
				draw.drawdir(cur, 1, left, right);
			continue;
//		case cntrl ('Y'):       /* clear line */
//			command [cpos = 0] = 0;
//			continue;
//		case cntrl ('X'):       /* next history */
//			cmd.nextcmd();
//			continue;
//		case cntrl ('E'):       /* prev history */
//			cmd.prevcmd();
//			continue;
//		case cntrl ('S'):       /* char left */
//		case cntrl ('A'):       /* char left */
//			cmd.leftcmd();
//			continue;
//		case cntrl ('D'):       /* char right */
//			cmd.rightcmd();
//			continue;
		case cntrl ('I'):       /* tab */
			if (cmdreg) {}
//				if (command [cpos])
//					cmd.endcmd();
//				else
//					cmd.homecmd();
			else {
				switchpanels ();
				if (fullwin) {
					draw.drawbanners();
					draw.drawdir(cur, 0, left, right);
					break;
				}
			}
			continue;
		case cntrl ('W'):       /* double width */
			if (! cmdreg) {
				setdwid ();
				draw.draw(cur, left, right);
			}
			continue;
//		case meta ('G'):        /* f7 */
//			makedir ();
//			draw.draw(cur, &left, &right);
//			continue;
		case meta ('h'):        /* home */
		case meta ('e'):        /* end */
		case meta ('u'):        /* up */
		case meta ('d'):        /* down */
		case meta ('l'):        /* left */
		case meta ('r'):        /* right */
		case meta ('n'):        /* next page */
		case meta ('p'):        /* prev page */
		case cntrl ('K'):       /* find file */
		case cntrl ('R'):       /* reread catalog */
		case cntrl ('T'):       /* tag file */
		case meta ('C'):        /* f3 */
		case meta ('D'):        /* f4 */
		case meta ('E'):        /* f5 */
		case meta ('F'):        /* f6 */
		case meta ('H'):        /* f8 */
		case cntrl ('L'):       /* status */
			if (cmdreg || cur->d.status) {}
//				docmdreg (c);
			else
				doscrreg (c);
			continue;
		}
	}
}
int main(int argc,char **argv)
{
  char command[MAXLN];  
  char demfile[MAXLN], pointfile[MAXLN], newfile[MAXLN]; //flood function
  char angfile[MAXLN], slopefile[MAXLN]; //setdir function
  char areafile[MAXLN]; //area function
  int  row=0,col=0,ccheck=0; //area function
  char sindexfile[MAXLN],tergridfile[MAXLN],terparfile[MAXLN],satfile[MAXLN]; //sindex function
    
  int err;
  char *ext;
  int isCmd;
  //printf("num of arg: %d\n" , argc);
  
  sprintf(command,"%s",argv[1]);
  isCmd = 0;
  
  time_t start,end;

time (&start);


if (strcmp( command, "flood" )== 0)
   {
     isCmd = 1;
    printf("MESSAGE: Executing %s command...\n" , command);
    sprintf(demfile,"%s",argv[2]);
    sprintf(pointfile,"%s",argv[3]);
    sprintf(newfile,"%s",argv[4]);
    
    
    if(err=flood(demfile, pointfile, newfile) != 0)
        printf("ERROR: Flood error %d\n",err);
    } 

if (strcmp( command, "setdir" )== 0)
   {
   isCmd = 1;
   printf("MESSAGE: Executing %s command...\n" , command);
   sprintf(demfile,"%s",argv[2]);
   sprintf(angfile,"%s",argv[3]);
   sprintf(slopefile,"%s",argv[4]);    
   if(err=setdir(demfile, angfile, slopefile) != 0)
        printf("ERROR: Setdir error %d\n",err);        
   }

if (strcmp( command, "area" )== 0)
   {
   isCmd = 1;
   printf("MESSAGE: Executing %s command...\n" , command);
   sprintf(angfile,"%s",argv[2]);
   sprintf(areafile,"%s",argv[3]);
   sscanf(argv[4],"%d",&col);
   sscanf(argv[5],"%d",&row);
   sscanf(argv[6],"%d",&ccheck);
      
   if(err=area(angfile, areafile, row, col, ccheck) != 0)
        printf("ERROR: Area error %d\n",err);        
   }      

if (strcmp( command, "sindex" )== 0)
   {
   isCmd = 1;
   printf("MESSAGE: Executing %s command...\n" , command);
   sprintf(slopefile,"%s",argv[2]);
   sprintf(areafile,"%s",argv[3]);
   sprintf(sindexfile,"%s",argv[4]);
   sprintf(tergridfile,"%s",argv[5]);
   sprintf(terparfile,"%s",argv[6]);
   sprintf(satfile,"%s",argv[7]);
      
   if(err=sindex(slopefile,areafile,sindexfile,tergridfile,terparfile,satfile) != 0)
        printf("ERROR: Area error %d\n",err);        
   }  

if (isCmd != 1)
   {
     printf("\n\n************************************\n\n");
     printf("SINMAP - Stability INdex MAPping\n");
     printf("original package version 1.0  3/30/98\n\n");
     printf("Program to compute stability index and factor of safety for landslide Hazard mapping.\n\n");
     printf("Main Author: David G Tarboton - Utah State University\n\n");
     printf("This version is provided by Enrico A. Chiaradia - University of Milan\n");
     printf("e-mail: [email protected]\n\n");
     printf("AVAILABLE COMMANDS ARE:\n");
     printf("flood demname=STRING pointname=STRING filldemname=STRING\n");
     printf("setdir filldemname=STRING anglename=STRING slopename=STRING\n");
     printf("area angname=STRING areaname=STRING ccell=INT rcell=INT ccheck=BOOLEAN\n");
     printf("sindex slopename=STRING areaname=STRING sindexname=STRING tergridname=STRING terparname=STRING satname=STRING\n");
     printf("\nUSAGE EXAMPLE:\n");
     printf("sinmap.exe flood dem.asc null.asc filleddem.asc\n");
     
     err = 0;
          }
time (&end);
double dif = difftime (end,start);
printf("Time elapsed: %.2lf seconds\n",dif );

if (err == 0)
   printf("Done.\n");
else
{
   printf("Finished with error!\n");
      
system("PAUSE");
}


return err;
}    
예제 #25
0
파일: main.c 프로젝트: Wuzzy2/instead
int main(int argc, char *argv[])
{
#ifdef _USE_UNPACK
	int clean_tmp = 0;
#endif
	int err = 0;
	int i;
#ifdef __APPLE__
	macosx_init();
#endif
#ifndef S60
	putenv("SDL_MOUSE_RELATIVE=0"); /* test this! */
#endif

#ifdef _WIN32_WCE
	libwince_init(argv[0], 1);
	wince_init(argv[0]);
#else
#ifdef S60
	extern char s60_data[];
	strcpy(game_cwd, s60_data);
#else
#ifdef _WIN32
	strcpy(game_cwd, dirname(argv[0]));
#else
	if (!getcwd(game_cwd, sizeof(game_cwd)))
		fprintf(stderr,"Warning: can not get current dir\n.");
#endif
#endif
#endif
	unix_path(game_cwd);
	setdir(game_cwd);

	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-vsync"))
			vsync_sw = 1;
		else if (!strcmp(argv[i], "-nosound"))
			nosound_sw = 1;
		else if (!strcmp(argv[i], "-fullscreen"))
			fullscreen_sw = 1;
		else if (!strcmp(argv[i], "-mode")) {	
			if ((i + 1) < argc)
				mode_sw = argv[++i];
			else
				mode_sw = "-1x-1";
		} else if (!strcmp(argv[i], "-window"))
			window_sw = 1;
		else if (!strcmp(argv[i], "-debug")) {
			if (!debug_sw)
				debug_init();
			debug_sw = 1;
		} else if (!strcmp(argv[i], "-owntheme"))
			owntheme_sw = 1;
		else if (!strcmp(argv[i], "-noautosave"))
			noauto_sw = 1;
		else if (!strcmp(argv[i], "-game")) {
			if ((i + 1) < argc)
				game_sw = argv[++i];
			else
				game_sw = "";
		} else if (!strcmp(argv[i], "-theme")) {
			if ((i + 1) < argc)
				theme_sw = argv[++i];
			else
				theme_sw = "";
		} else if (!strcmp(argv[i], "-nostdgames")) {
			nostdgames_sw = 1;
#ifdef _LOCAL_APPDATA
		} else if (!strcmp(argv[i], "-appdata")) {
			if ((i + 1) < argc)
				appdata_sw = argv[++i];
			else
				appdata_sw = "";
#endif
		} else if (!strcmp(argv[i], "-chunksize")) {
			if ((i + 1) < argc)
				chunksize_sw = atoi(argv[++i]);
			else
				chunksize_sw = DEFAULT_CHUNKSIZE;
		} else if (!strcmp(argv[i], "-gamespath")) {
			if ((i + 1) < argc)
				games_sw = argv[++i];
			else
				games_sw = "";
		} else if (!strcmp(argv[i], "-themespath")) {
			if ((i + 1) < argc)
				themes_sw = argv[++i];
			else
				themes_sw = "";
		} else if (!strcmp(argv[i], "-idf")) {	
			if ((i + 1) < argc)
				idf_sw = argv[++i];
			else {
				fprintf(stderr,"No data directory specified.\n");
				err = 1;
				goto out;
			}
		} else if (!strcmp(argv[i], "-encode")) {	
			if ((i + 1) < argc)
				encode_sw = argv[++i];
			else {
				fprintf(stderr,"No lua file specified.\n");
				err = 1;
				goto out;
			}
			if ((i + 1) < argc)
				encode_output = argv[++i];
			else
				encode_output = "lua.enc";
		} else if (!strcmp(argv[i], "-version")) {
			version_sw = 1;
		} else if (!strcmp(argv[i], "-nopause")) {
			nopause_sw = 1;
		} else if (!strcmp(argv[i], "-software")) {
			software_sw = 1;
#ifdef _USE_UNPACK
		} else if (!strcmp(argv[i], "-install")) {
			if ((i + 1) < argc) {
				char *file = argv[++i];
				char *p;
				if (games_sw)
					p = games_sw;
				else
					p = game_local_games_path(1);
				if (setup_zip(file, p)) {
					err = 1;
					goto out;
				}
			}
#endif
		} else if (!strcmp(argv[i], "-quit")) {
			exit(0);
		} else if (!strcmp(argv[i], "-hinting")) {
			if ((i + 1) < argc)
				hinting_sw = atoi(argv[++i]);
			else
				hinting_sw = 1;
		} else if (!strcmp(argv[i], "-lua") || !strcmp(argv[i], "-luac")) {
			if ((i + 1) < argc) {
				lua_exec = !strcmp(argv[i], "-lua");
				lua_sw = argv[++ i];
				opt_index = i + 1;
				break;
			} else {
				fprintf(stderr, "No lua script.\n");
				err = 1;
				goto out;
			}
		} else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help")
			|| !strcmp(argv[i], "--help")) {
			usage();
			goto out;
		} else if (argv[i][0] == '-') {
			fprintf(stderr,"Unknown option: %s\n", argv[i]);
			usage();
			err = 1;
			goto out;
		} else if (!start_idf(argv[i])) {
			fprintf(stderr, "Adding idf: %s\n", argv[i]);
		} else if (!run_game(argv[i])) {
			fprintf(stderr, "Opening game: %s\n", argv[i]);
		}
#ifdef _USE_UNPACK
		else {
			char *p;
			if (games_sw)
				p = games_sw;
			else
				p = game_tmp_path();
			if (setup_zip(argv[i], p)) {
				err = 1;
				goto out;
			}
			clean_tmp = 1;
		}
#endif
	}
	cfg_load();

	if (opt_debug == 1 && debug_sw == 0) {
		debug_sw = 1;
		debug_init();
	}

	if (opt_vsync == 1 && vsync_sw == 0)
		vsync_sw = 1;

	if (version_sw) {
		fprintf(stdout, VERSION"\n");
		goto out;
	}

	if (lua_sw) {
		err = instead_init_lua(dirname(lua_sw));
		if (err)
			goto out;
		if (!err)
			err = instead_loadscript(lua_sw,
				argc - opt_index,
				argv + opt_index,
				lua_exec);
		instead_done();
		goto out;
	}

	if (encode_sw) {
		err = instead_encode(encode_sw, encode_output);
		goto out;
	}

	if (idf_sw) {
		char *p = malloc(strlen(idf_sw) + 5);
		if (p) {
			char *b;
			strcpy(p, idf_sw);
			b = basename(p);
			strcat(b, ".idf");
			idf_create(b, idf_sw);
			free(p);
		} else
			idf_create("data.idf", idf_sw);
		goto out;
	}
	menu_langs_lookup(dirpath(LANG_PATH));
	
	if (!langs_nr) {
		fprintf(stderr, "No languages found in: %s.\n", dirpath(LANG_PATH));
		err = 1;
		goto out;
	}
	if (!opt_lang || !opt_lang[0])
		opt_lang = game_locale();
	
	if (menu_lang_select(opt_lang) && menu_lang_select(LANG_DEF)) {
		fprintf(stderr, "Can not load default language.\n");
		err = 1;
		goto out;
	}
	
	if (games_sw)
		games_lookup(games_sw);

	if (owntheme_sw && !opt_owntheme) {
		opt_owntheme = 2;
	}

	if (!nostdgames_sw && games_lookup(dirpath(GAMES_PATH)))
		fprintf(stderr, "No games found in: %s.\n", GAMES_PATH);

	if (themes_sw)
		themes_lookup(themes_sw);

	if (!nostdthemes_sw) {
		themes_lookup(dirpath(THEMES_PATH));
		themes_lookup(game_local_themes_path());
	}
	
	if (!nostdgames_sw)
		games_lookup(game_local_games_path(0));

	if (start_idf_sw) {
		char *d, *b;
		char *dd, *bb;
		static char idf_game[255];
		d = strdup(start_idf_sw);
		b = strdup(start_idf_sw);
		if (d && b) {
			dd = dirname(d);
			bb = basename(b);
			if (!games_replace(dirpath(dd), bb)) {
				game_sw = idf_game;
				strncpy(idf_game, bb, sizeof(idf_game) - 1);
				idf_game[sizeof(idf_game) - 1] = 0;
			}
		}
		if (d)
			free(d); 
		if (b)
			free(b);
	}

	if (noauto_sw && opt_autosave)
		opt_autosave = 2;
	if (window_sw)
		opt_fs = 0;
	if (fullscreen_sw)
		opt_fs = 1;
	
	if (mode_sw)
		parse_mode(mode_sw, opt_mode);
	
	if (game_sw) {
		FREE(opt_game);
		opt_game = game_sw;
	}	

	if (theme_sw) {
		FREE(opt_theme);
		opt_theme = theme_sw;
	}	
	
	if (opt_theme)
		game_theme_select(opt_theme);
	if (!curtheme_dir)
		game_theme_select(DEFAULT_THEME);
	
	/* Initialize SDL */
	if (gfx_init() < 0)
		return -1;
#ifdef _USE_GTK
	gtk_init(&argc, &argv); /* must be called AFTER SDL_Init when using SDL2 */
#endif
	if (gfx_video_init() || input_init())
		return -1;

	if (game_init(opt_game)) {
		game_error();
	}

	game_loop();
	cfg_save();
	game_done(0);

	gfx_video_done();

#ifndef ANDROID
	gfx_done();
#endif
out:
	if (debug_sw)
		debug_done();
#ifdef _USE_GTK
/*	gtk_main_quit (); */
#endif
#ifdef _USE_UNPACK
	if (clean_tmp)
		remove_dir(game_tmp_path());
#endif
#if defined(ANDROID) || defined(IOS)
	exit(err);
#endif
	return err;
}