std::ostream& operator<<(std::ostream& out, const Program& prog) { for (uint32_t i = 0; i < prog.size(); ++i) { printIndex(out, i) << prog[i] << '\n'; if (prog[i].OpCode == BIT_VECTOR_OP) { for (uint32_t j = 1; j < 9; ++j) { out << std::hex << std::setfill('0') << std::setw(8) << i + j << '\t' << *(uint32_t*)(&prog[i]+j) << '\n'; } out << std::dec; i += 8; } else if (prog[i].OpCode == JUMP_TABLE_RANGE_OP) { uint32_t start = 0, end = 255; if (prog[i].OpCode == JUMP_TABLE_RANGE_OP) { start = prog[i].Op.T2.First; end = prog[i].Op.T2.Last; } for (uint32_t j = start; j <= end; ++j) { ++i; printIndex(out, i) << std::setfill(' ') << std::setw(3) << j << ": " << reinterpret_cast<const uint32_t&>(prog[i]) << '\n'; } } else if (prog[i].OpCode == JUMP_OP || prog[i].OpCode == FORK_OP) { ++i; printIndex(out, i) << reinterpret_cast<const uint32_t&>(prog[i]) << '\n'; } } return out; }
void printObjName(__nis_index_t *index, char *name) { char *myself = "printObjName"; printIndex(index); p2buf(myself, "%s", NIL(name)); }
// write all other indexes foreach(UMLEntityAttribute* ea, entAttList) { if (ea->indexType() != UMLEntityAttribute::Index) continue; UMLEntityAttributeList tempList; tempList.append(ea); printIndex(sql, m_pEntity, tempList); tempList.clear(); }
int main(int argc, const char* argv[]) { if (argc < 4) { std::cerr << "Usage:\n" << " " << argv[0] << " <dbFilename> <indexFilename> [<options>] <sourceFilename>\n"; return 1; } const char* dbFilename = argv[1]; const char* indexFilename = argv[2]; const char* sourceFilename = argv[argc-1]; // Set up the clang translation unit CXIndex cxindex = clang_createIndex(0, 0); CXTranslationUnit tu = clang_parseTranslationUnit( cxindex, 0, argv + 3, argc - 3, // Skip over dbFilename and indexFilename 0, 0, CXTranslationUnit_None); // Print any errors or warnings int n = clang_getNumDiagnostics(tu); if (n > 0) { int nErrors = 0; for (unsigned i = 0; i != n; ++i) { CXDiagnostic diag = clang_getDiagnostic(tu, i); CXString string = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions()); fprintf(stderr, "%s\n", clang_getCString(string)); if (clang_getDiagnosticSeverity(diag) == CXDiagnostic_Error || clang_getDiagnosticSeverity(diag) == CXDiagnostic_Fatal) nErrors++; } } // Create the index EverythingIndexer visitor(sourceFilename); clang_visitChildren( clang_getTranslationUnitCursor(tu), &visitorFunction, &visitor); ClicIndex& index = visitor.usrToReferences; // OK, now write the index to a compressed file std::ofstream fout(indexFilename); boost::iostreams::filtering_stream<boost::iostreams::output> zout; zout.push(boost::iostreams::gzip_compressor()); zout.push(fout); printIndex(zout, index); // Now open the database and add the index to it ClicDb db(dbFilename); BOOST_FOREACH(const ClicIndex::value_type& it, index) { const std::string& usr = it.first; db.addMultiple(usr, it.second); } return 0; }
void ProgramData::restoreDefault() { pgm::read(currentProgramData.battery, &defaultProgram[Lipo]); currentProgramData.check(); for(int i=0;i< MAX_PROGRAMS;i++) { uint8_t maxSize = PROGRAM_DATA_MAX_NAME; char *buf = currentProgramData.name; printIndex(buf, maxSize, i+1); saveProgramData(i); } }
void webMain(struct sqlConnection *conn, struct trackDb *tdb) /* Set up fancy web page with hotlinks bar and * sections. */ { struct section *sectionList = NULL; printDescription(curGeneId, conn, tdb); sectionList = loadSectionList(conn); printIndex(sectionList); printUpdateTime(database, tdb, NULL); printSections(sectionList, conn, curGeneId); printTiming(sectionList); }
void ProgramData::createName(int index) { char *buf = name; uint8_t maxSize = PROGRAM_DATA_MAX_NAME; const char * type = pgm::read(&batteryString[battery.type]); printIndex(buf,maxSize, index); print_P (buf, maxSize, type); printChar(buf, maxSize, ' '); printUInt(buf, maxSize, battery.C); printChar(buf, maxSize, '/'); printUInt(buf, maxSize, battery.cells); }
int main(void) { uint16_t dat_p; ADC_init(); _delay_ms ( 100 ); //DDRB |= (1<<PB0); initTimer(); //initialize the hardware driver for the enc28j60 enc28j60Init(mymac); enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz _delay_loop_1(0); // 60us enc28j60PhyWrite(PHLCON,0x476); //init the ethernet/ip layer: init_udp_or_www_server(mymac,myip); www_server_port(MYWWWPORT); while(1) { // read packet, handle ping and wait for a tcp packet: dat_p=packetloop_arp_icmp_tcp(buf,enc28j60PacketReceive(BUFFER_SIZE, buf)); // dat_p will be unequal to zero if there is a valid http get if(dat_p==0) { // no http request continue; } // tcp port 80 begin if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0) { // head, post and other methods: dat_p=http200ok(); dat_p=fill_tcp_data_p(buf,dat_p,PSTR("<h1>200 OK</h1>")); www_server_reply(buf,dat_p); continue; } // just one web page in the "root directory" of the web server if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0) { //dat_p=print_webpage(buf); dat_p=printIndex(buf); www_server_reply(buf,dat_p); } else if (strncmp("/now.htm", (char *)&(buf[dat_p+4]),8) == 0 ) { dat_p = printNowHTML ( buf ); www_server_reply( buf, dat_p ); } else if (strncmp("/min0.htm", (char *)&(buf[dat_p+4]),9) == 0 ) { dat_p = printMinHTML ( buf, 0 ); www_server_reply( buf, dat_p ); } else if (strncmp("/min1.htm", (char *)&(buf[dat_p+4]),9) == 0 ) { dat_p = printMinHTML ( buf, 1 ); www_server_reply( buf, dat_p ); } else if (strncmp("/wlcm.htm", (char *)&(buf[dat_p+4]),9) == 0 ) { dat_p = printWelcomeHTML ( buf ); www_server_reply( buf, dat_p ); } else { dat_p=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>")); www_server_reply(buf,dat_p); } } return (0); }
void ProgramData::resetName(int index) { uint8_t maxSize = PROGRAM_DATA_MAX_NAME; char *buf = name; printIndex(buf, maxSize, index); }
// Main function int main( void ) { char command[MAXLENGTH]; char c; /******************************************************************** * YOU WILL NEED TO COMPLETE THE FOLLOWING SECTION FOR STAGES 2 - 5 * *******************************************************************/ printPrompt(); while( fgets( command, MAXLENGTH, stdin ) != NULL ) { int imgNum; char *p; if(( p=strrchr( command, '\n')) != NULL ) { *p = '\0'; // remove '\n' at end of line } // find the first non-space character in the command p = command; while(isspace(*p)) { p++; } c = tolower(*p); if( isdigit(c)) // Command k { if( sscanf( command, "%d", &imgNum ) == 1 ) { //Checks to see if there's images in the album. if(first != NULL) { //Retrieves the image. found = getCurrentImage(first); found2 = selectImage(found, imgNum); //Checks to see if the requested image exist in the album. if(found2 != NULL) { found->current = FALSE; found2->current = TRUE; printNodeInfos(found2); last_action = 'k'; location = found->index; //Index of the previous image found = NULL; found2 = NULL; } } } } else switch( c ) { case 'h': // help printf(" A - Add image\n" ); printf(" I - Index\n" ); printf(" P - Print image\n" ); printf(" F - Forward\n" ); printf(" B - Back\n" ); printf("<k>- make image number k the current image\n"); printf(" D - Delete image\n" ); printf(" L - Look for image\n" ); printf(" R - Rotate image counterclockwise\n" ); printf(" M - Mirror image (reflect vertically)\n" ); printf("NE - zoom into North East corner\n" ); printf("NW - zoom into North West corner\n" ); printf("SW - zoom into South West corner\n" ); printf("SE - zoom into South East corner\n" ); printf(" O - zoom Out\n" ); printf(" U - Undo\n" ); printf(" H - Help\n" ); printf(" Q - Quit\n" ); break; // INSERT CODE FOR OTHER COMMANDS case 'a': p++; //Moves cursor away from 'a' while(isspace(*p)) { p++; } int *dim; QTnode* qt = getImage(p, dim); if(qt != NULL) { insertNode(qt, dim, p); printNodeInfos(getCurrentImage(first)); //Whenever a node is added, it becomes the selected node } last_action = 'a'; break; case 'i': if(first != NULL) { printIndex(first); } break; case 'p': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { printImage(currentImage->image, currentImage->size); } break; } case 'f': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->next != NULL)) { currentImage->current = FALSE; currentImage = currentImage->next; currentImage->current = TRUE; printNodeInfos(currentImage); last_action = 'f'; } break; } case 'b': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->previous != NULL)) { currentImage->current = FALSE; currentImage = currentImage->previous; currentImage->current = TRUE; printNodeInfos(currentImage); last_action = 'b'; } break; } //'K' command is treated in the upper portion of the code case 'd': removeNode(); if(first != NULL) { printNodeInfos(getCurrentImage(first)); } last_action = 'd'; break; case 'l': if(first != NULL) { p++; //Moves cursor away from 'a' while(isspace(*p)) { p++; } ListNode* foundImage = findBySubString(first, p); //Image with the substring was found if(foundImage != NULL) { ListNode* currentImage = getCurrentImage(first); currentImage->current = FALSE; foundImage->current = TRUE; printNodeInfos(getCurrentImage(first)); last_action = 'l'; location = currentImage->index; } } break; case 'r': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { rotateImage(currentImage->image); printImage(currentImage->image, currentImage->size); } last_action = 'r'; break; } case 'm': { ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { mirrorImage(currentImage->image); printImage(currentImage->image, currentImage->size); } last_action = 'm'; break; } case 'n': { ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL) { break; } //This line gets the next character of the command, so it can be //treated accordingly. char c2 = *(++p); //Dereferencing the pointer and moving it to the next char of the string if(c2 == 'e') { if(currentImage->image->ne == NULL) { break; } currentImage->image = currentImage->image->ne; printImage(currentImage->image, currentImage->size); last_action = 'w'; //because "ne" does not work, find a letter that is not used location = 'w'; } else if(c2 == 'w') { if(currentImage->image->nw == NULL) { break; } currentImage->image = currentImage->image->nw; printImage(currentImage->image, currentImage->size); last_action = 'x'; location = 'x'; } break; } case 's': { ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL) { break; } //This line gets the next character of the command, so it can be //treated accordingly. char c2 = *(++p); //Dereferencing the pointer and moving it to the next char of the string if(c2 == 'e') { if(currentImage->image->se == NULL) { break; } currentImage->image = currentImage->image->se; printImage(currentImage->image, currentImage->size); last_action = 'y'; location = 'y'; } else if(c2 == 'w') { if(currentImage->image->sw == NULL) { break; } currentImage->image = currentImage->image->sw; printImage(currentImage->image, currentImage->size); last_action = 'z'; location = 'z'; } break; } case 'o': { ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL || (currentImage->image->out == NULL)) { break; } currentImage->image = currentImage->image->out; printImage(currentImage->image, currentImage->size); last_action = 'o'; break; } case 'u': if(last_action == 'm'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { mirrorImage(currentImage->image); printImage(currentImage->image, currentImage->size); } break; } else if(last_action == 'r'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL) { rotateImage(currentImage->image); rotateImage(currentImage->image); rotateImage(currentImage->image); printImage(currentImage->image, currentImage->size); break; } } else if(last_action == 'a'){ removeNode(); if(first != NULL) { printNodeInfos(getCurrentImage(first)); } break; } else if(last_action == 'd'){ //todo me no smart break; } else if(last_action == 'w' || (last_action == 'x') || (last_action == 'y') || (last_action == 'z')){ ListNode* currentImage = getCurrentImage(first); if(currentImage == NULL || (currentImage->image->out == NULL)) { break; } currentImage->image = currentImage->image->out; printImage(currentImage->image, currentImage->size); break; } else if(last_action == 'o'){ ListNode* currentImage = getCurrentImage(first); if(location == 'w') { if(currentImage->image->ne == NULL) { break; } currentImage->image = currentImage->image->ne; printImage(currentImage->image, currentImage->size); break; } else if(location == 'x') { if(currentImage->image->nw == NULL) { break; } currentImage->image = currentImage->image->nw; printImage(currentImage->image, currentImage->size); break; } else if(location == 'y') { if(currentImage->image->se == NULL) { break; } currentImage->image = currentImage->image->se; printImage(currentImage->image, currentImage->size); break; } else if(location == 'z') { if(currentImage->image->sw == NULL) { break; } currentImage->image = currentImage->image->sw; printImage(currentImage->image, currentImage->size); break; } } else if(last_action == 'b'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->next != NULL)) { currentImage->current = FALSE; currentImage = currentImage->next; currentImage->current = TRUE; printNodeInfos(currentImage); } break; } else if(last_action == 'f'){ ListNode* currentImage = getCurrentImage(first); if(currentImage != NULL && (currentImage->previous != NULL)) { currentImage->current = FALSE; currentImage = currentImage->previous; currentImage->current = TRUE; printNodeInfos(currentImage); } break; } else if(last_action == 'k' || (last_action == 'l')){ //Retrieves the image. found = getCurrentImage(first); found2 = selectImage(found, location); //Checks to see if the requested image exist in the album. if(found2 != NULL) { found->current = FALSE; found2->current = TRUE; printNodeInfos(found2); found = NULL; found2 = NULL; } break; } case 'q': // quit program printf("Bye!\n"); return 0; break; default: printf("Unrecognized command: %s\n", command ); break; } printPrompt(); } return 0; }
int main(int argc, char *argv[]) { int in; struct stat sb; uint8 *buf; index_header *h; struct options opts; char outnbuf[512]; parse_arguments(argc, argv, &opts); in = open(opts.infile, O_RDONLY); if (in == -1) { fprintf(stderr, "Error: Could not open file %s: %s\n", opts.infile, strerror(errno)); return EXIT_FAILURE; } if (fstat(in, &sb) == -1) { perror("stat() failed"); return EXIT_FAILURE; } buf = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, in, 0); if (buf == MAP_FAILED) { perror("mmap() failed"); return EXIT_FAILURE; } close(in); if (opts.sound && !opts.outfile) { char *pdot = strrchr(opts.infile, '.'); opts.outfile = outnbuf; strcpy(outnbuf, opts.infile); if (pdot) outnbuf[pdot - opts.infile] = 0; } h = readIndex(buf); if (opts.print) printIndex(h, buf, stdout); if (opts.list) { listEntries(h, buf, stdout); } if (opts.sound && opts.outfile) { writeSoundEntries(h, buf, opts.outfile); } else if (opts.outfile) { FILE *out; out = fopen(opts.outfile, "wb+"); if (out == NULL) { fprintf(stderr, "Could not open output file '%s': %s\n", opts.outfile, strerror(errno)); exit(EXIT_FAILURE); } writeEntries(h, buf, out); fclose(out); } // freeIndex(h); munmap(buf, sb.st_size); return EXIT_SUCCESS; }