home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / atarist / astfio.c next >
C/C++ Source or Header  |  2020-01-01  |  2KB  |  135 lines

  1. /*
  2.  * astfio.c ATARI ST kermit file i/o operations
  3.  */
  4.  
  5. #include <osbind.h>     /* TOS bindings */
  6. #include <stdio.h>      /* common I/O defs */
  7. #include "astinc.h"     /* common ST KERMIT defs */
  8.  
  9. extern FILE *fopen();
  10. extern FILE *fopenb();
  11. extern char *strcpy();
  12. extern char *strcat();
  13. extern char *rindex();
  14. extern char *index();
  15.  
  16.  
  17. /*
  18.  *          Global Variables
  19.  */
  20.  
  21. struct dta_struct {
  22.    char resv[21];
  23.    char attrib;
  24.    int  ctim;
  25.    int  cdat;
  26.    int  lbfsize;
  27.    int  hbfsize;
  28.    char fname[14];
  29.            };
  30.  
  31. struct dta_struct dta;
  32.  
  33.  
  34. /*
  35.  * file selection functions
  36.  */
  37.  
  38. fremnode(path)
  39. char path[];
  40. /* remove last node (i.e. actual filename) in path spec */
  41. {char *bsptr;
  42.  bsptr = rindex(path,'\\');
  43.  if ((bsptr == NIL) || (bsptr == &path[2]))
  44.     {
  45.      path[2] = '\\';
  46.      path[3] = '\0';
  47.     }
  48.  else
  49.     *bsptr = '\0';
  50. }
  51.  
  52. faddnode(path,node)
  53. char *path, *node;
  54. /* add name to path spec, which is terminated by a '\' */
  55. {
  56.  if (path[3] != '\0') strcat(path,"\\");
  57.  strcat(path,node);
  58. }
  59.  
  60.  
  61. fgetpath(path)
  62. char path[];
  63. /* get current path */
  64. {
  65.  Dgetpath(&path[2],0);
  66.  path[0] = Dgetdrv() + 'A';
  67.  path[1] = ':';
  68.  if (path[2] == '\0') strcat(path,"\\");
  69. }
  70.  
  71. fsetpath(path)
  72. char path[];
  73. {
  74.  Dsetdrv(path[0]-'A');
  75.  Dsetpath(&path[2]);
  76. }
  77.  
  78. int fgetfilename(path,name,newfullname)
  79. char path[], name[], newfullname[];
  80. /* request filename from user */
  81. /* full file name will be delivered on newfullname */
  82. /* path and name are'nt changed */
  83. /* on abort return FALSE else TRUE */
  84. {
  85.  int button;
  86.  char tname[PFILNAMLEN];
  87.  strcpy(newfullname,path);
  88.  faddnode(newfullname,"*.*");
  89.  strcpy(tname,name);
  90.  fsel_input(newfullname,tname,&button);
  91.  fremnode(newfullname);
  92.  faddnode(newfullname,tname);
  93.  return button;
  94. }
  95.  
  96. int fsetfilename(path,name)
  97. /* ask user for new filename */
  98. /* result will be delivered on path and name */
  99. /* also the path will be changed !*/
  100. /* and the DTA will be set! */
  101. /* on abort FALSE will be returned */
  102. char path[],name[];
  103. {int button;
  104.  faddnode(path,"*.*");
  105.  fsel_input(path,name,&button);
  106.  fremnode(path);
  107.  fsetpath(path);
  108.  if (button)
  109.      Fsetdta(&dta);
  110.  return button;
  111. }
  112.  
  113. /*
  114.  * get first file that match
  115.  */
  116. int f1stfil(name)
  117. char name[];
  118. {
  119.  if (Fsfirst(name,0) != 0)
  120.     return FALSE;
  121.  strcpy(filnam,dta.fname);
  122.  return TRUE;
  123. }
  124.  
  125. /*
  126.  * get next file name
  127.  */
  128. int fnxtfil()
  129. {
  130.  if (Fsnext() != 0)
  131.     return FALSE;
  132.  strcpy(filnam,dta.fname);
  133.  return TRUE;
  134. }
  135.