Esempio n. 1
0
static void macrobody(struct sbuf *sbuf, char *end)
{
	int first = 1;
	int c;
	char *req = NULL;
	cp_back('\n');
	cp_copymode(1);
	while ((c = cp_next()) >= 0) {
		if (sbuf && !first)
			sbuf_add(sbuf, c);
		first = 0;
		if (c == '\n') {
			if ((c = cp_next()) != c_cc) {
				cp_back(c);
				continue;
			}
			req = read_name(n_cp);
			if (!strcmp(end, req)) {
				in_push(end, NULL);
				cp_back(c_cc);
				break;
			}
			if (sbuf) {
				sbuf_add(sbuf, c_cc);
				sbuf_append(sbuf, req);
			}
			free(req);
			req = NULL;
		}
	}
	free(req);
	cp_copymode(0);
}
Esempio n. 2
0
// Search the array of phone records for a number
void search_records(PhoneRecord records[], size_t count)
{
  Name name;
  char answer = 'n';
  do
  {
    name = read_name();
    int index = 0;
    bool first = true;
    while((index = find_record(records, index, count, &name)) >= 0)
    {
      if(first)
      {
        printf_s("The numbers for %s %s are:\n", name.firstname, name.secondname); 
        first = false;   
      }
      printf_s("%s\n", records[index++].number);
      if(index >= count)
        break;  
    }
    if(first)
      printf_s("No numbers found for %s %s.\n", name.firstname, name.secondname);

    printf_s("\nDo you want to search for another name (y or n)? ");
    scanf_s(" %c" , &answer, sizeof(answer));
  }while(tolower(answer) == 'y');
}
Esempio n. 3
0
struct t_command* read_command( FILE* f )
{
  char *name = NULL;
  int value = 0;
  char *value_str = NULL;
  struct t_command *command = malloc( sizeof(struct t_command) );

  name = read_name( f );
  command->name = name;

  // printf("\nNome: '%s'\n", name);

  read_equal( f );

  value = read_value( f );
  if ( value == -1 ) {
	  /* Value is a string */
	  value_str = read_string( f );
	  // printf("Stringa('%s')\n", value_str );
    command->value_str = value_str;
    command->type = STRING;
  } else {
	  // printf("Value: %u\n", value );
    command->value_num = value;
    command->type = NUMERIC;
  }

