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.

174 lines
6.2 KiB

  1. /* $Header: /nw/tony/src/stevie/src/RCS/param.c,v 1.10 89/08/02 10:59:10 tony Exp $
  2. *
  3. * Code to handle user-settable parameters. This is all pretty much table-
  4. * driven. To add a new parameter, put it in the params array, and add a
  5. * macro for it in param.h. If it's a numeric parameter, add any necessary
  6. * bounds checks to doset(). String parameters aren't currently supported.
  7. */
  8. #include "stevie.h"
  9. extern long CursorSize;
  10. struct param params[] = {
  11. { "tabstop", "ts", 4, P_NUM },
  12. { "scroll", "scroll", 12, P_NUM },
  13. { "report", "report", 5, P_NUM },
  14. { "lines", "lines", 25, P_NUM },
  15. { "vbell", "vb", TRUE, P_BOOL },
  16. { "showmatch", "sm", FALSE, P_BOOL },
  17. { "wrapscan", "ws", TRUE, P_BOOL },
  18. { "errorbells", "eb", FALSE, P_BOOL },
  19. { "showmode", "mo", FALSE, P_BOOL },
  20. { "backup", "bk", FALSE, P_BOOL },
  21. { "return", "cr", TRUE, P_BOOL },
  22. { "list", "list", FALSE, P_BOOL },
  23. { "ignorecase", "ic", FALSE, P_BOOL },
  24. { "autoindent", "ai", FALSE, P_BOOL },
  25. { "number", "nu", FALSE, P_BOOL },
  26. { "modelines", "ml", FALSE, P_BOOL },
  27. { "tildeop", "to", FALSE, P_BOOL },
  28. { "terse", "terse", FALSE, P_BOOL },
  29. { "cursorsize", "cs", 25, P_NUM },
  30. { "highlightsearch", "hs", TRUE, P_BOOL },
  31. { "columns", "co", 80, P_NUM },
  32. { "hardtabs", "ht", FALSE, P_BOOL },
  33. { "shiftwidth", "sw", 4, P_NUM },
  34. { "", "", 0, 0, } /* end marker */
  35. };
  36. static void showparms();
  37. void wchangescreen();
  38. void
  39. doset(arg)
  40. char *arg; /* parameter string */
  41. {
  42. register int i;
  43. register char *s;
  44. bool_t did_lines = FALSE;
  45. bool_t state = TRUE; /* new state of boolean parms. */
  46. if (arg == NULL) {
  47. showparms(FALSE);
  48. return;
  49. }
  50. if (strncmp(arg, "all", 3) == 0) {
  51. showparms(TRUE);
  52. return;
  53. }
  54. if (strncmp(arg, "no", 2) == 0) {
  55. state = FALSE;
  56. arg += 2;
  57. }
  58. for (i=0; params[i].fullname[0] != NUL ;i++) {
  59. s = params[i].fullname;
  60. if (strncmp(arg, s, strlen(s)) == 0) /* matched full name */
  61. break;
  62. s = params[i].shortname;
  63. if (strncmp(arg, s, strlen(s)) == 0) /* matched short name */
  64. break;
  65. }
  66. if (params[i].fullname[0] != NUL) { /* found a match */
  67. if (params[i].flags & P_NUM) {
  68. did_lines = ((i == P_LI) || (i == P_CO));
  69. if (arg[strlen(s)] != '=' || state == FALSE)
  70. emsg("Invalid set of numeric parameter");
  71. else {
  72. params[i].value = atoi(arg+strlen(s)+1);
  73. params[i].flags |= P_CHANGED;
  74. }
  75. } else /* boolean */ {
  76. if (arg[strlen(s)] == '=')
  77. emsg("Invalid set of boolean parameter");
  78. else {
  79. params[i].value = state;
  80. params[i].flags |= P_CHANGED;
  81. }
  82. }
  83. } else
  84. emsg("Unrecognized 'set' option");
  85. /*
  86. * Update the screen in case we changed something like "tabstop"
  87. * or "list" that will change its appearance.
  88. */
  89. updatescreen();
  90. CursorSize = P(P_CS);
  91. VisibleCursor();
  92. if (did_lines) {
  93. Rows = P(P_LI);
  94. Columns = P(P_CO);
  95. screenalloc(); /* allocate new screen buffers */
  96. screenclear();
  97. (void)wchangescreen(Rows, Columns);
  98. updatescreen();
  99. }
  100. /*
  101. * Check the bounds for numeric parameters here
  102. */
  103. if (P(P_TS) <= 0 || P(P_TS) > 32) {
  104. emsg("Invalid tab size specified");
  105. P(P_TS) = 8;
  106. return;
  107. }
  108. if (P(P_SS) <= 0 || P(P_SS) > Rows) {
  109. emsg("Invalid scroll size specified");
  110. P(P_SS) = 12;
  111. return;
  112. }
  113. #ifndef TILDEOP
  114. if (P(P_TO)) {
  115. emsg("Tilde-operator not enabled");
  116. P(P_TO) = FALSE;
  117. return;
  118. }
  119. #endif
  120. /*
  121. * Check for another argument, and call doset() recursively, if
  122. * found. If any argument results in an error, no further
  123. * parameters are processed.
  124. */
  125. while (*arg != ' ' && *arg != '\t') { /* skip to next white space */
  126. if (*arg == NUL)
  127. return; /* end of parameter list */
  128. arg++;
  129. }
  130. while (*arg == ' ' || *arg == '\t') /* skip to next non-white */
  131. arg++;
  132. if (*arg)
  133. doset(arg); /* recurse on next parameter */
  134. }
  135. static void
  136. showparms(all)
  137. bool_t all; /* show ALL parameters */
  138. {
  139. register struct param *p;
  140. char buf[64];
  141. gotocmd(TRUE, 0);
  142. outstr("Parameters:\r\n");
  143. for (p = &params[0]; p->fullname[0] != NUL ;p++) {
  144. if (!all && ((p->flags & P_CHANGED) == 0))
  145. continue;
  146. if (p->flags & P_BOOL)
  147. sprintf(buf, "\t%s%s\r\n",
  148. (p->value ? "" : "no"), p->fullname);
  149. else
  150. sprintf(buf, "\t%s=%d\r\n", p->fullname, p->value);
  151. outstr(buf);
  152. }
  153. wait_return();
  154. }