Exemple #1
0
const field_value Dataset::get_field_value(const char *f_name) {
  if (ds_state != dsInactive)
  {
    if (ds_state == dsEdit || ds_state == dsInsert){
      for (unsigned int i=0; i < edit_object->size(); i++)
        if (str_compare((*edit_object)[i].props.name.c_str(), f_name)==0) {
          return (*edit_object)[i].val;
        }
      throw DbErrors("Field not found: %s",f_name);
    }
    else
    {
      //Lets try to reuse a string ->index conversation
      if (get_index_map_entry(f_name))
        return get_field_value(static_cast<int>(fieldIndexMap_Entries[fieldIndexMapID].fieldIndex));

      const char* name=strstr(f_name, ".");
      if (name)
        name++;

      for (unsigned int i=0; i < fields_object->size(); i++) 
        if (str_compare((*fields_object)[i].props.name.c_str(), f_name) == 0 || (name && str_compare((*fields_object)[i].props.name.c_str(), name) == 0)) {
          fieldIndexMap_Entries[fieldIndexMapID].fieldIndex = i;
          return (*fields_object)[i].val;
        }
    }
    throw DbErrors("Field not found: %s",f_name);
  }
  throw DbErrors("Dataset state is Inactive");
  //field_value fv;
  //return fv;
}
Exemple #2
0
int
str2ent(const char *str,
	int len)
{
    int i, d = -1;

    
    if (len < 0)
	len = strlen(str);

    if (sscanf(str, "&#x%x;", &d) == 1)
	return d;
    
    if (sscanf(str, "&#%u;", &d) == 1)
	return d;
    
    for (i = 0; d == -1 && iso88591_ev[i].name; ++i)
	if (str_compare(iso88591_ev[i].name, str, len, 0) == 0)
	    return iso88591_ev[i].c;

    for (i = 0; d == -1 && iso88591_ev[i].name; ++i)
	if (str_compare(iso88591_ev[i].name, str, len, 1) == 0)
	    return iso88591_ev[i].c;

    return -1;
}
constexpr uint32_t
get_id(const char *name)
{
  return

  str_compare(name, "Player") ? 1 : 
  str_compare(name, "Dynamic_green_cube") ? 2 : 
  str_compare(name, "Dynamic_red_cube") ? 3 : 
  str_compare(name, "Ground") ? 4 : 

  0;
}
Exemple #4
0
int str_find(const char *str, const char *str_to_find, int casesensitive)
{
  int i, str_len, str_to_find_len, count;

  if (!str || str[0] == 0 || !str_to_find || str_to_find[0] == 0)
    return -1;

  str_len = (int)strlen(str);
  str_to_find_len = (int)strlen(str_to_find);
  count = str_len - str_to_find_len;
  if (count < 0)
    return -1;

  count++;

  for (i = 0; i<count; i++)
  {
    if (str_compare(str, str_to_find, casesensitive))
      return i;

    str++;
  }

  return -1;
}
Exemple #5
0
/* Insert a new method into the structure */
int insert_method(char *method) {
        METHOD_NODE **node = &methods;
        int cmp;
        
#ifdef DEBUG
        ASSERT(method);
        ASSERT(strlen(method) > 0);
#endif
        
        while (*node) {
                cmp = str_compare(method, (*node)->method);
                if (cmp > 0) {
                        node = &(*node)->right;
                } else if (cmp < 0) {
                        node = &(*node)->left;
                } else {
                        WARN("Method '%s' already provided", method);
                        
                        return 0;
                }
        }
        
        if ((*node = (METHOD_NODE *) malloc(sizeof(METHOD_NODE))) == NULL) {
                LOG_DIE("Cannot allocate memory for method node");
        }
        
        if (((*node)->method = (char *) malloc(strlen(method) + 1)) == NULL) {
                LOG_DIE("Cannot allocate memory for method string");
        }
        
        strcpy((*node)->method, method);
        (*node)->left = (*node)->right = NULL;
        
        return 1;
}
const field_value Dataset::get_field_value(const char *f_name) {
  const char* name=strstr(f_name, ".");
  if (name) name++;
  if (ds_state != dsInactive) {
    if (ds_state == dsEdit || ds_state == dsInsert){
      for (unsigned int i=0; i < edit_object->size(); i++)
		if (str_compare((*edit_object)[i].props.name.c_str(), f_name)==0) {
	  		return (*edit_object)[i].val;
			}
      throw DbErrors("Field not found: %s",f_name);
       }
    else
      for (unsigned int i=0; i < fields_object->size(); i++) 
			if (str_compare((*fields_object)[i].props.name.c_str(), f_name)==0 || (name && str_compare((*fields_object)[i].props.name.c_str(), name)==0)) {
	  			return (*fields_object)[i].val;
			}
      throw DbErrors("Field not found: %s",f_name);
       }
  throw DbErrors("Dataset state is Inactive");
  //field_value fv;
  //return fv;
}
Exemple #7
0
int main(int argc, char **args)
{
	char *str = (char *) malloc(100);

	str_copy(str, "Hello World!");
	printf("%s\n", str);

	int cmp0 = str_compare("abcde", "abcde");
	int cmp1 = str_compare("abcde", "abcdf");
	int cmp2 = str_compare("abcdf", "abcde");
	int cmp3 = str_compare("abcde", "abcdef");
	int cmp4 = str_compare("abcdef", "abcde");
	printf("%d %d %d %d %d\n", cmp0, cmp1, cmp2, cmp3, cmp4);

	str_concat(str, "Hello ", "World!");
	printf("%s\n", str);

	str_sub(str, "Hello World!", 7, 2);
	printf("%s\n", str);

	int ind0 = str_index("Hello World!", "o", 0);
	int ind1 = str_index("Hello World!", "o", 5);
	printf("%d %d\n", ind0, ind1);

	str_copy(str, "Hello World!");
	str_insert(str, "My Beautiful ", 6);
	printf("%s\n", str);

	str_delete(str, 6, 3);
	printf("%s\n", str);

	str_delete(str, 6, 10);
	printf("%s\n", str);

	free(str);

	return 0;
}
Exemple #8
0
/*
 * dbg_find_command(name)
 *
 * Finds a command within the command list by its name.
 *
 */