  return command;
}
Esempio n. 4
0
static int read_names(xmlNode *entry_node, display_name_t **dst)
{
	xmlNode *n;
	display_name_t *name, *last;
	int res = 0;
	
	last = NULL;
	*dst = NULL;
	n = entry_node->children;
	while (n) {
		if (n->type == XML_ELEMENT_NODE) {
			if (cmp_node(n, "display-name", rl_namespace) >= 0) {
				res = read_name(n, &name);
				if (res == 0) {
					if (name) {
						SEQUENCE_ADD((*dst), last, name);
						name = NULL;
					}
				}
				else break;
			}
		}
		n = n->next;
	}
	return res;
}
Esempio n. 5
0
/* read arguments for .nr */
static void mkargs_reg1(struct sbuf *sbuf)
{
	char *s = read_name(n_cp);
	sbuf_append(sbuf, s);
	sbuf_add(sbuf, 0);
	free(s);
	mkargs_req(sbuf);
}
Esempio n. 6
0
/* read arguments for .ochar */
static void mkargs_ochar(struct sbuf *sbuf)
{
	char *s = read_name(0);
	sbuf_append(sbuf, s);
	sbuf_add(sbuf, 0);
	free(s);
	mkargs_ds(sbuf);
}
Esempio n. 7
0
/* read the next troff request; return zero if a request was executed. */
int tr_nextreq(void)
{
	char *mac;
	char *arg0 = NULL;
	int c;
	if (!tr_nl)
		return 1;
	c = cp_next();
	/* transparent line indicator */
	if (c == c_ec) {
		int c2 = cp_next();
		if (c2 == '!') {
			char *args[NARGS + 3] = {"\\!"};
			struct sbuf sbuf;
			sbuf_init(&sbuf);
			cp_copymode(1);
			mkargs_eol(&sbuf);
			cp_copymode(0);
			chopargs(&sbuf, args + 1);
			tr_transparent(args);
			sbuf_done(&sbuf);
			return 0;
		}
		cp_back(c2);
	}
	/* not a request, a blank line, or a line with leading spaces */
	if (c < 0 || (c != c_cc && c != c_c2 &&
			(c != '\n' || tr_bm < 0) &&
			(c != ' ' || tr_sm < 0))) {
		cp_back(c);
		return 1;
	}
	cp_reqbeg();
	if (c == '\n') {		/* blank line macro */
		mac = malloc(strlen(map_name(tr_bm)) + 1);
		strcpy(mac, map_name(tr_bm));
		arg0 = dotted(mac, '.');
		tr_nextreq_exec(mac, arg0, 0);
	} else if (c == ' ') {		/* leading space macro */
		int i;
		mac = malloc(strlen(map_name(tr_sm)) + 1);
		strcpy(mac, map_name(tr_sm));
		for (i = 0; c == ' '; i++)
			c = cp_next();
		cp_back(c);
		n_lsn = i;
		arg0 = dotted(mac, '.');
		tr_nextreq_exec(mac, arg0, 0);
	} else {
		mac = read_name(n_cp);
		arg0 = dotted(mac, c);
		tr_nextreq_exec(mac, arg0, 1);
	}
	free(arg0);
	free(mac);
	return 0;
}
Esempio n. 8
0
AST_expr* readASTExpr(BufferedReader* reader) {
    uint8_t type = reader->readByte();
    if (VERBOSITY("parsing") >= 2)
        printf("type = %d\n", type);
    if (type == 0)
        return NULL;

    uint8_t checkbyte = reader->readByte();
    assert(checkbyte == 0xae);

    switch (type) {
        case AST_TYPE::Attribute:
            return read_attribute(reader);
        case AST_TYPE::BinOp:
            return read_binop(reader);
        case AST_TYPE::BoolOp:
            return read_boolop(reader);
        case AST_TYPE::Call:
            return read_call(reader);
        case AST_TYPE::Compare:
            return read_compare(reader);
        case AST_TYPE::Dict:
            return read_dict(reader);
        case AST_TYPE::DictComp:
            return read_dictcomp(reader);
        case AST_TYPE::IfExp:
            return read_ifexp(reader);
        case AST_TYPE::Index:
            return read_index(reader);
        case AST_TYPE::Lambda:
            return read_lambda(reader);
        case AST_TYPE::List:
            return read_list(reader);
        case AST_TYPE::ListComp:
            return read_listcomp(reader);
        case AST_TYPE::Name:
            return read_name(reader);
        case AST_TYPE::Num:
            return read_num(reader);
        case AST_TYPE::Repr:
            return read_repr(reader);
        case AST_TYPE::Slice:
            return read_slice(reader);
        case AST_TYPE::Str:
            return read_str(reader);
        case AST_TYPE::Subscript:
            return read_subscript(reader);
        case AST_TYPE::Tuple:
            return read_tuple(reader);
        case AST_TYPE::UnaryOp:
            return read_unaryop(reader);
        default:
            fprintf(stderr, "Unknown expr node type (parser.cpp:" STRINGIFY(__LINE__) "): %d\n", type);
            abort();
            break;
    }
}
void read_names() {
	FILE * fp;
	fp = fopen("../names_table.txt", "r");
	if (fp == NULL)
		exit(EXIT_FAILURE);

	while (!feof(fp)) {
		read_name(fp);
	}

	fclose(fp);
	names = inverse_node(names, NULL);
}
Esempio n. 10
0
/* read arguments for .ds and .char */
static void mkargs_ds(struct sbuf *sbuf)
{
	char *s = read_name(n_cp);
	sbuf_append(sbuf, s);
	sbuf_add(sbuf, 0);
	free(s);
	s = read_string();
	if (s) {
		sbuf_append(sbuf, s);
		sbuf_add(sbuf, 0);
		free(s);
	}
	jmp_eol();
}
Esempio n. 11
0
// Function to read an arbitrary number of phone records from the keyboard
size_t get_records(PhoneRecord records[], size_t size)
{
  size_t count = 0;
  char answer = 'y';
  do
  {
    records[count].name = read_name();                                        // Read the name
    printf_s("Enter the number for this name: ");
    scanf_s(" %[ 0123456789]",records[count++].number, (rsize_t)NUMBER_LEN);  // Read the number - including spaces

    printf_s("Do you want to enter another(y or n)?: ");
    scanf_s(" %c", &answer, sizeof(answer));
  }while(count <= size && tolower(answer) == 'y');
  return count;
}
Esempio n. 12
0
/*
 * dump_name - dump length-prefixed name, align to n-byte boundary
 * return number of bytes read
 */
static int dump_name( bool align )
/********************************/
{
    char        name[256];
    unsigned    len, pad = 0;

    len = read_name( name ) + 1;
    Wdputs( name );
    if( align ) {
        pad = align - (len & (align - 1));
    }
    if( pad ) {
        lseek( Handle, pad, SEEK_CUR );
    }
    return( len + pad + 1 );
}
Esempio n. 13
0
/* reads in a name from stdin and returns the collection associated with it
   returns NULL and throws an error if there wasn't any collection by that name */
