static void dumpFile( FILE *fp, format *fmt ) { int ch; char *buf; char *prv; int repeat = 0; short int sz = 0; buf = (char *) malloc( MAX_BYTES ); prv = (char *) malloc( MAX_BYTES ); fseek( fp, fmt->offset, SEEK_SET ); for( ;; ) { ch = fgetc( fp ); if( ch != EOF ) { buf[ sz ] = (char) ch; } else { flushLine( buf, sz, fmt ); break; } sz++; if( isatty( fileno( fp ) ) && ch == '\n' ) { flushLine( buf, sz, fmt ); repeat = 0; fmt->offset += (long int) sz; sz = 0; memset( buf, 0, MAX_BYTES ); } else if( sz >= MAX_BYTES ) { if( repeat != 0 && memcmp( buf, prv, MAX_BYTES ) == 0 ) { if( repeat != 2 ) { fprintf( stdout, "*\n" ); repeat = 2; } } else { flushLine( buf, MAX_BYTES, fmt ); memcpy( prv, buf, MAX_BYTES ); repeat = 1; } fmt->offset += (long int) MAX_BYTES; sz = 0; memset( buf, 0, MAX_BYTES ); } } fmt->offset += (long int) sz; if( fmt->osfmt == DEC_OFFSET ) { fprintf( stdout, "%010ld\n", fmt->offset ); } else { fprintf( stdout, "%010lo\n", fmt->offset ); } }
STATIC int loadFrame(LINEBUF *data, int numFields) { register int nc; char *field, *stopChar; nc = -1; for (field = getNextLine(data); field != NULL && data->isComment; field = getNextLine(data) ) flushLine(data, NULL); if (field != NULL) { nc = 0; for ( field = nextField(data, field); field != NULL; field = nextField(data, field) ) { if (nc == numFields) { nc = 0; break; } A[fields[nc]] = strtod(fieldData, &stopChar); if (stopChar == fieldData || (*stopChar != 0 && !isspace(*stopChar))) { nc = 0; break; } nc++; } } return nc; }
int main(int argc, char* argv){ memset(world,0,sizeof(world)); int i; char c; rNum = 0; int trash = scanf("%d %d\n",&maxX,&maxY); while ((trash = scanf("%d %d %c\n", &x, &y, &orientation)) != -1){ rNum++; bool result = performAction(orientation); c = getchar(); while (c != '\n' && c != EOF && result){ result = performAction(c); c = getchar(); } if (c != '\n' && c != EOF) flushLine(); if (!result){ printf("%d %d %c LOST\n",x,y, orientation); } else { printf("%d %d %c\n",x,y,orientation); } } printWorld(); return 0; }
void Editor_Export::closeElementNode (xmlNodePtr node) { // The tag and class names of this element node. string tagName ((char *) node->name); string className; xmlChar * property = xmlGetProp (node, BAD_CAST "class"); if (property) { className = (char *) property; xmlFree (property); } if (tagName == "p") { // While editing it happens that the p element does not have a class. // Use the 'p' class in such cases. if (className == "") className = "p"; if (noteOpeners.find (className) != noteOpeners.end()) { // Deal with note closers. currentLine += usfm_get_closing_usfm (className); } else { // Normally a p element closes the USFM line. flushLine (); mono = false; // Clear active character styles. characterStyles.clear(); } } if (tagName == "span") { // Do nothing for monospace elements, because the USFM would be the text nodes only. if (mono) return; // Do nothing without a class. if (className.empty()) return; // Do nothing if no endmarkers are supposed to be produced. if (suppressEndMarkers.find (className) != suppressEndMarkers.end()) return; // Add closing USFM, optionally closing embedded tags in reverse order. vector <string> classes = filter_string_explode (className, ' '); characterStyles = filter_string_array_diff (characterStyles, classes); reverse (classes.begin(), classes.end()); for (unsigned int offset = 0; offset < classes.size(); offset++) { bool embedded = (classes.size () > 1) && (offset == 0); if (!characterStyles.empty ()) embedded = true; currentLine += usfm_get_closing_usfm (classes [offset], embedded); } } if (tagName == "a") { // Do nothing for note citations in the text. } }
STATIC long locateHeader(LINEBUF *data) { long headerOffset = -1; /* Find last explicit comment line */ rewindBuf(data); for (; getNextLine(data) != NULL && data->isComment; flushLine(data, NULL) ) { if (*(data->buffer) == data->commentChar) headerOffset = data->bufferOffset; } return headerOffset; }
void Editor_Export::openElementNode (xmlNodePtr node) { // The tag and class names of this element node. string tagName ((char *) node->name); string className; xmlChar * property = xmlGetProp (node, BAD_CAST "class"); if (property) { className = (char *) property; xmlFree (property); } if (tagName == "p") { // While editing, it may occur that the p element does not have a class. // Use the 'p' class in such cases. if (className.empty ()) className = "p"; if (className == "mono") { // Class 'mono': The editor has the full USFM in the text. mono = true; } else { // Start the USFM line with a marker with the class name. currentLine += usfm_get_opening_usfm (className); } } if (tagName == "span") { if (className == "v") { // Handle the verse. flushLine (); openInline (className); } else if (className.empty ()) { // Normal text is wrapped in elements without a class attribute. } else { // Handle remaining class attributes for inline text. openInline (className); } } if (tagName == "a") { processNoteCitation (node); } }
void Editor_Html2Usfm::openElementNode (xml_node node) { // The tag and class names of this element node. string tagName = node.name (); string className = node.attribute ("class").value (); if (tagName == "p") { // While editing, it may occur that the p element does not have a class. // Use the 'p' class in such cases. if (className.empty ()) className = "p"; if (className == "mono") { // Class 'mono': The editor has the full USFM in the text. mono = true; } else { // Start the USFM line with a marker with the class name. currentLine += usfm_get_opening_usfm (className); } } if (tagName == "span") { if (className == "v") { // Handle the verse. flushLine (); openInline (className); } else if (className.empty ()) { // Normal text is wrapped in elements without a class attribute. } else { // Handle remaining class attributes for inline text. openInline (className); } } if (tagName == "a") { processNoteCitation (node); } }
PrintOut::~PrintOut() { flushLine(); delete fmetrics; p.end(); }
VisualLog::~VisualLog(){ flushLine(); }
void paragraph::PutHandlingLine(wint_t ch,flags & flgs) // Called from GetPut, GetPutBullet and doTheSegmentation { if(flgs.inhtmltag) { flushLine(ch,flgs); } else { if(ch == '\n' || ch == '\r') { if(!lastEOLchar || lastEOLchar == ch) { flushLine('\n',flgs);/// lastEOLchar = ch; } else { // Ignore ch: CRLF or LFCR sequence equals '\n' lastEOLchar = '\0'; } } else { if( ch == WEOF || ch == 26 /*20150916*/ || overflowing() ) { flushLine(ch,flgs); } else { if(isFlatSpace(ch)) // if(ch == ' ' || ch == '\t') // reduces " \t\t \t\t\t" to " \t \t" // why keep spaces AND tabs, why not reduce to a single space? { if(MindTheSpace != 0 /*&& ch != flgs.MindTheSpace*/) { append(MindTheSpace); } MindTheSpace = ' ';//ch; //Line[Index++] = ch; } else if(MindTheSpace != 0) { append(MindTheSpace); MindTheSpace = 0; //assert(Index < sizeof(Line)/sizeof(Line[0])); append(ch); } else { append(ch); } // 20100106 The following does not reduce spaces, but increases their numbers! //assert(Index < sizeof(Line)/sizeof(Line[0])); //Line[Index++] = ch; } } lastEOLchar = '\0'; } }
void Editor_Html2Usfm::postprocess () { // Flush any last USFM line being built. flushLine (); }
/* Read a pgm form header from input file, return the first comment line found (when *headerState = 0). *headerState is modified to indicate the state of the pgm header read so far. If this value of *headerState is used in a second call to readPnmCommentLine, then a second comment line is read. And so on. The recognized types are: - "P5" - pgm image - "P6" - ppm image - "FP" - pfm image, image of floats in a PC format - "FU","F5" - pfm image, image of floats in a UNIX machine format readPnmCommentLine returns: -1 if error found 0 if no comment found 1 found a comment line *********/ int readPnmCommentLine(FILE *fpIn, char *commentLine, int *headerState) { char line[MAXLINE_PGM], fileType[MAXLEN], *cPtr; int i, k, paramCount, foundComment; /* Strip file type in first two characters */ if (*headerState == 0) { fread(line, (int) 2, 1, fpIn); line[2] = '\0'; /* Check if file type is one of the recognized types */ if (!((strcmp(line, "P5") == 0) || (strcmp(line, "P6") == 0) || (strcmp(line, "FP") == 0) || (strcmp(line, "F5") == 0) || (strcmp(line, "FU") == 0))) return(-1); /* unrecognized file type */ fread( line, (int) 1, 1, fpIn); if (!whtspc(line[0])) return(-1); *headerState = 1; } paramCount = (*headerState)-1; /* Read parameters nx, ny, ngray */ foundComment = 0; while(paramCount < 3 && foundComment == 0) { /* Seek next parameter or comment */ /* Strip white space */ while(whtspc(line[0])) { if (! fread(line, (int) 1, 1, fpIn)) return(-1); } if (line[0] == '#') { /* Read comment line */ k = getStripLine(fpIn, commentLine, MAXLINE_PGM); if (k==1) { /* Could not find a '\n' before MAXLINE_PGM, return first portion of comment line, and flush the rest. */ if (flushLine(fpIn) < 0) return(-1); /* Eof bumped into unexpectedly */ } else if (k < 0) return(-1); /* Eof bumped into unexpectedly */ foundComment = 1; } else { /* Read parameter */ i = 0; while( !whtspc(line[i]) && i < MAXLINE_PGM) { i++; if (!fread( &(line[i]), (int) 1, 1, fpIn)) return(-1); } strtol(line, &cPtr, 10); if (cPtr == NULL) return(-1); paramCount++; line[0] = line[i]; /* re-prime whitespace stream */ } } *headerState = paramCount+1; return(foundComment); }
void Editor_Export::postprocess () { // Flush any last USFM line being built. flushLine (); }