dbg_command_t* dbg_find_command(const utf8_t* name)
{
	int l__i = dbg_commands_n;
	
	while (l__i --)
	{
		if (!str_compare(dbg_commands[l__i].cmd_name, name, 32))
		{
			return &dbg_commands[l__i];
		}
	}
	
	return NULL;
}
bool Dataset::set_field_value(const char *f_name, const field_value &value) {
  bool found = false;
  if ((ds_state == dsInsert) || (ds_state == dsEdit)) {
      for (unsigned int i=0; i < fields_object->size(); i++) 
	if (str_compare((*edit_object)[i].props.name.c_str(), f_name)==0) {
			     (*edit_object)[i].val = value;
			     found = true;
	}
      if (!found) throw DbErrors("Field not found: %s",f_name);
    return true;
  }
  throw DbErrors("Not in Insert or Edit state");
  //  return false;
}
int isadded_str(struct object* a,char* string,int ascii_sum)		
{
	struct object* b = a;
	int ret_val = 0;
	while(b!=NULL)
	{
		if(str_compare(b->str,string)==1)
			ret_val = 1;
		if(b->ascii_sum==ascii_sum)
			b->flag = 1;
		b = b->next;
	}
	return ret_val;
}
Exemple #11
0
/* Lookup a particular node in hash; return pointer to node
   if found, NULL otherwise */
FORMAT_NODE *get_field(char *str) {
        FORMAT_NODE *node;

#ifdef DEBUG
        ASSERT(str);
        ASSERT(strlen(str) > 0);
        ASSERT((hash_str(str, HASHSIZE) >= 0) && (hash_str(str, HASHSIZE) < HASHSIZE));
#endif

        for (node = fields[hash_str(str, HASHSIZE)]; node != NULL; node = node->next)
                if (str_compare(str, node->name) == 0)
                        return node;

        return NULL;
}
Exemple #12
0
/* Lookup a particular node in hash; return pointer to node
   if found, NULL otherwise */
struct host_stats *get_host(char *str) {
        struct host_stats *node;

#ifdef DEBUG
        ASSERT(str);
        ASSERT(strlen(str) > 0);
        ASSERT((hash_str(str, HASHSIZE) >= 0) && (hash_str(str, HASHSIZE) < HASHSIZE));
#endif