static void* find_collection_by_name( struct Ordered_container* catalog )
{
    char name[ NAME_ARRAY_SIZE ];
    void* node;
    
    read_name( name );
    
    node = OC_find_item_arg( catalog, name, comp_Collection_to_name );
    
    if ( node == NULL )
    {
        print_error( "No collection with that name!\n" );
    }
    
    return node;
}
Esempio n. 14
0
void Squad::read_data() {
    if (!m_df || !m_df->memory_layout() || !m_df->memory_layout()->is_valid()) {
        LOGW << "refresh of squad called but we're not connected";
        return;
    }
    // make sure our reference is up to date to the active memory layout
    m_mem = m_df->memory_layout();
    TRACE << "Starting refresh of squad data at" << hexify(m_address);

    //qDeleteAll(m_members);
    m_members.clear();

    read_id();
    read_name();
    read_members();
}
Esempio n. 15
0
int main(int argc, char const *argv[])
{
	struct name myName = {0, 0, 0};
	read_name(&myName);

	printf("status %s\n", myName.status);

	int i = 0;
	for (i; i <= myName.count; i++)
	{
		printf("%s\n",myName.tok[i]);
	}
	
	

	return 0;
}
Esempio n. 16
0
static void add_coll( struct Ordered_container* catalog )
{
    struct Collection* new_coll;
    char name[ NAME_ARRAY_SIZE ];
    
    read_name( name );
    
    if ( OC_find_item_arg( catalog, name, comp_Collection_to_name ) != NULL )
    {
        print_error( "Catalog already has a collection with this name!\n" );
        return;
    }
    
    new_coll = create_Collection( name );
    
    OC_insert( catalog, new_coll );
    printf("Collection %s added\n", name );
}
Esempio n. 17
0
action read_action(deserializer & d) {
    action_kind k = static_cast<action_kind>(d.read_char());
    unsigned rbp;
    switch (k) {
    case action_kind::Skip:
        return notation::mk_skip_action();
    case action_kind::Binder:
        d >> rbp;
        return notation::mk_binder_action(rbp);
    case action_kind::Binders:
        d >> rbp;
        return notation::mk_binders_action(rbp);
    case action_kind::Expr:
        d >> rbp;
        return notation::mk_expr_action(rbp);
    case action_kind::Exprs: {
        name sep; expr rec; optional<expr> ini; bool is_fold_right;
        d >> sep >> rec;
        if (d.read_bool()) {
            ini = read_expr(d);
        }
        d >> is_fold_right >> rbp;
        optional<name> terminator;
        if (d.read_bool())
            terminator = read_name(d);
        return notation::mk_exprs_action(sep, rec, ini, terminator, is_fold_right, rbp);
    }
    case action_kind::ScopedExpr: {
        expr rec; bool use_lambda_abstraction;
        d >> rec >> rbp >> use_lambda_abstraction;
        return notation::mk_scoped_expr_action(rec, rbp, use_lambda_abstraction);
    }
    case action_kind::LuaExt:
        return notation::mk_ext_lua_action(d.read_string().c_str());
    case action_kind::Ext:
        break;
    }
    lean_unreachable();
}
Esempio n. 18
0
void reading (char name_file_case[SIZE_NAME_FILE])
{
   FILE *file_message, *file_case;

   exist_file_check(name_file_case);

   file_case= fopen (name_file_case, "r");
   if (file_case    == NULL) 
   {
      std::cerr << "Error opening of file. " << std::endl;
      exit(1);
   }

   read_title(file_case); 
   int size = read_int(file_case); 
   if (size > (SIZE_NAME_FILE))
   {
      std::cerr << "Error reading. File was corrupted. " << std::endl;
      exit(1);
   }

   std::string name_file_message = read_name(size, file_case);
   file_message = fopen (name_file_message.c_str(), "w+b");
   if (file_message == NULL) 
   {
      std::cerr << "Error opening of file. " << std::endl;
      exit(1);
   }         

   size = read_int(file_case);
   check_size_of_files_reading(file_case, size);

   read_data(size, file_case, file_message);

   fclose (file_message);
   fclose (file_case);
}
Esempio n. 19
0
void init_manager(void)
{
	#ifdef DEBUG
	printf(DEBUG_ACTIVATED);
	#endif

	_GemParBlk.global[0]=0;
	ap_id = appl_init();
	if (!_GemParBlk.global[0]) exit(0);
	if (ap_id < 0) exit(0);

	if (!_app) wind_update(BEG_UPDATE);

	Pdomain(1);
	check_cookies();
	
	if (_GemParBlk.global[1] != 1) multitask = 1;
	if ((_GemParBlk.global[0] >= 0x0400) && (multitask)) multitos = 1;
	
	allocmode = GLOBAL;
	if (_app) allocmode |= 3;
	
	read_name();
	check_info();
	
	if ((!_app) || ((multitos) && (!magix)))
	{
		menu_id = menu_register(ap_id,STRING_MENUENTRY);
		
		if (menu_id < 0)
		{
			if (!_app) wind_update(END_UPDATE);
			
			if (multitos)
			{
				appl_exit();
				exit(0);
			}
			else
			{
				while (1) evnt_timer(0,1);
			}
		}
	}
	
	find_inf();

	if (!_app) wind_update(END_UPDATE);

	Psignal(SIGTERM,sig_handler);
	Psignal(SIGQUIT,sig_handler);
	
	if (!multitask)
	{
		char s[256];
		
		strcpy(s,"[0][OLGA v");
		strcat(s,OLGAVERSIONSTR);
		strcat(s,"  Rev ");
		strcat(s,OLGAREVISION);
		strcat(s," (");
		strcat(s,OLGADATE);
		strcat(s,") | |");
		strcat(s,MESSAGE_MULTITASKING);
		
		form_alert(1,s);
		
		if (_app)
		{
			#ifdef DEBUG
			printf(DEBUG_DEACTIVATED);
			#endif
			
			appl_exit();
			exit(0);
		}
	}
	
	if (shutdown) shel_write(9,1,0,NULL,NULL);
	
	broadcast_olenew();
}
Esempio n. 20
0
Token* Scanner::get_token() {
  Token* t;
  if (tokens) {
    t = tokens->token;
    tokens = tokens->prev;
  } else {
    t = NULL;
    while (t == NULL) {
      fint c = get_char();
      switch (c) {
       case EOF:
        depth = 0;
        t = new Token(Token::ACCEPT, line, column, sourceAddr());
        break;
       case '\n':
       case '\r':
        if (depth <= 0 && !is_string_scanner()) {
          t = new Token(Token::ACCEPT, line, column - 1, sourceAddr() - 1);
          depth = 0;
        }
        break;
       case ' ':
       case '\t':
       case '\v':
       case '\b':
       case '\f':
        break;
       case '"':
        t = skip_comment();
        break;
       case '(':
        depth ++;
        t = new Token(as_TokenType('('), line, column - 1, sourceAddr() - 1);
        break;
       case ')':
        depth --;
        t = new Token(as_TokenType(')'), line, column - 1, sourceAddr() - 1);
        break;
       case '[':
        depth ++;
        t = new Token(as_TokenType('['), line, column - 1, sourceAddr() - 1);
        break;
       case ']':
        depth --;
        t = new Token(as_TokenType(']'), line, column - 1, sourceAddr() - 1);
        break;
       case '.':
        t = read_dot();
        break;
       case '\'':
        t = read_string();
        break;
       case '\\':
        c = get_char();
        if (c == '\n' || c == '\r') {
          // an escaped newline; ignore
        } else {
          push_char(c);
          c = '\\';
          t = read_op(c);
        }
        break;
       case '{':
        t = new Token(Token::ANNOTATION_START, line, column - 1, sourceAddr() - 1);
        break;
       case '}':
        t = new Token(Token::ANNOTATION_END,   line, column - 1, sourceAddr() - 1);
        break;
       default:
        if (is_digit(c) || c == '-') t = read_number(c);
        else if (is_id_alpha(c) || c == ':') t = read_name(c);
        else if (is_punct(c)) t = read_op(c);
        else t = TokenizingError("unknown character in input");
      }
    }
  }
  if (t && PrintTokens) t->print();
  return t;
}
Esempio n. 21
0
int read_elf(char *filename, struct _memory *memory, uint8_t *cpu_type, struct _symbols *symbols)
{
FILE *in;
uint8_t e_ident[16];
int e_shoff;
int e_shentsize;
int e_shnum;
int e_shstrndx;
int n;
int start, end;
struct _elf32_shdr elf32_shdr;
long strtab_offset = 0;
get_int16_t get_int16;
get_int32_t get_int32;

  memory_clear(memory);
  //memset(dirty, 0, memory->size);

  start = -1;
  end = -1;

  in = fopen(filename, "rb");
  if (in == 0)
  {
    return -1;
  }

  memset(e_ident, 0, 16);
  n = fread(e_ident, 1, 16, in);

  if (e_ident[0] != 0x7f || e_ident[1] != 'E' ||
      e_ident[2] != 'L' || e_ident[3] != 'F')
  {
    //printf("Not an ELF file.\n");
    fclose(in);
    return -2;
  }

  #define EI_CLASS 4   // 1=32 bit, 2=64 bit
  #define EI_DATA 5    // 1=little endian, 2=big endian
  #define EI_OSABI 7   // 0=SysV, 255=Embedded

  if (e_ident[EI_CLASS] != 1) // let's let other stuff in || e_ident[7]!=0xff)
  {
    printf("ELF Error: e_ident shows incorrect type\n");
    fclose(in);
    return -1;
  }

  // EI_DATA
  if (e_ident[EI_DATA] == 1)
  {
    memory->endian = ENDIAN_LITTLE;
    get_int16 = get_int16_le; 
    get_int32 = get_int32_le; 
  }
    else
  if (e_ident[EI_DATA] == 2)
  {
    memory->endian = ENDIAN_BIG;
    get_int16 = get_int16_be; 
    get_int32 = get_int32_be; 
  }
    else
  {
    printf("ELF Error: EI_DATA incorrect data encoding\n");
    fclose(in);
    return -1;
  }

  get_int16(in);
  n = get_int16(in);

  switch(n)
  {
    case 8:
    case 10:
      *cpu_type = CPU_TYPE_MIPS;
      break;
    case 40:
      *cpu_type = CPU_TYPE_ARM;
      break;
    case 83:
      *cpu_type = CPU_TYPE_AVR8;
      break;
    case 105:
      *cpu_type = CPU_TYPE_MSP430;
      break;
    case 118:
      *cpu_type = CPU_TYPE_DSPIC;
      break;
    default:
      printf("ELF Error: e_machine unknown\n");
      fclose(in);
      return -1;
  }

  fseek(in, 32, SEEK_SET);
  e_shoff = get_int32(in);
  fseek(in, 46, SEEK_SET);
  e_shentsize = get_int16(in);
  e_shnum = get_int16(in);
  e_shstrndx = get_int16(in);

  //printf("e_shoff=%d\n", e_shoff);
  //printf("e_shentsize=%d\n", e_shentsize);
  //printf("e_shnum=%d\n", e_shnum);
  //printf("e_shstrndx=%d\n", e_shstrndx);

  fseek(in, e_shoff + (e_shstrndx * e_shentsize) + 16, SEEK_SET);
  int stroffset = get_int32(in);
  char name[32];

  // Need to find .strtab so we can fill in symbol names
  for (n = 0; n < e_shnum; n++)
  {
    fseek(in, e_shoff + (n * e_shentsize), SEEK_SET);
    read_shdr(in, &elf32_shdr, get_int32);

    if (elf32_shdr.sh_type == SHT_STRTAB)
    {
      read_name(in, name, 32, stroffset + elf32_shdr.sh_name);
      if (strcmp(name, ".strtab") == 0)
      {
        strtab_offset = elf32_shdr.sh_offset;
        break;
      }
    }
  }

  for (n = 0; n < e_shnum; n++)
  {
    // FIXME - a little inefficient eh?
    fseek(in, e_shoff + (n * e_shentsize), SEEK_SET);
    read_shdr(in, &elf32_shdr, get_int32);

    read_name(in, name, 32, stroffset + elf32_shdr.sh_name);

    //printf("name=%s\n", name);
    //int is_text = strncmp(name, ".text", 5) == 0 ? 1 : 0;
    int is_text = (elf32_shdr.sh_flags & SHF_EXECINSTR) != 0 ? 1 : 0;
    if (is_text ||
        strncmp(name, ".data", 5) == 0 || strcmp(name, ".vectors") == 0)
    {
      if (is_text)
      {
        if (start == -1) { start = elf32_shdr.sh_addr; }
        else if (start > elf32_shdr.sh_addr) { start = elf32_shdr.sh_addr; }

        if (end == -1) { end = elf32_shdr.sh_addr + elf32_shdr.sh_size - 1; }
        else if (end < elf32_shdr.sh_addr + elf32_shdr.sh_size) { end = elf32_shdr.sh_addr+elf32_shdr.sh_size - 1; }
      }

      long marker = ftell(in);
      fseek(in, elf32_shdr.sh_offset, SEEK_SET);

      int n;
      for (n = 0; n < elf32_shdr.sh_size; n++)
      {
        if (elf32_shdr.sh_addr + n >= memory->size) break;
        memory_write_m(memory, elf32_shdr.sh_addr + n, getc(in)); 
      }

      fseek(in, marker, SEEK_SET);

      printf("Loaded %d %s bytes from 0x%04x\n", n, name, elf32_shdr.sh_addr);
    }
      else
    if (elf32_shdr.sh_type == SHT_SYMTAB && symbols != NULL)
    {
      long marker = ftell(in);
      fseek(in, elf32_shdr.sh_offset, SEEK_SET);

      for (n = 0; n < elf32_shdr.sh_size; n += 16)
      {
        char name[128];

        struct _elf32_sym elf32_sym;
        elf32_sym.st_name = get_int32(in);
        elf32_sym.st_value = get_int32(in);
        elf32_sym.st_size = get_int32(in);
        elf32_sym.st_info = getc(in);
        elf32_sym.st_other = getc(in);
        elf32_sym.st_shndx = get_int16(in);

        read_name(in, name, 128, strtab_offset + elf32_sym.st_name);

        printf("symbol %12s 0x%04x\n", name, elf32_sym.st_value);
        if (elf32_sym.st_info != STT_NOTYPE &&
            elf32_sym.st_info != STT_SECTION &&
            elf32_sym.st_info != STT_FILE)
        {
          symbols_append(symbols, name, elf32_sym.st_value);
        }
      }
      fseek(in, marker, SEEK_SET);
    }
  }

  memory->low_address = start;
  memory->high_address = end;

  fclose(in);

  return start;
}
Esempio n. 22
0
static void read_theorem(environment const & env, io_state const &, deserializer & d) {
    name n    = read_name(d);
    expr t    = read_expr(d);
    expr v    = read_expr(d);
    env->add_theorem(n, t, v);
}
Esempio n. 23
0
static void read_uvar_cnstr(environment const & env, io_state const &, deserializer & d) {
    name n    = read_name(d);
    level lvl = read_level(d);
    env->add_uvar_cnstr(n, lvl);
}
Esempio n. 24
0
static void read_variable(environment const & env, io_state const &, deserializer & d) {
    name n    = read_name(d);
    expr t    = read_expr(d);
    env->add_var(n, t);
}
Esempio n. 25
0
void gdb_save_stacktrace(const char *text_in, const char *text_out){
	FILE *fin;
	FILE *fout;
	int number = 0;
	size_t nbytes = 300;
	fout = fopen(text_out, "w+");
	fin = fopen(text_in, "r");
	str = (char *) malloc (nbytes + 1);
	
	while(1){
		size = getline (&str, &nbytes, fin);
		if (size == -1) break;
		if (size == 0) break;
		str[size-1] = '\0';
		poz = 4;
		if(get_char(poz) == '0'){
			read_pointer();
			poz += 4;
		}
		char *func = read_name();
		poz += 1;
		int tmppoz = poz;
		if (strcmp(func, "gdb_die") == 0) {
			fprintf(fout, "%s\n", c_rt_lib0get_die_additional_info());
			while(get_char(tmppoz) != '"' && get_char(tmppoz) != '\0') ++tmppoz;
			fprintf(fout, "\"");
			while(1){
				char tmp = get_char(++tmppoz);
				if(tmp == '"') break;
				if(tmp == '\0') break;
				if(tmp == '\\') tmp = get_char(++tmppoz);
				if(tmp == '"') fprintf(fout, "\"");
				fprintf(fout, "%c", tmp);
			}
			fprintf(fout, "\"\n");
			fflush(fout);
		}
		tmppoz = size-3;
		while(is_num(get_char(tmppoz))) --tmppoz;
		int line = atoi(str+tmppoz+1);
		if(get_char(tmppoz) == ':') str[tmppoz] = '\0';
		while(get_char(tmppoz)!=')') --tmppoz;
		tmppoz += 5;
		fprintf(fout, "%d	%s	%s	%d", number, func, str+tmppoz, line);
		int param = 0;
		while(1) {
			if(get_char(poz) == ',') {
				poz +=2;
			} else if(get_char(poz) == '(') {
				poz +=1;
				if(get_char(poz) == ')') break;
			} else if(get_char(poz) == ')') {
				break;
			} else {
				break;
			}
			char *name = read_name();
			void *ptr = NULL;
			if(get_char(poz) == '='){
				++poz;
				ptr = read_pointer();
			}
			if(startsWith("___nl__", name) && ptr != NULL){
				ImmT saved = dfile0ssave(ptr);
				NlString* p = toStringIfSim(saved);
				fprintf(fout, "	\"p%d ", param);
				fprintString(fout, p->s, p->length);
				fprintf(fout, "\"");
			} else if(startsWith("___ref___", name) && ptr != NULL && *(ImmT*)ptr != NULL){
				ImmT saved = dfile0ssave(*(ImmT*)ptr);
				NlString* p = toStringIfSim(saved);
				fprintf(fout, "	\"p%d REF ", param);
				fprintString(fout, p->s, p->length);
				fprintf(fout, "\"");
			} else {
				fprintf(fout, "	p%d %s=%p", param, name, ptr);
			}
			fflush(fout);
			++param;
		}
		fprintf(fout, "\n");
		fflush(fout);
		++number;
	}
	free(str);
	fclose(fin);
	fclose(fout);
}
Esempio n. 26
0
// ---------------------------------------------------------------------------
// Constructeur::ouverture
// ------------
bMacMapType::bMacMapType(int t, int *status)
			:_bse(this){
_bTrace_("bMacMapType::bMacMapType(int,int*)",true);
int		tbltype;
char	path[FILENAME_MAX+1],tname[FILENAME_MAX+1];
	
	_iter=NULL;
	_styles=NULL;
	_name[0]=0;
	_idx=_MMAPP_->typesMgr()->count()+1;
	_rmv=0;
    read_load_area();
                
	if(!PATH_get(t,&tbltype,path)){
		(*status)=-1;
_te_("status ="+(*status)+" at PATH_get");
		return;
	}
	
	tbltype=get_sign(tbltype);
_tm_("opening type with "+(UInt32*)&tbltype+" storage");
	*status=_bse.open(path,_MMAPP_->document()->srid(),GetRawPrecisionCoef(_MMAPP_));
	if(*status){
_te_("status = "+(*status)+" at new _bse.open "+path);
		return;
	}
	if(((*status)=_bse.h_read(1,kHDR_id_,&_id))){
_te_("status = "+(*status)+" at _bse.h_read kHDR_id_");
		return;
	}
	if(((*status)=_bse.h_read(1,kHDR_state_,&_state))){
_te_("status = "+(*status)+" at _bse.h_read kHDR_state_");
		return;
	}
	if(((*status)=_bse.h_read(1,kHDR_kind_,&_kind))){
_te_("status = "+(*status)+" at _bse.h_read kHDR_kind_");
		return;
	}
	
	/*if((*status)=_bse.h_read(1,kHDR_bounds_,&_bounds)){
_te_("status = "+(*status)+" at _bse.h_read kHDR_bounds_");
		return;
	}*/
	_bounds.top=1-__BOUNDS_MAX__;
	_bounds.left=1-__BOUNDS_MAX__;
	_bounds.bottom=1+__BOUNDS_MAX__;
	_bounds.right=1+__BOUNDS_MAX__;
				
	if(((*status)=_bse.h_read(1,kHDR_name_,tname))){
_te_("status = "+(*status)+" at _bse.h_read kHDR_name_");
		return;
	}
	if(((*status)=_bse.h_read(1,kHDR_precs_,&_precs))){
_te_("status = "+(*status)+" at _bse.h_read kHDR_precs_");
		return;
	}
	if(((*status)=_bse.h_read(1,kHDR_unit2m_,&_unit2m))){
_te_("status = "+(*status)+" at _bse.h_read kHDR_unit2m_");
		return;
	}
	if(((*status)=_bse.h_read(1,kHDR_srid_,&_srid))){
_te_("status = "+(*status)+" at _bse.h_read kHDR_srid_");
		return;
	}
	
//	snprintf(_name,256,tname);
	strncpy(_name,tname,sizeof(_name)-1);
				
	read_name(path,tname);
	if((strlen(tname)>0)&&(strcmp(_name,tname))){
_tw_("replacing type name \""+_name+"\" to \""+tname+"\"");
//		snprintf(_name,256,tname);
		strncpy(_name,tname,sizeof(_name)-1);
		if(((*status)=_bse.h_write(1,kHDR_name_,tname))){
_te_("status = "+(*status)+" at _bse.h_write kHDR_name_");
			_name[0]=0;
			return;
		}
	}
	
gi_init_p gp={&_bounds,status,SetFlag,GetFlag,GetBounds,ObjIDComp};
	_iter=(bGenericGeoIterator*)(extmgr->get_component(kComponentGeoIterator)->i_allocate(tbltype,_MMAPP_,&gp));
	if(!_iter){
_te_("no iterator");
		(*status)=-1;
		return;
	}

	_styles=new bStyleMgr(this,status);
	if((*status)){
_te_("status = "+(*status)+" at new bStyleMgr");
		return;
	}		
	
	_nbalive=0;
	_nbkilled=0;	
	_nsel=0;
	_ncnt=0;
		
	(*status)=noErr;
}
Esempio n. 27
0
void
AsxTokenizer::move_next ()
{
	char c;

	while ((c = read_char ()) != -1) {

		if (in_data) {
			bool entirely_whitespace;
			current_token->set_type (TOKEN_DATA);
			current_token->set_value (read_data (c, entirely_whitespace));
			current_token->set_entirely_whitespace (entirely_whitespace);
			return;
		}

		if (c == OP_OPEN_ELEMENT) {
			if (is_comment_open (c)) {
				read_comment ();
				continue;
			}
			current_token->set_type (TOKEN_OPEN_ELEMENT);
			current_token->set_value (NULL);
			in_data = false;
			return;
		}

		if (c == OP_CLOSE_ELEMENT) {
			current_token->set_type (TOKEN_CLOSE_ELEMENT);
			current_token->set_value (NULL);
			in_data = true;
			return;
		}

		if (c == OP_ASSIGNMENT) {
			current_token->set_type (TOKEN_ASSIGNMENT);
			current_token->set_value (NULL);
			return;
		}

		if (c == OP_SLASH) {
			current_token->set_type (TOKEN_SLASH);
			current_token->set_value (NULL);
			return;
		}

		if (g_ascii_isspace (c)) {
			current_token->set_type (TOKEN_WHITESPACE);
			current_token->set_value (NULL);
			return;
		}

		if (is_quote_char (c)) {
			current_token->set_type (TOKEN_QUOTED_STRING);
			current_token->set_value (read_quoted_string (c));
			return;
		}

		if (is_name_char (c)) {
			current_token->set_type (TOKEN_NAME);
			current_token->set_value (read_name (c));
			return;
		}
	}

	current_token->set_type (TOKEN_EOF);
	current_token->set_value (NULL);
}
Esempio n. 28
0
void main()
{
    char s[100];
    read_name(1,s);
    printf("%s",s);
}
Esempio n. 29
0
/**
 * params:
 *   the filedes where the data was received.
 * returns:
 *   0 if this fd should be taken out of the poll_fd array bcause it already has AS name.
 *   fd if an AS was completed (returns the fd of the events socket)
 *   -1 if there was an error
 *   -2 if client disconnected and should be closed and taken outside the poll_fd array
 */
