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