LPSTR CParser::GetKey( LPSTR far * lppData ) /***********************************************************************/ { LPSTR lpData, lpReturn; if ( !lppData ) return( NULL ); if ( !(lpData = *lppData) ) return( NULL ); // Skip white space while ( (*lpData) && IS_SEPARATOR(*lpData) ) lpData++; // If at the end of the data, get out if ( !(*lpData) ) return( NULL ); // Save the return value lpReturn = lpData; // Find the start point for the next call while ( !IS_SEPARATOR(*lpData) ) lpData++; // Null terminate the return string and advance to the next call if ( *lpData ) *lpData++ = '\0'; // Update the location for the next call *lppData = lpData; return( lpReturn ); }
/* TODO: be more tolerant regarding unmatched character in the needle. * Right now, we implicitly accept unmatched characters at the end of the * needle but absolutely not at the start. e.g. "xpy" won't match "python" at * all, though "pyx" will. */ static inline gint get_score (const gchar *needle, const gchar *haystack) { if (! needle || ! haystack) { return needle == NULL; } else if (! *needle || ! *haystack) { return *needle == 0; } if (IS_SEPARATOR (*haystack)) { return get_score (needle + IS_SEPARATOR (*needle), haystack + 1); } if (IS_SEPARATOR (*needle)) { return get_score (needle + 1, next_separator (haystack)); } if (*needle == *haystack) { gint a = get_score (needle + 1, haystack + 1) + 1 + IS_SEPARATOR (haystack[1]); gint b = get_score (needle, next_separator (haystack)); return MAX (a, b); } else { return get_score (needle, next_separator (haystack)); } }
int get_word_len(char *s) { int i; char c; if (!*s) return (0); i = 0; if (IS_INHIBITOR(s[i])) { c = s[i++]; while (s[i] && s[i] != c) { if (s[i] == '\\' && !s[++i]) return (-1); i += 1; } return (s[i] == c ? ++i : -1); } while (s[i] && !IS_SEPARATOR(s[i])) { if (s[i] == '\\' && !s[++i]) return (-1); i += 1; } return (i); }
LPSTR CParser::GetValues( LPSTR far * lppData, LPINT lpNumValues ) /***********************************************************************/ { LPSTR lpData, lpReturn; BOOL fNewValue; *lpNumValues = 0; if ( !lppData ) return( NULL ); if ( !(lpData = *lppData) ) return( NULL ); // Skip white space while ( (*lpData) && IS_SEPARATOR(*lpData) ) lpData++; // If at the end of the data, get out if ( !(*lpData) ) return( NULL ); // Save the return value lpReturn = lpData; // Find the start point for the next call fNewValue = TRUE; while ( *lpData && *lpData != ',') { if (IS_SPACE(*lpData)) fNewValue = TRUE; else if (fNewValue) { *lpNumValues += 1; fNewValue = FALSE; } lpData++; } // Null terminate the return string and advance to the next call if ( *lpData ) *lpData++ = '\0'; // Update the location for the next call *lppData = lpData; if (*lpNumValues) return( lpReturn ); else return( NULL ); }
static int get_argc(char *s) { int i; int skip; i = 0; do { while (*s && IS_SEPARATOR(*s)) s += 1; skip = get_arg_len(s); s += skip; i += (skip > 0 ? 1 : 0); } while (skip > 0); return (skip == 0 ? i : -1); }
BOOL CParser::GetEntryString( HPTR FAR * lppData, LPSTR lpReturn, int iLength ) /***********************************************************************/ { HPTR lpData; if ( !lppData ) return( NO ); if ( !(lpData = *lppData) ) return( NO ); // Skip white space while ( (*lpData) && IS_SEPARATOR(*lpData) ) lpData++; // If at the end of the data, get out if ( !(*lpData) ) return( NO ); // Copy bytes till we find the start point for the next call while ( *lpData && ((*lpData) != ';') ) { if ( --iLength > 0 ) *lpReturn++ = *lpData; lpData++; } // Null terminate the return string *lpReturn = '\0'; // Update the location for the next call if ( *lpData ) lpData++; *lppData = lpData; return( YES ); }
/////////////////////////////////////////////////////////////////////////////// // Paint the toolbar void CToolBarXP::OnPaint () { if ( m_bDelayedButtonLayout ) { Layout(); } CPaintDC cpDC (this); CBufferDC cDC (cpDC); CRect rcClip; cDC.GetClipBox (rcClip); cDC.SetBkMode (TRANSPARENT); cDC.SelectObject (CFont::FromHandle ((HFONT)GetStockObject (DEFAULT_GUI_FONT))); cDC.FillSolidRect (rcClip, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), 20, 0)); CPoint ptCursor; ::GetCursorPos (&ptCursor); ScreenToClient (&ptCursor); CClientRect rcClient (this); HIMAGELIST m_hImageList = (HIMAGELIST)DefWindowProc (TB_GETIMAGELIST, 0, 0); TBBUTTON tbbutton; int nCount = DefWindowProc (TB_BUTTONCOUNT, 0, 0); int nHotItem = GetToolBarCtrl().GetHotItem(); for ( int i = 0; i < nCount; i++ ) { VERIFY(DefWindowProc (TB_GETBUTTON, i, (LPARAM)&tbbutton)); if ( !IS_VISIBLE(tbbutton) ) { continue; } CRect rcButton; VERIFY(DefWindowProc (TB_GETITEMRECT, i, (LPARAM)&rcButton)); if ( !CRect().IntersectRect (rcClip, rcButton) ) { continue; } bool bOver = nHotItem == i && IS_ENABLED(tbbutton); bool bPressed = false; if ( IS_INDETERMINATE(tbbutton) ) { CPenDC pen (cDC, ::GetSysColor (COLOR_3DSHADOW)); cDC.MoveTo (rcButton.left, rcButton.bottom); cDC.LineTo (rcButton.left, rcButton.top); cDC.LineTo (rcButton.right-1, rcButton.top); cDC.LineTo (rcButton.right-1, rcButton.bottom-1); cDC.LineTo (rcButton.left, rcButton.bottom-1); bOver = true; } else if ( bOver || IS_CHECKED(tbbutton) ) { bPressed = KEYDOWN(VK_LBUTTON) && rcButton.PtInRect (ptCursor); if ( IS_DROPDOWN(tbbutton) && bPressed ) { bPressed = ptCursor.x < rcButton.right-13; if ( bPressed ) { rcButton.right -= 13; } } COLORREF crHighLight = ::GetSysColor (COLOR_HIGHLIGHT); CPenDC pen (cDC, crHighLight); CBrushDC brush (cDC, bPressed||(bOver&&IS_CHECKED(tbbutton)) ? HLS_TRANSFORM (crHighLight, +50, -50) : (bOver ? HLS_TRANSFORM (crHighLight, +70, -57) : HLS_TRANSFORM (crHighLight, +80, -66))); cDC.Rectangle (&rcButton); if ( IS_DROPDOWN(tbbutton) ) { if ( bPressed ) { int nLeft = rcButton.left; rcButton.left = rcButton.right-1; rcButton.right += 13; brush.Color (HLS_TRANSFORM (crHighLight, +70, -66)); cDC.Rectangle (&rcButton); rcButton.left = nLeft; } else { cDC.MoveTo (rcButton.right-14, rcButton.top); cDC.LineTo (rcButton.right-14, rcButton.bottom); } } } if ( IS_SEPARATOR(tbbutton) ) { CPenDC pen (cDC, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -15, 0)); if ( IS_WRAP(tbbutton) ) { cDC.MoveTo (rcClient.left+2, rcButton.bottom-4); cDC.LineTo (rcClient.right-2, rcButton.bottom-4); } else { cDC.MoveTo ((rcButton.right+rcButton.left)/2-1, rcButton.top+2); cDC.LineTo ((rcButton.right+rcButton.left)/2-1, rcButton.bottom-2); } } else if ( !IS_CONTROL(tbbutton) ) { if ( IS_DROPDOWN(tbbutton) ) { CPenDC pen (cDC, ( bOver && !IS_INDETERMINATE(tbbutton) ) ? RGB(0,0,0) : ::GetSysColor (IS_ENABLED(tbbutton) ? COLOR_BTNTEXT : COLOR_GRAYTEXT)); cDC.MoveTo (rcButton.right-9, (rcButton.top+rcButton.bottom)/2-1); cDC.LineTo (rcButton.right-4, (rcButton.top+rcButton.bottom)/2-1); cDC.MoveTo (rcButton.right-8, (rcButton.top+rcButton.bottom)/2); cDC.LineTo (rcButton.right-5, (rcButton.top+rcButton.bottom)/2); cDC.SetPixel (rcButton.right-7, (rcButton.top+rcButton.bottom)/2+1, pen.Color()); rcButton.right -= 14; } if ( tbbutton.iBitmap >= 0 ) { if ( !IS_ENABLED(tbbutton) || (bOver && !bPressed) ) { HICON hIcon = ImageList_ExtractIcon (NULL, m_hImageList, tbbutton.iBitmap); cDC.DrawState (CPoint (rcButton.left + ( bOver ? 4 : 3 ), rcButton.top + ( bOver ? 4 : 3 )), m_sizeImage, hIcon, DSS_MONO, CBrush (bOver ? (IS_INDETERMINATE(tbbutton) ? HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -20, 0) : HLS_TRANSFORM (::GetSysColor (COLOR_HIGHLIGHT), +50, -66)) : HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -27, 0))); DestroyIcon (hIcon); } if ( IS_ENABLED(tbbutton) ) { ::ImageList_Draw (m_hImageList, tbbutton.iBitmap, cDC.m_hDC, rcButton.left + ( (bOver && !bPressed) ? 2 : 3 ), rcButton.top + ( (bOver && !bPressed) ? 2 : 3 ), ILD_TRANSPARENT); } } } } }
static rfh_toktype_t get_token(const char **charpp, const char *endp, char *token, char *end_token) { const char *charp = *charpp; char *tokp = token; int ch; state_t state = ST_INITIAL; rfh_toktype_t toktype = TT_TOKEN; SKIP_SEPARATORS(charp, endp); while (state != ST_END && tokp < end_token) { ch = GETCHAR(charp, endp); if (debug_mode) fprintf(stderr, "state = %s, char = %c [%d]\n", rfh_state_to_s(state), (char)ch, ch); switch (state) { case ST_INITIAL: if (ch == EOS) { *tokp = '\0'; toktype = TT_END; state = ST_END; if (debug_mode) fprintf(stderr, "new state = %s, toktype = %s\n", rfh_state_to_s(state), rfh_toktype_to_s(toktype)); } else if (IS_UNQUOTED_ID_CHAR(ch)) { *tokp++ = (char)ch; state = ST_IN_UNQUOTED_ID; if (debug_mode) fprintf(stderr, "new state = %s\n", rfh_state_to_s(state)); } else if (ch == QUOTE) { state = ST_IN_QUOTED_ID; if (debug_mode) fprintf(stderr, "new state = %s\n", rfh_state_to_s(state)); } break; case ST_IN_UNQUOTED_ID: if (IS_SEPARATOR(ch) || ch == EOS) { *tokp = '\0'; state = ST_END; if (debug_mode) fprintf(stderr, "new state = %s\n", rfh_state_to_s(state)); } else if (ch == QUOTE) /* Not allowed in unquoted string */ { toktype = TT_ILLEGAL_QUOTE; state = ST_END; if (debug_mode) fprintf(stderr, "new state = %s, toktype = %s\n", rfh_state_to_s(state), rfh_toktype_to_s(toktype)); } else *tokp++ = (char)ch; break; case ST_IN_QUOTED_ID: if (ch == QUOTE) /* Could be end of token, or first char of "" */ { int lookahead_ch = LOOKAHEAD(charp, endp); if (lookahead_ch == QUOTE) /* Found escaped quote */ { *tokp++ = QUOTE; ++charp; /* Skip second quote */ } else if (IS_SEPARATOR(lookahead_ch) || lookahead_ch == EOS) /* End of token */ { *tokp = '\0'; state = ST_END; if (debug_mode) fprintf(stderr, "new state = %s\n", rfh_state_to_s(state)); } else /* Error: Unescaped quote */ { toktype = TT_UNESCAPED_QUOTE; state = ST_END; if (debug_mode) fprintf(stderr, "new state = %s, toktype = %s\n", rfh_state_to_s(state), rfh_toktype_to_s(toktype)); } } else if (ch == EOS) /* Error */ { toktype = TT_UNEXPECTED_EOS; state = ST_END; if (debug_mode) fprintf(stderr, "new state = %s, toktype = %s\n", rfh_state_to_s(state), rfh_toktype_to_s(toktype)); } else *tokp++ = (char)ch; break; default: toktype = TT_INTERNAL_ERROR; state = ST_END; if (debug_mode) fprintf(stderr, "new state = %s, toktype = %s\n", rfh_state_to_s(state), rfh_toktype_to_s(toktype)); break; } /* switch */ } /* while */ /* If state is not ST_END, an error may have occurred */ if (state != ST_END && toktype == TT_TOKEN) { if (tokp >= end_token) toktype = TT_TOKEN_TRUNCATED; else toktype = TT_UNEXPECTED_EOS; if (debug_mode) fprintf(stderr, "end state = %s, toktype = %s\n", rfh_state_to_s(state), rfh_toktype_to_s(toktype)); } *charpp = charp; if (debug_mode) fprintf(stderr, "-- leaving; end state = %s, returned toktype = %s, returned token = [%s]\n", rfh_state_to_s(state), rfh_toktype_to_s(toktype), token); return toktype; }
/* if strip_number: removes number extensions * note: dont use sizeof() for 'name' or 'from_name' */ void flip_side_name (char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME], int strip_number) { int len; char prefix[MAX_VGROUP_NAME]= ""; /* The part before the facing */ char suffix[MAX_VGROUP_NAME]= ""; /* The part after the facing */ char replace[MAX_VGROUP_NAME]= ""; /* The replacement string */ char number[MAX_VGROUP_NAME]= ""; /* The number extension string */ char *index=NULL; len= BLI_strnlen(from_name, MAX_VGROUP_NAME); if(len<3) return; // we don't do names like .R or .L BLI_strncpy(name, from_name, MAX_VGROUP_NAME); /* We first check the case with a .### extension, let's find the last period */ if(isdigit(name[len-1])) { index= strrchr(name, '.'); // last occurrence if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever! if(strip_number==0) BLI_strncpy(number, index, sizeof(number)); *index= 0; len= BLI_strnlen(name, MAX_VGROUP_NAME); } } BLI_strncpy(prefix, name, sizeof(prefix)); #define IS_SEPARATOR(a) ((a)=='.' || (a)==' ' || (a)=='-' || (a)=='_') /* first case; separator . - _ with extensions r R l L */ if( IS_SEPARATOR(name[len-2]) ) { switch(name[len-1]) { case 'l': prefix[len-1]= 0; strcpy(replace, "r"); break; case 'r': prefix[len-1]= 0; strcpy(replace, "l"); break; case 'L': prefix[len-1]= 0; strcpy(replace, "R"); break; case 'R': prefix[len-1]= 0; strcpy(replace, "L"); break; } } /* case; beginning with r R l L , with separator after it */ else if( IS_SEPARATOR(name[1]) ) { switch(name[0]) { case 'l': strcpy(replace, "r"); strcpy(suffix, name+1); prefix[0]= 0; break; case 'r': strcpy(replace, "l"); strcpy(suffix, name+1); prefix[0]= 0; break; case 'L': strcpy(replace, "R"); strcpy(suffix, name+1); prefix[0]= 0; break; case 'R': strcpy(replace, "L"); strcpy(suffix, name+1); prefix[0]= 0; break; } } else if(len > 5) { /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */ index = BLI_strcasestr(prefix, "right"); if (index==prefix || index==prefix+len-5) { if(index[0]=='r') strcpy (replace, "left"); else { if(index[1]=='I') strcpy (replace, "LEFT"); else strcpy (replace, "Left"); } *index= 0; strcpy (suffix, index+5); } else { index = BLI_strcasestr(prefix, "left"); if (index==prefix || index==prefix+len-4) { if(index[0]=='l') strcpy (replace, "right"); else { if(index[1]=='E') strcpy (replace, "RIGHT"); else strcpy (replace, "Right"); } *index= 0; strcpy (suffix, index+4); } } } #undef IS_SEPARATOR BLI_snprintf (name, MAX_VGROUP_NAME, "%s%s%s%s", prefix, replace, suffix, number); }
int expand_macro(struct prog_info *pi, struct macro *macro, char *rest_line) { int ok = True, macro_arg_count = 0, off, a, b = 0, c, i = 0, j = 0; char *line = NULL; char *temp; char *macro_args[MAX_MACRO_ARGS]; char tmp[7]; char buff[LINEBUFFER_LENGTH]; char arg = False; char *nmn; //string buffer for 'n'ew 'm'acro 'n'ame struct macro_line *old_macro_line; struct macro_call *macro_call; struct macro_label *macro_label; if(rest_line) { //we reserve some extra space for extended macro parameters line = malloc(strlen(rest_line) + 20); if(!line) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } /* exchange amca word 'src' with YH:YL and 'dst' with ZH:ZL */ for(c = 0, a = strlen(rest_line); c < a; c++) { switch (tolower(rest_line[c])) { case 's': if(IS_SEPARATOR(rest_line[c-1]) && (rest_line[c+1] == 'r') && (rest_line[c+2] == 'c') && IS_SEPARATOR(rest_line[c+3])) { strcpy(&line[b],"YH:YL"); b += 5; c += 2; } else { line[b++] = rest_line[c]; } break; case 'd': if(IS_SEPARATOR(rest_line[c-1]) && (rest_line[c+1] == 's') && (rest_line[c+2] == 't') && IS_SEPARATOR(rest_line[c+3])) { strcpy(&line[b],"ZH:ZL"); b += 5; c += 2; } else { line[b++] = rest_line[c]; } break; // case ';': // break; default: line[b++] = rest_line[c]; } } strcpy(&line[b],"\n"); /* set CR/LF at the end of the line */ /* here we split up the macro arguments into "macro_args" * Extended macro code interpreter added by TW 2002 */ temp = line; /* test for advanced parameters */ if( temp[0] == '[' ) { // there must be "[" " then "]", else it is garbage if(!strchr(temp, ']')) { print_msg(pi, MSGTYPE_ERROR, "found no closing ']'"); return(False); } // Okay now we are within the advanced code interpreter temp++; // = &temp[1]; // skip the first bracket nmn = malloc(LINEBUFFER_LENGTH); if(!nmn) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } strcpy(nmn,macro->name); // create a new macro name buffer c = 1; // byte counter arg = True; // loop flag while(arg) { while(IS_HOR_SPACE(temp[0])) { //skip leading spaces temp++; // = &temp[1]; } off = 0; // pointer offset do { switch(temp[off]) { //test current character code case ':': temp[off] = '\0'; if(off > 0) { c++; macro_args[macro_arg_count++] = temp; } else { print_msg(pi, MSGTYPE_ERROR, "missing register before ':'",nmn); return(False); } break; case ']': arg = False; case ',': a = off; do temp[a--] = '\0'; while( IS_HOR_SPACE(temp[a]) ); if(off > 0) { macro_args[macro_arg_count++] = temp; append_type(pi, nmn, c, temp); c = 1; } else { append_type(pi, nmn, 0, temp); c = 1; } break; default: off++; } } while(temp[off] != '\0'); if(arg) temp = &temp[off+1]; else break; } macro = get_macro(pi,nmn); if(macro == NULL) { print_msg(pi, MSGTYPE_ERROR, "Macro %s is not defined !",nmn); return(False); } free(nmn); } /* or else, we handle the macro as normal macro */ else { line = malloc(strlen(rest_line) + 1); if(!line) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } strcpy(line, rest_line); temp = line; while(temp) { macro_args[macro_arg_count++] = temp; temp = get_next_token(temp, TERM_COMMA); } } } if(pi->pass == PASS_1) { macro_call = calloc(1, sizeof(struct macro_call)); if(!macro_call) { print_msg(pi, MSGTYPE_OUT_OF_MEM, NULL); return(False); } if(pi->last_macro_call) pi->last_macro_call->next = macro_call; else pi->first_macro_call = macro_call; pi->last_macro_call = macro_call; macro_call->line_number = pi->fi->line_number; macro_call->include_file = pi->fi->include_file; macro_call->macro = macro; macro_call->prev_on_stack = pi->macro_call; if(macro_call->prev_on_stack) { macro_call->nest_level = macro_call->prev_on_stack->nest_level + 1; macro_call->prev_line_index = macro_call->prev_on_stack->line_index; } } else { for(macro_call = pi->first_macro_call; macro_call; macro_call = macro_call->next) { if((macro_call->include_file->num == pi->fi->include_file->num) && (macro_call->line_number == pi->fi->line_number)) { if(pi->macro_call) { /* Find correct macro_call when using recursion and nesting */ if(macro_call->prev_on_stack == pi->macro_call) if((macro_call->nest_level == (pi->macro_call->nest_level + 1)) && (macro_call->prev_line_index == pi->macro_call->line_index)) break; } else break; } } if(pi->list_line && pi->list_on) { fprintf(pi->list_file, "C:%06x + %s\n", pi->cseg_addr, pi->list_line); pi->list_line = NULL; } } macro_call->line_index = 0; pi->macro_call = macro_call; old_macro_line = pi->macro_line; //printf("\nconvert macro: '%s'\n",macro->name); for(pi->macro_line = macro->first_macro_line; pi->macro_line && ok; pi->macro_line = pi->macro_line->next) { macro_call->line_index++; if(GET_ARG(pi->args, ARG_LISTMAC)) pi->list_line = buff; else pi->list_line = NULL; /* here we change jumps/calls within macro that corresponds to macro labels. Only in case there is an entry in macro_label list */ strcpy(buff,"\0"); macro_label = get_macro_label(pi->macro_line->line,macro); if(macro_label) { /* test if the right macro label has been found */ temp = strstr(pi->macro_line->line,macro_label->label); c = strlen(macro_label->label); if(temp[c] == ':') { /* it is a label definition */ macro_label->running_number++; strncpy(buff, macro_label->label, c - 1); buff[c - 1] = 0; i = strlen(buff) + 2; /* we set the process indeafter label */ /* add running number to it */ strcpy(&buff[c-1],itoa(macro_label->running_number, tmp, 10)); strcat(buff, ":\0"); } else if(IS_HOR_SPACE(temp[c]) || IS_END_OR_COMMENT(temp[c])) { /* it is a jump to a macro defined label */ strcpy(buff,pi->macro_line->line); temp = strstr(buff, macro_label->label); i = temp - buff + strlen(macro_label->label); strncpy(temp, macro_label->label, c - 1); strcpy(&temp[c-1], itoa(macro_label->running_number, tmp, 10)); } } else { i = 0; } /* here we check every character of current line */ for(j = i; pi->macro_line->line[i] != '\0'; i++) { /* check for register place holders */ if(pi->macro_line->line[i] == '@') { i++; if(!isdigit(pi->macro_line->line[i])) print_msg(pi, MSGTYPE_ERROR, "@ must be followed by a number"); else if((pi->macro_line->line[i] - '0') >= macro_arg_count) print_msg(pi, MSGTYPE_ERROR, "Missing macro argument (for @%c)", pi->macro_line->line[i]); else { /* and replace them with given registers */ strcat(&buff[j], macro_args[pi->macro_line->line[i] - '0']); j += strlen(macro_args[pi->macro_line->line[i] - '0']); } } else if (pi->macro_line->line[i] == ';') { strncat(buff, "\n", 1); break; } else { strncat(buff, &pi->macro_line->line[i], 1); } } ok = parse_line(pi, buff); if(ok) { if((pi->pass == PASS_2) && pi->list_line && pi->list_on) fprintf(pi->list_file, " %s\n", pi->list_line); if(pi->error_count >= pi->max_errors) { print_msg(pi, MSGTYPE_MESSAGE, "Maximum error count reached. Exiting..."); ok = False; break; } } } pi->macro_line = old_macro_line; pi->macro_call = macro_call->prev_on_stack; if(rest_line) free(line); return(ok); }