OSDN Git Service

Merge remote-tracking branch 'refs/remotes/origin/master'
[eos/base.git] / sbin / makegeneral
1 #
2 # %M% %Y% %I%
3 #
4 # The latest update : %G% at %U%
5 #
6 #%Z% create a new named one
7 #%Z%
8 #
9 #%Z% Usage : makegeneral [Action] [World] [ClassName] [ObjectName]
10 #
11 #%Z% Attention
12 #%Z%
13 #%Z% Parameter: 
14 #%Z%     Essential:
15 #%Z%        Action          :
16 #%Z%        World           : Tools | Objects 
17 #%Z%        ClassName 
18 #%Z%        ObjectName 
19 #%Z% Optional:
20
21 WorldHomeDir=${EOS_HOME}/src
22 ObjectClassHomeDir=${WorldHomeDir}/Objects
23 ToolClassHomeDir=${WorldHomeDir}/Tools
24 AnotherWorldHomeDir=${EOS_ANOTHER_HOME}/src
25 AnotherObjectClassHomeDir=${AnotherWorldHomeDir}/Objects
26 AnotherToolClassHomeDir=${AnotherWorldHomeDir}/Tools
27
28 TemplateDir=${WorldHomeDir}/Config/Template
29
30 ToolHomeTemplate=${TemplateDir}/ToolsHomeTemplate.Dir
31 ToolClassTemplate=${TemplateDir}/ToolsClassTemplate.Dir
32 ToolTemplate=${TemplateDir}/ToolsTemplate.Dir
33
34 ObjectHomeTemplate=${TemplateDir}/ObjectsHomeTemplate.Dir
35 ObjectClassTemplate=${TemplateDir}/ObjectsClassTemplate.Dir
36 ObjectTemplate=${TemplateDir}/ObjectsTemplate.Dir
37
38 ##
39 #%Z% usage():Show Usage
40 ## No required argument
41 ##
42 usage()
43 {
44         echo "Usage:makegeneral [World] [ClassName] [ObjectName] [Action] [NoAns]"
45         exit
46 }
47
48 ##
49 #%Z% NameList():Show directory names except for Config/
50 ## Required arguments 
51 ##    $1:Name of directory including named ones  
52 ##
53 NameList()
54 {
55         Full=$1
56         echo ${Full}
57         ls -1F ${Full} | awk '
58                 BEGIN {
59                         i=0;
60                 } 
61                 $0 !~ /Config/ && /\// {
62                         i++; 
63                         gsub(/\//, ""); 
64                         printf("> %s\n", $0);
65                 }'
66 }
67
68 ##
69 #%Z% NameShow():Show a implemented list of tools/objects/classes
70 ##    $1: full pathname of directory including named tools/objects/classes
71 ##    $2: Tools | Objects | Class
72 ##
73 NameShow()
74 {
75         Full=$1
76         Target=$2
77         echo "Presently-implemented ${Target}"
78         NameList ${Full} > ${Full}/Config/Source.lst
79         cat ${Full}/Config/Source.lst
80 }
81
82 ##
83 #%Z% NameRead():Read name of one to treat
84 ##    $1: full pathname of directory including named ones  
85 ##    $2: Tools | Objects | Class
86 ##    
87 ## Output Variables
88 ##    Name : Name which was read
89 ##    ans  : "Y"
90 NameRead()
91 {
92         Full=$1
93         Target=$2
94
95         ans="N"
96         while [ $ans != "Y" -a $ans != "y" ] 
97         do
98                 NameShow ${Full} ${Target}
99                 echo "Enter ${Target} Name?"
100                 read Name
101                 if [ -d ${Full}/${Name} ]
102                 then
103                         echo  "${Name} is a implemented ${Target}."
104                 else
105                         echo  "${Name} is a new ${Target}!!"
106                 fi
107                 ans="N"; echo "${Name} is OK(y/n)?"
108                 read ans
109         done
110 }
111
112 #%Z% genDirCheckAndMake():
113 ##    $1: full pathname of directory including named ones  
114 ##    $2: Name 
115 ## Output Variables
116 ##    Name  : Name which was checked and made
117 ##    ans   : "Y"
118 genDirCheckAndMake()
119 {
120         Full=$1
121         Name=$2
122         if [ -d ${Full}/${Name} ]
123         then
124                 echo "${Name}: Implemented"
125         else
126                 mkdir ${Full}/${Name}
127         fi
128 }
129 #%Z% DirCheckAndMake():
130 ##    $1: full pathname of directory including named ones  
131 ##    $2: Name 
132 ##    $3: Tools | Objects | Class
133 ## Output Variables
134 ##    Name  : Name which was checked and made
135 ##    ans   : "Y"
136 ##    Full  :
137 ##    World :
138 ##    
139 DirCheckAndMake()
140 {
141         Full=$1
142         Name=$2
143         Which=$3
144         ans="N"
145         while [ $ans != "Y" -a $ans != "y" ]
146         do 
147                 ans="Y"
148                 genDirCheckAndMake ${Full} ${Name}
149                 genDirCheckAndMake ${Full} ${Name}/Config 
150         done
151 }
152 ##
153 ## World
154 ##
155 WorldNameShow()
156 {
157         case ${Action} in 
158                 Another|AnotherFollowingControlFile)
159                         NameShow ${AnotherWorldHomeDir} World
160                         ;;
161                 All|AllFollowingControlFile)
162                         NameShow ${WorldHomeDir} World
163                         ;;
164                 *)
165                         echo "Not Supported Action: ${Action}"
166                         exit
167                         ;;
168         esac
169 }
170
171 WorldNameRead()
172 {
173         case ${Action} in 
174                 Another|AnotherFollowingControlFile)
175                         NameRead ${AnotherWorldHomeDir} World
176                         ;;
177                 All|AllFollowingControlFile)
178                         NameRead ${WorldHomeDir} World
179                         ;;
180                 *)
181                         echo "Not Supported Action: ${Action}"
182                         exit
183                         ;;
184         esac
185         World=${Name}
186 }
187
188 WorldDirCheckAndMake() 
189 {
190         case ${Action} in 
191                 Another|AnotherFollowingControlFile)
192                         DirCheckAndMake ${AnotherWorldHomeDir} ${World} World
193                         ;;
194                 All|AllFollowingControlFile)
195                         DirCheckAndMake ${WorldHomeDir} ${World} World
196                         ;;
197                 *)
198                         echo "Not Supported Action: ${Action}"
199                         exit
200                         ;;
201         esac
202         World=${Name}
203 }
204
205 ##
206 ## Object Class
207 ##
208 ObjectClassNameShow()
209 {
210         case ${Action} in 
211                 Another|AnotherFollowingControlFile)
212                         NameShow ${AnotherObjectClassHomeDir} Class
213                         ;;
214                 All|AllFollowingControlFile)
215                         NameShow ${ObjectClassHomeDir} Class
216                         ;;
217                 *)
218                         echo "Not Supported Action: ${Action}"
219                         exit
220                         ;;
221         esac
222 }
223
224 ObjectClassNameRead()
225 {
226         case ${Action} in 
227                 Another|AnotherFollowingControlFile)
228                         NameRead ${AnotherObjectClassHomeDir} Class
229                         ;;
230                 All|AllFollowingControlFile)
231                         NameRead ${ObjectClassHomeDir} Class
232                         ;;
233                 *)
234                         echo "Not Supported Action: ${Action}"
235                         exit
236                         ;;
237         esac
238         ClassName=${Name}
239 }
240
241 ObjectClassDirCheckAndMake()
242 {
243         case ${Action} in 
244                 Another|AnotherFollowingControlFile)
245                         DirCheckAndMake ${AnotherObjectClassHomeDir} ${ClassName} Class
246                         ;;
247                 All|AllFollowingControlFile)
248                         DirCheckAndMake ${ObjectClassHomeDir} ${ClassName} Class
249                         ;;
250                 *)
251                         echo "Not Supported Action: ${Action}"
252                         exit
253                         ;;
254         esac
255         ClassName=${Name}
256 }
257
258 ##
259 ## Object
260 ##
261 ObjectNameShow()
262 {
263         NameShow ${ObjectClassHomeDir}/${ClassName} Objects
264 }
265
266 ObjectNameRead()
267 {
268         NameRead ${ObjectClassHomeDir}/${ClassName} Objects
269         ObjectName=${Name}
270 }
271
272 ObjectDirCheckAndMake()
273 {
274         DirCheckAndMake ${ObjectClassHomeDir}/${ClassName} ${ObjectName} Objects
275         ObjectName=${Name}
276 }
277
278 ##
279 ## Tool Class
280 ##
281 ToolClassNameShow()
282 {
283         case ${Action} in 
284                 Another|AnotherFollowingControlFile)
285                         NameShow ${AnotherToolClassHomeDir} Class
286                         ;;
287                 All|AllFollowingControlFile)
288                         NameShow ${ToolClassHomeDir} Class
289                         ;;
290                 *)
291                         echo "Not Supported Action: ${Action}"
292                         exit
293                         ;;
294         esac
295 }
296
297 ToolClassNameRead()
298 {
299         case ${Action} in 
300                 Another|AnotherFollowingControlFile)
301                         NameRead ${AnotherToolClassHomeDir} Class
302                         ;;
303                 All|AllFollowingControlFile)
304                         NameRead ${ToolClassHomeDir} Class
305                         ;;
306                 *)
307                         echo "Not Supported Action: ${Action}"
308                         exit
309                         ;;
310         esac
311         ClassName=${Name}
312 }
313
314 ToolClassDirCheckAndMake()
315 {
316         case ${Action} in 
317                 Another|AnotherFollowingControlFile)
318                         DirCheckAndMake ${AnotherToolClassHomeDir} ${ClassName} Class
319                         ;;
320                 All|AllFollowingControlFile)
321                         DirCheckAndMake ${ToolClassHomeDir} ${ClassName} Class
322                         ;;
323                 *)
324                         echo "Not Supported Action: ${Action}"
325                         exit
326                         ;;
327         esac
328         ClassName=${Name}
329 }
330
331 ##
332 ## Tool
333 ##
334 ToolNameShow()
335 {
336         NameShow ${ToolClassHomeDir}/${ClassName} Tools
337 }
338
339 ToolNameRead()
340 {
341         case ${Action} in 
342                 Another|AnotherFollowingControlFile)
343                         NameRead ${AnotherToolClassHomeDir}/${ClassName} Tools
344                         ;;
345                 All|AllFollowingControlFile)
346                         NameRead ${ToolClassHomeDir}/${ClassName} Tools
347                         ;;
348                 *)
349                         echo "Not Supported Action: ${Action}"
350                         exit
351                         ;;
352         esac
353         ToolName=${Name}
354 }
355
356 ToolDirCheckAndMake()
357 {
358         case ${Action} in 
359                 Another|AnotherFollowingControlFile)
360                         DirCheckAndMake ${AnotherToolClassHomeDir}/${ClassName} ${ToolName} Tools
361                         ;;
362                 All|AllFollowingControlFile)
363                         DirCheckAndMake ${ToolClassHomeDir}/${ClassName} ${ToolName} Tools
364                         ;;
365                 *)
366                         echo "Not Supported Action: ${Action}"
367                         exit
368                         ;;
369         esac
370         ToolName=${Name}
371 }
372
373 ##
374 ## Action
375 ##
376 ActionRead()
377 {
378         echo ">>>> ${Action} <<<<"
379         case ${Action} in
380                 All|Another|AllFollowingControlFile|AnotherFollowingControlFile)
381                         case ${World} in
382                                 unknown)
383                                         WorldNameRead
384                                         WorldDirCheckAndMake
385                                         ;;
386                                 Tools)
387                                         ;;
388                                 Objects)
389                                         ;;
390                                 *)
391                                         echo "Not Supported World : ${World}"
392                                         exit;
393                                 ;;
394                         esac
395                         ;;
396                 Tools)
397                         World=Tools
398                         ToolActionRead
399                         ;;
400                 Objects)
401                         World=Objects
402                         ObjectActionRead
403                         ;;
404                 *)
405                         echo "Not Supproted World : ${World}"
406                         exit
407                         ;;
408         esac
409 }
410
411 ToolActionRead()
412 {
413         echo "Supported Action"
414         echo "  0: Create a new tool on Eos."
415         echo "  1: Update a tool     on Eos."
416         echo "  2: Create a new tool on another Eos."
417         echo "  3: Update a tool     on another Eos."
418         echo "  4: Create a new tool on Eos (C++)."
419         echo "  5: Update a tool     on Eos (C++)."
420         echo "  6: Create a new tool on another Eos (C++)."
421         echo "  7: Update a tool     on another Eos (C++)."
422         echo "  8: Create a new tool on Eos (shell)."
423         echo "  9: Update a tool     on Eos (shell)."
424         echo " 10: Create a new tool on another Eos (shell)."
425         echo " 11: Update a tool     on another Eos (shell)."
426         echo " 99: exit"
427         echo "Which action do you want to select ? (number)"
428         read Ans
429         case $Ans in
430                 0)
431                         Action="All"
432                         ;;
433                 1)
434                         Action="AllFollowingControlFile"
435                         ;;
436                 2)
437                         Action="Another"
438                         ;;
439                 3) 
440                         Action="AnotherFollowingControlFile"
441                         ;;
442                 4)
443                         Action="AllCC"
444                         ;;
445                 5)
446                         Action="AllFollowingControlFileCC"
447                         ;;
448                 6)
449                         Action="AnotherCC"
450                         ;;
451                 7) 
452                         Action="AnotherFollowingControlFileCC"
453                         ;;
454                 8)
455                         Action="AllShell"
456                         ;;
457                 9)
458                         Action="AllFollowingControlFileShell"
459                         ;;
460                 10)
461                         Action="AnotherShell"
462                         ;;
463                 11) 
464                         Action="AnotherFollowingControlFileShell"
465                         ;;
466                 99)
467                         exit
468                         ;;
469                 *)
470                         echo "Not supported action"
471                         ToolActionRead
472                         ;;
473         esac
474 }
475 ##
476 ##
477 ObjectActionRead()
478 {
479         echo "Supported Action"
480         echo "  0: Create a new object on Eos"
481         echo "  1: Create a new object on another Eos"
482         echo " 99: exit"
483         echo "Which action do you want to select ? (number)"
484         read Ans
485         case $Ans in
486                 0)
487                         Action="All"
488                         ;;
489                 1)
490                         Action="Another"
491                         ;;
492                 99)
493                         exit
494                         ;;
495                 *)
496                         echo "Not supported action"
497                         ObjectActionRead
498                         ;;
499         esac
500 }
501
502 ##
503 #%Z% NewNameAddToMakefile
504 ##    $1: fullpathname of Makefile
505 ##    $2: name of named one
506 ##    $3: Class | Objects | Tools
507 ##
508 NewNameAddToMakefile()
509 {
510         Full=$1
511         Target=$2
512         World=$3
513         echo "${Target} is added as a new ${World}!!"
514         mv ${Full} ${Full}.org
515         cat ${Full}.org | awk -v Name=${Target} '
516                 $0 ~ /#LastSource/ {
517                         printf("\t%s \\\n",Name);
518                         print $0;
519                 } 
520                 $0 !~ /#LastSource/ {
521                         print $0;
522                 }
523         ' > ${Full}
524 }
525
526 #
527 # Object
528 #
529 ObjectClassDirModifyFollowingAction()
530 {
531         case ${Action} in
532                 All)
533                         ObjectClassHome=${EOS_HOME}/src/Objects/
534                         ;;
535                 Another)
536                         echo "AnotherHome is ${AnotherHome}. Is it OK ?"
537                         read ans
538                         case $ans in
539                                 Y|y)
540                                         ;;
541                                 *)
542                                         exit
543                                         ;;
544                         esac
545                         for dir in src bin doc sccs src/Objects
546                         do
547                                 if [ -d ${AnotherHome}/${dir} ]
548                                 then
549                                         echo "AnotherHome/${dir} : implemented."
550                                 else
551                                         mkdir ${AnotherHome}/${dir}
552                                 fi
553                         done
554                         rm -f ${AnotherHome}/src/Config
555                         #ln -s ${EOS_HOME}/src/Config ${AnotherHome}/src/Config
556                         cp -r ${EOS_HOME}/src/Config ${AnotherHome}/src/Config
557                         ObjectClassHome=${AnotherHome}/src/Objects
558                         ;;
559                 *)
560                         echo "Not Supported Action: ${Action}"
561                         exit
562                         ;;
563         esac
564         cd ${ObjectClassHome}
565         if [ -f ./Makefile ] 
566         then
567                 echo "Makefile : implemented."
568         else
569                 echo "A new Makefile is created"
570                 cp ${ObjectHomeTemplate}/Makefile ./Makefile
571         fi
572         OldClass=`cat ./Makefile | awk -v Name=${ClassName} '{ if($1==Name) print $1} ' `
573         if [ ${OldClass} ] 
574         then
575                 echo "${OldClass} : implemented in Objects/Makefile"
576         else
577                 NewNameAddToMakefile ./Makefile ${ClassName} Class
578         fi
579         fullClassDir=${EOS_HOME}/src/Objects/${ClassName}
580         if [ -d ${fullClassDir} ] 
581         then
582                 echo "Objects/${ClassName} : implemented."
583         else
584                 mkdir ${fullClassDir}
585         fi
586         if [ -d ${fullClassDir}/Config ] 
587         then
588                 echo "Objects/${ClassName}/Config : implemented."
589         else
590                 mkdir ${fullClassDir}/Config
591         fi
592         cp -r ${EOS_HOME}/src/Config/Template/ObjectHomeTemplate.Dir/Config ${fullClassDir}
593 }
594
595 ObjectDirModifyFollowingAction()
596 {
597         case ${Action} in
598                 All)
599                         ObjectHome=${EOS_HOME}/src/Objects/${ClassName}
600                         ;;
601                 Another)
602                         ObjectHome=${Another}/src/Objects/${ClassName}
603                         ;;
604                 *)
605                         echo "Not Supported Action: ${Action}"
606                         exit
607                         ;;
608         esac
609         cd ${ObjectHome}
610         if [ -f ./Makefile ] 
611         then
612                 echo "Makefile : implemented."
613         else
614                 echo "A new Makefile is created"
615                 cp ${ObjectClassTemplate}/Makefile ./Makefile
616         fi
617         OldClass=`cat ./Makefile | awk -v Name=${ObjectName} '{ if($1==Name) print $1} ' `
618
619         if [ ${OldClass} ] 
620         then
621                 echo "${OldClass} : implemented in Objects/${ClassName}/Makefile."
622         else
623                 NewNameAddToMakefile ./Makefile ${ObjectName} Objects
624         fi      
625         fullObjectDir=${EOS_HOME}/src/Objects/${ClassName}/${ObjectName}
626
627         case ${Action} in 
628                 All)
629                         if [ -d ${fullObjectDir} ]
630                         then
631                                 echo "Eos has ${ObjectName}."
632                         else 
633                                 mkdir ${fullObjectDir}          
634                         fi
635                         cd ${fullObjectDir}
636                         pwd
637                         for dir in src inc doc Config
638                         do
639                                 if [ -d $dir ]
640                                 then
641                                         echo "Eos has ${ObjectName}/${dir}"
642                                 else
643                                         mkdir ${dir}
644                                 fi
645                         done
646                         ### Root
647                         if [ -h Makefile ]      
648                         then
649                                 rm Makefile
650                         fi
651                         ### Config
652                         sed -e s/Object/${ObjectName}/g ${ObjectTemplate}/Config/Define.inc > Config/Define.inc
653                         sed -e s/Tool/${ToolName}/g ${ObjectTemplate}/Config/Target.inc > Config/Target.inc
654
655                         ### src
656                         rm -f ./Makefile
657                         #ln -s ${ObjectTemplate}/Makefile Makefile
658                         cp ${ObjectTemplate}/Makefile Makefile
659                         rm -f ./src/Makefile
660                         #ln -s ${ObjectTemplate}/src/Makefile ./src/Makefile
661                         cp ${ObjectTemplate}/src/Makefile ./src/Makefile
662                         touch src/.Depend
663                         touch src/.Source       
664                         touch src/.CHeader
665                         touch src/.CCHeader
666
667                         ### inc
668                         rm -f inc/Makefile
669                         #ln -s ${ObjectTemplate}/inc/Makefile inc/Makefile
670                         cp ${ObjectTemplate}/inc/Makefile inc/Makefile
671
672                         ### doc
673                         if [ -h doc/Makefile ]  
674                         then
675                                 rm doc/Makefile
676                         fi
677                         cp ${ObjectTemplate}/doc/Makefile doc/Makefile
678                         #ln -s ${ObjectTemplate}/doc/Makefile doc/Makefile
679                         touch doc/.header
680                         touch doc/.footer
681                         touch doc/.${ObjectName}.html
682                         ;;
683                 *)
684                         echo "Not supported action : %{Action}"
685                         exit
686                         ;;
687         esac
688         case ${Action} in 
689                 All)
690                         cd ${EOS_HOME}/src/${World}/${ClassName}/${ObjectName}; make check
691                         ;;
692                 *)
693                         echo "Not supported action : %{Action}"
694                         exit
695                         ;;
696         esac
697 }
698
699 #
700 # Tool
701 #
702 ToolClassDirModifyFollowingAction()
703 {
704         #### Create Tool Class Directory
705         case ${Action} in 
706                 All|AllFollowingControlFile)    
707                         ToolClassHome=${EOS_HOME}/src/Tools/
708                         ;;
709                 Another|AnotherFollowingControlFile)
710                         echo "AnotherHome is ${AnotherHome}. Is it OK ?"
711                         read ans
712                         case $ans in
713                                 Y|y)
714                                         ;;
715                                 *)
716                                         exit
717                                         ;;
718                         esac
719                         for dir in src bin doc sccs src/Tools
720                         do
721                                 if [ -d ${AnotherHome}/${dir} ]
722                                 then
723                                         echo "AnotherHome/${dir} : implemented."
724                                 else
725                                         mkdir ${AnotherHome}/${dir}
726                                 fi
727                         done
728                         if [ -d ${AnotherHome}/src/Config ]
729                         then
730                                 rm -f ${AnotherHome}/src/Config
731                         else
732                                 rm -f ${AnotherHome}/src/Config 
733                         fi
734                         #ln -s ${EOS_HOME}/src/Config ${AnotherHome}/src/Config
735                         cp -r ${EOS_HOME}/src/Config ${AnotherHome}/src/Config
736                         ToolClassHome=${AnotherHome}/src/Tools
737                         ;;
738                 *)
739                         echo "Not supported action in ToolClassDirModifyFollowingAction: ${Action}"
740                         exit
741                         ;;
742         esac
743
744         #### Create Makefile in Tools
745         cd ${ToolClassHome}
746         rm -f ./Makefile
747         #ln -s ${ToolHomeTemplate}/Makefile ./Makefile
748         cp ${ToolHomeTemplate}/Makefile ./Makefile
749         #### Create Config in Tools
750         cd ${ToolClassHome}
751         if [ -d ./Config ] 
752         then
753                 echo "Tools/Config : implemented"
754         else
755                 mkdir ./Config
756         fi
757         cd ${ToolClassHome}
758         if [ -f Config/Define.inc ] 
759         then
760                 ans=`cat Config/Define.inc | awk -v Name=WORLDNAME '{ if ($1==Name) print $0}' `
761                 if [ -n $ans ]
762                 then
763                         sed -e s/worldname/${World}/g ${ToolHomeTemplate}/Config/Define.inc >> Config/Define.inc
764                 fi
765         else
766                 sed -e s/worldname/${World}/g ${ToolHomeTemplate}/Config/Define.inc > Config/Define.inc
767         fi
768         if [ ! -f Config/Target.inc ] 
769         then
770                 sed -e s/worldname/${World}/g ${ToolHomeTemplate}/Config/Define.inc > Config/Define.inc
771         fi
772
773         ### Create Class in Tools
774         fullClassDir=${ToolClassHome}/${ClassName}
775         if [ -d ${fullClassDir} ] 
776         then
777                 echo "Tools/${ClassName} : implemented."
778         else
779                 mkdir ${fullClassDir}
780         fi
781         #### Update Makefile in Tools
782         cd ${ToolClassHome}
783         if [ -f ./.Source ]
784         then
785                 echo "Tools/Makefile : implemented."
786         else
787                 cp ${ToolHomeTemplate}/.Source ./.Source        
788         fi
789
790         OldClassName=
791         OldClassName=`cat ./.Source | awk -v Name=${ClassName} '{ if($1==Name) print $1} ' `
792         if [ ${OldClassName} ] 
793         then
794                 echo "${OldClassName} : implemented in Tools/${ClassName}/Makefile."
795         else
796                 ${EOS_HOME}/sbin/dotSourceInMakefileCreate ./ ${ClassName} Class
797         fi
798
799         #### Create Config in Tools/Class
800         cd ${fullClassDir}
801         if [ -d ${fullClassDir}/Config ] 
802         then
803                 echo "${fullClassDir}/Config : implemented."
804         else
805                 mkdir ${fullClassDir}/Config
806         fi
807         cd ${fullClassDir}
808         if [ -f Config/Define.inc ] 
809         then
810                 ans=`cat Config/Define.inc | awk -v Name=CLASSNAME '{ if ($1==Name) print $1}' `
811                 if [ ! $ans ]
812                 then
813                         sed -e s/classname/${ClassName}/g ${ToolClassTemplate}/Config/Define.inc >> Config/Define.inc
814                 fi
815         else
816                 sed -e s/classname/${ClassName}/g ${ToolClassTemplate}/Config/Define.inc > Config/Define.inc
817         fi
818         if [ ! -f Config/Target.inc ] 
819         then
820                 sed -e s/classname/${ClassName}/g ${ToolClassTemplate}/Config/Define.inc > Config/Define.inc
821         fi
822
823         rm -f ./Makefile
824         #ln -s ${ToolClassTemplate}/Makefile ./Makefile
825         cp ${ToolClassTemplate}/Makefile ./Makefile
826         if [ -f ./.Source ]
827         then
828                 echo "Tools/Makefile : implemented."
829         else
830                 cp ${ToolHomeTemplate}/.Source ./.Source        
831         fi
832 }
833 ##
834 ## ToolDirModityFollowingAction
835 ##     This routine is a main Routine to construct a tool directory.
836 ##
837 ToolDirModifyFollowingAction()
838 {
839         ##
840         ## Create Tool Home Directory
841         ##
842         case ${Action} in
843                 All|AllFollowingControlFile|AllShell|AllShellFollowingControlFile)
844                         ToolHome=${EOS_HOME}/src/Tools/${ClassName}
845                         ;;
846                 Another|AnotherFollowingControlFile)
847                         ToolHome=${AnotherHome}/src/Tools/${ClassName}
848                         ;;
849                 *)
850                         echo "Not supported action in ToolDirModifyFollowingAction: ${Action}"
851                         exit
852                         ;;
853         esac
854         if [ -d ${ToolHome} ]
855         then
856                 cd ${ToolHome}
857         else
858                 echo "Something Wrong !!!"
859                 echo "${ToolHome} is not found."
860                 exit
861         fi
862         fullToolDir=${ToolHome}/${ToolName}
863         ##
864         ## Register a new tool in Makefile
865         ##
866         cd ${ToolHome}
867         case ${Action} in 
868                 All|AllFollowingControlFile|Another|AnotherFollowingControlFile)
869                         ### Set Makefile 
870                         rm -f ./Makefile 
871                         #ln -s ${ToolClassTemplate}/Makefile ./Makefile
872                         cp ${ToolClassTemplate}/Makefile ./Makefile
873                         if [ -f ./.Source ]
874                         then
875                                 echo "${fullToolDir}/Makefile : implemented."
876                         else
877                                 cp ${ToolClassTemplate}/.Source ./.Source
878                         fi
879                         ### Set tool directory
880                         if [ -d ${fullToolDir} ] 
881                         then
882                                 echo "${ToolName} : implemented."
883                         else 
884                                 mkdir ${fullToolDir}
885                         fi
886                         ### Set .Source file
887                         OldToolName=`cat ./.Source | awk -v Name=${ToolName} '{ if($1==Name) print $1} ' `
888                         if [ ${OldToolName} ] 
889                         then
890                                 echo "${OldToolName} : implemented in Tools/${ClassName}/${ToolName}/Makefile."
891                         else
892                                 ${EOS_HOME}/sbin/dotSourceInMakefileCreate ./ ${ToolName} Tools
893                         fi
894                         ;;
895                 *)
896                         echo "Not supported action in ToolDirModifyFollowingAction: ${Action}"
897                         exit
898                         ;;
899         esac
900
901         #### Set Environment File #####
902         cd ${fullToolDir}
903         case ${Action} in 
904                 All|AllFollowingControlFile|Another|AnotherFollowingControlFile)
905                         ### Set tool directories
906                         for dir in Config inc src doc
907                         do
908                                 if [ -d ${dir} ] 
909                                 then
910                                         echo "${ToolName}/${dir} : implemented."
911                                 else
912                                         mkdir ${dir}
913                                 fi
914                         done
915                         ### Set Config/Define.inc ###
916                         if [ -f Config/Define.inc ]
917                         then
918                                 echo "Config/Define.inc : implemented."
919                         else
920                                 sed -e s/Tool/${ToolName}/g ${ToolTemplate}/Config/Define.inc > Config/Define.inc
921                         fi
922                         ### Set Config/Target.inc ###
923                         if [ -f Config/Target.inc ]
924                         then
925                                 echo "Config/Target.inc : implemented."
926                         else
927                                 sed -e s/Tool/${ToolName}/g ${ToolTemplate}/Config/Target.inc > Config/Target.inc
928                         fi
929                         ### Set Makefile ###
930                         rm -f Makefile 
931                         cp  ${ToolTemplate}/Makefile Makefile
932                         #ln -s ${ToolTemplate}/Makefile Makefile
933
934                         ### Set src/Makefile, src/.Depend, src/.Source, doc/Makefile  ###
935                         rm -f ./src/Makefile
936                         #ln -s ${ToolTemplate}/src/Makefile ./src/Makefile
937                         cp ${ToolTemplate}/src/Makefile ./src/Makefile
938                         touch src/.Depend
939                         touch src/.Source
940                         rm -f doc/Makefile
941                         #ln -s ${ToolTemplate}/doc/Makefile ./doc/Makefile
942                         cp ${ToolTemplate}/doc/Makefile ./doc/Makefile
943                         ;;
944                 *)
945                         echo "Not supported action in ToolDirModifyFollowingAction: ${Action}"
946                         exit
947                         ;;
948         esac
949         ##
950         ## Set OptionControl File 
951         ## 
952         cd ${fullToolDir}
953         case ${Action} in
954                 All|Another)
955                         if [ -f Config/OptionControlFile ] 
956                         then
957                                 echo "Config/OptionControlFile exists now.  Would you like to overwrite it ?"
958                                 read ans
959                         else
960                                 ans="y"
961                         fi
962                         if [ $ans = "Y" -o $ans = "y" ]
963                         then
964                                 cp ${ToolTemplate}/Config/OptionControlFile  Config/OptionControlFile
965                         else
966                                 echo "Not Overwrite Config/OptionControlFile"
967                         fi      
968                         ;;      
969                 AllFollowingControlFile|AnotherFollowingControlFile) 
970                         ;;
971                 *)
972                         echo "Not supported action in ToolDirModifyFollowingAction: ${Action}"
973                         exit
974                         ;;
975         esac
976         ##
977         ## Create prototype source code 
978         ## 
979         cd ${fullToolDir}
980         case ${Action} in
981                 All|Another)
982                         ### inc/config/h
983                         ans="y"
984                         if [ -f inc/config.h ] 
985                         then
986                                 echo "inc/config.h exists now. Would you like to overwrite it ?" 
987                                 read ans
988                         fi
989                         if [ $ans = "Y" -o $ans = "y" ]
990                         then
991                                 sed -e s/Tool/${ToolName}/g ${ToolTemplate}/inc/config.h > inc/config.h
992                         else
993                                 echo "Not Overwrite inc/config.h."
994                         fi
995
996                         ans="y"
997                         if [ -f src/${ToolName}.c ]
998                         then
999                                 echo "src/${ToolName}.c exists now. Would you like to overwrite it ?" 
1000                                 read ans
1001                         fi
1002                         if [ $ans = "Y" -o $ans = "y" ]
1003                         then
1004                                 sed -e s/Tool/${ToolName}/g ${EOS_HOME}/sbin/toolHead.Template \
1005                                         -e s/Class/${ClassName}/g                                    > src/${ToolName}.c
1006                                 sed -e s/Tool/${ToolName}/g ${ToolTemplate}/src/Tool.c \
1007                                         -e s/Class/${ClassName}/g                                    >> src/${ToolName}.c
1008                         else
1009                                 echo "Not Overwrite src/${ToolName}.c"
1010                         fi
1011                         ;;
1012                 AllFollowingControlFile|AnotherFollowingControlFile) 
1013                         ;;
1014                 *)
1015                         echo "Not supported action in ToolDirModifyFollowingAction: ${Action}"
1016                         exit
1017                         ;;
1018         esac
1019         case ${Action} in
1020                 All|AllFollowingControlFile|Another|AnotherFollowingControlFile) 
1021                         ${EOS_HOME}/sbin/ctrl2proto ${ClassName} ${ToolName} Config/OptionControlFile
1022                         ;;
1023                 *)
1024                         echo "Not supported action in ToolDirModifyFollowingAction: ${Action}"
1025                         exit
1026                         ;;
1027         esac
1028         ##
1029         ## Directory Structure Check
1030         ##
1031         case ${Action} in
1032                 All|AllFollowingControlFile|Another|AnotherFollowingControlFile) 
1033                         echo "Directory Checking"
1034                         cd ${EOS_HOME}/src/${World}/${ClassName}/${ToolName}; make check 
1035                         ;;
1036                 *)
1037                         echo "Not supported action in ToolDirModifyFollowingAction: ${Action}"
1038                         exit
1039                         ;;
1040         esac
1041
1042 }
1043
1044 ### Main Program
1045 #
1046 #
1047 #
1048 World="unknown"
1049 ClassName="unknown"
1050 ObjectName="unknown"
1051 ToolName="unknown"
1052
1053 # Store Flags
1054 FlagsCharacter="-"
1055
1056 ## Option Flag Check
1057 case $# in 
1058         0)
1059                 ;;
1060         *)
1061                 while [ `echo $1 | cut -c1` = ${FlagsCharacter} ]
1062                 do
1063                         if [ `echo $1 | cut -c2` = "h" ] 
1064                         then
1065                                 usage
1066                         else 
1067                                 parms="${parms} $1"
1068                                 shift 
1069                         fi              
1070                 done
1071                 ;;
1072 esac
1073
1074 ## argCheck and set ClassName and ObjectName
1075 case $# in
1076         0) #No Name     
1077                 WorldNameRead
1078                 WorldDirCheckAndMake
1079                 case $World in
1080                         Objects)
1081                                 ObjectClassNameRead
1082                                 ObjectClassDirCheckAndMake
1083         
1084                                 ObjectNameRead ${ClassName}
1085                                 ObjectDirCheckAndMake ${ClassName}
1086
1087                                 ObjectActionRead
1088                                 ;;
1089                         Tools)
1090                                 ToolClassNameRead
1091                                 ToolClassDirCheckAndMake
1092         
1093                                 ToolNameRead ${ClassName}
1094                                 ToolDirCheckAndMake ${ClassName}
1095
1096                                 ToolActionRead
1097                                 ;;
1098                         *)
1099                                 echo "Not Supported World: ${World}"
1100                                 exit
1101                                 ;;
1102                 esac
1103                 ANS="Y"
1104                 ;;
1105         1) # $1 : Action/World
1106                 Action=$1
1107                 ActionRead
1108                 case ${World} in
1109                         Objects)
1110                                 ObjectClassNameRead
1111                                 ObjectClassDirCheckAndMake
1112         
1113                                 ObjectNameRead ${ClassName}
1114                                 ObjectDirCheckAndMake ${ClassName}
1115
1116                                 ;;
1117                         Tools)
1118                                 ToolClassNameRead
1119                                 ToolClassDirCheckAndMake
1120         
1121                                 ToolNameRead ${ClassName}
1122                                 ToolDirCheckAndMake ${ClassName}
1123
1124                                 ;;
1125                         *)
1126                                 echo "Not Supported World in argnum=1: ${World}"
1127                                 exit
1128                 esac
1129                 ANS="Y"
1130                 ;;
1131         2) # $1 : Action, $2: World, $3 : Class
1132                 Action=$1
1133                 World=$2
1134                 ActionRead
1135                 case $World in
1136                         Objects)
1137                                 ObjectClassNameRead
1138                                 ObjectClassDirCheckAndMake
1139
1140                                 ObjectNameRead ${ClassName}
1141                                 ObjectDirCheckAndMake ${ClassName}
1142
1143                                 ;;
1144                         Tools)
1145                                 ToolClassNameRead
1146                                 ToolClassDirCheckAndMake
1147
1148                                 ToolNameRead ${ClassName}
1149                                 ToolDirCheckAndMake ${ClassName}
1150
1151                                 ;;
1152                         *)
1153                                 echo "Not Supported World ${World}"
1154                                 exit
1155                 esac
1156                 ANS="Y"
1157                 ;;
1158         3) # $1: Action, $2 : World, $3 : Class, $4 : Name
1159                 Action=$1
1160                 World=$2
1161                 ActionRead
1162                 ClassName=$3
1163                 case $World in
1164                         Objects)
1165                                 ObjectName=$4
1166                                 ;;
1167                         Tools)
1168                                 ToolName=$4
1169                                 ;;
1170                         *)
1171                                 echo "Not Supported World: ${World}"
1172                                 exit
1173                 esac
1174                 ANS="Y"
1175                 ;;
1176         4) # $1 : Action, $2: World, $3 : Class, $4 : Name
1177                 Action=$1
1178                 World=$2
1179                 ActionRead
1180                 ClassName=$3
1181                 case $World in
1182                         Objects)
1183                                 ObjectName=$4
1184                                 ;;
1185                         Tools)
1186                                 ToolName=$4
1187                                 ;;
1188                         *)
1189                                 echo "Not Supported World ${World}"
1190                                 exit
1191                 esac
1192                 ANS="Y"
1193                 ;;
1194         5) # $1 : Action, $2: World, $3 : Class, $4 : Name, $5 : ANS
1195                 Action=$1
1196                 World=$2
1197                 ActionRead
1198                 ClassName=$3
1199                 case $World in
1200                         Objects)
1201                                 ObjectName=$4
1202                                 ;;
1203                         Tools)
1204                                 ToolName=$4
1205                                 ;;
1206                         *)
1207                                 echo "Not Supported World ${World}"
1208                                 exit
1209                 esac
1210                 ANS = $5
1211                 ;;
1212         *) #
1213                 usage
1214                 ;;
1215 esac
1216 #
1217 #
1218 if [ ${World} = "unknown" -o ${ClassName} = "unknown" -o  ${ObjectName} = "unknown" -a ${ToolName} = "unknown" -o ${Action} = "unknown" ]
1219 then
1220         echo "Something wrong"
1221         usage
1222 else 
1223         echo "World:  ${World}"
1224         echo "Class:  ${ClassName}"
1225         case ${World} in
1226                 Tools)
1227                         echo "Tools:   ${ToolName}"
1228                         ;;
1229                 Objects)
1230                         echo "Objects: ${ObjectName}"
1231                         ;;
1232                 *)
1233                         echo "Not Supported World : ${World}"
1234                         exit
1235                         ;;
1236         esac
1237         echo "Action: ${Action}"
1238         if [ $ANS = "Y" ] 
1239         then 
1240                 echo "Is it OK ?"
1241                 read ans
1242                 if [ $ans = "y" -o $ans = "Y" ]
1243                 then
1244                         echo "----- Start -----"
1245                 else
1246                         echo "----- Please operate again !! -----"
1247                         exit
1248                 fi
1249         else 
1250                 echo "----- Start -----"
1251         fi
1252 fi
1253
1254 currentDir=`pwd`
1255 fullWorldDir=${EOS_HOME}/src/${World}
1256 fullClassName=${fullWorldDir}/${ClassName}
1257 fullObjectName=${fullClassName}/${ObjectName}
1258 fullToolName=${fullClassName}/${ToolName}
1259
1260 #
1261 if [ $EOS_ANOTHER_HOME ] 
1262 then
1263         AnotherHome=$EOS_ANOTHER_HOME
1264 else
1265         AnotherHome=$currentDir
1266 fi
1267
1268 case ${World} in
1269         Objects)
1270                 ObjectClassDirModifyFollowingAction
1271                 ObjectDirModifyFollowingAction
1272                 chgrp -R Eos ${fullObjectName}
1273                 chmod -R 775 ${fullObjectName}
1274                 ;;
1275         Tools)
1276                 ToolClassDirModifyFollowingAction
1277                 ToolDirModifyFollowingAction
1278                 chgrp -R Eos ${fullToolName}
1279                 chmod -R 775 ${fullToolName}
1280                 ;;
1281         *)
1282                 echo "Not Supported World : ${World}"
1283                 ;;
1284 esac
1285 #
1286
1287 ##echo "Do you inform this new one to Eos mailing list? Y/N"
1288 ##read Ans
1289 #case $Ans in
1290 #       Y|y)
1291 #               case ${Action} in
1292 #                       All)
1293 #                               echo "----- Information for Eos Group -----"
1294 #                               case ${World} in
1295 #                                       Object)
1296 #                                               #mailToEosGroup "makeobj  new: ${ObjectName} in ${ClassName}"
1297 #                                               ;;
1298 #                                       Tools)
1299 #                                               #mailToEosGroup "maketool new: ${ToolName} in ${ClassName}"
1300 #                                               ;;
1301 #                                       *)
1302 #                                               ;;
1303 #                               esac    
1304 #                               ;;
1305 #                       *)
1306 #                       ;;
1307 #               esac
1308 #               ;;
1309 #esac
1310
1311 pwd
1312 cd ${currentDir}
1313 EosWorld=$World
1314 EosClass=$ClassName
1315 EosObject=$ObjectName
1316 EosTool=$ToolName
1317 export EosWorld EosClass EosObject EosTool