Пример #1
0
void QLineEditEx::keyPressEvent(QKeyEvent *e)
{
    if(e->key() == Qt::Key_Up)	
	{
		loadHistory(true,m_History,m_Index);
		return;
	}
    else if (e->key() == Qt::Key_Down)
	{
		loadHistory(false,m_History,m_Index);
		return;
	}
	else if(e->key() == Qt::Key_Left)
	{
		if(m_TabIndex != -1)
		{
			suggest(false);
			return;
		}
	}
	else if(e->key() == Qt::Key_Right)
	{
		if(cursorPosition() == text().length() || m_TabIndex != -1)
		{
			suggest(true);
			return;
		}
	}
	else
	{
		m_TabBase.clear();
		m_TabIndex = -1;
	}
	QLineEdit::keyPressEvent(e);
}
Пример #2
0
void suggest(char password[], char out[], int len, int pos, char map[][2], int map_len) {
	// base case
	if(len == pos) {
		out[len] = '\0';
		printf("%s \n", out);
		return;
	}
	out[pos] = password[pos];
	suggest(password, out, len, pos+1, map, map_len);

	if(contains(password[pos], map, map_len)) {
		out[pos] = replace(password[pos], map, map_len);
		suggest(password, out, len, pos+1, map, map_len);
	}
}
Пример #3
0
AutoComplete::AutoComplete(SearchLineEdit *buddy, QLineEdit *lineEdit):
    QObject(buddy), buddy(buddy), lineEdit(lineEdit), enabled(true), suggester(0), itemHovering(false) {

    popup = new QListWidget();
    popup->setWindowFlags(Qt::Popup);
    popup->setFocusProxy(buddy);
    popup->installEventFilter(this);
    buddy->window()->installEventFilter(this);
    popup->setMouseTracking(true);

    // style
    popup->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    popup->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    popup->setWindowOpacity(.9);
    popup->setProperty("suggest", true);

    connect(popup, SIGNAL(itemClicked(QListWidgetItem*)), SLOT(acceptSuggestion()));
    connect(popup, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
            SLOT(currentItemChanged(QListWidgetItem*)));
    connect(popup, SIGNAL(itemEntered(QListWidgetItem*)), SLOT(itemEntered(QListWidgetItem *)));

    timer = new QTimer(this);
    timer->setSingleShot(true);
    timer->setInterval(500);
    connect(timer, SIGNAL(timeout()), SLOT(suggest()));
    connect(buddy, SIGNAL(textEdited(QString)), timer, SLOT(start()));
}
Пример #4
0
void main() {
	char password[] = "password";
	int len = strlen(password);
	char out[len];
	char map[3][2] = {{'a', '@'}, {'s', '$'}, {'o', '0'}};
	int map_len = sizeof(map)/sizeof(map[0]);
	suggest(password, out,  len, 0, map, map_len ); 
}
Пример #5
0
void Edit::suggest(double value)
{
  if (when() && !std::isnan(value)) {
    auto ctx = context();
    auto target = actualTarget();
    if (ctx && target) {
      ctx->suggest(get(), value);
    }
  }
}
Пример #6
0
KSpellDlg::KSpellDlg( QWidget * parent, const char * name, bool _progressbar, bool _modal )
  : KDialogBase(
      parent, name, _modal, i18n("Check Spelling"), Help|Cancel|User1,
      Cancel, true, i18n("&Finished")
    ),
    progressbar( false )
{
  Q_UNUSED( _progressbar );
  d = new KSpellDlgPrivate;
  d->ui = new KSpellUI( this );
  setMainWidget( d->ui );

  connect( d->ui->m_replaceBtn, SIGNAL(clicked()),
           this, SLOT(replace()));
  connect( this, SIGNAL(ready(bool)),
           d->ui->m_replaceBtn, SLOT(setEnabled(bool)) );

  connect( d->ui->m_replaceAllBtn, SIGNAL(clicked()), this, SLOT(replaceAll()));
  connect(this, SIGNAL(ready(bool)), d->ui->m_replaceAllBtn, SLOT(setEnabled(bool)));

  connect( d->ui->m_skipBtn, SIGNAL(clicked()), this, SLOT(ignore()));
  connect( this, SIGNAL(ready(bool)), d->ui->m_skipBtn, SLOT(setEnabled(bool)));

  connect( d->ui->m_skipAllBtn, SIGNAL(clicked()), this, SLOT(ignoreAll()));
  connect( this, SIGNAL(ready(bool)), d->ui->m_skipAllBtn, SLOT(setEnabled(bool)));

  connect( d->ui->m_addBtn, SIGNAL(clicked()), this, SLOT(add()));
  connect( this, SIGNAL(ready(bool)), d->ui->m_addBtn, SLOT(setEnabled(bool)));

  connect( d->ui->m_suggestBtn, SIGNAL(clicked()), this, SLOT(suggest()));
  connect( this, SIGNAL(ready(bool)), d->ui->m_suggestBtn, SLOT(setEnabled(bool)) );
  d->ui->m_suggestBtn->hide();

  connect(this, SIGNAL(user1Clicked()), this, SLOT(stop()));

  connect( d->ui->m_replacement, SIGNAL(textChanged(const QString &)),
           SLOT(textChanged(const QString &)) );

  connect( d->ui->m_replacement, SIGNAL(returnPressed()),   SLOT(replace()) );
  connect( d->ui->m_suggestions, SIGNAL(selectionChanged(QListViewItem*)),
           SLOT(slotSelectionChanged(QListViewItem*)) );

  connect( d->ui->m_suggestions, SIGNAL( doubleClicked ( QListViewItem *, const QPoint &, int ) ),
           SLOT( replace() ) );
  d->spellConfig = new KSpellConfig( 0, 0 ,0, false );
  d->spellConfig->fillDicts( d->ui->m_language );
  connect( d->ui->m_language, SIGNAL(activated(int)),
	   d->spellConfig, SLOT(sSetDictionary(int)) );
  connect( d->spellConfig, SIGNAL(configChanged()),
           SLOT(slotConfigChanged()) );

  setHelp( "spelldlg", "kspell" );
  setMinimumSize( sizeHint() );
  emit ready( false );
}
Пример #7
0
void Node::suggest(string localStr, int posistion , class Node *root)
{
	if( (localStr != root->NodeStr) && (root->ptrs[localStr[posistion]] != NULL ) )
	{
		suggest(localStr,posistion+1,root->ptrs[localStr[posistion]]);
	}
	else
	{
		printfunc(root);
	}
}
Пример #8
0
Edit::Edit(QQuickItem* pParent)
  : Targeted(pParent, Strength::Strong, 1.0)
{
  connect(this, &Edit::actualTargetChanged, [this](Variable* target) {
      set(target
          ? std::make_shared<rhea::edit_constraint>(target->variableImpl())
          : nullptr);
  });

  connect(this, &Edit::suggestedChanged, [this](double suggested) {
    suggest(suggested);
  });
}
Пример #9
0
    int
    test() {
        PhraseMap pm;
        pm.insert(1, "duckduckgo", "");
        pm.insert(2, "duckduckgeese", "");
        pm.insert(1, "duckduckgoose", "");
        pm.insert(9, "duckduckgoo", "");
        pm.insert(10, "duckgo", "");
        pm.insert(3, "dukgo", "");
        pm.insert(2, "luckkuckgo", "");
        pm.insert(5, "chuckchuckgo", "");
        pm.insert(15, "dilli - no one killed jessica", "");
        pm.insert(11, "aaitbaar - no one killed jessica", "");

        pm.finalize();

        RMQ st;
        vui_t weights;
        for (size_t i = 0; i < pm.repr.size(); ++i) {
            weights.push_back(pm.repr[i].weight);
        }

        st.initialize(weights);

        cout<<"\n";
        cout<<"suggest(\"d\"):\n"<<suggest(pm, st, "d")<<endl;
        cout<<"naive_suggest(\"d\"):\n"<<naive_suggest(pm, st, "d")<<endl;

        cout<<"\n";
        cout<<"suggest(\"a\"):\n"<<suggest(pm, st, "a")<<endl;
        cout<<"naive_suggest(\"a\"):\n"<<naive_suggest(pm, st, "a")<<endl;

        cout<<"\n";
        cout<<"suggest(\"b\"):\n"<<suggest(pm, st, "b")<<endl;
        cout<<"naive_suggest(\"b\"):\n"<<naive_suggest(pm, st, "b")<<endl;

        cout<<"\n";
        cout<<"suggest(\"duck\"):\n"<<suggest(pm, st, "duck")<<endl;
        cout<<"naive_suggest(\"duck\"):\n"<<naive_suggest(pm, st, "duck")<<endl;

        cout<<"\n";
        cout<<"suggest(\"k\"):\n"<<suggest(pm, st, "k")<<endl;
        cout<<"naive_suggest(\"k\"):\n"<<naive_suggest(pm, st, "k")<<endl;

        cout<<"\n";
        cout<<"suggest(\"ka\"):\n"<<suggest(pm, st, "ka")<<endl;
        cout<<"naive_suggest(\"ka\"):\n"<<naive_suggest(pm, st, "ka")<<endl;

        cout<<"\n";
        cout<<"suggest(\"c\"):\n"<<suggest(pm, st, "c")<<endl;
        cout<<"naive_suggest(\"c\"):\n"<<naive_suggest(pm, st, "c")<<endl;

        return 0;
    }
