Leaked source code of windows server 2003
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.

110 lines
2.4 KiB

  1. /*
  2. * File handling for LPR
  3. *
  4. * Read from an init file.
  5. * Read from a file, expanding tabs.
  6. */
  7. #include <windef.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include "lpr.h"
  11. extern BOOL fVerify; /* From lpr.c - for verifying our progression */
  12. #define cchIniMax 80 /* length of line in tools.ini file */
  13. #define cchPathMax 128 /* maximum length of USER env var. */
  14. /* from fgetl.c - expand tabs and return lines w/o separators */
  15. int colTab = 8; /* Tab stops every colTab columns */
  16. char* __cdecl fgetl(sz, cch, fh)
  17. /* returns line from file (no CRLFs); returns NULL if EOF */
  18. /* Maps nulls read in into .'s */
  19. char *sz;
  20. int cch;
  21. FILE *fh;
  22. {
  23. register int c;
  24. register char *p;
  25. /* remember NUL at end */
  26. cch--;
  27. p = sz;
  28. while (cch)
  29. {
  30. c = getc(fh);
  31. if (c == EOF || c == '\n')
  32. break;
  33. if (c != '\r')
  34. if (c != '\t')
  35. {
  36. *p++ = (char)((unsigned)c ? (unsigned)c : (unsigned)'.');
  37. cch--;
  38. }
  39. else
  40. {
  41. c = (int)(min(colTab - ((p-sz) % colTab), cch));
  42. memset(p, ' ', c);
  43. p += c;
  44. cch -= c;
  45. }
  46. }
  47. *p = 0;
  48. return (!( (c == EOF) && (p == sz) )) ? sz : NULL;
  49. }
  50. char *SzFindPath(szDirlist, szFullname, szFile)
  51. /* SzFindPath -- Creates szFullname from first entry in szDirlist and szFile.
  52. * The remaining directory list is returned. If the directory
  53. * list is empty, NULL is returned.
  54. */
  55. char *szDirlist;
  56. char *szFullname;
  57. char *szFile;
  58. {
  59. #define chDirSep ';' /* seperator for entries in directory list */
  60. #define chDirDelim '\\' /* end of directory name character */
  61. register char *pch;
  62. register char *szRc; /* returned directory list */
  63. if ((pch = strchr(szDirlist, chDirSep)) != 0)
  64. {
  65. *pch = (char)NULL; /* replace ';' with null */
  66. szRc = pch + 1;
  67. }
  68. else
  69. {
  70. pch = strchr(szDirlist,'\0');
  71. szRc = NULL;
  72. }
  73. strcpy(szFullname,szDirlist);
  74. if (szRc != NULL) {
  75. /* We MUST restore the input string */
  76. *(szRc-1) = chDirSep;
  77. }
  78. /* if directory name doesn't already end with chDirDelim, append it */
  79. if (*(pch-1) != chDirDelim)
  80. {
  81. pch = szFullname + strlen(szFullname);
  82. *pch++ = chDirDelim;
  83. *pch = (char)NULL;
  84. }
  85. strcat(szFullname,szFile);
  86. return(szRc);
  87. }