Esempio n. 1
0
/* Read history from session record */
void ReadHistory
    (
    History* recordPtr,     /* pointer to session record */
    UInt16   availableSize  /* amount of data available */
    )
{
    InitHistory();

    if ( sizeof( History ) < availableSize )
        availableSize = sizeof( History );
    if ( 0 < availableSize )
        MemMove( &history, recordPtr, availableSize );
}
Esempio n. 2
0
INT CommandHistory (LPTSTR param)
{
	LPTSTR tmp;
	INT tmp_int;
	LPHIST_ENTRY h_tmp;
	TCHAR szBuffer[2048];

	tmp=_tcschr(param,_T('/'));

	if (tmp)
	{
		param=tmp;
		switch (_totupper(param[1]))
		{
			case _T('F'):/*delete history*/
				CleanHistory();InitHistory();
				break;

			case _T('R'):/*read history from standard in*/
				//hIn=GetStdHandle (STD_INPUT_HANDLE);

				for(;;)
				{
					ConInString(szBuffer,sizeof(szBuffer)/sizeof(TCHAR));
					if (*szBuffer!=_T('\0'))
						History(0,szBuffer);
					else
						break;
				}
				break;

			case _T('A'):/*add an antry*/
				History(0,param+2);
				break;

			case _T('S'):/*set history size*/
				if ((tmp_int=_ttoi(param+2)))
					set_size(tmp_int);
				break;

			default:
				return 1;
		}
	}
	else
	{
		for (h_tmp = Top->prev; h_tmp != Bottom; h_tmp = h_tmp->prev)
			ConErrPuts(h_tmp->string);
	}
	return 0;
}
Esempio n. 3
0
/*****************************************************************************
 * FUNCTION: ZGConsoleInit
 *
 * RETURNS: None
 *
 * PARAMS:  p_cmdStrings  -- pointer to array of application-specific command strings
 *          numCmdStrings -- number of strings in p_cmdStrings
 *
 * NOTES:   Initialization for console thread
 *
 *****************************************************************************/
tZGVoidReturn ZGConsoleInit( ROM tZGU8 **p_cmdStrings, tZGU8 numCmdStrings)
{
    SET_RX_STATE(kSTWaitForChar);
    SET_CURSOR(0);

    // zero out command line buffer
    memset(g_ConsoleContext.rxBuf, 0x00, sizeof(g_ConsoleContext.rxBuf));

    g_ConsoleContext.bStateMachineLoop = kZGBoolTrue;
    g_ConsoleContext.firstChar         = kZGBoolFalse;
    g_ConsoleContext.p_cmdStrings      = p_cmdStrings;
    g_ConsoleContext.numCmdStrings     = numCmdStrings;
    g_ConsoleContext.appConsoleMsgRx   = kZGBoolFalse;
    SET_ECHO_ON();
#if (kZGNumHistoryEntries > 0)
    InitHistory();
#endif

}
Esempio n. 4
0
/*****************************************************************************
 * FUNCTION: WFConsoleInit
 *
 * RETURNS: None
 *
 * PARAMS:
 *
 * NOTES:   Initialization for console thread
 *
 *****************************************************************************/