Пример #10
0
static void*
handle_suggest(enum mg_event event,
               struct mg_connection *conn,
               const struct mg_request_info *request_info) {

    ++nreq;
    if (building) {
        print_HTTP_response(conn, 412, "Busy");
        return (void*)"";
    }

    std::string q    = get_qs(request_info, "q");
    std::string sn   = get_qs(request_info, "n");
    std::string cb   = get_qs(request_info, "callback");
    std::string type = get_qs(request_info, "type");

    DCERR("handle_suggest::q:"<<q<<", sn:"<<sn<<", callback: "<<cb<<endl);

    unsigned int n = sn.empty() ? NMAX : atoi(sn.c_str());
    if (n > NMAX) {
        n = NMAX;
    }

    const bool has_cb = !cb.empty();
    if (has_cb && !is_valid_cb(cb)) {
        print_HTTP_response(conn, 400, "Invalid Request");
        return (void*)"";
    }

    print_HTTP_response(conn, 200, "OK");

    str_lowercase(q);
    vp_t results = suggest(pm, st, q, n);

    /*
      for (size_t i = 0; i < results.size(); ++i) {
      mg_printf(conn, "%s:%d\n", results[i].first.c_str(), results[i].second);
      }
    */
    if (has_cb) {
        mg_printf(conn, "%s(%s);\n", cb.c_str(), results_json(q, results, type).c_str());
    }
    else {
        mg_printf(conn, "%s\n", results_json(q, results, type).c_str());
    }

    return (void*)"";
}
Пример #11
0
static void handle_suggest(client_t *client, parsed_url_t &url) {
    ++nreq;
    std::string body;
    headers_t headers;
    headers["Cache-Control"] = "no-cache";

    if (building) {
        write_response(client, 412, "Busy", headers, body);
        return;
    }

    std::string q    = unescape_query(url.query["q"]);
    std::string sn   = url.query["n"];
    std::string cb   = unescape_query(url.query["callback"]);
    std::string type = unescape_query(url.query["type"]);

    DCERR("handle_suggest::q:"<<q<<", sn:"<<sn<<", callback: "<<cb<<endl);

    unsigned int n = sn.empty() ? NMAX : atoi(sn.c_str());
    if (n > NMAX) {
        n = NMAX;
    }
    if (n < 1) {
        n = 1;
    }

    const bool has_cb = !cb.empty();
    str_lowercase(q);
    vp_t results = suggest(pm, st, q, n);

    /*
      for (size_t i = 0; i < results.size(); ++i) {
      mg_printf(conn, "%s:%d\n", results[i].first.c_str(), results[i].second);
      }
    */
    headers["Content-Type"] = "text/plain; charset=UTF-8";
    if (has_cb) {
        body = cb + "(" + results_json(q, results, type) + ");\n";
    }
    else {
        body = results_json(q, results, type) + "\n";
    }

    write_response(client, 200, "OK", headers, body);
}
Пример #12
0
void Speller::populateContextMenu(QMenu* menu, const QWebHitTestResult &hitTest)
{
    m_element = hitTest.element();

    if (!m_enabled || m_element.isNull() ||
            m_element.attribute(QLatin1String("type")) == QLatin1String("password")) {
        return;
    }

    const QString text = m_element.evaluateJavaScript("this.value").toString();
    const int pos = m_element.evaluateJavaScript("this.selectionStart").toInt() + 1;

    QTextBoundaryFinder finder =  QTextBoundaryFinder(QTextBoundaryFinder::Word, text);
    finder.setPosition(pos);
    m_startPos = finder.toPreviousBoundary();
    m_endPos = finder.toNextBoundary();

    const QString &word = text.mid(m_startPos, m_endPos - m_startPos).trimmed();

    if (!isValidWord(word) || !isMisspelled(word)) {
        return;
    }

    const int limit = 6;
    QStringList suggests = suggest(word);
    int count = suggests.count() > limit ? limit : suggests.count();

    QFont boldFont = menu->font();
    boldFont.setBold(true);

    for (int i = 0; i < count; ++i) {
        QAction* act = menu->addAction(suggests.at(i), this, SLOT(replaceWord()));
        act->setData(suggests.at(i));
        act->setFont(boldFont);
    }

    if (count == 0) {
        menu->addAction(tr("No suggestions"))->setEnabled(false);
    }

    menu->addAction(tr("Add to dictionary"), this, SLOT(addToDictionary()))->setData(word);
    menu->addSeparator();
}
Пример #13
0
// will only try to correct token for each leaf node 
// (SINGLE Query) and backup original token on Query::attr field, then 
// run it on the searcher
bool Suggester::suggest(Query *q) {
  if (q->sign == SIGN_SINGLE) {
    string t = q->token;
    if (match(t))  // correct word
      return false;
    vector<int> collect;
    kgram(t, collect);
    levenrank(t, collect);
    if (collect.size() > 0) {
      q->attr = q->token;
      q->token = ir->widmap[collect[0]];
      return true;
    }
    return false;
  }
  bool modified = false;
  for (unsigned i = 0; i < q->size(); ++i)
    if (suggest(q->get(i)))
      modified = true;
  return modified;
}
Пример #14
0
void parse_command(char *buf, struct gameinfo *gi) {
	char *tok, *param;
	int i_param;
	tok = strtok(buf, " "); //split input
	if (tok != 0) {
		if (strcmp(tok, "newgame") == 0) {
			param = strtok(0, " "); //get parameter if there is one
			//call appropriate functions
			if (param == 0) {
				newgame(gi, gi->default_size);
				findlegal(gi);
				showstate(gi);
			}
			else {
				if (isnum(param)) {
					i_param = atoi(param);
					if (i_param >= 4 && i_param <= 26 && i_param%2 == 0) {
						newgame(gi, i_param);
						findlegal(gi);
						showstate(gi);
					}
					else printf("Invalid size for command newgame (4 <= size <= 26,  size is an even number)\n");
				}
				else printf("Invalid parameter for command newgame (parameter is an integer)\n");
			}
		}
		else if (strcmp(tok, "play") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Missing parameter for command play\n");
			else if (gi->gamestarted == 0) printf("No game in progress\n");
			else if (gi->gs->nowplaying != gi->playercolor) printf("It's not your turn to play\n");
			else if (play(gi, param) == 1) showstate(gi); //if it's a valid move
		}
		else if (strcmp(tok, "cont") == 0) cont(gi);
		else if (strcmp(tok, "undo") == 0) undo(gi);
		else if (strcmp(tok, "suggest") == 0) suggest(gi);
		else if (strcmp(tok, "showstate") == 0) showstate(gi);
		else if (strcmp(tok, "save") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Missing parameter for command save\n");
			else if(gi->gamestarted == 0) printf("No game in progress\n");
			else save(gi, param);
		}
		else if (strcmp(tok, "load") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Missing parameter for command load\n");
			else load(gi, param);
		}
		else if (strcmp(tok, "selectcolor") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Missing parameter for command selectcolor\n");
			else {
				if (strcmp(param, "black") == 0) gi->playercolor = 'B';
				else if (strcmp(param, "white") == 0) gi->playercolor = 'W';
				else printf("Invalid parameter for command selectcolor (parameter is 'black' or 'white')\n");
			}
		}
		else if (strcmp(tok, "showlegal") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Missing parameter for command showlegal\n");
			else {
				if (strcmp(param, "on") == 0) gi->showlegal = 1;
				else if (strcmp(param, "off") == 0) gi->showlegal = 0;
				else printf("Invalid parameter for command showlegal (parameter is 'on' or 'off')\n");
			}
		}
		else if (strcmp(tok, "level") == 0) {
			param = strtok(0, " ");
			if (param == 0) printf("Current difficulty level: %d\n", gi->difficulty);
			else {
				if (isnum(param)) {
					i_param = atoi(param);
					if (i_param >= 1) gi->difficulty = i_param;
					else printf("Invalid parameter for command level (level >= 1)\n");
				}
				else printf("Invalid parameter for command level (parameter is an integer)\n");
			}
		}
		else if (strcmp(tok, "help") == 0) {
			printf("Available commands:\n"
				"newgame [<size>] - Start a new game,  optional parameter size (default %d)\n"
				"play <move> - Place a marker at the specified position\n"
				"cont - Allow the computer to play\n"
				"undo - Undo your last move\n"
				"suggest - Ask the computer to suggest a move\n"
				"selectcolor <black|white> - Select your color\n"
				"showlegal <on|off> - Show all possible moves\n"
				"level [<difficulty>] - Select a difficulty (difficulty >= 1) - If no parameter,  show the current difficulty\n"
				"save <filename> - Save the current game in a file\n"
				"load <filename> - Load game from a file\n"
				"showstate - Show the current state of the game\n"
				"quit - Exit the game\n"
				"help - Show the command list\n\n"
				, gi->default_size);
		}
		else printf("Unknown command %s (type help for a list of commands)\n", tok);
	}
}
Пример #15
0
/*
 * Dynamic mode loader for NetBSD/Amiga grf devices.
 */
