Ejemplo n.º 1
0
Matrix DataCollector::readPMatrixFromText(string filename)
{
	unsigned int rows, columns;
	countLines(filename, rows, columns);
	ifstream infile; //input file stream object
	infile.open(filename);
	if (!infile) {
		cerr << "Bad input! Can't open " << filename << endl;
		exit(1);
	}
	Matrix P(rows, columns);
	unsigned int i = 0;
	unsigned int j = 0;
	string line;
	string token;
	while (!infile.eof())
	{
		getline(infile, line, '\n');
		stringstream ss(line);
		j = 0;
		while (getline(ss, token, ','))
		{
			P(i, j) = stod(token);
			j++;
			//cout << price << "\t";
		}
		i++;
	}
	return P;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: codlab/ftpony
void drawFrame()
{
	u8* bufAdr=gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);

	int i, j;
	for(i=1;i<400;i++)
	{
		for(j=1;j<240;j++)
		{
			u32 v=(j+i*240)*3;
			bufAdr[v]=(pcCos(i+cnt)+4096)/32;
			bufAdr[v+1]=(pcCos(j-256+cnt)+4096)/64;
			bufAdr[v+2]=(pcCos(i+128-cnt)+4096)/32;
		}
	}
	gfxDrawText(GFX_TOP, GFX_LEFT, NULL, "ftPONY v0.0003 gamma\n", 240-fontDefault.height*1, 10);
	u32 ip = gethostid();
	char bof[256];
	sprintf(bof, "IP: %lu.%lu.%lu.%lu\n", ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF);
	gfxDrawText(GFX_TOP, GFX_LEFT, NULL, bof, 240-fontDefault.height*2, 10);

	gfxDrawText(GFX_TOP, GFX_LEFT, NULL, quotes[curQuote], 240-fontDefault.height*3, 10);
	i = countLines(superStr);
	while(i>240/fontDefault.height-3){cutLine(superStr);i--;}
	gfxDrawText(GFX_TOP, GFX_LEFT, NULL, superStr, 240-fontDefault.height*4, 20);
	cnt++;

	gfxFlushBuffers();
	gfxSwapBuffers();
}
Ejemplo n.º 3
0
// Create a graph from an input file. The format for the input file is specified
// in the graph.h header file
Graph* createGraph(FILE *inputFile)
{
  Graph *g = myMalloc(sizeof(Graph));
  g->numVertices = countLines(inputFile);
  g->numEdges = (countNumWords(inputFile)-(g->numVertices))/2;
  // init vertices
  g->vertices = myMalloc(sizeof(Vertex) * g->numVertices);
  for(int i = 0; i < g->numVertices; i++){
    Vertex *vp = g->vertices+i;
    vp->label = i+1;
    vp->head = NULL;
    vp->tail = NULL;
  }
  // init edges
  g->edges = myMalloc(sizeof(Edge) * g->numEdges);
  for(int i = 0; i < g->numEdges; i++){
    Edge *ep = g->edges+i;
    ep->endpoint1 = NULL;
    ep->endpoint2 = NULL;
  }
  //init connector elements
  g->connectors = myMalloc(sizeof(ConnectorElement) * g->numEdges * 2);
  for(int i = 0; i < g->numEdges*2; i++){
    ConnectorElement *connector = g->connectors+i;
    connector->adjacentEdge=NULL;
    connector->sourceVertex=NULL;
    connector->prev=NULL;
    connector->next=NULL;
  }
  hookupGraph(g, inputFile);
  rewind(inputFile);

  return g;
}
Ejemplo n.º 4
0
void Analysis::analysis(const char* testFile, const char* compareFile)
{
	int n = countLines(testFile);
	bool* abandon = new bool[n];
	

	ifstream in(testFile, ios::in);
	int number;
	int i = 0;
	while(!in.eof() && i < n)
	{
		in >> number;
		//printf("number: %d\n", number);
		if(number == 0)
			abandon[i] = false;
		else
			abandon[i] = true;
		i++;
		//if(i >= 7200)
			//printf("%d\n", i);
	}
	in.close();
	
	n = i;
	compare(compareFile, abandon, n);
}
Ejemplo n.º 5
0
/* kill all processes other than the given pid that have the given processName */
void killOtherProcessesWithName(pid_t pid, char* processName) {
        /* get the user running the parent process */
        char* userName = calloc(MAX_USERNAME_LENGTH + 1, sizeof(char));
        getUserNameForPid(pid, userName);

        /* build the command */
        char* command = calloc(55 + strlen(processName) + strlen(userName),
                        sizeof(char));
        sprintf(command,
                        "ps aux | grep %s | grep -v gdb | grep -v grep | grep %s",
                        processName, userName);

        /* get the number of processes */
        int numPids = countLines(command);

        /* get the pids */
        int pids[numPids];
        getPids(command, pids);

        /* for each process pid, if it's not yours, kill it */
        int index;
        for (index = 0; index < numPids; index++) {
                int otherpid = pids[index];
                if (otherpid != pid) {
                        /* printf("Killing procnanny  process found with pid %d\n",otherpid); */
                        if (kill(otherpid, 9) == -1) {
                                printMessageandExit("Kill error\n", EXIT_FAILURE);
                        }
                }
        }

        // clean up
        free(command);
        free(userName);
}
Ejemplo n.º 6
0
/*	================== buildHead =================
 This function creates the header structure that
 contains pointers to the tree and the hash table.
 It also calls other functions to read in the data
 file.
 Pre		pHeader - pointer to HEAD structure
 fileInput - name of the file
 Post		both the tree and the hash table are
 created.
 Return	pointer to create HEAD structure
 */
