//Print all Word in Word tree void printWord(Word* root) { if (root->left != NULL) { printWord(root->left); } printf("%s\n", root->tweet); if (root->right != NULL) { printWord(root->right); } }
void USARTPrint(){ //USART code for debugging purposes// printString("Piezo Value: "); printWord(piezoValue); printString(" Pot Value: "); printWord(potValue); printString(" Middle Value: "); printWord(middleValue); printString("\r\n"); }
void printData_Progmem(const uint16_t * dataPointer, uint8_t length) { while (length) { printWord((uint16_t) dataPointer); /* print out address */ printString(": "); printWord(pgm_read_word(dataPointer)); /* print out data */ printString("\r\n"); dataPointer++; /* move to next byte */ length--; /* one less byte to go */ _delay_ms(100); } }
void main () { dsco_led_init(); spi_init(FALSE); //no hardware chip select usart_init(); //initialise chip select on PD0 ( Open Drain not work for this module ) GPIOD->MODER |= GPIO_MODER_MODER0_0 ;SPI_CS_HIGH uint8_t response, i; GPIOD->ODR ^= DISCOF4_LED_GREEN; //Lights on green LED uint8_t inReset = 1; spi_write_auto(0x6B,0x80); printString("Reset command sent\r\n"); i = 0; while ( inReset ) { i++; response = spi_read_auto( 0x6B ); inReset = response & 0x80; if ( i > 500 ) { printString("Reset Error, Response: "); printWord(response); printString("\r\n"); i = 0; } } response = spi_read_auto( 0x6B ); printString("Module resets, Power MGT: ");printWord(response);printString("\r\n"); response = spi_read_auto( 0x75 ); printString("ID: ");printWord(response);printString("\r\n"); uint8_t gyro_xl, gyro_xh, gyro_yl, gyro_yh, gyro_zl, gyro_zh; uint8_t accel_xl, accel_xh, accel_yl, accel_yh, accel_zl, accel_zh; while (TRUE) { gyro_xh = spi_read_auto( 67 ) ; gyro_xl = spi_read_auto( 68 ) ; gyro_yh = spi_read_auto( 69 ) ; gyro_yl = spi_read_auto( 70 ) ; gyro_zh = spi_read_auto( 71 ) ; gyro_zl = spi_read_auto( 72 ) ; printString("Gyro : {");printWord((gyro_xh << 8) + gyro_xl); printString(", ");printWord((gyro_yh << 8) + gyro_yl); printString(", ");printWord((gyro_zh << 8) + gyro_zl); accel_xh = spi_read_auto( 59 ) ; accel_xl = spi_read_auto( 60 ) ; accel_yh = spi_read_auto( 61 ) ; accel_yl = spi_read_auto( 62 ) ; accel_zh = spi_read_auto( 63 ) ; accel_zl = spi_read_auto( 64 ) ; printString("} Accel : {");printWord((accel_xh << 8) + accel_xl); printString(", ");printWord((accel_yh << 8) + accel_yl); printString(", ");printWord((accel_zh << 8) + accel_zl);printString("}\r"); ms_delay(20); } }
void sensor_printvalues(uint16_t* values) { printString("C: "); printWord(values[0]); printString(" "); printString("R: "); printWord(values[1]); printString(" "); printString("G: "); printWord(values[2]); printString(" "); printString("B: "); printWord(values[3]); printString("\n"); }
int main(void) { initUSART(); char ramString[STRING_LEN]; uint8_t counter; while (1) { printString("\r\n------------------\r\n"); eeprom_read_block(ramString, eepromString, STRING_LEN); printString(ramString); printString("\r\nThe counter reads: "); counter = eeprom_read_byte(&eepromCounter); printByte(counter); printString("\r\nMy uint16_t value is: "); printWord(eeprom_read_word(&eepromWord)); printString("\r\n Enter a new introduction string below:\r\n"); readString(ramString, STRING_LEN); eeprom_update_block(ramString, eepromString, STRING_LEN); counter++; eeprom_update_byte(&eepromCounter, counter); } return (0); }
int main(void) { char myString[STRING_MAXLEN]; char *eepromAddress = (char *) STRING_ADDRESS; uint16_t counter; initUSART(); while (1) { // Read from EEPROM and print out eeprom_read_block(myString, eepromAddress, STRING_MAXLEN); counter = eeprom_read_word((uint16_t *) COUNTER_ADDRESS); printString("\r\nYour old favorite color is: "); printString(myString); // Take input, store in EEPROM printString("\r\n\r\n Type your new favorite color. "); readString(myString, sizeof(myString)); /* pass by address, function will change its values */ eeprom_update_block(myString, eepromAddress, STRING_MAXLEN); counter++; printString("Thanks! \r\nYou've answered the same question "); printWord(counter); printString(" times. \r\n"); eeprom_update_word((uint16_t *) COUNTER_ADDRESS, counter); } return 0; }
int main(void) { // -------- Inits --------- // clock_prescale_set(clock_div_1); /* full speed */ initUSART(); printString("==[ Cap Sensor ]==\r\n\r\n"); LED_DDR = 0xff; MCUCR |= (1 << PUD); /* disable all pullups */ CAP_SENSOR_PORT |= (1 << CAP_SENSOR); /* we can leave output high */ initPinChangeInterrupt(); // ------ Event loop ------ // while (1) { chargeCycleCount = 0; /* reset counter */ CAP_SENSOR_DDR |= (1 << CAP_SENSOR); /* start with cap charged */ sei(); /* start up interrupts, counting */ _delay_ms(SENSE_TIME); cli(); /* done */ if (chargeCycleCount < THRESHOLD) { LED_PORT = 0xff; } else { LED_PORT = 0; } printWord(chargeCycleCount); /* for fine tuning */ printString("\r\n"); } /* End event loop */ return (0); /* This line is never reached */ }
void printAll(int argc, char **argv){ int iline; for(iline = 0; iline != SYMBOL_HEIGHT; ++iline) { printWord(iline ,argc , argv); putsi("\n"); } }
/** * @brief printSentence * @param sentence */ void printSentence(int wordcount, char** sentence) { for(int idx = 0; idx < wordcount; ++idx) { printWord(sentence[idx]); usleep(WORD_PAUSE); } }
int testInsertBST(BST *tree, int isVerbose) { printf("TESTCASE: INSERTION\n"); // Print the tree if (isVerbose == TRUE) { printf("PRE-INSERTION - TREE OVERVIEW\n"); inOrderPrintBST(tree); } // Create test word WORD *insertionTestWord = newWord(TEST_WORD, newWordLocation(1, 1, 1)); if (isVerbose == TRUE) { printf("INSERTION - TEST WORD\n"); printWord(insertionTestWord, 15, maxPageDigit, maxLineDigit); } // Run the insert function insertBST(tree, insertionTestWord); // Print the tree if (isVerbose == TRUE) { printf("POST-INSERTION - TREE OVERVIEW\n"); inOrderPrintBST(tree); } if (searchBST(tree, TEST_WORD) != NULL) { return SUCCESS; } return FAILED; }
/** * The main function of strings.c * Calls getWord repeatidly, stores the words, calls sortWords(), exits. */ int main(int argc, char* argv[]){ char str_list[MAX_STR_COUNT][MAX_STR_LENGTH + 1]; int i = 0; int word_index = 0; int getWordResult = 0; /* * Call getWord repeatidly, retreving every word from stdin * If EOF_BEFORE_WORD is returned, don't count the whitespace read in and break * If EOF_AFTER_WORD is returned, count the word and break */ for(word_index = 0; word_index < MAX_STR_COUNT; word_index++){ getWordResult = getWord(str_list[word_index], MAX_STR_LENGTH); if(getWordResult == EOF_BEFORE_WORD){ word_index--; break; } if(getWordResult == EOF_AFTER_WORD){ break; } } // Output the current word array (unsorted) printf("Inputted Words (unsorted):\n"); for(i = 0; i < word_index + 1; i++){ printWord(str_list[i], strlen(str_list[i])); } printf("\n"); // Sort the array of parsed words sortWords(str_list, word_index + 1); // Output the array of sorted words printf("Inputted Words (sorted):\n"); for(i = 0; i < word_index + 1; i++){ printWord(str_list[i], strlen(str_list[i])); } printf("\n"); return EXIT_SUCCESS; }
int main(void) { initUSART(); char oneLetter; uint8_t i; while (1) { for (i = 0; i < sizeof(myVeryLongString); i++) { oneLetter = pgm_read_byte(&(myVeryLongString[i])); transmitByte(oneLetter); _delay_ms(100); /* slow it down to simulate typing effect :) */ } _delay_ms(1000); printWord(&sixteenBits); /* this throws a compiler warning... */ transmitByte('\r'); transmitByte('\n'); printWord(pgm_read_word(&sixteenBits)); } /* End event loop */ return 0; /* This line is never reached */ }
/* * This method performs encrypt operation given plaintext. * It read tables from tf and plaintext from fp. * Encrypts plainetxt using key */ void ProcessEncrypt(char *key, FILE *tf, FILE *fp) { table_check = 0; ProcessTableCheck(tf); char buf[16]; int ret = fread(buf, 1, 16, fp); if (ret < 16) { fprintf(stderr, "Input size for encryption can not be less than 16 bytes\n"); exit(1); } int i, Nr = 10, Nb = 4, round; unsigned char **state = (unsigned char **) malloc( sizeof(unsigned char *) * 4); for (i = 0; i < 4; i++) state[i] = (unsigned char *) malloc(sizeof(unsigned char) * 4); copyInStateArray(state, buf); unsigned char **word = doProcessKeyExpand(key); printOut(state, "input", 0); AddRoundKey(state, word, 0); printWord(word, "k_sch", 0, 0); for (round = 1; round < Nr; round++) { printOut(state, "start", round); SubBytes(state); printOut(state, "s_box", round); ShiftRows(state); printOut(state, "s_row", round); MixColumns(state, P); printOut(state, "m_col", round); AddRoundKey(state, word, round * Nb); printWord(word, "k_sch", round * Nb, round); } printOut(state, "start", round); SubBytes(state); printOut(state, "s_box", round); ShiftRows(state); printOut(state, "s_row", round); AddRoundKey(state, word, Nr * Nb); printWord(word, "k_sch", Nr * Nb, round); printOut(state, "output", round); }
void print_debug(RHTresult *result) { #if DEBUG printString("Bits:\r\n"); for(int i = 0; i < 43; i++) { printByte(i); printString(": "); printByte(tries_b[i]); printString("\r\n"); } printString("\r\n\r\n"); printString("Temperature: "); printWord(result->temperature); printString("\r\n"); printString("Humidity: "); printWord(result->humidity); printString("\r\n"); printString("Checksum: "); printByte(result->checksum); printString("\r\n\r\n"); #endif }
bool isPalindrome(char word[], int length) { printWord(word, length); if (length == 0 || length == 1) { return true; } else { if (firstChar(word) != lastChar(word, length)) { return false; } else { return isPalindrome(middle(word), length - 2); } } }
int testSearchBST(BST *tree, char** validWords, char** invalidWords, int isVerbose) { printf("\nTESTCASE: SEARCH\n"); // Search for valid words printf("Search - Valid Words\n"); // Start - Long Way char *searchWord = validWords[3]; WORD *w = searchBST(tree, searchWord); printWord(w, FRAME_SIZE, maxPageDigit, maxLineDigit); // End - Long way printWord(searchBST(tree, "mnm"), FRAME_SIZE, maxPageDigit, maxLineDigit); // Using String Literal printWord(searchBST(tree, validWords[6]), FRAME_SIZE, maxPageDigit, maxLineDigit); // Using Short Array Access -> char* printWord(searchBST(tree, validWords[9]), FRAME_SIZE, maxPageDigit, maxLineDigit); printf("\nSearch - Invalid Words\n"); for (int i = 0; i < 5; i++) { // Print Word if invalid word is in the BST, else, print message that word is not in the BST if ( (w = searchBST(tree, invalidWords[i])) != NULL) printWord(w, FRAME_SIZE, maxPageDigit, maxLineDigit); else printf("Cannot find '%s' in the Search Tree!\n", invalidWords[i]); } return SUCCESS; }
int parseWordIntoIdDebug(twcsa *wcsa, byte *aWord, uint len) { register uint min,max,p; unsigned char *vocword; uint vocwordlen; fprintf(stderr,"\n call to parseWordIntoIdDebug"); fprintf(stderr,"\n wordsize = %u",len); fprintf(stderr,"\n word = "); printWord(aWord,len); fprintf(stderr,"\n"); min = 0; max = (wcsa->nwords) - 1; while(min < max) { p = (min+max)/2; getWord(wcsa,p,&vocword,&vocwordlen); if(wtstrcompL(aWord, vocword, len, vocwordlen) >0 ) min = p+1; else max = p; } fprintf(stderr,"\n pos found = %u, max was %u",min,(wcsa->nwords) - 1); //getQgram(wcsa,min,qgram,len); getWord(wcsa,min,&vocword,&vocwordlen); fprintf(stderr,"\n Must compare (len = %u) ",len); printWord(aWord,len); fprintf(stderr,"\n with (len=%u) ",vocwordlen); printWord(aWord,len); if(!wtstrcompL(aWord, vocword, len, vocwordlen)) { return min; } else { //!SO NO WORD IS FOUND !! return -1; } }
int main(void) { initUSART(); const char *stringPointer; const uint16_t *wordPointer; uint8_t i; char oneLetter; stringPointer = &myVeryLongString[0]; /* address of first char */ // stringPointer = myVeryLongString; /* same as above */ wordPointer = &sixteenBits; /* address of first byte */ while (1) { for (i = 0; i < sizeof(myVeryLongString); i++) { oneLetter = pgm_read_byte(stringPointer + i); transmitByte(oneLetter); _delay_ms(100); /* slow it down to simulate typing effect :) */ } _delay_ms(1000); printWord(pgm_read_word(wordPointer)); } /* End event loop */ return 0; /* This line is never reached */ }
void drawBoard() { char word_custo[7] = "Custo:"; char word_premio[8] = "Premio:"; char word_energia[9] = "Energia:"; char custo_valor[30]; char premio_valor[30]; float step_x = 2.0/dim_x; float step_y = 2.0/dim_y; float x; float y; for(int ix=0; ix<dim_x; ix++) { for(int iy=0; iy<dim_y; iy++) { x = step_x * ix - 1; y = 1-(step_y * iy); if(casa_percorrida[ix][iy]) { glColor3f(0.3,0.3,0.5); glBegin(GL_QUADS); glVertex2d(x,y); glVertex2d(x+step_x,y); glVertex2d(x+step_x,y-step_y); glVertex2d(x,y-step_y); glEnd(); } glColor3f(1.0,1.0,1.0); glBegin(GL_LINE_STRIP); glVertex2d(x,y); glVertex2d(x+step_x,y); glVertex2d(x+step_x,y-step_y); glVertex2d(x,y-step_y); glEnd(); glColor3f(1.0f, 1.0f, 1.0f); printWord(x+0.01,y-0.05,word_custo); sprintf(custo_valor, "%d", cost[ix][iy]); glColor3f(1.0f, 0.0f, 0.0f); printWord(x+0.01,y-0.10,custo_valor); glColor3f(1.0f, 1.0f, 1.0f); printWord(x+0.01,y-0.15,word_premio); sprintf(premio_valor, "%d", prize[ix][iy]); glColor3f(0.0f, 1.0f, 0.0f); printWord(x+0.01,y-0.20,premio_valor); } } x = step_x * king_x - 1; y = 1-(step_y * king_y); float x_mid = x+step_x/2.0; float y_mid = y-step_y/2.0; glColor3f(0.0,0.0,1.0); glBegin(GL_TRIANGLES); glVertex2d(x_mid+0.2,y_mid+0.2); glVertex2d(x_mid+0.2,y_mid-0.2); glVertex2d(x_mid,y_mid); glEnd(); glBegin(GL_QUADS); glVertex2d(x_mid+0.2,y_mid-0.15); glVertex2d(x_mid+0.2,y_mid+0.15); glVertex2d(x_mid+0.4,y_mid+0.15); glVertex2d(x_mid+0.4,y_mid-0.15); glEnd(); glColor3f(1.0f, 1.0f, 1.0f); printWord(x_mid+0.12,y_mid+0.06,word_energia); sprintf(custo_valor, "%d", king_energy); glColor3f(0.0f, 1.0f, 0.0f); printWord(x_mid+0.12,y_mid+0.01,custo_valor); glColor3f(1.0f, 1.0f, 1.0f); printWord(x_mid+0.12,y_mid-0.04,word_premio); sprintf(premio_valor, "%d", king_prize); glColor3f(0.0f, 1.0f, 0.0f); printWord(x_mid+0.12,y_mid-0.09,premio_valor); }
/** *********************************************************************************** CONSTRUCTION OF THE INDEX, from a given text file "inbasename". ***********************************************************************************/ int build_WordIndex (char *inbasename, char *build_options, void **index){ twcsa *wcsa; wcsa = (twcsa *) malloc (sizeof (twcsa) * 1); *index = wcsa; wcsa->text = NULL; double t0, t1; t0 = getSYSTimeBF(); //char path2repaircompressor[1000]="./src/repair64bit/repairCompressor"; //wcsa->blockSize = DEFAULT_BLOCK_SIZE; //wcsa->q = DEFAULT_QGRAM_LEN; /** processing the parameters of the index:: blockSize, and q-gram-len (q) */ { char delimiters[] = " =;"; int j,num_parameters; char ** parameters; if (build_options != NULL) { parse_parameters_II(build_options,&num_parameters, ¶meters, delimiters); for (j=0; j<num_parameters;j++) { if ((strcmp(parameters[j], "blocksize") == 0 ) && (j < num_parameters-1) ) { //wcsa->blockSize = atoi(parameters[j+1]) * BLOCK_MULTIPLIER; j++; } else if ((strcmp(parameters[j], "qgram") == 0 ) && (j < num_parameters-1) ) { //wcsa->q =atoi(parameters[j+1]); j++; } else if ((strcmp(parameters[j], "path2repaircompressor") == 0 ) && (j < num_parameters-1) ) { //strcpy(path2repaircompressor,parameters[j+1]); j++; } } free_parameters_II(num_parameters, ¶meters); } //fprintf(stderr,"\n Parameters of II-blocks:: *basename = %s, blocksize = %d, q= %d",inbasename,wcsa->blockSize,wcsa->q); //fprintf(stderr,"\n \t path2repaircompressor= %s\n",path2repaircompressor); } /** 0 ** Inicializes the arrays used to detect if a char is valid or not. **/ StartValid(); /** 1 ** Loads the compressed text into memory. */ t1 = getSYSTimeBF(); fprintf(stderr,"\n... Entering LoadTextInmem:%s\n",inbasename); loadTextInMem(&(wcsa->text), &(wcsa->sourceTextSize),(char *)inbasename); fprintf(stderr,"... Loaded Source Sequence: %lu bytes\n", wcsa->sourceTextSize); fprintf(stderr,"... Done: %2.2f seconds (sys+usr time)\n\n", getSYSTimeBF() -t1); fflush(stderr); /** 2 ** loads the array of document boundaries */ uint ndocs; ulong *docboundaries; loadDocBeginngins(&docboundaries, &ndocs,(char *)inbasename); wcsa->ndocs = ndocs; //just for statistics. /** 3 ** Parses the sequence and gathers the vocabulary of words (sorted alphanumerically) the frecuency of such words: obtains "words", "nwords", and "wordsZone" Sets also wcsa->freqs (freq of each word) Sets also wcsa->maxNumOccs (needed for malloc during extraction) */ fprintf(stderr,"\n... Entering CreateVocabularyOfWords (1st pass) \n"); fflush(stderr); CreateVocabularyOfWords(*index, docboundaries, ndocs); //shows the words parsed... { int i; fprintf(stderr,"\n\n Despues de sorting ...."); fflush(stderr); unsigned char *str; uint len; // for (i = 0; i<100; i++) { for (i = 0; ((uint)i)<wcsa->nwords; i++) { if ((i<10) || (((uint)i) >wcsa->nwords-5)) { getWord(wcsa,i,&str,&len); fprintf(stderr,"\n freq[%6d]=%6u ",i, wcsa->freqs[i]); fprintf(stderr,", words[%6d] = ",i); printWord(str,len); } } } t1 = getSYSTimeBF(); fprintf(stderr,"\n %u words have been parsed", wcsa->nwords); fprintf(stderr,"\n... Done: %2.2f seconds (sys+usr time)\n", getSYSTimeBF() -t1); /** 4 ** creates a temporal list of occurrences of each word (block-oriented). gives also the len of each list */ { //decompression of the source text and creation of occList[][] and lenList[] uint **occList; uint *lenList; t1 = getSYSTimeBF(); fprintf(stderr,"\n... Entering createListsOfOccurrences (2nd pass) \n"); fflush(stderr); createListsOfOccurrences (*index, &occList, &lenList, docboundaries, ndocs); fprintf(stderr,"\n %u lists of occurrences were created.", wcsa->nwords);fflush(stderr); fprintf(stderr,"\n... Done: %2.2f seconds (sys+usr time)\n", getSYSTimeBF() -t1); #ifdef CIKM2011_HURRY free(wcsa->text); wcsa->text = NULL; #endif //Preparing a "list of occurrences" that will be later indexed through build_il() ** uint *source_il, sourcelen_il; uint maxPost = ndocs; uint nwords = wcsa->nwords; ulong source_il_ulong; t1 = getSYSTimeBF(); fprintf(stderr,"\n... Entering prepareSourceFormatForIListBuilder \n"); fflush(stderr); prepareSourceFormatForIListBuilder(nwords,maxPost,lenList, occList, &source_il, &source_il_ulong); /** FOR CIKM ILISTS_DO NOT STILL SUPPORT an ULONG HERE **/ sourcelen_il = (uint)source_il_ulong; fprintf(stderr,"\n there are %lu uints in all the lists of occurrences: size [uint32] = %lu bytes.\n ", (ulong)sourcelen_il - nwords -2, (ulong) sizeof(uint)*(sourcelen_il - nwords -2)); /* char fileuintpostings[256] = "postingsSequence.uint32"; output_posting_lists_concatenated_DEBUGGING_ONLY (nwords, maxPost, lenList, occList,fileuintpostings); */ { char fileposts[2048]; sprintf(fileposts,"%s.%s.%u","postinglists","posts", getpid()); FILE *ff = fopen(fileposts,"w"); fwrite(source_il, sizeof(uint), sourcelen_il,ff); fclose(ff); } /* FILE *ff = fopen ("2gbnopositional.posts.uint32","w"); fwrite (source_il, sizeof(uint), sourcelen_il, ff); fclose(ff); */ fprintf(stderr,"\n the lists of occurrences were formatted for build_il.");fflush(stderr); fprintf(stderr,"\n...Done: %2.2f seconds (sys+usr time)\n", getSYSTimeBF() -t1); t1 = getSYSTimeBF(); fprintf(stderr,"\n**... entering BUILD INVERTED LIST REPRESENTATION!! \n"); fflush(stderr); //compressing the lists of occurrences and setting wcsa->ils int error = build_il(source_il, sourcelen_il, build_options, &(wcsa->ils)); //source_il is freed inside!. IFERRORIL(error); fprintf(stderr,"\n... Done: %2.2f seconds (sys+usr time)\n", getSYSTimeBF() -t1); { //frees memory for the posting lists uint i; for (i=0;i<wcsa->nwords;i++) free(occList[i]); free(occList); free(lenList); } /** 5 ** compressed representation of the source text */ { #ifdef CIKM2011_HURRY uchar text_null[109] = "NULL-TEXT"; uint text_len_null=1; uint docbounds_null[2]= {0,10}; uint ndoc_null = 1; build_representation (text_null, text_len_null, docbounds_null, ndoc_null, build_options, &wcsa->ct); #endif #ifndef CIKM2011_HURRY build_representation (wcsa->text, wcsa->sourceTextSize, docboundaries, ndocs, build_options, &wcsa->ct); #endif unsigned char *document; uint doclen; extract_doc_representation (wcsa->ct, 0, &document, &doclen); fprintf(stderr,"\n =================== DOC 0 ======================"); fprintf(stderr,"\n%s",document); fprintf(stderr,"\n =================== ***** ======================\n"); free(document); //free(docbegsUL); } } #ifndef FREQ_VECTOR_AVAILABLE //<----- not needed in advance, only during construction free(wcsa->freqs); #endif free(docboundaries); ulong sizeI; index_size(*index, &sizeI); fflush(stderr); fflush(stdout); fprintf(stderr,"\n The index has already been built: %lu bytes!!\n", sizeI); fprintf(stderr,"\n... Done: OVERALL TIME = %2.2f seconds (sys+usr time)\n\n\n", getSYSTimeBF() -t0); fflush(stderr); fflush(stdout); return 0; }
/** *********************************************************************************** CONSTRUCTION OF THE INDEX ***********************************************************************************/ int build_WordIndex (char *inbasename, char *build_options, void **index){ twcsa *wcsa; wcsa = (twcsa *) malloc (sizeof (twcsa) * 1); *index = wcsa; wcsa->text = NULL; //char path2repaircompressor[1000]="./src/repair64bit/repairCompressor"; //wcsa->blockSize = DEFAULT_BLOCK_SIZE; //wcsa->q = DEFAULT_QGRAM_LEN; /** processing the parameters of the index:: blockSize, and q-gram-len (q) */ { char delimiters[] = " =;"; int j,num_parameters; char ** parameters; if (build_options != NULL) { parse_parameters_II(build_options,&num_parameters, ¶meters, delimiters); for (j=0; j<num_parameters;j++) { if ((strcmp(parameters[j], "blocksize") == 0 ) && (j < num_parameters-1) ) { //wcsa->blockSize = atoi(parameters[j+1]) * BLOCK_MULTIPLIER; j++; } else if ((strcmp(parameters[j], "qgram") == 0 ) && (j < num_parameters-1) ) { //wcsa->q =atoi(parameters[j+1]); j++; } else if ((strcmp(parameters[j], "path2repaircompressor") == 0 ) && (j < num_parameters-1) ) { //strcpy(path2repaircompressor,parameters[j+1]); j++; } } free_parameters_II(num_parameters, ¶meters); } //fprintf(stderr,"\n Parameters of II-blocks:: *basename = %s, blocksize = %d, q= %d",inbasename,wcsa->blockSize,wcsa->q); //fprintf(stderr,"\n \t path2repaircompressor= %s\n",path2repaircompressor); } /** 0 ** Inicializes the arrays used to detect if a char is valid or not. **/ StartValid(); /** 1 ** Loads the compressed text into memory. */ loadTextInMem(&(wcsa->text), &(wcsa->textSize),(char *)inbasename); wcsa->sourceTextSize = wcsa->textSize; fprintf(stderr,"... Loaded Source Sequence: %u bytes\n", wcsa->textSize); fflush(stderr); fflush(stderr); /** 2 ** loads the array of document boundaries */ uint ndocs; uint *docboundaries; loadDocBeginngins(&docboundaries, &ndocs,(char *)inbasename); wcsa->ndocs = ndocs; //just for statistics. /** 3 ** Parses the sequence and gathers the vocabulary of words (sorted alphanumerically) the frecuency of such words: obtains "words", "nwords", and "wordsZone" Sets also wcsa->freqs (freq of each word) Sets also wcsa->maxNumOccs (needed for malloc during extraction) */ fprintf(stderr,"... Entering CreateVocabularyOfWords \n"); fflush(stderr); CreateVocabularyOfWords(*index, docboundaries, ndocs); //shows the words parsed... { int i; fprintf(stderr,"\n\n Después de sorting ...."); fflush(stderr); unsigned char *str; uint len; // for (i = 0; i<100; i++) { for (i = 0; i<wcsa->nwords; i++) { if ((i<15) || (i>wcsa->nwords-5)) { getWord(wcsa,i,&str,&len); fprintf(stderr,"\n freq[%6d]=%6u ",i, wcsa->freqs[i]); fprintf(stderr,", words[%6d] = ",i); printWord(str,len); } } } fprintf(stderr,"\n %u words have been parsed", wcsa->nwords); /** 4 ** creates a temporal list of occurrences of each word (block-oriented). gives also the len of each list */ { //decompression of the source text and creation of occList[][] and lenList[] uint **occList; uint *lenList; uint *doc_offsets_sids; createListsOfOccurrences (*index, &occList, &lenList, &doc_offsets_sids, docboundaries, ndocs); wcsa->doc_offsets_sids=doc_offsets_sids; fprintf(stderr,"\n %u lists of occurrences were created.", wcsa->nwords);fflush(stderr); //fprintf(stderr,"\n The ranks of the document beginnings are:"); //{ // int i; // for (i=0;i<=ndocs;i++) fprintf(stderr,"[%u-th-> %u]",i,wcsa->doc_offsets_sids[i]); //} //Preparing a "list of occurrences" that will be later indexed through build_il() ** uint *source_il, sourcelen_il; //uint maxPost = ndocs; //!! uint maxPost = doc_offsets_sids[ndocs]; uint nwords = wcsa->nwords; prepareSourceFormatForIListBuilder(nwords,maxPost,lenList, occList, &source_il, &sourcelen_il); /* char fileuintpostings[256] = "postingsSequence.uint32"; output_posting_lists_concatenated_DEBUGGING_ONLY (nwords, maxPost, lenList, occList,fileuintpostings); */ FILE *ff = fopen ("postings.posts","w"); fwrite (source_il, sizeof(uint), sourcelen_il, ff); fclose(ff); #ifdef WRITE_POSTING_LIST FILE *ff = fopen ("postings.posts","w"); fwrite (source_il, sizeof(uint), sourcelen_il, ff); fclose(ff); #endif fprintf(stderr,"\n there are %lu uints in all the lists of occurrences: size [uint32] = %lu bytes.\n ", (ulong)sourcelen_il - nwords -2, (ulong) sizeof(uint)*(sourcelen_il - nwords -2)); fprintf(stderr,"\n maxPostValue = %u",maxPost); /*{ char fileposts[256]; sprintf(fileposts,"%s.%s.%u","POSTING_LISTS","posts", getpid()); FILE *ff = fopen(fileposts,"w"); fwrite(source_il, sizeof(uint), sourcelen_il,ff); fclose(ff); } for (int x=0;x<10;x++) printf("\n%u --> %u",x,source_il[x]); exit(0); */ fprintf(stderr,"\n the lists of occurrences were formatted for build_il.");fflush(stderr); //compressing the lists of occurrences and setting wcsa->ils int error = build_il(source_il, sourcelen_il, build_options, &(wcsa->ils)); //source_il is freed inside!. IFERRORIL(error); { //frees memory for the posting lists uint i; for (i=0;i<wcsa->nwords;i++) free(occList[i]); free(occList); free(lenList); } /** 5 ** compressed representation of the source text */ { //unsigned long *docbegsUL; unsigned int i; //docbegsUL = (ulong *) malloc (sizeof(ulong) * (ndocs+1)); //for (i=0;i<=ndocs;i++) docbegsUL[i] = docboundaries[i]; //build_representation (wcsa->text, wcsa->textSize, docbegsUL, ndocs, build_options, &wcsa->ct); fprintf(stderr,"\nNow compressing the text: %lu bytes", (ulong)wcsa->textSize);fflush(stderr); build_representation (wcsa->text, wcsa->textSize, docboundaries, ndocs, build_options, &wcsa->ct); unsigned char *document; uint doclen; extract_doc_representation (wcsa->ct, 0, &document, &doclen); fprintf(stderr,"\n =================== DOC 0 ======================"); fprintf(stderr,"\n%s",document); fprintf(stderr,"\n =================== ***** ======================\n"); free(document); //free(docbegsUL); } } #ifndef FREQ_VECTOR_AVAILABLE //<----- not needed in advance, only during construction free(wcsa->freqs); #endif free(docboundaries); ulong sizeI; index_size(*index, &sizeI); fflush(stderr); fflush(stdout); fprintf(stderr,"\n The index has already been built: %lu bytes!!\n", sizeI); fflush(stderr); fflush(stdout); return 0; }
void PrintPcPres(void) { gen g; long i, j, first = 1; if (Gap) putchar('#'); printf(" <"); for (i = 1; i <= NrPcGens; i++) { printGen(i, 'A'); if (i < NrPcGens + NrCenGens) putchar(','); } printf("\n"); if (Gap) putchar('#'); printf(" "); for (; i <= NrPcGens + NrCenGens; i++) { printGen(i, 'A'); if (i < NrPcGens + NrCenGens) putchar(','); } printf(" |"); for (i = 1; i <= NrPcGens + NrCenGens; i++) { if (Exponent[i] != (expo)0) { if (first) { putchar('\n'); first = 0; } else printf(",\n"); if (Gap) putchar('#'); printf(" "); printGen(i, 'A'); printf("^"EXP_FORMAT, Exponent[i]); if (Power[i] != (word)0 && Power[i]->g != EOW) { printf(" = "); printWord(Power[i], 'A'); } } } for (j = 1; j <= NrPcGens; j++) { i = 1; while (i < j && Wt(i) + Wt(j) <= Class + (NrCenGens == 0 ? 0 : 1)) { /* print Conjugate[j][i] */ if (first) { putchar('\n'); first = 0; } else printf(",\n"); if (Gap) putchar('#'); printf(" "); printGen(j, 'A'); putchar('^'); printGen(i, 'A'); if ((g = Conjugate[j][i][1].g) != EOW && Definition[g].h == j && Definition[g].g == i) printf(" =: "); else printf(" = "); printWord(Conjugate[j][i], 'A'); if (Exponent[i] == (expo)0) { if (first) { putchar('\n'); first = 0; } else printf(",\n"); if (Gap) putchar('#'); printf(" "); printGen(j, 'A'); putchar('^'); putchar('('); printGen(i, 'A'); printf("^-1) = "); printWord(Conjugate[j][-i], 'A'); } if (0 && Exponent[j] == (expo)0) { if (first) { putchar('\n'); first = 0; } else printf(",\n"); if (Gap) putchar('#'); printf(" "); putchar('('); printGen(j, 'A'); printf("^-1)^"); printGen(i, 'A'); printf(" = "); printWord(Conjugate[-j][i], 'A'); } if (0 && Exponent[i] + Exponent[j] == (expo)0) { if (first) { putchar('\n'); first = 0; } else printf(",\n"); if (Gap) putchar('#'); printf(" "); putchar('('); printGen(j, 'A'); printf("^-1)^"); putchar('('); printGen(i, 'A'); printf("^-1) = "); printWord(Conjugate[-j][-i], 'A'); } i++; } } printf(" >\n"); printf("\n# Class : %d\n", Class); printf("# Nr of generators of each class :"); for (i = 1; i <= Class; i++) printf(" %d", Dimension[i]); printf("\n"); }
// Replace the character with an ASCII equivalent, which can be an equivalent // character, a word, or nothing. static inline void printEquivalent(int c) { switch(c) { case 0x7f: break; case 0x80: printWord("euro"); break; case 0x81: break; case 0x82: putchar('\''); break; case 0x83: putchar('f'); break; case 0x84: putchar('"'); break; case 0x85: printWord("..."); break; case 0x86: break; case 0x87: break; case 0x88: putchar('^'); break; case 0x89: putchar('%'); break; case 0x8A: putchar('S'); break; case 0x8B: putchar('<'); break; case 0x8C: putchar('E'); break; case 0x8D: break; case 0x8E: putchar('Z'); break; case 0x8F: break; case 0x90: break; case 0x91: putchar('\''); break; case 0x92: putchar('\''); break; case 0x93: putchar('"'); break; case 0x94: putchar('"'); break; case 0x95: putchar('*'); break; case 0x96: putchar('-'); break; case 0x97: putchar('-'); break; case 0x98: putchar('~'); break; case 0x99: printWord("TM"); break; case 0x9A: putchar('S'); break; case 0x9B: putchar('>'); break; case 0x9C: putchar('e'); break; case 0x9D: break; case 0x9E: putchar('z'); break; case 0x9F: putchar('Y'); break; case 0xA0: putchar(' '); break; case 0xA1: break; case 0xA2: printWord("cents"); break; case 0xA3: printWord("pounds"); break; case 0xA4: printWord("currency"); break; case 0xA5: printWord("yen"); break; case 0xA6: putchar('|'); break; case 0xA7: break; case 0xA8: break; case 0xA9: printWord("copyright"); break; case 0xAA: putchar('a'); break; case 0xAB: printWord("<<"); break; case 0xAC: printWord("not"); break; case 0xAD: putchar('-'); break; case 0xAE: printWord("restricted"); break; case 0xAF: break; case 0xB0: printWord("degrees"); break; case 0xB1: printWord("plus/minus"); break; case 0xB2: putchar('2'); break; case 0xB3: putchar('3'); break; case 0xB4: putchar('\''); break; case 0xB5: putchar('u'); break; case 0xB6: break; case 0xB7: putchar('*'); break; case 0xB8: putchar(','); break; case 0xB9: putchar('1'); break; case 0xBA: putchar('0'); break; case 0xBB: printWord(">>"); break; case 0xBC: printWord("1/4"); break; case 0xBD: printWord("1/3"); break; case 0xBE: printWord("3/4"); break; case 0xBF: break; case 0xC0: putchar('A'); break; case 0xC1: putchar('A'); break; case 0xC2: putchar('A'); break; case 0xC3: putchar('A'); break; case 0xC4: putchar('A'); break; case 0xC5: putchar('A'); break; case 0xC6: printWord("AE"); break; case 0xC7: putchar('C'); break; case 0xC8: putchar('E'); break; case 0xC9: putchar('E'); break; case 0xCA: putchar('E'); break; case 0xCB: putchar('E'); break; case 0xCC: putchar('I'); break; case 0xCD: putchar('I'); break; case 0xCE: putchar('I'); break; case 0xCF: putchar('I'); break; case 0xD0: putchar('D'); break; case 0xD1: putchar('N'); break; case 0xD2: putchar('O'); break; case 0xD3: putchar('O'); break; case 0xD4: putchar('O'); break; case 0xD5: putchar('O'); break; case 0xD6: putchar('O'); break; case 0xD7: putchar('*'); break; case 0xD8: putchar('0'); break; case 0xD9: putchar('U'); break; case 0xDA: putchar('U'); break; case 0xDB: putchar('U'); break; case 0xDC: putchar('U'); break; case 0xDD: putchar('Y'); break; case 0xDE: putchar('Y'); break; case 0xDF: putchar('s'); break; case 0xE0: putchar('a'); break; case 0xE1: putchar('a'); break; case 0xE2: putchar('a'); break; case 0xE3: putchar('a'); break; case 0xE4: putchar('a'); break; case 0xE5: putchar('a'); break; case 0xE6: printWord("ae"); break; case 0xE7: putchar('c'); break; case 0xE8: putchar('e'); break; case 0xE9: putchar('e'); break; case 0xEA: putchar('e'); break; case 0xEB: putchar('e'); break; case 0xEC: putchar('i'); break; case 0xED: putchar('i'); break; case 0xEE: putchar('i'); break; case 0xEF: putchar('i'); break; case 0xF0: putchar('o'); break; case 0xF1: putchar('n'); break; case 0xF2: putchar('o'); break; case 0xF3: putchar('o'); break; case 0xF4: putchar('o'); break; case 0xF5: putchar('o'); break; case 0xF6: putchar('o'); break; case 0xF7: putchar('/'); break; case 0xF8: putchar('0'); break; case 0xF9: putchar('u'); break; case 0xFA: putchar('u'); break; case 0xFB: putchar('u'); break; case 0xFC: putchar('u'); break; case 0xFD: putchar('y'); break; case 0xFE: putchar('y'); break; case 0xFF: putchar('y'); break; default: printf("Unexpected character %c\n", c); } }
void Words::print( ) { for (long i=0;i<m_numWords;i++) { printWord(i); printf("\n"); } }