        for (node = stats[hash_str(str, HASHSIZE)]; node != NULL; node = node->next)
                if (str_compare(str, node->host) == 0)
                        return node;

        return NULL;
}
Exemple #13
0
void	param(char **tab, int end, int left)
{
  end--;
  while (end > left)
    {
      carac_special(tab, &end);
      if (str_compare(tab, end) == 1)
        my_putstr(tab[end]);
      if (my_strncmp(tab[end], ",", 1) == 0)
        my_putstr("et");
      end--;
      if (end > left + 1)
        my_putchar(' ');
    }
  my_putstr(".\n");
}
Exemple #14
0
/*
 * spxml_replace_stdentities(text, max)
 *
 * Converts als standard entity references in "text" to normal
 * UTF-8 characters. The "text" will have at least a length of "len"
 * bytes.
 *
 * All entities are stored in the entity table. The referenced
 * entities may be only smaller than the entity reference.
 *
 * Return value:
 *	Copy of the input string "text" with converted entity references.
 */
utf8_t* spxml_replace_stdentities(const utf8_t *text, size_t len)
{
	const utf8_t *l__ptr = text;
	utf8_t *l__out = mem_alloc(len);
	if (l__out == NULL) return NULL;
	utf8_t *l__outptr = l__out;
	size_t l__len = len;
	
	if (text == NULL) 
	{
		*tls_errno = ERR_INVALID_ARGUMENT;
		return NULL;
	}
	
	do
	{
		if (*l__ptr == '&')
		{
			int l__i = SPXML_REFTABLE_LEN;

			/* Search the reference in the reference table */
			while (l__i --)
			{
				if (!str_compare(l__ptr, spxml_entity_reftable[l__i].ref, spxml_entity_reftable[l__i].ref_len))
				{
					str_copy(l__outptr, spxml_entity_reftable[l__i].ch_replace, spxml_entity_reftable[l__i].ch_len);
					
					l__len -= spxml_entity_reftable[l__i].ref_len - 1;
					
					l__outptr += spxml_entity_reftable[l__i].ch_len;
					l__ptr += spxml_entity_reftable[l__i].ref_len - 1;
					
					break;
				}
			}	
			
			/* Found sthg.? Continue, else just copy the entity reference */
			if (l__i > -1) continue;
		}
	
		/* Copy normal charracters */
		*l__outptr++ = *l__ptr;
	}while((*l__ptr ++) && (l__len --));

	return l__out;

}
Exemple #15
0
/*
 * dbg_test_par(start, val)
 *
 * Searches the parameter value "val" in the parameter list
 * starting from the parameter entry "start".
 *
 * Return value:
 *	>-1	Number of the parameter entry
 *	-1	Parameter value not found
 *
 */
int dbg_test_par(unsigned start, const utf8_t *val)
{
	unsigned l__i = 0;
	dbg_shell_t *l__shell = (*dbg_tls_shellptr);
	
	/* Is the list smaller? */
	if (start >= l__shell->n_pars) return -1;
	
	/* Search it */
	for (l__i = start; l__i < l__shell->n_pars; l__i ++)
	{
		if (!str_compare(l__shell->pars[l__i], val, DBGSHELL_CMDBUFFER_SIZE))
			return (signed)l__i;
	}
	
	return -1;	
}
Exemple #16
0
/*
 * dbg_get_variable(name)
 *
 * Returns the variable structure of a variable with name "name".
 *
 * REMEMBER: This function should be run with locked mutex dbg_variables_mtx!
 *
 * Return value:
 *	!= NULL		Pointer to that variable
 *	== NULL		Variable not found
 *
 */
