9fans.net/go@v0.0.7/cmd/sam/error.go (about)

     1  // #include "sam.h"
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  )
     9  
    10  var emsg = [47]string{
    11  	/* error_s */
    12  	"can't open",
    13  	"can't create",
    14  	"not in menu:",
    15  	"changes to",
    16  	"I/O error:",
    17  	"can't write while changing:",
    18  	/* error_c */
    19  	"unknown command",
    20  	"no operand for",
    21  	"bad delimiter",
    22  	/* error */
    23  	"can't fork",
    24  	"interrupt",
    25  	"address",
    26  	"search",
    27  	"pattern",
    28  	"newline expected",
    29  	"blank expected",
    30  	"pattern expected",
    31  	"can't nest X or Y",
    32  	"unmatched `}'",
    33  	"command takes no address",
    34  	"addresses overlap",
    35  	"substitution",
    36  	"& match too long",
    37  	"bad \\ in rhs",
    38  	"address range",
    39  	"changes not in sequence",
    40  	"addresses out of order",
    41  	"no file name",
    42  	"unmatched `('",
    43  	"unmatched `)'",
    44  	"malformed `[]'",
    45  	"malformed regexp",
    46  	"reg. exp. list overflow",
    47  	"plan 9 command",
    48  	"can't pipe",
    49  	"no current file",
    50  	"string too long",
    51  	"changed files",
    52  	"empty string",
    53  	"file search",
    54  	"non-unique match for \"\"",
    55  	"tag match too long",
    56  	"too many subexpressions",
    57  	"temporary file too large",
    58  	"file is append-only",
    59  	"no destination for plumb message",
    60  	"internal read error in buffer load",
    61  }
    62  var wmsg = [8]string{
    63  	/* warn_s */
    64  	"duplicate file name",
    65  	"no such file",
    66  	"write might change good version of",
    67  	/* warn_S */
    68  	"files might be aliased",
    69  	/* warn */
    70  	"null characters elided",
    71  	"can't run pwd",
    72  	"last char not newline",
    73  	"exit status not 0",
    74  }
    75  
    76  func error_(s Err) {
    77  	hiccough(fmt.Sprintf("?%s", emsg[s]))
    78  }
    79  
    80  func error_s(s Err, a string) {
    81  	hiccough(fmt.Sprintf("?%s \"%s\"", emsg[s], a))
    82  }
    83  
    84  func error_r(s Err, a string, err error) {
    85  	if pe, ok := err.(*os.PathError); ok && pe.Path == a {
    86  		err = pe.Err
    87  	}
    88  	hiccough(fmt.Sprintf("?%s \"%s\": %v", emsg[s], a, err))
    89  }
    90  
    91  func error_c(s Err, c rune) {
    92  	hiccough(fmt.Sprintf("?%s `%c'", emsg[s], c))
    93  }
    94  
    95  func warn(s Warn) {
    96  	dprint("?warning: %s\n", wmsg[s])
    97  }
    98  
    99  func warn_S(s Warn, a *String) {
   100  	print_s(wmsg[s], a)
   101  }
   102  
   103  func warn_SS(s Warn, a *String, b *String) {
   104  	print_ss(wmsg[s], a, b)
   105  }
   106  
   107  func warn_s(s Warn, a string) {
   108  	dprint("?warning: %s `%s'\n", wmsg[s], a)
   109  }
   110  
   111  func termwrite(s string) {
   112  	if downloaded {
   113  		p := tmpcstr(s)
   114  		if cmd != nil {
   115  			loginsert(cmd, cmdpt, p.s)
   116  		} else {
   117  			Strinsert(&cmdstr, p, len(cmdstr.s))
   118  		}
   119  		cmdptadv += len(p.s)
   120  		freetmpstr(p)
   121  	} else {
   122  		os.Stderr.WriteString(s)
   123  	}
   124  }