Exemplo n.º 1
0
Arquivo: dir.c Projeto: alhazred/onarm
static int
noteUsage(int fd, int32_t startAt, struct pcdir *dp, struct pcdir *lp,
    int32_t longEntryStartCluster, int isHidden, int isDir,
    struct nameinfo *fullPathName)
{
	struct pcdir *orphanEntry;
	int32_t chain = startAt;
	int32_t count = 0;
	int savePathNextIteration = 0;
	int haveBad = 0;
	ClusterInfo *tmpl = NULL;

	while ((chain >= FIRST_CLUSTER) && (chain <= LastCluster)) {
		if ((markInUse(fd, chain, dp, lp, longEntryStartCluster,
		    isHidden ? HIDDEN : VISIBLE, &tmpl))
			!= CLINFO_NEWLY_ALLOCED)
			break;
		count++;
		if (savePathNextIteration == 1) {
			savePathNextIteration = 0;
			if (fullPathName != NULL)
				fullPathName->references++;
			squirrelPath(fullPathName, chain);
		}
		if (isMarkedBad(chain)) {
			haveBad = 1;
			savePathNextIteration = 1;
		}
		if (isHidden)
			HiddenClusterCount++;
		else if (isDir)
			DirClusterCount++;
		else
			FileClusterCount++;
		chain = nextInChain(chain);
	}
	/*
	 * Do a sanity check on the file size in the directory entry.
	 * This may create an orphaned cluster chain.
	 */
	if (sanityCheckSize(fd, dp, count, isDir, startAt,
	    fullPathName, &orphanEntry) == TRUNCATED) {
		/*
		 * The pre-existing directory entry has been truncated,
		 * so the chain associated with it no longer has any
		 * bad clusters.  Instead, the new orphan has them.
		 */
		if (haveBad > 0) {
			truncChainWithBadCluster(fd, orphanEntry, startAt);
		}
		haveBad = 0;
	}
	return (haveBad);
}
Exemplo n.º 2
0
void
MibParser::doTrapTypes(ifstream* ifile)
{
  skipImports(ifile);
  // now lets do trap types
  while (!ifile->eof())
  {
    try 
    {

      // read each line of file
      char lineBuffer[4096];
      char* lineBuf = lineBuffer;
      memset(lineBuffer, 0, 4096);

      ifile->getline(lineBuffer, 4096);
      int count = ifile->gcount();

      if (isComment(lineBuf))
	continue;

      if (strstr(lineBuf, "DESCRIPTION"))
	skipDescription(lineBuf, ifile);

      if (isTrapType(lineBuf))
      {
	node* n = new node;
	n->trap = true;
	while (*lineBuf == ' ' || *lineBuf == '\t') 
	  lineBuf++;
	char* spec = strstr(lineBuf, "TRAP-TYPE");
	if (spec != NULL)
	{
	  spec--;
	  while (*spec == ' ' || *spec == '\t')
	    spec--;
	}
	*++spec = 0;
	strncpy(n->name, lineBuf, 256);
	  
	while (1)
	{
	  memset(lineBuffer, 0, 4096);
	  lineBuf = lineBuffer;	

	  ifile->getline(lineBuffer, 4096);
	  count = ifile->gcount();
	  
	  if (isEnterprise(lineBuf))
	  {
	    char* ent = strstr(lineBuf, "ENTERPRISE");
	    ent += 10;
	    //	    while (*ent == ' ' || *ent == '\t')
	    while (*ent == ' ' || *ent == '\t' || *ent == '{')
	      ent++;
	    //	    int len = strlen(lineBuf);
	    int len = strlen(ent);
	    char* entEnd = ent + (len - 1);
	    //	    while (*entEnd == ' ' || *entEnd == '\r' || *entEnd == '\t')
	    while (*entEnd == ' ' || *entEnd == '\r' || *entEnd == '\t' || *entEnd == '}')
	      entEnd--;
	    *++entEnd = 0;
	    strncpy(n->oid, ent, 256);

	  }

	  if (isAssignment(lineBuf))
	  {
	    char* assign = strstr(lineBuf, "::=");
	    assign += 3;

	    while (*assign == ' ' || *assign == '\t')
		assign++;

	    //////////////////////
	    char* commentSpec = strstr(assign, "--");
	    if (commentSpec != NULL)
	      *commentSpec = 0;
	    //////////////////////
	    
	    char* assignEnd = assign + (strlen(assign) - 1);
	    while (*assignEnd == ' ' || *assignEnd == '\r' || *assignEnd == '\t')
	      assignEnd--;
	    *++assignEnd = 0;

	    strcat(n->oid, ".");	    
	    strcat(n->oid, assign);

	    n->insert(n);
	    break;
	  }

	  if (isVariableClause(lineBuf))
	  {
	    BOOL done = FALSE;
	    char* firstPosition;
	    char* lastPosition;
	    int currentCount;
	    int state = OPENCURLY;
	    int nextState;

	    while (!done)
	    {
	      switch (state)
	      {
	       case GETLINE:
		 {
		   memset(lineBuffer, 0, 4096);
		   lineBuf = lineBuffer;	
		   ifile->getline(lineBuffer, 4096);
		   count = ifile->gcount();
		   currentCount = 1;
		   state = nextState;
		   firstPosition = lineBuf;
		   break;
		 }
	     
	       case OPENCURLY:
		 {
		   firstPosition = lineBuf;
		   // find the opening curly brace
		   for (currentCount = 1; currentCount < count; currentCount++)
		   {
		     if (*firstPosition != '{')
		       firstPosition++;
		     else
		       break;
		   }
		   if (currentCount == count)
		   {
		     // look on next line
		     nextState = state;
		     state = GETLINE;
		   }
		   else
		   {
		     firstPosition++; 
		     currentCount++;
		     state = FINDVARBIND;
		   }
		   break;
		 }
	     
	       case FINDVARBIND:
		 {
		   // now skip white space to first varbind
		   for (; currentCount < count; currentCount++)
		   {
		     if (*firstPosition == ' ' || *firstPosition == '\t')
		       firstPosition++;
		     else
		       break;
		   }
		   if (currentCount == count)
		   {
		     nextState = state;
		     state = GETLINE;
		   }
		   else
		   {
		     // now find end of first varbind
		     lastPosition = firstPosition;
		     for (; currentCount < count; currentCount++)
		     {
		       if (*lastPosition != ' ' && *lastPosition != '\t' 
			   && *lastPosition != ',' && *lastPosition != '}')
			 lastPosition++;
		       else
			 break;
		     }
		     if (currentCount == count) // error
		     {
		       state = DONE;
		       break;
		     }
		   
		     char saveChar = *lastPosition;
		     *lastPosition = 0;
		     markInUse(firstPosition);
		     *lastPosition = saveChar;
		     if (saveChar == ',')
		     {
		       lastPosition++; 
		       currentCount++;
		     }
		     else
		       if (strchr(lastPosition, '}'))
			 state = DONE;
		     firstPosition = lastPosition;
		   }
		   break;
		 }
	     
	       case DONE:
		 done = TRUE;
		 break;
	      } // switch (state)
	    } // while (!done)
	  } // if (isVariableClause(lineBuf))	  
	} // while (1)
      } // if (isTrapType(lineBuf))
    }
    catch(...)
    {
      
    }
  }
  ifile->clear();
  ifile->seekg(0);
}
Exemplo n.º 3
0
int follow(float level, CONTOUR_POINT *point)
{
    int segment, start_heading, exitFace, adj, opp;
    float fadj,fopp;

    exitFace = CONTOUR_UNKNOWN;

    segment = -1;
    start_heading = point->heading;

    while (segment == -1)
    {
        /* SAVE PRESENT POINT IF VALID */

        if (savePoint(level,point))
        {

            /* HAS THE CONTOUR CLOSED */

            if (!(faceInUse(point,CONTOUR_SAME)))
            {
                markInUse(point);

                /* HAS THE CONTOUR REACHED AN EDGE */

                if (cellExists(point))
                {

                    /* COMPUTE THE EXIT FACE RELATIVE TO THE PRESENT FACE */

                    fadj = getDataPoint(point,CONTOUR_ADJACENT);
                    fopp = getDataPoint(point,CONTOUR_OPPOSITE);
                    adj = (fadj > level) ? 2 : 0;
                    opp = (fopp <= level) ? 1 : 0;
                    switch (adj+opp)
                    {
                        case 0:
                            exitFace = CONTOUR_OPPOSITE;
                            break;

                        case 1:
                            exitFace = CONTOUR_NEXT;
                            break;

                        case 2:
                            exitFace = CONTOUR_ADJACENT;
                            break;

                        case 3:
                            exitFace = getExit(level,point);
                            break;
                    }
                    if (exitFace == CONTOUR_UNKNOWN)
                    {
                        point->heading = start_heading;
                    }
                    else
                    {
                        point->heading = (point->heading + exitFace + 2) % 4;
                    }
          
                    /* UPDATE THE INDEXES BASE ON THE NEW HEADING */

                    switch (point->heading)
                    {
                        case CONTOUR_EAST:
                            point->x++;
                            break;

                        case CONTOUR_NORTH:
                            point->y++;
                            break;

                        case CONTOUR_WEST:
                            point->x--;
                            break;

                        case CONTOUR_SOUTH:
                            point->y--;
                            break;
                    }
                }
                else
                {
                    /* CONTOUR HAS REACHED AN EDGE, EXIT */

                    segment = CONTOUR_FALSE;
                }
            }
            else
            {
                /* CONTOUR HAS CLOSED, EXIT */
                segment = CONTOUR_FALSE;
            }
        }
        else
        {
            /* CONTOUR IS SEGMENTED BY INVALID DATA OR MAX CONTOUR POINTS */
            segment = CONTOUR_TRUE;
        }
    }
    return segment;
}
void Accidentals::calcChord()
{
	// init
	for (int i=0; i<stPerOct; i++) {
		// only naturals are available
		if (notes_sharp[i].length() == 1) {
			notes_av[i] = true;
		} else {
			notes_av[i] = false;
		}
		// default new_acc_state = old_acc_state
		new_acc_state[i] = old_acc_state[i];
		// init root note (dummy value)
		out_root_note[i] = 0;
		// init accidentals
		out_accidental[i] = Natural;
	}
	// pass 1: handle naturals
	// loop over all requested notes
	for (int i=0; i<stPerOct; i++) {
		// if note needed
		if (notes_req[i]) {
			// if note is a natural
			if (notes_sharp[i].length() == 1) {
				markInUse(i, i, Natural);
			}
		}
	}
	// pass 2: handle accidentals
	// loop over all requested notes
	for (int i=0; i<stPerOct; i++) {
		// if note needed
		if (notes_req[i]) {
			// if note is not a natural
			if (notes_sharp[i].length() != 1) {
				int nl = normalize(i - 1);	// lower note to try
				int nh = normalize(i + 1);	// higher note to try
				// first check of this pitch is already available
				// i.e. lower note available and acc_state is Sharp
				// or higher note available and acc_state is Flat
				if (notes_av[nl] && (old_acc_state[nl] == Sharp)) {
					// lower note: F# requested, F# used in previous chord
					markInUse(i, nl, Sharp);
				} else if (notes_av[nh] && (old_acc_state[nh] == Flat)) {
					// higher note: F# requested, Gb used in previous chord
					markInUse(i, nh, Flat);
				// pitch is not already available, make it
				} else if (notes_av[nl]) {
					// lower note: if F# req, if F av. use F + #
					markInUse(i, nl, Sharp);
				} else if (notes_av[nh]) {
					// higher note: if F# req, if G av. use G + b
					markInUse(i, nh, Flat);
				} else {
					// special case:
					// F# req, both F and G already used
					// for F use F + natural, for F# use F + #
					// new_acc_state is natural
					out_accidental[nl] = Natural;	// explicit natural
					out_root_note[i]   = nl;		// note name to use
					out_accidental[i]  = Sharp;
					new_acc_state[nl]  = Natural;
		        }
			}
		}
	}

	// copy new_acc_state into old_acc_state
	// set required "need accidental" flags
	for (int i=0; i<stPerOct; i++) {
		old_acc_state[i] = new_acc_state[i];
		if (notes_req[i] && (out_accidental[i] != None)) {
			naSetAll(notes_sharp[out_root_note[i]]);
		}
	}
}