Author: hummen Date: Thu Apr 8 11:34:41 2010 New Revision: 2259 Log: debug output is now a command-line option Modified: trunk/tools/iwlist_parser.c Modified: trunk/tools/iwlist_parser.c ============================================================================== --- trunk/tools/iwlist_parser.c Wed Apr 7 19:52:50 2010 (r2258) +++ trunk/tools/iwlist_parser.c Thu Apr 8 11:34:41 2010 (r2259) @@ -26,17 +26,13 @@ #define LINE_BUFFER_LENGTH 999 //#define USESTEP 0 -//#define DEBUG 1 -#ifdef DEBUG -#define dbg_printf(...) printf(__VA_ARGS__) -#else -#define dbg_printf(...) -#endif +#define dbg_printf(...) if (debug) {printf(__VA_ARGS__);} bool essidflag; //Look for one SSID only bool fileflag; //Use a file rather than stdin? bool selectByQualityFlag; +bool debug; char strEssid[MAX_CELLS][ESSID_LENGTH]; char strMAC[MAX_CELLS][MAC_LENGTH]; @@ -93,7 +89,6 @@ continue; } - //Parse AP Quality char *strTmp; char strQPos[ESSID_LENGTH]; @@ -152,7 +147,6 @@ continue; } - //Parse AP Essid strTmp = strstr(pTokens, "ESSID:"); if (strTmp) { @@ -163,7 +157,6 @@ } #endif /* USESTEP*/ - int j = 0; while (strTmp[7 + j] != 34) { strEssid[iCellNumber - 1][j] = strTmp[7 + j]; @@ -222,11 +215,10 @@ continue; } - if (strncmp(strEssid[i], strSelectedESSID, - !strlen(strSelectedESSID)) || !essidflag) { - //debug - //printf("MAC: %s\nESSID: %s\nQuality: %d\nSignalStrength: %d\n", - // strMAC[i], strEssid[i], iQuality[i], iSignalStrength[i]); + if (strncmp(strEssid[i], strSelectedESSID, strlen(strSelectedESSID)) + || !essidflag) { + dbg_printf("MAC: %s\nESSID: %s\nQuality: %d\nSignalStrength: %d\n", + strMAC[i], strEssid[i], iQuality[i], iSignalStrength[i]); if (selectByQualityFlag && iQuality[i] > iBestQuality) { iBestQuality = iQuality[i]; iIndexCell = i; @@ -243,7 +235,7 @@ //Output if (foundBest == true) { - printf("%s %s %d %d", strMAC[iIndexCell], strEssid[iIndexCell], + printf("%s %s %d %d\n", strMAC[iIndexCell], strEssid[iIndexCell], iQuality[iIndexCell], iSignalStrength[iIndexCell]); } else { printf("NONE"); @@ -256,6 +248,7 @@ essidflag = false; fileflag = false; selectByQualityFlag = false; + debug = false; step = 1; int c = 0; @@ -270,8 +263,10 @@ memset(pESSID, 0, ESSID_LENGTH); memset(strSelectedESSID, 0, ESSID_LENGTH); - while ((c = getopt(argc, argv, "s:f:hq")) != -1) { + while ((c = getopt(argc, argv, "ds:f:hq")) != -1) { switch (c) { + case 'd': + debug = true; case 's': essidflag = true; strcpy(strSelectedESSID, optarg);