Example #1
0
int main (void) {
    lua_State *L = lua_open();
   
    lua_newtable(L);

    lua_pushstring(L, "key-a");
    lua_pushstring(L, "I-am-value-9");

    lua_settable(L, -3);

    t_shallow_copy(L, 1);
    lua_pushstring(L, "key-a");
    lua_pushstring(L, "I-am-value-8888");
    lua_settable(L, -3);
    stackDump(L, "table");
    PrintTable(L);
    lua_pop(L, 1);
    PrintTable(L);

    Debug("Imadfdfa[%d] [%s]\n",1231, "dadd");
    

 return 0;

}
Example #2
0
void DoIt(char pre)
{
   FILENODE *fbase, **bp;
   int n;
   int *ix, *iy, *ia, *ib;

   fbase = ReadFile(pre);
   fbase = TstFile(pre, fbase, &n);  /* get rid of nodes that don't work */
   ix = malloc(4*n*sizeof(int));
   assert(ix);
   bp = malloc(n*sizeof(FILENODE*));
   assert(bp);
   iy = ix + n;
   ia = iy + n;
   ib = ia + n;
   n = GetCombos(fbase, ix, iy, ia, ib, bp);
   BruteTime(pre, n, fbase, ix, iy, ia, ib, bp);
   n = KillSpecCases(n, ix, iy, ia, ib, bp);
   fprintf(stdout, "%d:\n", __LINE__);
   PrintTable(n, ix, iy, ia, ib, bp);
   SortCases(n, ix, iy, ia, ib, bp);
   fprintf(stdout, "%d:\n", __LINE__);
   PrintTable(n, ix, iy, ia, ib, bp);
   CreateSumm(pre, n, ix, iy, ia, ib, bp);
   KillAllFN(fbase);
   free(bp);
   free(ix);
}
Example #3
0
File: Par.cpp Project: jdh8/dds
int main()
{
  ddTableResults DDtable;
  parResults pres;

  int res;
  char line[80];
  bool match;

#if defined(__linux) || defined(__APPLE__)
  SetMaxThreads(0);
#endif

  for (int handno = 0; handno < 3; handno++)
  {
    SetTable(&DDtable, handno);

    res = Par(&DDtable, &pres, vul[handno]);

    if (res != RETURN_NO_FAULT)
    {
      ErrorMessage(res, line);
      printf("DDS error: %s\n", line);
    }

    match = ComparePar(&pres, handno);

    printf("Par, hand %d: %s\n\n",
           handno + 1, (match ? "OK" : "ERROR"));

    PrintTable(&DDtable);

    PrintPar(&pres);
  }
}
Example #4
0
int GetCombos(FILENODE *fptr, int *ix, int *iy, int *ia, int *ib, FILENODE **bp)
/*
 * finds all combos of incX, incY, alpha and beta returns # of unique combos
 */
{
   FILENODE *fp, *pp;
   int i=1, j;

   if (!fptr) return(0);
/*
 * Always include general case
 */
   *ix = 0;
   *iy = 0;
   *ia = AlphaX;
   *ib = AlphaX;
   *bp = NULL;
   for (fp=fptr; fp; fp = fp->next)
   {
      for (j=0; j < i; j++)
         if (fp->incX == ix[j] && fp->incY == iy[j] && fp->alpha == ia[j] &&
             fp->beta == ib[j]) break;
      if (j == i) /* not already there */
      {
         ix[i] = fp->incX;
         iy[i] = fp->incY;
         ia[i] = fp->alpha;
         ib[i] = fp->beta;
         bp[i++] = NULL;
      }
   }
   PrintFN(fptr);
   PrintTable(i, ix, iy, ia, ib, bp);
   return(i);
}
Example #5
0
int main(int argc, char *argv[]){
	
	if(argc<2){
		printf("Specify the file name\n");
		exit(-1);
	}
	
	char*table_txt=argv[1];
	
	node*root=Init_tree();
	
	if(root==NULL)printf("Table successfully initialized\n");
	
	ReadTable(&root, table_txt);
	
	int option;
	int hop;
	char prefix[128];
	
	while(1){
		
		printf("Choose from the following options:\n1: Add Prefix\n2: Delete Prefix\n3: Print Table\n4: Convert Tree to Two Tree\n5: Address Look Up\n6: Exit\n\n");
		
		bzero(prefix, 128);
		if(scanf("%d",&option)==1)printf("deu\n");

		if(option==1){
			printf("\nPlease specify the prefix and next hop to add.\n");
			fscanf(stdin,"%s %d", prefix, &hop);
			AddPrefix(&root, prefix, hop);
			printf("\nAdded the prefix: %s with next hop: %d\n",prefix, hop);
		}
		if(option==2){
			printf("\nPlease specify the prefix to delete.\n");
			fscanf(stdin,"%s", prefix);
			printf("\n%s\t%d\n",prefix, hop);
			DeletePrefix(&root, prefix);
			printf("\nDeleted the prefix: %s\n",prefix);
		}
		if(option==3){
			PrintTable(root);
			printf("\nTable successfully printed\n");	
		}
		if(option==4){
			convert_tree(&root, root->next_hop);
			printf("\nTable successfully converted\n");
		}
		if(option==5){
			printf("\nPlease specify the prefix to scan.\n");
			fscanf(stdin,"%s", prefix);
			int result=AddressLookUp(root, prefix);
			printf("\nNext hop is: %d\n", result);
		}
		if(option==6){
			printf("The program will now exit.\n");
			exit(1);
		}
	}
	exit(0);
}
Example #6
0
  int PrintTable( lua_State* L )
  {
    // first key

    lua_pushnil(L);
    int tableIndex = lua_gettop(L) - 1;
    while (lua_next(L, tableIndex) != 0) 
    {
      for (int i = 0; i < tableIndex - 1; ++i)
        printf("  ");

      // print key-type and value-type, format: %s - %s

      printf("%s - %s\n", 
        lua_typename(L, lua_type(L, -2)),	// key type
        lua_typename(L, lua_type(L, -1)));	// value type

      // value type

      if (lua_typename(L, lua_type(L, -1)) == "table")
        PrintTable(L);

      lua_pop(L, 1); // pop value, keep key
    }

    return 1;
  }
