1 /*------------------------------------------------------------\
2 |                                                             |
3 | This file is part of the Alliance CAD System Copyright      |
4 | (C) Laboratoire LIP6 - D�partement ASIM Universite P&M Curie|
5 |                                                             |
6 | Home page      : http://www-asim.lip6.fr/alliance/          |
7 | E-mail         : mailto:alliance-users@asim.lip6.fr       |
8 |                                                             |
9 | This progam is  free software; you can redistribute it      |
10 | and/or modify it under the  terms of the GNU Library General|
11 | Public License as published by the Free Software Foundation |
12 | either version 2 of the License, or (at your option) any    |
13 | later version.                                              |
14 |                                                             |
15 | Alliance VLSI  CAD System  is distributed  in the hope that |
16 | it  will be useful, but WITHOUT  ANY WARRANTY;              |
17 | without even the  implied warranty of MERCHANTABILITY or    |
18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General       |
19 | Public License for more details.                            |
20 |                                                             |
21 | You should have received a copy  of the GNU General Public  |
22 | License along with the GNU C Library; see the file COPYING. |
23 | If not, write to the Free Software Foundation, Inc.,        |
24 | 675 Mass Ave, Cambridge, MA 02139, USA.                     |
25 |                                                             |
26 \------------------------------------------------------------*/
27 # include <stdio.h>
28 # include <stdlib.h>
29 # include <string.h>
30 
31 # include <mut.h>
32 # include "aut.h"
33 
34 /*------------------------------------------------------------\
35 |                                                             |
36 |                       Aut Sort Compare                      |
37 |                                                             |
38 \------------------------------------------------------------*/
39 
SortCompare(ValueArray,Index1,Index2)40 long SortCompare( ValueArray, Index1, Index2 )
41 
42   long *ValueArray;
43   long  Index1;
44   long  Index2;
45 {
46   return( ValueArray[ Index2 ] - ValueArray[ Index1 ] );
47 }
48 
main(argc,argv)49 int main( argc, argv )
50 
51   int argc;
52   char **argv;
53 {
54   FILE *File;
55   long  Value;
56   char *Buffer;
57   char *ScanName;
58   long *ValueArray;
59   long *IndexArray;
60   long  SizeArray;
61   long  Index;
62 
63   if ( argc < 2 ) return( 0 );
64 
65   autenv();
66 
67   if ( !strcmp( argv[1], "-sort" ) )
68   {
69     File = fopen( argv[2], "r" );
70 
71     if ( File != (FILE *)0 )
72     {
73       Buffer = autallocblock( 1024 );
74       Value  = 0;
75       Index  = -1;
76 
77       while ( fgets( Buffer, 1024, File ) != (char *)0 )
78       {
79         Value = atoi( Buffer );
80 
81         if ( Index == -1 )
82         {
83           SizeArray  = Value;
84           ValueArray = (long *)autallocblock( sizeof( long ) * SizeArray );
85           IndexArray = (long *)autallocblock( sizeof( long ) * SizeArray );
86           Index      = 0;
87         }
88         else
89         {
90           ValueArray[ Index++ ] = Value;
91         }
92       }
93 
94       fclose( File );
95 
96       sortautarray( ValueArray, IndexArray, SizeArray, 0 );
97 
98       for ( Index = 0; Index < SizeArray; Index++ )
99       {
100         fprintf( stdout, "%ld\n", ValueArray[ IndexArray[ Index ] ] );
101       }
102     }
103   }
104   else
105   if ( !strcmp( argv[1], "-namealloc" ) )
106   {
107     Buffer = autallocblock( 1024 );
108 
109     while ( fgets( Buffer, 1024, stdin ) != (char *)0 )
110     {
111       ScanName = strchr( Buffer, '\n' );
112       if ( ScanName != (char *)0 ) *ScanName = '\0';
113 
114       ScanName = autnamealloc( Buffer );
115       fprintf( stdout, "%s %lx\n", ScanName, (long)ScanName );
116     }
117   }
118 
119   return( 0 );
120 }
121