int
main(int ac, char  **av)
{
	struct	grfvideo_mode gv[1];
	struct	grf_flag *grf_flagp;
	FILE	*fp;
	int	c, y, grffd;
	size_t  i;
	int	lineno = 0;
	int	uplim, lowlim;
	char	rawdata = 0, testmode = 0;
	char	*grfdevice = 0, *ptr;
	char	*modefile = 0;
	char	buf[_POSIX2_LINE_MAX];
	char	*cps[31];
	char	*p;
	const char	*errortext;


	while ((c = getopt(ac, av, "rt")) != -1) {
		switch (c) {
		case 'r':	/* raw output */
			rawdata = 1;
			break;
		case 't':	/* test the modefile without setting it */
			testmode = 1;
			break;
		default:
			printf("grfconfig [-r] device [file]\n");
			return (1);
		}
	}
	ac -= optind;
	av += optind;


	if (ac < 1)
		errx(EXIT_FAILURE, "No grf device specified");
	grfdevice = av[0];

	if (ac >= 2)
		modefile = av[1];

	if ((grffd = open(grfdevice, O_RDWR)) == -1)
		err(EXIT_FAILURE, "Can't open grf device `%s'", grfdevice);

	/* If a mode file is specificied, load it in, don't display any info. */

	if (modefile) {
		if (!(fp = fopen(modefile, "r")))
			err(EXIT_FAILURE, 
			    "Cannot open mode definition file `%s'", modefile);

		while (fgets(buf, sizeof(buf), fp)) {
			char *obuf, tbuf[_POSIX2_LINE_MAX], *tbuf2;
			/*
			 * check for end-of-section, comments, strip off trailing
			 * spaces and newline character.
			 */
			for (p = buf; isspace((unsigned char)*p); ++p)
				continue;
			if (*p == '\0' || *p == '#')
				continue;
			for (p = strchr(buf, '\0'); isspace((unsigned char)*--p);)
				continue;
			*++p = '\0';

			obuf = buf;
			tbuf2 = tbuf;
			while ((*tbuf2 = *obuf) != '\0') {
				if (*tbuf2 == '#') {
					*tbuf2 = '\0';
					break;
				}
				if (isupper((unsigned char)*tbuf2)) {
					*tbuf2 = tolower((unsigned char)*tbuf2);
				}
				obuf++;
				tbuf2++;
			}
			obuf = tbuf;

			lineno = lineno + 1;

#define SP " \b\t\r\n"
			memset(cps, 0, sizeof(cps));
			for (i = 0, ptr = strtok(buf, SP);
			    ptr != NULL && i < __arraycount(cps);
			    i++, ptr = strtok(NULL, SP))
				cps[i] = ptr;


			if (i < 14)
				errx(EXIT_FAILURE, "Too few values in mode "
				    "definition file: `%s'\n", obuf);

			gv->pixel_clock	= atoi(cps[1]);
			gv->disp_width	= atoi(cps[2]);
			gv->disp_height	= atoi(cps[3]);
			gv->depth	= atoi(cps[4]);
			gv->hblank_start	= atoi(cps[5]);
			gv->hsync_start	= atoi(cps[6]);
			gv->hsync_stop	= atoi(cps[7]);
			gv->htotal	= atoi(cps[8]);
			gv->vblank_start	= atoi(cps[9]);
			gv->vsync_start	= atoi(cps[10]);
			gv->vsync_stop	= atoi(cps[11]);
			gv->vtotal	= atoi(cps[12]);

			if ((y = atoi(cps[0])))
				gv->mode_num = y;
			else
				if (strncasecmp("c", cps[0], 1) == 0) {
					gv->mode_num = 255;
					gv->depth = 4;
				} else {
					errx(EXIT_FAILURE,
					    "Illegal mode number: %s", cps[0]);
				}

			if ((gv->pixel_clock == 0) ||
			    (gv->disp_width == 0) ||
			    (gv->disp_height == 0) ||
			    (gv->depth == 0) ||
			    (gv->hblank_start == 0) ||
			    (gv->hsync_start == 0) ||
			    (gv->hsync_stop == 0) ||
			    (gv->htotal == 0) ||
			    (gv->vblank_start == 0) ||
			    (gv->vsync_start == 0) ||
			    (gv->vsync_stop == 0) ||
			    (gv->vtotal == 0)) {
				errx(EXIT_FAILURE, "Illegal value in "
				    "mode #%d: `%s'", gv->mode_num, obuf);
			}

			if (strstr(obuf, "default") != NULL) {
				gv->disp_flags = GRF_FLAGS_DEFAULT;
			} else {
				gv->disp_flags = GRF_FLAGS_DEFAULT;
				for (grf_flagp = grf_flags;
				  grf_flagp->grf_flag_number; grf_flagp++) {
				    if (strstr(obuf, grf_flagp->grf_flag_name) != NULL) {
					gv->disp_flags |= grf_flagp->grf_flag_number;
				    }
				}
				if (gv->disp_flags == GRF_FLAGS_DEFAULT)
					errx(EXIT_FAILURE, "Your are using a "
					    "mode file with an obsolete "
					    "format");
			}

			/*
			 * Check for impossible gv->disp_flags:
			 * doublescan and interlace,
			 * +hsync and -hsync
			 * +vsync and -vsync.
			 */
			errortext = NULL;
			if ((gv->disp_flags & GRF_FLAGS_DBLSCAN) &&
			    (gv->disp_flags & GRF_FLAGS_LACE))
				errortext = "Interlace and Doublescan";
			if ((gv->disp_flags & GRF_FLAGS_PHSYNC) &&
			    (gv->disp_flags & GRF_FLAGS_NHSYNC))
				errortext = "+hsync and -hsync";
			if ((gv->disp_flags & GRF_FLAGS_PVSYNC) &&
			    (gv->disp_flags & GRF_FLAGS_NVSYNC))
				errortext = "+vsync and -vsync";

			if (errortext != NULL)
				errx(EXIT_FAILURE, "Illegal flags in "
				    "mode #%d: `%s' are both defined",
				    gv->mode_num, errortext);

			/* Check for old horizontal cycle values */
			if ((gv->htotal < (gv->disp_width / 4))) {
				gv->hblank_start *= 8;
				gv->hsync_start *= 8;
				gv->hsync_stop *= 8;
				gv->htotal *= 8;
				suggest(gv, "horizontal videoclock cycle "
				    "values", obuf);
				return EXIT_FAILURE;
			}

			/* Check for old interlace or doublescan modes */
			uplim = gv->disp_height + (gv->disp_height / 4);
			lowlim = gv->disp_height - (gv->disp_height / 4);
			if (((gv->vtotal * 2) > lowlim) &&
			    ((gv->vtotal * 2) < uplim)) {
				gv->vblank_start *= 2;
				gv->vsync_start *= 2;
				gv->vsync_stop *= 2;
				gv->vtotal *= 2;
				gv->disp_flags &= ~GRF_FLAGS_DBLSCAN;
				gv->disp_flags |= GRF_FLAGS_LACE;
				suggest(gv, "vertical values for interlace "
				    "modes", obuf);
				return EXIT_FAILURE;
			} else if (((gv->vtotal / 2) > lowlim) &&
			    ((gv->vtotal / 2) < uplim)) {
				gv->vblank_start /= 2;
				gv->vsync_start /= 2;
				gv->vsync_stop /= 2;
				gv->vtotal /= 2;
				gv->disp_flags &= ~GRF_FLAGS_LACE;
				gv->disp_flags |= GRF_FLAGS_DBLSCAN;
				suggest(gv, "vertical values for doublescan "
				    "modes", obuf);
				return EXIT_FAILURE;
			}

			if (testmode == 1) {
				if (lineno == 1)
					printf("num clk wid hi dep hbs "
					    "hss hse ht vbs vss vse vt "
					    "flags\n");
				print_modeline(stdout, gv, 1);
			} else {
				gv->mode_descr[0] = 0;
				if (ioctl(grffd, GRFIOCSETMON, (char *) gv) < 0)
					err(EXIT_FAILURE, "bad monitor "
					    "definition for mode #%d",
					    gv->mode_num);
			}
		}
		fclose(fp);
	} else {
		ioctl(grffd, GRFGETNUMVM, &y);
		y += 2;
		for (c = 1; c < y; c++) {
			c = gv->mode_num = (c != (y - 1)) ? c : 255;
			if (ioctl(grffd, GRFGETVMODE, gv) < 0)
				continue;
			if (rawdata) {
				print_modeline(stdout, gv, 0);
				continue;
			}
			if (c == 255)
				printf("Console: ");
			else
				printf("%2d: ", gv->mode_num);

			printf("%dx%d",
			    gv->disp_width,
			    gv->disp_height);

			if (c != 255)
				printf("x%d", gv->depth);
			else
				printf(" (%dx%d)",
				    gv->disp_width / 8,
				    gv->disp_height / gv->depth);

			printf("\t%ld.%ldkHz @ %ldHz",
			    gv->pixel_clock / (gv->htotal * 1000),
			    (gv->pixel_clock / (gv->htotal * 100)) 
    	    	    	    	% 10,
			    gv->pixel_clock / (gv->htotal * gv->vtotal));
			printf(" flags:");
				
			if (gv->disp_flags == GRF_FLAGS_DEFAULT) {
				printf(" default\n");
				continue;
			}

			for (grf_flagp = grf_flags;
			    grf_flagp->grf_flag_number; grf_flagp++)
				if (gv->disp_flags & grf_flagp->grf_flag_number)
					printf(" %s", grf_flagp->grf_flag_name);
			printf("\n");
		}
	}

	close(grffd);
	return EXIT_SUCCESS;
}
Пример #16
0
void Edit::addIn(Context& ctx)
{
  Targeted::addIn(ctx);
  suggest(mSuggested);
}
Пример #17
0
void cuboid::suggest( const cuboid &cube )
    {
    suggest( cube.minimum() );
    suggest( cube.maximum() );
    }
