/**************************************************************************** * * * FUNCTION : ProcessFile(char *, int) * * * * PURPOSE : Gather and display information about a specific file. * * * ****************************************************************************/ void ProcessFile(char *szFileName, int iFileSize) { int i, j, k; void * iHandle; int iBytes; int iFileType = FILETYPE_UNKNOWN; int iCompression = COMPTYPE_UNKNOWN; unsigned char cBuf[TEMP_BUF_SIZE]; // small buffer to load header info int iBpp = 0; int iWidth = 0; int iHeight = 0; int iOffset; int iMarker; int iPhotoMetric; int iPlanar; int iCount; unsigned char ucSubSample; BOOL bMotorola; char szOptions[256]; // Detect the file type by its header iHandle = PILIOOpenRO(szFileName); if (iHandle == (void *)-1) { return; } iBytes = PILIORead(iHandle, cBuf, DEFAULT_READ_SIZE); if (iBytes != DEFAULT_READ_SIZE) return; // too small if (MOTOLONG(cBuf) == 0x89504e47) // PNG iFileType = FILETYPE_PNG; else if (cBuf[0] == 'B' && cBuf[1] == 'M') // BMP { if (cBuf[14] == 0x28) // Windows iFileType = FILETYPE_BMP; else iFileType = FILETYPE_OS2BMP; } else if (cBuf[0] == 0x0a && cBuf[1] < 0x6 && cBuf[2] == 0x01) { iFileType = FILETYPE_PCX; } else if (INTELLONG(cBuf) == 0x80 && (cBuf[36] == 4 || cBuf[36] == 6)) { iFileType = FILETYPE_JEDMICS; } else if (INTELLONG(cBuf) == 0x64637273) { iFileType = FILETYPE_CALS; } else if ((MOTOLONG(cBuf) & 0xffffff00) == 0xffd8ff00) // JPEG iFileType = FILETYPE_JPEG; else if (MOTOLONG(cBuf) == 0x47494638 /*'GIF8'*/) // GIF iFileType = FILETYPE_GIF; else if ((cBuf[0] == 'I' && cBuf[1] == 'I') || (cBuf[0] == 'M' && cBuf[1] == 'M')) iFileType = FILETYPE_TIFF; else { i = MOTOLONG(cBuf) & 0xffff8080; if (i == 0x50360000 || i == 0x50350000 || i == 0x50340000) // Portable bitmap/graymap/pixmap iFileType = FILETYPE_PPM; } // Check for Truvision Targa i = cBuf[1] & 0xfe; j = cBuf[2]; // make sure it is not a MPEG file (starts with 00 00 01 BA) if (MOTOLONG(cBuf) != 0x1ba && MOTOLONG(cBuf) != 0x1b3 && i == 0 && (j == 1 || j == 2 || j == 3 || j == 9 || j == 10 || j == 11)) iFileType = FILETYPE_TARGA; if (iFileType == FILETYPE_UNKNOWN) { printf("%s - unknown file type\n", szFileName); goto process_exit; } szOptions[0] = '\0'; // info specific to each file type // Get info specific to each type of file switch (iFileType) { case FILETYPE_PCX: iWidth = 1 + INTELSHORT(&cBuf[8]) - INTELSHORT(&cBuf[4]); iHeight = 1 + INTELSHORT(&cBuf[10]) - INTELSHORT(&cBuf[6]); iCompression = COMPTYPE_PACKBITS; iBpp = cBuf[3] * cBuf[65]; break; case FILETYPE_PNG: if (MOTOLONG(&cBuf[12]) == 0x49484452/*'IHDR'*/) { iWidth = MOTOLONG(&cBuf[16]); iHeight = MOTOLONG(&cBuf[20]); iCompression = COMPTYPE_FLATE; i = cBuf[24]; // bits per pixel j = cBuf[25]; // pixel type switch (j) { case 0: // grayscale case 3: // palette image iBpp = i; break; case 2: // RGB triple iBpp = i * 3; break; case 4: // grayscale + alpha channel iBpp = i * 2; break; case 6: // RGB + alpha iBpp = i * 4; break; } if (cBuf[28] == 1) // interlace flag strcpy(szOptions, ", Interlaced"); else strcpy(szOptions, ", Not interlaced"); } break; case FILETYPE_TARGA: iWidth = INTELSHORT(&cBuf[12]); iHeight = INTELSHORT(&cBuf[14]); iBpp = cBuf[16]; if (cBuf[2] == 3 || cBuf[2] == 11) // monochrome iBpp = 1; if (cBuf[2] < 9) iCompression = COMPTYPE_NONE; else iCompression = COMPTYPE_RLE; break; case FILETYPE_PPM: if (cBuf[1] == '4') iBpp = 1; else if (cBuf[1] == '5') iBpp = 8; else if (cBuf[1] == '6') iBpp = 24; j = 2; while ((cBuf[j] == 0xa || cBuf[j] == 0xd) && j<DEFAULT_READ_SIZE) j++; // skip newline/cr while (cBuf[j] == '#' && j < DEFAULT_READ_SIZE) // skip over comments { while (cBuf[j] != 0xa && cBuf[j] != 0xd && j < DEFAULT_READ_SIZE) j++; while ((cBuf[j] == 0xa || cBuf[j] == 0xd) && j<DEFAULT_READ_SIZE) j++; // skip newline/cr } // get width and height iWidth = ParseNumber(cBuf, &j, DEFAULT_READ_SIZE); iHeight = ParseNumber(cBuf, &j, DEFAULT_READ_SIZE); iCompression = COMPTYPE_NONE; break; case FILETYPE_BMP: iCompression = COMPTYPE_NONE; iWidth = INTELSHORT(&cBuf[18]); iHeight = INTELSHORT(&cBuf[22]); if (iHeight & 0x8000) // upside down iHeight = 65536 - iHeight; iBpp = cBuf[28]; /* Number of bits per plane */ iBpp *= cBuf[26]; /* Number of planes */ if (cBuf[30] && (iBpp == 4 || iBpp == 8)) // if biCompression is non-zero (2=4bit rle, 1=8bit rle,4=24bit rle) iCompression = COMPTYPE_RLE; // windows run-length break; case FILETYPE_OS2BMP: iCompression = COMPTYPE_NONE; if (cBuf[14] == 12) // version 1.2 { iWidth = INTELSHORT(&cBuf[18]); iHeight = INTELSHORT(&cBuf[20]); iBpp = cBuf[22]; /* Number of bits per plane */ iBpp *= cBuf[24]; /* Number of planes */ } else { iWidth = INTELSHORT(&cBuf[18]); iHeight = INTELSHORT(&cBuf[22]); iBpp = cBuf[28]; /* Number of bits per plane */ iBpp *= cBuf[26]; /* Number of planes */ } if (iHeight & 0x8000) // upside down iHeight = 65536 - iHeight; if (cBuf[30] == 1 || cBuf[30] == 2 || cBuf[30] == 4) // if biCompression is non-zero (2=4bit rle, 1=8bit rle,4=24bit rle) iCompression = COMPTYPE_RLE; // windows run-length break; case FILETYPE_JEDMICS: iBpp = 1; iWidth = INTELSHORT(&cBuf[6]); iWidth <<= 3; // convert byte width to pixel width iHeight = INTELSHORT(&cBuf[4]); iCompression = COMPTYPE_G4; break; case FILETYPE_CALS: iBpp = 1; iCompression = COMPTYPE_G4; PILIOSeek(iHandle, 750, 0); // read some more iBytes = PILIORead(iHandle, cBuf, 1); if (cBuf[0] == '1') // type 1 file { PILIOSeek(iHandle, 1033, 0); // read some more iBytes = PILIORead(iHandle, cBuf, 256); i = 0; iWidth = ParseNumber(cBuf, &i, 256); iHeight = ParseNumber(cBuf, &i, 256); } else // type 2 { PILIOSeek(iHandle, 1024, 0); // read some more iBytes = PILIORead(iHandle, cBuf, 128); if (MOTOLONG(cBuf) == 0x7270656c && MOTOLONG(&cBuf[4]) == 0x636e743a) // "rpelcnt:" { i = 9; iWidth = ParseNumber(cBuf, &i, 256); iHeight = ParseNumber(cBuf, &i, 256); } } break; case FILETYPE_JPEG: iCompression = COMPTYPE_JPEG; i = j = 2; /* Start at offset of first marker */ iMarker = 0; /* Search for SOF (start of frame) marker */ while (i < 32 && iMarker != 0xffc0 && j < iFileSize) { iMarker = MOTOSHORT(&cBuf[i]) & 0xfffc; if (iMarker < 0xff00) // invalid marker, could be generated by "Arles Image Web Page Creator" or Accusoft { i += 2; continue; // skip 2 bytes and try to resync } if (iMarker == 0xffe0 && cBuf[i+4] == 'E' && cBuf[i+5] == 'x') // EXIF, check for thumbnail { unsigned char cTemp[1024]; // int iOff; memcpy(cTemp, cBuf, 32); iBytes = PILIORead(iHandle, &cTemp[32], 1024-32); bMotorola = (cTemp[i+10] == 'M'); // Future - do something with the thumbnail // iOff = PILTIFFLONG(&cTemp[i+14], bMotorola); // get offset to first IFD (info) // PILTIFFMiniInfo(pFile, bMotorola, j + 10 + iOff, TRUE); } if (iMarker == 0xffc0) // the one we're looking for break; j += 2 + MOTOSHORT(&cBuf[i+2]); /* Skip to next marker */ if (j < iFileSize) // need to read more { PILIOSeek(iHandle, j, 0); // read some more iBytes = PILIORead(iHandle, cBuf, 32); i = 0; } } // while if (iMarker != 0xffc0) goto process_exit; // error - invalid file? else { iBpp = cBuf[i+4]; // bits per sample iHeight = MOTOSHORT(&cBuf[i+5]); iWidth = MOTOSHORT(&cBuf[i+7]); iBpp = iBpp * cBuf[i+9]; /* Bpp = number of components * bits per sample */ ucSubSample = cBuf[i+11]; sprintf(szOptions, ", color subsampling = %d:%d", (ucSubSample>>4),(ucSubSample & 0xf)); } break; case FILETYPE_GIF: iCompression = COMPTYPE_LZW; iWidth = INTELSHORT(&cBuf[6]); iHeight = INTELSHORT(&cBuf[8]); iBpp = (cBuf[10] & 7) + 1; if (cBuf[10] & 64) // interlace flag strcpy(szOptions, ", Interlaced"); else strcpy(szOptions, ", Not interlaced"); break; case FILETYPE_TIFF: bMotorola = (cBuf[0] == 'M'); // determine endianness of TIFF data i = TIFFLONG(&cBuf[4], bMotorola); // get first IFD offset PILIOSeek(iHandle, i, 0); // read the entire tag directory iBytes = PILIORead(iHandle, cBuf, MAX_TAGS*TIFF_TAGSIZE); j = TIFFSHORT(cBuf, bMotorola); // get the tag count iOffset = 2; // point to start of TIFF tag directory // Some TIFF files don't specify everything, so set up some default values iBpp = 1; iPlanar = 1; iCompression = COMPTYPE_NONE; iPhotoMetric = 7; // if not specified, set to "unknown" // Each TIFF tag is made up of 12 bytes // byte 0-1: Tag value (short) // byte 2-3: data type (short) // byte 4-7: number of values (long) // byte 8-11: value or offset to list of values for (i=0; i<j; i++) // search tags for the info we care about { iMarker = TIFFSHORT(&cBuf[iOffset], bMotorola); // get the TIFF tag switch (iMarker) // only read the tags we care about... { case 256: // image width iWidth = TIFFVALUE(&cBuf[iOffset], bMotorola); break; case 257: // image length iHeight = TIFFVALUE(&cBuf[iOffset], bMotorola); break; case 258: // bits per sample iCount = TIFFLONG(&cBuf[iOffset+4], bMotorola); /* Get the count */ if (iCount == 1) iBpp = TIFFVALUE(&cBuf[iOffset], bMotorola); else // need to read the first value from the list (they should all be equal) { k = TIFFLONG(&cBuf[iOffset+8], bMotorola); if (k < iFileSize) { PILIOSeek(iHandle, k, 0); iBytes = PILIORead(iHandle, &cBuf[iOffset], 2); // okay to overwrite the value we just used iBpp = iCount * TIFFSHORT(&cBuf[iOffset], bMotorola); } } break; case 259: // compression k = TIFFVALUE(&cBuf[iOffset], bMotorola); if (k == 1) iCompression = COMPTYPE_NONE; else if (k == 2) iCompression = COMPTYPE_HUFFMAN; else if (k == 3) iCompression = COMPTYPE_G3; else if (k == 4) iCompression = COMPTYPE_G4; else if (k == 5) iCompression = COMPTYPE_LZW; else if (k == 6 || k == 7) iCompression = COMPTYPE_JPEG; else if (k == 8 || k == 32946) iCompression = COMPTYPE_FLATE; else if (k == 9) iCompression = COMPTYPE_JBIG; else if (k == 32773) iCompression = COMPTYPE_PACKBITS; else if (k == 32809) iCompression = COMPTYPE_THUNDERSCAN; else iCompression = COMPTYPE_UNKNOWN; break; case 262: // photometric value iPhotoMetric = TIFFVALUE(&cBuf[iOffset], bMotorola); if (iPhotoMetric > 6) iPhotoMetric = 7; // unknown break; case 284: // planar/chunky iPlanar = TIFFVALUE(&cBuf[iOffset], bMotorola); if (iPlanar < 1 || iPlanar > 2) // unknown value iPlanar = 0; // unknown break; } // switch on tiff tag iOffset += TIFF_TAGSIZE; } // for each tag sprintf(szOptions, ", Photometric = %s, Planar config = %s", szPhotometric[iPhotoMetric], szPlanar[iPlanar]); break; } // switch printf("%s: Type=%s, Compression=%s, Size: %d x %d, %d-Bpp%s\n", szFileName, szType[iFileType], szComp[iCompression], iWidth, iHeight, iBpp, szOptions); process_exit: PILIOClose(iHandle); } /* ProcessFile() */
/** * parse the WAP text header * * use ElemIndexes to retrieve the index * an starting position of an element in iWapMessage * Length of element is calculated by * subtracting current index value from the next one * except for KOtherHeader and user data, of course */ TBool TWapTextMessage::ParseWapTextHeader(const TIndexInfo& aIndexArray) { OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSEWAPTEXTHEADER_1, "TWapTextMessage::ParseWapTextHeader: %s", iWAPMessage ); TInt ParsedNumber = 0; // parse the header TInt ElemIndexCount=aIndexArray.iLastIndex+1; for(TInt i=0; i<ElemIndexCount; i++) { if (i<ElemIndexCount-1) { // all the elems have a length defined in advance if (iWAPMessage.Length() >= aIndexArray.iIndexes[i+1]) { // the header fits into the wap datagram TPtrC8 Elem(iWAPMessage.Mid(aIndexArray.iIndexes[i], aIndexArray.iIndexes[i+1]- aIndexArray.iIndexes[i])); ParsedNumber = ParseNumber(Elem,ETrue,16); if( ParsedNumber == KErrNotFound ) return EFalse; switch(i) { case KIndexDestinationPort: iDestinationPort = ParsedNumber; break; case KIndexSourcePort: iSourcePort = ParsedNumber; break; case KIndexReferenceNumber: iReference = ParsedNumber; break; case KIndexTotalSegments: iTotalSegments = ParsedNumber; break; case KIndexSegmentNumber: iSegmentNumber = ParsedNumber; break; default: OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, TWAPTEXTMESSAGE_PARSEWAPTEXTHEADER_2, "Hm. unhandled WAP index [%d]", i ); break; } } } else { // elems have not a length defined in advance iOtherHeader = 0; iOtherHeaderLength = 0; // Search the terminating character ' ' iData = iWAPMessage.Locate(' '); TInt dataTmp = iWAPMessage.Locate('\n'); if (iData == KErrNotFound) { if (dataTmp == KErrNotFound) return EFalse; else iData = dataTmp; } else if (dataTmp != KErrNotFound) iData = Min(iData, dataTmp); // check the existence of other header // at least "// " should be there if ( iWAPMessage.Length() > aIndexArray.iIndexes[i]+2 && iWAPMessage[aIndexArray.iIndexes[i]] == '/' && iWAPMessage[aIndexArray.iIndexes[i]+1] == '/') { iOtherHeader = aIndexArray.iIndexes[i]; iOtherHeaderLength=iData-iOtherHeader; } // data: check if any characters after ' ' iDataLength = 0; iData++; if (iWAPMessage.Length() > iData) { iDataLength = iWAPMessage.Length() - iData; } // That's it } // end of other header and data }// end of for loop return ETrue; } // TWapTextMessage::ParseWapTextHeader
TEST(StringNumber, StringToNumber) { int16_t i16; int32_t i32; int64_t i64; long long ll; unsigned long long ull; ASSERT_FALSE(StringToNumber("223372036854775807", &i32)); ASSERT_TRUE(StringToNumber("223372036854775807", &i64)); ASSERT_TRUE(StringToNumber("223372036854775807", &ll)); ASSERT_TRUE(StringToNumber("223372036854775807", &ull)); ASSERT_EQ(i64, 223372036854775807LL); ASSERT_EQ(ll, 223372036854775807LL); ASSERT_EQ(ull, 223372036854775807ULL); ASSERT_FALSE(StringToNumber("1147483647", &i16)); ASSERT_TRUE(StringToNumber("1147483647", &i32)); ASSERT_TRUE(StringToNumber("1147483647", &i64)); ASSERT_EQ(i32, 1147483647); ASSERT_EQ(i64, 1147483647); uint32_t u32; ASSERT_TRUE(StringToNumber("1147483647", &u32)); char buffer[1024]; double d = 1.0003; ASSERT_STREQ(DoubleToString(d, buffer), "1.0003"); d = std::numeric_limits<double>::infinity(); ASSERT_STREQ(DoubleToString(d, buffer), "inf"); d = -std::numeric_limits<double>::infinity(); ASSERT_STREQ(DoubleToString(d, buffer), "-inf"); #ifdef __GNUC__ // divided by zero is not allowed in msvc d = NAN; ASSERT_STREQ(DoubleToString(d, buffer), "nan"); #endif float f = 1e+22; ASSERT_STREQ(FloatToString(f, buffer), "1e+22"); f = 0.000325; ASSERT_STREQ(FloatToString(f, buffer), "0.000325"); f = std::numeric_limits<double>::infinity(); ASSERT_STREQ(FloatToString(f, buffer), "inf"); f = -std::numeric_limits<double>::infinity(); ASSERT_STREQ(FloatToString(f, buffer), "-inf"); #ifdef __GNUC__ // divided by zero is not allowed in msvc f = NAN; ASSERT_STREQ(FloatToString(f, buffer), "nan"); f = INFINITY; ASSERT_STREQ(FloatToString(f, buffer), "inf"); #endif f = -std::numeric_limits<float>::infinity(); ASSERT_STREQ(FloatToString(f, buffer), "-inf"); uint32_t i = 255; ASSERT_STREQ(UInt32ToHexString(i, buffer), "000000ff"); std::string str = "1110.32505QQ"; char* endptr; ASSERT_TRUE(ParseNumber(str.c_str(), &d, &endptr)); ASSERT_TRUE(d == 1110.32505); ASSERT_FALSE(StringToNumber(str.c_str(), &d)); ASSERT_TRUE(ParseNumber(str.c_str(), &f, &endptr)); ASSERT_TRUE(f == 1110.32505f); ASSERT_FALSE(StringToNumber(str.c_str(), &f)); ASSERT_TRUE(ParseNumber(str.c_str(), &i, &endptr)); ASSERT_EQ(1110U, i); ASSERT_FALSE(StringToNumber(str.c_str(), &i)); str = "1110.32505"; d = 0; f = 0; i = 0; ASSERT_TRUE(StringToNumber(str.c_str(), &d)); ASSERT_TRUE(d == 1110.32505); ASSERT_TRUE(StringToNumber(str.c_str(), &f)); ASSERT_TRUE(f == 1110.32505f); ASSERT_FALSE(StringToNumber(str.c_str(), &i)); str = "-1110"; int32_t x; ASSERT_TRUE(StringToNumber(str.c_str(), &x)); ASSERT_EQ(x, -1110); }
void HandleCommand() { int i,margin,top,bottom; int picwidth,picheight,picmid; switch (toupper(*++text)) { case 'B': picy=ParseNumber(); picx=ParseNumber(); picwidth=ParseNumber(); picheight=ParseNumber(); VW_Bar(picx,picy,picwidth,picheight,BACKCOLOR); RipToEOL(); break; case ';': // comment RipToEOL(); break; case 'P': // ^P is start of next page, ^E is end of file case 'E': layoutdone = true; text--; // back up to the '^' break; case 'C': // ^c<hex digit> changes text color i = toupper(*++text); if (i>='0' && i<='9') fontcolor = i-'0'; else if (i>='A' && i<='F') fontcolor = i-'A'+10; fontcolor *= 16; i = toupper(*++text); if (i>='0' && i<='9') fontcolor += i-'0'; else if (i>='A' && i<='F') fontcolor += i-'A'+10; text++; break; case '>': px = 160; text++; break; case 'L': py=ParseNumber(); rowon = (py-TOPMARGIN)/FONTHEIGHT; py = TOPMARGIN+rowon*FONTHEIGHT; px=ParseNumber(); while (*text++ != '\n') // scan to end of line ; break; case 'T': // ^Tyyy,xxx,ppp,ttt waits ttt tics, then draws pic TimedPicCommand(); break; case 'G': // ^Gyyy,xxx,ppp draws graphic ParsePicCommand (); VWB_DrawPic (picx&~7,picy,picnum); if (w0 == true){ picwidth = pictableWL1[picnum-STARTPICS].width; picheight = pictableWL1[picnum-STARTPICS].height; } else if (w1 == true){ picwidth = pictableWL6[picnum-STARTPICS].width; picheight = pictableWL6[picnum-STARTPICS].height; } else if (s0 == true){ picwidth = pictableSDM[picnum-STARTPICS].width; picheight = pictableSDM[picnum-STARTPICS].height; } else { picwidth = pictableSOD[picnum-STARTPICS].width; picheight = pictableSOD[picnum-STARTPICS].height; } // // adjust margins // picmid = picx + picwidth/2; if (picmid > SCREENMID) margin = picx-PICMARGIN; // new right margin else margin = picx+picwidth+PICMARGIN; // new left margin top = (picy-TOPMARGIN)/FONTHEIGHT; if (top<0) top = 0; bottom = (picy+picheight-TOPMARGIN)/FONTHEIGHT; if (bottom>=TEXTROWS) bottom = TEXTROWS-1; for (i=top;i<=bottom;i++) if (picmid > SCREENMID) rightmargin[i] = margin; else leftmargin[i] = margin; // // adjust this line if needed // if (px < leftmargin[rowon]) px = leftmargin[rowon]; break; } }
// Return the next token in the string tokentype Parser::NextToken () { tokentype t; token = ""; if (pos >= text.length()) { t = ENDOFSTRING; } else { char ch = text[pos]; if (ch == '\'') { // Single quoted token bool done = false; pos++; while (!done) { ch = text[pos++]; // Look ahead for double quote if (ch == '\'') { ch = text[pos]; done = (ch != '\''); } if (!done && (ch != '\n') && (ch != '\r')) { token += ch; } } t = STRING; //classify the token } else if (isalpha (ch)) { while (isalnum (ch) || (ch == '_') || (ch == '.') && (pos < text.length())) { if (ch == '_') token += ' '; else token += ch; pos++; ch = text[pos]; } t = STRING; //classify the token } else { if (isdigit(ch) || (ch == '-')) { t = ParseNumber(); // int stop = text.find_first_not_of ("01234567890-.Ee", pos); // token = text.substr (pos, stop-pos); // pos = stop; // t = NUMBER; } else { token += ch; pos++; switch (ch) { case '(': t = LPAR; break; case ')': t = RPAR; break; case ' ': t = SPACE; break; case ',': t = COMMA; break; case ';': t = SEMICOLON; break; case ':': t = COLON; break; case '\t': t = TAB; break; case '\r': case '\n': t = NEWLINE; break; default: t = BAD; break; } } } } // cout << "token = " << token << endl; return (t); }
//------------------------------------------------------------------------------ Tokeniser::tokentype Tokeniser::GetNextToken () { tokentype TokenType = EMPTY; while ((TokenType == EMPTY) && !in.bad() && !atEOF) { curChar = GetNextChar (); //std::cout << curChar << " GetNextChar" << std::endl; if (IsWhiteSpace (curChar)) { // skip white space } else { if (IsPunctuation (curChar)) { // std::cout << curChar << " IsPunctuation" << std::endl; // classify punctuation token switch (curChar) { case '[': ParseComment (); break; case '\'': if (ParseString ()) TokenType = STRING; else TokenType = BAD; break; case '(': TokenType = LPAR; break; case ')': TokenType = RPAR; break; case '{': TokenType = LPAR; break; case '}': TokenType = RPAR; break; case '!': TokenType = BANG; break; case '#': TokenType = HASH; break; case '=': TokenType = EQUALS; break; case ';': TokenType = SEMICOLON; break; case ',': TokenType = COMMA; break; case '*': TokenType = ASTERIX; break; case ':': TokenType = COLON; break; case '-': TokenType = MINUS; break; case '"': TokenType = DOUBLEQUOTE; break; case '/': TokenType = BACKSLASH; break; default: TokenType = OTHER; break; } } else { // It's either a number, or a string if (isdigit (curChar)) { TokenType = ParseNumber(); /* if (ParseNumber ()) TokenType = NUMBER; else TokenType = BAD; */ } else { if (ParseToken ()) TokenType = STRING; else TokenType = BAD; } } } } if ((TokenType != STRING) && (TokenType != NUMBER)) { token = ""; token += curChar; } return TokenType; }