コード例 #1
0
ファイル: test_parse.c プロジェクト: mysidia/snservices1
int
main(int argc, char **argv)
{
	char *ts;
	char *ts1;
	char *ts2;
	char *ts3;
	char *arg;
	parse_t p;
	int n;

	n = 0;
	ts = strings[0];

	while (ts != NULL) {
		ts1 = strdup(ts);  /* strings might not be writable, so */
		ts2 = strdup(ts);  /* save away a few copies */
		ts3 = strdup(ts);

		printf("Parsing '%s'\n", ts1);
		parse_init(&p, ts1);
		while ((arg = parse_getarg(&p)) != NULL)
			printf("\tgetarg: '%s'\n", arg);
		parse_cleanup(&p);

		printf("Parsing '%s'\n", ts2);
		parse_init(&p, ts2);
		arg = parse_getarg(&p);
		if (arg != NULL) {
			printf("\tgetarg: '%s'\n", arg);
			arg = parse_getallargs(&p);
			if (arg != NULL)
				printf("\tallarg: '%s'\n", arg);
		}
		parse_cleanup(&p);
	    
		printf("Parsing '%s'\n", ts3);
		parse_init(&p, ts3);
		arg = parse_getallargs(&p);
		if (arg != NULL) {
			printf("\tallarg: '%s'\n", arg);
		}
		parse_cleanup(&p);

		n++;
		ts = strings[n];
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: hsk/docs
int
parse_input(FILE* f)
{
  parse_init();
  yyrestart(f);
  return yyparse();
}
コード例 #3
0
ファイル: parse.c プロジェクト: JeremShy/21sh
t_cmd			*parse(char *str, t_hc *heredocs, t_env **env, t_data *data)
{
	size_t		i;
	t_cmd		fake_cmd;
	t_cmd		*last;

	parse_init(data, &i, &heredocs);
	if (is_pipe_error(str))
		return (NULL);
	data->history = add_history_elem(data->history, create_history_elem(str));
	while (str[i])
	{
		count_and_init_command(data, &fake_cmd, str, &i);
		if (data->parse_count == -1)
			return (free_cmd_and_return(data));
		if (data->parse_count && !add_command(data, str, &i, env))
			return (NULL);
	}
	if (!data->command)
		return (NULL);
	last = data->command;
	while (last->next)
		last = last->next;
	return (data->command);
}
コード例 #4
0
ファイル: main.c プロジェクト: hsk/docs
int
parse_input(parser_state* p, FILE* f)
{
  parse_init(p);
  yyrestart(f);
  return yyparse(p);
}
コード例 #5
0
ファイル: main.c プロジェクト: hsk/docs
int
parse_string(parser_state* p, const char* prog)
{
  parse_init(p);
  yy_scan_string(prog);
  return yyparse(p);
}
コード例 #6
0
ファイル: redir_source.c プロジェクト: rsenn/shish
/* process all here-docs
 * 
 * nredir->data is set to the next here-doc redirection by redir_addhere()
 * after processing it is set to the content of the here-doc (an narg node)
 * ----------------------------------------------------------------------- */
void redir_source(void) {
  struct parser p;
  stralloc delim;
  int r;
    
  parse_init(&p, P_HERE);
      
  stralloc_init(&delim);
  
  for(; redir_list; redir_list = &redir_list->data->nredir) {
    /* expand the delimiter */
    stralloc_init(&delim);
    expand_catsa((union node *)redir_list, &delim, 0);
    
    /* when any character of the delimiter has been escaped
       then treat the whole here-doc as non-expanded word */
    r = parse_here(&p, &delim, (redir_list->list->nargstr.flag & S_ESCAPED));
    
    tree_free(redir_list->list);
    redir_list->list = parse_getarg(&p);
    
    /* free expanded delimiters */
    stralloc_free(&delim);
  }
}
コード例 #7
0
ファイル: main.c プロジェクト: hsk/docs
int
parse_string(const char* prog)
{
  parse_init();
  yy_scan_string(prog);
  return yyparse();
}
コード例 #8
0
ファイル: setkey.c プロジェクト: IIJ-NetBSD/netbsd-src
static void
stdin_loop(void)
{
	char line[1024], *semicolon, *comment;
	size_t linelen = 0;

	memset(line, 0, sizeof(line));

	parse_init();
	while (1) {
#ifdef HAVE_READLINE
		char *rbuf;
		rbuf = readline("");
		if (!rbuf)
			break;
#else
		char rbuf[1024];
		rbuf[0] = '\0';
		if (fgets(rbuf, sizeof(rbuf), stdin) == NULL)
			break;
		if (rbuf[strlen(rbuf)-1] == '\n')
			rbuf[strlen(rbuf)-1] = '\0';
#endif
		comment = strchr(rbuf, '#');
		if (comment)
			*comment = '\0';

		if (!rbuf[0])
			continue;

		linelen += snprintf(&line[linelen], sizeof(line) - linelen,
		    "%s%s", linelen > 0 ? " " : "", rbuf);

		semicolon = strchr(line, ';');
		while (semicolon) {
			char saved_char = *++semicolon;
			*semicolon = '\0';
#ifdef HAVE_READLINE
			add_history(line);
#endif

#ifdef HAVE_PFKEY_POLICY_PRIORITY
			last_msg_type = -1;  /* invalid message type */
#endif

			parse_string(line);
			if (exit_now)
				return;
			if (saved_char) {
				*semicolon = saved_char;
				linelen = strlen(semicolon);
				memmove(line, semicolon, linelen + 1);
				semicolon = strchr(line, ';');
			} else {
				semicolon = NULL;
				linelen = 0;
			}
		}
	}
}
コード例 #9
0
ファイル: parser.c プロジェクト: mercurycc/cs452
int parse_fill( char* str, char delim, char** tokens, int size, int* filled )
{
	Parse parse;

	parse_init( &parse, str, delim );

	return parse_token_fill( &parse, tokens, size, filled );
}
コード例 #10
0
ファイル: main-b.c プロジェクト: TXing123/prog1
int
main(int argc, char *argv[])
{
	int quiet = 0;
	char input[BUFSIZ];
	int r = 0;

	// Check for '-q' option: be quiet -- print no prompts
	if (argc > 1 && strcmp(argv[1], "-q") == 0)
		quiet = 1;
	signal(SIGCHLD,signal_handler);
	while (!feof(stdin)) {
		parsestate_t parsestate;
		command_t *cmdlist;
		// Print the prompt
		if (!quiet) {
			printf("prog1$ ");
			fflush(stdout);
		}

		// Read a string, checking for error or EOF
		if (fgets(input, BUFSIZ, stdin) == NULL) {
			if (ferror(stdin))
				// This function prints a description of the
				// error, preceded by 'cs111_fall07: '.
				perror("prog1");
			break;
		}

		// TODO: invoke some function(s) in cmdline.c for parsing the read string.
		parse_init(&parsestate,input);
		cmdlist=command_line_parse(&parsestate,0);

		if (!cmdlist) {
			printf("Syntax error\n");
			continue;
		}

		// print the command list
		if (!quiet) {
			// TODO: invoke some function(s) in cmdline.c for printing out the command for debugging.
			command_print(cmdlist,1);
			// why do we need to do this?
			fflush(stdout);
		}

		// and run it!
		int not_impotant=0;
		waitpid(-1,&not_impotant,WNOHANG);//kill zombies
		if (cmdlist)
			command_line_exec(cmdlist);
		if (cmdlist)
			command_free(cmdlist);

	}

	return 0;
}
コード例 #11
0
ファイル: variable.c プロジェクト: mkschreder/memwatch
int VariablePath_compile(VariablePath *self, const char *str){
	parser_t parser;
	token_t token;

	//Parse the expression
	parse_init(&parser, str);
	
	VariablePath_free(self);
	VariablePath_init(self);

	return parse_VariablePath(self, &parser, &token);
}
コード例 #12
0
ファイル: link_extractor.c プロジェクト: mneumann/cryl
VALUE
LinkExtractor__parse(VALUE self, VALUE filename)
{
  int fh, cont;
  void *p;
  off_t len;
  struct parse_state s;
  VALUE str;

  fh = open(RSTRING_PTR(filename), O_RDONLY);
  if (fh == -1)
  {
    return Qfalse;
  }

  len = lseek(fh, 0, SEEK_END); 
  if (len == -1)
  {
    close(fh);
    return Qfalse;
  }
  if (lseek(fh, 0, SEEK_SET) != 0)
  {
    close(fh);
    return Qfalse;
  }

  p = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fh, 0);
  if (p == MAP_FAILED)
  {
    close(fh);
    return Qfalse;
  }

  parse_init(&s, (char*)p, (char*)p+len, href_buf, HREF_BUF_SIZE-2);

  while (1)
  {
    cont = parse(&s);
    if (s.copy_buf_pos > 0)
    {
      str = rb_str_new(s.copy_buf, s.copy_buf_pos);
      rb_yield(str);
      s.copy_buf_pos = 0;
    }
    if (!cont) break;
  }

  munmap(p, len);
  close(fh);

  return Qtrue;
}
コード例 #13
0
ファイル: main.c プロジェクト: gerard-geer/GimmickShader
int main(int argc, char **argv)
{
	if (argc < 2)
	{
		printf("Usage: tracker (trackfile)\n");
		return 0;
	}
	if (parse_init(argv[1]))
	{
		read_loop();
	}
	return 0;
}
コード例 #14
0
ファイル: parse.c プロジェクト: jobol/smaunch
int parse_init_open(struct parse *parse, const char *path)
{
	int file;

	assert(parse);

	file = open(path, O_RDONLY);
	if (file < 0)
		return -errno;

	parse_init(parse, file);
	return 0;
}
コード例 #15
0
int parse_file(char *param_file)
{

	struct params *params;
        FILE *fd = fopen(param_file, "r");
	uint32_t file_size;
	char *buf;
	int i;	

        if(!fd)
        {
                PANEL_DEBUG("%s : Failed to open %s\n", __func__, param_file);
                return -1;
        }

	fseek(fd, 0, SEEK_END);
	file_size = ftell(fd);
	buf = (char *)malloc(file_size);
	fseek(fd, 0, SEEK_SET);
	fread(buf, file_size, 1, fd);
        fclose(fd);
	
	PANEL_DEBUG("Init sequence:\n%s\n", buf);


	parse_init(&params);
	parse_sequence(buf);

	PANEL_DEBUG("/**********  end of parse  **********/\n");	

	for(i = 0; i < params->line_nr; i++)
	{
		struct lcd_param *p;
		if(p = params->params[i])
		{
			int j;
			_PANEL_DEBUG("%d,0x%x,", p->delay, p->cmd);
			for(j = 0; j < p->data_len; j++)
				_PANEL_DEBUG("0x%x,", p->data[j]);
			_PANEL_DEBUG("\n");
		}

	}


	parse_deinit(params);


	
	return 0;
}
コード例 #16
0
ファイル: db.c プロジェクト: mysidia/snservices1
/**
 * \pre  fp Points to an open outfile in which a multi-line dbString is
 *       to be written.  Str points to a valid NUL-terminated character
 *       array.
 */
static void dbWriteString(FILE *fp, const char *istr)
{
	char *p, *str;
	parse_t lineSplit;

	str = str_dup(istr);
	assert(parse_init(&lineSplit, str) == 0);
	lineSplit.delim = '\n';

	while((p = parse_getarg(&lineSplit))) {
		fprintf(fp, "%s~\n", p);
	}
	fprintf(fp, "~$\n");
	parse_cleanup(&lineSplit);
	FREE(str);
}
コード例 #17
0
ファイル: parse.c プロジェクト: jobol/smaunch
int main(int argc, char **argv)
{
	struct parse parse;
	parse_init(&parse, 0);
	while(!parse.finished) {
		int sts = parse_line(&parse);
		int i;
		if (sts)
			printf("error %d\n",sts);
		else {
			printf("ok l=%d k=%d b=%d f=%d:",parse.lino,parse.fieldcount, parse.begsp, parse.finished);
			for (i = 0 ; i < parse.fieldcount ; i++)
				printf(" %d='%s'",i+1,parse.fields[i]);
			printf("\n");
		}
	}
	return 0;
}
コード例 #18
0
ファイル: parse.c プロジェクト: junjie18/myshell
int parsing(char **param,int count,struct parse_info *parse){
    parse_init(parse);

    int j;
    //for(j=0;j<count;j++) printf("%s\n",param[j]);

    if(!strcmp(param[count-1],"&")){
        parse->flag |= BACKGROUND;
        param[count-1]=NULL;
        count--;
    }
    int i=0;
    while(i<count){
        if(!strcmp(param[i],"<<") || !strcmp(param[i],"<")){
            parse->flag |= IN_REDIRECT;
            parse->in_file = param[i+1];
            param[i]=NULL;
            i+=2;
        }
        else if(!strcmp(param[i],">")){
            parse->flag |= OUT_REDIRECT;
            parse->out_file = param[i+1];
            param[i]=NULL;
            i+=2;
        }
        else if(!strcmp(param[i],">>")){
            parse->flag |= OUT_REDIRECT_APPEND;
            parse->out_file=param[i+1];
            param[i]=NULL;
            i+=2;
        }
        else if(!strcmp(param[i],"|")){
            parse->flag |= IS_PIPED;
            param[i]=NULL;
            parse->cmd2=param[i+1];
            parse->param2=&param[i+1];
            break;
        }
        else i++;
    }
}
コード例 #19
0
ファイル: control.c プロジェクト: dacav/maillearn
mbox_err_t mbox_new (const char *filename, mbox_t **mbox)
{
    register mbox_t *ret;
    assert(ret = malloc(sizeof(mbox_t)));

    if ((ret->file = fopen(filename, "rt")) == NULL) {
        return MBOX_OPENING;
    }
    ret->mail_queue = thq_new();
    parse_init(&ret->parse);
    ret->aux.key = NULL;
    ret->aux.multiline = dstrbuf_new(NULL, 0);
    ret->aux.status = STATUS_NODATA;

    *mbox = ret;

    /* Starting thread */
    assert(pthread_create(&ret->parser_th, NULL, parsing_thread,
                          (void *)ret) == 0);

    return MBOX_SUCCESS;
}
コード例 #20
0
ファイル: main.c プロジェクト: DoryuX/Xwell
int main( int argc, char *argv[] ) {
    char *filename = NULL;
    char *msg = NULL;

    if ( argc == 2 ) {
        filename = argv[ 1 ];

        switch ( utils_validate_filename( filename ) ) {
            case FILE_OK:
                printf( "Input File: %s\n", filename );
                
                parse_init( filename );
                parse_assignment();

                fclose( g_fptr );

                break;
            case BAD_EXTENSION:
                msg = "Expected a file in the format of '< filename >.xwell'";
                utils_error( msg, strlen( msg ) );
                break;
            default:
                msg = "Unknown FILECHECK_t Error";
                utils_error( msg, strlen( msg ) );
        }
    } else {
        char msgbf[ 100 ] = "\0";
        size_t n = sprintf( msgbf, "Usage - %s %s", argv[ 0 ], "< filename >.xwell" );
        utils_error( msgbf, n );
    }

    msg = NULL;
    filename = NULL;

    exit( EXIT_SUCCESS );
}
コード例 #21
0
ファイル: my_ops.c プロジェクト: chenbk85/myrelay
int my_hs_stage1_cb(int fd, void *arg)
{//读取mysql的连接认证原始数据
    int done, res = 0;
    my_conn_t *my;
    buf_t *buf;
    char *user, *pass, token[64], message[64];
    my_node_t *node;
    my_auth_init_t init;
    cli_auth_login_t login;
    my_info_t *info;

    my = (my_conn_t *)arg;
    node = my->node;
    buf = &(my->buf);

    user = node->user;
    pass = node->pass;
    info = node->info;


    if( (res = my_real_read(fd, buf, &done)) < 0 ){
        log_err(g_log, "read mysql error res[%d]\n", res);
        goto end;
    }

    if(done){
        if( (res = del_handler(fd)) < 0 ) {
            log(g_log, "del_handler fd[%d] error\n", fd);
            goto end;
        }

        res = add_handler(fd, EPOLLOUT, my_hs_stage2_cb, arg);
        if(res < 0){
            log(g_log, "add_handler fd[%d] error\n", fd);
            goto end;
        }

        if( (res = parse_init(buf, &init)) < 0 ){
            log(g_log, "parse init packet error\n");
            goto end;
        }

		memcpy(message, init.scram, 8);
        memcpy(message + 8, init.plug, 12);
        //memcpy(message, "%@R[SoWC", 8);
        //memcpy(message + 8, "+L|LG_+R={tV", 12);
        message[8+12] = '\0';

        my_info_set(init.prot_ver, init.lang, init.status, init.cap, init.srv_ver, strlen(init.srv_ver));

        login.pktno = 1;
        login.client_flags = init.cap & (~cap_umask);
        login.max_pkt_size = 16777216;
        login.charset = init.lang;
        strncpy(login.user, user, sizeof(login.user) - 1);
        login.user[sizeof(login.user) - 1] = '\0';
        if(pass[0] == '\0'){
            login.scram[0] = 0;
        } else {
            login.scram[0] = 20;
            scramble(token, message, pass);
            memcpy(login.scram + 1, token, 20);
        }
        strncpy(login.db, "", sizeof(login.db) - 1);
        login.db[sizeof(login.db) - 1] = '\0';

        if( (res = make_login(buf, &login)) < 0 ){
            log(g_log, "make login packet error\n");
            goto end;
        }
    }

    return res;

end:

	-- node->cur_connecting_cnt ;
    my_conn_close_on_fail(my);

    return res;
}
コード例 #22
0
ファイル: db.c プロジェクト: mysidia/snservices1
/** 
 * \brief Loads the memo database from disk
 */
void readMemoData(void)
{
	RegNickList *nick = NULL;
	RegNickList *from, *rnlb;
	MemoList *newmemo;
	char *command;
	char *topic;
	int done = 0;
	unsigned long linenum = 0;

	db.ms = fopen(MS_DB, "r");

	if (db.ms == NULL)
		return;

	while (!done) {
		if (!(sfgets(dbLine, 2048, db.ms))) {
			if (!done) {
				unexpected_eof(MS_DB);
			}
			done = 1;
			fclose(db.ms);
			return;
		}

		linenum++;
		if (parse_init(&state, dbLine) != 0) {
			/*! \bug XXX be nicer here... */
			abort();
		}

		command = parse_getarg(&state);

		if (strcmp(command, "data") == 0) {
			nick = getRegNickData(parse_getarg(&state));
			/*! \bug Increment the arguments.. we REALLY need to fix the dbs */
			(void)parse_getarg(&state);
			(void)parse_getarg(&state);
			if (nick) {
				nick->memos->flags = atoi(parse_getarg(&state));
				nick->memos->max = atoi(parse_getarg(&state));
				if (nick->memos->max <= 0)
					nick->memos->max = MS_DEF_RCV_MAX;
			}
		} else if (strcmp(command, "mblock") == 0) {
			MemoBlock *mbitem;
			if (nick && nick->memos) {
				char *nickToBlock;

				if ((nickToBlock = parse_getarg(&state))
					&& (rnlb = getRegNickData(nickToBlock))) {

					mbitem = (MemoBlock *) oalloc(sizeof(MemoBlock));
					mbitem->blockId = rnlb->regnum;
					mbitem->next = nick->memos->firstMblock;
					nick->memos->firstMblock = mbitem;
				}
			}
		} else if (strcmp(command, "redirect") == 0) {
			nick = getRegNickData(parse_getarg(&state));
			if (nick != NULL)
				nick->memos->forward =
					getRegNickData(parse_getarg(&state));
		} else if (strcmp(command, "memo") == 0) {
			char *cn;

			cn = parse_getarg(&state);

			nick = getRegNickData(cn);
			if (nick == NULL) {
				printf("memo: %s not valid\n", cn);
				continue;
			}
			newmemo = (MemoList *) oalloc(sizeof(MemoList));
			newmemo->realto = nick;
			/*! \bug Increment the argument 1, we need to fix the db */
			(void)parse_getarg(&state);
			newmemo->flags = atoi(parse_getarg(&state));
			newmemo->sent = (time_t) atol(parse_getarg(&state));

			/* Memo expiration code */

			if ((time(NULL) - newmemo->sent) >= NICKDROPTIME
			     && !(newmemo->flags & MEMO_SAVE)) {
				FREE(newmemo);
				continue;
			}

			strncpyzt(newmemo->from, parse_getarg(&state), NICKLEN);
			from = getRegNickData(newmemo->from);
			strncpyzt(newmemo->to, parse_getarg(&state), CHANLEN);

			/* Read the memo, skipping the leading : */
			topic = parse_getallargs(&state);
			if (topic == NULL) {
				FREE(newmemo);
				continue;
			}
			newmemo->memotxt = strdup(topic);

			/* Add the memo to the users memobox */
			LIST_ENTRY_INIT(newmemo, ml_lst);
			LIST_INSERT_HEAD(&nick->memos->mb_memos, newmemo, ml_lst);
			if (from && newmemo->flags & MEMO_UNREAD)
				LIST_INSERT_HEAD(&from->memos->mb_sent, newmemo, ml_sent);
			nick->memos->memocnt++;
		} else if (strcmp(command, "done") == 0) {
			done = 1;
		} else {
			fprintf(stderr, "Error in reading memo data (%s) %lu\n",
					dbLine, linenum);
			sshutdown(-1);
		}
#ifdef DBDEBUG
		sSend(":%s PRIVMSG " DEBUGCHAN " :Read memo data (%s)", MemoServ,
			  dbLine);
#endif

		parse_cleanup(&state);
	}

	fclose(db.ms);
}
コード例 #23
0
ファイル: db.c プロジェクト: mysidia/snservices1
/** 
 * \brief Loads the ChanServ database from disk
 */
void readChanData()
{
	RegChanList *rcl;
	RegNickList *rnl;
	char *command;
	int done = 0, db_version = 1;
	int line_num = 0;
	char *pass;
	char *topic;

	rcl = NULL;
	rnl = NULL;
	db.cs = fopen(CS_DIR "chanserv.db", "r");
	if (db.cs == NULL)
		return;

	while (!done) {
		if ((sfgets(dbLine, 2048, db.cs)) == 0) {
			if (!done) {
				unexpected_eof(CS_DB);
			}
			done = 1;
			fclose(db.cs);
			return;
		}
		line_num++;

		if (parse_init(&state, dbLine) != 0) {
			fprintf(stderr,
					CS_DIR "chanserv.db:%d: " " Fatal error during read "
					" (Null line?) \n", line_num);
			abort();
		}

		command = parse_getarg(&state);
		if (!strcmp(command, "version")) {
			db_version = atoi(parse_getarg(&state));
		}
		else if (!strcmp(command, "channel")) {
			char *sChannelName, *sFounderNick;

			rcl = (RegChanList *) oalloc(sizeof(RegChanList));
			sChannelName = parse_getarg(&state);
			sFounderNick = parse_getarg(&state);
			initRegChanData(rcl);

			if (strlen(sChannelName) >= CHANLEN) {
				fprintf(stderr,
						CS_DIR "chanserv.db:%d: "
						" Channel name '%.80s' exceeds " " CHANLEN.\n",
						line_num, sChannelName);
				sshutdown(-1);
			} else if (strlen(sFounderNick) >= NICKLEN) {
				fprintf(stderr,
						CS_DIR "chanserv.db:%d: "
						" Founder nick name '%.80s' " " (%.80s)"
						" exceeds NICKLEN.\n", line_num, sFounderNick,
						sChannelName);
				sshutdown(-1);
			}

			if (!sChannelName || !sFounderNick) {
				fprintf(stderr,
						CS_DIR "chanserv.db:%d: " " Parse error. (%p, %p)",
						line_num, sChannelName, sFounderNick);
				sshutdown(-1);
			}

			rnl = getRegNickData(sFounderNick);

			strcpy(rcl->name, sChannelName);

			if (rnl)
			{
				rcl->founderId = rnl->regnum;
				rnl->chans++;
			}
			else
				rcl->founderId = RegId(0, 0);

			rcl->mlock = atol(parse_getarg(&state));
			rcl->flags = atol(parse_getarg(&state));
			pass = parse_getarg(&state);	/*! \bug XXX verify this works */
			if (!pass) {
				fprintf(stderr,
						CS_DIR "chanserv.db:%d: " " Null password?!",
						line_num);
				sshutdown(-1);
			} 

			if ((db_version < 2) || *pass == '@') {
				if (db_version < 2)
					strcpy((char *)rcl->password, pass);
				else
					strcpy((char *)rcl->password, pass + 1);

				if (strlen(pass) > (u_int)((db_version < 2) ? PASSLEN : PASSLEN+1)) {
					fprintf(stderr,
							CS_DIR "chanserv.db:%d: " " password > PASSLEN",
							line_num);
					sshutdown(-1);
				}

				xorit((char *)rcl->password);
				rcl->flags &= ~CENCRYPT;
			}
			else {
				u_char *tmpup = fromBase64(pass+1, NULL);
				int q;

				if (!tmpup)
					abort();
				for(q = 0; q < 16; q++)
					rcl->password[q] = tmpup[q];
				FREE(tmpup);
				rcl->flags |= CENCRYPT;
			}

			rcl->timereg = (time_t) atol(parse_getarg(&state));
			rcl->timestamp = (time_t) atol(parse_getarg(&state));
			strncpyzt(rcl->key, parse_getarg(&state), KEYLEN);
			rcl->limit = atol(parse_getarg(&state));
			rcl->memolevel = atoi(parse_getarg(&state));
			rcl->tlocklevel = atoi(parse_getarg(&state));
			rcl->restrictlevel = atoi(parse_getarg(&state));
			/* The rest of the line - skipping the leading : */
			topic = parse_getallargs(&state);
			if (topic == NULL)
				rcl->desc[0] = '\0';
			else
				strncpyzt(rcl->desc, topic, CHANDESCBUF);
			addRegChan(rcl);
			mostchans++;
		} else if (!strcmp(command, "topic")) {
			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			strncpyzt(rcl->tsetby, parse_getarg(&state), NICKLEN);
			rcl->ttimestamp = (time_t) atol(parse_getarg(&state));
			/* The rest of the topic, skipping the : in it */
			topic = parse_getallargs(&state);
			if (topic == NULL)
				rcl->topic = NULL;
			else
				rcl->topic = strdup(topic);
		} else if (!strcmp(command, "url")) {
			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			topic = parse_getallargs(&state);
			if (topic == NULL)
				rcl->url = NULL;
			else
				rcl->url = strdup(topic);
		} else if (!strcmp(command, "autogreet")) {
			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			topic = parse_getallargs(&state);
			if (topic == NULL)
				rcl->autogreet = NULL;
			else
				rcl->autogreet = strdup(topic);
		} else if (!strcmp(command, "markby")) {
			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			topic = parse_getarg(&state);
			if (topic == NULL)
				rcl->markby = NULL;
			else
				rcl->markby = strdup(topic);
		} else if (strcmp(command, "chkey") == 0) {
			char *tmpp = parse_getarg(&state);
			if (rcl && tmpp)
				rcl->chpw_key = strtoul(tmpp, (char **)0, 16);
		} else if (!strcmp(command, "op")) {
			cAccessList *lame;
			char *tmpName;

			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			tmpName = parse_getarg(&state);
			if ((rnl = getRegNickData(tmpName)) != NULL)
			{
				lame = (cAccessList *) oalloc(sizeof(cAccessList));
				lame->nickId = rnl->regnum;
				lame->uflags = atoi(parse_getarg(&state));
				addChanOp(rcl, lame);
			}
		} else if (!strcmp(command, "akick")) {
			cAkickList *lame;
			lame = (cAkickList *) oalloc(sizeof(cAkickList));
			rcl = getRegChanData(parse_getarg(&state));
			if (rcl == NULL)
				continue;
			strncpyzt(lame->mask, parse_getarg(&state), 70);
			lame->added = (time_t) atol(parse_getarg(&state));
			/* The rest of the string... */
			topic = parse_getallargs(&state);
			if (topic == NULL)
				lame->reason[0] = '\0';
			else {
				strncpyzt(lame->reason, topic, NICKLEN + 50);
			}
			addChanAkick(rcl, lame);
		} else if (!strcmp(command, "done"))
			done = 1;
		else {
			fprintf(stderr, "GLOBOPS :Read chan data (%s)", dbLine);
			sshutdown(-1);
		}

#ifdef DBDEBUG
		sSend(":%s PRIVMSG " DEBGUGCHAN " :Read chan data (%s)", ChanServ,
			  dbLine);
#endif

		parse_cleanup(&state);
	}
	fclose(db.cs);
}
コード例 #24
0
ファイル: db.c プロジェクト: mysidia/snservices1
/**
 * \brief Loads the NickServ database from disk
 */
void readNickData()
{
	RegNickList *rnl = NULL;
	char *command, *tmpp;
	unsigned char *tmpup;
	int done = 0, db_version = 1;
	int line_num = 0, do_enc = 0;

#ifdef REQ_EMAIL
	readRegData();
#endif

	db.ns = fopen(NS_DB, "r");

	if (db.ns == NULL) {
		logDump(corelog, "Unable to open " NS_DB ": %s", strerror(errno));
		return;
	}

	while (!done) {
		if (!(sfgets(dbLine, 1024, db.ns))) {
			if (!done) {
				unexpected_eof(NS_DB);
			}
			done = 1;
			fclose(db.ns);
			return;
		}

		line_num++;

		if (parse_init(&state, dbLine) != 0) {
			/*! \bug XXX make a nicer error here! */
			abort();
		}

		command = parse_getarg(&state);
		if (strcmp(command, "version") == 0) {
			tmpp = parse_getarg(&state);
			assert(tmpp);

			if (tmpp)
				db_version = atoi(tmpp);
		}
		else
		if (strcmp(command, "nick") == 0) {
			rnl = (RegNickList *) oalloc(sizeof(RegNickList));
			char *sNick, *sUser, *sHost, *sPass;

			sNick = parse_getarg(&state);
			sUser = parse_getarg(&state);
			sHost = parse_getarg(&state);
			sPass = parse_getarg(&state);

			if (strlen(sNick) >= NICKLEN) {
				fprintf(stderr,
						NS_DB ":%d: " " Nickname '%.80s' exceeds "
						" NICKLEN.\n", line_num, sNick);
				sshutdown(-1);
			} 

			strcpy(rnl->nick, sNick);
			strncpyzt(rnl->user, sUser, USERLEN);
			SetDynBuffer(&rnl->host, sHost);

			if (db_version < 2)
			{
				if (strlen(sPass) > PASSLEN) {
					fprintf(stderr,
						NS_DB ":%d: " " Password for nick '%s' "
						" exceeds PASSLEN.\n", line_num, sNick);
					sshutdown(-1);
				}

				strcpy((char *)rnl->password, xorit(sPass));
			}
			else {
				char encType = *sPass;

				if (encType == '@') {
					if (strlen(sPass+1) > PASSLEN) {
						fprintf(stderr,
							NS_DB ":%d: " " Password for nick '%s' "
							" exceeds PASSLEN.\n", line_num, sNick);
						sshutdown(-1);
					}

					strcpy((char *)rnl->password, xorit(sPass + 1));
					do_enc = 0;
				}
				else if (encType == '$') {
					int q, len;

					tmpup = fromBase64(sPass + 1, &len);
					assert(tmpup);

					for(q = 0; q < 16; q++)
						rnl->password[q] = tmpup[q];
					do_enc = 1;
					FREE(tmpup);
				}
				else
					rnl->password[0] = '\0';
			}

			rnl->timestamp = (time_t) atol(parse_getarg(&state));
			rnl->timereg = (time_t) atol(parse_getarg(&state));
			rnl->flags = atoi(parse_getarg(&state));

			if (db_version >= 3) {
				const char *idString = parse_getarg(&state);
				int av, bv;

				sscanf(idString, "%X*%X", &av, &bv);
				rnl->regnum.SetDirect(top_regnick_idnum, av, bv);				
			}
			else {
				rnl->regnum.SetNext(top_regnick_idnum);
			}

			if (do_enc)
				rnl->flags |= NENCRYPT;
			else
				rnl->flags &= ~NENCRYPT;

			rnl->opflags = 0;
			rnl->idtime = DEF_NDELAY;
			ADD_MEMO_BOX(rnl);
			addRegNick(rnl);
		} else if (strcmp(command, "is") == 0) {
			char *data = parse_getarg(&state);
			if (rnl && data)
				rnl->is_readtime = atol(data);
		} else if (strcmp(command, "oper") == 0) {
			char *opflags_s;
			if (rnl && (rnl == getRegNickData(parse_getarg(&state)))) {
				if ((opflags_s = parse_getarg(&state)))
					rnl->opflags |=
						(strtoul(opflags_s, (char **)0, 10) &
						 ~(OROOT | OSERVOP));
				if (rnl->opflags)
					addOpData(rnl);
			}
		} else if (strcmp(command, "url") == 0) {
			if (rnl && (rnl == getRegNickData(parse_getarg(&state))))
			{
				rnl->url = strdup(parse_getarg(&state));
				if (strlen(rnl->url) > (URLLEN - 1))
					rnl->url[URLLEN - 1] = '\0';
			}
		} else if (strcmp(command, "gecos") == 0) {
#ifdef TRACK_GECOS
			char *gecos = parse_getallargs(&state);
			if (gecos != NULL)
				rnl->gecos = strdup(gecos);
#endif
		} else if (strcmp(command, "akey") == 0) {
#ifdef REQ_EMAIL
			if (rnl)
				rnl->email_key = atoi(parse_getarg(&state));
#endif
		} else if (strcmp(command, "chkey") == 0) {
			char *tmpp = parse_getarg(&state);
			if (rnl && tmpp)
				rnl->chpw_key = strtoul(tmpp, (char **)0, 16);
		} else if (strcmp(command, "markby") == 0) {
			char *mby;

			rnl = getRegNickData(parse_getarg(&state));
			if (!rnl || !(mby = parse_getarg(&state)))
				continue;
			rnl->markby = strdup(mby);
		} else if (strcmp(command, "access") == 0) {
			rnl = getRegNickData(parse_getarg(&state));
			addAccItem(rnl, parse_getarg(&state));
		} else if (!strcmp(command, "email")) {
			rnl = getRegNickData(parse_getarg(&state));

			strncpyzt(rnl->email, parse_getarg(&state), EMAILLEN);

			if (!strcmp(rnl->email, "(none)"))
				strcat(rnl->email, " ");
		} else if (!strcmp(command, "idtime")) {
			rnl = getRegNickData(parse_getarg(&state));
			rnl->idtime = atoi(parse_getarg(&state));
		} else if (!strcmp(command, "done"))
			done = 1;
		else {
			fprintf(stderr, NS_DB ":%d: Error reading nick data (%s)",
					line_num, dbLine);
			sshutdown(-1);
		}
#ifdef DBDEBUG
		sSend(":%s PRIVMSG " DEBUGCHAN " :Read nick data (%s)", NICKSERV,
			  dbLine);
#endif

		parse_cleanup(&state);
	}
	fclose(db.ns);

	readMemoData();
}
コード例 #25
0
ファイル: db.c プロジェクト: mysidia/snservices1
/** 
 * \brief Loads the InfoServ database from disk
 */
void readInfoData(void)
{
	char *command;
	int done = 0;
	SomeNews *news, *tmpnews;

	is_listhead = NULL;
	db.is = fopen(IS_DB, "r");

	if (db.is == NULL)
		return;

		/**
         * There was still a crash bug in what was here before...
         * cleaning this up .. allocate memory when it's
         * needed, don't allocate it in the beginning and
         * give it up later if superflous in a linked list
         * load.
         * -Mysidia
         */

	while (!done) {
		if (!(sfgets(dbLine, 2048, db.is))) {
			if (!done) {
				unexpected_eof(IS_DB);
			}
			done = 1;
			fclose(db.is);
			return;
		}

		if (parse_init(&state, dbLine) != 0) {
			/*! \bug XXX be nicer here... */
			abort();
		}

		command = parse_getarg(&state);

		if (!strcmp(command, "article")) {
			char *temp;

			news = (SomeNews *) oalloc(sizeof(SomeNews));
			if (!is_listhead)
				is_listhead = news;
			else {
				for (tmpnews = is_listhead; tmpnews->next;
					 tmpnews = tmpnews->next);
				tmpnews->next = news;
			}
			news->importance = atoi(parse_getarg(&state));
			strncpyzt(news->from, parse_getarg(&state), NICKLEN);
			news->timestamp = atol(parse_getarg(&state));
			temp = parse_getallargs(&state);
			if (temp)
				news->header = strdup(temp);
			news->content = dbReadString(db.is);

			if (news->timestamp > is_last_post_time)
				is_last_post_time = news->timestamp;
		}

		else if (!strcmp(command, "done"))
			done = 1;
		else
			sshutdown(-1);

		parse_cleanup(&state);
	}
	fclose(db.is);
}
コード例 #26
0
ファイル: main.cpp プロジェクト: 0xffffffRabbit/NextBSD-1
int main(int argc, char **argv)
{
  setlocale(LC_NUMERIC, "C");
#if defined(__MSDOS__) || defined(__EMX__)
  argv[0] = fix_program_name(argv[0], "pic");
#endif /* __MSDOS__ || __EMX__ */
  program_name = argv[0];
  static char stderr_buf[BUFSIZ];
  setbuf(stderr, stderr_buf);
  int opt;
#ifdef TEX_SUPPORT
  int tex_flag = 0;
  int tpic_flag = 0;
#endif
#ifdef FIG_SUPPORT
  int whole_file_flag = 0;
  int fig_flag = 0;
#endif
  static const struct option long_options[] = {
    { "help", no_argument, 0, CHAR_MAX + 1 },
    { "version", no_argument, 0, 'v' },
    { NULL, 0, 0, 0 }
  };
  while ((opt = getopt_long(argc, argv, "T:CDSUtcvnxzpf", long_options, NULL))
	 != EOF)
    switch (opt) {
    case 'C':
      compatible_flag = 1;
      break;
    case 'D':
    case 'T':
      break;
    case 'S':
      safer_flag = 1;
      break;
    case 'U':
      safer_flag = 0;
      break;
    case 'f':
#ifdef FIG_SUPPORT
      whole_file_flag++;
      fig_flag++;
#else
      fatal("fig support not included");
#endif
      break;
    case 'n':
      driver_extension_flag = 0;
      break;
    case 'p':
    case 'x':
      warning("-%1 option is obsolete", char(opt));
      break;
    case 't':
#ifdef TEX_SUPPORT
      tex_flag++;
#else
      fatal("TeX support not included");
#endif
      break;
    case 'c':
#ifdef TEX_SUPPORT
      tpic_flag++;
#else
      fatal("TeX support not included");
#endif
      break;
    case 'v':
      {
	printf("GNU pic (groff) version %s\n", Version_string);
	exit(0);
	break;
      }
    case 'z':
      // zero length lines will be printed as dots
      zero_length_line_flag++;
      break;
    case CHAR_MAX + 1: // --help
      usage(stdout);
      exit(0);
      break;
    case '?':
      usage(stderr);
      exit(1);
      break;
    default:
      assert(0);
    }
  parse_init();
#ifdef TEX_SUPPORT
  if (tpic_flag) {
    out = make_tpic_output();
    lf_flag = 0;
  }
  else if (tex_flag) {
    out = make_tex_output();
    command_char = '\\';
    lf_flag = 0;
  }
  else
#endif
#ifdef FIG_SUPPORT
  if (fig_flag)
    out = make_fig_output();
  else
#endif
    out = make_troff_output();
#ifdef FIG_SUPPORT
  if (whole_file_flag) {
    if (optind >= argc)
      do_whole_file("-");
    else if (argc - optind > 1) {
      usage(stderr);
      exit(1);
    } else
      do_whole_file(argv[optind]);
  }
  else {
#endif
    if (optind >= argc)
      do_file("-");
    else
      for (int i = optind; i < argc; i++)
	do_file(argv[i]);
#ifdef FIG_SUPPORT
  }
#endif
  delete out;
  if (ferror(stdout) || fflush(stdout) < 0)
    fatal("output error");
  return had_parse_error;
}
コード例 #27
0
ファイル: main.c プロジェクト: SiggyF/netcdf-c
int
main(
	int argc,
	char *argv[])
{
    int c;
    FILE *fp;
	struct Languages* langs;
    char* lang_name;//
#ifdef __hpux
    setlocale(LC_CTYPE,"");
#endif
    
    init_netcdf();

    opterr = 1;			/* print error message if bad option */
    progname = ubasename(argv[0]);
    cdlname = "-";
    netcdf_name = NULL;
    datasetname = NULL;
    l_flag = 0;
    nofill_flag = 0;
    syntax_only = 0;
    header_only = 0;
    mainname = "main";
    nciterbuffersize = 0;

    k_flag = 0;
    format_flag = 0;
    enhanced_flag = 0;
    specials_flag = 0;

    diskless = 0;

#if _CRAYMPP && 0
    /* initialize CRAY MPP parallel-I/O library */
    (void) par_io_init(32, 32);
#endif

    while ((c = getopt(argc, argv, "hbcfk:l:no:v:xdM:D:B:P")) != EOF)
      switch(c) {
	case 'd':
	  debug = 1;	  
	  break;
	case 'D':
	  debug = atoi(optarg);
	  break;
	case 'c': /* for c output, old version of "-lc" */
	  if(l_flag != 0) {
	    fprintf(stderr,"Please specify only one language\n");
	    return 1;
	  }
	  l_flag = L_C;
	  fprintf(stderr,"-c is deprecated: please use -lc\n");
	  break;
	case 'f': /* for f77 output, old version of "-lf" */
	  if(l_flag != 0) {
	    fprintf(stderr,"Please specify only one language\n");
	    return 1;
	  }
	  l_flag = L_F77;
	  fprintf(stderr,"-f is deprecated: please use -lf77\n");
	  break;
	case 'b': /* for binary netcdf output, ".nc" extension */
	  if(l_flag != 0) {
	    fprintf(stderr,"Please specify only one language\n");
	    return 1;
	  }
	  l_flag = L_BINARY;
	  break;
	case 'h':
	  header_only = 1;	  
	  break;
     case 'l': /* specify language, instead of using -c or -f or -b */

		 {
		if(l_flag != 0) {
		    fprintf(stderr,"Please specify only one language\n");
		    return 1;
		}
		lang_name = (char*) emalloc(strlen(optarg)+1);
		(void)strcpy(lang_name, optarg);
		for(langs=legallanguages;langs->name != NULL;langs++) {
		    if(strcmp(lang_name,langs->name)==0) {
			l_flag = langs->flag;
		        break;
		    }
		}
		if(langs->name == NULL) {
		    derror("%s: output language %s not implemented", 
			   progname, lang_name);
		    return(1);
		}
	    }
	  break;
	case 'n':		/* old version of -b, uses ".cdf" extension */
	  if(l_flag != 0) {
	    fprintf(stderr,"Please specify only one language\n");
	    return 1;
	  }
	  l_flag = L_BINARY;
          binary_ext = ".cdf";
	  break;
	case 'o':		/* to explicitly specify output name */
	  netcdf_name = nulldup(optarg);
	  break;
	case 'x': /* set nofill mode to speed up creation of large files */
	  nofill_flag = 1;
	  break;
        case 'v': /* a deprecated alias for "kind" option */
	    /*FALLTHRU*/
        case 'k': /* for specifying variant of netCDF format to be generated 
                     Possible values are:
                     1 (=> classic 32 bit)
                     2 (=> classic 64 bit)
                     3 (=> enhanced)
                     4 (=> classic, but stored in an enhanced file format)
                     Also provide string versions of above
                     "classic"
                     "64-bit-offset"
                     "64-bit offset"
		     "enhanced" | "hdf5" | "netCDF-4"
                     "enhanced-nc3" | "hdf5-nc3" | "netCDF-4 classic model"
		   */
	    {
		struct Kvalues* kvalue;
		char *kind_name = (char *) emalloc(strlen(optarg)+1);
		if (! kind_name) {
		    derror ("%s: out of memory", progname);
		    return(1);
		}
		(void)strcpy(kind_name, optarg);
	        for(kvalue=legalkinds;kvalue->name;kvalue++) {
		    if(strcmp(kind_name,kvalue->name) == 0) {
		        k_flag = kvalue->k_flag;
			break;
		    }
		}
		if(kvalue->name == NULL) {
		   derror("Invalid format: %s",kind_name);
		   return 2;
		}
	    }
	  break;
	case 'M': /* Determine the name for the main function */
	    mainname = nulldup(optarg);
	    break;
	case 'B':
	  nciterbuffersize = atoi(optarg);
	  break;
	case 'P': /* diskless with persistence */
	  diskless = 1;
	  break;
	case '?':
	  usage();
	  return(8);
      }

    if(l_flag == 0) {
	l_flag = L_BINARY; /* default */
	/* Treat -k or -o as an implicit -lb assuming no other -l flags */
        if(k_flag == 0 && netcdf_name == NULL)
	    syntax_only = 1;
    }

    /* Compute/default the iterator buffer size */
    if(l_flag == L_BINARY) {
	if(nciterbuffersize == 0 )
	    nciterbuffersize = DFALTBINNCITERBUFFERSIZE;
    } else {
	if(nciterbuffersize == 0)
	    nciterbuffersize = DFALTLANGNCITERBUFFERSIZE;
    }

#ifndef ENABLE_C
    if(c_flag) {
	  fprintf(stderr,"C not currently supported\n");
	  exit(1);
    }
#endif
#ifndef ENABLE_BINARY
    if(l_flag == L_BINARY) {
	  fprintf(stderr,"Binary netcdf not currently supported\n");
	  exit(1);
    }
#endif
#ifndef ENABLE_JAVA
    if(l_flag == L_JAVA) {
	  fprintf(stderr,"Java not currently supported\n");
	  exit(1);
    }
#else
    if(l_flag == L_JAVA && strcmp(mainname,"main")==0)
	mainname = "Main";
#endif
#ifndef ENABLE_F77
    if(l_flag == L_F77) {
	  fprintf(stderr,"F77 not currently supported\n");
	  exit(1);
    }
#endif

    if(l_flag != L_BINARY)
	diskless = 0;

    argc -= optind;
    argv += optind;

    if (argc > 1) {
	derror ("%s: only one input file argument permitted",progname);
	return(6);
    }

    fp = stdin;
    if (argc > 0 && strcmp(argv[0], "-") != 0) {
	if ((fp = fopen(argv[0], "r")) == NULL) {
	    derror ("can't open file %s for reading: ", argv[0]);
	    perror("");
	    return(7);
	}
	cdlname = (char*)emalloc(NC_MAX_NAME);
	cdlname = nulldup(argv[0]);
	if(strlen(cdlname) > NC_MAX_NAME) cdlname[NC_MAX_NAME] = '\0';
    }

    /* Standard Unidata java interface => usingclassic */

    parse_init();
    ncgin = fp;
    if(debug >= 2) {ncgdebug=1;}
    if(ncgparse() != 0)
        return 1;

    /* Compute the k_flag (1st pass) using rules in the man page (ncgen.1).*/

#ifndef USE_NETCDF4
    if(enhanced_flag) {
	derror("CDL input is enhanced mode, but --disable-netcdf4 was specified during build");
	return 0;
    }
#endif

    if(l_flag == L_JAVA || l_flag == L_F77) {
        k_flag = 1;
	if(enhanced_flag) {
	    derror("Java or Fortran requires classic model CDL input");
	    return 0;
	}
    }

    if(k_flag == 0)
	k_flag = format_flag;

    if(enhanced_flag && k_flag == 0)
	k_flag = 3;

    if(enhanced_flag && k_flag != 3) {
	derror("-k or _Format conflicts with enhanced CDL input");
	return 0;
    }

    if(specials_flag > 0 && k_flag == 0)
#ifdef USE_NETCDF4
	k_flag = 3;
#else
	k_flag = 1;
#endif

    if(k_flag == 0)
	k_flag = 1;

    usingclassic = (k_flag <= 2?1:0);

    /* compute cmode_modifier */
    switch (k_flag) {
    case 1: cmode_modifier = 0; break;
    case 2: cmode_modifier = NC_64BIT_OFFSET; break;
    case 3: cmode_modifier = NC_NETCDF4; break;
    case 4: cmode_modifier = NC_NETCDF4 | NC_CLASSIC_MODEL; break;
    default: ASSERT(0); /* cannot happen */
    }

    if(diskless)
	cmode_modifier |= (NC_DISKLESS|NC_NOCLOBBER);

    processsemantics();
    if(!syntax_only && error_count == 0) 
        define_netcdf();

    return 0;
}
コード例 #28
0
ファイル: relive.c プロジェクト: mintwans/cpsc483
bool initialize()
{	
	char* config_buff = (char*)malloc(sizeof(char)*100);

	// init some variables
	prevTime = 0;
	deltaTime = 0;
	deltaDist = 0;
	power_save = false;
	cam_focus_delay = 8000;

	// init parser structures for gps and config
	parse_init();

	// turn on leds so we know it started working
	cc3_led_set_state (1, true);
	cc3_led_set_state (2, true);

	// configure uart for gps serial communication
	cc3_uart_init (0, CC3_UART_RATE_4800, CC3_UART_MODE_8N1,
		CC3_UART_BINMODE_BINARY);

	// init the camera and file system
	cc3_camera_init ();
	cc3_filesystem_init();

#ifdef LOG
	snprintf(log_str, 100, "**********\n\rNew Session\n\r");
	write_log();
	snprintf(log_str, 100, "\n\rReading config file\r\n");
	write_log();
#endif

	// read config file from MMC
	memory = fopen ("c:/config.txt", "r");
	if (memory == NULL) {
		perror ("fopen failed\r\n");
		return false;
	}
	// get config file
	fscanf(memory, "%s", config_buff);
	if (fclose (memory) == EOF) {
		perror ("fclose failed\r\n");
		return false;
	}
	// parse config file
	parse_Config(config_buff);

	// if the config is not good then quit
	if(!config->good)
	{
#ifdef LOG
		snprintf(log_str, 100, "\n\rconfig.txt INVALID\r\n");
		write_log();
#endif
		return false;
	}

#ifdef LOG
	snprintf(log_str, 100, "\r\nConfig File:\n\rDelay(ms) - %d\tMin Dist(mm) - %d",(int)config->delay,(int)(config->min_dist*1000));
	write_log();
	if(config->halo)
	{
		snprintf(log_str, 100, "\tHalo - true\r\n");
		write_log();
		snprintf(log_str, 100, "\tHalo %s:\t Lat*1000000 - %d\tLon*1000000 - %d\tRange(mm) - %d\r\n",
			config->halo_info->name,
			(int)(config->halo_info->lat*1000000),
			(int)(config->halo_info->lon*1000000),
			(int)(config->halo_info->range*1000) );
		write_log();
	}
	else
	{
		snprintf(log_str, 100, "\tHalo - false\r\n");
		write_log();
	}
#endif

	//configure camera
	cc3_camera_set_colorspace (CC3_COLORSPACE_RGB);
	cc3_camera_set_resolution (CC3_CAMERA_RESOLUTION_HIGH);
	cc3_camera_set_auto_white_balance (true);
	cc3_camera_set_auto_exposure (true);

	// init pixbuf with width and height and JPEG compression
	cc3_pixbuf_load();
	init_jpeg();

	// try to open picNum.txt if exist that will be the 
	// picture number we will start with if not start at 0
#ifdef LOG
	snprintf(log_str, 100, "\n\rReading picNum file\r\n");
	write_log();
#endif
	memory = fopen ("c:/picNum.txt", "r");
	if (memory == NULL) {
		picNum = 0;
	}
	else
	{
		char* picNum_buff = (char*)malloc(sizeof(char)*100);
		fscanf(memory, "%s", picNum_buff);
		picNum = atoi(picNum_buff);
		free(picNum_buff);
	}
	if (fclose (memory) == EOF) {
		perror ("fclose failed\r\n");
		return false;
	}
#ifdef LOG
	snprintf(log_str, 100, "Starting picture numbering at: %d\r\n",picNum);
	write_log();
#endif

	// starts out awake with no gps signal
	cc3_led_set_state (1, false);
	cc3_led_set_state (2, true);

	cc3_timer_wait_ms(1000);
	free(config_buff);
	return true;
}
コード例 #29
0
ファイル: get.c プロジェクト: rmanis/lil
void create() {
    parse_init();
    add_rules(({ "OBJ" }), ({ "take" }));
コード例 #30
0
ファイル: db.c プロジェクト: mysidia/snservices1
/** 
 * \brief Loads the clone rule database from disk
 */
void readTriggerData(void)
{
	CloneRule *rule = NULL;
	char *command, *text;
	int done = 0;
	unsigned long linenum = 0;

	db.trigger = fopen(TRG_DB, "r");

	if (db.trigger == NULL) {
		logDump(corelog,
				"Unable to open trigger database for read access: %s",
				strerror(errno));
		return;
	}

	while (!done) {
		if (!(sfgets(dbLine, 2048, db.trigger))) {
			if (!done) {
				unexpected_eof(TRG_DB);
			}
			done = 1;
			fclose(db.trigger);
			return;
		}
		linenum++;

		if (parse_init(&state, dbLine) != 0) {
			/*! \bug XXX be nicer here... */
			abort();
		}

		command = parse_getarg(&state);

		if (strcmp(command, "Trigger") == 0) {
			rule = NewCrule();
			rule->kill_msg = NULL;
			rule->warn_msg = NULL;
			strncpyzt(rule->mask, parse_getarg(&state),
					  sizeof(rule->mask));
			rule->mask[sizeof(rule->mask) - 1] = '\0';
			rule->trigger = atoi(parse_getarg(&state));
			rule->utrigger = atoi(parse_getarg(&state));
			rule->flags = atol(parse_getarg(&state));
			AddCrule(rule, -2);	/* -2 is magic for append to end */
		} else if (strcmp(command, "Killmsg") == 0) {
			text = parse_getallargs(&state);
			if (text && rule)
				rule->kill_msg = strdup(text);
		} else if (strcmp(command, "Warnmsg") == 0) {
			text = parse_getallargs(&state);
			if (text && rule)
				rule->warn_msg = strdup(text);
		} else if (strcmp(command, "done") == 0) {
			done = 1;
		} else {
			fprintf(stderr, "Error in reading trigger data (%s) %lu\n",
					dbLine, linenum);
			parse_cleanup(&state);
			return;
		}
#ifdef DBDEBUG
		sSend(":%s PRIVMSG " DEBUGCHAN " :Read trigger data (%s)",
			  OperServ, dbLine);
#endif

		parse_cleanup(&state);
	}

	fclose(db.trigger);
}