summaryrefslogtreecommitdiff
path: root/src/user/mkpopup/main.c
blob: 5b56889c4d4f1466d946fb8cba255919c532ecd2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <popups/info.h>

#include <knob/heap.h>

#include <stdbool.h>
#include <stdint.h>

void main(const char *text) {
  uint32_t required_new_length = 0;
  bool needs_new = false;
  for (const char *c = text; c[0]; ++c) {
    ++required_new_length;
    if ((c[0] == '\\') && (c[1] == 'n')) {
      ++c;
      needs_new = true;
    }
  }

  if (needs_new) {
    char *new_text = get_block(required_new_length);
    const char *ci;
    char *co;
    for (ci = text, co = new_text; *ci; ++ci, ++co)
      if ((ci[0] == '\\') && (ci[1] == 'n')) {
        *co = '\n';
        ++ci;
      }
      else
        *co = *ci;
    text = new_text;
  }

  struct popup p;
  info_popup(&p, text, 0x10, 0x07);
  make_modal(&p);
}