Ejemplo n.º 1
0
/*
 * Handle one line.  Returns 0 if at EOF, and a positive value if there's
 * more data to handle.
 */
static int do_line( FILE *infile, FILE *miffile, char *outdir )
/*************************************************************/
{
    static int          curline;
    char                line[1024];
    char *              p;
    int                 numwords;
    char **             words;
    struct Alias        alias;
    int                 count;

    /*** Prepare the next line ***/
    p = fgets( line, 1024, infile );
    if( p == NULL ) {
        if( ferror( infile ) ) {
            FatalError( "Error reading line %d", curline );
        } else if( feof( infile ) ) {
            return( 0 );
        } else {
            Zoinks();
        }
    }
    if( line[0] == '#' ) {
        curline++;
        return( 2 );                    /* skip comment lines */
    }

    /*** Extract the individual words ***/
    numwords = parse_words( line, NULL );
    if( numwords == -1 ) {
        FatalError( "Error on line %d", curline );
        return( -1 );
    }
    if( numwords == 0 ) {               /* skip blank lines */
        curline++;
        return( 2 );
    }
    words = (char **)AllocMem( (numwords+1) * sizeof(char*) );
    numwords = parse_words( line, words );
    if( numwords < 4 ) {
        FatalError( "Error on line %d", curline );
        return( -1 );
    }

    /*** Construct an Alias structure and create the alias ***/
    alias.filename = words[0];
    alias.realname = words[1];
    alias.aliasname = words[2];
    alias.systems = NULL;
    for( count=3; words[count]!=NULL; count++ ) {   /* build system list */
        add_system( &alias, words[count] );
    }
    do_alias( miffile, &alias, outdir );

    curline++;
    return( 1 );
}
Ejemplo n.º 2
0
static int spawn_it( FILE *fp, const CHAR_TYPE *command )
/*******************************************************/
{
    int                 pid;
    int                 numWords;
    CHAR_TYPE           **words;    /* note: [0] and [1] used for "cmd.exe /c" */

    /*** Create an argv array from the command string ***/
    numWords = parse_words( command, NULL );
    if( numWords == -1 ) {
        return( 0 );
    }
    words = alloca( (numWords + 2 + 1) * sizeof( CHAR_TYPE * ) );
    if( words == NULL ) {
        return( 0 );
    }
    numWords = parse_words( command, &words[2] );
    if( numWords == -1 ) {
        return( 0 );
    }

    /*** Use CMD.EXE under NT and OS/2, and COMMAND.COM under Win95 ***/
#if defined( __OS2__ )
    words[0] = __F_NAME("cmd.exe",L"cmd.exe");
#else
    if( WIN32_IS_WIN95 ) {
        words[0] = __F_NAME("command.com",L"command.com");  /* 95 */
    } else {
        words[0] = __F_NAME("cmd.exe",L"cmd.exe");          /* NT */
    }
#endif
    words[1] = __F_NAME("/c",L"/c");

    /*** Spawn the process ***/
    pid = __F_NAME(spawnvp,_wspawnvp)( P_NOWAIT, words[0],
        (const CHAR_TYPE **)&words[0] );
    if( pid == -1 ) {
        return( 0 );
    }
    _FP_PIPEDATA(fp).pid = pid;

    /*** Free any memory used by parse_words ('words' freed on return) ***/
    for( numWords--; numWords>=2; numWords-- ) {
        lib_free( words[numWords] );
    }
    return( 1 );
}
Ejemplo n.º 3
0
static struct source *source_ptp_parse(char *parameter, char **settings)
{
	char *name, *value;
	struct source *source;
	int r = 0;

	source = xmalloc(sizeof(*source));
	source->type = PTP_DOMAIN;
	source->ptp.delay = DEFAULT_PTP_DELAY;
	source->ptp.ntp_poll = DEFAULT_PTP_NTP_POLL;
	source->ptp.phc2sys_poll = DEFAULT_PTP_PHC2SYS_POLL;
	source->ptp.interfaces = (char **)parray_new();
	source->ptp.ptp4l_settings = (char **)parray_new();
	source->ptp.ntp_options = xstrdup("");

	if (parse_int(parameter, &source->ptp.domain)) {
		pr_err("invalid ptp_domain number %s", parameter);
		goto failed;
	}

	for (; *settings; settings++) {
		parse_setting(*settings, &name, &value);
		if (!strcasecmp(name, "delay")) {
			r = parse_double(value, &source->ptp.delay);
		} else if (!strcasecmp(name, "ntp_poll")) {
			r = parse_int(value, &source->ptp.ntp_poll);
		} else if (!strcasecmp(name, "phc2sys_poll")) {
			r = parse_int(value, &source->ptp.phc2sys_poll);
		} else if (!strcasecmp(name, "ptp4l_option")) {
			parray_append((void ***)&source->ptp.ptp4l_settings,
				      xstrdup(value));
		} else if (!strcasecmp(name, "ntp_options")) {
			replace_string(value, &source->ptp.ntp_options);
		} else if (!strcasecmp(name, "interfaces")) {
			parse_words(value, &source->ptp.interfaces);
		} else {
			pr_err("unknown ptp_domain setting %s", name);
			goto failed;
		}

		if (r) {
			pr_err("invalid value %s for %s", value, name);
			goto failed;
		}
	}

	if (!*source->ptp.interfaces) {
		pr_err("no interfaces specified for ptp_domain %d",
		       source->ptp.domain);
		goto failed;
	}

	return source;
failed:
	source_destroy(source);
	return NULL;
}
Ejemplo n.º 4
0
TokenState::TokenState(const simple::string& prototype) :
    words(parse_words(prototype))
{
    cursor = 0;
    end = words.size();

    for (auto it = words.begin(); it != words.end(); ++it)
        printf("%zd. %s\n", it.get_index(), it->c_str());////----
}
Ejemplo n.º 5
0
void impl( char * filename)
{
	FILE * f = fopen(filename,"rb");
	char * line[0];
	ordered_tree_str_t * doc = ordered_tree_str_new("");
	int lineno = 0;
	while( read_line(line,1024,f) != -1)
	{
		lineno++;
		parse_words(doc,line,lineno);
	}
	ordered_tree_str_traverse(doc,print_ordered_tree_str);
	ordered_tree_str_free(doc);
}
Ejemplo n.º 6
0
static int parse_program_settings(char **settings,
				  struct program_config *config)
{
	char *name, *value;

	for (; *settings; settings++) {
		parse_setting(*settings, &name, &value);
		if (!strcasecmp(name, "path")) {
			replace_string(value, &config->path);
		} else if (!strcasecmp(name, "options")) {
			parse_words(value, &config->options);
		} else {
			pr_err("unknown program setting %s", name);
			return 1;
		}
	}

	return 0;
}