Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1498 serge 1
 
2
 *
3
 * Module Name: ascase - Source conversion - lower/upper case utilities
4
 *
5
 *****************************************************************************/
6
7
 
8
 *
9
 * 1. Copyright Notice
10
 *
11
 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12
 * All rights reserved.
13
 *
14
 * 2. License
15
 *
16
 * 2.1. This is your license from Intel Corp. under its intellectual property
17
 * rights.  You may have additional license terms from the party that provided
18
 * you this software, covering your right to use that party's intellectual
19
 * property rights.
20
 *
21
 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22
 * copy of the source code appearing in this file ("Covered Code") an
23
 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24
 * base code distributed originally by Intel ("Original Intel Code") to copy,
25
 * make derivatives, distribute, use and display any portion of the Covered
26
 * Code in any form, with the right to sublicense such rights; and
27
 *
28
 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29
 * license (with the right to sublicense), under only those claims of Intel
30
 * patents that are infringed by the Original Intel Code, to make, use, sell,
31
 * offer to sell, and import the Covered Code and derivative works thereof
32
 * solely to the minimum extent necessary to exercise the above copyright
33
 * license, and in no event shall the patent license extend to any additions
34
 * to or modifications of the Original Intel Code.  No other license or right
35
 * is granted directly or by implication, estoppel or otherwise;
36
 *
37
 * The above copyright and patent license is granted only if the following
38
 * conditions are met:
39
 *
40
 * 3. Conditions
41
 *
42
 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43
 * Redistribution of source code of any substantial portion of the Covered
44
 * Code or modification with rights to further distribute source must include
45
 * the above Copyright Notice, the above License, this list of Conditions,
46
 * and the following Disclaimer and Export Compliance provision.  In addition,
47
 * Licensee must cause all Covered Code to which Licensee contributes to
48
 * contain a file documenting the changes Licensee made to create that Covered
49
 * Code and the date of any change.  Licensee must include in that file the
50
 * documentation of any changes made by any predecessor Licensee.  Licensee
51
 * must include a prominent statement that the modification is derived,
52
 * directly or indirectly, from Original Intel Code.
53
 *
54
 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55
 * Redistribution of source code of any substantial portion of the Covered
56
 * Code or modification without rights to further distribute source must
57
 * include the following Disclaimer and Export Compliance provision in the
58
 * documentation and/or other materials provided with distribution.  In
59
 * addition, Licensee may not authorize further sublicense of source of any
60
 * portion of the Covered Code, and must include terms to the effect that the
61
 * license from Licensee to its licensee is limited to the intellectual
62
 * property embodied in the software Licensee provides to its licensee, and
63
 * not to intellectual property embodied in modifications its licensee may
64
 * make.
65
 *
66
 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67
 * substantial portion of the Covered Code or modification must reproduce the
68
 * above Copyright Notice, and the following Disclaimer and Export Compliance
69
 * provision in the documentation and/or other materials provided with the
70
 * distribution.
71
 *
72
 * 3.4. Intel retains all right, title, and interest in and to the Original
73
 * Intel Code.
74
 *
75
 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76
 * Intel shall be used in advertising or otherwise to promote the sale, use or
77
 * other dealings in products derived from or relating to the Covered Code
78
 * without prior written authorization from Intel.
79
 *
80
 * 4. Disclaimer and Export Compliance
81
 *
82
 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83
 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84
 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85
 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86
 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87
 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88
 * PARTICULAR PURPOSE.
89
 *
90
 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91
 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92
 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93
 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94
 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95
 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96
 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97
 * LIMITED REMEDY.
98
 *
99
 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100
 * software or system incorporating such software without first obtaining any
101
 * required license or other approval from the U. S. Department of Commerce or
102
 * any other agency or department of the United States Government.  In the
103
 * event Licensee exports any such software from the United States or
104
 * re-exports any such software from a foreign destination, Licensee shall
105
 * ensure that the distribution and export/re-export of the software is in
106
 * compliance with all laws, regulations, orders, or other restrictions of the
107
 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108
 * any of its subsidiaries will export/re-export any technical data, process,
