Example #1
0
GraphicLSystem::GraphicLSystem()
  : LSystem(), cursor(), graphicInformationForSymbols(0)
{
  graphicInformationForSymbols = new std::map<Symbol*, GraphicInformation*>;

  /* Symbols:
   *  [ - push current position
   *  ] - pop current position
   *  . - draw point
   *  _ - draw line forward FIXME of what length?
   */
  setAlphabet("[]._");

  // FIXME set axiom and copy it to producedString
  setAxiom(".");
}
int main(int argc, char *argv[]) {
    int opt; // Return value from getopt_lonn
    // structure used for getopt_long
    static struct option long_options[] = {
        {"all-uppercase",       no_argument, NULL, 'A'},
        {"all-lowercase",       no_argument, NULL, 'L'},
        {"first-capital",       no_argument, NULL, 'F'},
        {"follow-input",  optional_argument, NULL, 'f'},
        {"number-format", optional_argument, NULL, 'n'},
        {"alphabet",      required_argument, NULL, 'a'}
    };

    while((opt = getopt_long(argc, argv, "ALFf::n::a:", long_options, NULL)) != EOF) {
        switch(opt) {
            case 'A': universalFormat = CAPS;
                break;
            case 'L': universalFormat = LOWER;
                break;
            case 'F': universalFormat = FIRST;
                break;
            case 'f': setFollowFormat(optarg);
                break;
            case 'n': setNumberFormat(optarg);
                break;
            case 'a': setAlphabet(optarg);
                break;
            default: printf("%s\n", usage);
                exit(ERROR_THROWN);
                break;
        }
    }

    if(isDefaultAlpha) {
        int i;
        for(i = 0; i < MAX_DICT; i++) {
            Alphabet[i] = NPAlpha[i];
        }
    }

    takeInputLine();

    return ERROR_FREE;
}
Example #3
0
ESA build_ESA(char *pStr, int size, char *pAlphabet, char *pIgnore, int free_pStr) {

        // Check if the string includes a zero termination
        if(pStr[size] != '\0') {
	   setError("The string MUST include a zero termination within the size\n");
	   if(free_pStr)
	     free(pStr);
	   return NULL;
	}

	initTimer();

	int overshoot;
	ESA esa = malloc(sizeof(*esa));
	if(!esa)
	{
		setError("Couldn't allocate memory for ESA.\n");
		if(free_pStr)
		{
			free(pStr);
			freeTimer();
		}
	  	return NULL;
	}
	unsigned char *text;
	int n = size + 1; // Include the zeroterninatin in the string

	// Calculate the overshoot
	overshoot=init_ds_ssort(500,2000);	

	text = malloc((n + overshoot)*sizeof *text);	
	if(!text)
	{
		setError("Couldn't allocate memory for translated text.\n");
		free(esa);
		if(free_pStr)
		{
			free(pStr);
			freeTimer();
		}
		return NULL;
	}


	// Translate the text and stop if it fails
	if(! translate(text, pStr, n-1, pAlphabet, pIgnore) ) {
	  free(text);
	  free(esa);
	  if(free_pStr)
	    free(pStr);
	  freeTimer();
	  return NULL;
	}

	// Free pStr if possible
	if(free_pStr)
	  free(pStr);

	// Save the text, alphabet and size in the esa structure
	setStr(esa, text);
	setSize(esa, n);
	setAlphabetSize(esa, strlen(pAlphabet));
	setIgnoreAlphabetSize(esa, strlen(pIgnore));
	setAlphabet(esa, pAlphabet);
	setIgnoreAlphabet(esa, pIgnore);
	
	addTimer("Initializing");
	
	// Do the sorting, calc. lcp and calc. skip
	esa->suf = malloc(sizeof(int) * n);
	if(!esa->suf)
	{
		free(text);
		free(esa);
		freeTimer();
		setError("Couldn't allocate memory for suffix column in suffix array.\n");
		return NULL;
	}

	ds_ssort(esa->pStr, esa->suf, n, MAXPSSMSIZE);
	addTimer("DS-Sort");
	
	esa->lcp = malloc(sizeof(unsigned char) * n);	
	if(!esa->lcp)
	{
		setError("Couldn't allocate memory for LCP column in suffix array.\n");				
		free(esa->suf);
		free(text);
		free(esa);
		freeTimer();
		return NULL;
	}
	
	calcLcpNaiv(esa);
	addTimer("Calc Lcp");
	
	// The line below can be commented in to verify that there are "errors" in the suffix array
	// it will scan the array for errors and report the minimum depth at which an error was found
	// the last parameter specifies the max depth to search to).
	// As a side effect it calculates lcp (when used for this purpose the depth parameter should equa
	// that used when calling ds_ssort).
	// verifyNaively(esa, n, MAX_DEPTH);

	esa->skip = malloc(sizeof(int) * n);	
	if(!esa->skip)
	{
		setError("Couldn't allocate memory for SKIP column in suffix array.\n");						
		free(esa->lcp);
		free(esa->suf);
		free(text);
		free(esa);
		freeTimer();
		return NULL;		
	}
	
	if(calcSkip(esa) == 0)
	{
		free(esa->skip);
		free(esa->lcp);
		free(esa->suf);
		free(text);
		free(esa);
		freeTimer();
		return NULL;
	}
	addTimer("Calc Skip");
	printTimer();
	freeTimer();

	return esa;
}