Esempio n. 1
0
obj_t::obj_t( const char * objname ) 
{
    // long name
    fullpath = realname( objname ); 

    // model handle
    const char * shortname = strip_path_and_extension( objname );
    name = copy_string( shortname );

    // memory map file
    mmfile_t mm( fullpath ); 
    index = 0;
    size = mm.size;
    data = mm.data;
    
    
    while ( index < size ) 
    {
        strip_white_space();

        switch( data[i] ) 
        {
        case 'm':
            if ( check_name( "mtllib" ) )
                consume_line();
            break;
        case 'u':
            if ( check_name( "usemtl" ) )
                consume_line();
            break;
        case 'g':
            consume_line();
            break;
        case '#':
            strip_white_space();
            break;
        case 'v':
            if ( check_name( "vn" ) )
                add_normal();
            else if ( check_name( "vt" ) )
                add_texcoord();
            else if ( data[index+1] == ' ' )
                add_vertex();
            else
                core.warn( "obj_t: straggling v in objfile: %s", name );
            break;
        case 'f':
            if ( data[index+1] == ' ' ) 
                add_face();
            break;
        case 's':
        default:
            ++index;
            break;
        }
    }
}
Esempio n. 2
0
void obj_t::add_normal()
{
    if ( data[index] != 'v' && data[index] != 'n' )
        return;
    index += 2; // eat vn
    strip_white_space();
    vec3_t v;
    v[0] = get_float();
    strip_white_space();
    v[1] = get_float();
    strip_white_space();
    v[2] = get_float();
    normals.add( v );
}
Esempio n. 3
0
void obj_t::add_texcoord()
{
    if ( data[index] != 'v' && data[index] != 't' )
        return;
    index += 2; // eat vt
    strip_white_space();
    vec3_t v;
    v[0] = get_float();
    strip_white_space();
    v[1] = get_float();
    strip_white_space();
    v[2] = get_float();
    texcoords.add( v );
}
Esempio n. 4
0
void obj_t::add_vertex()
{
    if ( data[index] != 'v' )
        return;
    ++index; // eat v
    strip_white_space();
    vec3_t v;
    v[0] = get_float();
    strip_white_space();
    v[1] = get_float();
    strip_white_space();
    v[2] = get_float();
    verts.add( v );
}
Esempio n. 5
0
File: auth.c Progetto: Nyogtha/uhub
static int check_cmd_bool(const char* cmd, struct linked_list* list, char* line, int line_count)
{
	char* data;
	char* data_extra;
	
	if (!strncmp(line, cmd, strlen(cmd)))
	{
		data = &line[strlen(cmd)];
		data_extra = 0;
		data[0] = '\0';
		data++;
		
		data = strip_white_space(data);
		if (!*data)
		{
			LOG_FATAL("ACL parse error on line %d", line_count);
			return -1;
		}
		
		list_append(list, hub_strdup(data));
		LOG_DEBUG("ACL: Deny access for: '%s' (%s)", data, cmd);
		return 1;
	}
	return 0;
}
Esempio n. 6
0
File: auth.c Progetto: Nyogtha/uhub
static int acl_parse_line(char* line, int line_count, void* ptr_data)
{
	struct acl_handle* handle = (struct acl_handle*) ptr_data;
	int ret;

	strip_off_ini_line_comments(line, line_count);

	line = strip_white_space(line);
	if (!*line)
		return 0;

	LOG_DEBUG("acl_parse_line: '%s'", line);

	ACL_ADD_USER("bot",        handle->users, auth_cred_bot);
	ACL_ADD_USER("user_admin", handle->users, auth_cred_admin);
	ACL_ADD_USER("user_super", handle->users, auth_cred_super);
	ACL_ADD_USER("user_op",    handle->users, auth_cred_operator);
	ACL_ADD_USER("user_reg",   handle->users, auth_cred_user);
	ACL_ADD_USER("link",       handle->users, auth_cred_link);
	ACL_ADD_BOOL("deny_nick",  handle->users_denied);
	ACL_ADD_BOOL("ban_nick",   handle->users_banned);
	ACL_ADD_BOOL("ban_cid",    handle->cids);
	ACL_ADD_ADDR("deny_ip",    handle->networks);
	ACL_ADD_ADDR("nat_ip",     handle->nat_override);

	LOG_ERROR("Unknown ACL command on line %d: '%s'", line_count, line);
	return -1;
}
Esempio n. 7
0
File: auth.c Progetto: Nyogtha/uhub
static int check_cmd_addr(const char* cmd, struct linked_list* list, char* line, int line_count)
{
	char* data;
	struct ip_range* range = 0;

	if (!strncmp(line, cmd, strlen(cmd)))
	{
		data = &line[strlen(cmd)];
		data[0] = '\0';
		data++;

		data = strip_white_space(data);
		if (!*data)
		{
			LOG_FATAL("ACL parse error on line %d", line_count);
			return -1;
		}

		range = hub_malloc_zero(sizeof(struct ip_range));

		if (!range)
		{
			LOG_ERROR("ACL parse error. Out of memory!");
			return -1;
		}

		if (ip_convert_address_to_range(data, range))
		{
			add_ip_range(list, range);
			return 1;
		}
		hub_free(range);
	}
	return 0;
}
Esempio n. 8
0
// consume 1 line, irregardless of what's in it
void obj_t::consume_line( void )
{
    while ( index < size && data[index] != '\n' )
    {
        ++index;
    }
    strip_white_space();
}
Esempio n. 9
0
static int config_parse_line(char* line, int line_count, void* ptr_data)
{
	char* pos;
	char* key;
	char* data;
	struct hub_config* config = (struct hub_config*) ptr_data;

	strip_off_ini_line_comments(line, line_count);

	if (!*line) return 0;

	LOG_DUMP("config_parse_line(): '%s'", line);

	if (!is_valid_utf8(line))
	{
		LOG_WARN("Invalid utf-8 characters on line %d", line_count);
	}

	if ((pos = strchr(line, '=')) != NULL)
	{
		pos[0] = 0;
	}
	else
	{
		return 0;
	}

	key = line;
	data = &pos[1];

	key = strip_white_space(key);
	data = strip_white_space(data);
	data = strip_off_quotes(data);

	if (!*key || !*data)
	{
		LOG_FATAL("Configuration parse error on line %d", line_count);
		return -1;
	}

	LOG_DUMP("config_parse_line: '%s' => '%s'", key, data);

	return apply_config(config, key, data, line_count);
}
Esempio n. 10
0
File: auth.c Progetto: CoiLock/uhub
static int check_cmd_user(const char* cmd, int status, struct linked_list* list, char* line, int line_count)
{
	char* data;
	char* data_extra;
	struct auth_info* info = 0;

	if (!strncmp(line, cmd, strlen(cmd)))
	{
		data = &line[strlen(cmd)];
		data_extra = 0;
		data[0] = '\0';
		data++;

		data = strip_white_space(data);
		if (!*data)
		{
			LOG_FATAL("ACL parse error on line %d", line_count);
			return -1;
		}

		info = hub_malloc_zero(sizeof(struct auth_info));

		if (!info)
		{
			LOG_ERROR("ACL parse error. Out of memory!");
			return -1;
		}

		if (strncmp(cmd, "user_", 5) == 0)
		{
			data_extra = strrchr(data, ':');
			if (data_extra)
			{
				data_extra[0] = 0;
				data_extra++;
			}
		}

		strncpy(info->nickname, data, MAX_NICK_LEN);
		if (data_extra)
			strncpy(info->password, data_extra, MAX_PASS_LEN);
		info->credentials = status;
		list_append(list, info);
		LOG_DEBUG("ACL: Added user '%s' (%s)", info->nickname, auth_cred_to_string(info->credentials));
		return 1;
	}
	return 0;
}
Esempio n. 11
0
static HTMLFont *
alloc_new_font (HTMLFontManager *manager,
                HTMLFontSet **set,
                gchar *face_list,
                GtkHTMLFontStyle style)
{
	HTMLFont *font = NULL;
	gchar   **faces;
	gchar   **face;

	if (!(*set)) {
		face = faces = g_strsplit (face_list, ",", 0);
		while (*face) {
			gchar *face_name = strip_white_space (*face);

			/* first try to get font from available sets */
			font = get_font (manager, set, face_name, style);
			if (!font)
				font = manager_alloc_font (manager, face_name, style);
			if (font) {
				if (!(*set)) {
					*set = html_font_set_new (face_name);
					g_hash_table_insert (manager->font_sets, g_strdup (face_name), *set);
				}
				if (strcmp (face_list, *face)) {
					(*set)->ref_count++;
					g_hash_table_insert (manager->font_sets, g_strdup (face_list), *set);
				}
				break;
			}
			face++;
		}
		g_strfreev (faces);
		if (!(*set)) {
			/* none of faces exist, so create empty set for him and let manager later set fixed font here */
			*set = html_font_set_new (face_list);
			g_hash_table_insert (manager->font_sets, g_strdup (face_list), *set);
		}
	} else
		font = manager_alloc_font (manager, (*set)->face, style);

	if ((*set) && font)
		html_font_set_font (manager, (*set), style, font);

	return font;
}
Esempio n. 12
0
char *get_line_default(char *prompt, char *default_val)
{
    char *temp1=NULL, *temp2=NULL, *ret;
    int   len;

    buff_print("%s (%s) >", prompt, default_val);
    temp1 = read_line(stdin);
    temp2 = strip_white_space(temp1);
    free(temp1);

    len = string_len(temp2);
    if (len == 0) {
        ret = copy_string( default_val );
        free(temp2);
    }else{
        ret = temp2 ;
    }
    return(ret);
}
Esempio n. 13
0
struct cfg_settings* cfg_settings_split(const char* line)
{
	struct cfg_settings* s = NULL;
	struct cfg_tokens* tok = NULL;
	char* pos = NULL;

