Exemple #1
0
void printHead(char *inPtr, char *postPtr, int len)
{
	if(len <= 1){
		if(len == 1) putchar(inPtr[0]);
		return;
	}
	char head = postPtr[len - 1];
	if(head != '\r') putchar(head);
	int leftLen = 0, rightLen = 0;
	leftLen = strchr(inPtr, head) - inPtr;
	rightLen = len - leftLen - 1;
	printHead(inPtr, postPtr, leftLen);//left sub tree
	printHead(inPtr + leftLen + 1, postPtr + leftLen, rightLen);//right sub tree
}
//**************************************************************************
// Function:   printhtml
// Scope:      global
// Purpose:    prints in standard output an html
// Return:     -
//**************************************************************************
void printhtml(std::string& sDir, int iLanguage) {
   printHead(iLanguage);
   printTitle(sDir, iLanguage);
   printTitleAuthor(iLanguage);
   std::cout << "</tr>" << std::endl;

   for (int n = 0; n < vBooks.size(); n++) {
      // printing 
      std::string sNewFileName="";
      replaceName(vBooks[n].sFile, sNewFileName);
      std::cout << "<tr>" << std::endl
                << "<td>" 
                << "<A HREF=\"" << "books" << '/' << sDir << '/' << sNewFileName << "\">"
                << vBooks[n].sFileType
                << "</A>" 
                << "</td>" 
                << "<td align=" << '"' << "right" << '"' << '>';
      std::cout << vBooks[n].st_size/1024;
      std::cout << "</td>"
                << "<td>" << vBooks[n].sBook << "</td>" 
                << "<td>" << vBooks[n].sAuthors << "</td>" 
                << std::endl
                << "</tr>" << std::endl;
   }

   std::cout << "</table>" << std::endl;
   printFoot();
}
Exemple #3
0
int
printFile(char *file)
{
	if (file) {
		char buf[1024];
		FILE *fs;

		if ((fs = fopen(file, "r")) == NULL) {
			fprintf(stderr, "Cannot open %s%s%s: %s\n",
					file[0] == '/' ? "" : NEWS_PATH,
					file[0] == '/' ? "" : "/", file,
					strerror(errno));
			return 1;
		}

		printHead(file);

		if (!f_name) {
			while (fgets(buf, 1024, fs) != NULL) {
				if (buf[strlen(buf)-1] == '\n')
					printf("   ");
				printf("%s", buf);
			}
			printf("\n");
		}
		fclose(fs);
	}
	return 0;
}
Exemple #4
0
// -----------------------------------------------------------------------------
// Write a pgm file                                         
// -----------------------------------------------------------------------------
void Pgm::write(const char* fileName) {
	int n;
    char ch;

	// prevent accidental overwriting of output file
	ifstream testFile( fileName );
	if (testFile) {
		testFile.close();
		cout <<"File " <<fileName
             <<" exists. Do you want to overwrite it? [y/N]: ";
        cin >> ch;
		if (tolower(ch) != 'y') fatal("Aborted");
	}

	// Okay to continue
    ofstream pgmFile( fileName );
    if (!pgmFile) fatal("Can't open photo file '%s' for writing", fileName);
    printHead( pgmFile );
    pgmFile.close();

	/* write pixels */
	long pgmsz = height * width;
    pgmFile.open( fileName, ios_base::out | ios_base::app | ios_base::binary );
    pgmFile.write(image, pgmsz);
    if (!pgmFile.good()) fatal("Error writing pgm file '%s'", fileName);
	pgmFile.close();
}
Exemple #5
0
double SimpleSearch::find_root(double f(double x))
{
        double f0 = f(x0);
        double f_of_x = f0;

        int step = 0;
        if ( verbose ) {
                printHead("Simple Search with Step-Halving", accuracy, *os);
                printStep(step, x0, dx, f_of_x, *os);
        }

        while ( abs(dx) > accuracy && f_of_x != 0 && ++step <= max_steps ) {
                x0 += dx;                         //    take a step
                f_of_x = f(x0);
                if ( f0 * f_of_x < 0 ) {        //      jumped past root
                        x0 -= dx;                       //      backup
                        dx /= 2;                        //      halve the step size
                }
                if ( verbose )
                        printStep(step, x0, dx, f_of_x, *os);
        }

        if ( step > max_steps )
                printWarning(max_steps);
        steps = step;
        return x0;
}
Exemple #6
0
void enterProgram( uint8_t pnum )
{
	// signal midiSwitcher
	sendPC( pnum );

	// save previous program
	state.prev_pnum = loadProgramNumber();

	// load new program
	loadProgram( pnum );

	// display current bank number and first slice of bank name
	uint8_t i;
	char label[] = "                ";
	pnum = program.number+1;
	label[0] = 'B';
	label[1] = digits[pnum / 100];
	label[2] = digits[(pnum % 100) / 10];
	for (i=0; i<12; i++)
		label[i+4] = program.nameHead[i];
	printHead( label );

	// display current program number and rest of bank name
	label[0] = 'P';
	label[1] = ' ';
	label[2] = digits[pnum % 10];
	for (i=0; i<12; i++)
		label[i+4] = program.nameTail[i];
	printTail( label );
}
void WebServer::_handleRequest() {
  RequestHandler* handler;
  for (handler = _firstHandler; handler; handler = handler->next)
  {
    if (handler->method != HTTP_ANY && handler->method != _currentMethod)
      continue;

    if (handler->uri != _currentUri)
      continue;

    handler->fn();
    break;
  }

  if (!handler){
#ifdef DEBUG
    DEBUG_OUTPUT.println("request handler not found");
#endif

    if(_notFoundHandler) {
      _notFoundHandler();
    }
    else {
      printHead(404,"text/plain");
      print(String("Not found: ") + _currentUri);
      closeClient();
    }
  }

  _currentClient   = WiFiClient();
  _currentUri      = String();
}
Exemple #8
0
int main(int argc, char *argv[])
{
	char inSeq[BUFFSIZE], postSeq[BUFFSIZE];
	gets(inSeq);
	gets(postSeq);
	printHead(inSeq, postSeq, strlen(postSeq));
	return 0;
}
Exemple #9
0
double BisectionSearch::find_root(double f(double x))
{
        double f0 = f(x0);
        double f1 = f(x1);

        if ( f0 * f1 > 0 ) {
                cerr << " BisectionSearch: sorry, root not bracketed!\n"
                        << " f(" << x0 << ") = " << f0 << endl
                        << " f(" << x1 << ") = " << f1 << endl
                        << " Trying to bracket the root using bracket_root ..."
                        << flush;
                double save_x0 = x0;
                double save_x1 = x1;
                if ( bracket_root(f) ) {
                        cerr << " Bracketing succeeded !\n"
                                << " x0 = " << x0 << " x1 = " << x1
                                << " continuing ..." << endl;
                        f0 = f(x0);
                        f1 = f(x1);
                } else {
                        cerr << " Sorry, bracketing attempt failed" << endl;
                        x0 = save_x0;
                        x1 = save_x1;
                        return abs(f0) < abs(f1) ? x0 : x1;
                }
        }
        if ( f0 == 0 )
                return x0;
        if ( f1 == 0 )
                return x1;

        double xHalf, fHalf = 0.5 * (f0 + f1);
        int step = 0;
        if ( verbose ) {
                printHead("Bisection Search", accuracy, *os);
                printStep(step, x0, x1 - x0, fHalf, *os);
        }
        do {                                         //         iteration loop
                if ( ++step > max_steps )
                        break;
                xHalf = 0.5 * (x0 + x1);        //      bisection point
                fHalf = f(xHalf);
                if ( f0 * fHalf > 0 ) {  //     x0 and xHalf on same side of root
                        x0 = xHalf;             //      replace x0 by xHalf
                        f0 = fHalf;
                } else {                 //     x1 and xHalf on same side of root
                        x1 = xHalf;             //      replace x1 by xHalf
                        f1 = fHalf;
                }
                if ( verbose )
                        printStep(step, x0, x1 - x0, fHalf, *os);
        } while ( abs(x1 - x0) > accuracy && fHalf != 0);

        if ( step > max_steps )
                printWarning(max_steps);
        steps = step;
        return xHalf;
}
Exemple #10
0
void updateDisplay() {
    erase();
    initWins();

    // Get files and directories
    getEntries();
    printHead();

    printMenus();
}
Exemple #11
0
void go()
{		
	extern lua_State *L;
        extern int burnin_run;
        extern int fresh_display;	
//	if (getTableBooleanElement(L, "con", "FRT_SPLIT_DISPLAY"))
//	{
	        //fft split display
               	extern int flow_count;
        	extern char *radios[];
        	extern int ITEM_NUMBER;	
        	extern SDL_Widget *button_ensure;
        	extern int all_pass;

	clearWin();	
	burnin_run = 1;
        fresh_display = 1;
        	FR_THD_PARG *pdata;
//        	printf( "Item_number: %d\n", ITEM_NUMBER);
        	
        	pdata = (FR_THD_PARG *)malloc( ITEM_NUMBER * sizeof( FR_THD_PARG));
        	memset( pdata, 0, ITEM_NUMBER * sizeof( FR_THD_PARG));

        	char buf_s[64] = {0};
        	char buf_v[64] = {0};
        	char *station = (char *) getTableElement(L, "con", "STATION");
        	strcat( buf_s, station);
        	char *version = (char *) getTableElement(L, "con", "VERSION");
        	strcat( buf_v, version);
        	
        	printHead( buf_s, buf_v);
        	refreshWin();
        	
        	// create control thread
	        if ((threads[9] = SDL_CreateThread(go_burnin_ctl_thread, NULL)) == NULL ) {
		        fprintf(stderr, "Can't create thread: %s \n", SDL_GetError());
		        return;
                }
        	
        	int i = 0;                        	
        	int x, y;
                	
        	for( i = 0; i < ITEM_NUMBER; ++i)
        	{
        	        (pdata + i)->flow_number = i;
        	        (pdata + i)->ret_value = -1;
        	        printf( "flow: %d, size %d\n", (pdata + i)->flow_number, (pdata + i)->ret_value);
        	        
        	        if ((threads[i] = SDL_CreateThread( go_burnin_thread, (void *)(pdata+i))) == NULL){
        	                fprintf( stderr, "Can't create thread: %s \n", SDL_GetError());
        	                return;
                        }
        	}       
}
Exemple #12
0
void printBook ( Book  *b , int n)      /*输出所有图书记录的值*/
{
	int i;
    printHead();
	for (i=0;i<n;i++)
	{
		printf("%s\t ", b[i].ISBN);
		printf("%s\t ", b[i].name);
		printf("%s\t ", b[i].press);
		printf("%s\t ", b[i].author);
	    	printf("%.2lf\t ", b[i].price_out);
		printf("%.2lf\t ", b[i].price_in);
		printf("%d\t ", b[i].sale);
		printf("%d\t ", b[i].number);
	    	printf("%.2lf\n", b[i].profit);
	}
}
Exemple #13
0
//===== Display a web page with the console
int ICACHE_FLASH_ATTR
tplConsole(HttpdConnData *connData, char *token, void **arg) {
	if (token==NULL) return HTTPD_CGI_DONE;

	if (os_strcmp(token, "console") == 0) {
		if (console_wr > console_rd) {
			httpdSend(connData, console_buf+console_rd, console_wr-console_rd);
		} else if (console_rd != console_wr) {
			httpdSend(connData, console_buf+console_rd, BUF_MAX-console_rd);
			httpdSend(connData, console_buf, console_wr);
		} else {
			httpdSend(connData, "<buffer empty>", -1);
		}
	} else if (os_strcmp(token, "head")==0) {
		printHead(connData);
	} else {
		httpdSend(connData, "Unknown\n", -1);
	}
	return HTTPD_CGI_DONE;
}
Exemple #14
0
void copyProgram( void )
{
	printHead( "  copy program" );

	// print source and destination program numbers
	uint8_t pnum = program.number+1;
	char label[] = "  00.0 => 00.0";
	label[2] = digits[pnum / 100];
	label[3] = digits[(pnum % 100) / 10];
	label[5] = digits[pnum % 10];
	label[10] = digits[pnum / 100];
	label[11] = digits[(pnum % 100) / 10];
	label[13] = digits[pnum % 10];
	printTail( label );

	while ( 1 )
	{
		switch ( action() )
		{
			case CTRL_DN_ACTION:
				COUNT_DN
				break;
			case CTRL_UP_ACTION:
				COUNT_UP
				break;
			case CTRL_OK_ACTION:
				// signal switcher
				transmit_com( COPY_PROGRAM<<7 | program.number , 10 );
				return;
			default:
				continue;
		}

		// update program number
		pnum = program.number+1;
		label[10] = digits[(pnum) / 100];
		label[11] = digits[((pnum) % 100) / 10];
		label[13] = digits[(pnum) % 10];
		printTail( label );
	}
}
Exemple #15
0
double TangentSearch::find_root(double f(double x),
                                                   double f_prime(double x))
{
        double f0 = f(x0);
        double f_prime0 = f_prime(x0);

        if ( f0 == 0 )
                return x0;

        if ( f_prime0 != 0 )
                dx = - f0 / f_prime0;

        int step = 0;
        if ( verbose ) {
                printHead("Tangent Search", accuracy, *os);
                printStep(step, x0, dx, f0, *os);
        }
        do {
                if ( ++step > max_steps )
                        break;
                if ( f_prime0 == 0 ) {
                        cerr << " Tangent Search: f'(x0) = 0, algorithm fails!\n"
                                << " f(" << x0 << ") = " << f0 << endl
                                << " f'(" << x0 << ") = " << f_prime0 << endl;
                        break;
                }
                dx = - f0 / f_prime0;
                x0 += dx;
                f0 = f(x0);
                f_prime0 = f_prime(x0);
                if ( verbose )
                        printStep(step, x0, dx, f0, *os);
        } while ( abs(dx) > accuracy && f0 != 0);

        if ( step > max_steps )
                printWarning(max_steps);
        steps = step;
        return x0;
}
Exemple #16
0
double SecantSearch::find_root(double f(double x))
{
        double f0 = f(x0);
        double f1 = f(x1);

        if ( f0 == 0 )
                return x0;
        if ( f1 == 0 )
                return x1;

        int step = 0;
        if ( verbose ) {
                printHead("Secant Search", accuracy, *os);
                printStep(step, x0, x1 - x0, f1, *os);
        }
        do {
                if ( ++step > max_steps )
                        break;
                if ( f0 == f1 ) {
                        cerr << " Secant Search: f(x0) = f(x1), algorithm fails!\n"
                                << " f(" << x0 << ") = " << f0 << endl
                                << " f(" << x1 << ") = " << f1 << endl;
                        break;
                }
                dx *= - f1 / ( f1 - f0 );
                x0 = x1;
                f0 = f1;
                x1 += dx;
                f1 = f(x1);
                if ( verbose )
                        printStep(step, x0, dx, f1, *os);
        } while ( abs(dx) > accuracy && f1 != 0);

        if ( step > max_steps )
                printWarning(max_steps);
        steps = step;
        return x1;
}
Exemple #17
0
void copyBank( void )
{
	printHead( "   copy bank" );

	// print source- and destination bank numbers
	uint8_t bank = (program.number+1)/10;
	char label[15] = "  #000 => #000";
	label[4] = digits[(bank % 100) / 10];
	label[5] = digits[bank % 10];
	label[12] = digits[(bank % 100) / 10];
	label[13] = digits[bank % 10];
	printTail( label );

	while ( 1 ) // wait for input
	{
		switch ( action() )
		{
			case CTRL_DN_ACTION:
				if (bank > 0)   bank--; else bank = 11;
				break;
			case CTRL_UP_ACTION:
				if (bank < 11) bank++; else bank = 0;
				break;
			case CTRL_OK_ACTION:
				transmit_com( COPY_BANK<<7 | bank , 10 ); // signal switcher
				storeBank( bank );
				return;
			default:
				continue;
		}

		// update display
		label[12] = digits[(bank % 100) / 10];
		label[13] = digits[bank % 10];
		printTail( label );
	}
}
Exemple #18
0
string Rule::toString(){
    string str = "  " + printHead();
    return str;
}