Example #1
0
struct psfontmap *NewPSFont(struct psfontmap* copyfrom)
{
  struct psfontmap *newentry=NULL;
  if ((newentry=malloc(sizeof(struct psfontmap)))==NULL)
    Fatal("cannot malloc psfontmap space");
  if (copyfrom!=NULL) {
    newentry->line = copyfrom->line;
    newentry->tfmname = copyword(copyfrom->tfmname);
    newentry->psfile = copyword(copyfrom->psfile);
    newentry->encname = copyword(copyfrom->encname);
    newentry->encoding = copyfrom->encoding;
#ifdef HAVE_FT2
    newentry->ft_transformp = copyfrom->ft_transformp;
    newentry->subfont = copyfrom->subfont;
#endif
    newentry->end = copyfrom->end;
  } else {
    newentry->line = NULL;
    newentry->tfmname = NULL;
    newentry->psfile = NULL;
    newentry->encname = NULL;
    newentry->encoding = NULL;
#ifdef HAVE_FT2
    newentry->ft_transformp = NULL;
    newentry->subfont = NULL;
#endif
    newentry->end = NULL;
  }
  newentry->next=psfontmap;
  psfontmap=newentry;
  return(newentry);
}
Example #2
0
int
getbootline(char *kernel, char *bootstrap)
{
  	int 	rc = 1;
	char 	*ptr;
	char 	*kargs = kern_prog.args;
	char 	*bargs = boot_prog.args;

	for (;;) {
		if (com_enabled)
			flush_char();
		printf("\nboot: ");
		gets(ptr = boot_line);
		if (!*ptr)
			rc = 0;
		while (*ptr == ' ')
			ptr++;
		if (*ptr == '?') {
			usage();
			continue;
		}
#ifdef DEBUG
		if (*ptr == '~') {
			debug = !debug;
			continue;
		}
#endif
		ptr = copyword(ptr, kernel);
		while (*kargs++ = *kernel)
			kernel++;
		while (*ptr == '-') {
			if (*(ptr+1) == '-') {
				ptr += 2;
				while (*ptr == ' ')
					ptr++;
				break;
			}
			ptr = copyargs(ptr, &kargs);
		}
		kern_prog.args_size = kargs - kern_prog.args;
		ptr = copyword(ptr, bootstrap);
		while (*bargs++ = *bootstrap)
			bootstrap++;
		while (*ptr)
			ptr = copyargs(ptr, &bargs);
		boot_prog.args_size = bargs - boot_prog.args;
		return(rc);
	}
}
Example #3
0
static inline void addword(const char* s) {
    int hash_pos = hashword(s) % HASHMAP_CAPACITY;
    int i;
    int min_count;
    hashmap_element_t* backup_data;

    while(hashmap_data[hash_pos].m_count > 0 && cmpword(hashmap_data[hash_pos].m_word, s) != 0) {
        hash_pos = (hash_pos + 1) % HASHMAP_CAPACITY;
    }
    if(hashmap_data[hash_pos].m_count > 0) { /* word existed */
        hashmap_data[hash_pos].m_count += 1;
        return;
    }

    /* add a new word */
    copyword(hashmap_data[hash_pos].m_word, s);
    hashmap_size += 1;
    hashmap_data[hash_pos].m_count = 1;

    /* remove less used words when hashmap is full */
    if(hashmap_size == HASHMAP_MAXSIZE) {
        backup_data = malloc(HASHMAP_MAXSIZE * sizeof(hashmap_element_t));
        min_count = INT_MAX;

        for(i = 0; i < HASHMAP_CAPACITY; i++) {
            if(hashmap_data[i].m_count > 0) {
                if(hashmap_data[i].m_count < min_count) {
                    min_count = hashmap_data[i].m_count;
                }
                strcpy(backup_data[hashmap_size - 1].m_word, hashmap_data[i].m_word);
                backup_data[hashmap_size - 1].m_count = hashmap_data[i].m_count;
                hashmap_size -= 1;
            }
            hashmap_data[i].m_count = 0;
        }

        for(i = 0; i < HASHMAP_MAXSIZE; i++) {
            if(backup_data[i].m_count > min_count + 5) { /* regard words with (count <= min_count + 5) as "less used" */
                hash_pos = hashword(backup_data[i].m_word) % HASHMAP_CAPACITY;

                while(hashmap_data[hash_pos].m_count > 0 && cmpword(hashmap_data[hash_pos].m_word, backup_data[i].m_word) != 0) {
                    hash_pos = (hash_pos + 1) % HASHMAP_CAPACITY;
                }
                strcpy(hashmap_data[hash_pos].m_word, backup_data[i].m_word);
                hashmap_data[hash_pos].m_count = backup_data[i].m_count;
                hashmap_size += 1;
            }
        }
        free(backup_data);
    }
    return;
}
Example #4
0
int readGrades(char* filename, long** grades, long hwsPerLine) {
	// open file for reading
	FILE* f = fopen(filename, "r");
	if(f == NULL) {
		perror("input file");
		return 0;
	}

	// create buffer to hold line
	size_t buffsize = 128;
	char* linebuffer = malloc(buffsize);	// will temporarily hold lines from file
	char numberBuffer[4];			// will be used to iterate through each grade

	// iterate through array to add grades line by line
	int i;
	for(i = 0; i < NUM_STUDENTS; ++i) {
		size_t linesize = getline(&linebuffer, &buffsize, f);

		char* it = linebuffer;
		int gradeNum;
		for(gradeNum = 0; gradeNum < hwsPerLine; ++gradeNum) {
			// ignore whitespace
			while (*it == ' ' || *it == '\t') ++it;
			// retrieve next word
			int numDigits = copyword(numberBuffer, it);
			// convert to 
			long numberRead = strtol(numberBuffer, NULL, 10);
			grades[i][gradeNum] = numberRead;
			// move it forward by the length of the last word
			it += numDigits;
		}
	}
	// done reading from file
	free(linebuffer);	// free buffer that was used to hold each line
	fclose(f);		// close file

	return 1;
}
Example #5
0
void dicpick(FILE* fp, data_block_t* dic_block) {
    static unsigned char words[2][FDATA_BLOCK / WORD_MINLEN][WORD_MAXLEN + 2];
    static unsigned char fdata[FDATA_BLOCK];
    int nwords = 0;
    int flen;
    int x;
    int y;
    int p;
    int short_word = 0;
    uint8_t accept_suffixes[256] = {0};

    pthread_t thread;
    addword_thread_param_pack_t args;
    int k = 0;

    accept_suffixes[' '] = 1;
    accept_suffixes[','] = 1;
    accept_suffixes['.'] = 1;
    accept_suffixes[':'] = 1;
    accept_suffixes[';'] = 1;

    /* for first join */
    args.m_nwords = 0;
    args.m_words = NULL;
    pthread_create(&thread, NULL, (void*)addword_thread, &args);

    /* split words */
    while((flen = fread(fdata, 1, sizeof(fdata), fp)) > 0) {
        fdata[flen - 1] = 0;
        x = 1;
        nwords = 0;

        while(x < flen) {
            if(isalpha(fdata[x]) && !isalpha(fdata[x - 1])) {
                y = x + 1;
                while(y < flen && islower(fdata[y])) {
                    y++;
                }

                if(y >= x + WORD_MINLEN && y <= x + WORD_MAXLEN && accept_suffixes[fdata[y]]) {
                    copyword((char*)words[k][nwords++], (char*)fdata + x);
                }
                x = y;
            }
            x++;
        }
        pthread_join(thread, NULL); /* wait previous pass */
        args.m_words = words[k];
        args.m_nwords = nwords;
        pthread_create(&thread, NULL, (void*)addword_thread, &args);
        k = !k;
    }
    pthread_join(thread, NULL);

    /* sort words by count */
    y = 0;
    for(x = 0; x < HASHMAP_CAPACITY; x++) {
        if(hashmap_data[x].m_count > WORD_MIN_FREQ) { /* ignore "less used" words */
            copyword(hashmap_data[y].m_word, hashmap_data[x].m_word);
            hashmap_data[y].m_count = hashmap_data[x].m_count;
            y++;
        }
    }
    qsort(hashmap_data, y, sizeof(hashmap_element_t), hashmap_element_reverse_cmp_by_count);

    /* sort level-2 words by name */
    if(y > TOTAL_WORD_NUM - reserved_wordnum) {
        y = TOTAL_WORD_NUM - reserved_wordnum;
    }
    if(y > LEVEL1_WORD_NUM(y) - reserved_wordnum) {
        x = LEVEL1_WORD_NUM(y) - reserved_wordnum;
        qsort(hashmap_data + x, y - x, sizeof(hashmap_element_t), hashmap_element_cmp_by_words);
    }

    /* output */
    data_block_reserve(dic_block, (hashmap_size + reserved_wordnum) * (WORD_MAXLEN + 3));
    for(x = 0; x < reserved_wordnum; x++) {
        for(p = 0; reserved_words[x][p] != 0; p++) {
            data_block_add(dic_block, reserved_words[x][p]);
        }
        data_block_add(dic_block, '\n');
    }

    for(x = 0; x < y; x++) {
        if(x < LEVEL1_WORD_NUM(y) || strlen(hashmap_data[x].m_word) >= WORD_MINLEN + 1) { /* ignore too short words */
            for(p = 0; hashmap_data[x].m_word[p] != 0; p++) {
                data_block_add(dic_block, hashmap_data[x].m_word[p]);
            }
            data_block_add(dic_block, '\n');
        } else {
            short_word += 1;
        }
    }
    data_block_add(dic_block, 0);
    return;
}
Example #6
0
static void ReadPSFontMap(struct psfontmap *entry)
{
  char *pos,*end,*psname;
  int nameno = 0;

  DEBUG_PRINT(DEBUG_FT,("\n  PSFONTMAP: %s ",entry->tfmname));
  pos=entry->line;
  end=entry->end;
  while(pos < end) {
    if (*pos=='<') {                               /* filename follows */
      pos++;
      if (pos<end && *pos=='<') {           /* <<download.font */
	pos++;
	entry->psfile = newword((char**)&pos,end);
	DEBUG_PRINT(DEBUG_FT,("<%s ",entry->psfile));
      } else if (pos<end && *pos=='[') {    /* <[encoding.file */
	pos++;
	entry->encname = newword((char**)&pos,end);
	DEBUG_PRINT(DEBUG_FT,("<[%s ",entry->encname));
      } else {                                     /* <some.file      */
	char* word =newword((char**)&pos,end);
	if (strncmp(word+strlen(word)-4,".enc",4)==0) {/* <some.enc */
	  entry->encname=word;
	  DEBUG_PRINT(DEBUG_FT,("<[%s ",entry->encname));
	} else {                                   /* <font    */
	  entry->psfile=word;
	  DEBUG_PRINT(DEBUG_FT,("<%s ",entry->psfile));
	}
      }
    } else if (*pos=='"') { /* PS code: reencoding/tranformation exists */
      char *word;
      double cxx=1.0,cxy=0.0;
      pos++;
      DEBUG_PRINT(DEBUG_FT,("\""));
      while(pos < end && *pos!='"') {
	word=newword((char**)&pos,end);
	while(pos < end && (*pos==' ' || *pos=='\t')) pos++;
	if (pos+10<end && strncmp(pos,"ExtendFont",10)==0) {
	  cxx=strtod(word,NULL);
	  pos+=10;
	  DEBUG_PRINT(DEBUG_FT,("%f ExtendFont ",cxx));
	} else if (pos+9<end && strncmp(pos,"SlantFont",9)==0) {
	  pos+=9;
	  cxy=strtod(word,NULL);
	  DEBUG_PRINT(DEBUG_FT,("%f SlantFont ",cxy));
	} else if (pos+12<end && strncmp(pos,"ReEncodeFont",12)==0) {
	    pos+=12;
	    DEBUG_PRINT(DEBUG_FT,("%s ReEncodeFont ",word));
	} else {
	    DEBUG_PRINT(DEBUG_FT,("(?:%s) ",word));
	}
	free(word);
      }
#ifdef HAVE_FT2
      entry->ft_transformp=&(entry->ft_transform);
      entry->ft_transform.xx=(FT_Fixed)(cxx*0x10000);
      entry->ft_transform.xy=(FT_Fixed)(cxy*0x10000);
      entry->ft_transform.yx=0;
      entry->ft_transform.yy=0x10000;
#endif
      DEBUG_PRINT(DEBUG_FT,("\" "));
      pos++;
    } else {                                      /* bare word */
      switch (++nameno) {
      case 1: /* first word is tfmname and perhaps psname, NOT psfile */
	while(pos<end && *pos!=' ' && *pos!='\t') pos++;
	psname=entry->tfmname;
	break;
      case 2:                    /* second word is psname, NOT psfile */
	psname = newword((char**)&pos,end);
	DEBUG_PRINT(DEBUG_FT,("(%s) ",psname));
	free(psname);
	break;
      case 3:                             /* third word is encoding */
	entry->encname = newword((char**)&pos,end);
	DEBUG_PRINT(DEBUG_FT,("<[%s ",entry->encname));
	break;
      default:
	while(pos<end && *pos!=' ' && *pos!='\t') pos++;
	Warning("more than three bare words in font map entry");
      }
    }
    while(pos < end && (*pos==' ' || *pos=='\t')) pos++;
  }
  if (entry->psfile==NULL) {
    /* No psfile-name given, use tfmname */
    entry->psfile=copyword(entry->tfmname);
    DEBUG_PRINT(DEBUG_FT,(" <%s ",entry->psfile));
  }
  if (entry->encname!=NULL
      && (entry->encoding=FindEncoding(entry->encname))==NULL)
    Warning("unable to load font encoding '%s' for %s",
	    entry->encname,entry->tfmname);
}