Example #7
0
void PrintTable(lua_State *L, int tabCount)
{
    lua_pushnil(L);
    printf("{\n");
    while(lua_next(L, -2) != 0)
    {
        for (int c = 0; c < tabCount; c++) {
            printf("\t");
        }
        if(lua_isstring(L, -1))
            printf("\t%s = %s\n", lua_tostring(L, -2), lua_tostring(L, -1));
        else if(lua_isnumber(L, -1))
            printf("\t%s = %d\n", lua_tostring(L, -2), lua_tonumber(L, -1));
        //else if(lua_isfunction(L, -1))
        //    printf("\t%s = %s\n", lua_tostring(L, -2), lua_tostring(L, -1));
        else if(lua_istable(L, -1)) {
            printf("\t%s = ", lua_tostring(L, -2));
            PrintTable(L,tabCount+1);
        }
        else {
            int t = lua_type(L, -1);
            //printf("\t%s = %s\n", lua_tostring(L, -2), lua_typename(L, t));
            char* type = (char*)tolua_typename(L, -1);
            lua_pop(L, 1);
            printf("\t%s = %s\n", lua_tostring(L, -2), type);
            
        }
        lua_pop(L, 1);
    }
    printf("}\n");
}
Example #8
0
/**
  Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to
  install the Efi System Resource Table.

  @param[in]  Event    The Event that is being processed.
  @param[in]  Context  The Event Context.

**/
VOID
EFIAPI
EsrtReadyToBootEventNotify (
  IN EFI_EVENT  Event,
  IN VOID       *Context
  )
{
  EFI_STATUS                 Status;
  EFI_SYSTEM_RESOURCE_TABLE  *Table;

  Table = CreateFmpBasedEsrt ();
  if (Table != NULL) {
    //
    // Print table on debug builds
    //
    DEBUG_CODE_BEGIN ();
    PrintTable (Table);
    DEBUG_CODE_END ();

    Status = InstallEfiSystemResourceTableInUefiConfigurationTable (Table);
    if (EFI_ERROR (Status)) {
      FreePool (Table);
    }
  } else {
    DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Can't install ESRT table because it is NULL. \n"));
  }

  //
  // Close the event to prevent it be signalled again.
  //
  gBS->CloseEvent (Event);
}
Example #9
0
void Printer::PrintValue(std::string *result, Sqrat::Object object) {
	if (object.IsNull()) {
		result->append("null");
	} else {
		if (object.GetType() == OT_TABLE) {
			PrintTable(result, object.Cast<Sqrat::Table>());
		} else if (object.GetType() == OT_ARRAY) {
			PrintArray(result, object.Cast<Sqrat::Array>());
		} else if (object.GetType() == OT_INTEGER) {
			Util::SafeFormat(mPrintBuffer, sizeof(mPrintBuffer), "%lu",
					object.Cast<unsigned long>());
			result->append(mPrintBuffer);
		} else if (object.GetType() == OT_STRING) {
			result->append("\"" + object.Cast<std::string>() + "\"");
		} else if (object.GetType() == OT_BOOL) {
			result->append(object.Cast<bool>() ? "true" : "false");
		} else if (object.GetType() == OT_FLOAT) {
			Util::SafeFormat(mPrintBuffer, sizeof(mPrintBuffer), "%f",
					object.Cast<double>());
			result->append(mPrintBuffer);
		} else {
			Vector3 *vec3 = object.Cast<Vector3*>();
			if (vec3 != NULL) {
				Util::SafeFormat(mPrintBuffer, sizeof(mPrintBuffer),
						"Vector3(%f,%f,%f)", vec3->mX, vec3->mY, vec3->mZ);
				result->append(mPrintBuffer);
			}

		}
	}
}
Example #10
0
void HPrint(char **caption, char **result, int row, int col) {
	char sep[8192] = {0};
	int i, j, k, width[128] = {0};
	if (!row) return;
	for (j = k = 0; j < col; j++) {
		sep[k++] = '+';
		width[j] = Strlen(caption[j]);
		for (i = 0; i < row; i++)
			width[j] = max(width[j], Strlen(result[i*col+j]));
		for (i = 0; i < width[j] + 2; i++)
			sep[k++] = '-';
	}
	sep[k++] = '+';
	puts(sep);
	PrintTable(caption, width, 1, col);
	puts(sep);
	PrintTable(result, width, row, col);
	puts(sep);
}
void CDigitalStatusPrinter::DoPrinter(QPainter*p)
{
    m_pPrinter->newPage();
	printf("DigitalStatusPrinter start\n");
	PrintTitle(p);

	PrintHeader(p);

	PrintTable(p);
	printf("DigitalStatusPrinter end\n");
}
Example #12
0
int minMultiplyMatrixChainBottomUp( int* matrixChain, int chainSize )
{
	if (chainSize == 0)
	{
		return 0;
	}

	int** resultTable = new ( int*[chainSize] );
	for ( int i = 0; i < chainSize; ++ i )
	{
		resultTable[i] = new ( int[chainSize] );
		memset( resultTable[i], 0, sizeof( int )*chainSize );
	}


	for ( int diff = 1; diff < chainSize; ++diff )
	{
		for ( int startPoint = 0; startPoint < chainSize - diff; ++startPoint )
		{
			int endPoint = startPoint + diff;
			printf_s( "%d , %d \n", startPoint, endPoint );
			resultTable[startPoint][endPoint] = resultTable[startPoint + 1][endPoint] + ROW( startPoint + 1 )*COL( startPoint + 1 )*COL( endPoint + 1 );

			for ( int endOfFirst = startPoint + 1; endOfFirst < endPoint; ++endOfFirst )
			{
				int cost = resultTable[startPoint][endOfFirst] + resultTable[endOfFirst + 1][endPoint] + ROW( startPoint + 1 )*COL( endOfFirst + 1 )*COL( endPoint + 1 );

				if (cost < resultTable[startPoint][endPoint])
				{
					resultTable[startPoint][endPoint] = cost;
				}
			}

			

			PrintTable( resultTable, chainSize );
			getchar();
		}
	}

	int minCost = resultTable[0][chainSize - 1];

	for ( int i = 0; i < chainSize; ++ i )
	{
		delete[] resultTable[i];
	}

	delete[] resultTable;


	return minCost;

}
int main(int argc, char *argv[])
{
   char buf[LINE_LEN];              
   /* word string buffer */
   char fileName[LINE_LEN];         
   /* file name buffer */
   int howManyBins;                 
   /* number of bins to create */
   TABLE *hashTable;                
   /* pointer to hash table */
   FILE *fp;

   /* Read file name from command line */
   if (argc < MIN_ARGS || sscanf(argv[FILE_ARG_IX], BUFFMT "s", fileName) != 1)
   {
      fprintf(stderr, "No file name specified on command line\n");
      return EXIT_FAILURE;
   }
   fp = OpenFile(fileName);

   /* Read bin count from command line */
   if (sscanf(argv[BINS_ARG_IX], "%d", &howManyBins) != 1)
   {
      fprintf(stderr, "No bin count specified on command line\n");
      return EXIT_FAILURE;
   }
   hashTable = CreateTable((size_t)howManyBins);  
   /* allocate table array */

   /*
    * The following loop will read one string at a time from stdin until
    * EOF is reached.  For each string read the BuildList function will
    * be called to update the hash table.
    */
   while (fscanf(fp, BUFFMT "s", buf) != EOF) 
   /* get string from file */
   {
      /* find appropriate bin */
      BIN *bin = &hashTable->firstBin[HashFunction(buf, (size_t)howManyBins)];
      NODE *newStart = BuildTree(bin->firstNode, buf, bin);                   
      /* put string in list */
      bin->firstNode = newStart;
   }
   fclose(fp);
   PrintTable(hashTable);                    
   /* print all strings */
   FreeTable(hashTable);                     
   /* free the table */
   return(EXIT_SUCCESS);
}
Example #14
0
	//打印整个语法树
	int TSyntaxTreeAnalyse::Print(TMdbSqlParser * pSqlParser,int iLogType)
	{
//#if 0
		ST_SQL_STRUCT & stSqlStruct = pSqlParser->m_stSqlStruct;
		OutPutInfo(iLogType,"#################SqlStruct start################");
		OutPutInfo(iLogType,"==========================================");
		OutPutInfo(iLogType,"Insert(%d),delete(%d),update(%d),select(%d)",TK_INSERT,TK_DELETE,TK_UPDATE,TK_SELECT);
		OutPutInfo(iLogType,"[type = %d],[tablename = %s][alias = %s][pMdbTable = %p][pShmDSN= %p][pScanAllIndex= %p][vIndexUsed=%d]",
			stSqlStruct.iSqlType,
			ReplaceNull(stSqlStruct.sTableName),
			ReplaceNull(stSqlStruct.sAlias),
			stSqlStruct.pMdbTable,stSqlStruct.pShmDSN,
			stSqlStruct.pScanAllIndex,
			stSqlStruct.vIndexUsed.size());
		OutPutInfo(iLogType,"===========[index used]==================");
		PrintIndex(stSqlStruct.vIndexUsed,0,iLogType);
		OutPutInfo(iLogType,"===========[column list]==================");
		PrintExprList(stSqlStruct.pColList,0,iLogType);
		OutPutInfo(iLogType,"===========[where]========================");
		PrintExpr("root",stSqlStruct.pWhere,0,iLogType);
		OutPutInfo(iLogType,"===========[group by]========================");
		PrintExprList(stSqlStruct.pGroupby,0,iLogType);
		OutPutInfo(iLogType,"===========[having]========================");
		PrintExpr("root",stSqlStruct.pHaving,0,iLogType);
		OutPutInfo(iLogType,"===========[optimised where]==================");
		PrintWhereClause(iLogType,stSqlStruct.tWhereOrClause);
		OutPutInfo(iLogType,"===========[orderby]======================");
		PrintExprList(stSqlStruct.pOrderby,0,iLogType);
		OutPutInfo(iLogType,"===========[limit]========================");
		PrintExpr("root",stSqlStruct.pstLimit,0,iLogType);
		OutPutInfo(iLogType,"===========[offset]=======================");
		PrintExpr("root",stSqlStruct.pstOffset,0,iLogType);
		OutPutInfo(iLogType,"===========[idlist]=======================");
		PrintIdList(stSqlStruct.pstIdList,0,iLogType);
		OutPutInfo(iLogType,"==========================================");
		PrintValues(pSqlParser,iLogType);
		OutPutInfo(iLogType,"#################SqlStruct end#################");

    	_ST_DDL_SQL_STRUCT * pstDDLSqlStruct = pSqlParser->m_pDDLSqlStruct;
		OutPutInfo(iLogType,"###############DDLSqlStruct start##############");
    	if(pstDDLSqlStruct)
    	{
        	OutPutInfo(iLogType,"[sqltype = [%d][%d]][IfNE = %d]",pstDDLSqlStruct->iSqlType[0],pstDDLSqlStruct->iSqlType[1]
        															,pstDDLSqlStruct->bIfNE);
        	PrintTable(pstDDLSqlStruct->pTable,iLogType);
    	}
		OutPutInfo(iLogType,"###############DDLSqlStruct end################");
//#endif
		return 0;
	}
