home *** CD-ROM | disk | FTP | other *** search
/ World of Graphics / WOGRAPH.BIN / 321.TCVIS.C < prev    next >
C/C++ Source or Header  |  1992-04-10  |  13KB  |  520 lines

  1. /*****************************************************************************
  2. *   Copyright (c) DIDC, 1991.  All rights reserved.                          *
  3. *   Unauthorized use, duplication, or distribution is strictly prohibited.   *
  4. *****************************************************************************/
  5. #include <stdio.h>
  6. #include <conio.h>
  7. #include <stdlib.h>
  8. #include <dos.h>
  9. #include <bios.h>
  10. #include <string.h>
  11. #include <time.h>
  12. #include <direct.h>
  13. #include "tcvis.h"
  14.  
  15. #define DB_NAME_TOO_LONG       -561
  16. #define KEY_TOO_LONG           -559
  17. #define MAX_FNAME_LEN 64
  18. #define PARAM_ERR              -531
  19.  
  20.  
  21. #define MAX_RETRY     10
  22. #define DTI_TIMEOUT -555
  23.  
  24. static union REGS DIDC_regs;
  25. static char *DIDC_params;
  26. static unsigned DIDC_int;
  27. static char DIDC_strng[200];
  28. static int DIDC_res;
  29.  
  30. static char CURRENT_PATH[100];
  31. static char FULL_PATH[100];
  32.  
  33. /*************************************************************/
  34.  
  35. int DIDC_tsrloaded(unsigned int func_no)
  36. {
  37. static union REGS inregs, outregs;
  38.   
  39. inregs.x.ax = func_no;
  40. int86(0x16, &inregs, &outregs);
  41. if (outregs.x.ax == SIG)
  42.     return(TRUE);
  43. else
  44.     return(FALSE);
  45. }
  46.  
  47. /*************************************************************/
  48.  
  49. void DIDC_write_params(char s[])
  50. {
  51. static int i;
  52. for (i = 0; i <= strlen(s); i++)
  53.   DIDC_params[i] = (char) toupper(s[i]);
  54. }
  55.  
  56. /************************************************************************/
  57.  
  58. int DIDC_dti_done(void)
  59. {
  60. if (DIDC_params[0] == 0)
  61.   return 1;
  62. return 0;
  63. }
  64.  
  65. /************************************************************************/
  66.  
  67. int DIDC_result(void)
  68. {
  69. static int res;
  70. memmove(&res,&DIDC_params[1],2);
  71. return res;
  72. }
  73.  
  74. /************************************************************************/
  75.  
  76. int DIDC_call_tsr(char s[])
  77. {
  78. static int retry;
  79.  
  80. if (DIDC_int == 0)
  81.   return -557;
  82.  
  83. memset(&DIDC_regs,0,sizeof(DIDC_regs));
  84.  
  85. for (retry = 0; retry < MAX_RETRY; retry++)
  86.   {
  87.   DIDC_write_params(s);
  88.   DIDC_regs.x.ax = 1;
  89.   int86(DIDC_int,&DIDC_regs,&DIDC_regs);
  90.   delay(100);
  91.  
  92.   if (DIDC_dti_done())
  93.     return DIDC_result();
  94.   }
  95. /*printf("timeout\n");*/
  96. return DTI_TIMEOUT;
  97. }
  98.  
  99. /************************************************************************/
  100.  
  101. void *DIDC_ptr(unsigned s, unsigned o)
  102. {
  103. void *p;
  104. p = MK_FP(s,o);
  105. return p;
  106. }
  107.  
  108. /************************************************************************/
  109. /* General functions                                                    */
  110. /************************************************************************/
  111.  
  112. int DIDC_locate_tsr(void)
  113. {
  114. static unsigned *a;
  115. static unsigned s,o;
  116. static char *aa;
  117. static unsigned i,j;
  118.  
  119. for (j = 0x60; j <= 0x67; j++)
  120.   {
  121.   a = (unsigned *) DIDC_ptr(0,(j*4));
  122.   s = a[1];
  123.   o = a[0];
  124.  
  125.   if (s > 0)
  126.   for (i = 0; i < 5; i++)
  127.     {
  128.     aa = (char *) DIDC_ptr(s,o);
  129.     if ((aa[0] == 'P') &&
  130.         (aa[1] == 'Q') &&
  131.         (aa[2] == 'R') &&
  132.         (aa[3] == 'S'))
  133.       {
  134.       /* Obtain the address of the shared memory area */
  135.       DIDC_regs.x.ax = 0;
  136.       int86(j,&DIDC_regs,&DIDC_regs);
  137.       DIDC_params = (char *) (((long) DIDC_regs.x.cx << 16) + DIDC_regs.x.dx);
  138.       DIDC_int = j;
  139.       return 1;
  140.       }
  141.     o++;
  142.     }
  143.   }
  144. return 0;
  145. }
  146.  
  147. /************************************************************************/
  148.  
  149. int DIDC_total_pages(char dbname[], char kname[])
  150. {
  151. /* Function 001: Return total document pages */
  152. if (strlen(dbname) > MAX_FNAME_LEN)
  153.   return DB_NAME_TOO_LONG;
  154. if (strlen(kname) > 30)
  155.   return KEY_TOO_LONG;
  156. sprintf(DIDC_strng,"%d %s %s",1,dbname,kname);
  157. return DIDC_call_tsr(DIDC_strng);
  158. }
  159.  
  160. /************************************************************************/
  161.  
  162. int DIDC_total_pages_type(char dbname[], char kname[], int doc_type)
  163. {
  164. /* Function 002: Total pages of document type */
  165. if (strlen(dbname) > MAX_FNAME_LEN)
  166.   return DB_NAME_TOO_LONG;
  167. if (strlen(kname) > 30)
  168.   return KEY_TOO_LONG;
  169. if (doc_type < 0)
  170.   return PARAM_ERR;
  171.  
  172. sprintf(DIDC_strng,"%d %s %s %d",2,dbname,kname,doc_type);
  173. return DIDC_call_tsr(DIDC_strng);
  174. }
  175.  
  176. /************************************************************************/
  177.  
  178. int DIDC_call_menu(char dbname[], char kname[], int flag, char tfname[])
  179. {
  180. /* Function 003: call visage menu */
  181. if (strlen(dbname) > MAX_FNAME_LEN)
  182.   return DB_NAME_TOO_LONG;
  183. if (strlen(kname) > 30)
  184.   return KEY_TOO_LONG;
  185. if ((flag < 0) || (flag > 1))
  186.   return PARAM_ERR;
  187.  
  188. strcpy(FULL_PATH,dbname);
  189. if (strlen(FULL_PATH) > 63)
  190.   {
  191.   printf("Path length error\n");
  192.   return -1;
  193.   }
  194.  
  195. sprintf(DIDC_strng,"%d %s %s %d %s",3,FULL_PATH,kname,flag,tfname);
  196. return DIDC_call_tsr(DIDC_strng);
  197. }
  198.  
  199. /************************************************************************/
  200.  
  201. int DIDC_tsr_type(void)
  202. {
  203. /* Function 004 */
  204. sprintf(DIDC_strng,"%d",4);
  205. return DIDC_call_tsr(DIDC_strng);
  206. }
  207.  
  208. /************************************************************************/
  209.  
  210. int DIDC_batch_update(void)
  211. {
  212. /* Function 005 */
  213. strcpy(DIDC_strng,"5");
  214. return DIDC_call_tsr(DIDC_strng);
  215. }
  216.  
  217. /************************************************************************/
  218.  
  219. int DIDC_set_write_vol(unsigned wv)
  220. {
  221. /* Function 006 */
  222. sprintf(DIDC_strng,"%d %d",6,wv);
  223. return DIDC_call_tsr(DIDC_strng);
  224. }
  225.  
  226. /************************************************************************/
  227.  
  228. int DIDC_clear_doc_page(void)
  229. {
  230. /* Function 007 */
  231. sprintf(DIDC_strng,"%d",7);
  232. return DIDC_call_tsr(DIDC_strng);
  233. }
  234.  
  235. /************************************************************************/
  236.  
  237. int DIDC_unique_key(char dbname[], char kname[], int len)
  238. {
  239. /* Function 008 */
  240. int res;
  241.  
  242. if (strlen(dbname) > MAX_FNAME_LEN)
  243.   return DB_NAME_TOO_LONG;
  244. if (strlen(kname) > 30)
  245.   return KEY_TOO_LONG;
  246. if (len > 30)
  247.   return PARAM_ERR;
  248.  
  249. sprintf(DIDC_strng,"%d %s %d",8,dbname,len);
  250. res = DIDC_call_tsr(DIDC_strng);
  251. if (!res)
  252.   strcpy(kname,&DIDC_params[3]);
  253. else
  254.   strcpy(kname,"");
  255. return res;
  256. }
  257.  
  258. /************************************************************************/
  259.  
  260. int DIDC_get_write_vol(void)
  261. {
  262. /* Function 010 */
  263. sprintf(DIDC_strng,"%d",10);
  264. return DIDC_call_tsr(DIDC_strng);
  265. }
  266.  
  267. /************************************************************************/
  268.  
  269. int DIDC_show_luns(void)
  270. {
  271. /* Function 011 */
  272. sprintf(DIDC_strng,"%d",11);
  273. return DIDC_call_tsr(DIDC_strng);
  274. }
  275.  
  276. /************************************************************************/
  277. /* Scan functions                                                       */
  278. /************************************************************************/
  279.  
  280. int DIDC_scan_page(char dbname[], char kname[], int page_type)
  281. {
  282. /* Function 101 */
  283. if (strlen(dbname) > MAX_FNAME_LEN)
  284.   return DB_NAME_TOO_LONG;
  285. if (strlen(kname) > 30)
  286.   return KEY_TOO_LONG;
  287. if (page_type <= 0)
  288.   return PARAM_ERR;
  289.  
  290. sprintf(DIDC_strng,"%d %s %s %d",101,dbname,kname,page_type);
  291. return DIDC_call_tsr(DIDC_strng);
  292. }
  293.  
  294. /************************************************************************/
  295.  
  296. int DIDC_auto_scan(char dbname[], char kname[], int page_type)
  297. {
  298. /* Function 102 */
  299. if (strlen(dbname) > MAX_FNAME_LEN)
  300.   return DB_NAME_TOO_LONG;
  301. if (strlen(kname) > 30)
  302.   return KEY_TOO_LONG;
  303. if (page_type <= 0)
  304.   return PARAM_ERR;
  305.  
  306. sprintf(DIDC_strng,"%d %s %s %d",102,dbname,kname,page_type);
  307. return DIDC_call_tsr(DIDC_strng);
  308. }
  309.  
  310. /************************************************************************/
  311.  
  312. int DIDC_set_scanner(int page_len, int source, int intensity)
  313. {
  314. /* Function 103 */
  315. if ((page_len < 0) || (page_len > 1))
  316.   return PARAM_ERR;
  317. if ((source < 0) || (source > 1))
  318.   return PARAM_ERR;
  319. if ((intensity < 0) || (intensity > 6))
  320.   return PARAM_ERR;
  321.  
  322. sprintf(DIDC_strng,"%d %d %d %d",103, page_len, source, intensity);
  323. return DIDC_call_tsr(DIDC_strng);
  324. }
  325.  
  326. /************************************************************************/
  327.  
  328. int DIDC_insert_page(char dbname[],
  329.                      char kname[],
  330.                      int page_type,
  331.                      int page_num)
  332. {
  333. /* Function 104 */
  334. if (strlen(dbname) > MAX_FNAME_LEN)
  335.   return DB_NAME_TOO_LONG;
  336. if (strlen(kname) > 30)
  337.   return KEY_TOO_LONG;
  338. if (page_type <= 0)
  339.   return PARAM_ERR;
  340. if (page_num <= 0)
  341.   return PARAM_ERR;
  342.  
  343. sprintf(DIDC_strng,"%d %s %s %d %d",104, dbname, kname, page_type, page_num);
  344. return DIDC_call_tsr(DIDC_strng);
  345. }
  346.  
  347. /************************************************************************/
  348.  
  349. int DIDC_delete_page(char dbname[],
  350.                      char kname[],
  351.                      int page_type,
  352.                      int page_num)
  353. {
  354. /* Function 105 */
  355. if (strlen(dbname) > MAX_FNAME_LEN)
  356.   return DB_NAME_TOO_LONG;
  357. if (strlen(kname) > 30)
  358.   return KEY_TOO_LONG;
  359. if (page_type <= 0)
  360.   return PARAM_ERR;
  361. if (page_num <= 0)
  362.   return PARAM_ERR;
  363.  
  364. sprintf(DIDC_strng,"%d %s %s %d %d",105, dbname, kname, page_type, page_num);
  365. return DIDC_call_tsr(DIDC_strng);
  366. }
  367.  
  368. /************************************************************************/
  369.  
  370. int DIDC_get_scanner(int param)
  371. {
  372. /* Function 106 */
  373. sprintf(DIDC_strng,"%d %d",106, param);
  374. return DIDC_call_tsr(DIDC_strng);
  375. }
  376.  
  377. /************************************************************************/
  378.  
  379. int DIDC_save_scan_set(void)
  380. {
  381. /* Function 107 */
  382. sprintf(DIDC_strng,"%d",107);
  383. return DIDC_call_tsr(DIDC_strng);
  384. }
  385.  
  386. /************************************************************************/
  387. /* Print functions                                                      */
  388. /************************************************************************/
  389.  
  390. int DIDC_print_all_pages_type(char dbname[],
  391.                               char kname[],
  392.                               int doctype)
  393. {
  394. /* Function 201 */
  395. if (strlen(dbname) > MAX_FNAME_LEN)
  396.   return DB_NAME_TOO_LONG;
  397. if (strlen(kname) > 30)
  398.   return KEY_TOO_LONG;
  399. if (doctype < 0)
  400.   return PARAM_ERR;
  401.  
  402. sprintf(DIDC_strng,"%d %s %s %d", 201, dbname, kname, doctype);
  403. return DIDC_call_tsr(DIDC_strng);
  404. }
  405.  
  406. /************************************************************************/
  407.  
  408. int DIDC_print_pages(char dbname[],
  409.                      char kname[],
  410.                      int doctype,
  411.                      int first_page,
  412.                      int last_page)
  413. {
  414. if (strlen(dbname) > MAX_FNAME_LEN)
  415.   return DB_NAME_TOO_LONG;
  416. if (strlen(kname) > 30)
  417.   return KEY_TOO_LONG;
  418. if (doctype < 0)
  419.   return PARAM_ERR;
  420. if (first_page < 0)
  421.   return PARAM_ERR;
  422.  
  423. sprintf(DIDC_strng,"%d %s %s %d %d %d",
  424.   203, dbname, kname, doctype, first_page, last_page);
  425. return DIDC_call_tsr(DIDC_strng);
  426. }
  427.  
  428. /************************************************************************/
  429. /* Display Functions                                                    */
  430. /************************************************************************/
  431.  
  432. int DIDC_display_page(char dbname[],
  433.                       char kname[],
  434.                       int pagetype,
  435.                       int page,
  436.                       int control)
  437. {
  438. /* Function 300 */
  439.  
  440. if (strlen(dbname) > MAX_FNAME_LEN)
  441.   return DB_NAME_TOO_LONG;
  442. if (strlen(kname) > 30)
  443.   return KEY_TOO_LONG;
  444. if (pagetype < 1)
  445.   return PARAM_ERR;
  446. if (page < 0)
  447.   return PARAM_ERR;
  448.  
  449. sprintf(DIDC_strng,"%d %s %s %d %d %d",300,dbname,kname,pagetype,page,control);
  450. return DIDC_call_tsr(DIDC_strng);
  451. }
  452.  
  453. /************************************************************************/
  454. /* OCR Functions                                                        */
  455. /************************************************************************/
  456.  
  457. int DIDC_ocr_page(char dbname[],
  458.                   char kname[],
  459.                   int pagetype,
  460.                   int page,
  461.                   char textfname[],
  462.                   int append_flag)
  463. {
  464. /* Function 400 */
  465.  
  466. if (strlen(dbname) > MAX_FNAME_LEN)
  467.   return DB_NAME_TOO_LONG;
  468. if (strlen(kname) > 30)
  469.   return KEY_TOO_LONG;
  470. if (pagetype < 0)
  471.   return PARAM_ERR;
  472. if (page < 0)
  473.   return PARAM_ERR;
  474. if (strlen(textfname) == 0)
  475.   return PARAM_ERR;
  476.  
  477. sprintf(DIDC_strng,"%d %s %s %d %d %s %d",
  478.             400,dbname,kname,pagetype,page,textfname,append_flag);
  479. return DIDC_call_tsr(DIDC_strng);
  480. }
  481.  
  482. /************************************************************************/
  483.  
  484. int DIDC_extract_image(char dbname[],
  485.                        char kname[],
  486.                        int doctype,
  487.                        int page,
  488.                        char fname[])
  489. {
  490. /* Function 401 */
  491.  
  492. if (strlen(dbname) > MAX_FNAME_LEN)
  493.   return DB_NAME_TOO_LONG;
  494. if (strlen(kname) > 30)
  495.   return KEY_TOO_LONG;
  496. if (strlen(fname) > MAX_FNAME_LEN)
  497.   return PARAM_ERR;
  498. if (doctype < 0)
  499.   return PARAM_ERR;
  500. if (page <= 0)
  501.   return PARAM_ERR;
  502.  
  503. sprintf(DIDC_strng,"%d %s %s %d %d %s",11,dbname,kname,doctype,page,fname);
  504. return DIDC_call_tsr(DIDC_strng);
  505. }
  506.  
  507.  
  508. /************************************************************************/
  509. /* Other Functions                                                      */
  510. /************************************************************************/
  511.  
  512. int DIDC_printer_status(void)
  513. {
  514. int abyte;
  515. abyte=0;
  516. return biosprint(2, abyte, 0);
  517. #endif
  518. }
  519.  
  520.