NEWSTUFF.C
上传用户:dcs7469208
上传日期:2010-01-02
资源大小:443k
文件大小:7k
源码类别:

操作系统开发

开发平台:

DOS

  1. /****************************************************************/
  2. /*                                                              */
  3. /*                           newstuff.c                         */
  4. /*                            DOS-C                             */
  5. /*                                                              */
  6. /*                       Copyright (c) 1996                     */
  7. /*                          Svante Frey                         */
  8. /*                      All Rights Reserved                     */
  9. /*                                                              */
  10. /* This file is part of DOS-C.                                  */
  11. /*                                                              */
  12. /* DOS-C is free software; you can redistribute it and/or       */
  13. /* modify it under the terms of the GNU General Public License  */
  14. /* as published by the Free Software Foundation; either version */
  15. /* 2, or (at your option) any later version.                    */
  16. /*                                                              */
  17. /* DOS-C is distributed in the hope that it will be useful, but */
  18. /* WITHOUT ANY WARRANTY; without even the implied warranty of   */
  19. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See    */
  20. /* the GNU General Public License for more details.             */
  21. /*                                                              */
  22. /* You should have received a copy of the GNU General Public    */
  23. /* License along with DOS-C; see the file COPYING.  If not,     */
  24. /* write to the Free Software Foundation, 675 Mass Ave,         */
  25. /* Cambridge, MA 02139, USA.                                    */
  26. /****************************************************************/
  27. /* $Logfile:   C:/dos-c/src/kernel/newstuff.c_v  $ */
  28. #ifdef VERSION_STRINGS
  29. static BYTE *mainRcsId = "$Header:   C:/dos-c/src/kernel/newstuff.c_v   1.3   04 Jan 1998 23:15:22   patv  $";
  30. #endif
  31. /* $Log:   C:/dos-c/src/kernel/newstuff.c_v  $
  32.  * 
  33.  *    Rev 1.3   04 Jan 1998 23:15:22   patv
  34.  * Changed Log for strip utility
  35.  * 
  36.  *    Rev 1.2   04 Jan 1998 17:26:14   patv
  37.  * Corrected subdirectory bug
  38.  * 
  39.  *    Rev 1.1   22 Jan 1997 13:21:22   patv
  40.  * pre-0.92 Svante Frey bug fixes.
  41.  */
  42. /* $EndLog$ */
  43. #include        "../../hdr/portab.h"
  44. #include        "globals.h"
  45. #include        "proto.h"
  46. int SetJFTSize(UWORD nHandles)
  47. {
  48.         UWORD block, maxBlock;
  49.         psp FAR *ppsp = MK_FP(cu_psp, 0);
  50.         UBYTE FAR *newtab;
  51.         COUNT i;
  52.     
  53.         if (nHandles <= ppsp -> ps_maxfiles)
  54.         {
  55.                 ppsp -> ps_maxfiles = nHandles;
  56.                 return SUCCESS;
  57.         }
  58.         if (nHandles > SFTMAX)
  59.                 return DE_TOOMANY;
  60.     
  61.         if((DosMemAlloc((nHandles + 0xf) >> 4, mem_access_mode, &block, &maxBlock)) < 0)
  62.                 return DE_NOMEM;
  63.     
  64.         ++block;
  65.         newtab = MK_FP(block, 0);
  66.     
  67.         for (i = 0; i < ppsp -> ps_maxfiles; i++)
  68.                 newtab[i] = ppsp -> ps_filetab[i];
  69.     
  70.         for ( ; i < nHandles; i++)
  71.                 newtab[i] = 0xff;
  72.     
  73.         ppsp -> ps_maxfiles = nHandles;
  74.         ppsp -> ps_filetab = newtab;
  75.     
  76.         return SUCCESS;
  77. }
  78. int DosMkTmp(BYTE FAR *pathname, UWORD attr)
  79. {
  80.         /* create filename from current date and time */
  81.         char tokens[16] = "0123456789ABCDEF";
  82.         char FAR *ptmp = pathname;
  83.         BYTE wd, month, day;
  84.         BYTE h, m, s, hund;
  85.         WORD sh;
  86.         WORD year;
  87.         int rc;
  88.         
  89.         while (*ptmp) ptmp++;
  90.         
  91.         if (ptmp == pathname || (ptmp[-1] != '\' && ptmp[-1] != '/'))
  92.                 *ptmp++ = '\';
  93.         DosGetDate(&wd, &month, &day, (COUNT FAR *)&year);
  94.         DosGetTime(&h, &m, &s, &hund);
  95.         sh = s * 100 + hund;
  96.     
  97.         ptmp[0] = tokens[ year & 0xf ];
  98.         ptmp[1] = tokens[ month ];
  99.         ptmp[2] = tokens[ day & 0xf ];
  100.         ptmp[3] = tokens[ h & 0xf ];
  101.         ptmp[4] = tokens[ m & 0xf ];
  102.         ptmp[5] = tokens[ (sh >> 8) & 0xf ];
  103.         ptmp[6] = tokens[ (sh >> 4) & 0xf ];
  104.         ptmp[7] = tokens[ sh & 0xf ];
  105.         ptmp[8] = '.';                      
  106.         ptmp[9] = 'A';
  107.         ptmp[10] = 'A';
  108.         ptmp[11] = 'A';
  109.         ptmp[12] = 0;
  110.         while ((rc = DosOpen(pathname, 0)) >= 0)
  111.         {
  112.                 DosClose(rc);
  113.        
  114.                 if (++ptmp[11] > 'Z')
  115.                 {
  116.                         if (++ptmp[10] > 'Z')
  117.                         {    
  118.                                 if (++ptmp[9] > 'Z')
  119.                                         return DE_TOOMANY;
  120.                         
  121.                                 ptmp[10] = 'A';
  122.                         }
  123.                         ptmp[11] = 'A';
  124.                 }
  125.         }
  126.         
  127.         if (rc == DE_FILENOTFND) 
  128.         {
  129.                 rc = DosCreat(pathname, attr);
  130.         }
  131.         return rc;
  132. }   
  133. int truename(char FAR *src, char FAR *dest)
  134. {
  135.         char buf[128] = "A:\";
  136.         char *bufp = buf + 3;
  137.         BYTE far *test;
  138. /* First, adjust the source pointer */
  139. src = adjust_far(src);
  140.         /* Do we have a drive? */
  141.         if (src[1] == ':')
  142.         {
  143.                 buf[0] = (src[0] | 0x20) + 'A' - 'a';
  144.         
  145.                 if (buf[0] >= nblkdev + 'A')
  146.                         return DE_PATHNOTFND;
  147.         
  148.                 src += 2; 
  149.         } else 
  150.                 buf[0] = default_drive + 'A';
  151.       
  152.         if (*src != '\' && *src != '/')   /* append current dir */
  153.         {
  154.                 DosGetCuDir(buf[0] - '@', bufp);
  155.          
  156.                 if (*bufp)
  157.                 {
  158.                         while (*bufp) bufp++;
  159.                         *bufp++ = '\';
  160.                 }
  161.         } else src++;
  162.         /* convert all forward slashes to backslashes, and uppercase all characters */
  163.         while(*src)
  164.         {
  165.                 char c;
  166.                 switch((c = *src++))
  167.                 {
  168.                 case '/':         /* convert to backslash */
  169.                 
  170.                     *bufp++ = '\';   
  171.                     break;
  172.           
  173.                 /* look for '.' and '..' dir entries */
  174.                 case '.':         
  175.                     if (bufp[-1] == '\')
  176.                     {
  177.                         if (*src == '.' && (src[1] == '/' || src[1] == '\' || !src[1]))
  178.                         {    
  179.                             /* '..' dir entry: rewind bufp to last backslash */
  180.                 
  181.                             for (bufp -= 2 ; *bufp != '\'; bufp--)
  182.                             {
  183.                                 if (bufp < buf + 2)    /* '..' illegal in root dir */
  184.                                     return DE_PATHNOTFND;     
  185.                             }
  186.                             bufp++;
  187.                         } else if (*src == '/' || *src == '\' || *src == 0)     
  188.                         {
  189.                             if (*src != 0) src++;     /* '.' directory: just skip it */          
  190.                         }
  191.                     }
  192.                     else *bufp++ = c;
  193.                     break;
  194.                 default:
  195.                     *bufp++ = c;
  196.                     break;
  197.                 }
  198.         }
  199.         *bufp++ = 0;
  200.         /* finally, uppercase everything */
  201.         upString(buf);
  202.     
  203.         /* copy to user's buffer */
  204.         fbcopy(buf, dest, bufp - buf);
  205.         return SUCCESS;
  206. }