static int handle_unc_as_data(int fd)
{
   int i,j,k,len;
   char *name1;
   struct as_entry *as;
   /*first, we see if the data to read is from any of the uncompleted as's*/
   for(i=0;i<2*MAX_UNC_AS_NR ;i++)
      if(unc_as_t[i].valid && unc_as_t[i].fd==fd)
	 break;
   if(i==2*MAX_UNC_AS_NR){
      LM_ERR("has received an fd which is not in uncompleted AS array\n");
      return -1;
   }
   if(unc_as_t[i].flags & HAS_NAME){/*shouldn't happen, if it has a name, it shouldnt be in fdset[]*/
      LM_WARN("this shouldn't happen\n");
      return 0;/*already have a name, please take me out the uncompleted AS array*/
   }
   LM_DBG("Reading client name\n");

   if(-1==(len=read_name(fd,unc_as_t[i].name,MAX_AS_NAME))){
      /*this guy should be disconnected, it sent an AS_NAME too long*/
      LM_ERR("Bad name passed from fd\n");
      unc_as_t[i].valid=0;
      unc_as_t[i].flags=0;
      return -2;
   }else if(len==-2){
      LM_WARN("client disconnected\n");
      return -2;
   }
   name1=unc_as_t[i].name;

   /* Check the name isn't already taken */
   for(as=as_list;as;as=as->next){
      if(as->name.len==len && !memcmp(name1,as->name.s,len)){
	 if(as->connected){
	    LM_WARN("AppServer trying to connect with a name already taken (%.*s)\n",len,name1);
	    unc_as_t[i].valid=0;
	    unc_as_t[i].flags=0;
	    return -2;
	 }
	 break;
      }
   }
   if (!as) {
      LM_ERR("a client tried to connect which is not declared in config. script(%.*s)\n",len,name1);
      unc_as_t[i].valid=0;
      unc_as_t[i].flags=0;
      return -2;
   }
   unc_as_t[i].flags |= HAS_NAME;
   /* the loop's upper bound,
    * if 'i' is in the lower part, then look for an unc_as in the upper part*/
   k=(i>=MAX_UNC_AS_NR?MAX_UNC_AS_NR:2*MAX_UNC_AS_NR);
   /* the loop's lower bound */
   for(j=(i>=MAX_UNC_AS_NR?0:MAX_UNC_AS_NR);j<k;j++)
      if(unc_as_t[j].valid &&
	    (unc_as_t[j].flags & HAS_NAME) &&
	    !strcmp(unc_as_t[i].name,unc_as_t[j].name))
	 break;
   LM_INFO("Fantastic, we have a new client: %s\n",unc_as_t[i].name);
   if(j==k)/* the unc_as peer's socket hasn't been found, just take this one out of fdset because it already has its name */
      return 0;/*take me out from fdset[]*/
   LM_INFO("EUREKA, we have a new completed AS: %s\n",unc_as_t[i].name);
   /* EUREKA ! we have a sweet pair of AS sockets, with the same name !!*/
   if(add_new_as(i<j?i:j,i<j?j:i,as)==-1){
      close(unc_as_t[j].fd);
      close(unc_as_t[i].fd);
      unc_as_t[j].valid=unc_as_t[i].valid=0;
      unc_as_t[j].flags=unc_as_t[i].flags=0;
      return -1;
   }
   unc_as_t[j].valid=unc_as_t[i].valid=0;
   unc_as_t[j].flags=unc_as_t[i].flags=0;
   return unc_as_t[i<j?i:j].fd;
}
Esempio n. 30
0
void * process_requests(void * arg)
{
	int threadNum = *((int *)arg);
	int ret;  /* return value from a call */
	while (true)
	{
		struct tdata * local_tdata = removeq();

		if (local_tdata->socket == -1)
		{
			printf("exiting thread\n");
			return NULL;
		}

		FILE *logFile;
		logFile = fopen("log.txt", "a");

		int clientd = local_tdata->socket;
		char buff[MAXBUFF];  /* message buffer */
		if ((ret = recv(clientd, buff, MAXBUFF-1, 0)) < 0) {
			perror("recv()");
			return NULL;
		} 

		buff[ret] = '\0';  // add terminating nullbyte to received array of char
		printf("Received request (%d chars):\n%s\n", ret, buff);

		FILE *iFile;
		struct name myName = {0, 0, 0, 0, -1, 0};
		read_name(&myName, buff, ret);

		pthread_mutex_lock(&lMutex);
			if ((myName.tok[0][0] == 'Q') && (myName.tok[0][1] == 'U') && (myName.tok[0][2] == 'I') && (myName.tok[0][3] == 'T'))
			{
				struct tdata quitTdata = {-1, -1, NULL, NULL};
				int j;
				for (j = 0; j < NUMTHREADS; j++)
				{
					printf("TESTING\n");
					addq(&quitTdata);
				}
				exit(0);
			}
		pthread_mutex_unlock(&lMutex);

		if (myName.tok[1][0] == '/')
		{
			memmove(myName.tok[1], myName.tok[1] + 1, strlen(myName.tok[1]));
		}

		//print request to log
		time_t now;
		now = time(NULL);
		char timestamp[30];
		if(strftime(timestamp, 30, "%a, %d %b %Y %T %Z", gmtime(&now)) == 0)
		{
			printf("error: timestamp. Log not accurate.\n");
		}
		pthread_mutex_lock(&lMutex);
			fprintf(logFile, "%d %d %s \n%d %s %s", local_tdata->request_id, threadNum, timestamp, local_tdata->request_id, myName.tok[0], myName.tok[1]);
		pthread_mutex_unlock(&lMutex);

		if (!((myName.tok[0][0] == 'G') && (myName.tok[0][1] == 'E') && (myName.tok[0][2] == 'T'))) //GET syntax check
		{
			if ((ret = send(clientd, message4, strlen(message4), 0)) < 0)
			{
				perror("send()");
				return NULL;
			}
			return NULL;
		} else {
			printf("testing\n");
			printf("opening file: %s\n", myName.tok[1]);
			iFile = fopen(myName.tok[1], "r");
			if (iFile == NULL)
			{
				perror ("Error opening file");
				if ((ret = send(clientd, message5, strlen(message5), 0)) < 0)
				{
					perror("send()");
					return NULL;
				}
			} else {
				char sendBuff[MAXBUFF];  // message buffer
				size_t bufflen = 0;  // current capacity of buff
				size_t nchars;  // number of bytes recently read
				struct stat *stats;
				stat(myName.tok[1], stats);
				int numBytes = (int)stats->st_size;
				char numBytesChar[999];

				sprintf(numBytesChar, "%d", numBytes);
				if ((ret = send(clientd, message1, strlen(message1), 0)) < 0)
				{
					perror("send()");
					return NULL;
				}
				if ((ret = send(clientd, timestamp, strlen(timestamp), 0)) < 0)
				{
					perror("send()");
					return NULL;
				}
				if ((ret = send(clientd, message2, strlen(message2), 0)) < 0)
				{
					perror("send()");
					return NULL;
				}
				if ((ret = send(clientd, numBytesChar, strlen(numBytesChar), 0)) < 0)
				{
					perror("send()");
					return NULL;
				}
				if ((ret = send(clientd, message3, strlen(message3), 0)) < 0)
				{
					perror("send()");
					return NULL;
				}
				while (fgets(sendBuff, MAXBUFF, iFile))
				{
					if ((ret = send(clientd, sendBuff, MAXBUFF-1, 0)) < 0)
					{
						perror("send()");
						return NULL;
					}
				}
			}
		}

		shutdown(clientd, 0);
		if (myName.tok[3] == NULL)
		{
			if ((ret = close(clientd)) < 0)
			{
				perror("close(clientd)");
				return NULL;
			}
		}
		fclose(logFile);
		free(local_tdata->link);
	}
}