Пример #1
0
char *parsefilearg( int argcount, char *args[])
{
  int i;
  char *result = NULL;

   for (i = 1; i < argcount; i++)
   {
      if (args[i][0] != '\0' &&
	  (!isoptionchar (args[i][0]) || args[i][1] == '\0' ))
      {
	/*---------------------------------------------*
	 * The argument is a filename:                 *
	 * it is either no dash followed by something, *
	 * or it is a dash following by nothing.       *
	 *---------------------------------------------*/
	result = malloc( strlen( args[i]) + 1);
	if (result == NULL)
	    fatalperror( "Couldn't allocate memory for filename\n");
	strcpy( result, args[i]);
	args[i][0] = '\0';                    /* Mark as used up */
	break;
      }
   }
   return result;
}
Пример #2
0
/* --------------------------------------------------------------------
   Returns the index 'i' of the first argument that IS an option, and
   which begins with the label 's'. If there is none, -1.
   We also mark that option as done with, i.e. we cross it out.
   -------------------------------------------------------------------- */
int findoption( int argcount, char *args[], char *s)
{
   int i;

   if (test_usage)
     printf("Checking for option -%s\n", s);

   for (i=1; i<argcount; i++)
   {
     if (isoptionchar (args[i][0]) &&
	 strncmp( args[i] + 1, s, strlen( s)) == 0)
       {
	 args[i][0] = '\0';
	 return i;
       }
   }
   return -1;
}
Пример #3
0
/** \brief
 *
 *  \param ctx
 *  \param fp
 *
 *  \return Number of options set
 */
int iniread_file(configctx_t *ctx, FILE *fp)
{
    char        buffer[LIBINI_LINE_MAX];
    char       *start,*ptr;
    int         ret = 0;
    
    while (fgets(buffer,sizeof(buffer),fp) != NULL ) {
        start = skpws(buffer);
        if ( *start == ';' || *start =='#' || *start ==0)
            continue;
        if ( *start == '[' ) {
            get_section(ctx, start);
        } else {        /* Must be an option! */
            ptr = start;
            while ( isoptionchar(*ptr) )
                ptr++;
            if ( *ptr == '=' ) {
                *ptr++ = 0;
            } else {
                *ptr++ = 0;
                /* Search for the '=' now */
                if ( (ptr = strchr(ptr,'=') ) == NULL ) {
                    continue;
                }
                ptr++;
            }

            ptr = skpws(ptr); /* Skip over any white space */
            if ( *ptr == ';' || *ptr =='#' || *ptr ==0 ) {
                continue;
            }
            if ( strlen(start) ) {
                if ( option_set(ctx, start,ptr) >= 0 ) {
                    ret++;
                }
            }
        }
    }
    return ret;
}