コード例 #1
0
ファイル: ut.cpp プロジェクト: nkirov/timetool
Ut::Ut(QWidget *parent) : QDialog(parent)
{
qDebug() << "start Ut";
	ui.setupUi(this);
	connect(ui.convert, SIGNAL(clicked()), this, SLOT(read_write()));
	connect(ui.file, SIGNAL(textChanged(QString)), this, SLOT(newfile()));
	connect(ui.cat, SIGNAL(textChanged(QString)), this, SLOT(newcat()));
	connect(ui.observatory, SIGNAL(currentIndexChanged(int)), this, SLOT(observatory(int)));
	connect(ui.dir, SIGNAL(textChanged(QString)), this, SLOT(newdir()));
	connect(ui.convert, SIGNAL(pressed()), this, SLOT(processing()));

	connect(ui.LT2UT, SIGNAL(clicked()), this, SLOT(inpfilename()));	
	connect(ui.ST2UT, SIGNAL(clicked()), this, SLOT(inpfilename()));
    connect(ui.JD2UT, SIGNAL(clicked()), this, SLOT(inpfilename()));

	red.setColor(QPalette::Base,QColor(Qt::red));
	white.setColor(QPalette::Base,QColor(Qt::white));

//	filename = "..\\data\\" + ui.file->text() + "maindata_lt.txt";

	int index = 0;
	read_cfg(index);
	newfile();

	read_cat();
	observatory(index);

	read_dst();
	inpfilename();
qDebug() << "stop Ut";
}
コード例 #2
0
ファイル: test-recv.c プロジェクト: kalgynirae/cnt-project
int main(int argc, char *argv[])
{
    if (argc != 2) {
        fprintf(stderr,"usage: client hostname\n");
        exit(1);
    }

    read_cfg(COMMON_CFG_PATH);      //to find bitfield length

    struct peer_info info;
    strcpy(info.hostname, argv[1]);
    strcpy(info.port, PORT);

    int s = make_socket_to_peer(&info);
    if (s == -1) {
        fprintf(stderr, "client: make_socket_to_peer() failed");
        exit(1);
    }

    unsigned int payload_len;
    message_t type;
    unsigned char payload[5000];

    int i;
    for (i = 0 ; i < 8 ; i++)
    {
        type = recv_msg(info.from_fd, &payload_len, payload);
        process_msg(payload, payload_len, type);
        printf("\n");
    }

    close(info.from_fd);

    return 0;
}
コード例 #3
0
ファイル: spnavd.c プロジェクト: 5263/spacenav
/* signals usr1 & usr2 are sent by the spnav_x11 script to start/stop the
 * daemon's connection to the X server.
 */
static void sig_handler(int s)
{
    int tmp;

    switch(s) {
    case SIGHUP:
        tmp = cfg.led;
        read_cfg("/etc/spnavrc", &cfg);
        if(cfg.led != tmp) {
            set_led(cfg.led);
        }
        break;

    case SIGSEGV:
        fprintf(stderr, "Segmentation fault caught, trying to exit gracefully\n");
    case SIGINT:
    case SIGTERM:
        exit(0);

#ifdef USE_X11
    case SIGUSR1:
        init_x11();
        break;

    case SIGUSR2:
        close_x11();
        break;
#endif

    default:
        break;
    }
}
コード例 #4
0
CThreadPool::CThreadPool(int nServiceType)
{
	m_nThreadSum				= 250;
	m_nThreadRunCount		= 0;

	m_ServiceType				= DogService4;
	m_bInit						= FALSE;
	m_bDebug					= FALSE;
	m_bLogger					= FALSE;
	m_bThreadPoolRun		= FALSE;
	m_bAddTaskRun			= FALSE;
	m_bEndPrint				= FALSE;
	m_bReadCfg				= FALSE;
	m_ServiceType				= nServiceType;
	m_strIniPath				= L"";
	m_strLogPath				= L"";	

	get_cfg_path();
	read_cfg();	
	get_log_path();

	m_hWaitingWork		= CreateEvent(NULL, false, false, NULL);
	m_hGotgWork			= CreateEvent(NULL, false, false, NULL);
	m_hAddTask			= CreateEvent(NULL, false, false, NULL);

	HANDLE hAddTask = (HANDLE)_beginthreadex(NULL, 0, _thr_add_task, this, 0, NULL);
	CloseHandle(hAddTask);
	HANDLE hReadCfg = (HANDLE)_beginthreadex(NULL, 0, _thr_read_config, this, 0, NULL);
	CloseHandle(hReadCfg);
	HANDLE hPrintState = (HANDLE)_beginthreadex(NULL, 0, _thr_print_state, this, 0, NULL);
	CloseHandle(hPrintState);
	
	init_thread_pool(m_nThreadSum);
}
コード例 #5
0
ファイル: front.c プロジェクト: 5263/spacenav
void frontend(int pfd)
{
	int argc = 0;
	int ruid = getuid();
#ifdef __linux__
	int setresuid(uid_t ruid, uid_t euid, uid_t suid);
	setresuid(ruid, ruid, ruid);
#else
	seteuid(ruid);
#endif

	pipe_fd = pfd;

	gtk_init(&argc, 0);

	read_cfg(CFGFILE, &cfg);

	win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(win), "spacenavd configuration");
	g_signal_connect(G_OBJECT(win), "delete_event", G_CALLBACK(gtk_main_quit), 0);
	gtk_container_set_border_width(GTK_CONTAINER(win), 4);

	layout();

	gtk_widget_show_all(win);

	gtk_main();
}
コード例 #6
0
void CThreadPool::read_config_run()
{	
	while(!m_bReadCfg)
	{	
		read_cfg();
		Sleep(1000);
	}	
}
コード例 #7
0
bool read_host_cfg(char **data, size_t *line_count) {
    loff_t size_ = 0;

    if (!read_cfg(WL_NETWORK, data, &size_))
        return false;

    tok_str(data, '\n');
    // 根据 '\0' 确定行数更加准确
    *line_count = get_line_count(*data, size_);

    return true;
}
コード例 #8
0
ファイル: common_wrt.c プロジェクト: tlsalmin/vlbi-streamer
int common_readcfg(struct recording_entity *re, void *opti)
{
  int err;
  struct common_io_info *ioi = re->opt;
  struct opt_s *opt = opti;
  char *cfgname = (char *)malloc(sizeof(char) * FILENAME_MAX);
  CHECK_ERR_NONNULL(cfgname, "cfgname malloc");

  sprintf(cfgname, "%s%i%s%s%s%s%s", ROOTDIRS, ioi->id, "/", opt->filename,
          "/", opt->filename, ".cfg");
  err = read_cfg(&(opt->cfg), cfgname);
  free(cfgname);

  return err;
}
コード例 #9
0
ファイル: spnavd.c プロジェクト: 5263/spacenav
/* signals usr1 & usr2 are sent by the spnav_x11 script to start/stop the
 * daemon's connection to the X server.
 */