dbg_variable_t* dbg_get_variable(const utf8_t *name)
{
    dbg_variable_t *l__vars = dbg_variables;

    if (name == NULL) return NULL;

    /* Search it */
    while (l__vars != NULL)
    {
        if (!str_compare(l__vars->name, name, 32))
            return l__vars;

        l__vars = l__vars->ls.n;
    }

    return NULL;
}
Exemple #17
0
//------------------------------------------------------------------------------
static unsigned int normal_selector(
    const char* needle,
    const match_store& store,
    match_info* infos,
    int count)
{
    int select_count = 0;
    for (int i = 0; i < count; ++i)
    {
        const char* name = store.get(infos[i].store_id);
        int j = str_compare(needle, name);
        infos[i].select = (j < 0 || !needle[j]);
        ++select_count;
    }

    return select_count;
}
Exemple #18
0
void set_file_format(imImage* image, const char* filename)
{
  const char* ext = str_fileext(filename);
  const char* format = "JPEG";
  if (str_compare(ext, "jpg", 0) || str_compare(ext, "jpeg", 0))
    format = "JPEG";
  else if (str_compare(ext, "bmp", 0))
    format = "BMP";
  else if (str_compare(ext, "png", 0))
    format = "PNG";
  else if (str_compare(ext, "tga", 0))
    format = "TGA";
  else if (str_compare(ext, "tif", 0) || str_compare(ext, "tiff", 0))
    format = "TIFF";
  imImageSetAttribString(image, "FileFormat", format);
}
Exemple #19
0
void mafBlock_add_qLine(String *line, MafSubBlock *sub) {
  List *l = lst_new_ptr(3);
  String *str;
  int i;

  if (sub->numLine<1 || sub->lineType[0]!='s') 
    die("ERROR: got q-Line without preceding s-Line in MAF block\n");

  if (3 != str_split(line, NULL, l))
    die("ERROR: expected three fields in q-Line of maf file, got %i\n", lst_size(l));
  
  //field[0] should be 'q'
  if (!(str_compare_charstr((String*)lst_get_ptr(l, 0), "q")==0))
    die("ERROR mafBlock_add_qLine expected 'q' got %s\n",
	((String*)lst_get_ptr(l, 0))->chars);
  
  //field[1] should be src, and should match src already set in sub
  if (str_compare((String*)lst_get_ptr(l, 1), sub->src) != 0)
    die("iLine sourceName does not match preceding s-Line (%s, %s)\n", 
	((String*)lst_get_ptr(l, 1))->chars, sub->src->chars);

  //field[2] should be quality
  if (sub->seq == NULL)
    die("ERROR mafBlock_add_qLine: sub->seq is NULL\n");
  str = (String*)lst_get_ptr(l, 2);
  if (sub->seq->length != str->length) 
    die("ERROR: length of q-line does not match sequence length\n");
  sub->quality = str;
  for (i=0; i<sub->quality->length; i++) {
    if (sub->seq->chars[i] == '-') {
      if (sub->quality->chars[i] != '-') 
	die("ERROR: got quality score where alignment char is gap\n");
    } else {
      if (sub->quality->chars[i] != 'F' && sub->quality->chars[i] < '0' &&
	  sub->quality->chars[i] > '9')
	die("ERROR: Illegal quality score '%c' in MAF block\n", 
	    sub->quality->chars[i]);
    }
  }
   
  for (i=0; i<2; i++) str_free((String*)lst_get_ptr(l, i));
  lst_free(l);
  sub->lineType[sub->numLine++] = 'q';
}
Exemple #20
0
void mafBlock_add_iLine(String *line, MafSubBlock *sub) {
  List *l = lst_new_ptr(6);
  String *str;
  int i;

  if (sub->numLine<1 || sub->lineType[0]!='s') 
    die("ERROR: got i-Line without preceding s-Line in MAF block\n");
  
  if (6 != str_split(line, NULL, l))
    die("ERROR: expected six fields in MAF line starting with 'i' (got %i)\n",
	lst_size(l));

  //field[0] should be 'i'
  if (!(str_compare_charstr((String*)lst_get_ptr(l, 0), "i")==0))
    die("ERROR: mafBlock_add_iLine: field[0] should be 'i', got %s\n",
	((String*)lst_get_ptr(l, 0))->chars);

  //field[1] should be src, and should match src already set in sub
  if (str_compare((String*)lst_get_ptr(l, 1), sub->src) != 0)
    die("iLine sourceName does not match preceding s-Line (%s, %s)\n", 
	((String*)lst_get_ptr(l, 1))->chars, sub->src->chars);

  for (i=0; i<2; i++) {

    //field[2,4] should be leftStatus, rightStauts
    str = (String*)lst_get_ptr(l, i*2+2);
    if (str->length != 1) die("ERROR: i-Line got illegal %sStatus = %s\n",
			      i==0 ? "left": "right", str->chars);
    sub->iStatus[i] = str->chars[0];
    if (sub->iStatus[i] != 'C' && sub->iStatus[i] != 'I' &&
	sub->iStatus[i] != 'N' && sub->iStatus[i] != 'n' &&
	sub->iStatus[i] != 'M' && sub->iStatus[i] != 'T')
      die("ERROR: i-Line got illegal %sStatus = '%c'\n",
	  i==0 ? "left" : "right", sub->iStatus[i]);

    //field 3,5 should be leftCount, rightCount
    str = (String*)lst_get_ptr(l, i*2+3);
    sub->iCount[i] = atoi(str->chars);
  }
  
  for (i=0; i<6; i++) str_free((String*)lst_get_ptr(l, i));
  lst_free(l);
  sub->lineType[sub->numLine++] = 'i';
}
Exemple #21
0
void	carac_special(char **tab, int *end)
{
  if (str_compare(tab, *end) == 0 && my_strncmp(tab[*end], "*", 1) != 0
      && my_strncmp(tab[*end], "(", 1) != 0
      && my_strncmp(tab[*end], ")", 1) != 0
      && my_strncmp(tab[*end], "[", 1) != 0
      && my_strncmp(tab[*end], "]", 1) != 0
      && my_strncmp(tab[*end], ",", 1) != 0
      && my_strncmp(tab[*end], " ", 1) != 0)
    {
      my_putstr(tab[(*end)--]);
      my_putstr(" de type ");
    }
  while (my_strncmp(tab[*end], "*", 1) == 0)
    {
      my_putstr("pointeur sur ");
      (*end)--;
    }
}
Exemple #22
0
/* This function tries run program (which are defined in terminalapi_program_list.h and .c).
 * Returns: EC_FAILURE if program doesn't excist.
 *			EC_SUCCESS if program is runned correctly. */
