home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume38 / lude / part06 < prev    next >
Encoding:
Text File  |  1993-07-11  |  65.2 KB  |  1,962 lines

  1. Newsgroups: comp.sources.misc
  2. From: laplante@crim.ca (Pierre Laplante)
  3. Subject: v38i038:  lude - A Distributed Software Library, Part06/12
  4. Message-ID: <1993Jul11.224630.16571@sparky.imd.sterling.com>
  5. X-Md4-Signature: 9f25b74068e1cbf37d8de3db1f96e76a
  6. Sender: kent@sparky.imd.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Sun, 11 Jul 1993 22:46:30 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: laplante@crim.ca (Pierre Laplante)
  12. Posting-number: Volume 38, Issue 38
  13. Archive-name: lude/part06
  14. Environment: UNIX
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  lude-1.1/run/crim/sun4.1_sparc/include/lude/ludemisc
  21. #   lude-1.1/src/orig/info/Makefile lude-1.1/src/orig/src/ludeindexinc
  22. #   lude-1.1/src/orig/src/ludemisc
  23. # Wrapped by kent@sparky on Sun Jul 11 15:49:14 1993
  24. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 6 (of 12)."'
  27. if test -f 'lude-1.1/run/crim/sun4.1_sparc/include/lude/ludemisc' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'lude-1.1/run/crim/sun4.1_sparc/include/lude/ludemisc'\"
  29. else
  30.   echo shar: Extracting \"'lude-1.1/run/crim/sun4.1_sparc/include/lude/ludemisc'\" \(26934 characters\)
  31.   sed "s/^X//" >'lude-1.1/run/crim/sun4.1_sparc/include/lude/ludemisc' <<'END_OF_FILE'
  32. X# ludemisc - Project lude.
  33. X# Copyright (C) 1991,1992  Pierre Laplante
  34. X# Copyright (C) 1992,1993 Stephane Boucher, Ecole Polytechnique de Montreal.
  35. X#
  36. X# This program is free software; you can redistribute it and/or modify
  37. X# it under the terms of the GNU General Public License as published by
  38. X# the Free Software Foundation; either version 1, or (at your option)
  39. X# any later version.
  40. X#
  41. X# This program is distributed in the hope that it will be useful,
  42. X# but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  44. X# GNU General Public License for more details.
  45. X#
  46. X# You should have received a copy of the GNU General Public License
  47. X# along with this program; if not, write to the Free Software
  48. X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  49. X
  50. X$FULL_VERSION.= '$Id: ludemisc,v 1.4 1993/03/17 19:44:14 sbo Exp $' ."\n";
  51. X
  52. X#-----------------------------------------------------------------------
  53. X# Various useful global definitions
  54. X
  55. Xif (!defined($DEFAULTDEBUGLEVEL)) { $DEFAULTDEBUGLEVEL=9; }
  56. Xif (!defined($TRUE))              { $TRUE=1; }
  57. Xif (!defined($FALSE))             { $FALSE=0; }
  58. Xif (!defined($ERROR))             { $ERROR=STDERR; }
  59. Xif (!defined($OUT))               { $OUT=STDOUT; }
  60. X
  61. Xif (!defined($LUDE_FILE))         { die "\$LUDE_FILE should be defined, stopped at"; }
  62. Xif (!defined($LUDE_STAMP))        { $LUDE_STAMP="$LUDE_FILE"; }
  63. X
  64. X#-----------------------------------------------------------------------
  65. X# Description : Search for a software according to the search keys
  66. X#               given as parameters. Only  the softwares that are
  67. X#               ready (file LUDE under install/mod/class) are
  68. X#               considered, unless 't' command is given. In that
  69. X#               case, only the existence of /usr/local/soft/soft/install/mod/class
  70. X#               rather than /usr/local/soft/soft/install/mod/class/LUDE
  71. X#               to verify the match.
  72. X#
  73. X# Parameters  : $cmd - String indicating the command/location where
  74. X#                      to look for a copy of the software.
  75. X#                      'l' means local (in /usr/local)
  76. X#                      's' means on the servers (in /usr/local/server)
  77. X#                      't' Don't check for the lude stamp. By default
  78. X#                          the stamp must be there.
  79. X#                      'a' Means return all the possible matches.
  80. X#                          The commands/locations can be combined.
  81. X#                          The default is to return only the first match.
  82. X#               $server - specify a server to search. If specified
  83. X#                         only that server is searched. the other commands
  84. X#                         to specify servers location are therefore ignored.
  85. X#               $soft - name of the software that is to be searched.
  86. X#               $mod - specify a modification to look for.
  87. X#                      If not specified, all the mods are
  88. X#                      searched.
  89. X#               @classes - list of classes, in order of preference,
  90. X#                          used to find a match. At least one is required.
  91. X#
  92. X# Returns     : a list of the form:
  93. X#               (join($;, $server, $soft, $mod, $class), 
  94. X#                join($;, $server2, $soft2, $mod2, $class2)) 
  95. X#               An empty list indicate that the software 
  96. X#               was not found.
  97. X#               an undef value indicate that an error occured.
  98. X#               $server has a special value. if set to '/'
  99. X#               it means that the server is local 
  100. X#               (i.e. directory /usr/local).
  101. X#
  102. Xsub FindSoftware {
  103. X    # Make sure that the number of parameters is correct
  104. X    if (scalar(@_)<5){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d", scalar(@_), __FILE__, __LINE__));}
  105. X    local($cmd, $server, $soft, $mod, @classes)=@_;
  106. X    local(@lstcmds)=();
  107. X    local(@lstservers)=();    # List of all servers that will be searched
  108. X    local(@lstsofts)=();    # List of all softwares that will be looked
  109. X    local(@lstmods)=();        # List of all the modification that will 
  110. X                                # be looked
  111. X    local(@lstclasses)=();    # List of all the classes that will be looked
  112. X    local($stamp)=$LUDE_STAMP;
  113. X    local($keepallmatches)=$FALSE; # The default is to keep only the first
  114. X                   # soft/mod/class combination that matches
  115. X                   # The command 'a' turns this value to 
  116. X                                   # $TRUE so that all the matching 
  117. X                                   # combination will be kept.
  118. X    local(@matches)=();        # List of all the matches found.
  119. X
  120. X    # Check to see if a server was specified
  121. X    if ($server eq '/') {    # Local server
  122. X    push(@lstservers, "$SOFT_DIR");
  123. X    }
  124. X    elsif ($server ne '') {    # remote server
  125. X    push(@lstservers, "$SERVER_DIR/$server");
  126. X    }
  127. X    else {
  128. X    # no server specified
  129. X    }
  130. X
  131. X    # Examine the commands and build the lstservers
  132. X    @lstcmds=split(//, $cmd);
  133. X    for $c (@lstcmds) {
  134. X    if ($c eq 'l') {    # Local server
  135. X        if ($server eq '') { # (only if no server is specified)
  136. X        # use unshift so that the soft in $SOFT_DIR has precedence
  137. X        unshift(@lstservers, "$SOFT_DIR");
  138. X        }
  139. X    }
  140. X    elsif ($c eq 's') {    # Remote server
  141. X        if ($server eq '') { # (only If no server is specified)
  142. X        local(*dir, @lstdir);
  143. X
  144. X        # Read the directory containing the available remote
  145. X        # servers.
  146. X        opendir(dir, "$SERVER_DIR");
  147. X        @lstdir=grep(!/^\.{1,2}$/, readdir(dir));
  148. X        closedir(dir);
  149. X
  150. X        #For all servers found prepend $SERVER_DIR so that we
  151. X        # have /usr/local/server/something instead of
  152. X        # something. ($SERVER_DIR being equal to 
  153. X        # /usr/local/server by default)
  154. X        for (@lstdir) { s|(.*)|$SERVER_DIR/$1|; }
  155. X
  156. X        # Add the servers found to the existing list
  157. X        # use push so that the soft in $SOFT_DIR has precedence
  158. X        push(@lstservers, @lstdir);
  159. X        }
  160. X    }
  161. X    elsif ($c eq 't') {
  162. X        # By setting stamp to '', the stamp (or file that
  163. X        # indicate that a software is publicly available)
  164. X        # is not required. i.e. only the path leading
  165. X        # to the place where the file resides when any 
  166. X        # is required.
  167. X        # for exemple: if 
  168. X        # /usr/local/emacs-18.58/install/poly/sun4.1_sparc
  169. X        # exists, than the software is taken as existing.
  170. X        # Otherwise, with 't' not specified, the file
  171. X        # /usr/local/emacs-18.58/install/poly/sun4.1_sparc/$LUDE_STAMP
  172. X        # must exist to have a match. ($LUDE_STAMP contains
  173. X        # the name of the file that identifies the availability
  174. X        # of a software).
  175. X        $stamp='';
  176. X    }
  177. X    elsif ($c eq 'a') {
  178. X        # Keep searching to find all softwares available.
  179. X        # The default is to stop searching as soon as a
  180. X        # software is found.
  181. X        $keepallmatches=$TRUE;
  182. X    }
  183. X    else {
  184. X        # The command found is not one that is defined.
  185. X        &Error($ERR_INTERNAL, "Incorrect parameter to function");
  186. X    }
  187. X    }
  188. X
  189. X    # look at each servers
  190. X    for $path (@lstservers) {
  191. X    # Set the software list to examine
  192. X    if ($soft ne '') {
  193. X        # if a software was specified in parameters, then
  194. X        # only that software will be examined.
  195. X        @lstsofts=($soft);
  196. X    }
  197. X    else {
  198. X        # No software was specified. Therefore examine all the
  199. X        # available softwares on the current server.
  200. X        local(*dir);
  201. X        opendir(dir, "$path");
  202. X        @lstsofts=grep(!/^\.{1,2}$/, readdir(dir));
  203. X        closedir(dir);
  204. X    }
  205. X
  206. X    # Examine the specified software for the current server.
  207. X    for $s (@lstsofts) {
  208. X        if (-r "$path/$s/install") {
  209. X        # if a modification was specified in parameters, then
  210. X        # only that modification will be examined.
  211. X        if ($mod ne '') {
  212. X            # Use the specified modification
  213. X            @lstmods=($mod);
  214. X        }
  215. X        else {
  216. X            # No modification was specified. Therefore
  217. X            # examine all the available softwares on the
  218. X            # current server.
  219. X            local(*dir);
  220. X            opendir(dir, "$path/$s/install");
  221. X            @lstmods=grep(!/^\.{1,2}$/, readdir(dir));
  222. X            closedir(dir);
  223. X        }
  224. X
  225. X        # Examine the modifications for the current 
  226. X        # server/software.
  227. X        for $m (@lstmods) {
  228. X            if (@classes == 1 && $classes[$[] eq '') {
  229. X            # Use all the available classes, if only
  230. X            # one class is given and that class is eq
  231. X            # to the special value ''.
  232. X            local(*dir);
  233. X            opendir(dir, "$path/$s/install/$m");
  234. X            @lstclasses=grep(!/^\.{1,2}$/, readdir(dir));
  235. X            closedir(dir);
  236. X            }
  237. X            else {
  238. X            # if any classes were specified in parameters,
  239. X            # then only those classes will be examined.
  240. X            @lstclasses=@classes;
  241. X            }
  242. X
  243. X            # Examine the classes for the curent server/soft/mod
  244. X            for $c (@lstclasses) {
  245. X            if (-e "$path/$s/install/$m/$c/$stamp") {
  246. X                # The file $stamp exist, therefore the
  247. X                # combination server/soft/mod/class is 
  248. X                # declared available and added to the
  249. X                # list of matches. (Note that if the
  250. X                # command 't' was given in parameters
  251. X                # $stamp is eq to '', and the test of
  252. X                # existence is made only on the directory
  253. X                # leading to the place where $LUDE_STAMP
  254. X                # resides when existing.
  255. X                if ($path =~ m|^($SERVER_DIR)/(.+)$|) {
  256. X                # The path matches the form
  257. X                # /usr/local/server/some_server.
  258. X                # extract the part some_server and
  259. X                # use this with $s (soft), $m (modification)
  260. X                # $c (class) to form a new entry in the
  261. X                # list of matches.
  262. X                push(@matches, join($;, $2, $s, $m, $c));
  263. X                if (! $keepallmatches) {
  264. X                    # Return the first found match
  265. X                    return @matches;
  266. X                }
  267. X                }
  268. X                else {
  269. X                # The server is local, so use the special
  270. X                # value '/' as the server.
  271. X                push(@matches, join($;, '/', $s, $m, $c));
  272. X                if (! $keepallmatches) {
  273. X                    # Return the first found match
  274. X                    return @matches;
  275. X                }
  276. X                }
  277. X            }
  278. X            }
  279. X        }
  280. X        }
  281. X        else {
  282. X        # The software is not on this server
  283. X        }
  284. X    }
  285. X    }
  286. X
  287. X    return @matches;
  288. X}
  289. X
  290. X
  291. X#-----------------------------------------------------------------------
  292. X# Description : Run a command, and then return so that the execution 
  293. X#               can continue.
  294. X#               The global variable $Show is used to determine whether
  295. X#               to execute the command, or simply display the command
  296. X#               that is to be run.
  297. X#
  298. X# Parameters  : $cmd - Command to run
  299. X#
  300. X# Returns     : The returned value from the executed command
  301. X#               or 0 if $Show is set
  302. X#               In this case, 0 indicate success because
  303. X#               returned value correspond to the exit status
  304. X#               of the command, 0 being the standard exit value
  305. X#               to indicate success.
  306. X#
  307. Xsub RunCmd {
  308. X    local($cmd)=join(' ', @_);
  309. X    local($retval)=0;        # success by default
  310. X    
  311. X    if (&VerboseRetShow($WARN_CMD, $cmd)) {
  312. X    # Show is on, so do nothing
  313. X    }
  314. X    else {
  315. X    $retval=system($cmd) / 256;
  316. X    }
  317. X    return $retval;
  318. X}
  319. X#-----------------------------------------------------------------------
  320. X# Description : Validate the value specified for the given switch.
  321. X#               The value is returned in *value.
  322. X#
  323. X# Parameters  : $switch - Name of the switch
  324. X#               *value  - adress of the variable where the 
  325. X#                         validated value is placed
  326. X#               $type   - regexp used to check against the actual
  327. X#                         value. If the regexp matches the value,
  328. X#                         then that value is returned as valid.
  329. X#
  330. X# Returns     : nothing if no error
  331. X#               never returns if error
  332. X#
  333. Xsub Arg {
  334. X    # Make sure that the number of parameters is correct
  335. X    if (scalar(@_)!=3) {
  336. X    &Error($ERR_INTERNAL, 
  337. X           sprintf("(%d), %s:%d", scalar(@_), __FILE__, __LINE__));
  338. X    }
  339. X    local($switch, *value, $type)=@_;
  340. X    
  341. X    if (scalar(@ARGV)>0 && $ARGV[0] =~ m/^$type$/) {
  342. X    # The value is consitent with the type it must have
  343. X    $value=$ARGV[0];
  344. X    shift(@ARGV);
  345. X    }
  346. X    else {
  347. X    # The value is inconsistent with the type it must have
  348. X    &Usage($ERR_ARG, $switch, $type);  
  349. X    }            
  350. X}
  351. X
  352. X#-----------------------------------------------------------------------
  353. X# Description : Test to see if the system has the required
  354. X#               functionnality.
  355. X#               Test for the availability of the command
  356. X#               that will be needed during the execution
  357. X#               of the lude scripts.
  358. X#
  359. X# Parameters  : none
  360. X#
  361. X# Returns     : 1 if everything is fine.
  362. X#               0 if something wrong was found.
  363. X#
  364. Xsub VerifySystem {
  365. X    # Make sure that the number of parameters is correct
  366. X    if (scalar(@_)!=0) {
  367. X    &Error($ERR_INTERNAL, 
  368. X           sprintf("(%d), %s:%d", scalar(@_), __FILE__, __LINE__));
  369. X    }
  370. X    local($retval)=1;        # Success by default
  371. X
  372. X    # Check if the command tar is available
  373. X    if (! &Exist((split(/\s+/, "$PROG_TAR", 2))[0])) {
  374. X    &NFError($ERR_CMD, "$PROG_TAR");
  375. X    $retval=0;
  376. X    }
  377. X    # Check if the command cmp is available
  378. X    if (! &Exist((split(/\s+/, "$PROG_CMP", 2))[0])) {
  379. X    &NFError($ERR_CMD, "$PROG_CMP");
  380. X    $retval=0;
  381. X    }
  382. X    # Check if the command $MAKEWHATIS is available
  383. X    if (! &Exist((split(/\s+/, "$PROG_MAKEWHATIS", 2))[0])) {
  384. X    &NFError($ERR_CMD, $PROG_MAKEWHATIS);
  385. X    $retval=0;
  386. X    }
  387. X    # Check if the command class is available
  388. X    if (! &Exist('class')) {
  389. X    &NFError($ERR_CMD, 'class');
  390. X    $retval=0;
  391. X    }
  392. X
  393. X    return $retval;
  394. X}
  395. X
  396. X#-----------------------------------------------------------------------
  397. X# Description : Search the values associated to the server/soft/mod
  398. X#               triplet. The values are located in either
  399. X#               .../install/$IAFA_FILE or .../install/$mod/$LUDE_FILE.
  400. X#               Files are searched in the given order.
  401. X#
  402. X# Parameters  : $server   - Server to look for
  403. X#               $soft     - Software to look for
  404. X#               $dataFile - File to search (relative to ....soft/install)
  405. X#               @kws      - List of keywords to search
  406. X#
  407. X# Returns     : an assoc. array of the form $aa{"$keyword"}=$value
  408. X#               If 2 or more occurence of the same keyword, the last
  409. X#               value is kept.
  410. X#               If nothing is found, an empty array is returned.
  411. X#               if an error occured, undef is returned.
  412. X#
  413. Xsub GetKeyWord {
  414. X    # Make sure that the number of parameters is correct
  415. X    if (scalar(@_)<4) { &Error($ERR_INTERNAL, sprintf("(%d), %s:%d", scalar(@_), __FILE__, __LINE__)); }
  416. X    local($server, $soft, $dataFile, @kws)=@_; 
  417. X    local(%kwval)=();        # By default nothing was found
  418. X    local($file, *fptr);
  419. X    local($kword, $value);
  420. X
  421. X    # Determine the location of the file
  422. X    if ($server ne '/') {
  423. X    # On a remote server
  424. X    $file="$SERVER_DIR/$server/$soft/install/$dataFile";
  425. X    }
  426. X    else {
  427. X    # Local server
  428. X    $file="$SOFT_DIR/$soft/install/$dataFile";
  429. X    }
  430. X
  431. X    # Test for the accessibility of the software's log file
  432. X    stat($file);
  433. X    if (-e _ && -f _ && -r _) {
  434. X    if (! open(fptr, $file)) {
  435. X        # Cannot open the log file
  436. X        &NFError($ERR_FILE, $file);
  437. X    }
  438. X    else {
  439. X        # Undef the temporary variable that holds the text
  440. X        # for the current keyword. This means that nothing
  441. X        # is being accumulated for a keyword.
  442. X        undef $value;
  443. X        
  444. X        # Scan the log file
  445. X        while (<fptr>) {
  446. X        if (! defined($value) || /^[\-a-z]+:/i) {
  447. X            # No keyword is currently being processed
  448. X            # or the current line has the structure
  449. X            # of a line with a keyword. (e.g. 
  450. X            # ^keyword: text....)
  451. X
  452. X            # Check the line against all desired keywords
  453. X            for $k (@kws) {
  454. X            if (/^$Logkw{$k}:(.*)$/i) {
  455. X                # The current line matches the keyword $k.
  456. X                if (defined($value)) {
  457. X                # A $value was already being accumulated
  458. X                # for a previously found keyword, so store
  459. X                # the $value for the previous keyword.
  460. X                $kwval{"$kword"}=$value;
  461. X                }
  462. X                # Set the new current keyword
  463. X                $kword=$k;
  464. X                # Accumulate the first part of the value
  465. X                # That was found following the keyword.
  466. X                $value="$1\n";
  467. X            }
  468. X            }
  469. X        }
  470. X        else {
  471. X            # The line is an ordinary line that was preceded
  472. X            # by, maybe some ordinary line, and a line containing
  473. X            # a keyword.
  474. X            # Concatenate the current line to the accumulated
  475. X            # value of the current keyword.
  476. X            $value .= $_;
  477. X        }
  478. X        }
  479. X
  480. X        # The entire file was scanned
  481. X
  482. X        if (defined($value)) {
  483. X        # $value contains a value, and file file is
  484. X        # all scanned. So store the final value for the current
  485. X        # keyword.
  486. X        $kwval{"$kword"}=$value;
  487. X        }
  488. X        # Close the log file
  489. X        close(fptr);
  490. X    }
  491. X    }
  492. X    return %kwval;
  493. X}
  494. X
  495. X
  496. X#-----------------------------------------------------------------------
  497. X# Description : Scan the env. variable PATH to find the given command.
  498. X#
  499. X# Parameters  : $cmd - Command to be located.
  500. X#
  501. X# Returns     : 1 if command is found
  502. X#               0 if the command is not found
  503. X#
  504. Xsub Exist {
  505. X    # Make sure that the number of parameters is correct
  506. X    if(scalar(@_)!=1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  507. X    local($cmd)=@_;
  508. X    local(@dir);
  509. X    local($found)=0;        # Nothing found by default
  510. X
  511. X    if ($cmd =~ m|/|) {    
  512. X    # The command has a path component 
  513. X    # (e.g. bin/ls ./cat /usr/bin/ls etc)
  514. X    # so we don't check against PATH
  515. X    if (-x $cmd) {
  516. X        $found=1;
  517. X    }
  518. X    }
  519. X    else {
  520. X    @dir=split(/:/, $ENV{'PATH'});
  521. X    for $d (@dir) { $found=1 if (-x "$d/$cmd"); }
  522. X    }
  523. X    return $found;
  524. X}                
  525. X
  526. X#-----------------------------------------------------------------------
  527. X# Description : Output debug tracing information.
  528. X#
  529. X# Parameters  : $level - Specify the level of the message.
  530. X#                        If the level is supperior to the level that
  531. X#                        is run, then the message is displayed.
  532. X#               @rest  - List of arguments compatible with printf
  533. X#                        that represent the debug message.
  534. X#
  535. X# Returns     : nothing
  536. X#
  537. Xsub Debug {
  538. X    local($level,@rest)=@_;
  539. X    if ($Debuglevel > $level) {
  540. X    print "DEBUG ";
  541. X    printf (@rest);
  542. X    }
  543. X}                   
  544. X
  545. X#-----------------------------------------------------------------------
  546. X# Description : Non Fatal Error. Display the message given and return.
  547. X#
  548. X# Parameters  : $code - Error code that identifies the message
  549. X#               @rest - other arguments that are required by
  550. X#                       the format (a la printf) that correspond
  551. X#                       to $code.
  552. X#
  553. X# Returns     : nothing, but unlike Error it returns!
  554. X#
  555. Xsub NFError {
  556. X    # Make sure that the number of parameters is correct
  557. X    if(scalar(@_)<1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  558. X    local($code,@rest)=@_;
  559. X
  560. X    print $ERROR "$Progname: ";
  561. X    printf $ERROR ($MSGS[$code], @rest);
  562. X    print $ERROR "\n";
  563. X}
  564. X
  565. X#-----------------------------------------------------------------------
  566. X# Description : Fatal Error. Display the message given and abort 
  567. X#               execution.
  568. X#
  569. X# Parameters  : $code - Error code that identifies the message
  570. X#               @rest - other arguments that are required by
  571. X#                       the format (a la printf) that correspond
  572. X#                       to $code.
  573. X#
  574. X# Returns  : Never returns.
  575. X#
  576. Xsub Error {
  577. X    # Make sure that the number of parameters is correct
  578. X    if(scalar(@_)<1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  579. X    local($code)=@_;
  580. X    &NFError(@_);
  581. X    exit($code);
  582. X}
  583. X
  584. X#-----------------------------------------------------------------------
  585. X# Description : Warning. Display the message given and return.
  586. X#
  587. X# Parameters  : $code - Error code that identifies the message
  588. X#               @rest - other arguments that are required by
  589. X#                       the format (a la printf) that correspond
  590. X#                       to $code.
  591. X#
  592. X# Returns  : nothing, but unlike Error and like NFError it returns!
  593. X#
  594. Xsub Warning {
  595. X    # Make sure that the number of parameters is correct
  596. X    if(scalar(@_)<1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  597. X    local($code,@rest)=@_;
  598. X    printf $OUT ($MSGS[$code], @rest);
  599. X    print $OUT "\n";
  600. X}
  601. X
  602. X#-----------------------------------------------------------------------
  603. X# Description : Display a message if the global variable $Verbose
  604. X#               $FALSE, otherwise, do nothing.
  605. X#
  606. X# Parameters  : $code - Code that identifies the message
  607. X#               @rest - other arguments that are required by
  608. X#                       the format (a la printf) that correspond
  609. X#                       to $code.
  610. X#
  611. X# Returns     : The value of $Show
  612. X#
  613. Xsub VerboseRetShow {
  614. X    &Verbose(@_);
  615. X    return $Show;
  616. X}
  617. Xsub Verbose {
  618. X    if (@_ != 0) {
  619. X    local($code,@rest)=@_;
  620. X    if ($Verbose != $FALSE) {
  621. X        printf $OUT ($MSGS[$code], @rest);
  622. X        print $OUT "\n";
  623. X    }
  624. X    }
  625. X}
  626. X
  627. X#-----------------------------------------------------------------------
  628. X# Description : Extract the directory component of the file name.
  629. X#               Return that component.
  630. X#
  631. X# Parameters  : $name - Full path
  632. X#
  633. X# Returns     : Returns the extracted component.
  634. X#
  635. Xsub DirName {
  636. X    # Make sure that the number of parameters is correct
  637. X    if(scalar(@_)!=1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  638. X    local($name)=@_;
  639. X    substr($name, 0, rindex($name, "/"));
  640. X}                
  641. X
  642. X#-----------------------------------------------------------------------
  643. X# Description : Extract the last component of the file name.
  644. X#               Return that component.
  645. X#
  646. X# Parameters  : $name - Full path. 
  647. X#
  648. X# Returns     : Returns the extracted component.
  649. X#
  650. Xsub BaseName {
  651. X    # Make sure that the number of parameters is correct
  652. X    if(scalar(@_)!=1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  653. X    local($name)=@_;
  654. X    substr($name,rindex($name, "/") + 1);
  655. X}                
  656. X    
  657. X#-----------------------------------------------------------------------
  658. X# Description : Display the usage of the script
  659. X#
  660. X# Parameters  : $code - Error code that caused usage to be called.
  661. X#               @rest - other arguments that are required by
  662. X#                       the format (a la printf) that correspond
  663. X#                       to $code.
  664. X#
  665. X# Returns     : Never returns.
  666. X#
  667. Xsub Usage {            
  668. X    # Make sure that the number of parameters is correct
  669. X    if(scalar(@_)<1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  670. X    local($code, @rest)=@_;
  671. X    
  672. X    printf $ERROR ($MSGS[$code],@rest) if ($code != $OK);
  673. X    print $ERROR "\n$MSGS[$USAGE]\n";     
  674. X    exit $code if ($code);
  675. X}
  676. X
  677. Xsub Help {
  678. X    print $ERROR "$MSGS[$USAGE]\n\n";
  679. X    exit 0;
  680. X}
  681. X
  682. X#-----------------------------------------------------------------------
  683. X#    date(FORMAT): Return date in format yy/mm/dd
  684. X#
  685. Xsub Date {
  686. X    local($FMT_YYMMDD)=0;
  687. X    local($FMT_YYMMDDHHMMSS)=1;
  688. X    local($fmt)=@_;
  689. X    local($sec,$min,$hour,$mday,$mon,$year,@rest)=localtime(time);
  690. X
  691. X    $mon++;
  692. X    if ($fmt==$FMT_YYMMDD) {
  693. X    sprintf("%2.2d/%2.2d/%2.2d", $year,$mon,$mday);
  694. X    } 
  695. X    elsif ($fmt==$FMT_YYMMDDHHMMSS) {
  696. X    sprintf("%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d", $year, $mon, 
  697. X        $mday, $hour, $min, $sec);
  698. X    }
  699. X}
  700. X
  701. X#-----------------------------------------------------------------------
  702. X# Description : Append information about a command, to the history
  703. X#                file of a software.
  704. X# 
  705. X# Parameters  : 
  706. X#
  707. X# Returns     : 1 on success
  708. X#               0 if any errors
  709. X#
  710. Xsub HistAppend {
  711. X    # Make sure that the number of parameters is correct
  712. X    if(scalar(@_)!=5){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  713. X    local($cmd, $ser, $soft, $mod, $cla)=@_;
  714. X    local(*histFp, $pathToHistFile);
  715. X    local($retval)=1;        # Success bu default
  716. X
  717. X    $pathToHistFile=
  718. X      ($ser eq '/') ? "$SOFT_DIR/$soft" : "$SERVER_DIR/$ser/$soft"; 
  719. X
  720. X    stat($pathToHistFile);
  721. X    if (-d _ && -w _) {
  722. X    local($hostname);
  723. X    local($domainname);
  724. X    local($date);
  725. X    $hostname= `$PROG_HOSTNAME`; chop $hostname;
  726. X    if ($? != 0) {
  727. X        $retval=0;
  728. X        &NFError($ERR_HIST);
  729. X    }
  730. X    else {
  731. X        $domainname= `$PROG_DOMAINNAME`; chop $domainname;
  732. X        if ($? != 0) {
  733. X        $retval=0;
  734. X        &NFError($ERR_HIST);
  735. X        }
  736. X        else {
  737. X          $date= &Date(1);
  738. X          if ($? != 0) {
  739. X            $retval=0;
  740. X            &NFError($ERR_HIST);
  741. X        }
  742. X        else {
  743. X            local($loginName)=getlogin();
  744. X            local($userName)=(getpwnam($loginName))[6+$[];
  745. X            open(histFp, ">>$pathToHistFile/history");
  746. X            printf histFp "$cmd: $pathToHistFile $mod $cla:\\\n" .
  747. X                          "\t$date:\\\n" .
  748. X                          "\t$hostname.$domainname: " .
  749. X                  "$userName <$loginName@$domainname>\n";
  750. X            close(histFp);
  751. X        }
  752. X        }
  753. X    }
  754. X    }
  755. X
  756. X    return($retval);
  757. X}
  758. X
  759. X
  760. X#-----------------------------------------------------------------------
  761. X# Description : Copy a given source file to a given destination file
  762. X#
  763. X# Parameters  : $srcFile - Source file (i.e. file to be copied)
  764. X#               $dstFile - destination file (i.e. file where to copy)
  765. X#               $opt - option is optionnal!
  766. X#                      if eq to 'a' the file is instead appended
  767. X#                      the default is to overwrite.
  768. X#
  769. X# Returns     : 1 on success
  770. X#               0 if any errors
  771. X#
  772. Xsub CopyFile {
  773. X    # Make sure that the number of parameters is correct
  774. X    if(scalar(@_)!=2 && scalar(@_)!=3){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  775. X    local($srcFile, $dstFile, $opt)=@_;
  776. X    local($retval)=1;        # Success by default.
  777. X    local($copyMode)='>';    # overwrite copy by default 
  778. X    local(*fpin, *fpout, $data);
  779. X
  780. X    if (scalar(@_) == 3) {
  781. X    if ($opt eq 'a') {
  782. X        # Copy mode is append
  783. X        $copyMode='>>';
  784. X    }
  785. X    else {
  786. X        # Unknown option
  787. X        $retval=0;
  788. X    }
  789. X    }
  790. X
  791. X    if ($retval) {        # If still no error
  792. X    if (!open(fpin, $srcFile)) {
  793. X        # Open failed
  794. X        &NFError($ERR_OPEN, $srcFile);
  795. X        $retval=0;
  796. X    }
  797. X    elsif (!open(fpout, "$copyMode$dstFile")) {
  798. X        # Open failed
  799. X        close(fpin);
  800. X        &NFError($ERR_OPEN, "$copyMode$dstFile");
  801. X        $retval=0;
  802. X    }
  803. X    else {
  804. X        local($bytesRead);
  805. X        # Perform the copy
  806. X        do {
  807. X        $bytesRead=sysread(fpin, $data, 2048);
  808. X        if (!defined($bytesRead)) {
  809. X            # Error while reading
  810. X            $retval=0;
  811. X            last;
  812. X        }
  813. X        if (syswrite(fpout, $data, $bytesRead) != $bytesRead) {
  814. X            # Error while writing
  815. X            $retval=0;
  816. X            last;
  817. X        }
  818. X        } while ($bytesRead);
  819. X        close(fpin);
  820. X        close(fpout);
  821. X    }
  822. X    }
  823. X
  824. X    return $retval;
  825. X}
  826. X
  827. X
  828. X#-----------------------------------------------------------------------
  829. X# Description : Display the software that was found, only the first time
  830. X#               this function is invoqued. Any other call will be silent.
  831. X#
  832. X# Parameters  : $softdir - Directory where the software is located
  833. X#               $soft    - Software found
  834. X#               $mod     - Modification of the soft found
  835. X#               $cla     - Class of the software found
  836. X#
  837. X# Returns     : nothing
  838. X#
  839. X#This variable is set when ludemisc is required so that it
  840. X# is ready when the function is called.
  841. X$DispSoftFoundOnce'done=$FALSE;
  842. Xsub DispSoftFoundOnce {
  843. X    # Make sure that the number of parameters is correct
  844. X    if(scalar(@_)!=4){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  845. X    local($softdir, $soft, $mod, $cla)=@_;
  846. X    if ($DispSoftFoundOnce'done==$FALSE) {
  847. X        print $OUT "-- $softdir -- $soft -- mod: $mod -- cla: $cla --\n";
  848. X       $DispSoftFoundOnce'done=$TRUE;
  849. X    }
  850. X}
  851. X
  852. X
  853. X1;
  854. X
  855. X#     ;;; Local Variables: ***
  856. X#     ;;; mode:perl ***
  857. X#     ;;; End: ***
  858. END_OF_FILE
  859.   if test 26934 -ne `wc -c <'lude-1.1/run/crim/sun4.1_sparc/include/lude/ludemisc'`; then
  860.     echo shar: \"'lude-1.1/run/crim/sun4.1_sparc/include/lude/ludemisc'\" unpacked with wrong size!
  861.   fi
  862.   # end of 'lude-1.1/run/crim/sun4.1_sparc/include/lude/ludemisc'
  863. fi
  864. if test -f 'lude-1.1/src/orig/info/Makefile' -a "${1}" != "-c" ; then 
  865.   echo shar: Will not clobber existing file \"'lude-1.1/src/orig/info/Makefile'\"
  866. else
  867.   echo shar: Extracting \"'lude-1.1/src/orig/info/Makefile'\" \(1699 characters\)
  868.   sed "s/^X//" >'lude-1.1/src/orig/info/Makefile' <<'END_OF_FILE'
  869. X# Generated automatically from Makefile.in by configure.
  870. X# Makefile for the lude project.
  871. X
  872. X# Copyright (C) 1992,1993 Stephane Boucher, Ecole Polytechnique de Montreal.
  873. X#
  874. X# This program is free software; you can redistribute it and/or modify
  875. X# it under the terms of the GNU General Public License as published by
  876. X# the Free Software Foundation; either version 1, or (at your option)
  877. X# any later version.
  878. X#
  879. X# This program is distributed in the hope that it will be useful,
  880. X# but WITHOUT ANY WARRANTY; without even the implied warranty of
  881. X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  882. X# GNU General Public License for more details.
  883. X#
  884. X# You should have received a copy of the GNU General Public License
  885. X# along with this program; if not, write to the Free Software
  886. X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  887. X
  888. X# $Id: Makefile.in,v 1.5 1993/03/18 15:37:28 sbo Exp $
  889. X
  890. X# Root of the path where the directories bin, include, lib, etc.
  891. X# can be found.
  892. X# The standard way to install it is:
  893. X# $prefix=/usr/local/soft/lude-version/run/mod/class
  894. X# The class part should preferably the same as first_class
  895. Xprefix=/usr/local/soft/lude-1.1/run/crim/sun4.1_sparc
  896. X
  897. X# Directory where the emacs' info files should be placed.
  898. Xinfodir=$(prefix)/info
  899. X
  900. XLANG_INFO=fra eng
  901. X
  902. XVERSION=1.1
  903. X
  904. XMAKE=make
  905. XCHMOD=chmod
  906. XEMACS=emacs
  907. XSH=sh
  908. XMKDIR=mkdir
  909. XCP=cp
  910. X
  911. X# Install the emacs' info file
  912. Xinstall:
  913. X    @$(SH) -c 'if test ! -d $(infodir); then $(MKDIR) $(infodir); fi;'
  914. X    @$(SH) -c 'for l in $(LANG_INFO); do \
  915. X       $(EMACS) -batch lude_$${l}.texi -f texinfo-format-buffer -f save-buffer; \
  916. X      $(CP) lude_$${l}.info $(infodir); \
  917. X    done;'
  918. X
  919. Xclean:
  920. X    $(RM) lude_???.info *~ #*#
  921. X
  922. Xfull-clean: clean
  923. X    $(RM) Makefile
  924. END_OF_FILE
  925.   if test 1699 -ne `wc -c <'lude-1.1/src/orig/info/Makefile'`; then
  926.     echo shar: \"'lude-1.1/src/orig/info/Makefile'\" unpacked with wrong size!
  927.   fi
  928.   # end of 'lude-1.1/src/orig/info/Makefile'
  929. fi
  930. if test -f 'lude-1.1/src/orig/src/ludeindexinc' -a "${1}" != "-c" ; then 
  931.   echo shar: Will not clobber existing file \"'lude-1.1/src/orig/src/ludeindexinc'\"
  932. else
  933.   echo shar: Extracting \"'lude-1.1/src/orig/src/ludeindexinc'\" \(5469 characters\)
  934.   sed "s/^X//" >'lude-1.1/src/orig/src/ludeindexinc' <<'END_OF_FILE'
  935. X# ludeinc - Project lude.
  936. X# Copyright (C) 1993 Michel Dagenais
  937. X#
  938. X# This program is free software; you can redistribute it and/or modify
  939. X# it under the terms of the GNU General Public License as published by
  940. X# the Free Software Foundation; either version 1, or (at your option)
  941. X# any later version.
  942. X#
  943. X# This program is distributed in the hope that it will be useful,
  944. X# but WITHOUT ANY WARRANTY; without even the implied warranty of
  945. X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  946. X# GNU General Public License for more details.
  947. X#
  948. X# You should have received a copy of the GNU General Public License
  949. X# along with this program; if not, write to the Free Software
  950. X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  951. X
  952. X#-----------------------------------------------------------------------
  953. X#
  954. X# Description: Initialise some variables.
  955. X#              parse and validate the command line arguments.
  956. X#
  957. X# Parameters : none
  958. X#
  959. X# return     : the number of commands still to be done
  960. X#              or -1 if an error occured
  961. X#
  962. Xsub Initialisation {
  963. X    local($cmdsToDo)=0;        # Nothing left to do
  964. X    local($displayVersion)=$FALSE;
  965. X    local($displayFullVersion)=$FALSE;
  966. X
  967. X    
  968. X    local($debug_arg)       =&BldRegexpMinRqr("debug", 1);
  969. X    local($full_version_arg)=&BldRegexpMinRqr("full-version", 2);
  970. X    local($help_arg)        =&BldRegexpMinRqr("help", 2);
  971. X    local($language_arg)    ='language';
  972. X    local($show_arg)        =&BldRegexpMinRqr("show", 2);
  973. X    local($verbose_arg)     =&BldRegexpMinRqr("verbose", 4);
  974. X    local($version_arg)     =&BldRegexpMinRqr("version", 4);
  975. X    local($path_catman_arg) =&BldRegexpMinRqr("pathcatman", 5);
  976. X    local($path_waisman_arg)=&BldRegexpMinRqr("pathwaisman", 5);
  977. X    local($path_info_arg)   =&BldRegexpMinRqr("pathinfo", 5);
  978. X    local($path_soft_arg)   =&BldRegexpMinRqr("pathsoft", 5);
  979. X    local($host_www_arg)    =&BldRegexpMinRqr("hostwww", 5);
  980. X    local($host_wais_arg)   =&BldRegexpMinRqr("hostwais", 5);
  981. X    local($port_www_arg)    =&BldRegexpMinRqr("portwww", 5);
  982. X    local($port_wais_arg)   =&BldRegexpMinRqr("portwais", 5);
  983. X    local($catman_arg)      =&BldRegexpMinRqr("catman", 3);
  984. X    local($waisman_arg)     =&BldRegexpMinRqr("waisman", 5);
  985. X    local($info_arg)        =&BldRegexpMinRqr("info", 3);
  986. X    local($wwwsoft_arg)     =&BldRegexpMinRqr("wwwsoft", 4);
  987. X    local($waissoft_arg)    =&BldRegexpMinRqr("waissoft", 5);
  988. X    local($remotelink_arg)  =&BldRegexpMinRqr("remotelink", 5);
  989. X    local($no_www_ext_arg)  =&BldRegexpMinRqr("nowwwext", 5);
  990. X    local($all_arg)         =&BldRegexpMinRqr("all", 1);
  991. X
  992. X    while ($_=$ARGV[0],/^-/) {
  993. X
  994. X    last if (/^--$/);
  995. X
  996. X    shift(@ARGV);
  997. X
  998. X    if    (/^-$debug_arg$/o)     { &Arg($_, *Debugvalue, '[0-9]+'); }
  999. X    elsif (/^-$full_version_arg$/o) { $displayFullVersion=$TRUE; }
  1000. X    elsif (/^-($help_arg)|([?])$/o) { $Help=$TRUE; }
  1001. X    elsif (/^-$language_arg$/o)  { shift @ARGV; } # Just ignore it
  1002. X    elsif (/^-$show_arg$/o)      { $Show=$Verbose=$TRUE; } # Show implies Verbose
  1003. X    elsif (/^-$verbose_arg$/o)   { $Verbose=$TRUE; }
  1004. X    elsif (/^-$version_arg$/o)   { $displayVersion=$TRUE; }
  1005. X        elsif (/^-$path_catman_arg$/o) {
  1006. X            &Arg($_, *PathCatMan, '[^\s]+');
  1007. X        }
  1008. X        elsif (/^-$path_waisman_arg$/o) {
  1009. X            &Arg($_, *PathWAISMan, '[^\s]+');
  1010. X        }
  1011. X        elsif (/^-$path_info_arg$/o) {
  1012. X            &Arg($_, *PathInfo, '[^\s]+');
  1013. X        }
  1014. X        elsif (/^-$path_soft_arg$/o) {
  1015. X            &Arg($_, *PathSoft, '[^\s]+');
  1016. X        }
  1017. X    elsif (/^-$host_www_arg$/o)  {
  1018. X        &Arg($_, *HostWWW, '[^\s]+'); 
  1019. X    }
  1020. X    elsif (/^-$host_wais_arg$/o)  {
  1021. X        &Arg($_, *HostWAIS, '[^\s]+'); 
  1022. X    }
  1023. X    elsif (/^-$port_www_arg$/o)  {
  1024. X        &Arg($_, *PortWWW, '[0-9]+'); 
  1025. X    }
  1026. X    elsif (/^-$port_wais_arg$/o)  {
  1027. X        &Arg($_, *PortWAIS, '[0-9]+'); 
  1028. X    }
  1029. X        elsif (/^-$catman_arg$/o)   { $CatMan=$TRUE; }
  1030. X        elsif (/^-$waisman_arg$/o)  { $WAISMan=$TRUE; }
  1031. X        elsif (/^-$info_arg$/o)     { $Info=$TRUE; }
  1032. X        elsif (/^-$wwwsoft_arg$/o)  { $WWWSoft=$TRUE; }
  1033. X        elsif (/^-$waissoft_arg$/o) { $WAISSoft=$WWWSoft=$TRUE; }
  1034. X        elsif (/^-$remotelink_arg$/o) { $RemoteLink=$TRUE; }
  1035. X        elsif (/^-$no_www_ext_arg$/o) { $NoWWWExt=$TRUE; }
  1036. X        elsif (/^-$all_arg$/o)  { 
  1037. X            $CatMan=$WAISMan=$Info=$WWWSoft=$WAISSoft=$TRUE;
  1038. X        }
  1039. X
  1040. X    else {
  1041. X            print "$PGM: $TEXT[$BAD_ARGUMENT] $_\n";
  1042. X            print "\n$TEXT[$USAGE_HELP]\n";
  1043. X            exit(1);
  1044. X    }
  1045. X    }
  1046. X
  1047. X    # Display the version immediately if requested
  1048. X    if ($displayVersion) {
  1049. X    print $VERSION ."\n";
  1050. X    }
  1051. X    # Display the full version (i.e. RCS revs) immediately if requested
  1052. X    if ($displayFullVersion) {
  1053. X    print $FULL_VERSION ."\n";
  1054. X    }
  1055. X
  1056. X    #
  1057. X    # Validation of the arguments
  1058. X    #
  1059. X    # Extra and invalid argument 
  1060. X    if ( $ARGV[0] ne "" ) { 
  1061. X        print "$PGM: $TEXT[$BAD_ARGUMENT] $ARGV[0]\n";
  1062. X        print "\n$TEXT[$USAGE_HELP]\n";
  1063. X        exit(1);
  1064. X    }
  1065. X
  1066. X}    
  1067. X
  1068. Xsub Help {
  1069. X    print "$TEXT[$USAGE_HELP]\n\n";
  1070. X    exit 0;
  1071. X}
  1072. X
  1073. Xsub BaseName {
  1074. X    local($name)=@_;
  1075. X    substr($name,rindex($name, "/") + 1);
  1076. X}                               
  1077. X
  1078. X
  1079. Xsub Arg {
  1080. X
  1081. X    local($switch, *value, $type)=@_;
  1082. X    
  1083. X    if (scalar(@ARGV)>0 && $ARGV[0] =~ m/^$type$/) {
  1084. X    # The value is consitent with the type it must have
  1085. X    $value=$ARGV[0];
  1086. X    shift(@ARGV);
  1087. X    }
  1088. X    else {
  1089. X    # The value is inconsistent with the type it must have
  1090. X        print "$PGM: $TEXT[$BAD_TYPE] $switch\n";
  1091. X        exit(1);
  1092. X    }            
  1093. X}
  1094. X        
  1095. X1;
  1096. X
  1097. X#     ;;; Local Variables: ***
  1098. X#     ;;; mode:perl ***
  1099. X#     ;;; End: ***
  1100. END_OF_FILE
  1101.   if test 5469 -ne `wc -c <'lude-1.1/src/orig/src/ludeindexinc'`; then
  1102.     echo shar: \"'lude-1.1/src/orig/src/ludeindexinc'\" unpacked with wrong size!
  1103.   fi
  1104.   # end of 'lude-1.1/src/orig/src/ludeindexinc'
  1105. fi
  1106. if test -f 'lude-1.1/src/orig/src/ludemisc' -a "${1}" != "-c" ; then 
  1107.   echo shar: Will not clobber existing file \"'lude-1.1/src/orig/src/ludemisc'\"
  1108. else
  1109.   echo shar: Extracting \"'lude-1.1/src/orig/src/ludemisc'\" \(26934 characters\)
  1110.   sed "s/^X//" >'lude-1.1/src/orig/src/ludemisc' <<'END_OF_FILE'
  1111. X# ludemisc - Project lude.
  1112. X# Copyright (C) 1991,1992  Pierre Laplante
  1113. X# Copyright (C) 1992,1993 Stephane Boucher, Ecole Polytechnique de Montreal.
  1114. X#
  1115. X# This program is free software; you can redistribute it and/or modify
  1116. X# it under the terms of the GNU General Public License as published by
  1117. X# the Free Software Foundation; either version 1, or (at your option)
  1118. X# any later version.
  1119. X#
  1120. X# This program is distributed in the hope that it will be useful,
  1121. X# but WITHOUT ANY WARRANTY; without even the implied warranty of
  1122. X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1123. X# GNU General Public License for more details.
  1124. X#
  1125. X# You should have received a copy of the GNU General Public License
  1126. X# along with this program; if not, write to the Free Software
  1127. X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1128. X
  1129. X$FULL_VERSION.= '$Id: ludemisc,v 1.4 1993/03/17 19:44:14 sbo Exp $' ."\n";
  1130. X
  1131. X#-----------------------------------------------------------------------
  1132. X# Various useful global definitions
  1133. X
  1134. Xif (!defined($DEFAULTDEBUGLEVEL)) { $DEFAULTDEBUGLEVEL=9; }
  1135. Xif (!defined($TRUE))              { $TRUE=1; }
  1136. Xif (!defined($FALSE))             { $FALSE=0; }
  1137. Xif (!defined($ERROR))             { $ERROR=STDERR; }
  1138. Xif (!defined($OUT))               { $OUT=STDOUT; }
  1139. X
  1140. Xif (!defined($LUDE_FILE))         { die "\$LUDE_FILE should be defined, stopped at"; }
  1141. Xif (!defined($LUDE_STAMP))        { $LUDE_STAMP="$LUDE_FILE"; }
  1142. X
  1143. X#-----------------------------------------------------------------------
  1144. X# Description : Search for a software according to the search keys
  1145. X#               given as parameters. Only  the softwares that are
  1146. X#               ready (file LUDE under install/mod/class) are
  1147. X#               considered, unless 't' command is given. In that
  1148. X#               case, only the existence of /usr/local/soft/soft/install/mod/class
  1149. X#               rather than /usr/local/soft/soft/install/mod/class/LUDE
  1150. X#               to verify the match.
  1151. X#
  1152. X# Parameters  : $cmd - String indicating the command/location where
  1153. X#                      to look for a copy of the software.
  1154. X#                      'l' means local (in /usr/local)
  1155. X#                      's' means on the servers (in /usr/local/server)
  1156. X#                      't' Don't check for the lude stamp. By default
  1157. X#                          the stamp must be there.
  1158. X#                      'a' Means return all the possible matches.
  1159. X#                          The commands/locations can be combined.
  1160. X#                          The default is to return only the first match.
  1161. X#               $server - specify a server to search. If specified
  1162. X#                         only that server is searched. the other commands
  1163. X#                         to specify servers location are therefore ignored.
  1164. X#               $soft - name of the software that is to be searched.
  1165. X#               $mod - specify a modification to look for.
  1166. X#                      If not specified, all the mods are
  1167. X#                      searched.
  1168. X#               @classes - list of classes, in order of preference,
  1169. X#                          used to find a match. At least one is required.
  1170. X#
  1171. X# Returns     : a list of the form:
  1172. X#               (join($;, $server, $soft, $mod, $class), 
  1173. X#                join($;, $server2, $soft2, $mod2, $class2)) 
  1174. X#               An empty list indicate that the software 
  1175. X#               was not found.
  1176. X#               an undef value indicate that an error occured.
  1177. X#               $server has a special value. if set to '/'
  1178. X#               it means that the server is local 
  1179. X#               (i.e. directory /usr/local).
  1180. X#
  1181. Xsub FindSoftware {
  1182. X    # Make sure that the number of parameters is correct
  1183. X    if (scalar(@_)<5){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d", scalar(@_), __FILE__, __LINE__));}
  1184. X    local($cmd, $server, $soft, $mod, @classes)=@_;
  1185. X    local(@lstcmds)=();
  1186. X    local(@lstservers)=();    # List of all servers that will be searched
  1187. X    local(@lstsofts)=();    # List of all softwares that will be looked
  1188. X    local(@lstmods)=();        # List of all the modification that will 
  1189. X                                # be looked
  1190. X    local(@lstclasses)=();    # List of all the classes that will be looked
  1191. X    local($stamp)=$LUDE_STAMP;
  1192. X    local($keepallmatches)=$FALSE; # The default is to keep only the first
  1193. X                   # soft/mod/class combination that matches
  1194. X                   # The command 'a' turns this value to 
  1195. X                                   # $TRUE so that all the matching 
  1196. X                                   # combination will be kept.
  1197. X    local(@matches)=();        # List of all the matches found.
  1198. X
  1199. X    # Check to see if a server was specified
  1200. X    if ($server eq '/') {    # Local server
  1201. X    push(@lstservers, "$SOFT_DIR");
  1202. X    }
  1203. X    elsif ($server ne '') {    # remote server
  1204. X    push(@lstservers, "$SERVER_DIR/$server");
  1205. X    }
  1206. X    else {
  1207. X    # no server specified
  1208. X    }
  1209. X
  1210. X    # Examine the commands and build the lstservers
  1211. X    @lstcmds=split(//, $cmd);
  1212. X    for $c (@lstcmds) {
  1213. X    if ($c eq 'l') {    # Local server
  1214. X        if ($server eq '') { # (only if no server is specified)
  1215. X        # use unshift so that the soft in $SOFT_DIR has precedence
  1216. X        unshift(@lstservers, "$SOFT_DIR");
  1217. X        }
  1218. X    }
  1219. X    elsif ($c eq 's') {    # Remote server
  1220. X        if ($server eq '') { # (only If no server is specified)
  1221. X        local(*dir, @lstdir);
  1222. X
  1223. X        # Read the directory containing the available remote
  1224. X        # servers.
  1225. X        opendir(dir, "$SERVER_DIR");
  1226. X        @lstdir=grep(!/^\.{1,2}$/, readdir(dir));
  1227. X        closedir(dir);
  1228. X
  1229. X        #For all servers found prepend $SERVER_DIR so that we
  1230. X        # have /usr/local/server/something instead of
  1231. X        # something. ($SERVER_DIR being equal to 
  1232. X        # /usr/local/server by default)
  1233. X        for (@lstdir) { s|(.*)|$SERVER_DIR/$1|; }
  1234. X
  1235. X        # Add the servers found to the existing list
  1236. X        # use push so that the soft in $SOFT_DIR has precedence
  1237. X        push(@lstservers, @lstdir);
  1238. X        }
  1239. X    }
  1240. X    elsif ($c eq 't') {
  1241. X        # By setting stamp to '', the stamp (or file that
  1242. X        # indicate that a software is publicly available)
  1243. X        # is not required. i.e. only the path leading
  1244. X        # to the place where the file resides when any 
  1245. X        # is required.
  1246. X        # for exemple: if 
  1247. X        # /usr/local/emacs-18.58/install/poly/sun4.1_sparc
  1248. X        # exists, than the software is taken as existing.
  1249. X        # Otherwise, with 't' not specified, the file
  1250. X        # /usr/local/emacs-18.58/install/poly/sun4.1_sparc/$LUDE_STAMP
  1251. X        # must exist to have a match. ($LUDE_STAMP contains
  1252. X        # the name of the file that identifies the availability
  1253. X        # of a software).
  1254. X        $stamp='';
  1255. X    }
  1256. X    elsif ($c eq 'a') {
  1257. X        # Keep searching to find all softwares available.
  1258. X        # The default is to stop searching as soon as a
  1259. X        # software is found.
  1260. X        $keepallmatches=$TRUE;
  1261. X    }
  1262. X    else {
  1263. X        # The command found is not one that is defined.
  1264. X        &Error($ERR_INTERNAL, "Incorrect parameter to function");
  1265. X    }
  1266. X    }
  1267. X
  1268. X    # look at each servers
  1269. X    for $path (@lstservers) {
  1270. X    # Set the software list to examine
  1271. X    if ($soft ne '') {
  1272. X        # if a software was specified in parameters, then
  1273. X        # only that software will be examined.
  1274. X        @lstsofts=($soft);
  1275. X    }
  1276. X    else {
  1277. X        # No software was specified. Therefore examine all the
  1278. X        # available softwares on the current server.
  1279. X        local(*dir);
  1280. X        opendir(dir, "$path");
  1281. X        @lstsofts=grep(!/^\.{1,2}$/, readdir(dir));
  1282. X        closedir(dir);
  1283. X    }
  1284. X
  1285. X    # Examine the specified software for the current server.
  1286. X    for $s (@lstsofts) {
  1287. X        if (-r "$path/$s/install") {
  1288. X        # if a modification was specified in parameters, then
  1289. X        # only that modification will be examined.
  1290. X        if ($mod ne '') {
  1291. X            # Use the specified modification
  1292. X            @lstmods=($mod);
  1293. X        }
  1294. X        else {
  1295. X            # No modification was specified. Therefore
  1296. X            # examine all the available softwares on the
  1297. X            # current server.
  1298. X            local(*dir);
  1299. X            opendir(dir, "$path/$s/install");
  1300. X            @lstmods=grep(!/^\.{1,2}$/, readdir(dir));
  1301. X            closedir(dir);
  1302. X        }
  1303. X
  1304. X        # Examine the modifications for the current 
  1305. X        # server/software.
  1306. X        for $m (@lstmods) {
  1307. X            if (@classes == 1 && $classes[$[] eq '') {
  1308. X            # Use all the available classes, if only
  1309. X            # one class is given and that class is eq
  1310. X            # to the special value ''.
  1311. X            local(*dir);
  1312. X            opendir(dir, "$path/$s/install/$m");
  1313. X            @lstclasses=grep(!/^\.{1,2}$/, readdir(dir));
  1314. X            closedir(dir);
  1315. X            }
  1316. X            else {
  1317. X            # if any classes were specified in parameters,
  1318. X            # then only those classes will be examined.
  1319. X            @lstclasses=@classes;
  1320. X            }
  1321. X
  1322. X            # Examine the classes for the curent server/soft/mod
  1323. X            for $c (@lstclasses) {
  1324. X            if (-e "$path/$s/install/$m/$c/$stamp") {
  1325. X                # The file $stamp exist, therefore the
  1326. X                # combination server/soft/mod/class is 
  1327. X                # declared available and added to the
  1328. X                # list of matches. (Note that if the
  1329. X                # command 't' was given in parameters
  1330. X                # $stamp is eq to '', and the test of
  1331. X                # existence is made only on the directory
  1332. X                # leading to the place where $LUDE_STAMP
  1333. X                # resides when existing.
  1334. X                if ($path =~ m|^($SERVER_DIR)/(.+)$|) {
  1335. X                # The path matches the form
  1336. X                # /usr/local/server/some_server.
  1337. X                # extract the part some_server and
  1338. X                # use this with $s (soft), $m (modification)
  1339. X                # $c (class) to form a new entry in the
  1340. X                # list of matches.
  1341. X                push(@matches, join($;, $2, $s, $m, $c));
  1342. X                if (! $keepallmatches) {
  1343. X                    # Return the first found match
  1344. X                    return @matches;
  1345. X                }
  1346. X                }
  1347. X                else {
  1348. X                # The server is local, so use the special
  1349. X                # value '/' as the server.
  1350. X                push(@matches, join($;, '/', $s, $m, $c));
  1351. X                if (! $keepallmatches) {
  1352. X                    # Return the first found match
  1353. X                    return @matches;
  1354. X                }
  1355. X                }
  1356. X            }
  1357. X            }
  1358. X        }
  1359. X        }
  1360. X        else {
  1361. X        # The software is not on this server
  1362. X        }
  1363. X    }
  1364. X    }
  1365. X
  1366. X    return @matches;
  1367. X}
  1368. X
  1369. X
  1370. X#-----------------------------------------------------------------------
  1371. X# Description : Run a command, and then return so that the execution 
  1372. X#               can continue.
  1373. X#               The global variable $Show is used to determine whether
  1374. X#               to execute the command, or simply display the command
  1375. X#               that is to be run.
  1376. X#
  1377. X# Parameters  : $cmd - Command to run
  1378. X#
  1379. X# Returns     : The returned value from the executed command
  1380. X#               or 0 if $Show is set
  1381. X#               In this case, 0 indicate success because
  1382. X#               returned value correspond to the exit status
  1383. X#               of the command, 0 being the standard exit value
  1384. X#               to indicate success.
  1385. X#
  1386. Xsub RunCmd {
  1387. X    local($cmd)=join(' ', @_);
  1388. X    local($retval)=0;        # success by default
  1389. X    
  1390. X    if (&VerboseRetShow($WARN_CMD, $cmd)) {
  1391. X    # Show is on, so do nothing
  1392. X    }
  1393. X    else {
  1394. X    $retval=system($cmd) / 256;
  1395. X    }
  1396. X    return $retval;
  1397. X}
  1398. X#-----------------------------------------------------------------------
  1399. X# Description : Validate the value specified for the given switch.
  1400. X#               The value is returned in *value.
  1401. X#
  1402. X# Parameters  : $switch - Name of the switch
  1403. X#               *value  - adress of the variable where the 
  1404. X#                         validated value is placed
  1405. X#               $type   - regexp used to check against the actual
  1406. X#                         value. If the regexp matches the value,
  1407. X#                         then that value is returned as valid.
  1408. X#
  1409. X# Returns     : nothing if no error
  1410. X#               never returns if error
  1411. X#
  1412. Xsub Arg {
  1413. X    # Make sure that the number of parameters is correct
  1414. X    if (scalar(@_)!=3) {
  1415. X    &Error($ERR_INTERNAL, 
  1416. X           sprintf("(%d), %s:%d", scalar(@_), __FILE__, __LINE__));
  1417. X    }
  1418. X    local($switch, *value, $type)=@_;
  1419. X    
  1420. X    if (scalar(@ARGV)>0 && $ARGV[0] =~ m/^$type$/) {
  1421. X    # The value is consitent with the type it must have
  1422. X    $value=$ARGV[0];
  1423. X    shift(@ARGV);
  1424. X    }
  1425. X    else {
  1426. X    # The value is inconsistent with the type it must have
  1427. X    &Usage($ERR_ARG, $switch, $type);  
  1428. X    }            
  1429. X}
  1430. X
  1431. X#-----------------------------------------------------------------------
  1432. X# Description : Test to see if the system has the required
  1433. X#               functionnality.
  1434. X#               Test for the availability of the command
  1435. X#               that will be needed during the execution
  1436. X#               of the lude scripts.
  1437. X#
  1438. X# Parameters  : none
  1439. X#
  1440. X# Returns     : 1 if everything is fine.
  1441. X#               0 if something wrong was found.
  1442. X#
  1443. Xsub VerifySystem {
  1444. X    # Make sure that the number of parameters is correct
  1445. X    if (scalar(@_)!=0) {
  1446. X    &Error($ERR_INTERNAL, 
  1447. X           sprintf("(%d), %s:%d", scalar(@_), __FILE__, __LINE__));
  1448. X    }
  1449. X    local($retval)=1;        # Success by default
  1450. X
  1451. X    # Check if the command tar is available
  1452. X    if (! &Exist((split(/\s+/, "$PROG_TAR", 2))[0])) {
  1453. X    &NFError($ERR_CMD, "$PROG_TAR");
  1454. X    $retval=0;
  1455. X    }
  1456. X    # Check if the command cmp is available
  1457. X    if (! &Exist((split(/\s+/, "$PROG_CMP", 2))[0])) {
  1458. X    &NFError($ERR_CMD, "$PROG_CMP");
  1459. X    $retval=0;
  1460. X    }
  1461. X    # Check if the command $MAKEWHATIS is available
  1462. X    if (! &Exist((split(/\s+/, "$PROG_MAKEWHATIS", 2))[0])) {
  1463. X    &NFError($ERR_CMD, $PROG_MAKEWHATIS);
  1464. X    $retval=0;
  1465. X    }
  1466. X    # Check if the command class is available
  1467. X    if (! &Exist('class')) {
  1468. X    &NFError($ERR_CMD, 'class');
  1469. X    $retval=0;
  1470. X    }
  1471. X
  1472. X    return $retval;
  1473. X}
  1474. X
  1475. X#-----------------------------------------------------------------------
  1476. X# Description : Search the values associated to the server/soft/mod
  1477. X#               triplet. The values are located in either
  1478. X#               .../install/$IAFA_FILE or .../install/$mod/$LUDE_FILE.
  1479. X#               Files are searched in the given order.
  1480. X#
  1481. X# Parameters  : $server   - Server to look for
  1482. X#               $soft     - Software to look for
  1483. X#               $dataFile - File to search (relative to ....soft/install)
  1484. X#               @kws      - List of keywords to search
  1485. X#
  1486. X# Returns     : an assoc. array of the form $aa{"$keyword"}=$value
  1487. X#               If 2 or more occurence of the same keyword, the last
  1488. X#               value is kept.
  1489. X#               If nothing is found, an empty array is returned.
  1490. X#               if an error occured, undef is returned.
  1491. X#
  1492. Xsub GetKeyWord {
  1493. X    # Make sure that the number of parameters is correct
  1494. X    if (scalar(@_)<4) { &Error($ERR_INTERNAL, sprintf("(%d), %s:%d", scalar(@_), __FILE__, __LINE__)); }
  1495. X    local($server, $soft, $dataFile, @kws)=@_; 
  1496. X    local(%kwval)=();        # By default nothing was found
  1497. X    local($file, *fptr);
  1498. X    local($kword, $value);
  1499. X
  1500. X    # Determine the location of the file
  1501. X    if ($server ne '/') {
  1502. X    # On a remote server
  1503. X    $file="$SERVER_DIR/$server/$soft/install/$dataFile";
  1504. X    }
  1505. X    else {
  1506. X    # Local server
  1507. X    $file="$SOFT_DIR/$soft/install/$dataFile";
  1508. X    }
  1509. X
  1510. X    # Test for the accessibility of the software's log file
  1511. X    stat($file);
  1512. X    if (-e _ && -f _ && -r _) {
  1513. X    if (! open(fptr, $file)) {
  1514. X        # Cannot open the log file
  1515. X        &NFError($ERR_FILE, $file);
  1516. X    }
  1517. X    else {
  1518. X        # Undef the temporary variable that holds the text
  1519. X        # for the current keyword. This means that nothing
  1520. X        # is being accumulated for a keyword.
  1521. X        undef $value;
  1522. X        
  1523. X        # Scan the log file
  1524. X        while (<fptr>) {
  1525. X        if (! defined($value) || /^[\-a-z]+:/i) {
  1526. X            # No keyword is currently being processed
  1527. X            # or the current line has the structure
  1528. X            # of a line with a keyword. (e.g. 
  1529. X            # ^keyword: text....)
  1530. X
  1531. X            # Check the line against all desired keywords
  1532. X            for $k (@kws) {
  1533. X            if (/^$Logkw{$k}:(.*)$/i) {
  1534. X                # The current line matches the keyword $k.
  1535. X                if (defined($value)) {
  1536. X                # A $value was already being accumulated
  1537. X                # for a previously found keyword, so store
  1538. X                # the $value for the previous keyword.
  1539. X                $kwval{"$kword"}=$value;
  1540. X                }
  1541. X                # Set the new current keyword
  1542. X                $kword=$k;
  1543. X                # Accumulate the first part of the value
  1544. X                # That was found following the keyword.
  1545. X                $value="$1\n";
  1546. X            }
  1547. X            }
  1548. X        }
  1549. X        else {
  1550. X            # The line is an ordinary line that was preceded
  1551. X            # by, maybe some ordinary line, and a line containing
  1552. X            # a keyword.
  1553. X            # Concatenate the current line to the accumulated
  1554. X            # value of the current keyword.
  1555. X            $value .= $_;
  1556. X        }
  1557. X        }
  1558. X
  1559. X        # The entire file was scanned
  1560. X
  1561. X        if (defined($value)) {
  1562. X        # $value contains a value, and file file is
  1563. X        # all scanned. So store the final value for the current
  1564. X        # keyword.
  1565. X        $kwval{"$kword"}=$value;
  1566. X        }
  1567. X        # Close the log file
  1568. X        close(fptr);
  1569. X    }
  1570. X    }
  1571. X    return %kwval;
  1572. X}
  1573. X
  1574. X
  1575. X#-----------------------------------------------------------------------
  1576. X# Description : Scan the env. variable PATH to find the given command.
  1577. X#
  1578. X# Parameters  : $cmd - Command to be located.
  1579. X#
  1580. X# Returns     : 1 if command is found
  1581. X#               0 if the command is not found
  1582. X#
  1583. Xsub Exist {
  1584. X    # Make sure that the number of parameters is correct
  1585. X    if(scalar(@_)!=1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  1586. X    local($cmd)=@_;
  1587. X    local(@dir);
  1588. X    local($found)=0;        # Nothing found by default
  1589. X
  1590. X    if ($cmd =~ m|/|) {    
  1591. X    # The command has a path component 
  1592. X    # (e.g. bin/ls ./cat /usr/bin/ls etc)
  1593. X    # so we don't check against PATH
  1594. X    if (-x $cmd) {
  1595. X        $found=1;
  1596. X    }
  1597. X    }
  1598. X    else {
  1599. X    @dir=split(/:/, $ENV{'PATH'});
  1600. X    for $d (@dir) { $found=1 if (-x "$d/$cmd"); }
  1601. X    }
  1602. X    return $found;
  1603. X}                
  1604. X
  1605. X#-----------------------------------------------------------------------
  1606. X# Description : Output debug tracing information.
  1607. X#
  1608. X# Parameters  : $level - Specify the level of the message.
  1609. X#                        If the level is supperior to the level that
  1610. X#                        is run, then the message is displayed.
  1611. X#               @rest  - List of arguments compatible with printf
  1612. X#                        that represent the debug message.
  1613. X#
  1614. X# Returns     : nothing
  1615. X#
  1616. Xsub Debug {
  1617. X    local($level,@rest)=@_;
  1618. X    if ($Debuglevel > $level) {
  1619. X    print "DEBUG ";
  1620. X    printf (@rest);
  1621. X    }
  1622. X}                   
  1623. X
  1624. X#-----------------------------------------------------------------------
  1625. X# Description : Non Fatal Error. Display the message given and return.
  1626. X#
  1627. X# Parameters  : $code - Error code that identifies the message
  1628. X#               @rest - other arguments that are required by
  1629. X#                       the format (a la printf) that correspond
  1630. X#                       to $code.
  1631. X#
  1632. X# Returns     : nothing, but unlike Error it returns!
  1633. X#
  1634. Xsub NFError {
  1635. X    # Make sure that the number of parameters is correct
  1636. X    if(scalar(@_)<1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  1637. X    local($code,@rest)=@_;
  1638. X
  1639. X    print $ERROR "$Progname: ";
  1640. X    printf $ERROR ($MSGS[$code], @rest);
  1641. X    print $ERROR "\n";
  1642. X}
  1643. X
  1644. X#-----------------------------------------------------------------------
  1645. X# Description : Fatal Error. Display the message given and abort 
  1646. X#               execution.
  1647. X#
  1648. X# Parameters  : $code - Error code that identifies the message
  1649. X#               @rest - other arguments that are required by
  1650. X#                       the format (a la printf) that correspond
  1651. X#                       to $code.
  1652. X#
  1653. X# Returns  : Never returns.
  1654. X#
  1655. Xsub Error {
  1656. X    # Make sure that the number of parameters is correct
  1657. X    if(scalar(@_)<1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  1658. X    local($code)=@_;
  1659. X    &NFError(@_);
  1660. X    exit($code);
  1661. X}
  1662. X
  1663. X#-----------------------------------------------------------------------
  1664. X# Description : Warning. Display the message given and return.
  1665. X#
  1666. X# Parameters  : $code - Error code that identifies the message
  1667. X#               @rest - other arguments that are required by
  1668. X#                       the format (a la printf) that correspond
  1669. X#                       to $code.
  1670. X#
  1671. X# Returns  : nothing, but unlike Error and like NFError it returns!
  1672. X#
  1673. Xsub Warning {
  1674. X    # Make sure that the number of parameters is correct
  1675. X    if(scalar(@_)<1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  1676. X    local($code,@rest)=@_;
  1677. X    printf $OUT ($MSGS[$code], @rest);
  1678. X    print $OUT "\n";
  1679. X}
  1680. X
  1681. X#-----------------------------------------------------------------------
  1682. X# Description : Display a message if the global variable $Verbose
  1683. X#               $FALSE, otherwise, do nothing.
  1684. X#
  1685. X# Parameters  : $code - Code that identifies the message
  1686. X#               @rest - other arguments that are required by
  1687. X#                       the format (a la printf) that correspond
  1688. X#                       to $code.
  1689. X#
  1690. X# Returns     : The value of $Show
  1691. X#
  1692. Xsub VerboseRetShow {
  1693. X    &Verbose(@_);
  1694. X    return $Show;
  1695. X}
  1696. Xsub Verbose {
  1697. X    if (@_ != 0) {
  1698. X    local($code,@rest)=@_;
  1699. X    if ($Verbose != $FALSE) {
  1700. X        printf $OUT ($MSGS[$code], @rest);
  1701. X        print $OUT "\n";
  1702. X    }
  1703. X    }
  1704. X}
  1705. X
  1706. X#-----------------------------------------------------------------------
  1707. X# Description : Extract the directory component of the file name.
  1708. X#               Return that component.
  1709. X#
  1710. X# Parameters  : $name - Full path
  1711. X#
  1712. X# Returns     : Returns the extracted component.
  1713. X#
  1714. Xsub DirName {
  1715. X    # Make sure that the number of parameters is correct
  1716. X    if(scalar(@_)!=1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  1717. X    local($name)=@_;
  1718. X    substr($name, 0, rindex($name, "/"));
  1719. X}                
  1720. X
  1721. X#-----------------------------------------------------------------------
  1722. X# Description : Extract the last component of the file name.
  1723. X#               Return that component.
  1724. X#
  1725. X# Parameters  : $name - Full path. 
  1726. X#
  1727. X# Returns     : Returns the extracted component.
  1728. X#
  1729. Xsub BaseName {
  1730. X    # Make sure that the number of parameters is correct
  1731. X    if(scalar(@_)!=1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  1732. X    local($name)=@_;
  1733. X    substr($name,rindex($name, "/") + 1);
  1734. X}                
  1735. X    
  1736. X#-----------------------------------------------------------------------
  1737. X# Description : Display the usage of the script
  1738. X#
  1739. X# Parameters  : $code - Error code that caused usage to be called.
  1740. X#               @rest - other arguments that are required by
  1741. X#                       the format (a la printf) that correspond
  1742. X#                       to $code.
  1743. X#
  1744. X# Returns     : Never returns.
  1745. X#
  1746. Xsub Usage {            
  1747. X    # Make sure that the number of parameters is correct
  1748. X    if(scalar(@_)<1){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  1749. X    local($code, @rest)=@_;
  1750. X    
  1751. X    printf $ERROR ($MSGS[$code],@rest) if ($code != $OK);
  1752. X    print $ERROR "\n$MSGS[$USAGE]\n";     
  1753. X    exit $code if ($code);
  1754. X}
  1755. X
  1756. Xsub Help {
  1757. X    print $ERROR "$MSGS[$USAGE]\n\n";
  1758. X    exit 0;
  1759. X}
  1760. X
  1761. X#-----------------------------------------------------------------------
  1762. X#    date(FORMAT): Return date in format yy/mm/dd
  1763. X#
  1764. Xsub Date {
  1765. X    local($FMT_YYMMDD)=0;
  1766. X    local($FMT_YYMMDDHHMMSS)=1;
  1767. X    local($fmt)=@_;
  1768. X    local($sec,$min,$hour,$mday,$mon,$year,@rest)=localtime(time);
  1769. X
  1770. X    $mon++;
  1771. X    if ($fmt==$FMT_YYMMDD) {
  1772. X    sprintf("%2.2d/%2.2d/%2.2d", $year,$mon,$mday);
  1773. X    } 
  1774. X    elsif ($fmt==$FMT_YYMMDDHHMMSS) {
  1775. X    sprintf("%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d", $year, $mon, 
  1776. X        $mday, $hour, $min, $sec);
  1777. X    }
  1778. X}
  1779. X
  1780. X#-----------------------------------------------------------------------
  1781. X# Description : Append information about a command, to the history
  1782. X#                file of a software.
  1783. X# 
  1784. X# Parameters  : 
  1785. X#
  1786. X# Returns     : 1 on success
  1787. X#               0 if any errors
  1788. X#
  1789. Xsub HistAppend {
  1790. X    # Make sure that the number of parameters is correct
  1791. X    if(scalar(@_)!=5){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  1792. X    local($cmd, $ser, $soft, $mod, $cla)=@_;
  1793. X    local(*histFp, $pathToHistFile);
  1794. X    local($retval)=1;        # Success bu default
  1795. X
  1796. X    $pathToHistFile=
  1797. X      ($ser eq '/') ? "$SOFT_DIR/$soft" : "$SERVER_DIR/$ser/$soft"; 
  1798. X
  1799. X    stat($pathToHistFile);
  1800. X    if (-d _ && -w _) {
  1801. X    local($hostname);
  1802. X    local($domainname);
  1803. X    local($date);
  1804. X    $hostname= `$PROG_HOSTNAME`; chop $hostname;
  1805. X    if ($? != 0) {
  1806. X        $retval=0;
  1807. X        &NFError($ERR_HIST);
  1808. X    }
  1809. X    else {
  1810. X        $domainname= `$PROG_DOMAINNAME`; chop $domainname;
  1811. X        if ($? != 0) {
  1812. X        $retval=0;
  1813. X        &NFError($ERR_HIST);
  1814. X        }
  1815. X        else {
  1816. X          $date= &Date(1);
  1817. X          if ($? != 0) {
  1818. X            $retval=0;
  1819. X            &NFError($ERR_HIST);
  1820. X        }
  1821. X        else {
  1822. X            local($loginName)=getlogin();
  1823. X            local($userName)=(getpwnam($loginName))[6+$[];
  1824. X            open(histFp, ">>$pathToHistFile/history");
  1825. X            printf histFp "$cmd: $pathToHistFile $mod $cla:\\\n" .
  1826. X                          "\t$date:\\\n" .
  1827. X                          "\t$hostname.$domainname: " .
  1828. X                  "$userName <$loginName@$domainname>\n";
  1829. X            close(histFp);
  1830. X        }
  1831. X        }
  1832. X    }
  1833. X    }
  1834. X
  1835. X    return($retval);
  1836. X}
  1837. X
  1838. X
  1839. X#-----------------------------------------------------------------------
  1840. X# Description : Copy a given source file to a given destination file
  1841. X#
  1842. X# Parameters  : $srcFile - Source file (i.e. file to be copied)
  1843. X#               $dstFile - destination file (i.e. file where to copy)
  1844. X#               $opt - option is optionnal!
  1845. X#                      if eq to 'a' the file is instead appended
  1846. X#                      the default is to overwrite.
  1847. X#
  1848. X# Returns     : 1 on success
  1849. X#               0 if any errors
  1850. X#
  1851. Xsub CopyFile {
  1852. X    # Make sure that the number of parameters is correct
  1853. X    if(scalar(@_)!=2 && scalar(@_)!=3){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  1854. X    local($srcFile, $dstFile, $opt)=@_;
  1855. X    local($retval)=1;        # Success by default.
  1856. X    local($copyMode)='>';    # overwrite copy by default 
  1857. X    local(*fpin, *fpout, $data);
  1858. X
  1859. X    if (scalar(@_) == 3) {
  1860. X    if ($opt eq 'a') {
  1861. X        # Copy mode is append
  1862. X        $copyMode='>>';
  1863. X    }
  1864. X    else {
  1865. X        # Unknown option
  1866. X        $retval=0;
  1867. X    }
  1868. X    }
  1869. X
  1870. X    if ($retval) {        # If still no error
  1871. X    if (!open(fpin, $srcFile)) {
  1872. X        # Open failed
  1873. X        &NFError($ERR_OPEN, $srcFile);
  1874. X        $retval=0;
  1875. X    }
  1876. X    elsif (!open(fpout, "$copyMode$dstFile")) {
  1877. X        # Open failed
  1878. X        close(fpin);
  1879. X        &NFError($ERR_OPEN, "$copyMode$dstFile");
  1880. X        $retval=0;
  1881. X    }
  1882. X    else {
  1883. X        local($bytesRead);
  1884. X        # Perform the copy
  1885. X        do {
  1886. X        $bytesRead=sysread(fpin, $data, 2048);
  1887. X        if (!defined($bytesRead)) {
  1888. X            # Error while reading
  1889. X            $retval=0;
  1890. X            last;
  1891. X        }
  1892. X        if (syswrite(fpout, $data, $bytesRead) != $bytesRead) {
  1893. X            # Error while writing
  1894. X            $retval=0;
  1895. X            last;
  1896. X        }
  1897. X        } while ($bytesRead);
  1898. X        close(fpin);
  1899. X        close(fpout);
  1900. X    }
  1901. X    }
  1902. X
  1903. X    return $retval;
  1904. X}
  1905. X
  1906. X
  1907. X#-----------------------------------------------------------------------
  1908. X# Description : Display the software that was found, only the first time
  1909. X#               this function is invoqued. Any other call will be silent.
  1910. X#
  1911. X# Parameters  : $softdir - Directory where the software is located
  1912. X#               $soft    - Software found
  1913. X#               $mod     - Modification of the soft found
  1914. X#               $cla     - Class of the software found
  1915. X#
  1916. X# Returns     : nothing
  1917. X#
  1918. X#This variable is set when ludemisc is required so that it
  1919. X# is ready when the function is called.
  1920. X$DispSoftFoundOnce'done=$FALSE;
  1921. Xsub DispSoftFoundOnce {
  1922. X    # Make sure that the number of parameters is correct
  1923. X    if(scalar(@_)!=4){&Error($ERR_INTERNAL,sprintf("(%d), %s:%d",scalar(@_),__FILE__, __LINE__));}
  1924. X    local($softdir, $soft, $mod, $cla)=@_;
  1925. X    if ($DispSoftFoundOnce'done==$FALSE) {
  1926. X        print $OUT "-- $softdir -- $soft -- mod: $mod -- cla: $cla --\n";
  1927. X       $DispSoftFoundOnce'done=$TRUE;
  1928. X    }
  1929. X}
  1930. X
  1931. X
  1932. X1;
  1933. X
  1934. X#     ;;; Local Variables: ***
  1935. X#     ;;; mode:perl ***
  1936. X#     ;;; End: ***
  1937. END_OF_FILE
  1938.   if test 26934 -ne `wc -c <'lude-1.1/src/orig/src/ludemisc'`; then
  1939.     echo shar: \"'lude-1.1/src/orig/src/ludemisc'\" unpacked with wrong size!
  1940.   fi
  1941.   # end of 'lude-1.1/src/orig/src/ludemisc'
  1942. fi
  1943. echo shar: End of archive 6 \(of 12\).
  1944. cp /dev/null ark6isdone
  1945. MISSING=""
  1946. for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
  1947.     if test ! -f ark${I}isdone ; then
  1948.     MISSING="${MISSING} ${I}"
  1949.     fi
  1950. done
  1951. if test "${MISSING}" = "" ; then
  1952.     echo You have unpacked all 12 archives.
  1953.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1954. else
  1955.     echo You still must unpack the following archives:
  1956.     echo "        " ${MISSING}
  1957. fi
  1958. exit 0
  1959. exit 0 # Just in case...
  1960.