//: Advanced notation for the common/easy case where a recipe takes some fixed //: number of ingredients and yields some fixed number of products. :(scenario recipe_with_header) def main [ 1:num/raw <- add2 3, 5 ] def add2 x:num, y:num -> z:num [ local-scope load-ingredients z:num <- add x, y return z ] +mem: storing 8 in location 1 //: When loading recipes save any header. :(before "End recipe Fields") bool has_header; vector ingredients; vector products; :(before "End recipe Constructor") has_header = false; :(before "End Recipe Refinements") if (in.peek() != '[') { trace(9999, "parse") << "recipe has a header; parsing" << end(); load_recipe_header(in, result); } :(code) void load_recipe_header(istream& in, recipe& result) { result.has_header = true; while (has_data(in) && in.peek() != '[' && in.peek() != '\n') { string s = next_word(in); if (s.empty()) { assert(!has_data(in)); raise << "incomplete recipe header at end of file (0)\n" << end(); return; } if (s == "<-") raise << "recipe " << result.name << " should say '->' and not '<-'\n" << end(); if (s == "->") break; result.ingredients.push_back(reagent(s)); trace(9999, "parse") << "header ingredient: " << result.ingredients.back().original_string << end(); skip_whitespace_but_not_newline(in); } while (has_data(in) && in.peek() != '[' && in.peek() != '\n') { string s = next_word(in); if (s.empty()) { assert(!has_data(in)); raise << "incomplete recipe header at end of file (1)\n" << end(); return; } result.products.push_back(reagent(s)); trace(9999, "parse") << "header product: " << result.products.back().original_string << end(); skip_whitespace_but_not_newline(in); } // End Load Recipe Header(result) } :(scenario recipe_handles_stray_comma) def main [ 1:num/raw <- add2 3, 5 ] def add2 x:num, y:num -> z:num, [ local-scope load-ingredients z:num <- add x, y return z ] +mem: storing 8 in location 1 :(scenario recipe_handles_stray_comma_2) def main [ foo ] def foo, [ 1:num/raw <- add 2, 2 ] def bar [ 1:num/raw <- add 2, 3 ] +mem: storing 4 in location 1 :(scenario recipe_handles_wrong_arrow) % Hide_errors = true; def foo a:num <- b:num [ ] +error: recipe foo should say '->' and not '<-' :(scenario recipe_handles_missing_bracket) % Hide_errors = true; def main ] +error: main: recipe body must begin with '[' :(scenario recipe_handles_missing_bracket_2) % Hide_errors = true; def main local-scope { } ] # doesn't overflow line when reading header -parse: header ingredient: local-scope +error: main: recipe body must begin with '[' :(scenario recipe_handles_missing_bracket_3) % Hide_errors = true; def main # comment local-scope { } ] # doesn't overflow line when reading header -parse: header ingredient: local-scope +error: main: recipe body must begin with '[' :(after "Begin debug_string(recipe x)") out << "ingredients:\n"; for (int i = 0; i < SIZE(x.ingredients); ++i) out << " " << debug_string(x.ingredients.at(i)) << '\n'; out << "products:\n"; for (int i = 0; i < SIZE(x.products); ++i) out << " " << debug_string(x.products.at(i)) << '\n'; //: If a recipe never mentions any ingredients or products, assume it has a header. :(scenario recipe_without_ingredients_or_products_has_header) def test [ 1:num <- copy 34 ] +parse: recipe test has a header :(before "End Recipe Body(result)") if (!result.has_header) { result.has_header = true; for (int i = 0; i < SIZE(result.steps); ++i) { const instruction& inst = result.steps.at(i); if ((inst.name == "reply" && !inst.ingredients.empty()) || (inst.name == "return" && !inst.ingredients.empty()) || inst.name == "next-ingredient" || inst.name == "ingredient" || inst.name == "rewind-ingredients") { result.has_header = false; break; } } } if (result.has_header) { trace(9999, "parse") << "recipe " << result.name << " has a header" << end(); } //: Support type abbreviations in headers. :(scenario type_abbreviations_in_recipe_headers) def main [ local-scope a:text <- foo 1:char/raw <- index *a, 0 ] def foo -> a:text [ # 'text' is an abbreviation local-scope load-ingredients a <- new [abc] ] +mem: storing 97 in location 1 :(before "End Expand Type Abbreviations(caller)") for (long int i = 0; i < SIZE(caller.ingredients); ++i) expand_type_abbreviations(caller.ingredients.at(i).type); for (long int i = 0; i < SIZE(caller.products); ++i) expand_type_abbreviations(caller.products.at(i).type); //: Rewrite 'load-ingredients' to instructions to create all reagents in the header. :(before "End Rewrite Instruction(curr, recipe result)") if (curr.name == "load-ingredients") { curr.clear(); recipe_ordinal op = get(Recipe_ordinal, "next-ingredient-without-typechecking"); for (int i = 0; i < SIZE(result.ingredients); ++i) { curr.operation = op; curr.name = "next-ingredient-without-typechecking"; curr.products.push_back(result.ingredients.at(i)); result.steps.push_back(curr); curr.clear(); } } if (curr.name == "next-ingredient-without-typechecking") { raise << maybe(result.name) << "never call 'next-ingredient-without-typechecking' directly\n" << end(); curr.clear(); } //: internal version of next-ingredient; don't call this directly :(before "End Primitive Recipe Declarations") NEXT_INGREDIENT_WITHOUT_TYPECHECKING, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "next-ingredient-without-typechecking", NEXT_INGREDIENT_WITHOUT_TYPECHECKING); :(before "End Primitive Recipe Checks") case NEXT_INGREDIENT_WITHOUT_TYPECHECKING: { break; } :(before "End Primitive Recipe Implementations") case NEXT_INGREDIENT_WITHOUT_TYPECHECKING: { assert(!Current_routine->calls.empty()); if (current_call().next_ingredient_to_process < SIZE(current_call().ingredient_atoms)) { products.push_back( current_call().ingredient_atoms.at(current_call().next_ingredient_to_process)); assert(SIZE(products) == 1); products.resize(2); // push a new vector products.at(1).push_back(1); ++current_call().next_ingredient_to_process; } else { products.resize(2); // pad the first product with sufficient zeros to match its type products.at(0).resize(size_of(current_instruction().products.at(0))); products.at(1).push_back(0); } break; } //: more useful error messages if someone forgets 'load-ingredients' :(scenario load_ingredients_missing_error) % Hide_errors = true; def foo a:num [ local-scope b:num <- add a:num, 1 ] +error: foo: tried to read ingredient 'a' in 'b:num <- add a:num, 1' but it hasn't been written to yet +error: did you forget 'load-ingredients'? :(after "use-before-set Error") if (is_present_in_ingredients(caller, ingredient.name)) raise << " did you forget 'load-ingredients'?\n" << end(); :(scenario load_ingredients_missing_error_2) % Hide_errors = true; def foo a:num [ local-scope b:num <- add a, 1 ] +error: foo: missing type for 'a' in 'b:num <- add a, 1' +error: did you forget 'load-ingredients'? :(after "missing-type Error 1") if (is_present_in_ingredients(get(Recipe, get(Recipe_ordinal, recipe_name)), x.name)) raise << " did you forget 'load-ingredients'?\n" << end(); :(code) bool is_present_in_ingredients(const recipe& callee, const string& ingredient_name) { for (int i = 0; i < SIZE(callee.ingredients); ++i) { if (callee.ingredients.at(i).name == ingredient_name) return true; } return false; } //:: Check all calls against headers. :(scenario show_clear_error_on_bad_call) % Hide_errors = true; def main [ 1:num <- foo 34 ] def foo x:point -> y:num [ local-scope load-ingredients return 35 ] +error: main: ingredient 0 has the wrong type at '1:num <- foo 34' :(scenario show_clear_error_on_bad_call_2) % Hide_errors = true; def main [ 1:point <- foo 34 ] def foo x:num -> y:num [ local-scope load-ingredients return x ] +error: main: product 0 has the wrong type at '1:point <- foo 34' :(after "Transform.push_back(check_instruction)") Transform.push_back(check_calls_against_header); // idempotent :(code) void check_calls_against_header(const recipe_ordinal r) { const recipe& caller = get(Recipe, r); trace(9991, "transform") << "--- type-check calls inside recipe " << caller.name << end(); for (int i = 0; i < SIZE(caller.steps); ++i) { const instruction& inst = caller.steps.at(i); if (inst.operation < MAX_PRIMITIVE_RECIPES) continue; const recipe& callee = get(Recipe, inst.operation); if (!callee.has_header) continue; for (long int i = 0; i < min(SIZE(inst.ingredients), SIZE(callee.ingredients)); ++i) { // ingredients coerced from call to callee if (!types_coercible(callee.ingredients.at(i), inst.ingredients.at(i))) { raise << maybe(caller.name) << "ingredient " << i << " has the wrong type at '" << inst.original_string << "'\n" << end(); raise << " ['" << to_string(callee.ingredients.at(i).type) << "' vs '" << to_string(inst.ingredients.at(i).type) << "']\n" << end(); } } for (long int i = 0; i < min(SIZE(inst.products), SIZE(callee.products)); ++i) { if (is_dummy(inst.products.at(i))) continue; // products coerced from callee to call if (!types_coercible(inst.products.at(i), callee.products.at(i))) { raise << maybe(caller.name) << "product " << i << " has the wrong type at '" << inst.original_string << "'\n" << end(); raise << " ['" << to_string(inst.products.at(i).type) << "' vs '" << to_string(callee.products.at(i).type) << "']\n" << end(); } } } } //:: Check types going in and out of all recipes with headers. :(scenarios transform) :(scenario recipe_headers_are_checked) % Hide_errors = true; def add2 x:num, y:num -> z:num [ local-scope load-ingredients z:&:num <- copy 0/unsafe return z ] +error: add2: replied with the wrong type at 'return z' :(before "End Checks") Transform.push_back(check_return_instructions_against_header); // idempotent :(code) void check_return_instructions_against_header(const recipe_ordinal r) { const recipe& caller_recipe = get(Recipe, r); if (!caller_recipe.has_header) return; trace(9991, "transform") << "--- checking return instructions against header for " << caller_recipe.name << end(); for (int i = 0; i < SIZE(caller_recipe.steps); ++i) { const instruction& inst = caller_recipe.steps.at(i); if (inst.name != "reply" && inst.name != "return") continue; if (SIZE(caller_recipe.products) != SIZE(inst.ingredients)) { raise << maybe(caller_recipe.name) << "replied with the wrong number of products at '" << inst.original_string << "'\n" << end(); continue; } for (int i = 0; i < SIZE(caller_recipe.products); ++i) { if (!types_match(caller_recipe.products.at(i), inst.ingredients.at(i))) raise << maybe(caller_recipe.name) << "replied with the wrong type at '" << inst.original_string << "'\n" << end(); } } } :(scenario recipe_headers_are_checked_2) % Hide_errors = true; def add2 x:num, y:num [ local-scope load-ingredients z:&:num <- copy 0/unsafe return z ] +error: add2: replied with the wrong number of products at 'return z' :(scenario recipe_headers_are_checked_against_transformed_instructions) % Hide_errors = true; def foo -> x:num [ local-scope x:num <- copy 0 z:bool <- copy 0/false return-if z, z ] +error: foo: replied with the wrong type at 'return-if z, z' :(scenario recipe_headers_check_for_duplicate_names) % Hide_errors = true; def foo x:num, x:num -> z:num [ local-scope load-ingredients return z ] +error: foo: 'x' can't repeat in the ingredients :(scenario recipe_headers_check_for_duplicate_names_2) % Hide_errors = true; def foo x:num, x:num [ # no result local-scope load-ingredients ] +error: foo: 'x' can't repeat in the ingredients :(scenario recipe_headers_check_for_missing_types) % Hide_errors = true; def main [ foo 0 ] def foo a [ # no type for 'a' ] +error: foo: ingredient 'a' has no type
/*
 * occupantswin.c
 * vim: expandtab:ts=4:sts=4:sw=4
 *
 * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
 * Copyright (C) 2019 - 2023 Michael Vetter <jubalh@iodoru.org>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#include "config.h"

#include <assert.h>

#include "config/preferences.h"
#include "ui/ui.h"
#include "ui/window.h"
#include "ui/window_list.h"

static void
_occuptantswin_occupant(ProfLayoutSplit* layout, GList* item, gboolean showjid, gboolean isoffline)
{
    int colour