void sig_handler(int s)
{
	int tmp;

	switch(s) {
	case SIGHUP:
		tmp = cfg.led;
		read_cfg("/etc/spnavrc", &cfg);
		if(cfg.led != tmp) {
			set_led(cfg.led);
		}
		break;

	case SIGSEGV:
		fprintf(stderr, "Segmentation fault caught, trying to exit gracefully\n");
	case SIGINT:
	case SIGTERM:
		close_x11();	/* call to avoid leaving garbage in the X server's root windows */
		close_dev();
		remove(PIDFILE);
		exit(0);

#ifdef USE_X11
	case SIGUSR1:
		init_x11();
		break;

	case SIGUSR2:
		close_x11();
		break;
#endif

	default:
		break;
	}
}
コード例 #10
0
ファイル: mrbig.c プロジェクト: qbranch-code/Qbranch.MrBig
void mrbig(void)
{
	char *p;
	time_t t, lastrun;
	int sleeptime, i;
	char hostname[256];
	DWORD hostsize;

	/*
	 * install exception logging/stacktrace handler.
	 * We need to resolve the symbol at run time because windows 2000
	 * does not have it.
	 */
	do {
		HMODULE dll;
		PVOID (*ptr) (ULONG First,PVECTORED_EXCEPTION_HANDLER Handler) = NULL;
		dll = LoadLibraryEx("kernel32.dll", NULL, 0);
		if (dll == NULL)
			break;
		ptr = (typeof(ptr))GetProcAddress(dll, "AddVectoredExceptionHandler");
		if (ptr == NULL)
			break;
		ptr(1, VectoredExceptionHandler);
		mrlog("VectoredExceptionHandler handler has been installed");
	} while(0);

	if (debug) {
		mrlog("mrbig()");
	}
	for (i = 0; _environ[i]; i++) {
		startup_log("%s", _environ[i]);
	}
	for (;;) {
		if (debug) mrlog("main loop");
		read_cfg("mrbig", cfgfile);
		readcfg();
		t = time(NULL);
		strlcpy(now, ctime(&t), sizeof now);
		p = strchr(now, '\n');
		if (p) *p = '\0';
		hostsize = sizeof hostname;
		if (GetComputerName(hostname, &hostsize)) {
			for (i = 0; hostname[i]; i++)
				hostname[i] = tolower(hostname[i]);
			snprcat(now, sizeof now, " [%s]", hostname);
		}

		cpu();
		check_chunks("after cpu test");

		disk();
		check_chunks("after disk test");

		memory();
		check_chunks("after memory test");

		msgs();
		check_chunks("after msgs test");

		procs();
		check_chunks("after procs test");

		svcs();
		check_chunks("after svcs test");

		wmi();
		check_chunks("after wmi test");

		if (pickupdir[0]) ext_tests();

		lastrun = t;
		t = time(NULL);
		if (t < lastrun) {
			mrlog("mainloop: timewarp detected, sleep for %d",
				mrloop);
			sleeptime = mrloop;
		} else {
			sleeptime = mrloop-(t-lastrun);
		}
		if (sleeptime < SLEEP_MIN) sleeptime = SLEEP_MIN;
		if (debug) mrlog("started at %d, finished at %d, sleep for %d",
			(int)lastrun, (int)t, sleeptime);
		clear_cfg();
		if (debug) {
			dump_chunks();
			check_chunks("after main loop");
		}
		Sleep(sleeptime*1000);
	}
}
コード例 #11
0
ファイル: macfanctl.c プロジェクト: ChrisAldama/macfanctld
int main(int argc, char *argv[])
{
	int i;
	int daemon = 1;

	// setup daemon
	signal(SIGCHLD, SIG_IGN); 			// ignore child
	signal(SIGTSTP, SIG_IGN); 			// ignore tty signals
	signal(SIGTTOU, SIG_IGN);
	signal(SIGTTIN, SIG_IGN);
	signal(SIGINT, signal_handler); 	// catch Ctrl-C signal (terminating in foreground mode)
	signal(SIGHUP, signal_handler); 	// catch hangup signal (reload config)
	signal(SIGTERM, signal_handler); 	// catch kill signal

	for(i = 1; i < argc; ++i)
	{
		if(strcmp(argv[i], "-f") == 0)
		{
			daemon = 0;
		}		
		else
		{
			usage();
		}
	}

	if(daemon)
	{
		daemonize();
	}
	else
	{
		printf("Running in foreground, log to stdout.\n");
	}

	// main loop

	read_cfg(CFG_FILE);

	find_applesmc();
	scan_sensors();

	running = 1;
	while(running)
	{
		adjust();

		logger();

		if(reload)
		{
			read_cfg(CFG_FILE);
			scan_sensors();
			reload = 0;
		}

		sleep(update_time);
	}

	// close pid file and delete it

	if(lock_fd != -1)
	{
		close(lock_fd);
		unlink(PID_FILE);
	}

	printf("Exiting.\n");

	return 0;
}
コード例 #12
0
ファイル: mypool_tmp0331.c プロジェクト: jianglichi/code
main(int arc,char **argv){
     int port,*ret,option=1;
     int i;
     char *thishost;
     struct hostent* hostdata;
     struct sockaddr_in sadd;
     signal( SIGPIPE, sigpipefunc );

     
     if(arc!=3){
         printf("parater is error\n");
         exit(1);
     }
	
     
     read_cfg();          
	
     thishost=argv[1];
     port=atoi(argv[2]);
     
     if( (hostdata = gethostbyname( thishost )) == NULL ){
         printf("gethostbyname error!!\n");
         exit(1);
     }     
     sadd.sin_family = AF_INET;
     sadd.sin_port   = htons(port);
     sadd.sin_addr   = *(struct in_addr*) hostdata->h_addr;            
     sock = socket( AF_INET, SOCK_STREAM, 0 );
     if(sock==-1){
         printf("socket create error\n");
         exit(1);  
     }     

     setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (const void *)&option,sizeof( option ) );
     setsockopt (sock, SOL_SOCKET, SO_RCVTIMEO, (char *)_timeout,sizeof( _timeout ) );

     
     if (bind(sock, (struct sockaddr*) &sadd, sizeof(struct sockaddr_in)) == -1) { 
         perror("(bind) ");  
         exit(1);  
     } 


     if(listen(sock, SOMAXCONN) == -1) { 
         perror("(listen) "); 
         exit(1);   
     }else{
         printf("listening..\n");
     }      	
	
	
     t=time(NULL);
     datetime=localtime(&t);			
	
	 poci=(pool_oci *)malloc(sizeof(pool_oci)*_oracle_conns);
	 ph=(pthread_t *)malloc(sizeof(pthread_t)*_oracle_conns);
	
     for (i=0 ;i<_oracle_conns;i++){
         poci[i].commitmode=0;
         poci[i].busy=0;
         poci[i].datetime=0;
         poci[i].transfer=0;
         poci[i].id=-1;
         poci[i].size=0;
         poci[i].i=i;
		 
	     if(oci_login(&poci[i],host,user,pwd)==-1){
	         printf("oracle login fail!!\n");
	         exit(1);
	     }                  
     }
     
     //pthread_create(&ph_check, NULL, &thread_process_timeout,NULL);  
               
     for (i=0;i<threadmax;i++){
     	   printf("create thread %d\n",i);
         pthread_create(&ph[i], NULL, &thread_process,NULL);
		 sleep(1);
     }
     
     while(1){   
          printf("main program sleep\n");
     	  sleep(10000);
     	  pause();
     }
}
コード例 #13
0
static int
googleauth_login(const char *username, const char *password)
{
   uint8_t *secret = NULL;
   int      secretLen = 0;
   int      code = 0;
   char     *endptr;
   Config   config;

   if (read_cfg(username, &config)) {
		syslog(LOG_INFO, "user %s: error in user conf file", username);
      exit(EXIT_FAILURE);
   }

   long l = strtol(password, &endptr, 10);
   if (l < 0 || *endptr) {
      syslog(LOG_ERR, "user %s: failed to extract verification code", 
            username);
      return (AUTH_FAILED);
   }

   code = (int)l;

   if ((secret = get_shared_secret(username, &secretLen))) {
      int advance = 0;
      if (check_scratch_codes(username, code)) {
         if (config.is_totp) { 
            if (check_timebased_code(&config, secret, secretLen, code)) { 
#if 0 
               syslog(LOG_ERR, "user %s code %d: " 
                     "check_timebased_code != 0", 
                        username,
                        code); 
#else
               syslog(LOG_ERR, "user %s: " 
                     "check_timebased_code != 0", 
                        username);
#endif
               if (secret) {
                  memset(secret, 0, secretLen);
                  free(secret);
               }
               return (AUTH_FAILED);
            }
         } else { 
            int hotp_counter = get_hotp_counter(username);
            if (check_counterbased_code(&config, secret, secretLen, code,
                                        hotp_counter, &advance)) {
               syslog(LOG_ERR, "user %s: check_counterbased_code != 0",
                        username);
               if (secret) {
                  memset(secret, 0, secretLen);
                  free(secret);
               }
               return (AUTH_FAILED);
            }

            // If an hotp login attempt has been made, 
            // the counter must always be advanced by at least one
            if (advance) {
               if (advance_counter_by(username, hotp_counter, advance)) {
                  syslog(LOG_ERR, "user %s: failed to advance hotp counter",
                        username);
                  if (secret) { 
                     memset(secret, 0, secretLen);
                     free(secret);
                  }
                  return (AUTH_FAILED);
               }
            }
         }  
      }

      if (secret) {
         memset(secret, 0, secretLen);
         free(secret);
      }

      return (AUTH_OK);
   }

   return (AUTH_FAILED);
}
コード例 #14
0
ファイル: sqlog.c プロジェクト: vittrok/brj
int main()
{

    struct tm t1;
    struct tm t2;
//    struct tm *ct1,*ct2;
    char *s=getenv("REQUEST_METHOD");
    char *endptr;
    int i;
    unsigned int contentlength;
    char buff[10000];
    char a,b;
    const char *len1 = getenv("CONTENT_LENGTH");

/*
    printf("Content-Type: text/html\n\n");
    printf( "<HTML><HEAD><TITLE>Environment</TITLE></HEAD>\n");
    printf( "<BODY>\n");
    printf( "Your request is: %s<BR><br>\n",getenv("REQUEST_STRING"));
    printf( "Variables:<BR>\n");
    printf( "<I><B>REQUEST_METHOD</B></I>=%s<br>\n",getenv("REQUEST_METHOD"));
    printf( "<I><B>QUERY_STRING</B></I>=%s<br>\n",getenv("QUERY_STRING"));
    printf( "<I><B>CONTENT_LENGTH</B></I>=%s<br>\n",getenv("CONTENT_LENGTH"));
    printf( "<I><B>CONTENT_TYPE</B></I>=%s<br>\n",getenv("CONTENT_TYPE"));
    printf( "<I><B>GATEWAY_INTERFACE</B></I>=%s<br>\n",getenv("GATEWAY_INTERFACE"));
    printf( "<I><B>REMOTE_ADDR</B></I>=%s<br>\n",getenv("REMOTE_ADDR"));
    printf( "<I><B>REMOTE_HOST</B></I>=%s<br>\n",getenv("REMOTE_HOST"));
    printf( "<I><B>SCRIPT_NAME</B></I>=%s<br>\n",getenv("SCRIPT_NAME"));
    printf( "<I><B>SCRIPT_FILENAME</B></I>=%s<br>\n",getenv("SCRIPT_FILENAME"));
    printf( "<I><B>SERVER_NAME</B></I>=%s<br>\n",getenv("SERVER_NAME"));
    printf( "<I><B>SERVER_PORT</B></I>=%s<br>\n",getenv("SERVER_PORT"));
    printf( "<I><B>SERVER_PROTOCOL</B></I>=%s<br>\n",getenv("SERVER_PROTOCOL"));
    printf( "<I><B>SERVER_SOFTWARE</B></I>=%s<br>\n",getenv("SERVER_SOFTWARE"));
    printf( "<I><B>HTTP_ACCEPT</B></I>=%s<br>\n",getenv("HTTP_ACCEPT"));
    printf( "<I><B>HTTP_USER_AGENT</B></I>=%s<br>\n",getenv("HTTP_USER_AGENT"));
    printf( "</BODY></HTML>\n");
				    			    		    
    exit(2);
*/
    
    if(s!=NULL)
    {
	if(strcmp(s,"GET")==0)
	{
	    strcpy(buff,getenv("QUERY_STRING"));
	}else
	if(strcmp(s,"POST")==0)
	{
	    contentlength=strtol(len1, &endptr, 10);
	    fread(buff, contentlength, 1, stdin); 
	}
	ParseInput(buff);
    }

    if (InputCount!=10) print_err();

    print_hdr();

    t1.tm_mday=atoi(InputValues[0]);
    t1.tm_mon=atoi(InputValues[1])-1;
    t1.tm_year=atoi(InputValues[2])-1900;
    t1.tm_hour=atoi(InputValues[3]);
    t1.tm_min=atoi(InputValues[4]);
    t1.tm_sec=0;
    t2.tm_mday=atoi(InputValues[5]);
    t2.tm_mon=atoi(InputValues[6])-1;
    t2.tm_year=atoi(InputValues[7])-1900;
    t2.tm_hour=atoi(InputValues[8]);
    t2.tm_min=atoi(InputValues[9]);
    t2.tm_sec=59;

    time1=mktime(&t1);
    time2=mktime(&t2);


/*
	ct1 = gmtime(&time1);
	
	printf("ct1 y=%d m=%d d=%d h=%d mm=%d <br>\n",ct1->tm_year,ct1->tm_mon,ct1->tm_mday,ct1->tm_hour,ct1->tm_min);


	ct2 = gmtime(&time2);
	
	printf("ct2 y=%d m=%d d=%d h=%d mm=%d<br>\n",ct2->tm_year,ct2->tm_mon,ct2->tm_mday,ct2->tm_hour,ct2->tm_min);
*/

    printf("<h3>Statistics for %02d:%02d:%02d %02d:%02d - %02d:%02d:%02d %02d:%02d</h2><hr>\n",
    t1.tm_mday,t1.tm_mon+1,t1.tm_year+1900,t1.tm_hour,t1.tm_min,
    t2.tm_mday,t2.tm_mon+1,t2.tm_year+1900,t2.tm_hour,t2.tm_min);

//    printf("<h2>Statistics for %s - %s</h2><hr>\n",asctime(&t1),asctime(&t2));

//    printf("%d<br>",time1);
//    printf("%d",time2);

    read_cfg();

    qsort(entries,count,sizeof(s_entry),traf_comparer);
    puts("<h3>Sorted by traffic</h2>");
    print_results(1);

/* 


    qsort(entries,count,sizeof(s_entry),name_comparer);
    puts("<h3>Sorted by user name</h2>");
    print_results(2);

*/

    qsort(entries,count,sizeof(s_entry),ip_comparer);
    puts("<h3>Sorted by ip address</h2>");
    print_results(1);

    qsort(entries,count,sizeof(s_entry),name_comparer);
    puts("<h3>Statistics by date and time</h2>");
    print_stat_by_date_time();
    print_end();
        
    return 0;
}
コード例 #15
0
ファイル: parser.c プロジェクト: yangmeitang/darknet
network parse_network_cfg(char *filename)
{
    list *sections = read_cfg(filename);
    node *n = sections->front;
    if(!n) error("Config file has no sections");
    network net = make_network(sections->size - 1);
    size_params params;

    section *s = (section *)n->val;
    list *options = s->options;
    if(!is_network(s)) error("First section must be [net] or [network]");
    parse_net_options(options, &net);

    params.h = net.h;
    params.w = net.w;
    params.c = net.c;
    params.inputs = net.inputs;
    params.batch = net.batch;

    n = n->next;
    int count = 0;
    while(n){
        fprintf(stderr, "%d: ", count);
        s = (section *)n->val;
        options = s->options;
        layer l = {0};
        if(is_convolutional(s)){
            l = parse_convolutional(options, params);
        }else if(is_deconvolutional(s)){
            l = parse_deconvolutional(options, params);
        }else if(is_connected(s)){
            l = parse_connected(options, params);
        }else if(is_crop(s)){
            l = parse_crop(options, params);
        }else if(is_cost(s)){
            l = parse_cost(options, params);
        }else if(is_detection(s)){
            l = parse_detection(options, params);
        }else if(is_softmax(s)){
            l = parse_softmax(options, params);
        }else if(is_normalization(s)){
            l = parse_normalization(options, params);
        }else if(is_maxpool(s)){
            l = parse_maxpool(options, params);
        }else if(is_avgpool(s)){
            l = parse_avgpool(options, params);
        }else if(is_route(s)){
            l = parse_route(options, params, net);
        }else if(is_dropout(s)){
            l = parse_dropout(options, params);
            l.output = net.layers[count-1].output;
            l.delta = net.layers[count-1].delta;
            #ifdef GPU
            l.output_gpu = net.layers[count-1].output_gpu;
            l.delta_gpu = net.layers[count-1].delta_gpu;
            #endif
        }else{
            fprintf(stderr, "Type not recognized: %s\n", s->type);
        }
        l.dontload = option_find_int_quiet(options, "dontload", 0);
        option_unused(options);
        net.layers[count] = l;
        free_section(s);
        n = n->next;
        if(n){
            params.h = l.out_h;
            params.w = l.out_w;
            params.c = l.out_c;
            params.inputs = l.outputs;
        }
        ++count;
    }   
    free_list(sections);
    net.outputs = get_network_output_size(net);
    net.output = get_network_output(net);
    return net;
}
コード例 #16
0
ファイル: network.c プロジェクト: zoobab/linuxAP-eh
//----------------------------------------------------------------------
// NETWORK_MENU
//----------------------------------------------------------------------
static int network_menu()
{
    read_cfg("netcfg",nkw,SEP,nv);

    header("menu");
    oform(("POST ","/cgi-bin/setup", NULL));
    ohid("last_menu","network");
    printf("<h3>Primary Network Interface (R/L 2=wlan0 3=br0 4=eth0)</h3>");

    otbl(NULL);
    otr(NULL);
    oth("Use DHCP");
    {
	char *dhcp_sel[] = {
	    nkw[NV_P_DHCP], nv[NV_P_DHCP],
	    "Enabled", "enabled", "Disabled", "disabled",
	    NULL };
	    otd(sel("",dhcp_sel));
    }
    otr("/");

    otr(NULL);
    oth("Network Address");
    otd(itext(nkw[NV_P_ADDRESS],nv[NV_P_ADDRESS], 18, 15));
    otr("/");

    otr(NULL);
    oth("Mask Address");
    otd(itext(nkw[NV_P_NETMASK],nv[NV_P_NETMASK], 18, 15));
    otr("/");

    otr(NULL);
    oth("Broadcast Address");
    otd(itext(nkw[NV_P_BROADCAST],nv[NV_P_BROADCAST], 18, 15));
    otr("/");

    otbl("/");
    printf("<br>\n");
    printf("<h3>Secondary Network Interface (R/L 2=eth0 4=wlan0 3=N/A)</h3>\n");

    otbl(NULL);

    otr(NULL);
    oth("Use DHCP");
    {
	char *dhcp_sel[] = {
	    nkw[NV_S_DHCP], nv[NV_S_DHCP],
	    "Enabled", "enabled", "Disabled", "disabled",
	    NULL };
	    otd(sel("",dhcp_sel));
    }
    otr("/");

    otr(NULL);
    oth("Network Address");
    otd(itext(nkw[NV_S_ADDRESS],nv[NV_S_ADDRESS], 18, 15));
    otr("/");

    otr(NULL);
    oth("Mask Address");
    otd(itext(nkw[NV_S_NETMASK],nv[NV_S_NETMASK], 18, 15));
    otr("/");

    otr(NULL);
    oth("Broadcast Address");
    otd(itext(nkw[NV_S_BROADCAST],nv[NV_S_BROADCAST], 18, 15));
    otr("/");

    otbl("/");

    printf("<br>\n");
    printf("<h3>Miscellaneous Configuration Data</h3>\n");

    otbl(NULL);

    otr(NULL);
    oth("TFTP Host");
    otd(itext(nkw[NV_TFTPHOST], nv[NV_TFTPHOST], 18,15));
    otr("/");

    otr(NULL);
    oth("Log (syslog) Server");
    otd(itext(nkw[NV_LOGSVR], nv[NV_LOGSVR], 18,15));
    otr("/");

    otr(NULL);
    oth("Watchdog interfaces (sepparated with spaces)");
    otd(itext(nkw[NV_IW_WATCHDOG_IF], nv[NV_IW_WATCHDOG_IF], 18,15));
    otr("/");

    otr(NULL);
    oth("Watchdog time interval (sec)");
    otd(itext(nkw[NV_IW_WATCHDOG_TIME], nv[NV_IW_WATCHDOG_TIME], 18,15));
    otr("/");

    otr(NULL);
    oth("Remote Date Host");
    otd(itext(nkw[NV_TIMESVR], nv[NV_TIMESVR], 18,15));
    otr("/");

    otr(NULL);
    oth("Default Router");
    otd(itext(nkw[NV_ROUTER], nv[NV_ROUTER], 18,15));
    otr("/");

    otr(NULL);
    oth("SWAP (NBD) Server");
    otd(itext(nkw[NV_SWAPSVR], nv[NV_SWAPSVR], 18,15));
    otr("/");

    otr(NULL);
    oth("SWAP (NBD) Port");
    otd(itext(nkw[NV_SWAPPORT], nv[NV_SWAPPORT], 18,15));
    otr("/");

    otr(NULL);
    oth("Masquerade Network");
    otd(itext(nkw[NV_MASQ_NET], nv[NV_MASQ_NET], 18,15));
    otr("/");

    otbl("/");

    printf("<br>\n");
    ohid("menu","main");
    osub("f_click","OK");
    printf("&nbsp;&nbsp;&nbsp;\n");
    osub("f_click", "CANCEL");

    oform(("/"));
    printf("</body></html>\n");
}
コード例 #17
0
ファイル: lifl.c プロジェクト: binaryf/LIFL
int main(int argc,char *argv[])
{
    id=0;

    umask(0);

    if(atexit(exit_gracefull)!=0)
    {
        fprintf(stderr,"Sorry the program encountered a problem.\nExiting.\n");
        exit(EXIT_FAILURE);
    }

    static struct fuse_operations op;

    op.init           =lifl_init;

    op.getattr        =xmp_getattr;
    op.access         =xmp_access;
    op.readlink       =xmp_readlink;
    op.readdir        =xmp_readdir;
    op.mknod          =xmp_mknod;
    op.mkdir          =xmp_mkdir;
    op.symlink        =xmp_symlink;
    op.unlink         =xmp_unlink;
    op.rmdir          =xmp_rmdir;
    op.rename         =xmp_rename;
    op.link           =xmp_link;
    op.chmod          =xmp_chmod;
    op.chown          =xmp_chown;
    op.truncate       =xmp_truncate;

    #ifdef HAVE_UTIMENSAT
    op.utimens        =xmp_utimens,
    #endif

    op.open           =xmp_open;
    op.read           =xmp_read;
    op.write          =xmp_write;
    op.statfs         =xmp_statfs;
    op.release        =xmp_release;
    op.fsync          =xmp_fsync;

    #ifdef HAVE_POSIX_FALLOCATE
    op.fallocate      =xmp_fallocate;
    #endif

    #ifdef HAVE_SETXATTR
    op.setxattr       =xmp_setxattr;
    op.getxattr       =xmp_getxattr;
    op.listxattr      =xmp_listxattr;
    op.removexattr    =xmp_removexattr;
    #endif

    char config_file[255];
    strncpy(config_file,DEFAULT_CONF_NAME,255);
  
    static struct option long_options[]=
    {
            {"help",          no_argument,       0, 'h'},
            {"config",        required_argument, 0, 'c'},
            {"test",          no_argument,       0, 't'},
            {0,               0,                 0,  0 }
    };

    while(1)
    {
        int option_index=0;
        int ch=getopt_long(argc,argv,"hc:t",long_options,&option_index);
        
        if(ch==-1) break;
        switch (ch)
        {
        case 'h':
            fprintf(stdout,"-h --help\n");
            fprintf(stdout,"-c --config <filename>\n");
            fprintf(stdout,"-t --test\n");
            exit(EXIT_SUCCESS);    
        case 'c':
            strncpy(config_file,optarg,255);  
            break;
        case 't':
            read_cfg(config_file);
            test_cfg();
            errno=0;
            exit(EXIT_SUCCESS);
        }
    }

    if(optind<argc)
    {
        while(optind<argc) fprintf(stderr,"%s is not a valid argument\n",argv[optind++]);
    }

    read_cfg(config_file);
    
    conn=mysql_init(NULL);
    if(!conn) sql_err(conn,NULL);
    if(!mysql_real_connect(conn,conf.db_host,conf.db_username,conf.db_password,conf.db_database,conf.db_port,NULL,0)) sql_err(conn,NULL);

    sql_get_last_id();

    fprintf(stdout,"Starting up...\n");
    sleep(2);
    
    chdir(conf.mountpoint);
    fd0=open(".",0);

    char *fuse_argv[8];
    memset(fuse_argv,0,sizeof(fuse_argv));

    int fuse_argc;
    fuse_argc=0;

    fuse_argv[fuse_argc++]=argv[0];
    fuse_argv[fuse_argc++]=conf.mountpoint;

    if(conf.allow_other)
    {
        fuse_argv[fuse_argc++]="-o";
        fuse_argv[fuse_argc++]="allow_other";
    }

    if(conf.default_permissions)
    {
        fuse_argv[fuse_argc++]="-o";
        fuse_argv[fuse_argc++]="default_permissions";
    }
    
    if(conf.nonempty)
    {
        fuse_argv[fuse_argc++]="-o";
        fuse_argv[fuse_argc++]="nonempty";
    }

    fuse_argv[fuse_argc++]="-o";
    fuse_argv[fuse_argc++]="use_ino";
    fuse_argv[fuse_argc]=NULL;

    fuse_main(fuse_argc,fuse_argv,&op,NULL);
    mysql_close(conn);
    exit(EXIT_SUCCESS);
}
コード例 #18
0
ファイル: simple_demon.c プロジェクト: eselyavka/C
void set_main_vars()
{
        char *running_dir1="[Rr][Uu][Nn][Nn][Ii][Nn][Gg]_[Dd][Ii][Rr]=([A-Za-z1-9_/])";
        char *r_dir;
	char *lock_file="[Ll][Oo][Cc][Kk]_[Ff][Ii][Ll][Ee]=([A-Za-z1-9_/])";
	char *l_file;
	char *log_file="[Ll][Oo][Gg]_[Ff][Ii][Ll][Ee]=([A-Za-z1-9_/])";
	char *lg_file;
	char *from_dir="[Ff][Rr][Oo][Mm]_[Dd][Ii][Rr]=([A-Za-z1-9_/])";
	char *fr_dir;
	char *to_dir="[Tt][Oo]_[Dd][Ii][Rr]=([A-Za-z1-9_/])";
	char *todir;
	r_dir=NULL;
	l_file=NULL;
	lg_file=NULL;
	fr_dir=NULL;
	todir=NULL;

        r_dir=read_cfg(running_dir1);
	//printf("%s\n",r_dir);
	chomp(r_dir);
	if ((r_dir!=NULL) && (strlen(r_dir) < 255)) 
	{
		strncpy(RUNNING_DIR, r_dir, sizeof(RUNNING_DIR));
		//printf("SET_MAIN_VARS: %s\n",RUNNING_DIR);
	}
	else
	{
		strncpy(RUNNING_DIR,"/tmp",sizeof(RUNNING_DIR));
	}

	l_file=read_cfg(lock_file);
	//printf("%s\n",l_file);
	chomp(l_file);
	if ((l_file!=NULL) && (strlen(l_file) < 255))	
	{
		strncpy(LOCK_FILE,l_file,sizeof(LOCK_FILE));
		//printf("%s\n",LOCK_FILE);
	}
	else
	{
		strncpy(LOCK_FILE,"/tmp/mvd.lock",sizeof(LOCK_FILE));
	}

	lg_file=read_cfg(log_file);
	//printf("%s\n",lg_file);
	chomp(lg_file);
	if (lg_file!=NULL && (strlen(lg_file) < 255))
	{
		strncpy(LOG_FILE,lg_file,sizeof(LOG_FILE));
		//printf("%s\n",LOG_FILE);
	}
	else
	{
		strncpy(LOG_FILE,"/var/log/mvd.log",sizeof(LOG_FILE));
	}

	fr_dir=read_cfg(from_dir);
	//printf("%s",fr_dir);
	chomp(fr_dir);
	if (fr_dir!=NULL && (strlen(fr_dir) < 255))
	{
		strncpy(FROM_DIR,fr_dir,sizeof(FROM_DIR));
		//printf("%s\n",FROM_DIR);
	}
	else
	{
		strncpy(FROM_DIR,"/usr/local/samba/ftp/",sizeof(FROM_DIR));
	}

	todir=read_cfg(to_dir);
	//printf("%s\n",todir);
	chomp(todir);
	if (todir!=NULL && (strlen(todir) < 255))
	{
		strncpy(TO_DIR,todir,sizeof(TO_DIR));
		//printf("%s\n",TO_DIR);
	}
	else
	{
		strncpy(TO_DIR,"/usr/local/ftp/timur/",sizeof(TO_DIR));
	}
}
コード例 #19
0
ファイル: parser.c プロジェクト: EricDoug/darknet
network parse_network_cfg(char *filename)
{
    list *sections = read_cfg(filename);
    node *n = sections->front;
    if(!n) error("Config file has no sections");
    network net = make_network(sections->size - 1);
    size_params params;

    section *s = (section *)n->val;
    list *options = s->options;
    if(!is_network(s)) error("First section must be [net] or [network]");
    parse_net_options(options, &net);

    params.h = net.h;
    params.w = net.w;
    params.c = net.c;
    params.inputs = net.inputs;
    params.batch = net.batch;
    params.time_steps = net.time_steps;

    size_t workspace_size = 0;
    n = n->next;
    int count = 0;
    free_section(s);
    while(n){
        params.index = count;
        fprintf(stderr, "%d: ", count);
        s = (section *)n->val;
        options = s->options;
        layer l = {0};
        if(is_convolutional(s)){
            l = parse_convolutional(options, params);
        }else if(is_local(s)){
            l = parse_local(options, params);
        }else if(is_activation(s)){
            l = parse_activation(options, params);
        }else if(is_deconvolutional(s)){
            l = parse_deconvolutional(options, params);
        }else if(is_rnn(s)){
            l = parse_rnn(options, params);
        }else if(is_gru(s)){
            l = parse_gru(options, params);
        }else if(is_crnn(s)){
            l = parse_crnn(options, params);
        }else if(is_connected(s)){
            l = parse_connected(options, params);
        }else if(is_crop(s)){
            l = parse_crop(options, params);
        }else if(is_cost(s)){
            l = parse_cost(options, params);
        }else if(is_detection(s)){
            l = parse_detection(options, params);
        }else if(is_softmax(s)){
            l = parse_softmax(options, params);
        }else if(is_normalization(s)){
            l = parse_normalization(options, params);
        }else if(is_batchnorm(s)){
            l = parse_batchnorm(options, params);
        }else if(is_maxpool(s)){
            l = parse_maxpool(options, params);
        }else if(is_avgpool(s)){
            l = parse_avgpool(options, params);
        }else if(is_route(s)){
            l = parse_route(options, params, net);
        }else if(is_shortcut(s)){
            l = parse_shortcut(options, params, net);
        }else if(is_dropout(s)){
            l = parse_dropout(options, params);
            l.output = net.layers[count-1].output;
            l.delta = net.layers[count-1].delta;
#ifdef GPU
            l.output_gpu = net.layers[count-1].output_gpu;
            l.delta_gpu = net.layers[count-1].delta_gpu;
#endif
        }else{
            fprintf(stderr, "Type not recognized: %s\n", s->type);
        }
        l.dontload = option_find_int_quiet(options, "dontload", 0);
        l.dontloadscales = option_find_int_quiet(options, "dontloadscales", 0);
        option_unused(options);
        net.layers[count] = l;
        if (l.workspace_size > workspace_size) workspace_size = l.workspace_size;
        free_section(s);
        n = n->next;
        ++count;
        if(n){
            params.h = l.out_h;
            params.w = l.out_w;
            params.c = l.out_c;
            params.inputs = l.outputs;
        }
    }   
    free_list(sections);
    net.outputs = get_network_output_size(net);
    net.output = get_network_output(net);
    if(workspace_size){
    //printf("%ld\n", workspace_size);
#ifdef GPU
        net.workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1);
#else
        net.workspace = calloc(1, workspace_size);
#endif
    }
    return net;
}
コード例 #20
0
ファイル: main.c プロジェクト: appleorange1/asus-rt-n12-lx
int
main(int argc, char *argv[])
{
	int _argc = 0;
	char *_argv[5];
	pid_t pid;
	int execed = 0;

	int n, nfd, tflags = 0, ch;
	struct timeval *tvp, waittime;
	struct itimerval itval;
	fd_set ibits;
	sigset_t sigset, osigset;

	while ((ch = getopt(argc, argv, "D012bsqtdg")) != EOF) {
		switch (ch) {
			case 'D':
				execed = 1;
				break;
			case '0': ripversion = 0; break;
			case '1': ripversion = 1; break;
			case '2': ripversion = 2; break;
			case 'b': multicast = 0; break;
			case 's': supplier = 1; break;
			case 'q': supplier = 0; break;
			case 't': 
				tflags++;
				break;
			case 'd': 
				debug++;
				setlogmask(LOG_UPTO(LOG_DEBUG));
				break;
			case 'g': gateway = 1; break;
			default:
				fprintf(stderr, "usage: routed [ -1bsqtdg ]\n");
				exit(1);
		}
	}
	
	// Modified by Mason Yu
	sleep(2);
	/*
	if(!check_pid()) {
		// Commented by Mason Yu
		//write_cfg();
		exit(1);
	}
	*/
	
	if (!execed) {
		if ((pid = vfork()) < 0) {
			fprintf(stderr, "vfork failed\n");
			exit(1);
		} else if (pid != 0) {
			exit(0);
		}
		
		for (_argc=0; _argc < argc; _argc++ )
			_argv[_argc] = argv[_argc];
		_argv[0] = runPath;
		_argv[argc++] = "-D";
		_argv[argc++] = NULL;
		execv(_argv[0], _argv);
		/* Not reached */
		fprintf(stderr, "Couldn't exec\n");
		_exit(1);

	} else {
		setsid();
	}

	getkversion();

	sock = getsocket();
	assert(sock>=0);

	openlog("routed", LOG_PID | LOG_ODELAY, LOG_DAEMON);

#if 0
	if (debug == 0 && tflags == 0) {
#ifndef EMBED
		switch (fork()) {
			case -1: perror("fork"); exit(1);
			case 0: break;  /* child */
			default: exit(0);   /* parent */
		}
#endif
		close(0);
		close(1);
		close(2);
		setsid();
		setlogmask(LOG_UPTO(LOG_WARNING));
	}
	else 
#endif
	{
		setlogmask(LOG_UPTO(LOG_DEBUG));
	}

	/*
	 * Any extra argument is considered
	 * a tracing log file.
	 * 
	 * Note: because traceon() redirects stderr, anything planning to
	 * crash on startup should do so before this point.
	 */

	if (argc > 1) {
		traceon(argv[argc - 1]);
	}
	while (tflags-- > 0) {
		bumploglevel();
	}

	gettimeofday(&now, NULL);

	/*
	 * Collect an initial view of the world by
	 * checking the interface configuration and the gateway kludge
	 * file.  Then, send a request packet on all
	 * directly connected networks to find out what
	 * everyone else thinks.
	 */
	 read_cfg();
	rtinit();
	ifinit();
	gwkludge();

	if (gateway > 0) {
		rtdefault();
	}

	if (supplier < 0) {
		supplier = 0;
	}

	signal(SIGALRM, timer);
	signal(SIGHUP, hup);
	signal(SIGTERM, hup);
        signal(SIGTERM, terminate_routed); //RTK WiSOC modify for deleting all route entry
	signal(SIGINT, rtdeleteall);
	signal(SIGUSR1, sigtrace);
	signal(SIGUSR2, sigtrace);

	itval.it_interval.tv_sec = TIMER_RATE;
	itval.it_value.tv_sec = TIMER_RATE;
	itval.it_interval.tv_usec = 0;
	itval.it_value.tv_usec = 0;

	srandom(time(NULL) ^ getpid());

	if (setitimer(ITIMER_REAL, &itval, (struct itimerval *)NULL) < 0) {
		syslog(LOG_ERR, "setitimer: %m\n");
	}
	
	// Kaohj
//#ifdef EMBED //WiSOC we use pid file for system init
	write_pid();
//#endif
	rip_request_send();
	rip_input_init();
	DISPLAY_BANNER;
	FD_ZERO(&ibits);
	nfd = sock + 1;			/* 1 + max(fd's) */
	for (;;) {
		FD_SET(sock, &ibits);

		/*
		 * If we need a dynamic update that was held off,
		 * needupdate will be set, and nextbcast is the time
		 * by which we want select to return.  Compute time
		 * until dynamic update should be sent, and select only
		 * until then.  If we have already passed nextbcast,
		 * just poll.
		 */
		if (needupdate) {
			waittime = nextbcast;
			timevalsub(&waittime, &now);
			if (waittime.tv_sec < 0) {
				waittime.tv_sec = 0;
				waittime.tv_usec = 0;
			}
			if (traceactions)
				fprintf(ftrace,
				 "select until dynamic update %ld/%ld sec/usec\n",
				    (long)waittime.tv_sec, (long)waittime.tv_usec);
			tvp = &waittime;
		}
		else {
			tvp = (struct timeval *)NULL;
		}

		n = select(nfd, &ibits, 0, 0, tvp);
		if (n <= 0) {
			/*
			 * Need delayed dynamic update if select returned
			 * nothing and we timed out.  Otherwise, ignore
			 * errors (e.g. EINTR).
			 */
			if (n < 0) {
				if (errno == EINTR)
					continue;
				syslog(LOG_ERR, "select: %m");
			}
			sigemptyset(&sigset);
			sigaddset(&sigset, SIGALRM);
			sigprocmask(SIG_BLOCK, &sigset, &osigset);
			if (n == 0 && needupdate) {
				if (traceactions)
					fprintf(ftrace,
					    "send delayed dynamic update\n");
				(void) gettimeofday(&now,
					    (struct timezone *)NULL);
				toall(supply, RTS_CHANGED,
				    (struct interface *)NULL);
				lastbcast = now;
				needupdate = 0;
				nextbcast.tv_sec = 0;
			}
			sigprocmask(SIG_SETMASK, &osigset, NULL);
			continue;
		}

		gettimeofday(&now, (struct timezone *)NULL);
		sigemptyset(&sigset);
		sigaddset(&sigset, SIGALRM);
		sigprocmask(SIG_BLOCK, &sigset, &osigset);

		if (FD_ISSET(sock, &ibits)) {
			process(sock);
		}

		/* handle ICMP redirects */
		sigprocmask(SIG_SETMASK, &osigset, NULL);
	}
}
コード例 #21
0
ファイル: wlan.c プロジェクト: zoobab/linuxAP-eh
//----------------------------------------------------------------------
// WLAN_MENU
//----------------------------------------------------------------------
static int wlan_menu() {
    char **interface_list;
    char *filename;

    sprintf(bigbuf,"%s/wlan", globs.cfgdir);
    interface_sel = getenv("CGI_interface_sel");
    interface_list = get_file_chooser(bigbuf,interface_sel,"interface_sel","New Interface");
    if(interface_sel == NULL) {
	interface_sel = strdup(interface_list[1]);
    }

    sprintf(bigbuf,"wlan/%s", interface_sel);
    filename = strdup(bigbuf);
    read_cfg(filename,wkw,SEP,wv);
    free(filename);


    header("wlan");

    out_refresh_script();

    oform(("POST", "/cgi-bin/setup", "formw"));
    ohid("last_menu","wlan");
    ohid("j_click", "IGNORE");

    printf("<h3>Wireless Configuration Options</h3>\n");

    otbl(NULL);

    otr(NULL);
    oth("Wireless Interface");
    if (interface_sel[0] == 0 || strcmp(interface_sel,"__new") == 0) {
	otd(itext("interface_sel", "New Interface", 15, 15));
    } else {	
	otd(sel("onchange=\"send()\"", interface_list));
    }
    otr("/");

    otr(NULL);
    oth("Station ID (ESSID)");
    otd(itext(wkw[WLK_ESSID], wv[WLK_ESSID], 15, 12));
    otr("/");

    otr(NULL);
    oth("Security options (*)");
    {
	char *sec_sel[] = {
	    wkw[WLK_SECURITY], wv[WLK_SECURITY],
	    "None",                             "0",
	    "Hide SSID in beacon frames",       "1",
	    "Ignore clients with \"ANY\" SSID", "2",
	    "Both",                             "3",
	    NULL };
	    otd(sel("",sec_sel));
    }
    otr("/");

    otr(NULL);
    oth("Channel");
    {
	char *chan_sel[] = {
	    wkw[WLK_CHANNEL], wv[WLK_CHANNEL],
	    "Chan 1", "1",
	    "Chan 2", "2",
	    "Chan 3", "3",
	    "Chan 4", "4",
	    "Chan 5", "5",
	    "Chan 6", "6",
	    "Chan 7", "7",
	    "Chan 8", "8",
	    "Chan 9", "9",
	    "Chan 10", "10",
	    "Chan 11", "11",
	    "Chan 12", "12",
	    "Chan 13", "13",
	    NULL };
	    otd(sel("",chan_sel));
    }
    otr("/");

    otr(NULL);
    oth("Antenna Select RX");
    {
	char *aslr_list[] = {
	    wkw[WLK_ANTSEL_RX], wv[WLK_ANTSEL_RX],
	    "Default", "0", "Diversity", "1", "Low", "2", "High", "3",
	    NULL };
	    otd(sel("",aslr_list));
    }
    otr("/");

    otr(NULL);
    oth("TX");
    {
	char *aslt_list[] = {
	    wkw[WLK_ANTSEL_TX], wv[WLK_ANTSEL_TX],
	    "Default", "0", "Diversity", "1", "Low", "2", "High", "3",
	    NULL };
	    otd(sel("",aslt_list));
    }
    otr("/");

    otr(NULL);
    oth("Data Rate");
    {
	char *rate_list[] = {
	    wkw[WLK_RATE], wv[WLK_RATE],
	    "auto", "auto", "11Mb", "11Mb", "5Mb", "5Mb", "2Mb", "2Mb", "1Mb", "1Mb",
	    NULL };
	    otd(sel("",rate_list));
    }
    otr("/");

    otr(NULL);
    oth("Transmit Power");
    otd(itext(wkw[WLK_TXPOWER], wv[WLK_TXPOWER], 5, 4));
    otr("/");

    otr(NULL);
    oth("WEP Key<br>0x0x-0x0x-0x0x-0x0x-0x0x-0x0x-0x");
    otd(itext(wkw[WLK_WEP], wv[WLK_WEP], 40, 32));
    otr("/");

    otr(NULL);
    oth("Number of WDS Entries (AP Mode)");
    otd(itext(wkw[WLK_NWDS], wv[WLK_NWDS], 4, 2));
    otr("/");

    otbl("/");

    printf("(*) This option requires STA f/w ver 1.6.3 or newer\n");

    printf("<br><br>\n");
    ohid("menu","main");
    osub("f_click","OK");
    printf("&nbsp;&nbsp;&nbsp;\n");
    osub("f_click","CANCEL");
    oform(("/"));
}
コード例 #22
0
ファイル: udhcpd.c プロジェクト: BackupTheBerlios/linuxap-eh
//----------------------------------------------------------------------
// UDHCPD_MENU
//----------------------------------------------------------------------
static int udhcpd_menu()
{
    read_cfg("udhcpd.conf",uckw,uv);

    header("udhcpd");

    oform(("POST", "/cgi-bin/setup", NULL));
    ohid("last_menu","udhcpd");
    printf("<h3>DHCPD Configuration Options</h3>\n");

    otbl(NULL);

    otr(NULL);
    oth("Status");
    {
	char *stat_vals[] = {
	    ukw[UVK_ENABLE], uv[UVK_ENABLE],
	    "Enabled", "yes",
	    "Disabled", "no",
	    NULL };
	    otd(sel("",stat_vals));
    }
    otr("/");

    // This should be dynamically allocated
    otr(NULL);
    oth("Network Interface");
    {
	char *ifaces[] = {
	    ukw[UVK_INTERFACE], uv[UVK_INTERFACE],
	    "Ethernet 0 (eth0)", "eth0", 
	    "Ethernet 1 (eth1)", "eth1",
	    "Wireless 0 (wlan0)", "wlan0",
	    NULL };
	    otd(sel("",ifaces));
    }
    otr("/");

    otr(NULL);
    oth("Starting Address");
    otd(itext(ukw[UVK_START],uv[UVK_START], 18, 15));
    otr("/");

    otr(NULL);
    oth("Ending Address");
    otd(itext(ukw[UVK_END],uv[UVK_END], 18, 15));
    otr("/");

    otr(NULL);
    oth("Subnet Mask");
    otd(itext(ukw[UVK_SUBNET],uv[UVK_SUBNET], 18, 15));
    otr("/");

    otr(NULL);
    oth("Default Router");
    otd(itext(ukw[UVK_ROUTER],uv[UVK_ROUTER], 18, 15));
    otr("/");

    otr(NULL);
    oth("Domain Name Server(DNS)");
    otd(itext(ukw[UVK_DNS],uv[UVK_DNS], 18, 15));
    otr("/");

    otr(NULL);
    oth("Domain Name");
    otd(itext(ukw[UVK_DOMAIN],uv[UVK_DOMAIN], 18, 15));
    otr("/");

    otr(NULL);
    oth("Lease Time (in seconds)");
    otd(itext(ukw[UVK_LEASE], uv[UVK_LEASE], 18, 15));
    otr("/");

    otbl("/");

    printf("<br>\n");
    ohid("lease_file","/var/run/udhcpd.leases");
    ohid("menu","main");
    osub("f_click","OK");
    printf("&nbsp;&nbsp;&nbsp;\n");
    osub("f_click", "CANCEL");

    oform(("/"));
    printf("</body></html>\n");
}
コード例 #23
0
ファイル: pcat.c プロジェクト: tkorhon1/FDS-SMVgit
int convert_csv(char *csv_in, char *csv_out){
  FILE *stream;
  int i;
  int nlines;
  int ncommas, maxcommas;
  char line[1024];
  int icol, irow;
  float *times;
  int ntimes,ntimes2;
  float dt_max;

#define IJ(irow,icol) (icol) + (maxcommas+1)*(irow)

  read_cfg();

  stream = fopen(csv_in,"r");
  if(stream==NULL)return -1;

  // pass 1 - count lines, and fields

  ncommas=0;
  maxcommas=0;
  nlines=0;
  while(!feof(stream)){
    if(fgets(line,1024,stream)==NULL)break;
    nlines++;
    trim(line);
    ncommas=0;
    for(i=0;i<strlen(line);i++){
      if(line[i]==',')ncommas++;
    }
    if(ncommas>maxcommas)maxcommas=ncommas;
  }

  // allocate memory
  csv_fields=NULL;
  NewMemory((void **)&csv_fields,nlines*(maxcommas+1)*sizeof(char *));
  for(i=0;i<nlines*(maxcommas+1);i++){
    csv_fields[i]=NULL;
  }

  rewind(stream);
  irow=0;
  while(!feof(stream)){
    int nlength;
    char *line2;
    int ncommas=0;
    int icol;
    int ij;

    if(fgets(line,1024,stream)==NULL)break;

    trim(line);
    nlength = strlen(line);

    NewMemory((void **)&line2,nlength+1);
    strcpy(line2,line);


    ncommas=0;
    icol=0;
    ij = IJ(irow,icol);
    csv_fields[ij]=line2;
    for(i=0;i<nlength;i++){
      if(line2[i]=='"')line2[i]=' ';
      if(line2[i]==','){
        line2[i]=0;
        icol++;
        ij = IJ(irow,icol);
        csv_fields[ij]=line2+i+1;
      }
    }
    line2[nlength]=0;
    irow++;
  }
  fclose(stream);
  for(i=0;i<nlines*(maxcommas+1);i++){
    csv_fields[i]=trim_both(csv_fields[i]);
  }


  ntimes = nlines-2;
  NewMemory((void **)&times,ntimes*sizeof(float));
  for(i=0;i<ntimes;i++){
    char *field;
    int ij;

    ij=IJ(i+2,0);
    field = csv_fields[ij];
    sscanf(field,"%f",times+i);
  }
  dt_max=times[1]-times[0];
  for(i=2;i<ntimes;i++){
    float dt;

    dt = times[i]-times[i-1];
    if(dt>dt_max)dt_max=dt;
  }
  if(dt_skip<dt_max)dt_skip=dt_max+1;
  ntimes2=0;
  for(i=0;i<ntimes;i++){
    if(i*dt_skip<=times[ntimes-1])ntimes2++;
  }


  stream=fopen(csv_out,"w");
  if(stream==NULL)return -1;

  if(key_unit!=NULL){
    fprintf(stream,"%s,",key_unit);
  }
  else{
    fprintf(stream,",");
  }
  for(i=0;i<ntimes2;i++){
    fprintf(stream,"%i",(int)i*dt_skip);
    if(i!=ntimes2-1)fprintf(stream,",");
  }
  fprintf(stream,"\n");
  for(icol=0;icol<=maxcommas;icol++){
    if(icol!=0&&handle_key(csv_fields[IJ(1,icol)])==0)continue;
    for(irow=0;irow<nlines;irow++){
      char *field;
      int ij;

      //  times[i] int(f2)*dt_skip times[i+1]
      //   v1         vx              v2
      //   (vx-v1)/(v2-v1) = (ts-t1)/(t2-t1)
      //  vx = v1 + (v2-v1)*(ts-t1)/(t2-t1)
      //      = (v1*t2 - v1*t1 - v2*t1 + v1*t1 + ts*(v2-v1))/(t2-t1)
      //      = (v1*t2 - v2*t1 + ts*(v2-v1))/(t2-t1)
      //      = (v1*(t2-ts) + v2*(ts - t1) )/(t2-t1)
      //      = w1*v1 + w2*v2
      //   where w1 = (t2-ts)/(t2-t1) and w2 = 1 - w1

      if(irow==2){
        float val;

        if(icol==0){
          if(key_label!=NULL){
            fprintf(stream,"%s",key_label);
          }
          else{
            fprintf(stream,"");
          }
        }
        ij=IJ(1,icol);
        field = csv_fields[ij];
        if(handle_key(field)==1){
          val = get_key_val(field);
          fprintf(stream,"%f,",val);
        }
        else{
          fprintf(stream,",",val);
        }
      }
      if(irow>1&&irow<nlines-1){
        float t1, ts, t2, w1, w2, v1,v2;

        t1 = times[irow-2];
        t2 = times[irow-1];
        if(irow==2){
          ts = 0.0;
        }
        else{
          if((int)(t1/dt_skip)==(int)(t2/dt_skip))continue;
          ts = (int)(t2/dt_skip)*dt_skip;
        }
        w1 = (t2-ts)/(t2-t1);
        w2 = 1.0 - w1;
        ij=IJ(irow,icol);
        field = csv_fields[ij];
        sscanf(field,"%f",&v1);
        ij=IJ(irow+1,icol);
        field = csv_fields[ij];
        sscanf(field,"%f",&v2);
        if(icol==0){
          fprintf(stream,"DT_%04i,",(int)ts);
        }
        else{
          fprintf(stream,"%f,",w1*v1+w2*v2);
        }
        continue;
      }
      if(irow==nlines-1){
        fprintf(stream,"\n");
      }
      if(irow!=nlines-1&&irow>=2){
        fprintf(stream,",");
      }
    }
  }

  fclose(stream);
  return 0;
}
コード例 #24
0
ファイル: spnavd.c プロジェクト: 5263/spacenav
int main(int argc, char **argv)
{
	int i, become_daemon = 1;

	for(i=1; i<argc; i++) {
		if(argv[i][0] == '-' && argv[i][2] == 0) {
			switch(argv[i][1]) {
			case 'd':
				become_daemon = !become_daemon;
				break;

			case 'v':
				verbose = 1;
				break;

			case 'h':
				printf("usage: %s [options]\n", argv[0]);
				printf("options:\n");
				printf("  -d\tdo not daemonize\n");
				printf("  -v\tverbose output\n");
				printf("  -h\tprint this usage information\n");
				return 0;

			default:
				fprintf(stderr, "unrecognized argument: %s\n", argv[i]);
				return 1;
			}
		} else {
			fprintf(stderr, "unexpected argument: %s\n", argv[i]);
			return 1;
		}
	}

	if(become_daemon) {
		daemonize();
	}
	write_pid_file();

	read_cfg("/etc/spnavrc", &cfg);

	if(!(client_list = malloc(sizeof *client_list))) {
		perror("failed to allocate client list");
		return 1;
	}
	client_list->next = 0;

	signal(SIGINT, sig_handler);
	signal(SIGTERM, sig_handler);
	signal(SIGSEGV, sig_handler);
	signal(SIGHUP, sig_handler);
	signal(SIGUSR1, sig_handler);
	signal(SIGUSR2, sig_handler);

	init_dev();
	init_unix();
#ifdef USE_X11
	init_x11();
#endif

	/* event handling loop */
	while(1) {
		fd_set rd_set;

		if(dev_fd == -1) {
			if(init_dev() == -1) {
				sleep(30);
				continue;
			}
		}

		if(select_all(&rd_set) >= 0) {
			handle_events(&rd_set);
		}
	}

	/* just for the sense of symmetry, execution can't reach this :) */
#ifdef USE_X11
	close_x11();
#endif
	close_dev();
	return 0;
}
コード例 #25
0
ファイル: spnavd.c プロジェクト: 5263/spacenav
int main(int argc, char **argv)
{
    int i, ret, become_daemon = 1;

    for(i=1; i<argc; i++) {
        if(argv[i][0] == '-' && argv[i][2] == 0) {
            switch(argv[i][1]) {
            case 'd':
                become_daemon = !become_daemon;
                break;

            case 'v':
                verbose = 1;
                break;

            case 'h':
                printf("usage: %s [options]\n", argv[0]);
                printf("options:\n");
                printf("  -d\tdo not daemonize\n");
                printf("  -v\tverbose output\n");
                printf("  -h\tprint this usage information\n");
                return 0;

            default:
                fprintf(stderr, "unrecognized argument: %s\n", argv[i]);
                return 1;
            }
        } else {
            fprintf(stderr, "unexpected argument: %s\n", argv[i]);
            return 1;
        }
    }

    if(become_daemon) {
        daemonize();
    }
    write_pid_file();

    puts("Spacenav daemon " VERSION);

    read_cfg("/etc/spnavrc", &cfg);

    if(init_clients() == -1) {
        return 1;
    }

    signal(SIGINT, sig_handler);
    signal(SIGTERM, sig_handler);
    signal(SIGSEGV, sig_handler);
    signal(SIGHUP, sig_handler);
    signal(SIGUSR1, sig_handler);
    signal(SIGUSR2, sig_handler);

    if(init_dev() == -1) {
        init_hotplug();
    }
    init_unix();
#ifdef USE_X11
    init_x11();
#endif

    atexit(cleanup);

    for(;;) {
        fd_set rset;
        int fd, max_fd = 0;
        struct client *c;

        FD_ZERO(&rset);

        /* set the device fd if it's open, otherwise set the hotplug fd */
        if((fd = get_dev_fd()) != -1 || (fd = get_hotplug_fd()) != -1) {
            FD_SET(fd, &rset);
            if(fd > max_fd) max_fd = fd;
        }

        /* the UNIX domain socket listening for connections */
        if((fd = get_unix_socket()) != -1) {
            FD_SET(fd, &rset);
            if(fd > max_fd) max_fd = fd;
        }

        /* all the UNIX socket clients */
        c = first_client();
        while(c) {
            if(get_client_type(c) == CLIENT_UNIX) {
                int s = get_client_socket(c);
                assert(s >= 0);

                FD_SET(s, &rset);
                if(s > max_fd) max_fd = s;
            }
            c = next_client();
        }

        /* and the X server socket */
#ifdef USE_X11
        if((fd = get_x11_socket()) != -1) {
            FD_SET(fd, &rset);
            if(fd > max_fd) max_fd = fd;
        }
#endif

        do {
            ret = select(max_fd + 1, &rset, 0, 0, 0);
        } while(ret == -1 && errno == EINTR);

        if(ret > 0) {
            handle_events(&rset);
        }
    }
    return 0;	/* unreachable */
}
コード例 #26
0
ファイル: parser.c プロジェクト: iscaswcm/darknet
network *parse_network_cfg(char *filename)
{
    list *sections = read_cfg(filename);
    node *n = sections->front;
    if(!n) error("Config file has no sections");
    network *net = make_network(sections->size - 1);
    net->gpu_index = gpu_index;
    size_params params;

    section *s = (section *)n->val;
    list *options = s->options;
    if(!is_network(s)) error("First section must be [net] or [network]");
    parse_net_options(options, net);

    params.h = net->h;
    params.w = net->w;
    params.c = net->c;
    params.inputs = net->inputs;
    params.batch = net->batch;
    params.time_steps = net->time_steps;
    params.net = net;

    size_t workspace_size = 0;
    n = n->next;
    int count = 0;
    free_section(s);
    fprintf(stderr, "layer     filters    size              input                output\n");
    while(n){
        params.index = count;
        fprintf(stderr, "%5d ", count);
        s = (section *)n->val;
        options = s->options;
        layer l = {0};
        LAYER_TYPE lt = string_to_layer_type(s->type);
        if(lt == CONVOLUTIONAL){
            l = parse_convolutional(options, params);
        }else if(lt == DECONVOLUTIONAL){
            l = parse_deconvolutional(options, params);
        }else if(lt == LOCAL){
            l = parse_local(options, params);
        }else if(lt == ACTIVE){
            l = parse_activation(options, params);
        }else if(lt == LOGXENT){
            l = parse_logistic(options, params);
        }else if(lt == L2NORM){
            l = parse_l2norm(options, params);
        }else if(lt == RNN){
            l = parse_rnn(options, params);
        }else if(lt == GRU){
            l = parse_gru(options, params);
        }else if (lt == LSTM) {
            l = parse_lstm(options, params);
        }else if(lt == CRNN){
            l = parse_crnn(options, params);
        }else if(lt == CONNECTED){
            l = parse_connected(options, params);
        }else if(lt == CROP){
            l = parse_crop(options, params);
        }else if(lt == COST){
            l = parse_cost(options, params);
        }else if(lt == REGION){
            l = parse_region(options, params);
        }else if(lt == YOLO){
            l = parse_yolo(options, params);
        }else if(lt == ISEG){
            l = parse_iseg(options, params);
        }else if(lt == DETECTION){
            l = parse_detection(options, params);
        }else if(lt == SOFTMAX){
            l = parse_softmax(options, params);
            net->hierarchy = l.softmax_tree;
        }else if(lt == NORMALIZATION){
            l = parse_normalization(options, params);
        }else if(lt == BATCHNORM){
            l = parse_batchnorm(options, params);
        }else if(lt == MAXPOOL){
            l = parse_maxpool(options, params);
        }else if(lt == REORG){
            l = parse_reorg(options, params);
        }else if(lt == AVGPOOL){
            l = parse_avgpool(options, params);
        }else if(lt == ROUTE){
            l = parse_route(options, params, net);
        }else if(lt == UPSAMPLE){
            l = parse_upsample(options, params, net);
        }else if(lt == SHORTCUT){
            l = parse_shortcut(options, params, net);
        }else if(lt == DROPOUT){
            l = parse_dropout(options, params);
            l.output = net->layers[count-1].output;
            l.delta = net->layers[count-1].delta;
#ifdef GPU
            l.output_gpu = net->layers[count-1].output_gpu;
            l.delta_gpu = net->layers[count-1].delta_gpu;
#endif
        }else{
            fprintf(stderr, "Type not recognized: %s\n", s->type);
        }
        l.clip = net->clip;
        l.truth = option_find_int_quiet(options, "truth", 0);
        l.onlyforward = option_find_int_quiet(options, "onlyforward", 0);
        l.stopbackward = option_find_int_quiet(options, "stopbackward", 0);
        l.dontsave = option_find_int_quiet(options, "dontsave", 0);
        l.dontload = option_find_int_quiet(options, "dontload", 0);
        l.numload = option_find_int_quiet(options, "numload", 0);
        l.dontloadscales = option_find_int_quiet(options, "dontloadscales", 0);
        l.learning_rate_scale = option_find_float_quiet(options, "learning_rate", 1);
        l.smooth = option_find_float_quiet(options, "smooth", 0);
        option_unused(options);
        net->layers[count] = l;
        if (l.workspace_size > workspace_size) workspace_size = l.workspace_size;
        free_section(s);
        n = n->next;
        ++count;
        if(n){
            params.h = l.out_h;
            params.w = l.out_w;
            params.c = l.out_c;
            params.inputs = l.outputs;
        }
    }
    free_list(sections);
    layer out = get_network_output_layer(net);
    net->outputs = out.outputs;
    net->truths = out.outputs;
    if(net->layers[net->n-1].truths) net->truths = net->layers[net->n-1].truths;
    net->output = out.output;
    net->input = calloc(net->inputs*net->batch, sizeof(float));
    net->truth = calloc(net->truths*net->batch, sizeof(float));
#ifdef GPU
    net->output_gpu = out.output_gpu;
    net->input_gpu = cuda_make_array(net->input, net->inputs*net->batch);
    net->truth_gpu = cuda_make_array(net->truth, net->truths*net->batch);
#endif
    if(workspace_size){
        //printf("%ld\n", workspace_size);
#ifdef GPU
        if(gpu_index >= 0){
            net->workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1);
        }else {
            net->workspace = calloc(1, workspace_size);
        }
#else
        net->workspace = calloc(1, workspace_size);
#endif
    }
    return net;
}
コード例 #27
0
ファイル: SvrMain.c プロジェクト: yaoyang-6h/gwsman
void ReadFileConf(SerialCom* comm,
                  int* nPort, int* nBaud, int* nBits, int* nStop, char* cParity,
                  char* ifname, char* lcddev, int* distance, int* enable_route,
                  bool* debug_gws, bool* debug_lcd, bool* debug_neg) {
    int i = 0;
    int oPort = *nPort, oBaud = *nBaud, oBits = *nBits, oStop = *nStop;
    char oParity = *cParity;
    char sParamValue[MAX_VALUE_SIZE];
    memset(sParamValue, 0x00, MAX_VALUE_SIZE);
    for (i = 1; i <= 16; i++) {
        char sKey[13];
        memset(sKey, 0x00, 13);
        sprintf(sKey, "NameOfPort%d", i);
        if (0 == read_cfg(CONFIG_FILE, sKey, sParamValue)) {
            printf("\nmanage GWS by port %d(device name : %s)\n", i, sParamValue);
            ScSetDevName(comm, i - 1, sParamValue);
        }
    }
    if (0 == read_cfg(CONFIG_FILE, "IfName", sParamValue)) strcpy(ifname, sParamValue);
    if (0 == read_cfg(CONFIG_FILE, "LcdDev", sParamValue)) strcpy(lcddev, sParamValue);
    if (0 == read_cfg(CONFIG_FILE, "Port", sParamValue)) sscanf(sParamValue, "%d", nPort);
    if (0 == read_cfg(CONFIG_FILE, "Baud", sParamValue)) sscanf(sParamValue, "%d", nBaud);
    if (0 == read_cfg(CONFIG_FILE, "Byte", sParamValue)) sscanf(sParamValue, "%d", nBits);
    if (0 == read_cfg(CONFIG_FILE, "Stop", sParamValue)) sscanf(sParamValue, "%d", nStop);
    if (0 == read_cfg(CONFIG_FILE, "Parity", sParamValue)) sscanf(sParamValue, "%c", cParity);
    if (0 == read_cfg(CONFIG_FILE, "Distance", sParamValue)) sscanf(sParamValue, "%d", distance);
    if (0 == read_cfg(CONFIG_FILE, "MeshRoute", sParamValue)) sscanf(sParamValue, "%x", enable_route);
    if (0 == read_cfg(CONFIG_FILE, "TraceGws", sParamValue)) sscanf(sParamValue, "%d", debug_gws);
    if (0 == read_cfg(CONFIG_FILE, "TraceLcd", sParamValue)) sscanf(sParamValue, "%d", debug_lcd);
    if (0 == read_cfg(CONFIG_FILE, "TraceNeg", sParamValue)) sscanf(sParamValue, "%d", debug_neg);
    if (*nBaud != 1200 && *nBaud != 2400 && *nBaud != 4800 &&
            *nBaud != 9600 && *nBaud != 19200 && *nBaud != 38400 &&
            *nBaud != 57600 && *nBaud != 115200) *nBaud = oBaud;
    if (*nBits != 7 && *nBits != 8) *nBits = oBits;
    if (*nStop != 1 && *nStop != 2) *nStop = oStop;
    if (*cParity != 'N' && *cParity != 'n' && *cParity != 'O' &&
            *cParity != 'o' && *cParity != 'E' && *cParity != 'e') *cParity = oParity;
}
コード例 #28
0
ファイル: parser.c プロジェクト: Zumbalamambo/darknetFaceID
network parse_network_cfg(char *filename)
{
    list *sections = read_cfg(filename);
    node *n = sections->front;
    if(!n) error("Config file has no sections");
    network net = make_network(sections->size - 1);
    net.gpu_index = gpu_index;
    size_params params;

    section *s = (section *)n->val;
    list *options = s->options;
    if(!is_network(s)) error("First section must be [net] or [network]");
    parse_net_options(options, &net);

    params.h = net.h;
    params.w = net.w;
    params.c = net.c;
    params.inputs = net.inputs;
    params.batch = net.batch;
    params.time_steps = net.time_steps;
    params.net = net;

    size_t workspace_size = 0;
    n = n->next;
    int count = 0;
    free_section(s);
    fprintf(stderr, "layer     filters    size              input                output\n");
    while(n){
        params.index = count;
        fprintf(stderr, "%5d ", count);
        s = (section *)n->val;
        options = s->options;
        layer l = {0};
        LAYER_TYPE lt = string_to_layer_type(s->type);
        if(lt == CONVOLUTIONAL){
            l = parse_convolutional(options, params);
        }else if(lt == LOCAL){
            l = parse_local(options, params);
        }else if(lt == ACTIVE){
            l = parse_activation(options, params);
        }else if(lt == RNN){
            l = parse_rnn(options, params);
        }else if(lt == GRU){
            l = parse_gru(options, params);
        }else if(lt == CRNN){
            l = parse_crnn(options, params);
        }else if(lt == CONNECTED){
            l = parse_connected(options, params);
        }else if(lt == CROP){
            l = parse_crop(options, params);
        }else if(lt == COST){
            l = parse_cost(options, params);
        }else if(lt == REGION){
            l = parse_region(options, params);
        }else if(lt == DETECTION){
            l = parse_detection(options, params);
        }else if(lt == SOFTMAX){
            l = parse_softmax(options, params);
            net.hierarchy = l.softmax_tree;
        }else if(lt == NORMALIZATION){
            l = parse_normalization(options, params);
        }else if(lt == BATCHNORM){
            l = parse_batchnorm(options, params);
        }else if(lt == MAXPOOL){
            l = parse_maxpool(options, params);
        }else if(lt == REORG){
            l = parse_reorg(options, params);
        }else if(lt == AVGPOOL){
            l = parse_avgpool(options, params);
        }else if(lt == ROUTE){
            l = parse_route(options, params, net);
        }else if(lt == SHORTCUT){
            l = parse_shortcut(options, params, net);
        }else if(lt == DROPOUT){
            l = parse_dropout(options, params);
            l.output = net.layers[count-1].output;
            l.delta = net.layers[count-1].delta;
#ifdef GPU
            l.output_gpu = net.layers[count-1].output_gpu;
            l.delta_gpu = net.layers[count-1].delta_gpu;
#endif
        }else{
            fprintf(stderr, "Type not recognized: %s\n", s->type);
        }
        l.dontload = option_find_int_quiet(options, "dontload", 0);
        l.dontloadscales = option_find_int_quiet(options, "dontloadscales", 0);
        option_unused(options);
        net.layers[count] = l;
        if (l.workspace_size > workspace_size) workspace_size = l.workspace_size;
        free_section(s);
        n = n->next;
        ++count;
        if(n){
            params.h = l.out_h;
            params.w = l.out_w;
            params.c = l.out_c;
            params.inputs = l.outputs;
        }
    }   
    free_list(sections);
    net.outputs = get_network_output_size(net);
    net.output = get_network_output(net);
    if(workspace_size){
        //printf("%ld\n", workspace_size);
#ifdef GPU
        if(gpu_index >= 0){
            net.workspace = cuda_make_array(0, (workspace_size-1)/sizeof(float)+1);
        }else {
            net.workspace = calloc(1, workspace_size);
        }
#else
        net.workspace = calloc(1, workspace_size);
#endif
    }
    return net;
}
コード例 #29
0
ファイル: silo.c プロジェクト: dmgerman/linux-pre-history
int
parse_options (struct silo_options *o, int argc, char *argv[])
{
  int rc = 0;
  int oc;

  while ((oc = getopt (argc, argv, "Vf:F:d:p:r:b:B:h?v::t::")) != -1)
    {
      switch (oc)
	{
	case 'V':
	  printf("silo version: %s\n",SILO_VERSION);
	  exit(0);
	case 'v':
	  {
	    unsigned short v;
	    if (optarg && sscanf (optarg, "%hu", &v))
	      o->verbosity = v;
	    else
	      o->verbosity++;
	    PRINT_LEVEL (1, "Verbosity value is now %hu\n", o->verbosity);
	    break;
	  }
	case 't':
	  {
	    unsigned short t;
	    if (optarg && sscanf (optarg, "%hu", &t))
	      o->testlevel -= t;
	    else
	      o->testlevel--;
            PRINT_LEVEL (1, "Testonly flag is now %d\n", o->testlevel);
	    break;
	  }
	case 'h':
	case '?':
	  usage ();
	  exit(0);
	case 'd':
	  GETARG (o->ipldevice);
	  break;
	case 'f':
	  GETARG (o->image);
	  break;
        case 'F':                         
 	   GETARG (o->conffile);              
 	   break;                          
	case 'p':
	  GETARG (o->parmfile);
	  break;
	case 'r':
	  GETARG (o->ramdisk);
	  break;
	case 'b':
	  GETARG (o->bootsect);
	  break;
	case 'B':
	  GETARG (o->bootmap);
	default:
	  rc = EINVAL;
	  break;
	}
    }
  read_cfg(o);
  return rc;
}
コード例 #30
0
ファイル: signsrch.c プロジェクト: cyphunk/sectk
int main(int argc, char *argv[]) {
    u32     i,
            argi,
            found,
            offset,
            listsign        = 0,
            dumpsign        = 0;
    u8      *pid            = NULL,
            *dumpfile       = NULL,
            *sign_file      = NULL;

    setbuf(stdin,  NULL);
    setbuf(stdout, NULL);
    setbuf(stderr, NULL);

    fputs("\n"
        "Signsrch "VER"\n"
        "by Luigi Auriemma\n"
        "e-mail: [email protected]\n"
        "web:    aluigi.org\n"
        "  optimized search function from Andrew http://www.team5150.com/~andrew/\n"
        "\n", stderr);

    if(argc < 2) {
        help(argv[0]);
    }

    for(i = 1; i < argc; i++) {
        if(!stricmp(argv[i], "--help")) help(argv[0]);
        if(((argv[i][0] != '-') && (argv[i][0] != '/')) || (strlen(argv[i]) != 2)) break;
        switch(argv[i][1]) {
            case '-':
            case 'h':
            case '?': {
                help(argv[0]);
                } break;
            case 'l': {
                listsign  = 1;
                } break;
            case 'L': {
                if(!argv[++i]) {
                    printf("\nError: signature number needed\n");
                    exit(1);
                }
                dumpsign  = atoi(argv[i]);
                } break;
            case 's': {
                if(!argv[++i]) {
                    printf("\nError: signature filename needed\n");
                    exit(1);
                }
                sign_file = argv[i];
                } break;
            case 'p': {
                pid = "";
                } break;
            case 'P': {
                if(!argv[++i]) {
                    printf("\nError: process name or pid needed\n");
                    exit(1);
                }
                pid = argv[i];
                } break;
            case 'd': {
                if(!argv[++i]) {
                    printf("\nError: dump file name needed\n");
                    exit(1);
                }
                dumpfile = argv[i];
                } break;
            case 'e': {
                exe_scan        = 1;
                } break;
            case 'E': {
                exe_scan        = -1;
                } break;
            case 'b': {
                alt_endian      = 0;
                } break;
            default: {
                printf("\nError: wrong argument (%s)\n", argv[i]);
                exit(1);
                } break;
        }
    }
    argi = i;

    sign          = NULL;
    signs         = 0;
    sign_alloclen = 0;

    if(pid && !pid[0]) {
        process_list(NULL, NULL, NULL);
        goto quit;
    }

redo:
    if(!listsign && !dumpsign) {
        if(pid) {
            filemem = process_read(pid, &filememsz);
            if(!exe_scan) exe_scan = 1;
        } else {
            if(i == argc) {
                printf("\nError: you must specify the file to scan\n");
                exit(1);
            }
            filemem = fd_read(argv[argi], &filememsz);
        }
        printf("- %u bytes allocated\n", filememsz);
    }

    if(dumpfile) {
        fd_write(dumpfile, filemem, filememsz);
        goto quit;
    }

    if(!sign) {
        printf("- load signatures\n");
        if(!sign_file) {
            read_cfg(get_main_path(SIGNFILE, argv[0]));
        } else {
            read_cfg(sign_file);
        }
        printf(
            "- %u bytes allocated for the signatures\n"
            "- %u signatures in the database\n",
            sign_alloclen,
            signs);
        if(!dumpsign) signcrc();
    }

    if(dumpsign > 0) {
        dumpsign--;
        if(dumpsign >= signs) {
            printf("\nError: wrong signature number\n");
            exit(1);
        }
        printf("  %s\n", sign[dumpsign]->title);
        show_dump(sign[dumpsign]->data, sign[dumpsign]->size, stdout);
        goto quit;
    }

    if(listsign) {
        printf("\n"
            "  num  description [bits.endian.size]\n"
            "-------------------------------------\n");
        for(i = 0; i < signs; i++) {
            printf("  %-4u %s\n", i + 1, sign[i]->title);
        }
        printf("\n");
        goto quit;
    }

    if(filememsz > (10 * 1024 * 1024)) {   // more than 10 megabytes
        printf(
            "- WARNING:\n"
            "  the file loaded in memory is very big so the scanning could take many time\n");
    }

    if(exe_scan > 0) {
        if(parse_exe() < 0) {
            printf(
                "- input is not an executable or is not supported by this tool\n"
                "  the data will be handled in raw mode\n");
            exe_scan = 0;
        }
    }

    printf(
        "- start signatures scanning:\n"
        "\n"
        "  offset   num  description [bits.endian.size]\n"
        "  --------------------------------------------\n");

    for(found = i = 0; i < signs; i++) {
        offset = search_hashed(filemem, filememsz, sign[i]->data, sign[i]->size, sign[i]->and);
        if(offset != -1) {
            if(exe_scan > 0) offset = file2rva(offset);
            if(exe_scan < 0) offset += fixed_rva;
            printf("  %08x %-4u %s\n", offset, i + 1, sign[i]->title);
            found++;
        }
    }

    printf("\n- %u signatures found in the file\n", found);

    if(filemem) free(filemem);
    if(section) free(section);
    filemem = NULL;
    section = NULL;
    if(++argi < argc) {
        fputc('\n', stdout);
        goto redo;
    }

quit:
    if(sign) free_sign();
    return(0);
}