示例#1
0
void read_file_word_by_word(char *filename, list_t *list) {
    check(filename != NULL,
          "Given filename was null.");
    check(list != NULL,
          "list was NULL.");
    FILE *fp1 = NULL;
    char string[500];
    char c;
    fp1 = fopen(filename, "r");
    check(fp1 != NULL,
          "Could not open file: %s.", filename);
    do {
        c = fscanf(fp1, "%s", string);
        if(c != EOF) {
            string_to_lower(string);
            if(validate_word(string) != 0) {
                char *temp_word = string;
                check(dl_insert(list, temp_word) == 1,
                      "Did not insert '%s' properly,",
                      temp_word);
            }
        }
    } while(c != EOF);

    fclose(fp1);
    return;
error:
    if(list != NULL) {
        dl_clear_destroy(list);
    }
    exit(1);
}
示例#2
0
void dl_draw_strip(dl_list_t * dl,
				   const draw_vertex_t v[256],
				   int n,
				   int flags)
{
  struct dl_draw_strip_command * c = dl_alloc(dl,
											  sizeof(*c)
											  - sizeof(c->v)
											  + n * sizeof(c->v[0]));

/*   SDDEBUG("[%s] %d %x\n", __FUNCTION__, n, flags); */

  if (c) {
	int i;
	c->n = n;
	c->flags = flags;
	for (i=0; i<n; ++i) {
	  c->v[i] = v[i];
/* 	  SDDEBUG("%02d %f %f %f %f\n\n", i, v[i].x, v[i].y, v[i].w, v[i].w); */
	}
    dl_insert(dl, c,
			  dl_draw_strip_render_opaque,
			  dl_draw_strip_render_transparent);
  }
}
示例#3
0
bool get_all_files(char *dir_path, list_t *list) {
    check(dir_path != NULL,
          "dir_path is NULL.");
    check(list != NULL,
          "list is NULL.");
    check(is_file_or_dir(dir_path) == 2,
          "dir_path '%s' is not a directory.",
          dir_path);
    DIR *dir;
    struct dirent *ent;
    check((dir = opendir(dir_path)) != NULL,
          "could not open directory: %s", dir_path);
    while((ent = readdir(dir)) != NULL) {
        char fullpath[256];
        sprintf(fullpath, "%s/%s", dir_path, ent->d_name);
        if(ent->d_type == DT_REG) {
            check(dl_insert(list, fullpath) == 1,
                  "failed to insert %s into the list",
                  fullpath);
        } else if (ent->d_type == DT_DIR
                   && strcmp(ent->d_name, ".") != 0
                   && strcmp(ent->d_name, "..") != 0) {
            get_all_files(fullpath, list);
        }
    }
    closedir(dir);
    return 1;
error:
    if(dir != NULL) {
        closedir(dir);
    }
    return 0;
}
示例#4
0
void readFILE(FILE *fp)
{
		char *x;	
		
    /* assumes no word exceeds length of 1023 */
		//printf("Contents of the file:\n");
    while (!feof(fp)) {
				x =(char *) malloc(sizeof(char)*500);
				fscanf(fp, "%s ", x);
				//printf("%s\n",x);
				if(wordfilter(x) == TRUE)
                {
       	        dl_insert(front,x);
				  // printf("SECOND CALL IN READFILE word being read in: %s\n",x);
                }
				else
				{
					free(x);
				}
	
    }

		//printf("\n");
        

}
示例#5
0
static void scrolltext(dl_list_t * dl, 
		       float x, float y, float z,
		       float a, float r, float g, float b,
		       const char * text,
		       float w, float spd, int pingpong)
{
  struct scrolltext_command * c;
  int len;

  if (!text) {
    return;
  }
  if (len = strlen(text), len < 1) {
    return;
  }
  len += sizeof(*c);
  if (c = dl_alloc(dl, len), c) {
    c->x = x;    c->y = y;    c->z = z;
    c->a = a;    c->r = r;    c->g = g;    c->b = b;
    c->len = len;
    c->window = w > 0 ? w : 640;
    c->spd = (spd != 0) ? spd : 1;
    c->pingpong = pingpong;
    strcpy(c->text, text);
    text_size_str_prop(text, &c->w, &c->h, 0, 16, 1);
    if (pingpong == 2) {
      c->xs = 0;
    } else {
      c->xs = c->spd > 0 ? c->window : -c->w;
    }
    dl_insert(dl, c, 0, scrolltext_render_transparent);
  }
}
示例#6
0
static int gc_any(lua_State * L, dl_list_t * dl,  dl_command_func_t render)
{
  struct gc_com * c;
  
  if(c = dl_alloc(dl, sizeof(*c)), !c) {
    return DL_COMID_ERROR;
  }
  c->flags = strtoflags(lua_tostring(L, 2), GC_RESTORE_ALL);
  return dl_insert(dl, c, push_render, push_render);
}
示例#7
0
static void setcolor1(dl_list_t * dl, const draw_color_t * color)
{
  struct color1_com * c;

  if(c = dl_alloc(dl, sizeof(*c)), !c) {
	return;
  }
  c->color[0] = color[0];
  dl_insert(dl, c, dl_color1_render, dl_color1_render);
}
示例#8
0
bool read_file_word_by_word(FILE *fp, list_t *list, 
		int actual_offset, int child_read_size, int size){
	check(list != NULL, 
		"list was NULL.");
	check(fp != NULL,
		"file was NULL");
	int offset = fseek(fp, actual_offset, SEEK_SET);
	check_debug(offset == 0, 
		"fseek returned non-zero.");
	if(actual_offset != 0){
		offset = fseek(fp, -1, SEEK_CUR);
		int cur_character;
		do {
			cur_character = fgetc(fp);
			if(isspace(cur_character) != 0){
				break;
			} else {
				offset = fseek(fp, -2, SEEK_CUR);
			}
		} while(isspace(cur_character) == 0
			&& cur_character != EOF
			&& offset == 0);
		actual_offset = ftell(fp);
		if((size - (actual_offset + child_read_size)) < child_read_size){
			child_read_size = size - actual_offset;
		}
	}
	int byte_count = 0;
	char string[512];
	int c;
	do {
		c = fscanf(fp, "%s", string);
		byte_count = ftell(fp) - actual_offset;
		if(byte_count < child_read_size
			|| (actual_offset + byte_count) == size){
			if(c != EOF){
				string_to_lower(string);
				if(validate_word(string) != 0){
					char *temp_word = string;
					check(dl_insert(list, temp_word) == 1,
						"Did not insert '%s' properly,",
						temp_word);
				}
			}
		} else {

		}
	} while(c != EOF && byte_count < child_read_size);
	return 1;
error:
	return 0;
}
示例#9
0
int main(int args, char *argv[])
{
    
    FILE *input = fopen(argv[1],"r");
    int num;
    char command;

    

     while(fscanf(input,"%c %d\n",&command,&num) != EOF)
    {
        
        
        if(command == 'a')
        dl_insert(front,num);
        else if(command == 'b')
        dl_del(front,num);
        else if(command == 'f')
        { 
        valueT val = dl_get_front(front);
        printf("front value:%d\n",val);
        }
        else if(command == 'g')
        {
        valueT val = dl_get_back(front);
        printf("Back value:%d\n",val);
        }
        else if(command == 'd')
        dl_pop_front(front);
        else if(command == 'e')
        dl_pop_back(front);
        else if(command == 'h')
        {
        valueT val = dl_check(front, num);
        printf("val exists:%d\n",val);
        }
        else if(command == 'j')
        {
            dl_insert_front(front,num);
        }
        else if(command == 'p')
        {
            printList();
        }
        
    }
    fclose(input);
    return 0;
}
示例#10
0
static void properties(dl_list_t * dl,
		       fontid_t fontid, const float size, const float aspect,
		       int filter)
{
  struct textprop_command * c;

  if (fontid < 0 || size <= 0) {
    return;
  }
  if (c = dl_alloc(dl, sizeof(*c)), c) {
    c->font = fontid;
    c->size = size;
    c->aspect = aspect;
    c->filter = filter;
    dl_insert(dl, c, 0, properties_render_transparent);
  }
}
示例#11
0
static void dl_insert_test(void) {
    printsln((String)__func__);
    List ac, ex;

    ac = dl_of_string("1, 2, 3, 4, 5");
    dl_insert(ac, 0, 9);
    ex = dl_of_string("9, 1, 2, 3, 4, 5");
    dl_check_within(ac, ex);
    l_free(ac);
    l_free(ex);

    ac = dl_of_string("1, 2, 3, 4, 5");
    dl_insert(ac, 5, 9);
    ex = dl_of_string("1, 2, 3, 4, 5, 9");
    dl_check_within(ac, ex);
    l_free(ac);
    l_free(ex);

    ac = dl_of_string("1, 2, 3, 4, 5");
    dl_insert(ac, 3, 9);
    ex = dl_of_string("1, 2, 3, 9, 4, 5");
    dl_check_within(ac, ex);
    l_free(ac);
    l_free(ex);

    ac = dl_of_string("1");
    dl_insert(ac, -1, 9);
    ex = dl_of_string("1");
    dl_check_within(ac, ex);
    l_free(ac);
    l_free(ex);

    ac = dl_of_string("1");
    dl_insert(ac, 1, 9);
    ex = dl_of_string("1, 9");
    dl_check_within(ac, ex);
    l_free(ac);
    l_free(ex);

    ac = dl_of_string("");
    dl_insert(ac, 0, 9);
    ex = dl_of_string("9");
    dl_check_within(ac, ex);
    l_free(ac);
    l_free(ex);
}
示例#12
0
static void text(dl_list_t * dl, 
		 float x, float y, float z,
		 float a, float r, float g, float b,
		 const char * text)
{
  struct text_command * c;
  int len;

  if (!text) {
    return;
  }
  if (len = strlen(text), len < 1) {
    return;
  }
  len += sizeof(*c);
  if (c = dl_alloc(dl, len), c) {
    c->x = x;    c->y = y;    c->z = z;
    c->a = a;    c->r = r;    c->g = g;    c->b = b;
    strcpy(c->text, text);
    /* 	SDDEBUG("[dltext: [%s]]\n",c->text); */
    dl_insert(dl, c, 0, text_render_transparent);
  }
}
示例#13
0
void autoline(char *line)
{
	char *w;
	char *seen;
	int super_cnt;
	char *dflt = auto_yes;
	int homehost = 0;
	int i;

	if (auto_seen)
		return;
	auto_seen = 1;

	/* Parse the 'auto' line creating policy statements for the 'auto' policy.
	 *
	 * The default is 'yes' but the 'auto' line might over-ride that.
	 * Words in the line are processed in order with the first
	 * match winning.
	 * word can be:
	 *   +version   - that version can be assembled
	 *   -version   - that version cannot be auto-assembled
	 *   yes or +all - any other version can be assembled
	 *   no or -all  - no other version can be assembled.
	 *   homehost   - any array associated by 'homehost' to this
	 *                host can be assembled.
	 *
	 * Thus:
	 *   +ddf -0.90 homehost -all
	 * will auto-assemble any ddf array, no 0.90 array, and
	 * any other array (imsm, 1.x) if and only if it is identified
	 * as belonging to this host.
	 *
	 * We translate that to policy by creating 'auto=yes' when we see
	 * a '+version' line, 'auto=no' if we see '-version' before 'homehost',
	 * or 'auto=homehost' if we see '-version' after 'homehost'.
	 * When we see yes, no, +all or -all we stop and any version that hasn't
	 * been seen gets an appropriate auto= entry.
	 */

	/* If environment variable MDADM_CONF_AUTO is defined, then
	 * it is prepended to the auto line.  This allow a script
	 * to easily disable some metadata types.
	 */
	w = getenv("MDADM_CONF_AUTO");
	if (w && *w) {
		char *l = xstrdup(w);
		char *head = line;
		w = strtok(l, " \t");
		while (w) {
			char *nw = dl_strdup(w);
			dl_insert(head, nw);
			head = nw;
			w = strtok(NULL, " \t");
		}
		free(l);
	}

	for (super_cnt = 0; superlist[super_cnt]; super_cnt++)
		;
	seen = xcalloc(super_cnt, 1);

	for (w = dl_next(line); w != line ; w = dl_next(w)) {
		char *val;

		if (strcasecmp(w, "yes") == 0) {
			dflt = auto_yes;
			break;
		}
		if (strcasecmp(w, "no") == 0) {
			if (homehost)
				dflt = auto_homehost;
			else
				dflt = auto_no;
			break;
		}
		if (strcasecmp(w, "homehost") == 0) {
			homehost = 1;
			continue;
		}
		if (w[0] == '+')
			val = auto_yes;
		else if (w[0] == '-') {
			if (homehost)
				val = auto_homehost;
			else
				val = auto_no;
		} else
			continue;

		if (strcasecmp(w+1, "all") == 0) {
			dflt = val;
			break;
		}
		for (i = 0; superlist[i]; i++) {
			const char *version = superlist[i]->name;
			if (strcasecmp(w+1, version) == 0)
				break;
			/* 1 matches 1.x, 0 matches 0.90 */
			if (version[1] == '.' &&
			    strlen(w+1) == 1 &&
			    w[1] == version[0])
				break;
			/* 1.anything matches 1.x */
			if (strcmp(version, "1.x") == 0 &&
			    strncmp(w+1, "1.", 2) == 0)
				break;
		}
		if (superlist[i] == NULL)
			/* ignore this word */
			continue;
		if (seen[i])
			/* already know about this metadata */
			continue;
		policy_add(rule_policy, pol_auto, val, pol_metadata, superlist[i]->name, NULL);
		seen[i] = 1;
	}
	for (i = 0; i < super_cnt; i++)
		if (!seen[i])
			policy_add(rule_policy, pol_auto, dflt, pol_metadata, superlist[i]->name, NULL);

	free(seen);
}
示例#14
0
int main(int argc, char *argv[]){
	int pid = 0;
	int i = 0;
	int child = 0;
	int status;
	
	char *first_param = "2";
	int num_children = atoi(first_param);
		
	int children[num_children];

	struct stat st;
	char *file_name = "./dllist.c";
	int size = 0;
	stat(file_name, &st);
	size = st.st_size;
	printf("file_name: %s, file_size: %d\n", file_name, size);
	FILE *fp = fopen(file_name, "r");
	int child_read_size = size / num_children;	
	int child_segment_size = 0;
	for(i = 0; i < NUM_ELEMS(children); i++){
		child_segment_size += child_read_size;
		pid = fork();
		if(pid != 0){
			children[i] = pid;
			printf("child_pid: %d\n", pid);
			waitpid(children[i], &status, 0);
		} else {
			child = 1;
			break;
		}
	}
	if(child == 0){
		printf("parent process, pid: %d\n", getpid());
	} else {
		printf("child process, pid: %d, ppid: %d\n", pid, getppid());
		printf("\tchild_start: %d, child_end: %d\n", 
			child_segment_size - child_read_size,
			child_segment_size);
		int actual_offset = child_segment_size - child_read_size;
		int offset = fseek(fp, actual_offset, SEEK_SET);
		printf("\toffset: %d\n", offset);
		int ch = 0;
		int byte_count = 0;
		char string_buffer[512];
		if(actual_offset != 0){
			int cur_character;
			do{
				cur_character = fgetc(fp);
				if(isspace(cur_character) == 0){
					offset = fseek(fp, -2, SEEK_CUR);
				} else {
					offset = fseek(fp, -1, SEEK_CUR);
				}
			} while(isspace(cur_character) == 0
				&& (cur_character != EOF
				&& offset == 0));
			printf("\t\tftell(fp): %lu\n", ftell(fp));
		}
		int word_count = 0;
		list_t *list = NULL;
		list = dl_init();
		do {		
			ch = fscanf(fp, "%s", string_buffer);
			if(actual_offset != 0 && byte_count == 0){
				printf("\t\tfirst_word: %s\n", string_buffer);
			}
			byte_count = ftell(fp) - (actual_offset);
			if(string_buffer[0] == '\0'){
				printf("\t\twhitespace_at_bytecount: %d\n", byte_count);
			}
			if(byte_count < child_read_size
				|| (actual_offset + byte_count) == size){
				if(ch != EOF){
					string_to_lower(string_buffer);
					if(validate_word(string_buffer) != 0){
						char *temp_word = string_buffer;
						check(dl_insert(list, temp_word) == 1,
							"Did not insert '%s' properly.",
							temp_word);
						word_count++;
					}
				} else {
					printf("\t\tlast_word_file: %s\n", string_buffer);
				}
			} else {
				printf("\t\tlast_word: %s\n", string_buffer);	
			}
		} while( ch != EOF && byte_count < child_read_size);
		dl_clear_destroy(list);	
		printf("\tbyte_count: %d, word_count: %d\n", byte_count, word_count);
		fclose(fp);
		exit(0);
	}
	rewind(fp);
	int temp;
	char temp_buffer[512];
	int true_wordcount = 0;
	do{
		temp = fscanf(fp, "%s", temp_buffer); 
		if(temp != EOF){
			true_wordcount++;
		}
	} while(temp != EOF);
	fclose(fp);
	printf("true_wordcount: %d\n", true_wordcount);
	return 0;
error:
	return 1;
}