skipequiv.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "common.h"
  2. #include "send.h"
  3. #define isspace(c) ((c)==' ' || (c)=='\t' || (c)=='\n')
  4. /*
  5. * skip past all systems in equivlist
  6. */
  7. extern char*
  8. skipequiv(char *base)
  9. {
  10. char *sp;
  11. static Biobuf *fp;
  12. while(*base){
  13. sp = strchr(base, '!');
  14. if(sp==0)
  15. break;
  16. *sp = '\0';
  17. if(lookup(base, "equivlist", &fp, 0, 0)==1){
  18. /* found or us, forget this system */
  19. *sp='!';
  20. base=sp+1;
  21. } else {
  22. /* no files or system is not found, and not us */
  23. *sp='!';
  24. break;
  25. }
  26. }
  27. return base;
  28. }
  29. static int
  30. okfile(char *cp, Biobuf *fp)
  31. {
  32. char *buf;
  33. int len;
  34. char *bp, *ep;
  35. int c;
  36. len = strlen(cp);
  37. Bseek(fp, 0, 0);
  38. /* one iteration per system name in the file */
  39. while(buf = Brdline(fp, '\n')) {
  40. ep = &buf[Blinelen(fp)];
  41. for(bp=buf; bp < ep;){
  42. while(isspace(*bp) || *bp==',')
  43. bp++;
  44. if(strncmp(bp, cp, len) == 0) {
  45. c = *(bp+len);
  46. if(isspace(c) || c==',')
  47. return 1;
  48. }
  49. while(bp < ep && (!isspace(*bp)) && *bp!=',')
  50. bp++;
  51. }
  52. }
  53. /* didn't find it, prohibit forwarding */
  54. return 0;
  55. }
  56. /* return 1 if name found in one of the files
  57. * 0 if name not found in one of the files
  58. * -1 if neither file exists
  59. */
  60. extern int
  61. lookup(char *cp, char *local, Biobuf **lfpp, char *global, Biobuf **gfpp)
  62. {
  63. static String *file = 0;
  64. if (local) {
  65. if (file == 0)
  66. file = s_new();
  67. abspath(local, UPASLIB, s_restart(file));
  68. if (*lfpp != 0 || (*lfpp = sysopen(s_to_c(file), "r", 0)) != 0) {
  69. if (okfile(cp, *lfpp))
  70. return 1;
  71. } else
  72. local = 0;
  73. }
  74. if (global) {
  75. abspath(global, UPASLIB, s_restart(file));
  76. if (*gfpp != 0 || (*gfpp = sysopen(s_to_c(file), "r", 0)) != 0) {
  77. if (okfile(cp, *gfpp))
  78. return 1;
  79. } else
  80. global = 0;
  81. }
  82. return (local || global)? 0 : -1;
  83. }