actions.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* (C) C.D.F. Miller, Heriot-Watt University, March 1984
  2. *
  3. * Permission is hereby given to reproduce or modify this
  4. * software freely, provided that this notice be retained,
  5. * and that no use be made of the software for commercial
  6. * purposes without the express written permission of the
  7. * author.
  8. */
  9. /* actions.c:
  10. * keyword action routines
  11. */
  12. #include <lbl.h>
  13. #include <ctype.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include <err.h>
  17. #include "build.h"
  18. #include "find.h"
  19. extern char *def_format;
  20. extern int sflag;
  21. extern FILE *tempfile;
  22. void a_delimiter(int nargs, char *argvec[]);
  23. /*ARGSUSED*/
  24. void
  25. a_delimiter(int nargs, char *argvec[])
  26. {
  27. (void)nargs;
  28. if (strcmp(argvec[1], "off") == 0) {
  29. if (!sflag)
  30. fprintf(tempfile, "%c%c%c\n", MAGIC1, MAGIC2, M_DELIM);
  31. return;
  32. }
  33. if (argvec[1][1] != '\0') {
  34. warnx("%sdelimiter more than 1 character", maybe_loc());
  35. return;
  36. }
  37. if (argvec[1][0] == '\0') {
  38. warnx("%snull delimiter character", maybe_loc());
  39. return;
  40. }
  41. if (!sflag)
  42. fprintf(tempfile, "%c%c%c%c\n", MAGIC1, MAGIC2,
  43. M_DELIM, argvec[1][0]);
  44. }
  45. void a_format(int nargs, char *argvec[]);
  46. /*ARGSUSED*/
  47. void
  48. a_format(int nargs, char *argvec[])
  49. {
  50. Type *tp = findtype(argvec[1], 1);
  51. (void)nargs;
  52. if (tp->t_format != def_format)
  53. warnx("%s[warning] format for %s redefined", maybe_loc(), tp->t_name);
  54. tp->t_format = copy(argvec[2]);
  55. }
  56. void a_last(int nargs, char *argvec[]);
  57. /*ARGSUSED*/
  58. void
  59. a_last(int nargs, char *argvec[])
  60. {
  61. Type *tp = findtype(argvec[1], 1);
  62. int indx;
  63. nargs -= 2;
  64. argvec += 2;
  65. for (indx = 0; indx < nargs; indx++) {
  66. if (!isdigit(argvec[indx][0])) {
  67. warnx("%snon-numeric label index", maybe_loc());
  68. break;
  69. }
  70. tp->t_levels[indx] = atoi(argvec[indx]);
  71. }
  72. while (indx < NLEVELS)
  73. tp->t_levels[indx++] = 0;
  74. }