void PrintTable(lua_State *L, int tableSize, int *tableContents) {
	int i = 0; //increments to store w,x,y,z
	lua_pushnil(L);
	while (lua_next(L, -2) != 0) //while table or integers exist on stack
	{
		if (lua_isnumber(L, -1)) //If number = if x,y,w,h
				{
			tableContents[4 * (tableSize) + i] = lua_tointeger(L, -1);
			i++;
		} else if (lua_istable(L, -1)) // If table = detection. All detections stored in a table of tables
				{
			PrintTable(L, --tableSize, tableContents); //Recursive call to get table elements
		}
		lua_pop(L, 1); //Pop number off stack
	}
}
Example #16
0
int main()
{
  ddTableDealsPBN DDdealsPBN;
  ddTablesRes tableRes;
  allParResults pres;

  int mode = 0: // No par calculation
  int trumpFilter[DDS_STRAINS] = {0, 0, 0, 0, 0}; // All
  int res;
  char line[80];
  bool match;

#if defined(__linux) || defined(__APPLE__)
  SetMaxThreads(0);
#endif

  DDdealsPBN.noOfTables = 3;

  for (int handno = 0; handno < 3; handno++)
  {
    for (int h = 0; h < DDS_HANDS; h++)
      for (int s = 0; s < DDS_SUITS; s++)
        strcpy(DDdealsPBN.deals[handno].cards, PBN[handno]);
  }

  res = CalcAllTablesPBN(&DDdealsPBN, mode, trumpFilter,
                         &tableRes, &pres);

  if (res != RETURN_NO_FAULT)
  {
    ErrorMessage(res, line);
    printf("DDS error: %s\n", line);
  }

  for (int handno = 0; handno < 3; handno++)
  {
    match = CompareTable(&tableRes.results[handno], handno);

    sprintf(line,
            "CalcDDtable, hand %d: %s\n",
            handno + 1, (match ? "OK" : "ERROR"));

    PrintPBNHand(line, DDdealsPBN.deals[handno].cards);

    PrintTable(&tableRes.results[handno]);
  }
}
int main(int argc, char *argv[])
{
    int in_data,addr;
    int choose, loopflag=1;

    hash_init();

    while(loopflag)
    {
        printf("雜湊表內容(e表空格):");
        PrintTable(table);
        printf("\n(1)加入資料\n(2)搜尋資料\n(0)結束=>");
        scanf("%d",&choose);

        switch(choose)
        {
                case 0:
                        loopflag=0;                        /*結束程式*/
						break;
                case 1:
                        if(is_full())
                                printf("陣列已滿\n");
                        else
                        {
                                printf("請輸入欲加入之資料=>");
                                scanf("%d",&in_data);

                                hash_insert(in_data);
                        }
                        break;
                case 2:
                        printf("請輸入欲搜尋之資料=>");
                        scanf("%d",&in_data);

                        if((addr=hash_srch(in_data)) == -1)
                                printf("找不到資料\n");
                        else
                                printf("資料 %d 位於表格第 %d 個位置(由0算起)\n",in_data,addr);
                        break;
				default:
						printf("Wrong Input !!!! \n");
        }
    }
    system("PAUSE");
    return 0;
}
Example #18
0
void SearchSix(int row, int ld, int rd, int times){
    if(row == binary[n]-1){
        if(count < 3) {
            PrintTable(); 
        }
        count++; 
        return; 
    }
    int p; 
    int pos = binary[n]-1 & ~ (row | ld | rd); 
    while(pos != 0){
        p = pos & -pos; 
        pos = pos - p; 
        result[times] = p; 
        SearchSix(row+p, (ld+p) << 1, (rd+p) >> 1, times+1); 
        result[times] = -1; 
    }
}
void PreqDialog::initPreDialog() {

    PrintTable();
    ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(true);

    if(!preAttr.isEmpty()) {
        ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(false);
    }

    if(!preTraits.isEmpty()) {
        ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(false);
    }

    if(!preSkills.isEmpty()) {
        ui->buttonBox->button(QDialogButtonBox::Ok)->setDisabled(false);
    }

    if(earlyChild == "Nobility" && realLife == "Covert Operations") {
        QMessageBox::information(this, tr("Prerequisites"),tr("Choose one: 500XP in Wealth, Title or Property and 150XP in Connections Trait or Leadership Skill"));
    } else {
        if(earlyChild == "White Collar" && realLife == "Covert Operations") {
            QMessageBox::information(this, tr("Prerequisites"),tr("Choose one: 300XP in Wealth or Property and 150XP in Connections Trait or Leadership Skill"));
        } else {
            if (earlyChild == "Nobility") {
               QMessageBox::information(this, tr("Prerequisites"),tr("Choose one: 500XP in Wealth , Title or Property."));
            }

            if (earlyChild == "White Collar") {
               QMessageBox::information(this, tr("Prerequisites"),tr("Choose one: 300XP in Wealth or Property."));
            }

            if (realLife == "Covert Operations") {
               QMessageBox::information(this, tr("Prerequisites"),tr("Choose one: 150XP in Connections Trait or Leadership Skill."));
            }
        }

    }





}
Example #20
0
void GoToTown(char pre)
{
   FILENODE *fptr, **bp;
   int n, *ix, *iy, *ia, *ib;

   fptr = GetSumm(pre, &n, &ix, &iy, &ia, &ib, &bp);
   if (!fptr)
   {
      DoIt(pre);
      fptr = GetSumm(pre, &n, &ix, &iy, &ia, &ib, &bp);
      assert(fptr);
   }
   fprintf(stdout, "%d:\n", __LINE__);
   PrintTable(n, ix, iy, ia, ib, bp);
   GenFiles(pre, n, ix, iy, ia, ib, bp);

   KillAllFN(fptr);
   free(bp);
   free(ix);
}
Example #21
0
int main()
{
    init();
    while(1)
    {
        char ch;
        printf("先检查初始状态是否安全:\n");
        if(security())
        {
            printf("当前处于安全状态:\n");
            printf("安全序列是{P%d,P%d,P%d,P%d,P%d}。\n",safeseq[0],safeseq[1],safeseq[2],safeseq[3],safeseq[4]);
        }
        else
        {
            printf("系统处于不安全状态。程序将退出...\n");
            break;
        }
        do
        {
            int process;
            Resource res;
            PrintTable();
            printf("请依次输入请求分配的进程和对三类资源的请求数量:");
            scanf("%d%d%d%d",&process,&res.A,&res.B,&res.C);
            if(banker(process,&res))
            {
                printf("分配成功。\n");
                printf("安全序列是{P%d,P%d,P%d,P%d,P%d}。\n",safeseq[0],safeseq[1],safeseq[2],safeseq[3],safeseq[4]);
            }
            else
            {
                printf("分配失败。\n");
            }
            printf("是否继续分配?(Y/N):");
            fflush(stdin);
            ch=getchar();
        }
        while(ch=='y' || ch=='Y');
    }
    return 0;
}
int main(int argc, char *argv[])
{
	int in_data,choose, addr, loopflag=1;

    hash_init();

    while(loopflag)
    {
        printf("雜湊表內容:\n");
        PrintTable();
        printf("\n(1)加入資料\n(2)搜尋資料\n(0)結束=>");
        scanf("%d",&choose);

        switch(choose)
        {
                case 0:
                        Free_All_Node();
                        loopflag=0;                        /*結束程式*/
						break;
                case 1:
                        printf("請輸入欲加入之資料=>");
                        scanf("%d",&in_data);

                        hash_insert(in_data);
                        break;
                case 2:
                        printf("請輸入欲搜尋之資料=>");
                        scanf("%d",&in_data);

                        if((addr=hash_srch(in_data)) == -1)
							printf("找不到資料\n");
                        else
							printf("找到! 在第 %d 個串列\n",addr);
                        break;
                default:
                        printf("選項錯誤");
        }
    }
    system("PAUSE");
    return 0;
}
Example #23
0
int main()
{
  ddTableDeal tableDeal;
  ddTableResults table;

  int res;
  char line[80];
  bool match;

#if defined(__linux) || defined(__APPLE__)
  SetMaxThreads(0);
#endif

  for (int handno = 0; handno < 3; handno++)
  {

    for (int h = 0; h < DDS_HANDS; h++)
      for (int s = 0; s < DDS_SUITS; s++)
        tableDeal.cards[h][s] = holdings[handno][s][h];

    res = CalcDDtable(tableDeal, &table);

    if (res != RETURN_NO_FAULT)
    {
      ErrorMessage(res, line);
      printf("DDS error: %s\n", line);
    }

    match = CompareTable(&table, handno);

    sprintf(line,
            "CalcDDtable, hand %d: %s\n",
            handno + 1, (match ? "OK" : "ERROR"));

    PrintHand(line, tableDeal.cards);

    PrintTable(&table);
  }
}
Example #24
0
void ReadFromFile(FILE* input,MacroTable* table){
    char* instruc = (char*)calloc(100,sizeof(char));
    char* prev= (char*)calloc(100,sizeof(char)); 
    char* oper = (char*)calloc(100,sizeof(char)); 
    MacroSymbols* macro;

//READING MACROS AND CREATING TABLES
    while(fscanf(input,"%s",instruc) > 0){
        if(strcmp(instruc,"BEGINMACRO")!=0){
            strcpy(prev,instruc);
        } else {
            //creates macro with its name (prev)
	    //remove ":" from the macro name
	    remove2P(prev);
            macro = createMacroSymbols(prev);
            while(strcmp(instruc,"ENDMACRO")!=0){
                fscanf(input,"%s",instruc);
                //macro with parameter
                if(IsKeyword(instruc)==0){
                    strcpy(macro->parameter_,instruc);
		    macro->has_parameter_=1;
                } else {
                    //check if theres an operand to insert in table
                    if(IsKeyword(instruc)==2 &&(strcmp(instruc,"ENDMACRO")!=0)){
                       fscanf(input,"%s",oper);
		       
                       insertInstrucInTable(macro,instruc,oper);
                    } else if(strcmp(instruc,"ENDMACRO")!=0) {
		       strcpy(oper,"\0");
		       macro->has_parameter_=0;	
                       insertInstrucInTable(macro,instruc,oper);
                    }
                }
            }
            insertInMacroTable(table,macro);
        }
    }
    PrintTable(table);
}
Example #25
0
Json::Value JsonPrinter::PrintValue(Sqrat::Object object) {
	if(!object.IsNull()) {
		if(object.GetType() == OT_TABLE) {
			Json::Value v;
			PrintTable(v, object.Cast<Sqrat::Table>());
			return v;
		}
		else if(object.GetType() == OT_ARRAY) {
			Json::Value v(Json::arrayValue);
			PrintArray(v, object.Cast<Sqrat::Array>());
			return v;
		}
		else if(object.GetType() == OT_INTEGER) {
			return Json::UInt64(object.Cast<unsigned long>());
		}
		else if(object.GetType() == OT_STRING) {
			return Json::Value(object.Cast<std::string>());
		}
		else if(object.GetType() == OT_BOOL) {
			return Json::Value(object.Cast<bool>());
		}
		else if(object.GetType() == OT_FLOAT) {
			return Json::Value(object.Cast<double>());
		}
		else {
			Vector3 *vec3 = object.Cast<Vector3*>();
			if(vec3 != NULL) {
				Json::Value v3;
				v3["x"] = vec3->mX;
				v3["y"] = vec3->mY;
				v3["z"] = vec3->mZ;
				return v3;
			}
		}
	}
	Json::Value v;
	return v;
}
Example #26
0
void LuaManager::PrintTable(LuaPlus::LuaObject table, bool recursive)
{
	if(table.IsNil())
	{
		if(!recursive)
			GLIB_LOG("LuaManager", "null table");
		return;
	}

	if(!recursive)
		GLIB_LOG("LuaManager", "PrintTable()");

	cout << (!recursive ? "--\n" : "{ ");

	bool noMembers = true;
	for(LuaPlus::LuaTableIterator iter(table); iter; iter.Next())
	{
		noMembers = false;

		LuaPlus::LuaObject key = iter.GetKey();
		LuaPlus::LuaObject value = iter.GetValue();

		cout << key.ToString() << ": ";
		if(value.IsFunction())
			cout << "function" << "\n";
		else if(value.IsTable())
			PrintTable(value, true);
		else if(value.IsLightUserData())
			cout << "light user data" << "\n";
		else
			cout << value.ToString() << ", ";
	}

	cout << (!recursive ? "\n--" : "}");
	cout << endl;
}
void PreqDialog::on_preqListTable_cellClicked(int row, int)
{
    QTableWidgetItem *elemName = new QTableWidgetItem;
    elemName = ui->preqListTable->item(row, 0);
    QTableWidgetItem *elemVar = new QTableWidgetItem;
    elemVar = ui->preqListTable->item(row, 1);

    if(elemName != 0x0) {

        if(earlyChild == "Nobility" && realLife == "Covert Operations") {
            NobChange(elemName->text());
            CovOpChange(elemName->text());
        } else {
            if(earlyChild == "White Collar" && realLife == "Covert Operations") {
                WhiteColChange(elemName->text());
                CovOpChange(elemName->text());
            } else {
                if(earlyChild == "Nobility") {
                    NobChange(elemName->text());
                }

                if(earlyChild == "White Collar") {
                    WhiteColChange(elemName->text());
                }

                if(realLife == "Covert Operations") {
                    CovOpChange(elemName->text());
                }
            }
        }

    }

    PrintTable();

}
Example #28
0
    JNIEXPORT float JNICALL
    Java_com_torchandroid_facedemo_CameraClass_callTorch(JNIEnv *env, jobject thiz, jlong torchStateLocation,
            jint width, jint height, jbyteArray NV21FrameData, jintArray outPixels) {

        lua_State *L = (lua_State*) torchStateLocation;

        float netProfiler = 0;

        THFloatTensor *testTensor = THFloatTensor_newWithSize1d(1280*768);  //Initialize 1D tensor.
        jbyte *testTensor_data; //Initialize tensor to store java byte data from camera.
        testTensor_data = (env)->GetByteArrayElements(NV21FrameData,0); //Get pointer to java byte array region
        int imSize = 1280*768; //Define number of pixels

        jfloat *poutPixels = THFloatTensor_data(testTensor); //Torch tensor type to int
        jint *output = env->GetIntArrayElements(outPixels, 0); //Get java int array region for output

        //This loop ignores U and V channels. Network doesn't use them
        //Cam data comes like so - YYYYYY ... imSize times.... YYYYY UVUVUVUVUVUV.... <- ignore these
        for(int i = 0; i < imSize; i++)
        {
            output[i] = 0;
            poutPixels[i] = testTensor_data[i] & 0xFF;
        }

        int tableSize = 0; //Holds number of detections

        int *fill;

        lua_getglobal(L,"getDetections");

        lua_getglobal(L,"network");
        luaT_pushudata(L,testTensor,"torch.FloatTensor"); //Push tensor to lua stack
        lua_pushnumber(L,width);
        lua_pushnumber(L,height);
        if(lua_pcall(L,4,3,0) != 0) //Call function. Print error if call not successful
            __android_log_print(ANDROID_LOG_INFO, "Torchandroid", "Error running function: %s",lua_tostring(L, -1));

        else {

            netProfiler = (float) lua_tonumber(L,-1);
            lua_pop(L,1);

            tableSize = lua_tointeger(L,-1);  //Get #detections from stack
            lua_pop(L,1);
            if(tableSize != 0)  //Extract x,y,w,h for each detection
            {
                fill = (int*) malloc(4*tableSize*sizeof(int)); //Holds detections
                PrintTable(L,tableSize,fill);

            }
        }

        if(tableSize != 0)
        {
            int center[2] = {0};
            for(int i = 0; i < 4*tableSize; i+=4)
            {
                int x = fill[i];
                int y = fill[i+1];
                int w = fill[i+2];
                int h = fill[i+3];

                for(int j = i+4; j < 4*tableSize; j+=4)
                {
                    center[0] = fill[j]+fill[j+2]*0.5; //x center
                    center[1] = fill[j+1]+fill[j+3]*0.5; //y center
                    if(((center[0] <= (x+w)) && (center[0] >= x)) && ((center[1] <= (y+h)) && (center[1] >= y)))
                    {
                        fill[j+2] = 0;
                    }
                }

            }
        }

        if(tableSize != 0)
        {
            int tempnum2 = 2*1280;
            int tempnum3 = 3*1280;

            int jlim = 0; //Define to prevent computation of loop control for each iteration. Efficiency FTW
            int tempnum1 = 0;
            int center[2] = {0};  //Holds center of box xy

            for(int i = 0; i < 4*tableSize; i+=4)
            {

                if(fill[i+2] == 0)
                    continue;

                int x = fill[i];
                int y = fill[i+1];
                int w = fill[i+2];
                int h = fill[i+3];

                int tempnum2 = h*2*1280;
                int tempnum3 = h*3*1280;

                __android_log_print(ANDROID_LOG_INFO, "Torchandroid", "x = %u y = %u w = %u h = %u",x,y,w,h);


                jlim = ((y-1)*1280+x+w);
                tempnum1 = 1280*(h-1);
                //Assign output pixels red color. 4 byte - ARGB. x,y from network in 2D. Convert to 1 D
                for(int j = (y-1)*1280+x; j < jlim; j++)  //This loop does top and bottom lines of box
                {
                    output[j-1280] = 0xFFFF0000;
                    output[j+1280] = 0xFFFF0000;
                    output[j] = 0xFFFF0000;
                    output[j+tempnum1] = 0xFFFF0000;
                    output[j+tempnum1-1280] = 0xFFFF0000;
                    output[j+tempnum1+1280] = 0xFFFF0000;
                }

                jlim = (((y-1)*1280+x)+((1280*h)+w));
                for(int j = (y-1)*1280+x; j < jlim; j+=1280) //This loop does left and right of box
                {
                    output[j+1] = 0xFFFF0000;
                    output[j-1] = 0xFFFF0000;
                    output[j] = 0xFFFF0000;
                    output[j+w] = 0xFFFF0000;
                    output[j+w+1] = 0xFFFF0000;
                    output[j+w-1] = 0xFFFF0000;
                }
            }
        }

        env->ReleaseByteArrayElements(NV21FrameData, testTensor_data, 0); //Destroy pointer to location in C. Only need java now
        env->ReleaseIntArrayElements(outPixels, output, 0); //Same as above here
        return netProfiler;
    }
