Пример #1
0
static double
bound (FILE * stream, int mode)
{				//this function calculates the upper or lower bound from a file or stdin depending on the argument
  double lowerBound = 0.;
  double upperBound = 0.;
  double number = 0.;
  int test;
  if ((test = fscanf (stream, "%lf", &number)) != EOF)
    {
      if (!test)
	skipWord (stream);
      lowerBound = number;
      upperBound = number;
    }
  while ((test = fscanf (stream, "%lf", &number)) != EOF)
    {
      if (!test)
	skipWord (stream);
      if (number > upperBound)
	upperBound = number;
      if (number < lowerBound)
	lowerBound = number;
      if (fscanf (stream, "%lf", &number) != EOF)
	{
	}
    }
  if (mode == 1)
    return lowerBound;
  else
    return upperBound;
}
Пример #2
0
Файл: vim.c Проект: Monits/ctags
static boolean parseVimLine (const unsigned char *line, int infunction)
{
	boolean readNextLine = TRUE;

	if (wordMatchLen (line, "command", 3))
	{
		readNextLine = parseCommand(line);
		/* TODO - Handle parseCommand returning FALSE */
	}

	else if (isMap(line))
	{
		parseMap(skipWord(line));
	}

	else if (wordMatchLen (line, "function", 2))
	{
		parseFunction(skipWord(line));
	}

	else if	(wordMatchLen (line, "augroup", 3))
	{
		parseAutogroup(skipWord(line));
	}

	else if (wordMatchLen (line, "let", 3))
	{
		parseLet(skipWord(line), infunction);
	}

	return readNextLine;
}
Пример #3
0
Файл: vim.c Проект: Monits/ctags
static void parseAutogroup (const unsigned char *line)
{
	vString *name = vStringNew ();

	/* Found Autocommand Group (augroup) */
	const unsigned char *cp = line;
	if (isspace ((int) *cp))
	{
		while (*cp && isspace ((int) *cp))
			++cp; 

		if (*cp)
		{
			const unsigned char *end = skipWord (cp);

			/* "end" (caseless) has a special meaning and should not generate a tag */
			if (end > cp && strncasecmp ((const char *) cp, "end", end - cp) != 0)
			{
				vStringNCatS (name, (const char *) cp, end - cp);
				vStringTerminate (name);
				makeSimpleTag (name, VimKinds, K_AUGROUP);
				vStringClear (name);
			}
		}
	}
	vStringDelete (name);
}
Пример #4
0
static double
column (FILE * stream, int *tab)
{				// this function print out the sum of each column.
  double *tabNumber = NULL;
  double number;
  int lengthTab = 1, countMax = 0, count = 0;
  int test, i, j = 0, col = 1;
  if (!(tabNumber = (double *) calloc (1, sizeof (double))))
    {
      perror ("num-utils-ng");
      return EXIT_FAILURE;
    }
  while ((test = fscanf (stream, "%lf", &number)) != EOF)
    {
      if (!test)
	skipWord (stream);
      if (count == lengthTab)
	{
	  lengthTab *= 2;
	  if (!
	      (tabNumber =
	       (double *) realloc (tabNumber, lengthTab * sizeof (double))))
	    {
	      perror ("num-utils-ng");
	      return EXIT_FAILURE;
	    }
	}
      if (fgetc (stream) != '\n')
	{
	  tabNumber[count] += number;
	  count++;

	}
      else
	{
	  if (count >= countMax)
	    countMax = count;
	  tabNumber[count] += number;
	  count = 0;
	}
    }
  for (i = 0; i < countMax + 1; i++)
    {
      if (!tab || (col == tab[j]))
	{
	  printf ("%lf\n", tabNumber[i]);
	  j++;
	}
      col++;
    }
  free (tabNumber);
  return 0;
}
void makeRaPai(boolean isEst, char *raName, char *outName)
/* Make pair file. */
{
struct lineFile *lf = lineFileOpen(raName, TRUE);
static char acc[256];
static char clo[512];
static char dir[16];
int lineSize;
char *line;

printf("processing %s", raName);
fflush(stdout);
while (lineFileNext(lf, &line, &lineSize))
    {
    if ((lf->lineIx & 0xffff) == 0)
	{
	printf(".");
	fflush(stdout);
	}
    if (lineSize <=  2)  /* Blank line */
	{
	if (isEst)
	    addEst(lf, acc, clo, dir);
	else
	    addBac(lf, acc, clo);
	acc[0] = clo[0] = dir[0] = 0;
	}
    else if (startsWith("acc", line))
	strcpy(acc, skipWord(line));
    else if (startsWith("clo", line))
	strcpy(clo, skipWord(line));
    else if (startsWith("dir", line))
	strcpy(dir, skipWord(line));
    }
slReverse(&pairList);
printf("\n");
lineFileClose(&lf);
}
Пример #6
0
static double
row (FILE * stream, int *tab)
{				// this function print ou the sum of each row or specified row.
  double somme = 0., number;
  int test, line = 1, i = 0;
  while ((test = fscanf (stream, "%lf", &number)) != EOF)
    {
      if (!test)
	skipWord (stream);
      if (!tab)
	{
	  if (fgetc (stream) == '\n')
	    {
	      somme += number;
	      printf ("%lf \n", somme);
	      somme = 0.;
	      number = 0.;
	    }
	  somme += number;
	}
      else
	{
	  if (line == tab[i])
	    {
	      somme += number;
	    }
	  if (fgetc (stream) == '\n')
	    {
	      if (line == tab[i])
		{
		  i++;
		  printf ("%lf \n", somme);
		}
	      line++;
	      somme = 0.;
	      number = 0.;
	    }
	}
    }
  return 0;
}
Пример #7
0
static int
numgrep (FILE * stream, char expression[])
{
  int numberRead, number1, number2;
  int j;
  size_t i, count = 0;
  char *token;
  char *savestr = NULL;
  char *str;
  char **tab = NULL;
  int test;

  for (i = 0; i < strlen (expression); i++)
    {
      switch (expression[i])
	{
	case '/':
	  expression[i] = ',';
	  break;
	case '.':
	  break;
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
	  break;
	case '-':
	  break;
	case 'f':
	  break;
	case 'm':
	  break;
	case ',':
	  count++;
	  break;
	default:
	  return EXIT_SUCCESS;
	}
    }
  if (!(tab = (char **) calloc (count + 1, sizeof (char *))))
    {
      perror ("num-utils-ng");
      return EXIT_FAILURE;
    }
  for (i = 0, str = expression;; i++, str = NULL)
    {
      token = strtok_r (str, ",", &savestr);
      if (token == NULL)
	break;
      *(tab + i) = token;
    }

  while ((test = fscanf (stream, "%d", &numberRead)) != EOF)
    {
      if (!test)
	skipWord (stream);
      for (i = 0; i <= count; i++)
	{

	  if (strstr (*(tab + i), "f") != NULL)
	    {
	      sscanf (*(tab + i), "f%d", &number1);
	      if ((number1 >= numberRead) && (number1 % numberRead == 0))
		printf ("%d\n", numberRead);
	    }

	  else if (strstr (*(tab + i), "m") != NULL)
	    {
	      sscanf (*(tab + i), "m%d", &number1);
	      if ((numberRead >= number1) && (numberRead % number1 == 0))
		printf ("%d\n", numberRead);
	    }

	  else if (strstr (*(tab + i), "..") != NULL)
	    {
	      sscanf (*(tab + i), "%d..%d", &number1, &number2);
	      if (number1 < number2)
		{
		  for (j = number1; j <= number2; j++)
		    {
		      if (numberRead == j)
			printf ("%d\n", numberRead);
		    }
		}
	    }

	  else
	    {
	      sscanf (*(tab + i), "%d", &number1);
	      if (numberRead == number1)
		printf ("%d\n", numberRead);
	    }
	}
    }
  free (tab);
  return EXIT_SUCCESS;
}
Пример #8
0
Файл: vim.c Проект: Monits/ctags
static boolean parseCommand (const unsigned char *line)
{
	vString *name = vStringNew ();
	boolean cmdProcessed = TRUE;

	/* 
	 * Found a user-defined command 
	 *
	 * They can have many options preceeded by a dash
	 * command! -nargs=+ -complete Select  :call s:DB_execSql("select " . <q-args>)
	 * The name of the command should be the first word not preceeded by a dash
	 *
	 */
	const unsigned char *cp = line;

	if ( cp && ( (int) *cp == '\\' ) ) 
	{
		/*
		 * We are recursively calling this function is the command
		 * has been continued on to the next line
		 *
		 * Vim statements can be continued onto a newline using a \
		 * to indicate the previous line is continuing.
		 *
		 * com -nargs=1 -bang -complete=customlist,EditFileComplete
		 * 			\ EditFile edit<bang> <args>
		 *
		 * If the following lines do not have a line continuation
		 * the command must not be spanning multiple lines and should
		 * be synatically incorrect.
		 */
		if ((int) *cp == '\\')
			++cp;

		while (*cp && isspace ((int) *cp))
			++cp; 
	}
	else if ( line && wordMatchLen (cp, "command", 3) )
	{
		cp = skipWord (cp);

		if ((int) *cp == '!')
			++cp;

		if ((int) *cp != ' ')
		{
			/*
			 * :command must be followed by a space.  If it is not, it is 
			 * not a valid command.
			 * Treat the line as processed and continue.
			 */
			cmdProcessed = TRUE;
			goto cleanUp;
		}

		while (*cp && isspace ((int) *cp))
			++cp; 
	} 
	else 
	{
		/*
		 * We are recursively calling this function.  If it does not start
		 * with "com" or a line continuation character, we have moved off
		 * the command line and should let the other routines parse this file.
		 */
		cmdProcessed = FALSE;
		goto cleanUp;
	}

	/*
	 * Strip off any spaces and options which are part of the command.
	 * These should preceed the command name.
	 */
	do
	{
		if (isspace ((int) *cp))
		{
			++cp;
		}
		else if (*cp == '-')
		{
			/* 
			 * Read until the next space which separates options or the name
			 */
			while (*cp && !isspace ((int) *cp))
				++cp; 
		}
		else if (!isalnum ((int) *cp))
		{
			/*
			 * Broken syntax: throw away this line
			 */
			cmdProcessed = TRUE;
			goto cleanUp;
		}
	} while ( *cp &&  !isalnum ((int) *cp) );

	if ( ! *cp )
	{
		/*
		 * We have reached the end of the line without finding the command name.
		 * Read the next line and continue processing it as a command.
		 */
		if ((line = readVimLine ()) != NULL)
			cmdProcessed = parseCommand(line);
		else
			cmdProcessed = FALSE;
		goto cleanUp;
	}

	do
	{
		vStringPut (name, (int) *cp);
		++cp;
	} while (isalnum ((int) *cp)  ||  *cp == '_');

	vStringTerminate (name);
	makeSimpleTag (name, VimKinds, K_COMMAND);
	vStringClear (name);

cleanUp:
	vStringDelete (name);

	return cmdProcessed;
}
static char *getPragmaStr(char *p)
{
  return skipBlank(skipWord(skipBlank(skipSharp(skipBlank(p)))));
}
Пример #10
0
bool GeekBind::KeyBind::set(const char *keybind)
{
    int i = 0;
    len = 0;
    i = skipWhiteSpace(keybind, i);
    while(keybind[i])
    {
        mod[len] = 0;
        while (keybind[i] && keybind[i+1] == '-')
        {
            switch (keybind[i])
            {
            case 'C':
            case 'c':
                mod[len] |= GeekBind::CTRL;
            break;
            case 'M':
            case 'm':
                mod[len] |= GeekBind::META;
            break;
            case 'S':
            case 's':
                mod[len] |= GeekBind::SHIFT;
            break;
            default:
                return false;
            };
            i+=2;
        }
        i = skipWhiteSpace(keybind, i);
        if (keybind[i] == '#' && //is params
            keybind[i+1] != ' ' && // no '#'
            keybind[i+1] != '\0')
        {
            if (len == 0) // params w/o keybind
                return false;
            const char *str = keybind + i;
            params = std::string(str);
            return true;
        }
        int wordend = skipWord(keybind, i);
        if (wordend - i == 1) // char
        {
            c[len] = keybind[i];
            if (isupper(keybind[i])) // no upper case, just S-
            {
                c[len] = tolower(c[len]);
                mod[len] |= SHIFT;
            }
            // clear shit for some spec chars
            if (strchr(nonShiftChars, c[len]))
                mod[len] &= ~GeekBind::SHIFT;
        }
        else // key name
        {
            int ii=0;
            const char *str = keybind + i;
            bool found = false;
            while(keyNames[ii].keyName)
            {
                if (!strncmp(keyNames[ii].keyName, str, strlen(keyNames[ii].keyName)))
                {
                    c[len] = keyNames[ii].ckey;
                    found = true;
                    break;
                }
                ii++;
            }
            if (!found)
                return false;
        }
        if (len == MAX_KEYBIND_LEN)
            break;
        len++;

        i = wordend;
        if (!keybind[i])
            break;

        i = skipWhiteSpace(keybind, i+1);
        if (!keybind[i])
            break;
    }
    return true;
}