inquire.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "f2c.h"
  2. #include "fio.h"
  3. #include "string.h"
  4. #ifdef NON_UNIX_STDIO
  5. #ifndef MSDOS
  6. //#include "unistd.h" /* for access() */
  7. #endif
  8. #endif
  9. #ifdef KR_headers
  10. integer f_inqu(a) inlist *a;
  11. #else
  12. #ifdef __cplusplus
  13. extern "C" integer f_inqu(inlist*);
  14. #endif
  15. #ifdef MSDOS
  16. #undef abs
  17. #undef min
  18. #undef max
  19. #include "io.h"
  20. #endif
  21. integer f_inqu(inlist *a)
  22. #endif
  23. { flag byfile;
  24. int i;
  25. #ifndef NON_UNIX_STDIO
  26. int n;
  27. #endif
  28. unit *p;
  29. char buf[256];
  30. long x;
  31. if(a->infile!=NULL)
  32. { byfile=1;
  33. g_char(a->infile,a->infilen,buf);
  34. #ifdef NON_UNIX_STDIO
  35. x = access(buf,0) ? -1 : 0;
  36. for(i=0,p=NULL;i<MXUNIT;i++)
  37. if(f__units[i].ufd != NULL
  38. && f__units[i].ufnm != NULL
  39. && !strcmp(f__units[i].ufnm,buf)) {
  40. p = &f__units[i];
  41. break;
  42. }
  43. #else
  44. x=f__inode(buf, &n);
  45. for(i=0,p=NULL;i<MXUNIT;i++)
  46. if(f__units[i].uinode==x
  47. && f__units[i].ufd!=NULL
  48. && f__units[i].udev == n) {
  49. p = &f__units[i];
  50. break;
  51. }
  52. #endif
  53. }
  54. else
  55. {
  56. byfile=0;
  57. if(a->inunit<MXUNIT && a->inunit>=0)
  58. {
  59. p= &f__units[a->inunit];
  60. }
  61. else
  62. {
  63. p=NULL;
  64. }
  65. }
  66. if(a->inex!=NULL)
  67. if(byfile && x != -1 || !byfile && p!=NULL)
  68. *a->inex=1;
  69. else *a->inex=0;
  70. if(a->inopen!=NULL)
  71. if(byfile) *a->inopen=(p!=NULL);
  72. else *a->inopen=(p!=NULL && p->ufd!=NULL);
  73. if(a->innum!=NULL) *a->innum= p-f__units;
  74. if(a->innamed!=NULL)
  75. if(byfile || p!=NULL && p->ufnm!=NULL)
  76. *a->innamed=1;
  77. else *a->innamed=0;
  78. if(a->inname!=NULL)
  79. if(byfile)
  80. b_char(buf,a->inname,a->innamlen);
  81. else if(p!=NULL && p->ufnm!=NULL)
  82. b_char(p->ufnm,a->inname,a->innamlen);
  83. if(a->inacc!=NULL && p!=NULL && p->ufd!=NULL)
  84. if(p->url)
  85. b_char("DIRECT",a->inacc,a->inacclen);
  86. else b_char("SEQUENTIAL",a->inacc,a->inacclen);
  87. if(a->inseq!=NULL)
  88. if(p!=NULL && p->url)
  89. b_char("NO",a->inseq,a->inseqlen);
  90. else b_char("YES",a->inseq,a->inseqlen);
  91. if(a->indir!=NULL)
  92. if(p==NULL || p->url)
  93. b_char("YES",a->indir,a->indirlen);
  94. else b_char("NO",a->indir,a->indirlen);
  95. if(a->infmt!=NULL)
  96. if(p!=NULL && p->ufmt==0)
  97. b_char("UNFORMATTED",a->infmt,a->infmtlen);
  98. else b_char("FORMATTED",a->infmt,a->infmtlen);
  99. if(a->inform!=NULL)
  100. if(p!=NULL && p->ufmt==0)
  101. b_char("NO",a->inform,a->informlen);
  102. else b_char("YES",a->inform,a->informlen);
  103. if(a->inunf)
  104. if(p!=NULL && p->ufmt==0)
  105. b_char("YES",a->inunf,a->inunflen);
  106. else if (p!=NULL) b_char("NO",a->inunf,a->inunflen);
  107. else b_char("UNKNOWN",a->inunf,a->inunflen);
  108. if(a->inrecl!=NULL && p!=NULL)
  109. *a->inrecl=p->url;
  110. if(a->innrec!=NULL && p!=NULL && p->url>0)
  111. *a->innrec=(ftnint)(FTELL(p->ufd)/p->url+1);
  112. if(a->inblank && p!=NULL && p->ufmt)
  113. if(p->ublnk)
  114. b_char("ZERO",a->inblank,a->inblanklen);
  115. else b_char("NULL",a->inblank,a->inblanklen);
  116. return(0);
  117. }