Example #29
0
void test_hashtable(void)
{
	static char *tableContents[] = {
		"FirstKey", "FirstValue",
		"SecondKey", "SecondValue",
		"ThirdKey", "ThirdValue",
		"FourthKey", "FourthValue",
		NULL
	};
	
	MxHashtableRef table = MxHashtableCreatePropertyMap();
	if (!table)
		die("Couldn't create table - probably no memory");
	
	MxStatus status = MxStatusOK;
	
	if ((status = MxHashtableSetKeyFreeFunction(table, NULL)) != MxStatusOK)
		dieWithStatus("Setting key free", status);
	
	if ((status = MxHashtableSetValueFreeFunction(table, NULL)) != MxStatusOK)
		dieWithStatus("Setting value free", status);
	
	
	int idx = 0;
	while (tableContents[idx]) {
		if ((status = MxHashtablePut(table, tableContents[idx], tableContents[idx+1])) != MxStatusOK)
			dieWithStatus("put", status);
		idx += 2;
	}
	
	PrintTable("Initial", table);
	
	char *result = NULL;
	if ((status = MxHashtableGet(table, "SecondKey", (void **)&result)) != MxStatusOK)
		dieWithStatus("Table get", status);
    
	printf("Value for \"SecondKey\" : %s\n", result);
	
	PrintTable("After get 'SecondKey'", table);
	
	if ((status = MxHashtableTake(table, "ThirdKey", (void **)&result)) != MxStatusOK)
		dieWithStatus("Table take", status);
	
	printf("Value from take(\"ThirdKey\"): %s\n", result);
	
	PrintTable("After take 'ThirdKey'", table);
	
	printf("Keys: ");
	if ((status = MxHashtableIterateKeys(table, PrintCallback, NULL)) != MxStatusOK)
		dieWithStatus("Iterating keys", status);
	printf("\n\n");
	
	printf("Values: ");
	if ((status = MxHashtableIterateValues(table, PrintCallback, NULL)) != MxStatusOK)
		dieWithStatus("Iterating values", status);
	printf("\n\n");
	
	if ((status = MxHashtableRemove(table, "FourthKey")) != MxStatusOK)
		dieWithStatus("removing", status);
	
	PrintTable("Removed 'FourthKey'", table);
	
	status = MxHashtableRemove(table, "DoesntExist");
	if (status == MxStatusNotFound)
		printf("DoesntExist not found\n");
	else
		printf("Unexpected status: %s\n", MxStatusMsg(status));
	
	if ((status = MxHashtablePut(table, "SecondKey", "NewSecondValue")) != MxStatusOK)
		dieWithStatus("Replacing value", status);
	
	PrintTable("Replaced 'SecondKey'", table);
    
	printf("Clearing..."); fflush(stdout);
	if ((status = MxHashtableClear(table)) != MxStatusOK)
		dieWithStatus("Clearing", status);
	printf("Done."); fflush(stdout);
	
	PrintTable("After clear", table);
	
	if ((status	= MxHashtablePut(table, "foo", "bar")) != MxStatusOK)
		dieWithStatus("putting after clear", status);
	
	PrintTable("Put following clear", table);
	
	if ((status	= MxHashtablePut(table, "boo", "baz")) != MxStatusOK)
		dieWithStatus("putting after clear", status);
	
	PrintTable("Another put", table);
	
	status = MxHashtableContainsKey(table, "foo");
	printf("Contains \"foo\": (%d) %s\n", status, MxStatusMsg(status));
	
	MxHashtableDelete(table);
}
/***************************************************************************
 ** ReadSites --
 **    This function asks the user for the name of the data
 ** file to be used, opens it, reads the website Addresses and
 ** sorts them. The totals are then computed and the tables printed using
 ** other functions within this one.
 **      Inputs: None
 **      Outputs: 4 arrays fll of websites and printed results.
 ***************************************************************************/