extern errorc_t terminalapi_try_run_program(terminalapi_cmd_t *cmd_struct, terminalapi_program_t program_list[])
	{
	uint32_t program_idx = 0;
	
	/* Loop through command list and try find correct program to run. */
	while(program_list[program_idx].program_pointer != 0)
		{
		/* Command string can also end empty space (after space comes value), for that reason third argument
		 * is set to ' '. */
		if( str_compare(cmd_struct->command_str, program_list[program_idx].command_string, cmd_struct->cmd_end_idx) )
			{
			/* If strings match, run program in terminal */
			(*(*program_list[program_idx].program_pointer))(cmd_struct);
			return EC_SUCCESS;
			}
		program_idx++;
		}
	
	return EC_FAILURE;
	}
Exemple #23
0
void	return_func(char **tab, int left)
{
  my_putstr("Il/Elle retourne le type ");
  left--;
  while (left >= 0)
    {
      while (my_strncmp(tab[left], "*", 1) == 0)
	{
	  my_putstr("pointeur sur ");
	  left--;
	}
      if (str_compare(tab, left) == 1)
	{
	  my_putstr(tab[left]);
	  if (left != 0)
	    my_putchar(' ');
	}
      left--;
    }
  my_putstr(".\n");
}
Exemple #24
0
/*
 * dbg_get_breakpoint_adr(client, name)
 *
 * Returns the address of a breakpoint of the client "client" which has the
 * name "name".
 *
 * This function expects dbg_client_mtx to be locked and leaves it locked!
 *
 * Return value:
 *	0 	Error
 *	!= 0	Address of the break point
 *
 */
uintptr_t dbg_get_breakpoint_adr(dbg_client_t *client, const utf8_t *name)
{
	uintptr_t l__retval = 0;
	
	dbg_breaks_t *l__brk = client->breakpoints;
	
	/* Search the breaking point */
	while (l__brk != NULL)
	{
		if (!str_compare(l__brk->name, name, 32))
		{
			l__retval = l__brk->address;
			
			return l__retval;
		}
		
		l__brk = l__brk->ls.n;
	}	
	
	return 0;
}
Exemple #25
0
/*
 * dbg_execute_cmd
 *
 * Executes a command entered to the current shell. The
 * Command input has to be parsed by dbg_parse_cmd.
 *
 * Return value:
 *	>0	Status report of the executed command
 *	0	Command executed normally
 *	<0	Error value returned by the command
 *
 */
