コード例 #1
0
ファイル: PrintTable.cpp プロジェクト: mhoemmen/Trilinos
diag::Writer &
PrintTable::verbose_print(
  diag::Writer &	dout) const
{
  calculate_column_widths();

  dout << m_title << diag::dendl;

  for (Table::const_iterator row_it = m_header.begin(); row_it != m_header.end(); ++row_it) {
    dout << "";
    printRow(dout.getStream(), *row_it);
    dout << diag::dendl;
  }

  if (m_header.size() > 0) {
    dout << "";
    printHeaderBar(dout.getStream());
    dout << diag::dendl;
  }

  for (Table::const_iterator row_it = m_table.begin(); row_it != m_table.end(); ++row_it) {
    dout << "";
    printRow(dout.getStream(), *row_it);
    dout << diag::dendl;
  }

  return dout;
}
コード例 #2
0
ファイル: PrintTable.cpp プロジェクト: 00liujj/trilinos
diag::Writer &
PrintTable::verbose_print(
  diag::Writer &	dout) const
{
//   const ColumnWidthVector &column_width = calculate_column_widths();

//   for (Table::const_iterator row_it = m_header.begin(); row_it != m_header.end(); ++row_it) {
//     printRow(os, *row_it);
//     os << '\n';
//   }

//   if (m_header.size() > 0)
//     printHeaderBar(os);

//   for (Table::const_iterator row_it = m_table.begin(); row_it != m_table.end(); ++row_it) {
//     int i = 0;
//     for (Row::const_iterator cell_it = (*row_it).begin(); cell_it != (*row_it).end(); ++cell_it, ++i)
//       if ((*cell_it).m_flags & Cell::SPAN)
//	dout << (*cell_it).m_string;
//       else
//	dout << std::setw(column_width[i]) << (*cell_it).m_string;
//     dout << dendl;
//   }

  calculate_column_widths();

  dout << m_title << std::endl;

  for (Table::const_iterator row_it = m_header.begin(); row_it != m_header.end(); ++row_it) {
    dout << "";
    printRow(dout.getStream(), *row_it);
    dout << diag::dendl;
  }

  if (m_header.size() > 0) {
    dout << "";
    printHeaderBar(dout.getStream());
    dout << diag::dendl;
  }

  for (Table::const_iterator row_it = m_table.begin(); row_it != m_table.end(); ++row_it) {
    dout << "";
    printRow(dout.getStream(), *row_it);
    dout << diag::dendl;
  }

  return dout;
}
コード例 #3
0
/* function prints a 2-dimensional, square array to console */
void print2DArray(double **array, int length){
	int i;
	for(i = 0; i < length; ++i){
		printf("row%d\t",i);
		printRow(array[i], length);		
	}
}
コード例 #4
0
static void msBedPrintTable(struct bed *bedList, struct hash *erHash,
    char *itemName, char *expName, float minScore, float maxScore,
    float stepSize, int base,
    void(*printHeader)(struct bed *bedList, struct hash *erHash, char *item),
			    void(*printRow)(struct bed *bedList,struct hash *erHash, int expIndex, char *expName, float maxScore, enum expColorType colorScheme),
    void(*printKey)(float minVal, float maxVal, float size, int base, struct rgbColor(*getColor)(float val, float max, enum expColorType colorScheme), enum expColorType colorScheme),
    struct rgbColor(*getColor)(float val, float max, enum expColorType colorScheme),
	enum expColorType colorScheme)
