Ejemplo n.º 1
0
static int
scan_file(const char *file)
{ FILE *fd = fopen(file, "r");
  char buf[LINESIZE];
  size_t len = strlen(name);

  if ( !fd )
  { fprintf(stderr, "Warning: could not open %s (skipped)\n", file);
    return 0;
  }

  while(fgets(buf, sizeof(buf), fd))
  { const char *s;

    for(s = buf; *s; s++)
    { if ( s[0] == 'N' && strncmp(name, s, len) == 0 )
      { const char *start = s = s + len;
	char nbuf[200];

	if ( strncmp(s, "MAX", 3) == 0 ) /* avoid NAME_MAX */
	  continue;
	while(*s && (isalnum(*s & 0xff) || *s == '_') )
	  s++;
	strncpy(nbuf, start, s-start);
	nbuf[s-start] = '\0';
	save_name(nbuf);
      }
    }
  }

  fclose(fd);
  return 1;
}
Ejemplo n.º 2
0
page_snap::wk_params page_snap::page_data::to_wk_image_params() const
{
    page_snap::wk_params params;
    params.push_back(std::make_pair(page_snap::setting_img_in, url()));
    params.push_back(std::make_pair(page_snap::setting_img_out, save_path() + "/" + save_name()));
    params.push_back(std::make_pair(page_snap::setting_img_fmt, img_fmt()));

    return params;
}
int Trick::VariableServerThread::copy_sim_data() {

    unsigned int ii ;
    VariableReference * curr_var ;

    if ( vars.size() == 0 ) {
        return 0 ;
    }

    if ( pthread_mutex_trylock(&copy_mutex) == 0 ) { 

        // Get the simulation time we start this copy
        time = (double)exec_get_time_tics() / exec_get_time_tic_value() ;

        for ( ii = 0 ; ii < vars.size() ; ii++ ) {
            curr_var = vars[ii] ;

            // if this variable is unresolved, try to resolve it
            if ( retry_bad_ref ) {
                if (curr_var->ref->address == &bad_ref_int) {
                    REF2 *new_ref = ref_attributes(const_cast<char*>(curr_var->ref->reference));
                    if (new_ref != NULL) {
                        curr_var->ref = new_ref;
                    }
                }
            }

            // if there's a pointer somewhere in the address path, follow it in case pointer changed
            if ( curr_var->ref->pointer_present == 1 ) {
                curr_var->address = follow_address_path(curr_var->ref) ;
                if ( curr_var->address == NULL ) {
                    std::string save_name(curr_var->ref->reference) ;
                    if ( curr_var->ref->attr) {
                        free(curr_var->ref->attr) ;
                    }
                    free(curr_var->ref) ;
                    curr_var->ref = make_error_ref(save_name) ;
                    curr_var->address = curr_var->ref->address ;
                } else {
                    curr_var->ref->address = curr_var->address ;
                }
            }

            // if this variable is a string we need to get the raw character string out of it.
            if (( curr_var->string_type == TRICK_STRING ) && !curr_var->need_deref) {
                std::string * str_ptr = (std::string *)curr_var->ref->address ;
                curr_var->address = (void *)(str_ptr->c_str()) ;
            }

            // if this variable itself is a pointer, dereference it
            if ( curr_var->need_deref) {
                curr_var->address = *(void**)curr_var->ref->address ;
            }

            // handle c++ string and char*
            if ( curr_var->string_type == TRICK_STRING ) {
                if (curr_var->address == NULL) {
                    curr_var->size = 0 ;
                } else {
                    curr_var->size = strlen((char*)curr_var->address) + 1 ;
                }
            }
            // handle c++ wstring and wchar_t*
            if ( curr_var->string_type == TRICK_WSTRING ) {
                if (curr_var->address == NULL) {
                    curr_var->size = 0 ;
                } else {
                    curr_var->size = wcslen((wchar_t *)curr_var->address) * sizeof(wchar_t);
                }
            }
            memcpy( curr_var->buffer_in , curr_var->address , curr_var->size ) ;
        }

        retry_bad_ref = false ;

        // Indicate that sim data has been written and is now ready in the buffer_in's of the vars variable list.
        var_data_staged = true;
        packets_copied++ ;

        pthread_mutex_unlock(&copy_mutex) ;
    }


    return (0) ;

}
Ejemplo n.º 4
0
page_snap::wk_params page_snap::page_data::to_wk_pdf_params() const
{
    page_snap::wk_params params;
    params.push_back(std::make_pair(page_snap::setting_pdf_object_in, url()));
    params.push_back(std::make_pair(page_snap::setting_pdf_global_out, save_path() + "/" + save_name()));

    return params;
}