int dbg_execute_cmd(void)
{
	int l__i = dbg_commands_n;
	dbg_shell_t *l__shell = (*dbg_tls_shellptr);
	
	/* No command. Just return */
	if (l__shell->cmd == NULL) return 0;
	
	/* Find the right command */
	while (l__i --)
	{
		if (!str_compare(dbg_commands[l__i].cmd_name, l__shell->cmd, DBGSHELL_CMDBUFFER_SIZE))
		{
			/* Execute the command */
			return dbg_commands[l__i].execute_cmd();
		}
	}
	
	dbg_iprintf(l__shell->terminal, "Unkown command - \'%s\'\n", l__shell->cmd);
	
	return -1;
}
Exemple #26
0
/*
 * spxml_probe_element(&val, type)
 *
 * Test if the event "val" is a SPXML element of type "type",
 * which normally begins with "begin" and ends with "end".
 * "begin" has a length of "blen" bytes and "end" a length
 * of "elen" bytes.
 * The length element of "val" (val->len) has to be specified
 * to run this function.
 *
 * Return Value:
 * 	1 	Element found, the datas will be passed to "val"
 *	0	Element not found
 *
 */
static inline int spxml_probe_element(spxml_event_t *val, int type)
{
	utf8_t *l__buf = mem_alloc(5);
	str_copy(l__buf, val->position, 4);
	l__buf[4] = 0;	
	mem_free(l__buf);
		
	if (!str_compare(val->position, spxml_event_types[type].begin, spxml_event_types[type].blen))
	{
		val->type = type;
		if (!spxml_end_of_event(val, spxml_event_types[type].end, spxml_event_types[type].elen)) return 0;
		
		val->content = val->position + spxml_event_types[type].blen;
		val->len -= spxml_event_types[type].blen;

		return 1;
	}
	 else
	{
		return 0;
	}
}
Exemple #27
0
/* Search data structure for a matching method */
int is_request_method(const char *str) {
        METHOD_NODE *node = methods;
        int cmp;
        
#ifdef DEBUG
        ASSERT(node);
        ASSERT(str);
#endif
        
        if (strlen(str) == 0) return 0;
        
        while (node) {
                cmp = str_compare(str, node->method);
                if (cmp > 0) {
                        node = node->right;
                } else if (cmp < 0) {
                        node = node->left;
                } else {
                        return 1;
                }
        }
        
        return 0;
}
Exemple #28
0
int main(int argc, char const *argv[]) {
    /* str_new */
    str_t string = str_new();
    /* str_set */
    str_set(string, "   %d%d%d", 1, 2, 3);
    /* str_append */
    str_append(string, "appending   end");
    /* str_println */
    str_println(string);
    /* str_reverse */
    str_reverse(string);
    str_println(string);
    /* str_length */
    printf("size before trimming:\t%zu\n", str_length(string));
    /* str_trim */
    str_trim(string);
    printf("size after trimming:\t%zu\n", str_length(string));
    /* str_substr */
    str_t substr = str_substr(string, 0, 3);
    printf("substr before swap:\t");
    str_println(substr);
    printf("string before swap:\t");
    str_println(string);
    str_swap(substr, string);
    printf("substr after swap:\t");
    str_println(substr);
    printf("string after swap:\t");
    str_println(string);
    printf("is string empty?\t%s\n",
           str_isempty(string) ? "Yes" : "No");
    printf("is substr equal to string?\t%s\n",
           str_compare(substr, string) ? "No" : "Yes");

    /* str_readFromFile */
    str_readFromFile(string, "neostring.c");
    printf("string size: %zu\t", str_length(string));
    printf("string capacity: %zu\n", string->capacity);
    str_set(string, "ok");
    printf("Before trimToSize():\n");
    printf("string size: %zu\t", str_length(string));
    printf("string capacity: %zu\n", string->capacity);
    /* str_trimToSize */
    str_trimToSize(string);
    printf("After trimToSize():\n");
    printf("string size: %zu\t", str_length(string));
    printf("string capacity: %zu\n", string->capacity);
    str_set(string, "hello, world");
    str_println(string);
    printf("%zu\n", string->size);
    printf("string has prefix ello?\t%s\n", str_hasPrefix(string, "ello") ? "Yes" : "No");
    printf("%zu\n", string->size);
    printf("string has suffix orld?\t%s\n", str_hasSuffix(string, "orld") ? "Yes" : "No");
    /* str_clone */
    str_t clone = str_clone(string);
    /* str_toupper */
    str_toupper(clone);
    /* str_writeToFile */
    str_writeToFile(clone, "./test.txt");
    /* str_destroy */
    str_destroy(string);
    str_destroy(clone);
    str_destroy(substr);
    return 0;
}
Exemple #29
0
// START FUNC DECL
int
orphan_files(
    char *in_data_dir,
    char *action
    )