Пример #18
0
void play()
{
	char str[256],str2[256],log[81],done,doub,dh,split_card,suggestion
		,*YouWereDealt="\1n\1k\0015 You \1n\1m were dealt: %s\r\n"
		,*UserWasDealt="\1n\1m\1h%s\1n\1m was dealt: %s\r\n"
		,*YourHand="\1n\1k\0015 You \1n\1m                     (%2d) %s"
		,*UserHand="\1n\1m\1h%-25s \1n\1m(%2d) %s"
		,*DealerHand="\1n\1hDealer                    \1n\1m(%2d) "
		,*Bust="\1n\1r\1hBust\1n\r\n"
		,*Natural="\1g\1h\1iNatural "
		,*Three7s="\1r\1h\1iThree 7's "
		,*Blackjack="\1n\0011\1k Blackjack! \1n\r\n"
		,*TwentyOne="\1n\0012\1k Twenty-one \1n\r\n";
	int h,i,j,file;
	uint max;
	long val;
	time_t start,now;
	struct tm* tm;

sprintf(str,"MESSAGE.%d",node_num);         /* remove message if waiting */
if(fexist(str))
    remove(str);

getgamedat(0);
if(node[node_num-1]) {
	getgamedat(1);
	node[node_num-1]=0;
	putgamedat();
	getgamedat(0); }

if(total_players && misc&INPLAY) {
	bputs("\r\n\1hWaiting for end of hand (^A to abort)...\1n");
	start=now=time(NULL);
	getgamedat(0);
	while(total_players && misc&INPLAY) {
		if((i=inkey(0))!=0) {	 /* if key was hit */
			if(i==1) {		 /* if ctrl-a */
				bputs("\r\n");
				return; } }  /* return */
		mswait(100);
		getgamedat(0);
		now=time(NULL);
		if(now-start>300) { /* only wait up to 5 minutes */
			bputs("\r\ntimeout\r\n");
			return; } }
	bputs("\r\n"); }

getgamedat(1);
node[node_num-1]=user_number;
putgamedat();

if(!total_players)
    shuffle();
else
	listplayers();

sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,joined());
putallnodemsg(str);

