home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-3 / USERCODE.C < prev    next >
Text File  |  2000-06-30  |  3KB  |  100 lines

  1. /*
  2.     USERCODE.C: A Nice Idea Killed By A Stupid CP/M MisFeature.....
  3.  
  4.     Idea: Extend the filename syntax for user with ALL file I/O to
  5.           allow a user area prefix of the form "n/" on all filenames.
  6.  
  7.     Written by Leor Zolman, 12/81  
  8.  
  9.         ****************************************************************
  10.     **         FOR CP/M 2.x SYSTEMS ONLY!!!                          **
  11.         ****************************************************************
  12.  
  13.  
  14.     Generalized replacements for "open", "creat" and "unlink"
  15.     library functions, allowing a user area prefix to be attached
  16.     to all filenames (except those used as arguments to the "rename"
  17.     function). The new filename syntax becomes:
  18.  
  19.         [whitespace][nn/][d:][filename.ext]
  20.  
  21.     E.g, to reference file "foo.bar" on the currently logged disk in
  22.     user area 7, you'd use:
  23.  
  24.         7/foo.bar
  25.  
  26.     To reference foo.bar in user area 9 on disk b:, you'd say:
  27.  
  28.         9/b:foo.bar
  29.  
  30.     and so on. The user area prefix must always come first if both it and
  31.     a disk designator need to be specified. 
  32.  
  33.     NOTE: THIS WHOLE THING DOESN'T REALLY WORK FOR WRITING FILES INTO
  34.     USER AREAS DIFFERENT FROM THE CURRENTLY ACTIVE USER AREA, BECAUSE
  35.     GODDAMN CP/M DOESN'T LET YOU CLOSE A FILE THAT WAS OPENED IN A USER
  36.     AREA DIFFERENT FROM THE CURRENTLY ACTIVE ONE. DAMN!!!!!!!!!!!!!!!!!!!
  37.  
  38.     To install this library, follow these steps:
  39.         1) compile this file (USERCODE.C)
  40.         2) invoke CLIB and give it the following commands:
  41.             *o 0 usercode
  42.             *o 1 deff2
  43.             *e 1 open
  44.             *a 0 open_old
  45.             *e 1 creat
  46.             *a 0 creat_old
  47.             *e 1 unlink
  48.             *a 0 unlink_old
  49.             *c 0
  50.             *q
  51.         3) Link the programs you wish to have recognize the user code
  52.            on filenames by including "-f usercode" on the CLINK
  53.            command line.
  54. */
  55.  
  56. int open_old();
  57. int creat_old();
  58. int unlink_old();
  59.  
  60. open(filename, mode)
  61. {
  62.     return usercode(&open_old,filename,mode);
  63. }
  64.  
  65. creat(filename)
  66. {
  67.     return usercode(&creat_old,filename);
  68. }
  69.  
  70. unlink(filename)
  71. {
  72.     return usercode(&unlink_old,filename);
  73. }
  74.  
  75. int usercode(funcptr, filename, extra_arg)
  76. int (*funcptr)();
  77. char *filename;
  78. int extra_arg;
  79. {
  80.     int i, cur_user, new_user;
  81.     char *savnam;
  82.  
  83.     while (isspace(*filename)) filename++;    /* skip over whitespace    */
  84.     savnam = filename;        /* save in case of false start    */
  85.  
  86.     if (!isdigit(*filename)) return (*funcptr)(filename,extra_arg);
  87.  
  88.     cur_user = bdos(32, 0xff);    /* save current user number    */
  89.     new_user = atoi(filename);    /* get new user number        */
  90.     while (isdigit(*++filename))    /* skip over user number text    */
  91.         ;
  92.     if (*filename != '/' || new_user > 31)
  93.          return (*funcptr)(savnam,extra_arg);    
  94.     bdos(32,new_user);
  95.     i = (*funcptr)(filename + 1,extra_arg);
  96.     bdos(32,cur_user);
  97.     return i;
  98. }
  99.  
  100.