home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume37 / aimmdemo / part01 < prev    next >
Encoding:
Text File  |  1993-04-25  |  53.0 KB  |  2,335 lines

  1. Newsgroups: comp.sources.misc
  2. From: hsilbiger@attmail.att.com
  3. Subject: v37i025:  aimm-demo - ANSI/AIIM Image File Program and Sources, Part01/03
  4. Message-ID: <csm-v37i025=aimm-demo.083922@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: f756b31d0dc9b3f40f49f3eda50ace58
  6. Date: Mon, 26 Apr 1993 13:40:40 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: hsilbiger@attmail.att.com
  10. Posting-number: Volume 37, Issue 25
  11. Archive-name: aimm-demo/part01
  12. Environment: Borland_C, MicroSoft_C
  13.  
  14. This is part 1 of 3 of a program to construct an image file according 
  15. to ANSI/AIIM MS53 Standard bi-level image file format.  A description 
  16. of the format is included.  This material is intended primarily to 
  17. demonstrate the format.
  18.  
  19. This program was developed to generate the examples in appendix
  20. E of the ANSI/AIIM MS53-199x standard it would work as a primitive
  21. import routine. This program should compile with either Borland C or
  22. Microsoft C. The tab spacing was set to 4.
  23.  
  24. This was not written to be the most efficient code but rather as a
  25. demo of the A11 standard encoding. Also, there is minimal error checking
  26. a full implementation would have extensive error checking.
  27.  
  28. The ANSI/AIIM MS-53 Standard Recommended Practice - File Format for Storage
  29. and Exchange of Images - Bi-Level File Format: Part 1 is available from
  30.  
  31.     Association for Information and Image Management
  32.     1100 Wayne Avenue
  33.     Silver Spring, MD 20910-5699
  34.     Tel: +1 301 587-8202
  35.     Fax: +1 301 588-3848
  36. ----------------------------
  37. #! /bin/sh
  38. # This is a shell archive.  Remove anything before this line, then feed it
  39. # into a shell via "sh file" or similar.  To overwrite existing files,
  40. # type "sh file -c".
  41. # Contents:  a11_new.c e5.ctl gen_a11.c
  42. # Wrapped by kent@sparky on Mon Apr 26 08:32:53 CDT 1993
  43. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  44. echo If this archive is complete, you will see the following message:
  45. echo '          "shar: End of archive 1 (of 3)."'
  46. if test -f 'a11_new.c' -a "${1}" != "-c" ; then 
  47.   echo shar: Will not clobber existing file \"'a11_new.c'\"
  48. else
  49.   echo shar: Extracting \"'a11_new.c'\" \(24691 characters\)
  50.   sed "s/^X//" >'a11_new.c' <<'END_OF_FILE'
  51. X/* This program was written by Mike Fleischmann of Optical Publishing, Inc.
  52. X    Copyright 1993 Optical Publishing, Inc. All rights reserved.
  53. X    Redistribution and use in source and binary form are freely permitted
  54. X    provided that the above copyright notice appears in all documentation.
  55. X    
  56. X    THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESSED OR IMPLIED
  57. X    WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 
  58. X    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. By installing this 
  59. X    software, you agree to hold Optical Publishing, Inc. harmless for any 
  60. X    damages resulting from the use of this software.
  61. X*/
  62. X
  63. X/* The program was copyrighted to allow you to know the source of the code. 
  64. X    This way if you need to contact us, you at least know the company name.
  65. X    We are in based in Ft. Collins, Colorado at (303)-226-3466.
  66. X    Our intention is to allow you to use, modify, copy and redistribute this
  67. X    code as well as integrate it into your applications at no charge or 
  68. X    royalties of any kind. Our only request is that if you use sections of 
  69. X    this code in your products, you include a 'Portions Copyright 1993 Optical
  70. X    Publishing, Inc. All rights reserved.' in your documentation. That's it, 
  71. X    we want to make this standard as easy to use as possible and giving away
  72. X    working code seemed the best way to do it.
  73. X*/
  74. X
  75. X/***********************************************************************
  76. X!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  77. X!!!!!!!!!!!!!!!!!!!!!!!!      NOTE NOTE NOTE    !!!!!!!!!!!!!!!!!!!!!!!!!
  78. X!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  79. X    This version has proposed changes that affect table A.1 in annex A of
  80. X    the standard. Although this change is likely to be approved please 
  81. X    contact AIIM for confirmation of the approval.
  82. X!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  83. X/***********************************************************************/
  84. X
  85. X/* although this program was developed to generate the examples in appendix
  86. X    E of the ANSI/AIIM MS53-199x standard it would work as a primitive 
  87. X    import routine. This program should compile with either Borland C or 
  88. X    Microsoft C. The tab spacing was set to 4.
  89. X    
  90. X    This was not written to be the most efficient code but rather as a  
  91. X    demo of the A11 standard encoding. Also, there is minimal error checking
  92. X    a full implementation would have extensive error checking.
  93. X
  94. X
  95. X    The program's calling parameters are GEN_A11 filename.ext where
  96. X        filename.ext is the name of the control file.
  97. X    The control file is in the format keyword=value. All values are in HEX!!
  98. X    NOTE: all the keywords are not necessary if you are excluding the area
  99. X    where they are used. i.e. clipping.
  100. X
  101. X    keywords are (case insensitive):
  102. X        infile        the input image file
  103. X        outfile        the output image file name. (an extension .A11 is suggested)
  104. X        length        the length of the data file
  105. X        c4            the last digit in the c1 c2 c3 c4 encoding string
  106. X        cp            the compression flag
  107. X        lp            the line progression 
  108. X        pp            the pel path
  109. X        ps            the pel spaces value
  110. X        rl            the raster ratio for line spacing
  111. X        rp            the raster ratio for pel spacing
  112. X        sl            the spacing length
  113. X        string        the user string. (note this can span lines needs to be 
  114. X                    ended with the tilda (~) character.
  115. X        dh            horizontal block dimensions
  116. X        dv            vertical block dimensions
  117. X        fx            first X clipping coord in BMUs
  118. X        fy            first Y clipping coord in BMUs
  119. X        hp            horizontal page dimensions in BMUs
  120. X        nl            number of lines (if known)
  121. X        ph            horizontal starting position in BMUs
  122. X        pl            number of pels per line
  123. X        pv            vertical starting position in BMUs 
  124. X        sx            second X clipping coord in BMUs
  125. X        sy            secong Y clipping coord in BMUs
  126. X        vp            vertical page dimensions in BMUs
  127. X*/
  128. X
  129. X/****************************************************************************/
  130. X
  131. X#include <stdio.h>
  132. X#include <string.h>
  133. X#include <stdlib.h>
  134. X#include <ctype.h>
  135. X
  136. X#define LEN_A1_NARY (sizeof(a1_nary))
  137. X#define LEN_A2 (sizeof(a2))
  138. X#define LEN_A3_NARY (sizeof(a3_nary))
  139. X#define LEN_A4 (sizeof(a4))
  140. X
  141. Xunsigned char a1_nary[]={    /* fixed portion of a1 */
  142. X    0x84,0x05,
  143. X        0x2a,0x86,0x48,0xce,0x1c,
  144. X    0xa5,0x06,
  145. X        0x06,0x04,
  146. X            0x58,0x02,0x07,0x02,
  147. X        0x86,0x01,
  148. X            0x00,
  149. X    0xa8,0x4e,
  150. X        0x43,0x40,
  151. X            0x43,0x43,0x49,0x54,0x54,0x20,0x52,0x65,0x63,0x2e,
  152. X            0x20,0x54,0x2e,0x34,0x31,0x30,0x20,0x73,0x65,0x72,
  153. X            0x69,0x65,0x73,0x20,0x28,0x31,0x39,0x39,0x32,0x29,
  154. X            0x20,0x7c,0x20,0x49,0x53,0x4f,0x2f,0x49,0x45,0x43,
  155. X            0x20,0x38,0x36,0x31,0x33,0x3a,0x31,0x39,0x39,0x33,
  156. X            0x3b,0x20,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,
  157. X            0x32,0x2e,0x30,0x30,
  158. X        0x44,0x0a,
  159. X            0x31,0x39,0x39,0x32,0x2d,0x30,0x35,0x2d,0x30,0x31,
  160. X    0xaa,0x10,
  161. X        0xa0,0x0e,
  162. X            0x80,0x04,
  163. X                0x58,0x02,0x07,0x02,
  164. X            0xaa,0x06,
  165. X                0x86,0x04,
  166. X                    0x58,0x03,0x07,0x06
  167. X    };
  168. X
  169. Xunsigned char a2[]={        /* The document layout root  fixed content */
  170. X                    0xa2,0x0d,
  171. X                        0x02,0x01,
  172. X                            0x00,
  173. X                        0x31,0x08,
  174. X                            0x41,0x01,
  175. X                                0x31,
  176. X                            0xa0,0x03,
  177. X                                0x12,0x01,
  178. X                                    0x30
  179. X                    };
  180. X
  181. Xunsigned char a3_nary[]={    /* fixed portion of a3 */
  182. X        0x41,0x03,
  183. X            0x31,0x20,0x30,
  184. X        0xa0,0x03,
  185. X            0x12,0x01,
  186. X                0x30,
  187. X            0xaf,0x06,
  188. X                0x80,0x01,
  189. X                    0x00,
  190. X                0x80,0x01,
  191. X                    0x00
  192. X    };
  193. X
  194. Xunsigned char a4[]={        /* The document layout root  fixed content */
  195. X                    0xa2,0x11,
  196. X                        0x02,0x01,
  197. X                            0x03,
  198. X                        0x31,0x0c,
  199. X                            0x41,0x05,
  200. X                                0x31,0x20,0x30,0x20,0x30,
  201. X                            0xa0,0x03,
  202. X                                0x12,0x01,
  203. X                                    0x30
  204. X                    };
  205. X
  206. Xunsigned char c1[]={0x58,0x03,0x07,0xff};    /* the c1c2c3c4 param */
  207. Xunsigned char cp=0xff;        /* compression set to invalid value */
  208. Xunsigned char lp=0xff;        /* line progression set to invalid value */
  209. Xunsigned char pp=0xff;        /* pel path set to invalid character */
  210. Xunsigned char ps=0;    /* pel spaces (invalid value)*/
  211. Xunsigned char rl=0;    /* raster ratio line spacing (invalid value) */
  212. Xunsigned char rp=0;    /* raster ratio pel spacing (invalid value) */
  213. Xunsigned char sl=0;    /* spacing length (invalid value) */
  214. Xchar str1[510];            /* the variable length string. (512 bytes max) */
  215. X
  216. Xlong dh=0;                /* horizontal block dimensions in BMUs */
  217. Xlong dv=0;                /* vertical block dimensions in BMUs */
  218. Xlong fx=0;                /* first x clipping coord in BMUs */
  219. Xlong fy=0;                /* first y clipping coord in BMUs */
  220. Xlong hp=0;                /* horizontal page dimensions in BMU's */
  221. Xlong nl=0;                /* number of lines */
  222. Xlong ph=0;                /* horizontal starting position in BMUs */
  223. Xlong pl=0;                /* number of pels per line */
  224. Xlong pv=0;                /* vertical starting position */
  225. Xlong sx=0;                /* second X clipping coord in BMUs */
  226. Xlong sy=0;                /* second Y clipping coord in BMUs */
  227. Xlong vp=0;                /* vertical page dimensions in BMUs */
  228. X
  229. Xlong length=0;            /* length of the input data file */
  230. X
  231. XFILE *fin;                /* handle for the input image file */
  232. XFILE *fout;                /* handle for the output A11 file */
  233. XFILE *ctrl;                /* the file handle for the control file */
  234. X
  235. Xunsigned char buff[0x8000];        /* work buffer */
  236. Xunsigned char line[0x200];        /* line entry buffer */
  237. X
  238. Xchar *keyword[]={
  239. X    "INFILE",
  240. X    "OUTFILE",
  241. X    "LENGTH",
  242. X    "C4",
  243. X    "CP",
  244. X    "LP",
  245. X    "PP",
  246. X    "PS",
  247. X    "RL",
  248. X    "RP",
  249. X    "SL",
  250. X    "STRING",
  251. X    "DH",
  252. X    "DV",
  253. X    "FX",
  254. X    "FY",
  255. X    "HP",
  256. X    "NL",
  257. X    "PH",
  258. X    "PL",
  259. X    "PV",
  260. X    "SX",
  261. X    "SY",
  262. X    "VP",
  263. X    "~~~"};        /* mark as the end */
  264. X
  265. X#define INFILE 0
  266. X#define OUTFILE 1
  267. X#define LENGTH 2 
  268. X#define C4 3 
  269. X#define CP 4 
  270. X#define LP 5
  271. X#define PP 6
  272. X#define PS 7
  273. X#define RL 8
  274. X#define RP 9 
  275. X#define SL 10
  276. X#define STRING 11
  277. X#define DH 12
  278. X#define DV 13
  279. X#define FX 14
  280. X#define FY 15
  281. X#define HP 16
  282. X#define NL 17
  283. X#define PH 18
  284. X#define PL 19
  285. X#define PV 20
  286. X#define SX 21
  287. X#define SY 22
  288. X#define VP 23
  289. X
  290. X
  291. Xvoid Get_Line(void);
  292. Xint Char2val(int);
  293. Xlong Get_Hex(char *);
  294. XRead_Control(void);
  295. XDo_In_Fun(int,char *);
  296. Xint Gen_Lxx(int,unsigned long);        /* gen the format lxx table 5*/
  297. Xint Gen_Len(int,unsigned long);        /* gen the format lxx table 4*/
  298. XDo_A1(void);        /* this and the following will build the data from
  299. X                    the end
  300. X                    */ 
  301. XDo_A3(void);
  302. XDo_A5c(void);
  303. XDo_A5(int,int);        /* first int is current, second int is scpe loc */
  304. XDo_A6d(void);
  305. XDo_A6i(void);
  306. X
  307. X
  308. X
  309. Xint main(argc,argv)
  310. Xint argc;
  311. Xchar *argv[];
  312. X{
  313. X    int rtn;        /* used for function return checking */
  314. X
  315. X    str1[0]=' ';    /* guarentee at least a comment */
  316. X    str1[1]=0;    /* guarentee at least a comment */
  317. X    if(argc<2)
  318. X    {
  319. X        printf("calling parameters are A11_NEW ctrlfile.ext\n");
  320. X        printf(" where ctrlfile.ext is the controll file. See source code for\n");
  321. X        printf(" more information\n");
  322. X        exit(0);
  323. X    }
  324. X    
  325. X    ctrl=fopen(argv[1],"r");
  326. X    if(ctrl==NULL)
  327. X    {
  328. X        printf("unable to open the controll file >%s<\n",argv[1]);
  329. X        exit(0);
  330. X    }
  331. X    
  332. X    rtn=Read_Control();            /* read the control file in */
  333. X    if(rtn)        /* if an error */
  334. X    {
  335. X        printf("error reading controll file. Program ending\n");
  336. X        exit(0);
  337. X    }
  338. X    rtn=Do_A1();        /* go and do the a.1 table */
  339. X    if(rtn)        /* if an error */
  340. X    {
  341. X        printf("error in generation of the A.1 header table. Program ending\n");
  342. X        exit(0);
  343. X    }
  344. X
  345. X    rtn=fwrite(a2,1,LEN_A2,fout);        /* output the a2 table */
  346. X    if(rtn!=LEN_A2)        /* if an error */
  347. X    {
  348. X        printf("error in writing A.2 table. Program ending\n");
  349. X        exit(0);
  350. X    }
  351. X
  352. X    rtn=Do_A3();        /* go and do the a.3 table */
  353. X    if(rtn)        /* if an error */
  354. X    {
  355. X        printf("error in generation of the A.3 header table. Program ending\n");
  356. X        exit(0);
  357. X    }
  358. X
  359. X    rtn=fwrite(a4,1,LEN_A4,fout);        /* output the a4 table */
  360. X    if(rtn!=LEN_A4)        /* if an error */
  361. X    {
  362. X        printf("error in writing A.4 table. Program ending\n");
  363. X        exit(0);
  364. X    }
  365. X
  366. X    if(fx!=0 || fy!=0 || sx!=0 || sy!=0)
  367. X    {
  368. X        /* if here we have clipping */
  369. X        rtn=Do_A5c();        /* go and do the a.5 table for clipping */
  370. X        if(rtn)        /* if an error */
  371. X        {
  372. X            printf("error in generation of the A.51 header table. Program ending\n");
  373. X            exit(0);
  374. X        }
  375. X    }
  376. X    else
  377. X    {
  378. X        rtn=Do_A5(0x400,0x400);        /* go and do the a.5 table for no clipping*/
  379. X        if(rtn)        /* if an error */
  380. X        {
  381. X            printf("error in generation of the A.3 header table. Program ending\n");
  382. X            exit(0);
  383. X        }
  384. X    }
  385. X
  386. X    if(length>0)        /* definite length */
  387. X    {
  388. X        rtn=Do_A6d();        /* go and do the a.6 table */
  389. X        if(rtn)        /* if an error */
  390. X        {
  391. X            printf("error in generation of the A.6 table. Program ending\n");
  392. X            exit(0);
  393. X        }
  394. X    }
  395. X    else    /* indefinite length */
  396. X    {
  397. X        rtn=Do_A6i();        /* go and do the a.6 table */
  398. X        if(rtn)        /* if an error */
  399. X        {
  400. X            printf("error in generation of the A.6 table. Program ending\n");
  401. X            exit(0);
  402. X        }
  403. X    }
  404. X
  405. X    fclose(fout);
  406. X    fclose(fin);
  407. X    fclose(ctrl);
  408. X    printf("File build finished\n");
  409. X    return(0);
  410. X}
  411. X
  412. Xvoid Get_Line()
  413. X{
  414. X    int i;        /* temp work variable */
  415. X
  416. X    fgets(line,0x200,ctrl);
  417. X    i=strlen(line);
  418. X    for(i--;i>0 && line[i]<=' ';line[i--]=0) ;  /* remove trailing crlf */
  419. X    
  420. X    /* turn to uppercase */
  421. X    for(i=0;line[i] && line[i]!='=';line[i]=toupper(line[i]),i++);
  422. X    if(memcmp(line,"STRING",6)!=0)    /* skip string case */
  423. X        for(;line[i];line[i]=toupper(line[i]),i++);
  424. X
  425. X}
  426. X
  427. Xint Char2val(ch)
  428. Xint ch;
  429. X{
  430. X    if(ch<='9')
  431. X        ch-='0';
  432. X    else
  433. X        ch = ch-'A'+10;
  434. X    return(ch);
  435. X}
  436. X
  437. Xlong Get_Hex(str)
  438. Xchar *str;
  439. X{
  440. X    long l1;
  441. X    int i;
  442. X    
  443. X    for(i=0;str[i]<=' ' && str[i];i++);    /* ignore leading white space */
  444. X
  445. X    for(i=0,l1=0;isxdigit(str[i]);i++)
  446. X    {
  447. X        l1<<=4;
  448. X        l1+=(long)Char2val(str[i]);
  449. X    }
  450. X    return(l1);
  451. X}
  452. X
  453. XRead_Control()
  454. X{
  455. X    /* this will read in the control file and initialize the variables */
  456. X    char *cptr,*cptr1;        /* temp char pointer used for parsing */
  457. X    int i,j,k;
  458. X    
  459. X    Get_Line();        /* input the line */
  460. X    while(!feof(ctrl))
  461. X    {
  462. X        cptr=line;
  463. X        while(cptr[0]==' ')        /* skip leading spaces */
  464. X            cptr++;
  465. X        cptr1=strchr(cptr,'=');
  466. X        if(cptr1!=NULL)        /* if null treat as comment field */
  467. X        {
  468. X            /* if here have something to work with */
  469. X            cptr1[0]=0;        /* mark end */
  470. X            cptr1++;
  471. X            i=strlen(cptr);        /* get the length of compare string  */
  472. X            for(j=0;keyword[j][0]!='~';j++)
  473. X            {
  474. X                if(memcmp(cptr,keyword[j],i)==0)
  475. X                {
  476. X                    k=Do_In_Fun(j,cptr1);
  477. X                    if(k)
  478. X                        return(k);        /* return if error */
  479. X                    break;
  480. X                }
  481. X            }
  482. X        }
  483. X        Get_Line();        /* input the line */
  484. X    }
  485. X    return(0);        /* return valid processing */
  486. X}
  487. X
  488. XDo_In_Fun(fun,str)
  489. Xint fun;        /* the function number to do */
  490. Xchar *str;        /* the remaining string */
  491. X{
  492. X    int i,j;
  493. X    char *cptr;
  494. X    
  495. X    switch(fun)
  496. X    {
  497. X        case INFILE:
  498. X            fin=fopen(str,"rb");        /* open the input image file */
  499. X            if(fin==NULL)
  500. X                return(INFILE+1);
  501. X            break;
  502. X        case OUTFILE:
  503. X            fout=fopen(str,"wb");        /* open the output A11 file */
  504. X            if(fout==NULL)
  505. X                return(OUTFILE+1);
  506. X            break;
  507. X        case LENGTH:
  508. X            length=Get_Hex(str);        /* get the length */
  509. X            if(length<1)
  510. X                return(LENGTH+1);
  511. X            break;
  512. X        case C4:
  513. X            c1[3]=(char)Get_Hex(str);    /* get the c4 character */
  514. X            if(c1[3]>8)
  515. X                return(C4+1);
  516. X            break;
  517. X        case CP:
  518. X            cp=(char)Get_Hex(str);    /* get the cp character */
  519. X            if(cp<0 || cp>1)
  520. X                return(CP+1);
  521. X            break;
  522. X        case LP:
  523. X            lp=(char)Get_Hex(str);    /* get the lp character */
  524. X            if(lp!=1 && lp!=3)
  525. X                return(LP+1);
  526. X            break;
  527. X        case PP:
  528. X            pp=(char)Get_Hex(str);    /* get the pp character */
  529. X            if(pp<0 || pp>3)
  530. X                return(PP+1);
  531. X            break;
  532. X        case PS:
  533. X            ps=(char)Get_Hex(str);    /* get the ps character */
  534. X            if(ps==0)
  535. X                return(PS+1);
  536. X            break;
  537. X        case RL:
  538. X            rl=(char)Get_Hex(str);    /* get the cp character */
  539. X            if(rl==0)
  540. X                return(RL+1);
  541. X            break;
  542. X        case RP:
  543. X            rp=(char)Get_Hex(str);    /* get the cp character */
  544. X            if(rp==0)
  545. X                return(RP+1);
  546. X            break;
  547. X        case SL:
  548. X            sl=(char)Get_Hex(str);    /* get the cp character */
  549. X            if(sl==0)
  550. X                return(SL+1);
  551. X            break;
  552. X        case STRING:
  553. X            j=0;
  554. X            cptr=str;
  555. X            while(1)
  556. X            {
  557. X                for(i=0;cptr[i] && cptr[i]!='~' && j<500;i++)
  558. X                    str1[j++]=cptr[i];
  559. X                if(j>499 || cptr[i]=='~')    /* done entering string */
  560. X                    break;
  561. X                Get_Line();
  562. X                if(feof(ctrl))
  563. X                    return(STRING+1);
  564. X                cptr=line;
  565. X            }
  566. X            str1[j++]=0;        /* null terminate */
  567. X            break;
  568. X        case DH:
  569. X            dh=Get_Hex(str);    /* get the dh value */
  570. X            if(dh<1)
  571. X                return(DH+1);
  572. X            break;
  573. X        case DV:
  574. X            dv=Get_Hex(str);    /* get the dv value */
  575. X            if(dv<1)
  576. X                return(DV+1);
  577. X            break;
  578. X        case FX:
  579. X            fx=Get_Hex(str);    /* get the fx value */
  580. X            break;
  581. X        case FY:
  582. X            fy=Get_Hex(str);    /* get the fy value */
  583. X            break;
  584. X        case HP:
  585. X            hp=Get_Hex(str);    /* get the hp value */
  586. X            if(hp<1)
  587. X                return(HP+1);
  588. X            break;
  589. X        case NL:
  590. X            nl=Get_Hex(str);    /* get the nl value */
  591. X            if(nl<1)
  592. X                return(NL+1);
  593. X            break;
  594. X        case PH:
  595. X            ph=Get_Hex(str);    /* get the ph value */
  596. X            if(dh<0)
  597. X                return(PH+1);
  598. X            break;
  599. X        case PL:
  600. X            pl=Get_Hex(str);    /* get the pl value */
  601. X            if(pl<1)
  602. X                return(PL+1);
  603. X            break;
  604. X        case PV:
  605. X            pv=Get_Hex(str);    /* get the pv value */
  606. X            break;
  607. X        case SX:
  608. X            sx=Get_Hex(str);    /* get the sx value */
  609. X            break;
  610. X        case SY:
  611. X            sy=Get_Hex(str);    /* get the sy value */
  612. X            break;
  613. X        case VP:
  614. X            vp=Get_Hex(str);    /* get the vp value */
  615. X            if(vp<1)
  616. X                return(VP+1);
  617. X            break;
  618. X        default:
  619. X            return(-1);
  620. X    }
  621. X    return(0);
  622. X}
  623. X
  624. Xint Gen_Lxx(cur,val)        /* gen the format table 5 */
  625. Xint cur;        /* current position in buff */
  626. Xunsigned long val;        /* value to insert */
  627. X{
  628. X    
  629. X    if(val <0x80L)    /* single byte */
  630. X    {
  631. X        buff[cur]=(unsigned char) val & 0xff;
  632. X        return(1);
  633. X    }
  634. X    else if(val <0x100L)    /* single byte */
  635. X    {
  636. X        buff[cur]=(unsigned char) val & 0xff;
  637. X        buff[cur-1]=0x81;
  638. X        return(2);
  639. X    }
  640. X    else if(val <0x10000L)    /* 2 bytes */
  641. X    {
  642. X        buff[cur]=(unsigned char) val & 0xff;
  643. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  644. X        buff[cur-2]=0x82;
  645. X        return(3);
  646. X    }
  647. X    else if(val <0x1000000L)    /* 3 bytes */
  648. X    {
  649. X        buff[cur]=(unsigned char) val & 0xff;
  650. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  651. X        buff[cur-2]=(unsigned char) (val>>16) & 0xff;
  652. X        buff[cur-3]=0x83;
  653. X        return(4);
  654. X    }
  655. X    else    /* 4 bytes */
  656. X    {
  657. X        buff[cur]=(unsigned char) val & 0xff;
  658. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  659. X        buff[cur-2]=(unsigned char) (val>>16) & 0xff;
  660. X        buff[cur-3]=(unsigned char) (val>>24) & 0xff;
  661. X        buff[cur-4]=0x84;
  662. X        return(5);
  663. X    }
  664. X}
  665. X
  666. Xint Gen_Len(cur,val)        /* gen the format table 4 */
  667. Xint cur;        /* current position in buff */
  668. Xunsigned long val;        /* value to insert */
  669. X{
  670. X    
  671. X    if(val <0x100L)    /* single byte */
  672. X    {
  673. X        buff[cur]=(unsigned char) val & 0xff;
  674. X        buff[cur-1]=1;
  675. X        return(2);
  676. X    }
  677. X    else if(val <0x10000L)    /* 2 bytes */
  678. X    {
  679. X        buff[cur]=(unsigned char) val & 0xff;
  680. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  681. X        buff[cur-2]=2;
  682. X        return(3);
  683. X    }
  684. X    else if(val <0x1000000L)    /* 3 bytes */
  685. X    {
  686. X        buff[cur]=(unsigned char) val & 0xff;
  687. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  688. X        buff[cur-2]=(unsigned char) (val>>16) & 0xff;
  689. X        buff[cur-3]=3;
  690. X        return(4);
  691. X    }
  692. X    else    /* 4 bytes */
  693. X    {
  694. X        buff[cur]=(unsigned char) val & 0xff;
  695. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  696. X        buff[cur-2]=(unsigned char) (val>>16) & 0xff;
  697. X        buff[cur-3]=(unsigned char) (val>>24) & 0xff;
  698. X        buff[cur-4]=4;
  699. X        return(5);
  700. X    }
  701. X}
  702. X
  703. XDo_A1()        /* this and the following will build the data from the end 
  704. X            towards the front */
  705. X{
  706. X    int a1_end=0x400;
  707. X    int cur=0x400;
  708. X    int dend;
  709. X    int nend;
  710. X    int pt8;
  711. X    int pt7;
  712. X    int pt3;
  713. X    int i;
  714. X    
  715. X    i=strlen(str1);
  716. X    i--;
  717. X    while(i>=0)        /* copy the users string */
  718. X    {
  719. X        buff[cur--]=str1[i--];
  720. X    }
  721. X
  722. X    cur-=Gen_Lxx(cur,a1_end-cur);        /* do the LDR section */
  723. X    buff[cur--]=0x43;
  724. X    
  725. X    cur-=Gen_Lxx(cur,a1_end-cur);        /* do the LD3 section */
  726. X    buff[cur--]=0xa5;
  727. X    
  728. X    cur-=Gen_Lxx(cur,a1_end-cur);        /* do the LD2 section */
  729. X    buff[cur--]=0xa7;
  730. X    
  731. X    cur-=Gen_Lxx(cur,a1_end-cur);        /* do the LD1 section */
  732. X    buff[cur--]=0xa3;
  733. X    dend=cur;        /* mark the current position */
  734. X    
  735. X    i=LEN_A1_NARY;
  736. X    i--;
  737. X    while(i>=0)        /* copy the fixed array stuff */
  738. X    {
  739. X        buff[cur--]=a1_nary[i--];
  740. X    }
  741. X    nend=cur;        /* mark position of a1_end byte */
  742. X    
  743. X    buff[cur--]=ps;
  744. X    buff[cur--]=1;
  745. X    buff[cur--]=2;
  746. X
  747. X    buff[cur--]=sl;
  748. X    buff[cur--]=1;
  749. X    buff[cur--]=2;
  750. X    buff[cur--]=6;
  751. X    buff[cur--]=0xa0;
  752. X    buff[cur--]=8;
  753. X    buff[cur--]=0xa5;
  754. X    
  755. X    buff[cur--]=lp;
  756. X    buff[cur--]=1;
  757. X    buff[cur--]=0x8a;
  758. X    
  759. X    buff[cur--]=pp;
  760. X    buff[cur--]=1;
  761. X    buff[cur--]=0x89;
  762. X    buff[cur--]=0x10;
  763. X    buff[cur--]=0xa4;
  764. X    
  765. X    buff[cur--]=cp;
  766. X    buff[cur--]=1;
  767. X    buff[cur--]=0x80;
  768. X    buff[cur--]=3;
  769. X    buff[cur--]=0xa3;
  770. X
  771. X    pt8=cur;
  772. X    buff[cur--]=0;
  773. X    buff[cur--]=1;
  774. X    buff[cur--]=2;
  775. X    pt7=cur;
  776. X    
  777. X    cur-=Gen_Len(cur,vp);        /* do the vp */
  778. X    buff[cur--]=0x80;
  779. X
  780. X    cur-=Gen_Len(cur,hp);        /* do the hp */
  781. X    buff[cur--]=0x80;
  782. X
  783. X    cur-=Gen_Lxx(cur,pt7-cur);        /* do the L13 */
  784. X    buff[cur--]=0x30;
  785. X    
  786. X    cur-=Gen_Lxx(cur,pt8-cur);        /* do the LNP */
  787. X    buff[cur--]=0x30;
  788. X    
  789. X    cur-=Gen_Lxx(cur,pt8-cur);        /* do the LMT */
  790. X    buff[cur--]=0xa8;
  791. X    pt3=cur;
  792. X    
  793. X    cur-=Gen_Len(cur,vp);        /* do the vp */
  794. X    buff[cur--]=0x80;
  795. X
  796. X    cur-=Gen_Len(cur,hp);        /* do the hp */
  797. X    buff[cur--]=0x80;
  798. X
  799. X    cur-=Gen_Lxx(cur,pt3-cur);        /* do the L12 */
  800. X    buff[cur--]=0x30;
  801. X    
  802. X    cur-=Gen_Lxx(cur,pt3-cur);        /* do the L11 */
  803. X    buff[cur--]=0xa2;
  804. X    
  805. X    cur-=Gen_Lxx(cur,nend-cur);        /* do the LND */
  806. X    buff[cur--]=0xa2;
  807. X    buff[cur--]=0x00;
  808. X    buff[cur--]=0x01;
  809. X    buff[cur--]=0x81;
  810. X    
  811. X    cur-=Gen_Lxx(cur,dend-cur);        /* do the LDC*/
  812. X    buff[cur--]=0xa2;
  813. X    buff[cur--]=0x31;
  814. X    buff[cur--]=0x01;
  815. X    buff[cur--]=0x81;
  816. X    
  817. X    cur-=Gen_Lxx(cur,a1_end-cur);        /* do the LDP*/
  818. X    buff[cur--]=0xa0;
  819. X    
  820. X    i=fwrite(&buff[cur+1],1,a1_end-cur,fout);
  821. X    if(i!=a1_end-cur)
  822. X        return(1);
  823. X    return(0);
  824. X}
  825. X
  826. XDo_A3()
  827. X{
  828. X    int a3_end=0x400;
  829. X    int cur=0x400;
  830. X    int a3_nend;
  831. X    int a3_mt;
  832. X    int a3_nps;
  833. X    int a3_pde;
  834. X    int a3_pds;
  835. X    int a3_body;
  836. X    int a3_start;
  837. X    int i;
  838. X    
  839. X    buff[cur--]=0;
  840. X    buff[cur--]=1;
  841. X    buff[cur--]=2;
  842. X    a3_nend=cur;
  843. X    
  844. X    cur-=Gen_Len(cur,vp);        /* do the vp */
  845. X    buff[cur--]=0x80;
  846. X
  847. X    cur-=Gen_Len(cur,hp);        /* do the hp */
  848. X    buff[cur--]=0x80;
  849. X    a3_nps=cur;
  850. X
  851. X    cur-=Gen_Lxx(cur,a3_nend-a3_nps);        /* do the LN3 */
  852. X    buff[cur--]=0x30;
  853. X    a3_mt=cur;
  854. X    
  855. X    cur-=Gen_Lxx(cur,a3_end-a3_mt);        /* do the LM3 */
  856. X    buff[cur--]=0xb0;
  857. X    a3_pde=cur;
  858. X    
  859. X    cur-=Gen_Len(cur,vp);        /* do the vp */
  860. X    buff[cur--]=0x80;
  861. X
  862. X    cur-=Gen_Len(cur,hp);        /* do the hp */
  863. X    buff[cur--]=0x80;
  864. X    a3_pds=cur;
  865. X
  866. X    cur-=Gen_Lxx(cur,a3_pde-a3_pds);        /* do the LPD */
  867. X    buff[cur--]=0xa4;
  868. X
  869. X    i=LEN_A3_NARY;
  870. X    i--;
  871. X    while(i>=0)        /* copy the fixed array stuff */
  872. X    {
  873. X        buff[cur--]=a3_nary[i--];
  874. X    }
  875. X    a3_body=cur;        /* mark position */
  876. X    cur-=Gen_Lxx(cur,a3_end-a3_body);        /* do the LAB */
  877. X    buff[cur--]=0x31;
  878. X    buff[cur--]=0x02;
  879. X    buff[cur--]=0x01;
  880. X    buff[cur--]=0x02;
  881. X
  882. X
  883. X    a3_start=cur;        /* mark position of a1_end byte */
  884. X
  885. X    cur-=Gen_Lxx(cur,a3_end-a3_start);        /* do the LA3 */
  886. X    buff[cur--]=0xa2;
  887. X
  888. X    i=fwrite(&buff[cur+1],1,a3_end-cur,fout);
  889. X    if(i!=a3_end-cur)
  890. X        return(1);
  891. X    return(0);
  892. X}
  893. X
  894. XDo_A5c()
  895. X{
  896. X    int a5_end=0x400;
  897. X    int cur=0x400;
  898. X    int a5_dime;
  899. X    int a5_scpe;
  900. X    int a5_fcpe;
  901. X    
  902. X    
  903. X    if(nl<1)        /* if we don't know the number of lines (required for clp)*/
  904. X    {
  905. X        return(1);        /* return the error */
  906. X    }
  907. X
  908. X    cur-=Gen_Len(cur,pv);        /* do the pv */
  909. X    buff[cur--]=0x80;
  910. X
  911. X    cur-=Gen_Len(cur,ph);        /* do the ph */
  912. X    buff[cur--]=0x80;
  913. X
  914. X    cur-=Gen_Lxx(cur,a5_end-cur);        /* do the LPS */
  915. X    buff[cur--]=0xa3;
  916. X    a5_dime=cur;
  917. X
  918. X    cur-=Gen_Len(cur,dv);        /* do the dv */
  919. X    buff[cur--]=0x80;
  920. X
  921. X    cur-=Gen_Len(cur,dh);        /* do the dh */
  922. X    buff[cur--]=0x80;
  923. X
  924. X    cur-=Gen_Lxx(cur,a5_dime-cur);        /* do the LDM */
  925. X    buff[cur--]=0xa4;
  926. X    a5_scpe=cur;
  927. X
  928. X    cur-=Gen_Len(cur,sy);        /* do the sy */
  929. X    buff[cur--]=0x2;
  930. X
  931. X    cur-=Gen_Len(cur,sx);        /* do the sx */
  932. X    buff[cur--]=0x2;
  933. X
  934. X    cur-=Gen_Lxx(cur,a5_scpe-cur);        /* do the LSP */
  935. X    buff[cur--]=0xa1;
  936. X    a5_fcpe=cur;
  937. X
  938. X    cur-=Gen_Len(cur,fy);        /* do the fy */
  939. X    buff[cur--]=0x2;
  940. X
  941. X    cur-=Gen_Len(cur,fx);        /* do the fx */
  942. X    buff[cur--]=0x2;
  943. X
  944. X    cur-=Gen_Lxx(cur,a5_fcpe-cur);        /* do the LFP */
  945. X    buff[cur--]=0xa0;
  946. X
  947. X    cur-=Gen_Lxx(cur,a5_scpe-cur);        /* do the LFP */
  948. X    buff[cur--]=0xa4;
  949. X
  950. X    return(Do_A5(cur,a5_scpe));
  951. X}
  952. X
  953. XDo_A5(cur,a5_scpe)
  954. Xint    cur;            /* current position in the buffer */
  955. Xint a5_scpe;        /* scpe position in the buffer */
  956. X{
  957. X    int i;
  958. X    int a5_end=0x400;
  959. X    static char pa_data[]={6,4,0x58,2,7,2};
  960. X    static unsigned char db_data[]={
  961. X                            0x41,7,0x31,0x20,0x30,0x20,0x30,0x20,0x30,
  962. X                            0xa1,3,0x12,1,0x30
  963. X                        };
  964. X    
  965. X    buff[cur--]=rp;            /* pel spacing ratio */
  966. X    buff[cur--]=0x1;
  967. X    buff[cur--]=0x2;
  968. X    
  969. X    buff[cur--]=rl;            /* pel spacing ratio */
  970. X    buff[cur--]=0x1;
  971. X    buff[cur--]=0x2;
  972. X    
  973. X    buff[cur--]=0x6;
  974. X    buff[cur--]=0xa6;
  975. X    
  976. X    buff[cur--]=ps;            /* pel spaces */
  977. X    buff[cur--]=0x1;
  978. X    buff[cur--]=0x2;
  979. X    
  980. X    buff[cur--]=sl;            /* spacing length */
  981. X    buff[cur--]=0x1;
  982. X    buff[cur--]=0x2;
  983. X    
  984. X    buff[cur--]=0x6;
  985. X    buff[cur--]=0xa0;
  986. X    
  987. X    buff[cur--]=0x8;        /* pel spacing */
  988. X    buff[cur--]=0xa5;
  989. X    
  990. X    buff[cur--]=lp;            /* line progression */
  991. X    buff[cur--]=0x1;
  992. X    buff[cur--]=0x81;
  993. X    
  994. X    buff[cur--]=pp;            /* pel path */
  995. X    buff[cur--]=0x1;
  996. X    buff[cur--]=0x80;
  997. X    
  998. X    cur-=Gen_Lxx(cur,a5_scpe-cur);        /* do the LRG */
  999. X    buff[cur--]=0xa1;
  1000. X
  1001. X    for(i=sizeof(pa_data)-1;i>=0;i--)
  1002. X    {
  1003. X        buff[cur--]=pa_data[i];
  1004. X    }
  1005. X    
  1006. X    cur-=Gen_Lxx(cur,a5_scpe-cur);        /* do the LPA */
  1007. X    buff[cur--]=0xa6;
  1008. X
  1009. X    for(i=sizeof(db_data)-1;i>=0;i--)
  1010. X    {
  1011. X        buff[cur--]=db_data[i];
  1012. X    }
  1013. X    
  1014. X    cur-=Gen_Lxx(cur,a5_end-cur);        /* do the LDB */
  1015. X    buff[cur--]=0x31;
  1016. X
  1017. X    buff[cur--]=0x4;        /* pel spacing */
  1018. X    buff[cur--]=0x1;        /* pel spacing */
  1019. X    buff[cur--]=0x2;        /* pel spacing */
  1020. X    
  1021. X    cur-=Gen_Lxx(cur,a5_end-cur);        /* do the LDL */
  1022. X    buff[cur--]=0xa2;
  1023. X
  1024. X    i=fwrite(&buff[cur+1],1,a5_end-cur,fout);
  1025. X    if(i!=a5_end-cur)
  1026. X        return(1);
  1027. X    return(0);
  1028. X}
  1029. X
  1030. XDo_A6d()
  1031. X{
  1032. X    int a6_end=0x400;
  1033. X    long a6_tend;
  1034. X    int cur=0x400;
  1035. X    int i;
  1036. X    unsigned int u1,u2;
  1037. X    int a6_t1;
  1038. X    static unsigned char cpa_data[]={
  1039. X            0x40,0x09,0x31,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x30,
  1040. X            0x86,0x4};
  1041. X    
  1042. X    a6_tend=0x400+length;        /* calc the end of the data */
  1043. X    
  1044. X    cur-=Gen_Lxx(cur,a6_tend-cur);        /* do the LCN */
  1045. X    buff[cur--]=0x04;
  1046. X    a6_t1=cur;
  1047. X    
  1048. X    if(nl)        /* if we know the number of lines */
  1049. X    {
  1050. X        cur-=Gen_Len(cur,nl);        /* do the nl */
  1051. X        buff[cur--]=0x81;
  1052. X    }
  1053. X    
  1054. X    cur-=Gen_Len(cur,pl);        /* do the pl */
  1055. X    buff[cur--]=0x80;
  1056. X    
  1057. X    buff[cur--]=cp;        /* do the compression */
  1058. X    buff[cur--]=0x1;
  1059. X    buff[cur--]=0x82;
  1060. X    
  1061. X    cur-=Gen_Lxx(cur,a6_t1-cur);        /* do the LRC */
  1062. X    buff[cur--]=0xa2;
  1063. X    
  1064. X    for(i=3;i>=0;i--)
  1065. X    {
  1066. X        buff[cur--]=c1[i];
  1067. X    }
  1068. X    
  1069. X    for(i=sizeof(cpa_data)-1;i>=0;i--)
  1070. X    {
  1071. X        buff[cur--]=cpa_data[i];
  1072. X    }
  1073. X    
  1074. X    cur-=Gen_Lxx(cur,a6_t1-cur);        /* do the LCA */
  1075. X    buff[cur--]=0x31;
  1076. X    
  1077. X    cur-=Gen_Lxx(cur,a6_tend-cur);        /* do the LA6*/
  1078. X    buff[cur--]=0xa3;
  1079. X    
  1080. X    i=fwrite(&buff[cur+1],1,a6_end-cur,fout);
  1081. X    if(i!=a6_end-cur)
  1082. X        return(1);
  1083. X    
  1084. X    u1=fread(buff,1,0x8000,fin);
  1085. X    while(u1>0)
  1086. X    {
  1087. X        
  1088. X        u2=fwrite(buff,1,u1,fout);
  1089. X        if(u2!=u1)
  1090. X            return(2);
  1091. X        u1=fread(buff,1,0x8000,fin);
  1092. X    }
  1093. X    return(0);
  1094. X}
  1095. XDo_A6i()
  1096. X{
  1097. X    int a6_end=0x400;
  1098. X    int cur=0x400;
  1099. X    int i;
  1100. X    unsigned int u1,u2;
  1101. X    int a6_t1;
  1102. X    static unsigned char cpa_data[]={
  1103. X            0x40,0x09,0x31,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x30,
  1104. X            0x86,0x4};
  1105. X    
  1106. X    buff[cur--]=0x80;
  1107. X    buff[cur--]=0x04;
  1108. X    a6_t1=cur;
  1109. X    
  1110. X    if(nl)        /* if we know the number of lines */
  1111. X    {
  1112. X        cur-=Gen_Len(cur,nl);        /* do the nl */
  1113. X        buff[cur--]=0x81;
  1114. X    }
  1115. X    
  1116. X    cur-=Gen_Len(cur,pl);        /* do the pl */
  1117. X    buff[cur--]=0x80;
  1118. X    
  1119. X    buff[cur--]=cp;        /* do the compression */
  1120. X    buff[cur--]=0x1;
  1121. X    buff[cur--]=0x82;
  1122. X    
  1123. X    cur-=Gen_Lxx(cur,a6_t1-cur);        /* do the LRC */
  1124. X    buff[cur--]=0xa2;
  1125. X    
  1126. X    for(i=3;i>=0;i--)
  1127. X    {
  1128. X        buff[cur--]=c1[i];
  1129. X    }
  1130. X    
  1131. X    for(i=sizeof(cpa_data)-1;i>=0;i--)
  1132. X    {
  1133. X        buff[cur--]=cpa_data[i];
  1134. X    }
  1135. X    
  1136. X    cur-=Gen_Lxx(cur,a6_t1-cur);        /* do the LCA */
  1137. X    buff[cur--]=0x31;
  1138. X    
  1139. X    buff[cur--]=0x80;
  1140. X    buff[cur--]=0xa3;
  1141. X    
  1142. X    i=fwrite(&buff[cur+1],1,a6_end-cur,fout);
  1143. X    if(i!=a6_end-cur)
  1144. X        return(1);
  1145. X    
  1146. X    u1=fread(buff,1,0x8000,fin);
  1147. X    while(u1>0)
  1148. X    {
  1149. X        
  1150. X        u2=fwrite(buff,1,u1,fout);
  1151. X        if(u2!=u1)
  1152. X            return(2);
  1153. X        u1=fread(buff,1,0x8000,fin);
  1154. X    }
  1155. X    for(i=0;i<4;buff[i++]=0);
  1156. X    u2=fwrite(buff,1,4,fout);
  1157. X    if(u2!=4)
  1158. X        return(3);
  1159. X    
  1160. X    return(0);
  1161. X}
  1162. X
  1163. X    
  1164. X    
  1165. X    
  1166. X
  1167. END_OF_FILE
  1168.   if test 24691 -ne `wc -c <'a11_new.c'`; then
  1169.     echo shar: \"'a11_new.c'\" unpacked with wrong size!
  1170.   fi
  1171.   # end of 'a11_new.c'
  1172. fi
  1173. if test -f 'e5.ctl' -a "${1}" != "-c" ; then 
  1174.   echo shar: Will not clobber existing file \"'e5.ctl'\"
  1175. else
  1176.   echo shar: Extracting \"'e5.ctl'\" \(229 characters\)
  1177.   sed "s/^X//" >'e5.ctl' <<'END_OF_FILE'
  1178. Xinfile=annexe.dta
  1179. Xoutfile=e5.a11
  1180. Xlength=31f8
  1181. Xc4=03
  1182. Xcp=01
  1183. Xlp=03
  1184. Xpp=00
  1185. Xps=01
  1186. Xrl=01
  1187. Xrp=01
  1188. Xsl=04
  1189. Xstring=Example for Annex E.5 of ANSI/AIIM MS53 199X~
  1190. X
  1191. Xdh=27d8
  1192. Xdv=41a0
  1193. Xfx=0
  1194. Xfy=0
  1195. Xhp=27d8
  1196. Xnl=af0
  1197. Xph=0
  1198. Xpl=6c0
  1199. Xpv=0
  1200. Xsx=27d8
  1201. Xsy=3390
  1202. Xvp=41a0
  1203. END_OF_FILE
  1204.   if test 229 -ne `wc -c <'e5.ctl'`; then
  1205.     echo shar: \"'e5.ctl'\" unpacked with wrong size!
  1206.   fi
  1207.   # end of 'e5.ctl'
  1208. fi
  1209. if test -f 'gen_a11.c' -a "${1}" != "-c" ; then 
  1210.   echo shar: Will not clobber existing file \"'gen_a11.c'\"
  1211. else
  1212.   echo shar: Extracting \"'gen_a11.c'\" \(23635 characters\)
  1213.   sed "s/^X//" >'gen_a11.c' <<'END_OF_FILE'
  1214. X/* This program was written by Mike Fleischmann of Optical Publishing, Inc.
  1215. X    Copyright 1993 Optical Publishing, Inc. All rights reserved.
  1216. X    Redistribution and use in source and binary form are freely permitted
  1217. X    provided that the above copyright notice appears in all documentation.
  1218. X    
  1219. X    THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESSED OR IMPLIED
  1220. X    WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 
  1221. X    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. By installing this 
  1222. X    software, you agree to hold Optical Publishing, Inc. harmless for any 
  1223. X    damages resulting from the use of this software.
  1224. X*/
  1225. X
  1226. X/* The program was copyrighted to allow you to know the source of the code. 
  1227. X    This way if you need to contact us, you at least know the company name.
  1228. X    We are in based in Ft. Collins, Colorado at (303)-226-3466.
  1229. X    Our intention is to allow you to use, modify, copy and redistribute this
  1230. X    code as well as integrate it into your applications at no charge or 
  1231. X    royalties of any kind. Our only request is that if you use sections of 
  1232. X    this code in your products, you include a 'Portions Copyright 1993 Optical
  1233. X    Publishing, Inc. All rights reserved.' in your documentation. That's it, 
  1234. X    we want to make this standard as easy to use as possible and giving away
  1235. X    working code seemed the best way to do it.
  1236. X*/
  1237. X
  1238. X/* although this program was developed to generate the examples in appendix
  1239. X    E of the ANSI/AIIM MS53-199x standard it would work as a primitive 
  1240. X    import routine. This program should compile with either Borland C or 
  1241. X    Microsoft C. The tab spacing was set to 4.
  1242. X    
  1243. X    This was not written to be the most efficient code but rather as a  
  1244. X    demo of the A11 standard encoding. Also, there is minimal error checking
  1245. X    a full implementation would have extensive error checking.
  1246. X
  1247. X
  1248. X    The program's calling parameters are GEN_A11 filename.ext where
  1249. X        filename.ext is the name of the control file.
  1250. X    The control file is in the format keyword=value. All values are in HEX!!
  1251. X    NOTE: all the keywords are not necessary if you are excluding the area
  1252. X    where they are used. i.e. clipping.
  1253. X
  1254. X    keywords are (case insensitive):
  1255. X        infile        the input image file
  1256. X        outfile        the output image file name. (an extension .A11 is suggested)
  1257. X        length        the length of the data file
  1258. X        c4            the last digit in the c1 c2 c3 c4 encoding string
  1259. X        cp            the compression flag
  1260. X        lp            the line progression 
  1261. X        pp            the pel path
  1262. X        ps            the pel spaces value
  1263. X        rl            the raster ratio for line spacing
  1264. X        rp            the raster ratio for pel spacing
  1265. X        sl            the spacing length
  1266. X        string        the user string. (note this can span lines needs to be 
  1267. X                    ended with the tilda (~) character.
  1268. X        dh            horizontal block dimensions
  1269. X        dv            vertical block dimensions
  1270. X        fx            first X clipping coord in BMUs
  1271. X        fy            first Y clipping coord in BMUs
  1272. X        hp            horizontal page dimensions in BMUs
  1273. X        nl            number of lines (if known)
  1274. X        ph            horizontal starting position in BMUs
  1275. X        pl            number of pels per line
  1276. X        pv            vertical starting position in BMUs 
  1277. X        sx            second X clipping coord in BMUs
  1278. X        sy            secong Y clipping coord in BMUs
  1279. X        vp            vertical page dimensions in BMUs
  1280. X*/
  1281. X
  1282. X#include <stdio.h>
  1283. X#include <string.h>
  1284. X#include <stdlib.h>
  1285. X#include <ctype.h>
  1286. X
  1287. X#define LEN_A1_NARY 60
  1288. X#define LEN_A2 15
  1289. X#define LEN_A3_NARY 18
  1290. X#define LEN_A4 19
  1291. X
  1292. Xunsigned char a1_nary[]={    /* fixed portion of a1 */
  1293. X    0x84,0x05,
  1294. X        0x2a,0x86,0x48,0xce,0x1c,
  1295. X    0xa5,0x06,
  1296. X        0x06,0x04,
  1297. X            0x58,0x02,0x07,0x02,
  1298. X        0x86,0x01,
  1299. X            0x00,
  1300. X        0xa8,0x16,
  1301. X            0x43,0x08,
  1302. X                0x49,0x53,0x4f,0x20,0x38,0x36,0x31,0x33,
  1303. X            0x44,0x0a,
  1304. X                0x31,0x39,0x39,0x31,0x2d,0x31,0x32,0x2d,0x33,0x31,
  1305. X        0xaa,0x10,
  1306. X            0xa0,0x0e,
  1307. X                0x80,0x04,
  1308. X                    0x58,0x02,0x07,0x02,
  1309. X                0xaa,0x06,
  1310. X                    0x86,0x04,
  1311. X                        0x58,0x03,0x07,0x06
  1312. X    };
  1313. X
  1314. Xunsigned char a2[]={        /* The document layout root  fixed content */
  1315. X                    0xa2,0x0d,
  1316. X                        0x02,0x01,
  1317. X                            0x00,
  1318. X                        0x31,0x08,
  1319. X                            0x41,0x01,
  1320. X                                0x31,
  1321. X                            0xa0,0x03,
  1322. X                                0x12,0x01,
  1323. X                                    0x30
  1324. X                    };
  1325. X
  1326. Xunsigned char a3_nary[]={    /* fixed portion of a3 */
  1327. X        0x41,0x03,
  1328. X            0x31,0x20,0x30,
  1329. X        0xa0,0x03,
  1330. X            0x12,0x01,
  1331. X                0x30,
  1332. X            0xaf,0x06,
  1333. X                0x80,0x01,
  1334. X                    0x00,
  1335. X                0x80,0x01,
  1336. X                    0x00
  1337. X    };
  1338. X
  1339. Xunsigned char a4[]={        /* The document layout root  fixed content */
  1340. X                    0xa2,0x11,
  1341. X                        0x02,0x01,
  1342. X                            0x03,
  1343. X                        0x31,0x0c,
  1344. X                            0x41,0x05,
  1345. X                                0x31,0x20,0x30,0x20,0x30,
  1346. X                            0xa0,0x03,
  1347. X                                0x12,0x01,
  1348. X                                    0x30
  1349. X                    };
  1350. X
  1351. Xunsigned char c1[]={0x58,0x03,0x07,0xff};    /* the c1c2c3c4 param */
  1352. Xunsigned char cp=0xff;        /* compression set to invalid value */
  1353. Xunsigned char lp=0xff;        /* line progression set to invalid value */
  1354. Xunsigned char pp=0xff;        /* pel path set to invalid character */
  1355. Xunsigned char ps=0;    /* pel spaces (invalid value)*/
  1356. Xunsigned char rl=0;    /* raster ratio line spacing (invalid value) */
  1357. Xunsigned char rp=0;    /* raster ratio pel spacing (invalid value) */
  1358. Xunsigned char sl=0;    /* spacing length (invalid value) */
  1359. Xchar str1[510];            /* the variable length string. (512 bytes max) */
  1360. X
  1361. Xlong dh=0;                /* horizontal block dimensions in BMUs */
  1362. Xlong dv=0;                /* vertical block dimensions in BMUs */
  1363. Xlong fx=0;                /* first x clipping coord in BMUs */
  1364. Xlong fy=0;                /* first y clipping coord in BMUs */
  1365. Xlong hp=0;                /* horizontal page dimensions in BMU's */
  1366. Xlong nl=0;                /* number of lines */
  1367. Xlong ph=0;                /* horizontal starting position in BMUs */
  1368. Xlong pl=0;                /* number of pels per line */
  1369. Xlong pv=0;                /* vertical starting position */
  1370. Xlong sx=0;                /* second X clipping coord in BMUs */
  1371. Xlong sy=0;                /* second Y clipping coord in BMUs */
  1372. Xlong vp=0;                /* vertical page dimensions in BMUs */
  1373. X
  1374. Xlong length=0;            /* length of the input data file */
  1375. X
  1376. XFILE *fin;                /* handle for the input image file */
  1377. XFILE *fout;                /* handle for the output A11 file */
  1378. XFILE *ctrl;                /* the file handle for the control file */
  1379. X
  1380. Xunsigned char buff[0x8000];        /* work buffer */
  1381. Xunsigned char line[0x200];        /* line entry buffer */
  1382. X
  1383. Xchar *keyword[]={
  1384. X    "INFILE",
  1385. X    "OUTFILE",
  1386. X    "LENGTH",
  1387. X    "C4",
  1388. X    "CP",
  1389. X    "LP",
  1390. X    "PP",
  1391. X    "PS",
  1392. X    "RL",
  1393. X    "RP",
  1394. X    "SL",
  1395. X    "STRING",
  1396. X    "DH",
  1397. X    "DV",
  1398. X    "FX",
  1399. X    "FY",
  1400. X    "HP",
  1401. X    "NL",
  1402. X    "PH",
  1403. X    "PL",
  1404. X    "PV",
  1405. X    "SX",
  1406. X    "SY",
  1407. X    "VP",
  1408. X    "~~~"};        /* mark as the end */
  1409. X
  1410. X#define INFILE 0
  1411. X#define OUTFILE 1
  1412. X#define LENGTH 2 
  1413. X#define C4 3 
  1414. X#define CP 4 
  1415. X#define LP 5
  1416. X#define PP 6
  1417. X#define PS 7
  1418. X#define RL 8
  1419. X#define RP 9 
  1420. X#define SL 10
  1421. X#define STRING 11
  1422. X#define DH 12
  1423. X#define DV 13
  1424. X#define FX 14
  1425. X#define FY 15
  1426. X#define HP 16
  1427. X#define NL 17
  1428. X#define PH 18
  1429. X#define PL 19
  1430. X#define PV 20
  1431. X#define SX 21
  1432. X#define SY 22
  1433. X#define VP 23
  1434. X
  1435. X
  1436. Xvoid Get_Line(void);
  1437. Xint Char2val(int);
  1438. Xlong Get_Hex(char *);
  1439. XRead_Control(void);
  1440. XDo_In_Fun(int,char *);
  1441. Xint Gen_Lxx(int,unsigned long);        /* gen the format lxx table 5*/
  1442. Xint Gen_Len(int,unsigned long);        /* gen the format lxx table 4*/
  1443. XDo_A1(void);        /* this and the following will build the data from
  1444. X                    the end
  1445. X                    */ 
  1446. XDo_A3(void);
  1447. XDo_A5c(void);
  1448. XDo_A5(int,int);        /* first int is current, second int is scpe loc */
  1449. XDo_A6d(void);
  1450. XDo_A6i(void);
  1451. X
  1452. X
  1453. X
  1454. Xint main(argc,argv)
  1455. Xint argc;
  1456. Xchar *argv[];
  1457. X{
  1458. X    int rtn;        /* used for function return checking */
  1459. X
  1460. X    str1[0]=' ';    /* guarentee at least a comment */
  1461. X    str1[1]=0;    /* guarentee at least a comment */
  1462. X    if(argc<2)
  1463. X    {
  1464. X        printf("calling parameters are GEN_A11 ctrlfile.ext\n");
  1465. X        printf(" where ctrlfile.ext is the controll file. See source code for\n");
  1466. X        printf(" more information\n");
  1467. X        exit(0);
  1468. X    }
  1469. X    
  1470. X    ctrl=fopen(argv[1],"r");
  1471. X    if(ctrl==NULL)
  1472. X    {
  1473. X        printf("unable to open the controll file >%s<\n",argv[1]);
  1474. X        exit(0);
  1475. X    }
  1476. X    
  1477. X    rtn=Read_Control();            /* read the control file in */
  1478. X    if(rtn)        /* if an error */
  1479. X    {
  1480. X        printf("error reading controll file. Program ending\n");
  1481. X        exit(0);
  1482. X    }
  1483. X    rtn=Do_A1();        /* go and do the a.1 table */
  1484. X    if(rtn)        /* if an error */
  1485. X    {
  1486. X        printf("error in generation of the A.1 header table. Program ending\n");
  1487. X        exit(0);
  1488. X    }
  1489. X
  1490. X    rtn=fwrite(a2,1,LEN_A2,fout);        /* output the a2 table */
  1491. X    if(rtn!=LEN_A2)        /* if an error */
  1492. X    {
  1493. X        printf("error in writing A.2 table. Program ending\n");
  1494. X        exit(0);
  1495. X    }
  1496. X
  1497. X    rtn=Do_A3();        /* go and do the a.3 table */
  1498. X    if(rtn)        /* if an error */
  1499. X    {
  1500. X        printf("error in generation of the A.3 header table. Program ending\n");
  1501. X        exit(0);
  1502. X    }
  1503. X
  1504. X    rtn=fwrite(a4,1,LEN_A4,fout);        /* output the a4 table */
  1505. X    if(rtn!=LEN_A4)        /* if an error */
  1506. X    {
  1507. X        printf("error in writing A.4 table. Program ending\n");
  1508. X        exit(0);
  1509. X    }
  1510. X
  1511. X    if(fx!=0 || fy!=0 || sx!=0 || sy!=0)
  1512. X    {
  1513. X        /* if here we have clipping */
  1514. X        rtn=Do_A5c();        /* go and do the a.5 table for clipping */
  1515. X        if(rtn)        /* if an error */
  1516. X        {
  1517. X            printf("error in generation of the A.51 header table. Program ending\n");
  1518. X            exit(0);
  1519. X        }
  1520. X    }
  1521. X    else
  1522. X    {
  1523. X        rtn=Do_A5(0x400,0x400);        /* go and do the a.5 table for no clipping*/
  1524. X        if(rtn)        /* if an error */
  1525. X        {
  1526. X            printf("error in generation of the A.3 header table. Program ending\n");
  1527. X            exit(0);
  1528. X        }
  1529. X    }
  1530. X
  1531. X    if(length>0)        /* definite length */
  1532. X    {
  1533. X        rtn=Do_A6d();        /* go and do the a.6 table */
  1534. X        if(rtn)        /* if an error */
  1535. X        {
  1536. X            printf("error in generation of the A.6 table. Program ending\n");
  1537. X            exit(0);
  1538. X        }
  1539. X    }
  1540. X    else    /* indefinite length */
  1541. X    {
  1542. X        rtn=Do_A6i();        /* go and do the a.6 table */
  1543. X        if(rtn)        /* if an error */
  1544. X        {
  1545. X            printf("error in generation of the A.6 table. Program ending\n");
  1546. X            exit(0);
  1547. X        }
  1548. X    }
  1549. X
  1550. X    fclose(fout);
  1551. X    fclose(fin);
  1552. X    fclose(ctrl);
  1553. X    printf("File build finished\n");
  1554. X    return(0);
  1555. X}
  1556. X
  1557. Xvoid Get_Line()
  1558. X{
  1559. X    int i;        /* temp work variable */
  1560. X
  1561. X    fgets(line,0x200,ctrl);
  1562. X    i=strlen(line);
  1563. X    for(i--;i>0 && line[i]<=' ';line[i--]=0) ;  /* remove trailing crlf */
  1564. X    
  1565. X    /* turn to uppercase */
  1566. X    for(i=0;line[i] && line[i]!='=';line[i]=toupper(line[i]),i++);
  1567. X    if(memcmp(line,"STRING",6)!=0)    /* skip string case */
  1568. X        for(;line[i];line[i]=toupper(line[i]),i++);
  1569. X
  1570. X}
  1571. X
  1572. Xint Char2val(ch)
  1573. Xint ch;
  1574. X{
  1575. X    if(ch<='9')
  1576. X        ch-='0';
  1577. X    else
  1578. X        ch = ch-'A'+10;
  1579. X    return(ch);
  1580. X}
  1581. X
  1582. Xlong Get_Hex(str)
  1583. Xchar *str;
  1584. X{
  1585. X    long l1;
  1586. X    int i;
  1587. X    
  1588. X    for(i=0;str[i]<=' ' && str[i];i++);    /* ignore leading white space */
  1589. X
  1590. X    for(i=0,l1=0;isxdigit(str[i]);i++)
  1591. X    {
  1592. X        l1<<=4;
  1593. X        l1+=(long)Char2val(str[i]);
  1594. X    }
  1595. X    return(l1);
  1596. X}
  1597. X
  1598. XRead_Control()
  1599. X{
  1600. X    /* this will read in the control file and initialize the variables */
  1601. X    char *cptr,*cptr1;        /* temp char pointer used for parsing */
  1602. X    int i,j,k;
  1603. X    
  1604. X    Get_Line();        /* input the line */
  1605. X    while(!feof(ctrl))
  1606. X    {
  1607. X        cptr=line;
  1608. X        while(cptr[0]==' ')        /* skip leading spaces */
  1609. X            cptr++;
  1610. X        cptr1=strchr(cptr,'=');
  1611. X        if(cptr1!=NULL)        /* if null treat as comment field */
  1612. X        {
  1613. X            /* if here have something to work with */
  1614. X            cptr1[0]=0;        /* mark end */
  1615. X            cptr1++;
  1616. X            i=strlen(cptr);        /* get the length of compare string  */
  1617. X            for(j=0;keyword[j][0]!='~';j++)
  1618. X            {
  1619. X                if(memcmp(cptr,keyword[j],i)==0)
  1620. X                {
  1621. X                    k=Do_In_Fun(j,cptr1);
  1622. X                    if(k)
  1623. X                        return(k);        /* return if error */
  1624. X                    break;
  1625. X                }
  1626. X            }
  1627. X        }
  1628. X        Get_Line();        /* input the line */
  1629. X    }
  1630. X    return(0);        /* return valid processing */
  1631. X}
  1632. X
  1633. XDo_In_Fun(fun,str)
  1634. Xint fun;        /* the function number to do */
  1635. Xchar *str;        /* the remaining string */
  1636. X{
  1637. X    int i,j;
  1638. X    char *cptr;
  1639. X    
  1640. X    switch(fun)
  1641. X    {
  1642. X        case INFILE:
  1643. X            fin=fopen(str,"rb");        /* open the input image file */
  1644. X            if(fin==NULL)
  1645. X                return(INFILE+1);
  1646. X            break;
  1647. X        case OUTFILE:
  1648. X            fout=fopen(str,"wb");        /* open the output A11 file */
  1649. X            if(fout==NULL)
  1650. X                return(OUTFILE+1);
  1651. X            break;
  1652. X        case LENGTH:
  1653. X            length=Get_Hex(str);        /* get the length */
  1654. X            if(length<1)
  1655. X                return(LENGTH+1);
  1656. X            break;
  1657. X        case C4:
  1658. X            c1[3]=(char)Get_Hex(str);    /* get the c4 character */
  1659. X            if(c1[3]>8)
  1660. X                return(C4+1);
  1661. X            break;
  1662. X        case CP:
  1663. X            cp=(char)Get_Hex(str);    /* get the cp character */
  1664. X            if(cp<0 || cp>1)
  1665. X                return(CP+1);
  1666. X            break;
  1667. X        case LP:
  1668. X            lp=(char)Get_Hex(str);    /* get the lp character */
  1669. X            if(lp!=1 && lp!=3)
  1670. X                return(LP+1);
  1671. X            break;
  1672. X        case PP:
  1673. X            pp=(char)Get_Hex(str);    /* get the pp character */
  1674. X            if(pp<0 || pp>3)
  1675. X                return(PP+1);
  1676. X            break;
  1677. X        case PS:
  1678. X            ps=(char)Get_Hex(str);    /* get the ps character */
  1679. X            if(ps==0)
  1680. X                return(PS+1);
  1681. X            break;
  1682. X        case RL:
  1683. X            rl=(char)Get_Hex(str);    /* get the cp character */
  1684. X            if(rl==0)
  1685. X                return(RL+1);
  1686. X            break;
  1687. X        case RP:
  1688. X            rp=(char)Get_Hex(str);    /* get the cp character */
  1689. X            if(rp==0)
  1690. X                return(RP+1);
  1691. X            break;
  1692. X        case SL:
  1693. X            sl=(char)Get_Hex(str);    /* get the cp character */
  1694. X            if(sl==0)
  1695. X                return(SL+1);
  1696. X            break;
  1697. X        case STRING:
  1698. X            j=0;
  1699. X            cptr=str;
  1700. X            while(1)
  1701. X            {
  1702. X                for(i=0;cptr[i] && cptr[i]!='~' && j<500;i++)
  1703. X                    str1[j++]=cptr[i];
  1704. X                if(j>499 || cptr[i]=='~')    /* done entering string */
  1705. X                    break;
  1706. X                Get_Line();
  1707. X                if(feof(ctrl))
  1708. X                    return(STRING+1);
  1709. X                cptr=line;
  1710. X            }
  1711. X            str1[j++]=0;        /* null terminate */
  1712. X            break;
  1713. X        case DH:
  1714. X            dh=Get_Hex(str);    /* get the dh value */
  1715. X            if(dh<1)
  1716. X                return(DH+1);
  1717. X            break;
  1718. X        case DV:
  1719. X            dv=Get_Hex(str);    /* get the dv value */
  1720. X            if(dv<1)
  1721. X                return(DV+1);
  1722. X            break;
  1723. X        case FX:
  1724. X            fx=Get_Hex(str);    /* get the fx value */
  1725. X            break;
  1726. X        case FY:
  1727. X            fy=Get_Hex(str);    /* get the fy value */
  1728. X            break;
  1729. X        case HP:
  1730. X            hp=Get_Hex(str);    /* get the hp value */
  1731. X            if(hp<1)
  1732. X                return(HP+1);
  1733. X            break;
  1734. X        case NL:
  1735. X            nl=Get_Hex(str);    /* get the nl value */
  1736. X            if(nl<1)
  1737. X                return(NL+1);
  1738. X            break;
  1739. X        case PH:
  1740. X            ph=Get_Hex(str);    /* get the ph value */
  1741. X            if(dh<0)
  1742. X                return(PH+1);
  1743. X            break;
  1744. X        case PL:
  1745. X            pl=Get_Hex(str);    /* get the pl value */
  1746. X            if(pl<1)
  1747. X                return(PL+1);
  1748. X            break;
  1749. X        case PV:
  1750. X            pv=Get_Hex(str);    /* get the pv value */
  1751. X            break;
  1752. X        case SX:
  1753. X            sx=Get_Hex(str);    /* get the sx value */
  1754. X            break;
  1755. X        case SY:
  1756. X            sy=Get_Hex(str);    /* get the sy value */
  1757. X            break;
  1758. X        case VP:
  1759. X            vp=Get_Hex(str);    /* get the vp value */
  1760. X            if(vp<1)
  1761. X                return(VP+1);
  1762. X            break;
  1763. X        default:
  1764. X            return(-1);
  1765. X    }
  1766. X    return(0);
  1767. X}
  1768. X
  1769. Xint Gen_Lxx(cur,val)        /* gen the format table 5 */
  1770. Xint cur;        /* current position in buff */
  1771. Xunsigned long val;        /* value to insert */
  1772. X{
  1773. X    
  1774. X    if(val <0x80L)    /* single byte */
  1775. X    {
  1776. X        buff[cur]=(unsigned char) val & 0xff;
  1777. X        return(1);
  1778. X    }
  1779. X    else if(val <0x100L)    /* single byte */
  1780. X    {
  1781. X        buff[cur]=(unsigned char) val & 0xff;
  1782. X        buff[cur-1]=0x81;
  1783. X        return(2);
  1784. X    }
  1785. X    else if(val <0x10000L)    /* 2 bytes */
  1786. X    {
  1787. X        buff[cur]=(unsigned char) val & 0xff;
  1788. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  1789. X        buff[cur-2]=0x82;
  1790. X        return(3);
  1791. X    }
  1792. X    else if(val <0x1000000L)    /* 3 bytes */
  1793. X    {
  1794. X        buff[cur]=(unsigned char) val & 0xff;
  1795. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  1796. X        buff[cur-2]=(unsigned char) (val>>16) & 0xff;
  1797. X        buff[cur-3]=0x83;
  1798. X        return(4);
  1799. X    }
  1800. X    else    /* 4 bytes */
  1801. X    {
  1802. X        buff[cur]=(unsigned char) val & 0xff;
  1803. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  1804. X        buff[cur-2]=(unsigned char) (val>>16) & 0xff;
  1805. X        buff[cur-3]=(unsigned char) (val>>24) & 0xff;
  1806. X        buff[cur-4]=0x84;
  1807. X        return(5);
  1808. X    }
  1809. X}
  1810. X
  1811. Xint Gen_Len(cur,val)        /* gen the format table 4 */
  1812. Xint cur;        /* current position in buff */
  1813. Xunsigned long val;        /* value to insert */
  1814. X{
  1815. X    
  1816. X    if(val <0x100L)    /* single byte */
  1817. X    {
  1818. X        buff[cur]=(unsigned char) val & 0xff;
  1819. X        buff[cur-1]=1;
  1820. X        return(2);
  1821. X    }
  1822. X    else if(val <0x10000L)    /* 2 bytes */
  1823. X    {
  1824. X        buff[cur]=(unsigned char) val & 0xff;
  1825. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  1826. X        buff[cur-2]=2;
  1827. X        return(3);
  1828. X    }
  1829. X    else if(val <0x1000000L)    /* 3 bytes */
  1830. X    {
  1831. X        buff[cur]=(unsigned char) val & 0xff;
  1832. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  1833. X        buff[cur-2]=(unsigned char) (val>>16) & 0xff;
  1834. X        buff[cur-3]=3;
  1835. X        return(4);
  1836. X    }
  1837. X    else    /* 4 bytes */
  1838. X    {
  1839. X        buff[cur]=(unsigned char) val & 0xff;
  1840. X        buff[cur-1]=(unsigned char) (val>>8) & 0xff;
  1841. X        buff[cur-2]=(unsigned char) (val>>16) & 0xff;
  1842. X        buff[cur-3]=(unsigned char) (val>>24) & 0xff;
  1843. X        buff[cur-4]=4;
  1844. X        return(5);
  1845. X    }
  1846. X}
  1847. X
  1848. XDo_A1()        /* this and the following will build the data from the end 
  1849. X            towards the front */
  1850. X{
  1851. X    int a1_end=0x400;
  1852. X    int cur=0x400;
  1853. X    int dend;
  1854. X    int nend;
  1855. X    int pt8;
  1856. X    int pt7;
  1857. X    int pt3;
  1858. X    int i;
  1859. X    
  1860. X    i=strlen(str1);
  1861. X    i--;
  1862. X    while(i>=0)        /* copy the users string */
  1863. X    {
  1864. X        buff[cur--]=str1[i--];
  1865. X    }
  1866. X
  1867. X    cur-=Gen_Lxx(cur,a1_end-cur);        /* do the LDR section */
  1868. X    buff[cur--]=0x43;
  1869. X    
  1870. X    cur-=Gen_Lxx(cur,a1_end-cur);        /* do the LD3 section */
  1871. X    buff[cur--]=0xa5;
  1872. X    
  1873. X    cur-=Gen_Lxx(cur,a1_end-cur);        /* do the LD2 section */
  1874. X    buff[cur--]=0xa7;
  1875. X    
  1876. X    cur-=Gen_Lxx(cur,a1_end-cur);        /* do the LD1 section */
  1877. X    buff[cur--]=0xa3;
  1878. X    dend=cur;        /* mark the current position */
  1879. X    
  1880. X    i=LEN_A1_NARY;
  1881. X    i--;
  1882. X    while(i>=0)        /* copy the fixed array stuff */
  1883. X    {
  1884. X        buff[cur--]=a1_nary[i--];
  1885. X    }
  1886. X    nend=cur;        /* mark position of a1_end byte */
  1887. X    
  1888. X    buff[cur--]=ps;
  1889. X    buff[cur--]=1;
  1890. X    buff[cur--]=2;
  1891. X
  1892. X    buff[cur--]=sl;
  1893. X    buff[cur--]=1;
  1894. X    buff[cur--]=2;
  1895. X    buff[cur--]=6;
  1896. X    buff[cur--]=0xa0;
  1897. X    buff[cur--]=8;
  1898. X    buff[cur--]=0xa5;
  1899. X    
  1900. X    buff[cur--]=lp;
  1901. X    buff[cur--]=1;
  1902. X    buff[cur--]=0x8a;
  1903. X    
  1904. X    buff[cur--]=pp;
  1905. X    buff[cur--]=1;
  1906. X    buff[cur--]=0x89;
  1907. X    buff[cur--]=0x10;
  1908. X    buff[cur--]=0xa4;
  1909. X    
  1910. X    buff[cur--]=cp;
  1911. X    buff[cur--]=1;
  1912. X    buff[cur--]=0x80;
  1913. X    buff[cur--]=3;
  1914. X    buff[cur--]=0xa3;
  1915. X
  1916. X    pt8=cur;
  1917. X    buff[cur--]=0;
  1918. X    buff[cur--]=1;
  1919. X    buff[cur--]=2;
  1920. X    pt7=cur;
  1921. X    
  1922. X    cur-=Gen_Len(cur,vp);        /* do the vp */
  1923. X    buff[cur--]=0x80;
  1924. X
  1925. X    cur-=Gen_Len(cur,hp);        /* do the hp */
  1926. X    buff[cur--]=0x80;
  1927. X
  1928. X    cur-=Gen_Lxx(cur,pt7-cur);        /* do the L13 */
  1929. X    buff[cur--]=0x30;
  1930. X    
  1931. X    cur-=Gen_Lxx(cur,pt8-cur);        /* do the LNP */
  1932. X    buff[cur--]=0x30;
  1933. X    
  1934. X    cur-=Gen_Lxx(cur,pt8-cur);        /* do the LMT */
  1935. X    buff[cur--]=0xa8;
  1936. X    pt3=cur;
  1937. X    
  1938. X    cur-=Gen_Len(cur,vp);        /* do the vp */
  1939. X    buff[cur--]=0x80;
  1940. X
  1941. X    cur-=Gen_Len(cur,hp);        /* do the hp */
  1942. X    buff[cur--]=0x80;
  1943. X
  1944. X    cur-=Gen_Lxx(cur,pt3-cur);        /* do the L12 */
  1945. X    buff[cur--]=0x30;
  1946. X    
  1947. X    cur-=Gen_Lxx(cur,pt3-cur);        /* do the L11 */
  1948. X    buff[cur--]=0xa2;
  1949. X    
  1950. X    cur-=Gen_Lxx(cur,nend-cur);        /* do the LND */
  1951. X    buff[cur--]=0xa2;
  1952. X    buff[cur--]=0x00;
  1953. X    buff[cur--]=0x01;
  1954. X    buff[cur--]=0x81;
  1955. X    
  1956. X    cur-=Gen_Lxx(cur,dend-cur);        /* do the LDC*/
  1957. X    buff[cur--]=0xa2;
  1958. X    buff[cur--]=0x31;
  1959. X    buff[cur--]=0x01;
  1960. X    buff[cur--]=0x81;
  1961. X    
  1962. X    cur-=Gen_Lxx(cur,a1_end-cur);        /* do the LDP*/
  1963. X    buff[cur--]=0xa0;
  1964. X    
  1965. X    i=fwrite(&buff[cur+1],1,a1_end-cur,fout);
  1966. X    if(i!=a1_end-cur)
  1967. X        return(1);
  1968. X    return(0);
  1969. X}
  1970. X
  1971. XDo_A3()
  1972. X{
  1973. X    int a3_end=0x400;
  1974. X    int cur=0x400;
  1975. X    int a3_nend;
  1976. X    int a3_mt;
  1977. X    int a3_nps;
  1978. X    int a3_pde;
  1979. X    int a3_pds;
  1980. X    int a3_body;
  1981. X    int a3_start;
  1982. X    int i;
  1983. X    
  1984. X    buff[cur--]=0;
  1985. X    buff[cur--]=1;
  1986. X    buff[cur--]=2;
  1987. X    a3_nend=cur;
  1988. X    
  1989. X    cur-=Gen_Len(cur,vp);        /* do the vp */
  1990. X    buff[cur--]=0x80;
  1991. X
  1992. X    cur-=Gen_Len(cur,hp);        /* do the hp */
  1993. X    buff[cur--]=0x80;
  1994. X    a3_nps=cur;
  1995. X
  1996. X    cur-=Gen_Lxx(cur,a3_nend-a3_nps);        /* do the LN3 */
  1997. X    buff[cur--]=0x30;
  1998. X    a3_mt=cur;
  1999. X    
  2000. X    cur-=Gen_Lxx(cur,a3_end-a3_mt);        /* do the LM3 */
  2001. X    buff[cur--]=0xb0;
  2002. X    a3_pde=cur;
  2003. X    
  2004. X    cur-=Gen_Len(cur,vp);        /* do the vp */
  2005. X    buff[cur--]=0x80;
  2006. X
  2007. X    cur-=Gen_Len(cur,hp);        /* do the hp */
  2008. X    buff[cur--]=0x80;
  2009. X    a3_pds=cur;
  2010. X
  2011. X    cur-=Gen_Lxx(cur,a3_pde-a3_pds);        /* do the LPD */
  2012. X    buff[cur--]=0xa4;
  2013. X
  2014. X    i=LEN_A3_NARY;
  2015. X    i--;
  2016. X    while(i>=0)        /* copy the fixed array stuff */
  2017. X    {
  2018. X        buff[cur--]=a3_nary[i--];
  2019. X    }
  2020. X    a3_body=cur;        /* mark position */
  2021. X    cur-=Gen_Lxx(cur,a3_end-a3_body);        /* do the LAB */
  2022. X    buff[cur--]=0x31;
  2023. X    buff[cur--]=0x02;
  2024. X    buff[cur--]=0x01;
  2025. X    buff[cur--]=0x02;
  2026. X
  2027. X
  2028. X    a3_start=cur;        /* mark position of a1_end byte */
  2029. X
  2030. X    cur-=Gen_Lxx(cur,a3_end-a3_start);        /* do the LA3 */
  2031. X    buff[cur--]=0xa2;
  2032. X
  2033. X    i=fwrite(&buff[cur+1],1,a3_end-cur,fout);
  2034. X    if(i!=a3_end-cur)
  2035. X        return(1);
  2036. X    return(0);
  2037. X}
  2038. X
  2039. XDo_A5c()
  2040. X{
  2041. X    int a5_end=0x400;
  2042. X    int cur=0x400;
  2043. X    int a5_dime;
  2044. X    int a5_scpe;
  2045. X    int a5_fcpe;
  2046. X    
  2047. X    
  2048. X    if(nl<1)        /* if we don't know the number of lines (required for clp)*/
  2049. X    {
  2050. X        return(1);        /* return the error */
  2051. X    }
  2052. X
  2053. X    cur-=Gen_Len(cur,pv);        /* do the pv */
  2054. X    buff[cur--]=0x80;
  2055. X
  2056. X    cur-=Gen_Len(cur,ph);        /* do the ph */
  2057. X    buff[cur--]=0x80;
  2058. X
  2059. X    cur-=Gen_Lxx(cur,a5_end-cur);        /* do the LPS */
  2060. X    buff[cur--]=0xa3;
  2061. X    a5_dime=cur;
  2062. X
  2063. X    cur-=Gen_Len(cur,dv);        /* do the dv */
  2064. X    buff[cur--]=0x80;
  2065. X
  2066. X    cur-=Gen_Len(cur,dh);        /* do the dh */
  2067. X    buff[cur--]=0x80;
  2068. X
  2069. X    cur-=Gen_Lxx(cur,a5_dime-cur);        /* do the LDM */
  2070. X    buff[cur--]=0xa4;
  2071. X    a5_scpe=cur;
  2072. X
  2073. X    cur-=Gen_Len(cur,sy);        /* do the sy */
  2074. X    buff[cur--]=0x2;
  2075. X
  2076. X    cur-=Gen_Len(cur,sx);        /* do the sx */
  2077. X    buff[cur--]=0x2;
  2078. X
  2079. X    cur-=Gen_Lxx(cur,a5_scpe-cur);        /* do the LSP */
  2080. X    buff[cur--]=0xa1;
  2081. X    a5_fcpe=cur;
  2082. X
  2083. X    cur-=Gen_Len(cur,fy);        /* do the fy */
  2084. X    buff[cur--]=0x2;
  2085. X
  2086. X    cur-=Gen_Len(cur,fx);        /* do the fx */
  2087. X    buff[cur--]=0x2;
  2088. X
  2089. X    cur-=Gen_Lxx(cur,a5_fcpe-cur);        /* do the LFP */
  2090. X    buff[cur--]=0xa0;
  2091. X
  2092. X    cur-=Gen_Lxx(cur,a5_scpe-cur);        /* do the LFP */
  2093. X    buff[cur--]=0xa4;
  2094. X
  2095. X    return(Do_A5(cur,a5_scpe));
  2096. X}
  2097. X
  2098. XDo_A5(cur,a5_scpe)
  2099. Xint    cur;            /* current position in the buffer */
  2100. Xint a5_scpe;        /* scpe position in the buffer */
  2101. X{
  2102. X    int i;
  2103. X    int a5_end=0x400;
  2104. X    static char pa_data[]={6,4,0x58,2,7,2};
  2105. X    static unsigned char db_data[]={
  2106. X                            0x41,7,0x31,0x20,0x30,0x20,0x30,0x20,0x30,
  2107. X                            0xa1,3,0x12,1,0x30
  2108. X                        };
  2109. X    
  2110. X    buff[cur--]=rp;            /* pel spacing ratio */
  2111. X    buff[cur--]=0x1;
  2112. X    buff[cur--]=0x2;
  2113. X    
  2114. X    buff[cur--]=rl;            /* pel spacing ratio */
  2115. X    buff[cur--]=0x1;
  2116. X    buff[cur--]=0x2;
  2117. X    
  2118. X    buff[cur--]=0x6;
  2119. X    buff[cur--]=0xa6;
  2120. X    
  2121. X    buff[cur--]=ps;            /* pel spaces */
  2122. X    buff[cur--]=0x1;
  2123. X    buff[cur--]=0x2;
  2124. X    
  2125. X    buff[cur--]=sl;            /* spacing length */
  2126. X    buff[cur--]=0x1;
  2127. X    buff[cur--]=0x2;
  2128. X    
  2129. X    buff[cur--]=0x6;
  2130. X    buff[cur--]=0xa0;
  2131. X    
  2132. X    buff[cur--]=0x8;        /* pel spacing */
  2133. X    buff[cur--]=0xa5;
  2134. X    
  2135. X    buff[cur--]=lp;            /* line progression */
  2136. X    buff[cur--]=0x1;
  2137. X    buff[cur--]=0x81;
  2138. X    
  2139. X    buff[cur--]=pp;            /* pel path */
  2140. X    buff[cur--]=0x1;
  2141. X    buff[cur--]=0x80;
  2142. X    
  2143. X    cur-=Gen_Lxx(cur,a5_scpe-cur);        /* do the LRG */
  2144. X    buff[cur--]=0xa1;
  2145. X
  2146. X    for(i=sizeof(pa_data)-1;i>=0;i--)
  2147. X    {
  2148. X        buff[cur--]=pa_data[i];
  2149. X    }
  2150. X    
  2151. X    cur-=Gen_Lxx(cur,a5_scpe-cur);        /* do the LPA */
  2152. X    buff[cur--]=0xa6;
  2153. X
  2154. X    for(i=sizeof(db_data)-1;i>=0;i--)
  2155. X    {
  2156. X        buff[cur--]=db_data[i];
  2157. X    }
  2158. X    
  2159. X    cur-=Gen_Lxx(cur,a5_end-cur);        /* do the LDB */
  2160. X    buff[cur--]=0x31;
  2161. X
  2162. X    buff[cur--]=0x4;        /* pel spacing */
  2163. X    buff[cur--]=0x1;        /* pel spacing */
  2164. X    buff[cur--]=0x2;        /* pel spacing */
  2165. X    
  2166. X    cur-=Gen_Lxx(cur,a5_end-cur);        /* do the LDL */
  2167. X    buff[cur--]=0xa2;
  2168. X
  2169. X    i=fwrite(&buff[cur+1],1,a5_end-cur,fout);
  2170. X    if(i!=a5_end-cur)
  2171. X        return(1);
  2172. X    return(0);
  2173. X}
  2174. X
  2175. XDo_A6d()
  2176. X{
  2177. X    int a6_end=0x400;
  2178. X    long a6_tend;
  2179. X    int cur=0x400;
  2180. X    int i;
  2181. X    unsigned int u1,u2;
  2182. X    int a6_t1;
  2183. X    static unsigned char cpa_data[]={
  2184. X            0x40,0x09,0x31,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x30,
  2185. X            0x86,0x4};
  2186. X    
  2187. X    a6_tend=0x400+length;        /* calc the end of the data */
  2188. X    
  2189. X    cur-=Gen_Lxx(cur,a6_tend-cur);        /* do the LCN */
  2190. X    buff[cur--]=0x04;
  2191. X    a6_t1=cur;
  2192. X    
  2193. X    if(nl)        /* if we know the number of lines */
  2194. X    {
  2195. X        cur-=Gen_Len(cur,nl);        /* do the nl */
  2196. X        buff[cur--]=0x81;
  2197. X    }
  2198. X    
  2199. X    cur-=Gen_Len(cur,pl);        /* do the pl */
  2200. X    buff[cur--]=0x80;
  2201. X    
  2202. X    buff[cur--]=cp;        /* do the compression */
  2203. X    buff[cur--]=0x1;
  2204. X    buff[cur--]=0x82;
  2205. X    
  2206. X    cur-=Gen_Lxx(cur,a6_t1-cur);        /* do the LRC */
  2207. X    buff[cur--]=0xa2;
  2208. X    
  2209. X    for(i=3;i>=0;i--)
  2210. X    {
  2211. X        buff[cur--]=c1[i];
  2212. X    }
  2213. X    
  2214. X    for(i=sizeof(cpa_data)-1;i>=0;i--)
  2215. X    {
  2216. X        buff[cur--]=cpa_data[i];
  2217. X    }
  2218. X    
  2219. X    cur-=Gen_Lxx(cur,a6_t1-cur);        /* do the LCA */
  2220. X    buff[cur--]=0x31;
  2221. X    
  2222. X    cur-=Gen_Lxx(cur,a6_tend-cur);        /* do the LA6*/
  2223. X    buff[cur--]=0xa3;
  2224. X    
  2225. X    i=fwrite(&buff[cur+1],1,a6_end-cur,fout);
  2226. X    if(i!=a6_end-cur)
  2227. X        return(1);
  2228. X    
  2229. X    u1=fread(buff,1,0x8000,fin);
  2230. X    while(u1>0)
  2231. X    {
  2232. X        
  2233. X        u2=fwrite(buff,1,u1,fout);
  2234. X        if(u2!=u1)
  2235. X            return(2);
  2236. X        u1=fread(buff,1,0x8000,fin);
  2237. X    }
  2238. X    return(0);
  2239. X}
  2240. XDo_A6i()
  2241. X{
  2242. X    int a6_end=0x400;
  2243. X    int cur=0x400;
  2244. X    int i;
  2245. X    unsigned int u1,u2;
  2246. X    int a6_t1;
  2247. X    static unsigned char cpa_data[]={
  2248. X            0x40,0x09,0x31,0x20,0x30,0x20,0x30,0x20,0x30,0x20,0x30,
  2249. X            0x86,0x4};
  2250. X    
  2251. X    buff[cur--]=0x80;
  2252. X    buff[cur--]=0x04;
  2253. X    a6_t1=cur;
  2254. X    
  2255. X    if(nl)        /* if we know the number of lines */
  2256. X    {
  2257. X        cur-=Gen_Len(cur,nl);        /* do the nl */
  2258. X        buff[cur--]=0x81;
  2259. X    }
  2260. X    
  2261. X    cur-=Gen_Len(cur,pl);        /* do the pl */
  2262. X    buff[cur--]=0x80;
  2263. X    
  2264. X    buff[cur--]=cp;        /* do the compression */
  2265. X    buff[cur--]=0x1;
  2266. X    buff[cur--]=0x82;
  2267. X    
  2268. X    cur-=Gen_Lxx(cur,a6_t1-cur);        /* do the LRC */
  2269. X    buff[cur--]=0xa2;
  2270. X    
  2271. X    for(i=3;i>=0;i--)
  2272. X    {
  2273. X        buff[cur--]=c1[i];
  2274. X    }
  2275. X    
  2276. X    for(i=sizeof(cpa_data)-1;i>=0;i--)
  2277. X    {
  2278. X        buff[cur--]=cpa_data[i];
  2279. X    }
  2280. X    
  2281. X    cur-=Gen_Lxx(cur,a6_t1-cur);        /* do the LCA */
  2282. X    buff[cur--]=0x31;
  2283. X    
  2284. X    buff[cur--]=0x80;
  2285. X    buff[cur--]=0xa3;
  2286. X    
  2287. X    i=fwrite(&buff[cur+1],1,a6_end-cur,fout);
  2288. X    if(i!=a6_end-cur)
  2289. X        return(1);
  2290. X    
  2291. X    u1=fread(buff,1,0x8000,fin);
  2292. X    while(u1>0)
  2293. X    {
  2294. X        
  2295. X        u2=fwrite(buff,1,u1,fout);
  2296. X        if(u2!=u1)
  2297. X            return(2);
  2298. X        u1=fread(buff,1,0x8000,fin);
  2299. X    }
  2300. X    for(i=0;i<4;buff[i++]=0);
  2301. X    u2=fwrite(buff,1,4,fout);
  2302. X    if(u2!=4)
  2303. X        return(3);
  2304. X    
  2305. X    return(0);
  2306. X}
  2307. X
  2308. X    
  2309. X    
  2310. X    
  2311. X
  2312. END_OF_FILE
  2313.   if test 23635 -ne `wc -c <'gen_a11.c'`; then
  2314.     echo shar: \"'gen_a11.c'\" unpacked with wrong size!
  2315.   fi
  2316.   # end of 'gen_a11.c'
  2317. fi
  2318. echo shar: End of archive 1 \(of 3\).
  2319. cp /dev/null ark1isdone
  2320. MISSING=""
  2321. for I in 1 2 3 ; do
  2322.     if test ! -f ark${I}isdone ; then
  2323.     MISSING="${MISSING} ${I}"
  2324.     fi
  2325. done
  2326. if test "${MISSING}" = "" ; then
  2327.     echo You have unpacked all 3 archives.
  2328.     rm -f ark[1-9]isdone
  2329. else
  2330.     echo You still must unpack the following archives:
  2331.     echo "        " ${MISSING}
  2332. fi
  2333. exit 0
  2334. exit 0 # Just in case...
  2335.