コード例 #1
0
ファイル: main.c プロジェクト: r0sen/r0sen
int main(void){
NumPrinter *p1, *p2, *p3, *p4, *p5;
mutex_t * mut = mutex_new();
CONSTR(mut);

p1 = num_pr_new(1);
p2 = num_pr_new(2);
p3 = num_pr_new(3);
p4 = num_pr_new(4);
p5 = num_pr_new(5);

printStart(p1);
printStart(p2);
printStart(p3);
printStart(p4);
printStart(p5);

getchar();

printer_free(p1);
printer_free(p2);
printer_free(p3);
printer_free(p4);
printer_free(p5);

DESTR();
}
コード例 #2
0
ファイル: test.c プロジェクト: matannov/OS3
int main()
{
   printStart();
   printf("\n");
   

   printf("test_create_and_destroy...\n");
   test_create_and_destroy();


   printf("test_thread_pool_sanity...\n");
   test_thread_pool_sanity();


   printf("test_agressive, this might take a while...\n");
   test_agressive();


   printf("test_single_thread_many_tasks...\n");
   test_single_thread_many_tasks();


   printf("test_many_threads_single_task...\n");
   test_many_threads_single_task();


   printf("test_destroy_should_wait_for_tasks #1 (more threads then tasks)...\n");
   test_destroy_should_wait_for_tasks_1();


   printf("test_destroy_should_wait_for_tasks #2 (more tasks then threads)...\n");
   test_destroy_should_wait_for_tasks_2();


   printf("test_destroy_should_not_wait_for_tasks...\n");
   test_destroy_should_not_wait_for_tasks();


   printf("test_destroy_twice...\n");
   test_destroy_twice();


   printf("test_insert_task_after_destroy #1...\n");
   test_insert_task_after_destroy_1();


   printf("test_insert_task_after_destroy #2...\n");
   test_insert_task_after_destroy_2();
//*/

   printEnd();
   return 0;
}
コード例 #3
0
ファイル: gdf.c プロジェクト: EleanorRobson/oracc
void
gdf_sH(void *userData, const char *name, const char **atts)
{
  const char *xid = get_xml_id(atts);

  if (xid && !strcmp(((struct frag*)userData)->xid, xid))
    {
      charData_discard();
      printStart(userData, name, atts);
    }
  else if (((struct frag*)userData)->nesting)
    printStart(userData, name, atts);
  else if (!strcmp(name, "gdf:dataset"))
    {
      printStart(userData, "gdf:dataset", atts);
      need_gdf_closer = 1;
      ((struct frag*)userData)->nesting = 0;
    }
  else
    charData_discard();
}
コード例 #4
0
ファイル: gameRun.c プロジェクト: ChrisHoder/Projects
void  gameRun() {
  user.wins = 0;
  user.loss = 0;
  user.ties = 0;
  user.total = 0;
  printStart();
  int i=0;

  while (i == 0){
    char comp;
    printf("Enter p, r, or s: ");
    char strchoice[10];
    fgets(strchoice,sizeof(strchoice),stdin);

/* decides action based on input. Either starts game, help, exit or wrong input */
    switch(strchoice[0]) {

      case 'r':
      case 'p':
      case 's':
	/* gets the computer's choice in the game */
	comp = computerChoice();
	/* this function will compare the two choices to determine winner */
	srand(time(NULL));
	playGame(comp,strchoice[0]);
	break;

     case 'h':
      helpFunc();
      break;

    case 'g':
     gameStats();
     break;
  
    case 'e':
      i=1;
      break;

    default:
      printf("\n\nPlease type a correct input character");
      helpFunc();
    }
  }

}
コード例 #5
0
ファイル: content.c プロジェクト: jnovotny-lmu/oracc
static void
content_sH(void *userData, const char *name, const char **atts)
{
  const char *xid = get_xml_id(atts);

  if (*name == 'r' && !strcmp(name, "rp-wrap"))
    return;

  if (((struct frag*)userData)->nesting)
    printStart(userData, name, atts, xid);
  else if (xid && *xid && ((struct frag*)userData)->xid && !strcmp(((struct frag*)userData)->xid, xid))
    {
      charData_discard();
      if (((struct frag*)userData)->cop->wrap)
	printHTMLStart(userData);
      printStart(userData, name, atts, xid);
    }
  else if (((struct frag*)userData)->cop->unwrap)
    {
      if (cued_printStart)
	{
	  cued_printStart = 0;
	  if (((struct frag*)userData)->cop->wrap)
	    printHTMLStart(userData);
	  printStart(userData, name, atts, xid);
	}
      else if (!strcmp(name, "body"))
	{
	  charData_discard();
	  cued_printStart = 1;
	}
      else if (((struct frag*)userData)->nesting)
	printStart(userData, name, atts, xid);
      else
	charData_discard();
    }
  else if (!strcmp(name, "gdf:dataset"))
    {
      printStart(userData, "gdf:dataset", atts, xid);
      need_gdf_closer = 1;
      ((struct frag*)userData)->nesting = 0;
    }
  else if (((struct frag*)userData)->cop->html && !strcmp(name, "head"))
    {
      fputs("<html xmlns=\"http://www.w3.org/1999/xhtml\">", 
	    ((struct frag*)userData)->fp);
      printStart(userData, name, atts, xid);
    }
  else
    charData_discard();
}
コード例 #6
0
ファイル: xfrag.c プロジェクト: oracc/oracc
void
gdf_sH(void *userData, const char *name, const char **atts)
{
  const char *xid = (htmlid ? findAttr(atts, "id") : get_xml_id(atts));

  if (unwrap_html)
    {
      if (cued_printStart)
	{
	  cued_printStart = 0;
	  printStart(userData, name, atts);
	}
      else if (!strcmp(name, "body"))
	{
	  charData_discard();
	  cued_printStart = 1;
	}
      else if (((struct frag*)userData)->nesting)
	printStart(userData, name, atts);
      else
	charData_discard();
    }
  else if (xid && !strcmp(((struct frag*)userData)->xid, xid))
    {
      charData_discard();
      printStart(userData, name, atts);
    }
  else if (((struct frag*)userData)->nesting)
    printStart(userData, name, atts);
  else if (!strcmp(name, "o:records"))
    {
      printStart(userData, "o:records", atts);
      need_gdf_closer = 1;
      ((struct frag*)userData)->nesting = 0;
    }
  else if (html_mode && !strcmp(name, "head"))
    {
      fputs("<html xmlns=\"http://www.w3.org/1999/xhtml\">", 
	    ((struct frag*)userData)->fp);
      printStart(userData, name, atts);
    }
  else
    charData_discard();
}
コード例 #7
0
// Neue Widget-Klasse vom eigentlichen Widget ableiten
MyWindow::MyWindow( QMainWindow *parent,
                    Qt::WindowFlags flags) :
                    QMainWindow(parent, flags)  {
    editor = new QTextEdit;
    editor->setWhatsThis(
                "Dieser Text kann mit (Shift)+(F1) angezeigt werden."
                "Auch eine <b>HTML-Formatierung</b> ist möglich. ");


    // Das komplette Menü zum Hauptprogramm
    QMenu *fileMenu = new QMenu(tr("&Datei"), this);
    menuBar()->addMenu(fileMenu);
    act1 = fileMenu->addAction(
                QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/page_white.png")), tr("&Neu"),
       this, SLOT(newFile()),
       QKeySequence(tr("Ctrl+N", "Datei|Neu")) );
    act1->setStatusTip(
       tr("Löscht den aktuellen Inhalt der Datei"));
    act2 = fileMenu->addAction(
                QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/folder_page_white.png")),
       tr("&Öffnen..."), this, SLOT(openFile() ),
       QKeySequence(tr("Ctrl+O", "Datei|Öffnen")));
    act2->setStatusTip(
       tr("Öffnet eine Datei in den Texteditor"));
    fileMenu->addSeparator();
    act3 = fileMenu->addAction(
                QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/cancel.png"))   ,
                tr("Be&enden"),
       qApp, SLOT(quit()),
       QKeySequence(tr("Ctrl+E", "Datei|Beenden")) );
    act3->setStatusTip(tr("Programm beenden"));
    QMenu *workMenu = new QMenu(
       tr("&Bearbeiten"), this);
    menuBar()->addMenu(workMenu);
    act4 = workMenu->addAction(
       tr("&Suchen"), this, SLOT(search()),
       QKeySequence(tr("Ctrl+S", "Bearbeiten|Suchen")));
    act4->setStatusTip(
       tr("Nach einer Stringfolge suchen") );
    // Menü mit Linie von der Leiste Abnehmbar
    fileMenu->setSeparatorsCollapsible(true);

    // Mehrere Aktionen erzeugen
    QAction* underLineAct = new QAction(
       tr("&Unterstreichen"), this );
    underLineAct->setCheckable(true);
    underLineAct->setShortcut(tr("Ctrl+U"));
    underLineAct->setStatusTip(
       tr("Text unterstreichen") );
    underLineAct->setIcon(
                QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/text_underline.png")));
    connect( underLineAct, SIGNAL(triggered(bool)),
             editor, SLOT(setFontUnderline(bool)) );

    QAction *leftAlignAct = new QAction(
       tr("&Links ausgerichtet"), this);
    leftAlignAct->setCheckable(true);
    leftAlignAct->setShortcut(tr("Ctrl+L"));
    leftAlignAct->setStatusTip(
       tr("Text links ausrichten"));
    leftAlignAct->setIcon(
                 QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/text_align_left.png")));
    connect( leftAlignAct, SIGNAL(triggered()),
             this, SLOT(leftAlignment() ) );

    QAction *rightAlignAct = new QAction(
       tr("&Rechts ausgerichtet"), this);
    rightAlignAct->setCheckable(true);
    rightAlignAct->setShortcut(tr("Ctrl+R"));
    rightAlignAct->setStatusTip(
       tr("Text rechts ausrichten") );
    rightAlignAct->setIcon(
                 QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/text_align_right.png")));
    connect( rightAlignAct, SIGNAL(triggered()),
             this, SLOT(rightAlignment() ) );

    QAction *justifyAct = new QAction(
       tr("&Bündig ausrichten"), this);
    justifyAct->setCheckable(true);
    justifyAct->setShortcut(tr("Ctrl+J"));
    justifyAct->setStatusTip(
       tr("Text bündig ausrichten"));
    justifyAct->setIcon(
                QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/text_align_justify.png")));
    connect( justifyAct, SIGNAL(triggered()),
             this, SLOT(justifyAlignment() ) );

    QAction *centerAct = new QAction(
       tr("&Zentriert ausrichten"), this);
    centerAct->setCheckable(true);
    centerAct->setShortcut(tr("Ctrl+E"));
    centerAct->setStatusTip(
       tr("Text zentriert ausrichten") );
    centerAct->setIcon(
                  QIcon(QString("%1%2").arg(QCoreApplication::applicationDirPath()).arg("/images/text_align_center.png")));
    connect( centerAct, SIGNAL(triggered()),
             this, SLOT(centerAlignment() ) );

    // Einige Aktionen zu einer Gruppe zusammenfassen
    QActionGroup* alignmentGroup = new QActionGroup(
       this );
    alignmentGroup->addAction(leftAlignAct);
    alignmentGroup->addAction(rightAlignAct);
    alignmentGroup->addAction(justifyAct);
    alignmentGroup->addAction(centerAct);
    leftAlignAct->setChecked(true);

    // Nochmals zwei weitere Aktionen
    QAction *InZoom = new QAction(
       tr("&Zoom in ..."), this );
    InZoom->setStatusTip(tr("Zoom in the text"));
    connect( InZoom, SIGNAL(triggered()),
             editor, SLOT(zoomIn() ) );
    QAction *OutZoom = new QAction(
       tr("&Zoom out ..."), this );
    OutZoom->setStatusTip(tr("Zoom out the text"));
    connect( OutZoom, SIGNAL(triggered() ),
             editor, SLOT(zoomOut() ) );

    // Ein Sub-Menü "Format" bei "Bearbeiten" einfügen
    QMenu *formatMenu = workMenu->addMenu(
       tr("&Format") );
    formatMenu->addAction(underLineAct);
    formatMenu->addSeparator();
    formatMenu->addAction(leftAlignAct);
    formatMenu->addAction(rightAlignAct);
    formatMenu->addAction(justifyAct);
    formatMenu->addAction(centerAct);
    formatMenu->addSeparator();
    formatMenu->addAction(InZoom);
    formatMenu->addAction(OutZoom);
    workMenu->setTearOffEnabled(true);
    workMenu->setWindowTitle("Bearbeiten");

    // Zur Demonstration eine Aktion mit QVariant
    Start = new QAction(tr("&Programmstart ..."), this);
    Start->setStatusTip(tr("Zeit des Programmstarts"));
    Start->setData(QVariant(QTime::currentTime()));
    QFont font; font.setBold(true);
    Start->setFont(font);
    Start->setShortcut(tr("Ctrl+T"));
    Start->setShortcutContext(Qt::ApplicationShortcut);
    connect( Start, SIGNAL( triggered() ),
             this, SLOT( printStart() ) );
    workMenu->addAction(Start);


    // Eine neue Statusleiste erzeugen und zum
    // Hauptfenster hinzufügen
    (void*) statusBar ();
    // Permanente Meldung in der Statusleiste
    // Zeichen, Wörter, Zeilen
    sLabel = new QLabel;
    sLabel->setFrameStyle(
       QFrame::Panel | QFrame::Sunken );
    sLabel->setLineWidth(2);
    statusBar()->addPermanentWidget(sLabel);
    connect( editor, SIGNAL( textChanged() ),
             this, SLOT( updateStatusBar() ) );
    updateStatusBar();
    // Laufend aktuelle Uhrzeit in der Statusleiste
    time = new QLCDNumber;
    time->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    time->setLineWidth(2);
    time->setSegmentStyle(QLCDNumber::Flat);
    statusBar()->addPermanentWidget(time);
    QTimer *timer = new QTimer(this);
    connect( timer, SIGNAL(timeout()),
             this, SLOT(updateTime()) );
    // Jede Sekunde updateTime() aufrufen
    timer->start(1000);
    updateTime();

    // Werkzeugleiste erzeugen
    toolFile = addToolBar(tr("Datei"));
    // Icons mit Text darunter anzeigen
    toolFile->setToolButtonStyle (
       Qt::ToolButtonTextUnderIcon );
    // Werkzeugleiste nur nach links
    // oder oben Verschiebbar
    toolFile->setAllowedAreas(
       Qt::LeftToolBarArea | Qt::TopToolBarArea );
    // Aktionen zur Werkzeugleiste hinzufügen
    toolFile->addAction(act1);
    toolFile->addAction(act2);
    toolFile->addAction(act3);
    // Noch eine Werkzeugleiste
    toolWork = addToolBar(tr("Bearbeiten"));
    // Werkzeugleiste unten anzeigen
    addToolBar(Qt::TopToolBarArea, toolWork );
    // Position nicht mehr veränderbar
    toolWork->setMovable(false);
    // Aktionen zur Werkzeugleiste hinzufügen
    toolWork->addAction(underLineAct);
    toolWork->addSeparator ();
    toolWork->addAction(leftAlignAct);
    toolWork->addAction(rightAlignAct);
    toolWork->addAction(justifyAct);
    toolWork->addAction(centerAct);
    toolWork->addSeparator ();
    // Eine Schrift-Combobox zur Werkzeugleiste
    QFontComboBox *cFont = new QFontComboBox;
    toolWork->addWidget(cFont);
    connect(
      cFont, SIGNAL( currentFontChanged(const QFont& )),
      editor, SLOT(setCurrentFont ( const QFont&) ) );

    // Ein neues Dock-Widget-erzeugen
    QDockWidget *dock = new QDockWidget(
       tr("WYSIWYG-Editor"), this );
    // nur in den rechten und linken Bereich erlauben
    dock->setAllowedAreas(
       Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea);
    // Widget für das Dock-Widget erzeugen
    dock_editor = new QTextEdit;
    // Editor als Widget im Dock-Fenster verwenden
    dock->setWidget(dock_editor);
    // auf der rechten Seite zum Hauptfenster hinzufügen
    addDockWidget(Qt::RightDockWidgetArea, dock);
    connect( editor, SIGNAL(textChanged() ),
             this, SLOT( showHTML() ) );

    // Einstellungen des Programms speichern
    // Im Beispiel wird nur (ggf.) die zuletzt
    // geöffnete Datei und die Größe des Fensters
    settings = new QSettings(
       tr("J.Wolf"), tr("JWTexteditor") );
    settings->beginGroup("HauptFenster");
    QString fileName =
       settings->value("lastFile").toString();
    QSize size =
       settings->value("size", sizeHint()).toSize();
    if (!fileName.isEmpty()) {
       QFile file(fileName);
       if (file.open(QFile::ReadOnly | QFile::Text)) {
          editor->setPlainText(file.readAll());
          statusBar()->showMessage(
             tr("Zuletzt geöffnete Datei "
                "erfolgreich geladen"));
          // Wieder setzen
          settings->setValue("lastFile", fileName );
       }
       else // falls die Datei nicht mehr existiert
          settings->setValue("lastFile", "");
    }
    else // Keine Datei gesetzt
       settings->setValue("lastFile", "");
    settings->endGroup();

    if( size.isNull() )
       resize(640, 480);
    else
       resize(size);
    setCentralWidget(editor);
    setWindowTitle("QMainWindow - Demo");
}