static void devide_line( char * out /* 'out' is 'output' in actual */ ) /* * Devide a too long line into output lines shorter than NWORK. * This routine is called from putout(). */ { FILEINFO * file; char * save; char * wp; int c; file = unget_string( out, NULL); /* To re-read the line */ wp = out_ptr = out; while ((c = get_ch()), file == infile) { if (char_type[ c] & HSP) { if (keep_spaces || out == out_ptr || (char_type[ *(out_ptr - 1) & UCHARMAX] & HSP)) { *out_ptr++ = c; wp++; } continue; } scan_token( c, &wp, out_wend); /* Read a token */ if (NWORK-2 < wp - out_ptr) { /* Too long a token */ cfatal( "Too long token %s", out_ptr, 0L, NULL); /* _F_ */ } else if (out_end <= wp) { /* Too long line */ if (mcpp_debug & MACRO_CALL) { /* -K option */ /* Other than GCC or Visual C */ /* scan_token() scans a comment as sequence of some */ /* tokens such as '/', '*', ..., '*', '/', since it */ /* does not expect comment. */ save = out_ptr; while ((save = strrchr( save, '/')) != NULL) { if (*(save - 1) == '*') { /* '*' '/' sequence */ out_ptr = save + 1; /* Devide at the end*/ break; /* of a comment*/ } } } save = save_string( out_ptr); /* Save the token */ *out_ptr++ = '\n'; /* Append newline */ *out_ptr = EOS; put_a_line( out); /* Putout the former tokens */ wp = out_ptr = stpcpy( out, save); /* Restore the token */ free( save); } else { /* Still in size */ out_ptr = wp; /* Advance the pointer */ } } unget_ch(); /* Push back the source character */ put_a_line( out); /* Putout the last tokens */ sharp( NULL, 0); /* Correct line number */ }
static void mcpp_main( void) /* * Main process for mcpp -- copies tokens from the current input stream * (main file or included file) to the output file. */ { int c; /* Current character */ char * wp; /* Temporary pointer */ DEFBUF * defp; /* Macro definition */ int line_top; /* Is in the line top, possibly spaces */ LINE_COL line_col; /* Location of macro call in source */ keep_comments = option_flags.c && !no_output; keep_spaces = option_flags.k; /* Will be turned off if !compiling */ line_col.col = line_col.line = 0L; /* * This loop is started "from the top" at the beginning of each line. * 'wrong_line' is set TRUE in many places if it is necessary to write * a #line record. (But we don't write them when expanding macros.) * * 'newlines' variable counts the number of blank lines that have been * skipped over. These are then either output via #line records or * by outputting explicit blank lines. * 'newlines' will be cleared on end of an included file by get_ch(). */ while (1) { /* For the whole input */ newlines = 0; /* Count empty lines */ while (1) { /* For each line, ... */ out_ptr = output; /* Top of the line buf */ c = get_ch(); if (src_col) break; /* There is a residual tokens on the line */ while (char_type[ c] & HSP) { /* ' ' or '\t' */ if (c != COM_SEP) *out_ptr++ = c; /* Retain line top white spaces */ /* Else skip 0-length comment */ c = get_ch(); } if (c == '#') { /* Is 1st non-space '#' */ directive(); /* Do a #directive */ } else if (mcpp_mode == STD && option_flags.dig && c == '%') { /* In POST_STD digraphs are already converted */ if (get_ch() == ':') { /* '%:' i.e. '#' */ directive(); /* Do a #directive */ } else { unget_ch(); if (! compiling) { skip_nl(); newlines++; } else { break; } } } else if (c == CHAR_EOF) { /* End of input */ break; } else if (! compiling) { /* #ifdef false? */ skip_nl(); /* Skip to newline */ newlines++; /* Count it, too. */ } else if (in_asm && ! no_output) { /* In #asm block */ put_asm(); /* Put out as it is */ } else if (c == '\n') { /* Blank line */ if (keep_comments) mcpp_fputc( '\n', OUT); /* May flush comments */ else newlines++; /* Wait for a token */ } else { break; /* Actual token */ } } if (c == CHAR_EOF) /* Exit process at */ break; /* end of input */ /* * If the loop didn't terminate because of end of file, we * know there is a token to compile. First, clean up after * absorbing newlines. newlines has the number we skipped. */ if (no_output) { wrong_line = FALSE; } else { if (wrong_line || newlines > 10) { sharp( NULL, 0); /* Output # line number */ if (keep_spaces && src_col) { while (src_col--) /* Adjust columns */ mcpp_fputc( ' ', OUT); src_col = 0; } } else { /* If just a few, stuff */ while (newlines-- > 0) /* them out ourselves */ mcpp_fputc('\n', OUT); } } /* * Process each token on this line. */ line_top = TRUE; while (c != '\n' && c != CHAR_EOF) { /* For the whole line */ /* * has_pragma is set to TRUE so as to execute _Pragma() operator * when the psuedo macro _Pragma() is found. */ int has_pragma; if ((mcpp_debug & MACRO_CALL) && ! in_directive) { line_col.line = src_line; /* Location in source */ line_col.col = infile->bptr - infile->buffer - 1; } if (scan_token( c, (wp = out_ptr, &wp), out_wend) == NAM && (defp = is_macro( &wp)) != NULL) { /* A macro */ wp = expand_macro( defp, out_ptr, out_wend, line_col , & has_pragma); /* Expand it completely */ if (line_top) { /* The first token is a macro */ char * tp = out_ptr; while (char_type[ *tp & UCHARMAX] & HSP) tp++; /* Remove excessive spaces */ memmove( out_ptr, tp, strlen( tp) + 1); wp -= (tp - out_ptr); } if (has_pragma) { /* Found _Pramga() */ do_pragma_op(); /* Do _Pragma() operator*/ out_ptr = output; /* Do the rest of line */ wrong_line = TRUE; /* Line-num out of sync */ } else { out_ptr = wp; } if (keep_spaces && wrong_line && infile && *(infile->bptr) != '\n' && *(infile->bptr) != EOS) { src_col = infile->bptr - infile->buffer; /* Remember the current colums */ break; /* Do sharp() now */ } } else { /* Not a macro call */ out_ptr = wp; /* Advance the place */ if (wrong_line) /* is_macro() swallowed */ break; /* the newline */ } while (char_type[ c = get_ch()] & HSP) { /* Horizontal space */ if (c != COM_SEP) /* Skip 0-length comment*/ *out_ptr++ = c; } line_top = FALSE; /* Read over some token */ } /* Loop for line */ putout( output); /* Output the line */ } /* Continue until EOF */ }
QString Chord::baseString( EnharmonicPolicy epolicy ) const { switch (m_base) { case 0: return "C"; case 1: switch (epolicy) { case Sharp: return sharp("C"); case Natural: case Flat: return flat("D"); } case 2: return "D"; case 3: switch (epolicy) { case Sharp: return sharp("D"); case Natural: case Flat: return flat("E"); } case 4: return "E"; case 5: return "F"; case 6: switch (epolicy) { case Sharp: case Natural: return sharp("F"); case Flat: return flat("G"); } case 7: return "G"; case 8: switch (epolicy) { case Sharp: return sharp("G"); case Flat: case Natural: return flat("A"); } case 9: return "A"; case 10: switch (epolicy) { case Sharp: return sharp("A"); case Flat: case Natural: return flat("B"); } case 11: return "B"; default: return "?"; } }
bool Chord::parse(QString text) { if (text.isEmpty()) { return false; } QRegExp beforeMatcher( "^(" + IGNORE_BEFORE_PATTERN + ")" ); if (beforeMatcher.indexIn( text ) == 0 ) { int n = beforeMatcher.matchedLength(); m_before = text.left(n); text = text.mid(n); } QRegExp afterMatcher( "(" + IGNORE_AFTER_PATTERN + ")$" ); if ( afterMatcher.indexIn( text ) >= 0 ) { int n = afterMatcher.matchedLength(); m_after = text.right( n ); text = text.mid( 0, text.length() - n ); } QChar baseChar = text[0]; m_base = parseBase(baseChar); if (m_base < 0) { return false; } text = text.mid(1); if ( ifStartsWithTake( text, "es" ) || (!text.startsWith("sus") && ifStartsWithTake( text, "s") ) || ifStartsWithTake( text, "b" ) || ifStartsWithTake( text, flat()) ) { m_base--; } if ( ifStartsWithTake( text, "is" ) || ifStartsWithTake( text, "#" ) || ifStartsWithTake( text, sharp() ) ) { m_base++; } m_base %= 12; m_base += 12; m_base %= 12; if ( baseChar.isLower() || (!text.startsWith("min") && !text.startsWith("maj") && ifStartsWithTake( text, "m" ) ) ) { m_isMinor = true; } else { m_isMinor = false; } m_attachment = text; if (QRegExp( CHORD_EXTENSION_PATTERN ).exactMatch( m_attachment )) { return true; } else { return false; } }
/* * Main process for cpp -- copies tokens from the current input * stream (main file, include file, or a macro) to the output * file. */ void cppmain() { int c; /* Current character */ int counter; /* newlines and spaces */ /* * Explicitly output a #line at the start of cpp output so * that lint (etc.) knows the name of the original source * file. If we don't do this explicitly, we may get * the name of the first #include file instead. * We also seem to need a blank line following that first #line. */ #ifdef EVALDEFS if ( !bIsInEval ) #endif { sharp(); PUTCHAR('\n'); } /* * This loop is started "from the top" at the beginning of each line * wrongline is set TRUE in many places if it is necessary to write * a #line record. (But we don't write them when expanding macros.) * * The counter variable has two different uses: at * the start of a line, it counts the number of blank lines that * have been skipped over. These are then either output via * #line records or by outputting explicit blank lines. * When expanding tokens within a line, the counter remembers * whether a blank/tab has been output. These are dropped * at the end of the line, and replaced by a single blank * within lines. */ for (;;) { counter = 0; /* Count empty lines */ for (;;) { /* For each line, ... */ while (type[(c = get())] == SPA) /* Skip leading blanks */ ; /* in this line. */ if (c == '\n') /* If line's all blank, */ ++counter; /* Do nothing now */ else if (c == '#') { /* Is 1st non-space '#' */ keepcomments = FALSE; /* Don't pass comments */ counter = control(counter); /* Yes, do a #command */ keepcomments = (cflag && compiling); } else if (c == EOF_CHAR) /* At end of file? */ { break; } else if (!compiling) { /* #ifdef false? */ skipnl(); /* Skip to newline */ counter++; /* Count it, too. */ } else { break; /* Actual token */ } } if (c == EOF_CHAR) /* Exit process at */ break; /* End of file */ /* * If the loop didn't terminate because of end of file, we * know there is a token to compile. First, clean up after * absorbing newlines. counter has the number we skipped. */ if ((wrongline && infile->fp != NULL) || counter > 4) sharp(); /* Output # line number */ else { /* If just a few, stuff */ while (--counter >= 0) /* them out ourselves */ PUTCHAR('\n'); } /* * Process each token on this line. */ unget(); /* Reread the char. */ for (;;) { /* For the whole line, */ do { /* Token concat. loop */ for (counter = 0; type[(c = get())] == SPA;) { #if COMMENT_INVISIBLE if (c != COM_SEP) #endif counter++; /* Skip over blanks */ } if (c == EOF_CHAR || c == '\n') goto end_line; /* Exit line loop */ else if (counter > 0) /* If we got any spaces */ PUTCHAR(' '); /* Output one space */ c = macroid(c); /* Grab the token */ } while (type[c] == LET && catenate()); if (c == EOF_CHAR || c == '\n') /* From macro exp error */ goto end_line; /* Exit line loop */ switch (type[c]) { case LET: fputs(token, pCppOut); /* Quite ordinary token */ #ifdef EVALDEFS { int len; if ( bIsInEval && nEvalOff + (len=strlen(token)) < NEVALBUF ) { strcpy( &EvalBuf[nEvalOff], token ); nEvalOff += len; } } #endif break; case DIG: /* Output a number */ case DOT: /* Dot may begin floats */ #ifdef EVALDEFS if ( bIsInEval ) scannumber(c, outputEval); else scannumber(c, output); #else scannumber(c, output); #endif break; case QUO: /* char or string const */ scanstring(c, output); /* Copy it to output */ break; default: /* Some other character */ cput(c); /* Just output it */ #ifdef EVALDEFS if ( bIsInEval && nEvalOff < NEVALBUF ) EvalBuf[nEvalOff++] = c; #endif break; } /* Switch ends */ } /* Line for loop */ end_line: if (c == '\n') { /* Compiling at EOL? */ PUTCHAR('\n'); /* Output newline, if */ if (infile->fp == NULL) /* Expanding a macro, */ wrongline = TRUE; /* Output # line later */ } } /* Continue until EOF */ #ifdef EVALDEFS if ( bIsInEval ) EvalBuf[nEvalOff++] = '\0'; #endif }
INLINE FILE_LOCAL ReturnCode cppmain(struct Global *global) { /* * Main process for cpp -- copies tokens from the current input * stream (main file, include file, or a macro) to the output * file. */ int c; /* Current character */ int counter; /* newlines and spaces */ ReturnCode ret; /* return code variable type */ long bracelevel = 0; long parenlevel = 0; long bracketlevel = 0; int fake = 0; #define MAX_FUNC_LENGTH 50 char tempfunc[MAX_FUNC_LENGTH + 1]; char tempfunc2[MAX_FUNC_LENGTH + 1]; char define = 0; /* probability of a function define phase in the program */ char prev = 0; /* previous type */ char go = 0; char include = 0; char initfunc = 0; /* Initialize for reading tokens */ global->tokenbsize = 50; global->tokenbuf = malloc(global->tokenbsize + 1); if(!global->tokenbuf) return(FPP_OUT_OF_MEMORY); global->functionname = malloc(global->tokenbsize + 1); if(!global->functionname) return(FPP_OUT_OF_MEMORY); global->functionname[0] = '\0'; if(global->showspace) { global->spacebuf = (char *)malloc(MAX_SPACE_SIZE); if(!global->spacebuf) return(FPP_OUT_OF_MEMORY); } if(global->showversion) Error(global, VERSION_TEXT); /* * Explicitly output a #line at the start of cpp output so * that lint (etc.) knows the name of the original source * file. If we don't do this explicitly, we may get * the name of the first #include file instead. */ if(global->linelines) /* if #line lines are wanted! */ sharp(global); /* * This loop is started "from the top" at the beginning of each line * wrongline is set TRUE in many places if it is necessary to write * a #line record. (But we don't write them when expanding macros.) * * The counter variable has two different uses: at * the start of a line, it counts the number of blank lines that * have been skipped over. These are then either output via * #line records or by outputting explicit blank lines. * When expanding tokens within a line, the counter remembers * whether a blank/tab has been output. These are dropped * at the end of the line, and replaced by a single blank * within lines. */ include = global->included; while(include--) { openinclude(global, global->include[include], TRUE); } for (;;) { counter = 0; /* Count empty lines */ for (;;) { /* For each line, ... */ global->comment = FALSE; /* No comment yet! */ global->chpos = 0; /* Count whitespaces */ while (type[(c = get(global))] == SPA) /* Skip leading blanks */ if(global->showspace) { if(global->chpos<MAX_SPACE_SIZE-1) /* we still have buffer to store this! */ global->spacebuf[global->chpos++]=(char)c; } if (c == '\n') { /* If line's all blank, */ if(global->comment) { /* A comment was output! */ Putchar(global, '\n'); } else ++counter; /* Do nothing now */ } else if (c == '#') { /* Is 1st non-space '#' */ global->keepcomments = FALSE; /* Don't pass comments */ ret = control(global, &counter); /* Yes, do a #command */ if(ret) return(ret); global->keepcomments = (global->cflag && compiling); } else if (c == EOF_CHAR) /* At end of file? */ break; else if (!compiling) { /* #ifdef false? */ skipnl(global); /* Skip to newline */ counter++; /* Count it, too. */ } else { break; /* Actual token */ } } if (c == EOF_CHAR) /* Exit process at */ break; /* End of file */ /* * If the loop didn't terminate because of end of file, we * know there is a token to compile. First, clean up after * absorbing newlines. counter has the number we skipped. */ if(global->linelines) { /* if #line lines are wanted! */ if ((global->wrongline && global->infile->fp != NULL) || counter > 4) sharp(global); /* Output # line number */ else { /* If just a few, stuff */ while (--counter >= 0) /* them out ourselves */ Putchar(global, (int)'\n'); } } if(global->showspace) { /* Show all whitespaces! */ global->spacebuf[global->chpos] = '\0'; Putstring(global, global->spacebuf); } /* * Process each token on this line. */ unget(global); /* Reread the char. */ for (;;) { /* For the whole line, */ do { /* Token concat. loop */ for (global->chpos = counter = 0; (type[(c = get(global))] == SPA);) { #if COMMENT_INVISIBLE if (c != COM_SEP) counter++; #else if(global->showspace && global->chpos < MAX_SPACE_SIZE-1) { global->spacebuf[global->chpos++]=(char)c; } counter++; /* Skip over blanks */ #endif } if (c == EOF_CHAR || c == '\n') break; /* Exit line loop */ else if (counter > 0) { /* If we got any spaces */ if(!global->showspace) /* We don't output all spaces */ Putchar(global, (int)' ');/* Output one space */ else { global->spacebuf[global->chpos] = '\0'; Putstring(global, global->spacebuf); /* Output all whitespaces */ } } if(ret=macroid(global, &c)) /* Grab the token */ return(ret); } while (type[c] == LET && catenate(global, &ret) && !ret); if(ret) /* If the loop was broken because of a fatal error! */ return(ret); if (c == EOF_CHAR || c == '\n') /* From macro exp error */ break; /* Exit line loop */ go++; switch (type[c]) { case LET: go =0; /* Quite ordinary token */ Putstring(global, global->tokenbuf); if(!define) { /* Copy the name */ strncpy(tempfunc, global->tokenbuf, MAX_FUNC_LENGTH); tempfunc[MAX_FUNC_LENGTH]=0; } /* fputs(global->tokenbuf, stdout); */ break; case DIG: /* Output a number */ case DOT: /* Dot may begin floats */ go = 0; ret=scannumber(global, c, (ReturnCode(*)(struct Global *, int))output); if(ret) return(ret); break; case QUO: /* char or string const */ go = 0; /* Copy it to output */ if(!global->webmode) { ret=scanstring(global, c, (ReturnCode(*)(struct Global *, int))output); if(ret) return(ret); break; } /* FALLTHROUGH */ default: /* Some other character */ define++; switch(c) { case '{': if(! bracelevel++ && define > 2) { /* * This is a starting brace. If there is a probability of a * function defining, we copy the `tempfunc' function name to * `global->functionname'. */ strcpy(global->functionname, tempfunc2); global->funcline = global->line; if(global->outputfunctions) { /* * Output the discovered function name to stderr! */ Error(global, "#> Function defined at line %d: %s <#\n", global->line, global->functionname); } if(global->initialfunc) { int a; for(a=0; a<global->excluded; a++) { /* check for excluded functions */ if(!strcmp(global->functionname, global->excludedinit[a])) break; } if(a==global->excluded) { expstuff(global, "__brace__", "{"); expstuff(global, "__init_func__", global->initialfunc); initfunc = TRUE; } } } break; case '}': go = 0; if( (--bracelevel == initfunc) && strcmp(global->infile->filename, "__init_func__") ) { /* we just stepped out of the function! */ global->functionname[0] = '\0'; global->funcline = 0; define = 1; if(initfunc) { Putchar(global, '}'); bracelevel--; initfunc=0; } } fake = 0; break; case ';': case ',': if(go == 2) { define = 1; fake = 0; go--; break; } break; case '(': if(! parenlevel++ && !bracelevel) { if(go == 2) { /* foobar(text) -> "(" is found. This can't be a function */ go--; define = 1; break; } if( define < 2 && prev == LET) { /* This is the first parenthesis on the ground brace level, and we did previously not have a probable function name */ strncpy(tempfunc2, global->tokenbuf, MAX_FUNC_LENGTH); tempfunc2[MAX_FUNC_LENGTH]=0; define++; } else { /* we have a fake start */ fake++; } } break; case ')': if(! --parenlevel && !bracelevel && define>1 && !fake) { /* * The starting parentheses level and * the starting brace level. * This might be the start of a function defining coming * up! */ define++; /* increase probability */ fake = 0; go = 1; } break; case '[': bracketlevel++; break; case ']': bracketlevel--; break; } define--; /* decrease function probability */ Putchar(global, c); /* Just output it */ break; } /* Switch ends */ prev = type[c]; } /* Line for loop */ if (c == '\n') { /* Compiling at EOL? */ Putchar(global, '\n'); /* Output newline, if */ if (global->infile->fp == NULL) /* Expanding a macro, */ global->wrongline = TRUE; /* Output # line later */ } } /* Continue until EOF */ if(global->showbalance) { if(bracketlevel) { cwarn(global, WARN_BRACKET_DEPTH, bracketlevel); } if(parenlevel) { cwarn(global, WARN_PAREN_DEPTH, parenlevel); } if(bracelevel) { cwarn(global, WARN_BRACE_DEPTH, bracelevel); } } if (global->wflag) { global->out = TRUE; /* enable output */ outdefines(global); /* Write out #defines */ } return(FPP_OK); }