home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 3 / FreeSoftwareCollection3pd199x-jp.img / oh_fm / ccheck / chklib.c < prev   
Text File  |  1980-01-02  |  6KB  |  209 lines

  1.  
  2. 1000 '
  3. 1010 '/*  :
  4. 1020 '    :   chk 用ライブラリ    (Runser用)
  5. 1030 '    :
  6. 1040 '    :   標準ライブラリのいくつかをサポートする
  7. 1050 '    :
  8. 1060 '    :   filename "chklib.c"
  9. 1070 '    :
  10. 1080 '*/
  11. 1090 '
  12. 1100 '#define stdin   0
  13. 1110 '#define stdout  1
  14. 1120 '#define stderr  2
  15. 1130 '#define stdprt  3
  16. 1140 '
  17. 1150 'typedef char    FILE;
  18. 1160 '
  19. 1170 '#define NFIL    2
  20. 1180 'static          _FSflg[NFIL] = { 0,0 };
  21. 1190 'FILE            *_FSfcb[NFIL];
  22. 1200 'unsigned char   _FSbuf[304*NFIL];
  23. 1210 '
  24. 1220 '#undef  SLEN
  25. 1230 '#define SLEN    256
  26. 1240 '/* #define DEBUG */
  27. 1250 ' 
  28. 1260 'FILE *fopen(fname,md)
  29. 1270 ' char *fname,*md;
  30. 1280 '{   int     c,i;
  31. 1290 '    int     rw,er;
  32. 1300 '    FILE    *fp;
  33. 1310 '
  34. 1320 '    rw = 0;
  35. 1330 '    for( i=0 ; i<NFIL ; ++i )
  36. 1340 '    {   if( _FSflg[i]==0 )
  37. 1350 '        {   _FSflg[i] = -1;
  38. 1360 '            fp = (int)_FSbuf+i*304;
  39. 1370 '            strfil(fp,304,0);       /* Clear work area */
  40. 1380 '#ifdef  DEBUG
  41. 1390 '            printf("fcb %04x , %04x\n",_FSbuf,fp);
  42. 1400 '#endif
  43. 1410 '            goto Open;
  44. 1420 '        }
  45. 1430 '    }
  46. 1440 '#ifdef  DEBUG
  47. 1450 '    print ("@ Flg Err\n");
  48. 1460 '#endif
  49. 1470 '    return 0;   /* error */
  50. 1480 'Open:
  51. 1490 '    while( c = *md++ )
  52. 1500 '    {   if( c=='r' )
  53. 1510 '            rw += 1;
  54. 1520 '        else if( c=='w' )
  55. 1530 '            rw += 2;
  56. 1540 '    }
  57. 1550 '    switch( rw )
  58. 1560 '    {   case 1: /* read */
  59. 1570 '            fp[32] = 1;
  60. 1580 '            er = open(fname,fp);
  61. 1590 '            break;
  62. 1600 '        case 2: /* write */
  63. 1610 '            fp[11] = 0;    /* タイプナンバ */
  64. 1620 '            fp[12] =-1;    /* ASCII */
  65. 1630 '            fp[15] = 0;    /* ファイル属性の指定 */
  66. 1640 '            fp[25] = 0x00; /* エディションナンバの指定 */
  67. 1650 '            fp[32] = 2;
  68. 1660 '            er = open(fname,fp);
  69. 1670 '            break;
  70. 1680 '        default:
  71. 1690 '#ifdef  DEBUG
  72. 1700 '            print ("@ Mode Err\n");
  73. 1710 '#endif
  74. 1720 '            return( 0 );
  75. 1730 '    }
  76. 1740 '    return( er==ERR ? 0 : (int)fp );
  77. 1750 '}
  78. 1760 '
  79. 1770 'char _fprt = FALSE;
  80. 1780 '
  81. 1790 'putc(c,fp)
  82. 1800 ' int c;
  83. 1810 ' FILE *fp;
  84. 1820 '{   char p;
  85. 1830 '
  86. 1840 '#ifdef  DEBUG
  87. 1850 '    printf("putc c = %02x ,(fp=%04x)\n",c,fp);
  88. 1860 '#endif
  89. 1870 '    switch( (int)fp )
  90. 1880 '    {   case stdin:
  91. 1890 '            return( -1 );
  92. 1900 '        case stdout:
  93. 1910 '        case stderr:
  94. 1920 '            Pflg = FALSE;
  95. 1930 '            putchar( c );
  96. 1940 '            break;
  97. 1950 '        case stdprt:
  98. 1960 '            if( _fprt==FALSE )
  99. 1970 '            {   if( prtinit()==ERR )
  100. 1980 '                {   print ("@ Printer not ready!");
  101. 1990 '                    exit(0);
  102. 2000 '                }
  103. 2010 '                _fprt = TRUE;
  104. 2020 '            }
  105. 2030 '            Pflg = TRUE;
  106. 2040 '            putchar( c );
  107. 2050 '            break;
  108. 2060 '        default:
  109. 2070 '            p = c;
  110. 2080 '            write(fp,&p,1);
  111. 2090 '    }
  112. 2100 '}
  113. 2110 '
  114. 2120 'fprintf(fp,cs)
  115. 2130 ' FILE *fp;
  116. 2140 ' STRING cs;
  117. 2150 '{   char    buf[SLEN];
  118. 2160 '    char    *p;
  119. 2170 '
  120. 2180 '#ifdef  DEBUG
  121. 2190 '    printf("fprintf (fp=%04x)\n",fp);
  122. 2200 '#endif
  123. 2210 '    _sprintf(buf,cs,(int *)&cs+1);
  124. 2220 '    switch( (int)fp )
  125. 2230 '    {   case stdout:
  126. 2240 '        case stderr:
  127. 2250 '            Pflg = 0;
  128. 2260 '            print (buf);
  129. 2270 '            break;
  130. 2280 '        case stdprt:
  131. 2290 '            if( _fprt==FALSE )
  132. 2300 '            {   if( prtinit()==ERR )
  133. 2310 '                {   print ("@ Printer not ready!");
  134. 2320 '                    exit(0);
  135. 2330 '                }
  136. 2340 '                _fprt = TRUE;
  137. 2350 '            }
  138. 2360 '            Pflg = TRUE;
  139. 2370 '            printf(buf);
  140. 2380 '            break;
  141. 2390 '        default:
  142. 2400 '            p = buf;
  143. 2410 '            while( *p )
  144. 2420 '                write(fp,p++,1);
  145. 2430 '    }
  146. 2440 '}
  147. 2450 '
  148. 2460 'fgets(buf,n,fp)
  149. 2470 ' char   *buf;
  150. 2480 ' int    n;
  151. 2490 ' FILE   *fp;
  152. 2500 '{   int     c,i;
  153. 2510 '    char    ch;
  154. 2520 '
  155. 2530 '    switch( (int)fp )
  156. 2540 '    {   case stdin:
  157. 2550 '            i = input(buf,n);
  158. 2560 '            return( i<0 ? 0 : (int)buf+i );
  159. 2570 '        case stdout:
  160. 2580 '        case stderr:
  161. 2590 '        case stdprt:
  162. 2600 '            return( 0 );
  163. 2610 '        default:
  164. 2620 '#ifdef  DEBUG
  165. 2630 '        printf("fgets (fp=%04x)\n",fp);
  166. 2640 '#endif
  167. 2650 '        --n;
  168. 2660 '        for(i = 0 ; i<n ; ++i )
  169. 2670 '        {   if( (c=read(fp,&ch,1))==ERR )
  170. 2680 '            {   *buf = '\0';
  171. 2690 '                return( 0 );    /* ERROR */
  172. 2700 '            }
  173. 2710 '            if( c==EOF || ch==0x1A )        /* EOF */
  174. 2720 '            {   *buf = '\0';
  175. 2730 '                return( i ? 0x1A : 0 );
  176. 2740 '            }
  177. 2750 '            if( ch=='\b' )                  /* Back Scape */
  178. 2760 '            {   if( i )
  179. 2770 '                {   --buf;
  180. 2780 '                    --i;
  181. 2790 '                }
  182. 2800 '                --i;
  183. 2810 '                continue;
  184. 2820 '            }
  185. 2830 '            if( (*buf++ = ch)=='\n')
  186. 2840 '                break;
  187. 2850 '        }
  188. 2860 '        *buf++ = '\0';
  189. 2870 '        return( buf );
  190. 2880 '    }
  191. 2890 '}
  192. 2900 '
  193. 2910 'fclose( fp )
  194. 2920 ' FILE   *fp;
  195. 2930 '{   int     i;
  196. 2940 '
  197. 2950 '    if( fp!=stdin && fp!=stdout && fp!=stderr && fp!=stdprt )
  198. 2960 '    {   i = ((int)_FSbuf-(int)fp)/304;
  199. 2970 '        close( fp );
  200. 2980 '        _FSflg[i] = 0;
  201. 2990 '    }
  202. 3000 '}
  203. 3010 '
  204. 3020 'isspace( c )
  205. 3030 ' int     c;
  206. 3040 '{   return( c==' ' || c=='\n' || c=='\t' );
  207. 3050 '}
  208. 3060 '
  209.