void ReadSites()
{
   FILE *ifp;
   char filename[SIZE] = "cat";
   char temp[SIZE] = "dog";
   int j = 0;

   /*The  four arrays are declared*/
   WEBSITE t, comSites[SIZE], govSites[SIZE], eduSites[SIZE], netSites[SIZE];

   int TotalNonUniqueSites = 0, TotalUniqueSites = 0, TotalTimeLogged = 0;
   int TotalFunSites = 0, TotalSearchSites = 0, TotalEducationSites = 0;
   int  TotalNewsSites = 0, *pTotalNewsSites, *pTotalNonUniqueSites;
   int *pTotalUniqueSites, *pTotalTimeLogged, *pTotalFunSites; 
   int *pTotalSearchSites, *pTotalEducationSites;

   /*The pointers are set to point to the their corresponding values*/
   pTotalNonUniqueSites = &TotalNonUniqueSites;
   pTotalUniqueSites = &TotalUniqueSites;
   pTotalTimeLogged = &TotalTimeLogged;
   pTotalFunSites = &TotalFunSites;
   pTotalSearchSites = &TotalSearchSites;
   pTotalEducationSites = &TotalEducationSites;
   pTotalNewsSites = &TotalNewsSites;

   /*The are filled with dummy values*/
   FillArray(comSites);
   FillArray(netSites);
   FillArray(eduSites);
   FillArray(govSites);

   /*Asks the user for the file name*/
   fprintf(stdout, "\nPlease enter the file name: ");
   fscanf(stdin, "%s", filename);
   ifp = fopen(filename, "r");

   /*If the file cannot exit and give error message*/
   if(ifp == NULL)
   {
      fprintf(stderr, "The file could not be opened.");
      exit(-1);
   }

   /*Scans every thing in the file until it reaches the end*/
   while(fscanf(ifp, "%s %s %d", temp, t.siteType, &t.seconds) != EOF)
     {
	/*Breaks the string temp  into access code, domain name*/
	/* and domain ending and stores the in the temporary structure*/
	t.webAddress = CreateAddress(temp);
	
	/*Depending on the first letter of the domain ending, stores*/
	/*them into the appropriate array*/
	if(t.webAddress.domainEnding[0] == 'c')
	{
	   /*Finds the index of wherever the website is supposed to go*/
	   j = IsPresent(comSites, t);
	   
	   /*Stores the website in the proper location*/
	   comSites[j].webAddress = t.webAddress;
	   
	   /*Stores the siteType in the corresponding location*/
	   strcpy(comSites[j].siteType, t.siteType);
	   
	   /*Adds the number of hits and the seconds*/
	   comSites[j].hits += 1;
	   comSites[j].seconds += t.seconds;
	} 
	else if(t.webAddress.domainEnding[0] == 'g')
	{
	   j = IsPresent(govSites, t);
	   
	   govSites[j].webAddress = t.webAddress;
	   strcpy(govSites[j].siteType, t.siteType);
	   govSites[j].hits += 1;
	   govSites[j].seconds += t.seconds;
	}
	else if(t.webAddress.domainEnding[0] == 'n')
	{
	   j = IsPresent(netSites, t);
	   
	   netSites[j].webAddress = t.webAddress;
	   strcpy(netSites[j].siteType, t.siteType);
	   netSites[j].hits += 1;
	   netSites[j].seconds += t.seconds;
	 }
       else
	 {
	   j = IsPresent(eduSites, t);
	   
	   eduSites[j].webAddress = t.webAddress;
	   strcpy(eduSites[j].siteType, t.siteType);
	   eduSites[j].hits += 1;
	   eduSites[j].seconds += t.seconds;
	 } 
     }  
   
   /*Sorts the arrays*/
   SortArray(eduSites, ArrayLength(eduSites));
   SortArray(govSites, ArrayLength(govSites));
   SortArray(comSites, ArrayLength(comSites));
   SortArray(netSites, ArrayLength(netSites));
   
   /*Computes the totals using data from all the arrays*/
   ComputeTotals(comSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(eduSites, pTotalUniqueSites, pTotalNonUniqueSites, 
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(netSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(govSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   /*Prints the results of the read*/
   PrintTable(comSites, netSites, eduSites, govSites);
   
   /*Caclulates the percentages and prints them*/
   CalcStats(TotalUniqueSites, TotalFunSites, TotalSearchSites,
	     TotalNewsSites, TotalEducationSites, TotalTimeLogged,
	     TotalNonUniqueSites);
   
   return;
}