Пример #1
0
void model_readfield(model* m, char fname[], char varname[], int k, float* v)
{
    int ni, nj, nk;
    int mvid = model_getvarid(m, varname, 1);

    model_getvardims(m, mvid, &ni, &nj, &nk);
    assert(k < nk);
    readfield(fname, varname, k, ni, nj, nk, v);
}
Пример #2
0
int main(int argc, char **argv)
{
    char *filename;
    FILE *fd;
    int left = (9*9)*9;
    int count=0;

    if (argc == 2) {
        filename = argv[1];
    } else {
        filename = "fields.sud";
    }

    bf_backups = malloc(sizeof(struct bf_backups));

    if (!(fd = fopen(filename, "r"))) {
        printf("error opening file\n");
        exit(1);
    }
    if(readfield(fd)) {
        printf("error reading field\n");
        exit(1);
    }

    if (initialize())
        exit(1);

    fill_all();
    check_filled();
    printfield(wfield, 1);
    bruteforced = 0;

    /* main loop */
    while (left > 0) {
        check_validity();
        solve_run(&count);
        check_validity();
        left = get_left();
        count++;
    }
    if (final_check()) {
        winprintf(wtext, "\n\rSolved successfully\n\r");
    } else {
        winprintf(wtext, "\n\rThere are still some errors\n\r");
    }
    printfield(wfield, 1);
    press_any_key();
    endwin();
    return(0);
}
Пример #3
0
void model_readfield(model* m, char fname[], int mem, int time, char varname[], int k, float* v)
{
    readfield(fname, varname, k, v);
}
Пример #4
0
int showout()
{
	int     i, i2 = 0;
	char    foo[1024];
	char    tmpfile[STRLEN];
	char    buf[20];
	int     notreload = 0;
	GOPHER  newitem;
	while (1)
	{
		if (gopher_position < 0)
		{
			return;
		}
		print_gophertitle();
		printgopher_title();
		update_endline();
		if (!notreload)
		{
			i = 0;
			if (get_con(g_main[gopher_position]->server, g_main[gopher_position]->port) == -1)
			{
				show_message(NULL);
				free(g_main[gopher_position]);
				gopher_position--;
				notreload = 0;
				continue;
			}
			enterdir(g_main[gopher_position]->file);
			show_message("¶Áȡ׼±¸ÖÐ");
			for (i = 0; i < MAXGOPHERITEMS; i++)
			{
				if (readfield(a, foo, 1024) <= 0)
				{
					break;
				}
				if (foo[0] == '.' && foo[1] == '\r' && foo[2] == '\n')
				{
					break;
				}
				strncpy(newitem.title, foo, 70);
				if (readfield(a, foo, 1024) == 0)
				{
					break;
				}
				strncpy(newitem.file, foo, 80);
				if (readfield(a, foo, 1024) == 0)
				{
					break;
				}
				strncpy(newitem.server, foo, 40);
				if (readline(a, foo, 1024) == 0)
				{
					break;
				}
				newitem.port = atoi(foo);
				if (newitem.title[0] != newitem.file[0])
				{
					break;
				}
				if (newitem.title[0] != '0' && newitem.title[0] != '1')
				{
					i--;
					continue;
				}
				refresh();
				append_record(gophertmpfile, &newitem, sizeof(GOPHER));
				sprintf(buf, "[1;3%dmת[3%dm»»[3%dm×Ê[3%dmÁÏ[3%dmÖÐ", (i % 7) + 1
				        ,((i + 1) % 7) + 1, ((i + 2) % 7) + 1, ((i + 3) % 7) + 1, ((i + 4) % 7) + 1);
				show_message(buf);
			}
			show_message(NULL);
		}
		else
			notreload = 0;
		if (i <= 0)
		{
			move(3, 0);
			clrtobot();
			move(10, 0);
			clrtoeol();
			prints("                             ûÓÐÈκεÄ×ÊÁÏ...");
			pressanykey();
			free(g_main[gopher_position]);
			gopher_position--;
			continue;
		}
		close(a);
		move(0, 0);
		clrtobot();
		setlistrange(i);
		i2 = choose(NA, g_main[gopher_position]->position, print_gophertitle, deal_gopherkey, show_gopher, do_gopher);
		if (i2 == -1)
		{
			free(g_main[gopher_position]);
			clear_gophertmpfile();
			gopher_position--;
			continue;
		}
		g_main[gopher_position]->position = i2;
		get_record(gophertmpfile, &newitem, sizeof(GOPHER), i2 + 1);
		tmpitem = &newitem;
		if (newitem.title[0] == '0')
		{
			if (get_con(newitem.server, newitem.port) == -1)
				continue;
			enterdir(newitem.file);
			setuserfile(tmpfile, "gopher.tmp");
			savetmpfile(tmpfile);
			ansimore(tmpfile, YEA);
			notreload = 1;
			unlink(tmpfile);
			continue;
		}
		else
		{
			GOPHER *newgi;
			clear_gophertmpfile();
			gopher_position++;
			newgi = (GOPHER *) malloc(sizeof(GOPHER));
			strncpy(newgi->server, tmpitem->server, 40);
			strncpy(newgi->file, tmpitem->file, 80);
			strncpy(newgi->title, tmpitem->title, 70);
			newgi->port = tmpitem->port;
			newgi->position = 0;
			g_main[gopher_position] = newgi;
			continue;
		}
	}
}
Пример #5
0
static void
readfmt(                   /* read record format */
char  *spec,
int  output
)
{
	int  fd;
	char  *inptr;
	struct field  fmt;
	int  res;
	register struct field  *f;
						/* check for inline format */
	for (inptr = spec; *inptr; inptr++)
		if (*inptr == '$')
			break;
	if (*inptr)                             /* inline */
		inptr = spec;
	else {                                  /* from file */
		if ((fd = open(spec, 0)) == -1) {
			eputs(spec);
			eputs(": cannot open\n");
			quit(1);
		}
		res = read(fd, inpbuf+2, INBSIZ-2);
		if (res <= 0 || res >= INBSIZ-1) {
			eputs(spec);
			if (res < 0)
				eputs(": read error\n");
			else if (res == 0)
				eputs(": empty file\n");
			else if (res >= INBSIZ-1)
				eputs(": format too long\n");
			quit(1);
		}
		close(fd);
		(inptr=inpbuf+2)[res] = '\0';
	}
	f = &fmt;                               /* get fields */
	while ((res = readfield(&inptr)) != F_NUL) {
		f->next = (struct field *)emalloc(sizeof(struct field));
		f = f->next;
		f->type = res;
		switch (res & F_TYP) {
		case T_LIT:
			f->f.sl = savqstr(inpbuf);
			break;
		case T_STR:
			f->f.sv = getsvar(inpbuf);
			break;
		case T_NUM:
			if (output)
				f->f.ne = eparse(inpbuf);
			else
				f->f.nv = savestr(inpbuf);
			break;
		}
					/* add final newline if necessary */
		if (!igneol && *inptr == '\0' && inptr[-1] != '\n')
			inptr = "\n";
	}
	f->next = NULL;
	if (output)
		outfmt = fmt.next;
	else
		inpfmt = fmt.next;
}