109
 * software, or service, directly or indirectly, to any country for which the
110
 * United States government or any agency thereof requires an export license,
111
 * other governmental approval, or letter of assurance, without first obtaining
112
 * such license, approval or letter.
113
 *
114
 *****************************************************************************/
115
116
 
117
118
 
119
120
 
121
AsUppercaseTokens (
122
    char                    *Buffer,
123
    char                    *PrefixString);
124
125
 
126
 
127
 *
128
 * FUNCTION:    AsLowerCaseString
129
 *
130
 * DESCRIPTION: LowerCase all instances of a target string with a replacement
131
 *              string.  Returns count of the strings replaced.
132
 *
133
 ******************************************************************************/
134
135
 
136
AsLowerCaseString (
137
    char                    *Target,
138
    char                    *Buffer)
139
{
140
    char                    *SubString1;
141
    char                    *SubString2;
142
    char                    *SubBuffer;
143
    int                     TargetLength;
144
    int                     LowerCaseCount = 0;
145
    int                     i;
146
147
 
148
 
149
150
 
151
    SubString1 = Buffer;
152
153
 
154
    {
155
        /* Find the target string */
156
157
 
158
        if (!SubString1)
159
        {
160
            return LowerCaseCount;
161
        }
162
163
 
164
         * Check for translation escape string -- means to ignore
165
         * blocks of code while replacing
166
         */
167
        SubString2 = strstr (SubBuffer, AS_START_IGNORE);
168
169
 
170
            (SubString2 < SubString1))
171
        {
172
            /* Find end of the escape block starting at "Substring2" */
173
174
 
175
            if (!SubString2)
176
            {
177
                /* Didn't find terminator */
178
179
 
180
            }
181
182
 
183
184
 
185
        }
186
187
 
188
189
 
190
        {
191
            if (!AsMatchExactWord (SubString1, TargetLength))
192
            {
193
                SubBuffer = SubString1 + 1;
194
                continue;
195
            }
196
197
 
198
            {
199
                SubString1[i] = (char) tolower ((int) SubString1[i]);
200
            }
201
202
 
203
204
 
205
            {
206
                if ((SubBuffer[0] == ' ') && (SubBuffer[1] == ' '))
207
                {
208
                    AsInsertData (SubBuffer, "        ", 8);
209
                }
210
            }
211
212
 
213
        }
214
    }
215
216
 
217
}
218
219
 
220
 
221
 *
222
 * FUNCTION:    AsMixedCaseToUnderscores
223
 *
224
 * DESCRIPTION: Converts mixed case identifiers to underscored identifiers.
225
 *              for example,
226
 *
227
 *              ThisUsefullyNamedIdentifier   becomes:
228
 *
229
 *              this_usefully_named_identifier
230
 *
231
 ******************************************************************************/
232
233
 
234
AsMixedCaseToUnderscores (
235
    char                    *Buffer)