HEAD* buildHead (HEAD* pHeader, char* fileInput)
{
	//	Local Declarations
	DATA* newAirport;
    FILE* fpIn;
    
	//	Statements
    fpIn = fopen(fileInput, "r");
    if (!fpIn) {
        printf("Error opening input file\n");
        exit(101);
    }
    
    if ((pHeader = (HEAD*) malloc(sizeof(HEAD))))
    {
        pHeader->pHash = buildHash(2 * countLines(fileInput));
        pHeader->pTree = BST_Create(compareCode);
    }
    else{
        printf("Memory allocation error\n");
        exit(100);
    }
    
    while (getData(pHeader->pTree, fpIn, &newAirport)) {
        BST_Insert(pHeader->pTree, newAirport);
        insertHash(pHeader->pHash, newAirport);
    }
    
    return pHeader;
}	// buildHead
Ejemplo n.º 7
0
void OMXPlayerPlaylist::createPlaylist ()
{
   ifstream playlistFile;
   string line;
   int i;

   playlistLength = countLines ();

   playlistEntries = new OMXPlayerPlaylistEntry [ playlistLength ];

   playlistFile.open ( playlistPath.c_str () );

   if ( playlistFile.is_open() )
   {
      i = 0;
      while ( getline ( playlistFile, line ) )
      {
         // cout << line << '\n';
         // playlistEntries [ i ] = OMXPlayerPlaylistEntry ();
         createPlaylistEntry ( line, i );
         i++;
      }
      playlistFile.close();
   }
   else
   {
      cout << "Unable to open file";
   }
}
Ejemplo n.º 8
0
FileEditor* openFile(gchar* gfilename){
	char* filename = (char*)gfilename;
	FILE* file = fopen(filename, "r");
	FileEditor* edit = malloc(sizeof(FileEditor));
	
	if(file){
		edit->nLine = countLines(file);
		rewind(file);
		
		edit->content = (char**) malloc(sizeof(char*) * edit->nLine);
		for(int i = 0;i < edit->nLine ;i++){
			char *line = (char*) malloc(sizeof(char) * 100);
			 fgets(line,100,file);
			 //printf("line #%d: %s",i,line);
			 edit->content[i] = line;
		}
		rewind(file);
		
		printf("This file has %d lines\n",edit->nLine);
		fclose(file);
	} else{
		printf("Error while opening the file\n");
	}
	return edit;
}
int main()
{
    FILE * fin = NULL;
    int ** temps = NULL;
    int choice, total = 0;

    fin = openFilePrompt();

    total = countLines(fin);

    temps = fillArray(total, fin);

    do
    {
        choice = menu();

        if(choice == 1)
            displayMonthData(total, temps);

        else if(choice == 2)
            displayYearData(total, temps);

        else if(choice == 3)
            temps = addMoreTemps(temps, &total);

    }while (choice != 4);

    cleanUp(total, temps);

    return 0;
}// end main
Ejemplo n.º 10
0
// opens the file and stores the strings
//
//	input:		string of passenger data
//				container to store strings
//
int processFile( container* cp, char* fn )
{
	char line[80];
	FILE* in = fopen( fn,"r" );
	int count = 0;
	if ( in != NULL )
	{
		cp->rows = countLines(in);
		cp->strings = (char**)malloc(sizeof(char*)*cp->rows);
		while ( !feof(in) )
		{
			if ( fgets( line, 80, in ) )
			{
				cp->strings[count] = (char*)malloc(sizeof(char)*strlen(line)+1);
				strcpy(cp->strings[count],line);
				count++;
			}
		}
	}
	else
	{
		printf("Unable to open file %s\n",fn);
		exit(0);
	}
	fclose(in);
	return count;
}
Ejemplo n.º 11
0
void parse(const char *filename)
{
    char * line = NULL;
    char * token;
    size_t len = 0;
    int read_len = 0;
    int i=0;

    // open config file for reading
    FILE *conf_file = fopen(filename, "r");
    if (conf_file == NULL)
        fprintf(stderr, "Unable to open given file");

    // get number of users
    userNum = countLines(filename);

    users = malloc(userNum * sizeof(user));

    // for each line in config, add new user struct
    while((read_len = getline(&line, &len, conf_file)) != -1) {
        token = strtok(line, " ");
        strcpy(users[i].name, token);

        token = strtok(NULL, " ");
        strcpy(users[i].password,token);
        i++;
    }
    fclose(conf_file);
}
Ejemplo n.º 12
0
static void processFile(Regex* re, SearchOutput* output, OrderedOutput::Chunk* chunk, HighlightBuffer& hlbuf,
	const char* path, size_t pathLength, const char* data, size_t size, unsigned int startLine)
{
	const char* range = re->rangePrepare(data, size);

	const char* begin = range;
	const char* end = begin + size;

	unsigned int line = startLine;

	while (RegexMatch match = re->rangeSearch(begin, end - begin))
	{
		// discard zero-length matches at the end (.* results in an extra line for every file part otherwise)
		if (match.data == end) break;

		// update line counter
		line += 1 + countLines(begin, match.data);
		
		// print match
		const char* lbeg = findLineStart(begin, match.data);
		const char* lend = findLineEnd(match.data + match.size, end);
		processMatch(re, output, chunk, hlbuf, path, pathLength, (lbeg - range) + data, lend - lbeg, line, lbeg, match.data - lbeg, match.size);
		
		// move to next line
		if (lend == end) break;
		begin = lend + 1;
	}

	re->rangeFinalize(range);
}
Ejemplo n.º 13
0
static void showText(WScreen *scr, int x, int y, int h, int w, const char *text)
{
	int width;
	int height;
	Pixmap pixmap;
	Pixmap mask;
	WMFont *font = scr->info_text_font;
	int side = 0;
	int ty;
	int bx, by;

	if (scr->balloon->contents)
		XFreePixmap(dpy, scr->balloon->contents);

	width = getMaxStringWidth(font, text) + 16;
	height = countLines(text) * WMFontHeight(font) + 4;

	if (height < 16)
		height = 16;
	if (width < height)
		width = height;

	if (x + width > scr->scr_width) {
		side = RIGHT;
		bx = x - width + w / 2;
		if (bx < 0)
			bx = 0;
	} else {
		side = LEFT;
		bx = x + w / 2;
	}
	if (bx + width > scr->scr_width)
		bx = scr->scr_width - width;

	if (y - (height + SPACE) < 0) {
		side |= TOP;
		by = y + h - 1;
		ty = SPACE;
	} else {
		side |= BOTTOM;
		by = y - (height + SPACE);
		ty = 0;
	}
	pixmap = makePixmap(scr, width, height, side, &mask);

	drawMultiLineString(scr->wmscreen, pixmap, scr->black, font, 8, ty + 2, text, strlen(text));

	XSetWindowBackgroundPixmap(dpy, scr->balloon->window, pixmap);
	scr->balloon->contents = pixmap;

	XResizeWindow(dpy, scr->balloon->window, width, height + SPACE);
	XShapeCombineMask(dpy, scr->balloon->window, ShapeBounding, 0, 0, mask, ShapeSet);
	XFreePixmap(dpy, mask);
	XMoveWindow(dpy, scr->balloon->window, bx, by);
	XMapRaised(dpy, scr->balloon->window);

	scr->balloon->mapped = 1;
}
void main(int argc, char *argv[])
{

	/*file pointers*/ 
	FILE * fp_sc = NULL;
	FILE * fp_dict = NULL;


	/*check argument count*/
	if (argc != 3) {
		printf("Usage : source_file dict_file\n");
		printf("ERROR - wrong amount of arguments!\n");
		return WRONG_ARGUMENTS;
	}

	fp_sc = fopen(argv[1], "r+");
	if (fp_sc == NULL) {
		printf("ERROR - cannot open source file at %s.\n", argv[1]);
		return CANNOT_OPEN_SOURCE_FILE;
	}
	/* we dont need anything more than read*/
	fp_dict = fopen(argv[2], "r"); 
	if (fp_dict == NULL) {
		fclose(fp_sc);
		printf("ERROR - cannot open dictionary file at %s.\n", argv[3]);
		return CANNOT_OPEN_DICTIONARY_FILE;
	}

	/*dictionary format is  :
	<word> : <synonim>*/
	word_amount = countLines(fp_dict);
	size_t allocation_size = sizeof(char) * WORD_SIZE * word_amount;
	/* the word search array will contain all the words that we found in the dict file*/
	char *word_search_array = malloc(allocation_size);
	/*incase we loose the mem location , we need to free it in the end*/
	const char *word_search_start = word_search_array;

	/*init the word search array*/
	if (inint_word_search_array(fp_dict, word_search_start) == ERROR_BAD_FORMAT) {
		return ERROR_BAD_FORMAT;
	}

	char *after_replace = NULL;
	fseek(fp_sc, 0, SEEK_SET);
	printf("Starting to replace words\n".);
	replace_words(fp_sc, fp_dict, word_search_array, &after_replace);
	printf("Finished replacing words\n.");
	freopen(argv[1], "w", fp_sc);
	fputs(after_replace, fp_sc);
	/*free our allocated memory*/
	printf("Finished copying the data to the file.\nFreeing the memory and files.");
    free(after_replace);
	free(word_search_start);
	fclose(fp_dict);
	fclose(fp_sc);
}
Ejemplo n.º 15
0
TreeNode *buildTreeFromFile(FILE *fp)
{
  int numWords = countLines(fp);
  char **lexiconArray = buildArrayFromFile(fp, numWords);

  TreeNode *root = initNodeWithValue(lexiconArray[numWords/2], 0);
  buildTreeFromArray(lexiconArray, numWords/2, root, 1);
  buildTreeFromArray(lexiconArray+numWords/2+1, numWords - numWords/2 - 1, root, 1);

  return root;
}
void TEditor::setSelect( ushort newStart, ushort newEnd, Boolean curStart )
{
    ushort p;
    if( curStart != 0 )
        p = newStart;
    else
        p = newEnd;

    uchar flags = ufUpdate;

    if( newStart != selStart || newEnd != selEnd )
        if( newStart != newEnd || selStart != selEnd )
            flags = ufView;

    if( p != curPtr )
        {
        if( p > curPtr )
            {
            ushort l = p - curPtr;
            memmove( &buffer[curPtr], &buffer[curPtr + gapLen], l);
            curPos.y += countLines(&buffer[curPtr], l);
            curPtr = p;
            }
        else
            {
            ushort l = curPtr - p;
            curPtr = p;
            curPos.y -= countLines(&buffer[curPtr], l);
            memmove( &buffer[curPtr + gapLen], &buffer[curPtr], l);
            }
        drawLine = curPos.y;
        drawPtr = lineStart(p);
        curPos.x = charPos(drawPtr, p);
        delCount = 0;
        insCount = 0;
        setBufSize(bufLen);
    }
    selStart = newStart;
    selEnd = newEnd;
    update(flags);
}
struct ctgInfo *getCtgInfo(char *ooDir, char *chrom, char *contig)
/* Get contig info on dir. */
{
struct ctgInfo *ci;
char fileName[512];
AllocVar(ci);
ci->chrom = chrom;
ci->contig = contig;
sprintf(fileName, "%s/%s/%s/%s", ooDir, chrom, contig, "geno.lst");
ci->cloneCount = countLines(fileName);
return ci;
}
Ejemplo n.º 18
0
//Ham doc du lieu tu file test
void readTestData(Rating **B, int *len, char* filename)
{  
    int nRating = countLines(filename);
    Rating *T = calloc(nRating, sizeof(Rating));

    FILE *fp = fopen(filename, "r");
    if (fp == NULL)
    {
	perror("fopen() in readTestData()");
	exit(1);
    }

    int uID, mID, j=0;
    long t;
    float rate;
    int mIndex;

    if (dataFormat == ML100K)
	for (int i=0; i<nRating; i++)
	{
	    fscanf(fp, "%d%d%f%ld", &uID, &mID, &rate, &t);
	    mIndex = indexOfMovieID(mID);
	
	    if (mIndex < nMovies && mIndex >= 0 && uID <= nUsers)
	    {
		T[j].uID = uID-1;
		T[j].mID = mIndex;
		T[j].R = rate;
		j++;
	    }
	}
    else if (dataFormat == ML10M)
    	for (int i=0; i<nRating; i++)
	{
	    fscanf(fp, "%d::%d::%f::%ld", &uID, &mID, &rate, &t);
	    mIndex = indexOfMovieID(mID);
	
	    if (mIndex < nMovies && mIndex >= 0&& uID <= nUsers)
	    {
		T[j].uID = uID-1;
		T[j].mID = mIndex;
		T[j].R = rate;
		j++;
	    }
	}
    
    
    *B = T;
    *len = j; //Vi chi xet nhung phan tu hop le

    fclose(fp);
}
Ejemplo n.º 19
0
//Ham danh chi so movie
void indexMovie()
{
    nMovies = countLines(moviesData);
    MI = calloc(nMovies, sizeof(int));

    FILE *fp = fopen(moviesData, "r");
    char buf[1024];
    for (int i=0; i<nMovies; i++)
    {
	fgets(buf, 1024, fp);
	sscanf(buf, "%d", &MI[i]);
    }
    fclose(fp);
}
Ejemplo n.º 20
0
//Ham doc du lieu tu file training
void readData(float ***outArr, int nMovies, int nUsers, char* filename)
{
    nMovies = countLines(moviesData);

    MI = calloc(nMovies, sizeof(int));

    FILE *fp = fopen(moviesData, "r");
    char buf[1024];
    for (int i=0; i<nMovies; i++)
    {
	fgets(buf, 1024, fp);
	sscanf(buf, "%d", &MI[i]);
    }
    fclose(fp);

    
    fp = fopen(filename, "r");
    if (fp == NULL)
    {
	perror("fopen()");
	exit(1);
    }

    float **A;
    A = calloc(nMovies, sizeof(float*));
    for (int i=0; i<nMovies; i++)
	A[i] = calloc(nUsers, sizeof(float));

    int uID, mID;
    long t;
    float rate;
    int mIndex;

    //   FILE *fp1 = fopen(moviesData, "r");
    //fclose(fp1);
 
    while (!feof(fp))
    {
	
	if (dataFormat == ML100K)
	    fscanf(fp, "%d%d%f%ld", &uID, &mID, &rate, &t);
	else if (dataFormat == ML10M)
	    fscanf(fp, "%d::%d::%f::%ld", &uID, &mID, &rate, &t);
	mIndex = indexOfMovieID(mID);
	if (mIndex < nMovies && uID <= nUsers)
	    A[mIndex][uID-1] = rate;
    }
    
    *outArr = A;
}
Ejemplo n.º 21
0
int main (int argc, char* argv[])
{
    int count;

    if (argc == 1) {
       // no argument => count lines of standard input
       count = countLines(std::cin);
    }
    else {
       // count number of lines of all files passed as argument
       std::ifstream in;
       count = 0;
       for (int i=1; i<argc; ++i) {
           std::ifstream file(argv[i]);
           if (!file) {
               std::cerr << "failed to open " << argv[i] << "\n";
           }
           else {
               count += countLines(file);
           }
       }
    }
    std::cout << count << std::endl;
}
Ejemplo n.º 22
0
/* determine if a given processName exists */ 
int ifProcessExists( char *processName ){

        char* userName = calloc(MAX_USERNAME_LENGTH + 1, sizeof(char));
        getUserNameForPid(getpid(), userName);
                      
        /* build the command */
        char* command = calloc(55 + strlen(processName) + strlen(userName),
                        sizeof(char));
        sprintf(command,
                        "ps aux | grep %s | grep -v gdb | grep -v grep | grep %s",
                        processName, userName); 
        /* get the number of processes */
        int numPids = countLines(command);   
        return numPids; 
}
Ejemplo n.º 23
0
static void showText(WScreen *scr, int x, int y, int h, int w, const char *text)
{
	int width;
	int height;
	Pixmap pixmap;
	WMFont *font = scr->info_text_font;

	if (scr->balloon->contents)
		XFreePixmap(dpy, scr->balloon->contents);

	width = getMaxStringWidth(font, text) + 8;
	/*width = WMWidthOfString(font, text, strlen(text))+8; */
	height = countLines(text) * WMFontHeight(font) + 4;

	if (x < 0)
		x = 0;
	else if (x + width > scr->scr_width - 1)
		x = scr->scr_width - width;

	if (y - height - 2 < 0) {
		y += h;
		if (y < 0)
			y = 0;
	} else {
		y -= height + 2;
	}

	if (scr->window_title_texture[0])
		XSetForeground(dpy, scr->draw_gc, scr->window_title_texture[0]->any.color.pixel);
	else
		XSetForeground(dpy, scr->draw_gc, scr->light_pixel);

	pixmap = XCreatePixmap(dpy, scr->root_win, width, height, scr->w_depth);
	XFillRectangle(dpy, pixmap, scr->draw_gc, 0, 0, width, height);

	drawMultiLineString(scr->wmscreen, pixmap, scr->window_title_color[0], font, 4, 2, text, strlen(text));

	XResizeWindow(dpy, scr->balloon->window, width, height);
	XMoveWindow(dpy, scr->balloon->window, x, y);

	XSetWindowBackgroundPixmap(dpy, scr->balloon->window, pixmap);
	XClearWindow(dpy, scr->balloon->window);
	XMapRaised(dpy, scr->balloon->window);

	scr->balloon->contents = pixmap;

	scr->balloon->mapped = 1;
}
Ejemplo n.º 24
0
void getWordFirstRound(FILE*file, wordAndHints *newWordAndHint){
    static alreadyRandom = 0;

    int i, j, counter=0;
    char temporaria[BUFSIZ];
    rewind(file);
    i = countLines();
    if(!alreadyRandom) {
        srand(time(NULL));
        alreadyRandom = 1;
    }
    j=rand()%i;

    for(counter=1;counter<j;counter++){
        fgets(temporaria,BUFSIZ,file);
    }
    newWordAndHint->word = (char*) malloc(50*sizeof(char));
    newWordAndHint->hints[0] = (char*) malloc(50*sizeof(char));
    newWordAndHint->hints[1] = (char*) malloc(50*sizeof(char));
    newWordAndHint->hints[2] = (char*) malloc(50*sizeof(char));
    char temp[5];
    fscanf(file,"%s", (newWordAndHint->word));
    fscanf(file,"%s", temp);
    newWordAndHint->dificulty = temp[0];
    
    // hints in random order
    i=3;
    j=rand()%i;
    int temp2 = j;
    fscanf(file,"%s", (newWordAndHint->hints[j]));
    while(j == temp2) {
        j=rand()%i;
    }
    fscanf(file,"%s", (newWordAndHint->hints[j]));
    if(j!=2 && temp2 != 2) {
        j = 2;
    } else { if(j!=1 && temp2 != 1) {
        j = 1;
    } else {
        j = 0;
    }}
    fscanf(file,"%s", (newWordAndHint->hints[j]));

// printf("\na palavra e %s\n", newWordAndHint->word);
}
Ejemplo n.º 25
0
void AksenMain(void) {
	starting();	
	do {
		if (akt_time() >= timeoutAt) {
			setMotPow(0,0);
			break;
		}
		if(kurven == 8 && sensor[MID_MID] == 1 && sensor[MID_LEFT] == 1 && sensor[MID_RIGHT] == 1){
			setMotPow(0,0);
			break;		
		}
		followLine();
		countLines();
		manage(start);
		
				
	}while(1);
	while(1);
}
void TEditor::setBufLen( ushort length )
{
    bufLen = length;
    gapLen = bufSize - length;
    selStart = 0;
    selEnd = 0;
    curPtr = 0;
    delta.x = 0;
    delta.y = 0;
    curPos = delta;
    limit.x = maxLineLength;
    limit.y = countLines( &buffer[gapLen], bufLen ) + 1;
    drawLine = 0;
    drawPtr = 0;
    delCount = 0;
    insCount = 0;
    modified = False;
    update(ufView);
}
Ejemplo n.º 27
0
void drawError(gfxScreen_t screen, char* title, char* body, int offset)
{
	int i;

	int numLines=countLines(body);

	int width=numLines*8+32;
	int height=300;
	int x=240-width-12+offset, y=4;

	//main frame
	for(i=0; i<9; i++)gfxDrawRectangle(screen, GFX_LEFT, ENTRY_BGCOLOR, x+roundLutError[i], y+i, width-roundLutError[i]*2, 1);
	gfxDrawRectangle(screen, GFX_LEFT, ENTRY_BGCOLOR, x, y+9, width, height-9*2);
	for(i=0; i<9; i++)gfxDrawRectangle(screen, GFX_LEFT, ENTRY_BGCOLOR, x+roundLutError[i], y+height-1-i, width-roundLutError[i]*2, 1);

	//content
	gfxDrawText(screen, GFX_LEFT, &fontTitle, title, x+width-6-16, y+6);
	gfxDrawText(screen, GFX_LEFT, &fontDescription, body, x+width-5-16-13, y+8);
}
Ejemplo n.º 28
0
Matrix DataCollector::readQMatrixFromText(string filename)
{
	unsigned int rows, columns;
	countLines(filename, rows, columns);
	ifstream infile; //input file stream object
	infile.open(filename);
	if (!infile) {
		cerr << "Bad input! Can't open " << filename << endl;
		exit(1);
	}
	Matrix Q(rows, 1);
	unsigned int i = 0;
	string line;
	while (getline(infile, line, '\n'))
	{
		Q(i++, 0) = stod(line);
	}
	return Q;
}
Ejemplo n.º 29
0
int main(void)
{
   int rfd, flags, i, count;
   char buffer[SIZE];
   char** arr;

   flags = O_RDONLY;
   rfd = open(INPUT, flags);

   count = countLines(buffer, rfd);

   lseek(rfd, 0, SEEK_SET); //rewind the file, http://linux.die.net/man/2/lseek

   arr = (char**) malloc(count * sizeof(char*));

   for(i = 0; i < count; i++)
   {
      arr[i] = (char*) malloc((hash+1) * sizeof(char));
   }

   i = 0;
   while(readLine(buffer, SIZE, rfd) >= hash) 
   {
      strcpy(arr[i], buffer);
      i++;
   }

   for(i = 0; i < count; i++)
   {
      crack(arr[i]);

      free(arr[i]);
      arr[i] = NULL;
   }

   free(arr);
   arr = NULL;

   close(rfd);

   return 1;
}
Ejemplo n.º 30
0
int main(int argc, char *argv[])
{
  FILE *fp = fopen(argv[2], "r");
  int height = countLines(fp);
  int width = numCharsPerLine(fp);
  WBCell **cells = initializeCells(fp, height, width);
  fclose(fp);
  // printCells(cells, height, width);


  FILE *lexiconFilePtr = fopen(LEXICON_FILENAME, "r");
  TreeNode *lexTree = buildTreeFromFile(lexiconFilePtr);
  fclose(lexiconFilePtr);

  solvePuzzle(lexTree, cells, height, width, atoi(argv[1]));

  freeCells(cells, height, width);
  freeTree(lexTree);
  return 0;
}