/* prints out a table from the data present in the bedList */
{
int i,featureCount=0;
if(bedList == NULL)
    errAbort("hgc::msBedPrintTable() - bedList is NULL");
featureCount = slCount(bedList);
/* time to write out some html, first the table and header */
if(printKey != NULL)
    printKey(minScore, maxScore, stepSize, base, getColor, colorScheme);
printf("<p>\n");
printf("<basefont size=-1>\n");
printf("<table  bgcolor=\"#000000\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\"><tr><td>");
printf("<table  bgcolor=\"#fffee8\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">");
printHeader(bedList, erHash, itemName);
for(i=0; i<bedList->expCount; i++)
    {
    printRow(bedList, erHash, i, expName, maxScore, colorScheme);
    }
printf("</table>");
printf("</td></tr></table>");
printf("</basefont>");
}
コード例 #5
0
ファイル: entryPoint.c プロジェクト: dwinner/CppAppdev
/**
 * \brief Binary search of a sorted array
 * \param b Array
 * \param searchKey Search key
 * \param low low index
 * \param high high index
 * \return found index or -1 if the search element hasn't been found
 */
size_t binarySearch(const int b[], const int searchKey, size_t low, size_t high)
{
   // loop until low index is greater than high index
   while (low <= high)
   {
      // determine middle element of subarray being searched
      const size_t middle = (low + high) / 2;

      // display subarray used in this loop iteration
      printRow(b, low, middle, high);

      // if searchKey matched middle element, return middle
      if (searchKey == b[middle])
      {
         return middle;
      }

      if (searchKey < b[middle]) // if searchKey is less than middle element, set new high
      {
         high = middle - 1; // search low end of array
      }
      else // if searchKey is greater than middle element, set low
      {
         low = middle + 1; // search high end of array
      }
   }

   return -1; // searchKey not found
}
コード例 #6
0
void CRowSolution<T>::printSolutions(FILE *file, bool markNextUsed) const
{
	if (!solutionSize() || !numSolutions())
        return;
    
	MUTEX_LOCK(out_mutex);
	char buffer[2048];
	if (numSolutions() >= sizeof(buffer) / 2) {
  	if (markNextUsed) {
			SPRINTF(buffer, "Using solution # %zd out of %zd\n", solutionIndex(), numSolutions());
			outString(buffer, file);
		}
	}
	else {
		if (markNextUsed) {
			const size_t len2 = sizeof(buffer) << 1;
			const size_t len = solutionIndex() * 2;
			const size_t nLoops = len / len2;
			size_t idx = 0;
			for (size_t j = 0; j < nLoops; j++) {
				idx = setSolutionFlags(buffer, sizeof(buffer), idx);
				buffer[sizeof(buffer)-1] = '\0';
				outString(buffer, file);
			}

			const size_t lastLen = 2 * (numSolutions() - idx);
			setSolutionFlags(buffer, lastLen, idx);
			buffer[len % len2 + 1] = '*';
			strcpy_s(buffer + lastLen, sizeof(buffer)-lastLen, "\n");
			outString(buffer, file);
		}

		printRow(file);

		PERMUT_ELEMENT_TYPE *pPerm = solutionPerm() ? solutionPerm()->GetData() : NULL;
		if (pPerm)
			printRow(file, pPerm);

		const VECTOR_ELEMENT_TYPE *pSolution = firstSolution();
		for (unsigned int i = 0; i < solutionSize(); i++)
			printRow(file, pPerm, pSolution + i);
	}

	MUTEX_UNLOCK(out_mutex);
}
コード例 #7
0
std::ostream &
PrintTable::print(
    std::ostream &	os) const
{
    if (m_flags & COMMA_SEPARATED_VALUES)
        csvPrint(os);

    else {
        if (m_flags & PRINT_TRANSPOSED)
            transpose_table();

        calculate_column_widths();

        if (!m_title.empty()) {
            int prespaces = 0;

            if(m_title.length() < m_tableWidth)
                prespaces = (m_tableWidth - m_title.length())/2;;

            os << m_commentPrefix;
            os << std::left << std::setw(prespaces) << "" << m_title << '\n';
        }

        for (Table::const_iterator row_it = m_header.begin(); row_it != m_header.end(); ++row_it) {
            os << m_commentPrefix;
            printRow(os, *row_it);
            os << '\n';
        }

        if (m_header.size() > 0) {
            os << m_commentPrefix;
            printHeaderBar(os);
            os << '\n';
        }

        for (Table::const_iterator row_it = m_table.begin(); row_it != m_table.end(); ++row_it) {
            os << std::left << std::setw(m_commentPrefix.size()) << "";
            printRow(os, *row_it);
            os << '\n';
        }
    }

    return os;
}
コード例 #8
0
ファイル: csvexporter.cpp プロジェクト: callaa/KQueryBrowser
void CsvExporter::beginTable(TableCellIterator *iterator)
{
	// See RFC 4180 for format specification
	
	// Write header row
	QStringList cols;
	for(int i=0;i<iterator->columns();++i) {
		cols << iterator->header(i).name();
	}

	printRow(cols);

	// Write data rows
	while(iterator->nextRow()) {
		cols.clear();
		while(iterator->nextColumn())
			cols << iterator->value().toString();
		printRow(cols);
	}
}
コード例 #9
0
ファイル: hocode.c プロジェクト: ltoshea/SparseM
void stage1( char* X_name, int r, int c )       //r is row index, c is column index
{
   matrix *mainMatrix;
   mainMatrix = readInFile(X_name);
   //find the value in r,c
   int value;
   value = findingValue(c, r, mainMatrix);
   printf("%d\n", value);                          //prints the value
   printRow(mainMatrix, r);
   printCol(mainMatrix, c);
   return;
}
コード例 #10
0
void SplitTwo::printRow(EvenOdd row) const {
    switch (row) {
        case EvenOdd::EVEN: {
          cout << charForAnimal(this->animals[0][0]);
          cout << charForAnimal(this->animals[0][1]);
            break;}
        case EvenOdd::ODD: {
          cout << charForAnimal(this->animals[1][0]);
          cout << charForAnimal(this->animals[1][1]);
            break;}
        default: {
            printRow(this->row);
            break;}}}
コード例 #11
0
void printSudoku(int **board){
  int r;
  char strboard[19*38+1];
  char *majorborder = repeatStr("+===", 9);
  char *minorborder = repeatStr("+---", 9);
  for(r=0; r<9; r++){
	if (r%3==0){
	  printf ("%s+\n",majorborder);
	}else{
	  printf ("%s+\n",minorborder);
	}
	printf ("%s",printRow(board[r], 9));
  }
  printf ("%s+\n",majorborder);
}
コード例 #12
0
ファイル: pbmtolj.c プロジェクト: jhbsz/DIR-850L_A1
static void
doPage(FILE *             const ifP, 
       struct cmdlineInfo const cmdline) {

    bit * bitrow;
    int rows, cols, format, row;
    unsigned int blankRows;
    bool rowIsBlank;

    pbm_readpbminit(ifP, &cols, &rows, &format);

    bitrow = pbm_allocrow(cols);

    allocateBuffers(cols);

    putinit(cmdline);

    blankRows = 0;
    prevRowBufferIndex = 0;
    memset(prevRowBuffer, 0, rowBufferSize);

    for (row = 0; row < rows; ++row) {
        pbm_readpbmrow(ifP, bitrow, cols, format);

        convertRow(bitrow, cols, cmdline.pack, cmdline.delta,
                   &rowIsBlank);

        if (rowIsBlank)
            ++blankRows;
        else {
            printBlankRows(blankRows);
            blankRows = 0;
            
            printRow();
        }
    }    
    printBlankRows(blankRows);
    blankRows = 0;

    putrest(!cmdline.noreset);

    freeBuffers();
    pbm_freerow(bitrow);
}
コード例 #13
0
ファイル: BinearSearch.c プロジェクト: syvjohan/CFun
int binearSearch(const int arr[], int key, int low, int high) {
	int middle;

	while (low <= high) {
		middle = (low + high) / 2;

		printRow(arr, low, middle, high);

		if (key == arr[middle]) {
			return middle;
		}
		else if (key < arr[middle]) {
			high = middle - 1;
		}
		else {
			low = middle + 1;
		}
	}
	return -1;//searched key not found!
}
コード例 #14
0
ファイル: keymap.c プロジェクト: buddywithgol/visopsys
static void printMap(unsigned char *map)
{
	printf("%s\n", _("1st row"));
	printRow(keyEsc, keyPause, map);
	printf("%s\n", _("2nd row"));
	printRow(keyE0, keyMinus, map);
	printf("%s\n", _("3rd row"));
	printRow(keyTab, keyNine, map);
	printf("%s\n", _("4th row"));
	printRow(keyCapsLock, keyPlus, map);
	printf("%s\n", _("5th row"));
	printRow(keyLShift, keyThree, map);
	printf("%s\n", _("6th row"));
	printRow(keyLCtrl, keyEnter, map);
	printf("\n");
}
コード例 #15
0
ファイル: example_async.c プロジェクト: haosdent/libhbase
void scan_callback(int32_t err, hb_scanner_t scanner,
      hb_result_t results[], size_t num_results, void *extra) {
  if (num_results) {
    const char *table_name;
    size_t table_name_len;
    hb_result_get_table(results[0], &table_name, &table_name_len);
    HBASE_LOG_INFO("Received scan_next callback for table=\'%.*s\', row count=%d.",
        table_name_len, table_name, num_results);

    for (int i = 0; i < num_results; ++i) {
      printRow(results[i]);
      hb_result_destroy(results[i]);
    }
    hb_scanner_next(scanner, scan_callback, NULL);
  } else {
    hb_scanner_destroy(scanner, NULL, NULL);
    pthread_mutex_lock(&scan_mutex);
    scan_done = true;
    pthread_cond_signal(&scan_cv);
    pthread_mutex_unlock(&scan_mutex);
  }
}
コード例 #16
0
ファイル: Printer.cpp プロジェクト: evertlammerts/ipfixcol
bool Printer::print(TableManager &tm)
{
	/* if there is nothing to print, return */
	if (conf.getColumns().size() == 0) {
		return true;
	}

	this->tableManager = &tm;


	/* print table header */
	if (!conf.getQuiet()) {

		printHeader();
	}

	const Cursor *cursor;
	TableManagerCursor *tmc = tm.createCursor();
	if (tmc == NULL) {
		/* no tables, no rows */
		return true;
	}

	uint64_t numPrinted = 0;
	while (tmc->next()) {
		cursor = tmc->getCurrentCursor();
		printRow(cursor);
		numPrinted++;
	}

	delete(tmc);

	if (!conf.getQuiet()) {
		printFooter(numPrinted);
	}

	return true;
}
コード例 #17
0
ファイル: example_async.c プロジェクト: haosdent/libhbase
static void
get_callback(int32_t err, hb_client_t client,
    hb_get_t get, hb_result_t result, void *extra) {
  bytebuffer rowKey = (bytebuffer)extra;
  if (err == 0) {
    const char *table_name;
    size_t table_name_len;
    hb_result_get_table(result, &table_name, &table_name_len);
    HBASE_LOG_INFO("Received get callback for table=\'%.*s\'.",
        table_name_len, table_name);

    printRow(result);

    const hb_cell_t *mycell;
    bytebuffer qualifier = bytebuffer_strcpy("column-a");
    HBASE_LOG_INFO("Looking up cell for family=\'%s\', qualifier=\'%.*s\'.",
        FAMILIES[0], qualifier->length, qualifier->buffer);
    if (hb_result_get_cell(result, FAMILIES[0], 1, qualifier->buffer,
        qualifier->length, &mycell) == 0) {
      HBASE_LOG_INFO("Cell found, value=\'%.*s\', timestamp=%lld.",
          mycell->value_len, mycell->value, mycell->ts);
    } else {
      HBASE_LOG_ERROR("Cell not found.");
    }
    bytebuffer_free(qualifier);
    hb_result_destroy(result);
  } else {
    HBASE_LOG_ERROR("Get failed with error code: %d.", err);
  }

  bytebuffer_free(rowKey);
  hb_get_destroy(get);

  pthread_mutex_lock(&get_mutex);
  get_done = true;
  pthread_cond_signal(&get_cv);
  pthread_mutex_unlock(&get_mutex);
}
コード例 #18
0
ファイル: UniformData.cpp プロジェクト: jrco/nau
char *UniformData::ValueString(){
	ostringstream os;

	if (outputString){
		free(outputString);
	}
	if (isValueSet){

		
		if ((datasize[0] == datasize[1]) && (datasize[0] == 1)){ //Single Value
			switch(datatype){
				case 0:
					os << name << "(" << program << ", " << location << ") = " << ((int*) data)[0];
					break;
				case 1:
					os << name << "(" << program << ", " << location << ") = " << ((unsigned int*) data)[0];
					break;
				case 2:
					os << name << "(" << program << ", " << location << ") = " << ((float*) data)[0];
					break;
				case 3:
					os << name << "(" << program << ", " << location << ") = " << ((bool*) data)[0];
					break;
				default:
					os << name << "(" << program << ", " << location << ") = " << std::hex << ((unsigned int*) data)[0];
					break;
			}
		}
		else if (datasize[0] == 1){ //Array
			switch(datatype){
				case 0:
					os << name << "(" << program << ", " << location << ") = ";
					printRow(&os, 0);
					break;
				case 1:
					os << name << "(" << program << ", " << location << ") = ";
					printRow(&os, 0);
					break;
				case 2:
					os << name << "(" << program << ", " << location << ") = ";
					printRow(&os, 0);
					break;
				case 3:
					os << name << "(" << program << ", " << location << ") = ";
					printRow(&os, 0);
					break;
				default:
					os << name << "(" << program << ", " << location << ") = ";
					printRow(&os, 0);
					break;
			}
		}
		else  if (datasize[0] != 0){ //Matrix
			//int blanklength = 7 + name.length() + getLength(program) + getLength(location);
			os << name << "(" << program << ", " << location << ") = (about to be implemented)";
		}
		else{
			os << name << "(" << program << ", " << location << ") = (not implemented yet / unknown)";
		}
	}
	else{
		os << name << "(" << program << ", " << location << ") = (null)";
	}

	outputString = strdup(os.str().c_str());
	return outputString;
}
コード例 #19
0
ファイル: utils.cpp プロジェクト: frasercrmck/columbo
void printGrid(const Grid *const grid, bool use_colour, const char *phase) {

  if (phase != nullptr) {
    std::cout << "After " << phase << "...\n";
  }

  std::cout << "     ";
  for (unsigned i = 0; i < 9; ++i) {
    std::cout << i << "   ";
  }
  std::cout << "\n";

  printLine(grid, 0, /*big_grid*/ true, /*thick*/ true, /*top*/ true,
            /*bottom*/ false, use_colour);
  std::cout << "\n";

  for (unsigned row = 0; row < 9; ++row) {
    const bool in_small_grid = row >= 3 && row <= 5;

    unsigned small_row = (row - 3) * 3;

    printRow(*grid->rows[row], row, 0, /*big_grid*/ true, use_colour);
    if (in_small_grid) {
      printRow(*grid->rows[small_row], small_row, 0, /*big_grid*/ false,
               use_colour);
    }
    std::cout << "\n";

    printRow(*grid->rows[row], row, 1, /*big_grid*/ true, use_colour);
    if (in_small_grid) {
      printRow(*grid->rows[small_row + 1], small_row + 1, 0, /*big_grid*/ false,
               use_colour);
    }
    std::cout << "\n";

    printRow(*grid->rows[row], row, 2, /*big_grid*/ true, use_colour);
    if (in_small_grid) {
      printRow(*grid->rows[small_row + 2], small_row + 2, 0, /*big_grid*/ false,
               use_colour);
    }
    std::cout << "\n";

    if (row != 8) {
      printLine(grid, row, /*big_grid*/ true, row == 2 || row == 5,
                /*top*/ false,
                /*bottom*/ false, use_colour);
      if (row == 2) {
        // The line just before the small grid starts
        printLine(grid, 0, /*big_grid*/ false, true, /*top*/ true,
                  /*bottom*/ false, use_colour);
      } else if (in_small_grid) {
        printLine(grid, small_row + 2, /*big_grid*/ false, /*thick*/ true,
                  /*top*/ false,
                  /*bottom*/ row == 5, use_colour);
      }
      std::cout << "\n";
    }
  }

  printLine(grid, 8, /*big_grid*/ true, /*thick*/ true, /*top*/ false,
            /*bottom*/ true, use_colour);
  std::cout << "\n";
}
コード例 #20
0
ファイル: 6.c プロジェクト: ta5aka1/practice
void main(){
    int i;
    for(i = 1; i <= 9; i++){
        printRow(i);
    }
}
コード例 #21
0
ファイル: printMatrix.c プロジェクト: dwinner/CppAppdev
// Print the whole matrix.
void printMatrix( ROW_t *pMat, int nRows )
{
   for( int r = 0; r < nRows; ++r )
      printRow( pMat[r] );           // Print each row.
}
コード例 #22
0
ファイル: reader_ppm.c プロジェクト: bubuker/keggle_santa
/** prints given linear constraint information in PPM format to file stream */
static
SCIP_RETCODE printLinearCons(
   SCIP*                 scip,               /**< SCIP data structure */
   FILE*                 file,               /**< output file (or NULL for standard output) */
   SCIP_READERDATA*      readerdata,         /**< information for reader */
   SCIP_VAR**            vars,               /**< array of variables */
   SCIP_Real*            vals,               /**< array of coefficients values (or NULL if all coefficient values are 1) */
   int                   nvars,              /**< number of variables */
   int                   ncompletevars,      /**< number of variables in whole problem */
   SCIP_Bool             transformed,        /**< transformed constraint? */
   SCIP_Real*            maxcoef,            /**< maximal coefficient */
   SCIP_Bool             printbool           /**< print row or calculate maximum coefficient */
   )
{
   int v;
   SCIP_VAR** activevars;
   SCIP_Real* activevals;
   int nactivevars;
   SCIP_Real activeconstant = 0.0;

   assert( scip != NULL );
   assert( vars != NULL );
   assert( nvars > 0 );
   assert( readerdata != NULL );

   /* duplicate variable and value array */
   nactivevars = nvars;
   SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, vars, nactivevars ) );
   if( vals != NULL )
   {
      SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, vals, nactivevars ) );
   }
   else
   {
      SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) );

      for( v = 0; v < nactivevars; ++v )
         activevals[v] = 1.0;
   }

   /* retransform given variables to active variables */
   SCIP_CALL( getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, transformed) );

   if(!readerdata->rgb_relativ)
   {
      if(!printbool)
         for(v = 0; v < nactivevars; ++v)
         {
            if( REALABS(activevals[v]) > *maxcoef)
               *maxcoef = REALABS(activevals[v]);
         }
      else
      {
         assert (*maxcoef > 0);
         /* print constraint */
         printRow(scip, file, readerdata, activevars, activevals, nactivevars, ncompletevars, *maxcoef);
      }
   }
   else
   {
      /* print constraint */
      printRow(scip, file, readerdata, activevars, activevals, nactivevars, ncompletevars, *maxcoef);
   }

   /* free buffer arrays */
   SCIPfreeBufferArray(scip, &activevars);
   SCIPfreeBufferArray(scip, &activevals);

   return SCIP_OKAY;
}
コード例 #23
0
ファイル: 2052.cpp プロジェクト: Giuliao/algorithm-train
void printH(int n,int m){
  for(int i=0;i<n;i++)
    printRow(m);
}
コード例 #24
0
int main(int argc, char* argv[]){
  /*
   * Main variables
   */
  int shmfd;
  char *token;
  //void *shared_void;
  // shared segment capable of storing MAX_ROWS elements
  ssize_t shared_seg_size = (sizeof(sem_t)) + (MAX_ROWS * sizeof(host_row_t));
  
  // Struct defination
  struct addrinfo hints;
  struct addrinfo *addr_list;

  //printf("sizeof sem_t %lu\n",sizeof(sem_t));
  //Umask
  umask(0);

  //Define shm Name
  SHARED_MEM_NAME(sharedMemName);
  //fprintf(stderr,"Shared Mem Name: <%s>\n",sharedMemName);

  // Create shared Memory object
  if((shmfd = shm_open(sharedMemName,O_CREAT | O_RDWR | O_EXCL, SHARED_MEM_PERMISSIONS)) >= 0){
    //fprintf(stderr, "sharedMemName opened with O_EXCL: %s\n", strerror(errno));

    // Ftruncate space in shmfd 
    ftruncate(shmfd,shared_seg_size);
    //fprintf(stderr, "ftruncate: %s", strerror(errno));
  
    //mmap space (create space)
    shared_void = mmap(NULL, shared_seg_size, PROT_WRITE | PROT_READ, MAP_SHARED, shmfd, 0);
    //fprintf(stderr, "mmap: %s\n", strerror(errno));
    
    // Memset entire mmap space (host) to NULL if shm object doesn't exsist
    memset(shared_void,0,sizeof(shared_void));
    //fprintf(stderr, "memset host: %s\n", strerror(errno));
   
    // sem_t for entire DataBase
    globalSem = (sem_t *) shared_void;
    sem_init(globalSem, SHARE_BETWEEN_PROCESSES,NUM_RESOURCES);
    //fprintf(stderr, "globalSem init: %s\n", strerror(errno));


    // Go to Structs area in memory
    host = (host_row_t *) (shared_void + sizeof(sem_t));

    // Initialize semaphores
    for(i=0; i<=MAX_ROWS ;i++){
      sem_init(&host[i].host_lock, SHARE_BETWEEN_PROCESSES,NUM_RESOURCES);
      //fprintf(stderr, "sem_init[%d]: %s\n",i, strerror(errno));
    }
    
  }else{
    //fprintf(stderr,"shm object exsists\n");
    
    shmfd = shm_open(sharedMemName,O_RDWR, SHARED_MEM_PERMISSIONS);
    //fprintf(stderr, "sharedMemName opened no O_EXCL: %s", strerror(errno));

    //mmap space (get space) 
    shared_void = (host_row_t*)mmap(NULL, shared_seg_size, PROT_WRITE | PROT_READ, MAP_SHARED, shmfd, 0);
    //fprintf(stderr, "mmap: %s", strerror(errno));

    // sem_t for entire DataBase
    globalSem = (sem_t *) shared_void;

    // Go to Structs area in memory
    host = (host_row_t *) (shared_void + sizeof(sem_t));

  }

  while(1){
    printf("%s",PROMPT);
    fgets(input,NAME_SIZE,stdin);
    //perror("fgets");
    
    //fprintf(stderr,"User Command <%s>\n",input);
    
    // Strip newline charector from fgets 
    for(i = 0; i<= strlen(input); i++){
      if(strcmp(&input[i], "\n") == 0){
	input[i] = '\0';
      }
    }

    if(strncmp(CMD_SELECT,input,(ssize_t)6) == 0){
      strtok(input," ");
      token = strtok(NULL, " ");
      //fprintf(stderr,"In select\n");
      //fprintf(stderr,"token: %s \n",token);

      if(token == NULL){
	//fprintf(stderr,"All rows being printed\n");
	printAll(host);
      }else{
	//fprintf(stderr,"***** Finding & printing selected row(token) ******\n");
	i = search(token, host, 0);
	if(i >= 0){
	  printRow(host, i);
	}else{
	  fprintf(stdout,"There is no row named %s in database\n",token);
	}
      }
    }else if(strcmp(CMD_EXIT,input) == 0){
      printf("exit called\n");
      break;
    }else if(strncmp(CMD_INSERT,input,(ssize_t)6) == 0){
      //fprintf(stderr,"Insert Command <%s>\n",input);
      strtok(input," ");
      token = strtok(NULL, " ");
      if( token == NULL){
	printf("You must provide a hostname!\n");
      }else{
	//Memset hints
	memset(&hints, 0, sizeof(struct addrinfo));
	// memset addr_list
	memset(&addr_list, 0, sizeof(struct addrinfo));
	// Uset getInfo function to return relevant addresses
	getInfo(token,hints,addr_list,host);
	// Use insert function to insert the new row data
	if((z = insert(token, ipstr4, ipstr6, host, globalSem)) != -1){
	  //fprintf(stderr,"insert done\n");
	  memset(&ipstr6,0,sizeof(ipstr6));
	  memset(&ipstr4,0,sizeof(ipstr4));
	  printRow(host, z);
	} else{
	  //fprintf(stderr,"\ninsert function returned %d\n",z);
	}
      }
    }else if(strncmp(input,"clear",(ssize_t)5) == 0){
      printf("\e[1;1H\e[2J");
    }else if(strncmp(input,CMD_UPDATE,(ssize_t)6) == 0){
コード例 #25
0
ファイル: UniformData.cpp プロジェクト: jrco/nau
char *UniformData::UniformString(){
	ostringstream os;

	if (outputString){
		free(outputString);
	}

	os << name << "(" << program << ", " << location << ") type: " << std::hex << datatype_enum << " : " << datatypeName(datatype);
	
	if (isValueSet){

		
		if ((datasize[0] == datasize[1]) && (datasize[0] == 1)){ //Single Value
			switch(datatype){
				case CINT:
					os << " = " << ((int*) data)[0];
					break;
				case CUINT:
					os << " = " << ((unsigned int*) data)[0];
					break;
				case CFLOAT:
					os << " = " << ((float*) data)[0];
					break;
				case CBOOL:
					os << " = " << ((bool*) data)[0];
					break;
				default:
					os << " = " << std::hex << ((unsigned int*) data)[0];
					break;
			}
		}
		else if (datasize[0] == 1){ //Array
			os << " = ";
			printRow(&os, 0);
		}
		else if (datasize[0] != 0){ //Matrix
			os << " = ";
			int blanklength = os.str().length();
			char *blank = (char*) malloc (sizeof(char) * (blanklength + 1));
			for (int i = 0; i < blanklength; i++){
				blank[i] = ' ';
			}
			blank[blanklength] = 0;
			printRow(&os, 0);
			for (int i = 1; i < datasize[0]; i++)
			{
				os << '\n' << blank;
				printRow(&os, i);
			}
		}
		else{
			os << " = (not implemented yet / unknown)";
		}
	}
	else{
		os << " = (null / not set)";
	}

	outputString = strdup(os.str().c_str());
	return outputString;
}