// STOP FUNC DECL
{
  int status = 0;
  DIR *dp = NULL; FILE *ofp = NULL;
  struct dirent *ep = NULL;     
  char Xopfile[MAX_LEN_FILE_NAME+1];
  char Yopfile[MAX_LEN_FILE_NAME+1];
  char *X = NULL; size_t nX = 0;
  char *Y = NULL; size_t nY = 0;
  char nullc = '\0';
  int Xnum_files = 0, Ynum_files = 0;
  int ddir_id;
  char data_dir[MAX_LEN_DIR_NAME+1];

  if ( ( in_data_dir == NULL ) || ( *in_data_dir == '\0' ) ) {
    status = chdir(g_data_dir); cBYE(status);
    ddir_id = -1;
    if ( strlen(g_data_dir) >= MAX_LEN_DIR_NAME ) { go_BYE(-1); }
    strcpy(data_dir, g_data_dir);
  }
  else {
    status = strip_trailing_slash(in_data_dir, data_dir, MAX_LEN_DIR_NAME+1);
    cBYE(status);
    status = get_ddir_id(data_dir, g_ddirs, g_n_ddir, false, &ddir_id);
    cBYE(status);
    status = chdir(data_dir); cBYE(status);
  }

  zero_string(Xopfile, MAX_LEN_FILE_NAME+1);
  zero_string(Yopfile, MAX_LEN_FILE_NAME+1);

  /* START: Create X. X = filenames listed in the meta data (whose 
   * ddir_id matches that requested) in sorted order */
  status = open_temp_file(g_cwd, g_cwd, Xopfile, 0); cBYE(status);
  ofp = fopen(Xopfile, "w"); 
  return_if_fopen_failed(ofp, Xopfile, "w");
  for ( int i = 0; i < g_n_fld; i++ ) { 
    if ( g_flds[i].name[0] == '\0' ) { continue; }
    if ( g_flds[i].ddir_id != ddir_id ) { continue; }
    Xnum_files++;
    fwrite(g_flds[i].filename, sizeof(char), MAX_LEN_FILE_NAME+1, ofp);
  }
  fclose_if_non_null(ofp);
  if ( Xnum_files > 0 ) { 
    status = rs_mmap(Xopfile, &X, &nX, 1);
    qsort(X, Xnum_files, MAX_LEN_FILE_NAME+1, str_compare);
  }
  /* STOP ---- */

  status = open_temp_file(g_cwd, g_cwd, Yopfile, 0); cBYE(status);
  ofp = fopen(Yopfile, "w"); 
  return_if_fopen_failed(ofp, Xopfile, "w");
  dp = opendir(data_dir);
  if ( dp == NULL) { go_BYE(-1); }
  for ( ; ; ) { 
    ep = readdir (dp);
    if ( ep == NULL ) { break; }
    char *filename = ep->d_name;
    if ( ( filename == NULL ) || ( *filename == '\0' ) )  { break; }
    if ( strncmp(filename, "docroot", 7) == 0  ) { continue; }
    if ( strncmp(filename, ".LDB_META", 9) == 0  ) { continue; }
    if ( strcmp(filename, "..") == 0  ) { continue; }
    if ( strcmp(filename, ".") == 0  ) { continue; }
    int len = strlen(filename);
    if ( len >= MAX_LEN_FILE_NAME ) {
      // This is clearly no good 
      fprintf(stdout, "%s\n", filename);
    }
    else {
      Ynum_files++;
      fwrite(filename, sizeof(char), len, ofp);
      for ( int i = len; i < MAX_LEN_FILE_NAME+1; i++ ) { 
        fwrite(&nullc, sizeof(char), 1, ofp);
      }
    }
  }
  fclose_if_non_null(ofp);
  (void) closedir (dp);
  if ( Ynum_files > 0 ) { 
    status = rs_mmap(Yopfile, &Y, &nY, 1);
    qsort(Y, Ynum_files, MAX_LEN_FILE_NAME+1, str_compare);
  }
  /* Now compare X against Y */
  char *xptr = X;
  char *yptr = Y;
  int seenX = 0, seenY = 0;
  for ( ; ( ( seenX < Xnum_files ) && ( seenY < Ynum_files ) ) ; ) {
    int cmpval = str_compare(xptr, yptr);
    switch ( cmpval ) { 
      case 0 : 
      /* File in meta data exists on disk. This is good */
      xptr += MAX_LEN_FILE_NAME+1;
      yptr += MAX_LEN_FILE_NAME+1;
      seenX++;
      seenY++;
      break;
      case -1 : 
      /* File exists in meta data but not on disk. This is horrendous */
      printf("HORRENDOUS %s\n", yptr);
      xptr += MAX_LEN_FILE_NAME+1;
      seenX++;

      break;
      case 1 : 
      /* File on disk but not in meta data. This is an "orphan" * */
      printf("%s\n", yptr);
      yptr += MAX_LEN_FILE_NAME+1;
      seenY++;
      break;
      default : 
      go_BYE(-1);
      break;
    }
  }
  if ( seenX < Xnum_files ) {
    for ( ; seenX < Xnum_files ; seenX++ ) {
      fprintf(stderr, "MISSING FILE %s\n", xptr);
      xptr += MAX_LEN_FILE_NAME;
      seenX++;
    }
  }
  if ( seenY < Ynum_files ) {
    for ( ; seenY < Ynum_files ; seenY++ ) {
      fprintf(stderr, "%s\n", yptr);
      yptr += MAX_LEN_FILE_NAME;
      seenY++;
    }
  }


BYE:
  fclose_if_non_null(ofp);
  unlink_if_non_null(Xopfile); 
  unlink_if_non_null(Yopfile);
  return(status);
}
Exemple #30
0
FLSC dic_frounze(char *token)
{
    int i, j, k, l; /* temp variables      */

#if 0 /* F48 assembly works so these codes can be removed */
    if (str_compare(token,"int21h")==0) {
        /* [--] call int 21h, like int86 but for PMode it doesn't load segment registers  */
        asm Global int21h
        asm int21h:
        asm        int     21h
        return OK;
    }
    if (str_compare(token,"int20h")==0) {
        /* [--] call int 20n, like int86 but for PMode it doesn't load segment registers  */
        asm Global int20h
        asm int20h:
        asm        int     20h
        return OK;
    }
    
    if (str_compare(token,"&isr_00_wrapper")==0) {
        /* [ -- offset] Get ISR entry offset addresses       */
        asm        .386p
        asm        push    OFFSET isr_00_wrapper
        asm        call    near ptr _push
        asm        pop     cx
        return OK;
    }
    if (str_compare(token,"&isr_01_wrapper")==0) {
        /* [ -- offset] Get ISR entry offset addresses    
            Now we have 00 and 01, we know all of them by calculation.
            &isr_n = (&isr_01 - &isr_00)*n + &isr_00  
        */
        asm        push    OFFSET isr_01_wrapper
        asm        call    near ptr _push
        asm        pop     cx
        return OK;
    }                          
    if (str_compare(token,"&exc_handler")==0) {
        asm        push    OFFSET _exc_handler
        asm        call    near ptr _push
        asm        pop     cx
        return OK;
    }
#endif 

    if (str_compare(token,"&isr_wrapper_table")==0) {
        /* [ -- address] Store all isr wrappers' entry point to the given table */
        asm        .386p
        asm        push    OFFSET isr_wrapper_table
        asm        call    near ptr _push
        asm        pop     cx
        return OK;
    }                          
    if (str_compare(token,"&exc_has_error")==0) {
        asm        push    OFFSET exc_has_error
        asm        call    near ptr _push
        asm        pop     cx
        return OK;
    }

    return FAIL; /* Unknown word */
}