Revert "Omit calls to set composing region when pasting image."
[chromium-blink-merge.git] / third_party / codesighs / codesighs.c
blobf20fbb1e62ddb4b3eb4c312414a4b7b1d4a11e0f
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is codesighs.c code, released
17 * Oct 3, 2002.
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 2002
22 * the Initial Developer. All Rights Reserved.
24 * Contributor(s):
25 * Garrett Arch Blythe, 03-October-2002
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <time.h>
45 #include <ctype.h>
46 #include <errno.h>
48 #define ERROR_REPORT(num, val, msg) fprintf(stderr, "error(%d):\t\"%s\"\t%s\n", (num), (val), (msg));
49 #define CLEANUP(ptr) do { if(NULL != ptr) { free(ptr); ptr = NULL; } } while(0)
52 typedef struct __struct_Options
54 ** Options to control how we perform.
56 ** mProgramName Used in help text.
57 ** mInput File to read for input.
58 ** Default is stdin.
59 ** mInputName Name of the file.
60 ** mOutput Output file, append.
61 ** Default is stdout.
62 ** mOutputName Name of the file.
63 ** mHelp Whether or not help should be shown.
64 ** mModules Output module by module information.
65 ** mTotalOnly Only output one number, the total.
66 ** mMinSize Ignore lines below this size.
67 ** mMaxSize Ignore lines above this size.
68 ** mMatchScopes For a line to be processed, it should match.
69 ** mMachClasses For a line to be processed, it should match.
70 ** mMatchModules For a line to be processed, it should match.
71 ** mMatchSections For a line to be processed, it should match.
72 ** mMatchObjects For a line to be processed, it should match.
73 ** mMatchSymbols For a line to be processed, it should match.
76 const char* mProgramName;
77 FILE* mInput;
78 char* mInputName;
79 FILE* mOutput;
80 char* mOutputName;
81 int mHelp;
82 int mModules;
83 int mTotalOnly;
84 unsigned long mMinSize;
85 unsigned long mMaxSize;
86 char** mMatchScopes;
87 unsigned mMatchScopeCount;
88 char** mMatchClasses;
89 unsigned mMatchClassCount;
90 char** mMatchModules;
91 unsigned mMatchModuleCount;
92 char** mMatchSections;
93 unsigned mMatchSectionCount;
94 char** mMatchObjects;
95 unsigned mMatchObjectCount;
96 char** mMatchSymbols;
97 unsigned mMatchSymbolCount;
99 Options;
102 typedef struct __struct_Switch
104 ** Command line options.
107 const char* mLongName;
108 const char* mShortName;
109 int mHasValue;
110 const char* mValue;
111 const char* mDescription;
113 Switch;
115 #define DESC_NEWLINE "\n\t\t"
117 static Switch gInputSwitch = {"--input", "-i", 1, NULL, "Specify input file." DESC_NEWLINE "stdin is default."};
118 static Switch gOutputSwitch = {"--output", "-o", 1, NULL, "Specify output file." DESC_NEWLINE "Appends if file exists." DESC_NEWLINE "stdout is default."};
119 static Switch gHelpSwitch = {"--help", "-h", 0, NULL, "Information on usage."};
120 static Switch gModuleSwitch = {"--modules", "-m", 0, NULL, "Output individual module numbers as well."};
121 static Switch gTotalSwitch = {"--totalonly", "-t", 0, NULL, "Output only one number." DESC_NEWLINE "The total overall size." DESC_NEWLINE "Overrides other output options."};
122 static Switch gMinSize = {"--min-size", "-min", 1, NULL, "Only consider symbols equal to or greater than this size." DESC_NEWLINE "The default is 0x00000000."};
123 static Switch gMaxSize = {"--max-size", "-max", 1, NULL, "Only consider symbols equal to or smaller than this size." DESC_NEWLINE "The default is 0xFFFFFFFF."};
124 static Switch gMatchScope = {"--match-scope", "-msco", 1, NULL, "Only consider scopes that have a substring match." DESC_NEWLINE "Multiple uses allowed to specify a range of scopes," DESC_NEWLINE "though PUBLIC, STATIC, and UNDEF are your only choices."};
125 static Switch gMatchClass = {"--match-class", "-mcla", 1, NULL, "Only consider classes that have a substring match." DESC_NEWLINE "Multiple uses allowed to specify a range of classes," DESC_NEWLINE "though CODE and DATA are your only choices."};
126 static Switch gMatchModule = {"--match-module", "-mmod", 1, NULL, "Only consider modules that have a substring match." DESC_NEWLINE "Multiple uses allowed to specify an array of modules."};
127 static Switch gMatchSection = {"--match-section", "-msec", 1, NULL, "Only consider sections that have a substring match." DESC_NEWLINE "Multiple uses allowed to specify an array of sections." DESC_NEWLINE "Section is considered symbol type."};
128 static Switch gMatchObject = {"--match-object", "-mobj", 1, NULL, "Only consider objects that have a substring match." DESC_NEWLINE "Multiple uses allowed to specify an array of objects."};
129 static Switch gMatchSymbol = {"--match-symbol", "-msym", 1, NULL, "Only consider symbols that have a substring match." DESC_NEWLINE "Multiple uses allowed to specify an array of symbols."};
131 static Switch* gSwitches[] = {
132 &gInputSwitch,
133 &gOutputSwitch,
134 &gModuleSwitch,
135 &gTotalSwitch,
136 &gMinSize,
137 &gMaxSize,
138 &gMatchClass,
139 &gMatchScope,
140 &gMatchModule,
141 &gMatchSection,
142 &gMatchObject,
143 &gMatchSymbol,
144 &gHelpSwitch
148 typedef struct __struct_SizeStats
150 ** Track totals.
152 ** mData Size of data.
153 ** mCode Size of code.
156 unsigned long mData;
157 unsigned long mCode;
159 SizeStats;
162 typedef struct __struct_ModuleStats
164 ** Track module level information.
166 ** mModule Module name.
167 ** mSize Size of module.
170 char* mModule;
171 SizeStats mSize;
173 ModuleStats;
175 typedef enum __enum_SegmentClass
177 CODE,
178 DATA
180 SegmentClass;
183 static int moduleCompare(const void* in1, const void* in2)
185 ** qsort helper function.
188 int retval = 0;
190 const ModuleStats* one = (const ModuleStats*)in1;
191 const ModuleStats* two = (const ModuleStats*)in2;
192 unsigned long oneSize = one->mSize.mCode + one->mSize.mData;
193 unsigned long twoSize = two->mSize.mCode + two->mSize.mData;
195 if(oneSize < twoSize)
197 retval = 1;
199 else if(oneSize > twoSize)
201 retval = -1;
204 return retval;
208 void trimWhite(char* inString)
210 ** Remove any whitespace from the end of the string.
213 int len = strlen(inString);
215 while(len)
217 len--;
219 if(isspace(*(inString + len)))
221 *(inString + len) = '\0';
223 else
225 break;
231 int codesighs(Options* inOptions)
233 ** Output a simplistic report based on our options.
236 int retval = 0;
237 char lineBuffer[0x1000];
238 int scanRes = 0;
239 unsigned long size;
240 char segClass[0x10];
241 char scope[0x10];
242 char module[0x100];
243 char segment[0x40];
244 char object[0x100];
245 char* symbol;
246 SizeStats overall;
247 ModuleStats* modules = NULL;
248 unsigned moduleCount = 0;
250 memset(&overall, 0, sizeof(overall));
253 ** Read the file line by line, regardless of number of fields.
254 ** We assume tab separated value formatting, at least 7 lead values:
255 ** size class scope module segment object symbol ....
257 while(0 == retval && NULL != fgets(lineBuffer, sizeof(lineBuffer), inOptions->mInput))
259 trimWhite(lineBuffer);
261 scanRes = sscanf(lineBuffer,
262 "%x\t%s\t%s\t%s\t%s\t%s\t",
263 (unsigned*)&size,
264 segClass,
265 scope,
266 module,
267 segment,
268 object);
270 if(6 == scanRes)
272 SegmentClass segmentClass = CODE;
274 symbol = strchr(lineBuffer, '\t') + 1;
277 ** Qualify the segment class.
279 if(0 == strcmp(segClass, "DATA"))
281 segmentClass = DATA;
283 else if(0 == strcmp(segClass, "CODE"))
285 segmentClass = CODE;
287 else
289 retval = __LINE__;
290 ERROR_REPORT(retval, segClass, "Unable to determine segment class.");
293 if(0 == retval)
296 ** Match any options required before continuing.
297 ** This is where you would want to add more restrictive totalling.
301 ** Match size.
303 if(size < inOptions->mMinSize)
305 continue;
307 if(size > inOptions->mMaxSize)
309 continue;
313 ** Match class.
315 if(0 != inOptions->mMatchClassCount)
317 unsigned loop = 0;
319 for(loop = 0; loop < inOptions->mMatchClassCount; loop++)
321 if(NULL != strstr(segClass, inOptions->mMatchClasses[loop]))
323 break;
328 ** If there was no match, we skip the line.
330 if(loop == inOptions->mMatchClassCount)
332 continue;
337 ** Match scope.
339 if(0 != inOptions->mMatchScopeCount)
341 unsigned loop = 0;
343 for(loop = 0; loop < inOptions->mMatchScopeCount; loop++)
345 if(NULL != strstr(scope, inOptions->mMatchScopes[loop]))
347 break;
352 ** If there was no match, we skip the line.
354 if(loop == inOptions->mMatchScopeCount)
356 continue;
361 ** Match modules.
363 if(0 != inOptions->mMatchModuleCount)
365 unsigned loop = 0;
367 for(loop = 0; loop < inOptions->mMatchModuleCount; loop++)
369 if(NULL != strstr(module, inOptions->mMatchModules[loop]))
371 break;
376 ** If there was no match, we skip the line.
378 if(loop == inOptions->mMatchModuleCount)
380 continue;
385 ** Match sections.
387 if(0 != inOptions->mMatchSectionCount)
389 unsigned loop = 0;
391 for(loop = 0; loop < inOptions->mMatchSectionCount; loop++)
393 if(NULL != strstr(segment, inOptions->mMatchSections[loop]))
395 break;
400 ** If there was no match, we skip the line.
402 if(loop == inOptions->mMatchSectionCount)
404 continue;
409 ** Match object.
411 if(0 != inOptions->mMatchObjectCount)
413 unsigned loop = 0;
415 for(loop = 0; loop < inOptions->mMatchObjectCount; loop++)
417 if(NULL != strstr(object, inOptions->mMatchObjects[loop]))
419 break;
424 ** If there was no match, we skip the line.
426 if(loop == inOptions->mMatchObjectCount)
428 continue;
433 ** Match symbols.
435 if(0 != inOptions->mMatchSymbolCount)
437 unsigned loop = 0;
439 for(loop = 0; loop < inOptions->mMatchSymbolCount; loop++)
441 if(NULL != strstr(symbol, inOptions->mMatchSymbols[loop]))
443 break;
448 ** If there was no match, we skip the line.
450 if(loop == inOptions->mMatchSymbolCount)
452 continue;
457 ** Update overall totals.
459 if(CODE == segmentClass)
461 overall.mCode += size;
463 else if(DATA == segmentClass)
465 overall.mData += size;
469 ** See what else we should be tracking.
471 if(0 == inOptions->mTotalOnly)
473 if(inOptions->mModules)
475 unsigned index = 0;
478 ** Find the module to modify.
480 for(index = 0; index < moduleCount; index++)
482 if(0 == strcmp(modules[index].mModule, module))
484 break;
489 ** If the index is the same as the count, we need to
490 ** add a new module.
492 if(index == moduleCount)
494 void* moved = NULL;
496 moved = realloc(modules, sizeof(ModuleStats) * (moduleCount + 1));
497 if(NULL != moved)
499 modules = (ModuleStats*)moved;
500 moduleCount++;
502 memset(modules + index, 0, sizeof(ModuleStats));
503 modules[index].mModule = strdup(module);
504 if(NULL == modules[index].mModule)
506 retval = __LINE__;
507 ERROR_REPORT(retval, module, "Unable to duplicate string.");
510 else
512 retval = __LINE__;
513 ERROR_REPORT(retval, inOptions->mProgramName, "Unable to allocate module memory.");
517 if(0 == retval)
519 if(CODE == segmentClass)
521 modules[index].mSize.mCode += size;
523 else if(DATA == segmentClass)
525 modules[index].mSize.mData += size;
532 else
534 retval = __LINE__;
535 ERROR_REPORT(retval, inOptions->mInputName, "Problem extracting values from file.");
539 if(0 == retval && 0 != ferror(inOptions->mInput))
541 retval = __LINE__;
542 ERROR_REPORT(retval, inOptions->mInputName, "Unable to read file.");
546 ** If all went well, time to report.
548 if(0 == retval)
550 if(inOptions->mTotalOnly)
552 fprintf(inOptions->mOutput, "%u\n", (unsigned)(overall.mCode + overall.mData));
554 else
556 fprintf(inOptions->mOutput, "Overall Size\n");
557 fprintf(inOptions->mOutput, "\tTotal:\t%10u\n", (unsigned)(overall.mCode + overall.mData));
558 fprintf(inOptions->mOutput, "\tCode:\t%10u\n", (unsigned)overall.mCode);
559 fprintf(inOptions->mOutput, "\tData:\t%10u\n", (unsigned)overall.mData);
563 ** Check options to see what else we should output.
565 if(inOptions->mModules && moduleCount)
567 unsigned loop = 0;
570 ** Sort the modules by their size.
572 qsort(modules, (size_t)moduleCount, sizeof(ModuleStats), moduleCompare);
575 ** Output each one.
576 ** Might as well clean up while we go too.
578 for(loop = 0; loop < moduleCount; loop++)
580 fprintf(inOptions->mOutput, "\n");
581 fprintf(inOptions->mOutput, "%s\n", modules[loop].mModule);
582 fprintf(inOptions->mOutput, "\tTotal:\t%10u\n", (unsigned)(modules[loop].mSize.mCode + modules[loop].mSize.mData));
583 fprintf(inOptions->mOutput, "\tCode:\t%10u\n", (unsigned)modules[loop].mSize.mCode);
584 fprintf(inOptions->mOutput, "\tData:\t%10u\n", (unsigned)modules[loop].mSize.mData);
586 CLEANUP(modules[loop].mModule);
590 ** Done with modules.
592 CLEANUP(modules);
593 moduleCount = 0;
597 return retval;
601 int initOptions(Options* outOptions, int inArgc, char** inArgv)
603 ** returns int 0 if successful.
606 int retval = 0;
607 int loop = 0;
608 int switchLoop = 0;
609 int match = 0;
610 const int switchCount = sizeof(gSwitches) / sizeof(gSwitches[0]);
611 Switch* current = NULL;
614 ** Set any defaults.
616 memset(outOptions, 0, sizeof(Options));
617 outOptions->mProgramName = inArgv[0];
618 outOptions->mInput = stdin;
619 outOptions->mInputName = strdup("stdin");
620 outOptions->mOutput = stdout;
621 outOptions->mOutputName = strdup("stdout");
622 outOptions->mMaxSize = 0xFFFFFFFFU;
624 if(NULL == outOptions->mOutputName || NULL == outOptions->mInputName)
626 retval = __LINE__;
627 ERROR_REPORT(retval, "stdin/stdout", "Unable to strdup.");
631 ** Go through and attempt to do the right thing.
633 for(loop = 1; loop < inArgc && 0 == retval; loop++)
635 match = 0;
636 current = NULL;
638 for(switchLoop = 0; switchLoop < switchCount && 0 == retval; switchLoop++)
640 if(0 == strcmp(gSwitches[switchLoop]->mLongName, inArgv[loop]))
642 match = __LINE__;
644 else if(0 == strcmp(gSwitches[switchLoop]->mShortName, inArgv[loop]))
646 match = __LINE__;
649 if(match)
651 if(gSwitches[switchLoop]->mHasValue)
654 ** Attempt to absorb next option to fullfill value.
656 if(loop + 1 < inArgc)
658 loop++;
660 current = gSwitches[switchLoop];
661 current->mValue = inArgv[loop];
664 else
666 current = gSwitches[switchLoop];
669 break;
673 if(0 == match)
675 outOptions->mHelp = __LINE__;
676 retval = __LINE__;
677 ERROR_REPORT(retval, inArgv[loop], "Unknown command line switch.");
679 else if(NULL == current)
681 outOptions->mHelp = __LINE__;
682 retval = __LINE__;
683 ERROR_REPORT(retval, inArgv[loop], "Command line switch requires a value.");
685 else
688 ** Do something based on address/swtich.
690 if(current == &gInputSwitch)
692 CLEANUP(outOptions->mInputName);
693 if(NULL != outOptions->mInput && stdin != outOptions->mInput)
695 fclose(outOptions->mInput);
696 outOptions->mInput = NULL;
699 outOptions->mInput = fopen(current->mValue, "r");
700 if(NULL == outOptions->mInput)
702 retval = __LINE__;
703 ERROR_REPORT(retval, current->mValue, "Unable to open input file.");
705 else
707 outOptions->mInputName = strdup(current->mValue);
708 if(NULL == outOptions->mInputName)
710 retval = __LINE__;
711 ERROR_REPORT(retval, current->mValue, "Unable to strdup.");
715 else if(current == &gOutputSwitch)
717 CLEANUP(outOptions->mOutputName);
718 if(NULL != outOptions->mOutput && stdout != outOptions->mOutput)
720 fclose(outOptions->mOutput);
721 outOptions->mOutput = NULL;
724 outOptions->mOutput = fopen(current->mValue, "a");
725 if(NULL == outOptions->mOutput)
727 retval = __LINE__;
728 ERROR_REPORT(retval, current->mValue, "Unable to open output file.");
730 else
732 outOptions->mOutputName = strdup(current->mValue);
733 if(NULL == outOptions->mOutputName)
735 retval = __LINE__;
736 ERROR_REPORT(retval, current->mValue, "Unable to strdup.");
740 else if(current == &gHelpSwitch)
742 outOptions->mHelp = __LINE__;
744 else if(current == &gModuleSwitch)
746 outOptions->mModules = __LINE__;
748 else if(current == &gTotalSwitch)
750 outOptions->mTotalOnly = __LINE__;
752 else if(current == &gMinSize)
754 unsigned long arg = 0;
755 char* endScan = NULL;
757 errno = 0;
758 arg = strtoul(current->mValue, &endScan, 0);
759 if(0 == errno && endScan != current->mValue)
761 outOptions->mMinSize = arg;
763 else
765 retval = __LINE__;
766 ERROR_REPORT(retval, current->mValue, "Unable to convert to a number.");
769 else if(current == &gMaxSize)
771 unsigned long arg = 0;
772 char* endScan = NULL;
774 errno = 0;
775 arg = strtoul(current->mValue, &endScan, 0);
776 if(0 == errno && endScan != current->mValue)
778 outOptions->mMaxSize = arg;
780 else
782 retval = __LINE__;
783 ERROR_REPORT(retval, current->mValue, "Unable to convert to a number.");
786 else if(current == &gMatchClass)
788 char* dupMatch = NULL;
790 dupMatch = strdup(current->mValue);
791 if(NULL != dupMatch)
793 void* moved = NULL;
795 moved = realloc(outOptions->mMatchClasses, sizeof(char*) * (outOptions->mMatchClassCount + 1));
796 if(NULL != moved)
798 outOptions->mMatchClasses = (char**)moved;
799 outOptions->mMatchClasses[outOptions->mMatchClassCount] = dupMatch;
800 outOptions->mMatchClassCount++;
802 else
804 retval = __LINE__;
805 ERROR_REPORT(retval, current->mLongName, "Unable to expand array.");
808 else
810 retval = __LINE__;
811 ERROR_REPORT(retval, current->mValue, "Unable to duplicate string.");
814 else if(current == &gMatchScope)
816 char* dupMatch = NULL;
818 dupMatch = strdup(current->mValue);
819 if(NULL != dupMatch)
821 void* moved = NULL;
823 moved = realloc(outOptions->mMatchScopes, sizeof(char*) * (outOptions->mMatchScopeCount + 1));
824 if(NULL != moved)
826 outOptions->mMatchScopes = (char**)moved;
827 outOptions->mMatchScopes[outOptions->mMatchScopeCount] = dupMatch;
828 outOptions->mMatchScopeCount++;
830 else
832 retval = __LINE__;
833 ERROR_REPORT(retval, current->mLongName, "Unable to expand array.");
836 else
838 retval = __LINE__;
839 ERROR_REPORT(retval, current->mValue, "Unable to duplicate string.");
842 else if(current == &gMatchModule)
844 char* dupMatch = NULL;
846 dupMatch = strdup(current->mValue);
847 if(NULL != dupMatch)
849 void* moved = NULL;
851 moved = realloc(outOptions->mMatchModules, sizeof(char*) * (outOptions->mMatchModuleCount + 1));
852 if(NULL != moved)
854 outOptions->mMatchModules = (char**)moved;
855 outOptions->mMatchModules[outOptions->mMatchModuleCount] = dupMatch;
856 outOptions->mMatchModuleCount++;
858 else
860 retval = __LINE__;
861 ERROR_REPORT(retval, current->mLongName, "Unable to expand array.");
864 else
866 retval = __LINE__;
867 ERROR_REPORT(retval, current->mValue, "Unable to duplicate string.");
870 else if(current == &gMatchSection)
872 char* dupMatch = NULL;
874 dupMatch = strdup(current->mValue);
875 if(NULL != dupMatch)
877 void* moved = NULL;
879 moved = realloc(outOptions->mMatchSections, sizeof(char*) * (outOptions->mMatchSectionCount + 1));
880 if(NULL != moved)
882 outOptions->mMatchSections = (char**)moved;
883 outOptions->mMatchSections[outOptions->mMatchSectionCount] = dupMatch;
884 outOptions->mMatchSectionCount++;
886 else
888 retval = __LINE__;
889 ERROR_REPORT(retval, current->mLongName, "Unable to expand array.");
892 else
894 retval = __LINE__;
895 ERROR_REPORT(retval, current->mValue, "Unable to duplicate string.");
898 else if(current == &gMatchObject)
900 char* dupMatch = NULL;
902 dupMatch = strdup(current->mValue);
903 if(NULL != dupMatch)
905 void* moved = NULL;
907 moved = realloc(outOptions->mMatchObjects, sizeof(char*) * (outOptions->mMatchObjectCount + 1));
908 if(NULL != moved)
910 outOptions->mMatchObjects = (char**)moved;
911 outOptions->mMatchObjects[outOptions->mMatchObjectCount] = dupMatch;
912 outOptions->mMatchObjectCount++;
914 else
916 retval = __LINE__;
917 ERROR_REPORT(retval, current->mLongName, "Unable to expand array.");
920 else
922 retval = __LINE__;
923 ERROR_REPORT(retval, current->mValue, "Unable to duplicate string.");
926 else if(current == &gMatchSymbol)
928 char* dupMatch = NULL;
930 dupMatch = strdup(current->mValue);
931 if(NULL != dupMatch)
933 void* moved = NULL;
935 moved = realloc(outOptions->mMatchSymbols, sizeof(char*) * (outOptions->mMatchSymbolCount + 1));
936 if(NULL != moved)
938 outOptions->mMatchSymbols = (char**)moved;
939 outOptions->mMatchSymbols[outOptions->mMatchSymbolCount] = dupMatch;
940 outOptions->mMatchSymbolCount++;
942 else
944 retval = __LINE__;
945 ERROR_REPORT(retval, current->mLongName, "Unable to expand array.");
948 else
950 retval = __LINE__;
951 ERROR_REPORT(retval, current->mValue, "Unable to duplicate string.");
954 else
956 retval = __LINE__;
957 ERROR_REPORT(retval, current->mLongName, "No handler for command line switch.");
962 return retval;
966 void cleanOptions(Options* inOptions)
968 ** Clean up any open handles.
971 unsigned loop = 0;
973 CLEANUP(inOptions->mInputName);
974 if(NULL != inOptions->mInput && stdin != inOptions->mInput)
976 fclose(inOptions->mInput);
978 CLEANUP(inOptions->mOutputName);
979 if(NULL != inOptions->mOutput && stdout != inOptions->mOutput)
981 fclose(inOptions->mOutput);
984 for(loop = 0; loop < inOptions->mMatchClassCount; loop++)
986 CLEANUP(inOptions->mMatchClasses[loop]);
988 CLEANUP(inOptions->mMatchClasses);
990 for(loop = 0; loop < inOptions->mMatchScopeCount; loop++)
992 CLEANUP(inOptions->mMatchScopes[loop]);
994 CLEANUP(inOptions->mMatchScopes);
996 for(loop = 0; loop < inOptions->mMatchModuleCount; loop++)
998 CLEANUP(inOptions->mMatchModules[loop]);
1000 CLEANUP(inOptions->mMatchModules);
1002 for(loop = 0; loop < inOptions->mMatchSectionCount; loop++)
1004 CLEANUP(inOptions->mMatchSections[loop]);
1006 CLEANUP(inOptions->mMatchSections);
1008 for(loop = 0; loop < inOptions->mMatchObjectCount; loop++)
1010 CLEANUP(inOptions->mMatchObjects[loop]);
1012 CLEANUP(inOptions->mMatchObjects);
1014 for(loop = 0; loop < inOptions->mMatchSymbolCount; loop++)
1016 CLEANUP(inOptions->mMatchSymbols[loop]);
1018 CLEANUP(inOptions->mMatchSymbols);
1020 memset(inOptions, 0, sizeof(Options));
1024 void showHelp(Options* inOptions)
1026 ** Show some simple help text on usage.
1029 int loop = 0;
1030 const int switchCount = sizeof(gSwitches) / sizeof(gSwitches[0]);
1031 const char* valueText = NULL;
1033 printf("usage:\t%s [arguments]\n", inOptions->mProgramName);
1034 printf("\n");
1035 printf("arguments:\n");
1037 for(loop = 0; loop < switchCount; loop++)
1039 if(gSwitches[loop]->mHasValue)
1041 valueText = " <value>";
1043 else
1045 valueText = "";
1048 printf("\t%s%s\n", gSwitches[loop]->mLongName, valueText);
1049 printf("\t %s%s", gSwitches[loop]->mShortName, valueText);
1050 printf(DESC_NEWLINE "%s\n\n", gSwitches[loop]->mDescription);
1053 printf("This tool takes a tsv file and reports composite code and data sizes.\n");
1057 int main(int inArgc, char** inArgv)
1059 int retval = 0;
1060 Options options;
1062 retval = initOptions(&options, inArgc, inArgv);
1063 if(options.mHelp)
1065 showHelp(&options);
1067 else if(0 == retval)
1069 retval = codesighs(&options);
1072 cleanOptions(&options);
1073 return retval;