236
{
237
    UINT32                  Length;
238
    char                    *SubBuffer = Buffer;
239
    char                    *TokenEnd;
240
    char                    *TokenStart = NULL;
241
    char                    *SubString;
242
    BOOLEAN                 HasLowerCase = FALSE;
243
244
 
245
 
246
    {
247
        /* Ignore whitespace */
248
249
 
250
        {
251
            while (*SubBuffer == ' ')
252
            {
253
                SubBuffer++;
254
            }
255
            TokenStart = NULL;
256
            HasLowerCase = FALSE;
257
            continue;
258
        }
259
260
 
261
262
 
263
            (*SubBuffer == '>') ||
264
            (*SubBuffer == ')'))
265
        {
266
            SubBuffer++;
267
            TokenStart = NULL;
268
            HasLowerCase = FALSE;
269
            continue;
270
        }
271
272
 
273
274
 
275
        {
276
            SubBuffer++;
277
            while (*SubBuffer != '"')
278
            {
279
                if (!*SubBuffer)
280
                {
281
                    return;
282
                }
283
284
 
285
286
 
287
                {
288
                    SubBuffer++;
289
                }
290
                SubBuffer++;
291
            }
292
            SubBuffer++;
293
            continue;
294
        }
295
296
 
297
        {
298
            HasLowerCase = TRUE;
299
        }
300
301
 
302
         * Check for translation escape string -- means to ignore
303
         * blocks of code while replacing
304
         */
305
        if ((SubBuffer[0] == '/') &&
306
            (SubBuffer[1] == '*') &&
307
            (SubBuffer[2] == '!'))
308
        {
309
            SubBuffer = strstr (SubBuffer, "!*/");
310
            if (!SubBuffer)
311
            {
312
                return;
313
            }
314
            continue;
315
        }
316
317
 
318
319
 
320
        {
321
            if ((SubBuffer[1] == 'x') ||
322
                (SubBuffer[1] == 'X'))
323
            {
324
                SubBuffer += 2;
325
                while (isxdigit ((int) *SubBuffer))
326
                {
327
                    SubBuffer++;
328
                }
329
                continue;
330
            }
331
        }
332
333
 
334
#if 0
335
        /* Ignore format specification fields */
336
337
 
338
        {
339
            SubBuffer++;
340
341
 
342
            {
343
                SubBuffer++;
344
            }
345
346
 
347
        }
348
#endif
349
350
 
351
352
 
353
        {
354
            SubBuffer += 2;
355
            continue;
356
        }
357
358
 
359
         * Ignore identifiers that already contain embedded underscores
360
         * These are typically C macros or defines (all upper case)
361
         * Note: there are some cases where identifiers have underscores
362
         * AcpiGbl_* for example. HasLowerCase flag handles these.
363
         */
364
        if ((*SubBuffer == '_') && (!HasLowerCase) && (TokenStart))
365
        {
366
            /* Check the rest of the identifier for any lower case letters */
367
368
 
369
            while ((isalnum ((int) *SubString)) || (*SubString == '_'))
370
            {
371
                if (islower ((int) *SubString))
372
                {
373
                    HasLowerCase = TRUE;
374
                }
375
                SubString++;
376
            }
377
378
 
379
380
 
381
            {
382
                SubBuffer = SubString;
383
                continue;
384
            }
385
        }
386
387
 
388
389
 
390
        {
391
            TokenStart = SubBuffer;
392
        }
393
394
 
395
         * Convert each pair of letters that matches the form:
396
         *
397
         *      
398
         * to
399
         *      
400
         */
401
        else if ((islower ((int) SubBuffer[0]) || isdigit ((int) SubBuffer[0])) &&
402
                 (isupper ((int) SubBuffer[1])))
403
        {
404
            if (isdigit ((int) SubBuffer[0]))
405
            {
406
                /* Ignore  */
407
                /* Ignore  */
408
409
 
410
                    *(SubBuffer-1) == '_')
411
                {
412
                    SubBuffer++;
413
                    continue;
414
                }
415
            }
416
417
 
418
             * Matched the pattern.
419
             * Find the end of this identifier (token)
420
             */
421
            TokenEnd = SubBuffer;
422
            while ((isalnum ((int) *TokenEnd)) || (*TokenEnd == '_'))
423
            {
424
                TokenEnd++;
425
            }
426
427
 
428
429
 
430
            SubBuffer[1] = (char) tolower ((int) SubBuffer[1]);
431
432
 
433
            Length = 0;
434
435
 
436
            {
437
                /*
438
                 * If we have at least two trailing spaces, we can get rid of
439
                 * one to make up for the newly inserted underscore.  This will
440
                 * help preserve the alignment of the text
441
                 */
442
                if ((SubString[0] == ' ') &&
443
                    (SubString[1] == ' '))
444
                {
445
                    Length = SubString - SubBuffer - 2;
446
                    break;
447
                }
448
449
 
450
            }
451
452
 
453
            {
454
                Length = strlen (&SubBuffer[1]);
455
            }
456
457
 
458
            SubBuffer[1] = '_';
459
            SubBuffer +=2;
460
461
 
462
463
 
464
            {
465
                *TokenStart = (char) tolower ((int) *TokenStart);
466
                TokenStart = NULL;
467
            }
468
        }