void WFConsoleInit(void)
{

    SET_RX_STATE(kSTWaitForChar);
    SET_CURSOR(0);

    // zero out command line buffer
    memset(g_ConsoleContext.rxBuf, 0x00, sizeof(g_ConsoleContext.rxBuf));

    g_ConsoleContext.bStateMachineLoop = TRUE;
    g_ConsoleContext.firstChar         = FALSE;
    g_ConsoleContext.appConsoleMsgRx   = FALSE;
    SET_ECHO_ON();
#if (kWFNumHistoryEntries > 0)
    InitHistory();
#endif

    g_ConsoleContext.echoOn = TRUE;

}
Esempio n. 5
0
void main (void)
{
	FILE * infile;
	string choice;
	class_p clas;
	ship_p ship;
	ship_p cell[NUM_ROWS][NUM_COLS];
	int ship_num;
	coord history[100];

	Randomize();
	choice=StartGame();
	infile=GetFile();
	InitCell(cell);
	InitHistory(history);
	ship=GetData(infile,&clas,&ship,&ship_num);
	
	InitGraphics();
	DrawStartingBoard(choice);
	PlacingShips(clas,ship,cell,ship_num);
	

	PlayGame(history,cell,clas,ship,ship_num,choice);
}
Esempio n. 6
0
int main(int argc, char **arg) {
  clock_t start, endc, endt;
  double elapsedc, elapsedt;

  extmanager MyManager;
  DdNode *bdd;
  bddfileheader fileheader;
  int i, ivarcnt, code;
  gradientpair tvalue;
  double probability = -1.0;
  char *varpattern;
  varpattern = NULL;
  code = -1;
  params = loadparam(argc, arg);
  if (params.errorcnt > 0) {
    printhelp(argc, arg);
    for (i = 0; i < params.errorcnt; i++) {
      fprintf(stderr, "Error: not known or error at parameter %s.\n",
              arg[params.error[i]]);
    }
    return -1;
  }

  if (params.online == 0 && params.loadfile == -1) {
    printhelp(argc, arg);
    fprintf(stderr, "Error: you must specify a loading file.\n");
    return -1;
  }

  if (params.method != 0 && arg[params.method][0] != 'g' &&
      arg[params.method][0] != 'p' && arg[params.method][0] != 'o' &&
      arg[params.method][0] != 'l') {
    printhelp(argc, arg);
    fprintf(stderr, "Error: you must choose a calculation method beetween "
                    "[p]robability, [g]radient, [l]ine search, [o]nline.\n");
    return -1;
  }

  if (params.debug)
    DEBUGON;
  RAPIDLOADON;
  SETMAXBUFSIZE(params.maxbufsize);
#ifndef _WIN32
  signal(SIGINT, termhandler);
  if (params.ppid != NULL) {
    signal(SIGALRM, pidhandler);
    alarm(5);
  } else {
    signal(SIGALRM, handler);
    alarm(params.timeout);
  }
#endif
  if (params.online) {
    MyManager.manager = simpleBDDinit(0);
    MyManager.t = HIGH(MyManager.manager);
    MyManager.f = LOW(MyManager.manager);
    MyManager.varmap = InitNamedVars(1, 0);
    bdd = OnlineGenerateBDD(MyManager.manager, &MyManager.varmap);
    ivarcnt = GetVarCount(MyManager.manager);
  } else {
    fileheader = ReadFileHeader(arg[params.loadfile]);
    switch (fileheader.filetype) {
    case BDDFILE_SCRIPT:
      if (params.inputfile == -1) {
        printhelp(argc, arg);
        fprintf(stderr, "Error: an input file is necessary for this type of "
                        "loading file.\n");
        return -1;
      }
      MyManager.manager = simpleBDDinit(fileheader.varcnt);
      MyManager.t = HIGH(MyManager.manager);
      MyManager.f = LOW(MyManager.manager);
      MyManager.varmap = InitNamedMultiVars(
          fileheader.varcnt, fileheader.varstart, fileheader.bvarcnt);
      if (LoadMultiVariableData(MyManager.manager, MyManager.varmap,
                                arg[params.inputfile]) == -1)
        return -1;
      start = clock();
      bdd = FileGenerateBDD(MyManager.manager, MyManager.varmap, fileheader);
      endc = clock();
      elapsedc = ((double)(endc - start)) / CLOCKS_PER_SEC;
      printf("elapsed_construction(%lf).\n", elapsedc);
      ivarcnt = fileheader.varcnt;
      break;
    case BDDFILE_NODEDUMP:
      if (params.inputfile == -1) {
        printhelp(argc, arg);
        fprintf(stderr, "Error: an input file is necessary for this type of "
                        "loading file.\n");
        return -1;
      }
      MyManager.manager = simpleBDDinit(fileheader.varcnt);
      MyManager.t = HIGH(MyManager.manager);
      MyManager.f = LOW(MyManager.manager);
      MyManager.varmap = InitNamedVars(fileheader.varcnt, fileheader.varstart);
      bdd = LoadNodeDump(MyManager.manager, MyManager.varmap,
                         fileheader.inputfile);
      ivarcnt = fileheader.varcnt;
      break;
    default:
      fprintf(stderr, "Error: not a valid file format to load.\n");
      return -1;
      break;
    }
  }
#ifndef _WIN32
  alarm(0);
#endif
  // problem specifics

  if (bdd != NULL) {
    ivarcnt = RepairVarcnt(&MyManager.varmap);
    code = 0;
    /*
    if (params.inputfile != -1) {
      if (LoadVariableData(MyManager.varmap, arg[params.inputfile]) == -1)
    return -1;
      if (!all_loaded(MyManager.varmap, 1)) return -1;
    }*/
    MyManager.his = InitHistory(ivarcnt);
    if (params.method != 0) {
      switch (arg[params.method][0]) {
      case 'g':
        for (i = 0; i < MyManager.varmap.varcnt; i++) {
          if (MyManager.varmap.vars[i] != NULL) {
            varpattern = extractpattern(MyManager.varmap.vars[i]);
            if ((varpattern == NULL) ||
                (!patterncalculated(varpattern, MyManager, i))) {
              tvalue = CalcGradient(MyManager, bdd,
                                    i + MyManager.varmap.varstart, varpattern);
              probability = tvalue.probability;
              double factor =
                  sigmoid(MyManager.varmap.dvalue[i], params.sigmoid_slope) *
                  (1 -
                   sigmoid(MyManager.varmap.dvalue[i], params.sigmoid_slope)) *
                  params.sigmoid_slope;
              if (varpattern == NULL) {
                printf("query_gradient(%s,%s,%1.12f).\n", arg[params.queryid],
                       MyManager.varmap.vars[i], tvalue.gradient * factor);
              } else {
                varpattern[strlen(varpattern) - 2] = '\0';
                printf("query_gradient(%s,%s,%1.12f).\n", arg[params.queryid],
                       varpattern, tvalue.gradient * factor);
              }
              ReInitHistory(MyManager.his, MyManager.varmap.varcnt);
            }
            if (varpattern != NULL)
              free(varpattern);
          } else {
            fprintf(stderr, "Error: no variable name given for parameter.\n");
          }
        }
        if (probability < 0.0) {
          // no nodes, so we have to calculate probability ourself
          tvalue =
              CalcGradient(MyManager, bdd, 0 + MyManager.varmap.varstart, NULL);
          probability = tvalue.probability;
        }
        printf("query_probability(%s,%1.12f).\n", arg[params.queryid],
               probability);
        break;
      case 'l':
        tvalue =
            CalcGradient(MyManager, bdd, 0 + MyManager.varmap.varstart, NULL);
        probability = tvalue.probability;
        printf("query_probability(%s,%1.12f).\n", arg[params.queryid],
               probability);
        break;
      case 'p':
        printf("probability(%1.12f).\n", CalcProbability(MyManager, bdd));
        break;
      case 'o':
        onlinetraverse(MyManager.manager, MyManager.varmap, MyManager.his, bdd);
        break;
      default:
        myexpand(MyManager, bdd);
        break;
      }
    } else {
      start = clock();
      //	simpleNamedBDDtoDot(MyManager.manager, MyManager.varmap, bdd,
      //"bdd.dot");
      printf("probability(%1.12f).\n", ret_prob(MyManager, bdd));
      endt = clock();
      elapsedt = ((double)(endt - start)) / CLOCKS_PER_SEC;
      printf("elapsed_traversing(%lf).\n", elapsedt);
      //      myexpand(MyManager, bdd);
    }
    if (params.savedfile > -1)
      SaveNodeDump(MyManager.manager, MyManager.varmap, bdd,
                   arg[params.savedfile]);
    if (params.exportfile > -1)
      simpleNamedBDDtoDot(MyManager.manager, MyManager.varmap, bdd,
                          arg[params.exportfile]);
    ReInitHistory(MyManager.his, MyManager.varmap.varcnt);
    free(MyManager.his);
  }
  if (MyManager.manager != NULL) {
    KillBDD(MyManager.manager);
    exit(code);
    free(MyManager.varmap.dvalue);
    free(MyManager.varmap.ivalue);
    free(MyManager.varmap.dynvalue);
    for (i = 0; i < MyManager.varmap.varcnt; i++) {
      free(MyManager.varmap.vars[i]);
      free(MyManager.varmap.mvars[i].probabilities);
      free(MyManager.varmap.mvars[i].booleanVars);
    }
    free(MyManager.varmap.vars);
    free(MyManager.varmap.mvars);
    free(MyManager.varmap.bVar2mVar);
  }
  if (params.error != NULL)
    free(params.error);

  return code;
}
Esempio n. 7
0
int main(int argc, char **arg) {
  extmanager MyManager;
  DdNode *bdd, **forest;
  bddfileheader fileheader;
  int code;
  char yn;
  code = -1;
  if (argc != 2) {
    fprintf(stderr, "\nUsage: %s [filename]\nGenerates and traverses a BDD from file\n", arg[0]);
    fprintf(stderr, "\nUsage: %s -online\nGenerates and traverses a BDD online mode\n", arg[0]);
    return code;
  }
  RAPIDLOADON;
  if (strcmp("-online", arg[1]) == 0) {
    MyManager.manager = simpleBDDinit(0);
    MyManager.t = HIGH(MyManager.manager);
    MyManager.f = LOW(MyManager.manager);
    MyManager.varmap = InitNamedVars(1, 0);
    bdd = OnlineGenerateBDD(MyManager.manager, &MyManager.varmap);
  } else {
    fileheader = ReadFileHeader(arg[1]);
    switch(fileheader.filetype) {
      case BDDFILE_SCRIPT:
        MyManager.manager = simpleBDDinit(fileheader.varcnt);
        MyManager.t = HIGH(MyManager.manager);
        MyManager.f = LOW(MyManager.manager);
        MyManager.varmap = InitNamedVars(fileheader.varcnt, fileheader.varstart);
        if (fileheader.version > 1) {
          forest = FileGenerateBDDForest(MyManager.manager, MyManager.varmap, fileheader);
          bdd = forest[0];
        } else {
          forest = NULL;
          bdd = FileGenerateBDD(MyManager.manager, MyManager.varmap, fileheader);
        }
        break;
      case BDDFILE_NODEDUMP:
        MyManager.manager = simpleBDDinit(fileheader.varcnt);
        MyManager.t = HIGH(MyManager.manager);
        MyManager.f = LOW(MyManager.manager);
        MyManager.varmap = InitNamedVars(fileheader.varcnt, fileheader.varstart);
        bdd = LoadNodeDump(MyManager.manager, MyManager.varmap, fileheader.inputfile);
        break;
      default:
        fprintf(stderr, "Error: not a valid file format to load.\n");
        return code;
        break;
    }
  }
  int nextbdd = 0;
  while (bdd != NULL) {
    printf("Do you want to load parameter values from testdata.txt [y]? "); yn = getchar(); getchar();
    if (yn == 'y') {
      printf("yo\n");
      LoadVariableData(MyManager.varmap, "testdata.txt");
      printf("yo\n");
      char **a;
      a = GetVariableOrder("testdata.txt", MyManager.varmap.varcnt);
      int aa;
      for (aa = 0; aa < MyManager.varmap.varcnt; aa++)
        printf("%s\n", a[aa]);
      ImposeOrder(MyManager.manager, MyManager.varmap, a);
    }


    code = 0;
    MyManager.his = InitHistory(GetVarCount(MyManager.manager));
    if (strcmp("-online", arg[1]) != 0) {
      DFS(MyManager, bdd);
      printf("Do you need an export [y]? "); yn = getchar(); getchar();
      if (yn == 'y') simpleNamedBDDtoDot(MyManager.manager, MyManager.varmap, bdd, "SimpleCUDDExport.dot");
      printf("Do you want a save [y]? "); yn = getchar(); getchar();
      if (yn == 'y') SaveNodeDump(MyManager.manager, MyManager.varmap, bdd, "SimpleCUDDSave.sav");
      printf("Do you want to see all true paths [y]? "); yn = getchar(); getchar();
      if (yn == 'y') {
        ReInitHistory(MyManager.his, GetVarCount(MyManager.manager));
        getalltruepaths(MyManager, bdd, "", "");
      }
    } else {
      onlinetraverse(MyManager.manager, MyManager.varmap, MyManager.his, bdd);
    }
    nextbdd++;
    if (forest != NULL) bdd = forest[nextbdd]; else bdd = NULL;
  }
  if (MyManager.manager != NULL) KillBDD(MyManager.manager);
  return code;
}
Esempio n. 8
0
BOOL CreateWinGHCiMainWindow(INT nCmdShow)
{
	//hWndMain = CreateDialog(hThisInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, &MainWndProc);

	
	if (!RegisterWinGHCiWindowClass(hThisInstance) )
	{	
		ErrorExit(TEXT("Could not register WinGHCiWindowClass"));
		return FALSE;
	}

	hWndMain = CreateWindowEx(WS_EX_ACCEPTFILES,WinGHCiWindowClass, WinGHCiWindowTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hThisInstance, NULL);



	if (!hWndMain)
	{	
		ErrorExit(TEXT("CreateWinGHCiMainWindow"));
		return FALSE;
	}

    ShowWindow(hWndMain, nCmdShow);
    UpdateWindow(hWndMain);

	// Setup the icons
	SendMessage(hWndMain, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon(hThisInstance, MAKEINTRESOURCE(ID_GHCi_ICON)));	
	SendMessage(hWndMain, WM_SETICON, ICON_BIG,	(LPARAM) LoadIcon(hThisInstance, MAKEINTRESOURCE(ID_WinGHCi_ICON)));

	// Create status line
	hWndStatus = CreateWindowEx(
		0,                       
		STATUSCLASSNAME,        
		(LPCTSTR) TEXT(""),          
		WS_CHILD | SBARS_SIZEGRIP | WS_VISIBLE,               
		0, 0, 0, 0,              
		hWndMain,              
		(HMENU) IDC_Statusbar,      
		hThisInstance,                   
		NULL);                   


	// create rich edit control
	hWndRtf = CreateWindowEx(
		 WS_EX_CLIENTEDGE,
		 RICHEDIT_CLASS,        
		(LPCTSTR) TEXT(""),          
		WS_CHILD  | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_DISABLENOSCROLL | ES_WANTRETURN,               
		0, 0, 0, 0,              
		hWndMain,              
		(HMENU) IDC_Rtf,      
		hThisInstance,                   
		NULL);   

	RtfWindowInit();
	SetFocus(hWndRtf);

	CreateToolbar();
	InitMruFiles();
	InitHistory();

	RegistryReadWindowPos(hWndMain);


	return TRUE;
}