home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume26 / oraperl / patch04 next >
Encoding:
Text File  |  1991-11-20  |  36.0 KB  |  1,349 lines

  1. Newsgroups: comp.sources.misc
  2. From: kstock@gouldfr.encore.fr (Kevin Stock)
  3. Subject:  v26i036:  oraperl - Extensions to Perl to access Oracle databases, Patch04
  4. Message-ID: <1991Nov21.000708.16635@sparky.imd.sterling.com>
  5. X-Md4-Signature: 17834b3d980868d2d38d344d52f2ebc5
  6. Date: Thu, 21 Nov 1991 00:07:08 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: kstock@gouldfr.encore.fr (Kevin Stock)
  10. Posting-number: Volume 26, Issue 36
  11. Archive-name: oraperl/patch04
  12. Environment: Perl, Oracle
  13. Patch-To: oraperl: Volume 18, Issue 10
  14.  
  15. This is Patch 04 for Oraperl, a set of usersubs which allow Perl to
  16. access Oracle databases. You need Perl (v3.0.27 or better) and Oracle
  17. (including the Oracle Call Interface) to build Oraperl.
  18.  
  19. Oraperl appeared in comp.sources.misc as follows:
  20.  
  21.     v18i010        original
  22.     v20i097        patch 01
  23.     v22i058        patch 02
  24.     v25i035, 036    patch 03
  25.  
  26.  
  27.             Details of Patch 04
  28.             -------------------
  29.  
  30. The main change is that you can now build coraperl, a version of Perl
  31. which incorporates Larry's curses subs into Oraperl. Look at the new,
  32. all-singing, all-dancing mkdb.pl for an example. (This was trivial to
  33. add since Larry added Sys V curses in 4.0.19.)
  34.  
  35.  Changes
  36.  -------
  37. Added "coraperl" - Perl with Oracle and Curses
  38. Modified mkdb.pl to use the curses functions if they're available
  39. Added a note about dual-universe machines to the Hints file
  40. Added a strtoul() function instead of strtol
  41. Added "sql" - a script to execute SQL statements from the command line
  42. Separated the clean and realclean/clobber targets
  43.  
  44.  What to do
  45.  ----------
  46. To apply this patch, unshar the shar file which follows. This will
  47. create the following files:
  48.  
  49.     Patch04
  50.     sql
  51.     strtoul.c
  52.  
  53. Run the file Patch04 through the patch program.
  54.  
  55. Fix anything you need for your system in the Makefile. Then read
  56. README and run make.
  57.  
  58.   ,---------------.
  59. ,-+-------------. |    Kevin Stock
  60. | | E N C O R E | |
  61. | `-------------+-'    kstock@gouldfr.encore.fr
  62. `---------------'      kstock@encore.com
  63.  
  64.  
  65. #!/bin/sh
  66. # This is a shell archive (produced by shar 3.49)
  67. # To extract the files from this archive, save it to a file, remove
  68. # everything above the "!/bin/sh" line above, and type "sh file_name".
  69. #
  70. # made 11/19/1991 10:59 UTC by kstock@mmcompta
  71. # Source directory /usr/local/src/cmd/oraperl
  72. #
  73. # existing files will NOT be overwritten unless -c is specified
  74. #
  75. # This shar contains:
  76. # length  mode       name
  77. # ------ ---------- ------------------------------------------
  78. #  24488 -rw-r--r-- Patch04
  79. #   2802 -rwxr-xr-x sql
  80. #   4318 -rw-r--r-- strtoul.c
  81. #
  82. # ============= Patch04 ==============
  83. if test -f 'Patch04' -a X"$1" != X"-c"; then
  84.     echo 'x - skipping Patch04 (File already exists)'
  85. else
  86. echo 'x - extracting Patch04 (Text)'
  87. sed 's/^X//' << 'SHAR_EOF' > 'Patch04' &&
  88. XPrereq: 3
  89. X*** :PostedVersion/patchlevel.h    Tue Nov 19 11:36:52 1991
  90. X--- ./patchlevel.h    Wed Nov 13 15:55:28 1991
  91. X***************
  92. X*** 1,3 ****
  93. X  /* patchlevel.h */
  94. X  
  95. X! #define    PATCHLEVEL    3
  96. X--- 1,3 ----
  97. X  /* patchlevel.h */
  98. X  
  99. X! #define    PATCHLEVEL    4
  100. X*** :PostedVersion/CHANGES    Tue Nov 19 11:37:20 1991
  101. X--- ./CHANGES    Tue Nov 19 11:27:11 1991
  102. X***************
  103. X*** 28,30 ****
  104. X--- 28,40 ----
  105. X  Added the &ora_do() function, equivalent to &ora_close(&ora_open(...))
  106. X  Added handling of NULL values returned from the database
  107. X  Added an 'oraperl.ph' file
  108. X+ 
  109. X+ Patch 04
  110. X+ ========
  111. X+ Added "coraperl" - Perl with Oracle and Curses
  112. X+ Modified mkdb.pl to use the curses functions if they're available
  113. X+ Added sql, a script which executes SQL statements from the command line
  114. X+ Added a note about dual-universe machines to the Hints file
  115. X+ Added a strtoul() function
  116. X+ Separated the clean and realclean/clobber targets
  117. X+ Cleaned up a few bits and pieces - shouldn't make any difference
  118. X*** :PostedVersion/Hints    Tue Nov 19 11:37:21 1991
  119. X--- ./Hints    Tue Nov 19 11:27:25 1991
  120. X***************
  121. X*** 14,20 ****
  122. X  Building on a Convex machine
  123. X  ============================
  124. X  
  125. X! Uncomment the definitions of STRTOL and PUTENV in the Makefile.
  126. X  
  127. X  
  128. X  Building with Perl v3
  129. X--- 14,35 ----
  130. X  Building on a Convex machine
  131. X  ============================
  132. X  
  133. X! Uncomment the definition PUTENV and comment the definition of STRTOUL in
  134. X! the Makefile.
  135. X! 
  136. X! 
  137. X! Building on Dual Universe machines
  138. X! ==================================
  139. X! 
  140. X! This was reported on a Pyramid machine, but I think it applies to most (if
  141. X! not all) dual-universe systems (Sequent, Gould, etc).  Although packages
  142. X! built in one universe will run correctly in the other, hybrids (packages
  143. X! built partly in one universe and partly in the other) will not work
  144. X! properly in either.
  145. X! 
  146. X! Since Oracle specifies that it is to be installed in the ATT universe, you
  147. X! must also compile Perl and Oraperl in the ATT universe to allow them to be
  148. X! linked together successfully.
  149. X  
  150. X  
  151. X  Building with Perl v3
  152. X*** :PostedVersion/Makefile    Tue Nov 19 11:37:21 1991
  153. X--- ./Makefile    Mon Nov 18 16:43:57 1991
  154. X***************
  155. X*** 1,4 ****
  156. X! # Makefile for Oraperl
  157. X  
  158. X  # Change these to your ORACLE installation directory and Perl source directory
  159. X  
  160. X--- 1,4 ----
  161. X! # Makefile for Oraperl and Coraperl
  162. X  
  163. X  # Change these to your ORACLE installation directory and Perl source directory
  164. X  
  165. X***************
  166. X*** 18,38 ****
  167. X  
  168. X  GLOBINCS    = 
  169. X  LOCINCS        = 
  170. X! LIBS        = -lnsl_s -lsocket -ldbm -lmalloc -lm 
  171. X  
  172. X  # Oraperl Definitions
  173. X  
  174. X  # Set DEBUG to -DDEBUGGING, -DPERL_DEBUGGING or leave blank (see orafns.h)
  175. X- 
  176. X  DEBUG        = -DPERL_DEBUGGING
  177. X  
  178. X  # Some system-specific things
  179. X  #
  180. X  # If you have setenv() instead of putenv(), uncomment the next line
  181. X  # PUTENV    = -Dputenv=setenv
  182. X  #
  183. X! # If you have strtoul(), uncomment the next line
  184. X! # STRTOL    = -Dstrtol=strtoul
  185. X  #
  186. X  # If you are using Perl v3 instead of v4, uncomment the next line
  187. X  # STR_2MORTAL    = -Dstr_2mortal=str_2static
  188. X--- 18,41 ----
  189. X  
  190. X  GLOBINCS    = 
  191. X  LOCINCS        = 
  192. X! LIBS        = `. $(SRC)/config.sh; echo $$libs`
  193. X  
  194. X  # Oraperl Definitions
  195. X  
  196. X  # Set DEBUG to -DDEBUGGING, -DPERL_DEBUGGING or leave blank (see orafns.h)
  197. X  DEBUG        = -DPERL_DEBUGGING
  198. X  
  199. X+ # Curses Definitions
  200. X+ 
  201. X+ CURSELIB    = -lcurses    # you may also need -ltermlib
  202. X+ 
  203. X  # Some system-specific things
  204. X  #
  205. X  # If you have setenv() instead of putenv(), uncomment the next line
  206. X  # PUTENV    = -Dputenv=setenv
  207. X  #
  208. X! # If your system library does not include strtoul, uncomment the next line
  209. X! STRTOUL    = strtoul.o
  210. X  #
  211. X  # If you are using Perl v3 instead of v4, uncomment the next line
  212. X  # STR_2MORTAL    = -Dstr_2mortal=str_2static
  213. X***************
  214. X*** 39,63 ****
  215. X  
  216. X  # From here on, you shouldn't need to change anything
  217. X  
  218. X! SRCS        = usersub.c oracle.mus orafns.c getcursor.c colons.c
  219. X! OBJS        = usersub.o oracle.o orafns.o getcursor.o colons.o
  220. X  HDRS        = patchlevel.h orafns.h
  221. X  DEFS        = $(STRTOL) $(PUTENV) $(STR_2MORTAL)
  222. X  
  223. X  CFLAGS        = $(DEBUG) -I$(SRC) $(GLOBINCS) $(LOCINCS) $(DEFS) -O
  224. X  
  225. X! oraperl: $(SRC)/uperl.o $(OBJS)
  226. X!     $(CC) -o oraperl $(SRC)/uperl.o $(OBJS)                \
  227. X            -lm $(OCILIB) $(NETLIBS) $(ORALIBS) $(CLIBS) $(LIBS)
  228. X  
  229. X  oracle.c: $(SRC)/usub/mus oracle.mus
  230. X      $(SRC)/usub/mus oracle.mus >oracle.c
  231. X  
  232. X! $(OBJS):    $(HDRS)
  233. X  
  234. X  clean:
  235. X!     rm -f nohup.out oraperl *.o oracle.c oraperl.man oraperl.doc.pr \
  236. X!           oraperl.ref.pr listing tags core PATCHLEVEL
  237. X  
  238. X  listing:
  239. X      pr -fn Makefile $(HDRS) $(SRCS) >listing
  240. X--- 42,81 ----
  241. X  
  242. X  # From here on, you shouldn't need to change anything
  243. X  
  244. X! SRCS        = oracle.mus orafns.c getcursor.c colons.c usersub.c strtoul.c
  245. X! OBJS        = oracle.o orafns.o getcursor.o colons.o $(STRTOUL)
  246. X! OOBJS        = $(OBJS) usersub.o
  247. X! COBJS        = $(OBJS) cusersub.o
  248. X  HDRS        = patchlevel.h orafns.h
  249. X  DEFS        = $(STRTOL) $(PUTENV) $(STR_2MORTAL)
  250. X  
  251. X  CFLAGS        = $(DEBUG) -I$(SRC) $(GLOBINCS) $(LOCINCS) $(DEFS) -O
  252. X  
  253. X! oraperl: $(SRC)/uperl.o $(OOBJS)
  254. X!     $(CC) -o oraperl $(SRC)/uperl.o $(OOBJS)            \
  255. X            -lm $(OCILIB) $(NETLIBS) $(ORALIBS) $(CLIBS) $(LIBS)
  256. X  
  257. X+ coraperl: $(SRC)/uperl.o $(COBJS) $(SRC)/usub/curses.o
  258. X+     $(CC) -o coraperl $(SRC)/uperl.o $(COBJS) $(SRC)/usub/curses.o    \
  259. X+           -lm $(OCILIB) $(NETLIBS) $(ORALIBS) $(CLIBS) $(LIBS) $(CURSELIB)
  260. X+ 
  261. X+ cusersub.o:    usersub.c
  262. X+     @rm -f cusersub.c
  263. X+     ln usersub.c cusersub.c
  264. X+     $(CC) -c $(CFLAGS) -DCURSES cusersub.c
  265. X+ 
  266. X  oracle.c: $(SRC)/usub/mus oracle.mus
  267. X      $(SRC)/usub/mus oracle.mus >oracle.c
  268. X  
  269. X! $(OOBJS) $(COBJS):    $(HDRS)
  270. X  
  271. X  clean:
  272. X!     rm -f nohup.out *.o oracle.c cusersub.c            \
  273. X!         oraperl.man oraperl.doc.pr oraperl.ref.pr    \
  274. X!         listing tags core
  275. X! 
  276. X! clobber realclean:    clean
  277. X!     rm -f oraperl coraperl
  278. X  
  279. X  listing:
  280. X      pr -fn Makefile $(HDRS) $(SRCS) >listing
  281. X***************
  282. X*** 66,69 ****
  283. X      nroff -man oraperl.1 >oraperl.man
  284. X      nroff oraperl.doc >oraperl.doc.pr
  285. X      nroff oraperl.ref >oraperl.ref.pr
  286. X- 
  287. X--- 84,86 ----
  288. X*** :PostedVersion/README    Tue Nov 19 11:37:21 1991
  289. X--- ./README    Tue Nov 19 11:28:30 1991
  290. X***************
  291. X*** 1,5 ****
  292. X  This is an instant-mix package (just add Perl) to create Oraperl,
  293. X! a version of Perl which is capable of accessing Oracle databases.
  294. X  To use it, you must have the Oracle Pro*C product and a version of
  295. X  Perl which supports Usersubs (v3.0.27 or later).
  296. X  
  297. X--- 1,6 ----
  298. X  This is an instant-mix package (just add Perl) to create Oraperl,
  299. X! a version of Perl which is capable of accessing Oracle databases,
  300. X! and Coraperl, a version of Oraperl which also includes Curses.
  301. X  To use it, you must have the Oracle Pro*C product and a version of
  302. X  Perl which supports Usersubs (v3.0.27 or later).
  303. X  
  304. X***************
  305. X*** 22,30 ****
  306. X      STRTOL         +- system dependent - see Makefile for details
  307. X      STR_2MORTAL    /
  308. X  
  309. X  I've only tested this on an Encore Multimax 520 running UMAX V (Sys Vr3.2),
  310. X! using Perl 3.0.34, 4.0.00 4.0.03 and 4.0.10 with Oracle version 6, as I don't
  311. X! have access to any other system with Pro*C. I'd appreciate any comments,
  312. X  bug-reports etc.
  313. X  
  314. X  In addition to this README, the package contains the following files:
  315. X--- 23,38 ----
  316. X      STRTOL         +- system dependent - see Makefile for details
  317. X      STR_2MORTAL    /
  318. X  
  319. X+ As well as oraperl, you can also type "make coraperl" to create a version
  320. X+ of Oraperl which incorporates curses. You must compile curseperl first (in
  321. X+ $(SRC)/usub), and leave the curses.o file there. You probably need Perl
  322. X+ v4.0.19 or later for this to work, as that was the first version to
  323. X+ support System V curses.
  324. X+ 
  325. X  I've only tested this on an Encore Multimax 520 running UMAX V (Sys Vr3.2),
  326. X! using Perl (all versions from 3.0.34 to 4.0.19) with Oracle version 6, as
  327. X! I don't have access to any other system with Pro*C. However, other people
  328. X! have compiled and used it on different systems. I'd appreciate any comments,
  329. X  bug-reports etc.
  330. X  
  331. X  In addition to this README, the package contains the following files:
  332. X***************
  333. X*** 38,49 ****
  334. X      orafns.c    actual functions to interact with oracle
  335. X      usersub.c    initialisation routine
  336. X      colons.c    counts substitution variables in a statement
  337. X  
  338. X  Examples
  339. X      debug-p        tests to see if debugging is available
  340. X!     ex.pl        simple example of using the functions
  341. X!     mkdb.pl        more extensive example, showing the use of ora_bind()
  342. X!             and ora_do()
  343. X  
  344. X  Documentation
  345. X      oraperl.doc    explains some of the thinking behind Oraperl
  346. X--- 46,59 ----
  347. X      orafns.c    actual functions to interact with oracle
  348. X      usersub.c    initialisation routine
  349. X      colons.c    counts substitution variables in a statement
  350. X+     strtoul.c    for systems which don't have strtoul(3)
  351. X  
  352. X  Examples
  353. X      debug-p        tests to see if debugging is available
  354. X!     ex.pl        simple example of Oraperl functions
  355. X!     mkdb.pl        more extensive example, using curses if available
  356. X!             you can run this with either Oraperl or Coraperl
  357. X!     sql        execute an SQL statement from the command line
  358. X  
  359. X  Documentation
  360. X      oraperl.doc    explains some of the thinking behind Oraperl
  361. X*** :PostedVersion/getcursor.c    Tue Nov 19 11:37:22 1991
  362. X--- ./getcursor.c    Mon Nov 18 15:33:05 1991
  363. X***************
  364. X*** 16,22 ****
  365. X  
  366. X  
  367. X  /* head of the cursor list */
  368. X! struct cursor csr_list = { NULL, NULL, NULL, 0, NULL };
  369. X  
  370. X  
  371. X  /* ora_free_data(csr)
  372. X--- 16,22 ----
  373. X  
  374. X  
  375. X  /* head of the cursor list */
  376. X! struct cursor csr_list = { NULL, NULL, NULL, NULL, 0, 0, NULL };
  377. X  
  378. X  
  379. X  /* ora_free_data(csr)
  380. X*** :PostedVersion/mkdb.pl    Tue Nov 19 11:37:22 1991
  381. X--- ./mkdb.pl    Mon Nov 18 16:45:41 1991
  382. X***************
  383. X*** 1,39 ****
  384. X- #!./oraperl
  385. X- #
  386. X  # mkdb.pl
  387. X  #
  388. X! # Sample oraperl program to create a new database and load data into it.
  389. X  #
  390. X  # Author:    Kevin Stock
  391. X  # Date:        5th August 1991
  392. X  #
  393. X  
  394. X! # make sure that we really are running oraperl
  395. X  die ("You should use oraperl, not perl\n") unless defined &ora_login;
  396. X  
  397. X! # get debugging & error codes
  398. X! require('oraperl.ph');
  399. X  
  400. X! # let's see what oraperl is doing when it executes this
  401. X! $ora_debug = $ODBG_EXEC | $ODBG_STRNUM | $ODBG_MALLOC;
  402. X  
  403. X! # set these as strings to make the code more readable
  404. X! $CREATE = "create table tryit (name char(10), ext number(3))";
  405. X! $INSERT = "insert into tryit values (:1, :2)";
  406. X! $LIST    = "select * from tryit order by name";
  407. X! $DELETE    = "delete from tryit where name = :1";
  408. X! $DROP    = "drop table tryit";
  409. X  
  410. X! format top =
  411. X!        Name         Ext
  412. X!        ====         ===
  413. X  .
  414. X  
  415. X! format STDOUT =
  416. X!        @<<<<<<<<<   @>>
  417. X!        $name,       $ext
  418. X  .
  419. X  
  420. X  # function to list the database
  421. X  
  422. X  sub list
  423. X--- 1,85 ----
  424. X  # mkdb.pl
  425. X  #
  426. X! # Sample (c)oraperl program to create a new database and load data into it.
  427. X  #
  428. X  # Author:    Kevin Stock
  429. X  # Date:        5th August 1991
  430. X  #
  431. X+ # Modified to use curses functions if present.
  432. X+ #
  433. X+ # Date:        15th November 1991
  434. X+ #
  435. X  
  436. X! # make sure that we really are running (c)oraperl
  437. X  die ("You should use oraperl, not perl\n") unless defined &ora_login;
  438. X  
  439. X! # Arrange to use curses functions if they're available.
  440. X! # (This is just showing off)
  441. X  
  442. X! if (defined(&initscr) && &initscr())
  443. X! {
  444. X!     eval <<'____END_OF_CURSES_STUFF';
  445. X  
  446. X!     $curses = 1;
  447. X! 
  448. X!     # functions used by the list function
  449. X! 
  450. X!     sub before
  451. X!     {
  452. X!         &erase();
  453. X!         &standout();
  454. X!         &addstr("Num  Name           Ext\n\n");
  455. X!         &standend();
  456. X!         $lineno = 1;
  457. X!     }
  458. X! 
  459. X!     sub during
  460. X!     {
  461. X!         &addstr(sprintf("%2d   %-15s%3d\n", $lineno++, $name, $ext));
  462. X!     }
  463. X! 
  464. X!     sub after
  465. X!     {
  466. X!         &standout();
  467. X!         &move($LINES - 1, 0);
  468. X!         &addstr("Press RETURN to continue.");
  469. X!         &standend();
  470. X!         &refresh();
  471. X!         &getstr($dummy);
  472. X!         &move($LINES - 1, 0);
  473. X!         &addstr("                         ");
  474. X!         &move($LINES - 1, 0);
  475. X!         &refresh();
  476. X!     }
  477. X! 
  478. X! ____END_OF_CURSES_STUFF
  479. X! }
  480. X! else
  481. X! {
  482. X!     eval <<'____END_OF_PLAIN_STUFF';
  483. X! 
  484. X!     $curses = 0;
  485. X!     $ora_debug = 8;
  486. X  
  487. X!     format top =
  488. X!            Name         Ext
  489. X!            ====         ===
  490. X  .
  491. X  
  492. X!     format STDOUT =
  493. X!            @<<<<<<<<<   @>>
  494. X!            $name,       $ext
  495. X  .
  496. X  
  497. X+     # functions used by the list function
  498. X+ 
  499. X+     sub before    { $- = 0; }
  500. X+     sub during    { write; }
  501. X+     sub after    { 1; }
  502. X+ 
  503. X+ ____END_OF_PLAIN_STUFF
  504. X+ }
  505. X+ 
  506. X  # function to list the database
  507. X  
  508. X  sub list
  509. X***************
  510. X*** 40,56 ****
  511. X  {
  512. X      local($csr, $name, $ext);
  513. X  
  514. X!     $- = 0;
  515. X  
  516. X      $csr = &ora_open($lda, $LIST)            || die $ora_errstr;
  517. X      while (($name, $ext) = &ora_fetch($csr))
  518. X      {
  519. X!         write;
  520. X      }
  521. X      die $ora_errstr if ($ora_errno != 0);
  522. X      do ora_close($csr)                || die $ora_errstr;
  523. X  }
  524. X  
  525. X  # create the database
  526. X  
  527. X  $lda = &ora_login("t", "kstock", "kstock")    || die $ora_errstr;
  528. X--- 86,114 ----
  529. X  {
  530. X      local($csr, $name, $ext);
  531. X  
  532. X!     do before();
  533. X  
  534. X      $csr = &ora_open($lda, $LIST)            || die $ora_errstr;
  535. X      while (($name, $ext) = &ora_fetch($csr))
  536. X      {
  537. X!         do during();
  538. X      }
  539. X      die $ora_errstr if ($ora_errno != 0);
  540. X      do ora_close($csr)                || die $ora_errstr;
  541. X+ 
  542. X+     do after();
  543. X  }
  544. X  
  545. X+ # get debugging & error codes
  546. X+ require('oraperl.ph');
  547. X+ 
  548. X+ # set these as strings to make the code more readable
  549. X+ $CREATE = "create table tryit (name char(10), ext number(3))";
  550. X+ $INSERT = "insert into tryit values (:1, :2)";
  551. X+ $LIST    = "select * from tryit order by name";
  552. X+ $DELETE    = "delete from tryit where name = :1";
  553. X+ $DROP    = "drop table tryit";
  554. X+ 
  555. X  # create the database
  556. X  
  557. X  $lda = &ora_login("t", "kstock", "kstock")    || die $ora_errstr;
  558. X***************
  559. X*** 82,89 ****
  560. X  do list();
  561. X  
  562. X  # remove the database and log out
  563. X! $csr = &ora_do($lda, $DROP)            || die $ora_errstr;
  564. X  do ora_logoff($lda)                || die $ora_errstr;
  565. X  
  566. X  # This is the data which will go into the database
  567. X  __END__
  568. X--- 140,149 ----
  569. X  do list();
  570. X  
  571. X  # remove the database and log out
  572. X! do ora_do($lda, $DROP)                || die $ora_errstr;
  573. X  do ora_logoff($lda)                || die $ora_errstr;
  574. X+ 
  575. X+ do endwin() if $curses == 1;
  576. X  
  577. X  # This is the data which will go into the database
  578. X  __END__
  579. X*** :PostedVersion/oracle.mus    Tue Nov 19 11:37:23 1991
  580. X--- ./oracle.mus    Mon Nov 18 16:52:23 1991
  581. X***************
  582. X*** 106,112 ****
  583. X  
  584. X          if (curcsv->wantarray) {    /* in array context, return the data */
  585. X          int  retval;
  586. X-         char *tmps;
  587. X  
  588. X          retval = ora_fetch(csr);
  589. X          astore(stack, sp + retval, Nullstr);
  590. X--- 106,111 ----
  591. X***************
  592. X*** 120,126 ****
  593. X          struct cursor *csrp;
  594. X          extern int check_csr();
  595. X  
  596. X!         csrp = (struct cursor *) strtol(csr, (char *) NULL, 0);
  597. X          if (check_csr(csrp))
  598. X              str_numset(st[0], (double) csrp->nfields);
  599. X          else
  600. X--- 119,125 ----
  601. X          struct cursor *csrp;
  602. X          extern int check_csr();
  603. X  
  604. X!         csrp = (struct cursor *) strtoul(csr, (char *) NULL, 0);
  605. X          if (check_csr(csrp))
  606. X              str_numset(st[0], (double) csrp->nfields);
  607. X          else
  608. X***************
  609. X*** 136,142 ****
  610. X      else {
  611. X          char *csr        = (char *) str_get(st[1]);
  612. X          char **vars        = (char **) malloc((items-1) * sizeof(char *));
  613. X!         int i, retval;
  614. X  
  615. X          if (vars == NULL)
  616. X          {
  617. X--- 135,141 ----
  618. X      else {
  619. X          char *csr        = (char *) str_get(st[1]);
  620. X          char **vars        = (char **) malloc((items-1) * sizeof(char *));
  621. X!         int retval;
  622. X  
  623. X          if (vars == NULL)
  624. X          {
  625. X*** :PostedVersion/orafns.c    Tue Nov 19 11:37:23 1991
  626. X--- ./orafns.c    Mon Nov 18 17:31:39 1991
  627. X***************
  628. X*** 197,203 ****
  629. X      {
  630. X          DEBUG(8, -1, (fputs(
  631. X              "ora_login: couldn't select database\n", stderr)));
  632. X!         ora_dropcursor(lda);
  633. X          return(NULL);
  634. X      }
  635. X      else if (strcmp(database, getenv("ORACLE_SID")) != 0)
  636. X--- 197,203 ----
  637. X      {
  638. X          DEBUG(8, -1, (fputs(
  639. X              "ora_login: couldn't select database\n", stderr)));
  640. X!         (void) ora_dropcursor(lda);
  641. X          return(NULL);
  642. X      }
  643. X      else if (strcmp(database, getenv("ORACLE_SID")) != 0)
  644. X***************
  645. X*** 205,211 ****
  646. X          DEBUG(8, -1, (fprintf(stderr,
  647. X              "ora_login: ORACLE_SID misset to %s\n",
  648. X              (tmp = getenv("ORACLE_SID")) ? tmp : "<NULL>")));
  649. X!         ora_dropcursor(lda);
  650. X          ora_errno = ORAP_NOSID;
  651. X          return(NULL);
  652. X      }
  653. X--- 205,211 ----
  654. X          DEBUG(8, -1, (fprintf(stderr,
  655. X              "ora_login: ORACLE_SID misset to %s\n",
  656. X              (tmp = getenv("ORACLE_SID")) ? tmp : "<NULL>")));
  657. X!         (void) ora_dropcursor(lda);
  658. X          ora_errno = ORAP_NOSID;
  659. X          return(NULL);
  660. X      }
  661. X***************
  662. X*** 227,233 ****
  663. X      else
  664. X      {
  665. X          ora_errno = lda->csr->csrrc;
  666. X!         ora_droplda(lda);
  667. X          DEBUG(8, -1, (fprintf(stderr,
  668. X              "ora_login: failed (error %d)\n", ora_errno)));
  669. X          return((char *) NULL);
  670. X--- 227,233 ----
  671. X      else
  672. X      {
  673. X          ora_errno = lda->csr->csrrc;
  674. X!         (void) ora_droplda(lda);
  675. X          DEBUG(8, -1, (fprintf(stderr,
  676. X              "ora_login: failed (error %d)\n", ora_errno)));
  677. X          return((char *) NULL);
  678. X***************
  679. X*** 246,252 ****
  680. X  {
  681. X      int i;
  682. X      struct cursor *csr;
  683. X!     struct cursor *lda = (struct cursor *) strtol(lda_s, (char **) NULL, 0);
  684. X      short dsize;
  685. X  
  686. X      DEBUG(8, 1, (fprintf(stderr,
  687. X--- 246,252 ----
  688. X  {
  689. X      int i;
  690. X      struct cursor *csr;
  691. X!     struct cursor *lda = (struct cursor *)strtoul(lda_s, (char **) NULL, 0);
  692. X      short dsize;
  693. X  
  694. X      DEBUG(8, 1, (fprintf(stderr,
  695. X***************
  696. X*** 288,294 ****
  697. X          || ((csr->varfields == 0) && (oexec(csr->csr) != 0)))
  698. X      {
  699. X          ora_errno = csr->csr->csrrc;
  700. X!         ora_dropcursor(csr);
  701. X          DEBUG(8, -1, (fprintf(stderr,
  702. X              "ora_open: couldn't run SQL statement (error %d)\n",
  703. X              ora_errno)));
  704. X--- 288,294 ----
  705. X          || ((csr->varfields == 0) && (oexec(csr->csr) != 0)))
  706. X      {
  707. X          ora_errno = csr->csr->csrrc;
  708. X!         (void) ora_dropcursor(csr);
  709. X          DEBUG(8, -1, (fprintf(stderr,
  710. X              "ora_open: couldn't run SQL statement (error %d)\n",
  711. X              ora_errno)));
  712. X***************
  713. X*** 309,317 ****
  714. X  
  715. X      if (i > 0)
  716. X      {
  717. X          if ((csr->data = (char **) malloc(i * sizeof(char *))) == NULL)
  718. X          {
  719. X!             ora_dropcursor(csr);
  720. X              DEBUG((8 | 128), -1, (fputs(
  721. X                  "ora_open: out of memory\n", stderr)));
  722. X              ora_errno = ORAP_NOMEM;
  723. X--- 309,320 ----
  724. X  
  725. X      if (i > 0)
  726. X      {
  727. X+         DEBUG(8, 0, (fprintf(stderr,
  728. X+             "ora_open: statement returns %d fields\n", i)));
  729. X+ 
  730. X          if ((csr->data = (char **) malloc(i * sizeof(char *))) == NULL)
  731. X          {
  732. X!             (void) ora_dropcursor(csr);
  733. X              DEBUG((8 | 128), -1, (fputs(
  734. X                  "ora_open: out of memory\n", stderr)));
  735. X              ora_errno = ORAP_NOMEM;
  736. X***************
  737. X*** 323,329 ****
  738. X  
  739. X          if ((csr->rcode = (short *) malloc(i * sizeof(short))) == NULL)
  740. X          {
  741. X!             ora_dropcursor(csr);
  742. X              DEBUG((8 | 128), -1, (fputs(
  743. X                  "ora_open: out of memory\n", stderr)));
  744. X              ora_errno = ORAP_NOMEM;
  745. X--- 326,332 ----
  746. X  
  747. X          if ((csr->rcode = (short *) malloc(i * sizeof(short))) == NULL)
  748. X          {
  749. X!             (void) ora_dropcursor(csr);
  750. X              DEBUG((8 | 128), -1, (fputs(
  751. X                  "ora_open: out of memory\n", stderr)));
  752. X              ora_errno = ORAP_NOMEM;
  753. X***************
  754. X*** 344,350 ****
  755. X              if ((csr->data[i] = (char *) malloc(dsize+1)) == NULL)
  756. X              {
  757. X                  csr->nfields = i;
  758. X!                 ora_dropcursor(csr);
  759. X                  DEBUG((8 | 128), -1, (fputs(
  760. X                      "ora_open: out of memory\n", stderr)));
  761. X                  ora_errno = ORAP_NOMEM;
  762. X--- 347,353 ----
  763. X              if ((csr->data[i] = (char *) malloc(dsize+1)) == NULL)
  764. X              {
  765. X                  csr->nfields = i;
  766. X!                 (void) ora_dropcursor(csr);
  767. X                  DEBUG((8 | 128), -1, (fputs(
  768. X                      "ora_open: out of memory\n", stderr)));
  769. X                  ora_errno = ORAP_NOMEM;
  770. X***************
  771. X*** 385,391 ****
  772. X  char *csr_s;
  773. X  {
  774. X      int i;
  775. X!     struct cursor *csr = (struct cursor *) strtol(csr_s, (char **) NULL, 0);
  776. X  
  777. X      DEBUG(8, 1, (fprintf(stderr,
  778. X          "ora_fetch(%s)\n", csr_s)));
  779. X--- 388,394 ----
  780. X  char *csr_s;
  781. X  {
  782. X      int i;
  783. X!     struct cursor *csr = (struct cursor *)strtoul(csr_s, (char **) NULL, 0);
  784. X  
  785. X      DEBUG(8, 1, (fprintf(stderr,
  786. X          "ora_fetch(%s)\n", csr_s)));
  787. X***************
  788. X*** 452,459 ****
  789. X  
  790. X      if (ora_debug & 8)
  791. X      {
  792. X-         int i;
  793. X- 
  794. X          DEBUG(8, 0, (fputs("ora_fetch: returning data:\n", stderr)));
  795. X          for (i = 0 ; i < csr->nfields ; i++)
  796. X          {
  797. X--- 455,460 ----
  798. X***************
  799. X*** 480,487 ****
  800. X  char *csr_s, **vars;
  801. X  int nitems;
  802. X  {
  803. X!     int i, ret;
  804. X!     struct cursor *csr = (struct cursor *) strtol(csr_s, (char **) NULL, 0);
  805. X  
  806. X      DEBUG(8, 1, (fprintf(stderr,
  807. X          "ora_bind(%s, %#lx, %d)\n", csr_s, (long) vars, nitems)));
  808. X--- 481,488 ----
  809. X  char *csr_s, **vars;
  810. X  int nitems;
  811. X  {
  812. X!     int i;
  813. X!     struct cursor *csr = (struct cursor *)strtoul(csr_s, (char **) NULL, 0);
  814. X  
  815. X      DEBUG(8, 1, (fprintf(stderr,
  816. X          "ora_bind(%s, %#lx, %d)\n", csr_s, (long) vars, nitems)));
  817. X***************
  818. X*** 505,511 ****
  819. X  
  820. X      for (i = 0 ; i < nitems ; i++)
  821. X      {
  822. X!         if ((ret = obndrn(csr->csr, i+1, vars[i], strlen(vars[i])+1,
  823. X              5, -1, (short *) -1, (char *) -1, 0, 0)) != 0)
  824. X          {
  825. X              DEBUG(8, -1, (fprintf(stderr,
  826. X--- 506,512 ----
  827. X  
  828. X      for (i = 0 ; i < nitems ; i++)
  829. X      {
  830. X!         if ((obndrn(csr->csr, i+1, vars[i], strlen(vars[i])+1,
  831. X              5, -1, (short *) -1, (char *) -1, 0, 0)) != 0)
  832. X          {
  833. X              DEBUG(8, -1, (fprintf(stderr,
  834. X***************
  835. X*** 576,582 ****
  836. X  char *ora_close(csr_s)
  837. X  char *csr_s;
  838. X  {
  839. X!     struct cursor *csr = (struct cursor *) strtol(csr_s, (char **) NULL, 0);
  840. X  
  841. X  
  842. X      DEBUG(8, 1, (fprintf(stderr, "ora_close(%s)\n", csr_s)));
  843. X--- 577,583 ----
  844. X  char *ora_close(csr_s)
  845. X  char *csr_s;
  846. X  {
  847. X!     struct cursor *csr = (struct cursor *)strtoul(csr_s, (char **) NULL, 0);
  848. X  
  849. X  
  850. X      DEBUG(8, 1, (fprintf(stderr, "ora_close(%s)\n", csr_s)));
  851. X***************
  852. X*** 593,599 ****
  853. X  
  854. X      oclose(csr->csr);
  855. X      ora_errno = csr->csr->csrrc;
  856. X!     ora_dropcursor(csr);
  857. X  
  858. X      DEBUG(8, -1, (fputs("ora_close: returning OK\n", stderr)));
  859. X      return(OK);
  860. X--- 594,600 ----
  861. X  
  862. X      oclose(csr->csr);
  863. X      ora_errno = csr->csr->csrrc;
  864. X!     (void) ora_dropcursor(csr);
  865. X  
  866. X      DEBUG(8, -1, (fputs("ora_close: returning OK\n", stderr)));
  867. X      return(OK);
  868. X***************
  869. X*** 608,614 ****
  870. X  char *ora_logoff(lda_s)
  871. X  char *lda_s;
  872. X  {
  873. X!     struct cursor *lda = (struct cursor *) strtol(lda_s, (char **) NULL, 0);
  874. X  
  875. X      DEBUG(8, 1, (fprintf(stderr, "ora_logoff(%s)\n", lda_s)));
  876. X      DEBUG(32, 0, (fprintf(stderr,
  877. X--- 609,615 ----
  878. X  char *ora_logoff(lda_s)
  879. X  char *lda_s;
  880. X  {
  881. X!     struct cursor *lda = (struct cursor *)strtoul(lda_s, (char **) NULL, 0);
  882. X  
  883. X      DEBUG(8, 1, (fprintf(stderr, "ora_logoff(%s)\n", lda_s)));
  884. X      DEBUG(32, 0, (fprintf(stderr,
  885. X***************
  886. X*** 624,630 ****
  887. X  
  888. X      ologof(lda->csr);
  889. X      ora_errno = lda->csr->csrrc;
  890. X!     ora_droplda(lda);
  891. X  
  892. X      DEBUG(8, -1, (fputs("ora_logoff: returning OK\n", stderr)));
  893. X      return(OK);
  894. X--- 625,631 ----
  895. X  
  896. X      ologof(lda->csr);
  897. X      ora_errno = lda->csr->csrrc;
  898. X!     (void) ora_droplda(lda);
  899. X  
  900. X      DEBUG(8, -1, (fputs("ora_logoff: returning OK\n", stderr)));
  901. X      return(OK);
  902. X*** :PostedVersion/orafns.h    Tue Nov 19 11:37:24 1991
  903. X--- ./orafns.h    Mon Nov 18 17:31:08 1991
  904. X***************
  905. X*** 12,17 ****
  906. X--- 12,19 ----
  907. X  
  908. X  /* public functions to be called by Perl programs */
  909. X  
  910. X+ void        ora_version();
  911. X+ 
  912. X  char        *ora_login(),
  913. X          *ora_open(),
  914. X          *ora_close(),
  915. X***************
  916. X*** 77,85 ****
  917. X  
  918. X  /* functions that we use */
  919. X  
  920. X! int    count_colons();
  921. X! long    strtol();
  922. X! char    *getenv(), *malloc();
  923. X  
  924. X  
  925. X  /* variables accesible to the outside world */
  926. X--- 79,87 ----
  927. X  
  928. X  /* functions that we use */
  929. X  
  930. X! int        count_colons();
  931. X! unsigned long    strtoul();
  932. X! char        *getenv(), *malloc();
  933. X  
  934. X  
  935. X  /* variables accesible to the outside world */
  936. X*** :PostedVersion/oraperl.1    Tue Nov 19 11:37:24 1991
  937. X--- ./oraperl.1    Wed Nov 13 16:05:57 1991
  938. X***************
  939. X*** 4,9 ****
  940. X--- 4,11 ----
  941. X  .nh
  942. X  .SH NAME
  943. X  oraperl \- Perl access to Oracle databases
  944. X+ .br
  945. X+ coraperl \- Oraperl with Curses functions
  946. X  .SH SYNOPSIS
  947. X  .nf
  948. X  &ora_version
  949. X***************
  950. X*** 24,29 ****
  951. X--- 26,34 ----
  952. X  \fBOraperl\fP is a version of \fIPerl\fP
  953. X  which has been extended (through the \fIusersubs\fP feature)
  954. X  to allow access to \fIOracle\fP databases.
  955. X+ 
  956. X+ \fBCoraperl\fP additionally includes the \fIcurses\fP routines
  957. X+ from the \fIusub\fP example included with the \fIPerl\fP source.
  958. X  .SH Functions
  959. X  The \fIora_version\fP function
  960. X  prints the version number and copyright information concerning Oraperl.
  961. X***************
  962. X*** 203,209 ****
  963. X  
  964. X  .ti -5
  965. X  \fIPerl\fP documentation:
  966. X! \fIProgramming Perl\fP by Larry Wall and Randall Schwartz
  967. X  \fIperl(1)\fP
  968. X  .in -5
  969. X  .fi
  970. X--- 208,214 ----
  971. X  
  972. X  .ti -5
  973. X  \fIPerl\fP documentation:
  974. X! \fIProgramming Perl\fP by Larry Wall and Randal Schwartz
  975. X  \fIperl(1)\fP
  976. X  .in -5
  977. X  .fi
  978. X***************
  979. X*** 210,216 ****
  980. X  .SH AUTHORS
  981. X  \fIORACLE\fP by Oracle Corporation, California.
  982. X  .br
  983. X! \fIPerl\fP by Larry Wall, Netlabs
  984. X  .if t .ft C
  985. X  (lwall@netlabs.com).
  986. X  .if t .ft P
  987. X--- 215,221 ----
  988. X  .SH AUTHORS
  989. X  \fIORACLE\fP by Oracle Corporation, California.
  990. X  .br
  991. X! \fIPerl\fP and \fICurseperl\fP by Larry Wall, Netlabs
  992. X  .if t .ft C
  993. X  (lwall@netlabs.com).
  994. X  .if t .ft P
  995. X*** :PostedVersion/usersub.c    Tue Nov 19 11:37:25 1991
  996. X--- ./usersub.c    Wed Nov 13 15:55:19 1991
  997. X***************
  998. X*** 17,22 ****
  999. X--- 17,25 ----
  1000. X  userinit()
  1001. X  {
  1002. X      init_oracle();
  1003. X+ #ifdef CURSES
  1004. X+     init_curses();
  1005. X+ #endif
  1006. X  
  1007. X  #ifdef DEBUGGING
  1008. X  #   ifdef PERL_DEBUGGING
  1009. X***************
  1010. X*** 28,31 ****
  1011. X  
  1012. X      ora_errno = 0;
  1013. X  }
  1014. X- 
  1015. X--- 31,33 ----
  1016. SHAR_EOF
  1017. chmod 0644 Patch04 ||
  1018. echo 'restore of Patch04 failed'
  1019. Wc_c="`wc -c < 'Patch04'`"
  1020. test 24488 -eq "$Wc_c" ||
  1021.     echo 'Patch04: original size 24488, current size' "$Wc_c"
  1022. fi
  1023. # ============= sql ==============
  1024. if test -f 'sql' -a X"$1" != X"-c"; then
  1025.     echo 'x - skipping sql (File already exists)'
  1026. else
  1027. echo 'x - extracting sql (Text)'
  1028. sed 's/^X//' << 'SHAR_EOF' > 'sql' &&
  1029. X#!/usr/local/bin/oraperl
  1030. X'di';
  1031. X'ig00';
  1032. X#
  1033. X# sql [-ddelim] username/password statement
  1034. X#
  1035. X# Script to run an Oracle statement from the command line.
  1036. X# Written in response to <nirad.690285085@newdelphi> in alt.sources.wanted.
  1037. X#
  1038. X# Author:    Kevin Stock
  1039. X# Date:        18th November 1991
  1040. X#
  1041. X
  1042. X# $ora_debug = 8;        # if you want to see what's happenning
  1043. X
  1044. X$, = "\t";            # default delimiter is a tab
  1045. X$\ = "\n";            # each record terminated with newline
  1046. X
  1047. Xif ($ARGV[0] =~ /^-d(.*)/)    # allows the delimiter to be empty
  1048. X{
  1049. X    $, = $1;
  1050. X    shift;
  1051. X}
  1052. X
  1053. X$USER = shift;            # get the user name and password
  1054. Xdie "Usage: $0 sql [-ddelim] username/password statement\n" unless $#ARGV >= 0;
  1055. X
  1056. X# log into the database and execute the statement
  1057. X
  1058. X$lda = &ora_login($ENV{'ORACLE_SID'}, $USER, '') || die "$ora_errstr\n";
  1059. X$csr = &ora_open($lda, "@ARGV") || die "$ora_errstr\n";
  1060. X
  1061. X# print out any information which comes back
  1062. X
  1063. Xif (&ora_fetch($csr) > 0)    # does the statement return data?
  1064. X{
  1065. X    while (@result = &ora_fetch($csr))
  1066. X    {
  1067. X        print @result;
  1068. X    }
  1069. X    warn "$ora_errstr\n" if ($ora_errno != 0);
  1070. X}
  1071. X
  1072. X# finish off neatly
  1073. X
  1074. Xdo ora_close($csr);
  1075. Xdo ora_logoff($lda);
  1076. X
  1077. X__END__        # no need for perl even to scan the rest
  1078. X
  1079. X##############################################################################
  1080. X
  1081. X    # These next few lines are legal in both Perl and nroff.
  1082. X
  1083. X.00;            # finish .ig
  1084. X'di            \" finish diversion--previous line must be blank
  1085. X.nr nl 0-1        \" fake up transition to first page again
  1086. X.nr % 0            \" start at page 1
  1087. X';<<'.ex'; ############## From here on it's a standard manual page ############
  1088. X.ll 80
  1089. X.TH SQL L "18th November 1991"
  1090. X.ad
  1091. X.nh
  1092. X.SH NAME
  1093. Xsql \- execute an Oracle SQL statement from the command line
  1094. X.SH SYNOPSIS
  1095. X\fBsql\fP [\fB\-d\fP\fIdelim\fP] \fIname\fP\fB/\fP\fIpassword\fP \fIstatement\fP
  1096. X.SH DESCRIPTION
  1097. X.I Sql
  1098. Xconnects to an Oracle database
  1099. Xusing the \fIname/password\fP supplied
  1100. Xand executes the given SQL \fIstatement\fP
  1101. Xreturning the result
  1102. X(without column headers)
  1103. Xon its standard output.
  1104. XNormally, fields are separated with tabs;
  1105. Xthis may be changed to any desired string (\fIdelim\fP)
  1106. Xusing the \fB\-d\fP flag.
  1107. X.SH ENVIRONMENT
  1108. XThe environment variable \fBORACLE_SID\fP
  1109. Xdetermines the Oracle database to be used.
  1110. X.SH DIAGNOSTICS
  1111. XThe only diagnostic generated by \fIsql\fP is a usage message.
  1112. XHowever, you may also encounter
  1113. Xerror messages from Oraperl (unlikely) or Oracle (more common).
  1114. XSee the \fIOracle Error Messages and Codes Manual\fP for details.
  1115. X.SH NOTES
  1116. XThis program is only intended for use from the command line.
  1117. XIf you use it within a shell script
  1118. Xthen you should consider rewriting it in Oraperl
  1119. Xto use Perl's text manipulation and formatting commands.
  1120. X.SH "SEE ALSO"
  1121. X\fISQL Language Reference Manual\fP
  1122. X.br
  1123. Xperl(1),
  1124. Xoraperl(1)
  1125. X.SH AUTHOR
  1126. XKevin Stock,
  1127. X.if t .ft C
  1128. X<kstock@gouldfr.encore.fr, kstock@encore.com>
  1129. X.if t .ft P
  1130. X.ex
  1131. SHAR_EOF
  1132. chmod 0755 sql ||
  1133. echo 'restore of sql failed'
  1134. Wc_c="`wc -c < 'sql'`"
  1135. test 2802 -eq "$Wc_c" ||
  1136.     echo 'sql: original size 2802, current size' "$Wc_c"
  1137. fi
  1138. # ============= strtoul.c ==============
  1139. if test -f 'strtoul.c' -a X"$1" != X"-c"; then
  1140.     echo 'x - skipping strtoul.c (File already exists)'
  1141. else
  1142. echo 'x - extracting strtoul.c (Text)'
  1143. sed 's/^X//' << 'SHAR_EOF' > 'strtoul.c' &&
  1144. X/* 
  1145. X * strtoul.c --
  1146. X *
  1147. X *    Source code for the "strtoul" library procedure.
  1148. X *
  1149. X * Copyright 1988 Regents of the University of California
  1150. X * Permission to use, copy, modify, and distribute this
  1151. X * software and its documentation for any purpose and without
  1152. X * fee is hereby granted, provided that the above copyright
  1153. X * notice appear in all copies.  The University of California
  1154. X * makes no representations about the suitability of this
  1155. X * software for any purpose.  It is provided "as is" without
  1156. X * express or implied warranty.
  1157. X */
  1158. X
  1159. X#ifndef lint
  1160. Xstatic char rcsid[] = "$Header: /sprite/src/lib/tcl/compat/RCS/strtoul.c,v 1.2 91/09/22 14:04:43 ouster Exp $ SPRITE (Berkeley)";
  1161. X#endif /* not lint */
  1162. X
  1163. X#include <ctype.h>
  1164. X
  1165. X/*
  1166. X * The table below is used to convert from ASCII digits to a
  1167. X * numerical equivalent.  It maps from '0' through 'z' to integers
  1168. X * (100 for non-digit characters).
  1169. X */
  1170. X
  1171. Xstatic char cvtIn[] = {
  1172. X    0, 1, 2, 3, 4, 5, 6, 7, 8, 9,        /* '0' - '9' */
  1173. X    100, 100, 100, 100, 100, 100, 100,        /* punctuation */
  1174. X    10, 11, 12, 13, 14, 15, 16, 17, 18, 19,    /* 'A' - 'Z' */
  1175. X    20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  1176. X    30, 31, 32, 33, 34, 35,
  1177. X    100, 100, 100, 100, 100, 100,        /* punctuation */
  1178. X    10, 11, 12, 13, 14, 15, 16, 17, 18, 19,    /* 'a' - 'z' */
  1179. X    20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  1180. X    30, 31, 32, 33, 34, 35};
  1181. X
  1182. X/*
  1183. X *----------------------------------------------------------------------
  1184. X *
  1185. X * strtoul --
  1186. X *
  1187. X *    Convert an ASCII string into an integer.
  1188. X *
  1189. X * Results:
  1190. X *    The return value is the integer equivalent of string.  If endPtr
  1191. X *    is non-NULL, then *endPtr is filled in with the character
  1192. X *    after the last one that was part of the integer.  If string
  1193. X *    doesn't contain a valid integer value, then zero is returned
  1194. X *    and *endPtr is set to string.
  1195. X *
  1196. X * Side effects:
  1197. X *    None.
  1198. X *
  1199. X *----------------------------------------------------------------------
  1200. X */
  1201. X
  1202. Xunsigned long int
  1203. Xstrtoul(string, endPtr, base)
  1204. X    char *string;        /* String of ASCII digits, possibly
  1205. X                 * preceded by white space.  For bases
  1206. X                 * greater than 10, either lower- or
  1207. X                 * upper-case digits may be used.
  1208. X                 */
  1209. X    char **endPtr;        /* Where to store address of terminating
  1210. X                 * character, or NULL. */
  1211. X    int base;            /* Base for conversion.  Must be less
  1212. X                 * than 37.  If 0, then the base is chosen
  1213. X                 * from the leading characters of string:
  1214. X                 * "0x" means hex, "0" means octal, anything
  1215. X                 * else means decimal.
  1216. X                 */
  1217. X{
  1218. X    register char *p;
  1219. X    register unsigned long int result = 0;
  1220. X    register unsigned digit;
  1221. X    int anyDigits = 0;
  1222. X
  1223. X    /*
  1224. X     * Skip any leading blanks.
  1225. X     */
  1226. X
  1227. X    p = string;
  1228. X    while (isspace(*p)) {
  1229. X    p += 1;
  1230. X    }
  1231. X
  1232. X    /*
  1233. X     * If no base was provided, pick one from the leading characters
  1234. X     * of the string.
  1235. X     */
  1236. X    
  1237. X    if (base == 0)
  1238. X    {
  1239. X    if (*p == '0') {
  1240. X        p += 1;
  1241. X        if (*p == 'x') {
  1242. X        p += 1;
  1243. X        base = 16;
  1244. X        } else {
  1245. X
  1246. X        /*
  1247. X         * Must set anyDigits here, otherwise "0" produces a
  1248. X         * "no digits" error.
  1249. X         */
  1250. X
  1251. X        anyDigits = 1;
  1252. X        base = 8;
  1253. X        }
  1254. X    }
  1255. X    else base = 10;
  1256. X    } else if (base == 16) {
  1257. X
  1258. X    /*
  1259. X     * Skip a leading "0x" from hex numbers.
  1260. X     */
  1261. X
  1262. X    if ((p[0] == '0') && (p[1] == 'x')) {
  1263. X        p += 2;
  1264. X    }
  1265. X    }
  1266. X
  1267. X    /*
  1268. X     * Sorry this code is so messy, but speed seems important.  Do
  1269. X     * different things for base 8, 10, 16, and other.
  1270. X     */
  1271. X
  1272. X    if (base == 8) {
  1273. X    for ( ; ; p += 1) {
  1274. X        digit = *p - '0';
  1275. X        if (digit > 7) {
  1276. X        break;
  1277. X        }
  1278. X        result = (result << 3) + digit;
  1279. X        anyDigits = 1;
  1280. X    }
  1281. X    } else if (base == 10) {
  1282. X    for ( ; ; p += 1) {
  1283. X        digit = *p - '0';
  1284. X        if (digit > 9) {
  1285. X        break;
  1286. X        }
  1287. X        result = (10*result) + digit;
  1288. X        anyDigits = 1;
  1289. X    }
  1290. X    } else if (base == 16) {
  1291. X    for ( ; ; p += 1) {
  1292. X        digit = *p - '0';
  1293. X        if (digit > ('z' - '0')) {
  1294. X        break;
  1295. X        }
  1296. X        digit = cvtIn[digit];
  1297. X        if (digit > 15) {
  1298. X        break;
  1299. X        }
  1300. X        result = (result << 4) + digit;
  1301. X        anyDigits = 1;
  1302. X    }
  1303. X    } else {
  1304. X    for ( ; ; p += 1) {
  1305. X        digit = *p - '0';
  1306. X        if (digit > ('z' - '0')) {
  1307. X        break;
  1308. X        }
  1309. X        digit = cvtIn[digit];
  1310. X        if (digit >= base) {
  1311. X        break;
  1312. X        }
  1313. X        result = result*base + digit;
  1314. X        anyDigits = 1;
  1315. X    }
  1316. X    }
  1317. X
  1318. X    /*
  1319. X     * See if there were any digits at all.
  1320. X     */
  1321. X
  1322. X    if (!anyDigits) {
  1323. X    p = string;
  1324. X    }
  1325. X
  1326. X    if (endPtr != 0) {
  1327. X    *endPtr = p;
  1328. X    }
  1329. X
  1330. X    return result;
  1331. X}
  1332. SHAR_EOF
  1333. chmod 0644 strtoul.c ||
  1334. echo 'restore of strtoul.c failed'
  1335. Wc_c="`wc -c < 'strtoul.c'`"
  1336. test 4318 -eq "$Wc_c" ||
  1337.     echo 'strtoul.c: original size 4318, current size' "$Wc_c"
  1338. fi
  1339. chmod 0644 mkdb.pl
  1340. exit 0
  1341.  
  1342. exit 0 # Just in case...
  1343. -- 
  1344. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1345. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1346. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1347. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1348.