469
470
 
471
    }
472
}
473
474
 
475
 
476
 *
477
 * FUNCTION:    AsLowerCaseIdentifiers
478
 *
479
 * DESCRIPTION: Converts mixed case identifiers to lower case.  Leaves comments,
480
 *              quoted strings, and all-upper-case macros alone.
481
 *
482
 ******************************************************************************/
483
484
 
485
AsLowerCaseIdentifiers (
486
    char                    *Buffer)
487
{
488
    char                    *SubBuffer = Buffer;
489
490
 
491
 
492
    {
493
        /*
494
         * Check for translation escape string -- means to ignore
495
         * blocks of code while replacing
496
         */
497
        if ((SubBuffer[0] == '/') &&
498
            (SubBuffer[1] == '*') &&
499
            (SubBuffer[2] == '!'))
500
        {
501
            SubBuffer = strstr (SubBuffer, "!*/");
502
            if (!SubBuffer)
503
            {
504
                return;
505
            }
506
        }
507
508
 
509
510
 
511
            (SubBuffer[1] == '*'))
512
        {
513
            SubBuffer = strstr (SubBuffer, "*/");
514
            if (!SubBuffer)
515
            {
516
                return;
517
            }
518
519
 
520
        }
521
522
 
523
524
 
525
        {
526
            SubBuffer++;
527
528
 
529
530
 
531
            {
532
                /* Ignore escaped quote characters */
533
534
 
535
                {
536
                    SubBuffer++;
537
                }
538
                else if (SubBuffer[0] == '\"')
539
                {
540
                    SubBuffer++;
541
                    break;
542
                }
543
                SubBuffer++;
544
            }
545
        }
546
547
 
548
        {
549
            return;
550
        }
551
552
 
553
         * Only lower case if we have an upper followed by a lower
554
         * This leaves the all-uppercase things (macros, etc.) intact
555
         */
556
        if ((isupper ((int) SubBuffer[0])) &&
557
            (islower ((int) SubBuffer[1])))
558
        {
559
            Gbl_MadeChanges = TRUE;
560
            *SubBuffer = (char) tolower ((int) *SubBuffer);
561
        }
562
563
 
564
    }
565
}
566
567
 
568
 
569
 *
570
 * FUNCTION:    AsUppercaseTokens
571
 *
572
 * DESCRIPTION: Force to uppercase all tokens that begin with the prefix string.
573
 *              used to convert mixed-case macros and constants to uppercase.
574
 *
575
 ******************************************************************************/
576
577
 
578
AsUppercaseTokens (
579
    char                    *Buffer,
580
    char                    *PrefixString)
581
{
582
    char                    *SubBuffer;
583
    char                    *TokenEnd;
584
    char                    *SubString;
585
    int                     i;
586
    UINT32                  Length;
587
588
 
589
 
590
591
 
592
    {
593
        SubBuffer = strstr (SubBuffer, PrefixString);
594
        if (SubBuffer)
595
        {
596
            TokenEnd = SubBuffer;
597
            while ((isalnum ((int) *TokenEnd)) || (*TokenEnd == '_'))
598
            {
599
                TokenEnd++;
600
            }
601
602
 
603
            {
604
                if ((islower ((int) SubBuffer[i])) &&
605
                    (isupper ((int) SubBuffer[i+1])))
606
                {
607
608
 
609
                    Length = 0;
610
611
 
612
                    {
613
                        if ((SubString[0] == ' ') &&
614
                            (SubString[1] == ' '))
615
                        {
616
                            Length = SubString - &SubBuffer[i] - 2;
617
                            break;
618
                        }
619
620
 
621
                    }
622
623
 
624
                    {
625
                        Length = strlen (&SubBuffer[i+1]);
626
                    }
627
628
 
629
                    SubBuffer[i+1] = '_';
630
                    i +=2;
631
                    TokenEnd++;
632
                }
633
            }
634
635
 
636
            {
637
                SubBuffer[i] = (char) toupper ((int) SubBuffer[i]);
638
            }
639
640
 
641
        }
642
    }
643
}
644