Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
1.7 KiB

  1. #include <windows.h>
  2. #include <commdlg.h>
  3. #include <shellapi.h>
  4. #ifndef DBCS
  5. #define AnsiNext(x) ((x)+1)
  6. #endif
  7. #define BLOCKLEN 100
  8. PSTR NEAR PASCAL GetAppName(HANDLE hCommand)
  9. {
  10. static char szApp[17];
  11. PSTR pLast, pCommand, pDot;
  12. char cSave;
  13. for(pCommand=LocalLock(hCommand); *pCommand==' ';
  14. pCommand=AnsiNext(pCommand))
  15. /* skip spaces */ ;
  16. for(pDot=pLast=pCommand; ; pCommand=AnsiNext(pCommand)) {
  17. switch(*pCommand) {
  18. case ':':
  19. case '\\':
  20. pLast = pCommand + 1;
  21. break;
  22. case '.':
  23. pDot = pCommand;
  24. break;
  25. case '\0':
  26. case ' ':
  27. case '/':
  28. goto FoundEnd;
  29. }
  30. }
  31. FoundEnd:
  32. /* If there was a dot in the name or the name was too long */
  33. if(pDot > pLast)
  34. pCommand = pDot;
  35. if(pCommand-pLast > 8)
  36. pCommand = pLast+8;
  37. cSave = *pCommand;
  38. *pCommand = '\0';
  39. lstrcpy(szApp, pLast);
  40. *pCommand = cSave;
  41. AnsiUpper(szApp);
  42. pLast = AnsiNext(szApp);
  43. AnsiLower(pLast);
  44. LocalUnlock(hCommand);
  45. return(szApp);
  46. }
  47. HANDLE NEAR cdecl ConstructPath(PSTR pHead, ...)
  48. {
  49. HANDLE hBuf = NULL;
  50. PSTR *ppName, pBuf, pTemp;
  51. WORD wLen;
  52. if(!pHead)
  53. goto Error1;
  54. for(ppName=&pHead, wLen=0; *ppName; ++ppName)
  55. wLen += lstrlen(*ppName) + 1;
  56. if(!(hBuf=LocalAlloc(LMEM_MOVEABLE, wLen)))
  57. goto Error1;
  58. if(!(pBuf=LocalLock(hBuf)))
  59. goto Error2;
  60. for(ppName=&pHead, wLen=0, pTemp=pBuf; *ppName; ++ppName) {
  61. lstrcpy(pTemp, *ppName);
  62. pTemp += lstrlen(pTemp);
  63. *pTemp++ = '\\';
  64. }
  65. *(pTemp-1) = '\0';
  66. LocalUnlock(hBuf);
  67. goto Error1;
  68. Error2:
  69. LocalFree(hBuf);
  70. hBuf = NULL;
  71. Error1:
  72. return(hBuf);
  73. }