	if (   !line
		|| !*line
		|| ((pos = (char*) strchr(line, '=')) == NULL)
		|| ((s = hub_malloc_zero(sizeof(struct cfg_settings))) == NULL)
		|| ((tok = cfg_tokenize(line)) == NULL)
		|| (cfg_token_count(tok) < 1)
		|| (cfg_token_count(tok) > 3)
		|| (cfg_token_count(tok) == 3 && strcmp(cfg_token_get(tok, 1), "="))
		)
	{
		cfg_tokens_free(tok);
		cfg_settings_free(s);
		return NULL;
	}

	if (cfg_token_count(tok) == 1)
	{
		char* key = cfg_token_get_first(tok);
		pos = strchr(key, '=');
		if (!pos)
		{
			cfg_tokens_free(tok);
			cfg_settings_free(s);
			return NULL;
		}

		pos[0] = 0;
		key = strip_white_space(key);

		if (!*key)
		{
			cfg_tokens_free(tok);
			cfg_settings_free(s);
			return NULL;
		}

		s->key = strdup(key);
		s->value = strdup(strip_white_space(pos+1));
	}
	else if (cfg_token_count(tok) == 2)
	{
		char* key = cfg_token_get_first(tok);
		char* val = cfg_token_get_next(tok);

                if ((pos = strchr(key, '=')))
		{
			pos[0] = 0;
			key = strip_white_space(key);
		}
		else if ((pos = strchr(val, '=')))
		{
			val = strip_white_space(pos+1);
		}
		else
		{
			cfg_tokens_free(tok);
			cfg_settings_free(s);
			return NULL;
		}

		if (!*key)
		{
			cfg_tokens_free(tok);
			cfg_settings_free(s);
			return NULL;
		}

		s->key = strdup(key);
		s->value = strdup(val);
	}
	else
	{
		s->key = strdup(strip_white_space(cfg_token_get(tok, 0)));
		s->value = strdup(strip_white_space(cfg_token_get(tok, 2)));
	}
	cfg_tokens_free(tok);
	return s;
}
Esempio n. 14
0
File: audio.c Progetto: callaa/luola
/* Initialize */
void init_audio ()
{
#if HAVE_LIBSDL_MIXER
    Uint16 audio_format;
    LDAT *ldat;
    int w;

    /* Initialize SDL_mixer library */
    audio_format = MIX_DEFAULT_FORMAT;
    if (Mix_OpenAudio
        (luola_options.audio_rate, audio_format, 2,
         luola_options.audio_chunks) < 0) {
        fprintf (stderr,"Cannot open audio: %s\n", SDL_GetError ());
        audio_available = 0;
        return;
    } else {
        audio_available = 1;
        Mix_QuerySpec (&luola_options.audio_rate, &audio_format,
                       NULL);
    }
    /* Continue to the next song if it ends */
    Mix_HookMusicFinished (playlist_forward);

    /* Load samples */
    ldat = ldat_open_file(getfullpath(DATA_DIRECTORY,"sfx.ldat"));
    if(!ldat) {
        fprintf(stderr,"Can't load sound effects!");
    } else {
        for (w = 0; w < SAMPLE_COUNT; w++) {
            samples[w] = Mix_LoadWAV_RW(ldat_get_item(ldat,"SFX",w),0);
            if (samples[w] == NULL) {
                fprintf (stderr,"Couldn't get SFX %d\n", w);
            }
        }
    }
    ldat_free(ldat);

    /* Load playlist */
    playlist = NULL;
    {
        FILE *fp;
        char tmps[512];
        char *line = NULL;
        fp = fopen (getfullpath (HOME_DIRECTORY, "battle.pls"), "r");
        if (!fp) {
            fprintf (stderr,"No playlist file battle.pls\n");
            return;
        }
        for (; fgets (tmps, sizeof (tmps) - 1, fp); free (line)) {
            line = strip_white_space (tmps);
            if (line == NULL || strlen (line) == 0)
                continue;
            if (line[0] == '#')
                continue;
            if(playlist)
                dllist_append(playlist,strdup(line));
            else
                playlist = dllist_append(NULL,strdup(line));
        }
        fclose (fp);

        playlist_original = NULL;

        /* Load the first song */
        load_music();
    }
#endif
}
Esempio n. 15
0
/*---------------------------------------------------------------*/
int main(int argc, char **argv) {
  SDCMFILEINFO **sdfi_list;
  SDCMFILEINFO  *sdfi=NULL;
  int nlist;
  int NRuns;
  int nthfile;
  char *fname, *psname, *protoname;
  int PrevRunNo;

  Progname = argv[0] ;
  argc --;
  argv++;
  ErrorInit(NULL, NULL, NULL) ;
  DiagInit(NULL, NULL, NULL) ;

  if (argc == 0) usage_exit();

  cmdline = argv2cmdline(argc,argv);

  parse_commandline(argc, argv);
  check_options();

  uname(&uts);
  getcwd(cwd,2000);
  fprintf(stdout,"%s\n",vcid);
  fprintf(stdout,"cwd %s\n",cwd);
  fprintf(stdout,"cmdline %s\n",cmdline);
  fprintf(stdout,"sysname  %s\n",uts.sysname);
  fprintf(stdout,"hostname %s\n",uts.nodename);
  fprintf(stdout,"machine  %s\n",uts.machine);
  fprintf(stdout,"user     %s\n",VERuser());

  strip_leading_slashes(sdicomdir);

  /* open the output file, or set output stream to stdout */
  if (outfile != NULL) {
    outstream = fopen(outfile,"w");
    if (outstream == NULL) {
      fprintf(stderr,"ERROR: could not open %s for writing\n",outfile);
      exit(1);
    }
  } else outstream = stdout;

  /* Get all the Siemens DICOM files from this directory */
  fprintf(stderr,"INFO: scanning path to Siemens DICOM DIR:\n   %s\n",
          sdicomdir);
  sdfi_list = ScanSiemensDCMDir(sdicomdir, &nlist);
  if (sdfi_list == NULL) {
    fprintf(stderr,"ERROR: scanning directory %s\n",sdicomdir);
    exit(1);
  }
  printf("INFO: found %d Siemens files\n",nlist);
  printf("%s\n",sdfi_list[0]->NumarisVer);
  tmpstring = sdcmExtractNumarisVer(sdfi_list[0]->NumarisVer, &Maj, &Min, &MinMin);
  if (tmpstring == NULL) free(tmpstring);
  else {
    if ((Min == 1 && MinMin <= 6) && Maj < 4) {
      // This should only be run for pretty old data. I've lost
      // track as to which versions should do this. With Maj<4,
      // I'm pretty sure that this section of code will never
      // be run.  It might need to be run with version 4VA16
      // and earlier. Note: this same code is in DICOMRead.c
      printf("Computing TR with number of slices\n");
      TRSlice = 1;
    }
  }

  /* Sort the files by Series, Slice Position, and Image Number */
  printf("Sorting\n");
  fflush(stdout);
  fflush(stderr);
  SortSDCMFileInfo(sdfi_list,nlist);

  /* Assign run numbers to each file (count number of runs)*/
  if (sortbyrun) {
    fprintf(stderr,"Assigning Run Numbers\n");
    fflush(stderr);
    NRuns = sdfiAssignRunNo2(sdfi_list, nlist);
    if (NRuns == 0) {
      fprintf(stderr,"ERROR: sorting runs\n");
      fflush(stderr);
      exit(1);
    }
  }

  PrevRunNo = -1;
  for (nthfile = 0; nthfile < nlist; nthfile++) {

    sdfi = sdfi_list[nthfile];

    if (summarize && PrevRunNo == sdfi->RunNo) continue;
    PrevRunNo = sdfi->RunNo;

    sdfi->RepetitionTime /= 1000.0;

    // Old version of Siemens software had reptime as time between
    // slices. New has reptime as time between volumes.
    // Code (above) looks at version and does the right thing.
    if (sdfi->IsMosaic && TRSlice) sdfi->RepetitionTime *= sdfi->VolDim[2];

    fname     = fio_basename(sdfi->FileName,NULL);
    psname    = strip_white_space(sdfi->PulseSequence);
    protoname = strip_white_space(sdfi->ProtocolName);

    fprintf(outstream,
            "%4d %s  %3d %d  %4d %d  %3d %3d %3d %3d  %8.4f %8.4f %s\n",
            nthfile+1, fname,
            sdfi->SeriesNo, sdfi->ErrorFlag,
            sdfi->ImageNo, sdfi->IsMosaic,
            sdfi->VolDim[0], sdfi->VolDim[1], sdfi->VolDim[2], sdfi->NFrames,
            sdfi->RepetitionTime, sdfi->EchoTime,
            protoname);
    fflush(outstream);
    free(fname);
    free(psname);
    free(protoname);
  }

  while (nlist--) {
    // free strings
    free(sdfi_list[nlist]->FileName);
    free(sdfi_list[nlist]->StudyDate);
    free(sdfi_list[nlist]->StudyTime);
    free(sdfi_list[nlist]->PatientName);
    free(sdfi_list[nlist]->SeriesTime);
    free(sdfi_list[nlist]->AcquisitionTime);
    free(sdfi_list[nlist]->ScannerModel);
    free(sdfi_list[nlist]->NumarisVer);
    free(sdfi_list[nlist]->PulseSequence);
    free(sdfi_list[nlist]->ProtocolName);
    free(sdfi_list[nlist]->PhEncDir);
    //
    free(sdfi_list[nlist]);
  }
  free(sdfi_list);

  if (outfile != NULL) fclose(outstream);

  fflush(stdout);
  fflush(stderr);
  exit(0);
  return(0);
}