Пример #1
0
/*
 * Trenger begrenset lengde på feltnavn: 100 tegn * 6 for multibyte.
 * Dette skal la oss ende på 100 widechar tegn.
 *
 * Så vidt jeg har skjønt er sammenhengene slik:
 *
 * http://www.unicode.org/faq/utf_bom.html
 * utf8:  1-4 bytes
 * utf16: 2-4 bytes ( to 16 bit verdier)
 * utf32  4 bytes ( 1 32 bit verdi) widechar. ncurses jobber bra med widechars på 32 bit.
 *
 * Dette betyr at: jeg trenger 400 bytes satt av for å lagre hva som helst på 100 tegn.

 * New business rules, in the advent of ability of creation of db files from the commandline.
   This is the entry point for that functionality.

   if the databasefile, is merely specified, AND the file doesn't yet exist, AND we don't find
   any label file. (open_label_file() returns NULL ), THEN we create a new label file for the
   non-existant db file. Of course, should we be so happy to find one along the path then
   we'll use this one?

 * */
void
read_labelfile(void)
{
    const char procname[]="read_labelfile" ;
	FILE *fp;

	register int len;

	char buf[BUFSIZ];	/* 1024 characters per line on Mac Os X */
    /* we have gotten the name when we come here */
    fp = open_label_file() ;
    if ((fp == NULL ) && (!hasPattern()) && (shouldCreateMissingLabelFile()|| dbFileHasNoPath())) {
       newLabelFilePath() ; 
       create_db() ;
        char *labelfn =  getFullLabelFileName() ; 
        if ( file_is_empty(labelfn) || (!labelFileOkAfterLinting(labelfn))) {
            ysimpleError("Index: User redecided creating a new database and thereby quitted.",YX_ALL_WELL) ;
        } 
        /* we remove any trailing line-endings here */
        setLabelFileCreated() ;
        fp = fopen(labelfn,"r") ;
 /*       if (dbFileHasNoPath() ) {

        } */
        
    } else if (fp == NULL ) {
           char *labelfn =  getFullLabelFileName() ; 
           yerror(YFILE_FINDF_ERR,procname,labelfn,YX_EXTERNAL_CAUSE ) ; 
    }
    

	/* Zero out structure.                                      */
    memset(&idx,(int)0, sizeof(idxfile) ) ;
	/* Read lines from file.                                    */
	while (idx.idx_nlines < MAXDBLINES) {
		/* End of file.                                         */
		if (fgets(buf, (int)BUFSIZ , fp) == NULL)
			break;

		/* Strip newline. replace with a colon                  */
		len = strlen(buf) - 1;
		if (!len) {
			buf[len] = '\0';
		} else {	/* check for a colon! */
			if (buf[(len - 1)] == ':') {
				buf[len] = '\0';
			} else {	/* no colon, so we insert one! */
				buf[len] = ':';
			}
		}
		/* If first char is '!', then this line should not      */
		/* participate in searches.  Save stuff after the '!'.  */
		/* Otherwise this line does participate in searches,    */
		/* save  the whole line.                                */
		if (*buf == '!') {
			idx.idx_lines[idx.idx_nlines] = mbstowcs_alloc(&buf[1]);
			idx.idx_search[idx.idx_nlines] = 0;
			len--;
		} else {
			idx.idx_lines[idx.idx_nlines] = mbstowcs_alloc(buf);
			idx.idx_search[idx.idx_nlines] = 1;
		}
		/* Increment number of lines.                           */
		idx.idx_nlines++;

		/* Save the length of the longest field name.           */
		if (len > idx.idx_maxlen)
			idx.idx_maxlen = len;
	}

	/* Close file.                                              */
	fclose(fp);
}
Пример #2
0
/*****************************************************************************
 ** Function name:               GPSRetreiveData
 **
 ** Descriptions:                Reads and parses the next set of GPS data.
 **
 ** parameters:                  None
 ** Returned value:              The parsed information
 **
 *****************************************************************************/
const gpsData* GPSRetreiveData(void)
{
	uint8_t * pattern = (uint8_t*)"GPGGA";

	while (1) {
		uint8_t buf[100];
		uint8_t ch = 0;
		uint8_t *ptr = 0;
		int index = 0;

		// Retrieve the first byte
		if (!UARTGetChar(&ch))
			continue;

		 // look for "$GPGGA," header
		if (ch != '$') {
			continue;
		}

		// Retrieve the next six bytes
		for (index=0; index<6; index++) {
			buf[index] = UARTGetCharBlock();
		}

		//Check if its Global Positioning System fixed Data
		if(hasPattern((uint8_t*)&buf, pattern) == 0) {
			continue;
		}

		//Retrieve the data from the GPS module
		for (index=0; index<100; index++) {
			buf[index] = UARTGetCharBlock();

			if (buf[index] == '\r') {
				buf[index] = END_OF_MESSAGE;
				break;
			}
		}

		ptr = &buf[0];

		//parse UTC time
		parseUTC(&ptr);

		//parse Latitude
		parseLatitude(&ptr);

		// parse N/S field
		parseNSIndicator(&ptr);

		// parse Longitude
		parseLongitude(&ptr);

		// parse E/W field
		parseEWIndicator(&ptr);

		// parse fix position
		parseFixIndicator(&ptr);

		// parse satellites
		parseSatellites(&ptr);

		// parse horizontal-dilution-of-precision field
		parseHDOP(&ptr);

		// parse altitude
		parseAltitudes(&ptr);

		break;
	}
	return &data;
}