/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <string.h>

#include <descrip.h>

const int COLLAPSE = 2;
const int TRIM = 8 + 128;
const int COMPRESS = 16;
const int UPCASE = 32;
const int QUOTE = 256;

struct varstr
{
   short length;
   char body[256];
};

int dbasic$edit(struct dsc$descriptor_vs *newstr,
                struct dsc$descriptor_vs *oldstr,
                int editlist);

void test(char *s, int editlist)
{
   struct varstr res, temp;
   struct dsc$descriptor_vs newdesc;
   struct dsc$descriptor_vs olddesc;
   strcpy(temp.body, s);
   temp.length = strlen(s);
   newdesc.dsc$w_maxstrlen = sizeof(res.body) - 1;
   newdesc.dsc$b_dtype = DSC$K_DTYPE_VT;
   newdesc.dsc$b_class = DSC$K_CLASS_VS;
   newdesc.dsc$a_pointer = (char *)&res;
   olddesc.dsc$w_maxstrlen = sizeof(temp.body) - 1;
   olddesc.dsc$b_dtype = DSC$K_DTYPE_VT;
   olddesc.dsc$b_class = DSC$K_CLASS_VS;
   olddesc.dsc$a_pointer = (char *)&temp;
   dbasic$edit(&newdesc, &olddesc, editlist);
   res.body[res.length] = '\0';
   printf("|%s| -> |%s|\n", s, res.body);
}

int main(int argc, char *argv[])
{
   test("Test", UPCASE);
   test(" X ", TRIM);
   test("X   X", COMPRESS);
   test("X X X", COLLAPSE);
   test(" x  x  x ", COMPRESS + TRIM + UPCASE);
   test("x x \" x x \" x x", COLLAPSE + UPCASE);
   test("x x \" x x \" x x", COLLAPSE + UPCASE + QUOTE);
   return 0;
}
