void insertsort(int *a,int num){ int i,j,temp; for(i=1;i<num;i++){ temp=a[i]; binsert(temp,a,i-1); for(j=0;j<11;j++) printf("%d ",a[j]); printf("\n"); } }
/* * mvnum is number of move (rel zero) * see if swapped also tested */ static void trymove(int mvnum, int swapped) { int pos; /* position on board */ int rval; /* value of roll */ /* if recursed through all dice values, compare move */ if (mvnum == mvlim) { binsert(bsave()); return; } /* make sure dice in always same order */ if (d0 == swapped) swap; /* choose value for this move */ rval = dice[mvnum != 0]; /* find all legitimate moves */ for (pos = bar; pos != home; pos += cturn) { /* fix order of dice */ if (d0 == swapped) swap; /* break if stuck on bar */ if (board[bar] != 0 && pos != bar) break; /* on to next if not occupied */ if (board[pos] * cturn <= 0) continue; /* set up arrays for move */ p[mvnum] = pos; g[mvnum] = pos + rval * cturn; if (g[mvnum] * cturn >= home) { if (*offptr < 0) break; g[mvnum] = home; } /* try to move */ if (makmove(mvnum)) continue; else trymove(mvnum + 1, 2); /* undo move to try another */ backone(mvnum); } /* swap dice and try again */ if ((!swapped) && D0 != D1) trymove(0, 1); }
CDString* CD_PrependString (CDString* self, CDString* append) { assert(self); assert(append); cd_MakeStringInternal(self); if (binsert(self->raw, 0, append->raw, '\0') == BSTR_OK) { cd_UpdateLength(self); } else { self = NULL; } return self; }
CDString* CD_InsertString (CDString* self, CDString* insert, size_t position) { assert(self); assert(insert); cd_MakeStringInternal(self); if (binsert(self->raw, CD_UTF8_offset(CD_StringContent(self), position), insert->raw, '\0') == BSTR_OK) { cd_UpdateLength(self); } else { self = NULL; } return self; }
CDString* CD_AppendStringAndClean (CDString* self, CDString* append) { assert(self); assert(append); cd_MakeStringInternal(self); if (binsert(self->raw, self->raw->slen, append->raw, '\0') == BSTR_OK) { cd_UpdateLength(self); } else { self = NULL; } CD_DestroyString(append); return self; }
const char* glswGetShader(const char* pEffectKey, const char* pContentsFromMemory) { glswContext* gc = __glsw__Context; bstring effectKey; glswList* closestMatch = 0; struct bstrList* tokens; bstring effectName; glswList* pLoadedEffect; glswList* pShaderEntry; bstring shaderKey = 0; if (!gc) { return 0; } // Extract the effect name from the effect key effectKey = bfromcstr(pEffectKey); tokens = bsplit(effectKey, '.'); if (!tokens || !tokens->qty) { bdestroy(gc->ErrorMessage); gc->ErrorMessage = bformat("Malformed effect key key '%s'.", pEffectKey); bstrListDestroy(tokens); bdestroy(effectKey); return 0; } effectName = tokens->entry[0]; // Check if we already loaded this effect file pLoadedEffect = gc->LoadedEffects; while (pLoadedEffect) { if (1 == biseq(pLoadedEffect->Key, effectName)) { break; } pLoadedEffect = pLoadedEffect->Next; } // If we haven't loaded this file yet, load it in if (!pLoadedEffect) { bstring effectContents; struct bstrList* lines; int lineNo; if (!pContentsFromMemory) { FILE* fp; bstring effectFile; // Decorate the effect name to form the fullpath effectFile = bstrcpy(effectName); binsert(effectFile, 0, gc->PathPrefix, '?'); bconcat(effectFile, gc->PathSuffix); // Attempt to open the file fp = fopen((const char*) effectFile->data, "rb"); if (!fp) { bdestroy(gc->ErrorMessage); gc->ErrorMessage = bformat("Unable to open effect file '%s'.", effectFile->data); bdestroy(effectFile); bdestroy(effectKey); bstrListDestroy(tokens); return 0; } // Add a new entry to the front of gc->LoadedEffects { glswList* temp = gc->LoadedEffects; gc->LoadedEffects = (glswList*) calloc(sizeof(glswList), 1); gc->LoadedEffects->Key = bstrcpy(effectName); gc->LoadedEffects->Next = temp; } // Read in the effect file effectContents = bread((bNread) fread, fp); fclose(fp); bdestroy(effectFile); } else { effectContents = bfromcstr(pContentsFromMemory); } lines = bsplit(effectContents, '\n'); bdestroy(effectContents); effectContents = 0; for (lineNo = 0; lineNo < lines->qty; lineNo++) { bstring line = lines->entry[lineNo]; // If the line starts with "--", then it marks a new section if (blength(line) >= 2 && line->data[0] == '-' && line->data[1] == '-') { // Find the first character in [A-Za-z0-9_]. int colNo; for (colNo = 2; colNo < blength(line); colNo++) { char c = line->data[colNo]; if (__glsw__Alphanumeric(c)) { break; } } // If there's no alphanumeric character, // then this marks the start of a new comment block. if (colNo >= blength(line)) { bdestroy(shaderKey); shaderKey = 0; } else { // Keep reading until a non-alphanumeric character is found. int endCol; for (endCol = colNo; endCol < blength(line); endCol++) { char c = line->data[endCol]; if (!__glsw__Alphanumeric(c)) { break; } } bdestroy(shaderKey); shaderKey = bmidstr(line, colNo, endCol - colNo); // Add a new entry to the shader map. { glswList* temp = gc->ShaderMap; gc->ShaderMap = (glswList*) calloc(sizeof(glswList), 1); gc->ShaderMap->Key = bstrcpy(shaderKey); gc->ShaderMap->Next = temp; gc->ShaderMap->Value = bformat("#line %d\n", lineNo); binsertch(gc->ShaderMap->Key, 0, 1, '.'); binsert(gc->ShaderMap->Key, 0, effectName, '?'); } // Check for a version mapping. if (gc->TokenMap) { struct bstrList* tokens = bsplit(shaderKey, '.'); glswList* pTokenMapping = gc->TokenMap; while (pTokenMapping) { bstring directive = 0; int tokenIndex; // An empty key in the token mapping means "always prepend this directive". // The effect name itself is also checked against the token mapping. if (0 == blength(pTokenMapping->Key) || 1 == biseq(pTokenMapping->Key, effectName)) { directive = pTokenMapping->Value; binsert(gc->ShaderMap->Value, 0, directive, '?'); } // Check all tokens in the current section divider for a mapped token. for (tokenIndex = 0; tokenIndex < tokens->qty && !directive; tokenIndex++) { bstring token = tokens->entry[tokenIndex]; if (1 == biseq(pTokenMapping->Key, token)) { directive = pTokenMapping->Value; binsert(gc->ShaderMap->Value, 0, directive, '?'); } } pTokenMapping = pTokenMapping->Next; } bstrListDestroy(tokens); } } continue; } if (shaderKey) { bconcat(gc->ShaderMap->Value, line); bconchar(gc->ShaderMap->Value, '\n'); } } // Cleanup bstrListDestroy(lines); bdestroy(shaderKey); } // Find the longest matching shader key pShaderEntry = gc->ShaderMap; while (pShaderEntry) { if (binstr(effectKey, 0, pShaderEntry->Key) == 0 && (!closestMatch || blength(pShaderEntry->Key) > blength(closestMatch->Key))) { closestMatch = pShaderEntry; } pShaderEntry = pShaderEntry->Next; } bstrListDestroy(tokens); bdestroy(effectKey); if (!closestMatch) { bdestroy(gc->ErrorMessage); gc->ErrorMessage = bformat("Could not find shader with key '%s'.", pEffectKey); return 0; } return (const char*) closestMatch->Value->data; }
void Zopen_line(void) { binsert(Bbuff, NL); bmove(Bbuff, -1); }
void main() { int n,num,num1,flag=0; while(1) { clrscr(); printf("\n\t\t****** DOUBLY LINKED LIST OPERATION ******\n"); printf("\t\t......______________________________......\n"); printf("\nWELCOME,WHAT YOU WANT TO DO ?::"); printf("\n_____________________________\n\n"); printf("\nINSERTION --PRESS 1\n"); printf("\nDELETION --PRESS 2\n"); printf("\nSEARCH --PRESS 3\n"); printf("\nCOUNT --PRESS 4\n"); printf("\nDISPLAY(F) --PRESS 5\n"); printf("\nDISPLAY(R) --PRESS 6\n"); printf("\nEXIT --PRESS 7\n"); printf("\n\nENTER YOUR CHOICE::\n"); scanf("%d",&n); switch(n) { case 1: while(1) { flag=0; clrscr(); printf("INSERT A NODE ::\n"); printf("\t\tAT FIRST -PRESS 1.\n"); printf("\t\tAFTER A NODE -PRESS 2.\n"); printf("\t\tBEFORE A NODE -PRESS 3.\n"); printf("\t\tAT LAST -PRESS 4.\n"); printf("\t\tEXIT FROM HERE-PRESS 5.\n"); printf("\n\nENTER YOUR CHOICE::\n"); scanf("%d",&n); switch(n) { case 1: printf("\nENTER A ELEMENT FOR INSERTION\n"); scanf("%d",&num); finsert(num); printf("\n%d IS INSERT AT FIRST PROPERLY\n",num); break; case 2: printf("\nENTER A ELEMENT FOR INSERTION\n"); scanf("%d",&num); printf("AFTER WHICH ELEMENT YOU WANT TO INSERT\n"); scanf("%d",&num1); ainsert(num,num1); break; case 3: printf("ENTER A ELEMENT FOR INSERTION\n"); scanf("%d",&num); printf("BEFORE WHICH ELEMENT YOU WANT TO INSERT\n"); scanf("%d",&num1); binsert(num,num1); break; case 4: printf("ENTER AN ELEMENT FOR INSERT IN LAST\n"); scanf("%d",&num); linsert(num); break; case 5: printf("\nTHANK YOU FOR USING INSERT OPERETION\n"); flag=1; break; } getch(); if(flag==1) break; } break; case 2: while(1) { flag=0; clrscr(); printf("DELETE A NODE ::\n"); printf("\t\tAT FIRST -PRESS 1.\n"); printf("\t\tAFTER A NODE -PRESS 2.\n"); printf("\t\tBEFORE A NODE -PRESS 3.\n"); printf("\t\tAT LAST -PRESS 4.\n"); printf("\t\tEXACT A NODE -PRESS 5.\n"); printf("\t\tEXIT FROM HERE-PRESS 6.\n"); printf("\n\nENTER YOUR CHOICE::\n"); scanf("%d",&n); switch(n) { case 1: fdelete(); break; case 2: printf("\nENTER AFTER WHICH ELEMENT YOU WANT TO DELETE A NODE\n"); scanf("%d",&num); adelete(num); break; case 3: printf("\nENTER BEFORE WHICH ELEMENT YOU WANT TO DELETE A NODE\n"); scanf("%d",&num); bdelete(num); break; case 4: ldelete(); break; case 5: printf("WHICH ELEMENT CONTAIN NODE YOU WANT TO DELETE:\n"); scanf("%d",&num); edelete(num); break; case 6: printf("THANK YOU FOR USING DELETE OPERETION"); flag=1; break; } getch(); if(flag==1) break; } break; case 3: printf("WHICH ELEMENT YOU WANT TO SEARCH ?"); scanf("%d",&num); search(num); break; case 4: num=count(); printf("AT PRESENT LINKLIST CONTAIN %d NODES\n",num); break; case 5: fdisplay(); break; case 6: rdisplay(); break; case 7: printf("\n\nTHANK YOU FOR USING THIS PROGRAM\n"); getch(); exit(0); } getch(); } }
void createLine(int side, bstring base, bstring content, lineData lineMap, int * highlightMask) { if (lineMap.type == INFO) { content = bfromcstr(""); lineMap.lineNo = 0; } int position = 0; int needToCloseLastHighlightBeforeEscapingHTML = FALSE; if (highlightMask != NULL) { int lastState = MASK_SAME; int advanceBy; int i; int contentLen = content->slen; // Copy this because it will change as we work. for (i = 0; i < contentLen; i++) { advanceBy = 1; // Normally advance by one char. // Escape HTML as we go. if (content->data[position] == '&') { breplace(content, position, 1, bfromcstr("&"), ' '); advanceBy += 4; } else if (content->data[position] == '<') { breplace(content, position, 1, bfromcstr("<"), ' '); advanceBy += 3; } else if (content->data[position] == '>') { breplace(content, position, 1, bfromcstr(">"), ' '); advanceBy += 3; } if (highlightMask[i] != lastState) { if (highlightMask[i] == MASK_DIFFERENT) { binsert(content, position, bfromcstr("<em>"), ' '); advanceBy += 4; } else { binsert(content, position, bfromcstr("</em>"), ' '); advanceBy += 5; } } position += advanceBy; lastState = highlightMask[i]; } } // Escape HTML. // TODO: This can't possibly be good enough. bfindreplace(content, bfromcstr("&"), bfromcstr("&"), position); bfindreplace(content, bfromcstr("<"), bfromcstr("<"), position); bfindreplace(content, bfromcstr(">"), bfromcstr(">"), position); // Put something in blank lines. if (content->slen == 0) bcatcstr(content, " "); if (needToCloseLastHighlightBeforeEscapingHTML) { bcatcstr(content, "</em>"); } // TODO: there's a lot of string manipulation going on here. It might be // good for performance to call ballocmin and boost the base string size by // a big chunk. if (lineMap.lineNo >= 0 && lineMap.type != INFO) { char * lineNo = lineNumberString(lineMap.lineNo); bcatcstr(base, "<td class='line_number "); bcatcstr(base, typeString(lineMap.type)); bcatcstr(base, " "); bcatcstr(base, (side == LEFT) ? "left" : "right"); bcatcstr(base, "' width='*'>"); bcatcstr(base, lineNo); bcatcstr(base, "</td>\n"); bcatcstr(base, "<td class='line "); free(lineNo); } else { bcatcstr(base, "<td colspan='2' class='line "); } bstring whitespace; bcatcstr(base, typeString(lineMap.type)); bcatcstr(base, " "); bcatcstr(base, (side == LEFT) ? "left" : "right"); bcatcstr(base, "' width='49%'>"); bconcat(base, whitespace = getWhitespace(lineMap.leadingSpaces)); bconcat(base, content); bcatcstr(base, "</td>\n"); bdestroy(whitespace); }