while(1) {
	aborted=0;
	#if DEBUG
	debugline("top of loop");
	#endif
	if(autoplay)
		lncntr=0;
	bprintf(ShoeStatus,cur_card,total_decks*52);
	if(cur_card>(total_decks*52)-(total_players*10)-10 && lastplayer())
		shuffle();
	getgamedat(1);
	misc&=~INPLAY;
	status[node_num-1]=BET;
	node[node_num-1]=user_number;
	putgamedat();

	bprintf("\r\n\1n\1cYou have \1h%s\1n\1ck credits\r\n"
		,ultoac(credits/1024L,str));
	if(credits<min_bet/1024) {
		bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet);
		bputs("\1n\1r\1hCome back when you have more credits.\r\n");
        break; }
	if(credits/1024L>(ulong)max_bet)
		max=max_bet;
	else
		max=credits/1024L;
	sprintf(str,"\r\nBet amount (in kilobytes) or ~Quit [%u]: "
		,ibet<credits/1024L ? ibet : credits/1024L);
	chat();
	mnemonics(str);
	if(autoplay && keyhit())
		autoplay=0;
	if(autoplay)
		i=ibet;
	else
		i=getnum(max);
	if(i==-1)	/* if user hit ^C or 'Q' */
		break;
	bputs("\r\n");
	if(i)		/* if user entered a value */
		bet[0]=i;
	else		/* if user hit enter */
		bet[0]=ibet<credits/1024L ? ibet : credits/1024L;
	if(bet[0]<min_bet) {
		bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet);
		bputs("\1n\1r\1hCome back when you're ready to bet more.\r\n");
		break; }
	ibet=bet[0];
	getgamedat(0);	/* to get all new arrivals */
	sprintf(str,"\1m\1h%s\1n\1m bet \1n\1h%u\1n\1mk\r\n",user_name,bet[0]);
	putallnodemsg(str);

	pc[0]=2;						/* init player's 1st hand to 2 cards */
	for(i=1;i<MAX_HANDS;i++)		/* init player's other hands to 0 cards */
		pc[i]=0;
	hands=1;						/* init total player's hands to 1 */

	getgamedat(1);					/* first come first serve to be the */
	for(i=0;i<total_nodes;i++)		/* dealer in control of sync */
		if(node[i] && status[i]==SYNC_D)
			break;
	if(i==total_nodes) {
		#if DEBUG
		debugline("syncdealer");
		#endif
		syncdealer();  }			/* all players meet here */
	else {							/* first player is current after here */
		#if DEBUG
		debugline("syncplayer");
		#endif
		syncplayer(); } 			/* game is closed (INPLAY) at this point */

	#if DEBUG
	debugline("waitturn 1");
	#endif
    waitturn();
	getnodemsg();
										/* Initial deal card #1 */
	getcarddat();
	player[0][0]=card[cur_card++];
	putcarddat();
	sprintf(str,YouWereDealt,cardstr(card[cur_card-1]));
	if(!symbols)
		strip_symbols(str);
    bputs(str);
	sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1]));
    putallnodemsg(str);
	
	if(lastplayer()) {
		getcarddat();
		dealer[0]=card[cur_card++];
		dc=1;
		putcarddat(); }
	nextplayer();
	#if DEBUG
	debugline("waitturn 2");
	#endif
	waitturn();
	getnodemsg();

	getcarddat();					   /* Initial deal card #2 */
	player[0][1]=card[cur_card++];
	putcarddat();
	sprintf(str,YouWereDealt,cardstr(card[cur_card-1]));
	if(!symbols)
		strip_symbols(str);
	bputs(str);
	sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1]));
    putallnodemsg(str);
	
	if(lastplayer()) {
		getcarddat();
		dealer[1]=card[cur_card++];
		dc=2;
		putcarddat(); }
	nextplayer();
	#if DEBUG
	debugline("waitturn 3");
	#endif
	waitturn();
	getnodemsg();
	getcarddat();

	for(i=0;i<hands;i++) {
		if(autoplay)
			lncntr=0;
		done=doub=0;
		while(!done && pc[i]<MAX_CARDS && cur_card<total_decks*52) {
			h=hand(player[i],pc[i]);
			str[0]=0;
			for(j=0;j<pc[i];j++) {
				strcat(str,cardstr(player[i][j]));
				strcat(str," "); }
			j=bstrlen(str);
			while(j++<19)
				strcat(str," ");
			if(h>21) {
				strcat(str,Bust);
				sprintf(str2,YourHand,h,str);
				if(!symbols)
					strip_symbols(str2);
				bputs(str2);
				sprintf(str2,UserHand,user_name,h,str);
				putallnodemsg(str2);
				break; }
			if(h==21) {
				if(pc[i]==2) {	/* blackjack */
					if(player[i][0].suit==player[i][1].suit)
						strcat(str,Natural);
					strcat(str,Blackjack); }
				else {
					if(player[i][0].value==7
						&& player[i][1].value==7
						&& player[i][2].value==7)
						strcat(str,Three7s);
					strcat(str,TwentyOne); }
				sprintf(str2,YourHand,h,str);
				if(!symbols)
					strip_symbols(str2);
				bputs(str2);
				sprintf(str2,UserHand,user_name,h,str);
                putallnodemsg(str2);
				// fdelay(500);
				break; }
			strcat(str,"\r\n");
			sprintf(str2,YourHand,h,str);
			if(!symbols)
				strip_symbols(str2);
			bputs(str2);
			sprintf(str2,UserHand,user_name,h,str);
			putallnodemsg(str2);
			if(doub)
				break;
			sprintf(str,"\1n\1hDealer\1n\1m card up: %s\r\n"
				,cardstr(dealer[1]));
			if(!symbols)
				strip_symbols(str);
			bputs(str);

			if(tutor) {
				if(pc[i]==2)
					split_card=pair(player[i],pc[i]);
				else
					split_card=0;
                if(split_card==A
					|| (split_card==9 && (dealer[1].value<7
						|| (dealer[1].value>7 && dealer[1].value<10)))
                    || split_card==8
					|| (split_card==7 && dealer[1].value<9)
					|| (split_card==6 && dealer[1].value<7)
					|| (split_card==4 && dealer[1].value==5)
					|| (split_card && split_card<4 && dealer[1].value<8))
					suggestion='P';
                else if(soft(player[i],pc[i])) {
                    if(h>18)
						suggestion='S';
					else if(pc[i]==2
						&& ((h==18
							&& dealer[1].value>3 && dealer[1].value<7)
                        || (h==17
							&& dealer[1].value>2 && dealer[1].value<7)
                        || (h>13
							&& dealer[1].value>3 && dealer[1].value<7)
                        || (h==12
							&& dealer[1].value>4 && dealer[1].value<7)))
						suggestion='D';
                    else
						suggestion='H'; }
                else { /* hard */
					if(h>16 || (h>13 && dealer[1].value<7)
						|| (h==12 && dealer[1].value>3 && dealer[1].value<7))
						suggestion='S';
					else if(pc[i]==2
						&& (h==11 || (h==10 && dealer[1].value<10)
						|| (h==9 && dealer[1].value<7)))
						suggestion='D';
                    else
						suggestion='H'; } }

			if(tutor==1)
				suggest(suggestion);
			strcpy(str,"\r\n~Hit");
			strcpy(tmp,"H\r");
			if(bet[i]+ibet<=credits/1024L && pc[i]==2) {
				strcat(str,", ~Double");
				strcat(tmp,"D"); }
			if(bet[i]+ibet<=credits/1024L && pc[i]==2 && hands<MAX_HANDS
				&& player[i][0].value==player[i][1].value) {
				strcat(str,", ~Split");
				strcat(tmp,"S"); }
			strcat(str,", or [Stand]: ");
			chat();
			mnemonics(str);
			if(autoplay && keyhit())
				autoplay=0;


			if(autoplay) {
				lncntr=0;
				bputs("\r\n");
				strcpy(str,stand());
				bputs(str);
				putallnodemsg(str);
				done=1; }
			else
			switch(getkeys(tmp,0)) {
				case 'H':     /* hit */
					if(tutor==2 && suggestion!='H')
						wrong(suggestion);
					strcpy(str,hit());
					bputs(str);
					putallnodemsg(str);
					getcarddat();
					player[i][pc[i]++]=card[cur_card++];
					putcarddat();
					break;
				case 'D':   /* double down */
					if(tutor==2 && suggestion!='D')
                        wrong(suggestion);
					strcpy(str,doubit());
					bputs(str);
					putallnodemsg(str);
					getcarddat();
					player[i][pc[i]++]=card[cur_card++];
					putcarddat();
					doub=1;
					bet[i]+=ibet;
					break;
				case 'S':   /* split */
					if(tutor==2 && suggestion!='P')
                        wrong(suggestion);
					strcpy(str,split());
					bputs(str);
					putallnodemsg(str);
					player[hands][0]=player[i][1];
					getcarddat();
					player[i][1]=card[cur_card++];
					player[hands][1]=card[cur_card++];
					putcarddat();
					pc[hands]=2;
					bet[hands]=ibet;
					hands++;
					break;
				case CR:
					if(tutor==2 && suggestion!='S')
                        wrong(suggestion);
					strcpy(str,stand());
					bputs(str);
					putallnodemsg(str);
					done=1;
					break; } } }

	if(lastplayer()) {	/* last player plays the dealer's hand */
		getcarddat();
		while(hand(dealer,dc)<17 && dc<MAX_CARDS && cur_card<total_decks*52)
			dealer[dc++]=card[cur_card++];
		putcarddat(); }

	nextplayer();
	#if DEBUG
	debugline("waitturn 4");
	#endif
	waitturn();
	getnodemsg();

	if(firstplayer()==node_num) {
		strcpy(str,"\1n\0014\1h Final \1n\r\n");
		bputs(str);
		putallnodemsg(str); }
	getcarddat();
	dh=hand(dealer,dc); 					/* display dealer's hand */
	sprintf(str,DealerHand,dh);
	for(i=0;i<dc;i++) {
		strcat(str,cardstr(dealer[i]));
		strcat(str," "); }
	i=bstrlen(str);
	while(i++<50)				/* was 50 */
		strcat(str," ");
	if(dh>21) {
		strcat(str,Bust);
		if(!symbols)
			strip_symbols(str);
		bputs(str); }
	else if(dh==21) {
		if(dc==2) { 	/* blackjack */
			if(dealer[0].suit==dealer[1].suit)
				strcat(str,Natural);
			strcat(str,Blackjack); }
		else {			/* twenty-one */
			if(dc==3 && dealer[0].value==7 && dealer[1].value==7
				&& dealer[2].value==7)
				strcat(str,Three7s);
			strcat(str,TwentyOne); }
		if(!symbols)
            strip_symbols(str);
		bputs(str); }
	else {
		if(!symbols)
            strip_symbols(str);
		bprintf("%s\r\n",str); }

	for(i=0;i<hands;i++) {						/* display player's hand(s) */
		h=hand(player[i],pc[i]);
		str[0]=0;
		for(j=0;j<pc[i];j++) {
			strcat(str,cardstr(player[i][j]));
			strcat(str," "); }
		j=bstrlen(str);
		while(j++<19)
			strcat(str," ");
		if(logit) {
			now=time(NULL);
			tm=localtime(&now);
			sprintf(log,"%02d%02d%02d.log"                  /* log winnings */
				,tm->tm_mon+1,tm->tm_mday,tm->tm_year%100);
			if((file=nopen(log,O_RDONLY))!=-1) {
				read(file,tmp,filelength(file));
				tmp[filelength(file)]=0;
				val=atol(tmp);
				close(file); }
			else
				val=0L;
			if((file=nopen(log,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
				bprintf("error opening %s\r\n",log);
				return; } }
		if(h<22 && (h>dh || dh>21	/* player won */
			|| (h==21 && pc[i]==2 && dh==21 && dh>2))) {	/* blackjack */
			j=bet[i];								  /* and dealer got 21 */
			if(h==21 && 	/* natural blackjack or three 7's */
				((player[i][0].value==7 && player[i][1].value==7
				&& player[i][2].value==7)
				|| (pc[i]==2 && player[i][0].suit==player[i][1].suit)))
				j*=2;
			else if(h==21 && pc[i]==2)	/* regular blackjack */
				j*=1.5; /* blackjack pays 1 1/2 to 1 */
			sprintf(tmp,"\1n\1h\1m\1iWon!\1n\1h %u\1n\1mk",j);
			strcat(str,tmp);
			credits+=j*1024L;
			val-=j*1024L;
			moduserdat(); }
		else if(h<22 && h==dh)
			strcat(str,"\1n\1hPush");
		else {
			strcat(str,"\1nLost");
			credits-=bet[i]*1024L;
			val+=bet[i]*1024L;
			moduserdat(); }
		if(logit) {
			sprintf(tmp,"%ld",val);
			write(file,tmp,strlen(tmp));
			close(file); }					/* close winning log */
		strcat(str,"\1n\r\n");
		sprintf(str2,YourHand,h,str);
		if(!symbols)
			strip_symbols(str2);
		bputs(str2);
		sprintf(str2,UserHand,user_name,h,str);
		putallnodemsg(str2); }

	nextplayer();
	if(!lastplayer()) {
		#if DEBUG
		debugline("lastplayer waitturn");
		#endif
		waitturn();
		nextplayer(); }
	#if DEBUG
	debugline("end of loop");
	#endif
	getnodemsg(); }

getgamedat(1);
node[node_num-1]=0;
putgamedat();
sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,left());
putallnodemsg(str);
}